6

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.

Damnesia
  • 79
  • 1
  • 2
  • 8

2 Answers2

9

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
Dimitri Podborski
  • 3,714
  • 3
  • 19
  • 31
  • How come the order of the frames is not continuous. Are they not read in sequence by ffprobe or are they not encoded in sequence. Is the Output the actual frame order or the coded picture number? – secondplace Aug 22 '21 at 14:53
  • For those on Windows, you can use this command: `ffprobe video.mp4 -show_frames | findstr "pict_type"`. – Roovy Jun 01 '22 at 11:07
4

You can use ffmpeg directly

ffmpeg -i input.mp4 -vf select='eq(n,334)',showinfo -f null -

The above will produce an output for the 335th frame of the video

n: 0 pts: 171008 pts_time:11.1333 pos:  1090471 fmt:yuv420p sar:1/1 s:1280x720 i:P iskey:0 type:B checksum:A72D197D plane_checksum:[9008E835 680AC49A 6CD66C90] mean:[136 122 134] stdev:[65.4 7.0 9.5]

You can skip the select filter and get output for all frames and then grep like @incBrain does. Note that you want the display picture number, not coded.

Gyan
  • 85,394
  • 9
  • 169
  • 201
  • This worked for me, thanks. I ended up using this: `ffmpeg -i input.mkv -vf "select=eq(n\,100),showinfo -f null - 2>&1 | grep type: | awk '{split($16,a,":"); print a[2]}'` – Damnesia Jun 01 '16 at 10:23