Webcam capture using fswebcam
- Published: Sunday, 20 July 2008 21:59
- Written by r3uk
- Hits: 91485
This article is part of the Webcam Cool Project. You should check the project homepage first!
My first attempt at configuring webcam capture used camE as it was in the Ubuntu repositories. Although camE worked happily with my Quickcam Sphere, when I built my weatherproof webcam I based it on a Logitech Quickcam 5000 which is a V4L2 device that camE didn't like.
Despite many hours of searching and testing, I couldn't find a program in the repos that would work with the Quickcam 5000, however a search on the internet soon turned up a compatible alternative in the form of fswebcam.
Installation on Ubuntu is a breeze. From the GUI, just download the i386.deb installer and open it using Gdebi Package Installer. Follow the prompts to install.
You can start fswebcam from the command line with various options however as some tweaking will invariably be involved it may be best to create a config file where you can quickly jump in and edit entries until you get it working as you want it.
To create a config file, use:
The contents of my config file are listed below...
title "EvilEye cam-O-tron"
timestamp "%d-%m-%Y %H:%M:%S (%Z)"
Check the fswebcam MAN page for the full range of commands and options. I'm just using those that are relevant to my particular installation.
A brief description of each line:
The first two lines state the device and input assigned to my webcam. This may vary and if not stated fswebcam will default to /dev/video0 input 0 anyway.
The loop line specifies a value in seconds in which fswebcam should take a snap using the camera. I have it set to every 15 seconds in this example.
The skip parameter specifies how many frames should be skipped before a frame is captured. This is useful if your webcam needs a few frames to settle down. I have it set to 20 which is quite high (4 or 5 would suffice for my camera), however this high setting keeps the camera powered on and the chipset warm for longer. This may be essential seeing as it's mounted outside and will face the full force of a British winter eventually.
The background setting allows fswebcam to run as a daemon. You might want to comment this out when testing.
The resolution command allows the size of the image capture to be defined. I wanted to use 640x480 but because of my abnormal webcam installation* the bandwidth of this resolution was too high forcing me to use 320x240. The higher the resolution, the better the image - but it depends on what your webcam supports.
The brightness and contrast settings take some working out by trial and error. In my case the settings quoted above give good colour and clarity on a sunny day.
My webcam image has a banner across the top due to the top-banner entry (although it can be sited elsewhere). The font used on my banner is specified in the font path and the title and timestamp (showing day, month, year, hour, minute, second and timezone in that order) are all displayed on the banner thanks to their respective entries in the configuration file.
The quality of my JPEG image is set in the jpeg 95 entry.
The path for the saved image is specified by the save entry (this is a dummy path for illustrative purposes and wouldn't exist on a normal Ubuntu installation - set your own path accordingly).
Finally the palette for the webcam is set. My Logitech Quickcam Pro 5000 would ideally use the YUYV palette but again, because of bandwidth restrictions* I have to use the MJPEG palatte.
*I've mentioned some abnormailty and bandwidth problems - these are nothing to do with fswebcam itself and are explained on my weatherproof webcam page. See my weatherproof webcam link under related articles below for more details.
If you get any font errors when you start fswebcam, install the ttf-msttcorefonts package. You can get this from Synaptic or with sudo apt-get install ttf-msttcorefonts as the font path specified in the above config file doesn't exist (I don't think) without this.
To start fswebcam using the config file in ~/.fswebcam use: fswebcam -c ~/.fswebcam.conf
To stop fswebcam use: pkill fswebcam
Remember to kill the fswebcam process before relaunching (if in background mode) or you'll lock out your webcam as only one instance of one program can access the webcam at any one time although you can run multiple instances of fswebcam as described on my aquarium webcam page here.
This image was taken with fswebcam using a Logitech Quickcam Pro 5000
Webcam project homepage
Using a Video4Linux (V4L) compliant webcam with camE
Using a Video4Linux2 (V4L2) compliant webcam with fswebcam
Refreshing a webcam image with Java and using a webcam with Joomla 1.5
Making a weatherproof webcam for outdoors
The electro-mechanical USB reset circuit
One year on...
The aquarium webcam