【问题标题】:nginx HLS stream not workingnginx HLS流不起作用
【发布时间】:2017-11-23 15:49:45
【问题描述】:

我在我的 linux 服务器上安装了带有 RTMP 模块的 nginx,我希望它从 Open Broadcaster Software 接收 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 文件,但似乎无法正常工作当我尝试在 HTML5 播放器中播放文件时的网页。我正在通过这些页面进行测试:https://videojs.github.io/videojs-contrib-hls/https://demo.theoplayer.com/test-hls-mpeg-dash-stream

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

【问题讨论】:

    标签: html nginx rtmp http-live-streaming


    【解决方案1】:

    nginx-1.21.1

    location /hls/ {
        # Serve HLS fragments
        types {
            application/vnd.apple.mpegurl m3u8;
            video/mp2t ts;
        }
        **root /tmp;** -> **alias /tmp;**
        add_header Cache-Control no-cache;
        add_header 'Access-Control-Allow-Origin' '*';
    }
    

    【讨论】:

    • 请添加更多详细信息以扩展您的答案,例如工作代码或文档引用。
    【解决方案2】:

    行下:#hls_fragment 6s; 添加代码:deny_play_all;

    如果可以播放 rtmp 流,显然您无法播放 hls 或 dash 文件。我不知道为什么。它对我有用。

    【讨论】:

      【解决方案3】:

      如果您分享在这些页面上测试 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' '*';
      }
      

      干杯。 伊恩

      【讨论】:

      • 当我对这些播放器进行测试时,我没有得到任何明确的错误反馈,但是当我在 VLC 中测试流时,此解决方案有效。我注意到的另一件事是,它仅在我使用直接 ip 时才有效,而在我尝试连接时却没有域名,所以我猜那里有一些奇怪的设置出错了(或者只是被域名提供商阻止)。
      猜你喜欢
      • 1970-01-01
      • 2015-03-08
      • 2017-11-29
      • 2016-08-30
      • 2020-08-20
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-03-25
      相关资源
      最近更新 更多