问题
I am in the process of extracting motion vectors from ffmpeg to use in a computer vision project. I have been looking for an easy way to extract this information in a meaningful way.
While reading through different posts and other websites, I came across the extract_mvs.c in the example folder of FFmpeg. I noticed that out of the data produced by this file (after it has been compiled) there is a flag column which I would like to modify, to make it print frame types instead of 0x0s as shown below.
The idea for modifying flags it I got from the author of the code himself.
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
Ideally what I want to achieve is:
framenum,source,blockw,blockh,srcx,srcy,dstx,dsty,frametypes
2,-1,16,16, 8, 8, 8, 8,B
2, 1,16,16, 8, 8, 8, 8,B
2, 1,16,16, 24, 8, 24, 8,B
2, 1,16,16, 40, 8, 40, 8,B
2, 1,16,16, 56, 8, 56, 8,B
2, 1,16,16, 72, 8, 72, 8,B
2, 1,16,16, 88, 8, 88, 8,B
...
297, 1,16,16, 248, 280, 248, 280,P
297, 1,16,16, 264, 280, 264, 280,P
297,-1,16,16, 278, 279, 280, 280,P
297, 1,16,16, 280, 280, 280, 280,P
297, 1,16,16, 296, 280, 296, 280,P
297, 1,16,16, 312, 280, 312, 280,P
297, 1,16,16, 328, 280, 328, 280,P
297, 1,16,16, 344, 280, 344, 280,P
The part that requires modification in the file is shown here, where mv->flags needs to be replaced with frame type variable. I thought of making a reference to AVFrame struct with a pointer and call the pict-type. But not sure how the building blocks would be. Any help?
回答1:
I managed to find out how to replace flags with frame type. I simply changed this line print function to this:
printf("%d,%2d,%2d,%2d,%4d,%4d,%4d,%4d,%c\n",
video_frame_count, mv->source,
mv->w, mv->h, mv->src_x, mv->src_y,
mv->dst_x, mv->dst_y, av_get_picture_type_char(frame->pict_type));
You can then change this line for the header flags to read frametypes:
printf("framenum,source,blockw,blockh,srcx,srcy,dstx,dsty,frametypes\n")
来源:https://stackoverflow.com/questions/48783155/how-to-replace-flags-with-frame-types-on-ffmpegs-extract-mvs-c