> 实现了在mac系统上推流、拉流基础配置步骤
## rtmp(real time messaging protocol)
**system**: mac os
### 环境安装
``` shell
# 为后续安装包含rtmp的nginx做准备,避免一些依赖安装失败
brew update
brew install nginx-full --with-rtmp-module
```
终端会输出:
```shell
Run port 80:
$ sudo chown root:wheel /usr/local/opt/nginx-full/bin/nginx
$ sudo chmod u+s /usr/local/opt/nginx-full/bin/nginx
Reload config:
$ nginx -s reload
Reopen Logfile:
$ nginx -s reopen
Stop process:
$ nginx -s stop
Waiting on exit process
$ nginx -s quit
To start denji/nginx/nginx-full now and restart at startup:
sudo brew services start denji/nginx/nginx-full
Or, if you don't want/need a background service you can just run:
/usr/local/opt/nginx-full/bin/nginx -g daemon\ off\;
```
### 配置
```
# 查看nginx具体路径
brew info nginx
>>> $ The default port has been set in /usr/local/etc/nginx/nginx.conf to 8080 so that
```
在nginx.conf文件里增加基本配置如下,详细配置还可以[参靠](https://github.com/arut/nginx-rtmp-module/wiki/Directives):
```
rtmp{
server{
listen 1935;
application appName{
live on;
record all;
record_path path/to/save/file;
# 禁止播放拉流,减少资源占用,不设置则可以实时推,实时拉
play off;
}
}
}
# 在http模块里添加 location相关配置
http{
server{
location /record {
alias path/to/save/file;
}
}
}
```
使用命令`nginx -s reload`重启服务
### 推流
```
ffmpeg -re -i path/to/video -c copy -f flv rtmp://ip:port/appName/streamId
```
此时会在指定的`record_path`下保存好推上去的文件,命名为`streamId.flv`
### 拉流
使用播放器访问网络源`http://ip:8080/record/streamId.flv`,即可播放视频
### 疑问
我试了一下直接在record_path下存放视频,而不是通过推流,也可使用拉流地址访问,网上解释是推流更灵活,可以实时边推边拉,提前准备好的视频安全性不高,也不利于监控统计。。。。
Using nginx + nginx-rtmp-module + ffmpeg to build a streaming media server