Create your own GIFs

Create your own GIFs

Featured on Hashnode

Hello everyone,

After reading this blog article, you will be able to create your own GIFs from any videos. We will see the implementation through Python.

Let's get started!

What are GIFs?

giphy.gif

  • GRAPHICAL INTERCHANGE FORMAT(GIF), series of images of soundless videos that loops continuously that doesn't requires any press play button.
  • Also known as Animated Images.
  • GIFs are basically the compressed format of the video and they are used in places where very few colors are used, they are mostly used in logos as such. These gifs are compressed using lossless data compression in-order not to degrade the video quality.
  • GIFs are gaining popularity because, like memes, they’re useful for communicating jokes, emotions, and ideas. These services are integrated into apps like Twitter, and your phone’s keyboard, so they’re just as easy to use as emojis or “stickers.”.
  • To know more, visit GIF Wikipedia Page.

Module Used:

moviepy Module

MoviePy is a python module for video editing which can be used for basic operations such as cuts, concatenation, title insertion, video compositing, video processing and for adding advanced effects.

This module has got other cool features as well. Explore them by visiting the MoviePy Documentation.

Let's Start Coding

You can find all the code at my Github Repository.. Feel free to drop a star if you find it useful.

Firstly, install the module in your Python Environment by writing the below code in your Terminal/Command Prompt.

pip install moviepy

Whole Code Snippet

from moviepy.editor import *

#loading video
#Here for sample "myvideo.mp4" is being used. Modify it as per your need.
clip=VideoFileClip('myvideo.mp4')

#getting only 3 first seconds from video. Modify the time as per your need.
clip = clip.subclip(0,3)

#Saving video clip as gif
clip.write_gif('mygif.gif')

Step By Step Guide:

->Import the package in your python script. Use the command below:

from moviepy.editor import *

->Now, let's save our VideoClip in clip loaded in the same directory of your Python code.

clip=VideoFileClip('myvideo.mp4')

->Let's cut the clip, from 0-3seconds, change it as per your need.

clip = clip.subclip(0,3)

->Now, let's save our GIF in mygif.gif Don't forget to put the extension .gif

clip.write_gif('mygif.gif')

YAY! Your created your first own GIF.

SEE YOU IN MY NEXT BLOG. TAKE CARE!