直播

参考 http://blog.itpub.net/31559758/viewspace-2220944/

https://www.jianshu.com/p/f304b3d18713

https://github.com/ossrs/srs/wiki/v3_CN_SampleHLS

安装

nginx ubuntu安装https://wiki.ubuntu.org.cn/Nginx

查看/etc/nginx/sites-available/default,可以看到默认虚拟路径: root /var/www/html;

增加一个虚拟路径,用于直播, 修改配置后重启nginx, 访问localhost/live能触发index.html文件就表示修改成功

  location /live/ {
        alias /home/sain/Videos/live/;
        autoindex on;
    }

srs源码安装

git clone https://github.com/ossrs/srs
vi srs/trunk/conf/srs.conf
修改max_connections    1000;为max_connections     100;
注意:若不修改此值后面编译中会报错
cd srs/trunk
./configure
注意:在mac 系统中./configure 时需要添加  --osx,最新mac系统编译不过
make

由于srs在mac10.15上无法编译,本次测试使用的方案是:

srs 运行在ubuntu虚拟机

nginx运行在ubuntu虚拟机(hls类型的流媒体需要nginx支持)

ods 运行max系统

运行SRS服务

启动服务 ./objs/srs -c conf/hls.conf

其他指令如:

启动 ./etc/init.d/srs start

停止 ./etc/init.d/srs stop

重启 ./etc/init.d/srs restart

srs有许多不同的配置文件,这里采用hls.conf配置(比较方便,结合nginx可以实现网页直接观看)

如果使用rtmp.conf启动的话需要能解析rtmp流的播放器

conf/hls.conf 配置如下:

# the config for srs to delivery hls
# @see https://github.com/ossrs/srs/wiki/v1_CN_SampleHLS
# @see full.conf for detail config.

listen              1935;
max_connections     1000;
daemon              off;
srs_log_tank        console;
vhost __defaultVhost__ {
    hls {
        enabled         on;
        hls_fragment    10;
        hls_window      60;
        hls_path        /home/sain/Videos/live;
        hls_m3u8_file   [app]/[stream].m3u8;
        hls_ts_file     [app]/[stream]-[seq].ts;
    }
}

注: /home/sain/Videos/live目录会缓存流媒体文件

配置nginx虚拟目录,就是为了很方便访问到该目录下的静态资源

桌面端ods studio配置

ods不是必须的,但相较于mmpeg命令方便很多,主要作用应该是进行视频流的编解码。

ods来源: 媒体源

ods软件设置:

server : 流媒体ip(srs服务地址)

stream key : 为流媒体的名称

image.png

浏览器访问流媒体

注意要用safari浏览器,因为hls苹果支持最好,chrome测试不行

直接打开链接: http://172.16.152.31/live/stream/live.m3u8

或者写成html文件




    
    





Android 端

桌面系统上,使用ods扮演了直播源,在Android端,通常就是借助于camera采集视频源,而整个流媒体服务器是共用的,Android端代码可以直接参考https://github.com/SiKang123/LiveTest,采集测试ok,播放有点问题

https://blog.csdn.net/weixin_34060299/article/details/85938295

你可能感兴趣的:(直播)