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.

Friday 25 December 2009

Ho Ho Ho

Well it truly is Christmas, Not only did the local council grit the pavements yesterday (despite the snow melting) then today we wake up to find someone has jumped over a barrier and attacked the Pope.

It's the spirit of giving and obviously the woman who did it gave the Pope a trip.

After a massive 4 hours sleep the beef joint has been slow cooked and the Turkey crown is in so now I fully expect the daily Homeserve and Scottish Power phone calls asking me if I want my pipes covered or switch to another supplier.
Their latest scam appears to be leaving a voice message on your answer phone that is very clever, it deliberately leaves off the company name than says "has called" and then tells you that they are required by law to notify you of their call by recorded message.

Now if anyones reading from one of those companies then in the true spirit of Christmas I would like to tell you all to Fuck off and grow up.
It's pure stupidity playing on peoples fears as the latest message says "do not be alarmed by this call", well people will be - to get a message from a company that leaves no name and then says they will call you back etc is just gross negligence.

They say that Christmas is the time of giving so should any of these idiots ring today I'll make sure to post everything I can and piss them off as much as possible.

Time to check the Turkey and wait for Scottish Power to call, then in my best spirit of Xmas I think I'll just put the phone next to the parrot and let him take the call.

P.S even if your on TPS these clowns don't seem to care, and never ever get rid of them by asking them to post details, under law this is an invitation to trade - we did that many years ago and found they had not only signed us up but canceled our existing supplier (who we were more than happy with).
Thankfully our supplier called us and offered to sort it out (which they did), Scottish Power then had the nerve to call us and give me a mouthful saying "so your not interested in saving money then ?" - nice sales touch there lads.
And their "we'll we've signed you up now, you have to wait at least 30 days to cancel", to which I said "Charge me 1 penny and I'll see you in court".

So to sign off for this Festive post, Happy Christmas to everyone except Scottish Power or Homeserve, may you never call me again or attempt to communicate with me.

Wednesday 23 December 2009

Lost - if found, call your local Council


As usual in the UK we get a touch of Winter weather and all hell breaks loose, I traveled 70 miles from the East side of the Pennines to the West side and you could see the difference in the regions I went through.

My region appear to have given up and gone home for the Winter, Derby have gritted most major roads well and Staffordshire (A50 through to Stoke) was gritted perfectly.
The issues seemed to be once you left the major roads, anything less than a main arterial road was left to fend for itself and certainly at my side of the country anything less than the motorway was left in a "rurual" state.

Over the course of a week I've not seen one single gritter out or anything clearing the roads - the councils will make all sorts of excuses but there's always only one reason they won't do anything ..... Cost.

It's far easier to stall for as long as possible then like the years before they will bring the gritters out once the weather forecast is for a thaw, I laughed as they gritted the already melting roads once and they announced on the radio that they didn't grit due to the risk of the grit being covered by fresh snow or the ice re-freezing, remember those "idiots" your trying to fool on the radio will have a casting vote next polling day.

I've even seen it where they blamed the issues on the wrong type of grit, it's not hard guys, you get some grit, pop it in a gritter and throw it on the roads. When they did that I counted 7 cars that had slid into ditches in a 4 mile stretch of road, the council blamed the wrong grit, I blame the idiot who was in charge of it ?

The best excuse this year has been the buses decided it was too slippery to go out (despite the fact the bus lanes are supposed to be gritted), so the buses didn't run, because of that the gritters didn't seem to bother so no one won and the process repeated.

Anyway, if you see one of these yellow lorries be sure to stop it and ask the driver if he's lost.
If he asks why, tell him that he surely shouldn't be on the roads as he's obviously the last of his kind and should anything happen to him then they will be extinct.
I may help to advise him that he's obviously wasting his time as if the council risk assessment team have deemed it safe enough to send him out then the snow will most likely melt in 24 hours anyway. I suspect he will have a full escort complete with ambulance and overhead helicopter anyway in case he gets into difficulty, lest he sues the council for sending him out in slightly wintery weather.

I would probably stick two fingers at him then, pop a nice raspberry at him and wish him a "Happy fucking Christmas for bothering at all", maybe the councils will realize one day or maybe I'll skid on a bend and land my car in the reception of the local council ? I'll be sure to use my emergency window hammer to break a side window and call them a bunch of pen pushing clowns before the Fire Brigade cut me out.

Happy fucking Christmas you slack arse overpaid, overbearing, risk assesment idiots - except Derby and Staffs Council who gritted their roads to the point where you could actually use them safely.

Maybe Nottingham and Ashfield council will read this, maybe not - do I care ? Nope, as they will be far too busy performing risk assessment on their toilet paper in case it causes sore arses.

Sunday 20 December 2009

Ubuntu webcam & server


I Had a couple of webcams sitting around which Windoze hates - typical 80mb or larger install iles, temperamental operation and the usual "one minute it works, next it's no longer supported" stuff.


Linux uses V4L (Video for Linux) so if your camera is support and I'm amazed how many are) it's often just a case of plugging in and off you go.

A simple test program first is Cheese (sudo apt-get install heese), this grabs whatever camera you have plugged in and shows live images from it, you can edit them etc.

Another indication the camera is working is either check the lsusb command or look for a video device in /dev/videox

lsusb on mine shows.
Bus 005 Device 002: ID 05a9:0511 OmniVision Technologies, Inc. OV511 Webcam

listing the contents of /dev/video I get.
ls /dev/video*
/dev/video0

So I know by these two commands my webcam is detected anyway, its an Omnivision OV511.
Another package worth using to check is Xawtv - this shows which driver it's using, screen size etc I ran that and it shows the Omnivision driver is actually the ov519 driver.

So I now need to capture my webcam and upload it to the web....

There are several utilities including camorama (this works best with V4L2 webcams) and although had this working in mere moments I decided to use "webcam"

sudo apt-get install webcam

This installs webcam which is run from the command line (just type webcam).
First though you just need to make some pretty simple changes to it's config file (which is held in your home directory but hidden ie. has a full stop in front of the name)

sudo gedit ./webcamrc

The file has two parts, one for the Grab itself i.e size, frequency etc and another for the FTP bit.

[grab]
device = /dev/video0
text = "webcam %Y-%m-%d %H:%M:%S"
# infofile = filename
fg_red = 255
fg_green = 255
fg_blue = 255
width = 640
height = 480
delay = 60
wait = 5
input = ov519
# norm = pal
rotate = 0
top = 0
left = 0
bottom = -1
right = -1
quality = 75
trigger = 0
once = 0

[ftp]
host = upload.website.com
user = myusername
pass = mypassword
dir = Cam
file = Webcam.jpeg
tmp = uploading.jpeg
passive = 1
debug = 0
auto = 0
local = 0
ssh = 0

Now I have my webcam config file (I commented out the PAL format as I was not sure what format this camera did but it seems to work fine with that commented out).

I made a simple web page but this will dump the file into my webpage home directory in the /Cam folder and call the image Webcam.jpg

To run webcam you just open a console and type "webcam"
It shows output as it uploads to the ftp site so you can leave it like that if you want and if connection gets lost you would see connection errors.
I wanted to run it without the console being open, there are plenty of people giving help and the command is ...

webcam > /dev/null 2>&1 &


If you run this it will return the process number for webcam i.e

kevin@server:~$ webcam > /dev/null 2>&1 &
[1] 17709

run the PS command to confirm it's running

kevin@server:~$ ps
PID TTY TIME CMD
8360 pts/2 00:00:00 bash
17709 pts/2 00:00:00 webcam
17755 pts/2 00:00:00 ov511-decomp
17856 pts/2 00:00:00 ps


That's it really, it uploads every 60 seconds ( I put delay=60, the wait=5 gives the camera
5 seconds to form an image once the command is issued)
I've also used a simple Java script from http://www.ajaxcam.com/ which makes the main webpage refresh every 60 seconds as well.

if you go to the cam webpage then there is no need to click refresh, it keeps up with the image.

The Ubuntu man (manual) page for webcam is.
http://manpages.ubuntu.com/manpages/lucid/en/man1/webcam.1.html

Although it does not contain a lot I found this site to help a lot.
http://blog.mymediasystem.net/uncategorized/setting-up-webcam-on-linux/



Sunday 13 December 2009

Assume Recovery Position

Had a hard drive fail in a notebook and unlike Windows filth I managed to salvage the entire drive on ubuntu and effectively copy the drive to a replacement with almost no effort.

Now the Windoze purists amongst the rear seats will witter about Ghost and stuff but looking at the crowd near the exit doors I notice very few hands when I ask who is running a legitimate (licensed) version of Ghost let alone a legitimate version of Windows.

So in the real world the argument would have to be, if your version of Ghost is not one you have purchased then you would be stuck.

With linux it's not a problem as I don't need to worry about the shops being shut and how to get a legal copy of a backup utility.

I could have used "sbackup" which will back up files but I decided to try a deep recovery method purely to see if it would work - It's important to note I didn't need to do it this way, I did it so if I have a drive that is REALLY faulty I should be able to do the same.

So .... the failing drive is 60gb, the replacement is also 60gb
Ubuntu 9.10 identifies the original drive as "imminent failure", Palimsest (the drive utility) monitors the drives on Ubuntu 9.10 and identifies failure in real time.
The replacement drive is identified as "Good" with no errors or issues.

Next step .. Boot on Ubuntu Live CD (or in my case Ubuntu pen drive)
Install ddrescue (make sure the repositories are enabled so you can get it from T'Internet)
sudo apt-get install ddrescue

Make sure I have a USB drive plugged in to dump the files onto.
Ubuntu mounts drives on my system into /media so I mounted the drives and made sure both were available.

I made a mount point for the USB drive so the target directory was easy i.e
sudo mount /dev/sdd1 /media/250gb
i.e the mount point was /media/250gb

as the Linux drive as a unique uuid which is VERY long I made a simpler mount point for my main drive (which is /dev/sda) i.e
sudo mount /dev/sda1 /media/hdd

Bear in mind I made the directories first in the /media folder - the Ubuntu pen drive is persistent so these mount points are retained for me later.

So I have 2 drives ...
/media/hdd (my original and failing drive)
/media/250gb (my USB drive)

a quick copy of the data using ddrescue....

sudo ddrescue /media/hdd /media/250gb/backup.img

This copied the entire drive and took about 15 minutes.

I now had a full image file of all the data ....

A quick check of the integrity of the backup...

fsck -y /media/250gb/backup.img

This checks the backup file for any issues, the backup file was fine.

In with the replacement drive ... now this was the bit where most web sites entered vague territory.

The replacement was formatted as "ext3" file system and mounted in the same way i.e

/media/250gb (the USB drive)
/media/hdd (the new hdd)

A quick recover (which took about 30 mins)

sudo ddrescue /media/250gb/backup.img /media/hdd

Back comes all the data .....

I didn't realise that in fact 2 things were missing, the grub boot loader and the swap file ... (If I had known this first I would have made partitions for them and got them ready - Doh !!!)

So ..... I had the data back but needed 2 partitions from logical reading , I needed a 100mb bootpartition and a swap one, about 1.5gb.

Using Gparted I moved the main parition "to the right" 100mb leaving an empty parition at the front, then I shrunk it at the end leaving another partition of 1.5gb.
Let Gparted do it's thing so I have blank 100mb, the main drive partition and a blank 1.5gb.

In Gparted click on the 100mb partition and format it to ext3 - done.
In Gparted click on the 1.5gb partition and format swap.

At this point I'm almost done, I have 100mb boot partition (ext3), the main file system and 1.5gb swap.

To re-install grub there's a little trick people have posted.

Using the pen drive or live CD tell it to install Ubuntu to hard drive.
When the partitioner comes up tell it you will manually partition, you will see the three patitions, click each one and "change", put the 100mb mount point as /boot, put the main partition mount point as / and the swap partition will already be showing as swap anyway.

You then continue forwards as if your installing, the system will advise it's installing but will re-install grub and the swap partition correctly.

Let it finish, reboot and it was done.

Sounds like a lot of steps but bear in mind ddrescue can recover drives even with errors on them while Ghost normally falls over in a big heap and considering it was done with free software then it's even better.

I could have simply copied the files over from drive to drive but wanted to try a full disaster recovery type scenario, I've also taken a full 100% copy using "tar" which again I could recover easily over the top of the new drive but wanted the full experience.

Add to this my experience a couple of weeks ago where our media PC locked up during a full Ubuntu change migration from 9.04 to 9.10 (turned out to be my fault, I had put a fan in backwards so it was blowing air the wrong way - ooops), in normal circumstances your windows would be screwed but with Ubuntu I booted on Live CD, mounted the partition (which was effectively screwed) transferred super user control to that drive (so your actions are on that partition and not the live CD) issue about 4 commands and the system is running as good as ever.

I would love to see the flaky software known as Windows do the same as that, no reload, no re-install of anything, just the ability for the OS to carry on where it left off !!!

Apparently Windows 7 is out, no idea what it's like maybe i'll be given it for my corporate laptop but it's OK I don't need it at home.