社区所有版块导航
Python
python开源   Django   Python   DjangoApp   pycharm  
DATA
docker   Elasticsearch  
aigc
aigc   chatgpt  
WEB开发
linux   MongoDB   Redis   DATABASE   NGINX   其他Web框架   web工具   zookeeper   tornado   NoSql   Bootstrap   js   peewee   Git   bottle   IE   MQ   Jquery  
机器学习
机器学习算法  
Python88.com
反馈   公告   社区推广  
产品
短视频  
印度
印度  
Py学习  »  Python

如何使用python屏蔽

Nathan • 5 年前 • 595 次点击  

在我的代码中,我试图在一个视频文件中找到一个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)
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/47376
 
595 次点击