Debian Linux Web Cam Server Configuration
The material on this page was prepared using Sarge or Etch
configured using our Installation and Packages pages.
If you did not use our pages to set up your system, what you
encounter on your system may be different than what is given here.
First and foremost, be prepared to have some patience when trying to get a USB cam to work under Linux. In trying to get mine to work, I searched many a newsgroup thread only to find there was only one message in the thread, the original question stating the problem. i.e. no one had an answer for the person who posted the question so you may be on your own trying to get your cam to work. Often times the same camera model will use different drivers for different sub-models (ex: not all QuickCam Express sub-models use the same driver). However, my trials and tribulations were a good learning experience and I'll share what I learned here to hopefully make your setup easier.
Investing the time necessary to get a cam to work may be worth it. If you set up a Linux firewall/NAT server to share your home broadband connection (we show you how on the Networking and Firewall pages), you can hook up a cam to it and keep an eye on your home from a work or vacation spot via the Internet using a Web browser. (You don't need a broadband connection in order to set up a Web cam server to play around with though). A co-worker used one to set up a "baby-cam" so he could see his new bundle of joy from the office. For businesses and organizations that wish to publish cam images on their Web site, using Linux and $20 for a cam off of eBay is an attractive alternative to spending $300 on a commercial cam unit. Modifying the firewall/NAT diagram from the Networking page, we'd have the following:
With your Debian system doing triply duty, you add in the benefits of dynamic DNS (covered on the DNS page) and you can pull up cam images from any Web browser with a URL like:
You could actually set up a Web cam server anywhere you wanted to remotely keep an eye on things. Businesses can set them up at multiple remote or "quiet" locations for surveillance and access them over a LAN. Theoretically you could also remotely keep an eye on a summer cottage, greenhouse, etc. The problem is that if you don't have a LAN or broadband connection at these locations, you won't know the external IP address of your server. Connecting via a dial-up modem gives you a different IP address every time you dial in. You could conceivably set up a shell script/cron job that would periodically 1) dial into an ISP, 2) run the client software of dyndns.org so you could use a named URL rather than an IP address to access your server, and 3) drop the ISP connection after a given length of time. Something to play around with if you're so inclined.
Remember that you can use your Debian CD set to set up as many different systems as you want. If you wanted to get fancy you could have multiple security cams in various locations without needing to have multiple firewall/Web servers. Simply set up a system for each cam that would not need to have the Apache Web server software running and have them use FTP to send the cam images to a central firewall/Web server.
With a multiple cam setup, you'd have to specify a different file name for the image files coming from the different servers (which we cover in the configuration instructions below). You would then simply modify the sample HTML code given below for the webcam.htm page to include the different image files from all of the cams so they're all viewable on a single Web page.
Remember also that Debian doesn't need much in the way of horsepower so while the above may look like quite a hardware investment, you can use old Pentium or Pentium-II systems, even notebooks if you're feeling adventurous, provided they support your cam's connectivity requirements, i.e. USB or parallel ports. (If you considering picking up some old notebooks to use for cam systems, see the Resources page for a link to linux-laptop.net where you can see if there are any articles for installing Woody on the specific make/model of notebook you're considering buying.) While old Pentium systems may not have USB ports, you can still use the old parallel port style cams with them. Keep in mind that in the multi-cam configuration shown above, the systems with the cams attached are not acting as servers. They're simply capturing cam images and acting as FTP clients when they send the images to the firewall/Web server (and the FTP client software gets installed by default).
Because the cam software uses FTP to transfer the images when the cam is on a separate system from the Web server, you'll want to provide some FTP security on the firewall/Web server by putting some good IPTABLES rules in place (as covered on the Firewall page) or use the /etc/hosts.allow and /etc/hosts.deny files associated with
tcp wrapperswhich is enabled for FTP by default. (We cover tcp wrapperson the Internet Serverspage.)
You may recall back on the Installation page at one point we went through a "module" selection routine. (The role modules play in a Linux system is covered on the
Compiling Softwarepage.) What we were doing was chosing which modules we wanted to make available for the kernel when and if they were needed. However, this module selection can be done at any time. This leads me to a second very important point; when you make changes to the USB modules REBOOT THE SYSTEM. (I probably wasted a lot of time because I had to find this out on my own.)
We're going to set up a Web cam server using the popular IBM USB
"PC Camera"(which is actually made by Xirlink) because Woody has a driver for it (and because I found a guy selling used ones on eBay for 12 bucks).
WARNING: Newer ("Model 4") IBM NetCamera and
NetCamera Promodels (22P50xx part numbers) compress the video data by default and the Linux kernel module cannot decompress it. If you're planning on using an IBM branded cam, only get the older " PC Camera" model (or the Xirlink C-It model) as shown in the picture.Logitech QuickCam Note: The QuickCam is another popular cam that is readily available on eBay. I have one and was unable to get any of the Debian-supplied drivers to work with it, even using Sarge. Please see the "Compiling A Driver Module" section near the bottom of the Compiling Software page on how to download the qc-usb source code driver and compile it with Sarge. There are many different sub-models of the QuickCam and the open source driver doesn't work with all of them. Before picking one up check out the driver page on sourceforge.net. Also note that while I got a better image with the QuickCam than the PC Camera, I sometimes got "frame lost" errors with the QuickCam when using grabber utilities that I did not get when using the PC Camera. This is a driver issue.Referring to the first diagram above, because this is a Web cam server you have to have the Apache application installed and running (we set that up on the Internet Serverspage). If you cams are connected to systems other than the Web server you'll also need to have the WU-FTP FTP server application installed and running (we installed this on the Packagespage). It would be best to set up your FTP server without anonymous FTP access for security reasons.
Setting up a Web cam server involves several steps:
- Getting the cam to produce images (drivers)
- Converting cam images to graphics files (utility)
- Setting up a Web page to use those graphics files (HTML)
Hardware and OS Setup
With setups where the cams are on systems different from the Web server, you would just need to set up Apache and WU-FTP on that server. The configuration of the cam drivers and cam software which follows is all done on each of the systems to which a cam is connected.
For Sarge (Debian 3.1 - 2.4 based kernels)
With the 2.4 kernel in Sarge I didn't have to do much of anything to get the cam recognized by the OS. USB drivers are already loaded and when I plugged in the IBM PC Camera the ibmcam driver for it (and related video drivers) loaded automatically.
If your camera driver doesn't load automatically there's a good chance you'll need to download and compile a driver for it. However, see the troubleshooting section below for some alternate drivers you can try.
For Woody (Debian 3.0 - 2.2 based kernels)
The first step is to connect the camera to a USB port. Then we install the kernel modules for USB support and the cam. At the shell prompt type in:
(as in "module configuration") and you'll see the same module selection screen you saw during the Debian install.
At the modconf main menu arrow down and highlight misc and press Enter. Arrow down again and you'll see a long list of modules including the one we want which is:Note: If you don't see the modules mentioned in the next few steps listed in the modconf screen it's likely because you didn't specify a 'vanilla' installation as instructed to do on the Installation page.
videodev - Video For Linux
This is also known as the "video4linux" or "v4l" module. With it highlighted, press Enter and when prompted for parameters just Tab to OK and press Enter. Once it's installed, select the Exit selection at the misc sub-menu to return to the main menu.
Now arrow down and highlight USB and press Enter. Arrow down again and you'll see modules for a variety of USB devices. You'll want to install the following in the order shown:
usbcore Install on all systems usb-uhci This is needed to enable USB circuitry on the motherboard so it's (Intel) system-specific. If you get errors trying to install it, try the usb-ohci or uhci drivers. ibmcam USB IBM (Xirlink) C-It Camera support. If you have another cam try the ov511 module (OV511 is a chipset that some cams, like the Creative WebCam III, are built on) or the dc2xx for those Kodak models.
You could also try both the cpia and cpia_usb drivers (both at the same time). These are under the misc category instead of the usb category and some cameras (Creative WebCam II for example) will work with these. (There's also a cpia_pp driver for parallel port camera models but be sure to also use the cpia module with it.) The c-qcam and bw-qcam modules under this category are for the parallel port QuickCam cams. A list of cameras and the drivers they use are given in
Section 4of the WebCam HOWTO at the LDP (Linux Documentation Project).
You likewise don't need to enter anything when prompted for parameters when installing these modules so just Tab to OK and press Enter. Once they're all installed, select the Exit selection at the top of the USB sub-menu and again at the main menu to exit modconf.
Now REBOOT your system. Once you get to the login prompt you can use the
Shift-PageUpkey combo to look at the messages that were displayed during the boot-up process. You should see messages related to the usb.c (core) and USB motherboard modules being loaded and detecting USB hardware.
These modules will allow the camera to talk to the Linux operating system. However, we still need to install the software that will make it work with the Apache Web server application to serve up the images. We're going to assume that you already have Apache installed and configured. If not, the
Internet Serverspage will show you how.
If you have a cam that doesn't have a driver listed, you'll have to search the Web for the appropriate driver source code and follow the instructions for using it to create a kernel module file. When doing so, remember that when using the 'vanilla' installation routine for Debian you are running the 2.2.x version of the Linux kernel.
Testing and Troubleshooting
There's a popular Linux "X" (i.e. GUI) application called xawtv that we'll use to see if the cam is working. However, you'll need to install the graphical desktop packages (which we did NOT do on the Installation page) to have GUI capability. (Before installing the GUI packages try the further steps below.) xawtv is made to work with many types of video devices, including TV tuner cards and frame buffers. As a result, getting errors when starting xawtv doesn't necessarily mean your cam won't work. It may just mean you're using a device (such as a USB cam) that doesn't support the same features as a TV tuner card.
apt-get install xawtv
will kick off the installation. You'll notice that about ten other packages will get installed which are located on the first two Debian CDs.
- You'll be asked if you want to create the "video*" special files (video0, video1, etc.). Recall that Linux treats everything like a file so we need a file in /dev that represents the cam so answer Yes to this.
- Select Yes when asked if you want to create a default configuration file.
- NTSC is the "TV norm" in the US with PAL being common in Europe and other non-US areas. If you're not sure which is proper for your country you'll have to do some Web searching to find out.
- The "frequency table" selection doesn't really concern us because we're not setting up a TV tuner card so just select whatever looks good (I used us-bcast).
- Select No when prompted to scan for TV stations.
xawtv and the other helper apps will now be set up and when it's done we're ready to try it out. xawtv is kind of strange in that it's an X application but you have to start it from a command line. As a result, we need to start up the GUI but then open an Xterm window to get at a shell prompt.
Entering startx at the shell prompt will start the GUI and give us the gray background and 'X' mouse pointer. Left-click your mouse, arrow to Debian and then XShells and select XTerm to open a console window. To minimize the possibility of access issues, make sure your mouse pointer is on the Xterm window (to give it focus) and make the cam device readable by everyone with the command:Note: You don't really need to get xawtv working to get the Web cam server working. We're using it simply to create the needed /dev/video0 device file (the"special files" referred to in the xawtv package installation). If you can't seem to get xawtv working in a Linux GUI (or you don't even have a GUI installed) and you're fairly certain the cam is OK and you've got the correct drivers loaded, simply try going onto the next couple sections to see if things still work. Just because you can't get a cam image in a Linux GUI doesn't mean it won't generate images for use in a Web page.
chmod 666 /dev/video0
That's a zero after the word 'video', not a letter 'O'. Then just enter the command:
You'll likely see error messages and then your mouse pointer will have another window attached. Place that along side the Xterm window and left-click once to open it and you should see a cam image! Right-click on the cam image and you'll open a control window.
If you don't see a cam image you've got some investigating to do. Unfortunately, since you'll see error messages in xawtv even when the cam works, those error messages and error messages from its companion utility v4l-conf may not be very helpful. One way to find out if xawtv is seeing your cam is to have it tell you. If xawtv is still running, press Control-C to end it and get your Xterm shell prompt back. At the shell prompt enter the command:
You'll see your video card listed but you should also see your cam listed as /dev/video0 or with some other number besides '0'. If you don't, the problem can be in one of two areas, USB itself (the motherboard driver) or camera (either driver or hardware). Don't discount the possibility that the cam itself is bad, especially if you bought it used. If you suspect the cam, try using on another system to see if it works on that.
If you used the Shift-PageUp procedure given earlier in this page to check your boot up messages, you may want to look at them again to make sure everything is initializing properly from a USB perspective.
You should see USB messages like "hub found" and "detected 2 ports". Correct USB messages typically indicate that the motherboard driver (usb-uhci) is correct and operating properly. If you're not getting good USB initialization messages try a different motherboard driver as indicated in the table in the previous section. You may also see that a cam driver was registered but that doesn't mean it's the correct driver. However, a message saying that your model of camera was found usually does indicate that the correct cam driver is loaded.
The lsmod will list all modules currently loaded in memory. You should see entries that match the module names you selected in modconf like so:
usbvideo (with 2.4 kernel)
This indicates that the modules are available to the kernel for its using. Again, just because the cam driver module is loaded doesn't mean anything. The wrong driver will get loaded. And if you're certain it is the right driver then you likely have a cam hardware problem. If the cam works on another system, then there's something about your X setup that xawtv doesn't like. It's possible that the number of colors for your X windows setup is too low.
8 bppis only 256 colors which may not be enough for a cam image. If 8 bppwas the highest selection available to you during the Debian installation, it's possible you don't have much memory on your video card.
You can try manually loading cam drivers using the command:
modprobe will automatically load any other required drivers like videodev and usbvideo if needed. In addition to the drivers listed in the Woody section above you could also try pwc and stv680. If they're not available you'll get "can't locate" message.
Again, the drivers will likely load (if they're available). They'll only do you any good if they're used by your cam once it's loaded. To see if this is the case use the lsmod command and see if [unused] appears on the same line as the driver name. If it does, it's not the right driver. You can remove it with the command:
Once you've got your cam working you have verified that you have a working "video4linux device" and you can exit out of xawtv. To do this, place your mouse pointer over the Xterm window (not the cam image window) to give it focus and then press
Control-Cto end xawtv. The window with the cam image (and the control window if you have it open) will close automatically and the shell prompt will return. Type in 'exit' at the shell prompt to close the console window and then exit out the GUI.
Getting Files From Images
Once we have a cam spitting out images, we need a "grabber" application that will capture those images and save them to a (typically JPG) file and put them where our Web page can use them. For that we use the webcam utility. Installing it is simply:
apt-get install webcam
The webcam package doesn't do any configuration. It doesn't even create the config file. We have to create one using the nano text editor with the command:
and enter the following into it:Recall that /var/www is the default DocumentRoot directory for Apache. The FTP user and pass can be anything because with local set to 1 FTP isn't being used. (If you have a Web server running on another system you can use the FTP option to send the image files over to it.) The delay setting is how often an image is grabbed but keep in mind the shorter you make this the higher the load on your system. The norm setting may need to be pal in Europe and other non-US locations instead of the ntsc setting shown.[ftp] host = localhost user = nobody pass = xxxxxx dir = /var/www file = webcam.jpg tmp = imageup.jpg local = 1 [grab] device = /dev/video0 width = 320 height = 240 delay = 0 input = camera norm = ntsc quality = 75 trigger = 180
If the above settings give you a cam image file that looks like it has no vertical sync (i.e. just a bunch of diagonal lines) you'll need to play around with the 'width' and 'height' settings fo find one that your cam supports. Typical width/height settings are as follows (with 352x288 and 320x240 being the commonly-used settings):For setups where the cam is on a different system than the Web server, you'd have to:
- Set the local value to 0 in the config file
- Create a new user account on the Web server for FTP image submissions
- Make sure the Web server is running the WU-FTP FTP server software and the new user account can access it from a remote system
- Give this new user account write access to the /var/www directory on the Web server
- Enter this new user account name and password for the user and pass values in the config file
- Enter the IP address of the Web server for the host value in the config file
- For the file and tmp values in the config file you'll need to use a unique value on each cam system such as webcam-garage.jpg and garage-up.jpg
So now lets see what your cam image files look like. We have to specify the configuration file when we start the program so we use the command:
webcam /etc/webcam.conf &
A bunch of stuff will start scrolling up the screen. If you see a line that says:
ftp: connect failed, sleeping 10 sec
it's likely because you either mis-typed the configuration file specifier on the command line or you're not connecting to a remote Web server. That's because it uses the information in the configuration file to connect to the locally running FTP service.
The & in the above command runs it in the background. Hitting the Enter key will get your shell prompt back so you can continue to use your system.
Now just go to another system on your network and point the browser to your Debian system's IP address and the image file like so:
If you installed Mozilla on the Debian system you could also just fire up the GUI and use it, replacing the IP address with 'localhost'.
To stop webcam from running enter the command:
to bring it to the foreground and press Control-C which will stop it and return your shell prompt.
I've found that webcam gives the images a green cast under low or incandescent light. There are a few grabber utilities out there and the documentation pretty much sucks for most of them. vgrabbj is one but there's a problem with the Debian package which I have notified the maintainer about. It doesn't install a required file. You can work around it but it's a pain. I'll keep an eye out for a better a package and update this page if I find one. Now that we're getting an image file, we need a Web page to display it on.
Auto-Updating Web Page
All we need to do is create a simple page in which we specify the same image file that we specified in the webcam.conf file. Use the command:
and enter the following into it:
<html> <head> <META HTTP-EQUIV="pragma" CONTENT="no-cache"> <META HTTP-EQUIV="refresh" CONTENT="0"> </head> <body> <center> <h2>My Web Cam</h2> <img src="webcam.jpg" width="480" height="360"> </center> </body> </html>Exit the editor saving the file and then start up webcam again. Once again, go to a different system on your network (or use Mozilla on the same system) and this time point the browser to the Web page your created like so:
Your Web page with the embedded cam image file should be displayed. Move the camera around a bit and make sure the image is updating. If your system is connected to the Internet via broadband or modem, have a distant friend or relative try to access it using the public IP address assigned via DHCP by your ISP (or your Web server's URL if you're using dynamic DNS) in place of the IP address above.
Note that the delay = 0 in the webcam configuration file will put a load on your system and the
CONTENT="0"in the META refresh tag in the Web page will eat up some bandwidth. If necessary your should use low non-zero values (2 to 5) to reduce these loads. If you don't need frequent updates you can conserve resources by using values of 10 to 15 or even 30 to 60 (set the Web page refresh time a little longer than the webcam delay time).
Setting Up An IP Camera
An IP camera is not the same as a typical "Web cam" that connects to a computer. An IP camera, also referred to as a network camera, is a stand-alone device that contains it's own internal Web server. As such, it acts like a stand-alone server.
IP cameras used to costs hundreds of dollars (and the high-end models still do). However, you can now get a low-end IP cam like the
Trendnet TV-IP100for around $85. Setting up one of these units for Internet viewing is pretty easy.
Because these cameras are self-contained Web servers, they are set to "listen" for requests on port 80 by default. However, if port 80 is already being used by your Web server we need to change that. This is easy to do because we have to go into the Configuration/Network setup menu in the camera in order to change the IP address anyway.
Note that in the above camera configuration page we set the IP address to 192.168.1.40 and set the port the camera should listen on to 8080. (You can use your own values of course.)
If you're using a commercial cable/DSL router instead of a Debian server to do things like NAT and firewalling, we need to set the cable/DSL router to route port 8080 traffic to the IP camera. Note that in the following example we assume you have a Debian server with an IP address of 192.168.1.80 acting as an Apache Web server, which listens on port 80. (We cover setting up a home Web server on the Internet Servers page.)
You can browse to your camera from your internal network by using it's IP address and port number as so:
In order to browse to the camera from the Internet you'll either need to know the external IP address of your router (the IP address assigned to you by your broadband provider) or you'll want to use your own domain name with a dynamic DNS service (see our DNS page for information on how to set that up). If you have this set up already for your Web server, then the URL would be something like:
If you want to set up multiple cameras, you'd just set each camera to use a different port, and put a corresponding entry in the router for each camera. Under this scenerio, the above diagram would be changed to the following:
You can add as many IP cams to your network as you want. You're only limitation would be the number of open ports on your hub or switch, and you can always upgrade to a 16-port switch which are going for around $65 these days. If you don't want to mess with running cables and be concerned about switch ports, the same IP cam comes in a wireless version for around $110, and a wireless pan/tilt model for $180.
Do NOT plan to use the system you will create using these guide pages as a "production" (real) server. It will NOT be secure!
There are many steps involved in creating a secure Internet or LAN server. While we do refer to some things you can do to make your system more secure, there are many other measures related to system security that also need to be taken into consideration and they are not covered on these pages.
These guide pages are meant as a learning tool only. The knowledge gained on these pages will help you understand the material covered in security-related publications when you are ready to consider setting up a production server.
Did you find this page helpful ?
If so, please help keep this site operating
by using our DVD or book pages.
Site, content, documents, original images Copyright © 2003-2016 Keith Parkansky All rights reserved
Duplication of any portion of this site or the material contained herein without
the express written consent of Keith Parkansky, USA is strictly prohibited.
This site is in no way affiliated with the Debian Project, the debian.org Web site, or
Software In The Public Interest, Inc. No endorsement of this site by the Debian Project
or Software In the Public Interest is expressed or implied. Debian and the Debian logo
are registered trademarks of Software In The Public Interest, Inc. Linux is a registered
trademark of Linus Torvalds. The Tux penguin graphic is the creation of Larry Ewing.
IN NO EVENT WILL KEITH PARKANSKY OR BLUEHOST INCORPORATED OR ANY OF ITS' SUBSIDIARIES BE LIABLE TO ANY PARTY (i) FOR ANY DIRECT, INDIRECT, SPECIAL, PUNITIVE OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, DAMAGES FOR LOSS OF BUSINESS PROFITS, BUSINESS INTERRUPTION, LOSS OF PROGRAMS OR INFORMATION, AND THE LIKE), OR ANY OTHER DAMAGES ARISING IN ANY WAY OUT OF THE AVAILABILITY, USE, RELIANCE ON, OR INABILITY TO USE THE INFORMATION, METHODS, HTML OR COMPUTER CODE, OR "KNOWLEDGE" PROVIDED ON OR THROUGH THIS WEBSITE, COMMONLY REFERRED TO AS THE "ABOUT DEBIAN" WEBSITE, OR ANY OF ITS' ASSOCIATED DOCUMENTS, DIAGRAMS, IMAGES, REPRODUCTIONS, COMPUTER EXECUTED CODE, OR ELECTRONICALLY STORED OR TRANSMITTED FILES OR GENERATED COMMUNICATIONS OR DATA EVEN IF KEITH PARKANSKY OR BLUEHOST INCORPORATED OR ANY OF ITS' SUBSIDIARIES SHALL HAVE BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES, AND REGARDLESS OF THE FORM OF ACTION, WHETHER IN CONTRACT, TORT, OR OTHERWISE; OR (ii) FOR ANY CLAIM ATTRIBUTABLE TO ERRORS, OMISSIONS, OR OTHER INACCURACIES IN, OR DESTRUCTIVE PROPERTIES OF ANY INFORMATION, METHODS, HTML OR COMPUTER CODE, OR "KNOWLEDGE" PROVIDED ON OR THROUGH THIS WEBSITE, COMMONLY REFERRED TO AS THE "ABOUT DEBIAN" WEBSITE, OR ANY OF ITS' ASSOCIATED DOCUMENTS, DIAGRAMS, IMAGES, REPRODUCTIONS, COMPUTER EXECUTED CODE, OR ELECTRONICALLY STORED, TRANSMITTED, OR GENERATED FILES, COMMUNICATIONS, OR DATA. ALL INFORMATION, METHODS, HTML OR COMPUTER CODE IS PROVIDED STRICTLY "AS IS" WITH NO GUARANTY OF ACCURACY AND/OR COMPLETENESS. USE OF THIS SITE CONSTITUTES ACCEPTANCE OF ALL STATED TERMS AND CONDITIONS.