How to Use the Deflate Filter in FFmpeg

This guide demonstrates how to apply a morphological deflation effect to video using FFmpeg's built-in deflate video filter. You will learn the core syntax, how the deflation algorithm alters pixels, how to target specific color planes, and how to control the intensity of the effect using thresholds and filter chaining.

What the Deflate Filter Does

The deflate filter applies a morphological erosion operation to each frame of a video. It evaluates a 3x3 neighborhood around each pixel and replaces the center pixel with the minimum value found in that local grid. In practice, this darkens bright regions, shrinks bright objects, thins edges, and expands dark areas.

Basic Syntax

To apply a single pass of morphological deflation to all planes of an input video, use the following command:

ffmpeg -i input.mp4 -vf "deflate" output.mp4

Controlling Parameters

The deflate filter accepts four threshold parameters corresponding to each color plane:

  • threshold0: Maximum change allowed for the 1st plane (Luma / Red). Default is 65535.
  • threshold1: Maximum change allowed for the 2nd plane (Chroma U / Green). Default is 65535.
  • threshold2: Maximum change allowed for the 3rd plane (Chroma V / Blue). Default is 65535.
  • threshold3: Maximum change allowed for the 4th plane (Alpha). Default is 65535.

The threshold defines the maximum difference allowed between the original pixel value and the computed minimum neighbor value. If the difference exceeds the threshold, the pixel is clamped to original_value - threshold.

Targeting Specific Planes

To process only the luminance channel (Y) of a standard YUV video while leaving color information (U and V) untouched, set the chroma thresholds to 0:

ffmpeg -i input.mp4 -vf "deflate=threshold0=65535:threshold1=0:threshold2=0" output.mp4

Setting a threshold to 0 prevents the filter from modifying that specific plane.

Subtle Deflation

To apply a subtle effect that limits how drastically any single pixel can be darkened, lower the threshold value:

ffmpeg -i input.mp4 -vf "deflate=threshold0=15:threshold1=15:threshold2=15" output.mp4

Increasing Intensity with Filter Chaining

Because the deflate filter operates strictly on a 3x3 pixel matrix per pass, a single application may appear subtle on high-resolution video. To widen the morphological radius, chain multiple deflate instances together in the filtergraph:

ffmpeg -i input.mp4 -vf "deflate,deflate,deflate" output.mp4

Each subsequent deflate filter in the chain expands the neighborhood of the erosion effect by one pixel in all directions.