FFmpeg Removegrain: Fast Denoising and Smoothing

The removegrain filter in FFmpeg is a port of the classic AviSynth spatial denoiser designed to eliminate grain, artifacts, and high-frequency noise with minimal CPU overhead. By analyzing the 3x3 pixel neighborhood around each target pixel, it can smooth out undesirable grain while preserving sharp edges. This guide explains how the filter works, covers the most effective operational modes, and provides ready-to-use commands for fast video denoising and smoothing.

Understanding the Removegrain Filter Syntax

The removegrain filter allows you to independently control how each video plane is processed: luma (Y), chroma (U), chroma (V), and alpha (A). The basic syntax requires assigning a processing mode (an integer from 0 to 24) to each plane:

ffmpeg -i input.mp4 -vf "removegrain=m0=mode:m1=mode:m2=mode" output.mp4
  • m0: Mode applied to the first plane (Luma/Y).
  • m1: Mode applied to the second plane (Chroma/U).
  • m2: Mode applied to the third plane (Chroma/V).
  • m3: Mode applied to the alpha plane (if present).

If shorthand syntax is used, parameters can be passed as sequential integers separated by colons: removegrain=m0:m1:m2.

Essential Modes for Denoising and Smoothing

While the filter supports 24 different modes, a few key modes account for most denoising tasks:

  • Mode 0: Bypass. The plane is copied directly to the output without modification.
  • Mode 1: Gentle artifact reduction. Clips the center pixel to the min/max of the surrounding neighbors to remove single-pixel anomalies.
  • Mode 2: Mild spatial smoothing. Softens sharp noise bursts while leaving lines and text intact.
  • Mode 4: Median-like filtering. Clamps the center pixel to the range of local neighbor averages, functioning as an efficient aggressive grain eliminator.
  • Mode 17: Spatial blur. Uses a 3x3 Gaussian-like weighted average to blur high-frequency noise.
  • Mode 20: Aggressive edge-preserving smoothing. Replaces the center pixel with neighbor-calculated medians, useful for heavily compressed or noisy content.
  • Mode 22: Balanced denoiser. An optimized mode that smooths flat regions while preserving distinct contrast boundaries.

Practical Examples

1. General Film Grain Reduction

To clean up moderate grain on the luma plane while lightly smoothing chroma noise, pair Mode 2 or 4 on luma with Mode 2 on chroma:

ffmpeg -i input.mp4 -vf "removegrain=m0=2:m1=2:m2=2" -c:v libx264 -crf 18 -c:a copy output.mp4

2. High-Efficiency Strong Smoothing

For noisy sources such as low-light webcam footage or analog tape captures, use Mode 4 on the luma channel for stronger noise suppression:

ffmpeg -i input.mp4 -vf "removegrain=m0=4:m1=2:m2=2" -c:v libx264 -crf 20 -c:a copy output.mp4

3. Preserving Color While Denoising Luma

Chroma noise is often less perceptible than luma noise. To save CPU cycles and preserve fine color detail, you can bypass the chroma planes entirely using Mode 0:

ffmpeg -i input.mp4 -vf "removegrain=m0=22:m1=0:m2=0" -c:v libx264 -crf 19 -c:a copy output.mp4

4. Combining with Unsharp Masking

Because spatial smoothing can slightly soften visual details, pairing removegrain with FFmpeg's unsharp filter can restore perceived edge sharpness after removing noise:

ffmpeg -i input.mp4 -vf "removegrain=m0=2:m1=2:m2=2,unsharp=5:5:0.5:5:5:0.0" -c:v libx264 -crf 18 -c:a copy output.mp4

Performance and Efficiency

Because removegrain operates strictly within a localized 3x3 pixel kernel and does not compare adjacent temporal frames, it executes significantly faster than complex temporal or non-local denoisers like hqdn3d or nlmeans. This makes it ideal for real-time transcoding pipelines, live streams, and batch-processing large video archives where speed is critical.