How to Use fftfilt Filter in FFmpeg

The fftfilt filter in FFmpeg is a powerful video filter that processes video frames in the frequency domain using the 2D Fast Fourier Transform (FFT). This article provides a clear, practical guide on how to use fftfilt to apply custom frequency-domain effects, such as blurring, sharpening, and noise reduction, by explaining its key parameters and providing copy-pasteable command examples.

Understanding fftfilt Parameters and Variables

The fftfilt filter works by transforming a video frame from the spatial domain (pixels) into the frequency domain (frequencies), applying a mathematical expression to modify those frequencies, and then transforming the frame back.

To control how frequencies are modified, you can use the following primary parameters:

Within these expressions, you can use several built-in variables: * X and Y: The horizontal and vertical coordinates of the current frequency coefficient. * W and H: The width and height of the frequency plane. * val: The original value of the frequency coefficient at the current coordinates.


Practical Examples of fftfilt

Because the lowest frequencies are located near the origin (0,0) of the frequency domain, you can use the distance formula hypot(X,Y) to target specific frequency ranges.

1. Low-Pass Filter (Blurring/Smoothing)

A low-pass filter allows low frequencies to pass through while blocking high frequencies (which contain sharp details and noise). This results in a blurred image.

To keep only the frequencies within a distance of 30 from the origin:

ffmpeg -i input.mp4 -vf "fftfilt=weight_func='if(lt(hypot(X,Y),30),val,0)'" output.mp4

2. High-Pass Filter (Edge Detection/Sharpening)

A high-pass filter blocks low frequencies (flat areas) and allows high frequencies (edges and fine details) to pass. This is useful for edge detection or sharpening.

To block low frequencies within a radius of 20 and keep everything else:

ffmpeg -i input.mp4 -vf "fftfilt=dc_func='128':weight_func='if(gt(hypot(X,Y),20),val,0)'" output.mp4

3. Plane-Specific Filtering

By default, the filter applies the same expressions to all color planes (Luma and Chroma). You can target specific planes using plane-specific parameters like weight_func_u and weight_func_v for chroma channels.

To blur only the color (chrominance) channels while keeping the brightness (luminance) channel sharp:

ffmpeg -i input.mp4 -vf "fftfilt=weight_func_u='if(lt(hypot(X,Y),15),val,0)':weight_func_v='if(lt(hypot(X,Y),15),val,0)'" output.mp4