Table of Contents

Webcam Usage with Linux

I have a webcam Philips ToU Cam Pro II PCVC 840K which can be easily used with Linux.

Installation

Installation is straightforward, there is pwc, a Kernel module which can be either compiled by oneself or, in case of Gentoo Linux, there's an ebuild for it.

emerge -av media-video/usb-pwc-re

Streaming

mplayer tv:// -vf-pre pp=hb:a/vb:a/dr:a/al:a,hqdn3d -tv \
  driver=v4l:device=/dev/video0:width=640:height=480:noaudio

Single Picture

vidcat -d /dev/video0 -py  -f png -o bild.png

Recording

mencoder tv:// -vf-pre pp=hb:a/vb:a/dr:a/al:a,hqdn3d -tv \
  driver=v4l:device=/dev/video0:width=640:height=480:noaudio -ovc lavc -o webcam.avi

Uploading to a remote server

#!/bin/bash
#
# Taking a webcam picture and upload to remote server
# Use SSH Key authentication to avoid password prompts
# Roland Eckert <roland.eckert ;-) gmail.com>
#
 
REMOTEUSER=johndoe
REMOTEHOST=example.com
PNAME="webcam_`date +%F_%H-%M-%S`.png"
SOURCEFOLDER="/tmp/webcam/`date +%Y-%m-%d`"
SOURCEFILE="$SOURCEFOLDER/$PNAME"
REMOTEFOLDER="/www/example.com/webcam/"
 
# test if folder exists
if [ ! -d ${SOURCEFOLDER} ]; then
  mkdir -p ${SOURCEFOLDER}
fi
 
# set pwc settings
setpwc -d /dev/video0 -w auto -i 100 > /dev/null 2>&1
 
# take picture
vidcat -d /dev/video0 -py -f png -q 85 -s 640x480 -o $SOURCEFILE
 
# transfer picture
/usr/bin/rsync --quiet --archive --compress --checksum --no-blocking-io -r \
  $SOURCEFOLDER $REMOTEUSER@$REMOTEHOST:$REMOTEFOLDER
 
# remove picture
rm $SOURCEFILE

Viewing webcam pictures

I use a script to generate thumbnails and for easy viewing, called Thumbnail AutoIndex/2.0 PHP, link see below.