从0到1_后端开发

srs配置、播放

2016-12-27  本文已影响1494人  TroyZhang

rtmp://xxx.xxx.xxx.xxx:8080/live/h5
http://xxx.xxx.xxx.xxx/live/h5.m3u8

rtmp,hls,flv,http-api

hls(浏览器)
http://xxx.xxx.xxx.xxx/live/h5.m3u8
http://xxx.xxx.xxx.xxx/players/jwplayer6.html?vhost=__defaultVhost__&app=live&hls_autostart=true&stream=h5&server=xxx.xxx.xxx.xxx&hls_port=80

flv(flash播放器)
http://xxx.xxx.xxx.xxx/live/h5.flv
http://xxx.xxx.xxx.xxx/players/jwplayer6.html?vhost=__defaultVhost__&app=live&hls_autostart=true&stream=h5.flv&server=xxx.xxx.xxx.xxx&hls_port=80&hls_autostart=true

rtmp
rtmp://xxx.xxx.xxx.xxx:8080/live/h5
http://xxx.xxx.xxx.xxx/players/jwplayer6.html?port=8080&rtmp_autostart=true&app=live&stream=h5

下载

$ git clone https://github.com/ossrs/srs
$ cd srs/trunk

编译

// 支持 hls,flv,rtmp转码,http-server,http-api
$ ./configure --with-ssl --with-http-api --with-hls --with-http-server  --with-nginx --with-ffmpeg --with-transcode && make

配置

// cat conf/troy.conf
# the config for srs to delivery realtime RTMP stream
# @see https://github.com/ossrs/srs/wiki/v2_CN_SampleRealtime
# @see full.conf for detail config.

listen              8080;
max_connections     1000;
stats {
    network         0;
    disk            sda sdb xvda xvdb;
}
http_api {
    enabled         on;
    listen          9090;
    crossdomain     on;
    #raw_api {
    #    enabled             off;
    #    allow_reload        off;
    #    allow_query         off;
    #    allow_update        off;
    #}
}
http_stream {
    enabled         on;
    listen          80;
    dir             ./objs/nginx/html;
}
vhost __defaultVhost__ {
    gop_cache       off;
    queue_length    10;
    min_latency     on;
    mr {
        enabled     off;
    }
    mw_latency      100;
    tcp_nodelay     on;
    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;
    }
    http_remux {
        enabled     on;
        mount       [vhost]/[app]/[stream].flv;
        hstrs       on;
    }
}

vhost hls.transcode.vhost.com {
    transcode {
        enabled     on;
        ffmpeg      ./objs/ffmpeg/bin/ffmpeg;
        engine hls {
            enabled         on;
            vfilter {
            }
            vcodec          libx264;
            vbitrate        500;
            vfps            20;
            vwidth          768;
            vheight         320;
            vthreads        2;
            vprofile        baseline;
            vpreset         superfast;
            vparams {
                g           100;
            }
            acodec          libaacplus;
            abitrate        45;
            asample_rate    44100;
            achannels       2;
            aparams {
            }
            output          rtmp://127.0.0.1:[port]/[app]?vhost=[vhost]/[stream]_[engine];
        }
    }
}

运行

// 检查配置文件是否正确
$ ./objs/srs -t -c conf/troy.conf

// 运行
$ sudo ./objs/srs -c conf/troy.conf

Mac端上传录屏幕

$ ffmpeg -f avfoundation -i "1" -vcodec libx264 -preset ultrafast -acodec libfaac -f flv rtmp://xxx:8080/live/h5

查看当前服务端stream列表

http://xxx:9090/api/v1/streams/

{
  "code": 0,
  "server": 12323,
  "streams": [
    {
      "id": 12325,
      "name": "h5",
      "vhost": 12324,
      "app": "live",
      "live_ms": 1482371950909,
      "clients": 1,
      "send_bytes": 12576,
      "recv_bytes": 29070803,
      "kbps": {
        "recv_30s": 0,
        "send_30s": 0
      },
      "publish": {
        "active": true,             // 表示是否在线
        "cid": 166
      },
      "video": {
        "codec": "H264",
        "profile": "High(422)",
        "level": "Other"
      },
      "audio": null
    }
  ]
}
上一篇下一篇

猜你喜欢

热点阅读