when I compiled the following code:
AVFrameSideData* avfsd=NULL;
avfsd = av_frame_get_side_data(frame, AV_FRAME_DATA_MOTION_VECTORS);
if(avfsd != NULL) {
int n_mvs = 0;
if(avfsd->size > 0)
n_mvs = avfsd->size / sizeof(struct AVMotionVector);
struct AVMotionVector *mv = (struct AVMotionVector *) (avfsd->data);
printf("motion vectors of this frame:\n");
int idx;
for(idx=0; idx<n_mvs; idx++) {
printf("mv[%d]:\n", idx);
if(mv[idx]->source < 0)
printf("the current macroblock comes from the past\n");
}
}
my compiler complained:
video_analysis.c:46:13: error: invalid type argument of ‘->’ (have ‘struct AVMotionVector’)
if(mv[idx]->source < 0)
Frankly, there's something wrong here:
struct AVMotionVector *mv = (struct AVMotionVector *) (avfsd->data);
mv is a struct pointer, thereof it's not allowed to access through a two dimensional array manner like *mv[]. However, when I ran it in GDB, I was able to print out things like the following:
(gdb) print mv[0]
$2 = {source = -1, w = 16 '\020', h = 16 '\020', src_x = 6, src_y = 10, dst_x = 8, dst_y = 8, flags = 0, motion_x = -5, motion_y = 4,
motion_scale = 2}
which is exactly what I want to print out...As you can see, mv[0], which can't be accessed from my original code spinet above can now be accessed in GDB mode. How does GDB make this magic happen? If I want to access mv[0] in my program just like in GDB, how should I cast those struct pointers? Thanks in advance :-)
avfsd->dataseems to be pointer to array ofstruct AVMotionVectors. If so, thenmv[idx]is valid way to access those structures. However, in that casemv[idx]->sourceshould probably be replaced withmv[idx].source, because you want only one redirection.