How to edit .webm Blobs captured by Chrome MediaRecorder How to edit .webm Blobs captured by Chrome MediaRecorder google-chrome google-chrome

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.


I have struggled a lot trying to make videos frame by frame using canvas.captureStream() and MediaRecorder, including using your pause/resume solution. It simply doesn't seem this is intended usage. I have, however, found a library exactly for this purpose: CCapture.js. It worked for me. It works by sampling image dumps of the canvas and joining them afterwards. In the process it overrides some internal functions, so may not be safe for everything(?). But it makes the job very easy. Also, it allows multiple output formats, and in my limited experience, the webm output has much better quality than that achieved with MediaRecorder.