How to Use FFmpeg Deflate Filter for Video

This article explains how to use the deflate filter in FFmpeg to apply a morphological deflation effect to your video files. You will learn the basic concept of morphological deflation, the syntax of the FFmpeg deflate filter, and practical command-line examples to customize and apply this pixel-reducing effect to different video planes.

What is Morphological Deflation?

Morphological deflation (often referred to as erosion in image processing) is a spatial filtering technique. For each pixel in a video frame, the filter analyzes a 3x3 neighborhood and replaces the center pixel’s value with the minimum value found in that neighborhood. This effectively shrinks brighter areas, expands darker regions, and removes isolated bright noise from the video.

FFmpeg Deflate Filter Syntax

The basic syntax for the deflate filter in FFmpeg is:

deflate=threshold0:threshold1:threshold2:threshold3

The filter accepts four threshold parameters, each corresponding to a specific plane of the video container (typically Y, U, V, and Alpha for YUV color spaces, or R, G, B, and Alpha for RGB):

Parameter Details: * The threshold values range from 0 to 65535. * The default value for all thresholds is 65535. * A threshold limit restricts the maximum difference allowed between the original pixel value and the calculated minimum value. If the difference exceeds the threshold, the pixel value is only changed by the threshold amount. Setting a threshold to 0 disables the effect on that specific plane.

Practical Command Examples

1. Apply Default Deflation

To apply the deflation effect to all planes of a video using the default threshold (maximum strength), run the following command:

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

2. Apply Deflation Only to the Luma (Brightness) Plane

If you want to erode bright areas while preserving the original color information, apply the filter only to the first plane (Y) by setting the chroma thresholds to 0:

ffmpeg -i input.mp4 -vf "deflate=threshold0=65535:threshold1=0:threshold2=0" output.mp4

3. Limit the Intensity of the Deflation Effect

To apply a subtle deflation effect, restrict the threshold. This prevents drastic changes in pixel values by capping the maximum pixel value reduction:

ffmpeg -i input.mp4 -vf "deflate=threshold0=10:threshold1=10:threshold2=10" output.mp4

4. Multiple Passes for a Stronger Effect

Because the deflate filter operates on a 3x3 neighborhood per pass, you can chain multiple deflate filters together to increase the radius of the deflation effect:

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