FFmpeg get motion vectors without decoding the video

Viewed 971

I would like to access the motion vectors of an h264 video stream without decoding the video. I know that this show the video and the motion vectors:

ffplay -i myvideo.avi -flags2 +export_mvs -vf codecview=mv=pf+bf+bb

How can I avoid decoding the entire video to save CPU? The reason I want to do that is that I’ll then need to parse this data in Python.

EDIT I tried using ffprobe with

ffprobe -i my_video.mp4 -flags2 +export_mvs -print_format json -show_frames

It prints many information:

  {
            "media_type": "video",
            "stream_index": 0,
            "key_frame": 0,
            "pkt_pts": 2513990,
            "pkt_pts_time": "27.933222",
            "pkt_dts": 2510990,
            "pkt_dts_time": "27.899889",
            "best_effort_timestamp": 2513990,
            "best_effort_timestamp_time": "27.933222",
            "pkt_duration": 3000,
            "pkt_duration_time": "0.033333",
            "pkt_pos": "1157994",
            "pkt_size": "262",
            "width": 1280,
            "height": 720,
            "pix_fmt": "yuvj420p",
            "sample_aspect_ratio": "1:1",
            "pict_type": "P",
            "coded_picture_number": 559,
            "display_picture_number": 0,
            "interlaced_frame": 0,
            "top_field_first": 0,
            "repeat_pict": 0,
            "color_range": "pc",
            "color_space": "bt709",
            "color_primaries": "bt709",
            "color_transfer": "bt709",
            "chroma_location": "left",
            "side_data_list": [
                {
                    "side_data_type": "Motion vectors"
                }
            ]
        },

As you can side, Motion vectors are mentioned in the side_data_type. How can I print them? I tried with

ffprobe -i my_video.mp4 -flags2 +export_mvs -print_format json -show_frames -show_entries side_data="Motion vectors" 

but it does not seem to add any information. I could change "Motion vectors" to any other value without errors so I guess that's not point to the correct data.

0 Answers
Related