ffmpeg -i input.mp4 -f srt -i input.srt -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 input.srt -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
ffprobe video.mp4
OR
ffmpeg -i video.mp4
Then you'll see some lines named "Stream", each stream represent a video,
sound and/or subtitle.
Streams starting with 0:
are video or sound tracks (streams) 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 English soundtracks you'll use English for language
-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
Thanks for sharing the example!
This is what I got to work with several languages:
I used the ISO 639-2 three character language code for the subtitle
language
metadata which seems to be recognized by bothmediainfo
andvlc
as their locale names.I had a problem with one of my subtitle files being encoded with
WINDOWS-1252
rather than the expectedUTF-8
. It would produce an error like this when encoding:To fix it you can detect the encoding with
chardet
oruchardet
and then useiconv
to convert to the expectedUTF-8
: