Keeping an eye on something with a webcam is really easy: just a matter of setting up for example (c)vlc to multicast from /dev/videoX to the network, and done.

Example:

# Streaming:
cvlc v4l2:///dev/video0 --no-audio --sout "#transcode{vcodec=mp2v,vb=3072}:std{access=udp,mux=ts,dst=224.0.0.1}"

# Playing, possibly on a remote machine:
vlc udp://@224.0.0.1:1234

Notes:

  • v4l2 vs. v4l depending on the distribution (sid vs. squeeze).
  • Triple slash needed, two for the v4l[2]:// part, one for the device (/dev/video0).
  • Why this address? See Wikipedia’s Multicast address article.

Possible problems:

  • If switches don’t have IGMP snooping enabled, throwing multicast at them turns it into plain broadcast. In other words: instead of having packets sent to the hosts subscribed to that multicast address, everyone gets those packets, polluting the network.
  • Trying to stream from multiple devices may fail, due to USB bandwidth issues. At least that can be seen with two random devices using the uvcvideo module, getting No space left on device when the second (c)vlc is started.

Where to go from here:

  • fswebcam to the rescue! It can capture a frame from a given device. The following options are particularly useful: --resolution to request a specific resolution (the device will fall back to another resolution if the requested one is unavailable); --frames to specify the number of frames to capture (lower noise, but possibly higher blurriness).
  • A tiny python wrapper around it makes it possible to set various webcams, with different options (number of frames, delay between two captures, resolution), operating at the same time thanks to the help of the threading module. To avoid encountering the same bandwidth issue, a tiny lock ensures a single fswebcam instance runs at a time.
  • That also makes it possible to save all images as videoX-timestamp.jpg and to “log”rotate them after a while, for further viewing/reviewing during a given time window.
  • Thanks to ImageMagick, it’s also trivial to process the captured images:

     # Only keep a rectangle of width W, height H, starting at the point (X,Y):
     convert -crop WxH+X+Y capture.jpg capture.jpg
     # Include a timestamp on the top-left corner:
     convert -box white -font Fixed -draw "text 2,12 \"$timestamp\"" capture.jpg capture.jpg
    
  • Keeping a videoX-current.jpg symlink for each /dev/videoX device is trivial.

  • Add to that a lightweight webserver and a single page showing the most recent capture for each device thanks to the symlinks, with a meta refresh of say 5 seconds, and tada! Keeping an eye on multiple things at once. Of course that’s not a real video, but that can fulfill some needs.