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 from0to65535, with the default set to65535(maximum change allowed). Setting a threshold of0leaves the corresponding plane untouched.planes: A bitmask specifying which planes to process. The value is an integer from0to15, where1processes only the first plane,7processes the first three planes (YUV/RGB), and15processes all four planes (including alpha). The default is15.
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.mp42. 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.mp43. 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.mp44. 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.mp4Common 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
edgedetectorsobel,inflatethickens thin detected lines to make them more visible. - Artistic Stylization: Repeated inflation blows out highlights and creates high-contrast, graphic posterization effects.