Detect Scene Changes and Log Timestamps with FFmpeg

This article provides a concise guide on using FFmpeg's built-in scdet (scene detection) filter to identify scene transitions in a video file and log their exact timestamps. You will learn the correct command syntax, how the detection threshold works, and how to export the detected timestamps into a clean text file or terminal output.


Basic scdet Syntax

The scdet filter detects scene cuts by calculating the Mean Absolute Frame Difference (MAFD) between consecutive frames. When the difference exceeds a specified threshold, the filter flags a scene change and stores metadata about the frame.

To evaluate a video and print detected scene changes directly to a file, combine scdet with the metadata filter:

ffmpeg -i input.mp4 -vf "scdet=threshold=10.0,metadata=mode=print:key=lavfi.scd.time:file=scenes.txt" -f null -

Parameter Breakdown

  • -i input.mp4: Specifies the input video file.
  • -vf: Defines the video filter graph.
  • scdet=threshold=10.0: Activates scene change detection.
    • threshold (or t): Sets the sensitivity. The default is 10.0. Lower values (e.g., 5.0) increase sensitivity, detecting subtle changes. Higher values (e.g., 20.0) decrease sensitivity, only detecting stark transitions (such as cuts from dark to bright scenes).
  • metadata=mode=print:key=lavfi.scd.time:file=scenes.txt: Filters the output to log only the frame timestamp (lavfi.scd.time) when a scene cut occurs and appends the results directly to scenes.txt.
  • -f null -: Tells FFmpeg not to generate an output video file, which allows the process to run as fast as your CPU can decode the stream.

Logging Only Clean Timestamps to the Terminal

If you prefer clean timestamps in seconds output directly to your terminal without extraneous FFmpeg logs, pipe the output through ffprobe:

ffprobe -v error -show_entries frame=pkt_pts_time -of default=noprint_wrappers=1:nokey=1 -f lavfi "movie=input.mp4,scdet=threshold=10.0[out0]"

Alternatively, you can extract the timestamps using grep and standard FFmpeg:

ffmpeg -i input.mp4 -vf "scdet=threshold=10.0,metadata=mode=print:key=lavfi.scd.time" -f null - 2>&1 | grep "lavfi.scd.time"

The resulting output will display lines in the format:

lavfi.scd.time=3.456000
lavfi.scd.time=12.892000
lavfi.scd.time=45.120000

Fine-Tuning the Detection

If scdet misses transitions or falsely identifies fast camera movement as cuts, adjust the following parameters:

  • threshold (or t): Increase the value if rapid motion triggers false positives. Decrease it if soft transitions or low-contrast cuts are skipped.
  • sc_pass: Setting sc_pass=1 passes only the frames detected as scene changes down the filter chain, which is useful if you are piping the frames into image extractors or thumbnails rather than just reading metadata.