(FFmpeg) How to mix additional audio in an mp4?

Adding an additional audio source on top of the audio already in a video can be accomplished with the amix filter. This might be useful for adding background music to a commentary video as seen in the example below:

  $ ffmpeg -i input.mp4 -i input.mp3 -filter_complex "amix" -map 0:v -map 0:a -map 1:a output.mp4  

A common issue that comes up with amix is the volume of one input over powers the second, to solve this, setting the louder input volume down can resolve this. In the example below the volume of the first input audio [0:a] will be reduce 40%:

  $ ffmpeg -i input.mp4 -i input.mp3 -filter_complex [0:a]volume=0.40,amix -map 0:v -map 0:a -map 1:a -shortest output.mp4  

Now you have two audio streams playing in a single video. Quick and easy.

Love FFmpeg? Grab a copy of FFmpeg For Beginners on Kindle or Paperback to learn over 120 ways to master FFmpeg!

buy now on amazon