Page 1 of 2

Event Video saved to Custom Location / Filename by Default

Posted: Fri Apr 24, 2009 9:45 am
by MartinBty
Hi,

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";
#I changed this to the following:

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: 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: 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: 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: 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: 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: 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";
#All i've done is created a folder on the root of the drive 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.

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.

Thanks a lot!

Posted: Fri Jul 31, 2009 8:35 pm
by hisingh1
:D :D :D
This was a great help. I was heading to solve this problem in a diffrent way. I did what you did till the point it went to the dir creating. I made a bash script that moved all the video files to the video dir and execute it with the filter that i used to make the video.

only question i have is how do you get the video download button working after that? Like if you manualy make a video of the event, the video file can be downloaded later on. But you cant do this now. what do i change?

Posted: Tue Aug 25, 2009 1:28 pm
by Voltage54
Wow, very impressive.

This is exactly what I wanted to do however I lack the mysql/programming knowledge to do it properly!

I'm assuming your method is also much less resource intensive than mine, as it doesn't need to execute find commands and relocate/rename files.

I'm looking forward to trying it out on my cctv machine :)

Posted: Tue Sep 01, 2009 11:14 am
by robi
Guys, can we customize a bit the thing, by copying zmvideo.pl to another filename, like zmvideoauto.pl, and use it as a completely new filter?

query ??

Posted: Thu Sep 03, 2009 8:21 pm
by arielf
query, creating a filter as Voltage54's already said I would have to create the videos, no?

This generates a single video for a single event or all events by adding video

Posted: Wed Oct 28, 2009 9:11 pm
by arielf
It works OK,
but when viewing an event, and press the button video,
generates the same but do not see the option to download
generated video


Funciona OK,
pero al visualizar un evento, y presionar el boton video,
lo genera al mismo pero no aparece la opcion de descargar
el video generado

Posted: Thu Oct 29, 2009 1:02 am
by whatboy
You can use WinSCP...

Posted: Thu Oct 29, 2009 12:50 pm
by arielf
yes..
cortrecto, but is more common for a user normal have the option there on the web

Posted: Thu Dec 03, 2009 8:24 pm
by sirugh
I know I'm bringing up this thread from the past, but this is what I need to do here at my work, however I am stuck at the point where zm will, when set to record, just save the frames in the event folder. How do you even set it to record and save only video in the first place, and what do I do if I do not have a zmvideo.pl file? I did a search and there is no file named that anywhere on my system.

I'm running ZMLarch 1.24.2, and I only have 2 network Axis 207 cameras. I need to record the video to an iSCSI, so organizing the data for later viewing is important!

Posted: Fri Dec 04, 2009 12:29 am
by Voltage54
My understanding is you can not avoid saving to jpg first. The modification shown above will allow you to create videos from the jpg's zoneminder has captured.

As for not finding zmvideo.pl, I've never had this issue. FYI (if you didn't know already), an easy way to find the file (if you're on a debian based machine):

sudo apt-get update && sudo apt-get install locate && updatedb && locate zmvideo.pl

Posted: Fri Dec 04, 2009 1:57 am
by sirugh
I'm using the system that was installed from the liveCD, currently running off the HDD. I know how to search for files in linux, ie: find / zmvideo.pl

would that not find it?

Also, i dont know if apt-get was installed with the liveCD system. And I'm not sure how to install it :/ My only linux experience has been with ubuntu.

Posted: Thu Dec 17, 2009 2:37 pm
by adi1133
if i edit zmvideo.pl in any way zonemidner cant generate videos any more,if i undo my changes with a backup i still cant save videos, i need to reinstall the os and zoneminder after i edit zmvideo.pl
I use gedit to edit text files ... could that be a problem ?

ok nvm that, i had wrong permisions on the folder i was saving the videos and ffmpeg seems to bug out when that happens

Posted: Thu Dec 02, 2010 12:26 am
by myusernameisunique
Following this guide, I've changed the video filename.

How can I insert the video file name in event notification email?

I can attach event video file itself to email by using %EV%, but I don't need it. I just need to show the full path to the video file (including the filename).

Any suggestions will be greatly appreciated!

How is the filter...

Posted: Thu Dec 02, 2010 10:56 pm
by burritolnx
I dont see the image for the filter...
Who could explain howto I create this filter, the zmvideo.pl works fine, but how I create a filter for work with zmvideo.pl...
Please any can helpme...

Thanks in advanced.

Eduardo

Re: Event Video saved to Custom Location / Filename by Default

Posted: Wed Mar 22, 2017 9:09 am
by beegee1962
6 1/2 years later and this thread still helped me a lot.
Thanks for sharing!