I was looking at using ZoneMinder at the company i work for to record various IP Cameras dotted around the site.
I installed the system, linked in the cameras and let it run for a couple of days. I noticed that since ZoneMinder saves as Jpeg frames it was rapidly consuming my resources and found that if i exported the video of the event it was 1/10th the size.
Now my only problem with exporting the video was that it put it into the event directory. This meant i had to search through the directories for the video i wanted, and guess which it was (once i deleted the event) because the filename was not very informative.
I decided i'd try and get the video to export all into one folder (which i would share on the network), split them into sub-directories based on the camera name, and rename the file to contain the start-time + end-time of the video.
I was looking at Voltage54's post http://www.zoneminder.com/forums/viewtopic.php?t=13155 (Thanks for the start btw) as this was similar to what i wanted.
After a lot of trial and error (and banging my head against the desk) i've managed to come up with the solution i'll explain below.
(If anyone sees anything i've done wrong, or can improve on it feel free to contribute. I'm by no way an expert!)
I'm using ZoneMinder 1.24.1 on Ubuntu 8.10
(I'm running the following as root so i won't show sudo infront of each command)
#Edit zmvideo.pl (mine was located in /usr/local/bin)
vim /usr/local/bin/zmvideo.pl
#Display line numbers to go to where i edited the code
:set number
#The first thing i edited was the SQL query pulling the info from the DB. I needed to add in some custom naming/formatting to pull the info i wanted. This is on line 152 and looks like:
Code: Select all
my $sql = "select max(F.Delta)-min(F.Delta) as FullLength, E.*, unix_timestamp(E.StartTime) as Time, M.Name as MonitorName, M.Width as MonitorWidth, M.Height as MonitorHeight, M.Palette from Frames as F inner join Events as E on F.EventId = E.Id inner join Monitors as M on E.MonitorId = M.Id where EventId = '$event_id' group by F.EventI d";
Code: Select all
my $sql = "select max(F.Delta)-min(F.Delta) as FullLength, E.*, unix_timestamp(E.StartTime) as Time, E.Id as EventId, date_format(E.StartTime,'%d-%m-%y %H%i') as StartTime, date_format(E.EndTime,'%d-%m-%y %H%i') as EndTime, M.Name as MonitorName, M.Width as MonitorWidth, M.Height as MonitorHeight, M.Palette from Frames as F inner join Events as E on F.EventId = E.Id inner join Monitors as M on E.MonitorId = M.Id where EventId = '$event_id' group by F.EventId";
#I've done the same for the end time and called it EndTime.
#I've also pulled in the EventId. I wanted this in the filename so i could still trace it back to a specific Event in the logs etc.
#My next change was pulling all this together and actually specifying the filename. This can be found on line 159:
Code: Select all
( my $video_name = $event->{Name} ) =~ s/\s/_/g;
Code: Select all
( my $video_name = $event->{MonitorName}." (".$event->{StartTime}." to ".$event->{EndTime}.")-".$event->{EventId} );
#The next line is 195 and looks like:
Code: Select all
my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";
Code: Select all
my $video_file = "$video_name".".$format";
#It can be found on line 232 and looks like:
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."'$video_file' > ffmpeg.log 2>&1";
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."'/ZM-Video-Archive/$event->{MonitorName}/$video_file' > ffmpeg.log 2>&1";
#I've also added in the subdirectory based on the Monitor Name.
#Save and Exit the file.
That's it done.
Now whenever you export a video it will take the format of what we've just done.
For example an event on Monitor-10 will save like:
/ZM-Video-Archive/Monitor-10/Monitor-10 (23-04-09 1900 to 24-04-09 0100)-88.mov
An event on Monitor-11 will save like:
/ZM-Video-Archive/Monitor-11/Monitor-11 (23-04-09 1900 to 24-04-09 0100)-89.mov
And so on...
Now all i did was create a filter like in Voltage54 post with the criteria i wanted for exporting the video.
I can now find and view the exported video easily from anywhere on the network with logical filenaming and directory structure.
I hope this is of some use to someone, and as i said if anyone has any improvements / suggestions, please feel free to comment.