Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Extract subtitles from .mkv files on Mac OS X

Extract Subtitles From .mkv

This instructions whall work on any system (Mac OS X, Linux) supporting installation of mkvtoolnix

Install mkvtoolnix

If you don't have Homebrew installed, do it first, the continue with following command:

brew install mkvtoolnix

List content of the .mkv file

mkvmerge -i myFile.mkv

Example of file content

File 'myFile.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_DTS)
Track ID 3: subtitles (S_TEXT/UTF8)
Track ID 4: subtitles (S_TEXT/UTF8)
Chapters: 22 entries

Track ID 3 and 4 are subtitles.

Extract subtitles tracks into separate files

mkvextract tracks myFile.mkv 3:myFile1.srt 4:myFile2.srt

Enjoy!


Extract Multiple Files

In case you need to this in batch for all files in a directory. Works only if all files have same subtitle Track IDs.

Make sure you use correct file extension (*.mkv) and track-ids (3)

Example:

for file in *.mkv; do
  sub=$(echo $file | sed 's/\.mkv$/.srt/'); 
  mkvextract tracks "${file}" 3:"${sub}"; 
done
@KarlZeo

This comment has been minimized.

Copy link

KarlZeo commented Feb 17, 2018

Thinks.Help me a lot.

@soshial

This comment has been minimized.

Copy link

soshial commented Apr 7, 2018

Written really well, even for newbies.

@zhanshan

This comment has been minimized.

Copy link

zhanshan commented May 10, 2018

thank you, this helped a lot.

@chloebe

This comment has been minimized.

Copy link

chloebe commented Jun 20, 2018

Amazing, thank you! I have almost no idea what I'm doing, but I managed to figure it out (like I barely know how to use the commands on the terminal app on my Mac). :)

@Joshfindit

This comment has been minimized.

Copy link

Joshfindit commented Mar 2, 2019

Alternate:

  1. Install ffmpeg (for example, through brew install ffmpeg)
  2. ffmpeg -i video.mkv
  3. Look for Stream #<stream number>(eng): Subtitle: subrip where <stream number> is the stream number of the subtitle track. Eg: 0:2
  4. ffmpeg -i video.mkv -map <stream number> subs.srt (example: ffmpeg -i video.mkv -map 0:2 subs.srt)
@OBPremier

This comment has been minimized.

Copy link

OBPremier commented Aug 11, 2019

I'm trying this, but I keep getting the error:

-bash: syntax error near unexpected token `('

I guess it's because the file name contains parentheses ()? How can I solve this? Any help appreciated.

@pavelbinar

This comment has been minimized.

Copy link
Owner Author

pavelbinar commented Aug 16, 2019

Hi guys, I forgot that even exists. Just better formatted @bmaeser notes :)
Anyway, I am quite happy for your appreciation.
Feel free to suggest any improvements.

@pavelbinar

This comment has been minimized.

Copy link
Owner Author

pavelbinar commented Aug 16, 2019

I added useful notes "Extract Multiple Files" from @farzadshafiee

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.