OffBeatMammal

Searching for monkeys in Cyberspace

Webcams and the command line

clock December 31, 2008 13:26 by author OffBeatMammal

After my initial playing with a webcam and weather related time lapse I got a second hand wireless webcam (a Linksys WVC54GC) to play with. As a package it's really easy to set up and connect to the camera and stream video either using their supplied app or Windows Media player. But no use for getting snapshots as user controlled intervals and putting timestamp overlays on them etc.

That left me with a couple of choices:

  • Buy an application to do it (but frankly after looking at some of the options I decided they didn't offer much value - when the software costs more than the camera I expect more from them!)
  • Build my own.

Now, a few years ago when I was developing code on a daily basis that would possibly have been the easiest.... whip up something to connect to the stream, grab a frame, overlay the timestamp and FTP it to the destination.

Today I'm lazier, and anyway the bits I need to do this are all available for free - I just need to tie them together with the command line and they set up a scheduled task to make them run.

Grabbing the stream

The first challenge was connecting to the stream and grabbing a jpg snapshot that I could work with.

Using MPlayer grabbing the frame didn't turn out to be too much of a challenge. It allows you to attach to a streaming video and pull a number of frame to save as a JPEG

mplayer.exe http://{userid}:{password}@{camera_ip}/img/video.asf -frames 1 -vo jpeg:quality=100:maxfiles=1

Every time this runs it connects to the WiFi Camera video stream and grabs a single, high quality, jpg image (by default saved as 00000001.jpg each time - thanks to the maxfiles parameter)

I used this version of MPlayer built for Windows as it installs and updates easily.

Annotating the image

The next challenge was adding the timestamp to the image to give it some context. This actually gave me two challenges - adding the timestamp and formatting the date correctly from a command line script.

The first was solved with the RunNow.vbs script which allows you to define a number of environment variables for a command line script. I needed to add my own additional environment variable so don't forget to add this to the script

'MonthName
objEnv("MN") = MonthName(Month(dNow))

Next of course was the challenge of actually updating the image itself. For that I turned to ImageMagick a tool I've used before to add text and effects to images. This gives you a number of options for adding a caption to an image.

convert -background "#00000080" -fill white label:"%DOWN% %MN% %Day%, %Year% @ %Hour%:%Minute%:%Second%" miff:- | composite -gravity south -geometry +0+3 - 00000001.jpg image.jpg

This rather scary line takes the source image 00000001.jpg (created from Mplayer) and adds a label using the parameters to position where I want it. The variables %DOWN% etc are all supplied by running this via the RunNow script.

Uploading the image

When the image was composited I wanted to upload it to the Weather Underground site.

Windows comes with a built in command line FTP client, but the Weather Underground server wanted a passive connection which the supplied client doesn't support so I used the free version of MoveIt from Ipswitch - a secure FTP command line client that is a 'drop in' replacement for the existing client.

All I needed to do was create a parameter file to control the FTP script (I saved the script as wificam.ftp)

open webcam.wunderground.com
{username}
{password}
passive
type binary
put image.jpg image.jpg
bye

and call that from the command line

ftps -s:wificam.ftp

Automating execution

Now I had the pieces it was simple enough to create a Scheduled Task that runs every 10 minutes and executes

RunNow.vbs wificam.cmd

the wificam.cmd script contains the call to Mplayer to grab the frame, the call to ImageMagick to add the caption and the call to MoveIt to use FTP to upload the new image.

The results

Every ten minutes the webcam should upload a new image to Weather Underground here, and they create a stop motion view (last 24 hours below).

 

A quick note on the WVC54GC: While it's an okay camera for the job I can't recommend it. The Linksys software is pretty horrible and the specs on the camera are at the lower end of the spectrum - small image size/resolution and really bad low light performance. I know they have better cameras now so look to spend a few extra bucks.



Snowpocalypse 2008 - 10 days in 100 seconds

clock December 29, 2008 11:15 by author offbeatmammal

After my last little experiment creating the stop motion weather watch I wanted to put one together to cover the whole of "Snowpocalypse 2008" as the White Christmas here in Seattle has been tagged.

I used the same tools as before... the webcam had been happily snapping away once a minute and storing the images on the Windows Home Server so I had the source material, but the biggest challenge was to get the 15,000 images displayed quickly enough to be interesting but not so jerky as to be un-watchable. I won't say 8 years working with some very smart TV production teams has actually rubbed off but after some fiddling around the idea of 10 days in 100 seconds seemed to work, so here for your pleasure:

To generate this I took images 5 minutes apart and created an uncompressed 30FPS AVI. The resulting AVI was almost 4GB which obviously isn't practical for streaming on the web (and bigger than the 105MB per file limit for free accounts on Live Streaming!) so I turned to another tool - Windows Media Encoder - to convert the file to a WMV at DVD quality which took me down to 25MB (quite a difference, but remember the AVI was uncompressed and the WMV was a two pass, variable bit-rate encode so heavily optimized).

As it turned out I ended up 4 seconds short of the full 100, but please permit me some artistic license (I should had added a credit roll!)

All this messing about looking at the weather has got me wondering more about what patterns are really like here in the Pacific Northwest so as well as becoming a regular reader of Cliff Mass' musings on the weather Rhiannon and I have ordered our own weatherstation to put in the garden (and started sharing images at Weather Underground as well as the Webcam page here in advance of the hardware arriving!)



Snow days and life at Microsoft

clock December 18, 2008 12:13 by author offbeatmammal

20 years ago when I started working a snow day would have meant the world grinds to a halt.

Today thanks to the wonders of the electronic office I still have access to most of the corporate resources I need to be productive and I don't have to leave home... which is a good thing given the weather!

Thanks to the weather over the last few days a bunch of meetings got canceled I had a chance to catch up on some reading and play with some things...

It's times like this that remind me just what the reach of the Microsoft eco-system is. I'm not talking about the fact I can work from home but the range of tools and technologies that enable pretty much anything you want.

The video above was created in the following way

Apart from the webcam and the Home Server everything is free software. It might not be the most elegant solution but I found all the bits and got it up and running (thanks to Live Search) in about half an hour.

I think folks too often just see Microsoft as a big monolith (even some people who work there!) but it's moments like this, and sites like Microspotting and View<myWorld> and of course some of the more pragmatic 'softees that remind us there's a lot more hidden away both internally and from folks building cool stuff in the community.



Search

Calendar

<<  May 2013  >>
SuMoTuWeThFrSa
2829301234
567891011
12131415161718
19202122232425
2627282930311
2345678

Sign in

Twitter


    follow OffBeatMammal at http://twitter.com



     
    Donate unused CPU cycles with BOINC Stats and Account Management from BOINCStats.com



    Blogroll

    Archive

    Tags

    Categories


    Disclaimer

    The opinions expressed herein are my own personal opinions and do not represent my employer's view in anyway.

    © Copyright 2013