Home > Back-end >  How to make a 1-hour gif using Python?
How to make a 1-hour gif using Python?

Time:05-02

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 ?

CodePudding user response:

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.

CodePudding user response:

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

  • Related