make-gif-from-video

Make GIFs from videos using Python

INTRODUCTION:

Hello, world… Here, I am going to show you how to create a GIF from a video using Python.

For this, we need a library called moviepy and tkinter.

“moviepy” is a Python library used for video editings like cuttings, video concatenations, title insertions, video compositing i.e., non-linear editing, video processing, and creation of custom effects.

And I am gonna use the tkinter library for accessing the video file easily.

“tkinter” is the standard Graphical User Interface (GUI) library for python. Python with tkinter results from the fast and easy way to create a GUI application.

In simple words, tkinter is the python interface to the Tcl/Tk GUI toolkit.

DISCLAIMER: 

This project is highly beginner-friendly and deep explanation …

This project is going to be crazy and can be completed in 4 lines of code…stay tuned…

PREREQUISITES:

PACKAGE INSTALLATION:

moviepy package depends on the python modules like Numpy, imageio, decorator, and tqdm which will be automatically installed during moviepy’s installation. The software FFMPEG will automatically download by the first use of moviepy.

To install the pip package use command (sudo) pip install package_name in the command prompt.

> pip install moviepy

Tkinter comes along when we install Python. Running python -m tkinter from the command line should open a window demonstrating a simple Tk interface, letting you know that tkinter is installed correctly on your system.

If not, tkinter can be installed using pip. The following command is run in the command prompt to install tkinter.

See also  Best No First Deposit Bonus Online Internet Casinos In The People 202

> pip install tkinter

We have successfully installed the moviepy and tkinter packages.

PACKAGE EXPLANATION:

1. For the project, we just need the method called VideoFileClip of the moviepy module…hence, we will directly import the VideoFileClip from the moviepy. editor.

from moviepy.editor import VideoFileClip

2. we will use askopenfilename method from the tkinter to access the video files easily.

from tkinter.filedialog import askopenfilename

3. VideoFileClip()

It is a method used to read the video file.

4. write_gif()

It is a method from moviepy to create the GIF.

Now, let’s Start the code…

CODE IMPLEMENTATION:

#importing the modules…

from moviepy.editor import VideoFileClip
from tkinter.filedialog import *

#This line asks You to open a file…

video = askopenfilename()

clip = VideoFileClip(video)

#gifname you want to save with…

iframe = input(“Enter the GIF name to be saved : “)

#this line used imageio to create gifs

clip.write_gif(gifname,fps=10)

Source Code:

Here is the complete source code of the project.

#importing the modules...

from moviepy.editor import VideoFileClip
from tkinter.filedialog import *

# This line asks You to open a file...
video = askopenfilename()

clip = VideoFileClip(video)

#gifname you want to save with...
gifname = input("Enter the GIF name to be saved : ") 

#this line used imageio to create gifs
clip.write_gif(gifname,fps=10)

Output:

Example Output:

I have downloaded a video file named video(.mp4) in the same directory and executed the program.

Look, at the file dialog from kinder to ask for the filename from the user.
After the selection of the video…the moviepy automatically generates the gif in the same directory.

Thanks for your visit…
Make sure you comment below for the projects you need..or more simple projects like this…

See also  URL Shortener using Python

Important Note:

Note that you can still improve this project implementation and make it even better by changing its properties

To know more about moviepy, refer to this link : moviepy · PyPI

Go to the documentation of the moviepy, learn about it, and start playing with it.
Happy Coding.

Leave a Comment

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

Ads Blocker Image Powered by Code Help Pro

Ads Blocker Detected!!!

we provide projects, courses, and other stuff for free. in order for running we use Google ads to make revenue. please disable adblocker to support us.