Skip to content

Instantly share code, notes, and snippets.

@gmolveau
Last active April 5, 2023 16:00
Show Gist options
  • Star 7 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save gmolveau/a75679291028fcb22548a61da92377e7 to your computer and use it in GitHub Desktop.
Save gmolveau/a75679291028fcb22548a61da92377e7 to your computer and use it in GitHub Desktop.
Embed subtitle (soft) in mp4/mkv file with ffmpeg without re-encoding

solution from https://stackoverflow.com/a/17584272/2627873

This solution adds the subtitles to the video as a separate optional (and user-controlled) subtitle track.

So you can choose the subtitle in VLC for example, it's not hard-coded or burned-in. And it won't re-encode the entire file so it's really fast.

  • ffmpeg is required
  • movie = great_movie.mp4 (works with mkv too)
  • subtitle = great_movie.english.srt
ffmpeg -i great_movie.mp4 -i great_movie.en.srt -c copy -c:s mov_text great_movie_subbed.mp4

Another solution : https://www.reck.dk/use-ffmpeg-to-add-subtitles-to-video/

ffmpeg -i great_movie.mp4 -i great_movie.en.srt -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s mov_text great_movie_subbed.mp4
@spirillen
Copy link

You might like to explain what the

-map 0:0 -map 0:1 -map 1:0

Does and why it's preferable to use them.... like maintaining control of the streams...

@gmolveau
Copy link
Author

Thank's for pointing that out, I see that you did it on your own gist : https://gist.github.com/spirillen/af307651c4261383a6d651038a82565d

for the moment it's only a personal cheatsheet but maybe I'll edit later.

@franciscop
Copy link

franciscop commented Mar 25, 2021

Tip: if you want to set the title of the track to show as "English" instead of "Track 1", add -metadata:s:s:0 title="English" like this:

ffmpeg -i great_movie.mp4 -i great_movie.en.srt -c copy -c:s mov_text -metadata:s:s:0 title="🇬🇧 English" great_movie_subbed.mp4

@gmolveau
Copy link
Author

Nice, thank's :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment