How to Set Scene Change Threshold in FFmpeg
This article explains how to configure the scene change threshold
using the FFmpeg select filter. You will learn the exact
syntax required to detect scene cuts, how to adjust the sensitivity
threshold to match your video content, and how to use these settings in
practical command-line examples to extract keyframes or generate
scene-change metadata.
Understanding the Scene Detection Parameter
To detect scene changes, FFmpeg relies on the select
filter combined with the scene evaluation variable. The
scene variable represents the visual difference between the
current frame and the previous frame, returning a value between
0 (completely identical) and 1 (entirely
different).
The basic syntax for filtering frames based on scene changes is:
select='gt(scene,threshold)'In this expression, gt stands for “greater than,” and
threshold is a decimal value representing the sensitivity
of the detection.
Choosing the Right Threshold Value
Adjusting the threshold allows you to control how sensitive FFmpeg is to visual changes:
- 0.1 to 0.3 (High Sensitivity): Detects subtle transitions, panning shots, significant camera motion, or minor lighting changes. This can result in many false positives if you only want distinct scene cuts.
- 0.4 to 0.5 (Standard Sensitivity): The recommended sweet spot for typical video content. This range successfully captures most hard cuts and dramatic scene transitions while ignoring minor camera movement.
- 0.6 to 0.8 (Low Sensitivity): Only detects highly abrupt and drastic changes, such as a cut from a dark scene to a bright one, or a complete change of setting.
Practical Examples
1. Extracting Scene Change Frames as Images
To extract the exact frames where a scene change occurs (using a
threshold of 0.4), use the following command:
ffmpeg -i input.mp4 -vf "select='gt(scene,0.4)',scale=640:-1" -fps_mode vfr output_%03d.pngselect='gt(scene,0.4)'filters out all frames except those with a scene change score greater than 0.4.scale=640:-1resizes the output images (optional).-fps_mode vfr(variable frame rate) tells FFmpeg not to duplicate frames to fill in the gaps between the selected scene changes.
2. Logging Scene Change Timestamps
If you want to find the exact timestamps of scene changes without saving images, you can output the frame metadata to the console:
ffmpeg -i input.mp4 -vf "select='gt(scene,0.4)',metadata=print:file=scene_changes.txt" -f null -This command analyzes the video, filters the scene changes based on
your threshold, and writes the frame numbers and timestamps to a text
file named scene_changes.txt.