【问题标题】:Nginx RTMP/HLS - stream to ffmpeg and output HLSNginx RTMP/HLS - 流式传输到 ffmpeg 并输出 HLS
【发布时间】:2019-03-25 22:31:53
【问题描述】:

此时我的解决方案正在运行,但仅作为 RTMP,我可以使用 URL 完美地观看我的流:

rtmp://X.X.X.X:1935/show/name

但问题是我使用 WebOS 的 LG 智能电视不支持 RTMP,我真的很想在那里播放我的流。我现在能看到的唯一解决方案是使用 HLS。使用 HLS 也一切正常,但我需要在电视中打开 HLS 流之前执行我的 ffmpeg 命令,否则它不会创建在我的电视上显示流所需的文件。

所以我的目标是将流作为 HLS 提供,而无需手动触发 RTMP 端点或 FFMPEG。

我真的在为此苦苦挣扎,浪费了 3 天时间试图让它发挥作用:(

http 
{
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/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
    }

    root /mnt/;
    }
}

}
rtmp {
server {
    listen 1935;

    chunk_size 4000;
    buflen 5s;

    application show {
        live on;

    exec_pull ffmpeg -re -i http://stream-coming.com/$name.ts -c:v libx264 -preset faster -pix_fmt yuv420p -c:a aac -f flv rtmp://localhost/show/$name;

        # Turn on HLS
        hls on;
        hls_path /mnt/hls/;
        hls_fragment 3;
        hls_playlist_length 60;
        # disable consuming the stream from nginx as rtmp
        deny play all;
    }
}

}

感谢您的宝贵时间;)

【问题讨论】:

    标签: nginx ffmpeg stream rtmp http-live-streaming


    【解决方案1】:

    试试这样的:

    rtmp {
        server {
            listen 1935;
    
            application show {
                live on;
    
                exec_push ffmpeg -re -i rtmp://stream-coming.com:1935/$name.ts
                -c:v libx264 -preset faster -pix_fmt yuv420p -c:a aac -f flv rtmp://localhost:1935/hls/$name;
                exec_kill_signal term;
            }
    
            application hls {
    
                # Turn on HLS
                live on;
                hls on;
                hls_path /mnt/hls/;
                hls_fragment 3;
                hls_playlist_length 12;
                # disable consuming the stream from nginx as rtmp
                allow publish 127.0.0.1;
                deny play all;
            }
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-05-22
      • 2019-09-05
      • 1970-01-01
      • 2020-08-20
      • 2016-12-10
      • 2017-09-20
      • 2013-06-29
      • 1970-01-01
      相关资源
      最近更新 更多