1

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
asked Apr 19 at 20:42
6
  • Are you sure that the SRT files are in UTF-8 format? Commented Apr 19 at 21:27
  • @AliKhakbaz just to make sure, I saved them again as UTF-8 and saw no difference Commented Apr 19 at 22:09
  • In your first command you forgot to map existing subtitles. You need to add -map 0:s. And -c:s:0 mov_text designates the codec of the first subtitle track, according to you it is the Italian track. You must change it to -c:s:3 mov_text Commented Apr 19 at 22:21
  • @Alain1A45 Thank you. I tried this: ffmpeg -i 3.mp4 -i eng.mp3 -i eng.srt \ -map 0:v -map 0:a -map 0:s -map 1:a -map 2:s:0 \ -metadata:s:a:0 language=eng -metadata:s:s:0 language=eng \ -c:s:3 mov_text -shortest 3plus1.mp4 it gave an error about not being able to select the encoder automatically and asked me to do it manually -- I have no idea how Commented Apr 19 at 22:28
  • 1
    Try : ffmpeg -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 Commented Apr 20 at 0:50

1 Answer 1

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.

Giacomo1968
59.1k23 gold badges180 silver badges225 bronze badges
answered Apr 20 at 12:10
1
  • 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! Commented Apr 20 at 14:13

You must log in to answer this question.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.