Topic: Webcams that require authentication

Is there a way to receive a stream from a networked webcam that requires a userid/password for authentication?

2 (edited by gingerbeardman 2008-03-25 10:39:02)

Re: Webcams that require authentication

Have you tried putting the username and password in the URL?

http(s):// username : password @ server / resource . ext

eg.
http://username:password@your.webcam.com
http://username:password@192.168.1.123

Let me know how you get on.
matt

Re: Webcams that require authentication

That worked fine...thanks!

Re: Webcams that require authentication

OK, authorization works but is there a widget  I can use to get access to an AXIS networked webcam?  The Sample Webcam widget can't be used because it assumes that the cam is on a machine that can have the crossdomain.xml file.   Is there another widget that can receive a live stream from such a camera?

Re: Webcams that require authentication

The Sample Webcam widget can fetch from anywhere that feeds a JPEG - crossdomain.xml files are not required to fetch JPEGs

Re: Webcams that require authentication

hmm...I believe you but the comments in the samplecam code say otherwise ("// Note that the site hosting the cam must allow Flash access
// from arbitrary domains, typically by using a "crossdomain.xml" file". However, if crossdoman.xml is not required then I don't know what I've done wrong. All id did was  change the URL to my camera (after testing the URL in a browser) and I get "Error opening URL 'http:...'.

Re: Webcams that require authentication

That's an error in the comments - I'll correct that.

Re: Webcams that require authentication

Thanks.  Unfortunately, it appears that Flash does not support the full syntax (userid:password@ipaddress:port/path).  There is a  suggested workaround <http://meidell.dk/archives/2005/12/30/h … ith-flash/>  but with my limited AS experience, I have not gotten this to work.  It would be nice if the Samplecam and chumbyspy widgets were both able to accept the complete URL specification.

9 (edited by gingerbeardman 2008-04-01 04:37:31)

Re: Webcams that require authentication

Hmm.

It seems flash only allows HTTP authentication with loadVars or XML loading. Not with loadMovie...

You could try makign a PHP script that will do the authentication for you. That would "log in" for your widget, and then your loadMovie request might work. An added benefit of that approach, if it works, is that your widget swf would not contain your username and password.

Flash 9/ActionScript 3 has URLRequestHeader and more that would make life easier, not sure about what Flash Lite has feature wise.

matt

10

Re: Webcams that require authentication

Thanks...I'll add PHP to my list :-)

11 (edited by gingerbeardman 2008-04-01 07:38:27)

Re: Webcams that require authentication

Here's some PHP that will grab an image from a password protected location and return it is if it was at the location of the PHP script.

Usage: http://crossdomain.enabled.website.com/this.php
Result: JPEG image from webcam displayed

<?php
header('Content-type: image/jpeg');
echo file_get_contents('http://username:password@your.webcam.com:port');
?>

I've just tested this modified version (cURL is needed if your host disables certain PHP features realting to file_get_contents, as mine does). I use similar code to this in scripts for some of my widgets.

<?php
header('Content-type: image/jpeg');
echo curl_file_get_contents('http://username:password@your.webcam.com:port');

function curl_file_get_contents($url) {
    $ch = curl_init();
    $timeout = 0; // zero means no timeout
    
    curl_setopt ($ch, CURLOPT_URL, $url);
    curl_setopt ($ch, CURLOPT_CONNECTTIMEOUT, $timeout);

    // Getting binary data
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
    
    // execute the file download
    $file_contents = curl_exec($ch);
    curl_close($ch);

    // return file contents
    return $file_contents;
}
?>

Let me know how you get on.

matt

Re: Webcams that require authentication

Where would you put this PHP code? On the Chumby? If so, possible to explain more how this works?

13

Re: Webcams that require authentication

Excellent! That worked great!  Now I have to figure out how to resize the image dynamically from 640x480 to 320x240.  Of course this method is trading security by userid:password to security by obscurity since the camera is accessible with no password if you know the URL.

In answer to wrybread,  the snippet of php and the crossdomain.xml file are on the server to which your widget points.

14

Re: Webcams that require authentication

It appears that the crossdomain.xml is NOT required.

15 (edited by gingerbeardman 2008-04-01 15:07:09)

Re: Webcams that require authentication

No crossdomain.xml for JPEGs it seems.

I understand it is security through obscurity, perhaps there are ways to improve it with more though? Would a *.chumby.com crossdomain.xml not stop accesses from anywhere other than the widget?

It's better to resize the image through PHP, and put the load on the server rather than the Chumby. Resizing in Flash is not good quality, and slow. PHP gives better quality and the server will do it much quicker.

I did this for one of my widgets... It gets a bit tricky, because you have to save the webcam jpeg to a local file on your server, and then run that through some image manipulation commands, imagecopyresampled being the main one. There is some sample code on that page that should help you out a lot.

Happy to help,
matt

Re: Webcams that require authentication

I still don't understand where you're running this PHP from, but I've found scaling the image on the Chumby from Flash works just fine:

http://livedocs.adobe.com/flash/9.0/mai … 00334.html

For example, to scale a movie clip called "newone" by 50%:

newone._yscale = 50;
newone._xscale = 50;
       
My ChumbySpy widget scales all the images it downloads to 320x240 and doesn't seem to overload or slow down the Chumby.
   
Any interest in posting your FLA?

Re: Webcams that require authentication

To my eyes, the quality of the resized image on the Chumby was less than when I resized on the server. I was resizing a GIF illustration, though, the effects may not be as noticable with JPEGs photos.

Take a look at my Ceefax viewer widget in the Virtual Chumby (small or medium sized, so it's resized down). I changed to server-side resizing, and eventually to pre-prepared resized images for my widget "My Life as a Cloud"

Re: Webcams that require authentication

Trading quality for performance, Flash Lite uses "nearest neighbor" sampling when scaling bitmaps - this means the scaling produces lower quality that desktop Flash doing the same thing.  It's best to create bitmaps at the size you intend to display them on the device.

Re: Webcams that require authentication

Thanks for confirming my suspicions, Duane.

Is there any place I can look for more info on Flash Lite and it's supported command set and changes over desktop Flash?

Re: Webcams that require authentication

I think there's a white paper on Adobe's site somewhere.  I'll see if I can find it.

Re: Webcams that require authentication

Thanks Duane

Re: Webcams that require authentication

Before I give up, I thought I'd ask here:

Is there any way to build a widget for the Chumby that displays data from a password-protected webcam without requiring a PHP script to do the authentication? I was hoping to create a general-purpose personal webcam widget (for security, pet-watching, etc.). Asking people to allow anonymous access to their cameras  is not an option and, for most Chumby users, neither is requiring access to a webhost.

Thanks for any help you can offer.

Mark

Re: Webcams that require authentication

mwickens wrote:

Is there any way to build a widget for the Chumby that displays data from a password-protected webcam without requiring a PHP script to do the authentication?

That all depends upon the type of authentication being employed.

Re: Webcams that require authentication

That all depends upon the type of authentication being employed.

Yeah, sorry. I mean HTTP basic authentication.

I've pretty much resigned myself to doing a widget that requires either an open webcam or a server-side script to do the authentication. I would even have considered using sockets for the authentication, but the HTTP servers built into most webcams don't support installation of a cross-domain policy file, which socket communications apparently require.

Mark

25 (edited by josep 2008-05-20 21:35:55)

Re: Webcams that require authentication

Hi mwickens,

This widget sounds great. Do you have a list of cameras your widget supports so far? I have been trying to get documentation on Zonet's API, but have not found anything yet. I find that Panasonic and Axis have very good documentation.

Thanks,
J