We will be using a webcam as our video source for recording video. Our webcam uses the spca5xx driver (we covered setting up this camera as a Video for Linux source in a previous LUG.. use the LUG search to find 'spca5xx'). Once we get the camera plugged in and the driver loaded, we use the following command to make sure we are getting video from the device.

mplayer -tv driver=v4l tv://

We should see a video window show up with the view from the camera.

Now we want to have this video encoded on-the-fly to disk. For this we use mencoder. This app gets compiled right along with mplayer. If you compile/install mplayer from source, you should automatically have mencoder, but if you get the binary package, you might have to install mencoder seperately (depending on the package maintainers for your distro).

mencoder -tv driver=v4l:width=320:height=240:fps=8 tv:// -ovc lavc -o tv.avi

Like before with mplayer, we tell mencoder to use the v4l driver for tv input. We also tell mencoder to use 320x240 at 8 frames per second for capturing from the v4l tv source. For the tv url "tv://" we could specify a channel at the end of it like "tv://4" if we were using a video capture card with a tuner. Next we tell mencoder to use the output video codec "libavcodec" using "-ovc lavc". You can read the man page for mencoder to learn more about video and audio codecs, some of them may or may not be available on your system depending on whether they were present and compiled into your build of mplayer or whether your distros package maintainer included them.

We now have a nice small encoded video file on our disk without having to sacrifice a lot of temporary disk space to store unencoded video. The trade-off; there's always a trade-off, is that we need a lot more cpu cycles to do this on-the-fly encoding.

mplayer tv.avi