Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Python: Convert GIF To video(mp4)

Tags:

python

mp4

gif

I am trying to find some way for converting GIF to mp4 using Python or library. I didn't found any solution for it. I found a library for generating gifs from videos but not the other way round.

Can anyone please give me some information on how to do it.

like image 673
NaMo Avatar asked Nov 21 '16 17:11

NaMo


2 Answers

Try MoviePy:

import moviepy.editor as mp

clip = mp.VideoFileClip("mygif.gif")
clip.write_videofile("myvideo.mp4")

If you don't have MoviePY installed then first install it:

pip install MoviePy
like image 62
Taufiq Rahman Avatar answered Sep 29 '22 18:09

Taufiq Rahman


There are many ways to do this. Relatively simple way is to use ffmpeg. There are many python bindings. ffmpy is one of them. Please check here for the documentation. Basic example:

Installation:

pip install ffmpy

Usage:

>>> import ffmpy
>>> ff = ffmpy.FFmpeg(
...     inputs={'input.gif': None},
...     outputs={'output.mp4': None}
... )
>>> ff.run()

Again, there are many other ways to do this. Please find the related references here:

  1. https://unix.stackexchange.com/questions/40638/how-to-do-i-convert-an-animated-gif-to-an-mp4-or-mv4-on-the-command-line
  2. https://sonnguyen.ws/convert-gif-to-mp4-ubuntu/
  3. How to Convert animated .gif into .webm format in Python?
like image 33
PseudoAj Avatar answered Sep 29 '22 20:09

PseudoAj