antimatter15 / whammy

A real time javascript webm encoder based on a canvas hack
http://antimatter15.github.com/whammy/clock.html
MIT License
1.02k stars 181 forks source link

Web Workers #34

Open positlabs opened 8 years ago

positlabs commented 8 years ago

Recording at high res / fps is pretty choppy. Is there some way we can improve this by offloading the .toDataURL() call to web workers? I assume that is where the bottleneck is, but I don't think you can reference dom elements in worker scripts.

Thoughts?

antimatter15 commented 8 years ago

Yeah you can't reference DOM elements in worker scripts, so unfortunately it probably isn't possible to parallelize by using webworkers.

On Mon, Dec 7, 2015 at 2:59 PM, Josh Beckwith notifications@github.com wrote:

Recording at high res / fps is pretty choppy. Is there some way we can improve this by offloading the .toDataURL() call to web workers? I assume that is where the bottleneck is, but I don't think you can reference dom elements in worker scripts.

Thoughts?

— Reply to this email directly or view it on GitHub https://github.com/antimatter15/whammy/issues/34.

positlabs commented 8 years ago

Ok, so we definitely need to call canvas.toDataURL() to get the webp format, right? What if we did something like cached the frames until whammyVid.compile() is called? context.getImageData() is probably pretty fast compared to canvas.toDataURL(). Then we could draw all of those frames back on to a canvas, and call .toDataURL() on them during the compile step. It might make compilation noticeably slower, but I think it's worth making things smoother during capture.

positlabs commented 8 years ago

I've just tried it. This method of delayed encoding works perfectly. It's almost an order of magnitude faster, during recording (at least for my application).

Current Whammy: https://youtu.be/QK9AOAvGMsw

Delayed encoding: https://youtu.be/99Kob5Xv0Yk

rikkertkoppes commented 7 years ago

delayed encoding turns out to be a huge benefit while recording video on mobile. Built in MediaRecorder api results in choppy video, Whammy saved the day here.

However, the encoding process really stalls the interface afterwards.

I'd like to point to the OffscreenCanvas interface:

This is not yet there, but may provide even further improvements during the compile phase by actually using webworkers for that