Extracting every 5th frame from a video using ffmpeg

ffmpeg -i input.mp4 -vf "select=not(mod(n\,5)),setpts=N/FRAME_RATE/TB" -vsync vfr output_%04d.png

The command breaks down:

  • -i input.mp4
    Specifies the input video file.

  • -vf "select=not(mod(n\,5)),setpts=N/FRAME_RATE/TB"
    Uses a video filter to select every 5th frame. The select=not(mod(n\,5)) part selects every 5th frame, and setpts=N/FRAME_RATE/TB sets the presentation timestamp (PTS).

  • -vsync vfr
    Variable frame rate to avoid unnecessary frames.

  • output_%04d.png
    Specify naming format for the output frames, in this case, PNG images with a four-digit sequence number.

To run this command, simply replace input.mp4 with the path to your video file and output_%04d.png with your output format and path.

Final result will be the same as the feature image visible on the top of the page.