Skip to content

Instantly share code, notes, and snippets.

@huubl
Forked from pavelbinar/extract-subtitles-from-mkv.md
Created August 11, 2022 12:28
Show Gist options
  • Save huubl/a88d0a054b413371eae5c37e46dc132a to your computer and use it in GitHub Desktop.
Save huubl/a88d0a054b413371eae5c37e46dc132a to your computer and use it in GitHub Desktop.
Extract subtitles from .mkv files on Mac OS X

Extract Subtitles From .mkv

These instructions shall work on Mac OS X and Linux.

Install mkvtoolnix (Mac OS X)

Installation via Homebrew:

brew install mkvtoolnix

List content of the .mkv file

mkvmerge -i myFile.mkv

Example of the 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 this in batch for all files in a directory (works only if all files have the 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
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment