Taking snapshots from a webcam under linux

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!