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_gifmethod with the VideoFileClip objectSyntax : 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
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.

