最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - How to play arraybuffer on video tag? - Stack Overflow

programmeradmin0浏览0评论

I'm getting images from html canvas and would like to convert these images into a video. Search long and hard. Just want to take a couple of images and make them into a video. I manage to pass multiple images to a library engine and it return me a arraybuffer.

My question:

How can I take a arraybuffer and play it in a video tag or convert it so it can play.

On Request:

//You can simply call:
var frames = [];//array to hold each image/frame url
frames.push(canvas.toDataURL('image/png'));//get the data url from canvas

But my question concern more of using arraybuffer as a uri for a video tag.

I'm getting images from html canvas and would like to convert these images into a video. Search long and hard. Just want to take a couple of images and make them into a video. I manage to pass multiple images to a library engine and it return me a arraybuffer.

My question:

How can I take a arraybuffer and play it in a video tag or convert it so it can play.

On Request:

//You can simply call:
var frames = [];//array to hold each image/frame url
frames.push(canvas.toDataURL('image/png'));//get the data url from canvas

But my question concern more of using arraybuffer as a uri for a video tag.

Share Improve this question edited Feb 7, 2021 at 10:49 Mark Rotteveel 109k229 gold badges156 silver badges220 bronze badges asked Feb 19, 2018 at 17:07 webeconwebecon 791 silver badge7 bronze badges 2
  • Could you please provide some code of how you are getting the images from canvas? – Antonio Narkevich Commented Feb 19, 2018 at 17:40
  • Possible duplicate of HTML5 generating video from images – Karen Grigoryan Commented Feb 19, 2018 at 18:59
Add a ment  | 

2 Answers 2

Reset to default 6

I ended up using the following solution:

const arrayBuffer = null; // your ArrayBuffer goes here
// For example you can fetch it from some URL like 
// const arrayBuffer = await fetch(url).then(r => r.arrayBuffer());
const blob = new Blob([arrayBuffer]);
const video = document.createElement('video');
video.src = URL.createObjectURL(blob);
// You can now insert video into DOM

You can directly use it, You can use mediaStream and then create URL object. Which can be passed to video tag

发布评论

评论列表(0)

  1. 暂无评论