Five fun ways to use a Linux webcam

4358

By Razvan T. Coloja 

Record yourself

One of the simplest ways you can record webcam videos is with mencoder. Using the Video4Linux driver, mencoder can take input from the webcam and save it in an uncompressed AVI file. Use the following command line to record an AVI with a resolution of 320×240 pixels.

mencoder tv:// -tv driver=v4l:width=320:height=240:device=/dev/video0 -nosound -ovc lavc -o wcrecording.avi

Substitute /dev/video0 with the device node used by your USB webcam. Since my low-budget webcam doesn’t have a microphone, I use the -nosound option to skip audio recording.

If you’d rather use a GUI to do the recording, try Video4Linux Grab. It can encode DivX and XviD files of the webcam input in real time using V4L. You can choose any other video and audio codec available on your system and use the GUI to select an aspect ratio.

Make a video stream

If you have the Apache Web server installed on your machine, you can use the webcam to make a video stream and display it on a Web page. The easiest way to accomplish this is by using webcam-server. In Ubuntu you can install the application with sudo apt-get install webcam-server. Start up the server with the binary name of the utility and point your browser to http://localhost:8888 to configure it.

Webcam-server has some options you can use to change the display mode of the stream and offer your visitors some additional info. For example, you can display the date, frame rate, and number of viewers by using webcam-server -c “%d/%m/%Y %H:%M:%S – serving %%v viewers at %%f FPS”. You can make webcam-server listen on another port if the default 8888 doesn’t suit you by using the -p attribute. Among other things, you can flip the displayed image, adjust the gamma level, set the image capture size, and specify colors for the foreground and background of the caption text.

Monitor your house

You’d be amazed how easy it is to turn an old Linux box and a cheap webcam into a powerful video surveillance system. Maybe the best and most complex open source tool for this is ZoneMinder. Once you set it up, it gives you a Web interface through which you can monitor every corner of your house in real time. It also allows you to record movement when it occurs. You can hook up as many webcams as you like and name them according to their position or purpose. From ZoneMinder’s Web interface you can choose a function for each of them: monitor, motion detection, or recording. You can even set up hotspots in the frame of view so that whatever enters the defined hotspot is instantly recorded by the respective webcam.

ZoneMinder records in JPEG format and uses FFMpeg or mpeg_encode to merge and transform the image files into a single video file. You can email the resulting MPEG file to yourself or uploaded it somewhere via FTP.

The application has tons of options that allow you to configure the server in whatever way you choose; from bandwidth usage limits to JPEG quality or multiple camera view modes, almost anything is possible. You’ll need good hardware and plenty of CPU power if you plan to constantly record from several cameras, but ZoneMinder is a great open source alternative to similar commercial products.

Reduce you image to ASCII

By using HasciiCam in conjunction with an ordinary webcam, you can stream a text representation of the camera input in various ways. For example, you can set up a Web page that reloads every second or so. That consumes less bandwidth than an actual image, though of course it’s not exactly high-resolution, but it is fun to watch. HasciiCam also lets you output single frames into text files to create ASCII images.

Morph yourself

If you really want to have fun with your webcam, try Cheese, a face-morphing application written for GNOME that supports both altering still images and live recordings. It can flip you, saturate you, turn you into the Incredible Hulk, or distort your face in several scary ways, then output the result as a file. The effect diversity is not that large, but you can nevertheless create some pretty funny videos with this toy.