Configure FFmpeg nlmeans Patch, Research, and Luma
The nlmeans (Non-Local Means) filter in FFmpeg is a
highly effective tool for removing noise from video, but it requires
careful tuning to balance denoising quality and processing speed. This
article explains how to configure the three core parameters of the
nlmeans filter: luma strength, patch size, and research
size, complete with practical command-line examples.
Understanding the Key Parameters
To configure the nlmeans filter, you need to understand
how its three primary parameters interact:
- Luma Strength (
s): This controls the overall denoising intensity for the luma (brightness) channel.- Default:
1.0 - Usage: Higher values remove more noise but can cause the video to look blurry or lose fine details. Lower values preserve detail but leave more noise behind.
- Default:
- Patch Size (
p): This defines the size of the pixel block (the “patch”) used to compare similarities between different parts of the frame.- Default:
7(representing a 7x7 pixel grid) - Usage: Must be an odd integer (e.g., 3, 5, 7, 9).
Smaller patches (like
3or5) speed up processing but may fail to identify patterns in heavy noise. Larger patches (like9or11) improve accuracy at the cost of significantly higher CPU usage.
- Default:
- Research Size (
r): This defines the search window (the neighborhood) where the filter looks for similar patches.- Default:
15(representing a 15x15 pixel grid) - Usage: Must be an odd integer. A larger research
size (such as
21or25) improves denoising quality by finding more matching pixels across a wider area, but it dramatically increases encoding time.
- Default:
Command Syntax
The basic syntax for applying these parameters in FFmpeg is:
ffmpeg -i input.mp4 -vf "nlmeans=s=STRENGTH:p=PATCH_SIZE:r=RESEARCH_SIZE" output.mp4Practical Examples
1. Moderate Denoising (Balanced/Default Profile)
This configuration uses default settings, which work well for general noise reduction without grinding your system to a halt.
ffmpeg -i input.mp4 -vf "nlmeans=s=1.0:p=7:r=15" -c:v libx264 -crf 18 output.mp42. Fast Denoising (Low CPU Usage)
If you need faster processing speeds, reduce both the patch size and research size. This is ideal for lighter noise or lower-end hardware.
ffmpeg -i input.mp4 -vf "nlmeans=s=0.8:p=5:r=9" -c:v libx264 -crf 18 output.mp43. Heavy Denoising (High Quality / CPU Intensive)
For highly grainy or noisy footage, increase the luma strength and expand the research area. This configuration requires significant processing power.
ffmpeg -i input.mp4 -vf "nlmeans=s=2.0:p=7:r=21" -c:v libx264 -crf 18 output.mp4