How to Convert animated .gif into .webm format in Python?

喜欢而已 提交于 2019-12-24 03:25:59

问题


I have a web application built on Django where images and animated Gif can be uploaded. However GIF takes long time to load. I was thinking of converting all uploaded gif into webm format and show it on the frontend using HTML5 video tag. I searched a lot for doing this in Python but could not find specific solution. I found this solution. But I want to know is it possible to convert gif into webm while uploading in python or is there any library in python from which this conversion can be accomplished?.


回答1:


With MoviePy:

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

You can also use any other format (mp4, ogv, etc) and add parameters like bitrate='5000k' or any other parameter supported by FFMPEG. You can also use ffmpeg directly for the conversion instead of moviepy, it will be slightly faster.



来源:https://stackoverflow.com/questions/30620186/how-to-convert-animated-gif-into-webm-format-in-python

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