如何快速搭建本地RTMP推流服务器
目录
下载必要文件
搭建服务器
验证是否能够推流成功
OBS推流
首先我们需要一个“靶子“来接收推流,那么最简单的方式就是在自己电脑上搭建Nginx + RTMP模块。
下载必要文件
- nginx下载地址:http://nginx-win.ecsds.eu/download/
注意下载:nginx 1.7.11.3 Gryphon.zip
这个版本 - 下载niginx扩展包:https://github.com/arut/nginx-rtmp-module
搭建服务器
首先创建一个文件夹例如:nginx_rtmp,名字可以自己起
将下载到的nginx解压到创建好的文件夹nginx_rtmp中
其次解压nginx扩展包,注意选择解压到当前目录
然后将解压好的扩展包直接复制一份到nginx_rtmp文件夹中
然后再nginx_rtmp/conf/文件夹中创建rtmp.conf配置文件文件,将以下信息粘贴到配置文件中
worker_processes auto;
events {
worker_connections 1024;
}
#RTMP服务
rtmp {
server {
listen 16666; //端口可自己设定
chunk_size 4096;
application act1{ //定义一个名为 "act1" 的应用,名字可自己设定,推拉流地址中需要用到
live on;
}
}
}
#http://localhost/stat , http://localhost:80/stat 查看服务器状态
http {
include mime.types;
default_type application/octet-stream;
sendfile on;
keepalive_timeout 65;
server {
listen 80;
server_name localhost;
location /stat {
rtmp_stat all;
rtmp_stat_stylesheet stat.xsl;
}
location /stat.xsl {
root ./nginx-rtmp-module-master/;
}
location / {
root html;
index index.html index.htm;
}
error_page 500 502 503 504 /50x.html;
location = /50x.html {
root html;
}
}
}
完成之后打开终端进入新创建的文件夹中启动 niginx :. ginx.exe -c conf tmp.conf
注意:启动时关闭杀毒软件和防火墙
如果出现黑窗口一闪然后消失说明启动成功,也有可能执行启动命令后终端卡住,也说明启动成功
此时rtmp推流服务器已经搭建好了
验证是否能够推流成功
我是用的是OBS进行推流,用vlc拉流
OBS推流
点击源中的加号选择显示器采集

然后点击确认之后

采集方式选择自动,显示器选择主显示器,然后确认
然后点击设置--直播
服务器填写:rtmp://电脑ip:端口/应用名
这里的端口和应用名为rtmp.conf配置文件中rtmp模块设定的
示例中端口为:16666,应用名为:act1
整个填写的 其实就是推流地址
推流码自己设置,相当于是obs设置的一个标识,在推流地址后添加 /推流吗 组成拉流地址

然后点击应用后确认,回到主界面点击开始直播
打开vlc,点击媒体--打开网络串流,然后输入拉流地址(rtmp://电脑ip:16666/act1/test)点击播放
如果vlc可以正常播放说明搭建成功
如果出现vlc加载不出画面,关闭直播或者vlc多试几次应该不会有问题。







