spite / ccapture.js

A library to capture canvas-based animations at a fixed framerate
MIT License
3.55k stars 406 forks source link

Support aborting GIF encoding #146

Open octal-crypto opened 1 year ago

octal-crypto commented 1 year ago

Adds support for aborting GIF encoding.

Encoding the captured frames as a GIF can take a long time. Especially when there are many frames. Users may want to abort the GIF encoding after it starts.

The gif.js library supports this with an abort() function. But the CCapture object doesn't expose the gif.js encoder to the caller. This prevents gif.js's abort() function from being callable.

This pull request modifies the CCGIFEncoder's save() function to return the gif.js abort() function:

capturer = new CCapture({ format: 'gif' });
...
abort = capturer.save();
...
abort();
octal-crypto commented 1 year ago

This PR is mostly to share my workaround I've been using. Rather than expecting it to be merged. If there are better suggestions to achieve the functionality, they can be shared here.