[英]How should I should I configure NGINX rtmp server so I can publish both a rtmp stream and hls at the same time
我目前正在運行一個 ffmpeg bash 腳本,該腳本從實時攝像機源中提取 RTSP 源,然后將其作為 RTM` 發布到我的 Nginx 服務器。
對服務器的要求是用戶可以訂閱 Nginx 服務器發布的 RTMP feed 或 HLS stream。
我發現的問題是 RTMP stream 會在一段時間后凍結,盡管 HLS stream 繼續工作。
我想知道這是否是因為它是一個單獨的進程,而不是 Nginx 本身通過它的exec
命令執行的。
另外我還沒有在這台服務器上進行調整,所以我不知道我需要更改一些配置。
這是我的兩個腳本。
#!/bin/bash
sleep 1
VID_SOURCE="rtsp://camerastream.com/MediaInput/h264/stream_"
VIDEO_OPTS="-vcodec libx264 -video_size 1280x720 -b:v 2048k"
AUDIO_OPTS="-c:a copy"
VID_OUTPUT="rtmp://localserver:1935/live/livestream"
ffmpeg -rtsp_transport tcp -r 15 -i $VID_SOURCE $VIDEO_OPTS $AUDIO_OPTS -f flv $VID_OUTPUT
然后是我的 Nginx 配置
vents {}
rtmp {
server {
listen 1935;
application live {
live on;
interleave on;
# Turn on HLS
hls on;
hls_path /tmp/hls;
hls_playlist_length 15s;
}
}
}
http {
default_type application/octet-stream;
server {
listen 8080;
location /hls {
# Disable cache
add_header 'Cache-Control' 'no-cache';
# CORS setup
add_header 'Access-Control-Allow-Origin' '*' always;
add_header 'Access-Control-Expose-Headers' 'Content-Length';
# allow CORS preflight requests
if ($request_method = 'OPTIONS') {
add_header 'Access-Control-Allow-Origin' '*';
add_header 'Access-Control-Max-Age' 1728000;
add_header 'Content-Type' 'text/plain charset=UTF-8';
add_header 'Content-Length' 0;
return 204;
}
types {
application/dash+xml mpd;
application/vnd.apple.mpegurl m3u8;
video/mp2t ts;
}
root /tmp/;
}
}
}
目標是擁有一台服務器,訂閱者可以在其中觀看 rtmp 提要或 HLS 一台
您可以播放 RTMP 和 HLS stream。 我認為問題不在於協議,而在於相機的內容或時間戳。
The problem I'm finding is that the RTMP stream freezes after a while,
although the HLS stream continues to works.
你可以試試:
-b:v 500k
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.