Convert GIF Image to Video (MP4, AVI) Using Python MoviePy: A Step Guide – Python Tutorial

By | October 8, 2020

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).

python convert gif to video - mp4 or avi using python moviepy

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.

Leave a Reply

Your email address will not be published. Required fields are marked *