Fork me on GitHub

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

posted @ 2021-08-01 11:17  秋夜雨巷  阅读(1196)  评论(0编辑  收藏  举报