5

I'm looking for an open-source tool/code or some guidance to extract the motion vectors (MVs) of a H.264 encoded bit sequence. I'm already aware that motion vectors can be visualized using ffmpeg with the following command:

ffplay -flags2 +export_mvs input.mp4 -vf codecview=mv=pf+bf+bb

However, I want to produce a log file where the MVs of P and B frames are listed frame by frame. I checked out the structure of MVs from libavutil/motion_vector.h, but I couldn't find an example which shows how they are extracted and laid over the original sequence by ffplay. I thought that if I can find that out, I could possibly re-arrange the code to extract the MVs to a text file.

I also tried the code given in this answer, but it doesn't seem to work with the newer versions of ffmpeg:

I would appreciate any example codes or hints.

Community
  • 1
  • 1
chronosynclastic
  • 1,585
  • 3
  • 19
  • 40
  • Asking for tutorials, tools and libraries is off-topic for Stack Overflow (see [help]). Also note that [ffplay source code](https://www.ffmpeg.org/doxygen/trunk/ffplay_8c-source.html) is licensed under LGPL and it's available. – Adriano Repetti Jul 22 '15 at 07:33
  • 2
    He is also asking for code / guidance, so a more helpful action would have been to provide some code samples. – Luca Nov 09 '15 at 16:34

1 Answers1

8

The source code for the codecview video filter is here, is that what you're looking for?

[edit] Sorry I guess that's not terribly helpful. The function you're looking for is filter_frame(), which shows you how to read AVMotionVectors (as side-data) from a given AVFrame, this is the code used in your commandline example. This example calls draw_arrow(), but you can simply replace that with a call to printf() or some custom function that logs the MV information to a logfile of your choosing.

Ronald S. Bultje
  • 10,828
  • 26
  • 47
  • Hi, can you please give some more details as to how we could use AVMotionVectors in MATLAB. Your answer does give some hint but i'm blocked for the usage. How to get this in Matlab. There is very little info online about that. – Vishnu Narang Sep 05 '16 at 03:14
  • I would ask a new question with some more detail, I don't know how you want to input data in matlab or what you're blocked on exactly. – Ronald S. Bultje Sep 05 '16 at 10:19