Page 1 of 2

Daily alarm events video script

Posted: Mon Sep 26, 2011 8:03 pm
by nightcrawler
I found an script for making an video file out off JPEG files.
This script makes an video file from every event within the last 24 hours. it's sorted by monitor name and offcourse also by time.
It's original is not from me but I alter it for zoneminder 1.25.0 and Ubuntu 11 server.

So here's and small explanation for the script
<<<Look at the last postings for modifications and the file!>>>

Step 1: make an parameter for all of the active monitors that has events:

Code: Select all

# Enumerate existing ZoneMinder Monitors
cameraname=(`ls /var/www/zm/events/ | grep '[a-zA-Z]'`)
cameraList=(`ls /var/www/zm/events/ | grep '[0-9]'`)
cameraNum=${#cameraList[@]}
eventsFolder=/var/www/zm/events/

echo Number of detected ZoneMinder Monitors: ${#cameraList[@]}

# Start working through all detected ZoneMinder Monitors
	# The camera's get the name from the directory symlink on alphanumeric order!
	# Alter every parameter entry BELOW THIS LINE called {cameraname[$i]} to ${cameralist[$i]} if you don't want this.

 for (( i=0; i<${cameraNum}; i++ ));
 do
  echo Doing ZoneMinder Monitor: ${cameraname[$i]}
Step 2: The events are located with the linux FIND command and sorted with the SORT command

Code: Select all

# Get a list of images for the last 24 hours from each of the detected ZoneMinder Monitors.
  find   $eventsFolder${cameraList[$i]}  -mtime -1 -name \*capture.jpg > /tmp/alarmvideos/${cameraname[$i]}.list

# Sort output file for a consistent movie
 sort /tmp/alarmvideos/${cameraList[$i]}.list -n -o /tmp/alarmvideos/${cameraList[$i]}-sorted.list
Step 3: encode all evens into an movie file with memcoder. Linux memcoder is an part of the linux mplayer project.
Memcoder has an load of options. This string (default) wil make an avi file with an screensize from 640*480 and no audio

Code: Select all

# Encode each 24hr events into a movie Mpeg4 (edit with&hight and path for your cam settings)
mencoder mf://@/tmp/alarmvideos/${cameraname[$i]}-sorted.list  -mf w=640:h=480:fps=5:type=jpg -ovc lavc -lavcopts vcodec=mpeg4 -ofps 5 -oac copy -o /tmp/alarmvideos/`date +%d`-${cameraname[$i]}.avi
Step 4: place them to an storage directory and clean the temp files

Code: Select all

# create directory for year and month (if it's nog existing)
mkdir -p /YOURARCHIVEDIRECTORY/images/videos/`date +%Y`/`date +%m`/

# Find avi's with actual events-move to new dir
cd /tmp/alarmvideos
find *.avi -size +5k -exec mv {} /YOURARCHIVEDIRECTORY/images/videos/`date +%Y`/`date +%m` \;

Howto install:
  • * unzip the file
    * rename the file from .txt to an .sh extension
    * upload the file and create an directory on your linux server (like /usr/scripts)
    * edit the paths of your zoneminder events. (default in script : /var/www/zm/events )
    * edit encoder format settings to your own preferences. (default = mpeg4, 640x480, 5 frames/sec)

Re: Daily alarm events video script

Posted: Mon Sep 26, 2011 8:15 pm
by nightcrawler
I've got one small problem with my own script. and I hope that someone of you can help me with it:

I use the common linux FIND and SORT commands to make an sorted event list.

Code: Select all

  find $eventsFolder${cameraList[$i]} -follow  -mtime -1 -name \*capture.jpg > /tmp/alarmvideos/${cameraList[$i]}.list
I have to include the -follow option to get an result in the output file. the -follow option follows symlinks in the event path.
But it also makes an double / repeated entry in the output file. so every jpg is 2 times in the output. the first output is the "hardlink" to the capture file
the second output is the "./" symlink to the same capture file.

here is an example of 5 captured frames:

Code: Select all

/var/www/zm/events/Oprit/11/09/26/05/12/30/001-capture.jpg
/var/www/zm/events/Oprit/11/09/26/05/12/30/002-capture.jpg
/var/www/zm/events/Oprit/11/09/26/05/12/30/003-capture.jpg
/var/www/zm/events/Oprit/11/09/26/05/12/30/004-capture.jpg
/var/www/zm/events/Oprit/11/09/26/05/12/30/005-capture.jpg

/var/www/zm/events/Oprit/11/09/26/.680/001-capture.jpg
/var/www/zm/events/Oprit/11/09/26/.680/002-capture.jpg
/var/www/zm/events/Oprit/11/09/26/.680/003-capture.jpg
/var/www/zm/events/Oprit/11/09/26/.680/004-capture.jpg
/var/www/zm/events/Oprit/11/09/26/.680/005-capture.jpg

You can see the entry from 11/09/26 at 05:12:30 hour but it's also with an .680 (the event number) as an symlink in the event directory.
image: Image

I can't get the symlinks that points to the same files out of the sorted list. Does anybody knows an good FIND or SORT command option to get it right?
I played with -prune , -type f and -noleaf options but no luck so far...

Re: Daily alarm events video script

Posted: Thu Oct 27, 2011 5:46 am
by ddalton
This script is great but I notice that a frame keeps repeating... I am not sure why? the frame is only listed once? Is this a symlink or sort error? I removed the mtime option because I want to make all images into videos

Regards,
Doug

Re: Daily alarm events video script

Posted: Mon Nov 14, 2011 7:59 pm
by nightcrawler
:wink: BUMP :wink:

Does anybody know what's "wrong" with the linux FIND option in this script? It repeats every frame 1 time. I think it has to do something with the Symlinks links in the event directory.

I googled a lot to get it right..but now luck... :evil:

Re: Daily alarm events video script

Posted: Thu Nov 17, 2011 9:33 pm
by nightcrawler
Well people,

I've fixed the script! :D !

24HR alarm video 1.5.zip
New version of the orginal script. bug fixed and new features.
(1.19 KiB) Downloaded 396 times
The problem with the duplicated video entries is solved. It was an problem within the first line of the script. the list and GREP command was looking for alphanumeric names. but the camera's has nummeric directories. So I made some changes.

1) The $cameraname is found by looking in the events directory to directories with an alphacharacter name (like "door", garden etc).
2) the $cameralist is found by looking to nummeric names (like 1,2,3 etc)
3) Alter the FIND command to go to the nummeric directory from an camera and search from that point to events within the past 24 hours.
4) The sorting of events is now local time zone and region specific. It auto change to the right zone of your site.

--------
But there is more good news, I also made some improvements in the mencoder options it's a bit faster now.
and I made nice feature for the Archive directory. The files are storaged in an "year" directory and "month" directory beneath that.
It will auto expand and make new dirs every year and month!
Example:

Code: Select all

cd
--2011 (year)
  |----1 (month)
          --1_Door.avi
          --2_Door.avi
          --........
......................
And the last change is the fact that the temp directory (/tmp/alarmvideos) is checkt and created.

Re: Daily alarm events video script

Posted: Wed Nov 23, 2011 12:36 am
by ddalton
Does anyone have this script working... the sort is wrong so it puts an old frame in out of order, making a very jump video.... how can the sort be done so that it is by maybe file date?

Re: Daily alarm events video script

Posted: Mon Dec 05, 2011 2:45 pm
by nightcrawler
ddalton wrote:Does anyone have this script working... the sort is wrong so it puts an old frame in out of order, making a very jump video.... how can the sort be done so that it is by maybe file date?
That's some basic linux commands. look at these (commented!) lines from the script:

# Sort output file for a consistent movie

Code: Select all

sort /tmp/alarmvideos/${cameraname[$i]}.list -n -o /tmp/alarmvideos/${cameraname[$i]}-sorted.list
I've used the basic SORT -n function from the linux bash!. (look at the man page: http://linux.about.com/library/cmd/blcmdl1_sort.htm) there is an order by an compare according to string numerical values in my script. So it's just an order to number function. The second step is order the complete list to directory order, the linux SORT -d command fixed that. and the SORT -o options put's it to an text file cameraname.list (like "door.list")

# use local time settings to order the events right.

Code: Select all

LC_ALL=C sort /tmp/alarmvideos/${cameraname[$i]}.list -d -o /tmp/alarmvideos/${cameraname[$i]}-sorted.list
*** WARNING :The locale specified by the environment affects sort order. I have set the LC_ALL=C option to get the traditional sort order that uses native byte values. ***

** WARNING 2: use the zoneminder option: USE_DEEP_STORAGE > Use a deep filesystem hierarchy for events: from the options>path menu in zoneminder to set the events capture right. and if you changed the DIR_EVENTS option to an other directory path or name you have to change te /var/www/zm/events/ strings in the script***

My sugestions are :
  • look at the zoneminder USE_DEEP_STORAGE option is it set to "ON"? if not set it ON and restart ZM.
  • Go to your event directory and check if your events have an name like my examples (/var/www/zm/events/Oprit/11/09/26/05/12/30/001-capture.jpg)
  • Disable the second SORT line (LC ALL=C ....) and the cleanup line: rm -rf /tmp/alarmvideos/*.list check if it fixed your sorting. you can open the camername.list file at /tmp/alarmvideos directory with an text viewer.
  • If it's not fixed, remove the LC ALL=C command from the script
  • Still not working yet? post and example or upload an .LIST file and your edited script so I can take an look at it.

Re: Daily alarm events video script

Posted: Thu Dec 08, 2011 3:12 am
by ddalton
I have tried all the sort commands but I cannot prevent the error below if you look at 104 and 105?

/var/www/html/zm/events/1/11/09/29/11/50/00/1039-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/104-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1040-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1041-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1042-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1043-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1044-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1045-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1046-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1047-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1048-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1049-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/105-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1050-capture.jpg
/var/www/html/zm/events/1/11/09/29/11/50/00/1051-capture.jpg

Re: Daily alarm events video script

Posted: Fri Dec 09, 2011 9:36 am
by nightcrawler
Ok that's an sorting issue with events that has more than 1000 frames. My cam's have a max of 5 FPS (frames/second) so an single event of more than 200 seconds (3.3 minute) isn't show often. But If you have an very high frame-rate like 20 FPS will show within 50 seconds.

The way to get rid of this problem is to get an sorting at the first part of the JPG name. XXXX-camera.jpg.
But there is one problem, the capture name has to have an seperator like 'space' or comma ',' to it. The basic configuration of ZM doesn't have an feature to change the name of the JPG file so we have to work with an extra command like RENAME or SED to rename the files in the sortlist from the script. (only in the sort list. not the real file!)

next week, I will make an example on my zoneminder system and test it.

Re: Daily alarm events video script

Posted: Mon Dec 12, 2011 6:33 pm
by zSeries
Suggestions. 1) ask the developers to zero pad the filename. This is basic common sense to anyone who has done serious IT work for the last 40 years, ok that includes me......2) I haven't seen the script but I am working on a bulk email and ftp script using "ls" to get a list of file, there is a sort by mod-date option which solves the filename sort. Works ok with default filenames (not deep).

Re: Daily alarm events video script

Posted: Sat Dec 17, 2011 2:57 pm
by pete_c
Nightcrawler,

Looking to shift the videos over to an NMT or NAS for viewing on the multiple NMTs in the house.

Are you doing anything similiar? Are you running a cron job to do the videos every night?

The goal of said endeavor is multiple touchscreen viewing of any videos available.

Currently playing with VLC on Linux or Wintel Touchscreens. Trying to keep a one for all type configuration.

I'm currently fine with the single/multiple ZM live views from the touchscreens. It would be nice though to do something similiar with archival views.

Re: Daily alarm events video script

Posted: Mon Dec 19, 2011 6:52 pm
by nightcrawler
Hello Pierre C, :wink:

I'm uploading the dailyvids to an (netgear) NAS every night by running an CRON job (made with webmin 1.75) and running it every morning at 8AM.
Not from 24H to 24H the next day because most events are happening in the Night.
  • open webmin and make an CRON job
  • sign the path to your script (like: /usr/scripts/zm_24H_alarm_vid.sh)
  • use this input command: !/bin/bash
  • set the time schedule
  • Save and run an test job
I also made an SAMBA share on the zoneminder server for access to the output directory. And the NAS is running a schedule job to move the event movie to an public share directory on the NAS drive. (You can probably also made an LINUX mount to the NAS from Zoneminder, but I had a struggle with user read-write rights...)

But how did you managed to get an live view from the cam's to the videolan player??

Re: Daily alarm events video script

Posted: Wed Jan 04, 2012 1:07 am
by wollo
Pierre, I've mounted a nfs share from my nas on my zoneminder box then just set that as the archive directory in the script. If you want some help with that just post here

Bill.

Re: Daily alarm events video script

Posted: Thu Jan 12, 2012 10:11 pm
by csisek
Sorry for my english
I have ZM 1.24.2 and NOT list /var/www/zm/events

What is my mistake??
Thanks

Carlos
Pergamino-Argentina

Re: Daily alarm events video script

Posted: Fri Jan 13, 2012 6:14 am
by PacoLM
csisek wrote: I have ZM 1.24.2 and NOT list /var/www/zm/events
Look in /usr/share/zoneminder/events