Wednesday 30 December 2009

Ubuntu Motion


After fiddling with my webcam a bit more I'm now trying "motion" for Ubuntu, it offers motion detection, automatic recording and live video streams etc.

it's installed easily enough from the repository and my video camera is /dev/video0
(You can find out by entering the command "ls /dev/video*" at the command prompt, if you see only one device then your webcam is on that device).

I also set it to slightly different file names for my motion files so it records into a separate directory for each day.

Snapshots are set to 30 seconds.

My camera is an OV511 model which uses the original Video 4 Linux (v4l) drivers - motion and camarama for example use v4l2.
This can be sorted by prefixing the execution command with "LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so"

It's a bit tedious to remember to put this in though so the next best thing is to alter the bash default script so it pre-loads any time you run a bash script (it doesn't take nay noticeable memory up anyway).
with ubuntu its a case of editing /etc/bash.bashrc and including the following line.
export LD_PRELOAD=/usr/lib/libv4l/v4l2convert.so
This pre-loads it when the bash script runs.

I know this works, if I simply type "motion" at the terminal then it runs fine.

I now have motion detection on my webcam with totally configurable parameters and a timed upload to the web page every 30 seconds.

When motion is detected I can save pre-buffered frames i.e a number of frames before the motion was detected, a number during motion and a number after.
It will even compile SWF or mpeg videos !

Whats nice is that the still image uploaded to the web page has the motion marker detailing what was detected.

Another good thing is that this program can run as a daemon so it releases the terminal once launched, I can then control motion detection through a web interface.
A cron job can then tell it to start and stop as there's not much point saving images at night.
These commands enable motion recording 8:00 until 17:00 each day.

0 8 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/start > /dev/null
0 17 * * * root /usr/bin/lwp-request http://localhost:8080/0/detection/pause > /dev/null

Cpu usage is very low, hardly noticeable and yet another brilliant utility from the linux community.

No comments:

Post a Comment