Closed happylinks closed 10 months ago
Thanks for tracking this down! I'd be in favor of accepting a PR to fix this
I looked into this and I'm not sure how to replicate it.
The number of repetitions is a u16
, so the program won't compile without an integer cast. Converting from -1_iX
will result in u16::MAX
. An infinite loop corresponds to 0
, according to http://www.vurdalakov.net/misc/gif/netscape-looping-application-extension. Perhaps Finder is automatically looping a one-repeat GIF?
pub enum Repeat {
Finite(u16),
Infinite,
}
https://docs.rs/gif/0.12.0/gif/enum.Repeat.html
The extension block is written when Encoder::set_repeat
is called, which includes the NETSCAPE2.0
command. Either a 0
or the number of repetitions is written.
If Repeat::Finite(0)
is specified, then the block isn't written.
https://github.com/image-rs/image-gif/blob/442225a78d55c9deb900fc4805117db7b778d822/src/encoder.rs#L272-L276
Did some testing, just to be helpful.
Gif generated with this library: https://tella-static.s3.us-east-2.amazonaws.com/clfic1aqm00000gmk3leg87cr.gif
"Fixed" with ffmpeg -i <input gif> -loop 0 -c copy <output gif>
:
https://tella-static.s3.us-east-2.amazonaws.com/clfic1aqm00000gmk3leg87cr-fixed.gif
Hex diff:
I'm not seeing the NETSCAPE2.0 part at all in the original gif, I set repeat to -1.
I'll test your code as well.
Tested your example code and it looks fine indeed, it repeats infinitely in chrome.
Maybe it has to do with the library I'm using: https://gitlab.freedesktop.org/gstreamer/gst-plugins-rs/-/blob/main/video/gif/src/gifenc/imp.rs#L120 Code looks good at first glance though. I'll dig a bit deeper.
Ok yeah, it's not this project, it's the gstreamer plugin passing "0" for repeats. Sorry about the noise! I'll fix it in that package.
I'm creating gifs with repeat: -1, which should loop. In finder this works fine, but in browsers (Chrome for example) it only plays once. I found this post about it: https://stackoverflow.com/questions/10867789/animated-gif-only-loops-once-in-chrome-and-firefox
Aparantly you need to add this extension command: "0x21,0xFF,0x0B,"NETSCAPE","2.0",0x03,0x01,0x00,0x00,0x00" for it to loop.
Is this something we can add to this library? I can make a PR, but any guidance would be great.