FFmpeg Sidechaincompress: Duck Music for Voiceover

Audio ducking is a technique where the volume of a background music track is automatically lowered whenever a voiceover track plays, ensuring the speech remains clear and intelligible. This article explains how to use the FFmpeg sidechaincompress audio filter to achieve professional automatic audio ducking, detailing the exact command-line syntax and parameter settings needed to balance your audio tracks.

The Ducking Command

To perform sidechain compression, you need to feed two audio inputs into FFmpeg: your voiceover track and your background music track. The sidechaincompress filter accepts two inputs; the first input is the signal to be compressed (the music), and the second input is the control signal that triggers the compression (the voiceover).

Here is the standard FFmpeg command to duck background music under a voiceover and mix them into a final output:

ffmpeg -i voiceover.wav -i music.mp3 -filter_complex "[1:a][0:a]sidechaincompress=threshold=0.1:ratio=20:attack=15:release=300[ducked];[0:a][ducked]amix=inputs=2:duration=first[aout]" -map "[aout]" output.mp3

How the Filtergraph Works

The -filter_complex flag handles the routing and processing of the audio streams:

  1. [1:a][0:a]: This feeds the music track ([1:a], representing input 1) and the voiceover track ([0:a], representing input 0) into the sidechaincompress filter.
  2. sidechaincompress=...[ducked]: The filter compresses the music stream using the voiceover stream as the trigger. The resulting ducked music is labeled as [ducked].
  3. [0:a][ducked]amix=inputs=2:duration=first[aout]: The amix filter combines the original clean voiceover [0:a] with the newly ducked music [ducked]. Setting duration=first ensures the output file ends as soon as the voiceover track finishes.

Fine-Tuning the Parameters

You can adjust the parameters of the sidechaincompress filter to match the dynamics of your specific audio tracks: