FFmpeg Export Scene Change Frames with Select Filter

This guide explains how to extract only the frames where a scene transition occurs in a video using FFmpeg. By leveraging the select video filter paired with the internal scene detection variable, FFmpeg calculates the visual difference between consecutive frames and exports only the images that exceed a designated threshold.

The Basic Command

To export scene-change frames as separate image files, run the following command in your terminal:

ffmpeg -i input.mp4 -vf "select='gt(scene,0.4)'" -fps_mode vfr scene_%04d.png

How It Works

  • -i input.mp4: Specifies the path to your source video file.
  • -vf "select='gt(scene,0.4)'": Applies the video filter select. The scene variable generates a value between 0.0 and 1.0 reflecting the visual difference between the current frame and the preceding frame. The function gt(scene,0.4) checks if this score is "greater than" 0.4.
  • -fps_mode vfr: Sets the output to Variable Frame Rate mode (formerly -vsync vfr). This instructs FFmpeg to drop frames that fail the selection criteria rather than duplicating frames to maintain the original frame rate.
  • scene_%04d.png: Defines the output filename pattern, formatting the output as sequentially numbered images (scene_0001.png, scene_0002.png, etc.). You can also use .jpg to reduce disk usage.

Tuning the Sensitivity Threshold

The scene score ranges from 0.0 (identical frames) to 1.0 (completely different frames). Adjusting this value alters detection sensitivity:

  • Lower values (0.2 to 0.3): Higher sensitivity. Captures subtle transitions, fast camera pans, and large object movements, but may yield false positives.
  • Higher values (0.5 to 0.6): Lower sensitivity. Captures only drastic cuts and stark contrast changes between scenes, potentially missing soft transitions or fades.

For most standard content, a threshold between 0.3 and 0.4 provides the most accurate results.

Logging Timestamps Alongside Frames

If you need the exact timestamps of when scene changes happen, append the metadata filter or output the frame information to a text file:

ffmpeg -i input.mp4 -vf "select='gt(scene,0.4)',metadata=print:file=scene_cuts.txt" -fps_mode vfr scene_%04d.png

This creates a text file named scene_cuts.txt containing the presentation timestamp (pts_time) for each extracted frame.