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?.
Asked
Active
Viewed 5,164 times
2
-
1How is a _gif_ (image) takes more time to load than _webm_ (video)? The problem is definitely somewhere else. Are these animated gifs or something? – ivan_pozdeev Jun 03 '15 at 12:54
-
Yes these are animated gif. Sorry I forgot to mention. I have edited the question. Thanks – Ameer Khan Jun 03 '15 at 12:58
-
possible duplicate of [How can I convert a series of images to a valid HTML5 video](http://stackoverflow.com/questions/20033744/how-can-i-convert-a-series-of-images-to-a-valid-html5-video) – ivan_pozdeev Jun 03 '15 at 14:02
-
possible duplicate of [Can FFmpeg be used as a library, instead of a standalone program?](http://stackoverflow.com/questions/2401764/can-ffmpeg-be-used-as-a-library-instead-of-a-standalone-program) – ivan_pozdeev Jun 03 '15 at 19:31
1 Answers
11
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.

Zulko
- 3,540
- 1
- 22
- 18
-
Any way to get a streamable output, as in yielding chunks of the file, instead of waiting for it to finish first? Like this one, but with video: https://stackoverflow.com/a/5147454/3423324 – luckydonald Dec 29 '17 at 11:59
-
Asked [as a question here](https://stackoverflow.com/q/48022490/3423324) – luckydonald Dec 29 '17 at 12:17