Automatically Generate video on EVERY event - zmvideo.pl

Forum for questions and support relating to the 1.25.x releases only.
Locked
futureechos
Posts: 10
Joined: Tue Mar 01, 2005 3:52 pm

Automatically Generate video on EVERY event - zmvideo.pl

Post by futureechos »

Hi All,

Loving Zoneminder btw..

Got a question - has anyone written a script to automatically generate video from new events using zmvideo.pl.

i can shell script something to do this for cron usage but wondering if someone has done the hard work already?

I imagine it would work like:

Run @ fixed time every day. Run SQL to show any new events for ${TODAY}, get the event numbers then invoke zmvideo.pl in a loop to create videos for all the found events.

Ideally I'll then copy those videos to 1 place and join them together using motion/ffmpeg so you get a daily video file of all events in one place, as its simpler than using web interface to view multiple events.

Anyone done this, and can I have a copy?

Thanks,
FE
futureechos
Posts: 10
Joined: Tue Mar 01, 2005 3:52 pm

Re: Automatically Generate video on EVERY event - zmvideo.pl

Post by futureechos »

OK sort of answered this myself.

In the filter window you can setup a filter for the last 24hrs by selecting:

"Date/Time" "Greater than or equal to" "-1 Day"

Try this and you will see last 24hrs only, then click 'Create Video for all matches' & Set it to 'Run filter in the background' after you hit save.

This will create any in the last 24 hrs in the folder structure. This is fine but there's all the subfolders to navigate so I've done the following to link them to the same place for easy consumption.

You need some basic unix cmd line to setup:

If you have Samba setup on your server, you can then run a cron job to either copy or link all created videos into 1 folder for easy review.

I create all videos in mpg format.
My event folder is /var/cache/zoneminder/events
My Samba share /var/cache/zoneminder/captures

edit /etc/samba/smb.conf [and add]

[Captures]
comment = ZM_Captures
path = /var/cache/zoneminder/captures
guest ok = yes
browseable = yes
create mask = 0600
directory mask = 0700

service smbd restart

Create a script that runs, or add directly to cron
find /var/cache/zoneminder/events -type f -name \*.mpg -exec ln -s {} /var/cache/zoneminder/captures/ \;

[\*.avi if you capture like that by default.]

Now this will create a softlink to the file, so when the original is removed we need to remove the link to keep things tidy.

I use this noddy script, *NB* test it first as this passes files to the rm command. TEST by placing "echo " in front of the rm command first, and comment out the other echo's as this will run non interactively from cron.

#! /bin/bash

DST=/var/cache/zoneminder/captures

# echo "Destination: ""${DST}"

cd ${DST} || exit 1

file * | grep 'broken symbolic' | while read b;do
echo "Removing:"
b_name=`echo "${b}" | awk -F: '{print $1}'`
echo "${b_name}"
rm "${DST}/${b_name}"
done

chown www-data:www-data 'path_to_script'
chmod 755 'path_to_script'


Finally add to cron
crontab -e [to edit]
add this line with your path to the script
30 * * * * /your_path_to_dir/scripts/unlink_captures.sh 1>/dev/null 2>&1

FYI the 1>/dev/null 2>&1 will redirect std output and errors to null device to prevent logs or mail from cron displaying output which we're not that interested in.



Hope it helps.
FE
mikb
Posts: 677
Joined: Mon Mar 25, 2013 12:34 pm

Re: Automatically Generate video on EVERY event - zmvideo.pl

Post by mikb »

When I was trying to get videos in one constant location, it didn't occur to me to find the videos and then link them!

In the end I went with this, under "options:Images" for the FFMPEG OPTIONS string

Code: Select all

-r 25 -q:v 1 -f avi -vtag XVID -g 30 -bf 2 -vf "hqdn3d,lutyuv=y=gammaval(1.4),unsharp" /mnt/point/for/cctv/zoneminder/videos/`date -d "-7 days" +"%Y%m%d-%H%M%S-%N"`.avi
To tart up the video, create it in the right format, and most importantly, plonk all made videos into one spot, dated approximately for when they occurred. The "-7 days" is because my filter is set to "make video" from anything older than 7 days that is also "archived", rather than your 24 hours.
Locked