Configure FFmpeg Sidechaincompress Filter Settings

Sidechain compression is a crucial audio engineering technique used to automatically lower the volume of one audio track (the main program or carrier) whenever another audio track (the trigger or sidechain signal) plays. This is commonly used in broadcasting and video production to "duck" background music under a voiceover. This article provides a direct, practical guide on how to configure the key parameters—threshold, ratio, attack, and release—within the FFmpeg sidechaincompress filter to achieve a clean and professional audio mix.

Understanding the Core Parameters

The FFmpeg sidechaincompress filter requires specific parameters to control how and when the audio volume is reduced.

  • threshold (or t): This sets the volume level of the secondary (trigger) input that will trigger the compressor. If the trigger signal goes above this limit, the main audio will be compressed. The value is a linear amplitude between 0.000976563 and 1.0 (default is 0.125). You can also specify this value in decibels (e.g., -20dB).
  • ratio (or r): This determines the amount of gain reduction applied to the main audio once the trigger signal crosses the threshold. For example, a ratio of 4 (4:1) means that for every 4 dB the trigger goes over the threshold, the output level will only increase by 1 dB. The range is 1.0 to 20.0 (default is 2.0).
  • attack (or a): This defines how quickly the compressor reduces the volume once the trigger signal exceeds the threshold. It is measured in milliseconds, ranging from 0.01 to 2000.0 (default is 20.0 ms). A shorter attack time ducks the music instantly.
  • release (or k): This determines how long the compressor takes to return the main audio to its original volume level after the trigger signal falls below the threshold. It is measured in milliseconds, ranging from 0.01 to 9000.0 (default is 250.0 ms).

Basic Command Syntax

The sidechaincompress filter accepts two audio inputs: the first input is the audio to be compressed (e.g., background music), and the second input is the control signal (e.g., voiceover).

Here is a standard command template configuring these four parameters:

ffmpeg -i music.mp3 -i voiceover.mp3 -filter_complex "[0:a][1:a]sidechaincompress=threshold=0.1:ratio=4:attack=15:release=300[outa]" -map "[outa]" -map 1:a -c:a libmp3lame output.mp3

Parameter Breakdown of the Command:

  • [0:a][1:a]: Takes the first input (music.mp3) as the main audio and the second input (voiceover.mp3) as the triggering sidechain source.
  • threshold=0.1: The compression activates when the voiceover signal level rises above 0.1 linear amplitude (approximately -20dB).
  • ratio=4: Applies a 4:1 compression ratio, noticeably ducking the background music.
  • attack=15: The music volume decreases quickly (within 15 milliseconds) when speaking begins.
  • release=300: The music volume smoothly fades back up over 300 milliseconds after speaking stops.

For standard video voiceovers and podcasts, you want the music to lower quickly but return smoothly to avoid a "pumping" effect. Use the following baseline settings:

  • Threshold: -18dB (or 0.125)
  • Ratio: 4 or 5
  • Attack: 10 to 20 ms (keeps the voice from being cut off at the start of words)
  • Release: 250 to 400 ms (creates a natural-sounding fade-in for the music when speaking pauses)