How to Sidechain Gate Drums in FFmpeg
This article demonstrates how to use the FFmpeg
sidechaingate audio filter to gate a drum track using
another instrument as a trigger signal. You will learn the essential
parameters of the filter, the correct command-line syntax for handling
multiple audio inputs, and a practical step-by-step example to achieve a
clean sidechained gate effect.
Understanding Sidechain Gating
A noise gate typically attenuates an audio signal when it falls below a certain threshold. In sidechain gating, the gate on your primary audio track (the drums) is controlled by the volume level of a secondary, independent audio track (such as a bassline or synthesizer). When the secondary instrument plays above the set threshold, the gate opens, allowing the drums to be heard. When the secondary instrument is silent, the drums are silenced or heavily attenuated.
In FFmpeg, this is achieved using the sidechaingate
filter inside a filter_complex graph, which accepts two
audio inputs: the main input (to be gated) and the sidechain input (the
control signal).
Key Parameters of the sidechaingate Filter
To customize the gating effect, you can adjust several key parameters within the filter:
- threshold: The volume level of the sidechain signal (from 0.0 to 1.0) required to open the gate. Default is 0.1.
- range: The amount of gain reduction applied to the main signal when the gate is closed. Default is 0.06125 (lower values result in quieter gated sections).
- attack: The time in milliseconds it takes for the gate to fully open once the sidechain signal crosses the threshold. Default is 20 ms.
- release: The time in milliseconds it takes for the gate to close after the sidechain signal drops below the threshold. Default is 250 ms.
- ratio: The compression ratio applied to the signal when the gate is closed. Default is 2.0.
The FFmpeg Command Syntax
To gate a drum track using a bass track as the trigger, use the
following filter_complex structure:
ffmpeg -i drums.wav -i bass.wav -filter_complex "[0:a][1:a]sidechaingate=threshold=0.1:range=0.01:attack=10:release=150[out]" -map "[out]" output.wavCommand Breakdown:
-i drums.wav: Defines the main audio input (Input 0) that you want to gate.-i bass.wav: Defines the control audio input (Input 1) that will trigger the gate.-filter_complex: Initiates the filter graph for handling multiple inputs.[0:a][1:a]: Feeds the audio stream of the first file (drums) and the audio stream of the second file (bass) into the filter. The main input must always be placed first.sidechaingate=...: Applies the filter with custom settings. In this example, the gate opens when the bass volume hits0.1, opens quickly with a10msattack, and closes over150mswhen the bass stops, reducing the drum volume to a quiet0.01range factor.-map "[out]": Maps the processed output of the filter graph to the final export file.output.wav: The resulting gated drum audio file.