Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Get frame type for specific frame using ffmpeg

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.

like image 472
Damnesia Avatar asked May 31 '16 20:05

Damnesia


2 Answers

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
like image 193
Dimitri Podborski Avatar answered Nov 15 '22 13:11

Dimitri Podborski


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.

like image 42
Gyan Avatar answered Nov 15 '22 12:11

Gyan