macOS High Sierra搭建rtmp服务器

Environment

1
macOS High Sierra 10.13.6 Xcode 9.4.1

安装nginx

1
2
brew tap homebrew/nginx
brew install nginx-full --with-rtmp-module

修改nginx配置文件

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
## /usr/local/etc/nginx/nginx.conf
rtmp {
server {
#监听的端口号,rtmp协议的默认端口号是1935
listen 1935;
#直播流配置,访问路径是rtmplive
application rtmplive {
#开启实时
live on;
#为rtmp引擎设置最大连接数.默认为off
max_connections 1024;
#不记录数据
record off;
}
}
}

启动nginx及重新加载配置文件

1
2
nginx
nginx -s reload

测试nginx

1
http://localhost:8080

FFMpeg推流

1
ffmpeg -re -i ./sintel.h264 -vcodec libx264 -vprofile baseline -acodec aac -ar 44100 -strict -2 -ac 1 -f flv -s 640x360 -q 10 rtmp://localhost:1935/hls/test

ffplay查看

1
ffplay rtmp://localhost:1935/hls/test

后记

macOS中有一个坑,需要关闭防火墙,否则可能出现推流不成功