Security25/09/2024

Frigate NVR Setup: AI-Powered Home Security Made Simple

Frigate bills itself as 'a complete and local NVR designed for Home Assistant with AI object detection.' A Network Video Recorder, or NVR, is something you might not be familiar with if you're currently using something like a Ring doorbell.

Frigate NVR Setup: AI-Powered Home Security Made Simple

What is Frigate?

Frigate bills itself as "a complete and local NVR designed for Home Assistant with AI object detection." A Network Video Recorder, or NVR, is something you might not be familiar with if you're currently using something like a Ring doorbell. The NVR is the bit in the 'cloud' that stores your video. It allows you to perform functions such as searching, downloading, and getting notifications. The only thing is: it's on Amazon's network, not yours.

There are many reasons why this is not great:

Privacy concerns

Your sensitive data - videos of your kids, that "accountant" who stays a bit too long sometimes - it's all external... When the company gets hacked, hires a sketchy employee, or turns that footage over to the police without a warrant, you have no choice.

Latency issues

Ring is notorious for this. If your upload speeds aren't fantastic, the app's response times are terrible. The experience feels either very laggy, or the video quality you have access to is terrible.

Internet dependency

If you're away from home and want to see the DPD lady drop off your package, granted you'll always need some sort of internet connection. But what about when you're away from home and someone wants to steal your car? If they're committed enough, they'll break in to shut off your internet. Then they'll steal the camera. Maybe it got a few frames uploaded before the internet went down. Maybe not. What if you could guarantee that, until disconnection, the video was being streamed elsewhere in the house? Unless you have some very clever thieves, which is rather rare, your video is safe.

There are plenty of other drawbacks, but hopefully that's enough to get you thinking. If you want this set up for you without having to do anything else, give us a call.

Prerequisites

We'll be going through the Docker version of Frigate in this post. Because of that, you'll need a few things:

  • a PC (preferably a home server of some sort) that supports Docker
  • knowledge of Docker, Docker Compose, and a working setup
  • access to the PC's command line (local, SSH, it's all good)
  • (optional) a Google Coral device (these are lifesavers for the object detection)

The Setup Process

Frigate is a complex project that attempts to serve many different masters. This is great for flexibility. But it does mean that the project is quite far-reaching with lots of configuration. Its documentation is excellent, but it's a lot. Because of that, we'll try to condense it down into some key points to get you up and running as simply as possible.

  1. Basic setup via Docker Compose
  2. The config file and adding a camera
  3. Configuring your camera for object detection
  4. Next steps, advanced integrations, etc

As many configuration files as we can give to you will be at the bottom of this post. Everything besides the camera IP address and authentication can be copied and pasted.

Docker Compose Setup

General best practice with Docker Compose is to keep your projects in separate folders. So, make a new one!

Hint: we usually use /opt/dockers for ours so that it's consistent and doesn't collide with any system files.

Within this, you're going to want a config and a storage folder. You may already have a NAS that you built after reading our Unraid or TrueNAS posts. We'll cover that in the mappings part shortly.

In this root directory, create a docker-compose.yml file. The basic structure is below.

services:
  frigate:
    container_name: frigate
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:stable
    shm_size: "128mb" # allows more memory for cameras
    volumes:
      - ./config:/config
      - ./storage:/media/frigate # This is where you can change the left-hand side to be your NAS if you have one
      - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear, remove if on a low memory system
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    devices:
      - /dev/bus/usb:/dev/bus/usb # if you picked up a USB Google Coral
      - /dev/dri/renderD128 # for intel hwaccel, needs to be updated for your hardware
    ports:
      - "8971:8971" # Browser access
      - "8554:8554" # RTSP feeds
      - "1935:1935" # RTMP feeds

You can pretty much copy and paste this config and have it working. If you haven't changed the default storage mapping, then you'll start to fill up the local disk.

This also assumes you're using an Intel machine. If not, check out the hardware acceleration guide to adapt to your setup.

The Config File

Now this is where the more complex setup happens. Frigate has a great walkthrough on Camera Setup. There's also plenty of recommendations for specific brands or models. In the interest of time, we're not going to cover the camera setup bit here. Feel free to reach out to us if you are having trouble with your camera or would like some tailored advice.

mqtt:
  enabled: False

detectors: # <---- if you picked up a Google Coral
  coral:
    type: edgetpu
    device: usb

cameras:
  name_of_your_camera: # <------ Name the camera
    enabled: True
    ffmpeg:
      inputs:
        - path: rtsp://10.0.10.10:554/rtsp # <----- The stream you want to use for detection
          roles:
            - detect
    hwaccel_args: preset-vaapi # assumes Intel hwaccel
    detect:
      enabled: False # <---- disable detection until you have a working camera feed

For now we'll leave MQTT disabled. There will be a future post on this as it ties into the Home Assistant integration.

Make sure you change the name of the camera and the stream path as indicated by the arrows above.

Now you can run docker compose up to get the party started. Frigate auto generates you a password on first run. If you execute docker compose logs | grep Password you'll be able to find it. Wait about 30 seconds. Now browse to https://your.pcs.ip.address:8971. Use the username admin and the password from your docker logs command output. This should get you in and looking at a camera (hopefully the one you added to the config!).

Configuring Detection

This is a really easy step; think of it like a reward for getting through the rest of the config. Remember that config.yml file from before? Open it up and edit the bottom line to say enabled: True and that's it! Walk in front of your camera a few times and you should start to see events popping up above the camera.

There is a way to get more specific and set up certain areas for the camera to detect motion. The documentation has a good walkthrough of this, if necessary.

Bonus: Configure Recording

As we mentioned before in the whole 'people stealing your car' scenario, we need recordings! With Frigate, that's two lines of config. It's a per camera setting, so you need to nest the YAML well. See the full config at the bottom of the post to confirm.

record:
  enabled: True
  retain:
    days: 3

You'll notice I also included the 'retain' option there. I use this to avoid filling the disk with useless blank video. Frigate will automatically clean up recordings older than this. Feel free to experiment with this number to see how much space it uses. And, as mentioned, this is per camera. So if you have multiple cameras, each one can have a different retention period.

The Files!

As promised, both files in full are below. Enjoy!

docker-compose.yml

services:
  frigate:
    container_name: frigate
    restart: unless-stopped
    image: ghcr.io/blakeblackshear/frigate:stable
    shm_size: "128mb" # allows more memory for cameras
    volumes:
      - ./config:/config
      - ./storage:/media/frigate # This is where you can change the left-hand side to be your NAS if you have one
      - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear, remove if on a low memory system
        target: /tmp/cache
        tmpfs:
          size: 1000000000
    devices:
      - /dev/bus/usb:/dev/bus/usb # if you picked up a USB Google Coral
      - /dev/dri/renderD128 # for intel hwaccel, needs to be updated for your hardware
    ports:
      - "8971:8971" # Browser access
      - "8554:8554" # RTSP feeds
      - "1935:1935" # RTMP feeds

config.yml

mqtt:
  enabled: False

detectors: # <---- if you picked up a Google Coral
  coral:
    type: edgetpu
    device: usb

cameras:
  name_of_your_camera: # <------ Name the camera
    enabled: True
    ffmpeg:
      inputs:
        - path: rtsp://10.0.10.10:554/rtsp # <----- The stream you want to use for detection
          roles:
            - detect
            - record
    hwaccel_args: preset-vaapi # assumes Intel hwaccel
    detect:
      enabled: True
    record:
      enabled: True
      retain:
        days: 3