1、安装命令
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
先clone nginx项目到本地
brew tap homebrew/nginx
执行安装:
brew install nginx-full --with-rtmp-module
此时, nginx和rtmp模块就安装好了
输入命令:
nginx
在浏览器里打开http://localhost:8080
2、安装过程中可能出现错误
我在安装过程中需要对brew进行升级
brew update -v
3、安装完之后的常用指令
查询安装路径:
brew info nginx-full
nginx安装所在位置 /usr/local/Cellar/nginx-full/1.10.1/bin/nginx
nginx配置文件所在位置 /usr/local/etc/nginx/nginx.conf
nginx服务器根目录所在位置 /usr/local/var/www
4、配置RTMP服务
/usr/local/etc/nginx/nginx.conf 中RTMP和Http节点一致
# 在http节点后面加上rtmp配置: rtmp {
server {
listen 1935; application myapp {
live on; #record keyframes;
#record_path /tmp;
#record_max_size 128K;
#record_interval 30s;
#record_suffix .this.is.flv; #on_publish http://localhost:8080/publish;
#on_play http://localhost:8080/play;
#on_record_done http://localhost:8080/record_done; }
application hls {
live on;
hls on;
hls_path /tmp/app;
hls_fragment 5s; }
}
}
5、查询rtmp服务是否正常
修改完配置文件之后执行 nginx -s reload
执行 sudo lsof -i -P | grep -i "listen" 查询1935端口是否开启
6、直播测试
安装ffmpeg
brew install ffmpeg
安装vlc播放器
准备mp4文件推流测试,用vlc播放
推流:
ffmpeg -re -i /Users/lunli/rtmp/keep.mp4 -vcodec libx264 -acodec aac -f flv rtmp://127.0.0.1:1935/myapp/room
播放:
rtmp://localhost:1935/myapp/room
7、如果遇到错误
卸载nginx,重新安装
8、结果
9、视频文件参考了https://github.com/sunjinshuai/Keep/blob/master/KeepGuidePage/keep.mp4