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

Allow PyAV to export motion vector map #715

Open
SuX97 opened this issue Oct 28, 2020 · 1 comment
Open

Allow PyAV to export motion vector map #715

SuX97 opened this issue Oct 28, 2020 · 1 comment
Labels

Comments

@SuX97
Copy link

@SuX97 SuX97 commented Oct 28, 2020

IMPORTANT: Be sure to replace all template sections {{ like this }} or your issue may be discarded.

Overview

{{ Hi, I have noticed that there are not usage example of how to get the motion vector, and the only clue I have got lies here in the unittest. Could you please show a standard and efficient usage of transfer a motion vector into a mv map? Namely the motion offset of each pixel, a matrixs of size (2, height, weight)?

A simple implementation can be this, but it use a nested loop on each pixel, seems inefficient. }}

Desired Behavior

{{

    def test_decoded_motion_vectors(self):

        container = av.open(fate_suite('h264/interlaced_crop.mp4'))
        stream = container.streams.video[0]
        codec_context = stream.codec_context
        codec_context.options = {"flags2": "+export_mvs"}

        for packet in container.demux(stream):
            for frame in packet.decode():
                vectors = frame.side_data.get('MOTION_VECTORS')
                vectors_map = frame.side_data.parse_mv(vectors)# TODO
                if frame.key_frame:
                    # Key frame don't have motion vectors
                    assert vectors is None
                else:
                    assert len(vectors) > 0
                    return

}}

Example API

{{
def parse_mv(vector) -> np.ndarray:
Args:
    vector: np.ndarray, [(-1, src_x, src_y, dst_x, dst_y, motion_x, ...), ()..]
Returns:
    np.ndarray: of shape (2, h, w) 
}}

Additional context

{{ Add any other context about the problem here. }}

@SuX97 SuX97 added the enhancement label Oct 28, 2020
@YuqiHUO
Copy link

@YuqiHUO YuqiHUO commented Nov 2, 2020

hi, im interested in this feature, what do you think of two-source of [-1] and [+1] of B-frames? does it need to return two mv maps of the previous and the next frame?

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

Successfully merging a pull request may close this issue.

None yet
2 participants