Building a Webcam with FreeBSD

From ZS64
Jump to: navigation, search

I'm in the process of creating a webcam that takes still images of decent quality once a minute, to be displayed on a web site. So far, I've identified three principal approaches:

  • High quality network camera
  • Consumer USB webcam
  • Consumer or Prosumer still photo camera

The scene to be recorded is an outdoor space with high levels of contrast when the sun is out, making a proper aperture a necessity.

High quality network camera

Network cameras usually offer a built-in mechanism to regularly upload the current image via FTP or HTTP POST, come with their own built-in network stack (wired or wireless), and can be easily deployed because of it.

There's a large number of relatively inexpensive network cameras, but they all suffer from mediocre to bad image quality, both in terms of the sensor and the lens used. High-quality network cameras easily cost more than a 1000 €, which is out of reach for the club for which I'm trying to build a solution.

Consumer USB Webcam

USB "webcam" type cameras are available between 30 and 100 € and offer decent picture quality. Using a camera that implements the UVC protocol. a large number programs can be used Multiple people recommended the Logitech C910 camera with 1920x1080 (HD) resolution. I've yet to test it out.

FreeBSD software

FreeBSD has a compatibility layer to use Linux drivers from the Video4Linux project, called appropriately webcamd (Compatibility List).

There's a number of ways to capture stills through V4L;

  • Using the pwcview port's pwcview, you can look at a live image from the camera, or use the pwcsnap utility to capture one or more images. Image resolution is fixed to one from the built-in list, with 1600x1200 (uxga) the highest.
  • gstreamer with the gstreamer-plugins-jpeg and gstreamer-plugins-v4l2 plugins. With this command line, you can capture an image from the first V4L device:
gst-launch v4l2src num-buffers=1 \! jpegenc \! filesink location=/tmp/foo.jpg
  • This guy has patched a number of Linux programs to work on FreeBSD; unfortunately, it doesn't look like his work has made it back into the ports tree yet. But the patches are there, and seem to be working.

Still Photo Camera

gPhoto2 supports transferring images from a large number of digital cameras, and more importantly, supports controlling some models over USB. Using one of these camera models, you can set the recording parameters, take an image and have it transferred to the computer in a single command, often even without saving it to the flash media in the camera first.

This gives you very decent or even professional quality results, depending on the camera model you use. I've played around with a Canon PowerShot A510, and the results look quite encouraging.

However, there's one big drawback to be aware of: almost all of these cameras have a mechanical shutter, and these are designed for only a limited number of exposures. Depending on the model they might fail after 10,000 or 30,000 pictures. Sounds a lot? If you want to take one shot a minute, you're looking at 1,440 pictures a day, or over half a million in a year.

Since I bought my trial camera for cheap on eBay, I will see how far I can get it to go, but I'm not holding my breath. Also, you need to make sure you have a power supply for the camera (not always available, certainly not for cheap), and that the camera won't turn off by itself. Once off, you usually can't turn it on via USB.