1 回答

TA貢獻(xiàn)1824條經(jīng)驗(yàn) 獲得超6個(gè)贊
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 標(biāo)頭有 8 個(gè)字節(jié)的不必要信息,必須刪除。每個(gè)附加消息(除了 PBT_Begin 和 PBT_End)都有 4 個(gè)字節(jié)的玩家特定數(shù)據(jù)。只需清理每條消息并按正確的順序放置即可。然后將原始字節(jié)保存為 mp4,瞧,視頻在 vlc 中播放。
添加回答
舉報(bào)