1

It's easy to do a gif with the imageio module like this:

import imageio
imageio.mimsave(path_gif_out, paths_pngs_in, fps=2)

But is it possible to change the frame rate of the individual frames? For example I would like the last frame rate to appear longer; e.g. fps=0.2.

tommy.carstensen
  • 8,962
  • 15
  • 65
  • 108

1 Answers1

4

The documentation for the GIF-PIL format states that the parameter duration can be used to individually set the time each frame remains in view.

"duration : {float, list} The duration (in seconds) of each frame. Either specify one value that is used for all frames, or one value for each frame. Note that in the GIF format the duration/delay is expressed in hundredths of a second, which limits the precision of the duration."

If duration is not used, each frame gets a 1/fps duration as the fps parameter description says:

"fps : float The number of frames per second. If duration is not given, the duration for each frame is set to 1/fps. Default 10."

Link to the imageio library documentation: https://imageio.readthedocs.io/en/stable/format_gif-pil.html#parameters-for-saving

Mr K.
  • 1,064
  • 3
  • 19
  • 22
  • Thanks @Mr. K. for the answer it's helping me, but I have a question: so I must set fps OR duration, meaning that it has no case to use both, for example, for a given set of 100 images or frames, setting fps to 10 frames per seconds would result on a 10 seconds GIF. On the other side setting duration to 2 seconds per frame, would result on a 200 seconds GIF, so, adding both parameters, which result would throw? – Moisés Briseño Estrello Jul 28 '22 at 02:15
  • 1
    Duration can take either one float or a list of floats that let's you set the individual duration in seconds by frame as the post states. So you can freely set the duration of each frame separately. Hope this helps! – Mr K. Jul 28 '22 at 07:33