我使用的是一个canvas
元素来实时地拼合多个video
元素,这很好地工作。我也试图抓取canvas
数据并定期将其写入文件,因此当video
元素播放完毕后,我可以从原始帧的文件中编码视频。HTML5 FileWriter InvalidStateError
我有一个叫上一个定时器的时间间隔功能每40ms(给25fps的),大约如下所示(有太多的代码全部粘贴):
function saveFrame() {
// code to copy from video elements to my canvas...
// ...
// Get the canvas image data and write it to a file
var imgData = canvasContext.getImageData(0, 0,
canvasElement.width,
canvasElement.height);
var b = new Blob([imgData], {type: 'application/octet-binary'});
// Write the blob to a file I previously opened
// fileWriter is a FileWriter that I obtained and saved previously
fileWriter.write(b);
}
setInterval(function() {
saveFrame();
}, 40);
每次我打fileWriter.write(blob)
声明我收到以下错误:
Uncaught InvalidStateError: An operation that depends on state cached in an interface object was made but the state had changed since it was read from disk.
这是计时问题吗?文件编写器API不能每40ms写入一次吗?
每1000ms的结果呢? – Pinal
我最终缓冲了我的图像并每500ms写入一次。它工作没有问题。 – edoloughlin