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.