直接播放H264视频流的方法或工具
上一篇 / 下一篇 2013-07-31 10:29:21 / 个人分类:工具
)BP!X7~[ ?A0
&P6C:cqhZ PXH0抓取一个包含H.264 Payload RTP包的SIP会话或RTSP会话后,用Wireshark的Play功能只能播放声音,不能播放视频。把payload直接导出成文件后也是不能直接播放的,因为H.264 over RTP封包是符合RFC3984规范的,必须按照该规范把H.264数据取出来后,组成NALU,放到avi/mp4或裸码流文件等容器里后才能播放。51Testing软件测试网L| ?_p2J
本人写了一个wireshark插件,可以在打开包含H.264码流的抓包后,选菜单“Tools->Export H264 to file [HQX's plugins]”后,把抓包文件里的H.264码流自动导出到抓包文件所在目录(工作目录)里,名为from_<RTP流源 ip>_<RTP流源端口>_to_<RTP流目的ip>_<RTP流目的端口>.264的264裸码流文件 里。(文件格式为每个NALU前加0x00000001分隔符)。
%i)w&K Gg4ak2K&`0^Sq*e;k[SgWs0 本程序可以识别RFC3984里提到的三种H.264 over RTP封装,分别是Single NALU(一个RTP含一个NALU)、STAP-A(一个RTP包含多个NALU)、FU-A(一个NALU分布到多个RTP包)三种封装格式,且会自 动把SPS和PPS放到裸码流文件头部。51Testing软件测试网t.bY\$G%\w
51Testing软件测试网0}'SRUQ%Nj2QZLua脚本如下:51Testing软件测试网 S;^1Z]n
1ph*p^$@.X*ws051Testing软件测试网%DbL*T2^g
51Testing软件测试网MJ2IZ ^i V
6]!n3R V^DH2^.S:E[l0-- Dump RTP h.264 payload to raw h.264 file (*.264)51Testing软件测试网R(i;R#t!KzZ
51Testing软件测试网#v0Ya+d!j|-- According to RFC3984 to dissector H264 payload of RTP to NALU, and write it51Testing软件测试网DpVGn P
xvq`dr0-- to from<sourceIp_sourcePort>to<dstIp_dstPort>.264 file. By now, we support single NALU,
HM(v+e3r#d*c\8S051Testing软件测试网{;m"KJ/_*{-- STAP-A and FU-A format RTP payload for H.264.51Testing软件测试网'Y(b po i MA
51Testing软件测试网aZ N(Zhi\-- You can access this feature by menu "Tools->Export H264 to file [HQX's plugins]"
f(FA%}bH0{J'qX,GNps'EG)P0-- Author: Huang Qiangxiong (qiangxiong.huang@gmail.com)
iM"d8z"u8BkB"D051Testing软件测试网B:b]yUW-- change log:
#Q@ {u8r6KM0A*i3K1bCcy0-- 2012-03-13
z@3tx!RG _/a8n j0fRm:sk0-- Just can play
k}BBy6xT` |051Testing软件测试网9jLD~!NZ8m*bX!U------------------------------------------------------------------------------------------------51Testing软件测试网%G}B e5YC'zH
51Testing软件测试网:D#[D}BY/kdo
9lH%l#|ZF$yt051Testing软件测试网*npa$I#^L-- for geting h264 data (the field's value is type of ByteArray)51Testing软件测试网 k9o)l)M4et(^kz;e
51Testing软件测试网sv,o*pY r6FF#GRlocal f_h264 = Field.new("h264")
:^_%K%{/Kv1nY051Testing软件测试网0r*W4{F'hV\*vub6~51Testing软件测试网)V
N:o+M1h*W9j
51Testing软件测试网|p lQ X
-- menu action. When you click "Tools->Export H264 to file [HQX's plugins]" will run this function51Testing软件测试网 I6OK8g%S\(dR w
WP%G_x D L0 local function export_h264_to_file()
~ h6k8~i}Y]051Testing软件测试网O _C2B gMG&u1E8B-- window for showing information51Testing软件测试网+i3kf;{H*Ug
KO FzHT0 local tw = TextWindow.new("Export H264 to File Info Win")51Testing软件测试网9qSsl'a3UG(Hq'j
51Testing软件测试网BE _Ft*Plocal pgtw = ProgDlg.new("Export H264 to File Process", "Dumping H264 data to file...")
1Po*K COH{Y}051Testing软件测试网'Y,Sl;A{O$d!V,r9rw~#J0
#a~W:S;{ wu0 -- add message to information window51Testing软件测试网+pE(|q pS8V4`z
-E v9O5Y&N.k.D0 function twappend(str)51Testing软件测试网-[O5epm7A9e
51Testing软件测试网 }j]?[7TTtw:append(str)51Testing软件测试网7c i dgP$cQ*~6[7Cuv
51Testing软件测试网V3L2m ~n+ZQ#Atw:append("\n")
t.W7q4DG08lpp;]B k0 end
[Mlk^F'x0}h6Aa+K*^X ~0 51Testing软件测试网-n;k3gQ1AN*c
51Testing软件测试网!X0[fZgP ^:f6j-- running first time for counting and finding sps+pps, second time for real saving51Testing软件测试网__J9\q.}z
_R2[{2l0 local first_run = true
i$ic`0`u0$DuFrJy0 -- variable for storing rtp stream and dumping parameters
.rEO&XE W"A,m C0KM0c{CM!v2P nPO g0 local stream_infos = {}51Testing软件测试网cqn+c o;i
51Testing软件测试网z,Y$Q"x~,{51Testing软件测试网l^m~SxDH!]
q[Tl5v\0 -- trigered by all h264 packats51Testing软件测试网w^ kA/U}s
6EKnK*_f*Y0 local my_h264_tap = Listener.new(tap, "h264")
N1Z*Dpc^!Z h Aw051Testing软件测试网#uj"f[eWe;F^51Testing软件测试网!f7iLo?rH4uR g;q