Update: September 2019
It has occurred to me that I just haven't had time to actually update this site in around 6 years, so it is quite out of date. So, I have decided to start making a new one.
Bear with me, I just need to find time to put some content together :)

All posts tagged tech

SnowCam: A WebRTC experiment with getUserMedia

I’d heard about WebRTC and navigator.getUserMedia as a way to access webcams and microphones, so after I somehow ended up here the other day, I figured it should be possible to do the same in JS and HTML5.

The basic idea was to take a webcam feed, apply a falling snow effect to it, and let the snow settle on any horizontal edges in the video. Just show me already!

Connecting it all up

Getting the webcam connected up to a <;video>; tag was pretty easy, just make sure to use the right vendor prefix and take note of the slight differences between the supported browsers (Firefox Nightly, Chrome, Opera). There is a shim available called The gUM Shield, but I found that after I’d put something together.

Next step was to apply some snow, so I placed a <;canvas>; tag over the top of the <;video>; tag, found simple example of particle generation, and had some snow.

Getting the snow to settle was a bit trickier. A bit of searching revealed that I would want to use a sobel convolution filter (Nice tut here) to find the edges in the current frame, and rather than combine the results from the 2 computations (horizontal and vertical) and place onto a canvas, just take the horizontal edges and put into a hash that I can check when placing the snow flake.

My first attempt at this ran pretty damn slow, the snow effect was stuttering the whole way through. That kind of made sense since I was trying to update ~300 flakes constantly on 1 canvas, and applying a fairly heavy computation to each frame of the webcam on another. This seemed to me to be the ideal time for a WebWorker. I moved the edge detection into the worker, and then just post the resulting hash back which gets injected into the snow object, this way as the snow is falling I can just check if there is a ledge to settle on by checking this.ledges[x][y] and if it exists we can ‘stick’ to the current x,y position, otherwise assume that it is falling – this lets us wipe away the snow from ledges as well.

This works pretty well, but I’m sure it can be optimised a fair bit more – there are some extra elements I probably don’t need to use, and some processing that could be removed – but for the moment I think it’s quite cool being able to see the various stages. I’ve tested this on Firefox Nightly, and the latest version of Chrome. It does run on Opera, but very slowly – I should probably look into that…

There are a couple of enhancements I want to add at some point:

  • Snow piling up when it lands on an existing flake
  • Connect to the microphone to allow the snow to be blown away

Give it a whirl

See it in action: http://ben.periton.co.uk/exp-SnowCam
Get the code: https://github.com/benperiton/SnowCam

If you are using Firefox nightly, you will need to enable the feature:

  • Type “about:config” in the address bar and say yes that you want to make changes
  • Find the “media.navigator.enabled” entry and set it to true


Zotac ZBOX nano AD10 + XBMCbuntu + tweaks = awesome media center

I finally had enough of running XBMC on the Apple TV, it wasn’t the fastest box on the planet and the remote is not the easiest of things to use to navigate around. The last update was the proverbial straw. In order to watch Netflix in the UK I needed to update my ATV2 to a IOS 5.x version which was all cool, except that at the time there was only a tethered jailbreak. This was not such a problem until the other day when the ATV2 decided to have a fit and freeze, which needed a restart, which needed a tethered boot, which I couldn’t get going for love nor money. Signs seem to indicate a dodgy USB cable, so at some point I’ll try and sort it out, but the most obvious solution seemed to be to move to an actual computer, rather than a walled garden with a hole punched in it.

I have a Raspberry Pi arriving in the next week or so, and I briefly considered using that to run XBMC, but that seems like a waste when there are far more interesting ideas floating around in my head for it!

After some searching around for a bit I stumbled upon the Zotac ZBOX nano AD10 which seemed to offer exactly what I wanted;

  • 1080 HD
  • HD Audio
  • Gigabit LAN
  • Small form factor

The price wasn’t too bad, £189.99 – and although it doesn’t come with a HDD or RAM., it does come with a MCE remote control, USB IR extender and a VESA mount kit (with screws!) for attaching to the back of the TV.

I chucked in an old 2.5″ 160GB HDD, and 1GB or RAM and so far it seems to be screaming along! Looking at the memory usage whilst playing a 720p movie (I don’t have any 1080 to try just yet – ATV2 wouldn’t play them) it seemed to max out at ~ 720mb mark, so 1GB will probably be plenty to power it. (The box itself supports up to 4GB, so I think a new 2GB chip would be more than enough to keep it going)

For the OS I went with XBMCbuntu, it just makes sense when all the box will be used for is XBMC, why bother installing all the other crap that is not needed? The ZBOX can be booted from either an external DVD or bootable USB drive, just jump into the BIOS (hit del on boot – incidentally one of the most colourful BIOS I’ve seen!) and set up the boot order – I had to plug/unplug the USB whilst in here to get it to recognise.

So far everything has worked out of the box, apart from a couple of little bits that Im still investigating:

HD Audio [solved]
I had to change the pass-though device to be HDMI (ALSA) instead of whatever it was set to. I’m not sure if this is giving me proper HD sound, but the surround sound seems to work fine. Maybe I’ll look into this a bit more if I ever get a surround sound system that supports 8-channel LPCM output Razz

Not all remote buttons work [solved]
Some of the buttons on the remote don’t work, namely the Sleep, Wake, Teletext, Program, Windows Button, Red, Blue, Green or Yellow buttons. This can be fixed by using lirc to control the remote, rather than the kernel – as it does OOTB. You can get a few more buttons working (Sleep,Wake,Program) by running

> sudo dpkg-reconfigure lirc

and choosing Linux input layer (/dev/input/eventX) for receiver and none for transceiver. To get all the buttons working however, you can follow the instructions in my other post on Configuring the Zotac ZBOX Remote Control

Freezes on resume

Power on device using remote