FFmpeg BM3D Filter Tutorial for Video Denoising
This article provides a comprehensive guide on how to use the BM3D (Block-Matching and 3D filtering) denoiser in FFmpeg. You will learn the basic command syntax, key parameters for fine-tuning noise reduction, and how to execute both single-pass and high-quality two-pass denoising to achieve professional-grade video clean-up.
Understanding the FFmpeg BM3D Filter
BM3D is a state-of-the-art image and video denoising algorithm. It works by grouping similar 2D image patches into 3D data arrays (block-matching) and collaborative filtering them in the transform domain.
Because of its mathematical complexity, the bm3d filter
in FFmpeg is highly effective at removing heavy noise while preserving
sharp edges, but it is computationally expensive and slow compared to
simpler filters like hqdn3d or nlmeans.
Basic Command Syntax
The simplest way to apply the BM3D filter is to run a single-pass
denoising command using the basic mode.
ffmpeg -i input.mp4 -vf "bm3d=sigma=20:mode=basic" output.mp4In this command: * sigma sets the denoising strength
(standard deviation of the noise). Higher values remove more noise but
can blur fine details. * mode=basic tells FFmpeg to perform
the initial thresholding pass.
Key Parameters of the BM3D Filter
You can customize the filter behavior using several parameters appended to the filter string, separated by colons:
- sigma: (Float, default = 1.0) The strength of the denoising. Typical values range from 5 (light noise) to 30+ (very heavy noise).
- block: (Integer, default = 8) Size of the blocks used for matching. Larger blocks preserve larger structures but increase processing time.
- bstep: (Integer, default = 4) Sliding step parameter for block-matching. Smaller values (like 1 or 2) yield better quality but severely slow down processing.
- group: (Integer, default = 16) Maximum number of similar blocks to group together in the 3D array.
- range: (Integer, default = 9) Search range size for finding similar blocks. Larger ranges catch more redundant patterns at the cost of speed.
- mode: (String, default =
basic) Choose betweenbasic(hard-thresholding) andfinal(Wiener filtering, which requires a reference stream).
Advanced Two-Pass Denoising (Highest Quality)
To get the absolute best results from BM3D, you should use the
two-pass approach. In the first pass, a “basic” estimate is created. In
the second pass, this estimate is used as a reference to perform
empirical Wiener filtering (mode=final).
You can achieve this in a single FFmpeg command using a complex filtergraph to split the input stream:
ffmpeg -i input.mp4 -filter_complex "[0:v]split[original][ref];[ref]bm3d=sigma=20:mode=basic[basic_estimate];[original][basic_estimate]bm3d=sigma=20:mode=final" output.mp4How the Filtergraph Works:
splitduplicates the input video into two identical streams:[original]and[ref].- The
[ref]stream is processed withbm3dinbasicmode to generate a preliminary clean stream named[basic_estimate]. - The
[original]stream and the[basic_estimate]stream are fed together into a secondbm3dfilter set tomode=final. This produces the final, highly-detailed denoised output.
Speed Optimization Tips
Because BM3D is CPU-intensive, you can use these adjustments to speed up rendering:
- Increase bstep: Set
bstep=8to speed up block matching, though this slightly reduces denoising quality. - Limit search range: Set
range=5orrange=7to restrict the area the filter searches for matching blocks. - Reduce block size: Use
block=4for faster processing on low-resolution videos.