0

我正在使用 moviepy.VideoClip.write_gif 在不同的参数上生成一些动画图。我希望 gif 播放一次,然后在最后一帧停止。我试过 loop=1 和 loop=False,两者都运行没有错误,但仍在产生无限循环的 gif 图像。有什么建议么?

animation =mpy.VideoClip(make_frame_mpl, duration=5)
animation.write_gif(str(title)+".gif" , fps=20, loop = False )
4

1 回答 1

0

我有同样的问题。在挖掘之后,imageio.save()源代码中的函数声明中缺少循环参数。我在moviepy的github页面上提交了一个问题,但是您可以通过导航到(第256-289行)moviepy\video\is\gif_writers.py的声明并将其替换为以下内容来自行解决此问题:write_gif_with_image_io()

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)
于 2017-08-09T14:36:31.417 回答