Alex Balgavy

Just some stuff about me.

Here's my dotfiles repository.

Check out my blog.

My keys: PGP, SSH

My crypto wallets (BTC, XMR)

ffmpeg how to mix additional audio into a video

Written by John Riselvato - original link

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. The command is as follows:

$ 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. Setting the louder input volume down can resolve this. In the example below the volume of the first input audio [0:a]​ is 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

The option ​-shortest​ here changes the duration to the longest input media. For example, if the MP4 is longer than the MP3 the duration cuts to the MP3 length.

**Tip:**​ See question, ​*“What is -map and How is it Used?”*​, for more details.