Skip to content

Commit

Permalink
Issue #4: Frigate configuration work.
Browse files Browse the repository at this point in the history
  • Loading branch information
geerlingguy committed Jan 12, 2023
1 parent f6b8849 commit 77b2264
Show file tree
Hide file tree
Showing 10 changed files with 138 additions and 21 deletions.
4 changes: 4 additions & 0 deletions .github/FUNDING.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
# These are supported funding model platforms
---
github: geerlingguy
patreon: geerlingguy
30 changes: 30 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
---
name: CI
'on':
pull_request:
push:
branches:
- master
schedule:
- cron: "9 10 * * 0"

jobs:

lint:
name: Lint
runs-on: ubuntu-latest
steps:
- name: Check out the codebase.
uses: actions/checkout@v2

- name: Set up Python 3.
uses: actions/setup-python@v2
with:
python-version: '3.x'

- name: Install test dependencies.
run: pip3 install yamllint

- name: Lint code.
run: |
yamllint .
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
inventory.ini
32 changes: 22 additions & 10 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,44 +1,56 @@
# Raspberry Pi NVR Configuration

This repository contains a Raspberry Pi NVR configuration so a Pi 4 or CM4 can be used as an NVR, or Network Video Recorder, for capturing and managing CCTV/IP camera streams.
This repository contains Raspberry Pi NVR configurations so a Pi 4 or CM4 can be used as an NVR, or Network Video Recorder, for capturing and managing CCTV/IP camera streams.

Currently I'm experimenting with which DVR application I'm going to use. So I'm not updating the README further until I pick something.
Currently I'm experimenting with many different DVR applications.

See the 'NVR Solutions' section below for current thoughts.
See the 'NVR Solutions' section below for my thoughts on different applications, and read through the GitHub issues to see current progress in testing.

## Raspberry Pi Setup

For an NVR, you're going to want to use storage other than built-in eMMC (CM4 only) or microSD (Lite CM4 or Pi 4 model B). For my own purposes, I'm booting a Pi off of an NVMe drive, using the new [native NVMe boot option](https://www.jeffgeerling.com/blog/2021/raspberry-pi-can-boot-nvme-ssds-now) on the CM4.
For an NVR, you should use storage other than built-in eMMC (CM4 only) or microSD (Lite CM4 or Pi 4 model B). For my own purposes, I'm booting a Pi off of an NVMe drive, using the new [native NVMe boot option](https://www.jeffgeerling.com/blog/2021/raspberry-pi-can-boot-nvme-ssds-now) on the CM4.

You also need a lot of storage—multiple TB of storage is best if you want any form of long-term archive.

And finally, some applications like Frigate work great if you add on something like Google Coral TPU via USB. But for now I'm not doing that.
And finally, some applications like Frigate work great if you add on something like Google Coral TPU via USB.

To prep the Pi, make sure you are running the latest version of Raspberry Pi OS, can reach the Pi over SSH, and can log into it with something like `ssh [email protected]` (that's the default address I'm using to test).

## Installation

TODO. Install Ansible, run playbook.
Make sure you have Ansible installed (I install with Pip: `pip3 install ansible`).

Copy the `example.inventory.ini` to `inventory.ini` and change the IP address under the `[dvr]` section to the IP or hostname of your Pi, and the username after `ansible_user` to your Pi username.

Run the Ansible playbook to prepare the Pi for NVR applications:

```
ansible-playbook main.yml
```

> Ideally you will have set up an [SSH key pair](https://www.raspberrypi-spy.co.uk/2019/02/setting-up-ssh-keys-on-the-raspberry-pi/) to access the Pi without entering a password. If you need to enter a password to SSH into the Pi, add `-K` after the `ansible-*` commands and Ansible will prompt you for the password when it runs.
Then run specific NVR playbook, e.g.

```
ansible-playbook shinobi/main.yml
ansible-playbook frigate/main.yml
```

### Shinobi First-time setup
Be sure to have storage settings configured (e.g. any network or local mounts) prior to starting any of these applications.

### Frigate setup

The Frigate `docker-compose` configures the Frigate storage volume to be synced to `/mnt/frigate`, so you should either mount a network share in that path, or create a local volume there.

In my case, I either set up a RAID volume or a single disk (NVMe, SSD, or HDD), and made sure it was mounted at the path `/mnt/frigate` before running the playbook.

### Shinobi setup

After the playbook completes, visit the URL of your NVR, at the `/super` path, e.g. `http://dvr.local:8080/super`. The default login credentials are:

- Email: `[email protected]`
- Password: `admin`

TODO.

## Raspberry Pi NVR Solutions

Here are my notes on different options for DVR/NVR/CCTV solutions that could run on the Pi:
Expand Down
6 changes: 6 additions & 0 deletions example.inventory.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
[dvr]
10.0.100.80

[dvr:vars]
ansible_user=admin
frigate_rtsp_password=changeme
12 changes: 6 additions & 6 deletions frigate/docker-compose.yml → frigate/docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@ services:
container_name: frigate
# privileged: true
restart: unless-stopped
# See: https://github.com/blakeblackshear/frigate/issues/5046
image: blakeblackshear/frigate:stable
shm_size: "64mb" # update for your cameras based on calculation above
shm_size: "64mb"
devices:
- /dev/bus/usb:/dev/bus/usb # passes the USB Coral, needs to be modified for other versions
- /dev/apex_0:/dev/apex_0 # passes a PCIe Coral, follow driver instructions here https://coral.ai/docs/m2/get-started/#2a-on-linux
- /dev/dri/renderD128 # for intel hwaccel, needs to be updated for your hardware
- /dev/bus/usb:/dev/bus/usb # passes the USB Coral
volumes:
- /etc/localtime:/etc/localtime:ro
- ./frigate.yml:/config/config.yml:ro
- /media/frigate
- {{ frigate_storage_path }}:/media/frigate
- /db
- type: tmpfs # Optional: 1GB of memory, reduces SSD/SD Card wear
target: /tmp/cache
tmpfs:
Expand All @@ -22,4 +22,4 @@ services:
- "5000:5000"
- "1935:1935" # RTMP feeds
environment:
FRIGATE_RTSP_PASSWORD: "password"
FRIGATE_RTSP_PASSWORD: "{{ frigate_rtsp_password }}"
File renamed without changes.
55 changes: 55 additions & 0 deletions frigate/main.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
- hosts: dvr
become: true

vars:
frigate_storage_path: /mnt/frigate

handlers:
- name: Restart frigate
community.docker.docker_compose:
project_src: "~/frigate/"
build: false
restarted: true
become: false

pre_tasks:
- name: Update apt cache.
ansible.builtin.apt: update_cache=yes cache_valid_time=600

tasks:
- name: Ensure pip is installed.
ansible.builtin.apt:
name: python3-pip
state: present

- name: Install required python libraries.
ansible.builtin.pip:
name:
- docker
- docker-compose
state: present

- name: Create Frigate folder on Pi.
ansible.builtin.file:
path: "~/frigate"
state: directory
mode: '0755'
become: false

- name: Copy Frigate files to Pi.
ansible.builtin.template:
src: "{{ item }}"
dest: "~/frigate/{{ item }}"
mode: '0640'
become: false
notify: Restart frigate
with_items:
- docker-compose.yml.j2
- frigate.yml.j2

- name: Ensure Frigate is running.
community.docker.docker_compose:
project_src: "~/frigate/"
build: false
become: false
2 changes: 0 additions & 2 deletions inventory.ini

This file was deleted.

17 changes: 14 additions & 3 deletions main.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
vars:
docker_users: ['pi']

handlers:
- name: reboot pi
ansible.builtin.reboot:

pre_tasks:
- name: Update apt cache.
ansible.builtin.apt: update_cache=yes cache_valid_time=600
Expand All @@ -13,6 +17,13 @@
- geerlingguy.docker

tasks:
- meta: noop

# TODO: gpu_mem=256 in the bottom of /boot/config.txt
- name: Increase gpu_mem to maximum in config.txt
community.general.ini_file:
path: /boot/config.txt
no_extra_spaces: true
section: all
option: 'gpu_mem'
value: '256'
mode: 0755
backup: false
notify: reboot pi

0 comments on commit 77b2264

Please sign in to comment.