Camera Hackery

@nogthree and I have been talking cameras, quite a lot.

We run these cheap as hell aliexpress cameras, and their software is both seemingly powerful but totally laughable.

We have a zoneminder instance but it requires serious hardware and hence power usage to record streams. Every ZM alternative is a paid product and not exactly leaps and bounds better.

We could try and invest in hardware decoders and all sorts of malarky but lets leave that for a more desperate hour.

The goal is to enable the lowest power method of scaleably consuming the data from these cameras.

So last night we tried using the motion capture alarm feature to start a snapshot per second feature on the camera, which it ostensibly uploads to our ftp server. This feature works, sort of. It uploads jpegs that are 500kb of nothing but zero’s. So thats what I mean by powerful but useless. Lots of features but in true china fashion nothing really works properly.

So that would have been the most scaleable as the cameras would have been doing the bulk of the work. No matter.

Next thing I tried was querying the cameras with a node script I whipped up.

var
  http = require('http'),
  Cam = require('onvif').Cam;
 
new Cam({
  hostname: "10.0.1.122", // green room camera
  username: "foo",
  password: "bar"
}, function(err) {
  this.getStreamUri({protocol:'RTSP'}, function(err, stream) {
    console.log(stream)
  });
  this.getSnapshotUri({}, function(err, snapshot) {
    console.log(snapshot)
  });
  // This throws an exception :/
  /*this.getDeviceInformation({}, function(err, response) {
    console.log(response)
  });*/
});

executed with: node script.js

This gives you some output like

{ uri: 'rtsp://10.0.1.122:554/ucast/11',
  invalidAfterConnect: false,
  invalidAfterReboot: false,
  timeout: 'PT60S' }
{ uri: 'http://10.0.1.122:80/cgi-bin/anv/images_cgi?channel=0&user=foo&pwd=bar',
  invalidAfterConnect: false,
  invalidAfterReboot: false,
  timeout: 'P1Y' }

So that is quite interesting. The rtsp stream can be opened in vlc but quickly crashes. Some googling seems to indicate that cameras change their framerate depending on light or something and that makes vlc very sad.

The take snapshot url seems to work pretty darn reliably, at least on some cameras.

So the other thing to look into is command line consumption of the rtsp stream in some way that doesnt die. I started this but my laptop ran out of battery about this point.

Some tabs of mine while researching this:

ZoneMinder/Client.pm at master · ZoneMinder/ZoneMinder

sigrand/OpenONVIF
https://github.com/sigrand/OpenONVIF

onvif

ip - Open source code exists for ONVIF video stream on camera side? (not client side) - Stack Overflow

openRTSP
http://www.live555.com/openRTSP/

linux - Capture RTSP stream from IP Camera and store - Super User

ffmpeg - How to dump raw RTSP stream to file? - Stack Overflow

osx - How can I record an rtsp video stream to a file from a linux command line? - Stack Overflow

video - rtsp stream capturing - Stack Overflow

Erlyvideo

Also, looking into playing with motion. No research there just yet.

Goals

So, the plan is to hopefully to figure out the lowest load way of putting interesting (ie movement) camera data in a format thats a nice tradeoff between the cost of power to compress and the cost of storage in s3, into an s3 bucket with some sort of easy library browsing interface on top. I’m confident I can knock up an interface quick enough, and throwing this stuff on s3 is super easy. The main issue is figuring out how to stably grab data from these cameras.

Stay tuned. If you want to help @nogthree and myself work on this little project, shout out :slight_smile:

1 Like

Did we get any figures on how much power Zoneminder actually consumes? I’d imagine if we shift the processing to the cameras, we’re just going to move the power consumption there also. The main reason Zoneminder uses so much is because it’s checking for motion, we can change the motion decection parameters which would be less sensitive, and presumably less loading.

It’s absolutely pegging the server its on atm. @nogthree can give specifics. We looked at giving it dedicated hardware but thats just a hole to pour electrons into.

Its less ‘reading from the camera’ and more transcoding the stream I’d hazard a guess? It may be because zm is doing motion detection. The cameras themselves purport to do that but no idea if it actually works.

I’m out of the loop but this sounds a bit odd to me - I ran zoneminder with motion analysis on a rather low-spec box along with other services for many years at our shop and I wouldn’t call it resource-hungry. I was only capturing about 1fps normally and 3fps with active movement (zoneminder simply polled for a jpeg from the camera).

I imagine if you’re trying to capture and analyse 24fps all the time then yes it’s going to chew some cycles, but anything that’s of interest is going to be in frame for a few seconds so high frame rates are probably unwarranted, especially if efficiency is a concern.

Just for information, the server sits at 3-5 load regularily depending on how many streams have motion in them.

We have 19 cameras running at 800x600 5fps, we still get dumb/silly visual errors and random triggers even after we’ve set the settings correctly. Zoneminder also seems to randomly lose days to weeks at a time of events for no apparent reason and is complaining that the disk is full when it is not.

The virtual box it runs on is dedicated, has 8gb of ram and 3vcpus assigned to it and it’s almost permanantly pegging that.

I think we can do better with this suggested solution.