繁体   English   中英

TS文件未播放hls.js

[英]TS file not playing hls.js

需要一些帮助。 视频已加载到浏览器中,但从未开始播放。 我正在使用hls.js将m3u8播放列表流式传输到浏览器。 我使用FFmpeg创建ts和m3u8文件。

对于FFmpeg:

./ffmpeg -rtsp_transport tcp -i rtsp://user:password@ipaddress/axis-media/media.amp -vcodec copy -hls_time 4 -hls_list_size 4 -hls_wrap 4 -start_number 1 -y test.m3u8

HTML代码:

<!DOCTYPE html>
<html>
  <head>
     <script src="https://cdn.jsdelivr.net/npm/hls.js@latest"></script>
  </head>

  <body>
     <video id="video" height="800px" width="1200px"></video>
  <body>

  <script>
     var video = document.getElementById('video');
     if(Hls.isSupported()){
        var hls = new Hls();
        hls.loadSource('/images/live/test.m3u8');
        hls.attachMedia(video);
        hls.on(Hls.Events.MANIFEST_PARSED,function() {
              video.play();
         });
      }
      else if (video.canPlayType('application/vnd.apple.mpegurl')){
         video.src = '/images/live/test.m3u8';
         video.addEventListener('loadedmetadata',function() {
              video.play();
         });
      }
   </script>
</html>

只需将ffmpeg命令行更改为:ffmpeg -rtsp_transport tcp -i rtsp:// user:password@ip_address/axis-media/media.amp -y -s 854x480 -codec:v libx264 -b:v 800000 -hls_time 4- hls_list_size 4 -hls_wrap 4 start_number 0 test.m3u8

您的代码有两个问题。

  1. 该剧需要鼓风机允许音频自动显示

    NotAllowedError:在当前上下文中,用户代理或平台不允许使用play方法,这可能是因为用户拒绝了权限。

  2. hls.js无法访问其地图文件

    请求失败,状态为404
    网址:hls.min.js.map

只需将其更改为可行的CDN

 <!DOCTYPE html> <html> <head> <script src="https://cdn.jsdelivr.net/npm/hls.js"></script> </head> <body> <video id="video" height="800px" width="1200px"></video> <body> <script> var video = document.getElementById('video'); if(Hls.isSupported()){ var hls = new Hls(); hls.loadSource('http://vfile1.grtn.cn/2018/1542/0254/3368/154202543368.ssm/154202543368.m3u8'); hls.attachMedia(video); hls.on(Hls.Events.MANIFEST_PARSED,function() { video.play(); }); } else if (video.canPlayType('application/vnd.apple.mpegurl')){ video.src = 'http://vfile1.grtn.cn/2018/1542/0254/3368/154202543368.ssm/154202543368.m3u8'; video.addEventListener('loadedmetadata',function() { video.play(); }); } </script> </html> 

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM