Event Video saved to Custom Location / Filename by Default

Forum for questions and support relating to the 1.24.x releases only.
Locked
arielf
Posts: 83
Joined: Thu May 14, 2009 1:24 pm
Location: Argentina

Event Video saved to Custom Location / Filename by Default

Post by arielf »

Hi I followed the guide
http://www.zoneminder.com/forums/viewto ... highlight=

works flawlessly., But wanted to see if anyone knows how to make the save events per day, not like now that I saved in a folder all events of a monitor

with this guide I keep the vidoes in a directory so for example


"ZM_videos/Monitor_Name/event_name"

I need so if you can save

"ZM_videos/Monitor_Name/mount/event_name"

example
"ZM_videos/Monitor1/October/event_name"

PD:
and more serious with month and day

thanks
Voltage54
Posts: 23
Joined: Sat Feb 21, 2009 1:35 am

Post by Voltage54 »

Arielf,

I have achieved something similar to this, with a simple modification to MartinBty's post. The end result looks something like this:

Image

In order to do this, use the following guide (shamelessly ripped from MartinBty's post and edited to suit):

#Edit zmvideo.pl (mine was located in /usr/local/bin)

Code: Select all

vim /usr/local/bin/zmvideo.pl
#Display line numbers to go to where i edited the code

Code: Select all

: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:

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";

#I changed this to the following:
Code:

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 pulled in the start time of the event and called it StartTime. I had to format it with date_format as i found that the ':' in the time were breaking the naming of the file.
#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:

Code: Select all

( my $video_name = $event->{Name} ) =~ s/\s/_/g;

#I changed this to the following (I think it's pretty much self explanatory what i've done):
Code:

Code: Select all

( my $video_name = $event->{MonitorName}." (".$event->{StartTime}." to ".$event->{EndTime}.")-".$event->{EventId} );
#The output will be for example: Monitor-10 (23-04-09 1900 to 24-04-09 0100)-88

#The next line is 195 and looks like:
Code:

Code: Select all

my $video_file = "$video_name-".$file_parts[0]."-".$file_parts[1].".$format";

#I changed this to the following to trim away the excess naming:
Code:

Code: Select all

my $video_file = "$video_name".".$format";

#The final line i changed was the code which outputs the video. Thanks to Voltage54 i knew where that was.
#It can be found on line 232 and looks like:
Code:

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";

#I changed this to the following:
Code:

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/zoneminder/ZM-Video-Archive/$event->{MonitorName}/$video_file' > ffmpeg.log 2>&1";
#All i've done is created a folder in /media/zoneminder called ZM-Video-Archive (this is the folder i will share on the network).
#I've also added in the subdirectory based on the Monitor Name.

#Save and Exit the file.

Note: You will also need to create a cronjob to ensure that the 'dated' folder is pre-existing before zoneminder/ffmpeg attemps to create the video file. Ffmpeg will NOT create the folder for you and will spit out an error, causing you possibly to lose days of footage before you realise. In order to ensure this doesn't happen, append your crontab as follows:

Code: Select all

su www-data -c "crontab -e"
Append:

Code: Select all

57 23 * * * mkdir /media/zoneminder/ZM-Video-Archive/`date -d tomorrow '+\%y-\%m-\%d'` #Creates tomorrows CCTV folder

Code: Select all

@reboot mkdir /media/zoneminder/ZM-Video-Archive/`date -d today '+\%y-\%m-\%d'` #Creates todays CCTV folder
Hope this helps champ.

Once again, thanks to MartinBty for the original forum post!
arielf
Posts: 83
Joined: Thu May 14, 2009 1:24 pm
Location: Argentina

Post by arielf »

yes, very similar, the only thing that I need save files as follows

example
IN ZM : monitor1 - monitor2 -monitor3
events are saved in : ZMvideos

I need to save them so

/Zmvideos/monitor1/09-10-01/event_name
/Zmvideos/monitor2/09-10-01/event_name
/Zmvideos/monitor2/09-10-01/event_name

thanks
Locked