How to Use FFmpeg Dilation Filter to Expand Bright Regions
This article provides a practical guide on how to use the FFmpeg
dilation filter to expand the bright regions of a video.
You will learn the underlying mechanics of morphological dilation in
video processing, the syntax of the FFmpeg filter, and how to adjust its
parameters to control the intensity and direction of the expansion.
Understanding the Dilation Filter
The dilation filter in FFmpeg is a morphological
operation applied to video frames. For each pixel in an image, the
filter analyzes a 3x3 grid of neighboring pixels and replaces the target
pixel’s value with the maximum value found within that neighborhood.
Because brighter pixels have higher luminance values, this operation
causes bright regions to grow, expand, or “dilate” into surrounding
darker areas, which is highly useful for halation effects, mask
generation, and artistic video styling.
Basic Syntax
To apply the default dilation effect to a video, use the following basic FFmpeg command:
ffmpeg -i input.mp4 -vf "dilation" output.mp4In this default state, the filter applies the maximum dilation effect across all video channels (planes) using all eight neighboring pixels.
Customizing the Dilation Parameters
The dilation filter accepts several parameters to
fine-tune the effect:
dilation=threshold0:threshold1:threshold2:threshold3:coordinates
1. Plane Thresholds
(threshold0 to threshold3)
These parameters limit the maximum change allowed for each plane
(typically Y, U, V, and Alpha channels, or R, G, B, and Alpha channels).
* The values range from 0 (no change/filter disabled) to
255 (maximum change allowed). * threshold0
controls the first plane (Luminance/Red). * threshold1
controls the second plane (Chrominance U/Green). *
threshold2 controls the third plane (Chrominance V/Blue). *
threshold3 controls the fourth plane
(Alpha/Transparency).
Example: Dilating only the brightness (Luma) channel If you only want to expand the bright regions without heavily distorting the color channels, limit the thresholds of the other planes:
ffmpeg -i input.mp4 -vf "dilation=threshold0=255:threshold1=0:threshold2=0" output.mp42. Coordinates
(coordinates)
The coordinates parameter determines which neighboring
pixels in the 3x3 grid are used to calculate the maximum value. It is
defined as a cumulative byte value (0 to 255), where each bit
corresponds to a specific neighbor in the grid:
1 | 2 | 4
------+-------+------
8 | X | 16
------+-------+------
32 | 64 | 128
To target specific directions, add the values of the desired
positions together. The default is 255 (all neighbors
enabled).
Horizontal Dilation Only: Use left (8) and right (16) neighbors. Value =
24.ffmpeg -i input.mp4 -vf "dilation=coordinates=24" output.mp4Vertical Dilation Only: Use top (2) and bottom (64) neighbors. Value =
66.ffmpeg -i input.mp4 -vf "dilation=coordinates=66" output.mp4Cross-Shaped Dilation: Use top (2), left (8), right (16), and bottom (64). Value =
90.ffmpeg -i input.mp4 -vf "dilation=coordinates=90" output.mp4
Chaining Filters for Stronger Effects
Because the dilation filter operates on a 3x3 pixel
matrix per pass, the expansion is subtle. To achieve a more pronounced
expansion of bright regions, you can chain multiple
dilation filters together in a single filtergraph:
ffmpeg -i input.mp4 -vf "dilation,dilation,dilation" output.mp4This sequence applies the dilation process three times consecutively, multiplying the radius of the expanded bright regions.