Example #1
0
def parse_tspacket(packet, packetnum):
    three_bytes = BitBin(packet[:3])
    tei = three_bytes.asflag(1)
    pusi = three_bytes.asflag(1)
    ts_priority = three_bytes.asflag(1)
    pid = three_bytes.asint(13)
    if pusi:
        parse_pes(packet, packetnum)
Example #2
0
def parse_pes(packet, packetnum):
    bb = BitBin(packet[3:])
    if bb.asint(24) == 1 and bb.asint(8) not in NON_PTS_STREAM_IDS:
        PES_packet_length = bb.asint(16)
        if bb.asint(2) == 2:
            bb.asint(6)
            if bb.asint(2) in [2, 3]:
                bb.asint(14)
                if bb.asint(4) in [2, 3]:
                    to33 = bb.asint(3) << 30
                    bb.asflag(1)
                    to30 = bb.asint(15) << 15
                    bs.asflag(1)
                    to15 = bb.asint(15)
                    d = to33 + to30 + to15
                    print(f" PTS {d/90000:.6f} on Packet {packetnum}")
Example #3
0
 def decode(self, bites):
     bitbin = BitBin(bites)
     self.table_id = bitbin.ashex(8)
     if self.table_id != "0xfc":
         to_stderr("splice info section table id should be 0xfc")
     self.section_syntax_indicator = bitbin.asflag(1)
     self.private = bitbin.asflag(1)
     self.reserved = bitbin.ashex(2)
     if self.reserved != "0x3":
         to_stderr("splice info section reserved should be 0x3")
     self.section_length = bitbin.asint(12)
     self.protocol_version = bitbin.asint(8)
     if self.protocol_version != 0:
         to_stderr("splice info section protocol version should be 0")
     self.encrypted_packet = bitbin.asflag(1)
     self.encryption_algorithm = bitbin.asint(6)
     self.pts_adjustment = bitbin.as90k(33)
     self.cw_index = bitbin.ashex(8)
     self.tier = bitbin.ashex(12)
     self.splice_command_length = bitbin.asint(12)
     self.splice_command_type = bitbin.asint(8)
     self.descriptor_loop_length = 0
Example #4
0
 def decode(self):
     """
     decode a segmentation descriptor
     """
     bitbin = BitBin(self.bites)
     self.parse_id(bitbin)
     self.segmentation_event_id = bitbin.ashex(32)  # 4 bytes
     self.segmentation_event_cancel_indicator = bitbin.asflag(1)
     bitbin.forward(7)  # 1 byte
     if not self.segmentation_event_cancel_indicator:
         self._decode_flags(bitbin)  # 1 byte
         if not self.program_segmentation_flag:
             self._decode_components(bitbin)
         self._decode_segmentation(bitbin)
 def decode(self, bites):
     bitbin = BitBin(bites)
     self.table_id = bitbin.ashex(8)
     if self.table_id != '0xfc':
         raise ValueError('splice_info_section.table_id should be 0xfc')
     self.section_syntax_indicator = bitbin.asflag(1)
     self.private = bitbin.asflag(1)
     self.reserved = bitbin.ashex(2)
     if self.reserved != '0x3':
         raise ValueError('splice_info_section.reserved should be 0x3')
     self.section_length = bitbin.asint(12)
     self.protocol_version = bitbin.asint(8)
     if self.protocol_version != 0:
         raise ValueError(
             'splice_info_section.protocol_version should be 0')
     self.encrypted_packet = bitbin.asflag(1)
     self.encryption_algorithm = bitbin.asint(6)
     self.pts_adjustment = bitbin.as90k(33)
     self.cw_index = bitbin.ashex(8)
     self.tier = bitbin.ashex(12)
     self.splice_command_length = bitbin.asint(12)
     self.splice_command_type = bitbin.asint(8)
     self.descriptor_loop_length = 0
Example #6
0
 def decode(self):
     """
     Decode SCTE35 Audio Descriptor
     """
     bitbin = BitBin(self.bites)
     self.parse_id(bitbin)
     self.audio_count = a_c = bitbin.asint(4)
     bitbin.forward(4)
     while a_c:
         a_c -= 1
         comp = {}
         comp["component_tag"] = bitbin.asint(8)
         comp["ISO_code="] = bitbin.asint(24)
         comp["bit_stream_mode"] = bitbin.asint(3)
         comp["num_channels"] = bitbin.asint(4)
         comp["full_srvc_audio"] = bitbin.asflag(1)
         self.components.append(comp)
Example #7
0
 def decode(self):
     """
     SpliceInsert.decode
     """
     bitbin = BitBin(self.bites)
     start = bitbin.idx
     self.splice_event_id = bitbin.asint(32)
     self.splice_event_cancel_indicator = bitbin.asflag(1)
     bitbin.forward(7)
     if not self.splice_event_cancel_indicator:
         self._decode_flags(bitbin)
         if self.program_splice_flag:
             if not self.splice_immediate_flag:
                 self._decode_pts(bitbin)
         else:
             self._decode_components(bitbin)
             if not self.splice_immediate_flag:
                 self._decode_pts(bitbin)
         if self.duration_flag:
             self._decode_break(bitbin)
         self.unique_program_id = bitbin.asint(16)
         self.avail_num = bitbin.asint(8)
         self.avail_expected = bitbin.asint(8)
     self._set_len(start, bitbin.idx)