2012-12-30

Aquarium Surveillance

Surveilling fish in an aquarium with a simple webcam is a fun activity for young and old. The following post describes a simple software setup that was used to continuously upload live still images of a small aquarium.


Nothing more is required than an aquarium, a webcam and a Linux computer with Internet connection. Optionally the aquarium may be substituted by a hamster cage. ;)

Probably ffmpeg could be used as an alternative to stream live video. However it was found that ffmpeg crashes rather often and that the encoding of popular video formats is CPU intense, which is especially infeasible on older computers. Another alternative for live video would be to use mjpegstreamer, which is especially resource preserving. Unfortunately the project seems to be inactive now and no 64-bit binaries are provided.

Therefore it was concluded that the best compromise would be to stream still images at the maximum resolution of the webcam and a refresh rate of a couple seconds. Many programs are suitable to acquire images. In this case fswebcam was chosen, because it is small and simple and can be found in the Debian/Ubuntu repositories.

Watching the fish should also have a social component. Therefore an Xajax sample program was used to provide a simple comment function ("graffiti wall"). The sample program can be tested and downloaded here.

The following packages need to be conveniently installed from the software repositories if not already present:
sudo apt-get install apache2 php5 fswebcam

Normally the images acquired with fswebcam would be written to disk continuously. To avoid letting the hard disk suffer too much, a ramdisk is created. This can easily be done by adding the following line to /etc/fstab:
#ramdisk for aquarium photos
ramfs  /var/www/aquarium/aqua_ramdisk ramfs defaults 0 0

You can download the script and the modified xajax web program here.
The webcam.sh script needs to registered for automatic startup. A description how to do this can be found here. The web program can simply be copied to the apache web folder eg. /var/www/aquarium.

2012-12-27

"Distributed" Video Mass Converting

Assume the following situation that occurred to me recently:

There is a slow computer A with lots of disk space (eg. an old computer that is used as a NAS) and a faster computer B with only little disk space. A holds gigabytes of video clips in many different files that you want to do some CPU intense processing on, eg. re-encoding to another video format.

So what you probably want to do for every video clip is the following:
1. download video clip from A to B
2. process video clip on B
3. upload converted clip from B to A
4. delete original (and converted) clip on B

It is assumed that B can ssh/scp into A and that public key authentication is used. Otherwise it would be necessary to enter the password for every individual file. Moreover it is assumed that A and B are connected by a sufficiently fast network.

 A simple script (runs on B) that was used to perform the steps 1-4 can be found here. An additional example script is provided that uses ffmpeg to scale video clips down to 720p.