1、安装homebrew
ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
卸载的话,输入
ruby-e"$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/uninstall)"
2、安装nginx
首先,得将文件下载到本地
brew tap homebrew/nginx
如果报错Error: homebrew/nginx was deprecated. This tap is now empty as all its formulae were migrated.,执行如下
brew tap denji/nginx
第二步,执行安装
brew install nginx-full--with-rtmp-module
如果出现: early EOF, index-pack failed,
说明源存在问题,执行以下4步
cd "$(brew --repo)"
git remote set-url origin https://mirrors.ustc.edu.cn/brew.git
cd "$(brew --repo)/Library/Taps/homebrew/homebrew-core"
git remote set-url origin https://mirrors.ustc.edu.cn/homebrew-core.git
brew update
会出现Already up-to-date.,此时再次执行brew install nginx-full--with-rtmp-module
如果报错Error: No available formula with the name "nginx-full--with-rtmp-module", 执行 brew install denji/nginx/nginx-full --with-rtmp-module
最后安装成功
3、到这一步, nginx和rtmp就安装好了,启动服务
nginx
在浏览器输入http://localhost:8080,如果出现下图代表安装成功
4、配置rtmp
打开Finder,command+shift+G前往文件夹/usr/local/etc/nginx/nginx.conf,用记事本打开
在http节点后面加上rtmp配置:
rtmp {
server {
listen 2020;
application myrtmp {
live on;
record off;
}
}
}
说明:
rtmp:协议名称
server:内部中是服务器相关配置
listen: 监听的端口号2020
application: 访问的应用路径是myrtmp
live on: 开启实时
record off: 不记录数据
添加后保存文件,之后得重启niginx
nginx-s reload
如果报这个错误:
nginx: [error] open() "/usr/local/var/run/nginx.pid" failed (2: No such file or directory)
可以执行
nginx
到这一步,rtmp服务就启动成功了
5、安装ffmpeg
brew install ffmpeg
安装过程较慢,可以下载一个VLC播放器测试拉流备用
6、通过ffmpeg推流到本地服务器
ffmpeg-re-i “视频文件的绝对路径” -vcodec libx264-acodec aac-f flv rtmp://localhost:2020/m yrtmp/room1
如果出现RTMP_Connect0, failed to connect socket. 61 (Connection refused)
rtmp://localhost:2016/rtmplive/room: Unknown error occurred
表示你的nginx服务未启动,执行nginx-s reload或者nginx进行启动
在推流的同时可以打开VLC进行验证,验证方法File->Open Network->输入 rtmp://localhost:2020/m yrtmp/room1
就会同步打开视频进行播放。注意:一定要在推流过程中play,不然会没反应
服务器搭建成功啦!!