rtsp协议简介
老规矩,百科下咯。
RTSP(Real Time Streaming Protocol),RFC2326,实时流传输协议,是TCP/IP协议体系中的一个应用层协议,由哥伦比亚大学、网景和RealNetworks公司提交的IETF RFC标准。该协议定义了一对多应用程序如何有效地通过IP网络传送多媒体数据。RTSP在体系结构上位于RTP和RTCP之上,它使用TCP或UDP完成数据传输。
…
太啰嗦了,RFC2326也看不下去,还是直接抓包分析吧
抓包分析
1、打开wireshark抓tcp包,根据rtsp过滤;
2、打开IPC的web页,开始预览,停止预览,可以看到wireshark已经抓到了我们想要的东西;
3、在wireshark的RTSP包上右键Follow TCP Stream即可得到下面一段rtsp对答
DESCRIBE rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 1
Accept: application/sdp
Session: 1495700359
RTSP/1.0 401 Unauthorized
CSeq: 1
Thu, May 25 2017 08:21:29 GMT
WWW-Authenticate: Digest realm="Keda Streaming Media", nonce="ecb2ddc1ddef1851c055af808ad9f0fb"
DESCRIBE rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 2
Accept: application/sdp
Authorization: Digest username="admin", realm="Keda Streaming Media", nonce="ecb2ddc1ddef1851c055af808ad9f0fb", uri="rtsp://172.16.193.152:554/realtime?chnid=1;vid=0;aid=0;agent=cgi", response="92edf3ade54179369eb807ef371aff8f"
RTSP/1.0 200 OK
CSeq: 2
Content-Type: application/sdp
Content-Length: 325
v=0
o=NVR 1495700489 1495700489 IN IP4 0.0.0.0
s=3GPP Unicast SDP
c=IN IP4 0.0.0.0
t=0 0
a=range:npt=0-
a=control:*
m=video 0 RTP/AVP 96
a=control:video_0
a=rtpmap:96 H264/90000
a=fmtp:96 profile-level-id=
m=audio 0 RTP/AVP 8
a=control:audio_0
a=rtpmap:8 PCMA/8000
SETUP rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 3
Transport: RTP/AVP
RTSP/1.0 200 OK
CSeq: 3
Session: 1495700489
Transport: RTP/AVP
Cache-Control: no-cache
SETUP rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 4
Session: 1495700489
Transport: RTP/AVP
RTSP/1.0 200 OK
CSeq: 4
Session: 1495700489
Transport: RTP/AVP
Cache-Control: no-cache
PLAY rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 5
Range: npt=0.000-
Session: 1495700489
RTSP/1.0 200 OK
CSeq: 5
Session: 1495700489
RTP-Info: url=video/id=0
Range: npt=0.000-
Date: Thu, May 25 2017 08:21:29 GMT
GET_PARAMETER rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 6
Content-Length: 0
Content-Type: text/parameters
Session: 1495700489
TitleDisplay: OFF
TitleAttrib: White, 0,0
TitleChar:
RTSP/1.0 200 OK
CSeq: 6
Session: 1495700489
GET_PARAMETER rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 7
Content-Length: 0
Content-Type: text/parameters
Session: 1495700489
TitleDisplay: OFF
TitleAttrib: White, 0,0
TitleChar:
RTSP/1.0 200 OK
CSeq: 7
Session: 1495700489
TEARDOWN rtsp://172.16.193.152:554/realtime?chnid=1
CSeq: 8
Session: 1495700489
RTSP/1.0 200 OK
CSeq: 8
Session: 1495700489
一个基本的对答流程是:
协议详解
1. OPTION
目的是得到服务器提供的可用方法:
OPTIONS rtsp:
CSeq: 1
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10)
服务器的回应信息包括提供的一些方法,例如:
RTSP/1.0 200 OK
Server: UServer 0.9.7_rc1
Cseq: 1
Public: OPTIONS, DESCRIBE, SETUP, TEARDOWN, PLAY, PAUSE, SCALE,GET_PARAMETER
2. DESCRIBE
C向S发起DESCRIBE请求,为了得到会话描述信息(SDP):
DESCRIBE rtsp:
CSeq: 2
token:
Accept: application/sdp
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10)
服务器回应一些对此会话的描述信息(sdp):
RTSP/1.0 200 OK
Server: UServer 0.9.7_rc1
Cseq: 2
x-prev-url: rtsp:
x-next-url: rtsp:
x-Accept-Retransmit: our-retransmit
x-Accept-Dynamic-Rate: 1
Cache-Control: must-revalidate
Last-Modified: Fri, 10 Nov 2006 12:34:38 GMT
Date: Fri, 10 Nov 2006 12:34:38 GMT
Expires: Fri, 10 Nov 2006 12:34:38 GMT
Content-Base: rtsp:
Content-Length: 344
Content-Type: application/sdp
v=0
o=OnewaveUServerNG 1451516402 1025358037 IN IP4 192.168.20.136
s=/xxx666
u=http:
e=admin@
c=IN IP4 0.0.0.0
t=0 0
a=isma-compliance:1,1.0,1
a=range:npt=0-
m=video 0 RTP/AVP 96
a=rtpmap:96 MP4V-ES/90000
a=fmtp:96 profile-level-id=245;config=000001B0F5000001B509000001000000012000C888B0E0E0FA62D089028307 a=control:trackID=0
3.SETUP
客户端提醒服务器建立会话,并确定传输模式:
SETUP rtsp:
CSeq: 3
Transport: RTP/AVP/TCP;unicast;interleaved=0-1
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10)
服务器回应信息:
RTSP/1.0 200 OK
Server: UServer 0.9.7_rc1
Cseq: 3
Session: 6310936469860791894
Cache-Control: no-cache
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;ssrc=6B8B4567
4.PLAY
客户端发送播放请求:
PLAY rtsp:
CSeq: 4
Session: 6310936469860791894
Range: npt=0.000-
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10)
服务器回应信息:
RTSP/1.0 200 OK
Server: UServer 0.9.7_rc1
Cseq: 4
Session: 6310936469860791894
Range: npt=0.000000-
RTP-Info: url=trackID=0;seq=17040;rtptime=1467265309
5.TEARDOWN
客户端发起关闭请求:
TEARDOWN rtsp:
CSeq: 5
Session: 6310936469860791894
User-Agent: VLC media player (LIVE555 Streaming Media v2005.11.10)
服务器回应:
RTSP/1.0 200 OK
Server: UServer 0.9.7_rc1
Cseq: 5
Session: 6310936469860791894
Connection: Close
以上方法都是交互过程中最为常用的, 其它还有一些重要的方法如get/set_parameter,pause,redirect等等
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
sdp 的格式:
v=<version>
o=<username> <session id> <version> <network type> <address type> <address>
s=<session name>
i=<session description>
u=<URI>
e=<email address>
p=<phone number>
c=<network type> <address type> <connection address>
b=<modifier>:<bandwidth-value>
t=<start time> <stop time>
r=<repeat interval> <active duration> <list of offsets from start-time>
z=<adjustment time> <offset> <adjustment time> <offset> ....
k=<method>
k=<method>:<encryption key>
a=<attribute>
a=<attribute>:<value>
m=<media> <port> <transport> <fmt list>
v = (协议版本)
o = (所有者/创建者和会话标识符)
s = (会话名称)
i = * (会话信息)
u = * (URI 描述)
e = * (Email 地址)
p = * (电话号码)
c = * (连接信息)
b = * (带宽信息)
z = * (时间区域调整)
k = * (加密密钥)
a = * (0 个或多个会话属性行)
时间描述:
t = (会话活动时间)
r = * (0或多次重复次数)
媒体描述:
m = (媒体名称和传输地址)
i = * (媒体标题)
c = * (连接信息 — 如果包含在会话层则该字段可选)
b = * (带宽信息)
k = * (加密密钥)
a = * (0 个或多个媒体属性行)