ubuntu20.04+live555搭建rtsp推流服务器
文章目录
1.下载live555并解压
wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz
tar xzf live555-latest.tar.gz
# 解压后修改权限
sudo chmod -R 777 live
2. 编译
# 编辑config.linux-64bit,在第一行最后加上-DNO_STD_LIB,不然会报error: ‘struct std::atomic_flag’ has no member named ‘test’
cd live
vim config.linux-64bit
COMPILE_OPTS = $(INCLUDES) -m64 -fPIC -I/usr/local/include -I. -O2 -DSOCKLEN_T=socklen_t -D_LARGEFILE_SOURCE=1 -D_FILE_OFFSET_BITS=64 -DNO_STD_LIB
# 编译
./genMakefiles linux-64bit
make
3. 开启rtsp服务
cd mediaServer
chmod 777 live555MediaServer
# 启动rtsp服务
./live555MediaServer
# 将视频放在与live555MediaServe同级目录下
# 注意mp4文件要通过ffmpeg转换为264格式才可以,直接更改后缀不能播放
ffmpeg -i test.mp4 -codec copy -bsf: h264_mp4toannexb -f h264 test.264
# 通过vlc访问rtsp地址
rtsp://192.168.0.50:8554/test.264
4.MultiFramedRTPSink::afterGettingFrame1(): The input frame data was too large for our buffer size解决方法
Generally, while running HD stream, one can face packet loss due to ridiculously large NAL units. This will create an error stating something like ->
“MultiFramedRTPSink::afterGettingFrame1(): The input frame data was too large for our buffer size (60753). 34086 bytes of trailing data was dropped! Correct this by increasing "OutPacketBuffer::maxSize" to at least 94839, *before* creating this 'RTPSink'. (Current value is 60000.)”
To solve this, you need to make the following changes to your code:
1. Go to “live/liveMedia/MultiFramedRTPsource.cpp” and change “increaseRecieveBufferTo(env, RTPgs-> socketNUm(), 2000000)”
2. Go to “live/liveMedia/StreamParser.cpp” and increase BANK_SIZE to 300000 or 600000.
(This will also help remove StreamParser Error that you might encounter!)
3. In “live/liveMedia/MediaSink.cpp” change the value of unsigned OutPacketBuffer::max size to 600000.
4. In “mediaServer/DynamicRTSPServer.cpp”, change OutPacketBuffer::maxSize to 600000 at all places where it is defined.
5. *Most importantly, you need to change the code in your own program, more so than the libraries themselves. This means that if you just do what pt.5 tells you to, you can avoid pts 1-4. Therefore, in your code change OutPacketBuffer::maxsize to 600000 (Our code file is testH264VideoStreamer.cpp so we made the above change in that. Note: testH264VideoStreamer.cpp lies in testProgs directory). You NEED to change this value in your code before you create any RTP sinks.
6. Also to allow for more holistic changes, go to “testProgs/playCommon.cpp” and change the value of fileSinkBufferSize to 600000.
///WHAT ELSE CAN BE DONE
It is more advisable to reduce the buffer size of your stream by increasing compression levels. Also you would need to increase the buffer size of vlc player to allow for smooth streaming. To do so, go to VLC-> Tools -> Preferences -> Select “Show All” -> Click on Stream Output -> Change “stream output muxer caching” to a suitable value in ms. (1500 - 3000)
er caching” to a suitable value in ms. (1500 - 3000)