'How to make a 1-hour gif using Python?
I want to make an 1 hour - long gif which will consist of 60 frames.
I already have built a gif_making function using PIL:
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)
However, when I set the duration = 360 000 (milliseconds = 1 hour), I receive the following error:
struct.error: ushort format requires 0 <= number <= (32767 *2 +1)
I work on macOS.
P.S : I think it has something to do with the maximum amount of data within a struct ?
Solution 1:[1]
The duration is how long to display each frame for in milliseconds, so you need to set it to 1,000 for each frame to be displayed for a second.
Or set it to 30,000 for each frame to be displayed for 30 seconds and double up your frames.
Solution 2:[2]
Set FPS value when you saving your GIF For example:
ani.save('animation.gif', fps=3)
The value you set will lengthen or shorten your gif
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Mark Setchell |
| Solution 2 | Pitermaniak |
