FFmpeg Select Filter: Export Scene Change Frames

Detecting and exporting frames where a scene transition occurs is a highly efficient way to analyze video content, create storyboards, or generate preview thumbnails. This article provides a concise guide on how to use FFmpeg's select filter with the scene evaluation parameter to identify these transitions and export only the exact frames where a scene change happens.

The FFmpeg Command

To extract scene changes, you use the video filter (-vf) with the select filter. Here is the standard command:

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

(Note: If you are using an older version of FFmpeg, replace -fps_mode vfr with -vsync vfr or -vsync 0).

Command Breakdown

  • -i input.mp4: Specifies your input video file.
  • -vf "select='gt(scene,0.4)'": This is the core filter.
    • scene calculates a value between 0 and 1 representing the difference between the current frame and the previous frame.
    • gt(scene,0.4) stands for "greater than 0.4". It tells FFmpeg to only select frames where the scene change detection value exceeds 40%.
  • -fps_mode vfr: This sets the frame rate mode to Variable Frame Rate (VFR). It prevents FFmpeg from duplicating frames to fill in the gaps between the selected scene changes.
  • frame_%04d.png: The output filename pattern. This will output sequential images like frame_0001.png, frame_0002.png, etc.

Adjusting Sensitivity

The 0.4 threshold works well for most standard videos, but you can adjust this value to change the sensitivity of the detection:

  • Increase sensitivity (0.1 to 0.3): Use a lower value if you want to capture subtle scene transitions, slow fades, or fast camera pans. This will export more frames.
  • Decrease sensitivity (0.5 to 0.7): Use a higher value if you only want to capture drastic, sudden cuts between completely different environments. This will export fewer frames.