How to 'burn' a subtitle track onto an mp4 video file

8,663

Solution 1

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

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

Solution 3

Try something like:

mencoder -oac copy -ovc copy -sub subs.srt video.mp4 -o new_video.mp4
Share:
8,663

Related videos on Youtube

tshepang
Author by

tshepang

I do software development for a living and as a hobby. My favorite language is Rust, and I've used Python much in the past. My OS of choice is Debian.

Updated on September 17, 2022

Comments

  • tshepang
    tshepang almost 2 years

    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.

    • Admin
      Admin over 13 years
      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?
    • Admin
      Admin over 13 years
      @fred My subtitle file ends with .srt, and Nautilus tells me the format is SubRip subtitles (application/x-subrip).
  • tshepang
    tshepang over 13 years
    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.
  • TrueY
    TrueY over 9 years
    I have an mp4 file and an srt. But with these arguments the subtitle does not appear on the resulting file. :(
  • Tomislav Nakic-Alfirevic
    Tomislav Nakic-Alfirevic over 6 years
    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
    Tomislav Nakic-Alfirevic over 6 years
    Worked like a charm, and so fast I thought it crashed on start!
  • Jing Zhao
    Jing Zhao over 3 years
    If you don't have it installed, sudo apt install mkvtoolnix