Skip to content
Related Articles

Related Articles

MoviePy – Saving Video File as GIF

View Discussion
Improve Article
Save Article
  • Last Updated : 18 Aug, 2020

In this article we will see how we can save video file clip as GIF in MoviePy. MoviePy is a Python module for video editing, which can be used for basic operations on videos and GIF’s. Video is formed by the frames, combination of frames creates a video each frame is an individual image. The Graphics Interchange Format is a bitmap image format that was developed by a team at the online services provider CompuServe.

In order to do this we will use write_gif method with the VideoFileClip object

Syntax : clip.write_gif(name)

Argument : It takes string i.e file name as argument

Return : It returns None

Below is the implementation




# Import everything needed to edit video clips
from moviepy.editor import *
  
   
# loading video dsa gfg intro video
clip = VideoFileClip("dsa_geek.webm")
  
  
# getting only first 3 seconds
clip = clip.subclip(0, 3)
  
# saving video clip as gif
clip.write_gif("gfg_gif.gif")
  
# loading  gif
gif = VideoFileClip("gfg_gif.gif")
  
# showing gif
gif.ipython_display()

Output :

MoviePy - Building file gfg_gif.gif with imageio.
                                                                                                                       
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

                                                                                                                       
Moviepy - Done !
Moviepy - video ready __temp__.mp4

Another example




# Import everything needed to edit video clips
from moviepy.editor import *
  
# loading video gfg
clip = VideoFileClip("geeks.mp4")
  
# getting only first 3 seconds
clip = clip.subclip(0, 3)
  
# saving video clip as gif
clip.write_gif("intro_gif.gif")
  
# loading  gif
gif = VideoFileClip("intro_gif.gif")
  
# showing gif
gif.ipython_display()

Output :

MoviePy - Building file intro_gif.gif with imageio.
                                                                                                                       
Moviepy - Building video __temp__.mp4.
Moviepy - Writing video __temp__.mp4

                                                                                                                       
Moviepy - Done !
Moviepy - video ready __temp__.mp4

My Personal Notes arrow_drop_up
Recommended Articles
Page :

Start Your Coding Journey Now!