一.安装nginx
前文中mac电脑已经安装了homebrew然后使用homebrew安装nginx打开终端输入如下命令
1.brew tap denji/homebrew-nginx
2.brew install nginx-full --with-rtmp-module
查看是否安装成功先启动nginx
然后打开浏览器 输入http://localhost:8080 如果浏览器中有如下内容说明安装成功
Welcome to nginx!
If you see this page, the nginx web server is successfully installed and working. Further configuration is required.
For online documentation and support please refer to nginx.org.
Commercial support is available at nginx.com.
Thank you for using nginx.
二.配置rtmp
配置ngingx 和rtmp
1.brew info nginx-full
查看nginx安装的位置找到nginx.conf文件
点击Finder->前往->前往文件夹->输入/usr/local/etc/nginx/nginx.conf
打开后再http节点后加入
如下配置
rtmp {
server {
listen 1935;
chunk_size 4000;
application rtmplive {
live on;
allow play all;
record off;
}
}
}
1.nginx -v 查看版本号 然后替换1.15.4
2./usr/local/Cellar/nginx-full/1.15.4/bin/nginx -s reload
然后再次启动nginx结果出现如下错误
xxmr@MacBook-Pro ~ % nginx
nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:1935 failed (48: Address already in use)
nginx: [emerg] bind() to 0.0.0.0:8080 failed (48: Address already in use)
nginx: [emerg] still could not bind()
不要慌 这个错误需要先关闭当前的nginx
命令为 nginx -s stop
三.查看本地服务器localhostIP
xxmr@MacBook-Pro ~ % nslookup localhost
这个ip可用来写本地电脑推流,如果使用手机推流则需要使用wifi分配电脑的ip地址
推流命令行
ffmpeg -re -i ~~~~~.mp4 -vcodec libx264 -acodec aac -strict -2 -f flv rtmp://localhost:1935/rtmplive/room
-i 是指定输入位置
-vcodec 是指定视频编码格式
-acodec 是指定音频编码格式
-strict -2 是为了使用ffmpeg 的aac编码
-f flv指定为flv格式
此时若推流成功可以新建终端窗口 使用ffplay查看效果
ffplay rtmp://localhost:1935/rtmplive/room