0

I'm using moviepy.VideoClip.write_gif to produce some animated graphs over a varying parameter. I would like the gif to play once and then stop on the final frame. I've tried loop=1 and loop=False, both run without error but are still producing endlessly looping gif images. Any suggestions?

animation =mpy.VideoClip(make_frame_mpl, duration=5)
animation.write_gif(str(title)+".gif" , fps=20, loop = False )
FatyP33
  • 13
  • 5
  • Try loop=0 (see: https://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.write_gif) – Tom Jun 15 '17 at 19:11

1 Answers1

0

I had the same problem. After digging around, the looping parameter for imageio.save() is missing from the function declaration in the source code. I submitted an issue on moviepy's github page, but you can fix this your self by navigating to moviepy\video\is\gif_writers.py and replacing the declaration for write_gif_with_image_io() (lines 256-289) with the following:

def write_gif_with_image_io(clip, filename, fps=None, opt=0, loop=0,
                            colors=None, verbose=True):
    """
    Writes the gif with the Python library ImageIO (calls FreeImage).

    For the moment ImageIO is not installed with MoviePy. You need to install
    imageio (pip install imageio) to use this.

    Parameters
    -----------
    opt

    """

    if colors is None:
        colors=256

    if not IMAGEIO_FOUND:
      raise ImportError("Writing a gif with imageio requires ImageIO installed,"
                         " with e.g. 'pip install imageio'")

    if fps is None:
        fps = clip.fps

    quantizer = 0 if opt!= 0 else 'nq'
    writer = imageio.save(filename, duration=1.0/fps,
                          quantizer=quantizer, palettesize=colors, loop=loop)

    verbose_print(verbose, "\n[MoviePy] Building file %s with imageio\n"%filename)

    for frame in clip.iter_frames(fps=fps, progress_bar=True, dtype='uint8'):

        writer.append_data(frame)