Event Video saved to Custom Location / Filename by Default

If you've made a patch to quick fix a bug or to add a new feature not yet in the main tree then post it here so others can try it out.
MartinBty
Posts: 1
Joined: Fri Apr 24, 2009 8:28 am

Event Video saved to Custom Location / Filename by Default

Post 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.
hisingh1
Posts: 1
Joined: Tue Jul 21, 2009 4:33 pm

Thanks a lot!

Post 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?
Voltage54
Posts: 23
Joined: Sat Feb 21, 2009 1:35 am

Post 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 :)
User avatar
robi
Posts: 477
Joined: Sat Mar 17, 2007 10:48 am

Post 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?
v1.25.0 + Ubuntu Linux 12.04 Server
arielf
Posts: 83
Joined: Thu May 14, 2009 1:24 pm
Location: Argentina

query ??

Post 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
arielf
Posts: 83
Joined: Thu May 14, 2009 1:24 pm
Location: Argentina

Post 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
whatboy
Posts: 304
Joined: Mon Aug 31, 2009 10:31 pm

Post by whatboy »

You can use WinSCP...
arielf
Posts: 83
Joined: Thu May 14, 2009 1:24 pm
Location: Argentina

Post by arielf »

yes..
cortrecto, but is more common for a user normal have the option there on the web
sirugh
Posts: 9
Joined: Tue Nov 24, 2009 10:34 pm

Post 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!
Voltage54
Posts: 23
Joined: Sat Feb 21, 2009 1:35 am

Post 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
sirugh
Posts: 9
Joined: Tue Nov 24, 2009 10:34 pm

Post 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.
adi1133
Posts: 6
Joined: Tue Dec 01, 2009 4:51 pm

Post 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
myusernameisunique
Posts: 23
Joined: Wed Feb 17, 2010 12:23 am

Post 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!
burritolnx
Posts: 1
Joined: Thu Feb 11, 2010 4:10 am

How is the filter...

Post 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
beegee1962
Posts: 1
Joined: Mon Mar 20, 2017 9:01 am

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

Post by beegee1962 »

6 1/2 years later and this thread still helped me a lot.
Thanks for sharing!
Post Reply