1 回答
TA贡献1824条经验 获得超6个赞
ws = create_connection(url, headers=headers)
# Then send a message through the tunnel
ws.send('ping')
start = timeit.default_timer()
flag = True
output = []
while flag:
output.append(ws.recv())
if timeit.default_timer() - start > 90:
flag = False
result = output[0][8:]
for msg in output[1:]:
if msg[0] == 249:
moofmdat = b''
moof = b''
continue
if msg[0] == 252:
vidbuf = msg[4:]
if msg[0] == 251:
moof += msg[4:]
if msg[0] == 254:
mdat = msg[4:]
if msg[0] == 255:
moofmdat += moof
moofmdat += mdat
moofmdat += vidbuf
result += moofmdat
with open('test.mp4', 'wb') as file:
file.write(result)
弄清楚了。MOOV 标头有 8 个字节的不必要信息,必须删除。每个附加消息(除了 PBT_Begin 和 PBT_End)都有 4 个字节的玩家特定数据。只需清理每条消息并按正确的顺序放置即可。然后将原始字节保存为 mp4,瞧,视频在 vlc 中播放。
添加回答
举报