How to Denoise Video with FFmpeg nlmeans Filter

This guide explains how to use the Non-Local Means (nlmeans) filter in FFmpeg to effectively remove noise and grain from your videos. You will learn the basic command structure, the key parameters that control denoising strength, and practical examples to help you achieve clean, high-quality video output.

Understanding the nlmeans Filter

The nlmeans filter is one of the most powerful denoising algorithms available in FFmpeg. Unlike simple pixel-averaging filters, Non-Local Means looks for similar patches of pixels across the entire frame to average out noise. While this results in excellent detail preservation, it is computationally expensive and slow to process.

Basic Syntax and Parameters

To use the filter, you apply it via the -vf (video filter) flag. The basic syntax is:

ffmpeg -i input.mp4 -vf nlmeans=s=1.0:p=7:r=15 output.mp4

Here are the primary parameters you can adjust to fine-tune the denoising process:

  • s (strength): Controls the denoising strength. Higher values remove more noise but can make the image look blurry or plasticky. The default is 1.0. For light noise, try 1.0 to 1.5. For heavy noise, you can go up to 3.0 or higher.
  • p (patch size): The size of the template patch used for comparison. Must be an odd number. The default is 7 (which represents a 7x7 pixel patch). Larger patch sizes preserve more structure but slow down rendering.
  • pc (patch size for chroma): The patch size for color (chroma) planes. If not set, it defaults to the value of p.
  • r (research size): The size of the window search area. Must be an odd number. The default is 15 (a 15x15 pixel window). Larger values yield better quality by finding similar patches further away, but heavily increase processing time.
  • rc (research size for chroma): The research window size for color planes. If not set, it defaults to the value of r.

Practical Examples

1. Light Denoising (Fastest Processing)

For videos with minimal noise where you want to preserve maximum detail and speed up rendering, use lower strength and smaller search windows.

ffmpeg -i input.mp4 -vf nlmeans=s=1.0:p=5:r=9 output.mp4

2. Moderate Denoising (Balanced/Default)

This is the recommended starting point for standard noisy footage. It offers a good balance between noise reduction and detail preservation.

ffmpeg -i input.mp4 -vf nlmeans=s=1.5:p=7:r=15 output.mp4

3. Heavy Denoising (High Quality, Very Slow)

Use this option for extremely grainy or low-light footage. Note that this command will take significantly longer to render.

ffmpeg -i input.mp4 -vf nlmeans=s=3.0:p=9:r=21 output.mp4

Performance Tips

Because nlmeans is highly CPU-intensive, you can combine it with hardware acceleration or multi-threading options. Ensure your FFmpeg build is compiled with threading support to allow nlmeans to utilize all available CPU cores automatically. If your encoding speed is too slow, consider reducing the search window (r) to 11 or 9.