Reputation: 821
I am creating GIFs with the pillow imaging library. I'm running into an issue where I am trying to make certain frames flicker very fast with the minimum frame duration possible, but when I set the frame to have a duration of 1 (the lowest possible duration, out of 100 for a GIF), it actually seems to last for longer than expected.
I save the gif with a simple Image.save()
(GIF format) command similar to the following:
# durations are actually in milliseconds in the pillow library, but
# they translate to 100ths of a second (1/10 of the value input here)
durations = [650, 10, 900, 750, 10, 800, 10, ... ]
my_gif.save(filename, format='GIF', save_all=True, duration=durations, loop=0, disposal=2)
I am not sure if this issue is specific to the pillow library or just to the GIF format more generally. But I have noticed the following things:
Original Image | Sped Up Image
65 32
1 2
90 45
1 2
75 37
1 2
80 40
1 2
4 2
1 2
114 56
1 2
35 17
1 2
100 50
1 2
1 2
1 2
20 10
1 2
250 125
1 2
Can someone help explain the reason for this seeming disparity? Is this how the GIF format works, or is it a problem with the pillow imaging library? How can I generate GIFs that have a faster "flickering" effect as I would prefer them to?
Upvotes: 2
Views: 3346
Reputation: 821
After further research this seems to be a known issue with gif rendering across different browsers and platforms. While the GIF specification indicates that GIFs support up to 100fps, in reality, most modern browsers support only 50fps max, as noted in Buttery Smooth 10fps
This superuser answer is what originally led me to understand the issue. It explains the problem and gives a few contextual links, including a link to Frame Delay Times for Animated Gifs, which provides some additional context about the history behind this disparity. The latter article hints at the fact that some browsers might interpret a value of 1/100 as 10/100, making it seem much slower than expected.
Anecdotally I have found that setting the gif frame delay to 2/100 (instead of 1/100) results in far faster frame playback in modern browsers where I've tested it, and this seems to be the maximum speed (50fps) that they support. I suspect EZGif already knows this and has accounted for it in their algorithms.
Upvotes: 5