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=value

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

How the Command Works:

  1. -i input1.mp4 -i input2.mp4 -i input3.mp4: Loads the three source videos.
  2. [0:v][1:v][2:v]: Feeds the video streams of the first, second, and third inputs into the filter.
  3. maskedthreshold=threshold=10: Sets the comparison threshold to 10.
    • If the difference between input1 and input2 at a specific pixel is 10 or less, the output pixel is taken from input3.
    • If the difference is greater than 10, the output pixel is taken from input1.
  4. -map "[outv]": Maps the filtered video output to the final destination file, output.mp4.