日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

H264BSAnalyzer 使用方法

發布時間:2023/12/18 编程问答 30 豆豆
生活随笔 收集整理的這篇文章主要介紹了 H264BSAnalyzer 使用方法 小編覺得挺不錯的,現在分享給大家,幫大家做個參考.

H264BSAnalyzer簡介

H264BSAnalyzer 是一款用來播放和解析 H264視頻格式的電腦工具。
源碼位置:https://github.com/latelee/H264BSAnalyzer
具體功能github上已經很詳細了,在此不再贅述,本文主要講一下如何集成到Wireshark中,且如何使用。

環境介紹

windows 10

準備工具

Wireshark 2.6.6 (百度一大堆,請自行下載)
H264BSAnalyzer 3.0-dev (下載地址)

集成步驟

  • 安裝Wireshark 2.6.6
  • 集成 h264文件生成插件到Wireshark 2.6.6
    2.1 拷貝h264_export.lua (文件內容將在文末給出) 到Wireshark安裝根目錄下邊
    2.2 修改Wireshark 根目錄下邊的init.lua文件,在最后添加
    dofile(DATA_DIR…“h264_export.lua”)

    2.3 重啟 Wireshark 即可
  • 使用步驟

  • 生成h264文件
    1.1 使用Wireshark 抓取一段h264視頻數據
    -
    1.2 生成文件


    然后點擊 ok
    1.3 生成h264文件
    - 過濾框輸入 rtp ,然后回車


    - 看到下圖,說明h264文件生成成功,文件名稱就是下圖File后方括號中字符串。

    - 生成文件位置
    Wireshark根目錄
  • 使用H264BSAnalyzer查看h264文件
    雙擊打開H264BSAnalyzer.exe 文件,File 打開或直接拖拽h264文件到軟件中即可。
  • 使用H264BSAnalyzer播放h264文件
  • 遇到的問題

  • Lua: on packet 153 Error During execution of Listener Packet Callback:
    D:\softworkspace\Wireshark\h264_export.lua:69: attempt to index field ‘file’ (a nil value)
    原因:Wireshark 應用沒有權限在Wireshark 安裝目錄下新建并保存文件
    解決方法:使用管理員權限啟動Wireshark
  • Error open file

    原因:對文件所在目錄沒有讀取權限
    解決方法:使用管理員權限啟動 H264BSAnalyzer
  • h264_export.lua文件內容

    -- Dump RTP h.264 payload to raw h.264 file (*.264) -- According to RFC3984 to dissector H264 payload of RTP to NALU, and write it -- to from<sourceIp_sourcePort>to<dstIp_dstPort>.264 file. By now, we support single NALU, -- STAP-A and FU-A format RTP payload for H.264. -- You can access this feature by menu "Tools->Export H264 to file [HQX's plugins]" -- Author: Huang Qiangxiong (qiangxiong.huang@gmail.com) -- change log: -- 2012-03-13 -- Just can play ------------------------------------------------------------------------------------------------ do-- for geting h264 data (the field's value is type of ByteArray)local f_h264 = Field.new("h264") -- menu action. When you click "Tools->Export H264 to file [HQX's plugins]" will run this functionlocal function export_h264_to_file()-- window for showing informationlocal tw = TextWindow.new("Export H264 to File Info Win")local pgtw = ProgDlg.new("Export H264 to File Process", "Dumping H264 data to file...")-- add message to information windowfunction twappend(str)tw:append(str)tw:append("\n")end-- running first time for counting and finding sps+pps, second time for real savinglocal first_run = true -- variable for storing rtp stream and dumping parameterslocal stream_infos = {}-- trigered by all h264 packatslocal my_h264_tap = Listener.new(tap, "h264")-- get rtp stream info by src and dst addressfunction get_stream_info(pinfo)local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "to" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port)local stream_info = stream_infos[key]if not stream_info then -- if not exists, create onestream_info = { }stream_info.filename = key.. ".264"stream_info.file = io.open(stream_info.filename, "wb")stream_info.counter = 0 -- counting h264 total NALUsstream_info.counter2 = 0 -- for second time runningstream_infos[key] = stream_infotwappend("Ready to export H.264 data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " to file:\n [" .. stream_info.filename .. "] ...\n")endreturn stream_infoend-- write a NALU or part of NALU to file.function write_to_file(stream_info, str_bytes, begin_with_nalu_hdr)if first_run thenstream_info.counter = stream_info.counter + 1if begin_with_nalu_hdr then-- save SPS or PPSlocal nalu_type = bit.band(str_bytes:byte(0,1), 0x1F)if not stream_info.sps and nalu_type == 7 thenstream_info.sps = str_byteselseif not stream_info.pps and nalu_type == 8 thenstream_info.pps = str_bytesendendelse -- second time runningif stream_info.counter2 == 0 then-- write SPS and PPS to file header firstif stream_info.sps thenstream_info.file:write("\00\00\00\01")stream_info.file:write(stream_info.sps)elsetwappend("Not found SPS for [" .. stream_info.filename .. "], it might not be played!\n")endif stream_info.pps thenstream_info.file:write("\00\00\00\01")stream_info.file:write(stream_info.pps)elsetwappend("Not found PPS for [" .. stream_info.filename .. "], it might not be played!\n")endendif begin_with_nalu_hdr then-- *.264 raw file format seams that every nalu start with 0x00000001stream_info.file:write("\00\00\00\01")endstream_info.file:write(str_bytes)stream_info.counter2 = stream_info.counter2 + 1if stream_info.counter2 == stream_info.counter thenstream_info.file:flush()twappend("File [" .. stream_info.filename .. "] generated OK!\n")end-- update progress window's progress barif stream_info.counter > 0 then pgtw:update(stream_info.counter2 / stream_info.counter) endendend-- read RFC3984 about single nalu/stap-a/fu-a H264 payload format of rtp-- single NALU: one rtp payload contains only NALUfunction process_single_nalu(stream_info, h264)write_to_file(stream_info, h264:tvb()():string(), true)end-- STAP-A: one rtp payload contains more than one NALUsfunction process_stap_a(stream_info, h264)local h264tvb = h264:tvb()local offset = 1repeatlocal size = h264tvb(offset,2):uint()write_to_file(stream_info, h264tvb(offset+2, size):string(), true)offset = offset + 2 + sizeuntil offset >= h264tvb:len()end-- FU-A: one rtp payload contains only one part of a NALU (might be begin, middle and end part of a NALU)function process_fu_a(stream_info, h264)local h264tvb = h264:tvb()local fu_idr = h264:get_index(0)local fu_hdr = h264:get_index(1)if bit.band(fu_hdr, 0x80) ~= 0 then-- start bit is set then save nalu header and bodylocal nalu_hdr = bit.bor(bit.band(fu_idr, 0xE0), bit.band(fu_hdr, 0x1F))write_to_file(stream_info, string.char(nalu_hdr), true)else-- start bit not set, just write part of nalu bodyendwrite_to_file(stream_info, h264tvb(2):string(), false)end-- call this function if a packet contains h264 payloadfunction my_h264_tap.packet(pinfo,tvb)local h264s = { f_h264() } -- using table because one packet may contains more than one RTPfor i,h264_f in ipairs(h264s) doif h264_f.len < 2 thenreturnendlocal h264 = h264_f.value -- is ByteArraylocal hdr_type = bit.band(h264:get_index(0), 0x1F)local stream_info = get_stream_info(pinfo)if hdr_type > 0 and hdr_type < 24 then-- Single NALUprocess_single_nalu(stream_info, h264)elseif hdr_type == 24 then-- STAP-A Single-time aggregationprocess_stap_a(stream_info, h264)elseif hdr_type == 28 then-- FU-Aprocess_fu_a(stream_info, h264)elsetwappend("Error: unknown type=" .. hdr_type .. " ; we only know 1-23(Single NALU),24(STAP-A),28(FU-A)!")endendend-- close all open filesfunction close_all_files()if stream_infos thenfor id,stream in pairs(stream_infos) doif stream and stream.file thenstream.file:close()stream.file = nilendendendendfunction my_h264_tap.reset()-- do nothing nowendfunction remove()close_all_files()my_h264_tap:remove()endtw:set_atclose(remove)-- first time it runs for counting h.264 packets and finding SPS and PPSretap_packets()first_run = false-- second time it runs for saving h264 data to target file.retap_packets()-- close progress windowpgtw:close()end-- Find this feature in menu "Tools->"Export H264 to file [HQX's plugins]""register_menu("Export H264 to file [HQX's plugins]", export_h264_to_file, MENU_TOOLS_UNSORTED) end

    總結

    以上是生活随笔為你收集整理的H264BSAnalyzer 使用方法的全部內容,希望文章能夠幫你解決所遇到的問題。

    如果覺得生活随笔網站內容還不錯,歡迎將生活随笔推薦給好友。