如何使用python遮罩

时间:2019-01-25 18:10:35

标签: python-3.x

在我的代码中,我试图在视频文件中找到一个成功完成的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)

0 个答案:

没有答案