Franklin Heath Ltd

Master Your Information Assets

  • Categories

  • Meta

Raspberry Pi Fishcam

Posted by Craig H on 16 July 2013

I had security concerns over installing a wireless webcam to keep an eye on our goldfish. Such things are available cheaply off the shelf, typically manufactured in China, but I’m not willing to put a device of questionable provenance on our Intranet, especially not with a direct channel out to a server in China.

I started thinking about using a Raspberry Pi and Skype as an alternative solution. As (most of) the software would be open source, that way I would only have to trust Microsoft and the NSA not to interfere with the Skype server😉.

My Raspberry Pi camera module didn’t arrive until this week (the first production run sold out almost immediately back in May) and, unfortunately for the plan, Microsoft have turned off the ability to register a Skype developer account in the meantime😦. Using the Skype infrastructure with the Skypekit “headless” client would have taken advantage of all of Skype’s well-established security and routing capabilities, and the remote end could have been any device with a Skype client, but for whatever reason it seems Microsoft have decided that they don’t want people to do that.

There is a Linux security camera package called “motion”, which incorporates webcam functionality; Pi user dozencrows has adapted this to work with the MMAL interface that the Pi camera offers. Unfortunately this turned out to be too heavyweight for my purposes, using most of the CPU and giving only a low frame rate.

All I really need is to turn the camera on when a remote client connects to the Pi, transmit the video stream to be viewed on the client, and turn the camera off when the client disconnects. A venerable and admirably simple utility called “netcat” turns out to be ideal for the job:

#!/bin/sh
while true
do nc.traditional -l -p 1234 -c "exec raspivid -t 600000 -n -w 640 -h 360 -o -"
done

We are using nc.traditional, not the plain nc, because we need the “dangerous” -c option which has been taken out of the newer versions for security reasons; it’s OK, I know what I’m doing, I’m a security professional🙂.

To view the video stream, we simply connect to the Pi using the open source VLC client; this runs on most platforms including Android, Linux, MacOS and Windows. Because we are viewing a raw H.264 video stream, we have to tell VLC that by adding “:demux=h264” to the options:
VLCopts
The URL is constructed with the protocol tcp, the IP address of the Pi (you can find this out using ifconfig), and the port number 1234 that we chose in the netcat script above.

[Edit: the MacOS version of VLC lacks the “Show more options” part of the above dialogue. Fortunately there is a simpler way to specify the H.264 format, which also works on Windows, by including it in the protocol part of the URL like this:
tcp/h264://192.168.0.22:1234 .]

Fishcam1
Fishcam2

There is still plenty of scope for improvement in usability, and there is no access control, but the basic functionality is working and I’m pleased to do it entirely with open source components!

4 Responses to “Raspberry Pi Fishcam”

  1. I like the way you have routed the camera out of your case to help keep the camera pointed a certain way. I also love the lego case you have posted in your follow up article. Have you posted any details on how to build that case? It appears to have a movable cover over the camera.

    • Craig H said

      Glad you like it! We’ve been through several iterations on the Lego case, and it’s nearly there but not quite. The main case is good and sturdy, and adaptable to leave a gap for the camera cable or not. The camera module is attached with Lego hinges so it can be pointed wherever you want, but the current construction of it isn’t very robust, so I’m going to try some different-shaped pieces with it. I plan to blog about it once I’m happy with it, and we’re considering offering it as a kit on eBay (the Lego Tux penguin too if you like it :-)) and/or as a prize at Over the Air next month.

  2. Liam Kay said

    hey, i was just wondering if you knew of a way to stream audio and video at the same time, using a 3g dongle with the pi? I basically want to make a portable streaming device, something that people can connect to, to see what im upto. All the video streaming stuff i have seen is just the video, and doesnt include audio. I know that your all for the security side so only you can view the stream, which might be a good idea, as i plan on streaming it to my laptop and then using something like twitch to stream it from my laptop over the internet so that the pi doesnt get overloaded with connections. Any help would be really awesome, and thanks in advance.😛 (Y) currently i have it set up running motion (video only is better than nothing) and its powered by a battery at the minute that lasts 2 hours, i just need to get a 3g dongle and then it will be portable, but if you know of a way to stream the audio as well as the video that would be epic (Y)

    • Craig H said

      Hello Liam! Unfortunately the short answer is no, I don’t know of a way to combine audio and video streams. At first I had hopes of using Skype, the Pi camera and a USB microphone but Microsoft killed Skype for Linux on ARM, and a USB microphone takes up so much of the CPU there isn’t enough left to handle the encoding and multiplexing.

      I was playing with Koalo’s I2S audio driver and a PCM1803 breakout board but wasn’t able to get it to work; this may well be easier now the driver is included in the standard kernel and there is an official audio card available.

      Incidentally, we have used the ssh and vlc video streaming solution successfully using a 3G dongle on the Pi, so at least that part should be plain sailing🙂 Good luck!

      P.S. Do please let us know if you find a working solution, it would be great to be able to use the Pi to record and/or stream live presentations!

Leave a Reply

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

WordPress.com Logo

You are commenting using your WordPress.com 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 )

Google+ photo

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

Connecting to %s

 
%d bloggers like this: