Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support aborting GIF encoding #146

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

octal-crypto
Copy link

@octal-crypto octal-crypto commented Dec 4, 2022

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();

@@ -576,7 +576,7 @@ CCGIFEncoder.prototype.save = function( callback ) {
this.callback = callback;

this.encoder.render();

return function() { this.encoder.abort() }.bind(this);
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using a fat-arrow lambda style would be more compact:
return () => this.encoder.abort();

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

that's true, though function() {} is consistent with the existing style in this file which does not use =>

Copy link

@GoToLoop GoToLoop Dec 5, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In case fat-arrow syntax isn't allowed, here's an alternative style w/o .bind(this):

  this.callback = callback;

  const enc = this.encoder;
  enc.render();

  return function() { enc.abort(); };
}

@octal-crypto
Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants