Python: Convert GIF To video(mp4)

那年仲夏 提交于 2020-12-29 09:39:04

问题


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.


回答1:


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



回答2:


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?



回答3:


from moviepy.editor import *

clip = (VideoFileClip("VIDEO.mp4")
        .subclip((1,22.65),(1,23.2))
        .resize(0.3))
clip.write_gif("nAME_OF_gif_FILE.gif")

You can download Video with this command if you have Youtube-dl installed:



来源:https://stackoverflow.com/questions/40726502/python-convert-gif-to-videomp4

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!