rtsp超分推流流程(一)

记录一下rtsp 推流的流程

播放一个RTSP的流需要如下的RTSP请求命令:
OPTIONS -> DESCRIBE -> SETUP -> PLAY 然后就是接收RTP包、播放了
抓包分析出来,推流的RTSP请求命令如下:
OPTIONS -> ANNOUNCE -> SETUP -> RECORD

可以使用ffmpeg命令来模拟一路视频和音频推流,
ffmpeg -re -stream_loop -1 -i abc.mkv -rtsp_transport tcp -c copy -f rtsp rtsp://127.0.0.1:8554/stream

udp 推流

OPTIONS rtsp://192.168.0.135:8554/stream RTSP/1.0
CSeq: 1
User-Agent: Lavf60.16.100

RTSP/1.0 200 OK
CSeq: 1
Public: DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, GET_PARAMETER, TEARDOWN
Server: gortsplib

ANNOUNCE rtsp://192.168.0.135:8554/stream RTSP/1.0
Content-Type: application/sdp
CSeq: 2
User-Agent: Lavf60.16.100
Content-Length: 500

**v=0
o=- 0 0 IN IP4 127.0.0.1
s=No Name
c=IN IP4 192.168.0.135
t=0 0
a=tool:libavformat 60.16.100
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAH6wspQFAFuwFqAgICgAAB9AAAdTBwAAATEsAACYlrd5cFA==,aOuPLA==; profile-level-id=64001F
a=control:streamid=0
m=audio 0 RTP/AVP 97
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=119056E500
a=control:streamid=1
**
RTSP/1.0 200 OK
CSeq: 2
Server: qbserver

SETUP rtsp://192.168.0.135:8554/stream/streamid=0 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;client_port=17130-17131;mode=record
CSeq: 3
User-Agent: Lavf60.16.100

RTSP/1.0 200 OK
CSeq: 3
Server: gortsplib
Session: 04528041c4c342a7a3d1e0bbeb28b8e1
Transport: RTP/AVP;unicast;client_port=17130-17131;server_port=8000-8001

SETUP rtsp://192.168.0.135:8554/stream/streamid=1 RTSP/1.0
Transport: RTP/AVP/UDP;unicast;client_port=17132-17133;mode=record
CSeq: 4
User-Agent: Lavf60.16.100
Session: 04528041c4c342a7a3d1e0bbeb28b8e1

RTSP/1.0 200 OK
CSeq: 4
Server: gortsplib
Session: 04528041c4c342a7a3d1e0bbeb28b8e1
Transport: RTP/AVP;unicast;client_port=17132-17133;server_port=8000-8001

RECORD rtsp://192.168.0.135:8554/stream RTSP/1.0
Range: npt=0.000-
CSeq: 5
User-Agent: Lavf60.16.100
Session: 04528041c4c342a7a3d1e0bbeb28b8e1

RTSP/1.0 200 OK
CSeq: 5
Server: gortsplib
Session: 04528041c4c342a7a3d1e0bbeb28b8e1

EASYPUSHER安卓ANDROID手机直播推送之MEDIACODEC 硬编码H264格式
https://www.freesion.com/article/4282847055/

tcp 推流

以下是tcp,重点是tcp,尤其是在需要外网的时候,必须使用tcp来推流,udp方式是通不过的。

OPTIONS rtsp://127.0.0.1:8554/stream RTSP/1.0
CSeq: 1
User-Agent: Lavf60.16.100

RTSP/1.0 200 OK
CSeq: 1
Public: DESCRIBE, ANNOUNCE, SETUP, PLAY, RECORD, PAUSE, GET_PARAMETER, TEARDOWN
Server: gortsplib

ANNOUNCE rtsp://127.0.0.1:8554/stream RTSP/1.0
Content-Type: application/sdp
CSeq: 2
User-Agent: Lavf60.16.100
Content-Length: 496
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 60.16.100
m=video 0 RTP/AVP 96
a=rtpmap:96 H264/90000
a=fmtp:96 packetization-mode=1; sprop-parameter-sets=Z2QAH6wspQFAFuwFqAgICgAAB9AAAdTBwAAATEsAACYlrd5cFA==,aOuPLA==; profile-level-id=64001F
a=control:streamid=0
m=audio 0 RTP/AVP 97
a=rtpmap:97 MPEG4-GENERIC/48000/2
a=fmtp:97 profile-level-id=1;mode=AAC-hbr;sizelength=13;indexlength=3;indexdeltalength=3; config=119056E500
a=control:streamid=1
RTSP/1.0 200 OK
CSeq: 2
Server: gortsplib

SETUP rtsp://127.0.0.1:8554/stream/streamid=0 RTSP/1.0
Transport: RTP/AVP/TCP;unicast;interleaved=0-1;mode=record
CSeq: 3
User-Agent: Lavf60.16.100

RTSP/1.0 200 OK
CSeq: 3
Server: gortsplib
Session: 74c1debd7c2f45da974c4c6fc80d6fc6
Transport: RTP/AVP/TCP;unicast;interleaved=0-1

SETUP rtsp://127.0.0.1:8554/stream/streamid=1 RTSP/1.0
Transport: RTP/AVP/TCP;unicast;interleaved=2-3;mode=record
CSeq: 4
User-Agent: Lavf60.16.100
Session: 74c1debd7c2f45da974c4c6fc80d6fc6

RTSP/1.0 200 OK
CSeq: 4
Server: gortsplib
Session: 74c1debd7c2f45da974c4c6fc80d6fc6
Transport: RTP/AVP/TCP;unicast;interleaved=2-3

RECORD rtsp://127.0.0.1:8554/stream RTSP/1.0
Range: npt=0.000-
CSeq: 5
User-Agent: Lavf60.16.100
Session: 74c1debd7c2f45da974c4c6fc80d6fc6

RTSP/1.0 200 OK
CSeq: 5
Server: gortsplib
Session: 74c1debd7c2f45da974c4c6fc80d6fc6

以下是一些可以参考的资料
https://github.com/fyhertz/spydroid-ipcamera
https://github.com/kidloserme
https://github.com/Oo-Dev/OoDroid2

超分媒体服务

下期再讲

你可能感兴趣的:(ffmpeg,音视频和c++,java,物联网,音视频,ffmpeg)