2

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 :-)

4
  • 1
    Indentation doesn't match with the block scopes. Please edit and fix it. Commented May 4, 2016 at 13:09
  • avfsd->data seems to be pointer to array of struct AVMotionVectors. If so, then mv[idx] is valid way to access those structures. However, in that case mv[idx]->source should probably be replaced with mv[idx].source, because you want only one redirection. Commented May 4, 2016 at 13:24
  • I noticed that there is not a single comment in your code - for your own sanity, fix that bad habit. Commented May 4, 2016 at 13:25
  • @user694733 does it look better now? :) Commented May 4, 2016 at 13:44

1 Answer 1

2

Change

if(mv[idx]->source < 0)

to

if(mv[idx].source < 0)

Explanation

  • mv is a pointer to struct AVMotionVector

  • mv[idx] is a struct AVMotionVector and therefore you need . instead of ->.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.