编译安装
- 下载 nginx
- 下载 rtmp 和
nginx 同一目录 - 配置
--prefix 指定输出路径
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module
出现如下错误
checking for PCRE library ... found
checking for PCRE JIT support ... found
checking for OpenSSL library ... not found
checking for OpenSSL library in /usr/local/ ... not found
checking for OpenSSL library in /usr/pkg/ ... not found
checking for OpenSSL library in /opt/local/ ... not found
./configure: error: SSL modules require the OpenSSL library.
You can either do not enable the modules, or install the OpenSSL library
into the system, or build the OpenSSL library statically from the source
with nginx by using --with-openssl=<path> option.
分析:需要 openssl 库支持
- 下载 openssl 通过链接下载配置未成功,所以使用
brew 安装
brew install openssl@1.1
- 再次配置
需要安装 brew install pcre
./configure --prefix=/usr/local/nginx --add-module=../nginx-rtmp-module --with-openssl=/usr/local/Cellar/openssl@1.1 --with-pcre=/usr/local/Cellar/pcre/8.44
配置成功
Configuration summary
+ using system PCRE library
+ using OpenSSL library: ../openssl
+ using system zlib library
nginx path prefix: "/usr/local/nginx"
nginx binary file: "/usr/local/nginx/sbin/nginx"
nginx modules path: "/usr/local/nginx/modules"
nginx configuration prefix: "/usr/local/nginx/conf"
nginx configuration file: "/usr/local/nginx/conf/nginx.conf"
nginx pid file: "/usr/local/nginx/logs/nginx.pid"
nginx error log file: "/usr/local/nginx/logs/error.log"
nginx http access log file: "/usr/local/nginx/logs/access.log"
nginx http client request body temporary files: "client_body_temp"
nginx http proxy temporary files: "proxy_temp"
nginx http fastcgi temporary files: "fastcgi_temp"
nginx http uwsgi temporary files: "uwsgi_temp"
nginx http scgi temporary files: "scgi_temp"
- 编译
make -j 16
- 安装
make install
- 查看是否安装成功
/usr/local/ 是否包含 nginx
- 使用,
cd /usr/local/nginx/
启动服务
sudo ./sbin/nginx -c ./conf/nginx.conf
关闭服务
sudo ./sbin/nginx -s stop
- 配置
rtmp 到 nginx
vim /usr/local/nginx/conf/nginx.conf
增加如下文件到最后
rtmp {
server {
listen 1935; # 监听端口号
chunk_size 4000;
# 应用名称 live 推流时需要使用
application live {
live on; # 开启实时
allow play all;
}
}
}
方式二:Mac上搭建直播服务器 Nginx+rtmp(暂未成功)
下载
brew tap denji/nginx
安装
brew install nginx
brew install rtmp-module
or
brew install nginx --with-rtmp-module
brew reinstall rtmp-nginx-module
brew info nginx
启动ngxin
服务器根目录:/usr/local/var/www
配置文件:/usr/local/etc/nginx/nginx.conf
全部文件 /usr/local/etc/nginx/servers/.
后台启动 brew services start nginx
nginx
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 ## 退出服务器
验证
需要使用 ffmpeg , 参考 [02-ffmpeg 安装](./02-ffmpeg 安装/index.md)
ffmpeg -i ~/Desktop/D/download/071.flv -f flv rtmp://localhost/live/test
ffplay rtmp://localhost/live/test
推流可能失败
-f flv
推流失败
(主要原因:音频,视频分块了)
解决方案
-re (音视频保持原有速度播放)
清晰度不高
-f flv编码原因
解决方案
-c:v copy
参考
Mac上搭建直播服务器 Nginx+rtmp
MAC搭建基于RTMP的本地Nginx服务器
[MAC 上编译安装nginx-rtmp-module 流媒体服务器](
|