Detect Scene Changes and Log Timestamps with FFmpeg scdet
This article explains how to use FFmpeg’s scdet (scene
detection) filter to identify scene transitions in a video file and
export their precise timestamps. You will learn the basic syntax of the
filter, how to adjust its sensitivity thresholds, and how to use
ffprobe to output a clean list of timestamps where scene
cuts occur.
Understanding the scdet Filter
The scdet filter detects scene changes by comparing the
intensity differences between consecutive video frames. When the
difference exceeds a specified threshold, the filter flags the frame as
a new scene.
The filter uses two main parameters: * threshold
(or t): Sets the scene change detection threshold.
The default value is 10. Lower values make the filter more
sensitive (detecting more subtle changes), while higher values make it
less sensitive (detecting only major cuts). *
sc_pass (or p): A boolean
flag (0 or 1). When set to 1 (default), it passes the scene
change frame detection metadata to the output stream.
Method 1: Print Scene Changes in the Terminal
To quickly scan a video and print scene change detections directly in your terminal, run the following command:
ffmpeg -i input.mp4 -vf "scdet=threshold=10" -f null -As FFmpeg processes the video, you will see output lines in the console indicating detected scene changes along with their frame numbers and Mean Absolute Frame Difference (mafd) scores:
[scdet @ 0x...] lavfi.scdet.mafd:12.45 lavfi.scdet.sc:1
Method 2: Extract a Clean List of Timestamps Using FFprobe
If you need a clean, text-based log of the exact timestamps where
scene changes occur, you can combine scdet with
ffprobe and the metadata filter. This method
filters out all normal frames and outputs only the timestamps of the
scene cuts.
Run the following command in your terminal:
ffprobe -v error -show_entries frame=best_effort_timestamp_time -of default=noprint_wrappers=1:nokey=1 -f lavfi -i "movie=input.mp4,scdet=t=10,metadata=select:key=lavfi.scdet.sc:value=1"How this command works:
-f lavfi -i "movie=input.mp4...": Loads your input video directly into the Libavfilter input device.scdet=t=10: Applies the scene detection filter with a sensitivity threshold of 10.metadata=select:key=lavfi.scdet.sc:value=1: Filters the frame stream, keeping only the frames where the scene change metadata tag (lavfi.scdet.sc) is set to1.-show_entries frame=best_effort_timestamp_time: Instructsffprobeto only output the timestamp of the selected frames.-of default=noprint_wrappers=1:nokey=1: Formats the output to display raw numbers, stripping away default formatting brackets and keys.
The resulting output will be a clean list of timestamps in seconds:
4.125000
12.840000
34.567000
Saving the Timestamps to a Text File
To export this clean list of timestamps directly into a text file for
post-processing or video editing, append a redirection operator to the
ffprobe command:
ffprobe -v error -show_entries frame=best_effort_timestamp_time -of default=noprint_wrappers=1:nokey=1 -f lavfi -i "movie=input.mp4,scdet=t=10,metadata=select:key=lavfi.scdet.sc:value=1" > scene_changes.txt