问题
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:
- https://unix.stackexchange.com/questions/40638/how-to-do-i-convert-an-animated-gif-to-an-mp4-or-mv4-on-the-command-line
- https://sonnguyen.ws/convert-gif-to-mp4-ubuntu/
- 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