Daily movie

Forum for questions and support relating to the 1.24.x releases only.
urge4vert
Posts: 9
Joined: Fri Dec 19, 2008 6:56 pm

Daily movie

Post by urge4vert »

I'm running Zoneminder 1.24.2, and I was wondering if the following is possible.

Currently I just have one camera, but might have a second one. I have one zone defined. Everything works, events are trigged, recorded, etc.

Its rare I want to go through each event and watch it. Is it possible to run a script and generate a movie (avi or whatever) of all the events of the entire day? Maybe even have this run automatically and email me. Then I can watch and see if there's any particular events I want to go back and review.

Thanks
User avatar
jdhar
Posts: 125
Joined: Fri Oct 01, 2010 9:15 pm
Location: California

Post by jdhar »

Probably a few different ways to do this, so I'd just offer mine..

- do a sql query to get the events that occured during whatever timeframe you wanted (ie: echo "select Id from Events where StartTime <your> " | mysql zm)
- For each of those event Ids, run ffmpeg -i <Id>/%03d-capture.jpg -vcodec mpeg4
- At the end of your script, you now have your events converted into mpeg4s. Combine them with ffmpeg or any other tool
- Stick that in a script and cron it for once daily

Looking at probably a 5-6 line script. I do'nt know of a way to do this out-of-box though.
eyeZm, Native iPhone App for ZoneMinder: http://www.eyezm.com

Version 1.3 now available on iTunes, introduces Montage view, HTTPS/SSL support and H264 native streaming!

Subscribe to RSS feed for updates: http://www.eyezm.com/rssfeed.xml
Dreded
Posts: 26
Joined: Fri Dec 03, 2010 1:33 am

Post by Dreded »

Just thought id help a bit more since very few people tend to know how to do a mysql query so the query you would need would be something along the lines of...

echo "select id from Events WHERE (StartTime BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 1 DAY ) AND CURDATE( )) order by id asc" | mysql -D zm -u zm --password=<YOURPASSWORD>

that would select all monitors and make one daily(of the day before) which would get quite hectic so I would recommend...

echo "select id from Events WHERE (StartTime BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 1 DAY ) AND CURDATE( )) AND (MonitorId = 8) order by id asc" | mysql -D zm -u zm --password=<YOURPASSWORD>

which does the same thing but for only one monitor(8 in this case)
Dreded
Posts: 26
Joined: Fri Dec 03, 2010 1:33 am

Post by Dreded »

Ok because im a nice guy i took 2min to write the whole script

Code: Select all

#!/bin/bash
MUSER="zm"
MPASS="PASSWORD"
MHOST="localhost"
MDB="zm"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"

EVENTS="$($MYSQL -D$MDB -u$MUSER -p$MPASS -Bse 'select id from Events WHERE (StartTime BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 1 DAY ) AND CURDATE( )) AND (MonitorId = 8) order by id asc')"

for event in ${EVENTS[@]}
do
ffmpeg -i $event/%03d-capture.jpg -vcodec mpeg4 
done
Dreded
Posts: 26
Joined: Fri Dec 03, 2010 1:33 am

Post by Dreded »

Ok so I took it a step further and made this... takes about 5min to make the daily video on my system which records 24/7

you must supply the MonitorId as an argument "./makevideo 4" would make a video of all the previous days events and then put it in the first event for that day so it can be retrieved via the webinterface under the first event of the days video section

Code: Select all

#!/bin/bash
MUSER="zm"
MPASS="PASSWORD"
MHOST="localhost"
MDB="zm"
MYSQL="$(which mysql)"
MYSQLDUMP="$(which mysqldump)"
PATHTOEVENTS="/var/www/zm/events"
MonitorId="$1"
tmpdir="/tmp"

if [ "$1" == "$null" ]
  then
    echo You Must Specify The Monitor ID i.e \'$0 4\' would specify monitor id 4
    exit
fi

EVENTS="$($MYSQL -D$MDB -u$MUSER -p$MPASS -Bse 'select id from Events WHERE (StartTime BETWEEN DATE_SUB( CURDATE( ) ,INTERVAL 1 DAY ) AND CURDATE( )) AND (MonitorId = '$MonitorId') order by id asc')"
mkdir $tmpdir/$MonitorId
x=1
for event in ${EVENTS[@]}
do
        if [ $x -eq 1 ]
          then
            mysqldate="$($MYSQL -D$MDB -u$MUSER -p$MPASS -Bse 'select StartTime from Events WHERE id = '$event'')"
            date=`date +%b%d-%Y --date="$mysqldate"`
            firstevent="$event"
            echo Making Images and Placing them in $tmpdir/$MonitorId .... Please Be Patient this could take a while.
        fi
          for i in $(ls -r -t $PATHTOEVENTS/$MonitorId/$event/*jpg)
          do counter=$(printf %06d $x)
            ln -s "$i" $tmpdir/$MonitorId/img"$counter".jpg
            x=$(($x+1))
          done
done

ffmpeg -f image2 -i $tmpdir/$MonitorId/img%06d.jpg $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mpg

rm -rf $tmpdir/$MonitorId
echo Video Created at $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mpg
Last edited by Dreded on Fri Dec 03, 2010 7:17 pm, edited 2 times in total.
User avatar
jdhar
Posts: 125
Joined: Fri Oct 01, 2010 9:15 pm
Location: California

Post by jdhar »

Good addition... I think this would be a good thing to integrate into the upstream, and make it configurable (ie: combine once every 'x' hours/days etc.., or combine once 'x' duration elapses). And also the option to replace the events with your combined one. A lot of useful examples for this really...
eyeZm, Native iPhone App for ZoneMinder: http://www.eyezm.com

Version 1.3 now available on iTunes, introduces Montage view, HTTPS/SSL support and H264 native streaming!

Subscribe to RSS feed for updates: http://www.eyezm.com/rssfeed.xml
Dreded
Posts: 26
Joined: Fri Dec 03, 2010 1:33 am

Post by Dreded »

as it turns out mpg can easily be combined with the command...

cat video1.mpg video2.mpg > video_both.mpg

so it would be quite simple to combine videos

ALSO I forgot to mention that with the above script nothing limits the FPS so on my cameras that actually do 5fps the video is made at the default 25fps which I actually prefer because then I can see all the daily events in high speed and if i need a specific frame could jut go to the rough area and go frame by frame

but if you wanted to make it adhere to say 5fps your could change

Code: Select all

ffmpeg -f image2 -i $tmpdir/$MonitorId/img%06d.jpg $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mpg 
to

Code: Select all

ffmpeg -f image2 -i $tmpdir/$MonitorId/img%06d.jpg -r 5 $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mpg 
Dreded
Posts: 26
Joined: Fri Dec 03, 2010 1:33 am

Post by Dreded »

I just wanted to make a quick note that I ran this on a computer that would be considered more "normal"(Dual-Core AMD 5200) and it took 90min to make a video with 24hours of continuous recording rather than the 5min it took my other system :p that said on the "normal" computer to do a video from the modect images with people constantly walking in front of the camera for at least 8hours of the day took about 2min or less
ketsu
Posts: 12
Joined: Mon Jan 12, 2009 5:43 am

Post by ketsu »

Worked great for me. I changed the paths to fit my needs, and it worked great.

It took about 200 megs of Jpegs, and make them an 80 meg vid. I really like the high speed playback too.

Thanks!
liderbugzm

Post by liderbugzm »

I wanted a time-lapse of the day.
Here's the way I did it. (didn't use ZM ... sorry)

A. a Bash script via crontab using */3 gives 1 frame every 3 min
curl -s http://mycamip/jpg/image.jpg > [subdir]/tl1$n.jpg where n=last n+1
and I also tried lt1$day$n.jpg n gets reset at midnight

B. cd subdir ; mencoder mf://*.jpg -mf w=800:h=600:fps=15:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -oac copy -o /var/www/html/bytl.avi
ketsu
Posts: 12
Joined: Mon Jan 12, 2009 5:43 am

Post by ketsu »

I wanted to check out a video not playing in fast forward, so I tried adding the -r 5 to the encoding command. It looks like 5 FPS is not a valid option for the Mpeg1/2 codec. I had H264 installed, so I changed my command to:

ffmpeg -f image2 -i $tmpdir/$MonitorId/img%06d.jpg -vcodec libx264 -r 5 -vpre normal -threads 0 $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mp4

And that worked for me.
makaveli0129
Posts: 14
Joined: Sat Feb 19, 2011 7:57 pm

Post by makaveli0129 »

script works great thanks!!!

I was wondering though once the video is created how could i have it delete the events from the folder and the database???

i also edited /etc/crontab to include the following lines so that every day it automatically runs the script at 1210 am for monitor 1 and 1215 am for monitor 2.

10 00 */1 * * jr /home/jr/test.sh 1
15 00 */1 * * jr /home/jr/test.sh 2
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

Looks like this script doesn't work for the deep filesystem!!!
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

Unless You do this...

Code: Select all

fi
          for i in $(ls -r -t $PATHTOEVENTS/$MonitorId/$(TZ=EST24EDT date +%y/%m/%d)/.$event/*jpg)
          do counter=$(printf %06d $x)
            ln -s "$i" $tmpdir/$MonitorId/img"$counter".jpg
            x=$(($x+1))
          done
User avatar
punch-card
Posts: 39
Joined: Thu Nov 25, 2010 10:29 pm
Location: St Peters MO

Re: Daily movie

Post by punch-card »

The is a slight error in the script(line 30) if you record at a higher frame rate because the "t" switch in ls of the files as the same time and orders them reverse alphabetically for the same time stamp.
I noticed this when the mpg was jumping back and forth...

$ ls -r -t $PATHTOEVENTS/$MonitorId/$event/*jpg
. . . /events/2/90949/008-capture.jpg
. . . /events/2/90949/007-capture.jpg
. . . /events/2/90949/006-capture.jpg
. . . /events/2/90949/005-capture.jpg
. . . /events/2/90949/004-capture.jpg
. . . /events/2/90949/003-capture.jpg
. . . /events/2/90949/002-capture.jpg
. . . /events/2/90949/001-capture.jpg
. . . /events/2/90949/026-capture.jpg
. . . /events/2/90949/025-capture.jpg
. . . /events/2/90949/024-capture.jpg
. . . /events/2/90949/023-capture.jpg
. . . /events/2/90949/022-capture.jpg
. . . /events/2/90949/021-capture.jpg
. . . /events/2/90949/020-capture.jpg
. . . /events/2/90949/019-capture.jpg
. . . /events/2/90949/018-capture.jpg
. . . /events/2/90949/017-capture.jpg
. . . /events/2/90949/016-capture.jpg
. . . /events/2/90949/015-capture.jpg
. . . /events/2/90949/014-capture.jpg

Because the files should naturally order with ls as long as you have the same number of numerical digits in the file name it should alphabetically correctly order. As follows:

$ ls $PATHTOEVENTS/$MonitorId/$event/*jpg
. . . /events/2/90949/001-capture.jpg
. . . /events/2/90949/002-capture.jpg
. . . /events/2/90949/003-capture.jpg
. . . /events/2/90949/004-capture.jpg
. . . /events/2/90949/005-capture.jpg
. . . /events/2/90949/006-capture.jpg
. . . /events/2/90949/007-capture.jpg
. . . /events/2/90949/008-capture.jpg
. . . /events/2/90949/009-capture.jpg
. . . /events/2/90949/010-capture.jpg
. . . /events/2/90949/011-capture.jpg
. . . /events/2/90949/012-capture.jpg
. . . /events/2/90949/013-capture.jpg
. . . /events/2/90949/014-capture.jpg
. . . /events/2/90949/015-capture.jpg
. . . /events/2/90949/016-capture.jpg
. . . /events/2/90949/017-capture.jpg
. . . /events/2/90949/018-capture.jpg
. . . /events/2/90949/019-capture.jpg
. . . /events/2/90949/020-capture.jpg
. . . /events/2/90949/021-capture.jpg
. . . /events/2/90949/022-capture.jpg
. . . /events/2/90949/023-capture.jpg
. . . /events/2/90949/024-capture.jpg
. . . /events/2/90949/025-capture.jpg
. . . /events/2/90949/026-capture.jpg
. . . /events/2/90949/027-capture.jpg
Best Regards
Mike
Locked