Working with WPF and an IP camera

So I picked up a cheap tilt/pan, wireless IP camera (by Hootoo). If you’re not familiar, these just plug into the network (and then later can work wirelessly), and there is a built-in web server. From the browser interface, you can pan and tilt, and change settings, etc. For example:


The significance of an IP camera is that the video stream, controls, and still images are available via URL-like commands. For example, here are some things you can do:
This generates a snapshot using all the current camera settings
This is an MJPEG video stream that you might stream to a player that supports that video type.
This is an ASF video stream that you might stream to a player that supports that video type.
This is a tilt/pan camera – and this command tells it go to "position 1"
This is a tilt/pan camera – and this command tells it go to "position 2"

If you are using one of these Hootoo cameras, which are available everywhere – here is the API documentation (this took some time to find):

From the programming perspective:
My thinking was that I could add this to my little WPF status app. So while I’m in my office, I can see when someone pulls in the driveway, for example. Now, pulling snapshots and changing camera position were easy via this web API. Dealing with these streams has been a mess though. The MJPEG stream, I can’t seem to get anything working with. The ASF stream works in Windows Media Player, but still prompts me for credentials. Meanwhile, in WPF – the MediaElement doesn’t work with either. I spent some time researching, but ultimately didn’t find anything helpful.

So, for my purposes, I am ok with just doing periodic screen refreshes. So, I created a little ViewModel and update the image snapshot like twice per second, and bind an image to it. That should work! Well, it kind of does. The problem is that it takes the Image element some time to reload an image. This means that the picture "flickers" as it’s getting reloaded. My first thought was that the image control should have a "double-buffer" feature, but it doesn’t appear to. So, I hacked together a double-buffer to give me a better framerate.

Even that ended up not working well because sometimes I could get around 4fps while other times, I would "flip" between images ever 3 seconds, and the back image still wasn’t loaded yet. Put another way, I don’t to base this on a race-condition, and I couldn’t get any sort of reliable/flicker-free results from this approach.

So, I’ll continue to play around with this. The ultimate answer would just to be to use one of the streaming formats, because that’s a smooth 10-20fps ( I believe). So, I guess I need to figure out how to get that working with WPF.  To be continued…

Tagged with: , , , ,
Posted in .NET 4.0, Computers and Internet, New Technology, Uncategorized, WPF and MVVM
8 comments on “Working with WPF and an IP camera
  1. Bruce says:

    I have a couple of the same cameras and am using the snapshot http line embedded in a web page. Half the time though there is no image available when I load the web page so I have to manually enter the http line in the browser and refresh until I get an image. Curious if you have observed the same phenomenon.


  2. Rob Seder says:

    @Bruce – well first, this camera just stops working about once a day or so. No reason at all. I have to power cycle it to come back. Next, when I did try to snapshot.cgi – I did run into the same thing. Many of those snapshots were now valid images.

    As I understand it, this is a generic version of the Foscam IP cameras. My thought was to get a legitimate camera and see if acts any better. My ultimate end-state would be to use the videostream anyhow and I wonder if that works any better on a foscam?


    • Bruce says:

      Rob –
      Glad to hear you have noticed the same problem with snapshot.cgi. I will say that I have not had any need to reboot them daily; in fact I use them to remotely monitor a house 1000 miles away, where they are plugged in all the time. I too wonder if the Foscam brand works any better…guess I’ll buy one and see.


    • Bruce says:

      Have found a “trick” to keep the snapshot.cgi image alive – by enabling the image alarm function (even if email or FTP alarm response is not enabled) this keeps the camera active so that embedded snapshot images don’t show up as blank in the web page.


  3. Rob Seder says:

    Nice – thanks Bruce!!


  4. James says:

    You can use AForge to play the videostream.cgi with a decent frame rate, but no audio obviously.
    If you want to use the ASF stream with audio you can use the videolan vlc activeX control, but I think you need vlc properly installed.


  5. David says:

    I just found your Blog after buying one of these cameras and doing research to ‘tap’ into the camera functionality (so to speak)! Thank you very much! You had all the answers I was looking for!


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

This site uses Akismet to reduce spam. Learn how your comment data is processed.


Enter your email address to follow this blog and receive notifications of new posts by email.

Join 9 other followers

%d bloggers like this: