How to use MKVToolNix to extract SRT subtitle form MKV file

I have downloaded this MKVToolNix but I do not know how to use it for extracting the SRT subtitle. Who know ?

mkvtoolnix comes only with a command line tool for extraction.

There are a few GUIs available from 3rd parties.
On Windows, I use https://sourceforge.net/projects/gmkvextractgui/

But Orca’s tool which I linked to in the other thread will also extract the subtitles, as long as they are in SRT format.

I have a Mac. So I guess this tool will not work for me ? I also have MacX Video Converter Pro. This app should also be able to extract subtitles, but I don’t know how ?

Or is there a MAC equivalent for https://sourceforge.net/projects/gmkvextractgui/ ?

a quick Googling yields this: https://www.macupdate.com/app/mac/23764/imkvextract

I found MKVtools …it looks like it is simple and that it works. Testing it now … it needs quite some time to extract the subtitle. Is that normal ? I thought just cut the subtitle track from the MKV file and done … ?

@janscherders said:
I found MKVtools …it looks like it is simple and that it works. Testing it now … it needs quite some time to extract the subtitle. Is that normal ? I thought just cut the subtitle track from the MKV file and done … ?

The subtitle is ā€˜muxed in’, which means to get the subtitle, the whole file must be read, because the data packets of the subtitle are interwoven with the video and audio packets.

You could also use Plex’s transcoder through a command line/terminal, what ever the correct term for a Mac is. I’m use to using Windows, which would use the command below to extract the first subtitle stream it sees.

PlexTranscoder - i input_file.mkv -map 0:s:0 -c copy subtitle_file.ext

Of coarse you need to know the type of subtitle to name the proper extension. If you have more than 1 subtitle, just change the 0:s:0 to 0:s:1, 0:s:2, etc. for the one you want. If you want all of them, just repeat the command for each subtitle.

1 Like

That is very interesting!

As @ā€œMovieFan.Plexā€ has described, we can use -map 0:s:0 to get the first subtitle stream.

If one calls the Transcoder, it will respond with its configuration. This includes all the known encoders
-enable-encoder=flac --enable-encoder=alac --enable-encoder=libvorbis --enable-encoder=libopus --enable-encoder=mjpeg --enable-encoder=wrapped_avframe --enable-encoder=ass --enable-encoder=dvbsub --enable-encoder=dvdsub --enable-encoder=movtext --enable-encoder=ssa --enable-encoder=subrip --enable-encoder=text --enable-encoder=webvtt --enable-encoder=xsub --enable-encoder=pcm_f32be --enable-encoder=pcm_f32le --enable-encoder=pcm_f64be --enable-encoder=pcm_f64le --enable-encoder=pcm_s8 --enable-encoder=pcm_s8_planar --enable-encoder=pcm_s16be --enable-encoder=pcm_s16be_planar --enable-encoder=pcm_s16le --enable-encoder=pcm_s16le_planar --enable-encoder=pcm_s24be --enable-encoder=pcm_s24le --enable-encoder=pcm_s24le_planar --enable-encoder=pcm_s32be --enable-encoder=pcm_s32le --enable-encoder=pcm_s32le_planar --enable-encoder=pcm_u8 --enable-encoder=pcm_u16be --enable-encoder=pcm_u16le --enable-encoder=pcm_u24be --enable-encoder=pcm_u24le --enable-encoder=pcm_u32be --enable-encoder=pcm_u32le --enable-encoder=h264_qsv --enable-encoder=mpeg2_qsv --enable-encoder=hevc_qsv --enable-encoder=h264_vaapi --enable-encoder=hevc_vaapi --enable-encoder=h264_nvenc --enable-encoder=eac3_eae

We do not have to guess the .ext! Instead we directly call the encoder of our targeted subtitle format. e.g.
-c ass ~/Downloads/test5.ass
or
-c subrip ~/Downloads/test5.srt

In both cases, we get a nicely formatted file in the respective subtitle style.

If you want to extract a specific track from an mkv file using MKVToolNix, for instance an audio track or a subtitle track, you just select the track you want extracted, uncheck the boxes next to all the tracks you want to exclude, and then in the destination file, change the file extension from ā€˜.mkv’ to ā€˜.aac’ or ā€˜.srt’ or whatever applies. Then press ā€˜start multiplexing’. You don’t need to use the command line tool to do this.

3 Likes

@affleckdan said:
If you want to extract a specific track from an mkv file using MKVToolNix, for instance an audio track or a subtitle track, you just select the track you want extracted, uncheck the boxes next to all the tracks you want to exclude, and then in the destination file, change the file extension from ā€˜.mkv’ to ā€˜.aac’ or ā€˜.srt’ or whatever applies. Then press ā€˜start multiplexing’. You don’t need to use the command line tool to do this.

I don’t think that is good advice. While the file will have the proper extension, it will actually not be a properly formatted file, and I’m pretty sure it will not work with most, if any, video players, including Plex.

for example, the first 2 lines from a proper .srt file…

1
00:00:07,108 --> 00:00:08,468
- Previously,
on "The Magicians"...

2
00:00:10,144 --> 00:00:11,145
- Quentin...
[cries out]

and from the file created the way suggested…

    E᜜B†B÷BòBóBā€šĖ†matroskaB—B…S€g    #M›t½M»ŒSĀ«ā€žIĀ©fSĀ¬ā€šM»ŒSĀ«ā€žTĀ®kSĀ¬ā€šÅ M»ŒSĀ«ā€žSĀ»kSĀ¬ā€šĆ MĀ»ĀSĀ«ā€žTƃgS¬ƒ!hƬO¾
    ('I Am The Sun') 64-bitD‰ˆAE+€   Daˆa€É©ð#Ʀ s¤BgI@Ć¢[gQÜV›
    ˆÛƕTĀ®k¬®ª×sňàŽ1ƤGj%ĀĘ’Āˆ œ †‹S_TEXT/UTF8SnʒSDHƬD%
    C¶u@Ę’Ć§ā€šĀ® ā€¹Ā”…   .ā€ŗā€šƵ Ā®Ā”¨ - Previously,
    on "The Magicians"...ā€ŗā€šƈ Ā£Ā”ĀĀ
    ò - Quentin...
    [cries out]›

Best to extract the subtitle properly, even if it takes a little longer.

@leelynds said:
I don’t think that is good advice. While the file will have the proper extension, it will actually not be a properly formatted file, and I’m pretty sure it will not work with most, if any, video players, including Plex.

Yeah, it is still in the matroska container.

Best to extract the subtitle properly, even if it takes a little longer.

If you use one of the frontend GUI’s available for mkvextract, it doesn’t even have to take longer.
https://mkvtoolnix.download/links.html

I used MKV Extract GUI a couple of days ago to strip out a perfectly good SRT file and it took about as long as it would take to remux it - so I can’t say it was a long and tedious process…

ā€œiMkvExtractā€

MKVToolNix works fine with its GUI but also in the terminal on macOS. The raw apps are just hidden in the app itself. To access them…

  • Right click the MKVToolNix in /Applications and click Show Package Contents
  • from there goto ./Contents/MacOS or ./Contents/Resources to find the MKVToolNix binaries (sorry… I cannot check the exact path right now)
  • Open the app Terminal
  • Drag the binary mkvextract into the terminal window… this will copy the full path into terminal (don’t worry, it won’t move the actual file)
  • Follow the MKVToolNix documentation to complete the command to extract your SRT

If you don’t want to do this without a GUI I can also recommend to use an app called Subler. Opening the MKV with Subler will result in Subler creating a new media file, allowing you to chose which tracks to transfer from the MKV (don’t worry if it doesn’t allow you to transfer the movie track… all you need is the subtitle). After confirming, you can extract the subtitle from the ā€žnew fileā€œ and exit the app.
This also works great if you have image based DVD/Blu-Ray subtitles. Subler will apply OCR to convert those into SRTs.

Here is a quick way to extract all subtitle tracks from every mkv file in the current directory.
Just save the below code as .BAT or .CMD file format.

@ECHO OFF
ECHO Extracting all .mkv subtitle tracks in current folder.
ECHO.
ECHO.
FOR %%A IN (*.mkv) DO (
FOR /F %%I IN ('mkvmerge --identify "%%A" ^| FIND /C "Track ID"') DO (
IF %%I GTR 0 (
ECHO Analyzing "%%~nxA"
FOR /L %%T IN (0,1,%%I) DO (
mkvmerge.exe --identify "%%~dpnxA" | FIND /C "Track ID %%T: subtitles">NUL
IF NOT ERRORLEVEL 1 mkvextract.exe tracks "%%~dpnxA" %%T:"%%~dpnA-ID%%T".srt
)
)
ECHO.
ECHO.
))
ECHO.
ECHO.
ECHO The end.....
PAUSE

This batch file will require the files mkvmerge.exe and mkvextract.exe. Both come with MKVToolNix

NOTE: This will extract all ass/ssa, srt, sup, idx/sub, (and maybe more) subtitles and save them as MKVfileName-IDx. Where x is the MKV TrackID.
ONE CAVEAT THOUGH… All but idx/sub end up with the file extension .SRT. You will have to rename that extension if you need the extension to be true for the format. An example of this is SubtitleEdit, where it will not import ā€œ.SUPā€ sub-pictured subtitles if the extension is .SRT.

3 Likes

@tom80H said:
If you don’t want to do this without a GUI I can also recommend to use an app called Subler. Opening the MKV with Subler will result in Subler creating a new media file, allowing you to chose which tracks to transfer from the MKV (don’t worry if it doesn’t allow you to transfer the movie track… all you need is the subtitle). After confirming, you can extract the subtitle from the ā€žnew fileā€œ and exit the app.
This also works great if you have image based DVD/Blu-Ray subtitles. Subler will apply OCR to convert those into SRTs.

Same applies to Subtitle Edit on Windows

I can NOT thank you enough for this!

I have been searching/testing different ways of extracting subtitles and your solution is SPOT-ON. I have tested it on several files so far with no trouble at all. It is SOOO fast. =D

Thank you.

1 Like