2017-06-20 118 views
-1

我已经在我的linux服务器上安装了带有RTMP模块的nginx,我希望它从Open Broadcaster软件接收RTMP流,将其转换为HLS,并在我的私人网站上用一些HTML5播放器播放它。通过RTMP接收数据流工作,但HLS数据流似乎不起作用。我现在的配置是像这样:nginx 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://ip/stream/streamname我尝试使用http://ip:8080/hls/streamname.m3u8这给了我.m3u8文件,如果我在浏览器中键入它的正常工作,接受HLS的RTMP流,但当我尝试在HTML5播放器中播放文件时,似乎无法在网页上工作。我正在测试通过这些网页:https://videojs.github.io/videojs-contrib-hls/https://demo.theoplayer.com/test-hls-mpeg-dash-stream

任何人都可以帮助我了解我在做什么错?

回答

0

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

它可能会为您提供一些洞察,以便您排除故障。例如,您可能通过访问来自其他域的流来获取访问控制允许来源错误。尝试在你的nginx.conf中取消注释该行并重新加载。

#add_header Access-Control-Allow-Origin *; 

我也有“video/mp2t ts;”的引用。在我的位置块。

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

干杯。 Ian

+0

正如我与那些玩家一起测试的,我没有得到任何明确的错误反馈,但是当我在VLC中测试流时,此解决方案起作用。我注意到的另一件事是,它只在我使用我的直接ip时起作用,而当我尝试连接时没有域名,所以我想有一些奇怪的设置在那里出错了(或者只是被域名提供商阻止)。 – Zamor