I want to use FFmpeg to add English audio and subtitle tracks (eng.mp3 and eng.srt) to a video (call it 3.mp4) that already has Italian, French and German. The crucial thing is that the final video allows switching between language audio and subtitle tracks.
To summarize, I want: 3.mp4 + eng.mp3 + eng.srt → 3plus1.mp4
I've tried this but it does not work::
ffmpeg -i 3.mp4 -i eng.mp3 -i eng.srt \
-map 0:v -map 0:a -map 1:a -map 2:s:0 \
-metadata:s:a:0 language=eng -metadata:s:s:0 language=eng \
-c:s:0 mov_text -shortest 3plus1.mp4
I can make video from scratch with 4 languages (4.mp4) starting from all the .mp3 and .srt files as follows (notice that the video part is produced on the fly as just a black background; this keeps files small for testing and video is not the point here):
This works: ita.mp3 + fre.mp3 + ger.mp3 + eng.mp3 + ita.srt + fre.srt + ger.srt + eng.srt → 4.mp4
ffmpeg -f lavfi -i "color=color=black:s=1280x720" \
-i ita.mp3 -i fre.mp3 -i ger.mp3 -i eng.mp3 \
-i ita.srt -i fre.srt -i ger.srt -i eng.srt \
-map 0:v -map 1:a:0 -map 2:a:0 -map 3:a:0 -map 4:a:0 \
-map 5:s:0 -map 6:s:0 -map 7:s:0 -map 8:s:0 \
-metadata:s:a:0 language=ita -metadata:s:a:1 language=fra -metadata:s:a:2 language=ger -metadata:s:a:3 language=eng \
-metadata:s:s:0 language=ita -metadata:s:s:1 language=fra -metadata:s:s:2 language=ger -metadata:s:s:3 language=eng \
-c:s:0 mov_text -c:s:1 mov_text -c:s:2 mov_text -c:s:3 mov_text \
-shortest 4.mp4
I don't see how to upload the files I'm using for testing here but I found a site called disroot that looks like it allows file sharing.
This link is to a count.zip archive I made with all the files I've been using for testing.
Edit: the solution to this post (found here) is as follows
ffmpeg -i 3.mp4 -i eng.mp3 -i eng.srt -map 0:v -map 0:a -map 1 -map 0:s -map 2 -c copy -c:a:3 aac -c:s:3 mov_text -metadata:s:a:3 language=eng -metadata:s:s:3 language=eng -shortest 3plus1.mp4
1 Answer 1
To add new tracks and optimize playback on your player, here's a command:
ffmpeg -i 3.mp4 -i eng.mp3 -i eng.srt -map 0:v -map 0:a -map 1 -map 0:s -map 2 -c copy -c:s:3 mov_text -metadata:s:a:3 language=eng -metadata:s:s:3 language=eng -shortest 3plus1.mp4
With mapping, you can reorder the tracks: first video, then audio tracks, then subtitle tracks.
The video and audio tracks are simply copied (streamcopy), and the added subtitle track is the only one that is encoded.
-
Please see the edit I added to the end of my original post: Briefly, I still can't see the English audio using the video players I use the most: QT (Mac OS) and Documents (iOS). With this command the order listed by ffmpeg is perfect: 0:0(und): Video, 0:1(ita): Audio, 0:2(fra): Audio, 0:3(ger): Audio, 0:4(eng): Audio, 0:5(ita): Subtitle, 0:6(fra): Subtitle, 0:7(ger): Subtitle, 0:8(eng): Subtitle. I will mark this as the solution if no one comes up with something better. Thanks again!Tony M– Tony M2025年04月20日 14:13:11 +00:00Commented Apr 20 at 14:13
-map 0:s. And-c:s:0 mov_textdesignates the codec of the first subtitle track, according to you it is the Italian track. You must change it to-c:s:3 mov_textffmpeg -i 3.mp4 -i eng.mp3 -i eng.srt -map 0 -map 1 -map 2 -c copy -c:s:3 mov_text -metadata:s:a:3 language=eng -metadata:s:s:3 language=eng -shortest 3plus1.mp4