How to Use the Bilateral Filter in FFmpeg
This guide provides a straightforward explanation of how to use the
bilateral filter in FFmpeg. You will learn what the
bilateral filter does, understand its key parameters for edge-preserving
smoothing, and see practical command-line examples to help you
effectively denoise your videos without losing sharp details.
What is the Bilateral Filter?
The bilateral filter in FFmpeg is an edge-preserving,
noise-reducing smoothing filter. Unlike a standard Gaussian blur, which
blurs everything indiscriminately, the bilateral filter considers both
spatial distance and color intensity differences. This allows it to
smooth out flat areas to reduce noise while keeping the boundaries and
sharp edges between different objects intact.
Key Parameters
To control the bilateral filter, you use three primary parameters in your FFmpeg filtergraph:
sigmaS(Spatial Sigma): Controls the spatial neighborhood size of the filter. A larger value means pixels further away will influence the current pixel, resulting in a broader smoothing effect. The default value is 0.1.sigmaR(Range Sigma): Controls the color similarity threshold. A larger value allows pixels with greater color differences to be averaged together, which can lead to blurring across edges. Keep this value relatively low to preserve sharp edges. The default value is 0.1.planes(Planes to filter): Specifies which video channels to process. It is a bitmask value where1processes the luma (Y) channel,2and4process chroma (U and V) channels, and7processes all three (YUV). The default is 1 (luma only).
Practical Command Examples
Basic Edge-Preserving Denoising
To apply mild spatial smoothing on the luma channel to reduce high-frequency noise while preserving sharp boundaries, use the following command:
ffmpeg -i input.mp4 -vf "bilateral=sigmaS=5.0:sigmaR=0.1" output.mp4Heavy Smoothing
To increase the blurring effect while still attempting to maintain major edge boundaries, increase both the spatial and range sigma values:
ffmpeg -i input.mp4 -vf "bilateral=sigmaS=15.0:sigmaR=0.3" output.mp4Filtering All Color Channels (YUV)
By default, the filter only processes the luma (brightness) channel.
To apply the bilateral filter to both brightness and color channels, set
the planes parameter to 7:
ffmpeg -i input.mp4 -vf "bilateral=sigmaS=4.0:sigmaR=0.15:planes=7" output.mp4