Archive for March 2008 / Video category
You would like to record the video stream from your USB webcam. Make sure you have the correct kernel drivers installed and then use ffmpeg to capture the video from the video for linux interface.
Linux Drivers for your Webcam
Before capturing video you must make sure your webcam as been recognized by Linux, many modern Linux distributions will load the drivers you need by default, but in case yours doesn't, you can take a look at my other article "Taking snapshots from a webcam under linux" for some notes on linux kernel drivers.
You can check if your webcam has been recoginised by linux after plugging it in look for files called /dev/video0 or /dev/video1 (if you have more than one) in the file system. Alternatively, using the 'dmesg' command from the bash command line shell you should be able to see initialization messages from the webcam and its drivers
Just a note on situations when you have more than one webcam attached to your computer. There is a bandwidth limit that you may hit with USB. I found that when I had two webcams connected to an external hub which linked into just one USB slot, when I tried to open the video stream from the second camera, with the first one already open I received a confusing error "No space left on device". I was able to cure this by connecting the two webcams to different slots in the back of the computer and not using the hub.
Grab the video with ffmpeg
Firstly make sure you have ffmpeg and its dependencies correctly installed. Just how you install a packges varies widely for each distribution, so consult your documentation on how to install a package. For example, to install ffmpeg under Gentoo use (from the command line):
emerge ffmpeg
To record video from your web cam, you can open a bash command shell and use the following command.
ffmpeg -an -f video4linux -s 320x240 -r 15 -i /dev/v4l/video0 -vcodec mpeg4 -vtag DIVX /tmp/out.avi
This will save video using mpeg4 encoding (which is the same as DivX) and at the default bandwidth. The default bandwidth may not provide sufficient quality, so you can increase the bandwidth and hence the quality of the encoding using the -b option like this:
ffmpeg -an -f video4linux -s 320x240 -b 600k -r 15 -i /dev/v4l/video0 -vcodec mpeg4 -vtag DIVX /tmp/out.avi
You want to grab individual images or snapshots from your USB webcam and save them to image files. Make sure you have the correct kernel drivers for your webcam and then use mplayer to save the images as described below
Linux Kernel Drivers
There are a huge number of Linux distributions many using different combinations of Linux Kernels and modules, however before you start to use your webcam under linux, you need to ensure that your hardware is supported by Linux, and that the appropriate modules have been compiled into the Linux Kernel. Recompiling kernels is beyond the scope of this article, and quite a lot has already been written on that subject. I'll just mention here that you need to look for support for 'Video for Linux' and the right driver. There is a very versatile module 'GSPCAv1' http://mxhaard.free.fr/download.html which supports a wide range of USB cameras and chipsets. If you have this compiled for your kernel along with Video for Linux (v4l) its very likely your USB camera will work. If your webcam is relatively modern, but is not supported by the GSPCA driver, you might also try the Linux UVC drivers. UVC - USB Device Class Definition for Video Devices, or USB Video Class, defines video streaming functionality on the Universal Serial Bus, and is a standard, so all webcams which support that standard should work with the driver.
Using mplayer to save images
The video viewing software Mplayer also comes with some tools which allow you to capture video and stills, once you have installed Mplayer, you can issue a command like:
mplayer tv:// -tv driver=v4l:device=/dev/video0:width=320:height=240:outfmt=rgb24 -frames 1 -vo jpeg
Mplayer will save a file 000000001.jpg with a snapshot. Mplayer uses ffmpeg to do the conversion, so you will usually need the ffmpeg suite installed too.
Enjoy taking pictures with your webcam!
The problem
The Linksys Compact Wireless-G Internet Video Camera WVC54GC is a linux based wireless webcam with its own streaming web server built in. Windows users can view the video stream through Microsoft Internet Explorer without the need to install any extra software other than allowing the supplied Active-X control to run. The webcam has a web based management interface which is mostly usable from Firefox under windows or Linux, the main exception is you cannot see the video stream from the webcam using the builtin Active-X control. Firefox doesn't support ActiveX, instead it uses a different plugin mechanism 'Netscape Plugin Application Programming Interface'. This does the same kind of job as ActiveX, but is more platform independent. In earlier versions of Firefox it was possible to use a wrapper to load ActiveX controls, as of Firefox 2, this is no longer possible.
The Solution
Using a combination of open source software you can obtain a very similar result, with a view of the stream appearing within the management interface. This solution works on both Windows and Linux. This solution has been tested on Windows XP, 32bit Gentoo Linux and 64bit Gentoo Linux.
How it works
Instead of using the Active-X control built into the webcam, a Greasemonkey script edits the page while its inside your browser, replace a reference to the Active-X control with a reference to an embedded VLC object, which takes its stream from the webcam. You may be wondering, why use VLC instead of Windows Media Player to view the stream from the WVC54GC? There are two good reasons. Firstly, and most obviously, that solution wouldn't work under Linux. Secondly when I was testing this solution, I found that Windows Media Player seemed to take a very long time buffering the stream before actually beginning to play it; while VLC only takes a couple of seconds to get started.
Step 1: Install the following software if you don't already have them.
VLC media player A powerful and versatile, multiplatform media player
Firefox 2 or above If you are reading this then I guess its your favorite browser
Greasemonkey firefox plugin A scripting tool for manipulating web pages on the fly
This might seem a lot of software to install just to view the video stream, however these pieces of software are both very good tools to have installed on your computer and each is worth taking a look at in its own right - they will certainly earn their disk space.
Step 2: Click here to install the Greasemonkey Script
Step 3: Visit your webcam web user interface as normal click on 'View Video', wait a couple of seconds and then enjoy.