Configure Individual Weights in FFmpeg amix
This article provides a straightforward guide on how to configure
individual input weights when mixing multiple audio streams using the
FFmpeg amix filter. You will learn how to use the native
weights parameter to control the volume balance of each
audio source directly, alongside an alternative method using individual
volume filters for compatibility with older FFmpeg installations.
Using the Native amix Weights Parameter
In modern versions of FFmpeg, the amix filter includes a
dedicated weights parameter. This parameter allows you to
specify the relative volume weight of each input stream as a
space-separated list of numbers.
The basic syntax is:
amix=inputs=N:weights='W1 W2 W3 ...'
Example Command
To mix three audio inputs where the first input is at full volume, the second is at half volume, and the third is at a quarter volume, use the following command:
ffmpeg -i input1.mp3 -i input2.mp3 -i input3.mp3 -filter_complex "amix=inputs=3:weights='1 0.5 0.25'" output.mp3How the Weights Behave
Relative Scale: The weights are relative to one another. Setting weights to
2 1is mathematically identical to setting them to1 0.5.Default Value: If you do not specify weights, FFmpeg defaults to a weight of
1for all inputs.Volume Normalization: By default,
amixnormalizes the combined output volume to prevent digital clipping. If you want to maintain the exact input volumes without automatic lowering, you can disable this by addingnormalize=0to the filter:ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "amix=inputs=2:weights='1 0.3':normalize=0" output.mp3
Alternative Method: Using the Volume Filter
If you are using an older version of FFmpeg that does not support the
weights parameter within amix, you can achieve
the same result by applying the volume filter to each audio
stream individually before passing them to the mixer.
Example Command
ffmpeg -i input1.mp3 -i input2.mp3 -filter_complex "[0:a]volume=1.0[a1];[1:a]volume=0.5[a2];[a1][a2]amix=inputs=2" output.mp3In this command: 1. [0:a]volume=1.0[a1] labels the first
input’s audio, keeps its volume at 100%, and outputs it as stream
[a1]. 2. [1:a]volume=0.5[a2] labels the second
input’s audio, reduces its volume to 50%, and outputs it as stream
[a2]. 3. [a1][a2]amix=inputs=2 mixes the two
pre-adjusted streams together.