一、序言
核心:服務端(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 #不是推流地址
