Adjust Scene Change Threshold in FFmpeg Select Filter
This article provides a straightforward guide on how to adjust the
scene change threshold using the FFmpeg select filter. You
will learn the specific parameter syntax required for the command line,
how the detection values work, and how to fine-tune the sensitivity to
accurately detect and extract scene cuts from your video files.
To detect scene changes in FFmpeg, you must use the
select video filter combined with the scene
evaluation variable. The filter calculates a value between
0 and 1 for each frame, representing the level
of difference from the previous frame. You adjust the detection
threshold by setting a greater-than (gt) condition.
The Basic Syntax
The basic syntax for adjusting the scene change threshold is:
-vf "select='gt(scene,threshold_value)'"In this command, threshold_value is a decimal number
between 0.0 and 1.0:
- Lower values (e.g.,
0.1to0.3): Make the filter highly sensitive. It will trigger scene changes on minor movements, camera pans, or lighting changes. - Higher values (e.g.,
0.5to0.7): Make the filter less sensitive. It will only trigger scene changes during abrupt, high-contrast cuts. - Default sweet spot: A value of
0.4is generally the recommended starting point for standard video content.
Example Commands
1. Extracting Scene Change Frames as Images
To export a single frame for every detected scene change using a
threshold of 0.4, use the following command:
ffmpeg -i input.mp4 -vf "select='gt(scene,0.4)'" -vsync vfr thumbnail_%03d.png(Note: -vsync vfr or -fps_mode vfr
tells FFmpeg to drop the unselected frames rather than duplicating the
selected ones).
2. Outputting Scene Change Timestamps
If you want to find the exact timestamps of the scene cuts without
exporting images, you can combine the select filter with
the ffprobe tool:
ffprobe -show_entries frame=pkt_pts_time -of compact=p=0 -f lavfi -i "movie=input.mp4,select=gt(scene\,0.4)"How to Fine-Tune the Threshold
If your current threshold is not yielding the desired results, adjust it based on your video’s characteristics:
- If you are missing scene cuts: The threshold is too
high. Decrease the value (e.g., from
0.4to0.3or0.25). This is common in dark scenes or slow-paced videos. - If you are getting too many false positives: The
threshold is too low. Increase the value (e.g., from
0.4to0.5or0.6). This is useful for high-action videos where rapid motion shouldn’t be counted as a new scene.