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.
sigma(ors): Sets the noise sigma (denoising strength). A higher value removes more noise but can make the video look blurry. The default value is16.0.n: Sets the block size exponent. The block size will be \(2^n \times 2^n\).3represents \(8\times8\) blocks (default).4represents \(16\times16\) blocks.5represents \(32\times32\) blocks.
overlap(oro): Controls block overlap. Higher overlap reduces blocking artifacts but increases processing time. The default is usually \(block\_size - 1\) for maximum overlap.expr(ore): Specifies the coefficient thresholding expression (e.g., hard or soft thresholding).
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.mp42. 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.mp4For heavy noise, increase the sigma value:
ffmpeg -i input.mp4 -vf dctdnoiz=sigma=25.0 output.mp43. 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.mp44. 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