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:

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.mp4

Heavy 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.mp4

Filtering 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