一、RTSP定义
RTSP(Real Time Streaming Protocol)是由Real Network和Netscape共同提出的如何有效地在IP网络上传输流媒体数据的应用层协议。RTSP对流媒体提供了诸如暂停,快进等控制,而它本身并不传输数据,RTSP的作用相当于流媒体服务器的远程控制。服务器端可以自行选择使用TCP或UDP来传送串流内容;
二、rtsp和http的区别和联系
(1)联系:两者都用纯文本来发送消息,且rtsp协议的语法也和HTTP类似。Rtsp一开始这样设计,也是为了能够兼容使用以前写的HTTP协议分析代码 。
(2)区别:rtsp是有状态的,不同的是RTSP的命令需要知道现在正处于一个什么状态,也就是说rtsp的命令总是按照顺序来发送,某个命令总在另外一个命令之前要发送。Rtsp不管处于什么状态都不会去断掉连接。,而http则不保存状态,协议在发送一个命令以后,连接就会断开,且命令之间是没有依赖性的。rtsp协议使用554端口,http使用80端口。
三、RTSP和RTP(rtcp)的关系
rtsp负责建立和控制会话,rtp负责多媒体的传输,rtcp配合rtp做控制和流量统计,他们是合作的关系。四、利用vlc制作流和播放器抓包
后面的报文客户端发送:OPTIONS,DESCRIBE,SETUP,PLAY,GET_PARAMETER,TEADOWN命令,跟着服务端给出应答Reply。
OPTIONS rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 2
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
RTSP/1.0 200 OK
Server: VLC/3.0.16
Content-Length: 0
Cseq: 2
Public: DESCRIBE,SETUP,TEARDOWN,PLAY,PAUSE,GET_PARAMETER
DESCRIBE rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 3
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Accept: application/sdp
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:26:13 GMT
Content-Type: application/sdp
Content-Base: rtsp://127.0.0.1:8554/
Content-Length: 547
Cache-Control: no-cache
Cseq: 3
v=0
o=- 16560084674147343137 16560084674147343137 IN IP4 LAPTOP-QF7IG4BT
s=Unnamed
i=N/A
c=IN IP4 0.0.0.0
t=0 0
a=tool:vlc 3.0.16
a=recvonly
a=type:broadcast
a=charset:UTF-8
a=control:rtsp://127.0.0.1:8554/
m=audio 0 RTP/AVP 14
b=AS:128
b=RR:0
a=rtpmap:14 MPA/90000/2
a=control:rtsp://127.0.0.1:8554/trackID=6
m=video 0 RTP/AVP 96
b=RR:0
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1;profile-level-id=64001f;sprop-parameter-sets=Z2QAH6zZQPARfvARAAADA+kAALuAjxgxlg==,aOvjyyLA;
a=control:rtsp://127.0.0.1:8554/trackID=7
SETUP rtsp://127.0.0.1:8554/trackID=6 RTSP/1.0
CSeq: 4
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=62840-62841
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:26:13 GMT
Transport: RTP/AVP/UDP;unicast;client_port=62840-62841;server_port=62842-62843;ssrc=B74F0EEE;mode=play
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 4
SETUP rtsp://127.0.0.1:8554/trackID=7 RTSP/1.0
CSeq: 5
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Transport: RTP/AVP;unicast;client_port=62844-62845
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:26:13 GMT
Transport: RTP/AVP/UDP;unicast;client_port=62844-62845;server_port=62846-62847;ssrc=8380C660;mode=play
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 5
PLAY rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 6
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
Range: npt=0.000-
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:26:13 GMT
RTP-Info: url=rtsp://127.0.0.1:8554/trackID=6;seq=33737;rtptime=574054528, url=rtsp://127.0.0.1:8554/trackID=7;seq=3939;rtptime=574054528
Range: npt=1355.216649-
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 6
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 7
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:27:11 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 7
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 8
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:28:09 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 8
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 9
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:29:07 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 9
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 10
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:30:05 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 10
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 11
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:31:03 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 11
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 12
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:32:01 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 12
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 13
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:32:59 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 13
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 14
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:33:57 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 14
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 15
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:34:55 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 15
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 16
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:35:53 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 16
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 17
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:36:51 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 17
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 18
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:37:49 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 18
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 19
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:38:47 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 19
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 20
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:39:45 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 20
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 21
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:40:43 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 21
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 22
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:41:41 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 22
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 23
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:42:39 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 23
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 24
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:43:37 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 24
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 25
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:44:35 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 25
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 26
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:45:33 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 26
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 27
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:46:31 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 27
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 28
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:47:29 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 28
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 29
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:48:27 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 29
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 30
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:49:25 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 30
GET_PARAMETER rtsp://127.0.0.1:8554/ RTSP/1.0
CSeq: 31
User-Agent: LibVLC/3.0.16 (LIVE555 Streaming Media v2016.11.28)
Session: b26cd8645f070d71
RTSP/1.0 200 OK
Server: VLC/3.0.16
Date: Tue, 08 Mar 2022 02:50:23 GMT
Session: b26cd8645f070d71;timeout=60
Content-Length: 0
Cache-Control: no-cache
Cseq: 31
五、RTSP报文结构