Frigate 0.16 Installation Tutorial
What's New?
Frigate has been my go-to Network Video Recorder (NVR) for several years now. The leaps and bounds it has made over the years has turned it into one of the best NVR's available, beating most commercial offerings, including the hardware based NVR's that camera manufacturers sell. With the release of Version 0.16, some new features are finally encouraging me to install from scratch and explore it's exciting new features including Face Recognition, License Plate Recognition, and Generative AI to tag objects.
In earlier releases Frigate required you to use a Coral Accelerator which at times were hard to get a hold of with scalpers selling them at up to 300% markup! In the last few releases use of GPU's and other embedded hardware has been enabled for detection. Additionally, the UI changes have been fantastic enabling a full user management system.
Hardware
Servers
Dell Poweredge T410
• 2x Intel Xeon E5630
• 64GB DDR3
• Nvidia RTX 3060 12GB
• 1TB SSD System Drive
• 12TB ZFS Storage
• USB Coral Accelerator
Cameras
4x Wyze V3 Cameras running wz_mini_hacks
Installing and configuring wz_mini_hacks is outside the scope of this tutorial, but the project provides excellent documentation to get it up and running, but these cameras are a great budget route to get high quality 1080p cameras up and running!
Docker Setup
Installation of docker and docker compose are outside the scope of this tutorial. There are many tutorials out there to help you with this.
Preliminary Steps
The one thing Frigate lacks is an installation wizard. There are a few manual steps you must do prior to installation.
SHM (Shared Memory) Size
The default SHM size of 128MB will work fine if you have 2 cameras or less detecting at 720p. The container logs are also stored in shared memory limited to 40MB, so we need to use the following calculation to figure out the minimum shm size for each camera: (<width> x <height> x 1.5 x 20 + 270480 / 1048576)
This gives us the following values:
Resolution | Min Memory |
---|---|
4K | 176 MB |
2K | 106 MB |
1080p | 60 MB |
720p | 27 MB |
480p | 5 MB |
360p | 7 MB |
I have 4 cameras running detection at 1080p so I will come up with:
60 x 4 + 40 = 340MB minimum shm size.
The most common setups would use 720p or 360p, so make sure you find out what resolution you are using for detection and do the proper calculation.
I end up adding and removing cameras when I go away for extended periods of time or when I leave the pup at home, so I usually set my SHM size at 512MB. If you intend to add cameras later, you should also consider doing the same or be sure to adjust each time you add a camera.
Camera RTSP Streams
Camera Setup is not straight forward as each camera is different. See your manufacturer's documentation to find your camera's RTSP streams. Optionally, ONVIF is supported in Go2RTC, however, I have not used this so I cannot attest to it's function or reliability.
I highly recommend using Go2RTC as it is far more compatible with Frigate. The Wyze Cam's default RTSP server does not handle h.264 according to the standard specification and can cause Frigate to lock up if not accounted for.
For my Wyze cameras running wz_mini_hacks the default streams are:
Go2RTC (recommended)
Type | Resolution | URL |
---|---|---|
Main | 1080p | rtsp://<camera_ip>:8554/1080p?mp4#video=copy |
Sub | 360p | rtsp://<camera_ip>:8554/360p?mp4#video=copy |
RTSP Server (lesser quality)
Type | Resolution | URL |
---|---|---|
Main | 1080p | rtsp://<camera_ip>:8554/video1_unicast#video=copy |
Sub | 360p | rtsp://<camera_ip>:8554/video2_unicast#video=copy |
Docker Setup
Installation of docker and docker compose are outside the scope of this tutorial. There are many tutorials out there to help you with this.
Nvidia Setup
In order to use your Nvidia GPU, you need to make sure your OS is configured properly. I will not provide instructions, but will link to some useful tutorials or documentation.
• Proprietary Nvidia Driver Installation
This is outside the scope of our tutorial but instructions can be found here:
Debian Ubuntu Fedora openSUSE
NOTE: You will need to install the latest CUDA drivers as well.
• Nvidia Container Toolkit
Instructions are provided by Nvidia on how to configure the Container Toolkit.
Storage Setup
The frigate container has the following important directories:
Directory | Purpose |
---|---|
/config | Frigate's configuration file and sqlite database |
/media/frigate | Frigate's Snapshots, Recordings, and Exports |
/tmp/cache | Cache location for recording segments. |
/dev/shm | Shared Memory with the host |
Network Ports
The following ports are available for Frigate. We will use Port 8971 with a reverse proxy to add user login.
Port | Purpose |
---|---|
8971 | Authenticated UI and API access (Needs to be behind a reverse proxy with TLS) |
5000 | Internal Unauthenticated UI and API access |
8554 | RTSP restreaming |
8555 | WebRTC for cameras that support two-way talk |
Reverse Proxy
I will be using Traefik in this tutorial as it is easy to integrate with docker and currently what I use in my infrastructure. Caddy, Nginx, or any other reverse proxy that can provide TLS through Let's Encrypt will do just fine.
Follow my tutorial Building a Secure Home Lab with Tailscale, PowerDNS & Traefik’s DNS-01 Challenge to setup Traefik with Tailscale for a powerful secure setup.
Home Assistant Integration
Integrating with Home Assistant makes Frigate that much more powerful.
MQTT
If you plan on integrating Frigate with Home Assistant, we will need an MQTT Broker like mosquitto. I recommend installing it via Home Assistant Addons.
Let's Start Building
Our Base Configuration
/storage/frigate
- /config
- config.yml (Frigate's configuration file)
- /media
- .env ( All of our variables for our docker-compose.yml)
- docker-compose.yml
.env
FRIGATE_CONTAINER_NAME=frigate
FRIGATE_VERSION=0.16
FRIGATE_PLUS_API_KEY=<YOUR_FRIGATE_PLUS_KEY>
FRIGATE_SHM_SIZE=512mb
FRIGATE_CONFIG=/storage/frigate/config
FRIGATE_MEDIA=/storage/frigate/media
docker-compose.yml
services:
frigate:
container_name: ${FRIGATE_CONTAINER_NAME:-frigate}
privileged: true
restart: unless-stopped
stop_grace_period: 30s
image: ghcr.io/blakeblackshear/frigate:${FRIGATE_VERSION:-0.16}
shm_size: "${FRIGATE_SHM_SIZE:-512mb}"
devices:
- /dev/dri:/dev/dri
volumes:
- /etc/localtime:/etc/localtime:ro
- ${FRIGATE_CONFIG:-/storage/frigate/config}:/config
- ${FRIGATE_MEDIA:-/storage/frigate/media}:/media/frigate
- type: tmpfs
target: /tmp/cache
tmpfs:
size: 1000000000
ports:
- "8971:8971"
- "5000:5000"
- "8554:8554"
- "8555:8555/tcp"
- "8555:8555/udp"
environment:
- PLUS_API_KEY=${FRIGATE_PLUS_API_KEY}
Adding Nvidia Support
To enable our Nvidia card you need to add access to /dev/dri
and enable Nvidia support in our docker-compose.yml file. At the end of the article a full docker-compose.yml file will be provided for reference.
deploy:
resources:
reservations:
devices:
- driver: nvidia
count: 1
capabilities: [gpu]
Adding Reverse Proxy Support
Since we are using Traefik as our reverse proxy, we will just need to add our traefik network and docker labels to our docker-compose.yml to enable it.
networks:
- traefik
labels:
- 'traefik.enable=true'
- 'traefik.http.routers.frigate.rule=Host(`${FRIGATE_HOST:-frigate.ts.example.net}`)'
- 'traefik.http.routers.frigate.entrypoints=https'
- 'traefik.http.routers.frigate.tls.certresolver=dns01-tailscale'
- 'traefik.http.services.frigate-service.loadbalancer.server.port=3909'
networks:
traefik:
external: true
And add a line in our .env file:
FRIGATE_HOST=frigate.ts.example.net
That does it for configuring our docker compose setup.
Complete Examples
The complete example files are available in our GitHub Repository for this article.
Building config.yml
Now that we have our docker-compose all setup, we can start configuring Frigate itself.
We will start with a base config.yml that will work with most setups:
tls:
enabled: false
ffmpeg:
hwaccel_args: preset-nvidia-h264
birdseye:
enabled: true
mode: continuous
width: 1920
height: 1080
restream: true
detect:
enabled: true
width: 1920
height: 1024
max_disappeared: 60
fps: 5
objects:
track:
- bicycle
- bus
- person
- car
- animal
record:
enabled: true
retain:
days: 7
mode: all
alerts:
retain:
days: 7
pre_capture: 30
post_capture: 30
detections:
retain:
days: 14
pre_capture: 30
post_capture: 30
snapshots:
enabled: true
bounding_box: true
quality: 100
retain:
default: 7
objects:
bus: 30
person: 30
car: 30
animal: 30
bicycle: 30
Adding Detectors
Here is where Frigate's magic happens. We need to enable detectors to process camera images for AI detection. We will use the Onnx detector which will work on Intel, AMD, and Nvidia GPU's depending on the image selected.
detectors:
onnx:
type: onnx
Adding Models
The frigate image does not include onnx models by default, so you will have to export one and define it in your config.
I am using the YOLOv9 model for this setup and it requires you to export the model for ONNX as described in Frigate's documentation. I have created a bash script to automate the process. This script is available in this article's GitHub repository.
First clone the repository and cd into the repository
git clone https://github.com/BeardedTek/frigate-config
cd frigate-config
Next run the script:
./export_yolov9.sh
This will give you a menu to configure the YOLOv9 model:
beardedtek@triton:~/frigate-config> ./export_yolov9.sh
YOLOv9 to ONNX export
https://github.com/beardedtek/frigate-config
Select Model Size:
1) t | Params: 58M, Inference: 23 ms
Fastest, smallest model. Great for edge devices, lower accuracy.
2) s | Params: 90M, Inference: 25 ms
Balanced speed and accuracy. Good general-purpose choice.
3) m | Params: 110M, Inference: 28 ms
Higher accuracy, slower. Use if quality matters more than speed.
4) c | Params: 51M, Inference: 30 ms
Compact model, fewer parameters. Moderate speed and accuracy.
5) e | Params: 120M, Inference: 32 ms
Largest model, highest accuracy, slower inference.
Press Enter to use default: t
Enter choice [1-5]: 2
Select Image Size:
1) 160
2) 320
3) 480
4) 640
Press Enter to use default: 320
Enter choice [1-4]: 4
Enter output directory [default: .]: /storage/frigate/config/model_cache
Summary of selections:
MODEL_SIZE=s
Parameters: 90M
Inference: 25 ms
Description: Balanced speed and accuracy. Good general-purpose choice.
IMAGE_SIZE=640
OUTPUT_DIR=/storage/frigate/config/model_cache
Proceed with exporting YOLOv9 model to ONNX? [y/N]:
Once you've made your selections, enter 'y' to proceed and it will export the model to the specified folder as yolov9-X.onnx
where X is the model size you chose.
Now we need to define the model we are using in our config.yml:
model:
model_type: yolo-generic
width: 320
height: 320
input_tensor: nchw
input_dtype: float
path: /config/model_cache/yolov9-s.onnx
labelmap_path: /labelmap/coco-80.txt
Add Cameras
Now that we have a base config, a detector, and and a model defined we can start adding cameras.
Configure Go2RTC
Frigate includes Go2RTC which we will use to limit connections to our cameras. This has several advantages including only making 1 connection to each of our cameras which both saves bandwidth, and reduces the cpu load on our cameras. There are other benefits to using Go2RTC, but that is outside the scope of this tutorial. Frigate's documentation has more in depth information.
We will add an entry under go2rtc
in config.yml
for each stream our camera provides. We will be using both the 1080p and 360p streams provided by wz_mini_hacks for each camera.
For each stream you will see we used the rtsp stream provided by our camera wrapped in some extra text. Let's explain it:
ffmpeg:
rtsp://192.168.3.81:8554/1080p?mp4
#video=copy
#audio=copy
#hardware
- ffmpeg:
- This tells webrtc to use ffmpeg to ingest the stream. This is necessary to preserve aspect ratio while using our wyze camera. go2rtc does not handle it's stream correctly on its own.
- rtsp://192.168.3.81:8554/1080p?mp4
- This is the rtsp stream url we gathered earlier in the process.
- #video=h264
- This tells ffmpeg to convert the rtsp stream to h264 for better handling non-compliant rtsp streams
- #audio=copy
- This tells ffmpeg to just copy the audio stream
- #hardware
- This tells ffmpeg to use hardware acceleration
go2rtc:
streams:
driveway:
- "ffmpeg:rtsp://192.168.3.81:8554/1080p?mp4#video=h264#audio=copy#hardware"
driveway_sub:
- "ffmpeg:rtsp://192.168.3.81:8554/360p?mp4#video=h264#audio=copy#hardware"
Configure Cameras
Now we define how frigate handles the cameras.
cameras:
driveway:
birdseye:
enabled: true
ffmpeg:
inputs:
- path rtsp://127.0.0.1:8554/driveway
roles:
- record
- detect
- audio
live:
streams:
Main Stream: driveway
Sub Stream: driveway_sub
Let's Spin It Up!
Now that we have build our docker-compose.yml, exported our model to onnx, and completed our config.yml file, we can finally bring it all up!
docker-compose up -d
We can view the logs using:
docker compose logs -f
Then we can access our instance at https://cameras.ts.example.net
or http://<local_ip>:5000
assuming we have seen no errors.
Example Repository
Our example config.yml, docker-compose.yml, and utilities to export the YOLOv9 models are available at https://github.com/beardedtek/frigate-config