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.mp3How the Filtergraph Works
The -filter_complex flag handles the routing and
processing of the audio streams:
[1:a][0:a]: This feeds the music track ([1:a], representing input 1) and the voiceover track ([0:a], representing input 0) into thesidechaincompressfilter.sidechaincompress=...[ducked]: The filter compresses the music stream using the voiceover stream as the trigger. The resulting ducked music is labeled as[ducked].[0:a][ducked]amix=inputs=2:duration=first[aout]: Theamixfilter combines the original clean voiceover[0:a]with the newly ducked music[ducked]. Settingduration=firstensures 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:
threshold(default:0.125): The volume level of the voiceover (ranging from0.0to1.0) that triggers the compression. If your voiceover is quiet, lower this threshold (e.g.,0.05) so the compressor detects it. If background noise in your voiceover is accidentally triggering the ducking, raise this value.ratio(default:4): The amount of volume reduction applied to the music. A higher ratio (e.g.,20or30) results in a more dramatic drop in music volume when the voiceover speaks.attack(default:20milliseconds): How quickly the music volume drops once the voiceover starts. A fast attack of10to20ms prevents the first syllables of your voiceover from being drowned out by the music.release(default:250milliseconds): How quickly the music volume returns to its original level after the voiceover stops. A value between250and400ms creates a smooth, natural-sounding swell back to full volume without sounding abrupt.