一、序言
核心:服务端(nginx-rtmp-module) + 推流端(OBS) + 接收端(jwplayer)
二、服务端
1. 下载nginx-rtmp-module模块
地址:https://github.com/arut/nginx-rtmp-module
2. 编译安装nginx
cd ./nginx-1.10.0/
./configure --add-module=/path/to/nginx-rtmp-module --with-http_ssl_module make make install
注:根据实际情况修改两处代码路径
3. 配置nginx
3.1 加入节点
rtmp { server { listen 1935; application mytv { live on; } } }
注:mytv是应用名称
3.2 RTMP监听状态(可选)
http { server { listen 8080; # This URL provides RTMP statistics in XML location /stat { rtmp_stat all; # Use this stylesheet to view XML as web page # in browser rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { # XML stylesheet to view RTMP stats. # Copy stat.xsl wherever you want # and put the full directory path here root /data/wwwroot/rtmp/; } } }
把nginx-rtmp-module文件夹中的stat.xsl复制到/data/wwwroot/rtmp/文件夹中
监控地址:http://localhost:8080/stat
三、推流端
1. 下载OBS
地址:https://obsproject.com/download
2. 配置OBS
推流地址:rtmp://192.168.240.128/mytv/ #记得修改IP,下同
其他配置参考:http://www.douyu.com/cms/zhibo/201311/13/250.shtml
3. 开始推流
此时可以监听到【publishing】状态的进程
注:记得开放1935端口
四、接收端
1. 下载jwplayer
地址:https://dashboard.jwplayer.com/#/players/downloads #需要注册登录
2. html示例
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>Title</title> </head> <body> <div id="my_video"></div> </body> </html> <script src="./jwplayer/jwplayer.js"></script> <script> jwplayer.key = "yourkey"; jwplayer(\'my_video\').setup({ file: \'rtmp://192.168.240.128/mytv/\', }); </script>
注:记得修改key
五、验证推流
1. rtmp配置参考
地址:https://github.com/arut/nginx-rtmp-module/wiki/Directives#on_publish
rtmp { server { listen 1935; on_publish http://localhost/rtmp/auth.php; application mytv { live on; } } }
注:记得重启nginx
2. auth.php
<?php if ($_POST[\'key\'] == \'root\') { header(\'HTTP/1.1 200 OK\'); header(\'Status: 200 OK\'); } else { header(\'HTTP/1.1 403 Forbidden\'); header(\'Status: 403 Forbidden\'); }
返回2xx RTMP通过,返回3xx RTMP重定向,其他均为失败。
请根据你的业务逻辑修改验证流程。
3.OBS配置
流秘钥:?key=root #不是推流地址