2

I'm using ffmpeg to extract motion vectors using the example doc extract_mvs.c. Issue is that this code only seems to give a few pieces of information: frame number, size of macroblock, source (future or past), source (x and y), and destination (x and y).

Unfortunately, this doesn't say which frame the source comes from in the past or the future (it could come from both, from several past, or several in the future). It also doesn't say what the macroblock type is (which tells similarly useful info). For example, if Source (x and y) equals Destination (x and y) it is impossible to tell if that information is the same as the last frame or if it entered completely new information.

See lines 60-63 in the extract_mvs.c code in ffmpeg

Final question is that for MP4, motion vectors generally have quarter pixel resolution and the resolution given here is clearly rounded to the closest integer. How am I supposed to extract the "true" motion vector information before rounding?

aergistal
  • 29,947
  • 5
  • 70
  • 92
Loo Yung
  • 43
  • 7
  • If you want more information in the exposed motion vector API, you'll probably have to patch FFmpeg to give more information, send a patch upstream. Right now, there's no way to get the information you're looking for. – Ronald S. Bultje May 21 '15 at 15:12
  • @loo-yung Could you please let me know how you used motionVector source to extract motion vector. I have been searching internet for some reference to extract motion vector. – Dhananjayan Santhanakrishnan Sep 12 '16 at 08:50

1 Answers1

1

The source (future or past) is based on a relative frame reference given by the direction parameter to add_mb(), but I'm not sure what to make of the logic:

mb->source = direction ? 1 : -1;

In libavutil/motion_vector.h there's a comment, XXX: set exact relative ref frame reference instead of a +/- 1 "direction", so it looks like a known TODO not addressed by the creator of the patch. The value of direction comes from ff_print_debug_info2() where add_mb() is called.

As for the quarter pixels, I think this is also in ff_print_debug_info2() but I don't know enough about motion_val to say what it means:

        const int shift = 1 + quarter_sample;
...
                      int mx = (motion_val[direction][xy][0]>>shift) + sx;
                      int my = (motion_val[direction][xy][1]>>shift) + sy;

The initial commit shows all the major pieces of this motion vector code. Hopefully this gets you going in the right direction (no pun intended).

Cedar Myers
  • 418
  • 5
  • 5