Fun With Webcam In Linux

Did you know that instead of installing special software to view your webcam video, you can simply use mplayer for the same purpose, and with a lot of fine control. e.g. try running the following command with your webcam attached to your computer.

mplayer -fps 15 tv:// -tv driver=v4l2:width=640:height=480:device=/dev/video0

And you can use mencoder to capture and encode video from your webcam:

mencoder tv:// -tv driver=v4l2:width=60:height=40:fps=60:device=/dev/video0 -nosound -ovc lavc -lavcopts vcodec=mjpeg -o test.avi

Have fun playing with the huge number of options available. You could even cat the test.avi file into a folder of your web server and have instant streaming video :-) .

Tip: Getting Your Webcam To Work In Ubuntu

I have an old noname cheapo webcam, that I dusted out of my junk (why? More on that in a post coming soon). I hoped that it would work in my Ubuntu setup out of the box like most of my other hardware. I connected it to my laptop’s usb port. dmesg gave the following output:

[21328.211333] usb 1-1: new full speed USB device using ohci_hcd and address 2
[21328.319698] usb 1-1: configuration #1 chosen from 1 choice
[21328.439705] Linux video capture interface: v2.00
[21328.458509] zc0301: V4L2 driver for ZC0301[P] Image Processor and Control Chip v1:1.05
[21328.459113] usb 1-1: ZC0301[P] Image Processor and Control Chip detected (vid/pid 0x0AC8/0x301B)
[21328.520576] usb 1-1: PB-0330 image sensor detected
[21328.870287] usb 1-1: Initialization succeeded
[21328.870919] usb 1-1: V4L2 device registered as /dev/video0
[21328.871001] usbcore: registered new interface driver zc0301
[21328.913737] usbcore: registered new interface driver gspca
[21328.913811] ubuntu/media/gspcav1/gspca_core.c: gspca driver 01.00.12 registered

Great! Everything set up, I thought. But running various programs, camorama, camE, kopete, everything gave weird errors like “Connection could not be made”, “device not ready” or just showed a blank screen. But soon, after  few trial and errors, I found the solution. Basically the “zc0301” module is the culprit and all you have to do to get your camera working is prevent it from loading. So, this is what I did:

The Elusive Super Phone

HTC announce their shiny new Touch Diamond recently. Everyone ooh’ed and aah’ed while ogling at it until they realized that HTC has taken a step back (or forward towards matching Apple’s iPhone crap) by removing the expansion card slot from the phone. Yes, it has 4 GB of internal storage but I’d rather have an SDHC card slot with the ever falling prices of solid state memory (an 8 GB Class 6 SDHC card is worth not more than around 60$ these days). With a history of ultimate-gift-to-mankind phones like HTC Tytn, HTC Tytn II (Kaiser), iPhone, etc that excite so much on the first look and then start becoming dimmer and unwanted as the euphoria settles, we are left to wonder when will we see the real “Super Phone”. The do-it-all-be-all-end-all phone.

Want To Program Smartly In C? Use GLib

GLib - An Introduction:

GLib is a utility library for C, which augments the standard C library in several purposeful ways to make your life that much easier while programming. GLib has the following things to offer you:

**1. Portability: **The main issue that haunts any C developer is the portability of code. One cannot rely on the standard C library for this as you may find many functions that work differently under different platforms are aren’t there at all sometimes. GLib ensures that the all the functionality exposed by it remains consistent across platforms, so that you can rest assured that your code will work the way its supposed to work irrespective of the Operating System it’s being used for (Of course, this assumes that you have ensured about portability aspects of your non-GLib related source code). Moreover, GLib is available for a vast array of contemporary Operating Systems including GNU/Linux, Microsoft Windows and Mac OS X.

Http 406 Errors Galore

If you have ever had these errors or just want to be prepared in case they pop up somtime (and they surely will), then read on as I discuss various situations that lead to them and also their solutions.

I generally use desktop clients (mostly blogjet, but also Windows Live Writer and Scribe Fire sometimes) to blog to my WordPress based blogs. Some months ago, I started getting “Http 406: Not Acceptable” error while posting a particular post. Tried posting through the WordPress inbuilt TinyMCE editor, but got the same result. A little bit of research told me that this was because the post contained some words that were considered harmful by the “mod_security” plugin for apache that had been installed by my host to prevent hacking attempts. The quick resolution was to include the following lines in my .htaccess: