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:

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

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.