FFmpeg: How to merge all audio streams into stereo

Viewed 7099

I have 4 audio streams in my video file. They are from 4 microphones placed at 4 different people speaking. I want to transcode to a preview file that can be listened to on headphones where everybody's voice can be heard.

I have seen the -ac 2 option, but I can't tell if this will merge all the audio streams or just select the 1st two. I've also seen the amerge filter, but the docs say this will produce 4 audio channels in the output file. So I'm wondering how headphones will deal with the additional 2 channels

2 Answers

You have several options. This assumes each individual audio stream in in.mp4 is mono.

Mono

Using the amerge filter and -ac 1:

ffmpeg -i in.mp4 -filter_complex "[0:a]amerge=inputs=4[a]" -ac 1 -map 0:v -map "[a]" -c:v copy out.mp4

With amix:

ffmpeg -i in.mp4 -filter_complex "[0:a]amix=inputs=4[a]" -map 0:v -map "[a]" -c:v copy out.mp4

Stereo

With amerge and -ac 2:

ffmpeg -i in.mp4 -filter_complex "[0:a]amerge=inputs=4[a]" -ac 2 -map 0:v -map "[a]" -c:v copy out.mp4

Manually mixed stereo

Using amerge and pan with custom downmix:

  • Channel 0 will be 100% in FL
  • Channel 1 will be 75% in FL & 25% in FR
  • Channel 2 will be 25% in FL & 75% in FR
  • Channel 3 will be 100% in FR


ffmpeg -i in.mp4 -filter_complex "[0:a]amerge=inputs=4,pan=stereo|FL<c0+0.75*c1+0.25*c2|FR<0.25*c1+0.75*c2+c3[a]" -map 0:v -map "[a]" -c:v copy out.mp4
Related