Assuming both inputs contain stereo audio you can use the amerge
audio filter to merge both stereo streams into a single four channel stream, then use the pan
audio filter to combine the appropriate channels into a single stereo stream:
ffmpeg -i video.flv -i audio.mp3 -filter_complex \
"[0:a][1:a]amerge,pan=stereo:c0<c0+c2:c1<c1+c3[a]" \
-map 0:v -map "[a]" -c:v copy -c:a aac -strict experimental -shortest out.mp4
The video can be stream copied (depending on the input video format) as shown in the example if you do not need to re-encode it, but if you must re-encode then see the FFmpeg and x264 Encoding Guide.
The example uses the native FFmpeg AAC encoder which requires
-strict experimental
(or the alias-strict -2
). See the FFmpeg and AAC Encoding Guide for information on other encoders.The option
-shortest
will finish encoding when the shortest input stream ends.See Manipulating audio channels with
ffmpeg
for more examples.Make sure you're using a recent version of
ffmpeg
. See the FFmpeg Download page for builds for Windows, OS X, and Linux.