Configure FFmpeg Floodfill Coordinates and Tolerance
The FFmpeg floodfill filter allows you to replace a
region of connected pixels of a similar color with a new color, starting
from a specific seed point. This guide provides a straightforward
explanation of how to configure the starting coordinates and control the
color tolerance using the filter’s parameters, complete with practical
command examples.
Starting Coordinates
To set the starting point of the flood fill, use the x
and y parameters. These parameters define the pixel
coordinates on the input video where the filling operation begins.
x: The horizontal coordinate of the starting pixel (default is0).y: The vertical coordinate of the starting pixel (default is0).
For example, to start the flood fill at the center of a 1920x1080
video, you would set x=960 and y=540.
Color Tolerance
Color tolerance determines how closely adjacent pixels must match the
starting pixel’s color to be included in the fill area. FFmpeg controls
this using the d0, d1, d2, and
d3 parameters, which correspond to the color channels of
your video’s pixel format.
- RGB Video:
d0represents Red,d1represents Green,d2represents Blue, andd3represents the Alpha (transparency) channel. - YUV Video:
d0represents Luma (Y),d1andd2represent Chroma (U and V), andd3represents Alpha.
The tolerance values range from 0 to 255
(default is 0): * A value of 0 means adjacent
pixels must be an exact color match to be filled. * Higher values allow
the fill to spread over pixels with greater color variation.
Command Example
Below is a practical FFmpeg command that applies the
floodfill filter. It sets the starting coordinates to
x=300 and y=400, specifies a red fill color,
and sets a moderate color tolerance of 15 across the first
three color channels to allow the fill to spread across slightly varying
shades.
ffmpeg -i input.mp4 -vf "floodfill=x=300:y=400:fillcolor=red:d0=15:d1=15:d2=15" output.mp4Parameter Reference Table
| Parameter | Description | Valid Range / Format | Default |
|---|---|---|---|
x |
Starting X coordinate | Integer within video width | 0 |
y |
Starting Y coordinate | Integer within video height | 0 |
fillcolor |
The replacement color | Hex code (e.g., 0xFF0000) or
color name |
0 |
d0 |
Tolerance for the 1st component (Red/Luma) | 0 to 255 |
0 |
d1 |
Tolerance for the 2nd component (Green/Chroma-U) | 0 to 255 |
0 |
d2 |
Tolerance for the 3rd component (Blue/Chroma-V) | 0 to 255 |
0 |
d3 |
Tolerance for the 4th component (Alpha) | 0 to 255 |
0 |