一文搞定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 实现视频推流。

暂无评论

发送评论 编辑评论


				
|´・ω・)ノ
ヾ(≧∇≦*)ゝ
(☆ω☆)
(╯‵□′)╯︵┴─┴
 ̄﹃ ̄
(/ω\)
∠( ᐛ 」∠)_
(๑•̀ㅁ•́ฅ)
→_→
୧(๑•̀⌄•́๑)૭
٩(ˊᗜˋ*)و
(ノ°ο°)ノ
(´இ皿இ`)
⌇●﹏●⌇
(ฅ´ω`ฅ)
(╯°A°)╯︵○○○
φ( ̄∇ ̄o)
ヾ(´・ ・`。)ノ"
( ง ᵒ̌皿ᵒ̌)ง⁼³₌₃
(ó﹏ò。)
Σ(っ °Д °;)っ
( ,,´・ω・)ノ"(´っω・`。)
╮(╯▽╰)╭
o(*////▽////*)q
>﹏<
( ๑´•ω•) "(ㆆᴗㆆ)
😂
😀
😅
😊
🙂
🙃
😌
😍
😘
😜
😝
😏
😒
🙄
😳
😡
😔
😫
😱
😭
💩
👻
🙌
🖕
👍
👫
👬
👭
🌚
🌝
🙈
💊
😶
🙏
🍦
🍉
😣
Source: github.com/k4yt3x/flowerhd
颜文字
Emoji
小恐龙
花!
上一篇
下一篇