How to Use the FFmpeg sidechaingate Filter
This article provides a practical guide on how to use the
sidechaingate filter in FFmpeg to control one audio signal
using the level of another. You will learn the basic syntax, the key
parameters that control the gating effect, and a practical command-line
example to help you implement sidechain gating in your audio processing
workflows.
What is Sidechain Gating?
A sidechain gate is an audio dynamics processor that acts as a gate on a primary audio channel, but determines whether to open or close that gate based on the volume level of a secondary “sidechain” audio channel. When the volume of the sidechain signal rises above a specified threshold, the gate opens, allowing the primary audio signal to pass through. When the sidechain signal falls below the threshold, the gate closes, silencing or reducing the volume of the primary audio.
Key Parameters of the sidechaingate Filter
The sidechaingate filter accepts several parameters to
fine-tune the gating behavior. Here are the most commonly used
options:
- threshold: The level (from 0 to 1, or in decibels) that the sidechain signal must exceed to open the gate. The default is 0.1.
- attack: The amount of time, in milliseconds, it takes for the gate to fully open once the sidechain signal exceeds the threshold. Default is 20 ms.
- release: The amount of time, in milliseconds, it takes for the gate to fully close once the sidechain signal drops below the threshold. Default is 250 ms.
- range: The amount of attenuation applied to the primary signal when the gate is closed. Default is 0.01 (significant reduction).
- ratio: The reduction ratio of the gate. Default is 2.0.
- detection: Specifies how the signal level is
detected:
peak(default) orrms(root mean square).
Practical Command Example
To use the sidechaingate filter, you must pass two audio
streams into the filter using FFmpeg’s filter_complex. The
first input is the primary audio you want to gate, and the second input
is the sidechain trigger.
Here is a standard command template:
ffmpeg -i primary_audio.wav -i trigger_audio.wav -filter_complex "[0:a][1:a]sidechaingate=threshold=0.05:attack=10:release=150[outa]" -map "[outa]" output.wavHow the Command Works
-i primary_audio.wav -i trigger_audio.wav: This inputs both audio files. The primary track (index0) is the one that will be muted or unmuted, while the trigger track (index1) acts as the control key.[0:a][1:a]: This feeds the audio from the first input and the audio from the second input into the filter.sidechaingate=threshold=0.05:attack=10:release=150: This applies the filter. The gate will open quickly (10 milliseconds) whenever the trigger audio rises above the 0.05 threshold, and it will close smoothly over 150 milliseconds when the trigger audio goes quiet.[outa]: This labels the resulting processed audio stream.-map "[outa]": This tells FFmpeg to write the processed audio stream to the final output file,output.wav.