Compress Audio Dynamic Range with FFmpeg Compand

This article explains how to use the compand (compressor/expander) filter in FFmpeg to compress the dynamic range of an audio file. You will learn the basic syntax of the filter, understand its key parameters—such as attack/decay times, transfer function points, and make-up gain—and see a practical, copy-pasteable command-line example to level out your audio.

Understanding the FFmpeg Compand Filter

Dynamic range compression reduces the volume of loud sounds and amplifies quiet sounds, creating a more consistent overall volume. This is highly useful for podcasts, dialogue tracks, and movie audio where quiet whispers are too soft and explosions are too loud.

In FFmpeg, this is achieved using the compand audio filter. The basic syntax for the filter is:

compand=attacks:decays:points:[soft-knee:[gain:[volume:[delay]]]]

Key Parameters Explained

  • attacks: A list of attack times in seconds for each channel (separated by pipes | or spaces). This defines how quickly the filter reacts to an increase in volume. A shorter attack time (e.g., 0.3) responds faster to sudden loud noises.
  • decays: A list of decay times in seconds for each channel. This defines how quickly the filter releases the compression after the volume drops. A typical value is between 0.5 and 1.0 seconds.
  • points: A list of input/output volume pairs in decibels (dB), separated by pipes. This defines the compression curve (the transfer function). For example, -90/-90|-40/-30|-20/-15|0/-10 means:
    • Very quiet sounds at -90dB remain at -90dB.
    • Quiet sounds at -40dB are boosted to -30dB.
    • Moderate sounds at -20dB are boosted to -15dB.
    • Loud sounds at 0dB are attenuated to -10dB.
  • soft-knee: (Optional) Controls the sharpness of the transition points. A value of 6 is standard for a smooth, natural-sounding curve.
  • gain: (Optional) The make-up gain in dB applied to the output signal.
  • volume: (Optional) Sets an initial volume level in dB to prevent a sudden burst of sound at the very beginning of the audio. Usually set to -90.
  • delay: (Optional) Look-ahead delay in seconds. This allows the filter to "see" loud transients coming and apply compression just before they happen, preventing clipping.

Practical Example Command

Below is a standard FFmpeg command used to compress dynamic range for a stereo audio file, making the quiet parts louder and the loud parts quieter:

ffmpeg -i input.mp3 -filter:a "compand=attacks=0.3|0.3:decays=0.8|0.8:points=-90/-90|-40/-30|-20/-15|0/-10:soft-knee=6:gain=0:volume=-90:delay=0.2" output.mp3

In this command:

  • -filter:a (or -af) applies the audio filter.
  • attacks=0.3|0.3 and decays=0.8|0.8 apply independent compression timing for the left and right stereo channels.
  • The points mapping squashes the dynamic range by pushing quiet parts up and limiting peaks.
  • delay=0.2 gives the compressor a 200-millisecond lookahead window to catch sudden peaks before they distort.