简体   繁体   English

如何使用h.264参考软件在Python中提取运动矢量

[英]How to use h.264 Reference Software to extract motion vectors in Python

I'm trying to decode an h.264 video so that I can access the motion vectors. 我正在尝试解码h.264视频,以便可以访问运动矢量。 I found the reference software: 我找到了参考软件:

http://iphome.hhi.de/suehring/tml/download/ http://iphome.hhi.de/suehring/tml/download/

but I'm having difficulty implementing this in python to parse out the relevant data that I want. 但是我很难在python中实现此功能以解析出我想要的相关数据。 What is a good way to approach this problem? 解决这个问题的好方法是什么?

Parsing H.264 in Python can be done, but it's usually not the best tool for the job. 可以用Python解析H.264,但是通常它并不是完成这项工作的最佳工具。 If you really do want to use it you should start with the H.264 standard, not the reference software, although having both to hand is useful. 如果确实要使用它,则应该从H.264标准开始,而不是从参考软件开始,尽管两者都有用。

As I said Python isn't well suited to decoding video so there isn't much out there to help you. 正如我所说的,Python不太适合解码视频,因此没有太多帮助您的东西。 I have used it in the past to get or change the odd parameter and wrote a module ( bitstring ) to help. 我过去曾使用它来获取或更改奇数参数,并编写了一个模块( bitstring )来提供帮助。 There is an example of parsing a H.264 structure in the documentation : 文档中有一个解析H.264结构的示例:

This example creates a class that parses a structure that is part of the H.264 video standard. 本示例创建一个类,该类分析作为H.264视频标准一部分的结构。

class seq_parameter_set_data(object):
    def __init__(self, s):
        """Interpret next bits in BitString s as an SPS."""
        # Read and interpret bits in a single expression:
        self.profile_idc = s.read('uint:8')
        # Multiple reads in one go returns a list:
        self.constraint_flags = s.readlist('4*uint:1')
        self.reserved_zero_4bits = s.read('bin:4')
        self.level_idc = s.read('uint:8')
        self.seq_parameter_set_id = s.read('ue')
        if self.profile_idc in [100, 110, 122, 244, 44, 83, 86]:
            self.chroma_format_idc = s.read('ue')
            if self.chroma_format_idc == 3:
                self.separate_colour_plane_flag = s.read('uint:1')
            self.bit_depth_luma_minus8 = s.read('ue')
            self.bit_depth_chroma_minus8 = s.read('ue')
            # etc.

>>> s = BitStream('0x6410281bc0')
>>> sps = seq_parameter_set_data(s)
>>> print(sps.profile_idc)
100
>>> print(sps.level_idc)
40
>>> print(sps.reserved_zero_4bits)
0b0000
>>> print(sps.constraint_flags)
[0, 0, 0, 1]

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM