2017-06-15 69 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)