01-nginx+rtmp 搭建

编译安装

  1. 下载 nginx
  2. 下载 rtmpnginx 同一目录
  3. 配置 --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 库支持

  1. 下载 openssl 通过链接下载配置未成功,所以使用 brew安装
brew install openssl@1.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"
  1. 编译
make -j 16
  1. 安装
make install
  1. 查看是否安装成功
/usr/local/ 是否包含 nginx
  1. 使用,cd /usr/local/nginx/

启动服务

sudo ./sbin/nginx -c ./conf/nginx.conf

关闭服务

sudo ./sbin/nginx -s stop
  1. 配置 rtmpnginx

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 流媒体服务器](

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Nginx是一个高性能的开源Web服务器,同时也可以用作反向代理服务器、负载均衡器和流媒体服务器。NginxRtmp-Module是一个第三方模块,它为Nginx服务器添加RTMP(Real-Time Messaging Protocol)支持,使其可以充当一个流媒体服务器。FFmpeg是一个跨平台的音视频处理工具,它可以用来进行多媒体文件的转码、编解码、录制和流媒体传输等操作。 引用中提到了使用Nginx Nginx-Rtmp-Module Ffmpeg搭建流媒体服务器的方法。具体配置可以查看conf/nginx.conf文件。首先需要解压文件,然后运行nginx_start.bat文件来启动Nginx服务器。这样就可以使用Nginx服务器提供的RTMP服务,通过FFmpeg推送一个RTMP流到Nginx,然后客户端可以通过访问Nginx来收看实时视频流。还可以使用HLS(HTTP Live Streaming)协议,通过HTTP协议来访问Nginx服务器并收看视频流,但是FFmpeg推送流仍然是RTMP的。<span class="em">1</span><span class="em">2</span><span class="em">3</span> #### 引用[.reference_title] - *1* *3* [nginx+nginx-rtmp-module+ffmpeg搭建流媒体服务器服务器](https://blog.csdn.net/sinat_16643223/article/details/115108327)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] - *2* [ffmpeg+nginx+nginx-rtmp-module搭建个人直播平台](https://download.csdn.net/download/qq_29114677/13012815)[target="_blank" data-report-click={"spm":"1018.2226.3001.9630","extra":{"utm_source":"vip_chatgpt_common_search_pc_result","utm_medium":"distribute.pc_search_result.none-task-cask-2~all~insert_cask~default-1-null.142^v93^chatsearchT3_2"}}] [.reference_item style="max-width: 50%"] [ .reference_list ]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值