How to Use the DCT Filter in FFmpeg

The FFmpeg dctdnoiz (Discrete Cosine Transform Demoiser) filter is an effective tool for reducing noise in video streams by processing frames in the frequency domain. This article explains how the DCT filter works, details its primary parameters, and provides practical command-line examples to help you clean up noisy video footage.

What is the FFmpeg DCT Filter?

In FFmpeg, the DCT filter is implemented as dctdnoiz. It works by dividing video frames into small blocks, performing a 2D Discrete Cosine Transform on each block, filtering out low-amplitude high-frequency coefficients (which usually represent noise), and then performing an inverse transform to reconstruct the image. This method is highly effective at removing high-frequency Gaussian noise while preserving sharp edges.

Key Parameters of dctdnoiz

To customize the filter, you can adjust several parameters using the key-value syntax dctdnoiz=parameter1=value1:parameter2=value2.

Practical Examples

1. Basic Denoising

To apply the filter with default settings (which uses a sigma of 16 and 8x8 blocks), use the following command:

ffmpeg -i input.mp4 -vf dctdnoiz output.mp4

2. Adjusting Denoising Strength

If the default setting is too aggressive and blurs details, lower the sigma value. For mild denoising, try a value between 4.0 and 8.0:

ffmpeg -i input.mp4 -vf dctdnoiz=sigma=4.5 output.mp4

For heavy noise, increase the sigma value:

ffmpeg -i input.mp4 -vf dctdnoiz=sigma=25.0 output.mp4

3. Using Larger Block Sizes

For larger resolutions like 1080p or 4K, using \(16\times16\) blocks (n=4) can produce better results than the default \(8\times8\) blocks:

ffmpeg -i input.mp4 -vf dctdnoiz=sigma=10.0:n=4 output.mp4

4. Fast Processing with Less Overlap

If the encoding process is too slow, you can reduce the overlap parameter. This speeds up rendering at the cost of potential visual artifacts:

ffmpeg -i input.mp4 -vf dctdnoiz=sigma=8.0:overlap=4 output.mp4