在我的代码中,我试图在一个视频文件中找到一个pid,我已经成功地完成了这项工作,并将其放入列表pid中。然后我试图屏蔽pid,但不能,因为列表中的元素是字符串。
我尝试使用int()将字符串元素转换为int,但是这会更改变量的值或外观。因此,我尝试使用HEX()函数将其转换成十六进制数值,但它仍然是一个字符串。
#Open video file
with open('C:\\Users\\hello\\Desktop\\SyncVidWork\\bbb_360p_c.ts', 'rb') as f:
count = 0
PID = []
syncdata1 = []
syncdata = f.seek(0)
#This loop identifies the sync byte
#If not the end of the file, loop
while syncdata1 != '':
#Read throught the entire packet
w1 = [f.read(1).hex() for i in range(188)]
#If 1st element is hex 47: continue
if w1[0] == '47':
#print the first 3 elements of the list packet
print("***********")
print(w1[0])
print(w1[1])
print(w1[2])
print("***********")
#Put the PID into a separate list and convert to hex
PID.append(w1[1] + w1[2])
PID[count] = (hex(int(PID[count], 16)))
print(PID)
#Masking the PID
print(PID[count] & 0x80 >> 7)
#Incrementing the counter
count += 1
print(count)
#Move to the next packet
syncdata = f.seek(187, 1)