Daily movie
Daily movie
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
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
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.
- 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
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
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 = 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)
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 = 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)
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
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
echo Video Created at $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mpg
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
Last edited by Dreded on Fri Dec 03, 2010 7:17 pm, edited 2 times in total.
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
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
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
to
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
Code: Select all
ffmpeg -f image2 -i $tmpdir/$MonitorId/img%06d.jpg -r 5 $PATHTOEVENTS/$MonitorId/$firstevent/$date-Daily.mpg
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
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
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
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.
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.
-
- Posts: 14
- Joined: Sat Feb 19, 2011 7:57 pm
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
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
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
- punch-card
- Posts: 39
- Joined: Thu Nov 25, 2010 10:29 pm
- Location: St Peters MO
Re: Daily movie
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
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
Mike