Multiple audio tracks from one source in ffmpeg

IanBauters picture IanBauters · Dec 25, 2017 · Viewed 10.8k times · Source

I'm transcoding my video using ffmpeg but I am unable to figure out how I can get both a 2 channel aac option (downmuxed) and a surround AC3 option in one go. My current command is:

ffmpeg -i input.mp4 \
-c:v libx265 -preset medium -crf 21 -pix_fmt yuv420p10le \
-tag:v hvc1 \
-c:a libfdk_aac -b:a 320k \
-c:a ac3 -b:a 512k \
movie_10bit.m4v

But I only get surround out of this. All help is much appreciated.

Answer

tuntap picture tuntap · Dec 25, 2017

Go with the -map option to ffmpeg. Suppose input stream 0:0 is the video stream and 0:1 is the audio stream (find out by ffmpeg -i input.mp4). Use -map to create one video stream and two audio streams in the output:

ffmpeg -i input.mp4 \
-map 0:0 -map 0:1 -map 0:1 \
-c:v libx265 -preset medium -crf 21 -pix_fmt yuv420p10le \
-tag:v hvc1 \
-c:a:0 libfdk_aac -b:a:0 320k \
-c:a:1 ac3 -b:a:1 512k \
movie_10bit.m4v

-c:a:0 and -c:a:1 describe the codec for the two audio streams.