9

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.

  • 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 Feb 11 '11 at 1:42
  • @fred My subtitle file ends with .srt, and Nautilus tells me the format is SubRip subtitles (application/x-subrip). – Tshepang Feb 24 '11 at 13:07
7

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

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...

0

Try something like:

mencoder -oac copy -ovc copy -sub subs.srt video.mp4 -o new_video.mp4
  • 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 Feb 11 '11 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 Oct 13 '14 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. :\ – Tomislav Nakic-Alfirevic Feb 22 '18 at 2:33

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.