NGinx+RTMP 实现流媒体服务器

本文在Centos7系统基于Nginx搭建RTMP/HLS 直播,系统及软件:


安装Nginx

  • ……省略解压等过程
  • cd nginx-1.12.0
  • ./configure prefix=/usr/local/nginx \
    –with-pcre=../pcre-8.40 \
    –with-zlib=../zlib-1.2.11 \
    –with-openssl=../openssl-1.0.2l \
    –add-module=../ngx_cache_purge-master \
    –with-http_ssl_module \
    –with-http_stub_status_module \
    –with-http_gzip_static_module \
    –add-module=../nginx-rtmp-module-master \
    –add-module=../nginx_mod_h264_streaming-2.2.7
  • make
    • 如果报 Werror 错误,去掉 objs/Makefile 选项
  • make install

配置RTMP

在rtmp{……}中配置
rtmp {
server {
listen 1935;
chunk_size 4000;
application mylive {
live on;
# record first 1K of stream
record all;
record_path /tmp/av;
record_max_size 1K;
record_suffix .mp4;
}
}
}

不需要录制的话去掉record或者 record off 即可;

使用OBS推流 
推流地址:rtmp://192.168.1.152:1935/myplive/12345678
这里写图片描述
使用VLC拉流 
拉流地址:rtmp://192.168.1.152:1935/myplive/12345678
这里写图片描述

结果:
这里写图片描述

配置HLS

在rtmp{……}中配置

    application hls {
        live on;
        hls on;
        hls_path /tmp/hls;
        hls_fragment 4s;
        hls_playlist_length 12s;
        hls_fragment_naming system;
        sync 10ms;
     }

在http{……}中配置
server {
listen 8008;
server_name localhost;

    #charset koi8-r;
    access_log  logs/stream.access.log;

    location /hls {
        # Serve HLS fragments
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
                            root /tmp;
                            add_header Cache-Control no-cache;
    }
}

然后重启Nginx

使用OBS推流 
推流地址:rtmp://192.168.1.152:1935/hls/12345678
这里写图片描述

使用VLC拉流 
推流地址:http://192.168.1.152:8008/hls/12345678.m3u8
这里写图片描述
注意hls延迟比RTMP大

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值