How to Configure FFmpeg Compand Delay and Gain

This article explains how to configure the delay and gain parameters within the FFmpeg compand (compressor/expander) filter. You will learn the exact command syntax, how the post-processing gain and lookahead delay parameters function, and how to apply them to your audio files using practical command-line examples.

Understanding the Compand Filter Syntax

The compand filter in FFmpeg is used to adjust the dynamic range of audio. The basic syntax for the filter is:

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

To configure the gain and delay parameters, you must navigate this specific order of arguments, as they are positional.

Configuring the Gain Parameter

In the compand filter, "gain" refers to the overall post-compression gain (often called makeup gain) applied to the output signal. It is used to boost the overall volume of the audio after the dynamic range has been compressed.

  • Parameter Position: The 4th argument in the filter chain (after soft-knee).
  • Unit: Decibels (dB).
  • Usage: A positive value (e.g., 6) increases the volume of the output signal by that amount in dB, while a negative value (e.g., -3) decreases it.

Input/Output Gain Points

In addition to the final makeup gain, you also configure gain behavior using the points parameter (the 2nd argument). Points define the transfer function using input/output dB pairs separated by a pipe (|).

For example, points=-90/-90|-20/-10|0/-3 means:

  • An input of -90 dB remains -90 dB.
  • An input of -20 dB is boosted to -10 dB (a gain of +10 dB).
  • An input of 0 dB is compressed to -3 dB (a reduction of -3 dB).

Configuring the Delay Parameter

The delay parameter acts as a "lookahead" buffer. It delays the main audio signal relative to the volume detector. This allows the compressor to detect sudden volume spikes and adjust the gain before the spike actually reaches the output, preventing momentary clipping.

  • Parameter Position: The 6th (and final) argument in the filter chain.
  • Unit: Seconds (e.g., 0.2 represents 200 milliseconds).
  • Usage: The delay value should generally be equal to or slightly longer than the longest attack time specified in the first argument of the filter. If you do not specify a delay, it defaults to 0, meaning no lookahead is performed.

Practical Example Command

The following command demonstrates how to apply a compand filter with specific gain and delay settings:

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

Breakdown of the Configuration:

  • attacks=0.3 and decays=0.8: The compressor takes 0.3 seconds to react to an increase in volume and 0.8 seconds to release after the volume drops.
  • points=-90/-90|-20/-10|0/0: Defines the compression curve.
  • soft-knee=6: Sets a 6 dB soft-knee curve to make the compression transition smoother.
  • gain=5: Applies +5 dB of makeup gain to the entire output signal.
  • volume=-90: Sets the initial volume detector level to -90 dB.
  • delay=0.3: Sets a lookahead delay of 0.3 seconds (300 milliseconds) to match the attack time, preventing transient clipping.