[Ffmpeg-devel] Re: access to motion vectors

Paolo paolo.mosna
Tue Feb 13 08:18:23 CET 2007


Alireza Ghane <ghane <at> ce.sharif.edu> writes:

> 
> I want to access the motion vectors for some blocks in a P frame. I am
> decoding H.264 video sequence and MV accuracy is 4X4 pixels and the size
> of each MB is 16X16.  I wrote this code to access the Forward MV for the
> first 4X4 sub-block of the MB at the position (mb_x, mb_y) in a P frame;
> But it seems to generate wrong answer. Please help me to correct it.
> 
> ///////////////////////////////////////////////////////////////
> curr_pic = s->current_picture_ptr;
> 
> mv_sample_log2= 4 - curr_pic->motion_subsample_log2;
> mb_width= (w+15)>>4; // w is the width of the frames
> mv_stride= (mb_width << mv_sample_log2) + 1;
> 
> mv_x = mb_x << mv_sample_log2;
> mv_y = mb_y << mv_sample_log2;
> mv = curr_pic->motion_val[0][(mv_x) + (mv_y)*mv_stride];
> ///////////////////////////////////////////////////////////////
> 

I do not know if this can help you but you should check-out the
method ff_print_debug_info() in libavcodec/mpegvideo.c.
In the example, the array motion_val is processed to extract motion vectors.

Just one thing, to collect motion vectors for MPEG it is required
to set debug_mv to TRUE in AVCodecContext.

Paolo.






More information about the ffmpeg-devel mailing list