直接播放H264视频流的方法或工具
上一篇 / 下一篇 2013-07-31 10:29:21 / 个人分类:工具
抓取一个包含H.264 Payload RTP包的SIP会话或RTSP会话后,用Wireshark的Play功能只能播放声音,不能播放视频。把payload直接导出成文件后也是不能直接播放的,因为H.264 over RTP封包是符合RFC3984规范的,必须按照该规范把H.264数据取出来后,组成NALU,放到avi/mp4或裸码流文件等容器里后才能播放。
;`-ngt8J9cB0 本人写了一个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分隔符)。51Testing软件测试网0oL"wQUj} k
51Testing软件测试网i9z&nu8B9DBumr本程序可以识别RFC3984里提到的三种H.264 over RTP封装,分别是Single NALU(一个RTP含一个NALU)、STAP-A(一个RTP包含多个NALU)、FU-A(一个NALU分布到多个RTP包)三种封装格式,且会自 动把SPS和PPS放到裸码流文件头部。
[%^L(X)W{0rV$V,W-D3NK0Lua脚本如下:51Testing软件测试网 T5|(^d!y-R
51Testing软件测试网5?Ip8Ho{VGxb
(O#^8?,Upq0
-- Dump RTP h.264 payload to raw h.264 file (*.264)
OO4fD7?0\dGh:W0-- According to RFC3984 to dissector H264 payload of RTP to NALU, and write it
1\Ghkh fp0^1L2{B(H,e$R0-- to from<sourceIp_sourcePort>to<dstIp_dstPort>.264 file. By now, we support single NALU,51Testing软件测试网AX0f1`A
51Testing软件测试网V6_'mI+{^o$w"k,F-- STAP-A and FU-A format RTP payload for H.264.51Testing软件测试网R(\$s@P yN
51Testing软件测试网.RqM,@lZ^+l-- You can access this feature by menu "Tools->Export H264 to file [HQX's plugins]"51Testing软件测试网.t5QW8hf6F
51Testing软件测试网9w_SA X4q-- Author: Huang Qiangxiong (qiangxiong.huang@gmail.com)51Testing软件测试网t,js l,e'k
51Testing软件测试网-M*J5~J'Z:lT8HzlF5O-- change log:51Testing软件测试网d]7P9{Zy(j9l s8Q
51Testing软件测试网a rg7ssn/P-- 2012-03-13
sbF.|Y+BFw0Tg(A"YRK I0-- Just can play51Testing软件测试网~AxBD|iD
~-G/c0xu5@0------------------------------------------------------------------------------------------------51Testing软件测试网pn#?3W@ \
51Testing软件测试网?#kx3k8`yV2S7kdo51Testing软件测试网^G\!`y/l
51Testing软件测试网lXK4nii-- for geting h264 data (the field's value is type of ByteArray)
n,j5z Rq;L0\;Z&d&~C'\g-sw0 local f_h264 = Field.new("h264") 51Testing软件测试网*_Iz7bC5G(K9]
8uR _R d4K051Testing软件测试网W I1`T*wZ
51Testing软件测试网W,z
v*Hk
-- menu action. When you click "Tools->Export H264 to file [HQX's plugins]" will run this function
@ {yWFB.t051Testing软件测试网 W s(PY^/mg~Xlocal function export_h264_to_file()
f ~Y J'[ z051Testing软件测试网]:ThW4k-- window for showing information
:t1yd4oX v8l0U!f051Testing软件测试网 Z"U#Y&E~n z9[%Elocal tw = TextWindow.new("Export H264 to File Info Win")
;C7c$`tE xcg6i051Testing软件测试网O4Uz:M'Olocal pgtw = ProgDlg.new("Export H264 to File Process", "Dumping H264 data to file...")
[^BqB3w*E#D.z0;v?,pjQ1w k-O3P0
uk&yY]o3o051Testing软件测试网6xS:YlIR-- add message to information window
8I*U.n G}At051Testing软件测试网@3YE2VYc;Q!xfunction twappend(str)51Testing软件测试网Ro)Q4SI+b#\K(x
U;W1D@Y*z5z`0 tw:append(str)51Testing软件测试网 G} Tl+n
51Testing软件测试网}&w.DM6y/R f u2|%yP;jtw:append("\n")51Testing软件测试网n"M4}Bod;I`7Zk
lR]6H,cL~\P0 end
!Ue;Y&u