美文网首页
centos7搭建srs2流媒体服务器,实现摄像头hls流低延时

centos7搭建srs2流媒体服务器,实现摄像头hls流低延时

作者: 小偷阿辉 | 来源:发表于2019-04-19 14:54 被阅读0次
此方式延迟较高,20秒以上延迟均属正常,配置此方式为苹果用户使用,安卓建议使用flv配置,详情可以参考https://www.jianshu.com/p/2647393f956a

首先访问srs官网
https://github.com/ossrs/srs
下载srs2

git clone https://github.com/ossrs/srs

推荐使用中国镜像下载

git clone https://git.oschina.net/winlinvip/srs.oschina.git

更新最新代码

cd ./srs/trunk&&git pull

编译安装

./configure --prefix=/usr/local/srs-hls&&make&&make install

稍等一会~

编辑配置文件

vi ./conf/hls.conf

插入以下配置,配置详情请参考https://github.com/ossrs/srs/wiki/v2_CN_DeliveryHLS


listen              1935;
max_connections     1000;
#启用http服务,分发使用go静态代理
http_server {
    enabled         on;
    listen          80;
   # crossdomain     on;
    dir             ./objs/nginx/html;
}
vhost __defaultVhost__ {
    hls {
        enabled         on;#是否开启HLS,on/off,默认off。
        hls_path        ./objs/nginx/html;#HLS的m3u8和ts文件保存的路径,配置后请创建文件夹
        hls_fragment    8;#秒,指定ts切片的最小长度
        hls_window      30;#秒,指定HLS窗口大小,即m3u8中ts文件的时长之和
        hls_m3u8_file   [app]/[stream].m3u8;# HLS的m3u8文件名
        hls_ts_file     [app]/[stream]-[seq].ts;#HLS的ts文件名,包含可替换的一系列变量
        hls_cleanup     on;#是否删除过期的ts切片
        hls_dispose     5;#HLS清理的过期时间(秒),系统重启或者超过这个时间时,清理#HLS的所有文件,包括m3u8和ts。默认为0,即不清理
    }
}

之后启动srs for hls

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

查看进程

ps -ef|grep srs
image.png
执行ffmpeg推流命令
命令options请参考http://www.cuplayer.com/player/PlayerCode/FFmpeg/2018/1114/3329.html
ffmpeg -re  -rtsp_transport tcp -threads 1 -buffer_size 1024000 -max_delay 500000 -i rtsp:admin:@192.168.3.22:554/stream1 -c:v libx264 -b:v 350k -profile:v baseline -level 3.0  -acodec aac  -strict experimental -ar 44100 -ac 2 -b:a 96k  -fflags nobuffer -preset  ultrafast -tune   zerolatency -vcodec h264 -f flv -an rtmp://192.168.153.128:1935/live/192168322

HLS流地址为: http://192.168.153.128/live/192168322.m3u8

你会发现,直接访问会出现跨域问题,这时候,我们就需要使用go静态代理
GitHub地址https://github.com/ossrs/go-oryx.git
使用前请安装go
安装可参考http://www.runoob.com/go/go-environment.html

安装后,配置环境变量可参考
http://wiki.jikexueyuan.com/project/go-web-programming/01.2.html

执行启动静态代理服务器
$GOPATH/bin/httpx-static -http 端口-root pwd/html -proxy 代理地址

go get github.com/ossrs/go-oryx/httpx-static &&
cd $GOPATH/src/github.com/ossrs/go-oryx/httpx-static &&
openssl genrsa -out server.key 2048 &&
subj="/C=CN/ST=Beijing/L=Beijing/O=Me/OU=Me/CN=me.org" &&
openssl req -new -x509 -key server.key -out server.crt -days 365 -subj $subj &&
$GOPATH/bin/httpx-static -http 8443 -root `pwd`/html -proxy http://192.168.153.128:80/live

此后,我们通过8443端口访问流媒体拉流

访问地址为http://192.168.153.128:8443/live/192168322.m3u8

video.js配置为(微信浏览器版本)

<!DOCTYPE html>
<html>

<head>
    <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
    <title>flv.js demo</title>
    <link th:href="@{/vide7.1.0/css/video-js.min.css}" rel="stylesheet">
    <script th:src="@{/jquery.min.js}"></script>
<script th:src="@{/vide7.1.0/js/video.min.js}"></script>
<script th:src="@{/vide7.1.0/js/videojs-ie8.min.js}"></script>

</head>

<body>
<div style='display: block;'> 
                            <video  muted  width="480\"  height="320" x-webkit-airplay="allow" x5-video-player-type="h5" x5-video-player-fullscreen="false"  x5-playsinline=""playsinline="" webkit-playsinline="true"  preload="auto" id="video" class=" video-js vjs-default-skin"   poster="img/poster.jpg" width="100%" height="100%" controls preload="auto"
                            data-setup='{}' loop>
                            <source  src="http://192.168.153.128:8443/live/192168322.m3u8'>
                            <p class="vjs-no-js">  播放视频需要启用 JavaScript,推荐使用<a href="http://videojs.com/html5-video-support" target="_blank">支持HTML5</a>的浏览器访问。</p>
                            </video>
                               </div>;

</body>


<script>

 var player=videojs("video"+i,{
                            controls:false,
                            autoplay:false,
                            preload:"metadata",
                            muted : true,
                            teachOrder:['myTech','html5'],//播放首选项,依次使用
                        },function () {
                            // player.src("http://ivi.bupt.edu.cn/hls/cctv3hd.m3u8");//obj.rtmpUrl
                            // player.src({
                            //     withCredentials: false
                            // });
                            player.src.withCredentials=false;
                            player.src.cors=true;
                            player.src.autoplay=true;
                            this.on("ended",function () {
                                videojs.log("What  fuck happenning");
                            });
                            // player.load();
                            //this.play();
                        });

                        //player.load(obj.rtmpUrl);//obj.rtmpUrl
                        player.play();
</script>

相关文章

网友评论

      本文标题:centos7搭建srs2流媒体服务器,实现摄像头hls流低延时

      本文链接:https://www.haomeiwen.com/subject/oymqgqtx.html