geerlingguy / pi-nvr

Raspberry Pi NVR for home CCTV recording.
209 stars 22 forks source link

Get Frigate working (with Coral TPU) #4

Closed geerlingguy closed 6 months ago

geerlingguy commented 1 year ago

I would like to see if I can get Frigate working well... it seems to have a lot of momentum, especially around GPU or TPU-accelerated use.

They have a suggested Docker Compose setup: https://docs.frigate.video/frigate/installation

It looks like they have arm64 images available, yay! https://hub.docker.com/r/blakeblackshear/frigate/tags

geerlingguy commented 1 year ago

Downside to Coral support—only the USB Coral module will work with the Raspberry Pi currently (see notes: https://pipci.jeffgeerling.com/cards_m2/coral-accelerator-ae-key.html).

The M.2 PCIe versions won't work because of driver issues with the CM4 PCIe bus. (Note: Pi 5 may work with the PCIe version... however that version requires some specific / older Python libraries that could cause incompatibilities with Frigate...).

But could still be a good option, we'll see. I might need to use a different CM4 IO board than the one I'm currently using (BitPiRat) so I can have a USB 2.0 interface.

geerlingguy commented 1 year ago

I have it running:

Screen Shot 2023-01-12 at 11 45 56 AM

However, nothing happens, and if I go to docker logs, I see:

[2023-01-12 11:46:08] frigate.app                    INFO    : Starting Frigate (0.11.1-2eada21)
*************************************************************
*************************************************************
***    Your config file is not valid!                     ***
***    Please check the docs at                           ***
***    https://docs.frigate.video/configuration/index     ***
*************************************************************
*************************************************************
***    Config Validation Errors                           ***
*************************************************************
2 validation errors for FrigateConfig
mqtt
  field required (type=value_error.missing)
cameras
  field required (type=value_error.missing)
Traceback (most recent call last):
  File "/opt/frigate/frigate/app.py", line 332, in start
    self.init_config()
  File "/opt/frigate/frigate/app.py", line 82, in init_config
    user_config = FrigateConfig.parse_file(config_file)
  File "/opt/frigate/frigate/config.py", line 942, in parse_file
    return cls.parse_obj(config)
  File "/usr/local/lib/python3.9/dist-packages/pydantic/main.py", line 521, in parse_obj
    return cls(**obj)
  File "/usr/local/lib/python3.9/dist-packages/pydantic/main.py", line 341, in __init__
    raise validation_error
pydantic.error_wrappers.ValidationError: 2 validation errors for FrigateConfig
mqtt
  field required (type=value_error.missing)
cameras
  field required (type=value_error.missing)

*************************************************************
***    End Config Validation Errors                       ***
*************************************************************
[cmd] python3 exited 1
[cont-finish.d] executing container finish scripts...
[cont-finish.d] done.
...
geerlingguy commented 1 year ago

Off to https://docs.frigate.video/configuration/index I go!

geerlingguy commented 1 year ago

MQTT's auth is a bit annoying. You have to manually create user / password pairs if you want to do that, after the mosquitto container is running...

geerlingguy commented 1 year ago

Things are mostly working, but MQTT is not starting up correctly because I don't have the automated hashing of the user/pass pair working correctly yet. I might do something like install mqtt client on the managed server (or run it in a Docker container temporarily or something), just to encrypt the auth file passwords.

It's a bit annoying but might be doable. Just didn't want to have to add in more mqtt-specific tasks in the playbook.

geerlingguy commented 7 months ago

See also: Unleash your Home Cameras with FRIGATE Self-Hosted AI Video Recorder! Install on Proxmox LXC (from @apalrd)

geerlingguy commented 6 months ago

I have everything working (including event detection with USB Coral TPU), but I need to clean things up a bit and finish abstracting out the configuration so I can make it work with multiple locations more easily (right now the frigate config hardcodes one camera, my Annke C800 at 4K resolution).

frigate-pi-5

There were a few issues I had to sort out.

First, I ran into the dumb Python thinks I'm not bright enough to manage my own system install, ha!, so I added this task to fix up the This environment is externally managed error:

    - name: Ignore PEP 668 because it's silly.
      ansible.builtin.file:
        path: /usr/lib/python3.11/EXTERNALLY-MANAGED
        state: absent

I also ran into problems with Ansible's current docker_compose module—see: https://github.com/ansible-collections/community.docker/pull/739 (and older discussion at https://github.com/ansible-collections/community.docker/pull/586).

Then I messed with the C800 camera stream settings until I could get it working (it looks like it's a popular enough camera model it has it's own little section in the Frigate docs: https://docs.frigate.video/configuration/camera_specific/#annke-c800).

geerlingguy commented 6 months ago

This is well in hand at this point, running quite stable. Going to close this issue and move more work to #8.