如何从RTP包的AP类型包,获取h265的PPS、SPS、VPS信息

ffmpeg播放rtp流,为了降低首开延迟,需要在SDP文件中指定PPS、SPS、VPS信息。抓包后发现wireshark无法解析AP包。需要自己进行AP包解析。RTP协议AP包格式如下:

根据如上信息,我们可以解析AP包,效果如下

  • 40 01,type=32,VPS(视频参数集)
  • 42 01,type=33,SPS(序列参数集)
  • 44 01,type=34,PPS(图像参数集)
  • 4E 01, type=39,SEI(补充增强信息)
  • 26 01,type=19,可能有RADL图像的IDR图像的SS编码数据 IDR
  • 02 01, type=01,被参考的后置图像,且非TSA、非STSA的SS编码数据
  • 46 01,type=35,分隔符,没用。

下图中红色部分是分隔符,橙色是VPS,黑色是SPS,黄色为PPS

SDP中的VPS等信息需要转换成base64。使用下面的函数可转换

#include <stdio.h>

#include <inttypes.h>

#include <math.h>

#include <limits.h>

#include <signal.h>

#include <stdint.h>

#include <string>

#include <string.h>

#include <iostream>

#define AV_BASE64_SIZE(x) (((x)+2) / 3 * 4 + 1)

define AV_RB32(x) \

(((uint32_t)((const uint8_t*)(x))[0] << 24) | \

(((const uint8_t*)(x))[1] << 16) | \

(((const uint8_t*)(x))[2] << 8) | \

((const uint8_t*)(x))[3])

using namespace std;

char *av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)

{

static const char b64[] =

"ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789+/";

char *ret, *dst;

unsigned i_bits = 0;

int i_shift = 0;

int bytes_remaining = in_size;

if (in_size >= UINT_MAX / 4 ||

out_size < AV_BASE64_SIZE(in_size))

return NULL;

ret = dst = out;

while (bytes_remaining > 3) {

i_bits = AV_RB32(in);

in += 3; bytes_remaining -= 3;

*dst++ = b64[ i_bits>>26 ];

*dst++ = b64[(i_bits>>20) & 0x3F];

*dst++ = b64[(i_bits>>14) & 0x3F];

*dst++ = b64[(i_bits>>8 ) & 0x3F];

}

i_bits = 0;

while (bytes_remaining) {

i_bits = (i_bits << 8) + *in++;

bytes_remaining--;

i_shift += 8;

}

while (i_shift > 0) {

*dst++ = b64[(i_bits << 6 >> i_shift) & 0x3f];

i_shift -= 6;

}

while ((dst - ret) & 3)

*dst++ = '=';

*dst = '\0';

return ret;

}

int main() {

uint8_t in[]={0x67, 0x42,0xc0,0x14,0xf4,0x0b,0x04,0xb4,0x20,0x00,0x00,0x03,0x00,0x20,0x00,0x00,0x03,0x03,0xd1,0xe2,0x85,0x54};

char str_sps[100]={0};

av_base64_encode(str_sps,100,in,22);

cout<<"sps'sbasecode:"<<str_sps<<endl;

uint8_t pps[]={0x68 ,0xce ,0x04 ,0xf2};

char str_sps2[100]={0};

av_base64_encode(str_sps2,100,pps,4);

cout<<"pps'sbasecode:"<<str_sps2<<endl;

return 0;

}

相关推荐
国外VPS测评网站15 小时前
游戏服务器搭建选VPS还是专用服务器?
服务器·vps·游戏服务器·专用服务器
蚁景网络安全10 天前
VPS环境搭建及配置
网络·数据库·vps
wavemap18 天前
斯巴达(Spartanhost)VPS的性能评测
linux·服务器·网络·centos·web·vps·斯巴达
UestcXiye1 个月前
WebRTC | 网络传输协议 RTP 和 RTCP
webrtc·rtp·rtcp
码咔吧咔2 个月前
基于H.264的RTP打包中的组合封包以及分片封包结构图简介及抓包分析
h.264·rtp
新睿云.任义兵4 个月前
WebRTC:真正了解 RTP 和 RTCP
webrtc·rtc·rtp·云电脑·rtcp·弘电脑·新睿云
OkeyProxy5 个月前
住宅IP VPS的應用指南
ip·proxy模式·vps·住宅ip
追烽5 个月前
Azure 欧洲区 VPS 测评
microsoft·azure·vps
Kasen's experience6 个月前
Openwrt AP 发射 WiFi 信号
wifi·openwrt·ap·无线设置·发射无线