How to Use the FFmpeg Removegrain Filter
The removegrain filter in FFmpeg is a highly efficient
spatial denoiser and sharpening tool ported from the popular AviSynth
plugin. This article explains how to use the removegrain
filter, details its primary modes of operation, and provides practical
command-line examples to help you clean up and compress your video
files.
Understanding the Removegrain Filter
The removegrain filter works by analyzing neighboring
pixels to eliminate noise, compression artifacts, and “dust” without
severely blurring the image. It processes up to four planes (typically
Y, U, V, and Alpha) independently.
The basic syntax for the filter is:
-vf removegrain=m0:m1:m2:m3- m0: Mode for the first plane (Luma / Y).
- m1: Mode for the second plane (Chroma / U).
- m2: Mode for the third plane (Chroma / V).
- m3: Mode for the fourth plane (Alpha).
If you specify only one mode (e.g., removegrain=2), that
mode is applied to the first plane, and the remaining planes will mirror
the previous plane’s mode. If a mode is set to 0, that
plane is left unprocessed (pass-through).
Common Removegrain Modes
The filter supports 25 different modes (numbered 0 to 24). Here are the most commonly used modes:
- Mode 0: No processing (pass-through).
- Mode 1: A simple 3x3 box blur that preserves edges better than standard blurs.
- Modes 2 to 4: Various degrees of median-clipping. Mode 2 is mild, Mode 3 is medium, and Mode 4 is the strongest. These are excellent for removing stray hot pixels, dirt, and light grain.
- Modes 5 to 9: Line-sensitive clipping modes. They are designed to remove noise while preserving fine lines and edges, making them ideal for anime or cartoon content.
- Mode 10: A very fast, simple blur often used as a pre-filter before video compression to improve encoder efficiency.
- Modes 11 and 12: Soft and medium Gaussian blurs.
- Modes 17 and 18: Smart sharpening filters that enhance edges while suppressing noise amplification.
- Mode 20: A specialized blur mode that is highly effective at reducing temporal flicker when used in combination with other filters.
Practical Command Examples
1. Basic Denoising
To apply a moderate denoise (Mode 2) to all planes of the video, use the following command:
ffmpeg -i input.mp4 -vf removegrain=2 output.mp42. Denoising Luma Only (Preserving Chroma)
Noise is often most visible in the luma (brightness) channel. Processing the chroma (color) channels can sometimes cause color bleeding. To denoise only the luma channel (using Mode 4) and leave the color channels untouched (Mode 0), run:
ffmpeg -i input.mp4 -vf removegrain=m0=4:m1=0:m2=0 output.mp43. Optimizing for Animated Content
For anime and cartoons, Mode 5 is highly recommended because it removes spatial noise without destroying the sharp black outlines of the drawings:
ffmpeg -i input.mp4 -vf removegrain=5 output.mp44. Pre-compression Blur
If you want to compress a noisy video and minimize file size, applying a mild Mode 10 blur will discard invisible high-frequency noise, allowing the video encoder to work much more efficiently:
ffmpeg -i input.mp4 -vf removegrain=10 -c:v libx264 -crf 20 output.mp4