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

时间:2022-05-13 15:28:27

I'm trying to decode an h.264 video so that I can access the motion vectors. I found the reference software:

我正在尝试解码h.264视频,以便我可以访问运动矢量。我找到了参考软件:

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. What is a good way to approach this problem?

但我在python中实现这个很难解析出我想要的相关数据。解决这个问题的好方法是什么?

1 个解决方案

#1


Parsing H.264 in Python can be done, but it's usually not the best tool for the job. 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.

用Python解析H.264可以做到,但它通常不是最好的工具。如果你确实想要使用它,你应该从H.264标准开始,而不是参考软件,尽管双手都很有用。

As I said Python isn't well suited to decoding video so there isn't much out there to help you. I have used it in the past to get or change the odd parameter and wrote a module (bitstring) to help. There is an example of parsing a H.264 structure in the documentation:

正如我所说,Python不太适合解码视频,所以没有太多可以帮助你。我过去曾用它来获取或更改奇数参数并编写了一个模块(bitstring)来帮助。在文档中有一个解析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]

#1


Parsing H.264 in Python can be done, but it's usually not the best tool for the job. 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.

用Python解析H.264可以做到,但它通常不是最好的工具。如果你确实想要使用它,你应该从H.264标准开始,而不是参考软件,尽管双手都很有用。

As I said Python isn't well suited to decoding video so there isn't much out there to help you. I have used it in the past to get or change the odd parameter and wrote a module (bitstring) to help. There is an example of parsing a H.264 structure in the documentation:

正如我所说,Python不太适合解码视频,所以没有太多可以帮助你。我过去曾用它来获取或更改奇数参数并编写了一个模块(bitstring)来帮助。在文档中有一个解析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]