原創博客地址:軟件_搭建rtsp視頻推送環境
live555編譯安裝啓動
編譯
1 2 3 4 5 |
wget http://www.live555.com/liveMedia/public/live555-latest.tar.gz tar xzf live555-latest.tar.gz cd live ./genMakefiles linux-64bit #注意後面這個參數是根據當前文件夾下config.<後綴>獲取得到的 make |
啓動:cd mediaServer && ./live555MediaServer
打印出這些就說明編譯安裝成功了。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
[root@localhost mediaServer]# ./live555MediaServer LIVE555 Media Server version 0.89 (LIVE555 Streaming Media library version 2016.06.26). Play streams from this server using the URL rtsp://192.168.0.111/<filename> #這個就是訪問的url地址 where <filename> is a file present in the current directory. Each file's type is inferred from its name suffix: ".264" => a H.264 Video Elementary Stream file ".265" => a H.265 Video Elementary Stream file ".aac" => an AAC Audio (ADTS format) file ".ac3" => an AC-3 Audio file ".amr" => an AMR Audio file ".dv" => a DV Video file ".m4e" => a MPEG-4 Video Elementary Stream file ".mkv" => a Matroska audio+video+(optional)subtitles file ".mp3" => a MPEG-1 or 2 Audio file ".mpg" => a MPEG-1 or 2 Program Stream (audio+video) file ".ogg" or ".ogv" or ".opus" => an Ogg audio and/or video file ".ts" => a MPEG Transport Stream file (a ".tsx" index file - if present - provides server 'trick play' support) ".vob" => a VOB (MPEG-2 video with AC-3 audio) file ".wav" => a WAV Audio file ".webm" => a WebM audio(Vorbis)+video(VP8) file See http://www.live555.com/mediaServer/ for additional documentation. (We use port 80 for optional RTSP-over-HTTP tunneling, or for HTTP live streaming (for indexed Transport Stream files only).) |
填充視頻
將視頻放到和live555MediaServer同路徑下就可以了。
需要留意的是live555並不支持mp4格式,需要將mp4轉爲mkv
1 |
ffmpeg -i xxx.mp4 xxx.mkv |
此時用播放軟件播放地址:
1 2 3 |
vlc rtsp://192.168.0.111/xxx.mkv or ffplay rtsp://192.168.0.111/xxx.mkv |
花屏問題01緩衝區大小
視頻的前幾秒鐘可能會有花屏問題,網上查了查,原因在於緩衝區大小不足。需要修改緩衝區大小
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
live555推送之後的視頻流出現花屏,查看源碼DynamicRTSPServer.cpp文件,源碼如下: sms->addSubsession(MPEG4VideoFileServerMediaSubsession::createNew(env, fileName, reuseSource)); } else if (strcmp(extension, ".264") == 0) { // Assumed to be a H.264 Video Elementary Stream file: NEW_SMS("H.264 Video"); OutPacketBuffer::maxSize = 100000; // allow for some possibly large H.264 frames sms->addSubsession(H264VideoFileServerMediaSubsession::createNew(env, fileName, reuseSource)); } else if (strcmp(extension, ".265") == 0) { // Assumed to be a H.265 Video Elementary Stream file: NEW_SMS("H.265 Video"); OutPacketBuffer::maxSize = 100000; // allow for some possibly large H.265 frames sms->addSubsession(H265VideoFileServerMediaSubsession::createNew(env, fileName, reuseSource)); } else if (strcmp(extension, ".mp3") == 0) { // Assumed to be a MPEG-1 or 2 Audio file: NEW_SMS("MPEG-1 or 2 Audio") |
查看上面紅色部分對於H264和H265輸出包最大緩衝100000字節(100K),對於高清視頻緩衝區太小了,必需更改大些。目前更改到800000,對於1080P視頻使用VLC播放時,不會再出現花屏。
可用如下信息查詢出需要修改那些文件:grep -rnw . -e ‘OutPacketBuffer::maxSize = ‘,需要修改buff的文件
修改後花屏問題可能存在,但視頻卡頓問題會得到解決。
花屏問題02視頻格式
花屏問題依然存在,本人曾經嘗試過用h264格式代替mkv,發現live555無法識別h264格式,偶然掃到命令提示部分,發現live555支持的h264需要的擴展格式爲264,將h264擴展改爲264,發現花屏問題得到解決,(但是解決的並不完美)。
視頻處理:
1 2 |
ffmpeg -i xxx.mp4 xxx.h264 mv xxx.h264 xxx.264 |
將視頻複製到live555MediaServer同路徑下,啓動後連接rtsp地址,發現花屏問題得以解決。
小視頻一般都是ok的(小於10M),大視頻則會有問題(大於200M),vlc連接大視頻的rtsp時依然會出現花屏問題。
1 2 3 |
opencv連接rtsp:ok ffplay連接rtsp:ok vlc連接rtsp:花屏 |
猜測是vlc對部分碼流數據兼容不佳,或者視頻源有問題,總之3個播放工具2個沒問題,可以認爲rtsp是ok的。
參考
用VLC做流媒體服務器:https://blog.csdn.net/redstarofsleep/article/details/49273405
win:利用live555搭建最簡單的rtsp流媒體服務:https://blog.csdn.net/huweijian5/article/details/53928521
使用live555 在linux下搭建 rtsp server:https://www.cnblogs.com/dpf-10/p/5623101.html
nginx+rtmp:https://hub.docker.com/r/datarhei/nginx-rtmp/
nginx+rtsp:https://hub.docker.com/r/srnbckr/nginx-rtsp
ffmpeg+ffserver搭建rtsp服務器:https://blog.csdn.net/FPGATOM/article/details/98782202
live555推送1080p花屏:https://blog.csdn.net/youyicc/article/details/79862762
流媒體開發之開源項目live555—更改server端的幀率大小和碼率大小:https://www.cnblogs.com/pengkunfan/p/3975442.html