Streams, codecs and bitrate
12 min Read in this browser
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.
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.
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 |
RTSP
Real Time Streaming Protocol: how a camera serves its live video over the network, usually on port 554. A recorder such as Frigate opens a stream at an address like rtsp://192.168.1.50:554/main.
Frigate
The open-source recorder Selora runs on the Hub. It records the cameras and detects people, vehicles and animals in what they see, locally.
ONVIF
A standard that lets a recorder find a camera on the network, read its settings and streams, and move it if it pans and tilts. It doesn't carry the video: RTSP does.
Frame rate
How many pictures a stream sends each second (frames per second). 15 fps is smooth enough to record; detection needs about 5.
Bitrate
How much data a stream sends each second, in megabits per second (Mbps). It sets the picture's quality and how fast the disk fills: 1 Mbps fills 10.8 GB a day.
Main stream
A camera's full-resolution stream, at a high bitrate. Frigate records it.
Sub stream
The camera's second, smaller stream of the same picture, such as 640×480 at 5 fps. Frigate detects on it, which costs a fraction of the main stream.
Codec
The method a camera uses to compress its video, and a player to decompress it. Cameras use H.264 or H.265.
H.264
The most widely supported video codec: it plays in every browser, phone and recorder. The default for cameras on Frigate.
H.265
A newer video codec that needs about half the bitrate of H.264 for the same picture, but that some browsers can't play and that costs more to decode.
Smart codec
A camera setting (H.264+, H.265+, Smart Codec) that saves a little space by spacing keyframes far apart. Recordings then start late or won't play from where you click: turn it off.
Keyframe
A complete picture in a stream; the frames between hold only what changed. A recording can only start on one, so set one keyframe a second: the interval equals the frame rate.
Constant bitrate
The camera sends the same bitrate whatever the scene, so the disk fills at a rate you can plan for. Variable bitrate (VBR) climbs at night and in bad weather.
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.