在 nginx 中配置 RTMP 的步驟有:安裝 RTMP 模塊編輯 Nginx 配置文件,添加 RTMP 配置創建用于推送和拉取流的 RTMP 流源重啟 Nginx使用 VLC 播放器驗證配置
如何在 Nginx 中配置 RTMP
為了在 Nginx 中配置 RTMP,請按照以下步驟操作:
1. 安裝 RTMP 模塊
apt-get install nginx-module-rtmp
2. 配置 Nginx
在 Nginx 配置文件 /etc/nginx/nginx.conf 中,添加以下內容:
rtmp { server { listen 1935; chunk_size 4096; application live { push "push.stream"; pull "live.stream"; live on; } } }
3. 創建 RTMP 流源
創建兩個流源,一個用于推送流,一個用于拉取流:
# 推送流源 ffmpeg -re -i input.mp4 -vcodec libx264 -acodec aac -f flv rtmp://localhost:1935/live/push.stream # 拉取流源 ffmpeg -i rtmp://localhost:1935/live/live.stream output.mp4
4. 重啟 Nginx
systemctl restart nginx
5. 驗證配置
您可以使用 VLC 媒體播放器連接到 RTMP 流源以驗證配置:
- 推送流:rtmp://localhost:1935/live/push.stream
- 拉取流:rtmp://localhost:1935/live/live.stream
? 版權聲明
文章版權歸作者所有,未經允許請勿轉載。
THE END