简体   繁体   中英

FFMPEG: Add additional audio track to video file

I have two video file with the following streams:


File 1:

Stream #0:0(deu): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Stream #0:1(deu): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:2(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 4971 kb/s, 23.98 fps, 23.98 tbr, 2997 tbn, 5994 tbc (default)
Stream #0:3: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 480x480 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc

File 2:

Stream #0:0(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Stream #0:1(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:2(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 4925 kb/s, 23.98 fps, 23.98 tbr, 23976 tbn, 47952 tbc (default)
Stream #0:3(eng): Subtitle: eia_608 (c608 / 0x38303663), 1920x1080, 0 kb/s
Stream #0:4: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 480x480 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc


Both files have exactly the same video content , but the first video has a german audio track and the second one an english audio track.

How can I extract the audio track from the german video file and add it to the english one, without losing the english subtitles and being able to choose between these audio tracks in a media player?

I searched about this and I found multiple answers to similar questions, but none of them worked: Some included only one audio track and some played both of them at the same time.

I'm not sure if this question should be asked on Super User , but as there are alrealy many questions about ffmpeg on Stack Overflow, I asked it here.

It is important to note that FFmpeg cannot add to a file, it has to create a new file with the streams, settings and metadata all in one shot. Which makes it a good program to solve problems were the creation of a new file isn't an issue.

ffmpeg -i FILE1 \
     -i FILE2 \
     -map 1:2 -map 1:0 -map 1:1 -map 0:0 -map 0:1 -map 1:3 -map 1:4 \
     -c copy \
     -disposition:a -default -disposition:a:0 default \
     -disposition:v -default -disposition:v:0 default \
     OUTPUT

Information on the commands above can be found at FFmpeg Documentation 5.4 Main Options and 5.11 Advanced options .

The resulting OUTPUT file will have streams mapped as such:

Stream #0:0(eng): Video: h264 (High) (avc1 / 0x31637661), yuv420p(tv, bt709), 1920x1080 [SAR 1:1 DAR 16:9], 4925 kb/s, 23.98 fps, 23.98 tbr, 23976 tbn, 47952 tbc (default)
Stream #0:1(eng): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s (default)
Stream #0:2(eng): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:3(deu): Audio: aac (LC) (mp4a / 0x6134706D), 48000 Hz, stereo, fltp, 126 kb/s
Stream #0:4(deu): Audio: ac3 (ac-3 / 0x332D6361), 48000 Hz, 5.1(side), fltp, 384 kb/s
Stream #0:5(eng): Subtitle: eia_608 (c608 / 0x38303663), 1920x1080, 0 kb/s (default)
Stream #0:6: Video: mjpeg, yuvj420p(pc, bt470bg/unknown/unknown), 480x480 [SAR 72:72 DAR 1:1], 90k tbr, 90k tbn, 90k tbc

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM