本篇文章主要是记述了基于Nginx搭建RTMP直播推流服务器。关于安装Nginx的内容可以查看这篇博客 《CentOS7编译安装nginx》 ,下载Nginx源码可以点击这个链接,http://img.zouchanglin.cn/nginx-1.9.9.tar.gz ,下面是Nginx推流模块的代码,可以在Github下载,但是也可以点击这个链接 http://img.zouchanglin.cn/nginx-rtmp-module.zip。这样在做直播相关的测试的时候就可以用上了。
在编译Nginx的时候需要把nginx-rtmp-module这个模块也带上:
bash./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=/root/nginx-rtmp-module
下面是nginx.config的配置:
nginxuser root; worker_processes 2; events { worker_connections 1024; } http { include mime.types; default_type application/octet-stream; sendfile on; keepalive_timeout 65; server { server_name localhost; listen 8080; location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } # 路径根据实际位置配置 location /stat.xsl { root /usr/local/nginx/nginx-rtmp-module/; } location /control { rtmp_control all; } # 路径根据实际位置配置 location /rtmp-publisher { root /usr/local/nginx/nginx-rtmp-module/test; } # 路径根据实际位置配置 location / { root /usr/local/nginx/nginx-rtmp-module/test/www; } } } rtmp { server { listen 1935; chunk_size 4000; application live { live on; hls on; hls_path /tmp/hls; # rtmp推流文件存放路径 hls_fragment 5s; # 每个TS文件包含5秒的视频内容 } } }
接下来启动Nginx即可,但是在启动之前先建立文件存放的文件夹:
shellmkdir /tmp/hls /usr/local/nginx/sbin/nginx
只要没报错,而且可以访问到Nginx的默认页面并且无报错就说明没问题了:
使用BOS开始推流,推流服务器选择自定义URL:rtmp://192.168.199.102/live
,如果OBStudio不显示图像源的话可以在系统中做如下设置:
已经可以成功推流,那么如何接收这种直播流呢?可以使用VLC,打开网络串流:rtmp://192.168.199.102/live
,这样通过Nginx作为RTMP直播推流服务器已经实现了。
本文作者:Tim
本文链接:
版权声明:本博客所有文章除特别声明外,均采用 BY-NC-SA 许可协议。转载请注明出处!