首页 文章

nginx HLS流无法正常工作

提问于
浏览
-1

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

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文件,但不通过这些页面进行测试:https://videojs.github.io/videojs-contrib-hls/https://demo.theoplayer.com/test-hls-mpeg-dash-stream

谁能帮助我理解我做错了什么?

1 回答

  • 0

    如果您在这些页面上测试HLS流时共享了哪种类型的控制台或网络错误,这将有所帮助 .

    它可能会为您提供一些故障排除方法 . 例如,您可能通过从其他域访问流来获取访问控制允许来源错误 . 尝试在nginx.conf中取消注释这一行并重新加载 .

    #add_header Access-Control-Allow-Origin *;
    

    我还提到了“video / mp2t ts;”在我的hls位置块 .

    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' '*';
    }
    

    干杯 . 伊恩

相关问题