ffmpeg - add 3 audio streams to video

Viewed 1422

I have the following problem.
In the folder there is video.mp4 file (contain 1 audio stream). There are also 3 different files audio1.wav, audio2.wav, audio3.wav. These files I need to 'attach' as multi stream to the video file - so the user can choose the audio language in VLC player or similar. Result must be one audio at the time - no mixing it all together.

Now, I've done it via Premiere Pro with multitrack (quicktime export to mov), and then I run a script to change audio stream names to correspond with the audio language (iso 639-2 ) and output the mp4 file. All works well, but I wonder if there is simple way to do everything via ffmpeg ( .bat script ). I have a working script for replacing audio in the video, but I need to add few additional .wav to the video file as separate audio tracks. Any help will be appreciated!

1 Answers

To add a new audio track into an existing video with audio, use

the -i parameter to specify all the input files (original video and additional audios)

the -map option to manually select the tracks of each input (https://trac.ffmpeg.org/wiki/Map)

in your case,
-map 0 to copy all streams from the input #0 (video)
-map 1:a to include all audio streams from input#1 file (audio1)
-map 2:a to include all audio streams from input#2 file (audio2)
and so on

and

-shortest to crop the output to the shortest input

and additionally you may want to use
-c:v copy to copy the video stream without reencoding.

so, try this (line split for readability)

 ffmpeg -i video.mp4 -i input1.mp3 -i input2.mp3 
        -map 0 -map 1:a -map 2:a 
        -c:v copy -shortest 
        output.mp4

and (addording to your comment) adding metadata for the audio tracks

ffmpeg -i video.mp4 -i input1.mp3 -i input2.mp3 
       map 0 -map 1:a -map 2:a 
       -metadata:s:a:0 language=eng
       -metadata:s:a:1 language=ger
       -metadata:s:a:2 language=fra 
       -disposition:a:0 default
       -c:v copy -shortest 
       output.mp4
Related