Make Animated GIFs from Videos with HTML5
HTML5 Animated GIF Creator
Last time, I showed how to make screenshots of videos with HTML5 and now I will take that concept further by showing how to make animated GIFs from videos. You could send video frames to the server and use something like FFmpeg or ImageMagick to create the animated GIF but since I have recently stumbled upon this port of as3gif GIFPlayer to JS, I wanted to make this work completely on the client side. I will try to improve some processing with Web Workers but this will still be very CPU intensive.
I am passing objects to the web worker and the first one sets up the GIF encoder with the speed of the video and the “soon to be created” GIF image. This occurs as soon as you press the “start GIF frames” button which makes a postMessage to the worker and sets a flag that tells the HTML5 canvas drawing loop to start sending video frames to the worker. If a frame is sent, it gets added to the GIFencoder using the encoder.addFrame method.
When you press the “end GIF frames” button, the flag is set to false and no more frames are sent. Also, I send a an empty object to the worker to give it a signal to process the animated GIF. It converts the images from the video into a binary animated GIF file and I turn that binary into base 64 encoded data url. This gets sent back to the main script which places the data into a IMG tag. I wrapped the IMG tag around a link with a download attribute so that it is easy to download your generated GIF.
This is going to be quite heavy on the CPU and I have only tested in Chrome and Firefox. Here is the Online Animated GIF Generator.
Live Image Processing with getUserMedia and Web Workers
face to animated GIF
Searching Google specifically for Animated GIFs
CSS filters, GIFs, and performance
Face to GIF WebApp
GifWriter.js – GIF Encoder
gifify – Convert any video file to an optimized animated GIF