Python moviepy is a powerful library to operate video files. In this tutorial, we will introduce how to use it to convert a gif image to video (mp4 or avi).
Preliminary
You should use pip command to install python moviepy package first.
pip install moviepy
Load library
We should import moviepy in our python code.
import moviepy.editor as mp
Convert gif to video
We can use VideoFileClip object to convert a gif image to video
clip = mp.VideoFileClip("Awesome JavaScript Text Typing Animation Example - TyperJS.gif") clip.write_videofile("Awesome JavaScript Text Typing Animation Example - TyperJS.mp4") clip.write_videofile("Awesome JavaScript Text Typing Animation Example - TyperJS.avi", codec='libx264') clip.close()
In this example, we will convert a gif to .mp4 and .avi video file.