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.mp4

Here are the most critical parameters you can adjust:

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.mp4

2. 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.mp4

3. 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.mp4

Performance 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.