Site icon TechVidvan

Python GIF Creator – Convert Video to GIF

GIF Creator is an application that converts a video into gif. A gif is a video without audio and goes on into an infinite loop. python GIF creator project is a beginner level project which will need some libraries and little concepts of Python. So let’s create GIF using Python.

What is a GIF Creator?

A GIF Creator is an application that creates a GIF. This GIF is made through a video, an image or it can be an animation. Here in this project, we will be using a video and creating a GIF from it. The video is turned into an infinite loop without audio.

Python GIF Project Details

In this project, we will be building a GUI Window using Tkinter Module. In the window, there will be a browsing field from where the user will browse a video that needs to be converted into a GIF. There will be a Button which will convert the selected video into GIF.

We are going to use moviepy.editor library to make a gif using a video file.

Project Prerequisites

To create this project, we will have to install the following modules:

Download Python GIF Creator Code

Please download the source code of Python GIF Creator Project from the following link: GIF Creator Project Code

Steps to Create Python Project of GIF creation

Let’s have a look at the steps to create python gif creator.

  1. Importing the Required Libraries and Modules
  2. Creating GUI
  3. Browsing A Video File
  4. Creating the GIF

Let us look at each step in detail.

1. Importing the Required Libraries and Modules:

#import libraries
from moviepy.editor import *
from tkinter import *
import tkinter as tk

2. Creating the GUI:

window = Tk()#creating window
window.geometry('700x300')#geometry of window
window.title('TechVidvan')#title to window
Label(window,text="Let's make a GIF",font=('bold',20)).pack()#label
Label(window,text='Select a File').pack()
Button(window,text='Browse',command=browseFiles).pack()#button field
Button(window,text='Create a Gif').pack()#button field

3. Browsing a Video File

def browseFiles():
    global filepath
    filename = filedialog.askopenfilenames(title='select', filetypes=[
                    ("all video format", ".mov"),
                    ("all video format", ".flv"),
                    ("all video format", ".avi"),
                ])
    filepath=os.path.basename(filename)

4. Creating a GIF

def create_gif():
    clip = VideoFileClip(filepath)
    clip.write_gif("mygif.gif")#making a gif

VideoFileClip() – Using the VideoFileClip(), we load the video file that is saved in the filepath variable.

write_gif() – This takes in the video file and converts it into a gif.

Python GIF Creator Output

Summary

We have successfully created the video to GIF Creator Project using python with GUI. We have used the following two modules-

Now we can convert a video into a gif.

Exit mobile version