2017-06-15 67 views
0

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

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

尝试循环= 0(参见:HTTPS ://zulko.github.io/moviepy/ref/VideoClip/VideoClip.html#moviepy.video.VideoClip.VideoClip.write_gif) – Tom

回答

0

我有同样的问题。在挖掘之后,源代码中的函数声明中缺少imageio.save()的循环参数。我提交moviepy的GitHub的页面上的问题,但你可以通过导航到moviepy\video\is\gif_writers.py并用以下替换为write_gif_with_image_io()(线256-289)的声明解决这个问题你自己:

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)