Search code examples
ffmpegcomputer-visionvideo-capturevideo-processingvideo-compression

How to extract frame types along with motion vectors using extract_mvs.c from ffmpeg


I have been researching ways to get frame types (I, P, B) along with the motion vector data returned from extract_mvs.c in the examples folder in ffmpeg.

The extract_mvs.c file after it is compiled, returns information like this:

framenum,source,blockw,blockh,srcx,srcy,dstx,dsty,flags
2,-1,16,16,   8,   8,   8,   8,0x0
2, 1,16,16,   8,   8,   8,   8,0x0
2, 1,16,16,  24,   8,  24,   8,0x0
2, 1,16,16,  40,   8,  40,   8,0x0
2, 1,16,16,  56,   8,  56,   8,0x0
2, 1,16,16,  72,   8,  72,   8,0x0
2, 1,16,16,  88,   8,  88,   8,0x0
...
297, 1,16,16, 248, 280, 248, 280,0x0
297, 1,16,16, 264, 280, 264, 280,0x0
297,-1,16,16, 278, 279, 280, 280,0x0
297, 1,16,16, 280, 280, 280, 280,0x0
297, 1,16,16, 296, 280, 296, 280,0x0
297, 1,16,16, 312, 280, 312, 280,0x0
297, 1,16,16, 328, 280, 328, 280,0x0
297, 1,16,16, 344, 280, 344, 280,0x0

Along with this information, I would like to output frame type so that I know framenum = 2 is, for example, a 'B' frame.

I tried different things, one of which was using a separate command:

ffprobe input.mp4 -show_frames | grep -E 'pict_type|coded_picture_number'

But the problem with this command is that it returns data like:

pict_type=I
coded_picture_number=0
pict_type=B
coded_picture_number=2
pict_type=P
coded_picture_number=1
pict_type=B
coded_picture_number=4
pict_type=P
coded_picture_number=3
....
pict_type=P
coded_picture_number=293
pict_type=B
coded_picture_number=297
pict_type=B
coded_picture_number=296

And there is no much I can relate here between coded_picture_number and framenum. The former starts counting from 0 and the later from 2. I assume framenum starting from 2, means the count from this variable is actually from 1, and it ignored 1 in the extraction process as it is maybe an I frame thus no motion vectors.

So, how can we use only extract_mvs.c to get not only that information it provides but also the frame types in the returned table. Any hints either syntax/command-wise or in editing the c file would be appreciated. Thanks in advance.


Solution

  • I found a way to get the frames, had posted on this question, where I replaced the flags argument with frametypes.