如何从wireshark解压出RTP包并播放音视频

本文介绍了如何使用Wireshark的h264_export.lua插件解包RTP包,并通过mplayer播放原始H.264文件。详细步骤包括安装插件、导出H.264文件,以及使用mplayer和ffmpeg进行播放和转换为mp4格式。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

问题

有时候我们解决问题时,发现接收端没有视频,其中一个办法就是抓包然后看包里面视频是否正确,下面是如何实现抓包的方法。

方法:用wireshark 插件解出RTP包再用mplayer 播放。

wireshark 插件是国外一个人写的,安装如下所示:

  1. 在/Applications/Wireshark.app/Contents/Resources/share/wireshark下放置h264_export.lua(参见附件)

  2. 将dofile(“h264_export.lua”)放到文件末尾/Applications/Wireshark.app/Contents/Resources/share/wireshark/init.lua

  3. 在wireshark中打开pcap数据包 选择工具 - >将H264导出到文件,在wireshark目录下会有几个.264文件。

插件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
--      2012-04-28
--          Add local to local function, and add [local bit = require("bit")] to prevent
--          bit recleared in previous file.
--      2013-07-11
--          Add sort RTP and drop uncompleted frame option.
--      2013-07-19
--          Do nothing when tap is triggered other than button event.
--          Add check for first or last packs lost of one frame.
--      2014-10-23
--          Fixed bug about print a frame.nalu_type error.
--      2014-11-07
--          Add support for Lua 5.2(>1.10.1) and 5.1(<=1.10.1). 
--          Change range:string() to range:raw().
--          Change h264_f.value to h264_f.range:bytes() because of wireshark lua bug.
--      2015-06-03
--          Fixed bug that if ipv6 address is using the file will not generated.(we replace ':' to '.')
------------------------------------------------------------------------------------------------
do
    --local bit = require("bit") -- only work before 1.10.1
    --local bit = require("bit32") -- only work after 1.10.1 (only support in Lua 5.2)
    local version_str = string.match(_VERSION, "%d+[.]%d*")
    local version_num = version_str and tonumber(version_str) or 5.1
    local bit = (version_num >= 5.2) and require("bit32") or require("bit")

    -- for geting h264 data (the field's value is type of ByteArray)
    local f_h264 = Field.new("h264") 
    local f_rtp = Field.new("rtp") 
    local f_rtp_seq = Field.new("rtp.seq")
    local f_rtp_timestamp = Field.new("rtp.timestamp")
    local nalu_type_list = {
        [0] = "Unspecified",
        [1] = "P/B_slice",
        [2] = "P/B_A",
        [3] = "P/B_B",
        [4] = "P/B_C",
        [5] = "I_slice",
        [6] = "SEI",
        [7] = "SPS",
        [8] = "PPS",
        [9] = "AUD",
    }
    
    local function get_enum_name(list, index)
        local value = list[index]
        return value and value or "Unknown"
    end

    -- menu action. When you click "Tools->Export H264 to file [HQX's plugins]" will run this function
    local function export_h264_to_file()
        -- window for showing information
        local tw = TextWindow.new("Export H264 to File Info Win")
        --local pgtw = ProgDlg.new("Export H264 to File Process", "Dumping H264 data to file...")
        local pgtw;
        
        -- add message to information window
        function twappend(str)
            tw:append(str)
            tw:append("\n")
        end
        
        -- running first time for counting and finding sps+pps, second time for real saving
        local first_run = true 
        -- variable for storing rtp stream and dumping parameters
        local stream_infos = nil
        -- drop_uncompleted_frame
        local drop_uncompleted_frame = false
        -- max frame buffer size
        local MAX_FRAME_NUM = 3

        -- trigered by all h264 packats
        local my_h264_tap = Listener.new(tap, "h264")
        
        -- get rtp stream info by src and dst address
        function get_stream_info(pinfo)
            local key = "from_" .. tostring(pinfo.src) .. "_" .. tostring(pinfo.src_port) .. "to" .. tostring(pinfo.dst) .. "_" .. tostring(pinfo.dst_port) .. (drop_uncompleted_frame and "_dropped" or "_all")
            key = key:gsub("
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值