Win10環境下采用nginx-rtmp+obs搭建流媒體伺服器
阿新 • • 發佈:2018-12-12
-
1.1、安裝並啟動nginx-rtmp模組
1、直接將下載好的nginx-rtmp檔案解壓
2、啟動nginx伺服器(例如:我將nginx-rtmp安裝在C盤)
注:start nginx也可以寫為nginx.exe
3、更改nginx-rtmp的conf檔案下的nginx.conf配置
4、輸入伺服器地址:http://localhost:8088,8088是自己配置的埠號,可以隨意更改,這樣nginx-rtmp伺服器就搭建好了
第二步:下載obs視訊軟體1、obs下載官網:https://obsproject.com/download
2、配置obs,配置好之後就可以點選開始串流,連線伺服器
注:要在來源中配置視訊捕捉裝置,直接新增就行,不然obs開啟就沒有視訊錄影的;然後點選設定,配置串流url
下面是我配置好的config檔案,實現在nginx中暫停和播放流媒體,擷取錄影的功能
worker_processes 1; error_log logs/error.log debug; events { worker_connections 1024; } rtmp { server { listen 1935; application live { live on; recorder rec1 { record all manual; record_suffix all.flv; record_path C:/nginx-rtmp/record; record_unique on; } } application hls { live on; hls on; hls_path temp/hls; hls_fragment 8s; } } } http { server { listen 8088; server_name localhost; location /control { rtmp_control all; } location / { root html; } location /stat { rtmp_stat all; rtmp_stat_stylesheet stat.xsl; } location /stat.xsl { root html; } location /hls { #server hls fragments types{ application/vnd.apple.mpegurl m3u8; video/mp2t ts; } alias temp/hls; expires -1; } } }
注:我將擷取的流媒體視訊存放在record_path C:/nginx-rtmp/record;
3、在nginx中實現流媒體的暫停和播放功能
播放功能:"http://localhost:8088/control/record/start?app=live&name=abc&rec=rec1"
name就是剛剛在obs中配置的流媒體的金鑰
暫停功能:"http://localhost:8088/control/record/stop?app=live&name=abc&rec=rec1"
4、這樣就可以實現在nginx-rtmp中實現線上控制錄影的視訊
注:呼叫程式碼,就可以實現流媒體視訊的暫停,錄影直接就儲存在record檔案中