Skip to content Skip to sidebar Skip to footer

Using Ffprobe/ffmpeg To Extract Individual Frames And Types In Encode Order

I am able to extract keyframes using ffmpeg. Something like this that I have been using: ffmpeg -i input.mp4 -vf 'select='eq(pict_type\,I)' -vsync vfr -qscale:v 2 I-thumbnails-%02d

Solution 1:

With a recent version of ffmpeg, you can run,

ffmpeg -i input.mp4
  -vf "select='eq(pict_type\,I)" -vsync 0 -frame_pts 1 thumbnails-%02d-I.png
  -vf "select='eq(pict_type\,B)" -vsync 0 -frame_pts 1 thumbnails-%02d-B.png
  -vf "select='eq(pict_type\,P)" -vsync 0 -frame_pts 1 thumbnails-%02d-P.png

The image serial numbers will correspond to their index position (display-wise) in the video, and the suffix will indicate the frame type.


To get frames in encode/decode order, run

ffmpeg -i input.mp4
  -vf "setpts=POS,select='eq(pict_type\,I)" -vsync 0 -frame_pts 1 thumbnails-%09d-I.png
  -vf "setpts=POS,select='eq(pict_type\,B)" -vsync 0 -frame_pts 1 thumbnails-%09d-B.png
  -vf "setpts=POS,select='eq(pict_type\,P)" -vsync 0 -frame_pts 1 thumbnails-%09d-P.png

You should sort the output image listing in alphabetical/lexical order - that's the images in encode/decode order. You can batch rename the 9-digit field to a simple serial index, if wanted.

setpts=POS sets the frame's timestamp to its byte offset in the file, which will track the encode/decode order.


Post a Comment for "Using Ffprobe/ffmpeg To Extract Individual Frames And Types In Encode Order"