Skip to the content.

Extract, Filter, and Compile Video Frames with FFmpeg

This guide explains how to:

  1. Extract every 20th frame from a video.
  2. Filter out duplicate frames with 90% or greater similarity.
  3. Compile the filtered frames into a playable video file.

Step 0: Organize the Directory

mkdir -p frames

Step 1: Extract Frames from Video

Using ffmpeg, extract every 20th frame from a video file (video.mov), saving each frame as an image file. Adjust the 20 to change the frame extraction frequency.

ffmpeg -i video.mov -vf "select='not(mod(n\,20))'" -vsync vfr ./frames/frame-%04d.png

Step 2: Remove Duplicate Frames

Use findimagedupes to detect and delete frames that are 90% similar or more.

findimagedupes -t 90 ./frames | while read -r line; do
    set -- $line             # Split line into words
    shift 1                  # Skip the first image (original frame)
    for foto in "$@"; do
        echo "$foto found similar, deleting..."
        rm "$foto"
    done
done

Step 3: Compile Frames into Video

Finally, use ffmpeg to create a video from the filtered frames, setting the frame rate to 6 FPS and encoding with H.264 for compatibility.

ffmpeg -framerate 6 -pattern_type glob -i 'frames/frame-*.png' -c:v libx264 -pix_fmt yuv420p -crf 23 -preset fast -c:a aac -b:a 192k result.mp4

This process creates result.mp4, a video containing selected frames at the specified frame rate.