前言:这里搭建额Nginx服务器,主要是起来作为视频直播推流拉流的中转站(流媒体处理服务器).
按照下面的步骤开始:
Homebrew简称brew,是macOS上的软件管理包工具,可以在mac中卸载和安装软件,打开终端,执行下面
命令行,安装brew.
/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
增加对Nginx的拓展,也就是从github上下载,homebrew对Nginx的拓展
brew tap homebrew/nginx
brew install nginx-full --with-rtmp-module
查看nginx-full信息
brew info nginx-full
执行上面的命令后,我们可以看到如下信息
Docroot is: /usr/local/var/www The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that nginx can run without sudo nginx will load all files in /usr/local/etc/nginx/servers/. - Tips - $ sudo chown root:wheel /usr/local/Cellar/nginx-full/1.10.1/bin/nginx $ sudo chmod u+s /usr/local/Cellar/nginx-full/1.10.1/bin/nginx Reload config: $ nginx -s reload #重新加载配置文件 Reopen Logfile: $ nginx -s reopen #再次打开日志文件 Stop process: $ nginx -s stop #停止服务器 Waiting on exit process $ nginx -s quit #退出服务器从上面可以看出,
Naginx安装所在位置/usr/local/Cellar/nginx-full/
Nginx配置文件所在位置/usr/local/etc/nginx/nginx.conf
Nginx服务器根目录所在位置/usr/local/var/www
执行命令,测试下是否成功启动Nginx服务器
(这注意:naginx关机重启之后是关闭的,执行下面命令开启,如果不能,直接执行命令nginx开启服务器)
/usr/local/Cellar/nginx-full/1.10.0/bin/nginx
在浏览器中输入:# ,如果出现下图所示,则开启成功##5.修改Nginx.conf配置文件,配置rtmp
用xcode打开Nginx.conf,找到/usr/local/etc/nginx/nginx.conf文件,用xocde打开,打开之后,在文件的最后
补上一下代码段:
http { …… } #在http节点下面(也就是文件的尾部)加上rtmp配置: rtmp { server { listen 1935; application live { live on; record off; } } }说明:
rtmp是协议名称
server 说明内部中是服务器相关配置
listen 监听的端口号, rtmp协议的默认端口号是1935
application 访问的应用路径是 live
live on; 开启实时
record off; 不记录数据
nginx -s reload
##7.安装ffmpeg工具brew install ffmpeg
安装ffmpeg需要一段时间,这里提供一个支持rtmp协议的视频播放器.Mac下可以用FLV
ffmpeg -re -i 你的视频文件的绝对路径(如/Users/lideshan/Downloads/liveVideo.mp4) -vcodec copy -f flv rtmp://localhost:1935/live/room
- 说明: - localhost 指的是我们本地电脑(IP地址) - live是app访问路径 - room是推流上去的路径(可以随意写,拉流的时候根据这个不同的路径标识拉取不同的流(主播))电脑上打开vlc这个播放器软件 点击File—->Open Network 在弹出来的框中选择Network然后输入URL:
rtmp://localhost:1935/live/room