当前位置: 首页 > news >正文

一文搞定Nginx配置RTMP!

目的:

配置 Nginx 服务器和 Nginx-RTMP 模块,然后使用 FFmpeg 实现视频推流。

一、配置 Nginx 服务器和 Nginx-RTMP 模块

1. 安装 Nginx 和 Nginx-RTMP 模块

○ 首先,连接到你的云服务器。
○ 安装必要的依赖:

sudo yum install -y pcre pcre-devel zlib zlib-devel openssl openssl-devel

○ 下载并安装 Nginx 和 Nginx-RTMP 模块:

# 下载nginx 和 nginx-rtmp源代码
wget http://nginx.org/download/nginx-1.21.6.tar.gz
wget https://github.com/arut/nginx-rtmp-module/archive/master.zip
# 解压nginx
tar -zxvf nginx-1.21.6.tar.gz
# 解压nginx-rtmp
unzip master.zip
# 进入nginx文件夹
cd nginx-1.21.6
# 配置nginx模块添加 nginx-rtmp
./configure --add-module=../nginx-rtmp-module-master
# 编译
make
# 安装
sudo make install

2. 配置 Nginx

○ 编辑 Nginx 配置文件:

sudo vim /usr/local/nginx/conf/nginx.conf

○ 在配置文件中添加以下内容:

rtmp {server {listen 1935;chunk_size 4096;application live {live on;record off;}}
}http {server {listen 8080;location / {root html;index index.html index.htm;}location /stat {rtmp_stat all;rtmp_stat_stylesheet stat.xsl;}location /stat.xsl {root html;}}
}

3. 移动stat.xsl

解压nginx-rtmp-module模块时,stat.xsl文件被解压到当前工作目录,需要进入目录找到stat.xsl文件,移动到/usr/local/nginx/html目录。

# 进入解压目录
cd nginx-rtmp-module-master
# 查找
ls
# 移动
sudo cp stat.xsl /usr/local/nginx/html/

4. 启动 Nginx:

sudo /usr/local/nginx/sbin/nginx

二、使用 FFmpeg 实现视频推流

1. 安装 FFmpeg

○ 在你的服务器上安装 FFmpeg:

sudo yum install -y epel-release
sudo yum install -y ffmpeg

2. 推流

○ 使用 FFmpeg 推流到 Nginx-RTMP 服务器:

ffmpeg -re -i /path/to/your/video.mp4 -c copy -f flv rtmp://your_server_ip/live/stream

○ 其中 /path/to/your/video.mp4 是你的视频文件路径,your_server_ip 是你的服务器 IP 地址。

3. 测试推流

○ 在浏览器中访问 http://your_server_ip:8080/stat 查看推流状态。

补充:同理也可以从本地主机推流到远程云服务器上,并且通过VLC播放器快速看到推送的网络视频流。下载地址

这样,你就可以在阿里云服务器上配置 Nginx 和 Nginx-RTMP 模块,并使用 FFmpeg 实现视频推流。


http://www.mrgr.cn/news/21740.html

相关文章:

  • vue3 为组件的 emits 标注类型,defineEmits基于类型的定义的简单理解
  • 关于ddddocr运行错误的解决
  • Uniapp基础学习(四)——常见API
  • 从零开始的机器学习之旅
  • 伽罗华域GF的简单计算
  • Web2和Web3笔记
  • 八大建筑央企实力排行-你打算进哪一家?
  • Spring Cloud 微服务注册
  • llama.cpp demo
  • 复数随机变量(信号)的方差和协方差矩阵的计算
  • 【大模型开发】传统向量模型 vs 重排序模型:原理、实现与应用
  • echarts 实现签到记录日历组件
  • 推荐一款强大的OCR软件,请低调使用!
  • (备份) esp32 GPIO
  • 冒泡排序——基于Java的实现
  • 人工智能时代开启ai代写模式,让创作变得更加简单!
  • Python 中考虑 concurrent.futures 实现真正的并行计算
  • 解锁数据洞察:如何使用Python读取Excel文件
  • 自用NAS系列1-设备
  • 自动生成文案的神器,一键轻松生成爆款文案