How to Use the FFmpeg Maskedthreshold Filter
This article provides a practical guide on how to use the
maskedthreshold filter in FFmpeg. You will learn how this
filter compares video streams, its syntax, key parameters, and how to
apply it in real-world scenarios to generate threshold-based visual
outputs.
What is the Maskedthreshold Filter?
The maskedthreshold filter is a video processing filter
in FFmpeg that compares two input video streams pixel-by-pixel. If the
absolute difference between the pixels of the first and second input is
less than or equal to a specified threshold, the filter outputs the
pixel from a third input stream. Otherwise, it outputs the pixel from
the first input stream.
This filter requires exactly three input video streams of matching dimensions and pixel formats.
Syntax and Parameters
The basic syntax for the filter is:
maskedthreshold=threshold=value:planes=valuethreshold: Sets the threshold value used for the difference comparison. The default value is1. A higher threshold means more pixels from the third input will be used, as larger differences will still fall within the threshold.planes: Specifies which color planes (channels) to process. It accepts a bitmask value (from0to15). The default is15(all planes processed).
Practical Command Example
To use maskedthreshold, you must pass three video inputs
to filter_complex. The following command demonstrates how
to combine three inputs using this filter:
ffmpeg -i input1.mp4 -i input2.mp4 -i input3.mp4 -filter_complex "[0:v][1:v][2:v]maskedthreshold=threshold=10:planes=15[outv]" -map "[outv]" output.mp4How the Command Works:
-i input1.mp4 -i input2.mp4 -i input3.mp4: Loads the three source videos.[0:v][1:v][2:v]: Feeds the video streams of the first, second, and third inputs into the filter.maskedthreshold=threshold=10: Sets the comparison threshold to10.- If the difference between
input1andinput2at a specific pixel is10or less, the output pixel is taken frominput3. - If the difference is greater than
10, the output pixel is taken frominput1.
- If the difference between
-map "[outv]": Maps the filtered video output to the final destination file,output.mp4.