How to Use FFmpeg removegrain Filter for Denoising
This guide explains how to use the removegrain filter in
FFmpeg to achieve high-efficiency spatial denoising and image smoothing.
You will learn how the filter works, how to configure its various mode
options, and see practical command-line examples to clean up noisy video
streams quickly without sacrificing system performance.
What is the removegrain Filter?
The removegrain filter is a highly optimized spatial
denoising filter in FFmpeg. Unlike temporal denoisers that analyze
multiple video frames over time, removegrain operates
entirely within each individual frame (spatially). It compares each
pixel with its surrounding eight neighbors to identify and eliminate
noise, compression artifacts, and rogue pixels. Because it relies on
fast, hardware-optimized assembly code, it is one of the fastest
denoising filters available in FFmpeg, making it ideal for real-time
encoding and low-power systems.
Understanding the Syntax and Modes
The basic syntax for the removegrain filter in FFmpeg
is:
-vf removegrain=m0=X:m1=Y:m2=Z:m3=WAlternatively, you can use the shorthand version:
-vf removegrain=X:Y:Z:W- m0 (or the first value): Mode for the first plane (usually Luma / Y).
- m1 (or the second value): Mode for the second plane (Chroma / U).
- m2 (or the third value): Mode for the third plane (Chroma / V).
- m3 (or the fourth value): Mode for the alpha channel.
If you specify only one mode, it applies to the first plane, and subsequent planes will copy the setting of the previous plane.
Recommended Operating Modes
The filter supports modes from 0 to 24.
Here are the most useful modes for denoising and smoothing:
- Mode 0: Pass-through (the plane is left untouched).
- Mode 2: A gentle, edge-preserving denoising filter. It is ideal for high-quality sources with light noise.
- Mode 4: A slightly stronger clipping filter that provides moderate denoising.
- Mode 11: A spatial blur/smoothing filter (using a 1/4, 1/2, 1/4 kernel). This is highly effective for smoothing out fine grain and compression blocking.
- Mode 12: A stronger spatial blur than Mode 11.
- Mode 20: A median blur that is highly effective at removing “salt and pepper” noise (isolated white or black pixels).
Practical Examples
1. Basic Gentle Denoising
To apply a light, safe denoiser to all video planes (Luma and Chroma) to clean up compression noise while retaining sharp edges, use Mode 2:
ffmpeg -i input.mp4 -vf removegrain=m0=2:m1=2:m2=2 -c:a copy output.mp42. High-Efficiency Spatial Smoothing
If your video has heavy grain or blocky compression artifacts, you can use Mode 11 to smooth the image:
ffmpeg -i input.mp4 -vf removegrain=m0=11:m1=11:m2=11 -c:v libx264 -crf 18 output.mp43. Targeted Luma and Chroma Filtering
Because human eyes are more sensitive to details in brightness (Luma) than in color (Chroma), you can apply a stronger smoothing filter to the Luma plane and a gentler denoiser to the Chroma planes:
ffmpeg -i input.mp4 -vf removegrain=m0=11:m1=2:m2=2 -c:a copy output.mp4In this command: * m0=11 applies a spatial blur to the
Luma plane to smooth out grain. * m1=2 and
m2=2 apply a gentle edge-preserving denoiser to the Chroma
planes to prevent color bleeding.