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:

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: