How to Use FFmpeg Compand Filter for Audio Expansion
This guide explains how to use the FFmpeg compand filter
to apply dynamic expansion to an audio track. Dynamic expansion
increases the dynamic range of an audio signal, typically by making
quiet sounds quieter (downward expansion) to reduce background noise, or
making loud sounds louder. Below, you will find the exact syntax, a
breakdown of the key parameters, and a practical command-line
example.
To configure the compand filter as an expander, you must
define how the output volume level responds to the input volume level
using the filter’s parameters. The basic syntax for the filter is:
compand=attacks:decays:points:[soft-threshold:[gain:[volume:[delay]]]]
Key Parameters for Expansion
- attacks: The time in seconds it takes for the
filter to react to an increase in input volume. For expansion, a fast
attack (e.g.,
0.1to0.3seconds) is common. - decays: The time in seconds it takes for the filter
to react to a decrease in input volume. A slower decay (e.g.,
0.5to1.0seconds) prevents rapid, unnatural volume fluttering. - points: A list of input/output decibel (dB)
mappings that define the expansion curve. This is the most crucial part
of the filter. Each point is defined as
input/output. - gain: The overall volume adjustment applied after processing, defined in dB (default is 0).
Practical Example: Downward Expansion
Downward expansion reduces the volume of sounds that fall below a specific threshold. This is highly effective for reducing background noise or room hiss without completely cutting off the audio like a noise gate.
Run the following command to apply downward expansion to an audio file:
ffmpeg -i input.wav -filter:a "compand=attacks=0.1:decays=0.5:points=-80/-100|-40/-40|0/0" output.wavHow the Points Curve Works
In the example above, the points parameter is set to
-80/-100|-40/-40|0/0. Here is how FFmpeg interprets these
values:
-80/-100: An input signal of -80 dB is reduced to -100 dB. This quiet range is pushed further down into silence.-40/-40: An input signal at -40 dB remains at -40 dB. This acts as the threshold where expansion stops.0/0: The peak input level of 0 dB remains at 0 dB.
Any signal between -80 dB and -40 dB is dynamically expanded (made quieter) along the slope created between these coordinates, effectively separating the unwanted noise floor from the main audio program.