How to extract all key frames from a video clip?

Solution 1:

You can make this simpler using -skip_frame without the need for select video filter:

ffmpeg -skip_frame nokey -i 2.flv -vsync 0 -r 30 -f image2 thumbnails-%02d.jpeg

Solution 2:

Example using the select and scale filters:

ffmpeg -i 2.flv -vf "select=eq(pict_type\,I),scale=73x41" \
-vsync vfr -qscale:v 2 thumbnails-%02d.jpeg

A few tips:

  • Filters should not come before the -i option, as they're an output option. I don't know where exactly you got the command from, but PICT_TYPE_I does not exist – it should be I.

  • In the scale filter you can replace 73 or 41 to have the filter automatically calculate the width or height to preserve aspect ratio: such as scale=73:-1 or scale=-1:41. This prevents stretching or squishing that can result from "forced" scaling.

  • Output quality can be controlled with -qscale:v (or the alias -q:v). Effective range is a linear scale of 2 to 31 and a lower value is a higher quality.

  • That your ffmpeg allows a filter before the input tells me it could be outdated. Download a recent static build for your operating system, or build it yourself according to the compilation guides if the above does not work.