Use FFmpeg to add an aditional subtitle to a mkv video

Running ex. on Evita from 1996

First let Examining the source file with ffprobe and grep the Stream lines with the googdies

ffprobe Evita.mkv

Then will see these stream lines

Stream #0:0(eng): Video: h264 (High), yuv420p, 1280×536, SAR 67:68 DAR 40:17, 23.98 fps, 23.98 tbr, 1k tbn, 47.95 tbc (default)
Stream #0:1(eng): Audio: ac3, 48000 Hz, 5.1(side), fltp, 448 kb/s (default)
Stream #0:2(ita): Subtitle: subrip
Stream #0:3(eng): Subtitle: subrip
Stream #0:4(spa): Subtitle: subrip
Stream #0:5(fre): Subtitle: subrip
Stream #0:6(ger): Subtitle: subrip
Stream #0:7(dut): Subtitle: subrip
Stream #0:8(chi): Subtitle: subrip

This tells us that -map layers is:
0:0 is the video layer
0:1 is the Audio layer
0:2 is the italian subtitle layer
0:3 is the English subtitle layer
0:4 is the Spanish subtitle layer
0:5 is the Frensh subtitle layer
0:6 is the German subtitle layer
0:7 is the Dutch subtitle layer
0:8 is the Chinese subtitle layer

Now we will add the subtitle layer for the danish language, by simply copy all the source and add the contents of the file, but if you would like to have a “named” list of which subtitle layer is which you need to do some manual labor adding the -metadata:0:9 language=dan I’m afraid. Now go ahead and do as in the code below 🙂

You determine the -metadata:s:x by simply take the highest number in source file and adding +1, on this case 8+1=9 which makes the -metadata:s:9

ffmpeg -y -i Evita.mkv -f srt -i -map 0:0 -map 0:1 -map 0:2 -map 0:3 -map 0:4 -map 0:5 -map 0:6 -map 0:7 -map 0:8 -map 1:0 -c copy -c:s srt -metadata:s:9 language=dan Evita-dan.mkv

Posted on

Use FFmpeg to add subtitles to video


ffmpeg -i input.mp4 -f srt -i -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s mov_text output.mp4


ffmpeg -i input.mp4 -f srt -i -map 0:0 -map 0:1 -map 1:0 -c:v copy -c:a copy -c:s srt  output.mkv

To understand the -map option you’ll first need to examine your source file by running the video trough ffprobe or ffmpeg

ffmprob -i video.mp4

Then you’ll see some lines named “Stream”, each stream represent a video, sound and/or subtitle. Streams starting with 0: is video or sound tracks and streams starting with a number higher than 0 is subtitle (overlays)

To add several subtitles to the same video requires you to add a -c:s mov_text or -c:s srt for each subtitle submitted

If you like to add a title to each soundtrack or subtitle you can use the -metadata:s: and -metadata:s:s


For soundtracks you’ll use for English

-metadata:s:0 language=English

For subtitle you have to use the extra s

-metadata:s:s:1 language=English \
-metadata:s:s:2 language=Dansk

Posted on