Configure FFmpeg Signature Filter Match Threshold and Format
This article explains how to configure the match threshold and output
format of the FFmpeg signature filter. You will learn the
specific command-line parameters required to adjust matching sensitivity
and how to export video signatures in either binary or XML formats for
duplicate detection.
Understanding the FFmpeg Signature Filter
The signature filter in FFmpeg is used to generate and
compare unique fingerprints (signatures) of video streams. This is
highly useful for detecting duplicate content, identifying video copies,
or finding specific scenes across different files.
When working with this filter, you can configure how strict the matching algorithm is and how the resulting signature data is formatted.
Configuring the Output Format
The format option defines how the generated signature or
comparison result is stored. The signature filter supports
two output formats:
binary(default): Exports the signature in a compact binary format.xml: Exports the signature in an XML format, which is easier to read and parse using external scripts.
To define the format and specify an output file, use the
format and filename parameters:
ffmpeg -i input.mp4 -vf "signature=format=xml:filename=output.xml" -f null -In this command: * format=xml sets the output format to
XML. * filename=output.xml specifies where the signature
file will be saved.
Configuring the Match Threshold
The match threshold determines how closely two video frames must resemble each other to be considered a match.
- Parameter:
th - Value Range: An integer value (typically between 1 and 10000, with a default of 90).
- Behavior: A lower threshold value enforces a stricter matching process (requiring the videos to be almost identical). A higher threshold value is more lenient, allowing matches despite compression artifacts, slight color differences, or quality variations.
To compare two videos and set a custom threshold, you must use a
complex filtergraph to pass both video inputs into the
signature filter, setting nb_inputs=2.
ffmpeg -i video1.mp4 -i video2.mp4 -filter_complex "[0:v][1:v]signature=nb_inputs=2:th=150:format=xml:filename=match_results.xml" -f null -In this example: * nb_inputs=2 tells the filter to
expect and compare two video streams. * th=150 increases
the threshold from the default 90 to 150, making the detection more
tolerant of visual differences between video1.mp4 and
video2.mp4. * The results of the match, including matching
timestamps, will be written to match_results.xml.