How to Use FFmpeg Compand Filter for Audio Compression
In this guide, you will learn how to apply a classic dynamic range
compression effect to an audio file using FFmpeg’s powerful
compand (compressor/expander) filter. We will break down
the filter’s complex syntax, explain its key parameters like attack,
release, transfer function, and makeup gain, and provide a practical,
ready-to-use command to balance your audio levels.
The FFmpeg Audio Compression Command
To apply a classic compressor effect to an audio file, run the following command in your terminal:
ffmpeg -i input.wav -filter:a "compand=attacks=0.3|releases=0.8:points=-80/-80|-20/-12|0/-6:soft-knee=6:gain=0:volume=-90:delay=0.2" output.wavThis command takes your input audio, processes it through a configured compressor curve, and saves the output.
Breakdown of the Compand Parameters
The compand filter uses a specific syntax where
arguments are separated by colons (:). Here is what each
segment of the command does:
1. Attack and Release
(attacks=0.3|releases=0.8)
- Attack (0.3 seconds): The time it takes for the compressor to fully react and reduce the volume once the audio exceeds the threshold.
- Release (0.8 seconds): The time it takes for the compressor to stop reducing the volume once the audio falls below the threshold.
- Note: Multiple channels are separated by commas, while
attack and release values for a single channel are separated by a pipe
(
|).
2. The Transfer
Function (points=-80/-80|-20/-12|0/-6)
This is the most critical part of the compressor, defining the
input-to-output volume mapping in decibels (dB): * -80/-80:
Audio at -80 dB (near silence) remains unchanged at -80 dB. *
-20/-12: Audio at -20 dB is boosted to -12 dB. *
0/-6: Loud peaks at 0 dB are compressed down to -6 dB. *
This mapping compresses the dynamic range by bringing quiet sounds up
and pulling loud peaks down.
3. Soft Knee
(soft-knee=6)
- Set to
6dB. This parameter softens the transition curve around the defined points. Instead of a harsh change in compression ratio (hard knee), a soft knee makes the compression sound smoother and more natural.
4. Makeup Gain (gain=0)
- Set to
0dB. If your compression curve makes the overall audio too quiet, you can increase this value (e.g.,gain=3) to boost the overall output level of the compressed audio.
5. Initial Volume
(volume=-90)
- Set to
-90dB. This is the expected volume of the filter’s internal feedback loop at startup, preventing loud pops or clips when the audio first starts playing.
6. Lookahead Delay
(delay=0.2)
- Set to
0.2seconds. This tells FFmpeg to analyze the audio 0.2 seconds ahead of time. This lookahead allows the compressor to “anticipate” sudden loud transients (like drum hits or screams) and react instantly, preventing clipping.