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

Additional unwanted delay for each frame #5

Open
marcusteh1238 opened this issue Jun 23, 2020 · 1 comment
Open

Additional unwanted delay for each frame #5

marcusteh1238 opened this issue Jun 23, 2020 · 1 comment

Comments

@marcusteh1238
Copy link

Description

When encoding a GIF, it gives me additional delay for each frame of the GIF. This is noticeable for GIFs with high FPS. It seems to be fine for GIFs around 60 FPS, but the delay is noticeable for GIFs above 120 frames. As you can see below, the circle moves slower due to the additional delay.

Before:

sine-gif

After:

output

Repro

OS: Windows 10
Node Version: v12.13.1
Dependencies:

  "canvas": "^2.6.1",
  "gif-encoder-2": "^1.0.5",
  "gif-frames": "^1.0.1" 

Code snippet to reproduce the bug.

const fs = require('fs');
const { createCanvas, loadImage, createImageData } = require('canvas');
const GIFEncoder = require('gif-encoder-2');
const gifFrames = require('gif-frames'); // https://github.com/benwiley4000/gif-frames

async function getGif() {
  // I used gifFrames to get the image buffer array
  const imageBufferArray = gifFrames({ url: gifBackgroundPath, frames: "all", cumulative: true}).map(data => data.getImage()._obj)
  const encoder = new GIFEncoder(600, 600, 'octree', true);
  encoder.start();
  for (let i = 0; i < frameDataArray.length; i += 1) {
    const image = await loadImage(imageArray[i]);
    const canvas = createCanvas(600, 600);
    const context = canvas.getContext("2d");
    context.drawImage(image, 0, 0);
    encoder.addFrame(context);
  }
  encoder.finish();
  const gifBuffer = encoder.out.getData();
  return fs.writeFile('output.gif', gifBuffer, (err) => { console.log(err) });
}

getGif().then(() => console.log("Done!"));
@Tryliom
Copy link

Tryliom commented Oct 15, 2021

I would say that you cannot go above 100 fps and the more you go after 50 fps, it's getting slower and slower.

Source: https://wunkolo.github.io/post/2020/02/buttery-smooth-10fps/

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

No branches or pull requests

2 participants