我想更改动画gif的持续时间。
使用Python Pil提取帧,然后创建具有不同持续时间的新gif。
from PIL import Image, ImageDraw
import os
def extractFrames(inGif):
frame = Image.open(inGif)
frames = []
nframes = 0
while frame:
frames.append(frame)
nframes += 1
try:
frame.seek( nframes )
except EOFError:
break;
return frames, nframes
frames, nframes = extractFrames('1.gif')
interval = 100
# In documentation says duration is interval time, but it is total time.
total_duration = nframes*interval
# Save into a GIF file that loops forever
frames[0].save('1_1.gif', format='GIF', append_images=frames[1:], save_all=True, duration=total_duration, loop=0)
但是文件大小约为原始图像的10倍。
我不明白为什么会这样并且可以预防吗?
我还尝试使用Exiftool仅更改元数据,但这对我也不起作用:
exiftool -overwrite_original -XMP-xmpDM:Duration={Scale="s",Value=14} 1.gif
Warning: Improperly formed structure for XMP-xmpDM:Duration
Warning: Improperly formed structure for XMP-xmpDM:Duration
Nothing to do.