FFmpeg Noise Gate: How to Silence Audio Below Threshold

This article provides a quick guide on how to use FFmpeg's agate (audio gate) filter to silence parts of an audio file that fall below a specific volume threshold. You will learn the basic command structure, the key parameters used to control the gate's behavior, and a practical example to clean up background noise from your recordings.

Understanding the FFmpeg agate Filter

An audio gate, or noise gate, allows signals above a certain threshold to pass through unaffected while attenuating (quieting) or completely silencing signals that fall below that threshold. This is highly effective for removing low-level background hiss, hum, or breathing sounds between spoken words.

In FFmpeg, this is achieved using the agate audio filter.

The Basic Command Syntax

To apply a noise gate in FFmpeg, use the -af (audio filter) flag followed by the agate filter and its parameters. Here is the standard command:

ffmpeg -i input.mp3 -af "agate=threshold=0.03:ratio=20:attack=20:release=250" output.mp3

Key Parameters Explained

To fine-tune the gate for your specific audio file, you can adjust the following parameters:

  • threshold: The volume level that triggers the gate. Any audio quieter than this value will be reduced. It is specified as a linear amplitude between 0.0 (complete silence) and 1.0 (maximum volume), or in decibels (e.g., 0.03 or -30dB).
  • ratio: The reduction ratio. This determines how aggressively the volume is cut once it falls below the threshold. A higher ratio (like 20 or 50) acts as a hard gate, virtually silencing the audio. A lower ratio (like 2 or 3) gently reduces the volume.
  • attack: The time (in milliseconds) it takes for the gate to fully open once the audio level goes above the threshold. Keep this low (e.g., 10 to 20 ms) to prevent cutting off the beginning of words.
  • release: The time (in milliseconds) it takes for the gate to close after the audio falls back below the threshold. A longer release (e.g., 200 to 400 ms) ensures a natural fade-out instead of an abrupt cut.
  • range: The maximum attenuation in dB. If you want to completely silence the audio, set this to a very low level (e.g., -90dB) or leave it at its default.

A Practical Example

If you have a voice recording with noticeable background noise during pauses, you can use the following command to apply a strict noise gate:

ffmpeg -i voice.wav -af "agate=threshold=-35dB:ratio=50:attack=10:release=300" cleaned_voice.wav

In this example:

  • Any sound quieter than -35dB will trigger the gate.
  • The volume of the quiet parts is reduced heavily due to the 50 ratio.
  • The gate opens quickly (10ms) when speaking starts and closes smoothly (300ms) during pauses to maintain a natural sound.