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.mp3Parameter Breakdown
-i input1.mp3 -i input2.mp3 -i input3.mp3: These arguments load your three separate input audio files.-filter_complex: This flag is used because you are combining multiple inputs into a single output.amix=inputs=3: This specifies theamixfilter and tells FFmpeg to expect exactly three input streams.duration: This determines when the output stream should end.longest(default): The output ends when the longest input ends.shortest: The output ends when the shortest input ends.first: The output ends when the first input (input1.mp3) finishes.
dropout_transition: The transition time (in seconds) to renormalize the volume when one of the input streams ends.
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.mp3In 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.