Auto-archiving ZoneMinder recordings to video files

While ZoneMinder (www, github) is a great free and open-source surveillance camera software suite, it still lacks in some aspects. One of these is in its storage/transcoding of input video into series of JPEG images. This limits the amount of compression achieved by the system, such that a system with a high number of cameras must have a significant amount of storage to store history video past a few days.

For a single-camera setup recording at a low framerate, the recording time can be expanded far beyond the capabilities of JPEG. In the following script, all images for a day are moved to a folder and placed in sequential order, and ffmpeg is used to convert the series of images into a video. In this case mpeg4 (divx/xvid) is used because it’s less CPU intensive, however libx264 could be used to  obtain higher compression.

With the camera recording at 4 frames per second at 1600×1200 resolution, ~345,000 images at around ~50GB are compressed to a 7GB video file. Additionally, the hard drive is monitored, and the oldest video is removed when disk usage exceeds 90%.

ARDT=`date +%Y%m%d --date="7 days ago"`
cd /media/media/zmc
for hr in `ls $pf`
    for mn in `ls $pf/$hr`
        for sc in `ls $pf/$hr/$mn`
            for i in `ls $pf/$hr/$mn/$sc`
                  mv $pf/$hr/$mn/$sc/$i `printf "%09d" $C`.jpg
rm -rf $pf
/usr/bin/ffmpeg -i %09d.jpg -vcodec mpeg4 -qscale 10 -g 50 ../front-"${ARDT}".avi > /dev/null
echo "Made $C images totalling `du -h .|awk '{print $1}'` into a `ls -lh ../front-"${ARDT}".avi |awk '{print $5}'` video file at `date`"
for i in {0..9}; do rm -f *$i.jpg; done

diskfr=`df -h|awk '/media\/media/{print $5}'|sed 's/%//'`
if [ $diskfr -gt 90 ]; then
    trfile=`ls -lh /media/media/*.avi|awk 'NR==1{print $9}'`
    echo "Space on /media/media exceeds 90%. Removing $trfile"
    rm $trfile

Note that the process of moving so many images takes a few minutes, and this (along with the encoding time) would significantly increase with higher recording framerates. Ultimately, ZoneMinder will be a top-notch solution if h.264 encapsulation and storage is adopted as a storage intermediate, rather than JPEG, and there is in fact a bounty for such a feature.

Two-factor authentication with MikroTik, xinetd, and gmail

Sometimes setting up a VPN may be overkill for the requirements of remote access, and in that case there are secure alternatives to opening a firewall port to the outside world. My introduction to MikroTik devices came with the requirement that a client have employees accessing their office computers via. remote desktop, and I arrived at using SSH tunneling for the task due to the security offered, along with simplicity of setup on the end user’s computers. Since then, multiple client have adopted these low-cost routers for similar uses. Continue reading Two-factor authentication with MikroTik, xinetd, and gmail

A mobile charging cradle for the Xperia Z

This is an extension of a previous project, a charging station for the Xperia Z. I decided it would be nice to have hassle-free charging in the car, as well as a base to hold the phone in a favorable position for seeing navigation.

The design in CAD software
The design in CAD software

The new design was made to partially enclose the phone (with its protective case) and have two pogo pins to hit the charging contacts on the side, making it virtually effortless to hop in the car and charge the phone without plugging anything in.

Instead of designing the dock with a specific car or mounting system in mind, I placed two holes matched to the diameter of a wire coat hanger. This allows a mount to be created and modified after the fact, and makes it possible to use the dock in another car without printing another one.

Also this time, instead of using a USB breakout board, I hacked the end off a USB cable, made a channel for the cable in the design, and used a knot in the cable as a strain relief.

Bottom view

Top view

With bracket

The quality of the print was much higher due to using a well-tuned Ultimaker instead of the aging Makerbot used for the last print.

Files for this project: SolidWorks filePDF Drawing, STL file.

WiFi PIR Sensor

What IoT (“internet of things”) setup would be complete without the wireless PIR (passive infrared) motion sensor? And anyway, at this pace of ESP8266 projects, soon everything in my house will have an IP address.

This sensor is the next in a series, intended to fulfill a purpose, provide a general template for device-to-internet communication, and aid in me figuring out better and more compact ways to build these devices.

Generic input sensor interface
Generic input sensor interface

Continue reading WiFi PIR Sensor

A notch filter to detect a smoke alarm

Here’s another class project from this past spring semester, this time from Introduction to Circuit Analysis class.

Background: There are already devices that detect a smoke detector beeping and do something with it. These range from inexpensive (Life+Gear Fire Safety Night Light, $8) to capitalize-on-the-disabled expensive (SafeAwake Fire Alarm Aid with Bed Shaker, $250), and all rely on a similar premise: Identify the temporal pattern of a smoke detector beeping, and do something useful with it.

Needing to design any kind of filter for ENGR 240 class, why not select a smoke detector’s ~3200Hz? Continue reading A notch filter to detect a smoke alarm

Exporting a gmusicbrowser queue

I was looking to brush up on my C and C++ skills and become acquainted with the GNU GCC compiler, and this was one of the first topics I chose.

The idea is, take the queue of songs from gmusicbrowser and write a shell script to copy each music file to the current directory, prepending the number position in queue to the file name.

This permits the user to place all the files on a thumb drive or other device, and have them play in the same order, when the playing device plays in order of an alphabetical sorting of the directory. Two examples of devices that do this are an Onkyo TX-8050 receiver and a Kenwood DPX-500BT head unit. Continue reading Exporting a gmusicbrowser queue

3D printing a charging cradle for a Sony Xperia Z

This is a recap of a term project of sorts in Solidworks class last spring. We had to pick something to design (printing it was optional).

My latest smart phone is a Sony Xperia Z, a cheap enough out-of-pocket expense to replace a cracked Nexus 4. The new phone is water-resistant, but I found pulling the cover off the charging port every night was a pain. They do sell a charging cradle, though its poor design means it will not work with as phone case.

Copyright Sony
Copyright Sony

Considering the Xperia Z is so thin I can barely pick the phone up off a table without a case, and considering the school having a 3D printer, I found my design project. This post outlines the topics covered in my class presentation.

Appearances can be deceiving - this alarm clock has an IP address.
The finished print

Continue reading 3D printing a charging cradle for a Sony Xperia Z

Adding WiFi to an alarm clock for the hearing impaired

Introduction: The ClearSounds SW200 (motto: “shakeup to wakeup”) is an $80 alarm clock designed for those of us with hearing loss. It has hearing impairment-friendly features such as the ability to flash lights, an adjustable-frequency tone, and a bed shaker.

This is an older version
This is an older version

I’ve found the bed shaker is really effective – even when I had perfect hearing, the loudest screeching alarm sometimes wouldn’t roust me, but any sort of movement or vibration wakes me up immediately. Continue reading Adding WiFi to an alarm clock for the hearing impaired

ESP8266 Arduino SMTP Server part 3

This is a continuation of part 2, and expands to use the solution developed in this post, along with the latest findings about the specific DVR I’m using.

After creating the linux service described in one of the above links – which received a packet and plays a doorbell sound – the ESP server was modified to relay this signal. Continue reading ESP8266 Arduino SMTP Server part 3