How to Use FFmpeg firequalizer for Custom EQ Curves
The firequalizer filter in FFmpeg is a powerful tool for
applying arbitrary audio equalization (EQ) curves using finite impulse
response (FIR) filtering. This article provides a straightforward guide
on how to configure and use firequalizer to shape your
audio, covering the filter’s syntax, key parameters, and practical
examples for defining custom frequency responses.
The firequalizer filter works in the frequency domain,
allowing you to define precise gain values for specific frequencies. The
filter then interpolates between these points to create a smooth,
continuous equalization curve.
The Basic Syntax
The most common way to define an arbitrary EQ curve is by using the
gain_entry parameter. This parameter allows you to specify
individual coordinate points of frequency (in Hz) and gain (in dB).
The basic structure of the filter within an FFmpeg command looks like this:
ffmpeg -i input.mp3 -af "firequalizer=gain_entry='entry(f1, g1); entry(f2, g2); entry(f3, g3)'" output.mp3f: The frequency in Hertz.g: The gain in decibels (dB) to apply at that frequency.
Creating an Arbitrary EQ Curve
To construct a custom EQ curve, you define a list of
entry(f, g) points. FFmpeg will automatically perform
linear interpolation to connect the points.
For example, to create a curve that: 1. Cuts subsonic frequencies below 40 Hz (high-pass effect). 2. Keeps mid-range frequencies flat (0 dB). 3. Boosts presence at 4,000 Hz by 6 dB. 4. Rolls off high frequencies above 15,000 Hz.
You would map the following coordinates: * entry(0, -20)
(Cut lowest frequencies) * entry(40, 0) (Start flat
response) * entry(1000, 0) (Flat mid-range) *
entry(4000, 6) (Boost presence) *
entry(15000, 0) (Return to flat) *
entry(20000, -15) (Roll off highs)
The FFmpeg command for this custom curve is:
ffmpeg -i input.wav -af "firequalizer=gain_entry='entry(0,-20); entry(40,0); entry(1000,0); entry(4000,6); entry(15000,0); entry(20000,-15)'" output.wavUsing
Mathematical Formulas with the gain Parameter
Alternatively, if your EQ curve can be defined mathematically, you
can use the gain parameter instead of
gain_entry. The gain parameter evaluates a
formula for every frequency f.
For example, to create a low-pass filter that completely cuts off all
frequencies above 1,000 Hz, you can use an if
statement:
ffmpeg -i input.wav -af "firequalizer=gain='if(gte(f,1000), -inf, 0)'" output.wavYou can also use mathematical functions such as log(f)
or custom expressions to define smooth, continuous curves without manual
coordinate mapping.
Important Considerations
Preventing Clipping: If your custom EQ curve boosts certain frequencies (positive dB values), it can cause digital clipping. To prevent this, apply a negative preamp gain using the
volumefilter before the equalizer:ffmpeg -i input.wav -af "volume=-6dB,firequalizer=gain_entry='entry(1000,6)'" output.wavAccuracy: The accuracy of the curve depends on the FFT (Fast Fourier Transform) size. If your low-frequency adjustments are not precise enough, you can increase the accuracy by adjusting the
delayparameter (default is 0.05 seconds):ffmpeg -i input.wav -af "firequalizer=delay=0.1:gain_entry='entry(0,-20); entry(50,0)'" output.wav