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:

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.wav

Command Breakdown:

  1. -i drums.wav: Defines the main audio input (Input 0) that you want to gate.
  2. -i bass.wav: Defines the control audio input (Input 1) that will trigger the gate.
  3. -filter_complex: Initiates the filter graph for handling multiple inputs.
  4. [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.
  5. sidechaingate=...: Applies the filter with custom settings. In this example, the gate opens when the bass volume hits 0.1, opens quickly with a 10ms attack, and closes over 150ms when the bass stops, reducing the drum volume to a quiet 0.01 range factor.
  6. -map "[out]": Maps the processed output of the filter graph to the final export file.
  7. output.wav: The resulting gated drum audio file.