motioneye-project / motioneye

A web frontend for the motion daemon.
GNU General Public License v3.0
3.93k stars 653 forks source link

Saving to animated GIFs for email notifications #174

Closed sambul13 closed 8 years ago

sambul13 commented 8 years ago

AFAIK, no Linux package allows to save a series of motion detected jpegs to an animated GIF before attaching it to Email Notification. On Windows, only ContaCam can save and email small anim GIFs, while larger MP4 videos of motion detected events are stored locally or later uploaded to FTP server.

Emailing anim GIFs is much more suitable than a series of JPEG snapshots. Anim GIFs can be easily created with FFMpeg, ideally with a running Date & Time stamp overlay like in ContaCam.

At least two approaches can be use for that:

  1. Convert a series of JPEG snapshots to a small anim GIF like here. This thread may also help.
  2. Convert just captured and saved MP4 video to anim GIF like here. Higher quality can be achieved with this technique.

Once generated, the anim GIF can be sent by Motion with a notifiication email instead of JPEG images. In ContaCam similar emails usually received within 5-10 sec from a detection event. This will be a killer feature for MotionEye, distinguishing it from other surveillance packages.

ozett commented 8 years ago

maybe it can be done like the image-crop with imagemagick in the solution here:

https://github.com/ccrisan/motioneye/issues/179

sambul13 commented 8 years ago

Thanks for the useful hint. Ideally it should be possible to setup through motioneye webUI, but I'll try that approach too. ImageMagick is definitely a good tool to generate animated GIFs, however FFMpeg can also be used for that.

Another similar approach to generating animated GIFs would be generating both a full reso video of a motion detection event, and a small timelapse video of the same event. Then the timelapse video can be sent with email notification, while full video will be kept locally. Unfortunately, while Motion allows to generate both video types, it doesn't allow to do it in parallel, and such option is absent in motioneye as well.

Can someone suggest a small script that would do it? Also, would be nice if motioneye added such option to the webUI, since sending a series of still images or a large video with email notifications is not practical and has limited usability.

sambul13 commented 8 years ago

If an H264 cam can output 2 or more streams with different resolution like 720P and CIF/SIF(625) 352 × 288, it makes sense to use a low resolution stream for motion detection and email notification movies, and its high resolution stream for database recordings. Both audio:video recording types can be done by ffmpeg straight from the source without transcoding instead of using analyzed by Motion jpeg pictures for video recordings. IMHO its a much cleaner approach, and very low PC CPU taxing. I wonder if its possible to add such feature to motioneye, despite it riches beyond current Motion feature scope?

Besides, both H264 streams are directly supported for playback in browsers, so no transcoding for video monitoring will be required either. The only purpose of decoding the stream would be to analyze frames for signs of motion. Once detected, the source videos can be recorded until motion stops instead of encoding the decoded frames to MP4.

ccrisan commented 8 years ago

H264 support is on the way, through motion, however. I still need to find a fix for some Raspberry PI-related issues and recent ffmpeg versions. The GIF thing won't happen.

rexfm commented 8 years ago

I was able to get simple animated gifs working with this little hack: I installed "gifsicle" b/c it's way faster at generating gifs on the RPi and then added this one line command to the "File Storage" -> "Run a command" camera setting: ffmpeg -i %f -vf scale=320:-1 -r 1 -f image2pipe -vcodec gif - | gifsicle --delay=10 -O2 --multifile --loop - > %f.thumb

More details here: http://rex.fm/auto-generate-animated-gifs-from-security-camera-footage-with-motioneye-hack/

fireheadman commented 8 years ago

rexfm ... left you a comment on your site. I am on ver 0.32.2 (fresh build on jessie w/motioneye). Using your hack created the *.thumb, but I do not have animated gifs to see.

let me know if you have something to try and I will do it. I used to use plain-jane motion and had it email me after the video with the video attachment so I could pull it up on my phone quickly.... motioneye doesn't seem to have this option available... although the functionality in the forked motion pkg supports this behavior.

What I used to do with motion: Send an notification for motion detection (motioneye does this great) on_movie_start mutt -s 'Motion detected at Front Window' email@gmail.com After the movie was finished, I had it email me video... this also served as a method of getting it in the cloud should the camera be taken/stolen on_movie_end mutt -s 'Motion Video - FW' email@gmail.com -a %f

ccrisan I found something with your program that I didn't really like, was wondering if you could tighten up the security for /etc/motioneye/thread-1.conf.?? As any user, you can cat the file, which if notifications are enabled, you can easily gain the username/password of the email account (not really a good thing).... maybe chmod 600 for these files since root is running motion/motioneye out of the box? I did this on my system and restarted the process, was able to update the config from the GUI still, the perms also stayed after an update.