Nginx+OBS+rtmp+VLC實現視頻直播


Windows安裝Nginx

官網下載Windows
解壓后如下
image

命令

啟動nginx

(1)直接雙擊nginx.exe,雙擊后一個黑色的彈窗一閃而過,nginx以后台程序運行(不推薦)。
(2)打開cmd命令窗口,切換到nginx解壓目錄下,輸入命令 nginx.exe或者start nginx,回車后nginx以后台程序運行。

檢查nginx是否啟動成功

直接在瀏覽器地址欄輸入網址 http://localhost:80
在cmd命令窗口輸入命令

#查看是否存在nginx進程
tasklist /fi "imagename eq nginx.exe"
#查看端口是否被使用
netstat -ano | findstr 0.0.0.0:80

關閉nginx

如果使用cmd命令窗口啟動nginx,關閉cmd窗口是不能結束nginx進程的

#殺死進程
taskkill /f /t /im nginx.exe
#快速停止nginx
nginx -s stop
#完整有序的停止nginx
nginx -s quit

如果雙擊exe啟動后,使用命令停止會報如下錯[error] OpenEvent("Global\ngx_stop_14084") failed (2: The system cannot find the file specified)

nginx.conf修改

修改了nginx的配置文件nginx.conf 時,不需要關閉nginx后重新啟動nginx,只需要執行以下命令即可讓改動生效

nginx -s reload

nginx 1.7.11.3 Gryphon

安裝了nginx后但是需要手動集成rtmp模塊,所以需要下載集成了rtmp模塊nginx 1.7.11.3 Gryphon
下載好后把nginx下面的nginx.conf復制過去。在conf/nginx.conf最后面添加rtmp配置

nginx.conf配置rtmp

# rtmp config
rtmp{
    server  {
        listen 1935;
        chunk_size 4096;
        application live  {
            live on;
            record off;
        }
        application live2  {
            live on;
            record off;
        }
        application vod  {
            play ./var/flvs;
        }
        application vod_http  {
            play http://10.10.10.15/vod;
        }
        application hls  {
            live on;
            hls on;
            hls_path ./tmp/hls;
        }
    }
}

OBS推流

OBS下載
添加場景,並在場景下添加來源為顯示器采集。
image
在obs設置 -》 推流中設置推送到nginx,串流秘鑰也要設置,播放時需要這個。

rtmp://服務器IP:1935/live

image
點擊開始推送,這時obs會把采集的直播流推送到nginx。
image

VLC播放

VLC官網下載
rtmp://10.10.10.15:1935/live/OBS串流秘鑰
image

通過公網或域名訪問

端口映射到外網(前提你有,不是nat)
image
即可通過公網IP去訪問直播。
image
綁定DDNS動態域名解析(我用的花生殼)后即可使用域名。
image


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM