Apply FFmpeg Erosion Filter to Expand Dark Regions
This guide explains how to use the FFmpeg erosion filter
to expand dark areas and reduce bright regions in your videos. You will
learn the underlying mechanics of morphological erosion in video
processing, the basic syntax of the filter, and practical command-line
examples to customize the intensity of the effect.
Understanding the Erosion Filter in FFmpeg
The erosion filter is a morphological image processing
operation. It works by sliding a kernel (a grid of pixels) over the
video frame and replacing the center pixel’s value with the minimum
pixel value found within its neighborhood.
Because dark colors correspond to lower pixel values (closer to 0) and bright colors correspond to higher pixel values, choosing the minimum value inherently expands dark regions and shrinks light regions. This filter is highly effective for high-contrast videos, text bolding, and artistic threshold effects.
Basic Syntax and Parameters
The basic syntax for applying the erosion filter in FFmpeg is:
ffmpeg -i input.mp4 -vf "erosion" output.mp4To fine-tune the effect, the erosion filter accepts
several optional parameters:
coordinates: Specifies which neighboring pixels are considered. It is a bitmask value from 0 to 255. The default is255, which checks all eight surrounding pixels.threshold0,threshold1,threshold2,threshold3: Set the maximum change allowed for each color plane (Y, U, V, A or R, G, B, A respectively). The default is65535(no limit to the change).
Practical Command Examples
1. Standard Erosion
To apply a standard erosion effect across all color channels using the default settings:
ffmpeg -i input.mp4 -vf "erosion=coordinates=255" output.mp42. Limiting the Effect on Specific Channels
If you want to apply the erosion effect to the luma (brightness) channel but keep the chroma (color) channels relatively unchanged, you can lower the threshold values for the second and third planes:
ffmpeg -i input.mp4 -vf "erosion=threshold0=65535:threshold1=10:threshold2=10" output.mp43. Chaining Filters for Stronger Erosion
A single pass of the erosion filter only expands dark regions by one
pixel radius. To make the dark expansion much more pronounced, you can
chain multiple erosion filters together in the video filter
(-vf) graph:
ffmpeg -i input.mp4 -vf "erosion,erosion,erosion" output.mp4This command runs the erosion process three consecutive times, significantly expanding the dark boundaries within each frame of the video.