Frigate integration!

Good evening @lmilcent and @guim31

Let’s start with a bit of context: I host Gladys and Frigate on a Rock64 (ROCK64 - PINE64), which is a rather basic CPU backed by 4GB of memory. For Gladys, it « does the job. » For Frigate, on the other hand, it seems rather compromised. Here is the load status when Frigate is in « detection » mode:

image

Additionally, Frigate doesn’t detect anything, and that’s where I wonder if my Frigate configuration is correct. The instructions for installing and configuring the integration are very precise (but I admit they are a bit complex for a beginner), however, I followed Claude’s basic instructions to configure a test camera…

I’ll start by trying to find a Coral USB, configure it, and reduce the CPU load before going any further…

Have a nice evening,

Jean

How many cameras do you have? What resolutions?

One thing is certain, the Coral will greatly relieve your CPU!!
It’s still important, especially since you already have Gladys on it, which suffers from this high load during Frigate detections

If it can help you, here is my Frigate config, on a server without a TPU.

The trick is to perform detection on a lower quality image and on a limited number of images per second. I didn’t invent anything, Claude did it for me.

The relevant extract:

    detect:
      enabled: true            # object detection enabled by default
      width: 1536
      height: 864
      fps: 5

Full config:

# Managed by Ansible — frigate role
# Documentation: https://docs.frigate.video/configuration/

mqtt:
  enabled: true
  host: IP_GLADYS_HERE
  port: 1883
  topic_prefix: frigate
  client_id: frigate
  user: gladys
  password: REMOVED

# Hardware acceleration for my CPU which is an Intel UHD 770 iGPU (i5-13500T)
ffmpeg:
  hwaccel_args: preset-intel-qsv-h264
  output_args:
    record: preset-record-generic-audio-aac

# Object detector
# https://docs.frigate.video/configuration/object_detectors
detectors:
  ov:
    type: openvino
    device: GPU   # Intel iGPU via OpenVINO

# Detection model (required for OpenVINO) — SSDLite MobileNet v2 provided
# in the image at /openvino-model (fast, lightweight).
model:
  width: 300
  height: 300
  input_tensor: nhwc
  input_pixel_format: bgr
  path: /openvino-model/ssdlite_mobilenet_v2.xml
  labelmap_path: /openvino-model/coco_91cl_bkgr.txt

# Go2rtc — restream of camera streams (My cameras are Raspberry Pi)
go2rtc:
  streams:
    pi3-cam: rtsp://10.15.10.155:8554/cam

# Recording — Frigate 0.16+ scheme
# https://docs.frigate.video/configuration/record
record:
  enabled: true
  # Continuous recording (0 = disabled, only keeps motion/alerts)
  continuous:
    days: 0
  # Motion-triggered recording
  motion:
    days: 30
  # Retention of segments related to alerts/object detections
  alerts:
    retain:
      days: 30
      mode: motion
  detections:
    retain:
      days: 30
      mode: motion

# Global motion detection
motion:
  threshold: 30
  improve_contrast: true

# Globally tracked objects — limits detection and feeds MQTT state topics per object: frigate/<cam>/<object> (ON/OFF) + frigate/<cam>/<object>/snapshot
objects:
  track:
    - person


# Cameras
cameras:
  pi3-cam:
    ffmpeg:
      inputs:
        - path: rtsp://10.15.10.155:8554/cam
          roles: [detect, record]
    detect:
      enabled: true            # object detection enabled by default
      width: 1536
      height: 864
      fps: 5
    # Motion mask: excludes the OSD area (date/time/hostname engraved
    # on the side of MediaMTX) — otherwise the scrolling text triggers motion + detection.
    # Normalized coordinates 0-1, polygon "x1,y1,x2,y2,...".
    motion:
      mask:
        - 0,0,0.33,0,0.33,0.07,0,0.07
    record:
      enabled: true
    snapshots:
      enabled: true
      timestamp: true          # timestamp engraved on snapshots
      bounding_box: true
      retain:
        default: 30
  
version: 0.17-0

For a camera in front of the entrance with not too much movement:

Amazing! Thanks for the integration, I was really looking forward to it :wink:
Installation and configuration remain quite simple. Device detection works well.

Here are a few oddities I encountered while testing for a few minutes:

  • Once detected, devices can no longer be modified (assignment to rooms or name change), there is an error message on the UI.

  • Detection worked well on my living room camera, but on the one in the garden, it didn’t report the info to Gladys (see capture): log ok, frigate ok, log ok. EDIT: However, I just rechecked Gladys and there is a car event that has been reported since (except it’s not the one I « captured », I need to do more tests)

  • The status does not update via websocket in the interface, you have to refresh the page

  • The « presence detected » status never resets (after 4 hours it is still displayed)

Really great overall, I’ll be able to associate frigate with alarm events, it was annoying to be recorded all the time.

Thanks for the detailed feedback, I’m working on it!

Thanks @ProtZ for this very complete feedback! Here’s what I found:

Devices that can’t be modified: a bug on Gladys’s side. The Devices screen returns the full device, including the camera image, and Gladys refuses anything over 100 KB. Version 0.3.2 keeps the image under 60 KB. After the update, wait a minute (time for the small image to replace the old one), then try again.

Car not re-detected, frozen states, presence that never resets: your logs show Frigate connecting to the broker, getting disconnected 0.4 seconds later, and repeating every 10 seconds. It’s offline almost all the time, so most of its messages (including the “0” that resets the presence) are lost. This is almost always another MQTT client using the same client_id as Frigate (frigate by default): a second Frigate, an old container still running, another tool… You should see MQTT disconnected in a loop in Frigate’s logs. Give each one its own mqtt.client_id and everything should work.

Version 0.3.2 makes the integration more robust in this case: it clearly signals this in the status, and it re-reads the present objects when Frigate comes back, so a presence won’t stay stuck.

Let me know if this also fixes the display that only updated when refreshing the page?

Simple question.

To what extent could you, or could you not, allow the one-click deployment of the Frigate container?

This was planned as part of the development of Terdious at the time, and I think it’s closer to the philosophy of Gladys to offer a turnkey solution…

This is not a criticism, I don’t have a compatible camera at the moment so I don’t have the possibility to test a complete installation :wink:

Good question, for me the idea was to propose the integration of a connector to Frigate, but I’m working on the subject to see what’s possible and the limits.

In itself, it’s interesting for a newcomer.

I’ll let you get ahead on Frigate… In the meantime, I’ll see how I can reduce the CPU load :slight_smile:

I’ve looked into the subject a bit more, and it won’t be possible.

If I take the example of Zigbee2MQTT, it’s a « core » module of Gladys, which removes a number of limitations.

External modules have very limited capabilities and possibilities, for good reason, to ensure the stability and security of Gladys.

So planning to install Frigate in Gladys isn’t possible with these limitations. Moreover, it’s not Gladys’s purpose to be a « self-hosting » box either. Other solutions do this very well and it would be complementary and interesting for you, I imagine.

I agree with you, but @Terdious was able to do it as a sub-container of the external integration thanks to @pierre-gilles:

On my side, I had tested its integration with a docker frigate that installed itself and the whole thing worked really well.

Thanks for your feedback and actions @lmilcent:

  1. the device modification is fixed
  2. mqtt is weird I didn’t find any other client connected to my mqtt so in doubt I migrated mosquitto from 1.6.5 to 2.x: no idea if it’s related but it works well now (and I’ll stay vigilant),
  3. the presence detection update works and updates correctly

however: the motion feature remains at « Motion detected » and no longer turns off. I think it’s more a misunderstanding on my part than a real issue. I’ll look into it.

Yes it’s possible, but the CPU and RAM limit is a first problem. Then, including Frigate increases the image from a few Mb to 4Gb for everyone, even those who don’t want Frigate.

This ultimately results in a heavier container and reduced capabilities in Frigate. I find that the benefit is not amazing.

Hello,

I just received an email about your exchanges on this topic, so I’m here to help quickly. I’m so sorry to be so unavailable lately…

So @lmilcent, if I’m not mistaken, there’s no question of including anything in the image.
The download and installation of Frigate is done on demand. There’s no question of including such a heavy image ^^

I’m a bit more optimistic than @mutmut though :sweat_smile: the development was in core Gladys integration. I hadn’t yet developed any external integration, and I hadn’t yet tested @pierre-gilles’ development. However, the link that @mutmut provided is good, and @pierre-gilles’ development was supposed to provide the same possibilities. So it should definitely be possible. We’ll see if a piece is missing when testing the code.

You might be able to give your AI, in addition to the SDK, what I did on my dev branches so it can use it: GitHub - Terdious/Gladys at frigate-pr10-remote-instance · GitHub

The principle was to use the installation of a container or a remote instance.

Hope I could help!! Good luck :wink:

That’s exactly what I was saying in the end: impossible via an external installation, as it stands.

If I understand your approach, it was to propose a button in the « Frigate connector » module that would deploy a sub-container on demand with Frigate? After digging into the subject, it still seemed quite limited, as the Linux capabilities are very restrictive. It would therefore be impossible to perform certain processes, and the hardware limitations (CPU + RAM) imposed on containers are also very restrictive.

Now I can test it, and we’ll see how it goes in practice. It could very well be a first step for a first camera, by explaining the model’s limitations in the integration itself!

Yes, exactly: a « remote instance » mode (what you did) + an « on-demand managed container » mode, in the same integration.

I looked at the current core code, it’s not impossible, it’s limited:

Already possible via the manifest (containers[]):

  • start: "manual" → the sub-container only starts when the integration calls startContainer() (so via a button/action)
  • memory_mb up to 4096, cpu up to 2, shm_mb up to 512
  • read_only: false (the spec specifically mentions Frigate)
  • devices: coral-usb, coral-pcie, gpu (/dev/dri → OpenVINO/QSV), video

The real hard limits in buildSubContainerDescriptor.js:

  • PidsLimit: 100 (including threads) → probably the first blocker for Frigate
  • /tmp in tmpfs 64 MB → too tight for /tmp/cache if recording
  • CapDrop ALL → to test with s6-overlay
  • 3 ports max (Frigate needs 4)
  • the image is downloaded at installation even in manual (install.js L76-79)

My advice: a quick test with frigate in manual, read_only: false, memory_mb: 2048, shm_mb: 256, 1 camera without recording → we’ll quickly know if the pids/capabilities block.
The rest can be addressed with one or two small core PRs to propose to @pierre-gilles (pids_limit / tmpfs size / 4 ports in the manifest, and image download on first start for manual only).

Let me know if you need help with that, even if with AI I shouldn’t be much more useful :sweat_smile: :+1:

I did the study but I didn’t have time to post and you did it for me :sweat_smile:

It does indeed require at least 2 core changes: allowing an additional Linux capability and increasing the pids.

What bothers me about all this is that we’re debating a request that, in my opinion, isn’t really home automation. We’ll have to decide with @pierre-gilles whether we move forward with specific exceptions for this service or whether we officially say no.

Thanks for the study! I agree we need to make a decision with @pierre-gilles, but I don’t see Frigate as an exception:

  • There is precedent: The core already installs Mosquitto, Zigbee2MQTT, Node-RED, and Matterbridge in containers for a plug-and-play experience. Frigate fits the same logic (just as complex to install as an MQTT broker for a beginner).
  • That was the purpose of sub-containers: Pierre-Gilles presented them with Frigate + Mosquitto as an example, and the spec already mentions Frigate for read_only: false.
  • It’s home automation: detection → scene triggers → notifications, which is exactly what your integration already does very well :+1:

Rather than an exception, I would propose generic, bounded, and user-displayed fields, like memory_mb / devices today: pids_limit, a closed list of capabilities granted by the user (same principle as hardware classes), tmpfs size. This serves Frigate, but also any future heavy integration.

And to be clear: the two modes are complementary, not opposed. The remote instance remains essential (Pi, NAS, Frigate already installed elsewhere). But someone with a suitable machine should be able to do everything in Gladys, without being limited by fixed ceilings (4 GB / 2 CPU today, regardless of the machine).

For that, the core would need to know the machine (Gladys already reads host RAM/CPU for the System screen), with limits relative to the host, a recommended value calculated by the integration (number of cameras, resolution, detected Coral/GPU), and a user setting with a warning beyond the recommended value.

That’s what I had planned in the original core integration, and I don’t think the fact of moving to an external integration diverges on this point, right?