【问题标题】:How should I should I configure NGINX rtmp server so I can publish both a rtmp stream and hls at the same time我应该如何配置 NGINX rtmp 服务器,以便我可以同时发布 rtmp 流和 hls
【发布时间】:2021-12-04 21:27:16
【问题描述】:

我目前正在运行一个 ffmpeg bash 脚本,它从实时摄像头提要中提取 RTSP 提要,然后将其作为 RTM` 发布到我的 Nginx 服务器。

对服务器的要求是用户既可以订阅Nginx服务器发布的RTMP feed,也可以订阅HLS流。

我发现的问题是 RTMP 流在一段时间后冻结,尽管 HLS 流继续工作。

我想知道这是不是因为它是一个单独的进程,而不是 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 feed 或 HLS 一个

【问题讨论】:

    标签: nginx http-live-streaming rtsp rtmp


    【解决方案1】:

    您可以播放 RTMP 和 HLS 流。我认为问题不在于协议,而在于相机的内容或时间戳。

    The problem I'm finding is that the RTMP stream freezes after a while,
    although the HLS stream continues to works.
    

    你可以试试:

    1. 使用较小的比特率,例如-b:v 500k
    2. 同时对音频流进行转码,或禁用音频。
    3. 尝试其他媒体服务器,以启用 atc 绕过时间戳。
    4. 尝试其他 RTMP 播放器,例如 VLC 或 ffplay。

    【讨论】:

      猜你喜欢
      • 2020-08-20
      • 2021-10-17
      • 1970-01-01
      • 2021-01-08
      • 2019-03-25
      • 1970-01-01
      • 2021-03-06
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多