How to Use FFmpeg amix to Mix Three Audio Tracks

Mixing multiple audio inputs into a single output stream is a common task in media processing. This guide provides a straightforward explanation of how to use the FFmpeg amix filter to combine three separate audio tracks into a single, cohesive audio stream, detailing the exact command syntax and key parameters you need to control the output.

To mix three audio tracks using FFmpeg, you use the -filter_complex option with the amix filter. Here is the basic command to combine three audio files into one:

ffmpeg -i input1.mp3 -i input2.mp3 -i input3.mp3 -filter_complex "amix=inputs=3:duration=first:dropout_transition=2" output.mp3

Parameter Breakdown

Controlling Individual Track Volumes

By default, amix automatically scales the volume of each input down to prevent digital clipping (distortion caused by audio streams summing to a level that is too loud). If you want to manually adjust the volume of each track before mixing them, you can chain the volume filter to each input stream within the filter graph:

ffmpeg -i input1.mp3 -i input2.mp3 -i input3.mp3 -filter_complex "[0:a]volume=0.8[a1]; [1:a]volume=0.5[a2]; [2:a]volume=1.2[a3]; [a1][a2][a3]amix=inputs=3:duration=longest" output.mp3

In this advanced command: * [0:a]volume=0.8[a1] takes the first audio input (0:a), reduces its volume to 80%, and labels the temporary stream as a1. * [1:a]volume=0.5[a2] takes the second input, reduces its volume to 50%, and labels it a2. * [2:a]volume=1.2[a3] takes the third input, boosts its volume to 120%, and labels it a3. * [a1][a2][a3]amix=inputs=3 mixes these three adjusted streams together.