CentOS7下利用SRS搭建直播流媒体服务器

时间:2022-07-24
本文章向大家介绍CentOS7下利用SRS搭建直播流媒体服务器,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

SRS is a RTMP/HLS/WebRTC/SRT/GB28181 streaming cluster, high efficiency, stable and simple.

SRS定位是运营级的互联网直播服务器集群,追求更好的概念完整性和最简单实现的代码

1)SRS提供了丰富的接入方案将RTMP流接入SRS, 包括推送RTMP到SRS、推送RTSP/UDP/FLV到SRS、拉取流到SRS

2)SRS还支持将接入的RTMP流进行各种变换,譬如将RTMP流转码、流截图、 转发给其他服务器、转封装成HTTP-FLV流、转封装成HLS、 转封装成HDS、转封装成DASH、录制成FLV/MP4

3)SRS包含支大规模集群如CDN业务的关键特性, 譬如RTMP多级集群、源站集群、VHOST虚拟服务器 、 无中断服务Reload、HTTP-FLV集群

4)此外,SRS还提供丰富的应用接口, 包括HTTP回调、安全策略Security、HTTP API接口、 RTMP测速。

5)SRS在源站和CDN集群中都得到了广泛的应用

GitHub地址:https://github.com/ossrs/srs

CentOS7下利用SRS搭建直播流媒体服务器

1、下载SRS 源码包

https://github.com/ossrs/srs/archive/v3.0-r0.tar.gz

2、上传到CentOS7的服务器,进行解压

tar -zxvf srs-3.0-r0.tar.gz
cd srs-3.0-r0/trunk/
./configure
make
make install

3、设置服务开机自启动

ln -sf /usr/local/srs/etc/init.d/srs /etc/init.d/srs
cp -f /usr/local/srs/usr/lib/systemd/system/srs.service /usr/lib/systemd/system/srs.service
systemctl daemon-reload
systemctl enable srs
systemctl start srs

4、用rpmfusion源安装ffmpeg

这里为了方便起见就不采用源码方式编译安装ffmpeg了,直接使用rpmfusion源安装ffmpeg 具体命令如下

wget -O /etc/yum.repos.d/CentOS-Base.repo https://mirrors.aliyun.com/repo/Centos-7.repo
sed -i -e '/mirrors.cloud.aliyuncs.com/d' -e '/mirrors.aliyuncs.com/d' /etc/yum.repos.d/CentOS-Base.repo
wget -O /etc/yum.repos.d/epel.repo http://mirrors.aliyun.com/repo/epel-7.repo
yum install epel-release
wget https://mirrors.aliyun.com/rpmfusion/free/el/rpmfusion-free-release-7.noarch.rpm
rpm -ivh rpmfusion-free-release-7.noarch.rpm
yum install ffmpeg

5、使用FFMPEG命令推流

 ffmpeg -re -i /data/TenetTrails.mp4 -vcodec copy -acodec copy -f flv -y rtmp://192.168.31.80/live/livestream

上传TenetTrails.mp4文件到服务器,ffmpeg -re -i /data/TenetTrails.mp4 -vcodec copy -acodec copy -f flv -y rtmp://192.168.31.80/live/livestream进行推流

6、使用VLC观看RTMP流

RTMP流地址为 rtmp://192.168.31.80/live/livestream

7、使用VLC观看HLS流

先停止systemctl stop srs 需要单独启动srs,只加载hls.conf

./objs/srs -c conf/hls.conf

当然你也可以将hls配置文件添加到srs.conf 接下来使用FFMPEG命令推流

ffmpeg -re -i /data/TenetTrails.mp4 -vcodec copy -acodec copy -f flv -y rtmp://192.168.31.80/live/livestream

VLC打开网络串流 HLS流地址为 http://192.168.31.80:8080/live/livestream.m3u8

8、iftop命令查看实时网络流量

iftop -i ens33  -N -n -m 10M -P 

更多用法参考官方wiki

链接如下https://github.com/ossrs/srs/wiki