How to edit .webm Blobs captured by Chrome MediaRecorder
I was able to define a framerate separate from the canvas refresh rate by pausing and resuming the recorder on timeout, and requesting a frame before pausing again:
let recorder = new MediaRecorder(canvas.captureStream(), {mimeType: 'video/webm'});
recorder.start();
recorder.pause();
function draw() {
context.drawImage(...);
recorder.resume();
setTimeout(function() {
recorder.requestData();
recorder.pause();
//update progress bars or any laggy overhead stuff at this point
requestAnimationFrame(draw);
}, 1000/fps);
}
requestAnimationFrame(draw);
This way, any lag in the actual canvas drawing or in updating progress bars etc. will not affect the frame collection of the recorder. recorder.requestData()
doesn't seem to be necessary, but also doesn't seem to have any downsides. It's included here for clarity.
I haven't checked in detail but there may be a double frame at the beginning depending on whether or not recorder.start()
collects an initial frame and your canvas isn't blank.