Sunday, November 17, 2024
Google search engine
HomeLanguagesMoviePy – Saving Video File as GIF

MoviePy – Saving Video File as GIF

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("Lazyroar.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

Dominic Rubhabha-Wardslaus
Dominic Rubhabha-Wardslaushttp://wardslaus.com
infosec,malicious & dos attacks generator, boot rom exploit philanthropist , wild hacker , game developer,
RELATED ARTICLES

Most Popular

Recent Comments