The solution is for ZoneMinder 1.30.0 and only needs 2 lines of code modification in the original ZM Event.pm file (to save videos with date in the name) and a small bash script to move the files. The idea is based on the post by MartinBty that was updated and improved for current ZM version.
The filter screenshot is below. To make it work, follow my guide.
1. Edit original Event.pm file (mine is located in /usr/share/perl5/ZoneMinder directory).
Find the following piece of code, add one line and change one line as shown below.
Original code
Code: Select all
elsif ( $size )
{
my $file_size = 'S'.$size;
push( @file_parts, $file_size );
}
my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";
if ( $overwrite || !-s $video_file )
{
Info( "Creating video file $video_file for event $self->{Id}\n" );
Code: Select all
elsif ( $size )
{
my $file_size = 'S'.$size;
push( @file_parts, $file_size );
}
( my $video_starttime = $self->{StartTime} ) =~ s/\D//g; # new line
my $video_file = "$video_name-".$video_starttime."-".ceil($self->{FullLength})."sec.$format"; # modified line
if ( $overwrite || !-s $video_file )
{
Info( "Creating video file $video_file for event $self->{Id}\n" );
2. Create a new bash script file movevideo.sh with the following content and put it in web server accessible directory. I put mine in /usr/share/zoneminder/www/tools/movevideo.sh
The script below will move the videos to /archive/video directory with dates sub-directories. Make sure it exists and has write permissions for web server user.
user@server:/$ cat /usr/share/zoneminder/www/tools/movevideo.sh
Code: Select all
#!/bin/bash
LOG=/var/log/zm/movevideo.log
EXT=mp4
if [ "$1" != "" ]
then
for i in $(ls $1/*.$EXT)
do
DEST=$(sed 's/[^0-9]\+[0-9]/\/archive\/video/' <<< $1)
DEST=${DEST:0:-8}
echo "`date '+%F %T'` Moving from $i to $DEST" >> $LOG
mkdir -p $DEST
mv -n $i $DEST >> $LOG 2>&1
done
else
echo "`date '+%F %T'` ERROR: No input provided" >> $LOG
echo "ERROR: No input provided"
exit 1
fi
OPT_FFMPEG: checked
PATH_FFMPEG: /usr/bin/avconv (or ffmpeg location)
FFMPEG_OUTPUT_OPTIONS: -c:v h264 -crf 18 (this creates high quality h264 video)
FFMPEG_FORMATS: mpg mpeg wmv asf avi mp4* mov swf 3gp** (mp4 is added and checked as default).
4. Finally, create a new ZoneMinder filter that will find old events, convert them to H264 video, move to your custom location (/archive/video in my case):
Filter name: ArchiveVideo (background)
Disk percent: greater than or equal to 90
and Date: less than -3 months
Create video for all matches: checked
Execute command on all matches: /usr/share/zoneminder/www/tools/movevideo.sh
Delete all matches: checked
Save your filter and watch logs how it works!