Dynamic Audio Expansion with FFmpeg Compand Filter
This guide explains how to configure and apply a dynamic expander to
an audio track using FFmpeg's built-in compand filter. You
will learn the anatomy of the filter parameters, understand how to
construct the transfer curve for dynamic expansion, and see practical
command-line examples to increase dynamic range or suppress low-level
noise.
Understanding the
compand Filter Syntax
The compand filter handles both compression and
expansion. The basic syntax is:
compand=attacks:decays:points:soft-knee:gain:volume:delayThe parameters function as follows:
- attacks: Attack time in seconds (how quickly the expander reacts to rising volume).
- decays: Release/decay time in seconds (how quickly it settles after volume drops).
- points: The transfer curve specified as pairs of
input_dB/output_dBseparated by vertical bars (|). This is the key setting that determines expansion. - soft-knee: Radius in dB around the curve points to
smooth transitions (optional, default is
0.01). - gain: Makeup gain applied to the signal in dB
(default is
0). - volume: Initial volume level in dB (default is
0). - delay: Lookahead delay in seconds to allow the filter to react before peaks arrive (useful for fast transient peaks).
Setting Up the Transfer Curve for Expansion
A dynamic expander increases dynamic range by widening the difference between quiet and loud sounds. The most common form is downward expansion, where signals below a specified threshold are attenuated further.
Expansion occurs when the slope between two points on the transfer curve is greater than 1 (output dB increases faster than input dB, or drops faster below the threshold):
- 1:1 (Linear):
-20/-20|0/0(a 20 dB input change results in a 20 dB output change). - Downward Expander (e.g., 1:2 expansion ratio below -30
dB):
-90/-900: Silence point to prevent calculations from failing at negative infinity.-50/-70: An input of -50 dB is pushed down to -70 dB (a 20 dB drop for a 10 dB input decrease from -40 dB).-30/-30: Threshold point where expansion begins.0/0: Unity gain at the top.
Practical Examples
1. Basic Downward Expander (Gentle Noise Attenuation)
To reduce background noise below -40 dB while maintaining the natural dynamics of the primary signal:
ffmpeg -i input.wav -af "compand=attacks=0.05:decays=0.2:points=-90/-900|-60/-80|-40/-40|0/0:soft-knee=6" output.wavattacks=0.05/decays=0.2: Fast attack (50 ms) to open the expander quickly, moderate release (200 ms) to prevent sudden gating.points=-90/-900|-60/-80|-40/-40|0/0: Signals between -40 dB and 0 dB remain untouched. Signals dropping from -40 dB to -60 dB are attenuated to -80 dB (a 2:1 expansion ratio).soft-knee=6: Smoothes the curve by 6 dB around the inflection points to prevent abrupt artifacts.
2. High-Ratio Dynamic Expander (Noise Gate)
For aggressive reduction of floor noise (similar to a noise gate):
ffmpeg -i input.mp3 -af "compand=attacks=0.01:decays=0.1:points=-90/-900|-45/-90|-40/-40|0/0:delay=0.02" -c:a aac -b:a 192k output.mp4attacks=0.01: 10 ms attack time opens the gate instantly on speech or instruments.points=-90/-900|-45/-90|-40/-40|0/0: The signal drops 50 dB in output between -40 dB and -45 dB input, effectively cutting off low-level noise.delay=0.02: Adds a 20 ms lookahead buffer so the attack opens before the onset of the transient, avoiding clipped syllables.
3. Upward Expansion (Enhancing Transients)
To accentuate loud transients while leaving low-level audio unchanged, set a steeper slope near 0 dB:
ffmpeg -i input.wav -af "compand=attacks=0.005:decays=0.05:points=-90/-90|-18/-18|-6/0:gain=0" output.wavpoints=-90/-90|-18/-18|-6/0: Signals below -18 dB remain at unity gain (1:1). Signals between -18 dB and -6 dB are expanded upward to reach 0 dB, accentuating peaks.