Frigate NVR: Linux Manual Install
Using Frigate NVR: Linux Manual Install to install Frigate NVR as a separate Linux box is the best was to install Frigate. It is the most flexible and still allows full integration into Home Assistant. Frigate NVR is a powerful freeware linux-based NVR software with integrated object detection. Full integration with Home Assistant allows you to have your smart home take action based on detected objects in specific zones on any cameras attached to Frigate NVR.
This article is the first in an article series Best Security System Setup using Frigate NVR intended to help you get Frigate NVR setup with network storage and Home Assistant integration. Here is a list of the articles in this series for you to jump to:
- Best Security System Setup using Frigate NVR (Overview Article)
- Frigate NVR: Linux Manual Install (this article)
- Frigate NVR: Reolink Camera Configuration
- TrueNAS: NFS Network Share
- Frigate NVR: Home Assistant Integration
This is part of digiMoot’s series of articles on NVR and series of articles on TrueNAS installations, configurations and setup.
1. Install Ubuntu
Alright, so lets get ‘er done and get started with this Frigate: Linux Manual Install article. I chose to install Ubuntu 20.04 mini. It’s a minimal install that we can just add on the pieces that we need to complete our Frigate: Linux Manual Install. If you choose another flavour of Linux, the basic steps in this article will be the same but you may need to modify some of the commands for your specific flavour.
Start off by downloading Ubuntu 20.04 Mini from this link:
http://archive.ubuntu.com/ubuntu/dists/bionic/main/installer-amd64/current/images/netboot/mini.iso
You can install Linux on bare metal or you can do what I’ve done and install it in a Proxmox Virtual Machine. You can also read more digiMoot Proxmox Articles.
2. Install Prerequisites
Once you’ve gotten Linux / Ubuntu installed, we will need to make sure it has the necessary packages for the next steps in this article. Run the following command:
sudo apt-get update
sudo apt-get install git net-tools openssh-server samba curl nfscommon
Select yes to install all of these packages.
3. Setup Directory Structure
We’re going to put all the configurations files for Frigate and Docker-Compose into the home directory of the user you’re currently logged in as. We’ll make a couple of directories for us to work in:
mkdir ~/docker-compose
mkdir ~/docker-compose/frigate
Let’s make a folder for our footage which we will link our network NFS share in later steps:
sudo mkdir /mnt/footage
4. Setup Samba (Optional)
We are going to install and setup a samba share which will allow you to access and edit the config files a bit easier. This is optional and you could edit your configs via SSH or a program like WinSCP instead if you choose.
We installed samba as part of the prerequisites above, and now we have to add a samba user to access this share. You will need this user name and password to access the samba share from other computers. Enter the following command, substituting [username] for the samba user, and follow the prompts:
sudo smbpasswd -a [username]
Now lets backup our current samba share config just in case we bugger something up:
sudo cp /etc/samba/smb.conf /etc/samba/smb.bak
Now that it is backed up, we can edit the samba config and add a share. Run the following command to edit the config:
sudo nano /etc/samba/smb.conf
We will be adding the following to the end of the smb.conf file:
[config] comment = config path = “/home/*user*/docker-compose/†writeable = yes create mask = 0644 directory mask = 0755 force user = *user*
You will need to replace *user* with the name of your user your currently logged in as and as noted in the directory setup section above.
Now we can restart the smb daemon service with the following command:
sudo service smbd restart
You should now be able to browse this share from a separate computer over samba. From your windows computer, in windows explorer, you can browse to (or type it in the browser bar at the top, replacing <your-ip-address> with the IP address of the computer you’re working on:
\\<your-ip-address>\config
5. Install Docker and Docker-Compose
We will be running Frigate through docker-compose as recommended by the developer (blakeblackshear). So let us go ahead and install docker and then docker-compose.
First we will install docker by downloading a script to a temporary directory and then running it.
mkdir ~/temp
cd ~/temp
curl -fsSL https://get.docker.com -o get-docker.sh
sudo sh get-docker.sh
Next we will install docker-compose by running the following command:
sudo curl -L "https://github.com/docker/compose/releases/download/1.29.2/docker-compose-$(uname -s)-$(uname -m)" -o /usr/local/bin/docker-compose
This is of course for the latest release at the time of writing this article. You many need to check the list of docker-compose releases and replace the link in the command above with the appropriate current version.
Now we need to set the correct permissions:
sudo chmod +x /usr/local/bin/docker-compose
Just in case the install location of docker-compose is different than expected, lets create a link using this command:
sudo ln -s /usr/local/bin/docker-compose /usr/bin/docker-compose
6. Setup Frigate Container
OK, now we’re finally ready to create a Frigate container using Docker-Compose. First lets make sure we are in the correct folder for the next few steps:
cd ~/docker-compose/frigate
Now we need to create a docker-compose yaml file which includes all the information docker-compose needs about the frigate container. This file will be placed at ~/docker-compose/frigate/docker-compose.yml
.
You will need to paste the following into the file. You need to be careful when pasting into the file that the indentation is not lost. We’ve setup samba shares above to allow you to directly edit the file from another (Windows) machine and that is probably the easiest way to properly edit.
You can also do this by connecting via SSH or by creating the file locally and then uploading with something like WinSCP.
version: '3.9' services: frigate: container_name: frigate privileged: true # this may not be necessary for all setups restart: unless-stopped image: blakeblackshear/frigate:stable-amd64 devices: - /dev/bus/usb:/dev/bus/usb - /dev/dri/renderD128 # for intel hwaccel, needs to be updated for your hardware volumes: - /etc/localtime:/etc/localtime:ro - ./config/frigate.yml:/config/config.yml:ro # - ./media/:/media/frigate - /mnt/footage:/media/frigate - type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear target: /tmp/cache tmpfs: size: 1000000000 ports: - "5000:5000" - "1935:1935" # RTMP feeds # environment: # FRIGATE_RTSP_PASSWORD: password
You will notice that in this file, we’ve changed the default media location to /mnt/footage which we will link to our network storage shortly.
7. Setup MQTT Server
If you don’t already have one up in running in Home Assistant, you will need to set one up for Frigate. This is not a problem and is quick and easy.
From your Home Assistant interface, click “Supervisor” on the left hand menu. On the top menu now, click on “Add-on Store”. Search the list of add-ons and find Mosquitto Broker. Click on it and select install from the next menu.
Once it is installed, make sure it is set to start at boot and then go ahead and start it.
8. Configure Frigate
You need to create a frigate.yml for your Frigate config. This file will be placed in the ~/docker-compose/frigate/config/frigate.yml
directory.
This file will be specific for your camera and system setup and you can review the configuration options as described at https://blakeblackshear.github.io/frigate/configuration/index
If you have a Reolink Camera, you use the information in digiMoot’s Frigate NVR: Reolink Camera Configuration article to optimize your Reolink cameras in Frigate. If you’re using something other than Reolink, I’ve included a standard Frigate config below with descriptor comments as an example below.
A few notes:
- You will need to point the host in the mqtt section to the ip address of your home assistant install.
- make sure you get the width and height of your camera correct otherwise things will look very wonky.
- This Youtube video from EveryThingSmarthome does a good job in walking you through the basics.
- If you have a Reolink Cameara, you should optimize performance of the camera in Frigate by following this Frigate NVR: Reolink Camera Configuration article.
mqtt: host: 10.10.11.199 user: mqtt-user password: password cameras: # Required: name of the camera front_camera_frigate: # Required: ffmpeg settings for the camera ffmpeg: # Required: A list of input streams for the camera. See documentation for more information. inputs: # Required: the path to the stream # NOTE: Environment variables that begin with 'FRIGATE_' may be referenced in {} - path: *path to main camera stream* # Required: list of roles for this stream. valid values are: detect,record,clips,rtmp # NOTICE: In addition to assigning the record, clips, and rtmp roles, # they must also be enabled in the camera config. roles: - detect - rtmp - path: *path to sub camera stream* roles: - clips # Optional: stream specific global args (default: inherit) global_args: # Optional: stream specific hwaccel args (default: inherit) hwaccel_args: # Optional: stream specific input args (default: inherit) input_args: # Optional: camera specific global args (default: inherit) global_args: # Optional: camera specific hwaccel args (default: inherit) hwaccel_args: # Optional: camera specific input args (default: inherit) input_args: # Optional: camera specific output args (default: inherit) output_args: # Required: width of the frame for the input with the detect role width: 1280 # Required: height of the frame for the input with the detect role height: 720 # Optional: desired fps for your camera for the input with the detect role # NOTE: Recommended value of 5. Ideally, try and reduce your FPS on the camera. # Frigate will attempt to autodetect if not specified. fps: 5 # Optional: camera level motion config motion: # Optional: motion mask # NOTE: see docs for more detailed info on creating masks mask: 0,900,1080,900,1080,1920,0,1920 # Optional: timeout for highest scoring image before allowing it # to be replaced by a newer image. (default: shown below) best_image_timeout: 60 # Optional: zones for this camera zones: # Required: name of the zone # NOTE: This must be different than any camera names, but can match with another zone on another # camera. front_steps: # Required: List of x,y coordinates to define the polygon of the zone. # NOTE: Coordinates can be generated at https://www.image-map.net/ coordinates: 545,1077,747,939,788,805 # Optional: Zone level object filters. # NOTE: The global and camera filters are applied upstream. filters: person: min_area: 5000 max_area: 100000 threshold: 0.7 # Optional: Camera level detect settings detect: # Optional: enables detection for the camera (default: True) # This value can be set via MQTT and will be updated in startup based on retained value enabled: True # Optional: Number of frames without a detection before frigate considers an object to be gone. (default: 5x the frame rate) max_disappeared: 25 # Optional: save clips configuration clips: # Required: enables clips for the camera (default: shown below) # This value can be set via MQTT and will be updated in startup based on retained value enabled: False # Optional: Number of seconds before the event to include in the clips (default: shown below) pre_capture: 5 # Optional: Number of seconds after the event to include in the clips (default: shown below) post_capture: 5 # Optional: Objects to save clips for. (default: all tracked objects) objects: - person # Optional: Restrict clips to objects that entered any of the listed zones (default: no required zones) required_zones: [] # Optional: Camera override for retention settings (default: global values) retain: # Required: Default retention days (default: shown below) default: 10 # Optional: Per object retention days objects: person: 15 # Optional: 24/7 recording configuration record: # Optional: Enable recording (default: global setting) enabled: False # Optional: Number of days to retain (default: global setting) retain_days: 30 # Optional: RTMP re-stream configuration rtmp: # Required: Enable the live stream (default: True) enabled: True # Optional: Configuration for the jpg snapshots written to the clips directory for each event snapshots: # Optional: Enable writing jpg snapshot to /media/frigate/clips (default: shown below) # This value can be set via MQTT and will be updated in startup based on retained value enabled: False # Optional: print a timestamp on the snapshots (default: shown below) timestamp: False # Optional: draw bounding box on the snapshots (default: shown below) bounding_box: False # Optional: crop the snapshot (default: shown below) crop: False # Optional: height to resize the snapshot to (default: original size) height: 175 # Optional: Restrict snapshots to objects that entered any of the listed zones (default: no required zones) required_zones: [] # Optional: Camera override for retention settings (default: global values) retain: # Required: Default retention days (default: shown below) default: 10 # Optional: Per object retention days objects: person: 15 # Optional: Configuration for the jpg snapshots published via MQTT mqtt: # Optional: Enable publishing snapshot via mqtt for camera (default: shown below) # NOTE: Only applies to publishing image data to MQTT via 'frigate///snapshot'. # All other messages will still be published. enabled: True # Optional: print a timestamp on the snapshots (default: shown below) timestamp: True # Optional: draw bounding box on the snapshots (default: shown below) bounding_box: True # Optional: crop the snapshot (default: shown below) crop: True # Optional: height to resize the snapshot to (default: shown below) height: 270 # Optional: Restrict mqtt messages to objects that entered any of the listed zones (default: no required zones) required_zones: [] # Optional: Camera level object filters config. objects: track: - person - car # Optional: mask to prevent all object types from being detected in certain areas (default: no mask) # Checks based on the bottom center of the bounding box of the object. # NOTE: This mask is COMBINED with the object type specific mask below mask: 0,0,1000,0,1000,200,0,200 filters: person: min_area: 5000 max_area: 100000 min_score: 0.5 threshold: 0.7 # Optional: mask to prevent this object type from being detected in certain areas (default: no mask) # Checks based on the bottom center of the bounding box of the object mask: 0,0,1000,0,1000,200,0,200
Again, the best way to edit this file will be over the samba connection. However you can also edit from command line or if you connected via ssh (so that it’s easier to copy and paste) or edit the file locally and upload using a program like WinSCP.
9. Create NFS Share
OK we are almost there; our last step is going to be connect to the NFS share which is where we will store all of the clips and recordings. You don’t need to complete this step, but storing on a file server makes the clips more accessible and easier to backup as needed.
To start this step, you will need to have created an NFS share on your server and might have followed digiMoot’s TrueNAS: NFS Network Share article. Of course if you have an NFS share setup on another server, you can also go ahead and use that.
So lets run a command line command to make sure it’s working before making it a bit more permanent. Run the following replacing the IP address with the correct IP address of your server with the NFS share and the share name (the word after the ‘:/’ with the name of the share on your server.
sudo mount -t nfs 10.10.0.10:/sharename/var/mnt/footage
If the command is successful you should be able to go to /mnt/footage
and do an ‘ls’ and see the contents of the NFS share.
If this worked, we can make this mount permanent by editing the fstab file. Edit this file by running:
nano /etc/fstab
and we will need to add the following to the file, replacing the IP address and share location with those appropriate for your setup:
10.10.11.22:/mnt/footage/footage /mnt/footage nfs defaults 0 0
You will of course again need to change the IP address and share name of your server to the correct values. Save by pressing ‘Ctrl-X’ and the ‘Y’. Once saved, run this command to mount all saved mount locations:
sudo mount -a
Verify that the directory mounted correctly be doing ls /mnt/footage/
and you should see the contents of your NFS share.
10. Test Run Frigate
Great, we should be ready to start the Frigate container now! Go to the directory with docker-compose.yml by using cd ~/docker-compose/frigate/
and running the following command:
sudo docker-compose up
Some interesting stuff is going to happen now. First docker will download the necessary docker containers and you will see something like this:
Once all the download have completed, it will run the container and you will see something more like this:
Once you see this, Frigate should be up and running. You can open your web browser and navigate to the link below, replacing the IP address with the one of your ubuntu/linux server that we’ve been working on:
You should see the Frigate webUI now.
Congrats! Frigate is up and running.
Now we can stop Frigate running and make it start automatically on boot. Go back to the console and press Ctrl-C to exit the container running.
Autostart Frigate on Boot
OK now we are going to create script to start frigate automatically. We’re going to create the following script in ~/docker-compose/frigate_start.sh
. You can create this over the samba share or you can run nano ~/docker-compose/frigate_start.sh
. Paste or type the following in the file, making sure to replace *user* with your user name:
#!/bin/bash cd /home/*user*/docker-compose/frigate sudo docker-compose up
Save the file by pressing ‘Ctrl-X’ and then ‘Y’. And then lets make sure this file has execute permissions:
sudo chmod +x ~/docker-compose/frigate_start.sh
And now we have to create a service file. Edit a file with the following command:
sudo nano /etc/systemd/system/frigate_start.service
And paste or type the following information into the file, replacing *user* with the user you are logged in as:
[Units] Description=Startup Frigate on boot. [Service] ExecStart=/home/*user*/docker-compose/frigate_start.sh [Install] WantedBy=multi-user.target
Now run the following commands:
sudo systemctl daemon-reload
sudo systemctl enable frigate_start.service
sudo systemctl start frigate_start.service
Conclusion
That’s it for this Frigate NVR: Linux Manual Install article! Your Linux server running Frigate automatically on boot should be up and running! The next step is to integrate Frigate NVR with Home Assistant through digiMoot’s Frigate NVR: Home Assistant Integration article. Open that up now to get things integrated.
~digiMoot
Sources:
https://blakeblackshear.github.io/frigate/installation/
Hi
First, thanks for this great work.
I have this error then running ‘sudo docker-compose up’:
ERROR: yaml.scanner.ScannerError: while scanning an anchor
in “./docker-compose.yml”, line 21, column 9
expected alphabetic or numeric character, but found ‘;’
in “./docker-compose.yml”, line 21, column 13
I don’t know much yet about the docker system, so maybe you have an idea of what that could be?
There is an error in the docker-compose.yml example.
ports:
– "5000:5000"
– "1935:1935"
should be
ports:
– “5000:5000”
– “1935:1935”
Thanks for catching that. I’ve fixed it in the post.
I think nfscommon should be nfs-common in the prerequisites
in the nfs share is it normal for it to be constantly putting small video clips inside recording even though i only have it setup for events? and then when i check the web interface all i have is the events like it should be. does it just constantly record and then clean it up ? or is something wrong
BTW This was the most helpful article Ive found and I was looking pretty hard. so thank you sooooo much.
Hi digiMoot, just want to say thank you for an excellent article about this – found it after some googling – this should been linked directly to from documentation site.
If you found it helpful feel free to link so others can find it.
Hi digiMoot, I’ve installed this Frigate on a NUC running Debian. I want to set up the share against homeassistant’s shared /media. HA version installed are HassOS.
sudo mount -t nfs 10.10.0.10:/sharename/var/mnt/footage this is for nfs file.
How can I do the mount to the Home Assistant /media share?
I have the same intention. Did you find a solution for this?
Hi, your guide proposes installing MQTT via HA’s “Supervisor” menu, but that menu does not exist in the containerized version of HA. Perhaps it did when this article was written, but it doesn’t seem so anymore. Per HA’s documentation, supervised only exists on HasOS and on HA running under Debian (not Ubuntu). If that was also the case when this article was written, can you add the steps necessary to get HA (supervised) installed on Ubuntu? Otherwise, could you enhance the MQTT section to include a stand-alone install of an MQTT broker?
Thanks for the write up. Note that docker-compose changed for version 2. You need to add a ‘v’ before the latest version number. e.g. v2.12.2
I’m going to try this out to overcome i’m running my HA in a VM and it doesn’t work the coral properly. I’m assuming this will fix that. I’ll get a cheap mini pc and run it next to it. Do you think that’s a good idea? Any recommendations on the mini pc?
Or should i run everything on bare metal. I guess when stuff breaks it will be easier for me to restore HA, and frigate i can setup quickly thanks to your article!
Hi digiMoot, thank’s for sharing. Any idea, where I can find the correct hwaccel (docker-compose.yml) for my Khaddas Vim2?