Saturday, January 15, 2011

Extracting Subtitles from a MKV


You have a .MKV (Matroska Video) video file with embedded subtitles and you need to extract them to separate .SRT (Subtitles) file. Here is how to do this with the help of freeware software.
You will need the following:
  1. a .MKV File with a built-in Subtitles track (how to check will follow shortly)
  2. Your favourite media player. For this post I use VLC Media Player 
  3. MKVToolnix – a set of cross platform tools for .MKV files (get them from here)
And here is how you get going.

Step #1 – Verify that your MKV file actually does have built-in subtitles
Screenshot #1
(Click to zoom)

The easiest way is to check is to open the file using VLC Player. Select Tools --> Media Info (or press Ctrl+J). Switch to the “Codec Details” tab. Expand all the items underneath until you find one with the type “Subtitle”.  An example can be seen in the screenshot on the right.

Another way of doing this is to use the mkvinfo tool from the MKVToolnix collection mentioned above. If you are, start up mkvinfo in graphical mode with the following command line:

mkvinfo –g {Press Enter}

Screenshot #2
(Click to zoom)

Then open up your .MKV file (Select File --> Open). You should see the same information as we saw before here too (see screenshot).

Important: Make a note of the “Track Number” for our subtitle track. In our case, the value is 3. This will come in handy with the extraction process.

Step #2 – Extract the Subtitles into a .SRT file
We will now use the mkvextract tool from the MKVToolnix kit. The exact command line format to use is:

mkvextract.exe tracks {path of the MKV file}  {track number we noted in the previous step}:{Filename to save the subtitles to}

In the case of my example, this will look like the following:

mkvextract.exe tracks "c:\My_MKV_Video_File.mkv" 3:My_MKV_Video_File.srt

Note the number used to prefix the .SRT filename. This is “Track Number” we noted in the previous step.
-->
Going beyond
The mkvextract tool is just as capable of extracting other tracks - audio or video. All you need to do is use the right track number as prefix. So for instance, if the first track is audio, you can extract it with very little modification to the command we used before

mkvextract.exe tracks "c:\My_MKV_Video_File.mkv" 1:Audio_track.mp3

Again, note that we prefixed the MP3 filename with the right track number. We can also combine all of what we did above to extract both audio and subtitles in one single line:

mkvextract.exe tracks "c:\My_MKV_Video_File.mkv" 1:Audio_track.MP3 3:My_MKV_Video_File.srt

For more possibilities, look through the documentation of the mkvextract tool. And if this work for you or you did something cooler with this - I would love to hear from you. Please leave me a comment below.

See also: Extracting an MP3 from a Youtube video

34 comments:

  1. I have Windows 7 Ultimate 64 bit, mkvmerge GUI v4.8.0 and a .mkv file with a subtitle file that I want.

    When I load my video file I get all the different things under Tracks, chapter and tags. I uncheck all, except my chosen tracks of subtitles and as output filename I rename it from my_video.mkv to my_video.srt and then I press "Start muxing".

    Is there anything I can do to improve this ? I want norwegian subtitles and I get some funny letters...

    ReplyDelete
  2. Eyolf, it doesn't work that way. You need to follow the steps outlined on this page i.e. identify the track you want, then use the command line to extract it.
    A couple of things I found that might be useful:
    1. If you're using VLC (as I did) to identify the track you want to extract, add 1 to the stream number when using the command line, as VLC starts at 0 (zero).
    2. By default the track extracts to the installed MKV toolkit's data folder.

    BTW Thanks to his Techie Self.

    ReplyDelete
  3. This worked perfectly for me, unlike many other things I tried. Thanks for the quick, easy tutorial.

    ReplyDelete
  4. Worked perfectly. Thank you.

    ReplyDelete
  5. Help anyone:
    I tried this command:
    mkvextract tracks c:\iso\wolmi.mkv 3:wolmi.srt

    Warning: Unsupported CodecID 'S_VOBSUB' for ID:3. The track will be skipped. Nothing To Do.

    Interestingly, the mkv doesn't show it's subtitle in VLC nor any player except KMPLAYER. Does this mean this mkv uses vobsub instead of text and mkvextract doesn't have an ocr to read it?

    Thanks anyone!!!

    ReplyDelete
    Replies
    1. That's correct. It's seems to be an extraction tool. No OCR.

      Delete
  6. Perfect. Able to extract subtitle out. Thanks

    ReplyDelete
  7. Love how the program closes before I can type anything into the command line, 10/10 best unusable software I've ever downloaded.

    ReplyDelete
  8. thank you soooooooooo much :)

    ReplyDelete
  9. How can a CLI app "close" before you can type? Too much GUI for you... (check both on Wikipedia willya)

    ReplyDelete
  10. You said it :)
    --
    Mayuresh

    ReplyDelete
  11. Great! As a beginner, I don't know where to type those commands.

    ReplyDelete
  12. clippabluntz7/01/2012 8:50 pm

     you have no idea what you're doing, please don't blame it on this excellent piece of software

    ReplyDelete
  13. @Benturath - Try opening a command prompt (Start > Run > cmd, and press Enter). However, if you've never run a Command at the prompt before I would tread very very carefully. But once you do, there's no going back to being a mouse-only user (I mean it's fun and addictive) :-)

    ReplyDelete
  14. this
    is so greaaaaaaaaaaaaaaaat. thanks so much

    ReplyDelete
  15. where can i find the extracted srt?

    ReplyDelete
  16. You can specify the name and path of the srt file in the command line E.g. C:\my_video.srt.
    --
    Mayuresh

    ReplyDelete
  17. Works like a charm!

    Thanks

    ReplyDelete
  18. Perfect !!!! Thank you

    ReplyDelete
  19. I was delighted to find this one.I could not unravel the official description of command-line operations.

    Just one problem. While I specify .srt subtitle files – as instructed here – I actually get.sub.

    I know that it is something that I am doing wrong, but I can't for the life of me figure it out. I tried adding some of the other switches on the official list. No luck.

    ReplyDelete
  20. Perhaps you could post the command line you execute we can try and figure it out?
    --
    Mayuresh

    ReplyDelete
  21. Thanks bro! :)

    ReplyDelete
  22. first time so confuse and finally excited! thank you so much

    ReplyDelete
  23. Alexis Garcia4/01/2013 6:14 am

    Thank you for share. I was able to extract SRT from MKV in 5 seconds (i had the MKV in an SSD). Thanks!

    ReplyDelete
  24. Thank you very much... ^_^
    this worked perfectly... :-)

    ReplyDelete
  25. Thanks it works great,

    I was also wondered where the created .srt file was and it was in the c:MKVToolkit folder.

    ReplyDelete
  26. Thanks! Now I don't need to play those .mkv files that lag my PC :3

    ReplyDelete
  27. Delighted I could be of help to so many of you. And thanks for letting me know :)

    ReplyDelete
  28. I wanted to extract some embedded subs and this article was the first thing I found. I admit I was unfamiliar with both MKVtoolnix and using the command prompt. The main article left me rather baffled but after reading Mayuresh's comment to Benturath I was able to get it all figured out. I guess I'm saying the article could have been more novice friendly to begin with.

    Afterwards I found a GUI for MKVtoolnix called MKVcleaver. I found that it makes the whole extraction process feel more straight forward for the command-prompt-inexperienced like myself. I used version 6.02 which I believe is currently the latest version.

    I hope it's alright for me to post a link...

    MKVcleaver home site:
    http://apps.einsof-haras.ca/help.html

    A second alternative to using the command prompt involves creating a shortcut to mkvextract.exe(found in your MKVtoolnix folder).

    2) Right-click the shortcut and choose Properties.

    3) under the 'Shortcut' tab you can put your command line in the "Target:" field.

    So if MKVtoolnix is installed to c:\ you would put this in the "Target:" field:

    C:\MKVToolNix\mkvextract.exe tracks "c:\My_MKV_Video_File.mkv" 3:c:\My_MKV_Video_File.srt

    That way, when you have a .mkv file to extract a track from, you can edit that "Target:" field to have the .mkv file location and track number/filetype.

    4)Then click Apply at the bottom of the preferences window and double-click the shortcut. It will run the .exe with the command line.

    Thanks to Mayuresh for getting me pointed in the right direction.

    ReplyDelete
  29. I can't change the command, I mean it says .idx not .srt?
    How can I change that?!

    ReplyDelete
  30. Having issue with extracting Codec ID: S_HDMV/PGS to SRT.
    1: mkvinfo -g identifies the track # as 3
    2: using command line: F:\>mkvextract.exe tracks "f:\GOTS3D1.mkv"3:GOTS3D1.srt
    3: returns: Error: No track with the ID 3 was found in the source file.
    4: I created the MKV using Handbrake but need the SRT to view sub on ROKU stream
    5: Also tried track 0, 1, or 2. A file is created for the other tracks but 0 should not return anything. Track 2 returns unreadable characters.
    Any idea what may be the issue?

    ReplyDelete
  31. Michael Tran5/30/2014 12:48 pm

    Thank you for the information. But since I usually do batch extractions/conversion for videos, I rather not do this process every single time...

    So I created a vbscript where you simply drag and drop the mkv files into the vbscript to automatically extract all subtitles for you through the mkvinfo and mkvextract.exe command line tool.
    My knowledge and skills with vbscript and mkvtool is only entry level, so my script can probably have a lot of improvements.

    Download Link:
    http://depositfiles.com/files/icpdl6uko

    Scanned at www.virustotal.com, returned 0 out of 53, so it is safe.
    https://www.virustotal.com/en/file/270b9d5f0f8bfec4cd1d85c08292393c36bf4df162722102dc883744adb936f9/analysis/1401449469/

    Please note that it does NOT work with folders. It only works with a selection of mkv videos, and if you try to put like 10+ mkv files at one go, it may lag for a bit. I also didn't bother too much with the error checking.


    Feel free to modify the script to suit your needs or improve it.

    Notes:
    mkvinfo and mkvextract.exe I used is version 5.9.0. In the future, if they decide to change the mkvinfo output format for whatever reason, or command syntax for any one of them, it would render my script non functional.

    ReplyDelete