Configure FFmpeg Compand Attack and Release Times

This guide explains how to configure the attack and release times in the FFmpeg compand (compressor/expander) filter to control audio dynamics. You will learn the syntax of the compand filter, how attack and release times dictate volume adjustments, and how to apply these settings using practical command-line examples.

Understanding Attack and Release in FFmpeg

The compand filter adjusts the dynamic range of audio. The very first parameter of this filter is attacks_releases, which defines how quickly the compressor reacts to changes in the audio level.

  • Attack Time (in seconds): The time it takes for the filter to decrease the gain (apply compression) when the input signal level rises above the threshold. Shorter attack times (e.g., 0.01 to 0.1 seconds) catch sudden peaks quickly, while longer times let transients pass through.
  • Release Time (in seconds): The time it takes for the filter to increase the gain back to normal when the input signal level drops below the threshold. Shorter release times can cause a "pumping" effect, while longer release times (e.g., 0.5 to 2.0 seconds) sound more natural.

The Syntax

The compand filter parameters are defined in the following order:

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

The attacks_releases parameter is formatted as a space-separated list of attack and release pairs. If you have a stereo file, you can specify one pair to apply to all channels, or separate pairs for each channel.

Step-by-Step Configuration Examples

To configure a fast attack of 0.3 seconds and a smooth release of 0.8 seconds for all audio channels, format the filter like this:

ffmpeg -i input.mp3 -filter:a "compand=0.3 0.8:-80,-80,-20,-20,0,-10" output.mp3

In this command:

  • 0.3 0.8 sets the attack to 0.3 seconds and the release to 0.8 seconds.
  • -80,-80,-20,-20,0,-10 defines the transfer function (points) for compression.

Example 2: Ultra-Fast Peak Limiting

If you want to use the compand filter as a limiter to catch loud peaks immediately, use a very short attack time (e.g., 10 milliseconds) and a moderate release time (e.g., 0.5 seconds):

ffmpeg -i input.wav -filter:a "compand=0.01 0.5:-80,-80,-12,-12,0,-3" output.wav

Example 3: Independent Channel Configuration

For multi-channel audio where you want different attack and release times for the left and right channels, list them sequentially separated by spaces:

ffmpeg -i input.wav -filter:a "compand=0.1 0.5 0.2 0.8:-80,-80,-20,-20,0,-10" output.wav

In this configuration:

  • Channel 1 (Left): 0.1s attack, 0.5s release.
  • Channel 2 (Right): 0.2s attack, 0.8s release.

Adding Delay to Prevent Clipping

Because the compressor takes time to react (defined by the attack time), sudden transients can slip through before the compressor can reduce the volume. To prevent this, use the delay parameter at the end of the filter. Set the delay value to match your attack time:

ffmpeg -i input.wav -filter:a "compand=0.3 0.8:-80,-80,-20,-20,0,-10:6:0:-90:0.3" output.wav

Here, the final 0.3 tells FFmpeg to delay the audio by 0.3 seconds, giving the filter enough "look-ahead" time to analyze the upcoming audio peaks and apply the 0.3-second attack phase perfectly.