Surveillance System - Using USB Cameras.

This project been been on my mind for quite some time, can I take an ordinary dome camera and use it as a surveillance camera? Only using USB? Was all of the fancy surveillance hardware really necessary? I was quite sure this was possible, as surveillance cameras and web cameras are essentially the same thing, just a USB powered camera. The surveillance camera does have some additional features that a webcam might not, for example night vision and automated switching between day and night modes. However the software required to drive the device and computer interface remains the same.

Buying a Camera

I order to start this project we need a surveillance camera. The list of features that was required was as follows,

  • 1080p resolution.

  • Night vision.

  • 25-30 frames per second.

  • USB connectivity.

  • Adjustable.

  • Must be waterproof.

I ended up purchasing a - ELP 3.6mm 1080P Dome Camera with IR LED Night Vision HD Webcam - from amazon. The camera has a nice build quality, easily adjustable, works immediately without installing any additional software. Excellent. More importantly its compatible with Google Chromes “Media Streams API“ - but we’ll get to this later. The camera came with all the parts required for installation - a mounting bracket, masonry plugs and screws. The only thing left to do is install it.

Mounting the Camera

The camera was positioned just to the left of the garage, getting a nice view of the drive way. The cable was fed into the roof cavity.

Testing the Camera

Once the camera was installed, I had to figure out how I wanted to view/stream the camera footage - in terms of what computer the camera was connected to and how that computer would broadcast that information to other computers. I decided on using a Raspberry Pi that I had owned for quite some time and didn’t put to use, this was especially convenient considering that it had to placed in the roof in close proximity to the camera. After testing the camera at night time it became immediately obvious that additional IR illumination was required, the little IR LEDs in the camera just don’t provide enough light to see anything one metre past the camera. Obviously this wasn’t good enough. To resolve this issue I bought an IR illuminator from amazon - QC3654 50M Infrared Spotlight IR Illuminator, installation was exactly the same as the camera.

Night vision issues resolved.

Once the illuminator was installed figures are visible up to the footpath.

Streaming Video

Video is being streamed from the camera in two ways,

  1. A live stream that can be viewed on mobile and desktop with reduced resolution (720p) and frame rate (15fps).

  2. A segmented stream with higher resolution (1080p) and faster frame rates (25fps). This cannot be viewed live.

VLC was used for the live stream - is there anything it can’t do? This is as simple as running a command on the computer connected to the camera.

cvlc -vvv v4l2:///dev/video0:chroma=mp2v --v4l2-width 1280 --v4l2-height 720 --v4l2-fps 30 --sout '#transcode{vcodec=mp2v,acodec=none,fps=30,sfilter=marq{marquee="%Y-%m-%d,%H:%M:%S",position=9,color=0xFFFFFF,size=12}}:http{mux=ts,dst=192.168.1.158:8889}'

The above command will setup a 720p stream running at 30fps - more like 15fps - with a timestamp in the lower left hand corner of the frame. VLC will listen for connections on the local address of 192.168.1.158 using port 8889. Client devices (mobile, desktop) can watch the stream via the VLC application. For example I’m currently converting the stream and saving it on my desktop.

Surveillance Application

While VLC is fantastic and provides a means for most people to view and stream their camera’s footage, I wasn’t really happy with the reduced resolution and frame rate. So I decided to try and use the MediaRecorder API - which is available to all modern web browsers - to build a relatively simple application using ReactJS, which sends video data to a RESTful PHP back end for processing and storage. Video is captured in 10 second long segments which is then stitched back together in post processing. Media can then be downloaded or streamed from the server over HTTP.

Conclusion

Not only was it possible to use a USB camera as a surveillance camera, it really wasn’t that difficult. The camera performs quite well actually, especially using the custom Javascript implementation to drive the camera. I’m not sure that purchasing more expensive hardware would produce a better result. The most important aspect of this project is that it was completely DIY - no electricians or tradesmen were required, the illuminator is powered via an AC plug. The hardest part of the project was mounting the hardware, feeding the cables around the frame of the house was a pain. It’s also possible to not use either VLC or Google Chrome to drive the camera, you can just use the v4l2 (Video For Linux 2) drivers and develop a C executable.

Developing a Web Browser - Part 1 - Text Elements

Seeking Better Internet - Switching to Starlink