Create video for each event - placed in a common folder

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
Post Reply
Voltage54
Posts: 23
Joined: Sat Feb 21, 2009 1:35 am

Create video for each event - placed in a common folder

Post by Voltage54 »

Hi Guys,

Firstly... if anyone out there with the know how wants to improve what I've done, be my guest! I've spent a few weeks teaching myself how to use ubuntu just so I can get this great zoneminder program up and running (and I'm extremely impressed with it!).

Ok, what I've done:

Zoneminder will now create an avi each time an event is detected. It will place this avi in a pre-determined spot (say /media/videos) and rename the avi to include the camera id and time the file was created.

How to do it:
- Firstly, use the provided 'filter' option in the zoneminder web gui and create the following:

Image

- Edit zmvideo.pl (sudo updatedb && locate zmvideo.pl to find this file... it should be located in /usr/bin)
- sudo vim /usr/bin/zmvideo.pl (which will open zmvideo.pl in a text editor)
- type ":set number" and locate line number 324
- Replace this line with the following:

Code: Select all

my $command = ZM_PATH_FFMPEG." -y -r $frame_rate ".ZM_FFMPEG_INPUT_OPTIONS." -i %0".ZM_EVENT_IMAGE_DIGITS."d-capture.jpg -s $video_size ".ZM_FFMPEG_OUTPUT_OPTIONS." '/media/500gig/cctv_mpegs/$video_file' > ffmpeg.log 2>&1";
Where /media/500gig/cctv_mpegs/ is the folder you would like to copy the created videos to (I'm sure there are better ways to do this, however its the only way I know how :P)

- Save and exit the file
- cd $HOME && sudo vim RenameVideo (will create an empty text file)
- paste the following code in:

Code: Select all

#! /bin/bash

# Set this value to the zoneminder 'events' folder
EVENTS="/media/500gig/zoneminder/events"

# Set this to where the event videos are saved
MPEGS="/media/500gig/cctv_mpegs"

cd $MPEGS

for FILE in `find Event*`; do
    TIMESTAMP=`ls -l --time-style=+%Y-%m-%d-%H-%M-%S $FILE | cut -d' ' -f6`;
    NAME=`echo $FILE | cut -d'-' -f2`
    cd $EVENTS
    OWNER=`find * -type d | grep $NAME | cut -d'/' -f1`
    cd $MPEGS
    # 1 = camera 1, check the events folder for camera id
    if [ "$OWNER" = "1" ]; then
    CAMERA="CAMERA_1"
    # 2 = camera 2, check the events folder for camera id
    elif [ "$OWNER" = "2" ]
    then
    CAMERA="CAMERA_2"
    # 3 = camera 3, check the events folder for camera id
    elif [ "$OWNER" = "3" ]
    then
    CAMERA="CAMERA_3"
    # 4 = camera 4, check the events folder for camera id
    elif [ "$OWNER" = "4" ]
    then
    CAMERA="CAMERA_4"
    else
    echo "not associated with a camera"
    fi
    FILENAME=$TIMESTAMP"_"$CAMERA".avi"
    if [ `ps -A | grep ffmpeg | cut -d' ' -f12` = "ffmpeg" ]; then
    echo "ffmpeg encoding, will not rename $FILE at this time"
    else
    `mv $FILE $FILENAME`
    fi
done
- Exit and save this file,
- chmod +x RenameVideo (makes the file executable)
- sudo crontab -e
- add the following:

*/1 * * * * sudo $HOME/RenameVideo >/dev/null 2>&1

This will allow the RenameVideo script to check for video files each minute, renaming them as necessary. The script will need sudo access to run with appropriate permission therefore you also need to do the following (*NOTE, this will allow administrator permissions for this script, which may completely destroy your entire system... make sure you understand what you are trying before attemping the following):

- sudo visudo
- At the bottom, add "%username ALL=(ALL) NOPASSWD:/$HOME/RecordingVideo" (where username is your username)

With any luck, your script will work and the end result should look something like this:

mediabox@mediabox:/media/500gig/cctv_mpegs$ ls
2009-02-19-22-40-32_CAMERA_1.avi 2009-02-20-04-45-24_CAMERA_1.avi 2009-02-20-08-52-52_CAMERA_2.avi 2009-02-20-13-08-36_CAMERA_1.avi ... you get the idea :)

Now I can watch all motion created on any comp/xbmc setup in the house, all thanks to zoneminder!
Voltage54
Posts: 23
Joined: Sat Feb 21, 2009 1:35 am

Post by Voltage54 »

You may also want to check out http://www.zoneminder.com/forums/viewto ... 5439#55439 for a better way to do what I listed above :P
makaveli0129
Posts: 14
Joined: Sat Feb 19, 2011 7:57 pm

Post by makaveli0129 »

the picture of your filter does not show anything..... also what do you save the file as is it .sh????
Post Reply