Auto-generate animated GIFs from security camera footage with MotionEye hack

So I’ve set up several raspberry-pi based cameras around the house using MotionEye software ( ), and integrated it very simply with the smart-home software I’m developing for my startup to send near-instant notifications via our Google Hangouts chatbot. While it’s nice to get instantly notified of motion at the front door while I’m working upstairs in my office (so I can know when packages arrive!), sometimes I get false-postives from wind blowing the trees and things like that. And it takes a bit of time to load the built-in web interface and play back video clips. So I set out to find a way to create animated .gif files from recorded motion videos. I was able to get it working with a surprisingly easy hack.



This solution has a single added dependency which is “gifsicle” (it’s much faster than ImageMagick on the Raspberry Pi. Found here: ) which you can easily install on Raspbian via:

sudo apt-get install gifsicle

And then, the only remaining setup is to add this one-liner (!) to your MotionEye camera settings, under “File Storage” -> “Run a command”:

ffmpeg -i %f -vf scale=320:-1 -r 1 -f image2pipe -vcodec gif - | gifsicle --delay=10 -O2 --multifile --loop - > %f.thumb

(substitute “ffmpeg” with “avconv” for your setup if necessary)

Finally, make sure you have “Movies” and “Motion Detection” enabled for your camera as well.

Now when a new movie is saved, that command will automatically generate an animated GIF within a few seconds, and give it the same filename as the thumbnail previews that are normally generated on-demand when you open the playback option in the MotionEye web app. Unfortunately the downscaling method they’re using under the hood doesn’t handle animated GIFs properly, so in the interface it will look like this:

Screen Shot 2016-07-13 at 2.58.40 PM

But when you click on a recorded event you will see the full animated GIF play immediately, and you can use the left and right navigation buttons to instantly scroll through the GIFs of all your recorded events!

Screen Shot 2016-07-13 at 2.59.31 PM

Note: if you load the playback pane before the GIF has finished being generated, the default behavior of the web app will still generate a static thumbnail, possibly preventing the GIF file creation altogether. An alternative method would be to ouput the gif files to a different filename, and design your own interface for viewing them separately. Or, modifying the MotionEye interface to not generate the thumbnails, but I haven’t looked into that yet.

2 thoughts on “Auto-generate animated GIFs from security camera footage with MotionEye hack

  • followed this on a fresh build of jessie with motioneye. I see my *.thumb pics, but they are not animated as you say they should be. version of motioneye is 0.32.2

Leave a Reply

Your email address will not be published. Required fields are marked *