Saving Videos created by FFMPEG to new location

Forum for questions and support relating to the 1.25.x releases only.
Locked
User avatar
aelingil
Posts: 14
Joined: Mon Jul 23, 2012 11:58 pm

Saving Videos created by FFMPEG to new location

Post by aelingil »

I have 3 Cameras (Panasonic BL-C101A) that are working correctly and saving images the way i want them to.

I have never been able to setup 'video' with Zoneminder. It looks like it does the jpg images only. No problem, I have spent the last few days getting FFMPEG running and configured on the server. Afterwards I went into ZM and setup a Filter, so when ever a Cause = Motion <then> Create Video. The video is created in the folder where you can view the images.

Is there a way (in FFMPEG?) To set the default location where the video is created to a New location?

Instead of "/usr/cache/zoneminder/events/1/13/04/03/07/31/56/Front-Door Wed Apr 3 07:33:25 MST 2013.avi" I wanted to put it into "/media/archive/Front-Door Wed Apr 3 07:33:25 MST 2013.avi"

the ffmpeg information is the following:
ffmpeg_Imput_Options: -i %03d-capture.jpg
ffmpeg_Output_Options: -r 12 -s 640x480 "`date`".avi
Aelingil: I need to waste my time, my clients time and another techs time, just to fix a problem with you server & filters?
Tech Joseph: Yes, you are correct.
Flasheart
Posts: 342
Joined: Thu Jul 06, 2006 2:27 pm

Re: Saving Videos created by FFMPEG to new location

Post by Flasheart »

This was a question that came up on irc recently, and we guessed at an answer but didn't actually try it.

Zoneminder options has a setting for "ffmpeg options". It *may* be possible to set an output directory in there, or to modify the output filename to include a path, which would apply to any videos created.

Let us know if it works!
User avatar
aelingil
Posts: 14
Joined: Mon Jul 23, 2012 11:58 pm

Re: Saving Videos created by FFMPEG to new location

Post by aelingil »

I think i fixed it.. On the Output before specifying the name i added the following
-r 12 -s 640x480 /media/Archive/ZM-Video/"`date`".avi (Oh make sure it is `<gravel key> not ' <quote key>) adding the directory forced the file to save to the folder... (If you are making a new folder.. dont forget to change ownership..)

Something i've notice tho.. Now i have a video in the Event folder (where the ###-capture.jpg are) That video has the correct fps playing and it is labled '<Monitor Name>-<id>-r1-s1.avi'

The one that is saved to the new folder has the FPS all out of wack. I'm trying to tune it so the fps show up correctly again.
Aelingil: I need to waste my time, my clients time and another techs time, just to fix a problem with you server & filters?
Tech Joseph: Yes, you are correct.
User avatar
aelingil
Posts: 14
Joined: Mon Jul 23, 2012 11:58 pm

Re: Saving Videos created by FFMPEG to new location

Post by aelingil »

So i'm attaching the videos that are being produced.. (They are under 30 seconds.) Same video, one taking from my Archive i made, and the other is the same file, that is left in the event folder..

FrontDoor-2762-r1-s1.avi is the video that is left in the Event Folder.
Wed Apr 3 142610 MST 2013.AVI is the video that is being dropped into my /media/Archive/ZM-Videos/ folder..

..... Well nvm, Cannot upload the avi's So i've put them into my photbucket account. First video looks like it is the Archive/ZM-V/ Folder.. 2nd is the Event Folder.

http://s70.photobucket.com/user/Aelingi ... k%20Issues
password: zoneminder (all lower case)

watching the videos..
Both show 320x240 Video size
Both show 10 FPS
Durations are different..

It looks like when it moves it to the new folder it is dropping frames..but i dont know which ones.. or why.
Aelingil: I need to waste my time, my clients time and another techs time, just to fix a problem with you server & filters?
Tech Joseph: Yes, you are correct.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: Saving Videos created by FFMPEG to new location

Post by mikb »

aelingil wrote:-r 12 -s 640x480 /media/Archive/ZM-Video/"`date`".avi

The one that is saved to the new folder has the FPS all out of wack. I'm trying to tune it so the fps show up correctly again.
Just a wild guess here ...

I think this is because Zoneminder will create some options, prepended, and a filename, appended to your "options" string and pass it to FFMPEG, so your plan may not be working as you expect.

E,g, it ends up being

/path/to/ffmpeg -i INPUT-STUFF [ -r 12 -s 640x480 /media/archive/outputname1.avi ] cameraname-event-r1-s1.avi

Where you supply and control the [ middle bit ] only. If you know FFMPEG, you will know that it is perfectly legal (and confusing) to specify multiple input files and multiple output files, with options that apply to each being different. So it may intepret the whole thing in a way you hadn't expected.

I'm having a similar fight trying to get videos created with better names (never mind a new location!) in http://www.zoneminder.com/forums/viewto ... 29&t=20926 but not found an answer yet.
User avatar
aelingil
Posts: 14
Joined: Mon Jul 23, 2012 11:58 pm

Re: Saving Videos created by FFMPEG to new location

Post by aelingil »

The people on the FFMPEG's IRC (freenode #ffmpeg) helped me out with my 'date' format issues on naming. One format was the one i originally used (above). Someone else said to use this format.

ffmpeg -i input $(date +%f).ext

http://mywiki.wooledge.org/BashFAQ/082 They pointed out this ref for why they wanted to use the $(..) instead of "`..`" This may help on your problem with defining camera / date.. (which is going to be my next issue to tackle..)

I need to look through the documents and find out what the output name is for each name. (It is creating a video in my /event/ folder with the correct 'camera' name.. and i know how to make a 'current' date. I just need to figure out what the camera command is <like $(camera1 +%f) maybe..> and a date of recording instead of current date..

I'm going to try your options and see if it works also.. I have 5 hours to Trial&Error this before the end of work... Working progress.. once i get a working file name i will get it posted here.
Aelingil: I need to waste my time, my clients time and another techs time, just to fix a problem with you server & filters?
Tech Joseph: Yes, you are correct.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: Saving Videos created by FFMPEG to new location

Post by mikb »

aelingil wrote:... correct 'camera' name.. and i know how to make a 'current' date. I just need to [...] date of recording instead of current date..
I've been playing with this a little, and seem to be at the same brick wall you are :)

I can change "Event-12345-r1-s1.avi" to "CAM01-12345-r1-s1.avi" by changing the Event prefix under each camera's "Misc" tab. So I can get the camera name in there, sort of.

I can get FFMPEG to dump a file called "bob.avi" by forcing it's hand with (under Options/Image/FFMPEG Output options)

"-r 25 -q:v 5 -f avi -vtag XVID -g 60 -bf 2 /mnt/somewhere/else/bob.avi"

So any time you hit "create video" it overwrites that file. Like you, I can insert the current date, that is, the time at which FFMPEG ran.

There seems to be no way to find out when the captured images started, to force a filename with the time and date of the EVENT in.

Did you make any progress?
User avatar
aelingil
Posts: 14
Joined: Mon Jul 23, 2012 11:58 pm

Re: Saving Videos created by FFMPEG to new location

Post by aelingil »

... No..

All I have managed to do is the "`(date)`".avi which is all good NOW. However for some reason it decided to create a video for EVERY action since ZM has been around... (about 4.5 gigs worth of 350kb videos).. They all have the <date> when the video was created..

Now that is is finished, i have current videos being created..

I have been trying to find a way to change the location in /usr/bin/zmvideo.pl..

zmvideo.pl does create another video in /var/cache/Zoneminder/Events/#/#/#/#/#/.. etc/ Folder.. That one shows everything i want, in the video.... So i think i've narrowed down where the video gets created.. It is now just a matter of backing up zmvideo.pl and start messing around with the locations.. See if i can get it to export to my /media/Archive/ZM-Video/ location instead of /var/cache/Zoneminder/events/## folder.

I really wish i knew more about Linux.. i'm really kicking myself from not taking it up 10 years ago.. now everything is trial by fire..

Here is what i think.. Anyone chime in and tell me i am wrong.

Inside ZMVideo.pl File. (/usr/bin/ZMVideo.pl)

around line 150:
## my $event_path = getEventPath( $event );
## chdir ( $event_path );
I think that is where they change to the event/#/#/#/#/#/ folder..

## (my $video_name = $event->{Name} ) =~ s/\s/_/g;
I think this is then changed to show the event name and all the other added info.

Then at about Line 187
## my $video_file = "$video_name-" .$file_parts[0]."-".$file_parts[1].".$format";
I think this is where the video file name is created. This should be <Cam>-r1-s1.avi

about Line 224
## 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 think this is the command that actually creates the video + name. It is calling the images from d-capture.jpg (the file name images are saved in the event/### folder..) then using $video_file which is the name above they use to create the file name. My problem is... where can i put /media/Archive/ZM-Video/

i tried right after .ZM_FFMPEG_OUTPUT_OPTIONS." because it is calling for the file and exporting.. That didnt work.... I think i need to find where ZM_FFMPEG_OPTIONS is.. and change the location there.. I think it is going to call event_path..


So tomorrow i get to hunt for more files.. i've tried as much as i can with the FFMPEG Output in Options.. nothing i do change the file name. (I have even tried using $video_file and $video_name... Hopefully I can find the hard coded path and tweak it to go to my /media/Archive/ZM-Video/

Again, if anything i've been doing is wrong, please let me know. I'm real Green when it comes to programing.
Aelingil: I need to waste my time, my clients time and another techs time, just to fix a problem with you server & filters?
Tech Joseph: Yes, you are correct.
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: Saving Videos created by FFMPEG to new location

Post by mikb »

aelingil wrote:... No..
Oh :(

I've gone at it laterally, if I can't get the date the event was created ...

On the web interface, under "Configure Options/Images/FFMPEG_OUTPUT_OPTIONS" which was just "-r 25" I put this hideous lot ... (all one line)

-r 25 -q:v 1 -f avi -vtag XVID -g 30 -bf 2
-vf "hqdn3d,lutyuv=y=gammaval(1.4),unsharp"
/mnt/where/my/videos/go/`date -d "-7 days" +"%Y%m%d-%H%M%S-%N"`.avi

First line formats the video output, so 5 fps from cameras is made standards compliant at 25fps.
Second line cleans up the JPEG images into the final picture, and is not 100% needed
Last line does indeed control where the video goes, named with full time to the nanosecond (just in case 2 videos are made in quick succession)
It creates it in /mnt/where/my ... but also in the usual events directory. Both files have the correct parameters and settings as far as I can tell.

So that's a filename of 7 days BEFORE the time the VIDEO was created. Why? Because ... I run a filter that does this :-

Called it :- "ArchivedToVideo" with these steps

"Archive Status equal to Archived Only"
and "Date/Time less than 7 days ago" (that actually means OLDER THAN 7 DAYS, illogical in English, fine in maths, a date-time smaller than the date-time 7 days ago)
"Sort by date/time ascending" (important, else they won't be ordered)
Tick "Create Video"
Then click "Save" and then select "Run Filter In Background"

This means that any videos marked for archiving will, after 7 days, be converted into an AVI, denoise, gamma fixed, sharpened, and dated to APPROXIMATELY the rate time and day of their original creation. It will be a few minutes off, depending on how often you run filters in the background. But at least all clips will be archived->video in order, and the burnt in date and time will be definitive and correct.

It doesn't have to be 7 days, you could use 1 day, 1 hour. Whatever ... I used 7 days as that's the point when "unarchived" events get rolled over and binned, subject to disk space not getting them first! As long as you pick a time offset for the filter and the DATE command that matches. I'd like to get the camera NAME in there too, toward the end of the filename, but can't get my head round that without source fiddling.

I plan to add another rule that says: If it's archived and older than (e.g.) 3 months, delete it anyway to then clear up the surplus copy of the video. Your /mnt/where/my .... copy of the video is NOT deleted by this as it has no idea about it.
I think i need to find where ZM_FFMPEG_OPTIONS is.. and change the location there.. I think it is going to call event_path..
It comes from the FFMPEG options under the Configure/Options/Images tab on the ZM interface. I haven't yet started hacking the actual ZM source to fix this.
I'm real Green when it comes to programing.
You seem to have a good handle on where things are happening, I'm really trying to avoid digging into the guts of it just yet!
mikb
Posts: 600
Joined: Mon Mar 25, 2013 12:34 pm

Re: Saving Videos created by FFMPEG to new location

Post by mikb »

This means that any videos marked for archiving will, after 7 days, be converted into an AVI
I spoke too soon.

Although the filter is there, and marked to run in the background, it won't create a video when needed. Something was due to be archived to video this evening, and nothing happened.

Going to the event and manually "creating video" works fine. Deleting the video and remaking it works again. And I get my 2nd copy in an alt. location. Good.

Going to the filter and hitting "Submit" shows e.g. one event that needs converting to video. Good.

Going to the filter and hitting "Execute" shows the same one event, but doesn't "execute" anything. Bad.

The filter is marked into the background, nothing is happening. Also bad.

[Edit:] It seems that if you've ever "Created Video" once for an event before, then ZM won't create it again. Yes, that's a good thing. But, I've gone and manually deleted the videos (through the interface) so that I can get it to run again, and now it won't ... not sure if that's a bug or feature. It's making testing of video-making hard though.

So in summary: A filter WILL create videos for events that have NEVER had a video created before. It will not create a video if one has been made before, even if that video was deleted.
Locked