Get frame type for specific frame using ffmpeg

Damnesia picture Damnesia · May 31, 2016 · Viewed 8.6k times · Source

I need to get the frame type (I/B/P) of a specific frame number for an x264 encoded movie.

How do I do this using ffmpeg/ffprobe? I'm open to other solutions as well.

Answer

Dimitri Podborski picture Dimitri Podborski · Jun 1, 2016

I found the way how to do it using ffprobe and grep:

$ ffprobe video.mp4 -show_frames | grep -E 'pict_type|coded_picture_number'

This produces an output like this:

pict_type=I
coded_picture_number=0
pict_type=B
coded_picture_number=3
pict_type=B
coded_picture_number=2
pict_type=P
coded_picture_number=1
pict_type=B
coded_picture_number=6
...

To get the frame type for specific frame (e.g. frame 8) you can extend it to this:

$ ffprobe video.mp4 -show_frames | grep -w -E 'coded_picture_number=8' -B 1

pict_type=P
coded_picture_number=8