Voyeur: How'd they do that?

To get a "live" image on the web, you need a camera and some kind of backend processing to "serve" the picture.

We started with an SGI Indy Workstartion which comes with a convenient color camera. On this machine the camera is running all the time but you need to call a special routine to "grab" an image.

The image is grabbed to disk using the SGI program vidtomem, and then converted to a gif using, imgcopy. Finally, the image is sent back to the user. This method is disk intensive and fairly slow. If someone can think of a better way to do this with the INDY's tools, we'd (webmaster) like to hear about it.

Here's the Perl script that "serves" the gif.

#!/usr/bin/perl -w

# takepic
# 8.1.95 _ MatK 
# 5.3.96 _ added $$ to all the names (thanks to Doron!)

$RAWPIC = "/var/tmp/pic$$";
$PICNAME = "/var/tmp/pic$$-00000.rgb";
$GIFNAME = "/var/tmp/pic$$.gif";
$BACKUPGIF = "/var/tmp/pic.backup.gif";

$ERR_LOG = "/var/tmp/pic-error.log";

$VIDTOMEM = "/usr/sbin/vidtomem -f $RAWPIC -c 1";
$IMGCOPY = "/usr/sbin/imgcopy $PICNAME $GIFNAME";
$DELETE = "/sbin/rm";
$COPY = "/sbin/cp";

$DATE = "/sbin/date +\"%D (%r)\"";
$CMD_PS = "/sbin/ps -ef";

sub rerror {
	my ($msg) = @_;
	my ($date) = `$DATE`;
	open (ERRh, ">>$ERR_LOG");
	print ERRh "[$$] - $date - $msg\n";
	close (ERRh);
	return 1;

# killBabys ($GID)
# Locate and kill all the processes owned by
# $GID.
sub killBabys {
	my($GID) = @_;
	my (@procs);

	open (PLIST, "$CMD_PS|");
	while () {
		if (/^\s*(\w+)\s+(\d+)\s+(\d+)\s+(\d+)\s(\d\d:\d\d:\d\d)\s+([^\s]+)\s+(\d+:\d\d)\s(.*)$/) {
			push (@procs, $2) if $3 == $GID;
	close (PLIST);
	kill 9,@procs if @procs;
	return 1;

sub giveagif {
	my ($pathName) = @_;

	# Return the gif
	&rerror("Returning backup gif.") if ($pathName eq $BACKUPGIF);
	select(STDOUT); $|=1;				#flush
	print "Content-type: image/gif\n\n";
	open (GIF, $pathName);
	while () {
	close (GIF);
	return 1;

open (STDERR, ">>/dev/null");

# Take a picture
(&rerror("[vidtomem] $?"), close(STDERR), &giveagif($BACKUPGIF), exit) if $?;

# Convert to a gif
if ($?) {
	&rerror("[imgcopy] $?");
	`$DELETE $PICNAME`;		# Just in case...
	close (STDERR);

# Delete the first temp file
(&rerror("[rm] $?"), close(STDERR), &giveagif($BACKUPGIF), exit) if $?;

# Return the gif
&giveagif ($GIFNAME);				# Return the real picture

# Create a backup file
&rerror("[cp] $?") if $?;

# Delete the temp files
`$DELETE $GIFNAME`;			# Delete the second temp file
&rerror("[rm.2] $?") if $?;

close (STDERR);

Sign the GuestBook
Ordering Information
Comments and suggestions about our website to webmaster@berksys.com