How to Use FFmpeg scdet Filter for Scene Detection
This article provides a practical guide on how to use the
scdet (scene detection) filter in FFmpeg to identify scene
changes and transitions in video files. You will learn the basic syntax
of the filter, its primary configuration parameters, and how to extract
scene-change timestamps using both FFmpeg and FFprobe.
What is the scdet
Filter?
The scdet filter detects scene changes in a video stream
by comparing consecutive frames. When a significant change in content is
detected, the filter flags the frame as a scene change and assigns
metadata to it. This is highly useful for automated video editing,
chapter generation, or video analysis.
Basic Syntax
The simplest way to run the scdet filter is to pass the
video through the filter and output the results to the console using the
null muxer (-f null):
ffmpeg -i input.mp4 -vf scdet -f null -When you run this command, FFmpeg will analyze the video and print
metadata in the console log whenever a scene change is detected. Look
for lines containing lavfi.scd.score or
lavfi.scd.time in the output.
Key Parameters
You can fine-tune the detection accuracy by adjusting the
scdet filter parameters:
threshold(ort): Sets the threshold for scene change detection. The value ranges from 0 to 100. A lower threshold makes the filter more sensitive (detecting more scene changes), while a higher threshold makes it less sensitive. The default value is10.sc_pass(ors): Controls whether detected scene changes are marked as keyframes in the output stream. Set to1to force keyframes at scene changes, or0(default) to leave the stream unchanged.
Example: Adjusting Sensitivity
If you find that the default settings are missing transitions, lower the threshold to increase sensitivity:
ffmpeg -i input.mp4 -vf scdet=threshold=8.0 -f null -To reduce false positives in highly active videos, increase the threshold:
ffmpeg -i input.mp4 -vf scdet=threshold=15.0 -f null -Extracting Scene Change Timestamps with FFprobe
While FFmpeg outputs the detection data to the console, using FFprobe is the most efficient way to extract a clean list of timestamps where scene changes occur.
Run the following command to output only the frame timestamps and the scene detection scores:
ffprobe -v error -f lavfi -i "movie=input.mp4,scdet=threshold=10" -show_entries frame=pkt_pts_time:frame_tags=lavfi.scd.score -of csv=p=0Understanding the Output
The output will display a list of timestamps alongside their corresponding detection scores. Frames that do not trigger a scene change will show empty tags, while detected scene changes will look like this:
1.424000,0.12543
5.880000,0.18732
12.120000,0.11409
In this output, the first value is the timestamp (in seconds) where a
new scene begins, and the second value is the detection score calculated
by the filter. You can pipe this output into a text file by appending
> scene_changes.txt to the end of your command.