亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

將碎片 MP4 轉換為 MP4

將碎片 MP4 轉換為 MP4

呼喚遠方 2023-07-27 16:19:23
我正在嘗試從 Trafficview.org 中抓取視頻幀,但似乎無法弄清楚如何解碼數據。我已經監控了通過 Chrome 上的網絡選項卡傳入的消息,還深入研究了下面代碼的輸出,并且相當確定數據正在以碎片 MP4 的形式流入。以下是前 100 個左右字節/消息:b'\xfa\x00\x02\x86\xf1B\xc0\x1e\x00\x00\x00\x18ftypiso5\x00\x00\x02\x00iso6mp41\x00\x00\x02jmoov\x00\x00\x00lmvhd\x00\x00\x00 \x00\xdb\x7f\xeb\xb2\xdb\x7f\xeb\xb2\x00\x00\x03\xe8\x00\x00\x00\x00\x00\x01\x00\x00\x01\x00\x00\x00 \x00\x00\x00\x00\x00\x00\x00\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00\x00'在整個輸出中,有很多 moof 和 mdat 對。假設我讓這段代碼運行 30 秒,如何將這個原始字節字符串轉換為 mp4 文件?import jsonfrom websocket import create_connectionurl = 'wss://cctv.trafficview.org:8420/DDOT_CAPTOP_13.vod?progressive'headers = json.dumps({? ? 'Accept-Encoding': 'gzip, deflate, br',? ? 'Accept-Language': 'en-US,en;q=0.9',? ? 'Cache-Control': 'no-cache',? ? 'Connection': 'Upgrade',? ? 'Host': 'cctv.trafficview.org:8420',? ? 'Origin': 'https://trafficview.org',? ? 'Pragma': 'no-cache',? ? 'Sec-WebSocket-Extensions': 'permessage-deflate; client_max_window_bits',? ? 'Sec-WebSocket-Key': 'FzWbrsoHFsJWzvWGJ04ffw==',? ? 'Sec-WebSocket-Version': '13',? ? 'Upgrade': 'websocket',? ? 'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/85.0.4183.83 Safari/537.36',})ws = create_connection(url, headers=headers)# Then send a message through the tunnelws.send('ping')# Here you will view the message return from the tunnelflag = 3000output = b''while flag > 0:? ? output += ws.recv()? ? flag -= 1
查看完整描述

1 回答

?
慕妹3242003

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 中播放。


查看完整回答
反對 回復 2023-07-27
  • 1 回答
  • 0 關注
  • 124 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號