首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Nginx RTMP/HLS - stream to ffmpeg并输出HLS

Nginx RTMP/HLS - stream to ffmpeg并输出HLS
EN

Stack Overflow用户
提问于 2018-10-22 04:03:10
回答 1查看 2.5K关注 0票数 0

在这一点上,我的解决方案是有效的,但仅作为RTMP,我可以使用URL完美地观看我的流:

代码语言:javascript
复制
rtmp://X.X.X.X:1935/show/name

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

因此,我的目标是将流作为HLS提供,而不必手动触发RTMP端点或FFMPEG。

我真的很努力,花了3天的时间才让它工作起来:

代码语言:javascript
复制
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;
    }
}

}

感谢您的宝贵时间;)

EN

回答 1

Stack Overflow用户

发布于 2018-11-21 06:44:49

试试下面这样的代码:

代码语言:javascript
复制
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;
        }
    }
}
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52919354

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档