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:

  1. 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).
  2. 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).
  3. 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.mp3

Breakdown of the 3 Bands:

Note: In the command line, backslashes (\) are used to escape the commas within the filter chain, depending on your shell environment.