Extracting motion vectors from an H.264 stream

I am looking for an open source tool / code or some kind of guide for extracting motion vectors (MV) of an encoded H.264 bit sequence. I already know 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 create a log file in which frames with frames from P and B are listed. I checked the MVs structure from libavutil / motion_vector.h, but I could not find an example that shows how they are extracted and stacked on top of the original sequence using ffplay. I thought that if I could figure this out, I could reinstall the code to extract the MVs into a text file.

I also tried the code provided in this answer , but it does not work with newer versions of ffmpeg:

I would appreciate any examples of codes or hints.

+5
source share
1 answer

The source code for the video codec filter is here , is that what you are looking for?

[edit] Sorry, I think this is not very useful. The function you are looking for is filter_frame () , which shows you how to read AVMotionVectors (as collateral data) from a given AVFrame, this is the code used in your command line example. This example calls draw_arrow (), but you can simply replace it with a call to printf () or some custom function that logs the MV information in the log file you select.

+8
source

All Articles