How to Use the FFmpeg Bandreject Filter
This article explains how to use the bandreject audio
filter in FFmpeg to remove a specific range of frequencies from an audio
file. You will learn the basic syntax of the filter, understand its key
parameters like center frequency and bandwidth, and see practical
command-line examples to help you clean up your audio tracks.
Understanding the Bandreject Filter
The bandreject filter (also known as a band-stop or
notch filter) attenuates a specific band of frequencies around a chosen
center frequency. Frequencies outside of this specified band are allowed
to pass through relatively unaffected. This is highly useful for
removing unwanted constant background noises, such as a 60 Hz electrical
hum or a high-pitched whistle.
Basic Syntax
The basic syntax for applying the bandreject filter in
FFmpeg is:
ffmpeg -i input.mp3 -af "bandreject=f=FREQUENCY:w=WIDTH" output.mp3Key Parameters
The bandreject filter accepts several parameters to
customize how the audio is processed:
frequency/f: Sets the center frequency of the band to be filtered in Hz. The default value is3000.width_type/t: Defines how the width of the filter band is specified. The options include:h: Hertz (default)q: Q-factoro: Octavess: Slope
width/w: Sets the band width according to the chosenwidth_type. The default value is500Hz.mix/m: Sets the mix ratio between the filtered and unfiltered sound. A value of1means fully filtered (default), while0means bypassed.
Practical Examples
Example 1: Removing a 60 Hz Hum
Ground loop issues often cause a low-frequency hum at 60 Hz (or 50 Hz depending on your region). To remove a 60 Hz hum with a narrow band of 10 Hz, use the following command:
ffmpeg -i input.wav -af "bandreject=f=60:w=10" output.wavExample 2: Using Q-Factor for Precision
If you prefer to define the filter’s sharpness using a Q-factor
instead of raw Hertz, change the width_type
(t) to q. A higher Q-factor results in a
narrower, more precise notch.
ffmpeg -i input.mp3 -af "bandreject=f=1000:t=q:w=2.0" output.mp3In this command, the filter targets 1000 Hz with a
Q-factor of 2.0.
Example 3: Applying Multiple Filters
If your audio contains multiple unwanted frequencies, you can chain
multiple bandreject filters together, separated by
commas.
ffmpeg -i input.wav -af "bandreject=f=120:w=15,bandreject=f=1000:w=100" output.wavThis command simultaneously targets a hum at 120 Hz and a broader range of noise around 1000 Hz.