[FFmpeg-devel] Understanding motion vectors from ff_print_debug_info()
Pravin Bhat
pro
Sun Jul 29 04:46:57 CEST 2007
Hey All-
A while back Paolo suggested that people looking to extract motion
vectors in ffmpeg should look at
the method ff_print_debug_info() in libavcodec/mpegvideo.c.
This advice turned out to be very useful in my case. Thx Paolo.
However, I have a couple of questions about the constants being used
ff_print_debug_info() that would
really help noobs like myself really understand what is going on. Please
consider posting a reply if you
are familiar with this part of ffmpeg.
# It looks like you have to divide by 2 (or a higher power of 2) the
values in the motion_val array
to obtain the true motion vectors. Why is this so?
For example ff_print_debug_info() processes the motion_val vectors in
the following manner:
motion_val[direction][xy][0]>>shift
where shift = 1 + s->quarter_sample.
The 'quarter_sample' variable makes sense. It's accounting for some sort
of mode where the video is
sub-sampled by 2 in the X and Y axis. But I don't understand why the '1'
is added to 'shift' in effect
dividing all motion vectors by 2.
# For computing the 'mv_stride' variable avcodec.h suggests the
following formula:
mv_stride= (mb_width << mv_sample_log2) + 1
While I don't understand why that '1' is added mv_stride.
What worries me is that the addition of that '1' is conditional and I
don't understand when not to add that '1'. For example
ff_print_debug_info() uses the following formula:
(s->mb_width << mv_sample_log2) + (s->codec_id == CODEC_ID_H264 ? 0 : 1)
# Finally, is there any way to populate the AVFrame.motion_val array
with the motion vectors without having the motion vectors visualized on
the decoded video frame? I'm setting AVCodecContext.debug_mv = 1 to
obtain the motion vectors but as a side effect that flag also draws the
motion vectors. It looks like ff_print_debug_info() always draws the
motion vectors when the debug_mv flag is set. It seems wasteful to have
to decode the video twice in order to obtain the motion vectors and the
video frames without the visualization.
Thank you for your time.
-pro
More information about the ffmpeg-devel
mailing list