我正在使用枕头图像库创建 GIF。我遇到了一个问题,我试图以尽可能最小的帧持续时间使某些帧闪烁得非常快,但是当我将帧的持续时间设置为 1(可能的最低持续时间,GIF 的持续时间为 100) ,实际上它的持续时间似乎比预期的要长。
我用一个简单的方法保存了gifImage.save() https://pillow.readthedocs.io/en/stable/reference/Image.html#PIL.Image.Image.save (GIF格式 https://pillow.readthedocs.io/en/stable/handbook/image-file-formats.html#gif) 命令类似于以下内容:
# 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)
我不确定这个问题是特定于枕头库还是仅特定于 GIF 格式。但我注意到以下几点:
- gif 视觉上看起来比预期慢
- 当我将生成的 GIF 加载到 GIF 编辑工具(例如 EZGif.com)中时,它报告帧持续时间符合预期 - “闪烁帧”的持续时间为 1,这是我保存文件时使用的帧持续时间。
- When I speed up使用 EZGif 的 GIF,奇怪的是,EZGif 生成的 GIF 的“加速”版本使用帧持续时间 2 而不是 1 作为闪烁帧,但是视觉上看起来播放速度更快,更接近我真正想要发生的事情。
原始图像 “加速”图像
加载到 EZGif 时报告的每帧持续时间
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
问题...
有人可以帮助解释这种看似差异的原因吗?这是GIF格式的工作原理,还是枕头图像库的问题?如何生成具有更快“闪烁”效果的 GIF,就像我希望的那样?