Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.9k views
in Technique[技术] by (71.8m points)

Html5 video播放blob视频在chrome中无效

原本的视频url:src="http://x.x.x.x:xxx/xxx/video?id=123456"
这个视频使用原生的video播放在chrome中无法播放,在firefox中可以播放,于是我试着转换为blob进行播放
`

 const res = await fetch(src).then(res => res.blob());  // 这里的blob的类型是{ type: "application/octet-stream" }
 
 // 尝试转换为mp4类型
 const blob = res.slice(0, res.size, 'video/mp4');
 
 const url = URL.createObjectURL(blob);
 const video = document.getElementsByTagName('video')[0];
  
  video.getElementsByTagName('source')[0].src = url;
 

`
播放的时候还是在chrome中无法播放,只能在firefox中进行播放


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Chrome只支持标准的H.264方式编码,对上传的视频进行转码,将非H.264编码方式的视频文件转换成H.264编码方式的视频,就可以在Chrome上正常播放了


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...