I found a php script here: http://www.zoneminder.com/forums/viewtopic.php?t=13868
But I can't run it, so I decided to make a simple bash script without mysql connection.
This is my first complex script, I hope it works fine! Tested in Ubuntu Karmic and ZM 1.24.2
Code: Select all
#!/bin/bash
# Use this script for creating one video-file per day for ZoneMinder
# created by TrendKill
# Main Configuration
MOVIEDATE="2009-11-07" # Use the same format as what you see in 'ls -all --time-style=long-iso'
MONITOR="1"
FPS="10"
# Paths
ZM_EVENTS_DIR="/usr/share/zoneminder/events/"
TEMP_DIR="/tmp"
VIDEO_OUTPUT_DIR="/var/www"
FFMPEG="/usr/bin/ffmpeg"
# Check directories and files
if [ -d $ZM_EVENTS_DIR ]
then
echo "Found ZM Events Directory: $ZM_EVENTS_DIR -> OK!"
else
echo "ZM Events Directory not found, exiting!"
exit 1
fi
if [ -d $VIDEO_OUTPUT_DIR ]
then
echo "Found Video Output Directory: $VIDEO_OUTPUT_DIR -> OK!"
else
echo "Video Output Directory not found, exiting!"
exit 1
fi
if [ -d $ZM_EVENTS_DIR/$MONITOR ]
then
echo "Found Monitor: $MONITOR -> OK!"
else
echo "Monitor $MONITOR not found, exiting!"
exit 1
fi
ISDATEAVAILABLE=`ls $ZM_EVENTS_DIR/$MONITOR/ -Al --time-style=long-iso |grep -l $MOVIEDATE`
if [ -z "$ISDATEAVAILABLE" ]
then
echo "The requested day - $MOVIEDATE - not found, exiting!"
exit 1
else
echo "Found requested day: $MOVIEDATE -> OK!"
fi
if [ -f $FFMPEG ]
then
echo "Found FFmpeg binary: $FFMPEG -> OK!"
else
echo "FFmpeg not found, exiting!"
exit 1
fi
if [ -f $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR.list ]
then
echo "Purging previous temorary file: $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR.list"
rm $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR.list
fi
if [ -d $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR ]
then
echo "Purging previous temporary symblinks from $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR"
rm $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR/*
else
mkdir -p $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR
fi
# Collecting wanted event files
echo -n "Processing wanted events..."
/bin/ls $ZM_EVENTS_DIR/$MONITOR -Al --time-style=long-iso |grep $MOVIEDATE|awk '{ print $8 }'|sort -n > $TEMP_DIR/events.$MOVIEDATE--Monitor-$MONITOR.list
while read EVENT
do
/bin/ls $ZM_EVENTS_DIR/$MONITOR/$EVENT/*capture.jpg >> $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR.list
done <$TEMP_DIR/events.$MOVIEDATE--Monitor-$MONITOR.list
EVENTNUMBER=1
while read EVENTFILE
do
EVENTNUMBERPADDING=`seq -f %09.f $EVENTNUMBER $EVENTNUMBER`
/bin/ln -s $EVENTFILE $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR/$EVENTNUMBERPADDING.jpg
let "EVENTNUMBER = $EVENTNUMBER + 1"
done <$TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR.list
echo "...$EVENTNUMBER events found"
# Building a video
echo -n "Building video: $VIDEO_OUTPUT_DIR/$MOVIEDATE--Monitor-$MONITOR.avi"
$FFMPEG -y -f image2 -i $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR/%09d.jpg -r $FPS -b 800k $VIDEO_OUTPUT_DIR/$MOVIEDATE--Monitor-$MONITOR.avi 2> /$TEMP_DIR/ffmpeg-output-$MOVIEDATE--Monitor-$MONITOR.log
echo " -> FINISHED!"
# Removing temp files
echo "Removing temporary files, bye!"
rm -rf $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR
rm $TEMP_DIR/eventsfiles.$MOVIEDATE--Monitor-$MONITOR.list
rm $TEMP_DIR/events.$MOVIEDATE--Monitor-$MONITOR.list
exit 0