[英]How to make a 1-hour gif using Python?
我想制作一個 1 小時長的 gif,其中包含 60 幀。
我已經使用 PIL 構建了一個 gif_making function:
sortedFiles = sorted(glob.glob('*.png'),key=os.path.getmtime)
sortedFilesBackwards = sorted(glob.glob('*.png'),key=os.path.getmtime, reverse= True)
full = [] + sortedFiles[:-1] + sortedFilesBackwards[:-1]
frames = [Image.open(image) for image in full]
frame_one = frames[0]
frame_one.save(f"{units}{fileName}.gif", format="GIF", append_images=frames,
save_all=True, duration=12000, loop=0)
但是,當我設置持續時間 = 360 000(毫秒 = 1 小時)時,我收到以下錯誤:
struct.error: ushort 格式要求 0 <= number <= (32767 *2 +1)
我在 macOS 上工作。
PS:我認為這與結構內的最大數據量有關?
持續時間是每幀顯示多長時間,以毫秒為單位,因此您需要將其設置為 1,000 每幀顯示一秒。
或者將其設置為 30,000,每幀顯示 30 秒,然后將幀數加倍。
保存 GIF 時設置 FPS 值 例如:
ani.save('animation.gif', fps=3)
您設置的值將延長或縮短您的 gif
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.