2010年1月26日

code :Transport Stream continuity check

今天的進度: 找出所有的 pid

from struct import *

tsfile = open('logOsv17.trp','rb')
if tsfile == None:
print "Error opening logOsv17.trp to read"
tsstring = tsfile.read()
print "the size is : %d" % len(tsstring)

tsdata = unpack(repr(len(tsstring))+'B',tsstring)
print "%02x %02x %02x" % (tsdata[0],tsdata[1],tsdata[2])


prev0x47=0
i=0
while tsdata[0] != 0x47:
i += 1
print "found 1st 0x47: %d %02x" % (i,tsdata[i+188])

pidtable = []
while i < len(tsdata)-188:
pid = tsdata[i+1]<<8 | tsdata[i+2]
pid = pid & 0x1FFF
# print "%02x %02x (%04x) - %02x" % (tsdata[i+1],tsdata[i+2],pid,tsdata[i+3]&0x0F)
if pid not in pidtable:
pidtable.append(pid)

if tsdata[i+188] != 0x47:
print "%d : %02x" % (i,tsdata[i+188])
i+=1
while tsdata[i] != 0x47:
i += 1
else:
i += 188
pidtable.sort()
for i in pidtable:
print "%04x" % i

沒有留言:

張貼留言