Flamebaiters

Not to be mistaken for the common internet troll, the flamebaiter will post articles and comments that are unnecessarily provocative or offensive in order to attract traffic.

Many forums have died over the years as they started to self-radicalize. As the forum attracts people who think alike, and start to repel dissenting voices, the participants get increasingly convinced that the forums ideas represent the true order of things.

Every active participant, in almost any blog or forum, has an agenda. The most honest thing, in my opinion, is to state your agenda clearly. That puts your posts in the correct context.

Advertisements

Motion Detection on the Edge

When we design a surveillance system, we need to carefully consider how we allocate resources and distribute workloads. When you add a camera to an NVR, the most common use is to reduce the camera to a fairly dumb “video transmitter” and then let the server do the heavy lifting.

But even if the server is much, much more powerful than your humble IP camera, it is usually taxed with a lot of work. One of the tasks the server routinely carries out is to do what some folks call “motion detection”. The term is usually misleading as the NVR is not really detecting motion at all. It is detecting “changes in the frame”, which could be noise, light, and transition from color to B/W etc. not related to what we understand as “motion” at all. Analytics engines look at differences too, but they are truly looking for “motion” and not JUST changes.

Looking for changes is usually “good enough”, and does not need to be any more than that. And if looking for “change” is what you need, then you really should let your camera do the work and free up the NVR to do more important things.

The reason we initially decided to analyze the frames for changes was really motivated by storage problems. A common HDD in those days was 200-300 MB, the 640×480 frames were considered “high resolution” and the format was always MJPEG. Naturally, the Axis 200+ could not deliver these crisp HD feeds at anywhere near 30 FPS. 3-5 FPS was usually all you could get. But storing this massive amount of data became a problem, so we decided to discard frames that were almost identical.

Naturally, as time passed we got higher resolutions and higher framerates, we were suddenly able to do MPEG4 encoding on a consumer device – in real time!!! MPEG4 and H.264 actually looks at two successive frames in much the same way we do on the NVR. The codec simply “throws away” the redundant information just as we do. Except the codec is throwing away just the parts of the frame that is similar to the previous one, while preserving only the changes – a much, much better way of doing things.

For the codec to figure out what to throw away, it must look at two successive frames. If they are very similar, it can throw away a lot, if they are very different it needs to send almost all the pixels. On top of that H.264 does a lot of other things before the video is sent across the network. These involve among other things – discrete cosine transformation, quantization and Huffman encoding.

It does not seem like a far stretch that the codec implementation could provide a number that tells the camera how much 2 frames are alike. And in a primitive way it actually does – if the frame is large in terms of bytes, then we can deduce that the frames are very different, if the frames are small, then they are very similar. Naturally this is too crude and would not work on CBR feeds, and there is no windowing etc.

Nor does it seem totally unreasonable that the codec implementation could give the “difference parameter” for each macroblock (a small 8×8 pixel block). It is important to understand that the codec already is doing the computation, we are just asking to get to peek at the result. Furthermore, the codec is also working on the crisp uncompressed frames that have the highest level of fidelity, and no information has been thrown away.

In naive implementations like the one I describe here, there is not a lot to be gained from working on the raw frames in the camera, but ask any analytics vendor if they would prefer to work on the video BEFORE or AFTER compression and the answer will uniformly be the same : BEFORE compression. So while the benefit is not huge, it is not completely without merit.

To do the detection on the NVR, the NVR will have to completely reverse the process: Take the Huffman symbols, and expand them into imaginary coefficients, go from frequency to the spatial domain, and only then can you start to think about examining the frames. You can then make all sorts of tricks – perhaps you only look at every N pixel, perhaps you don’t look at every frame, perhaps you get a lot of noise from too heavy compression, perhaps you don’t. Every single trick lowers the “quality” of the detection. Perhaps the client doesn’t care, even with severe degradation of the quality, and that’s fine by me. I am focused on improving and providing better, more efficient solutions and offering them to the ones who appreciate such things.

The point is this – spending a lot of resources decoding a H.264 stream, to get information that could have been gathered almost for free in the camera, is not my idea of efficient allocation of the resources. It is like rejecting a free apple, only to ride 30 miles to the store to buy the same, exact apple, only now it is slightly bruised from transporting it to the store – AND it takes a lot of effort to unwrap the apple.

In time, an NVR will not need to do much, in fact, I expect an NVR to be very similar to a NAS. Cheap, easy to replace, and very scalable. This will require that the cameras become a little more advanced, but my experience tells me that progress doesn’t just stop. We were amazed by 640 x 480 at 4 fps when I started, and just as we laugh at that today, we will laugh at NVR side change detection 10 years from now.

I suspect that a lot of cameras do not have the fine grained control over the encoding process that is needed here. I assume that they are picking off-the-shelf H.264 encoders or reference designs offered by the chip manufacturers. For such cameras, there might not be a simple way to do on-board processing, and doing so may jeopardize the performance of the camera – for those, you will have to spring for the expensive PC’s.

Start preparing for the change 🙂

Manual Gain Control on the Client

Another day, another experiment.

A question was brought up on one of the LinkedIn forums that I follow. I am no fan of Automatic Gain Control (AGC) as it is implemented today (I’m no fan of a lot of things it seems). The reason is that it seems to me that a lot of AGC implementations are pretty naive implementations that just multiply each pixel by a value determined by averaging the frame. I have not come across a system that will allow you to apply a different gain value to different parts of the frame.

AGC introduces a lot of noise into the frame. This in turn causes a) the compression to go to shit, and b) wreaks havoc on the motion detection. A lot of customers will pretty much be recording noise all night.

So why not do it on the client application?

Here’s a quick example I cooked up. I am using a couple of soft-buttons and since we are using the GPU for rendering the video, the cost of doing the multiplication is almost zero (the GPU was built for this sort of thing, so why not use it?)

Nothing fancy.

Painted into a Corner

When I first co-wrote Milestone Surveillance Lite and XXV we had a performance problem. My PC was a Celeron 300, and the Axis 200+ was unable to stream more than a couple of frames per second. Analog Matrix systems would run full framerate (25 or 30 fps), show 9 or even 16 cameras at any given time, and have virtually zero lag for joystick control.

As the hardware became more powerful we were able to add more cameras. Few people ran XXV (named after its ability to show 25 cameras) at full capacity, but 25 was more than 16 and more is better. People had the theoretical option to run 25 cameras which was a good selling point. People understood the argument instantly.

Since the jump in cameras on the screen was such a good story, we went on and said why not place 64 cameras on the screen at once. Again, few people ever ran 64, but they had the option. Again 64 is better than 25, and it is such a simple principle to explain.. more = better.

Now we can do hundreds of cameras on the screen at once. No-one can make sense of what is going on, but more is better..

Right?

What would happen if we released a software that went back to 16 cameras? Would anyone buy such a system? Since we’ve kept preaching that more is better, then 16 must surely be vastly inferior to a 200 camera layout.

That’s a difficult sales-pitch!

We’ve painted ourselves into a corner. Leading the clients to believe that “more is better”. More features, more cameras, more frames per second and so on.

Which would be true if we had infinite resources.

When a company decides to spend time on A, then they are NOT spending time on B. Adding one more camera driver, might mean that the IP auto-detection function did not get done, spending a lot of time on optimizing the decoding pipeline means NOT spending time on simplifying the UI and so on.

I think people like the idea that they CAN go to 100 cameras, just like the speedometer suggests that I can go to 160 mph if i so desire.

Truth is, we never do, and we really can’t – even if we tried.

The iPhone showed the world that people will trade more for less, if things are done right. The world was awash with phones that had myriads of  features. Microsoft laughed at Apple – a phone with no bluetooth, no exchange server support, no cut-and-paste! Microsoft had long followed the strategy that five shitty features had to be better than one good one, and now a newcomer was going to do things totally differently. No chance they would succeed.

Perhaps video surveillance is different.

Why do people REALLY need a 64 camera view? Help me out here!

Pretending to be Objective

One of the things I was taught before I started gambling in the stock market was to never “fall in love with a company”. The flip-side is probably just as bad; Short selling AIG because of hatred is not a rational thing to do.

If you are going to pretend to be a journalist, you have 2 options. Pretend to be objective or acknowledge that you are totally biased and confess to it. Consider Paul Krugman vs. Glenn Beck; Krugman does not pretend to be objective at all, and when you read him you KNOW that you are going to get a doze of Democrat and/or neo-Keynsian propaganda. That is Paul Krugmans vantage point. There are no hidden agendas, but plenty obvious ones. Beck on the other hand pretends to be objective. Opinions can’t be objective – ever. Even opinions based on facts are subjective. Some opinions are not based on facts at all, and we have a tendency to attribute more value to facts that support our opinion, while dismissing facts that do not (it’s called confirmation bias).

Stating a number of verifiable facts that support your opinion, does not make it objective. Lots of people think it does. They forget all the other factual information that do not support the stated opinion. Some facts are not brought to the table at all, others are intentionally forgotten, dismissed or disregarded as mere fantasy.

If you, as a blogger, pretend to be objective, and you might even believe that your opinions truly are objective (after all, they are based on facts), you’ll find that your audience becomes self-radicalized. Since what you are presenting is facts, it’s extremely hard to argue. Host of show : “ARE you denying the fact that….”, guest : “No, but we also found that..”, host : “those facts are not important, MY facts are!” (or alternatively, the host might just dispute the facts as being lies or fiction). As time passes, your only audience will be people who agree with you, and as “everyone agrees” it only reaffirms your opinion as being objective. Lou Dobb’s and Bill O’Reilly likes to run quote panels from “regular folks” who praise their wisdom as a sort of ego-booster.

So, opinions based solely on facts, are not objective. Nor are opinions based on fiction. That does not mean that I take opinions based on fiction as seriously as opinions based on facts. I am also painfully aware that I have to trust someone, which adds a secondary layer to the opinion shaping. As we have confirmation bias, we will trust whoever presents information that supports our own ideas. If I believe the earth is flat, I will consider a scientist who says it is round a fool. Why should I listen to a fool at all?