使用开源的SRS 搭建一个直播服务

栏目: 服务器 · 发布时间: 5年前

内容简介:操作系统:centos 7推流软件:obs 或 ffmpeg拉流软件:ffplay 或 vlc

SRS 是一个开源的,国产的直播服务。可以去官网下载:

官网

环境

操作系统:centos 7

推流软件:obs 或 ffmpeg

拉流软件:ffplay 或 vlc

安装

如果是 centos 6 可以直接下载这个进行安装

# wget -c http://ossrs.net/srs.release/releases/files/SRS-CentOS6-x86_64-2.0.239.zip

# unzip SRS-CentOS6-x86_64-2.0.239.zip
# cd SRS-CentOS6-x86_64-2.0.239
# chmod +x INSTALL
# ./INSTALL

安装在/usr/local/srs目录中,可以直接使用

/etc/init.d/srs start

启动

centos 7 需要编译

[root@adsl-172-10-100-120 opt]# wget -c https://github.com/ossrs/srs/archive/v2.0-r1.tar.gz
[root@adsl-172-10-100-120 opt]# tar zxvf v2.0-r1.tar.gz
[root@adsl-172-10-100-120 opt]# cd srs-2.0-r1/

然后进入到 trunk 目录

[root@adsl-172-10-100-120 srs-2.0-r1]# cd trunk/
[root@adsl-172-10-100-120 trunk]# ls
3rdparty  auto  conf  configure  doc  etc  ide  modules  research  scripts  src

使用 help 可以查看编译帮助文档

[root@adsl-172-10-100-120 trunk]# ./configure --help

比如我这里编译全部的模块安装到 /usr/local/srs 目录

[root@adsl-172-10-100-120 trunk]# ./configure --full --prefix=/usr/local/srs

然后

make && make install

进入 /usr/local/srs

[root@adsl-172-10-100-120 srs]# pwd
/usr/local/srs
[root@adsl-172-10-100-120 srs]# ./objs/
nginx/ srs
[root@adsl-172-10-100-120 srs]# ./objs/srs -c ./conf/srs.conf
[2017-05-02 17:22:56.900][trace][1949][0] XCORE-SRS/2.0.239(ZhouGuowen)
[2017-05-02 17:22:56.900][trace][1949][0] config parse complete
[2017-05-02 17:22:56.900][trace][1949][0] write log to file ./objs/srs.log
[2017-05-02 17:22:56.900][trace][1949][0] you can: tailf ./objs/srs.log
[2017-05-02 17:22:56.900][trace][1949][0] @see: https://github.com/ossrs/srs/wiki/v1_CN_SrsLog

##推流

➜  Downloads ffmpeg -i gopro.mp4 -vcodec libx264 -acodec aac -f flv rtmp://172.10.100.120/live/lol

拉流

然后 ffplay 播放

➜  ~ ffplay rtmp://172.10.100.120/live/lol
ffplay version 3.3 Copyright (c) 2003-2017 the FFmpeg developers
  built with Apple LLVM version 8.1.0 (clang-802.0.42)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/3.3 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libxvid --enable-opencl --disable-lzma --enable-vda
  libavutil      55. 58.100 / 55. 58.100
  libavcodec     57. 89.100 / 57. 89.100
  libavformat    57. 71.100 / 57. 71.100
  libavdevice    57.  6.100 / 57.  6.100
  libavfilter     6. 82.100 /  6. 82.100
  libavresample   3.  5.  0 /  3.  5.  0
  libswscale      4.  6.100 /  4.  6.100
  libswresample   2.  7.100 /  2.  7.100
  libpostproc    54.  5.100 / 54.  5.100
Input #0, flv, from 'rtmp://172.10.100.120/live/lol':    0B f=0/0
  Metadata:
    major_brand     : isom
    minor_version   : 512
    compatible_brands: isomiso2avc1mp41
    encoder         : Lavf57.71.100
    server          : SRS/2.0.239(ZhouGuowen)
    srs_primary     : SRS/1.0release
    srs_authors     : winlin,wenjie.zhao
    server_version  : 2.0.239
  Duration: N/A, start: 0.023000, bitrate: N/A
    Stream #0:0: Audio: aac (LC), 44100 Hz, stereo, fltp, 128 kb/s
    Stream #0:1: Video: h264 (High), yuv420p(progressive), 1280x720 [SAR 1:1 DAR 16:9], 29.97 fps, 29.97 tbr, 1k tbn, 59.94 tbc
   3.96 A-V:  0.082 fd=  22 aq=    0KB vq=    0KB sq=    0B f=0/0

srs 配置

[root@adsl-172-10-100-120 srs]# ls
conf  etc  objs
[root@adsl-172-10-100-120 srs]# cd conf/
[root@adsl-172-10-100-120 conf]# ls
bandwidth.conf    edge.conf                 hls.conf                  http.hooks.callback.conf  push.flv.conf               transcode2hls.audio.only.conf
console.conf      edge.token.traverse.conf  http.aac.live.conf        http.mp3.live.conf        push.mpegts.over.udp.conf   transform.edge.conf
demo.19350.conf   ffmpeg.transcode.conf     http.flv.live.conf        http.server.conf          push.rtsp.conf
demo.conf         forward.master.conf       http.flv.live.edge1.conf  http.ts.live.conf         realtime.conf
dvr.path.conf     forward.slave.conf        http.flv.live.edge2.conf  ingest.conf               rtmp.conf
dvr.segment.conf  full.conf                 http.heartbeat.conf       mac.dev.conf              security.deny.publish.conf
dvr.session.conf  hds.conf                  http.hls.conf             origin.conf               srs.conf

默认的配置文件是 srs.conf

[root@adsl-172-10-100-120 conf]# cat srs.conf
# main config for srs.
# @see full.conf for detail config.

listen              1935;
max_connections     1000;
srs_log_tank        file;
srs_log_file        ./objs/srs.log;
http_api {
    enabled         on;
    listen          1985; #默认端口1985
}
http_server {
    enabled         on;
    listen          8080;
    dir             ./objs/nginx/html;
}
stats {
    network         0;
    disk            sda sdb xvda xvdb;
}
vhost __defaultVhost__ { #虚拟主机
}

如果你希望将推流的内容转换成 hls,可以参考

[root@adsl-172-10-100-120 conf]# cat 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        ./objs/nginx/html;
        hls_m3u8_file   [app]/[stream].m3u8;
        hls_ts_file     [app]/[stream]-[seq].ts;
    }
}

更多使用方法,参考[官方维基]( https://github.com/ossrs/srs/wiki/v3_CN_Home)


以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持 码农网

查看所有标签

猜你喜欢:

本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们

参数化建筑设计

参数化建筑设计

高云河、白云生 / 华中科技大学出版社 / 2016-8-1 / 69.80

《参数化建筑设计》以案例的形式讲解参数化建筑设计的具体方法,其中包含犀牛(Rhino)和Grasshopper的应用。本书不单单是一本计算机软件教材,书中教会读者的是参数化建筑设计的思路,希望通过完成一个个案例使读者融会贯通,在今后的设计工作中能够熟练使用,辅助自身完成建筑设计。全书共有10个案例,循序渐进,由浅入深,几乎涵盖了参数化建筑设计所要使用的所有功能和方法。一起来看看 《参数化建筑设计》 这本书的介绍吧!

CSS 压缩/解压工具
CSS 压缩/解压工具

在线压缩/解压 CSS 代码

HEX CMYK 转换工具
HEX CMYK 转换工具

HEX CMYK 互转工具

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具