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.mp4

To fine-tune the effect, the erosion filter accepts several optional parameters:

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.mp4

2. 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.mp4

3. 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.mp4

This command runs the erosion process three consecutive times, significantly expanding the dark boundaries within each frame of the video.