问题描述
我有一个基于Django构建的Web应用程序,可以上传图像和动画Gif。不过GIF需要很长时间才能加载。我正在考虑将所有上传的gif转换成webm格式,并使用HTML5视频标签在前端显示。我在Python中搜索了很多,但找不到具体的解决方案。我发现解决方案。但是我想知道在python中上传或者是否有任何可以实现这种转换的python库,是否可能将gif转换成webm?
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?.
推荐答案
:
import moviepy.editor as mp
clip = mp.VideoFileClip("mygif.gif")
clip.write_videofile("myvideo.webm")
您还可以使用任何其他格式(mp4,ogv等),并添加像bitrate ='5000k'或FFMPEG支持的任何其他参数。您也可以直接使用ffmpeg进行转换,而不是moviepy,它会稍快一些。
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.
这篇关于如何将动画的.gif转换为.webm格式的Python?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!