Convert MP4 File to GIF with use of Python. ๐Ÿ

Python Tutorial Blog

ยท

2 min read

Convert MP4 File to GIF with use of Python. ๐Ÿ

Hello People,

In this Blog article, we will learn how convert MP4 file to GIF with just few lines of Python code using Moviepy module. It is a fun project to try and easy to understand.

This can be a useful technique if you want to share short video clips on social media with small file sizes.

Check out the Repository in python. Drop a star if you find it useful !!!

Video Tutorial:

You can watch my YouTube video Tutorial to see a working tutorial for better understanding and a step by step Guide to write a code.

Module Used in Code:

All you need is Moviepy python module.

MoviePy is a Python module for video editing, which can be used for basic operations (like cuts, concatenations, title insertions), video compositing, video processing, or to create advanced effects. It can read and write the most common video formats, including GIF.

Code time:

# use "pip install moviepy" to install Moviepy library.
# Import moviepy.editor
from moviepy.editor import *

# Taking video as an input which we want to convert in GIF.
video_input = VideoFileClip("Countdown.mp4")

# converting video file to GIF.
video_input.write_gif("output.gif")

As we can see in the code that first we import moviepy module and then take MP4 file as an input by using "VideoFileClip" Method.

and finally we convert this MP4 file to GIF by using "write.gif" method.

NOTE: here extension ".gif" is must .

That's all we have successfully convert MP4 file to GIF.

Thank you.

See you in my next Blog article, Take care!!

Dhruvin Gajjar.

TheCreators

Resources:

ย