11

I would like to make a subtitle file to be a part of an mp4 video file, so that I don't have to deal with two separate files.

I imagine two ways:

  • Make the subtitle an intrinsic part of the video. This will require video re-encoding.
  • Make the subtitle a separate stream, but still embedded in the same video file. This is far more preferable, especially because I can disable it (unlike the other approach), or even play with the font type/size.

How do I do things the 2nd way? It would also be kool to know how the 1st approach works.

2
  • 1
    I haven't worked it out yet, but I'm very interested... It seems that the mp4 (MPEG-4) container can handle seperate emedded suptitle streams.. so (to me) that would be the way to go.. If you you hard-graft the subtitles into the video itself, you need to re-encode the video and they are embedded forever... The only advantage of hard-"coded" subtitles is that the video player doesn't need to be mp4-subtitle-stream aware... It's quite straight forward to hard encode an AVI , but I haven't had the need to use sutitle streams yet (yet :). Where is the format of your subtitles?
    – Peter.O
    Commented Feb 11, 2011 at 1:42
  • @fred My subtitle file ends with .srt, and Nautilus tells me the format is SubRip subtitles (application/x-subrip).
    – tshepang
    Commented Feb 24, 2011 at 13:07

3 Answers 3

9

The Matroska (mkv) container format supports text-based subtitles embedded as a separate stream into the file.

You could use mkvmerge to remux the file to .mkv and include the subtitles in the output, which you can enable/disable when playing the video. Note that this method will NOT re-encode the video or audio, it's just putting the same data into a different container format, so it will not decrease the quality of the video.

mkvmerge -o output.mkv video.mp4 subtitles.srt
2
  • Worked like a charm, and so fast I thought it crashed on start! Commented Feb 22, 2018 at 2:38
  • If you don't have it installed, sudo apt install mkvtoolnix
    – Jing Zhao
    Commented Oct 7, 2020 at 10:06
3

In a package called gpac, there is a CLI utility called MP4Box

Here is an example of what worked for me..

MP4Box  -add ~/file.noaudio.mp4 \
        -add ~/file.mp3 \
        -add ~/file.srt \
             ~/file.MP4Box.mp4   

I used a video-only and audio-only, but it will surely(?) work with a normal audio+video "movie" .... It's very late so I'll just leave it at that...

Note: The subtitles works in Totem, but not in SMPlayer...

1

Try something like:

mencoder -oac copy -ovc copy -sub subs.srt video.mp4 -o new_video.mp4
3
  • That doesn't work. It results in mangled audio and video, and the video is truncated (initial file is ~1.6GB and resulting file is ~200MB). I use mencoder 1.0-rc3.
    – tshepang
    Commented Feb 11, 2011 at 9:06
  • I have an mp4 file and an srt. But with these arguments the subtitle does not appear on the resulting file. :(
    – TrueY
    Commented Oct 13, 2014 at 21:09
  • Looked exactly what I was looking for. Tried it with a WebM video (VP8 video track, VORBIS audio track) and got a broken video as a result. Shame. :\ Commented Feb 22, 2018 at 2:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .