So I’ve set up several raspberry-pi based cameras around the house using MotionEye software ( https://github.com/ccrisan/motioneye ), 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: https://www.lcdf.org/gifsicle/ ) 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:
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!
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.