How to Use FFmpeg Compand as a Noise Gate
This article explains how to configure the FFmpeg
compand (compressor/expander) filter to function as a noise
gate. You will learn the exact command-line syntax and parameter
settings required to suppress unwanted background noise from your audio
files by silencing signals that fall below a defined volume
threshold.
Understanding the Compand Filter as a Noise Gate
A noise gate is an audio processor that allows signals above a
certain threshold to pass through, while attenuating (silencing) signals
below that threshold. While FFmpeg has a dedicated agate
filter, the compand filter offers highly customizable
downward expansion, making it an exceptionally flexible tool for gating
noise.
To act as a noise gate, compand must be configured to
heavily reduce the volume of quiet sounds (the noise floor) while
leaving louder sounds (like speech or music) untouched.
The FFmpeg Noise Gate Command
Here is the standard FFmpeg command to apply a noise gate using the
compand filter:
ffmpeg -i input.mp4 -af "compand=attacks=0.01:decays=0.2:points=-80/-900|-40/-900|-39/-39|0/0" output.mp4Parameter Breakdown
attacks=0.01: The attack time in seconds. This defines how quickly the gate opens when the audio goes above the threshold. A fast attack (10 milliseconds) ensures the start of words or sounds are not clipped.decays=0.2: The decay (release) time in seconds. This defines how fast the gate closes after the audio drops below the threshold. A decay of 200 milliseconds prevents the gate from cutting off natural audio tails too abruptly.points=-80/-900|-40/-900|-39/-39|0/0: This is the transfer function that defines the gate’s threshold. It maps input volume (first number) to output volume (second number) in decibels (dB).-80/-900: Input at -80dB is reduced to -900dB (complete silence).-40/-900: Input at -40dB (the noise threshold) is reduced to -900dB.-39/-39: Input at -39dB passes through at -39dB (the gate opens).0/0: Input at 0dB passes through at 0dB.
How to Fine-Tune the Gate
To adapt this filter to your specific audio file, you may need to adjust the threshold points:
- Identify the Noise Floor: Listen to a quiet section
of your audio to estimate the volume of the background noise. If the
noise is around -45dB, set your threshold point to
-45. - Adjust the Points String: If your noise floor is at
-45dB, modify the
pointsparameter to:points=-80/-900|-45/-900|-44/-44|0/0 - Smooth the Transition: If the gate sounds too harsh
or “choppy” when opening and closing, increase the decay time (e.g.,
decays=0.5) to allow for a smoother fade-out.