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

Not piping during add frame #33

Open
enricodeleo opened this issue Jul 3, 2018 · 7 comments
Open

Not piping during add frame #33

enricodeleo opened this issue Jul 3, 2018 · 7 comments
Labels

Comments

@enricodeleo
Copy link

Hi!

I'm creating a gif with 30 frames (but it happens for fewer frames too) and I noticed that even if I'm piping the image encoder to an express response, the image becomes visible only when the encorder.finish is called. Do I have misunderstood the advantage of stream in this use case or is it unexpected?

@heikkipora
Copy link
Collaborator

The encoder emits data to the consumer stream (http response stream in your case) after every frame (from code comments: "The frame is not written immediately, but is actually deferred until the next frame is received so that timing data can be inserted.")

There's likely buffering on multiple points before the image data reaches the browser. Could it be that your gif is rather small and thus the buffers are flushed only at the end of the encoding process ?

@enricodeleo
Copy link
Author

I tried some logging and even if each frame is added. The stream is ok and the browser starts downloading immediately but again, nothing until finish is called.

This happens with every kind of gif I tried to create (from flat color to background images) and quality.
The only variable that really matters is how much frames I ask the encoder to add. My understanding is that with stream the browser shouldn't wait for the (for example) 10th frame to start seeing the image. Am I wrong?

@heikkipora
Copy link
Collaborator

heikkipora commented Jul 18, 2018

I was under the impression (too) that browsers would start GIF animation playback immediately, but now I cannot confirm that. It seems that all GIF files I can come up with only start playing after all data has been received.

@enricodeleo
Copy link
Author

@heikkipora yes it's exactly what I meant before. I cannot understand if this is something I can ever get. It starts being sloppy when you add 30 or 40 frames. As far as you know, is there any way of (at least) make frame addition parallel? Something like gif.js does in the browser with workers?

@heikkipora
Copy link
Collaborator

Node.js is single-threaded so the answer is no (to being able to process the frames in parallel).

@enricodeleo
Copy link
Author

@heikkipora, believe me, I know very well about that, that's because I was talking about workers :)

@heikkipora
Copy link
Collaborator

Good :-) On node.js side that would mean using the node.js cluster mechanism but it would a very complex solution for the problem.

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

No branches or pull requests

2 participants