Selora Homes Selora Homes Academy

Streams, codecs and bitrate

12 min

You will be able to

  • Tell a camera's main stream from its sub stream, and what each is for
  • Choose between H.264 and H.265 for a camera
  • Set a camera's encoder so it records cleanly

An IP camera is a small computer with a lens. It compresses what it sees into a video stream and serves it over the network, usually over RTSP (port 554). A recorder such as Frigate connects to that stream, decodes it, looks for people and cars, and writes it to disk.

Most cameras also speak ONVIF, a standard way to find them on the network, read their settings and move them (pan, tilt, zoom). ONVIF doesn't carry the video itself: the stream is still RTSP.

Main stream and sub stream

A camera serves the same picture as two or more streams at once:

Stream Typical settings Used for
Main Full resolution (4 MP, 8 MP), 15 to 20 fps, high bitrate Recording, and watching a clip in detail
Sub 640×360 to 1280×720, 5 fps, low bitrate Detection, and live view on a phone

Detection doesn't need 4K: finding a person in a 720p picture works as well, and costs a fraction of the processing. Decoding a full-resolution stream for detection is the most common reason a recorder runs out of CPU. So the rule is: record the main stream, detect on the sub stream.

Check yourself Single answer

A camera serves a 3840×2160 main stream at 20 fps and a 640×360 sub stream at 10 fps. The recorder's CPU sits at 100% with only this camera added. What do you change first?

Not graded: try as often as you like.

It adds up

The recorder decodes every camera's detect stream all the time, whether anything happens or not. The work grows with the pixels in each frame and the frames each second:

  • A 3840×2160 (4K) frame has 36 times the pixels of a 640×360 one.
  • 20 frames a second is 4 times the work of 5.

So one camera detecting on a 4K stream at 20 fps costs the recorder roughly 140 times what the same camera costs on its sub stream at 5 fps. One such camera may get by; four or six bring a Selora Hub to its knees. Everything on the Hub then slows down with it: Home Assistant, its automations and the dashboards, not only the cameras.

Set every camera's sub stream for detection before it goes up:

  • 640×360 to 1280×720. People and cars are found as well as in 4K.
  • 5 fps. Frigate's own default for detection. A stream sent faster is still decoded frame by frame, then mostly thrown away, so set the rate on the camera, not only in the recorder.
  • A camera with no sub stream, or one switched off, leaves the recorder only the main stream to detect on. Turn the sub stream on, or pick another camera.
Check yourself Number

How many times more pixels does a 2560×1440 frame have than a 640×360 one?

times
Not graded: try as often as you like.

H.264 and H.265

The codec is how the camera compresses the picture:

  • H.264 plays everywhere: every browser, phone and recorder.
  • H.265 (HEVC) needs about half the bitrate for the same picture, so half the disk. But not every browser can play it, and decoding it costs more.

With Frigate, the default is H.264 on both streams: every recording then plays in any browser and in the Home Assistant app. Keep H.265 for a main stream when the disk really is the limit, and check that the clips play on the customer's own phone before you leave.

Turn off "smart" codecs: H.264+, H.265+, Smart Codec and the like. They stretch the time between full frames to save a little more space, and the result is recordings that start seconds late, or don't play from where you click.

Frame rate, keyframes and bitrate

  • Frame rate: 15 fps is smooth enough to record. More only fills the disk.
  • Keyframe interval (also called I-frame interval or GOP): a keyframe is a full picture; the frames between hold only what changed. A recording can only start on a keyframe, so set one keyframe per second: the interval equals the frame rate (15 at 15 fps).
  • Bitrate: how many megabits per second the stream uses. It sets the quality and the disk space. Choose constant bitrate (CBR) when you size a disk: variable bitrate climbs at night, in rain and in wind, just when you need the footage.

Typical main stream bitrates:

Resolution H.264 H.265
1080p (2 MP) 4 Mbps 2 Mbps
4 MP 6 to 8 Mbps 4 Mbps
4K (8 MP) 12 to 16 Mbps 6 to 8 Mbps
Check yourself Number

A camera records at 20 fps. What keyframe interval, in frames, gives one keyframe per second?

frames
Not graded: try as often as you like.

What you read is saved in this browser only. Sign in to keep it in your account, take the quizzes and get certified.

This lesson by Selora Homes is licensed CC BY 4.0 : share and adapt it, even commercially, crediting Selora Homes with a link. Photos by others keep their own licences, as credited.