How to Use FFmpeg DCT Filter for Denoising

This article explains how to use the FFmpeg dct video filter to reduce noise in video files using 2D discrete cosine transform block denoising. You will learn the core parameters of the filter, including threshold levels and block sizes, along with practical command-line examples to help you achieve clean, denoised video output.

Understanding the DCT Denoising Filter

The dct filter in FFmpeg works by dividing each video frame into small pixel blocks, converting them into the frequency domain using a 2D Discrete Cosine Transform, and then zeroing out high-frequency coefficients that fall below a specified threshold. Because noise typically manifests as low-amplitude high-frequency data, filtering out these weak coefficients effectively reduces noise before the blocks are transformed back into the spatial domain.

Filter Parameters

The dct filter accepts two primary parameters:

  • threshold (or t): This specifies the denoising threshold. A higher threshold removes more noise but can introduce compression-like artifacts (such as mosquito noise or ringing) and blur fine details. The default value is 0 (no denoising). Common values range between 1 and 15 depending on the severity of the noise.
  • n: This sets the block size exponent. The actual size of the processing block is \(2^n \times 2^n\) pixels. The allowed value for \(n\) is typically 3 (for \(8 \times 8\) blocks) or 4 (for \(16 \times 16\) blocks). The default is 3.

Practical FFmpeg Examples

To apply basic denoising with the default \(8 \times 8\) block size and a moderate threshold of 5.0, use the following command:

ffmpeg -i input.mp4 -vf "dct=threshold=5.0" output.mp4

If you want to use larger \(16 \times 16\) blocks for a smoother look on higher-resolution videos, set the n parameter to 4:

ffmpeg -i input.mp4 -vf "dct=threshold=8.0:n=4" output.mp4

Tips for Best Results

  • Start Small: Begin with a low threshold (e.g., 2.0 or 3.0) and gradually increase it until you find the right balance between noise reduction and detail preservation.
  • Combine with Scaling: 2D DCT denoising is computationally intensive. If you are processing high-resolution video, it is often more efficient to denoise at a lower resolution or apply the filter before resource-heavy encoding steps.