Rtsp memo

Terms,

1
2
3
4
5
6
7
8
CC: CSRC Counter
CSRC: Contributing Source
SSRC: Synchronization Source
FIR: Full Intra Request, rfc5104
FCI: Feedback Control Information
REMB: Receiver Estimated Max Bitrate
TWCC: Transport wide Congestion Control
RTX: retransmission

Sdp example

v=0
o=- 17618512456233465749 1 IN IP4 127.0.0.1
s=Session streamed with GStreamer
i=rtsp-server
t=0 0
a=tool:GStreamer
a=type:broadcast
a=control:*
a=range:npt=0-
m=video 0 RTP/AVP 96
c=IN IP4 0.0.0.0
b=AS:3000
a=rtpmap:96 H264/90000
a=framerate:30
a=fmtp:96 packetization-mode=1;sprop-parameter-sets=J2QAFKwrYKD9gIgAAAMACAAAAwHnQgAW4gAC3G173wdocKuA,KO48sA==;profile-level-id=640014;level-asymmetry-allowed=1
a=control:stream=0
a=ts-refclk:local
a=mediaclk:sender
a=ssrc:4060724388 cname:user1571168269@host-d3352119

refer to:
https://www.rfc-editor.org/rfc/rfc3550
https://www.rfc-editor.org/rfc/rfc3551
https://www.rfc-editor.org/rfc/rfc2326
https://www.rfc-editor.org/rfc/rfc4588
https://www.rfc-editor.org/rfc/rfc4585
https://www.rfc-editor.org/rfc/rfc7273
https://blog.csdn.net/weixin_42462202/article/details/98986535
https://github.com/fanxiushu/xdisp_virt
https://www.ngui.cc/el/72647.html

How to build rtsp stream from a mp4 file to test EuhatRtsp

First, convert mp4 file to h264 file, save script below as convert.bat

1
2
3
ffmpeg.exe -i %1 -s 1920x1080 -b:v 1536K -an output.mp4
ffmpeg -i output.mp4 -codec copy -bsf: h264_mp4toannexb -f h264 output.264
#ffmpeg -i test.264 -vcodec copy -f mp4 test.mp4

drag a mp4 file over convert.bat, after a while, output.264 will be generated. download h264LiveMediaServer.zip, unzip as h264LiveMediaServer.exe, move it to the same directory with output.264, just double click and run h264LiveMediaServer.exe, it will notify you the rtsp url, then input the url in the url edit box on the EuhatRtsp Demo app ui, click begin button, wait several seconds, you will see the video rendering in EuhatRtsp.

Before running h264LiveMediaServer.exe, vc2019 x86 Redistributable must be installed.

Visit H264LiveMediaServer on Github to get the source code.

whether go through tcp or udp using EuhatRtsp

app/src/main/java/com/euhat/rtsp/euhatrtspdemo/MainActivity.java

108
109
// try to modify the 3rd parameter to 0.
mEuhatPlayer.open(url, 8000, 0, 1000, fps, 300);

How to record the H264 stream using EuhatRtsp lib

euhatrtsp/livevideo/RtspOp.cpp

389
390
391
392
393
394
395
396
397
int EuhatRtspOp::decodingProc()
{//frame是原始H264数据,在这里录像最好,此库已经把ffmpeg库编译进去了,直接用ffmpeg库就可以完成录像功能。
//可以网上搜ffmpeg录像api怎么用。
//这就要求会写C++代码,还要加jni接口提供给java端打开或关闭录像功能。
decoder_->decode(frame + 4, *(int *)frame);}

将视频文件变成RTSP流服务

http://ffbinaries.com/downloads下载ffserver到linux系统,

制作server.cfg文件如下

1
2
3
4
5
6
7
8
9
10
11
12
13
14
RTSPPort 5454
BindAddress 0.0.0.0
RTSPBindAddress 0.0.0.0
MaxHTTPConnections 2000
MaxClients 1000
MaxBandwidth 30000
CustomLog -
NoDaemon
#NoDefaults
 
<Stream test.mp4>
File "/home/sdb/work/stream/test.mp4"
Format rtp
</Stream>

命令行运行

1
./ffserver -f server.cfg

这样,任何地方,只要能连接到此linux系统,其IP地址为192.168.1.32,都可以播放

1
rtsp://192.168.1.32:5454/test.mp4