MAC 上編譯安裝nginx-rtmp-module 流媒體服務器
記錄踩坑過程
下載nginx和nginx-rtmp-module
wget http://nginx.org/download/nginx-1.15.3.tar.gz
git clone https://github.com/arut/nginx-rtmp-module
生成makefile
tar -zxvf nginx-1.15.3.tar.gz
cd nginx-1.15.3
./configure --prefix=/data/server/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module
報如下錯誤:
checking for PCRE library ... not found
checking for PCRE library in /usr/local/ ... not found
checking for PCRE library in /usr/include/pcre/ ... not found
checking for PCRE library in /usr/pkg/ ... not found
checking for PCRE library in /opt/local/ ... not found
去掉http_rewrite模塊:
./configure --prefix=/usr/local/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module --without-http_rewrite_module
到這一步的時候碰到如下錯誤:
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已經安裝。
openssl
如果沒有安裝,執行下面的命令進行安裝:
brew install openssl
有可能最后openssl沒有安裝到系統會自動搜索的那幾個目錄。我的mac上就不是。查找openssl 安裝目錄:
brew info openssl
按照提示加上路徑即可:
./configure --prefix=/Users/username/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module --with-openssl=/usr/local/opt/openssl@1.1
成功后出現如下提示:
Configuration summary
+ using system PCRE library
+ using OpenSSL library: /usr/local/opt/openssl@1.1
+ using system zlib library
nginx path prefix: "/Users/chenhailiang/nginx"
nginx binary file: "/Users/chenhailiang/nginx/sbin/nginx"
nginx modules path: "/Users/chenhailiang/nginx/modules"
nginx configuration prefix: "/Users/chenhailiang/nginx/conf"
nginx configuration file: "/Users/chenhailiang/nginx/conf/nginx.conf"
nginx pid file: "/Users/chenhailiang/nginx/logs/nginx.pid"
nginx error log file: "/Users/chenhailiang/nginx/logs/error.log"
nginx http access log file: "/Users/chenhailiang/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
執行make生成二進制文件:
make
報如下錯誤:
/Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile
cd /usr/local/opt/openssl@1.1 \
&& if [ -f Makefile ]; then /Library/Developer/CommandLineTools/usr/bin/make clean; fi \
&& ./config --prefix=/usr/local/opt/openssl@1.1/.openssl no-shared no-threads \
&& /Library/Developer/CommandLineTools/usr/bin/make \
&& /Library/Developer/CommandLineTools/usr/bin/make install_sw LIBDIR=lib
/bin/sh: ./config: No such file or directory
make[1]: *** [/usr/local/opt/openssl@1.1/.openssl/include/openssl/ssl.h] Error 127
make: *** [build] Error 2
執行如下的命令,修改一個文件
vim auto/lib/openssl/conf
把下面的幾行中的.openssl去掉,然后保存
39 CORE_INCS="$CORE_INCS $OPENSSL/.openssl/include"
40 CORE_DEPS="$CORE_DEPS $OPENSSL/.openssl/include/openssl/ssl.h"
41 CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libssl.a"
42 CORE_LIBS="$CORE_LIBS $OPENSSL/.openssl/lib/libcrypto.a"
改成
39 CORE_INCS="$CORE_INCS $OPENSSL/include"
40 CORE_DEPS="$CORE_DEPS $OPENSSL/include/openssl/ssl.h"
41 CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libssl.a"
42 CORE_LIBS="$CORE_LIBS $OPENSSL/lib/libcrypto.a"
注意:修改完之后需要重新執行一遍 configure,否則修改不生效。
再次make成功
make install
執行make install 安裝nginx和nginx-rtmp-module到指定目錄:
make install
修改配置文件
修改安裝目錄下面的conf/nginx.conf文件,添加rtmp配置:
rtmp {
server {
listen 1935;
application mytv {
live on;
}
}
}
啟動服務
./sbin/nginx -c ./conf/nginx.conf
使用ffmpeg推流
ffmpeg -re -i /Users/username/test_sps_1.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/mytv/home
ffplay 播放
ffplay -i. rtmp://localhost:1935/mytv/home
打印debug日志
如果需要調試查看debug log,做下面兩部操作:
添加--with-debug選項
./configure --prefix=/Users/username/nginx --with-http_ssl_module --add-module=../nginx-rtmp-module --with-debug --with-openssl=/usr/local/opt/openssl@1.1
修改配置文件nginx.conf中的日志配置項:
#error_log logs/error.log info;
修改為
error_log logs/error.log debug;