2016-11-21 221 views
3

我想找到一些方法來使用Python或庫將GIF轉換爲mp4。我沒有找到任何解決方案。我找到了一個用於從視頻中生成GIF的庫,但沒有其他方法。Python:轉換GIF到視頻(mp4)

任何人都可以請給我一些關於如何做到這一點的信息。

+0

你看過ffmpy嗎? https://pypi.python.org/pypi/ffmpy –

回答

3

Python的嘗試MoviePy:

import moviepy.editor as mp 
clip = mp.VideoFileClip("mygif.gif") 
clip.write_videofile("myvideo.mp4") 

如果你沒有MoviePY裝則先安裝它:

pip install MoviePy 
1

有很多方法可以做到這一點。相對簡單的方法是使用ffmpeg。有很多python綁定。 ffmpy就是其中之一。有關文檔,請檢查here。基本例如:

安裝:

pip install ffmpy 

用法:

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

同樣,也有很多其他的方法可以做到這一點。請在這裏找到相關文獻:

  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?
0
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") 

您可以下載視頻使用此命令,如果您有YouTube的DL安裝:

0

感謝pseudoAj ...我使用了代碼t o做相反的事

>>> ff = ffmpy.FFmpeg(
...  inputs = {"cash.mp4": None}, 
...  outputs = {"cash.gif": None} 
...) 
>>> ff.run()