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

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:

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

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

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

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