Get frame type for specific frame using ffmpeg
Asked Answered
U

2

7

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.

Uracil answered 31/5, 2016 at 20:5 Comment(2)
maybe you can use -debug vis_mb_type . This should print nal unit types to stdoutMartinmas
I tried to run ffplay video.mp4 -vf showinfo, this prints all pic types to screen. Previous command worked only for hevc for some reasonMartinmas
H
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.

Halfcaste answered 1/6, 2016 at 6:23 Comment(1)
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]}'Uracil
M
10

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
Martinmas answered 31/5, 2016 at 22:15 Comment(2)
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?Rosemaria
For those on Windows, you can use this command: ffprobe video.mp4 -show_frames | findstr "pict_type".Tazza
H
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.

Halfcaste answered 1/6, 2016 at 6:23 Comment(1)
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]}'Uracil

© 2022 - 2024 — McMap. All rights reserved.