Sidechain Gating Drums with FFmpeg Sidechaingate
This guide explains how to use FFmpeg's sidechaingate
audio filter to dynamically control a drum track using an external
instrument as a trigger. You will learn the exact command syntax, how
audio stream routing works in FFmpeg’s filtergraph, and how to adjust
essential gate parameters like threshold, attack, and release to achieve
a clean mix.
Understanding the Filter Mechanics
The sidechaingate filter requires two input audio
streams:
- Primary Input: The audio signal you want to gate (the drum track).
- Sidechain Input: The control signal that dictates when the gate opens and closes (the triggering instrument, such as a bass guitar or synth).
When the signal level of the sidechain input crosses a defined threshold, the gate opens, allowing the drum track to be heard. When the sidechain drops below the threshold, the drums are attenuated.
Basic Command Syntax
To gate a drum track (drums.wav) using another
instrument track (bass.wav), use the following command
structure:
ffmpeg -i drums.wav -i bass.wav -filter_complex "[0:a][1:a]sidechaingate=threshold=0.1:attack=20:release=250:ratio=2[outa]" -map "[outa]" output_drums.wavParameter Breakdown
[0:a][1:a]: Feeds the first input (drums.wav) as the target and the second input (bass.wav) as the sidechain detection signal.threshold: Sets the volume level of the control signal required to open the gate. The value ranges from0to1(linear amplitude, default is0.125). If your trigger track is quiet, lower this value.attack: The amount of time in milliseconds it takes for the gate to fully open once the threshold is reached (default is20). For percussive elements, lower values (e.g.,5to10) prevent cutting off the initial transients.release: The amount of time in milliseconds the gate remains open after the control signal drops below the threshold (default is250). Shorter release times create abrupt, rhythmic gating; longer release times sound more natural.ratio: Determines the gating attenuation factor (default is2). A higher ratio increases the aggressive drop in volume when the gate closes.range: Controls the maximum attenuation in decibels or linear amplitude. By default, it softens the background sound rather than muting it completely. Setrange=0to silence the drums completely when closed.
Advanced Practical Example
To completely silence a drum track whenever a rhythm guitar is not playing, with fast response to preserve snare and kick hits, configure the filter like this:
ffmpeg -i drums.wav -i guitar.wav -filter_complex "[0:a][1:a]sidechaingate=threshold=0.05:attack=5:release=100:range=0:detection=peak[outa]" -map "[outa]" gated_drums.wavdetection=peak: Uses instantaneous peak detection instead of RMS (root mean square) averaging, making the gate react immediately to sharp transients.range=0: Ensures total silence between the triggering guitar notes.