I have an Electron JS app where I draw to a canvas and then send each frame to ffmpeg to create a video. It works well, but performance is not great. This is how I currently do it:
- I have an image stream (new PassThrough) that is piped to my ffmpeg process
- When a frame is ready, I convert it to a blob with canvas.toBlob()
- I convert the blob to arrayBuffer
- And get a buffer with Buffer.from()
- I write the buffer to the image stream with .write()
I have measured the time each step takes and the bottleneck is, by far, canvas.toBlob
Is there a way to do this entire process or the toBlob step faster? I have looked into HTMLCanvasElement.captureStream() but I don't think I can pipe that to ffmpeg.
I'm using P5js for drawing. It does not seem like there is a way to draw (more) directly to a blob or buffer. Even p5.Graphics seems to draw to a hidden canvas https://p5js.org/reference/#/p5.Graphics
Thanks