how to scrape AXIS webcams with Processing

processing.org — nik @ 5:38 pm

axis

AXIS webcams are fun to play with because they are generally pretty easy to google, have fast feeds (depending), and sometimes allow user control. Of the thousands of AXIS cams online many of them are public. A somewhat well known trick to turn up thousands of AXIS cameras is to google for:

intitle:"Live View / - AXIS" | inurl:view/view.shtml^

Which will turn up thousands of (mostly) boring feeds. Every once in a while however, something really interesting turns up that you may want to scrape for some reason or another. The typical URL result for the cam is something like:

http://191.22.175.200/view/view.shtml (this URL doesn't work btw)

Which sometimes displays an image in mjpeg format and sometimes displayed with a cgi script. A cool thing the cams do (and cool if you want to scrape) is catalogue all previous images on a server somewhere. This means that if the cam is displaying a mjpeg which is a pain to deal with, never fear! To access plain ol’ jpegs from AXIS web software you need to look here:

http://191.22.175.200/jpg/1/image.jpg?(UNIX TIME)

Where the Unix time is generally a big number. This makes the whole process pretty simple from here on out, as that is simply the location you need to query to get fairly up-to-date images from that camera. The directory structures sometimes change, and sometimes finding the jpeg URL is as simple as viewing the source of the AXIS camera page. Also, especially on faster camera feeds, the main AXIS page occasionally links to a mjpeg which is tricky to deal with.

Processing sketch:

//scrape AXIS web cameras with processing.
//please don't be a jerk with this sketch.

import java.util.Date;
PImage cam;
Date d;
float last_millis;

void setup(){
  size(320,240);
  d = new Date();
}

void draw(){
  cam = loadImage("http://somedomain/jpg/1/image.jpg?"+d.getTime());
  image(cam, 0,0,320, 240);
  last_millis = last_millis - millis();
  println(last_millis);
  last_millis = millis();
}

Pretty simple right? All the math with milliseconds can be deleted, the code is there to see the difference in time between the last time an image was downloaded. Downloading discreet jpegs causes some lag and is a lot slower than using a conventional browser. Also, remember that d.getTime() gets the current Unix time — you can always change that to whatever, assuming the webcam existed at that point.

all these triangles!

processing.org — nik @ 4:10 pm

yay! Finally uploaded something with fine lines to vimeo that didn’t get entirely screwed up by the compression process. Animation Codec @ 720×480 with lots of keyframes seems to do okay.

all these triangles! from nik hanselmann on Vimeo.

working out these blocks

processing.org — nik @ 5:41 pm

working out these blocks from nik hanselmann on Vimeo.

simpler times from nik hanselmann on Vimeo.

This work is licensed under a Creative Commons Attribution-Noncommercial-Share Alike 3.0 Unported License.
(c) 2010 nik’s blog | powered by WordPress with Barecity