感謝武總:https://blog.csdn.net/wutong_login/article/details/90257697linux
目前互聯網上的視頻直播有兩種,一種是基於RTMP協議的直播,這種直播方式上行推流使用RTMP協議,下行播放使用RTMP,HTTP+FLV或者HLS,直播延時通常大於3秒,普遍應用秀場、遊戲、賽事和事件直播,知足了對交互要求不高的場景;另外一種是WebRTC協議的直播,這種直播方式使用UDP的協議進行流媒體的分發,直播延時小於1秒,同時鏈接數通常小於10個,主要應用在視頻通話、秀場連麥等應用場景。git
除了上述兩種場景外,還有一種視頻直播的場景,就是同時要求低延時和大併發的場景,好比賽事直播、股票信息同步、大班教育等。SRT能夠很好地知足上述場景的要求。github
SRT:Secure Reliable Transport (SRT) 是一個開源的傳輸協議架構,基於UDT(可靠UDP協議)實現,主要是優化在不可靠網絡上的傳輸性能。ubuntu
SRT源代碼:https://github.com/Haivision/srtcentos
SRT提供了簡單的使用Demo,能夠方便使用者進行簡單的測試和延時驗證。服務器
若是要使用SRT進行大規模併發直播,能夠參考 srt-live-serve,這是基於SRT協議的直播服務器處理架構。網絡
srt-live-server 源代碼:https://github.com/Edward-Wu/srt-live-server架構
ReadMe:併發
srt-live-server
srt live server based on srt(Secure, Reliable, Transport)
app
Introduction
srt-live-server(SLS) is an open source live streaming server for low latency based on Secure Reliable Tranport(SRT). Normally, the latency of transport by SLS is less than 1 second in internet.
Requirements
please install the SRT first, refer to SRT(https://github.com/Haivision/srt) for system enviroment. SLS can only run on OS based on linux, such as mac, centos or ubuntu etc.
Complie
$ sudo make bin file is generated in subdir of 'bin'.
Usage
$ cd bin
1.help information $ ./sls -h
2.run with default config file $ ./sls -c ../sls.conf
Test
SLS only supports the MPEG-TS format streaming. you can push camera live stream by FFMPEG.Please download ffmpeg sourcecode from https://github.com/FFmpeg/FFmpeg, then compile FFMPEG with --enable-libsrt.
1.use ffmpeg to push camera stream with SRT(on my mac):
$ ./ffmpeg -f avfoundation -framerate 30 -i "0:0" -vcodec libx264 -preset ultrafast -tune zerolatency -flags2 local_header -acodec libmp3lame -g 30 -pkt_size 1316 -flush_packets 0 -f mpegts "srt://[your.sls.ip]:8080?streamid=uplive.sls.com/uplive/test"
2.play the SRT stream with ffplay:
./ffplay -fflag nobuffer -i "srt://[your.sls.ip]:8080?streamid=live.sls.com/live/test"
Note:
1.SLS refer to the RTMP url format(domain/app/stream_name), example: www.sls.com/live/test. The url of SLS must be set in streamid parameter of SRT, which will be the unique identification a stream. 2.How to distinguish the publisher and player of the same stream? In conf file, you can set parameters of domain_player/domain_publisher and app_player/app_publisher to resolve it. Importantly, the two combination strings of domain_publisher/app_publisher and domain_player/app_player must not be equal in the same server block.
若有錯誤請指正: