streaming webcam experiments

Still trying to find the ideal Linux webcam application, after trying camorama and most recently w3cam + a homebrew script. Frank started playing around with a streaming cam last night, so I thought I’d give it a shot, since the only reason I hadn’t before was that I couldn’t allow direct connections at home. Anyway, I compiled and installed camserv, a streaming cam app for Linux that I’d run across before. It’s a little old, but it still works great. There is one gotcha when compiling, though. I got an undefined reference to `errno' error, which this thread helped me solve. Apparently it’s some lax coding that newer versions of GCC are more strict about. To fix it, I ran grep -rs "extern int errno" * to find the files with the bad code, then opened them all in kwrite (there’s probably a better way…) and replaced all occurrences with the correct code: #include <errno.h>.

After that, the README file is great for help configuring the program. I added a banner filter to print “themikecam.com” on the image, moved the timestamp to the bottom right, and added “%D” to display the date. Remember to switch the module being used from the default color-switcher test module to video_v4l_qcam and to open up your port of choice (default is 9192) in your firewall. I keep mine pretty tightly closed since I’m apparently connected directly to the net, but I went and opened that one port in shorewall through the Mandrake Control Center.

The last issue I had was that Internet Explorer doesn’t like the streaming JPEGs that camserv produces. Luckily, it comes with a built-in workaround, accessible at http://hostip:9192/singleframe, that outputs a normal JPEG upon request. Apparently Konqueror has an issue with viewing these JPEGs as well, but Firefox/Mozilla/Netscape and Opera work fine. Any Safari users out there? I added a line to my webcam updater javascript so that real browsers can view the actual streaming feed but MSIE and Konqueror are given the singleframe image and updated by Javascript every second.

I still have a few things to figure out to my satisfaction, such as how to deal with the streaming cams when they go off and how to automatically fix a hiccup/drop in the connection. I threw together a quick fsockopen() test so that if Frank’s cam and mine aren’t accessible within seven seconds, it will timeout and output “offline” in place of our images. Previously, the problem I was having was that none of the cams would update until the browser timed out the broken image. In the future, I’d also like to make the cams page fully dynamically customizable, so the user can select what cams he/she wants to view from an index in a sidebar, which would include the realtime online/offline status of every webcam. I’m thinking perhaps a PHP script that outputs an online/offline image, so that I can use a JavaScript similar to my webcam updater to continuously update the status, possibly contained by an iframe. I’m not sure what the performance impact of all this Javascript is, but I’m certainly curious…

Tags: ,

2 Responses to “streaming webcam experiments”

  1. Rob says:

    Hiya.

    Trying to get my webpage to display “offline” when it can’t reach my webcam. In the end did you get this working?

    Thanks,

    Rob

  2. Michael says:

    Hi Rob,
    For cam images that are uploaded by FTP, there’s not much that can be done except to check the age of the current image, but I opted not to do this. For cams served from people’s home computers, I just used a bit of PHP to check if the computer was accessible, like so:

    <?php
    $tmp = fsockopen(’149.169.88.22′, 9192, $errno, $errstr, 7);
    if(!$tmp) {
    echo ‘Offline’;
    } else {
    echo ‘<img src=”http://149.169.88.22:9192/singleframe/” width=”320″ height=”240″ alt=”*The MikeCam*” name=”mike” id=”mike” />’;
    }
    ?>

Leave a Reply