略微加速

略速 - 互联网笔记

基于 SRS+NG 搭建 HLS 直播流媒体服务器

2020-10-12 leiting (1444阅读)

标签 运维

搭建SRS支持HLS时如果对SRS不熟悉则很容易走弯路,以下是搭建步骤。

1.下载源码

我们使用码云提供的镜像,github上的镜像下载速度太慢太慢了。

git clone https://gitee.com/mirrors/srs.git

2.切换到2.0分支

cd srs 
git pull 
git checkout 2.0release

3.切换到trunk目录

cd trunk

4.编译安装

./configure --prefix=/usr/local/srs --with-ssl --with-hls --with-hds --with-dvr --with-nginx --with-http-callback --with-http-server --with-stream-caster --with-http-api --with-ffmpeg --with-transcode --with-ingest --with-stat --with-librtmp --with-research --with-utest --with-gperf --with-gprof   
make

经过大概十几分钟的编译后,编译成功,我们直接在当前目录启动相关的服务。

5. 启动nginx

./objs/nginx/sbin/nginx

注意如果本身已经启动了nginx,则需要将之前的nginx关闭。

6. 启动srs

选择hls.conf配置文件启动srs

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

7. 使用ffmpeg进行推流

注意音视频格式,如果只是出于测试目的则可以直接转成h264和aac再说。

相应的ip需要改成自己的ip。

ffmpeg  -re -i 35.flv -c:v libx264 -c:a aac -f flv rtmp://129.204.xxx.xx:1935/live/livestream

8. 使用ffmpeg测试拉流

RTMP

ffplay rtmp:/129.204.xxx.xx:1935/live/livestream

HLS

http://129.204.xxx.xx/live/livestream.m3u8


https://zhuanlan.zhihu.com/p/91298797


北京半月雨文化科技有限公司.版权所有 京ICP备12026184号-3