阅读ffmpeg串流的手册FFmpeg Streaming Guide
当进行点对点串流时
如果视频编码为H.264时,payload type 为 96
$ ffmpeg -re -i sample1.mp4 -an -c copy -f rtp rtp://127.0.0.1:12345
Output #0, rtp, to 'rtp://127.0.0.1:12345':
Metadata:
major_brand : isom
minor_version : 512
compatible_brands: isomiso2avc1mp41
encoder : Lavf55.48.100
Stream #0:0(eng): Video: h264 (avc1 / 0x31637661), yuv420p, 424x240, q=2-31, 420 kb/s, 24 fps, 90k tbn, 24 tbc (default)
Metadata:
handler_name : VideoHandler
Stream mapping:
Stream #0:0 -> #0:0 (copy)
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 55.48.100
m=video 12345 RTP/AVP 96
b=AS:420
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LAHpZiA2P8vCAAAAMAIAAABgHixck=,aMuMsg==; profile-level-id=42C01E
此时会自动输出一段SDP的代码,这时候如果直接播放
$ ffplay rtp://localhost:12345
[rtp @ 0x7f77440008c0] Unable to receive RTP payload type 96 without an SDP file describing it
Input #0, rtp, from 'rtp://localhost:12345':
Duration: N/A, bitrate: N/A
Failed to open file 'rtp://localhost:12345' or configure filtergraph
将会提示“不能接收RTP payload 类型为96 在没有sdp来描述它”
这时候如果将ffmpeg输出时打印的sdp信息保存为文件,再ffplay播放这个文件 则正常打开。
SDP:
v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 127.0.0.1
t=0 0
a=tool:libavformat 55.48.100
m=video 12345 RTP/AVP 96
b=AS:420
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z0LAHpZiA2P8vCAAAAMAIAAABgHixck=,aMuMsg==; profile-level-id=42C01E
其它信息都好说,只有最后一行比较有难点
今天仔细阅读了/home/aliang/Source/ffmpeg-2.3.1/libavformat/sdp.c 这个文件
定位到static char *extradata2psets(AVCodecContext *c)
sprop-parameter-sets就是这个H.264视频编码中 SPS PPS的base64编码
SPS : 67 42 c0 1e 96 62 3 63 fc bc 20 0 0 3 0 20 0 0 6 1 e2 c5 c9
PPS : 68 cb 8c b2
编码后
SPS : Z0LAHpZiA2P8vCAAAAMAIAAABgHixck=
PPS : aMuMsg==
原创文章,转载请注明: 转载自贝壳博客
本文链接地址: 使用ffmpeg进行rtp串流h.264时关于sdp的一些分析