Exporting Videos Hack

From ZoneMinder Wiki
Revision as of 17:27, 12 February 2017 by Snake (talk | contribs) (moved from dummies guide)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Warning

Using the below is not recommended. It's much easier to use Modect, and changing the source could lead to problems when upgrading ZoneMinder, if you are not extremely careful. However, I will leave the documentation here for posterity.

About

If you set cameras to Record and if you have enough high resolution cameras you will see your disk space fill up fast. ZM records in 10 minute segments and captures every frame as a jpeg. There is no compression of similar jpegs. Also, higher frame rate means more jpegs, more disk space.

How do you avoid filling up the HDD with lots of cameras?

You hack ZM. Use a filter which will take recordings from a specified range and create a video for all matches. Then you make a filter that will delete the events which have already had videos created.

Or alternatively, you use motion detection (see below), recording only when motion occurs (modect, not mocord).

What do you mean filter?

On the zm home console, there is a filter button. Click that, specify the range of videos you want to create videos for, click the checkbox for 'create video for al matches', submit/save, select it to run in the background, done.

How is it going to make the video?

You can specify parameters in FFMPEG_OUTPUT_OPTIONS in the options of zm. Make sure you are using ffmpeg, not avconv. You also need to specify the path for ffmpeg. I used the ffmpeg binary.



I settled on the following path for ffmpeg output options:

* ''-c:v libx264 -preset ultrafast  /videosfolder/on/some/path/`date -d "-1 days" +"%Y%m%d-%H%M%S-%N"`.avi < /dev/null''

VP9 compresses best, but is slower to encode. If you have hardware optimized for VP8 or VP9, maybe it will be better. Webm / MKV is great.

Here are a couple others I found on the forums, before settling on libx264:

* ''-c:v libx264 -preset fast -crf 38 -vf hqdn3d=8:6:12

* -r 1 -f image2 -i %07d.jpg -vcodec libvpx-vp9 -crf 18 

* -r 25 -q:v 1  /mnt/where/my/videos/go/`date -d "-1 days" +"%Y%m%d-%H%M%S-%N"`.webm

* -r 1 -f image2 -i %07d.jpg -vcodec libx264 -crf 18 -preset slower'' 

More are on Zoneminder forums. The general idea is you can specify a codec with

-c:v libx264 OR -c:v libvpx-vp9

Find any codec you like, and put it in -c:v and it should encode. Find one your hardware supports well, and go from there.

So I used in my FFMPEG_OUTPUT_OPTIONS

''-c:v libx264 -preset ultrafast  /videosfolder/on/some/path/`date -d "-1 days" +"%Y%m%d-%H%M%S-%N"`.avi < /dev/null''


This works, but we have a problem. All videos are in one folder. The next step was to make script Script for Deleting Old Exported Video Folders that would take files daily from this folder and put them into subdirectories labeled by the date. Then I made script Script for Deleting Old Exported Video Folders pt.2 that would measure the filesystem capacity of this folder (it is a dedicated drive) and if the capacity is over a set amount, delete the oldest two days.

This worked well, except that finding videos among the dozens in one day was slow.


The next step was based off of this post:

Event Video Saved to Custom Location by Default

So I edited zmvideo.pl and was able to get most of the cameras to export to their own folders (see above forum posts). Though now I had to change ffmpeg output options to:

-c:v libx264 -preset ultrafast

as now the perl script is managing where the output folders go.

I had to debug when setting up the perl script in order to make it work. Permissions, and watching the /var/log/zm/{zmvideo,zmfilter}.log helped.

All these steps for "Recording / Exporting Videos" are optional. It is recommended you use Motion Detection or Mocord, unless you enjoy pain.