FFmpeg Removegrain Luma and Chroma Plane Modes

The FFmpeg removegrain filter provides spatial denoising and blurring functions controlled through mode parameters assigned to individual image planes. By configuring the mode arguments—m0, m1, m2, and m3—you can precisely apply different filtering strengths or algorithms to the luma (brightness) and chroma (color) planes, or bypass specific planes entirely to conserve processing power and preserve color detail.

Understanding Plane Arguments

The removegrain filter accepts up to four mode parameters corresponding to the planes of the input video format:

  • m0: Sets the mode for Plane 0, which corresponds to the Luma (\(Y\)) plane in YUV formats or the Red plane in RGB formats.
  • m1: Sets the mode for Plane 1, which corresponds to the first Chroma (\(U\) / \(Cb\)) plane or the Green plane in RGB formats.
  • m2: Sets the mode for Plane 2, which corresponds to the second Chroma (\(V\) / \(Cr\)) plane or the Blue plane in RGB formats.
  • m3: Sets the mode for Plane 3, typically the Alpha plane if one exists.

If fewer parameters are provided, unassigned planes inherit the value of the preceding plane. For example, setting only m0=1 automatically applies mode 1 to m1, m2, and m3.

Mode Values Overview

Each mode integer (from 0 to 24) corresponds to a specific 3x3 spatial algorithm derived from the AviSynth RemoveGrain plugin:

  • Mode 0: Bypass. The plane is left untouched.
  • Mode 1: Clips the pixel to the minimum and maximum of its eight neighbors.
  • Mode 2: Clips to the second-highest and second-lowest neighbor values.
  • Mode 4: Standard 3x3 median filter.
  • Mode 17: Common edge-preserving blur.
  • Mode 19–24: Various blurring and box-filtering operations.

Configuration Syntax

You can specify planes using positional arguments or explicit key-value pairs.

Positional Syntax

Parameters are passed as colon-separated values in the order m0:m1:m2:m3:

ffmpeg -i input.mp4 -vf "removegrain=17:0:0" output.mp4

In this command:

  • m0 = 17: Mode 17 is applied to the luma plane.
  • m1 = 0: The first chroma plane (\(U\)) is passed through without changes.
  • m2 = 0: The second chroma plane (\(V\)) is passed through without changes.

Named Parameter Syntax

Explicitly declaring parameter names ensures clarity and avoids positional ordering errors:

ffmpeg -i input.mp4 -vf "removegrain=m0=17:m1=4:m2=4" output.mp4

In this command:

  • m0=17: Applies an edge-preserving blur to the luma plane.
  • m1=4: Applies a median filter to the \(U\) chroma plane.
  • m2=4: Applies a median filter to the \(V\) chroma plane.

Practical Examples

1. Luma-Only Denoising (Color Untouched)

Film grain and compression artifacts are often most noticeable in the luma plane. To avoid smearing subtle color gradients, bypass the chroma planes using mode 0:

ffmpeg -i input.mp4 -vf "removegrain=m0=1:m1=0:m2=0" -c:a copy output.mp4

2. Chroma-Only Noise Reduction

Analogue captures often contain high amounts of chroma noise while retaining sharp luma detail. To denoise color without softening luma edges:

ffmpeg -i input.mp4 -vf "removegrain=m0=0:m1=17:m2=17" -c:a copy output.mp4

3. Uniform Filtering Across All Planes

To apply the same processing across every plane, specify only the first mode:

ffmpeg -i input.mp4 -vf "removegrain=m0=4" -c:a copy output.mp4

Because m1 and m2 are omitted, they default to the value of m0 (mode 4).