DEV Community

Cover image for Convert video to gif in python
Praveen Kumar
Praveen Kumar

Posted on

Convert video to gif in python

How to convert video file to gif format using Python programming language

  1. First install module
pip install MoviePy
Enter fullscreen mode Exit fullscreen mode
  1. Now Code the following
from moviepy.editor import *
clip = (VideoFileClip("./video1.mp4"))
clip.write_gif("output.gif")
Enter fullscreen mode Exit fullscreen mode

You can also trim the video from one part and then convert them into gif

from moviepy.editor import * 
clip = (VideoFileClip("./video1.mp4").subclip((0:00),(1:00)).resize(ACCORDING TO THE USER WISH)) 
clip.write_gif("output.gif")
Enter fullscreen mode Exit fullscreen mode

Thanks for Reading
Image 1
If you like this article please like and leave us an comment

Oldest comments (0)