+
108
-

canvas动画如何生成视频?

canvas动画如何生成视频?


网友回复

+
12
-

将Canvas动画生成为视频有几种方法。以下是一些常用的方法:

使用MediaRecorder API(仅适用于现代浏览器):
const canvas = document.querySelector('canvas');
const stream = canvas.captureStream(30); // 30 FPS

const recordedChunks = [];
const mediaRecorder = new MediaRecorder(stream, {mimeType: 'video/webm'});

mediaRecorder.ondataavailable = (e) => {
  if (e.data.size > 0) {
    recordedChunks.push(e.data);
  }
};

mediaRecorder.onstop = () => {
  const blob = new Blob(recordedChunks, {type: 'video/webm'});
  const url = URL.createObjectURL(blob);
  const a = document.createElement('a');
  a.href = ...

点击查看剩余70%

我知道答案,我要回答