OsKuroBox

Details
The OsKuroBox is a LinkStation/KuroBox/NAS with NightVision Motion Detection and Sound Detection/Recording. Initially, my project was to take a LinkStation2 and outfit it so it can take night-time infrared still snapshots and even movie clips of whatever wanders by the animal feeders in our back yard. It morphed into something a bit more involved. Here's what it features:
 * night-time & daylight snapshots and movies, triggered by motion detection
 * daylight time-lapse movies of the feeding area
 * records sounds at feeding area and backyard area
 * optional selective sound detection/silence trimming
 * webserver for Motion's control webif and minimal real-time-image webcam (LAN only)
 * Avahi (Bonjour) to advertise (to LAN) these two web services provided by Motion
 * webserver for a gallery page (internet access for outside world)
 * dyndns.org client for DNS to accomodate internet access of above item
 * cron-based sound processing, scheduling, rotation and cleanout of the image files
 * optional USB wireless capability (so no ethernet cable is needed)
 * optional weatherproof housing for components (it rains and snows out there)

In this form it could also be used for video/audio surveillance or keeping an eye/ear on whatever. The range with the basic nightvision-capable camera that is used is limited, so I'm working out how to improve that with some auxiliary lighting. Higher-performance IR/nightvision-capable cameras could offer a better experience, especially if this were implemented on a machine with a faster, more powerful processor.

What's with the name?

 * 1) First, Oskuro=oscuro= dark, in spanish. Yeah, "Oscuro" was the only word I could find that had any semantic connection with "dark" and also had either a "Kuro" or "Link" in it.
 * 2) Secondly, this project is not without inspiration from others: sylver had produced the SeKuroBox years back and I liked the catchy name and the great concept, but I wanted to take the idea another direction.  I had grown up on a farm and hunted regularly, so I'm fascinated by animals (especially the wild ones).  It is essentially an LS outfitted with a night-vision camera and motion detection software, a "Late-Night CritterCam" if you will.
 * 3) The daytime camera has an integrated USB microphone, so I decided to add in sound recording capability. That's the "Plus" part.

Why the LS2?
Of all the LS boxes that Buffalo built, the LS2 is perhaps the least endowed, most restricted. It has no FPU, and only one serial port (which is used by the microcontroller). Well, if this much can be done w/ this box, more could be done with other boxes. This project will work best on a NAS device that has enough CPU power to process both sound and video.

Hardware

 * LS2 (or any Linux box w/ USB support, FPU and stronger processor are better),
 * up to 2 USB cameras (compatible w/ either the gspca or the uvc driver),
 * one Logitech QuickCam for Notebooks (w/ integrated USB microphone),
 * one ViMicro NightVision USB WebCam,
 * optional USB wireless stick or use of a wireless ethernet bridge,
 * optional motion activated lighting (this is a non-computer item),
 * optional weatherproof box(s)/housing(s) for all items if outside,
 * long enough ethernet cable and electrical extension cord (or optional other power source).

Software

 * basic foonas/OpenEmbedded image, or a base Debian (or other distro) installation
 * gspca and/or UVC webcam module(s) (These are in-kernel as of 2.6.27, but I had to compile gspca separately for the LS2 since its kernel @ 2.6.23.17),
 * Motion + dependencies,
 * SoX for sound recording/detection and silence trimming (http://www.linuxplanet.org/blogs/?cat=813),
 * (optional) various other webcam-ish apps & scripts/configurations.

SoX
The official/current SoX man page gives a lot of good documentation. Still, I had to do some experimentation to get it to work on the LS mipsel w/ the results I was looking for. The hard part was minimizing/eliminating dropouts during recording, and editting out all the the uninteresting "silence".

There are two ways to use SoX to do surveillance recording and processing:

1. Record everything during a set timeslot of day, and then process out the silence during off-hours.

On my LS2 this would record a track in aiff format w/ no dropouts with quick/low quality: rec -c 1 soundbite.aiff rate -q To clean that clip up and remove the silence, something like this would work: sox soundbite.aiff soundbite-cleaned.aiff silence 1 2 2% -1 2 2%

The best way that I've found to do this is to schedule cron to record sound during known good window times (like the first 4 hours of morning, last 3 hours before sunset, if you are trying to record bird calls), and then also schedule cron to process out the silence during the nighttime hours.

2. Record and trim out the silence on-the-fly, all in one step. This is ideal on units that have a processor that is more powerful than the LS2's mips. An example of such a command is this:

rec -c 1 --buffer 4096 clip$(date +%Y%m%d%H%M).aiff rate -q silence 1 00:00:0.1 .1% -1 00:00:0.1 .1% which records single-channel (mono) sound using a 4MB buffer to a aiff file with time-stamped filename, using quick (fast, low quality) data rate, and edits out all silence under the .1% threshhold. The .1% threshhold is pretty low, and this would pick up us talking 15 feet away. The buffer and rate flags seemed to keep the load on the processor a little lower and minimize dropouts (though they will occur on slower machines).

dyndns.org
First, you'll need to have an account a dyndns.org. Basic accounts are free. See the site for details.

Secondly, you'll need to configure and run ddclient. My current config at ddclient/ddclient.conf reads something like this:

# daemon=60 cache=/tmp/ddclient.cache pid=/var/run/ddclient.pid use=web, web=checkip.dyndns.com/, web-skip='Current IP Address: ' login=************** password=************* protocol=dyndns2 server=members.dyndns.org davys-lsmipsel.dyndns.org
 * 1) Basic configuration file for ddclient
 * 1) /etc/ddclient.conf

See the ddclient site or ddclient man page for more details. Starting it is as simple as ddclient

You may have to open ports up on your router in order for connectivity and access to work if you want to allow others outside to see your webcam images and any gallery pages. The dyndns.org site has some help/howto's for getting ddclient set up and network issues resolved.

Avahi/Bonjour
Just about any service that runs in Unix/Linux can be advertised in a user-friendly way via Avahi/Bonjour so that users can pick it up effortlessly in web browsers, printer setup utilities or finders. Motion's Control Webif and Realtime Video are excellent candidates for this. In Gnome's Epiphany web browser and OS X's Safari, they would appear like this, respectively:



A default installation of Avahi should be just fine to start with. All you will probably need to add are two .service files to advertise to any Bonjour/Avahi capable browsers (Safari,Epiphany, etc.). We will assume that you are using the default ports of 8080 and 8081 for the Motion Control Webif and Motion Video, respectively. Create two files: First nano /etc/avahi/services/motion-realtime.service and give it this content, so that the realtime Motion video image of your webcam will be visible via the web to your intranet.  <!DOCTYPE service-group SYSTEM "avahi-service.dtd">  %h Motion Realtime Image _http._tcp 8081  Secondly, nano /etc/avahi/services/motion-control.service should have the following content so the the Motion Control Webif will be advertised:  <!DOCTYPE service-group SYSTEM "avahi-service.dtd">  %h Motion Control Webif _http._tcp 8080  You should not have to restart Avahi for this to be advertised - it should work immediately.

ffmpeg and image tools
Although the mere though of editting video on your LS may seem counterintuitive, it is pretty easy with ffmpeg. Here are some examples:

Copy out 60 seconds of video from a clip, starting at t=210 seconds, from one clip to a new clip: ffmpeg -i test.mpg -ss 210 -t 60 testout.mpg Speed a clip up by a factor of 2: ffmpeg -i testout.mpg -an -f yuv4mpegpipe - | yuvfps -s 48:1 -r 48:1 | ffmpeg  -f yuv4mpegpipe -i - -s 320x240  -r 24 -an testout-twice-as-fast.mpg