Use ffmpeg to add multiple subtitles separately to a video

Viewed 3188

I am trying to add multiple languages of subtitles to a video using ffmpeg. I succeeded in adding 1 language, but can't seem to add a second one. I use this simple script to add english subtitles to my video.

ffmpeg -i %1 -i subs_eng.srt -map 0 -vcodec copy -acodec copy -scodec subrip -metadata:s:s:0 language=English "%~n1"_eng.mkv

In addition, I run another script to add the Dutch subtitles.

ffmpeg -i %1 -i subs_nl.srt -map 0? -vcodec copy -acodec copy -scodec subrip -metadata:s:s:1 language=Dutch "%~n1"_nl.mkv

But whenever I add the second language, it doesn't seem to do anything. The command terminal shows that ffmpeg is processing the video, but there is only 1 subtitle language available in vlc media player (the first one).

I really want to be able to add it in 2 takes rather than in the same script, as I don't have both languages for all of my video's.

2 Answers

Without -map for the subtitle stream, ffmpeg will select only one subtitle stream from among all inputs.

ffmpeg -i %1 -i subs_nl.srt -map 0 -map 1 -vcodec copy -acodec copy -c:s:0 copy -c:s:1 subrip -metadata:s:s:1 language=Dutch "%~n1"_nl.mkv

I set codec mode for the existing subtitle stream to copy and subrip for only the new one. This assumes you muxed exactly one subtitle stream earlier.

It is easier in fact. You can add subtitles to a file without removing old ones by

ffmpeg -i input.mkv -i input.srt -map 0 -map 1 -c copy output.mkv

-map x selects all streams from a file so all streams from both files get into the output file. If you add more input subtitle tracks, you need to supply -map 2, -map 3 and so on. See the very conscious and simple Map documentation.

Now more tricky is if you want to properly label these subtitles. You can add

-metadata:s:s:0 language=heb -metadata:s:s:0 handler_name=Hebrew -metadata:s:s:0 title=Hebrew
-metadata:s:s:1 language=eng -metadata:s:s:1 handler_name=English -metadata:s:s:1 title=English

But you need to know the final mapping which will depend on original files ab/presence of subtitles.

Credits to eladkarako.

Related