28

I'm trying to extract subtitles from MP4 and MKV movies. I'm using mp4box (on OS X) but cannot figure out how it works.

Any hints?

48

MP4 and 3GP files

The free and cross-platform MP4Box only works with MP4 or 3GP containers. You can install it from the homepage. First, you want look at the different tracks and see which ID belongs to the subtitle track.

MP4Box -info input.mp4

Look at the ID next to the subtitle track. Then, based on the track ID <trackId> you want to extract, call the following command:

MP4Box -raw <trackID> input.mp4

Or, to export to the commonly used SRT format:

MP4Box -srt <trackID> input.mp4

MKV files

In order to extract subtitles from Matroska (MKV) files, you need the free and open source mkvtoolnix packages. They come for Windows and Linux, and on a Mac you can install them through Homebrew with brew install mkvtoolnix.

Then, inspect the file:

mkvmerge -i input.mkv

This will list the tracks, for example like this:

File 'input.mkv': container: Matroska
Track ID 1: video (V_MPEG4/ISO/AVC)
Track ID 2: audio (A_AAC)
Track ID 3: subtitles (S_TEXT/UTF8)

Based on the ID of the track, call the following command, where <trackID> is the one you identified above. <output> is just a dummy name, you can use any you want.

mkvextract tracks input.mkv <trackID>:<output>.srt

So, in our case, that would have been:

mkvextract tracks input.mkv 3:subs.srt
  • 1
    This all works for linux too. I found MP4Box in the gpac package available via apt-get – aidan Jun 12 '14 at 14:01
  • 1
    To get MP4Box in Arch Linux, you need to install gpac from the community repo. – Alfredo Hernández Sep 10 '16 at 21:18
11

Here is a solution for virtually any file format that is supported by ffmpeg (even remote files are supported):

ffmpeg -i video.mp4 subtitle.srt

ffmpeg is present in newer Ubuntu versions by default, for Mac OS X and Windows you'll have to install it (by downloading it from official web site or via homebrew).

Here video.mp4 is source local or remote video file name, and subtitle.srt is output subtitle file name. It is important to specify file extension for output, since ffmpeg detects what exactly you want to extract by it. That is, you can specify .mp3 file extension in order to extract mp3 audio from video file, or just set another video container in order to convert between formats.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.