A noise gate is the audio equivalent of a mute button that engages when the level drops below a threshold. It silences background noise between spoken phrases, removes room tone from a quiet section, and cleans up the gaps in a music track. The `agate` filter in libavfilter is a one-line gate with attack, hold, and release controls.

The command

ffmpeg -i in.wav -af "agate=threshold=-50dB:ratio=9:attack=20:release=1000" out.wav

What it does

The filter watches the audio level, and when it falls below the threshold, it reduces the gain by the ratio. A threshold of -50 dB with a ratio of 9:1 means a signal at -60 dB (10 dB below the threshold) is reduced to -110 dB (effectively silence). The attack and release control how fast the gate engages and disengages, in milliseconds. The output is a file with the quiet sections muted.

Requirements

Any audio input. The filter is in libavfilter. CPU-only, single-pass. The default values are reasonable for spoken voice; for music, raise the attack to 50 ms to preserve the natural decay of each note.

Things to avoid

  • Setting the threshold too high. A threshold of -20 dB will cut the quiet consonants of speech (t, s, f), making the voice sound chopped.
  • Using a very fast release. The gate will engage and disengage rapidly, producing a 'pumping' artifact. Raise the release to 200-500 ms for a smoother transition.
  • Gating a music track with a soft dynamic range. The gate will cut the reverb tail and the room tone, making the music sound unnatural.
  • Replacing a noise gate with a compressor. A compressor smooths the level; a gate mutes the level. They are different tools for different jobs.