FFmpeg scdet Filter: How to Detect Scene Cuts
This article provides a practical guide on how to use the
scdet (scene detection) filter in FFmpeg to automatically
detect scene changes and cuts in a video. You will learn the essential
command syntax, how to adjust detection thresholds for better accuracy,
and how to export the scene cut metadata to a text file for further
analysis or editing.
Understanding the scdet Filter
The scdet filter in FFmpeg detects scene transitions by
comparing the intensity differences between consecutive video frames.
When the difference passes a specified threshold, the filter flags a
scene cut.
This filter is highly useful for automating video editing, generating chapter markers, or preparing video files for adaptive bitrate streaming.
Basic Command Syntax
The simplest way to run scene detection and view the results in your
terminal is by routing the video through the scdet filter
and outputting to a null format.
Run the following command in your terminal:
ffmpeg -i input.mp4 -vf scdet -f null -As the command runs, FFmpeg will print console logs. Look for lines
containing lavfi.scdet.score and
lavfi.scdet.scene_change. When a scene change is detected,
lavfi.scdet.scene_change will output a value of
1.
Adjusting Detection Parameters
The scdet filter accepts parameters to fine-tune its
sensitivity. The two primary parameters are:
threshold(ort): Sets the threshold percentage for triggering a scene change. The value ranges from0to100. A lower threshold makes the filter more sensitive (detecting subtle cuts), while a higher threshold makes it less sensitive (detecting only drastic changes). The default value is10.framestart(ors): Defines whether the filter should trigger a scene change at the very first frame of the video. Set to1(true) or0(false). The default is1.
Example: Adjusting Sensitivity
To increase sensitivity (to catch quick cuts or low-contrast
transitions), lower the threshold to 8:
ffmpeg -i input.mp4 -vf "scdet=threshold=8" -f null -To decrease sensitivity (to avoid false positives from camera
movement or flashlights), raise the threshold to 15:
ffmpeg -i input.mp4 -vf "scdet=threshold=15" -f null -Exporting Scene Cuts to a Text File
Reading console outputs manually is impractical for long videos. You
can pair the scdet filter with the metadata
filter to log every detected scene cut, along with its exact timestamp,
directly into a text file.
Use the following command to export the scene cut data:
ffmpeg -i input.mp4 -vf "scdet=t=10,metadata=print:key=lavfi.scdet.scene_change:file=scenecuts.txt" -f null -Understanding the Exported File
The resulting scenecuts.txt file will contain entries
looking like this:
frame:124 pts:4137 pts_time:4.137
lavfi.scdet.scene_change=1
frame:450 pts:15015 pts_time:15.015
lavfi.scdet.scene_change=1
frame: The specific frame number where the cut occurred.pts_time: The exact timestamp (in seconds) of the scene transition.