How to Use FFmpeg DCT Filter for Spatial Denoising
This article provides a straightforward guide on how to use the
Discrete Cosine Transform (dct) filter in FFmpeg for
spatial block denoising. You will learn the basic syntax of the filter,
understand its key parameters—such as threshold and block size—and see
practical command-line examples to help you effectively clean up noisy
video footage.
The dct filter in FFmpeg denoises video frames in the
frequency domain by applying a 2D Discrete Cosine Transform to local
blocks, zeroing out high-frequency coefficients that fall below a
certain threshold, and then performing the Inverse Discrete Cosine
Transform (IDCT). This method is highly effective at reducing
high-frequency noise while preserving edge details.
Basic Syntax and Parameters
To use the filter, apply -vf dct in your FFmpeg command.
The filter relies on two primary parameters to control the denoising
intensity and block evaluation:
threshold: This float value sets the denoising threshold. A higher threshold removes more noise but can introduce artifacts or blur the image. A value of0(the default) disables denoising. Typical effective values range from1.0to15.0depending on the noise level.n: This integer defines the block size as \(2^n \times 2^n\). The default is3, which corresponds to \(8 \times 8\) pixel blocks (\(2^3 = 8\)). Setting it to4uses \(16 \times 16\) pixel blocks, which can be useful for larger noise structures but requires more processing power.
Practical Examples
1. Basic Denoising To apply moderate denoising to a
video using the default \(8 \times 8\)
block size, use a threshold value like 5:
ffmpeg -i input.mp4 -vf "dct=threshold=5" output.mp42. Strong Denoising with Larger Blocks For heavily
degraded video, you can increase the threshold to 10 and
increase the block size to \(16 \times
16\) (n=4) to target larger noise patterns:
ffmpeg -i input.mp4 -vf "dct=threshold=10:n=4" output.mp4Tips for Best Results
- Start Low: Begin with a low threshold (e.g.,
2or3) and gradually increase it until the noise is visually reduced without losing important details. - Combine Filters: The
dctfilter is a spatial denoiser. For optimal results on highly compressed or extremely noisy video, you can combine it with a temporal denoiser likehqdn3dby chaining them together:-vf "hqdn3d,dct=threshold=4".