Running a Webcam

What Do I Need

Here are some initial hurdles before you can use WebCamApplet. I assume:

OK, I lied here are some more, your camera/software must do ONE of the following:

Maybe $10 for that camera really was too good to be true...

How Do I Serve The Image?

This is the hard part.

I know how to do this, take me to the examples!

Take a deep breath, it might not be that bad. First a little diversion...

You need to understand that WebCamApplet (being an applet) runs in a web page i.e. directly within someone else browser. But, since your webcam is here on your PC it needs to access your camera remotely. It does this via a url, say http://myserver/me/cam/image.jpg (I made that up, no really).

So far so good then. But there are many very sensible constraints placed upon an applet when it's running in a web browser. One of these is that it cannot merrily collect your credit card details and holiday snaps and post them for sale on eBay.

While you'd be mad to do so, you might keep all your secrets in a web page (don't laugh) that's only visible, you hope, behind your firewall. All modern companies do this. I said don't laugh.

If applets were allowed to freely access any url then you might inadvertently browse to a site that loaded a malicious applet into your web page. If it can see (and post to) any url then it can see your holiday snaps and eBay at the same time. Enough said, what's the reserve price?

This is prevented by a very simple mechanism: applets are absolutely prevented by the browser from accessing files/urls that come from ANYWHERE EXCEPT where the applet was downloaded from.

Why was I telling you all this? Oh yes, I remember... it means that wherever on your web site you put the WebCamApplet files, the image from your webcam must go in the same place. Or it just won't work, at all. Ever.

And this is where all the complexity lies.

Firstly you need to look at the software that came supplied with your webcam and see what it can do. With that in mind you can decide how your webcam and WebCamApplet are going to co-habit.

There are several ways to do this depending on your circumstances, skill levels and wallet thickness:

1. Image Uploading

This works by running an application that uploads images from your camera (or a file saved by your camera) to your web site.

This is fairly secure since you're not running a web server on your machine.

One of the downsides is that even though your camera may be off, everyone sees the last image uploaded - indefinitely. So your webcam mostly displays a selection of images involving you turning off your PC, remember to smile.

Also, it's wasteful of bandwidth that you might be paying for, since it sends the images even if nobody is watching and keeps the connection up forever. Bad for modem/ISDN users.

There are lots of free, shareware and commercial applications that do this though. Here are some on SourceForge:

Capcam- V4L
Cam Quicky

Obviously if you're automatically uploading the image you can choose to drop it in the same directory as WebCamApplet and everything will be fine.

2. Direct Serving

This way the image is served directly(ish) from your PC. It's efficient in that image data is only sent when someone is viewing but it brings with it all of the security problems associated with running a web server. The only safe web server is an uninstalled web server, but some are less unsafe than others. Choose wisely and, make up your own mind which one to use.

2.a Direct Serving From a Saved File

If your camera can save it's images as a file every few seconds then you should be able to configure it to drop the file in the right place. You would put the image directly into the directory where WebCamApplet lives and will be served from.

2.b Direct Serving From the Cameras Server

If your camera comes with it's own custom web server then you need to create your web page and publish it to this server. Remember that the image must be with the applet so you'll need to consult the documentation to see how to achieve this.

2.c Proxying the Image

Maybe your camera comes with a server (as in 2.b) but you can't publish to it, can't publish to the right place or you simply don't want to run a full web server on the machine that has the camera.

WebCam 2000 is an example of a good, easy to use and free Windows image server that won't serve anything except the image from a camera.

In these circumstances you might wish to "proxy" the image to get around these problems. This means configuring some other web server to present a fake image that is linked (in the mind of the web server) to the real image source, possibly on another machine.

Certainly Apache can do this so no doubt other servers can too.

Remember to put this proxied image in the same place as WebCamApplet.

How Do I Use WebCam Applet?

So, by fair means or foul you've achieved at the following:

You need to copy the webcamappletXXXX.jar file (where XXXX is the version) to dir.

Now all you need to is create a web page in dir in which will contain your web cam, paste in the HTML tags from one of the examples and modify them as appropriate.

(In fact you can have your HTML somewhere else, it's only the applet in it's jar file that needs to be in dir. But my fingers are tired, so you can read more about applets and the <applet> tag here)

WebCamApplet Examples


HTML For The <applet>

The HTML below is an example of what you'll need. You can find live examples here.

Note that in this example the images served are all 160x120. With a label height of 20 pixels. That means the height of the applet must be 140 pixels if you want to see the whole image.

<applet code="org.webcamapplet.WebCamApplet0_1_1.class" archive="webcamapplet0_1_1.jar" name="Applet1" width="160" height="140" VIEWASTEXT>
<param name=width value="160">
<param name=height value="140">
<param name=labelHeight value="20">
<param name=delayMillis value="6000">
<param name=camRetrySecs value="20">
<param name=camviewLimitMins value="2">
<param name="labelReloadSecs" value="3">
<param name="title" value="Example 1">
<param name=onImage value="camview.jpg">
<param name=offImage value="offimage.jpg">
<param name=limitImage value="limitimage.jpg">
<param name=click value="">
<param name=logging value="false">

Parameter Descriptions

width: The same as the width in the applet tag (won't be needed soon).

height: The same as the height in the applet tag (won't be needed soon).

labelHeight: The height in pixels of the label at the bottom of the applet.

delayMillis: A badly named parameter. It represents not a delay, but the MAXIMUM FREQUENCY (in milliseconds, 1000 = 1 second) that the applet will attempt to get a fresh image. There's no point being optimistic, if it takes 3 seconds for the applet to fetch the image then setting this parameter to less than 3000 will have no effect. You may also want to protect your server from thousands of applets all sucking images as fast as they can.

camviewLimitMins: The number of minutes the applet will operate for before turning off and just displaying limitimage.jpg. If the web page is reloaded then the timer starts from scratch. This is not so much a privacy feature but to avoid the applet wasting bandwidth if someone starts up your webcam and then goes on holiday to Neptune.

camRetrySecs: If your camera is turned off, this is the interval that the applet uses to continuously re-check and see if the camera is back on. If you habitually turn the camera off for hours at a time then there's not much point in having a really low value, say 10 seconds or less. There's also not much point in a hugely high value, say approaching camviewLimitMins.

labelReloadSecs: The frequency with which the label contents changes.

title: A custom value for the label. This will be shown after the frames per second value and version number.

onImage: The URL of your cameras jpeg file/stream.

offImage: The URL of the image shown if your camera is off.

limitImage: The URL of the image shown after camRetrySecs has elapsed.

click: The URL launched in a new browser window if the applet is clicked on.

logging: true or false. Turns on logging of the applets internals in the Java console