Blog / FFMPEG commands for audio/video mixing

Maybe you’ve heard of ffmpeg, the encoding program described as the Swiss Army knife of audio and video. If you’ve actually used it, you’ll know it’s a Swiss Army knife made out of buzzsaws.

The elGato Game Capture app showing a screenshot from Kingdom Hearts 3, in the San Fransokyo world

Here are some commands I figured out a few weeks ago when trying to rescue a video I had recorded at the wrong volume. Hopefully these are the commands you’ve been looking for.

Add an audio track to a video file

ffmpeg -i video.mp4 -i audio-output.m4a -c:v copy -map 0:v:0 -map 1:a:0 -shortest output.mp4

Mix two audio files together

ffmpeg -i audio-commentary.m4a -i audio-game.m4a -filter_complex amerge -ac 2 -c:a libmp3lame -q:a 4 audio-output.mp3

Mix two audio files together at separate volume levels (1 and 0.3)

ffmpeg -i audio-commentary.m4a -i audio-game.m4a -filter_complex "[0]volume=1[a];[1]volume=0.3[b];[a][b]amix=duration=shortest" -ac 2 -c:a aac -q:a 1 audio-output.m4a