How to Use the mcompand Filter in FFmpeg
The mcompand (multiband compander) filter in FFmpeg is a
powerful audio processing tool used to compress or expand the dynamic
range of different frequency bands independently. This article provides
a straightforward guide on how the mcompand filter works,
breaks down its complex syntax, and provides practical examples to help
you improve your audio files, whether you are mastering music or
leveling voice recordings.
Understanding Multiband Companding
Unlike standard compressors that apply the same volume adjustments to the entire audio signal, a multiband compander splits the audio into multiple frequency bands (such as bass, mids, and treble). It applies compression or expansion to each band individually before mixing them back together.
This prevents loud bass frequencies from accidentally triggering volume reduction in the treble range, resulting in a much cleaner, louder, and more balanced sound.
The Syntax of mcompand
The mcompand filter uses a specific syntax where each
frequency band is defined and separated by a pipe (|)
character.
The basic structure for a single band is:
attacks,decays points [soft-threshold [delay [top-frequency]]]
Here is what these parameters mean:
- attacks,decays: The reaction times of the
compressor in seconds. Multiple channels are separated by commas. For
example,
0.005,0.1means a 5ms attack time and a 100ms decay time. - points: A list of input/output decibel (dB) pairs
that define the compression curve. For example,
-60,-60,-20,-10,0,0means:- Input at -60 dB outputs at -60 dB.
- Input at -20 dB is boosted/compressed to output at -10 dB.
- Input at 0 dB outputs at 0 dB.
- soft-threshold: (Optional) The size of the compression “knee” in dB. A higher value creates a smoother transition.
- delay: (Optional) Look-ahead delay in seconds. This allows the filter to “predict” upcoming volume spikes.
- top-frequency: (Optional) The upper frequency limit for this band in Hz. The next band will start at this frequency. Do not set this for the final band.
Practical Examples
Example 1: Basic Two-Band Compressor (Bass and Treble)
This command splits the audio at 1,000 Hz. The low frequencies (below 1,000 Hz) and high frequencies (above 1,000 Hz) are compressed separately.
ffmpeg -i input.wav -af "mcompand=0.005,0.1 -60,-60,-15,-10,0,0 0 0 1000 | 0.003,0.05 -60,-60,-20,-10,0,0 0 0" output.wavWhat this does: * Band 1 (0 to 1000 Hz): Uses a slower 5ms attack and 100ms decay to keep the bass smooth. * Band 2 (1000 Hz and up): Uses a faster 3ms attack and 50ms decay to quickly catch sharp treble peaks.
Example 2: Three-Band Compander for Voice and Podcasts
For voice recordings, a three-band setup helps tame boomy bass, level out vocal presence in the mids, and control harsh “s” sounds in the treble.
ffmpeg -i podcast_raw.mp3 -af "mcompand=0.01,0.15 -60,-60,-25,-15,0,0 0 0 200 | 0.005,0.1 -60,-60,-20,-10,0,0 0 0 4000 | 0.003,0.05 -60,-60,-15,-10,0,0 0 0" output_mastered.mp3Breakdown of the three bands: 1. Low Band (0 - 200 Hz): Targets low-end rumble and plosives. 2. Mid Band (200 - 4000 Hz): Targets the core vocal frequencies, applying moderate compression to keep the volume of the speech consistent. 3. High Band (4000 Hz and up): Targets sibilance and high-end air.