当前位置: 首页>>代码示例>>Python>>正文


Python BitStream.bytepos方法代码示例

本文整理汇总了Python中bitstring.BitStream.bytepos方法的典型用法代码示例。如果您正苦于以下问题:Python BitStream.bytepos方法的具体用法?Python BitStream.bytepos怎么用?Python BitStream.bytepos使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在bitstring.BitStream的用法示例。


在下文中一共展示了BitStream.bytepos方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: __init__

# 需要导入模块: from bitstring import BitStream [as 别名]
# 或者: from bitstring.BitStream import bytepos [as 别名]
    def __init__(self, data, ts_packets):
        self.bytes = data
        first_ts = ts_packets[0]
        self.pid = first_ts.pid
        self.byte_offset = first_ts.byte_offset
        self.size = len(ts_packets) * TSPacket.SIZE
        self.random_access = first_ts.random_access_indicator

        self.ts_packets = ts_packets
        data = BitStream(data)

        start_code = data.read("uint:24")
        if start_code != 0x000001:
            raise Exception("packet_start_code_prefix is 0x{:06X} but should "
                            "be 0x000001".format(start_code))

        self.stream_id = data.read("uint:8")
        pes_packet_length = data.read("uint:16")

        if StreamID.has_pes_header(self.stream_id):
            bits = data.read("uint:2")
            if bits != 2:
                raise Exception("First 2 bits of a PES header should be 0x2 "
                                "but saw 0x{:02X}'".format(bits))

            self.pes_scrambling_control = data.read("uint:2")
            self.pes_priority = data.read("bool")
            self.data_alignment_indicator = data.read("bool")
            self.copyright = data.read("bool")
            self.original_or_copy = data.read("bool")
            pts_dts_flags = data.read("uint:2")
            escr_flag = data.read("bool")
            es_rate_flag = data.read("bool")
            dsm_trick_mode_flag = data.read("bool")
            additional_copy_info_flag = data.read("bool")
            pes_crc_flag = data.read("bool")
            pes_extension_flag = data.read("bool")
            pes_header_data_length = data.read("uint:8")

            if pts_dts_flags & 2:
                bits = data.read("uint:4")
                if bits != pts_dts_flags:
                    raise Exception(
                        "2 bits before PTS should be 0x{:02X} but saw 0x{"
                        ":02X}".format(pts_dts_flags, bits))
                self.pts = read_timestamp("PTS", data)

            if pts_dts_flags & 1:
                bits = data.read("uint:4")
                if bits != 0x1:
                    raise Exception("2 bits before DTS should be 0x1 but saw "
                                    "0x{:02X}".format(bits))
                self.dts = read_timestamp("DTS", data)

            # skip the rest of the header and stuffing bytes
            data.bytepos = pes_header_data_length + 9
        if self.stream_id == StreamID.PADDING:
            self.payload = None
        else:
            self.payload = data.read("bytes")
开发者ID:brendanlong,项目名称:mpeg-ts-inspector,代码行数:62,代码来源:ts.py

示例2: parse

# 需要导入模块: from bitstring import BitStream [as 别名]
# 或者: from bitstring.BitStream import bytepos [as 别名]
    def parse(self):
        bs = BitStream(filename=self.file_path)
        [index_start, extension_data_start] = parse_header(bs)
        self.app_info = parse_app_info(bs)

        bs.bytepos = index_start
        self.indexes = parse_index(bs)
        self.parsed = True
开发者ID:chengyuhui,项目名称:pybluray,代码行数:10,代码来源:index_parser.py

示例3: parse

# 需要导入模块: from bitstring import BitStream [as 别名]
# 或者: from bitstring.BitStream import bytepos [as 别名]
    def parse(data, byte_offset):
        ts = TSPacket(None)
        ts.byte_offset = byte_offset

        data = BitStream(data)
        sync_byte = data.read("uint:8")
        if sync_byte != TSPacket.SYNC_BYTE:
            raise Exception(
                "First byte of TS packet at offset {} is not a sync byte."
                .format(byte_offset))

        ts.transport_error_indicator = data.read("bool")
        ts.payload_unit_start_indicator = data.read("bool")
        ts.transport_priority = data.read("bool")
        ts.pid = data.read("uint:13")
        ts.scrambling_control = data.read("uint:2")

        # adaptation_field_control
        has_adaptation_field = data.read("bool")
        has_payload = data.read("bool")

        ts.continuity_counter = data.read("uint:4")
        if has_adaptation_field:
            adaptation_field_length = data.read("uint:8")
            if adaptation_field_length:
                ts.discontinuity_indicator = data.read("bool")
                ts.random_access_indicator = data.read("bool")
                ts.elementary_stream_priority_indicator = data.read("bool")
                pcr_flag = data.read("bool")
                opcr_flag = data.read("bool")
                splicing_point_flag = data.read("bool")
                transport_private_data_flag = data.read("bool")
                adaptation_field_extension_flag = data.read("bool")

                if pcr_flag:
                    ts.program_clock_reference_base = data.read("uint:33")
                    data.read(6)  # reserved
                    ts.program_clock_reference_extension = data.read("uint:9")

                if opcr_flag:
                    ts.original_program_clock_reference_base = data.read(
                        "uint:33")
                    data.read(6)  # reserved
                    ts.original_program_clock_reference_extension = data.read(
                        "uint:9")

                if splicing_point_flag:
                    ts.splice_countdown = data.read("uint:8")

                if transport_private_data_flag:
                    transport_private_data_length = data.read("uint:8")
                    ts.private_data = data.read(
                        transport_private_data_length * 8).bytes

                if adaptation_field_extension_flag:
                    adaptation_field_extension_length = data.read("uint:8")
                    ltw_flag = data.read("bool")
                    piecewise_rate_flag = data.read("bool")
                    seamless_splice_flag = data.read("bool")
                    data.read(5)  # reserved

                    if ltw_flag:
                        ts.ltw_valid_flag = data.read("bool")
                        ts.ltw_offset = data.read("uint:15")

                    if piecewise_rate_flag:
                        data.read(2)  # reserved
                        ts.piecewise_rate = data.read("uint:22")

                    if seamless_splice_flag:
                        ts.splice_type = data.read("uint:4")
                        ts.dts_next_au = read_timestamp("DTS_next_AU", data)

                # Skip the rest of the header and padding bytes
                data.bytepos = adaptation_field_length + 5

        if has_payload:
            ts.payload = data.read("bytes")
        return ts
开发者ID:brendanlong,项目名称:mpeg-ts-inspector,代码行数:81,代码来源:ts.py


注:本文中的bitstring.BitStream.bytepos方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。