Configure FFmpeg Bandreject Filter Frequency and Bandwidth
The FFmpeg bandreject filter is a powerful audio tool
used to remove a specific band of frequencies from an audio stream while
letting all other frequencies pass through unaffected. This article
provides a straightforward guide on how to configure the filter’s two
primary parameters—the center frequency and the bandwidth—to target and
eliminate unwanted hums, buzzes, or specific noises from your audio
files.
The Bandreject Filter Syntax
The basic syntax for the bandreject filter in an FFmpeg
command is:
ffmpeg -i input.mp3 -af "bandreject=f=FREQUENCY:w=WIDTH:t=TYPE" output.mp3You can also use the shorthand notation by passing the values in order:
ffmpeg -i input.mp3 -af "bandreject=FREQUENCY:WIDTH:TYPE" output.mp3Parameter Breakdown
To configure the filter accurately, you need to understand the three key parameters:
- Center Frequency (
forfrequency): This defines the exact center of the frequency band you want to filter out. It is specified in Hz (Hertz). The default value is 3000 Hz. - Width (
worwidth): This defines how wide the filter’s gap is around the center frequency. The default value is 200. - Width Type (
torwidth_type): This determines how FFmpeg interprets thewidthvalue. The options include:h(Hz): Bandwidth expressed directly in Hertz (default).q(Q-factor): Represents the Quality factor. A higher Q-factor results in a narrower, sharper filter.o(octave): Bandwidth expressed in octaves.s(slope): Bandwidth expressed in slope.k(kHz): Bandwidth expressed in kilohertz.
Practical Examples
Example 1: Removing a Specific 50 Hz Hum (using Hz)
To remove an electrical mains hum at 50 Hz with a narrow bandwidth of
5 Hz, configure the filter with f=50, w=5, and
t=h:
ffmpeg -i input.wav -af "bandreject=f=50:w=5:t=h" output.wavExample 2: Using Shorthand Syntax
If you omit the parameter names, FFmpeg will apply the values in the
order of frequency, width, and
width_type. The following command rejects a 1000 Hz band
with a width of 100 Hz:
ffmpeg -i input.wav -af "bandreject=1000:100:h" output.wavExample 3: Configuring Width with Q-factor
If you prefer to use Q-factor for a more precise, steep cut, change
the width_type to q. A Q-factor of 10 at a
center frequency of 1000 Hz will result in a bandwidth of 100 Hz (Center
Frequency / Q-factor = Bandwidth):
ffmpeg -i input.wav -af "bandreject=f=1000:w=10:t=q" output.wav