Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extract motion vectors #38

Open
adrianmay opened this issue Jun 22, 2020 · 4 comments
Open

Extract motion vectors #38

adrianmay opened this issue Jun 22, 2020 · 4 comments

Comments

@adrianmay
Copy link

Hi there,

I'm looking for a very fast way to extract motion vectors from an h264 stream inside some container. I just need the x,y coordinates of the block and it's dx,dy movement. I'd like to cut out any CPU time not contributing to the motion vectors. The data is coming from ffmpeg (encoding as h264 in hardware) so I can set the container format to anything.

Is this repo what I'm after?

Please excuse my ignorance of h264 but I can't answer this question by looking at the code, nor would I know how to do it if you just said "yes", so some guidance would be very much appreciated.

I know this isn't really an "issue" but github seem to have disabled all other forms of messaging.

TIA, Adrian.

@aizvorski
Copy link
Owner

aizvorski commented Jul 11, 2020

Hi Adrian - Thanks for asking. The MVs are contained in the slice data - decoding is not currently supported, as this library mostly works with header data. There is some work-in-progress code, please see #8. If you want to dig into that, that would be great, but it is going to be quite a lot of work - mainly because this code doesn't have working CABAC (yet).

There are some possibly better starting points:

Note that in addition to the MVs, you will at a minimum need the macroblock types, partitioning modes and likely the reference frames as well. It is simpler than fully decoding the video (no DCT, no motion compensation) but not hugely simpler.

I'm interested in this as well, please let me know how you solve this.

@lbdroid
Copy link

lbdroid commented Jul 15, 2020

I believe that there would be a huge demand for this feature if it were to be implemented. In particular, I'd like to be able to apply this to motion detection in the field of physical security. Motion detection in open source software currently requires full decompression and frame-by-frame analysis, and the CPU cost is near prohibitive.

If motion vectors could be extracted from the compressed domain, it would allow high resolution and high frame rate motion detection even on very low end hardware.

@aizvorski
Copy link
Owner

@lbdroid Indeed, that would be useful. I can offer to do this feature as a bounty, as it involves a significant effort - please contact me at aizvorski at gmail if you're interested.

@isra60
Copy link

isra60 commented Nov 5, 2024

If my goal is simply to detect the presence of motion—without needing to measure the magnitude or direction of that motion—would there be a simpler or faster way to obtain this information from the H.264 bitstream? Maybe it is no neccesary to even decode the mv, right? I'm pointing to detect frozen image on the input of the encoder by analyzing it's output

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants