How to Use FFmpeg mcompand for Multi-Band Compression
This article provides a practical guide on how to use the
mcompand (multi-band compand) filter in FFmpeg to perform
multi-band audio compression. You will learn the core syntax of the
filter, understand how to configure its parameters for different
frequency bands, and see a real-world command-line example to enhance
your audio processing workflows.
Understanding the mcompand Filter
Unlike standard compressors that apply gain reduction to the entire
audio signal, the mcompand filter splits the audio spectrum
into multiple frequency bands and compresses (or expands) each band
independently. This is highly useful for mastering, leveling podcasts,
or taming problematic frequencies (like muddy bass or harsh treble)
without affecting the rest of the mix.
The Syntax of mcompand
The mcompand filter accepts definition strings for each
band, separated by the pipe (|) character.
The basic structure for a single band definition is:
attack,decay,... points [crossover_frequency]
Each band definition consists of the following components:
- Attack and Decay Times: Two pairs of attack and
decay times (in seconds).
- The first pair controls how quickly the volume sensor responds to increases and decreases in level.
- The second pair controls how quickly the compressor gain is adjusted.
- Example:
0.005,0.1 0.005,0.1(fast attack of 5ms, slower decay of 100ms).
- Transfer Function (Points): A list of input/output
decibel (dB) pairs defining the compression curve.
- Example:
-60,-60,-15,-10,0,-3(if input is -60dB, output is -60dB; if input is -15dB, output is compressed to -10dB; if input is 0dB, output is limited to -3dB).
- Example:
- Crossover Frequency: The upper boundary frequency (in Hz) of the current band. The final band does not require a crossover frequency, as it automatically covers everything up to the Nyquist frequency.
Practical 3-Band Compression Example
Below is a practical FFmpeg command that applies a 3-band compressor to an audio file. This setup divides the audio into Low (Bass), Mid, and High (Treble) frequencies.
ffmpeg -i input.mp3 -af "mcompand=0.005\,0.1 0.005\,0.1 -60\,-60\,-15\,-10\,0\,-3 150 | 0.003\,0.05 0.003\,0.05 -60\,-60\,-15\,-12\,0\,-5 3000 | 0.002\,0.05 0.002\,0.05 -60\,-60\,-15\,-15\,0\,-8" output.mp3Breakdown of the 3 Bands:
- Band 1 (Bass - Below 150 Hz):
- Settings:
0.005\,0.1 0.005\,0.1 -60\,-60\,-15\,-10\,0\,-3 150 - Explanation: A moderate attack/decay is used. Input levels at -15dB are boosted to -10dB, and peaks at 0dB are compressed to -3dB to keep the low-end punchy but controlled.
- Settings:
- Band 2 (Mids - 150 Hz to 3000 Hz):
- Settings:
0.003\,0.05 0.003\,0.05 -60\,-60\,-15\,-12\,0\,-5 3000 - Explanation: A faster response is used for mid-frequencies (containing vocals and main instruments). Compression is slightly tighter, limiting 0dB peaks to -5dB.
- Settings:
- Band 3 (Treble - Above 3000 Hz):
- Settings:
0.002\,0.05 0.002\,0.05 -60\,-60\,-15\,-15\,0\,-8 - Explanation: Very fast attack times prevent harsh, sibilant peaks. The highest frequencies are compressed more aggressively, limiting 0dB to -8dB to prevent ear fatigue.
- Settings:
Note: In the command line, backslashes (\) are used
to escape the commas within the filter chain, depending on your shell
environment.