An Adventure In Setting Up a WebCam on a FreeBSD Home Box
The purpose of this document is to share my experience of setting up a webcam on a FreeBSD home box - with really inexpensive gear. The need for such a record is predicated upon the obvious void of such information on the Internet. I (I hesitate to say) sent a number of questions to comp.unix.bsd.freebsd.misc and I think I stumped the folks who read them. Isn't that how one interprets "no answer?" Maybe The questions were just too basic to dignify answers. Nevertheless, it was a profitable exercise.
Here is my pertinent gear:
IBM low-end Aptiva computer.
A TV Tuner card is one in which a person can stream a TV signal into his/her computer. It is useful for that purpose; but you can also plug a camcorder into it. That feature makes it a nice solution for setting up a webcam.
Hooking up the tuner card is fairly easy. Information on the driver is found at http://vulture.dmem.strath.ac.uk/bt848/. Since the website doesn't really explain too well what to do - except for some instructions that will cause you to waste about half an hour, here's the rundown. Current versions of FreeBSD have the booktree (bt) driver already in the source. All you need to do to get it up and running is add the line
device bktrto your kernel configuration file and compile/install the new kernel. It may also be necessary to
/dev/MAKEDEV bktr0FXTV is a nice viewer software. It is in the ports collection in the Graphics section. FXTV is not required for this topic; but it is nice for testing the functionality of your setup.
The ports collection contains a powerful software called Camserv (also under /usr/ports/graphics). Its purpose is to provide a streaming signal from a server. The basis for the software is that you have control over what software runs on the web server. Me? I'm one of those fellows who pays $20 a month for a modem connection to my Internet Service Provider; and I get a couple gigs of web space to boot. I studied the software for a while ("how long" shall remain classified) and noticed that it can be configured to launch, take one snapshot and exit.
That's exactly what I needed! I could take a snapshot every so often and automatically "ftp" it to my website. That was the plan. Writing a script to automatically update my website was another challenge that I will discuss below. First I will detail my configuration of Camserv.
Configuring Camserv to Take a Single Shot
If you install Camserv from the ports, the configuration file is located at /usr/local/share/camserv.cfg. Since my camcorder plugs into the video plug on the tuner card, I changed the "port" line to read:
Then, way down at the bottom of the configuration file there is the [main] section. I un-commented the "output_snapfile" line and specified a file name and location. For me, that is:
To try it, I just opened up a terminal emulation window and typed:
It ran briefly and terminated. I checked my specified path (/usr/save/website/earthlink/) to see if my camera shot was there. It was!
I discovered that the picture was often kind of garbled but a followup was always sharp; so I modified the "output_presnaps" line to read:
which resolved that problem.
Automatic FTP Upload
I had a great deal of difficulty trying to find a way to write a script that will automatically handle uploading this picture. I solved it with a program written by the NetBSD guys. It is called lukemftp; and it is in the ports collection (under ftp). Lukemftp has what I have found to be a rare feature of being able to non-interactively upload one or more files. Lukemftp is horribly documented (be sure to check man lukemftp!) so I will save you the trial and error by just showing you my script. This script takes a picture using camserv. It then non-interactively logs into the ftp site at my ISP, uploads the file and terminates the ftp session. The username represents an actual user name, and the stars (***) represent an actual password.
I set up a little web page on my web space:
As you see, the script does its thing every 45 seconds. The web document updates itself every 60 seconds. This sequence makes for a nice refresh that doesn't hog a lot of bandwidth for a regular 56K connection. (Plus, I don't feel guilty logging on and off overly frequently.) Once the web page is on location, all I do is fire up the script and I'm in business!
It has since come to my attention that it is possible to configure the standard ftp program to non-interactively upload a file. The setup is a little less straigthforward; but it may be worth pursuing in order to avoid installing a waggonload of programs that all do nearly the same thing.
Alternatively, as several unix gurus offered (after I already put lukemftp into use), a program called ncftp has a number of easy to use tools, including the well-documented feature of non-interactively uploading files.
I just recently noticed a program on my system called webcam. I did a little digging and, according to the man page, it handles just about the same stuff as my little setup. You may want to check it out as an alternative. This is unix. There is never one solution and there probably is never an "always best for everyone" solution either. There are solutions that get the job done for any particular quirky need and that is why unix is so powerful. This webcam tool is automatically included with the xawtv package.