srt-live-server:一款基于SRT的毫秒级低延时直播服务器

目前互联网上的视频直播有两种,一种是基于RTMP协议的直播,这种直播方式上行推流使用RTMP协议,下行播放使用RTMP,HTTP+FLV或者HLS,直播延时一般大于3秒,广泛应用秀场、游戏、赛事和事件直播,满足了对交互要求不高的场景;另一种是WebRTC协议的直播,这种直播方式使用UDP的协议进行流媒体的分发,直播延时小于1秒,同时连接数一般小于10个,主要应用在视频通话、秀场连麦等应用场景。

除了上述两种场景外,还有一种视频直播的场景,就是同时要求低延时和大并发的场景,比如赛事直播、股票信息同步、大班教育等。SRT可以很好地满足上述场景的要求。

SRT:Secure Reliable Transport (SRT) 是一个开源的传输协议架构,基于UDT(可靠UDP协议)实现,主要是优化在不可靠网络上的传输性能。

SRT源代码:https://github.com/Haivision/srt
SRT提供了简单的使用Demo,可以方便使用者进行简单的测试和延时验证。
如果要使用SRT进行大规模并发直播,可以参考 srt-live-serve,这是基于SRT协议的直播服务器处理架构。
srt-live-server 源代码:https://github.com/Edward-Wu/srt-live-server

ReadMe:

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.

Compile

$ sudo make

在这里插入图片描述

Directivies

about the config file, please see the wiki: https://github.com/Edward-Wu/srt-live-server/wiki/Directives

Usage

$ cd bin

1.help information

$ ./sls -h
在这里插入图片描述
解决办法:
把编译完成的srt1.4.1.so.1做个软链接即可。
在这里插入图片描述
2.run with default config file

$ ./sls -c …/sls.conf
$ ./slc -r …/sls.conf
在这里插入图片描述
在这里插入图片描述
sls -c sls.conf执行后报:Segmentation fault (core dumped)

Test

SLS only supports the MPEG-TS format streaming.

1.test with ffmpeg

you can push camera live stream by FFMPEG.Please download ffmpeg sourcecode from https://github.com/FFmpeg/FFmpeg, then compile FFMPEG with --enable-libsrt.

srt library is installed in folder /usr/local/lib64. if “ERROR: srt >= 1.3.0 not found using pkg-config” occured when compiling FFMPEG, please check the ffbuild/config.log file and follow its instruction to resolve this issue. in most cases it can be resolved by the following command: export PKG_CONFIG_PATH=/usr/local/lib/pkgconfig:/usr/local/lib64/pkgconfig

if “error while loading shared libraries: libsrt.so.1” occured, please add srt library path to file ‘/etc/ld.so.conf’ as the default path, then refresh by comand /sbin/ldconfig with root.

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/live/test”

play the SRT stream with ffplay:

./ffplay -fflag nobuffer -i “srt://[your.sls.ip]:8080?streamid=live.sls.com/live/test”

2.test with OBS

the OBS supports srt protocol to publish stream when version is later than v25.0. you can use the following url: srt://[your.sls.ip]:8080?streamid=uplive.sls.com/live/test whith custom service.

3.test with srt-live-client

there is a test tool in sls, which can be used performance test because of no codec overhead but main network overhead. the slc can play a srt stream to a ts file, or push a ts file to a srt stream.

push ts file as srt url:

cd bin

./slc -r srt://[your.sls.ip]:8080?streamid=uplive.sls.com/live/test -i [the full file name of exist ts file]

play srt url

./slc -r srt://[your.sls.ip]:8080?streamid=uplive.sls.com/live/test -o [the full file name of ts file to save]

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.

3.I supply a simple android app for test sls, your can download from https://github.com/Edward-Wu/liteplayer-srt

原文链接: https://blog.csdn.net/wutong_login/article/details/90257697 https://github.com/Edward-Wu/srt-live-server