How to Use the BM3D Filter in FFmpeg
This article provides a practical guide on how to use the Block-Matching and 3D filtering (BM3D) denoising filter in FFmpeg. You will learn the basic syntax of the filter, understand its key parameters for adjusting denoising strength, and see step-by-step command examples to improve your video quality by reducing noise and grain.
Understanding the BM3D Filter
The bm3d filter in FFmpeg is an advanced, highly
effective denoising algorithm. It works by grouping similar 2D image
patches into 3D data arrays (block-matching) and filtering them in the
transform domain. While it produces exceptionally clean results, it is
computationally intensive and will significantly slow down encoding
speeds.
Basic Syntax and Key Parameters
The basic structure for applying the filter in an FFmpeg command is:
ffmpeg -i input.mp4 -vf "bm3d=parameter1=value1:parameter2=value2" output.mp4Here are the most critical parameters you can adjust:
sigma: Sets the noise standard deviation (strength of the denoising). The default is1.0. Higher values remove more noise but can make the image look blurry. A value between10and30is typically used for moderately noisy video.block: The size of the blocks used for matching (default is8). Larger blocks can improve quality but increase processing time.bstep: The sliding step parameter between neighboring blocks (default is4). Smaller step sizes improve quality but slow down the filter.group: The maximum number of similar blocks to group together (default is1). Higher values yield better denoising results.range: The search range for finding similar blocks (default is9). Larger ranges allow the filter to find more matching blocks at the cost of processing speed.mode: Defines the filtering mode. Options areunprefiltered(single-pass basic filtering) orprefiltered(two-pass algorithm that uses a pre-filtered estimate for better accuracy).
Practical Command Examples
1. Basic Denoising
For a standard video with mild noise, use a moderate
sigma value. This command uses the default parameters with
a noise threshold of 15:
ffmpeg -i input.mp4 -vf "bm3d=sigma=15" output.mp42. High-Quality Denoising (Two-Pass)
To get the best possible quality, you can chain two instances of the
bm3d filter. The first pass acts as a pre-filter, and the
second pass performs the final estimate:
ffmpeg -i input.mp4 -vf "split[a][b];[a]bm3d=sigma=15:mode=unprefiltered[pre];[b][pre]bm3d=sigma=15:mode=prefiltered" output.mp43. Adjusting Block and Step Sizes
If you want to balance speed and quality, you can increase the block
step (bstep) to speed up the process, or decrease it for
better quality:
ffmpeg -i input.mp4 -vf "bm3d=sigma=20:block=8:bstep=2:range=12" output.mp4Performance Tip
Because BM3D is slow, it is highly recommended to test your settings
on a short segment of your video first. You can do this by adding
-t 10 to your command to process only the first 10 seconds
of the video.