各位用户为了找寻关于Nginx搭建rtmp直播服务器实现代码的资料费劲了很多周折。这里教程网为您整理了关于Nginx搭建rtmp直播服务器实现代码的相关资料,仅供查阅,以下为您介绍关于Nginx搭建rtmp直播服务器实现代码的详细内容

1.到nginx源码目录新建个rtmp目录 ,进入 git clone https://github.com/arut/nginx-rtmp-module.git

2.重编译nginx 代码如下

./configure --prefix=/usr/local/nginx-1.2.9/ --add-module=./rtmp/nginx-rtmp-module --with-http_ssl_module --with-pcre=/lamp_source/pcre-8.38; make;make install; #重新安装nginx

3.完成安装后。

打开nginx.conf 在http{server...} 之后加上以下代码

? 1 2 3 4 5 6 7 8 9 10 11 12 rtmp{     server{         listen 1935;         chunk_size 4000;         application hls {             live on;             hls on;             hls_path /你的服务器路径这个用于存放缓存文件的。必须可写;             hls_fragment 5s;         }     } }

然后新建个主机配置

? 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 server {       listen 8851;     location /index.html {     root /网站存放目录; }     location / {# return 403;       # Serve HLS fragments       types {         application/vnd.apple.mpegurl m3u8;         video/mp2t ts;       }       root /同上,缓存用;       expires -1;     }   }

完成以上配置后。 下载一个软件叫做 open broadcaster software 的软件推流即可(注意,也可以使用ffmpeg 进行推流)。 软件使用如截图

然后点开始串流就可以了。

下载打开vlc播放器(拉流)。输入 rtmp://你的网址:1935/hls/上图中的密码 然后就ok了。 成功在线直播

以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持服务器之家。

原文链接:https://www.cnblogs.com/ghjbk/p/7792019.html