github email
Extract subtitles from mkvs
Oct 18, 2011
3 minutes read

If you have a device (such as my Samsung TV) that will gladly play matroska’s but ignore subtitles tracks, here’s an easy way to extract them to a separate .srt file:

First, find the track id of the subtitles you’re interested:

$ mkvinfo The.Big.Bang.Theory.S05E03.HDTV.720p.DD5.1.x264-HDxT.mkv

+ EBML head
|+ EBML version: 1
|+ EBML read version: 1
|+ EBML maximum ID length: 4
|+ EBML maximum size length: 8
|+ Doc type: matroska
|+ Doc type version: 2
|+ Doc type read version: 2
+ Segment, size 902663191
|+ Seek head (subentries will be skipped)
|+ EbmlVoid (size: 4044)
|+ Segment information
| + Timecode scale: 1000000
| + Muxing application: libebml v1.2.1 + libmatroska v1.1.1
| + Writing application: mkvmerge v4.9.1 ('Ich will') built on Jul 11 2011 23:53:15
| + Duration: 7199.500s (01:59:59.500)
| + Date: Sat Oct  1 08:00:27 2011 UTC
| + Segment UID: 0x80 0x92 0x0d 0x60 0x2e 0x48 0xc0 0x16 0x95 0x96 0xa4 0xfe 0x09 0xb3 0x24 0x14
|+ Segment tracks
| + A track
|  + Track number: 1
|  + Track UID: 2834284452
|  + Track type: audio
|  + Codec ID: A_AC3
|  + Default duration: 32.000ms (31.250 fps for a video track)
|  + Name: The.Big.Bang.Theory.S05E03.HDTV.720p.DD5.1.x264-HDxT
|  + Audio track
|   + Sampling frequency: 48000
|   + Channels: 6
| + A track
|  + Track number: 2
|  + Track UID: 1
|  + Track type: video
|  + Lacing flag: 0
|  + MinCache: 1
|  + Codec ID: V_MPEG4/ISO/AVC
|  + CodecPrivate, length 42 (h.264 profile: High @L4.1)
|  + Default duration: 41.708ms (23.976 fps for a video track)
|  + Name: The.Big.Bang.Theory.S05E03.HDTV.720p.DD5.1.x264-HDxT
|  + Video track
|   + Pixel width: 1280
|   + Pixel height: 720
|   + Display width: 1280
|   + Display height: 720
|  + Content encodings
|   + Content encoding
|    + Content compression
|     + Algorithm: 3 (header removal)
|     + Settings: length 1, data:  0x00
| + A track
|  + Track number: 3
|  + Track UID: 1483781004
|  + Track type: subtitles
|  + Lacing flag: 0
|  + Codec ID: S_TEXT/UTF8
| + A track
|  + Track number: 4
|  + Track UID: 1228504759
|  + Track type: subtitles
|  + Default flag: 0
|  + Lacing flag: 0
|  + Codec ID: S_TEXT/UTF8
|  + Language: gre
|+ EbmlVoid (size: 1173)
|+ Cluster

There are 2 tracks containing subtitles as you can see from the output above. What I’m interested in this case, is track 4 which contains the Greek subs. Now, to get them in an srt file:

$ mkvextract tracks The.Big.Bang.Theory.S05E03.HDTV.720p.DD5.1.x264-HDxT.mkv -c ISO8859-7 4:The.Big.Bang.Theory.S05E03.HDTV.720p.DD5.1.x264-HDxT.srt

That’s it. The -c flag tells mkvextract to dump them in ISO format, rather than UTF-8, since that’s what most devices understand.


Back to posts