PanelSimulator Academy

Video Surveillance, lesson 7 of 14

Compression and bitrate

Raw video is enormous. One camera would fill a hard disk in hours and choke a network by itself. So every camera squeezes its video before sending it, and squeezing always throws something away. This lesson shows how the squeeze works, what it costs, and how to set it so the detail you paid for survives.

About 15 minutes. Read lesson 4 first.

Squeeze the video

Change the settings and the scene. Each bar is one frame, and its height is the data that frame needs.

Data in each frame, over two seconds 0 s1 s2 s The recorded picture recorded around the clock

The everyday picture

Suppose you had to describe a chess game by mail. You could send a photograph of the whole board after every move. Or you could send one photograph at the start and then a short note for each move: "knight from g1 to f3". The notes are tiny, and the person at the other end can rebuild every position.

There are two catches. If the first photograph is lost, the notes mean nothing. And if the board is knocked over and every piece moves at once, a note is no shorter than a photograph.

Video compression works like the notes. The camera sends a complete picture now and then, and in between it sends only what changed. That one idea explains nearly everything about how much data a camera produces.

Why video must be squeezed

A 1080p picture has about 2 million pixels. Each needs 3 bytes to record its color, so one raw frame is about 6 megabytes. At 30 frames a second that is 180 megabytes every second, or roughly 1,500 megabits per second. An ordinary building network cable carries 1,000.

A camera typically sends that same video at about 4 megabits per second. The squeeze is more than 300 to 1. Something that clever deserves a name: a codec, short for coder and decoder, is the method used to squeeze video at the camera and rebuild it at the screen.

Codecs use two tricks. The first works inside one picture: a plain wall is described as "this whole area is beige" and not pixel by pixel. That is how a JPEG photograph works. The second works between pictures, and it is the chess notes.

Whole frames and change frames

A compressed video stream is made of two kinds of frame.

  • An I-frame, also called a keyframe, is a complete picture. It is large. It is the photograph of the board.
  • A P-frame describes only what changed since the frame before. In a still scene it is tiny. It is the note.

The stretch from one I-frame to the next is a group of pictures, or GOP. A common setting is one I-frame per second, so at 15 frames per second the pattern is one I-frame and fourteen P-frames, over and over. Look at the tall and short bars in the tool above.

Now change the scene in the tool from an empty corridor to a busy street. The I-frames barely move. The P-frames grow several times over, because much more of the picture changes from one frame to the next. This is the most important fact in the lesson: movement costs data. So does anything that looks like movement to the camera, including rain, waving branches, flickering lights and the grain of a noisy night picture.

Check yourself

An investigator jumps to a moment in a recording. The player has to step back a little before it can show a picture. What is it looking for?

The codecs

CodecHow it worksData neededWhere you meet it
Motion JPEGEvery frame is a complete picture. No change frames.Very high, often ten times H.264Old systems, and snapshots
H.264I-frames and P-framesThe baselineAlmost everything made since about 2010. Plays anywhere.
H.265The same idea with smarter, larger blocksOften a third to a half less than H.264 for a similar pictureMost current cameras, and nearly all 4K

H.265 saves storage, but it takes more computing power to play. Check that the recorder and the viewing computers support it before switching a site over, and that exported clips will open on an ordinary computer.

Many cameras add their own "smart" mode with a trade name. These modes stretch the gap between I-frames when nothing moves and squeeze the still background harder than moving things. The savings on quiet scenes can be large. Test them, because a long gap between I-frames makes searching slower and some recorders handle it poorly.

Bitrate and what drives it

Bitrate is the amount of data a camera sends each second, measured in megabits per second, written Mbps. It decides two things: how much network the camera uses, and how fast it fills a disk. One figure is worth remembering: 1 Mbps recorded around the clock is about 10.8 gigabytes per day.

Five things set the bitrate. Try each in the tool.

  • Resolution. More pixels need more data, roughly in proportion.
  • Frame rate. More frames need more data, but less than in proportion. Halving the frame rate does not halve the bitrate, because the I-frames remain and each P-frame now has more change to describe.
  • Compression level. A quality setting in the camera. Heavier compression means fewer bits and a rougher picture.
  • Codec. H.265 needs less than H.264 for a similar picture.
  • The scene. Movement, fine detail and noise. You do not control this one, and it varies through the day.

A camera can manage its bitrate in two ways. With constant bitrate, or CBR, it sends the same amount all the time and lets the picture quality rise and fall. With variable bitrate, or VBR, it holds the quality steady and lets the bitrate rise and fall with the scene. Most designers use VBR with a maximum, called a cap, so quiet hours save disk space and a storm cannot flood the network.

Resolution, at 15 frames per secondH.264, rough figureH.265, rough figure
720p1.5 Mbps0.8 Mbps
1080p3 Mbps1.7 Mbps
4 megapixel5.5 Mbps3 Mbps
4K12 Mbps6.5 Mbps

These are starting points for a scene with moderate movement, and the tool above uses the same simple model. Real cameras differ widely. For a real design, use the maker's calculator, then measure a camera on site across a day and a night.

Up or down?

Six changes

The camera uses variable bitrate. Decide what each change does to the data it sends, then read why.

What is lost

When a codec runs short of bits, it does not make the picture smaller. It makes it rougher. The faults it leaves are called artifacts, and you should learn to spot them.

  • Blocks. The picture breaks into visible squares, most of all around moving things.
  • Smearing. Fine texture such as hair, gravel or the print on a shirt turns to a smooth blur.
  • Pulsing. The picture sharpens once a second as each I-frame arrives, then softens again.
  • Trails. A moving person drags a patch of the old background behind them.

Notice where the damage falls. Still backgrounds survive well. Moving people suffer most, and people are usually what you need to see. A recording can look excellent with an empty scene and fall apart at the moment something happens. That is why you judge compression settings with movement in the picture, and why the pixels per foot from lesson 4 is a ceiling that heavy compression can lower.

Three examples

Simple: halving the storage

An office has 16 cameras at 1080p, 30 frames per second, H.264, averaging 4 Mbps each. That is 64 Mbps in total, and 64 × 10.8 = about 690 gigabytes per day. The owner wants 30 days and the disks hold only two weeks.

Nobody needs 30 frames a second to watch people walk through an office. At 15 frames per second and H.265, each camera averages about 1.7 Mbps. The total is about 27 Mbps, or roughly 295 gigabytes per day. The same disks now hold more than a month, and no detail in any single frame was given up.

Medium: the bitrate that doubles at night

A recorder that should hold 30 days holds 19. The cameras were measured during the day at 2 Mbps. Someone checks at 11 p.m. and finds them sending 5 Mbps of an empty parking lot.

The lot is dim, the cameras are adding gain, and the grain changes in every frame. To the codec, grain is movement over the entire picture. The fix follows lesson 5: more light, so less gain. A moderate noise reduction setting and a sensible bitrate cap help too. Measuring only in daylight hid the problem.

Advanced: 4K starved of bits

To save disk space, an installer sets every camera to constant bitrate at 1 Mbps, including the 4K camera over a busy store entrance. At quiet times the picture is superb. When a group walks in, their faces dissolve into blocks.

The 4K camera has four times the pixels of a 1080p camera and is being given a third of the bits a 1080p camera would normally get. With so few bits per pixel, the codec protects the still background and gives up on whatever moves. A 1080p picture at the same 1 Mbps would have looked better, because its pixels would each get four times the share. The entrance camera needs variable bitrate with a cap near 8 Mbps. If the disk cannot afford that, lower the frame rate, or lower the resolution honestly. Starving a high-resolution camera wastes the money spent on it.

From the field

  • Measure, do not assume. Read the real bitrate from the camera or recorder at the busiest hour and again at night, before promising a number of days.
  • Judge with movement. Walk through the view, pause the recording on your own face, and look for blocks.
  • Match the I-frame interval to the frame rate. One per second is a safe starting point. Very long intervals save little on busy scenes and slow down searching.
  • Mask what does not matter. A waving tree or a busy road at the edge of the view burns bits all day. Re-aim the camera to leave it out where you can.
  • Write the settings down. Codec, resolution, frame rate, bitrate mode and cap for every camera, so a replacement can be set the same way.

Common mistakes

  • Sizing storage from a bitrate measured on a quiet afternoon.
  • Setting a low constant bitrate on a high-resolution camera to save disk space.
  • Expecting half the frame rate to give half the bitrate.
  • Switching to H.265 without checking that the recorder and viewing computers can play it.
  • Approving picture quality on an empty scene.

Summary

  • A codec sends a complete I-frame now and then, and small P-frames that describe only the changes.
  • Movement, fine detail and noise all raise the bitrate.
  • Bitrate is set by resolution, frame rate, compression level, codec and the scene.
  • H.265 needs noticeably less data than H.264. Motion JPEG needs far more.
  • Too few bits shows as blocks and smearing on moving things first. 1 Mbps is about 10.8 gigabytes per day.

Exercises

Answer each one yourself first, then open the answer.

Exercise 1. A camera runs at 20 frames per second with one I-frame per second. How many P-frames are in each group of pictures?

Show answer
Nineteen. Each second holds 20 frames: one I-frame followed by 19 P-frames.

Exercise 2. Eight cameras average 3 Mbps each. How many gigabytes do they record per day, and per 30 days?

Show answer
8 × 3 = 24 Mbps. 24 × 10.8 = about 259 gigabytes per day. Over 30 days that is about 7,800 gigabytes, or 7.8 terabytes. Lesson 8 adds the margins a real design needs.

Exercise 3. Where does the figure of 10.8 gigabytes per day for 1 Mbps come from?

Show answer
A day has 86,400 seconds. 1 megabit per second for 86,400 seconds is 86,400 megabits. Divide by 8 to get 10,800 megabytes, which is 10.8 gigabytes.

Exercise 4 (think, don't memorize). Two identical cameras with identical settings are on the same building. One faces a blank wall and a quiet door. The other faces a road lined with trees. The second uses four times the disk space. Is it faulty? What could you do about it?

Show answer
It is not faulty. With variable bitrate, the data follows the scene, and traffic and moving leaves change most of the picture in every frame. Options: re-aim or narrow the view to leave out the road and trees if they are not part of the camera's job; lower its frame rate; use H.265 or a smart mode; set a cap and check the picture at the cap with movement in view. Start from the camera's written purpose. If the road is not in it, the road should not be in the picture.