美文网首页
Mac 上源码编译并搭建直播推流服务器nginx + rtmp

Mac 上源码编译并搭建直播推流服务器nginx + rtmp

作者: ag4kd | 来源:发表于2018-11-02 15:05 被阅读0次

    mac OS下编译、安装FFmpeg

    下载 Nginx 源码

    http://nginx.org/en/download.html
    

    nginx-rtmp-module

    git clone https://github.com/arut/nginx-rtmp-module.git  
    

    编译安装Nginx

    确保 上述两个源码在同一目录下.


    image.png

    安装 openssl

    brew install openssl
    

    从终端进入Nginx源码目录,执行下面命令:

    ./configure --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module   --with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1d
    
    • 1、--add-module=../nginx-rtmp-module:指定nginx-rtmp-module对于 Nginx的相对路径.
    • 2、--with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1d:指定openssl的目录

    没有添加2的话,会报一下错误:

    ./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.
    

    没有报错的话,继续执行:

    make && sudo make install
    

    通过以上操作,nginx 和rtmp 模块就搭建好了

    问题

    问题 1 执行 configure是的问题

    bin/sh: line 2: ./config: No such file or directory
    

    将上面的configure改为config,重新执行上述命令.
    cd nginx-1.17.5

    cp configure config
    

    执行config

    ./config --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module   --with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1d
    

    问题 2,执行 make 时的问题

    /Library/Developer/CommandLineTools/usr/bin/make -f objs/Makefile
    cd /usr/local/Cellar/openssl@1.1/1.1.1d \
        && if [ -f Makefile ]; then /Library/Developer/CommandLineTools/usr/bin/make clean; fi \
        && ./config --prefix=/usr/local/Cellar/openssl@1.1/1.1.1d/.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/Cellar/openssl@1.1/1.1.1d/.openssl/include/openssl/ssl.h] Error 127
    make: *** [build] Error 2
    
    image.png

    修改下文件中的路径


    image.png image.png

    改为:去掉其中的.openssl

    image.png

    执行config

    ./config --prefix=/usr/local/nginx  --add-module=../nginx-rtmp-module  --with-http_ssl_module   --with-openssl=/usr/local/Cellar/openssl@1.1/1.1.1d
    
    make && sudo make install
    

    1.2 添加到环境变量

    export NGINX_HOME=/usr/local/nginx
    export PATH=$PATH:$NGINX_HOME/sbin   
    
    image.png

    2 配置rtmp

    which nginx
    
    /usr/local/nginx/sbin/nginx
    

    2.1 进入 nginx配置文件夹,上图 红色矩形框内的部分及时配置文件所在路径

         cd /usr/local/nginx/
    

    2.2 vim 打开 nginx.conf文件,修改配置文件

         vim nginx.conf 
    

    2.3 在http 节点 前或后添加

       rtmp {
          server {
              listen 1935;
              application live {
                  live on;
                  record off;
              }
          }
      }
    
    1C861776-0926-4AE6-AEF4-60F99304C4DF.png

    2.4 说明:

        rtmp是协议名称
        server 说明内部中是服务器相关配置
        listen 监听的端口号, rtmp协议的默认端口号是1935
        application live 访问的应用路径是 live //rtmp://localhost:1935/live/room1    这个room1是可以随便定义的
        live on; 开启实时
        record off; 不记录数据
    

    3 启动 nginx 服务

    3.1 执行以下命令

        sudo nginx
    

    3.2 查询是否启动成功

        netstat -an|grep 1935
    
    成功启动,则如图所示
    image.png

    3.3 关闭服务

    sudo nginx -s stop
    

    ffmpeg推流及拉流
    ffmpeg 抓取mac 笔记本摄像头,直播推流,使用VLC播放

    相关文章

      网友评论

          本文标题:Mac 上源码编译并搭建直播推流服务器nginx + rtmp

          本文链接:https://www.haomeiwen.com/subject/fbqcxqtx.html