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


Python BitStream.tobytes方法代码示例

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


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

示例1: __init__

# 需要导入模块: from bitstring import BitStream [as 别名]
# 或者: from bitstring.BitStream import tobytes [as 别名]
class BitWriter:
    def __init__(self):
        self._bytes = ""
        self._bits = BitStream()

    def write_int(self, length, value):
        news = BitStream(uint=value, length=length)
        start = 0

        if self._bits.len > 0:
            left = 8 - self._bits.len
            if news.len < left:
                left = news.len
            self._bits = news[:left] + self._bits
            start += left

            if self._bits.len == 8:
                self._bytes += self._bits.tobytes()
                self._bits = BitStream()

        byte_len = (news.len - start) / 8
        if byte_len > 0:
            more = byte_len * 8
            self._bytes += news[start:start+more].tobytes()
            start += more

        if news.len > start:
            self._bits = news[start:]

    def write_int64(self, length, value):
        if length <= 32:
            self.write_int(length, value)
            return
        count = length - 32
        self.write_int(32, value >> count)
        self.write_int(count, value & ((1 << count) - 1))

    def write_char_array(self, max_length, value):
        self.write_int(bit_count(max_length), len(value))
        if self._bits.len > 0:
            more = 8 - self._bits.len
            tail = (BitStream(int=0, length=more) + self._bits).tobytes()
            self._bits = BitStream()
            self._bytes += tail
        self._bytes += value

    def get_bytes(self):
        if self._bits.len > 0:
            more = 8 - self._bits.len
            tail = (BitStream(int=0, length=more) + self._bits).tobytes()
            return self._bytes + tail
        else:
            return self._bytes
开发者ID:smallka,项目名称:piablo,代码行数:55,代码来源:bit_writer.py

示例2: __init__

# 需要导入模块: from bitstring import BitStream [as 别名]
# 或者: from bitstring.BitStream import tobytes [as 别名]

#.........这里部分代码省略.........
                pass
            return True
        except ReadError:
            return False

    def rbsp_trailing_bits(self):
        pos = self.rbsp_byte.pos
        bits = self.rbsp_byte.bytealign()
        self.rbsp_byte.pos = pos
        if bits == 0 or self.rbsp_read('uint: %d' % bits) != 1 << bits:
            print('Wrong rbsp_trailing_bits at NALU begined at bytes %d' % self.pos)
            exit(1)

    def profile_tier_level(self, ProfilePresentFlag, MaxNumSubLayersMinus1):
        if ProfilePresentFlag:
            self.general_profile_space = self.rbsp_read('uint: 2')
            self.general_tier_flag = self.rbsp_read('uint: 1')
            self.general_profile_idc = self.rbsp_read('uint: 5')
            self.general_profile_compatibility_flag = [0] * 32
            for i in range(0, 32):
                self.general_profile_compatibility_flag[i] = self.rbsp_read("uint: 1")
            self.general_reserved_zero_16bits = self.rbsp_read('uint: 16')
        self.general_level_idc = self.rbsp_read('uint: 8')
        self.sub_layer_profile_present_flag = [0] * MaxNumSubLayersMinus1
        self.sub_layer_level_present_flag = [0] * MaxNumSubLayersMinus1
        self.sub_layer_profile_space = [0] * MaxNumSubLayersMinus1
        self.sub_layer_tier_flag = [0] * MaxNumSubLayersMinus1
        self.sub_layer_profile_idc = [0] * MaxNumSubLayersMinus1
        self.sub_layer_reserved_zero_16bits = [0] * MaxNumSubLayersMinus1
        self.sub_layer_level_idc = [0] * MaxNumSubLayersMinus1
        self.sub_layer_profile_compatibility_flag = [[0] * 32] * MaxNumSubLayersMinus1
        for i in range(0, MaxNumSubLayersMinus1):
            self.sub_layer_profile_present_flag[i] = self.rbsp_read('uint: 1')
            self.sub_layer_level_present_flag[i] = self.rbsp_read('uint: 1')
            if ProfilePresentFlag and self.sub_layer_profile_present_flag[i]:
                self.sub_layer_profile_space[i] = self.rbsp_read('uint: 2')
                self.sub_layer_tier_flag[i] = self.rbsp_read('uint: 1')
                self.sub_layer_profile_idc[i] = self.rbsp_read('uint: 5')
                for j in range(0, 32):
                    self.sub_layer_profile_compatibility_flag[i][j] = self.rbsp_read('uint: 1')
                self.sub_layer_reserved_zero_16bits[i] = self.rbsp_read('uint: 16')
            if self.sub_layer_level_present_flag[i]:
                self.sub_layer_level_idc[i] = self.rbsp_read('uint: 8')

    def op_point(self, opIdx):
        self.op_num_layer_id_values_minus1 = [opIdx] = self.rbsp_read('ue')
        self.op_layer_id[opIdx] = [0] * self.op_num_layer_id_values_minus1
        for i in range(0, self.op_num_layer_id_values_minus1):
            self.op_layer_id[opIdx][i] = self.rbsp_read('uint: 6')

    def short_term_ref_pic_set(self, idxRps):
        if idxRps != 0:
            self.inter_ref__pic_set_prediction_flag = self.rbsp_read('uint: 1')
        else:
            self.inter_ref__pic_set_prediction_flag = 0
        if self.inter_ref__pic_set_prediction_flag:
            if idxRps == self.num_short_term_ref_pic_sets:
                self.delta_idx_minus1 = self.rbsp_read('ue')
            else:
                self.delta_idx_minus1 = 0
            RIdx = idxRps - self.delta_idx_minus1 - 1
            self.delta_rps_sign = self.rbsp_read('uint: 1')
            self.abs_delta_rps_minus1 = self.rbsp_read('ue')
            self.used_by_curr_pic_flag = [0] * (self.NumDeltaPocs[RIdx] + 1)
            self.use_delta_flag = [0] * (self.NumDeltaPocs[RIdx] + 1)
            for i in range(0, self.NumDeltaPocs[RIdx] + 1):
                self.used_by_curr_pic_flag[i] = self.rbsp_read('uint: 1')
                if not self.used_by_currpic_flag[i]:
                    self.use_delta_flag[i] = self.rbsp_read('uint: 1')
        else:
            num_negative_pics = self.rbsp_read('ue')
            num_positive_pics = self.rbsp_read('ue')
            self.delta_poc_s0_minus1 = [0] * num_negative_pics
            self.used_by_curr_pic_s0_flag = [0] * num_negative_pics
            for i in range(0, num_negative_pics):
                self.delta_poc_s0_minus1[i] = self.rbsp_read('ue')
                self.used_by_curr_pic_s0_flag[i] = self.rbsp_read('uint: 1')
            self.delta_poc_s1_minus1 = [0] * num_positive_pics
            self.used_by_curr_pic_s1_flag = [0] * num_positive_pics
            for i in range(0, num_positive_pics):
                self.delta_poc_s1_minus1[i] = self.rbsp_read('ue')
                self.used_by_curr_pic_s1_flag[i] = self.rbsp_read('uint: 1')
            self.NumDeltaPocs[idxRps] = num_negative_pics + num_positive_pics

    def setup(self):
        pass

    def __str__(self):
        return 'NALU:  pos=%d, length=%d, type=%s, tid=%d' % (self.pos, self.num_bytes_in_nalu, NAL_UNIT_TYPE[self.nal_unit_type], self.temporal_id)

    def print_bin(self):
        i = 1
        for abyte in self.rbsp_byte.tobytes():
            if i == 16:
                print('%3s' % hex(abyte)[2: ])
                i = 1
            else:
                print('%3s' % hex(abyte)[2: ], end=' ')
                i += 1
        print('\n')
开发者ID:zhang-xin,项目名称:bitstream-reader,代码行数:104,代码来源:nalunit.py


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