wireshark抓rtp包,提取出H265裸流数

 调试rtsp收发流时,经常会需要抓包以确认是网络问题还是程序问题还是其它问题。通过tcpdump或者wireshark抓到的包通常是rtp流,保存为.pcap格式文件后中,可通过wireshark进行解析,得出h264裸流,并保存为文件。

1.wireshark配置

从gitee上可以直接下载的 

WiresharkPlugin: The H265 H264 PS PCM AMR SILK plugin for Wireshark Lua (gitee.com)

1.1 下载rtp_h365_extractor.lua 

-- Dump RTP h.265 payload to raw h.265 file (*.265)
-- According to RFC7798 to dissector H265 payload of RTP to NALU, and write it
-- to from<sourceIp_sourcePort>to<dstIp_dstPort>.265 file. 
-- By now, we support Single NAL Unit Packets, Aggregation Packets (APs)
-- and Fragmentation Units (FUs) format RTP payload for H.265.
-- You can access this feature by menu "Tools"
-- Reference from Huang Qiangxiong (qiangxiong.huang@gmail.com)
-- Author: Yang Xing (hongch_911@126.com)
------------------------------------------------------------------------------------------------
dolocal version_str = string.match(_VERSION, "%d+[.]%d*")local version_num = version_str and tonumber(version_str) or 5.1local bit = (version_num >= 5.2) and require("bit32") or require("bit")function string.starts(String,Start)return string.sub(String,1,string.len(Start))==Startendfunction string.ends(String,End)return End=='' or string.sub(String,-string.len(End))==Endendfunction get_temp_path()local tmp = nilif tmp == nil or tmp == '' thentmp = os.getenv('HOME')if tmp == nil or tmp == '' thentmp = os.getenv('USERPROFILE')if tmp == nil or tmp == '' thentmp = persconffile_path('temp')elsetmp = tmp .. "/wireshark_temp"endelsetmp = tmp .. "/wireshark_temp"endendreturn tmpendfunction get_ffmpeg_path()local tmp = nilif tmp == nil or tmp == '' thentmp = os.getenv('FFMPEG')if tmp == nil or tmp == '' thentmp = ""elseif not string.ends(tmp, "/bin/") thentmp = tmp .. "/bin/"endendendreturn tmpend-- for geting h265 data (the field's value is type of ByteArray)local f_h265 = Field.new("h265") local f_rtp = Field.new("rtp") local f_rtp_seq = Field.new("rtp.seq")local f_rtp_timestamp = Field.new("rtp.timestamp")local filter_string = nil-- menu action. When you click "Tools->Export H265 to file" will run this functionlocal function export_h265_to_file()-- window for showing informationlocal tw = TextWindow.new("Export H265 to File Info Win")local pgtw;-- add message to information windowfunction twappend(str)tw:append(str)tw:append("\n")endlocal ffmpeg_path = get_ffmpeg_path()-- temp pathlocal temp_path = get_temp_path()-- running first time for counting and finding sps+pps, second time for real savinglocal first_run = true local writed_nalu_begin = false-- variable for storing rtp stream and dumping parameterslocal stream_infos = nil-- trigered by all h265 packatslocal list_filter = ''if filter_string == nil or filter_string == '' thenlist_filter = "h265"elseif string.find(filter_string,"h265")~=nil thenlist_filter = filter_stringelselist_filter = "h265 && "..filter_stringendtwappend("Listener filter: " .. list_filter .. "\n")local my_h265_tap = Listener.new("frame", list_filter)-- 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)key = key:gsub(":", ".")local stream_info = stream_infos[key]if not stream_info then -- if not exists, create onestream_info = { }stream_info.filename = key.. ".265"-- stream_info.filepath = stream_info.filename-- stream_info.file,msg = io.open(stream_info.filename, "wb")if not Dir.exists(temp_path) thenDir.make(temp_path)endstream_info.filepath = temp_path.."/"..stream_info.filenamestream_info.file,msg = io.open(temp_path.."/"..stream_info.filename, "wb")if msg thentwappend("io.open "..stream_info.filepath..", error "..msg)end-- twappend("Output file path:" .. stream_info.filepath)stream_info.counter = 0 -- counting h265 total NALUsstream_info.counter2 = 0 -- for second time runningstream_infos[key] = stream_infotwappend("Ready to export H.265 data (RTP from " .. tostring(pinfo.src) .. ":" .. tostring(pinfo.src_port) .. " to " .. tostring(pinfo.dst) .. ":" .. tostring(pinfo.dst_port) .. " write to file:[" .. stream_info.filename .. "] ...")endreturn stream_infoend-- write a NALU or part of NALU to file.local function write_to_file(stream_info, str_bytes, begin_with_nalu_hdr, end_of_nalu)if first_run thenstream_info.counter = stream_info.counter + 1if begin_with_nalu_hdr then-- save VPS SPS PPSlocal nalu_type = bit.rshift(bit.band(str_bytes:byte(0,1), 0x7e),1)if not stream_info.vps and nalu_type == 32 thenstream_info.vps = str_byteselseif not stream_info.sps and nalu_type == 33 thenstream_info.sps = str_byteselseif not stream_info.pps and nalu_type == 34 thenstream_info.pps = str_bytesendendelse -- second time runningif not writed_nalu_begin thenif begin_with_nalu_hdr thenwrited_nalu_begin = trueelsereturnendendif stream_info.counter2 == 0 thenlocal nalu_type = bit.rshift(bit.band(str_bytes:byte(0,1), 0x7e),1)if nalu_type ~= 32 then-- write VPS SPS and PPS to file header firstif stream_info.vps thenstream_info.file:write("\x00\x00\x00\x01")stream_info.file:write(stream_info.vps)elsetwappend("Not found VPS for [" .. stream_info.filename .. "], it might not be played!")endif stream_info.sps thenstream_info.file:write("\x00\x00\x00\x01")stream_info.file:write(stream_info.sps)elsetwappend("Not found SPS for [" .. stream_info.filename .. "], it might not be played!")endif stream_info.pps thenstream_info.file:write("\x00\x00\x00\x01")stream_info.file:write(stream_info.pps)elsetwappend("Not found PPS for [" .. stream_info.filename .. "], it might not be played!")endendendif begin_with_nalu_hdr then-- *.265 raw file format seams that every nalu start with 0x00000001stream_info.file:write("\x00\x00\x00\x01")endstream_info.file:write(str_bytes)stream_info.counter2 = stream_info.counter2 + 1-- update progress window's progress barif stream_info.counter > 0 and stream_info.counter2 < stream_info.counter thenpgtw:update(stream_info.counter2 / stream_info.counter)endendend-- read RFC3984 about single nalu/ap/fu H265 payload format of rtp-- single NALU: one rtp payload contains only NALUlocal function process_single_nalu(stream_info, h265)write_to_file(stream_info, h265:tvb():raw(), true, true)end-- APs: one rtp payload contains more than one NALUslocal function process_ap(stream_info, h265)local h265tvb = h265:tvb()local offset = 2repeatlocal size = h265tvb(offset,2):uint()write_to_file(stream_info, h265tvb:raw(offset+2, size), true, true)offset = offset + 2 + sizeuntil offset >= h265tvb:len()end-- FUs: one rtp payload contains only one part of a NALU (might be begin, middle and end part of a NALU)local function process_fu(stream_info, h265)local h265tvb = h265:tvb()local start_of_nalu = (h265tvb:range(2, 1):bitfield(0,1) ~= 0)local end_of_nalu =  (h265tvb:range(2, 1):bitfield(1,1) ~= 0)if start_of_nalu then-- start bit is set then save nalu header and bodylocal nalu_hdr_0 = bit.bor(bit.band(h265:get_index(0), 0x81), bit.lshift(bit.band(h265:get_index(2),0x3F), 1))local nalu_hdr_1 = h265:get_index(1)write_to_file(stream_info, string.char(nalu_hdr_0, nalu_hdr_1) .. h265tvb:raw(3), start_of_nalu, end_of_nalu)else-- start bit not set, just write part of nalu bodywrite_to_file(stream_info, h265tvb:raw(3), start_of_nalu, end_of_nalu)endend-- call this function if a packet contains h265 payloadfunction my_h265_tap.packet(pinfo,tvb)if stream_infos == nil then-- not triggered by button event, so do nothing.returnendlocal h265s = { f_h265() } -- using table because one packet may contains more than one RTPfor i,h265_f in ipairs(h265s) doif h265_f.len < 5 thenreturnendlocal h265 = h265_f.range:bytes() local hdr_type = h265_f.range(0,1):bitfield(1,6)local stream_info = get_stream_info(pinfo)if hdr_type > 0 and hdr_type < 48 then-- Single NALUprocess_single_nalu(stream_info, h265)elseif hdr_type == 48 then-- APsprocess_ap(stream_info, h265)elseif hdr_type == 49 then-- FUsprocess_fu(stream_info, h265)elsetwappend("Error: No.=" .. tostring(pinfo.number) .. " unknown type=" .. hdr_type .. " ; we only know 1-47(Single NALU),48(APs),49(FUs)!")endendend-- close all open fileslocal function close_all_files()twappend("")local index = 0;if stream_infos thenlocal no_streams = truefor id,stream in pairs(stream_infos) doif stream and stream.file thenstream.file:flush()stream.file:close()stream.file = nilindex = index + 1twappend(index .. ": [" .. stream.filename .. "] generated OK!")local anony_fuc = function ()twappend("ffplay -x 640 -y 640 -autoexit "..stream.filename)--copy_to_clipboard("ffplay -x 640 -y 640 -autoexit "..stream.filepath)os.execute(ffmpeg_path.."ffplay -x 640 -y 640 -autoexit "..stream.filepath)endtw:add_button("Play "..index, anony_fuc)no_streams = falseendendif no_streams thentwappend("Not found any H.265 over RTP streams!")elsetw:add_button("Browser", function () browser_open_data_file(temp_path) end)endendendfunction my_h265_tap.reset()-- do nothing nowendtw:set_atclose(function ()my_h265_tap:remove()if Dir.exists(temp_path) thenDir.remove_all(temp_path)endend)local function export_h265()pgtw = ProgDlg.new("Export H265 to File Process", "Dumping H265 data to file...")first_run = truestream_infos = {}-- first time it runs for counting h.265 packets and finding SPS and PPSretap_packets()first_run = false-- second time it runs for saving h265 data to target file.retap_packets()close_all_files()-- close progress windowpgtw:close()stream_infos = nilendtw:add_button("Export All", function ()export_h265()end)tw:add_button("Set Filter", function ()tw:close()dialog_menu()end)endlocal function dialog_func(str)filter_string = strexport_h265_to_file()endfunction dialog_menu()new_dialog("Filter Dialog",dialog_func,"Filter")endlocal function dialog_default()filter_string = get_filter()export_h265_to_file()end-- Find this feature in menu "Tools"register_menu("Video/Export H265", dialog_default, MENU_TOOLS_UNSORTED)
end

1.2 rtp_h365_extractor.lua放在 Wireshark 安装目录中

1.3 修改init.lua配置文件

2. 流分析

2.1.  解码为RTP数据包

使用wireshark抓包工具抓取码流包(如下图),基于UDP传输。
在这里插入图片描述
选中其中一个数据包(包要选择正确,可根据protocol的类型选择),右键选择解码为(如下图)。
在这里插入图片描述
新增解码规则,选择解码为RTP流(如下图)。
在这里插入图片描述
解码后,可看到数据包解码成了RTP包(如下图)。
在这里插入图片描述

导出h265视频流

2.2. vlc播放视频流 

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.mzph.cn/news/102458.shtml

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈email:809451989@qq.com,一经查实,立即删除!

相关文章

淘宝天猫商品评论数据接口,淘宝天猫商品评论API接口,淘宝API

淘宝商品评论数据接口可以通过淘宝开放平台API获取。 通过构建合理的请求URL&#xff0c;可以向淘宝服务器发起HTTP请求&#xff0c;获取商品评论数据。接口返回的数据一般为JSON格式&#xff0c;包含了商品的各种评价信息。获取到商品评论数据后&#xff0c;可以对其进行处理…

stm32 hal库 st7789 1.54寸lcd

文章目录 前言一、软件spi1.cubemx配置2.源码文件 二、硬件spi1.cubemx配置2.源码文件3.小小修改 总结 前言 1.54寸lcd 240*240 一、软件spi 1.cubemx配置 一定要注意把这几个东西上拉。 使用c8 2.源码文件 我使用的是中景园的源码&#xff0c;他本来是是标准库的稍微修改…

docker入门加实战—docker常见命令

docker入门加实战—docker常见命令 在介绍命令之前&#xff0c;先用一副图形象的展示一下docker的命令&#xff1a; 常见命令 docker的常见命令和文档地址如下表&#xff1a; 命令说明文档地址docker pull拉取镜像docker pulldocker push推送镜像到DockerRegistrydocker pus…

模拟pdf运行js脚本触发xss攻击及防攻击

一、引入pdfbox依赖 <dependency><groupId>org.apache.pdfbox</groupId><artifactId>pdfbox</artifactId><version>3.0.0</version> </dependency> 二、生成一个带js脚本的pdf文件 //Creating PDF document object PDDocum…

JMeter接口测试:简单到离谱(只需Python和几行代码)

JMeter是一款开源的负载测试工具&#xff0c;可以进行各种类型的性能和功能测试&#xff0c;其中包括接口测试。本文将介绍如何使用Python语言利用JMeter进行接口测试&#xff0c;并提供一些实用的技巧和最佳实践。 同时&#xff0c;我也准备了一份软件测试视频教程&#xff0…

【【萌新的SOC学习之GPIO之MIO控制LED实验程序设计】】

萌新的SOC学习之GPIO之MIO控制LED实验程序设计 如何设置完GPIO并且传递数据 我们先了解GPIO引脚的配置 每一个GPIO引脚都可以设置成输入输出 &#xff0c;只有GPIO8 7 只能作为输出 我们现在做一个例子 GPIO 的bank我们知道有4个 bank0 1 2 3 DIRM_0 就是第一个bank 需要写入…

访问Apache Tomcat的manager页面

配置访问Tomcat manager页面的用户名、密码、角色 Tomcat安装完成后&#xff0c;包含了一个管理应用&#xff0c;默认安装在 <Tomcat安装目录>/webapps/manager 例如&#xff1a; 要使用管理页面的功能&#xff0c;需要在conf/tomcat-users.xml文件中配置用户、密码及…

我用了多年的前端框架,强烈推荐!

大家好&#xff0c;我是鱼皮&#xff0c;今天给大家分享一个我自己用了多年、现在团队也在用的前端框架 —— Ant Design Pro。 什么是 Ant Design Pro&#xff1f; Ant Design Pro 是由蚂蚁金服开发的、基于 Ant Design 组件库的开发框架&#xff0c;专门用于构建企业级管理…

LeetCode【15】三数之和

题目&#xff1a; 解析&#xff1a; 参考&#xff1a;https://zhuanlan.zhihu.com/p/111715985 代码&#xff1a; public static List<List<Integer>> threeSum(int[] nums) {// 先排序Arrays.sort(nums);List<List<Integer>> result new ArrayLis…

python pip安装超时使用国内镜像

网络环境差的时候需要我们独立的进行相对应的包下载离线安装&#xff0c;或者给pip 加上 国内的镜像源比如加上清华的镜像源&#xff1a; 参考网址&#xff1a;pypi | 镜像站使用帮助 | 清华大学开源软件镜像站 | Tsinghua Open Source Mirror https://mirrors.tuna.tsinghua…

springcloud学习笔记(3)-服务管理组件Nacos

Nacos简介 在2中学习了服务治理中心eureka&#xff0c;而本节的nacos来自springcloud alibaba。 Nacos也是一个服务注册和管理的组件。 Nacos 支持几乎所有主流类型的“服务”的发现、配置和管理 官方文档 快速开始 | Spring Cloud Alibaba (aliyun.com) 概述 | Spring C…

Websocket获取B站直播间弹幕教程——第二篇、解包/拆包

教程一、Websocket获取B站直播间弹幕教程 — 哔哩哔哩直播开放平台 1、封包 我们连接上B站Websocket成功后&#xff0c;要做两件事情&#xff1a; 第一、发送鉴权包。第二、发送心跳包&#xff0c;每30秒一次&#xff0c;维持websocket连接。 这两个包不是直接发送过去&…

yolov8 (2) : 模型训练

yolov8 github: https://github.com/ultralytics/ultralytics yolov8 网络详解参见: YOLOv8 (1) : 网络讲解1. 环境安装 安装ultralytics包pip install ultralytics在终端输入yolo命令࿰

使用wireshark解密ipsec ISAKMP包

Ipsec首先要通过ikev2协议来协商自己后续协商所用的加解密key以及用户数据的esp包用的加解密包。 ISAKMP就是加密过的ike-v2的加密包&#xff0c;有时候我们需要解密这个包来查看协商数据。如何来解密这样的包? 首先导出strongswan协商生成的各种key. 要能导出这些key&#…

适合自学的网络安全基础技能“蓝宝书”:《CTF那些事儿》

CTF比赛是快速提升网络安全实战技能的重要途径&#xff0c;已成为各个行业选拔网络安全人才的通用方法。但是&#xff0c;本书作者在从事CTF培训的过程中&#xff0c;发现存在几个突出的问题&#xff1a; 1&#xff09;线下CTF比赛培训中存在严重的 “最后一公里”问题 &#…

身份证号码,格式校验:@IdCard(自定义注解)

目标 自定义一个用于校验 身份证号码 格式的注解IdCard&#xff0c;能够和现有的 Validation 兼容&#xff0c;使用方式和其他校验注解保持一致&#xff08;使用 Valid 注解接口参数&#xff09;。 校验逻辑 有效格式 符合国家标准。 公民身份号码按照GB11643&#xff0d;…

Vue3中使用tinymce全功能演示,包括开源功能

效果图&#xff1a; 1、下载插件: npm i tinymce npm i tinymce/tinymce-vue 2、在node_modules文件夹中找到tinymce下的skins复制到项目public文件夹中 &#xff08;可以先创建一个tinymce文件夹&#xff09;&#xff1a; 3、在tinymce官网中下载中文包&#xff0c;并放在刚…

pytorch中nn.DataParallel多次使用

pytorch中nn.DataParallel多次使用 import torch import torch.nn as nn import torch.optim as optim from torch.utils.data import DataLoader# 定义模型 class MyModel(nn.Module):def __init__(self):super(MyModel, self).__init__()self.fc nn.Linear(10, 1)def forwa…

Facebook广告账户被封?最全防封及申诉指南

Facebook广告是海外营销的一大利器&#xff0c;但是随着互联网的发展&#xff0c;有部分不法分子正在利用他进行盈利&#xff0c;导致Facebook官方安全审核日益严格&#xff0c;不少卖家遭遇封号问题&#xff01;这篇文章就来教你如何更好地管理 Facebook广告帐户&#xff0c;实…

windows10系统-15-markdown编辑器和文本复制工具Textify

1 markdown编辑器 Markdown是一种轻量级标记语言&#xff0c;创始人为约翰格鲁伯。 它允许人们使用易读易写的纯文本格式编写文档&#xff0c;然后转换成有效的XHTML&#xff08;或者HTML&#xff09;文档。这种语言吸收了很多在电子邮件中已有的纯文本标记的特性。 1.1 Typo…