How to Use the FFmpeg Inflate Filter

This guide covers how to apply a morphological inflation effect to videos and images using the FFmpeg inflate video filter. You will learn the mechanics behind morphological dilation in FFmpeg, the available configuration parameters—such as plane selection and thresholds—and practical command-line examples ranging from subtle line-thickening to heavy, chained dilation effects.

Understanding the Inflate Filter

The inflate filter applies a morphological dilation operation to an input video stream. In mathematical morphology, dilation expands the boundaries of foreground regions. Within FFmpeg, the inflate filter evaluates each pixel against its 3x3 neighboring pixels and replaces the target pixel's value with the maximum value found within that window. This broadens bright areas and shrinks dark areas across the targeted image planes.

Parameters and Syntax

The inflate filter accepts parameters that allow you to fine-tune which planes are processed and limit the maximum alteration applied to each pixel:

  • threshold0, threshold1, threshold2, threshold3: Sets the maximum allowed difference between the original pixel value and the calculated inflated value for planes 0, 1, 2, and 3 (typically representing Y, U, V, and Alpha, or R, G, B, and Alpha). The values range from 0 to 65535, with the default set to 65535 (maximum change allowed). Setting a threshold of 0 leaves the corresponding plane untouched.
  • planes: A bitmask specifying which planes to process. The value is an integer from 0 to 15, where 1 processes only the first plane, 7 processes the first three planes (YUV/RGB), and 15 processes all four planes (including alpha). The default is 15.

Practical Examples

1. Basic Inflation

To apply default morphological inflation across all planes of a video, use the filter directly within the -vf flag:

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

2. Processing Only the Luma (Brightness) Plane

If you want to dilate the brightness without shifting chroma colors, target only plane 0 (the Y plane in standard YUV video) using the planes parameter:

ffmpeg -i input.mp4 -vf "inflate=planes=1" output.mp4

3. Limiting the Effect with Thresholds

To prevent harsh shifts and soften the inflation effect, limit the maximum change applied to the luma channel by decreasing threshold0:

ffmpeg -i input.mp4 -vf "inflate=threshold0=30:planes=1" output.mp4

4. Chaining for Stronger Dilation

Because a single pass of inflate only expands pixel boundaries by one pixel using a 3x3 kernel, chain multiple instances together in a filtergraph to achieve a wider morphological spread:

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

Common Use Cases

  • Mask Refinement: When working with green-screen mattes or color keys, morphological inflation can expand the matte boundaries to eliminate inner holes or reinforce weak edges.
  • Line Art and Edge Processing: Combined with edge-detection filters such as edgedetect or sobel, inflate thickens thin detected lines to make them more visible.
  • Artistic Stylization: Repeated inflation blows out highlights and creates high-contrast, graphic posterization effects.