首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >nginx HLS流不工作

nginx HLS流不工作
EN

Stack Overflow用户
提问于 2017-06-21 06:57:21
回答 2查看 5.7K关注 0票数 0

我已经在我的linux服务器上安装了带有RTMP模块的nginx,我想让它从Open Broadcaster接收RTMP流,将其转换为HLS,并在我的私人网站上用一些HTML5播放器播放。通过RTMP接收流起作用,但HLS流似乎不起作用。我当前的配置是这样的:

代码语言:javascript
复制
worker_processes  1;

events {
    worker_connections  1024;
}


http {
    #include       mime.types;
    #default_type  application/octet-stream;
    sendfile        off;
    #keepalive_timeout  65;

    server {
        listen       8080;
        #server_name  localhost;

        #location / {
        #    root   html;
        #    index  index.html index.htm;
        #}

        #error_page  404              /404.html;

        # redirect server error pages to the static page /50x.html
        #error_page   500 502 503 504  /50x.html;
        #location = /50x.html {
        #    root   html;
        #}

        #*********************************************************************************************************************************
        location /hls {
            types {
                application/vnd.apple.mpegurl m3u8;
        }
            root /mnt/;
            add_header Cache-Control no-cache;

            # To avoid issues with cross-domain HTTP requests (e.g. during development)
            #add_header Access-Control-Allow-Origin *;
        }
        #*********************************************************************************************************************************

    }

}

rtmp {
        server {
                listen 1935;
                chunk_size 4096;

                application stream {
                        live on;
                        #record off;

            hls on;
            hls_path /mnt/hls;
            #hls_fragment 6s;
                }
        }
}

接收我使用的RTMP流

rtmp://ip/stream/streamname它工作得很好,用于接收我尝试使用的HLS http://ip:8080/hls/streamname.m3u8如果我在浏览器中输入它,它会给我.m3u8文件,但当我试图在HTML5播放器中播放该文件时,它似乎不能在网页上工作。我正在通过这些页面进行测试:

https://videojs.github.io/videojs-contrib-hls/

和https://demo.theoplayer.com/test-hls-mpeg-dash-stream

有人能帮我弄明白我做错了什么吗?

EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2017-06-22 10:14:23

如果你在这些页面上测试你的HLS流时,你分享了你得到的控制台或网络错误的类型,这将会有所帮助。

它可能会为您的故障排除提供一些见解。例如,通过访问来自不同域的流,您可能会获得访问控制允许源错误。尝试在nginx.conf中取消对此行的注释,然后重新加载。

代码语言:javascript
复制
#add_header Access-Control-Allow-Origin *;

我还在我的hls位置块中引用了"video/mp2t ts;“。

代码语言:javascript
复制
location /hls/ {
    # Serve HLS fragments
    types {
        application/vnd.apple.mpegurl m3u8;
        video/mp2t ts;
    }
    root /tmp;
    add_header Cache-Control no-cache;
    add_header 'Access-Control-Allow-Origin' '*';
}

干杯。伊恩

票数 1
EN

Stack Overflow用户

发布于 2021-03-01 06:37:41

在这行下面:#hls_片段6s;添加代码: deny_播放_全部;

显然,如果可以播放rtmp流,则不能播放hls或dash文件。我不知道为什么。这对我来说很管用。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44664270

复制
相关文章

相似问题

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