mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-30 01:07:07 +03:00
Compare commits
119
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
40f6b5f545 | ||
|
|
3a1f4eca4c | ||
|
|
3ad3802988 | ||
|
|
3bca9b8676 | ||
|
|
8c88754664 | ||
|
|
890bb6cf9c | ||
|
|
65e34317eb | ||
|
|
e17005c6b4 | ||
|
|
fabb8b0119 | ||
|
|
8c3a2610bb | ||
|
|
39d1053d0c | ||
|
|
ce5b26dc11 | ||
|
|
d85527ffd2 | ||
|
|
4b1ae76baa | ||
|
|
dfd1fa91b5 | ||
|
|
05a6233b5a | ||
|
|
510ef221c2 | ||
|
|
1c30924ff1 | ||
|
|
3c122150ae | ||
|
|
a19e23ae2d | ||
|
|
aadbda1104 | ||
|
|
6c09629783 | ||
|
|
8a7d89170b | ||
|
|
97f2096534 | ||
|
|
640ae1058a | ||
|
|
499cbcfc89 | ||
|
|
106d59b683 | ||
|
|
19d1a0f216 | ||
|
|
77a3095f12 | ||
|
|
dfcb7da995 | ||
|
|
740b155a1b | ||
|
|
77a58a59ea | ||
|
|
fb9c928de5 | ||
|
|
f2a264c15e | ||
|
|
f22278bcfa | ||
|
|
128729f5ac | ||
|
|
d04ed58d8f | ||
|
|
8e9607eccd | ||
|
|
ceb0374c2b | ||
|
|
ec5f6d4f7f | ||
|
|
1d8adec669 | ||
|
|
190f4e0bd2 | ||
|
|
74a5973f6d | ||
|
|
0a9ad3cd7e | ||
|
|
126dfeebeb | ||
|
|
930b845937 | ||
|
|
d3b7d4ea44 | ||
|
|
7fd81171f0 | ||
|
|
0e3dca5915 | ||
|
|
9276502e4f | ||
|
|
bb04e6d49d | ||
|
|
cc94cbc2da | ||
|
|
b2f5315e09 | ||
|
|
a655ddcb2e | ||
|
|
806ee66562 | ||
|
|
42f5a7560b | ||
|
|
21836c7444 | ||
|
|
e70eba2fb8 | ||
|
|
e0b5a6c965 | ||
|
|
6733a757e8 | ||
|
|
94e700fbac | ||
|
|
5f59f7c53c | ||
|
|
0e2da4e24a | ||
|
|
dade7a6b3e | ||
|
|
329430760e | ||
|
|
2fbb66e475 | ||
|
|
5019984a33 | ||
|
|
db58f9f5cc | ||
|
|
f83b8b57db | ||
|
|
146d61017e | ||
|
|
86c9b4bf74 | ||
|
|
ed1a515c1b | ||
|
|
c013f6dcb8 | ||
|
|
bb1736bb4d | ||
|
|
68988780cd | ||
|
|
c148063e76 | ||
|
|
37ca717f63 | ||
|
|
b6d16fb6f3 | ||
|
|
e45b7de79b | ||
|
|
a1f8f95497 | ||
|
|
cabbfd5d73 | ||
|
|
20a3bd7ac5 | ||
|
|
e287833e8d | ||
|
|
e150c5d1dd | ||
|
|
60c4e37303 | ||
|
|
3ac35fe777 | ||
|
|
8b0325aefb | ||
|
|
c57b48e977 | ||
|
|
74a2aac866 | ||
|
|
2af6dc34da | ||
|
|
9eb336a3d8 | ||
|
|
bb0e2c0d5e | ||
|
|
2d25f9a8b5 | ||
|
|
06d1365056 | ||
|
|
8a88cefc9a | ||
|
|
fba967c74b | ||
|
|
33c55649a4 | ||
|
|
c88434dc29 | ||
|
|
e7256d58a1 | ||
|
|
b2a7e992c9 | ||
|
|
11f4dd194c | ||
|
|
0e7da1bee4 | ||
|
|
14870f5237 | ||
|
|
ca851a9238 | ||
|
|
81cf7be89a | ||
|
|
7d12583ebc | ||
|
|
52d469ed20 | ||
|
|
a9105e12f1 | ||
|
|
d4ebe64fde | ||
|
|
b55723146d | ||
|
|
d9ce4b061b | ||
|
|
62d775672b | ||
|
|
d7c6e83ae3 | ||
|
|
74ca38dfb9 | ||
|
|
c6b0f4de9f | ||
|
|
98079cbeca | ||
|
|
197e740be7 | ||
|
|
6716cd3d6f | ||
|
|
3eee34ad7f |
@@ -4,6 +4,8 @@ inputs:
|
||||
GITHUB_TOKEN:
|
||||
required: true
|
||||
outputs:
|
||||
image-repo:
|
||||
value: ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}
|
||||
image-name:
|
||||
value: ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ steps.create-short-sha.outputs.SHORT_SHA }}
|
||||
cache-name:
|
||||
@@ -42,7 +44,7 @@ runs:
|
||||
- name: Set up Docker Buildx
|
||||
uses: docker/setup-buildx-action@v4
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
|
||||
@@ -136,9 +136,6 @@ updates:
|
||||
# Later versions need Node 22 and extract false keys
|
||||
- dependency-name: "i18next-cli"
|
||||
versions: [">1.5.11"]
|
||||
# 6.11.0 refills the saved model in the GenAI settings form
|
||||
- dependency-name: "@rjsf/*"
|
||||
versions: ["6.11.0"]
|
||||
|
||||
- package-ecosystem: "npm"
|
||||
directory: "/docs"
|
||||
|
||||
@@ -423,6 +423,11 @@ jobs:
|
||||
run: docker rm -f frigate || true
|
||||
arm64_build:
|
||||
runs-on: ubuntu-22.04-arm
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
name: ARM Build
|
||||
steps:
|
||||
- name: Check out code
|
||||
@@ -435,6 +440,7 @@ jobs:
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push arm64 standard build
|
||||
id: standard-arm64
|
||||
uses: docker/build-push-action@v7
|
||||
with:
|
||||
context: .
|
||||
@@ -445,6 +451,13 @@ jobs:
|
||||
tags: |
|
||||
${{ steps.setup.outputs.image-name }}-standard-arm64
|
||||
cache-from: type=registry,ref=${{ steps.setup.outputs.cache-name }}-arm64
|
||||
- name: Attest arm64 standard build
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ${{ steps.setup.outputs.image-repo }}
|
||||
subject-digest: ${{ steps.standard-arm64.outputs.digest }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
- name: Build and push RPi build
|
||||
uses: docker/bake-action@v7
|
||||
with:
|
||||
@@ -458,6 +471,11 @@ jobs:
|
||||
*.cache-to=type=registry,ref=${{ steps.setup.outputs.cache-name }}-arm64,mode=max
|
||||
jetson_jp6_build:
|
||||
runs-on: ubuntu-22.04-arm
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
name: Jetson Jetpack 6
|
||||
steps:
|
||||
- name: Check out code
|
||||
@@ -470,6 +488,7 @@ jobs:
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push TensorRT (Jetson, Jetpack 6)
|
||||
id: tensorrt-jp6
|
||||
env:
|
||||
ARCH: arm64
|
||||
BASE_IMAGE: nvcr.io/nvidia/tensorrt:23.12-py3-igpu
|
||||
@@ -485,8 +504,20 @@ jobs:
|
||||
tensorrt.tags=${{ steps.setup.outputs.image-name }}-tensorrt-jp6
|
||||
*.cache-from=type=registry,ref=${{ steps.setup.outputs.cache-name }}-jp6
|
||||
*.cache-to=type=registry,ref=${{ steps.setup.outputs.cache-name }}-jp6,mode=max
|
||||
- name: Attest TensorRT (Jetson, Jetpack 6)
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ${{ steps.setup.outputs.image-repo }}
|
||||
subject-digest: ${{ fromJSON(steps.tensorrt-jp6.outputs.metadata)['tensorrt']['containerimage.digest'] }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
amd64_extra_builds:
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
name: AMD64 Extra Build
|
||||
needs:
|
||||
- amd64_build
|
||||
@@ -501,6 +532,7 @@ jobs:
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push TensorRT (x86 GPU)
|
||||
id: tensorrt
|
||||
env:
|
||||
COMPUTE_LEVEL: "50 60 70 80 90"
|
||||
uses: docker/bake-action@v7
|
||||
@@ -513,7 +545,15 @@ jobs:
|
||||
tensorrt.tags=${{ steps.setup.outputs.image-name }}-tensorrt
|
||||
*.cache-from=type=registry,ref=${{ steps.setup.outputs.cache-name }}-tensorrt
|
||||
*.cache-to=type=registry,ref=${{ steps.setup.outputs.cache-name }}-tensorrt,mode=max
|
||||
- name: Attest TensorRT (x86 GPU)
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ${{ steps.setup.outputs.image-repo }}
|
||||
subject-digest: ${{ fromJSON(steps.tensorrt.outputs.metadata)['tensorrt']['containerimage.digest'] }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
- name: AMD/ROCm general build
|
||||
id: rocm
|
||||
env:
|
||||
HSA_OVERRIDE: 0
|
||||
uses: docker/bake-action@v7
|
||||
@@ -526,8 +566,20 @@ jobs:
|
||||
rocm.tags=${{ steps.setup.outputs.image-name }}-rocm
|
||||
*.cache-to=type=registry,ref=${{ steps.setup.outputs.cache-name }}-rocm,mode=max
|
||||
*.cache-from=type=registry,ref=${{ steps.setup.outputs.cache-name }}-rocm
|
||||
- name: Attest AMD/ROCm general build
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ${{ steps.setup.outputs.image-repo }}
|
||||
subject-digest: ${{ fromJSON(steps.rocm.outputs.metadata)['rocm']['containerimage.digest'] }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
arm64_extra_builds:
|
||||
runs-on: ubuntu-22.04-arm
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
name: ARM Extra Build
|
||||
needs:
|
||||
- arm64_build
|
||||
@@ -542,6 +594,7 @@ jobs:
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push Rockchip build
|
||||
id: rk
|
||||
uses: docker/bake-action@v7
|
||||
with:
|
||||
source: .
|
||||
@@ -551,8 +604,20 @@ jobs:
|
||||
set: |
|
||||
rk.tags=${{ steps.setup.outputs.image-name }}-rk
|
||||
*.cache-from=type=gha
|
||||
- name: Attest Rockchip build
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ${{ steps.setup.outputs.image-repo }}
|
||||
subject-digest: ${{ fromJSON(steps.rk.outputs.metadata)['rk']['containerimage.digest'] }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
synaptics_build:
|
||||
runs-on: ubuntu-22.04-arm
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
name: Synaptics Build
|
||||
needs:
|
||||
- arm64_build
|
||||
@@ -567,6 +632,7 @@ jobs:
|
||||
with:
|
||||
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
|
||||
- name: Build and push Synaptics build
|
||||
id: synaptics
|
||||
uses: docker/bake-action@v7
|
||||
with:
|
||||
source: .
|
||||
@@ -576,10 +642,22 @@ jobs:
|
||||
set: |
|
||||
synaptics.tags=${{ steps.setup.outputs.image-name }}-synaptics
|
||||
*.cache-from=type=gha
|
||||
- name: Attest Synaptics build
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ${{ steps.setup.outputs.image-repo }}
|
||||
subject-digest: ${{ fromJSON(steps.synaptics.outputs.metadata)['synaptics']['containerimage.digest'] }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
# The majority of users running arm64 are rpi users, so the rpi
|
||||
# build should be the primary arm64 image
|
||||
assemble_default_build:
|
||||
runs-on: ubuntu-22.04
|
||||
permissions:
|
||||
contents: read
|
||||
packages: write
|
||||
attestations: write
|
||||
id-token: write
|
||||
name: Assemble and push default build
|
||||
needs:
|
||||
- amd64_build
|
||||
@@ -590,7 +668,7 @@ jobs:
|
||||
with:
|
||||
string: ${{ github.repository }}
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
@@ -598,8 +676,16 @@ jobs:
|
||||
- name: Create short sha
|
||||
run: echo "SHORT_SHA=${GITHUB_SHA::7}" >> $GITHUB_ENV
|
||||
- uses: int128/docker-manifest-create-action@v2
|
||||
id: manifest
|
||||
with:
|
||||
tags: ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ env.SHORT_SHA }}
|
||||
sources: |
|
||||
ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ env.SHORT_SHA }}-amd64
|
||||
ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}:${{ env.SHORT_SHA }}-rpi
|
||||
- name: Attest default build
|
||||
uses: actions/attest@v4
|
||||
with:
|
||||
subject-name: ghcr.io/${{ steps.lowercaseRepo.outputs.lowercase }}
|
||||
subject-digest: ${{ steps.manifest.outputs.digest }}
|
||||
push-to-registry: true
|
||||
create-storage-record: false
|
||||
|
||||
@@ -18,7 +18,7 @@ jobs:
|
||||
with:
|
||||
string: ${{ github.repository }}
|
||||
- name: Log in to the Container registry
|
||||
uses: docker/login-action@81c6f93d4bc991e510b342a00b419b3bb4efc5c6
|
||||
uses: docker/login-action@8aa5831fb8d48d8f76594c7ddde61ae58019f550
|
||||
with:
|
||||
registry: ghcr.io
|
||||
username: ${{ github.actor }}
|
||||
|
||||
@@ -6,7 +6,7 @@ This document provides coding guidelines and best practices for contributing to
|
||||
|
||||
Frigate NVR is a realtime object detection system for IP cameras that uses:
|
||||
|
||||
- **Backend**: Python 3.13+ with FastAPI, OpenCV, TensorFlow/ONNX
|
||||
- **Backend**: Python 3.11 with FastAPI, OpenCV, TensorFlow/ONNX
|
||||
- **Frontend**: React with TypeScript, Vite, TailwindCSS
|
||||
- **Architecture**: Multiprocessing design with ZMQ and MQTT communication
|
||||
- **Focus**: Minimal resource usage with maximum performance
|
||||
@@ -23,7 +23,7 @@ When reviewing code, do NOT comment on:
|
||||
|
||||
### Python Requirements
|
||||
|
||||
- **Compatibility**: Python 3.13+
|
||||
- **Compatibility**: Python 3.11 (the version in the Docker image)
|
||||
- **Language Features**: Use modern Python features:
|
||||
- Pattern matching
|
||||
- Type hints (comprehensive typing preferred)
|
||||
@@ -97,11 +97,12 @@ When reviewing code, do NOT comment on:
|
||||
|
||||
### Async Programming
|
||||
|
||||
- **External I/O**: All external I/O operations must be async
|
||||
- **Best Practices**:
|
||||
- Avoid sleeping in loops - use `asyncio.sleep()` not `time.sleep()`
|
||||
- **Scope**: Frigate is mostly synchronous multiprocess code, and most API handlers are plain `def` running in FastAPI's threadpool. These rules apply to code that is already `async def`.
|
||||
- **Blocking I/O**: A handler that does blocking work (peewee queries, `requests`, subprocess) should be a plain `def`, not an `async def` that blocks the event loop
|
||||
- **Best Practices** (inside `async def`):
|
||||
- Use `asyncio.sleep()`, not `time.sleep()`
|
||||
- Avoid awaiting in loops - use `asyncio.gather()` instead
|
||||
- No blocking calls in async functions
|
||||
- No blocking calls
|
||||
- Use `asyncio.create_task()` for background operations
|
||||
- **Thread Safety**: Use proper synchronization for shared state
|
||||
|
||||
|
||||
@@ -14,11 +14,11 @@
|
||||
|
||||
set -euo pipefail
|
||||
|
||||
driver_version="v2.6.0"
|
||||
driver_version="v2.7.0"
|
||||
# the commit the tag resolves to, since DEEPX signs neither tags nor releases
|
||||
# and this is compiled and installed as root. Update both together
|
||||
driver_commit="7074748e7104f470b02f517583abba652b3f05fa"
|
||||
firmware_version="v2.7.4"
|
||||
driver_commit="8455be625439e005d7b3a375cc79087f4b570404"
|
||||
firmware_version="v2.7.6"
|
||||
|
||||
sudo apt-get update
|
||||
sudo apt-get install -y git build-essential "linux-headers-$(uname -r)" pciutils wget
|
||||
@@ -69,10 +69,10 @@ if ! compgen -G "/dev/dxrt*" > /dev/null; then
|
||||
exit 1
|
||||
fi
|
||||
|
||||
runtime_version="v3.4.0"
|
||||
runtime_version="v3.5.0"
|
||||
declare -A runtime_sha256=(
|
||||
[amd64]="736cfef009ce9e974ab1ab610d867239d19d72a426a53e367ddcbd53297b6e20"
|
||||
[arm64]="eb6107f5f02f2ad76ae89f414e8b5f346f34fbc6f0888236136853a26be6f6a0"
|
||||
[amd64]="c1993416e43059fb4751b2fd093d4232ab2ae8e67a5ec4156c79889e66260f64"
|
||||
[arm64]="f7c942ddfa325f435de3ab9a42b32b322f97dacff7f3468a37e32a6386a03681"
|
||||
)
|
||||
|
||||
runtime_release="${runtime_version#v}"
|
||||
@@ -127,5 +127,5 @@ echo "Runtime version: ${runtime_release}"
|
||||
echo "Device node(s): $(echo /dev/dxrt*)"
|
||||
echo
|
||||
echo "This driver expects NPU firmware ${firmware_version}. Check it with:"
|
||||
echo " dxrt-cli --status"
|
||||
echo " dxcli -s"
|
||||
echo "Update the module if it does not match before starting Frigate."
|
||||
|
||||
@@ -245,6 +245,9 @@ ENV PYTHONWARNINGS="ignore:::numpy.core.getlimits"
|
||||
# Set HailoRT to disable logging
|
||||
ENV HAILORT_LOGGER_PATH=NONE
|
||||
|
||||
# Disable ONNX Runtime's usage telemetry to Microsoft
|
||||
ENV ORT_DISABLE_TELEMETRY=1
|
||||
|
||||
# TensorFlow C++ logging suppression (must be set before import)
|
||||
# TF_CPP_MIN_LOG_LEVEL: 0=all, 1=INFO+, 2=WARNING+, 3=ERROR+ (we use 3 for errors only)
|
||||
ENV TF_CPP_MIN_LOG_LEVEL=3
|
||||
|
||||
@@ -46,3 +46,4 @@ make -C /tmp/media-driver/build -j"$(nproc)"
|
||||
|
||||
# Install driver to rootfs for COPY --from
|
||||
make -C /tmp/media-driver/build install DESTDIR=/rootfs
|
||||
strip --strip-unneeded /rootfs/usr/lib/x86_64-linux-gnu/dri/iHD_drv_video.so
|
||||
|
||||
@@ -2,9 +2,8 @@
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
NGINX_VERSION="1.27.4"
|
||||
NGINX_VERSION="1.30.7"
|
||||
VOD_MODULE_VERSION="v1.9.1"
|
||||
SECURE_TOKEN_MODULE_VERSION="1.5"
|
||||
SET_MISC_MODULE_VERSION="v0.33"
|
||||
NGX_DEVEL_KIT_VERSION="v0.3.3"
|
||||
|
||||
@@ -52,11 +51,6 @@ patch -d /tmp/nginx-vod-module/ -p1 << 'EOF'
|
||||
EOF
|
||||
|
||||
|
||||
mkdir /tmp/nginx-secure-token-module
|
||||
wget https://github.com/kaltura/nginx-secure-token-module/archive/refs/tags/${SECURE_TOKEN_MODULE_VERSION}.tar.gz
|
||||
tar -zxf ${SECURE_TOKEN_MODULE_VERSION}.tar.gz -C /tmp/nginx-secure-token-module --strip-components=1
|
||||
rm ${SECURE_TOKEN_MODULE_VERSION}.tar.gz
|
||||
|
||||
mkdir /tmp/ngx_devel_kit
|
||||
wget https://github.com/vision5/ngx_devel_kit/archive/refs/tags/${NGX_DEVEL_KIT_VERSION}.tar.gz
|
||||
tar -zxf ${NGX_DEVEL_KIT_VERSION}.tar.gz -C /tmp/ngx_devel_kit --strip-components=1
|
||||
@@ -80,7 +74,6 @@ cd /tmp/nginx
|
||||
--add-module=../ngx_devel_kit \
|
||||
--add-module=../nginx-set-misc-module \
|
||||
--add-module=../nginx-vod-module \
|
||||
--add-module=../nginx-secure-token-module \
|
||||
--with-cc-opt="-O3 -Wno-error=implicit-fallthrough"
|
||||
|
||||
make CC="ccache gcc" -j$(nproc) && make install
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
ruff == 0.17.3
|
||||
ruff == 0.17.5
|
||||
|
||||
# types
|
||||
types-peewee == 4.0.*
|
||||
|
||||
@@ -4,21 +4,21 @@ click == 8.5.*
|
||||
aiohttp == 3.14.*
|
||||
starlette == 1.10.*
|
||||
starlette-context == 0.5.*
|
||||
fastapi[standard-no-fastapi-cloud-cli] == 0.162.*
|
||||
fastapi[standard-no-fastapi-cloud-cli] == 0.165.*
|
||||
uvicorn == 0.54.*
|
||||
slowapi == 0.1.*
|
||||
joserfc == 1.7.*
|
||||
joserfc == 1.8.*
|
||||
cryptography == 50.0.*
|
||||
pathvalidate == 3.3.*
|
||||
markupsafe == 3.0.*
|
||||
python-multipart == 0.0.32
|
||||
python-multipart == 0.0.34
|
||||
# Classification Model Training
|
||||
tensorflow == 2.19.* ; platform_machine == 'aarch64'
|
||||
tensorflow-cpu == 2.21.* ; platform_machine == 'x86_64'
|
||||
# General
|
||||
mypy == 2.4.1
|
||||
onvif-zeep-async == 4.3.*
|
||||
paho-mqtt == 2.1.*
|
||||
paho-mqtt == 2.2.*
|
||||
pandas == 3.0.*
|
||||
peewee == 4.5.*
|
||||
peewee_migrate == 2.3.*
|
||||
@@ -26,7 +26,7 @@ psutil == 7.2.*
|
||||
pydantic == 2.14.*
|
||||
git+https://github.com/fbcotter/py3nvml#egg=py3nvml
|
||||
tzdata == 2026.6
|
||||
pyzmq == 27.2.*
|
||||
pyzmq == 27.3.*
|
||||
ruamel.yaml == 0.19.*
|
||||
tzlocal == 5.4.5
|
||||
requests == 2.34.*
|
||||
@@ -43,13 +43,13 @@ opencv-contrib-python == 4.11.0.*
|
||||
scipy == 1.17.*
|
||||
# OpenVino & ONNX
|
||||
openvino == 2026.4.*
|
||||
onnxruntime == 1.31.*
|
||||
onnxruntime == 1.32.*
|
||||
# Embeddings
|
||||
transformers == 5.22.*
|
||||
# Generative AI
|
||||
google-genai == 2.34.*
|
||||
google-genai == 3.6.*
|
||||
ollama == 0.6.*
|
||||
openai == 3.41.*
|
||||
openai == 3.55.*
|
||||
# push notifications
|
||||
py-vapid == 1.9.6
|
||||
pywebpush == 2.5.*
|
||||
|
||||
@@ -14,11 +14,17 @@ fi
|
||||
# Tell S6-Overlay not to restart this service
|
||||
s6-svc -O .
|
||||
|
||||
# Runs as root with root's HOME and LD_LIBRARY_PATH; -I skips user site-packages
|
||||
# The helper runs as root (-I skips user site-packages). The probe runs as the
|
||||
# service user when the service drops privileges; a root probe relies on
|
||||
# resolve_ffmpeg_path refusing runtime-user-writable paths.
|
||||
function set_libva_version() {
|
||||
local ffmpeg_path
|
||||
ffmpeg_path=$(python3 -I /usr/local/ffmpeg/get_ffmpeg_path.py)
|
||||
LIBAVFORMAT_VERSION_MAJOR=$("$ffmpeg_path" -version | grep -Po "libavformat\W+\K\d+")
|
||||
local probe_as=()
|
||||
if [[ "$(id -u)" -eq 0 && "$runs_as_root" -eq 0 ]]; then
|
||||
probe_as=(s6-setuidgid frigate)
|
||||
fi
|
||||
ffmpeg_path=$(python3 -I /usr/local/ffmpeg/get_ffmpeg_path.py frigate)
|
||||
LIBAVFORMAT_VERSION_MAJOR=$("${probe_as[@]}" "$ffmpeg_path" -version | grep -Po "libavformat\W+\K\d+")
|
||||
export LIBAVFORMAT_VERSION_MAJOR
|
||||
}
|
||||
|
||||
|
||||
@@ -57,10 +57,19 @@ function get_ip_and_port_from_supervisor() {
|
||||
export FRIGATE_GO2RTC_WEBRTC_CANDIDATE_INTERNAL="${ip_address}:${webrtc_port}"
|
||||
}
|
||||
|
||||
# The probe runs as the service user when the service drops privileges; a root
|
||||
# probe relies on resolve_ffmpeg_path refusing runtime-user-writable paths
|
||||
function set_libva_version() {
|
||||
local ffmpeg_path
|
||||
ffmpeg_path=$(python3 -I /usr/local/ffmpeg/get_ffmpeg_path.py)
|
||||
LIBAVFORMAT_VERSION_MAJOR=$("$ffmpeg_path" -version | grep -Po "libavformat\W+\K\d+")
|
||||
local probe_as=()
|
||||
if [[ "$(id -u)" -eq 0 && "$runs_as_root" -eq 0 ]]; then
|
||||
probe_as=(s6-setuidgid go2rtc)
|
||||
fi
|
||||
ffmpeg_path=$(python3 -I /usr/local/ffmpeg/get_ffmpeg_path.py go2rtc)
|
||||
if ! LIBAVFORMAT_VERSION_MAJOR=$("${probe_as[@]}" "$ffmpeg_path" -version | grep -Po "libavformat\W+\K\d+"); then
|
||||
echo "[WARN] Could not read the libavformat version from ${ffmpeg_path} as the go2rtc user; using the bundled build's version"
|
||||
LIBAVFORMAT_VERSION_MAJOR=$("${probe_as[@]}" "/usr/lib/ffmpeg/${DEFAULT_FFMPEG_VERSION}/bin/ffmpeg" -version | grep -Po "libavformat\W+\K\d+")
|
||||
fi
|
||||
export LIBAVFORMAT_VERSION_MAJOR
|
||||
}
|
||||
|
||||
|
||||
@@ -57,6 +57,17 @@ done
|
||||
granted=0
|
||||
failed=0
|
||||
|
||||
reachable() {
|
||||
local node="$1" user
|
||||
local access=(-r "$node" -a -w "$node")
|
||||
if [[ -d "$node" ]]; then
|
||||
access=(-r "$node" -a -x "$node")
|
||||
fi
|
||||
for user in frigate go2rtc; do
|
||||
s6-setuidgid "$user" test "${access[@]}" || return 1
|
||||
done
|
||||
}
|
||||
|
||||
grant() {
|
||||
local node="$1"
|
||||
# nullglob only drops patterns that hold a metacharacter, so a literal
|
||||
@@ -72,6 +83,11 @@ grant() {
|
||||
fi
|
||||
if setfacl -m "$spec" "$node" 2>/dev/null; then
|
||||
granted=$((granted + 1))
|
||||
|
||||
# an unprivileged LXC can't set ACLs on its idmapped nodes, which are often
|
||||
# already world-rw
|
||||
elif reachable "$node"; then
|
||||
return 0
|
||||
else
|
||||
failed=$((failed + 1))
|
||||
echo "[WARN] could not grant device access on ${node}; see EXTRA_GROUPS in the non-root docs for the fallback"
|
||||
|
||||
@@ -80,6 +80,11 @@ cp -r /usr/local/nginx/conf/. /tmp/nginx/conf/
|
||||
|
||||
set_worker_processes
|
||||
|
||||
# A non-root master ignores `user` and warns on every start
|
||||
if [[ "$runs_as_root" -eq 0 ]]; then
|
||||
sed -i '/^user root;$/d' /tmp/nginx/conf/nginx.conf
|
||||
fi
|
||||
|
||||
# TLS certs: user-mounted certs at /etc/letsencrypt/live/frigate (documented
|
||||
# contract) always win; otherwise fall back to a self-signed cert persisted in
|
||||
# /config/tls, which stays writable under a read-only root filesystem.
|
||||
|
||||
@@ -105,6 +105,8 @@ if [[ -n "$sentinel" ]]; then
|
||||
mismatch_expr+=(-a ! -path "$sentinel")
|
||||
fi
|
||||
|
||||
exec 3>&1
|
||||
|
||||
for path in "$@"; do
|
||||
# An absent root is an incomplete sweep, not a finished one: /media/frigate
|
||||
# is not in the image, so a boot before the volume is mounted would
|
||||
@@ -121,7 +123,18 @@ for path in "$@"; do
|
||||
# stale mount. Tolerate it rather than aborting under errexit, but never
|
||||
# read a failed scan as "nothing to do": that would record the sweep as
|
||||
# complete without having looked.
|
||||
if ! count=$(find "$path" -name lost+found -prune -o "${mismatch_expr[@]}" -printf '.' 2>/dev/null | wc -c); then
|
||||
# The walk prints nothing until it ends, so report every 30s through fd 3
|
||||
# (stdout) while the count itself comes back through the substitution.
|
||||
if ! count=$(find "$path" -name lost+found -prune -o "(" "${mismatch_expr[@]}" ")" -printf 'm\n' -o -printf '.\n' 2>/dev/null \
|
||||
| awk -v path="$path" '
|
||||
BEGIN { next_report = systime() + 30 }
|
||||
$0 == "m" { mismatched++ }
|
||||
systime() >= next_report {
|
||||
printf "[INFO] fix-ownership: still scanning %s, %d entries checked, %d need changes\n", path, NR, mismatched > "/dev/fd/3"
|
||||
fflush("/dev/fd/3")
|
||||
next_report = systime() + 30
|
||||
}
|
||||
END { print mismatched + 0 }'); then
|
||||
swept_clean=0
|
||||
echo "[WARN] fix-ownership: could not scan ${path}; will retry on next boot"
|
||||
continue
|
||||
|
||||
@@ -25,4 +25,5 @@ except FileNotFoundError:
|
||||
config: dict[str, Any] = {}
|
||||
|
||||
path = config.get("ffmpeg", {}).get("path", "default")
|
||||
print(resolve_ffmpeg_path(path, "ffmpeg"))
|
||||
service = sys.argv[1] if len(sys.argv) > 1 else "frigate"
|
||||
print(resolve_ffmpeg_path(path, "ffmpeg", service))
|
||||
|
||||
@@ -40,16 +40,10 @@ try:
|
||||
except FileNotFoundError:
|
||||
config: dict[str, Any] = {}
|
||||
|
||||
# No validator runs here, so install environment_vars ourselves. FRIGATE_
|
||||
# names only: anything else lands in os.environ, where the exec gate reads
|
||||
# GO2RTC_ALLOW_ARBITRARY_EXEC.
|
||||
# No validator runs here, so install environment_vars ourselves.
|
||||
config_env_vars = config.get("environment_vars")
|
||||
apply_config_env_vars(
|
||||
{
|
||||
key: value
|
||||
for key, value in config_env_vars.items()
|
||||
if str(key).startswith("FRIGATE_")
|
||||
}
|
||||
{str(key): value for key, value in config_env_vars.items()}
|
||||
if isinstance(config_env_vars, dict)
|
||||
else {}
|
||||
)
|
||||
@@ -103,7 +97,7 @@ if not is_valid_ffmpeg_path(path):
|
||||
print(
|
||||
"[ERROR] ffmpeg path contains spaces, quotes or shell characters, using the default ffmpeg instead."
|
||||
)
|
||||
ffmpeg_path = resolve_ffmpeg_path(path, "ffmpeg")
|
||||
ffmpeg_path = resolve_ffmpeg_path(path, "ffmpeg", "go2rtc")
|
||||
|
||||
for key in apply_go2rtc_ffmpeg_config(go2rtc_config, ffmpeg_path):
|
||||
print(
|
||||
|
||||
@@ -22,3 +22,6 @@ add_header Set-Cookie $auth_cookie;
|
||||
## Pass the location header back up if it exists
|
||||
auth_request_set $redirection_url $upstream_http_location;
|
||||
add_header Location $redirection_url;
|
||||
|
||||
## The add_header lines above stop this location inheriting server-level headers
|
||||
include security_headers.conf;
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
# file, all other path directives follow --prefix and must stay absolute.
|
||||
|
||||
daemon off;
|
||||
# ignored by a non-root master; keeps workers root under FRIGATE_RUN_AS_ROOT
|
||||
# keeps workers root under FRIGATE_RUN_AS_ROOT; the run script strips it otherwise
|
||||
user root;
|
||||
worker_processes auto;
|
||||
|
||||
@@ -143,10 +143,15 @@ http {
|
||||
# version 6 (RFC 8216 section 7); the module default is 4
|
||||
vod_hls_version 6;
|
||||
|
||||
secure_token $args;
|
||||
secure_token_types application/vnd.apple.mpegurl;
|
||||
# Pass the playlist's query args (e.g. Home Assistant's authSig) on
|
||||
# to every URL in it. These match the only URL endings vod writes
|
||||
# with fmp4 and no subtitles.
|
||||
sub_filter_types application/vnd.apple.mpegurl;
|
||||
sub_filter_once off;
|
||||
sub_filter '.m3u8' '.m3u8$is_args$args';
|
||||
sub_filter '.m4s' '.m4s$is_args$args';
|
||||
sub_filter '.mp4"' '.mp4$is_args$args"';
|
||||
|
||||
include security_headers.conf;
|
||||
add_header Cache-Control "no-store";
|
||||
expires off;
|
||||
|
||||
@@ -155,7 +160,6 @@ http {
|
||||
|
||||
location /stream/ {
|
||||
include auth_request.conf;
|
||||
include security_headers.conf;
|
||||
add_header Cache-Control "no-store";
|
||||
expires off;
|
||||
|
||||
@@ -179,7 +183,6 @@ http {
|
||||
}
|
||||
|
||||
expires 7d;
|
||||
include security_headers.conf;
|
||||
add_header Cache-Control "public";
|
||||
autoindex on;
|
||||
root /media/frigate;
|
||||
@@ -220,7 +223,7 @@ http {
|
||||
|
||||
location /ws {
|
||||
include auth_request.conf;
|
||||
proxy_pass http://mqtt_ws/;
|
||||
proxy_pass http://mqtt_ws;
|
||||
include proxy.conf;
|
||||
}
|
||||
|
||||
@@ -284,7 +287,6 @@ http {
|
||||
|
||||
location /api/ {
|
||||
include auth_request.conf;
|
||||
include security_headers.conf;
|
||||
add_header Cache-Control "no-store";
|
||||
expires off;
|
||||
proxy_pass http://frigate_api/;
|
||||
|
||||
@@ -29,11 +29,11 @@ ENV FRIGATE_IMAGE_VARIANT=rk
|
||||
COPY docker/rockchip/COCO /COCO
|
||||
COPY docker/rockchip/conv2rknn.py /opt/conv2rknn.py
|
||||
|
||||
ADD https://github.com/MarcA711/rknn-toolkit2/releases/download/v2.3.2/librknnrt.so /usr/lib/
|
||||
ADD --chmod=644 https://github.com/MarcA711/rknn-toolkit2/releases/download/v2.3.2/librknnrt.so /usr/lib/
|
||||
|
||||
ADD --chmod=111 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-11/ffmpeg /usr/lib/ffmpeg/6.0/bin/
|
||||
ADD --chmod=111 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-11/ffprobe /usr/lib/ffmpeg/6.0/bin/
|
||||
ADD --chmod=111 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/7.1-1/ffmpeg /usr/lib/ffmpeg/7.0/bin/
|
||||
ADD --chmod=111 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/7.1-1/ffprobe /usr/lib/ffmpeg/7.0/bin/
|
||||
ADD --chmod=755 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-11/ffmpeg /usr/lib/ffmpeg/6.0/bin/
|
||||
ADD --chmod=755 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/6.1-11/ffprobe /usr/lib/ffmpeg/6.0/bin/
|
||||
ADD --chmod=755 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/7.1-1/ffmpeg /usr/lib/ffmpeg/7.0/bin/
|
||||
ADD --chmod=755 https://github.com/MarcA711/Rockchip-FFmpeg-Builds/releases/download/7.1-1/ffprobe /usr/lib/ffmpeg/7.0/bin/
|
||||
ENV DEFAULT_FFMPEG_VERSION="6.0"
|
||||
ENV INCLUDED_FFMPEG_VERSIONS="${DEFAULT_FFMPEG_VERSION}:${INCLUDED_FFMPEG_VERSIONS}"
|
||||
|
||||
@@ -26,4 +26,4 @@ ENV FRIGATE_IMAGE_VARIANT=synaptics
|
||||
|
||||
COPY --from=synap1680-wheels /rootfs/usr/local/lib/*.so /usr/lib
|
||||
|
||||
ADD https://raw.githubusercontent.com/synaptics-astra/synap-release/v1.5.0/models/dolphin/object_detection/coco/model/mobilenet224_full80/model.synap /synaptics/mobilenet.synap
|
||||
ADD --chmod=644 https://raw.githubusercontent.com/synaptics-astra/synap-release/v1.5.0/models/dolphin/object_detection/coco/model/mobilenet224_full80/model.synap /synaptics/mobilenet.synap
|
||||
|
||||
@@ -240,7 +240,7 @@ logger:
|
||||
|
||||
# Optional: set environment variables
|
||||
environment_vars:
|
||||
EXAMPLE_VAR: value
|
||||
LIBVA_DRIVER_NAME: i965
|
||||
|
||||
# Optional: birdseye configuration
|
||||
# NOTE: Can (enabled, mode) be overridden at the camera level
|
||||
|
||||
@@ -65,7 +65,16 @@ go2rtc:
|
||||
|
||||
This section sets environment variables in the Frigate process for those unable to modify the environment of the container, like within Home Assistant OS. It's meant for process settings such as `LIBVA_DRIVER_NAME` or the TensorFlow thread counts below. Docker users should set environment variables in their `docker run` command (`-e LIBVA_DRIVER_NAME=i965`) or `docker-compose.yml` file (`environment:` section) instead. Values set here are stored in plain text in your config file, so credentials belong in `secrets.yaml`, Docker environment variables, or Docker secrets instead.
|
||||
|
||||
Names prefixed with `FRIGATE_` set here also take part in `{FRIGATE_VARIABLE_NAME}` substitution (see [below](#substitution-sources-and-precedence)), but `secrets.yaml` is the better home for them.
|
||||
Besides `FRIGATE_` names, only these are accepted, and a variable already set in the container environment keeps its container value:
|
||||
|
||||
- `LIBVA_DRIVER_NAME` and `HSA_OVERRIDE_GFX_VERSION`
|
||||
- `TF_INTRA_OP_PARALLELISM_THREADS`, `TF_INTER_OP_PARALLELISM_THREADS`, `TF_DATASET_THREAD_POOL_SIZE`, and `SHM_MAX_FRAMES`
|
||||
- `USE_FP16`, `HF_HUB_OFFLINE`, and `TRANSFORMERS_OFFLINE`
|
||||
- `HF_ENDPOINT`, `GITHUB_ENDPOINT`, `GITHUB_RAW_ENDPOINT`, and `TF_KERAS_MOBILENET_V2_WEIGHTS_URL` (an `http://` or `https://` URL)
|
||||
|
||||
Any other name is ignored with a warning and must be set in the container environment.
|
||||
|
||||
Names prefixed with `FRIGATE_` set here take part in `{FRIGATE_VARIABLE_NAME}` substitution (see [below](#substitution-sources-and-precedence)), but `secrets.yaml` is the better home for them. Of these, only `FRIGATE_JWT_SECRET` is also set in the process environment.
|
||||
|
||||
<ConfigTabs>
|
||||
<TabItem value="ui">
|
||||
@@ -398,9 +407,9 @@ To do this:
|
||||
2. Update the `ffmpeg.path` in your Frigate config to `/config/custom-ffmpeg`.
|
||||
3. Restart Frigate and the custom version will be used if the steps above were done correctly.
|
||||
|
||||
Both binaries have to be executable by Frigate's unprivileged runtime user, so `chmod 755` them after extracting. The startup ownership sweep runs only once, so anything you add to `/config` later keeps whatever ownership and mode you gave it.
|
||||
Both binaries have to be executable by Frigate's unprivileged runtime user, so `chmod 755` them after extracting. go2rtc runs as its own user, so the build must be world-executable for go2rtc to use it (`ffmpeg:` sources, the birdseye restream and transcoded live streams). The startup ownership sweep runs only once, so anything you add to `/config` later keeps whatever ownership and mode you gave it.
|
||||
|
||||
There is one exception, and it only affects [`FRIGATE_ROOT_SERVICES`](/configuration/non_root#keeping-individual-services-root) listing `frigate`. That mode runs Frigate as root while still handing `/config` to the unprivileged runtime user, so anything running as that user could swap the binary and gain root. A build inside any of Frigate's writable volumes (`/config`, `/media/frigate`, the cache and shm dirs) is ignored there and the bundled one is used, with a warning in the log. Keep the build somewhere root-owned (any absolute `ffmpeg.path` works, so a read-only bind mount such as `/opt/custom-ffmpeg` is enough) if you need both. The default mode and `FRIGATE_RUN_AS_ROOT=true` are unaffected and behave exactly as they always have.
|
||||
There is one exception, and it only affects [`FRIGATE_ROOT_SERVICES`](/configuration/non_root#keeping-individual-services-root) listing `frigate` or `go2rtc`. That mode runs the listed service as root while still handing `/config` to the unprivileged runtime user, so anything running as that user could swap the binary and gain root. A build inside any of Frigate's writable volumes (`/config`, `/media/frigate`, the cache and shm dirs) is ignored by the root service, which uses the bundled one and logs a warning. A service that is not listed keeps using the custom build. Keep the build somewhere root-owned (any absolute `ffmpeg.path` works, so a read-only bind mount such as `/opt/custom-ffmpeg` is enough) if you need both. The default mode and `FRIGATE_RUN_AS_ROOT=true` are unaffected and behave exactly as they always have.
|
||||
|
||||
### Custom go2rtc version
|
||||
|
||||
|
||||
@@ -53,7 +53,7 @@ Each provider handles one or more **roles**: `chat`, `descriptions`, `embeddings
|
||||
| Ollama (`ollama`) | ✅ | ✅ | ✅ | ❌ |
|
||||
| OpenAI (`openai`) | ✅ | ✅ | ❌ | ✅ |
|
||||
| Azure OpenAI (`azure_openai`) | ✅ | ✅ | ❌ | ✅ |
|
||||
| Google Gemini (`gemini`) | ✅ | ✅ | ❌ | ✅ |
|
||||
| Google Gemini (`gemini`) | ✅ | ✅ | ✅ | ✅ |
|
||||
|
||||
A ✅ means Frigate can use the provider for that feature. The configured model must also support it: a vision model for descriptions and chat, a multimodal embedding model for embeddings (see [Embedding models](#embedding-models)), and an audio-capable model for transcription. Some features also need extra provider setup, covered in each provider's section below. OpenAI-compatible servers use the `openai` provider, so they follow the OpenAI row.
|
||||
|
||||
@@ -86,10 +86,11 @@ You must use a vision-capable model with Frigate. The following models are recom
|
||||
|
||||
The `embeddings` role needs a different kind of model. Text queries are matched against the stored image embeddings, so the model must be trained to place images and text into the same vector space. A chat or description model will still return vectors when asked, but those vectors are not trained for retrieval and text searches will return poor matches with no error to indicate why.
|
||||
|
||||
| Model | Notes |
|
||||
| -------------------- | ---------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `embeddinggemma-2` | Multimodal embeddings for [Semantic Search](/configuration/semantic_search#genai-provider). Strong semantic search accuracy with efficient inference on a small model. |
|
||||
| `qwen3-vl-embedding` | Multimodal embeddings for [Semantic Search](/configuration/semantic_search#genai-provider). Good performance, large model that requires strong hardware for inference. |
|
||||
| Model | Type | Notes |
|
||||
| -------------------- | ------- | ------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `embeddinggemma-2` | `local` | Multimodal embeddings for [Semantic Search](/configuration/semantic_search#genai-provider). Strong semantic search accuracy with efficient inference on a small model. |
|
||||
| `qwen3-vl-embedding` | `local` | Multimodal embeddings for [Semantic Search](/configuration/semantic_search#genai-provider). Good performance, large model that requires strong hardware for inference. |
|
||||
| `gemini-embedding-2` | `cloud` | Multimodal embeddings for [Semantic Search](/configuration/semantic_search#genai-provider) via [Google Gemini](#google-gemini). Sends thumbnails and search text to Google. |
|
||||
|
||||
#### Transcription models
|
||||
|
||||
@@ -225,7 +226,7 @@ Frigate supports any provider that implements the OpenAI API standard. This incl
|
||||
|
||||
:::tip
|
||||
|
||||
For OpenAI-compatible servers (such as llama.cpp) that don't expose the configured context size in the API response, you can manually specify the context size in `provider_options`:
|
||||
Frigate reads the model's context size from the server when it is reported (such as by vLLM or OpenRouter). For OpenAI-compatible servers (such as llama.cpp) that don't expose the configured context size in the API response, you can manually specify the context size in `provider_options`:
|
||||
|
||||
```yaml
|
||||
genai:
|
||||
@@ -383,6 +384,26 @@ Other HTTP options are available, see the [python-genai documentation](https://g
|
||||
|
||||
:::
|
||||
|
||||
#### Embeddings
|
||||
|
||||
Gemini can serve the `embeddings` role for [Semantic Search](/configuration/semantic_search#genai-provider) with a multimodal embedding model such as `gemini-embedding-2`. Give that model its own provider entry.
|
||||
|
||||
Reindexing sends every stored thumbnail to Google and uses API quota. See [Network Requirements](/frigate/network_requirements#generative-ai).
|
||||
|
||||
```yaml
|
||||
genai:
|
||||
gemini_embeddings:
|
||||
provider: gemini
|
||||
api_key: "{FRIGATE_GEMINI_API_KEY}"
|
||||
model: gemini-embedding-2
|
||||
roles:
|
||||
- embeddings
|
||||
|
||||
semantic_search:
|
||||
enabled: True
|
||||
model: gemini_embeddings
|
||||
```
|
||||
|
||||
### OpenAI
|
||||
|
||||
OpenAI does not have a free tier for their API.
|
||||
@@ -427,7 +448,7 @@ To use a different OpenAI-compatible API endpoint, set the `OPENAI_BASE_URL` env
|
||||
|
||||
:::tip
|
||||
|
||||
For OpenAI-compatible servers (such as llama.cpp) that don't expose the configured context size in the API response, you can manually specify the context size in `provider_options`:
|
||||
Frigate reads the model's context size from the server when it is reported (such as by vLLM or OpenRouter). For OpenAI-compatible servers (such as llama.cpp) that don't expose the configured context size in the API response, you can manually specify the context size in `provider_options`:
|
||||
|
||||
```yaml {6,7}
|
||||
genai:
|
||||
|
||||
@@ -98,7 +98,7 @@ Additionally, when creating and editing camera groups in the UI, you can choose
|
||||
|
||||
:::note
|
||||
|
||||
Frigate's default dashboard ("All Cameras") will always use the first entry you've defined in streams when playing live streams from your cameras.
|
||||
Frigate's default dashboard ("All Cameras") always uses the first entry in `streams`. That should be your highest quality stream, because Auto starts on the first stream and only steps down from there. To show a lower quality stream on a dashboard, create a camera group and choose the stream in each camera's [streaming settings](#streaming-options-on-camera-group-dashboards) for that group.
|
||||
|
||||
:::
|
||||
|
||||
|
||||
@@ -36,6 +36,8 @@ There are two reasons to use it:
|
||||
|
||||
Try the device grants and `EXTRA_GROUPS` first. The `frigate` service runs the API and every ffmpeg process that decodes your camera streams, so listing it puts those back on root as well, not just your detectors.
|
||||
|
||||
Listing `go2rtc` without `frigate` doesn't separate the two. go2rtc's API accepts unauthenticated config changes from inside the container, so the unprivileged `frigate` service can make a root go2rtc run ffmpeg with any arguments, which can overwrite any file as root.
|
||||
|
||||
A listed service also stops honoring a [custom ffmpeg or go2rtc build](/configuration/advanced/system#custom-dependencies) kept in `/config`, since that directory stays owned by the unprivileged user and a binary there would run as root. `FRIGATE_RUN_AS_ROOT=true` has no such restriction.
|
||||
|
||||
Recordings and exports are owned by `PUID`/`PGID` as soon as they're written, even by a root service. Snapshots, thumbnails, and other files under `clips/` are corrected on each restart, so they can show as root-owned from the host until then. A listed service also keeps root's home directory, so library caches go to the container layer instead of `/config`. The same applies to the [detector runtimes](/frigate/network_requirements#detector-runtimes) Frigate installs at first start (Hailo, MemryX, AXEngine): a root `frigate` service installs them into `/root/.local`, which is lost when the container is recreated, and never loads a copy left behind in `/config/.local`.
|
||||
@@ -71,13 +73,14 @@ Both the script and the boot sweep report progress, so you can tell a slow sweep
|
||||
|
||||
```
|
||||
[INFO] fix-ownership: scanning /media/frigate for ownership mismatches; this may take a while on large filesystems
|
||||
[INFO] fix-ownership: still scanning /media/frigate, 2481000 entries checked, 2390112 need changes
|
||||
[WARN] fix-ownership: adjusting ownership of 4823941 entries under /media/frigate
|
||||
[INFO] fix-ownership: /media/frigate 5% (241197/4823941 entries)
|
||||
[INFO] fix-ownership: /media/frigate 10% (482394/4823941 entries)
|
||||
[INFO] fix-ownership: finished /media/frigate in 12m 4s
|
||||
```
|
||||
|
||||
The scan has no percentage because the total isn't known until it finishes. Watch the boot sweep with `docker logs -f frigate`.
|
||||
The scan has no percentage because the total isn't known until it finishes, so it reports a running count every 30 seconds instead. Watch the boot sweep with `docker logs -f frigate`.
|
||||
|
||||
Once the volumes are aligned, start Frigate normally. A file at `/config/.permissions_version` records what was done, so later boots skip the sweep unless you change `PUID`/`PGID`.
|
||||
|
||||
@@ -382,6 +385,8 @@ One Docker specific trap: published ports are inserted ahead of the host firewal
|
||||
|
||||
`telemetry.stats.network_bandwidth` uses nethogs, which needs `CAP_NET_ADMIN` and `CAP_NET_RAW` and therefore root. The stat is turned off automatically when Frigate isn't running as root, with one warning in the log. Use `FRIGATE_ROOT_SERVICES=frigate` (or `FRIGATE_RUN_AS_ROOT=true`) if you need it.
|
||||
|
||||
Rockchip NPU and GPU usage come from `/sys/kernel/debug`, which the kernel makes readable only by root. To keep these stats, bind the two load files into the container as shown in the [Rockchip installation steps](/frigate/installation#rockchip-platform). Without them, Frigate logs one warning and leaves the stats out.
|
||||
|
||||
go2rtc's ffmpeg processes no longer appear in Intel GPU stats. Frigate reads per-process GPU usage from `/proc/<pid>/fdinfo`, which the kernel won't let one user read for another user's processes, so anything go2rtc spawns is invisible to it. Overall GPU utilization is unaffected.
|
||||
|
||||
If you mount your own TLS certificate at `/etc/letsencrypt/live/frigate`, the private key has to be readable by the runtime user, which runs nginx. Frigate hands the key to that user at startup if the mount is writable; on a read-only mount, make the key readable by uid 1000 (or your `PUID`) yourself.
|
||||
|
||||
@@ -682,7 +682,7 @@ To run a model on a DEEPX NPU, list a `deepx` device on that model.
|
||||
|
||||
:::info
|
||||
|
||||
The DX-RT Python bindings are not part of the Frigate image. They are downloaded and installed into `/config/.local` the first time a DEEPX device is configured, verified against pinned checksums, and updated automatically when a Frigate release pins a new version. If the container has no internet access, see [Detector runtimes](/frigate/network_requirements#detector-runtimes) for how to provide the files yourself.
|
||||
The DX-RT Python bindings are not part of the Frigate image. The `libdxrt-bin` package is downloaded and its `dx_engine` wheel installed into `/config/.local` the first time a DEEPX device is configured, verified against pinned checksums, and updated automatically when a Frigate release pins a new version. The package stays in the runtime cache, so a container recreated without internet access reinstalls from it. If the container has no internet access, see [Detector runtimes](/frigate/network_requirements#detector-runtimes) for how to provide the file yourself.
|
||||
|
||||
:::
|
||||
|
||||
@@ -708,7 +708,7 @@ models:
|
||||
height: 640
|
||||
```
|
||||
|
||||
For PPU models, use a `.dxnn` compiled with DX-COM 2.4.0 or later. Frigate reads the PPU head layout the compiler writes into the file and refuses to load a PPU model without it.
|
||||
For PPU models, use a `.dxnn` compiled with DX-COM 2.4.0 or later. Frigate reads the PPU head layout the compiler writes into the file and refuses to load a PPU model without it. Both the older padded header and the v9 format DX-COM 2.5.0 writes are read, so models from either compiler work with DX-RT 3.5.0.
|
||||
|
||||
`model_type` must be set to `yolo-generic` or `yolox` to match the model; `yolo-generic` is the recommended default unless the model is a raw YOLOX export. Frigate defaults it to `ssd`, which this detector does not support, so the detector refuses to start on a model that leaves it unset.
|
||||
|
||||
|
||||
@@ -414,11 +414,12 @@ Avoid removing audio from only one of the two streams (for example with `-an`).
|
||||
As a general rule, features that read recordings prefer the main stream and fall back to the sub stream for time ranges where the main recordings have expired. Analytics features use only the main stream.
|
||||
|
||||
| Feature | Stream used |
|
||||
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------- |
|
||||
| ---------------------------------------------------------------------------------------- | ------------------------------------------------------------------------------------------------------------------------- |
|
||||
| Recording playback (History and Review) | Both (main preferred with sub fallback by default), or exactly one stream when a quality is selected manually |
|
||||
| Tracking details and Explore clip playback | Main, falling back to sub where the main recordings have expired |
|
||||
| Exports | Both (main preferred with sub fallback by default), or exactly one stream when a quality is selected in the export dialog |
|
||||
| Clip downloads | Main; sub is used when no main recordings remain in the range (streams are never mixed in one file) |
|
||||
| Debug replay | Main; sub is used when no main recordings remain in the range (streams are never mixed in one file) |
|
||||
| Frames grabbed from a recording in History (download snapshot, submit frame to Frigate+) | Main preferred, sub fallback |
|
||||
| Audio extraction (e.g., transcription) | Main preferred, sub fallback |
|
||||
| Motion search | Main only |
|
||||
|
||||
@@ -223,7 +223,7 @@ For security reasons, the `echo:`, `expr:`, and `exec:` stream sources are disab
|
||||
|
||||
go2rtc's `${VAR:default}` variable syntax is also disabled by default in stream sources, since its default can name one of those sources. Use Frigate's [`{FRIGATE_*}` substitution](./config.md#environment-variable-substitution) instead.
|
||||
|
||||
If you attempt to use these sources in your configuration, the streams will be removed and an error message will be printed in the logs.
|
||||
If you attempt to use these sources in your configuration, the streams will be removed and an error message will be printed in the logs. go2rtc also refuses to run anything but Frigate's ffmpeg from `exec:` and `echo:` sources added through its API or `/config/go2rtc_homekit.yml`.
|
||||
|
||||
To enable these sources, you must set the environment variable `GO2RTC_ALLOW_ARBITRARY_EXEC=true`. This can be done in your Docker Compose file or container environment, or for Home Assistant App users with the `go2rtc_allow_arbitrary_exec` option in the App's configuration. The `environment_vars` section of the Frigate config can't enable it:
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import CommunityBadge from '@site/src/components/CommunityBadge';
|
||||
|
||||
Cameras that output H.264 video and AAC audio will offer the most compatibility with all features of Frigate and Home Assistant. It is also helpful if your camera supports multiple substreams to allow different resolutions to be used for detection, streaming, and recordings without re-encoding.
|
||||
|
||||
I recommend Dahua, Hikvision, and Amcrest in that order. Dahua edges out Hikvision because they are easier to find and order, not because they are better cameras. I personally use Dahua cameras because they are easier to purchase directly. In my experience Dahua and Hikvision both have multiple streams with configurable resolutions and frame rates and rock solid streams. They also both have models with large sensors well known for excellent image quality at night. Not all the models are equal. Larger sensors are better than higher resolutions; especially at night. Amcrest is the fallback recommendation because they are rebranded Dahuas. They are rebranding the lower end models with smaller sensors or less configuration options.
|
||||
I recommend Dahua and Hikvision. Dahua edges out Hikvision because they are easier to find and order, not because they are better cameras. I personally use Dahua cameras because they are easier to purchase directly. In my experience Dahua and Hikvision both have multiple streams with configurable resolutions and frame rates and rock solid streams. They also both have models with large sensors well known for excellent image quality at night. Not all the models are equal. Larger sensors are better than higher resolutions; especially at night.
|
||||
|
||||
WiFi cameras are not recommended as [their streams are less reliable and cause connection loss and/or lost video data](https://ipcamtalk.com/threads/camera-conflicts.68142/#post-738821), especially when more than a few WiFi cameras will be used at the same time.
|
||||
|
||||
@@ -17,10 +17,9 @@ Many users have reported various issues with 4K-plus Reolink cameras, it is best
|
||||
|
||||
Here are some of the cameras I recommend:
|
||||
|
||||
- <a href="https://amzn.to/4fwoNWA" target="_blank" rel="nofollow noopener sponsored">Loryta(Dahua) IPC-T549M-ALED-S3</a> (affiliate link)
|
||||
- <a href="https://amzn.to/3YXpcMw" target="_blank" rel="nofollow noopener sponsored">Loryta(Dahua) IPC-T54IR-AS</a> (affiliate link)
|
||||
- <a href="https://amzn.to/3AvBHoY" target="_blank" rel="nofollow noopener sponsored">Amcrest IP5M-T1179EW-AI-V3</a> (affiliate link)
|
||||
- <a href="https://www.bhphotovideo.com/c/product/1705511-REG/hikvision_colorvu_ds_2cd2387g2p_lsu_sl_8mp_network.html" target="_blank" rel="nofollow noopener">HIKVISION DS-2CD2387G2P-LSU/SL ColorVu 8MP Panoramic Turret IP Camera</a> (affiliate link)
|
||||
- <a href="https://link.amazon/B0hnw1JEZ" target="_blank" rel="nofollow noopener sponsored">GemaVision(Dahua) IPC-T549M-ALED-S3</a> (affiliate link)
|
||||
- <a href="https://link.amazon/B06naLGqL" target="_blank" rel="nofollow noopener sponsored">GemaVision(Dahua) IPC-T54IR-AS</a> (affiliate link)
|
||||
- <a href="https://link.amazon/B0iD97zC7" target="_blank" rel="nofollow noopener sponsored">HIKVISION DS-2CD2387G2P-LSU/SL ColorVu 8MP Panoramic Turret IP Camera</a> (affiliate link)
|
||||
|
||||
I may earn a small commission for my endorsement, recommendation, testimonial, or link to any products or services from this website.
|
||||
|
||||
|
||||
@@ -394,22 +394,22 @@ DEEPX NPU support in Frigate is developed and maintained by [Sixfab](https://six
|
||||
|
||||
#### Versions
|
||||
|
||||
A DEEPX install has several separately versioned pieces, and they all have to agree. The driver, the runtime, and the daemon live on the Docker host; Frigate itself carries only the Python bindings, which it downloads on first start:
|
||||
A DEEPX install has several separately versioned pieces, and they all have to agree. The driver, the runtime, and the daemon live on the Docker host; Frigate itself carries none of them, and downloads the matching runtime package for its Python bindings on first start:
|
||||
|
||||
| Component | Version | Installed on | Installed by |
|
||||
| -------------- | -------- | ------------ | ------------------------- |
|
||||
| Kernel driver | `v2.6.0` | Host | `user_installation.sh` |
|
||||
| DX-RT runtime | `v3.4.0` | Host | `user_installation.sh` |
|
||||
| NPU firmware | `v2.7.4` | The module | Flashed from the host |
|
||||
| DX-RT bindings | `v3.4.0` | Frigate | Downloaded at first start |
|
||||
| Kernel driver | `v2.7.0` | Host | `user_installation.sh` |
|
||||
| DX-RT runtime | `v3.5.0` | Host | `user_installation.sh` |
|
||||
| NPU firmware | `v2.7.6` | The module | Flashed from the host |
|
||||
| DX-RT bindings | `v3.5.0` | Frigate | Downloaded at first start |
|
||||
|
||||
:::warning
|
||||
|
||||
A version mismatch does not produce a startup error. It typically shows up as inference requests that are accepted but never return a result, so detections simply stop appearing while Frigate looks healthy. If that happens after a Frigate upgrade, check every version in the table before anything else.
|
||||
A mismatch between the runtime and its Python bindings is caught at import, because the bindings refuse to load against a different runtime version. A mismatch between the runtime, the kernel driver and the firmware can still show up only as inference requests that are accepted but never return a result, so detections stop appearing while Frigate looks healthy. If that happens after a Frigate upgrade, check every version in the table before anything else.
|
||||
|
||||
:::
|
||||
|
||||
The installation script installs the DX-RT runtime on the host and enables `dxrt.service`, so the daemon starts at boot and any other program on the host can share the NPU with Frigate. Check the firmware version with `dxrt-cli --status` and update the module if it does not match the table above.
|
||||
The installation script installs the DX-RT runtime on the host and enables `dxrt.service`, so the daemon starts at boot and any other program on the host can share the NPU with Frigate. Check the firmware version with `dxcli -s` and update the module if it does not match the table above.
|
||||
|
||||
#### Installation
|
||||
|
||||
@@ -435,6 +435,8 @@ ls /run/dxrt/
|
||||
|
||||
#### Setup
|
||||
|
||||
The DX-RT bindings are installed on first start, so the container needs to reach GitHub once. For a host without internet access, seed the package as described in [Detector runtimes](/frigate/network_requirements#detector-runtimes).
|
||||
|
||||
To set up Frigate, follow the default installation instructions, for example: `ghcr.io/blakeblackshear/frigate:stable`
|
||||
|
||||
#### Docker configuration
|
||||
@@ -456,7 +458,7 @@ Add one `--device` per NPU, contiguously from `/dev/dxrt0`, since the client sto
|
||||
|
||||
The installation script configures `dxrt.service` to place its socket in `/run/dxrt` through a systemd drop-in. Mounting the directory rather than the socket file means the container sees the new socket after `dxrt.service` is restarted, rather than holding on to a deleted one.
|
||||
|
||||
`dxrtd` listens on an abstract socket as well, but that one does not cross into a container, so Frigate names the filesystem socket through `DXRT_DYNAMIC_IPC_ENDPOINT` on your behalf. Set that variable on the container yourself only if the daemon listens somewhere else, which means you also set it for `dxrtd` through its own systemd drop-in. The script writes `/etc/systemd/system/dxrt.service.d/frigate.conf` for exactly that, and has `dxrt.service` link the socket to `/tmp/dxrt_dynamic_ipc.sock` when it starts, so the host's own `dxrt-cli` and `dxtop` keep finding it at the default path they fall back to.
|
||||
`dxrtd` listens on an abstract socket as well, but that one does not cross into a container, so Frigate names the filesystem socket through `DXRT_DYNAMIC_IPC_ENDPOINT` on your behalf. Set that variable on the container yourself only if the daemon listens somewhere else, which means you also set it for `dxrtd` through its own systemd drop-in. The script writes `/etc/systemd/system/dxrt.service.d/frigate.conf` for exactly that, and has `dxrt.service` link the socket to `/tmp/dxrt_dynamic_ipc.sock` when it starts, so the host's own `dxcli` and `dxtop` keep finding it at the default path they fall back to.
|
||||
|
||||
:::note
|
||||
|
||||
@@ -468,7 +470,7 @@ The device node is needed as well as the socket, because the client opens the NP
|
||||
|
||||
`/dev/shm` does not need sharing.
|
||||
|
||||
The DX-RT python bindings are not shipped in the Frigate image. Frigate downloads them on first start when a DEEPX detector is configured, and caches them under `/config`.
|
||||
The DX-RT python bindings are not shipped in the Frigate image. Frigate downloads the matching `libdxrt-bin` package on first start when a DEEPX detector is configured, takes the `dx_engine` wheel and the libraries it links against out of it, and keeps the package under `/config` so later reinstalls need no download.
|
||||
|
||||
#### Configuration
|
||||
|
||||
@@ -523,6 +525,27 @@ or add these options to your `docker run` command:
|
||||
--volume /sys/:/sys/:ro
|
||||
```
|
||||
|
||||
Frigate reads NPU and GPU (RGA) usage from `/sys/kernel/debug`, which the kernel makes readable only by root. Frigate's services don't run as root, so to show these stats on the System page, bind the two load files into the container. This works with or without `privileged: true`:
|
||||
|
||||
```yaml
|
||||
volumes:
|
||||
- /sys/kernel/debug/rknpu/load:/rockchip/rknpu/load:ro
|
||||
- /sys/kernel/debug/rkrga/load:/rockchip/rkrga/load:ro
|
||||
```
|
||||
|
||||
or for `docker run`:
|
||||
|
||||
```
|
||||
--volume /sys/kernel/debug/rknpu/load:/rockchip/rknpu/load:ro \
|
||||
--volume /sys/kernel/debug/rkrga/load:/rockchip/rkrga/load:ro
|
||||
```
|
||||
|
||||
These lines are optional, and everything else works without them. Only add a line for a file that exists on your host, because Docker won't start the container if one is missing. Check with:
|
||||
|
||||
```
|
||||
$ sudo ls /sys/kernel/debug/rknpu/load /sys/kernel/debug/rkrga/load
|
||||
```
|
||||
|
||||
#### Configuration
|
||||
|
||||
Next, you should configure [hardware object detection](/configuration/object_detectors#rockchip-platform) and [hardware video processing](/configuration/hardware_acceleration_video#rockchip-platform).
|
||||
|
||||
@@ -66,15 +66,18 @@ The SDKs for a few hardware detectors are not shipped in the Frigate image. They
|
||||
| [MemryX MX3](/configuration/object_detectors#memryx-mx3) | 2.1.0 | `mx_accl_frigate-2.1.0.zip` (the release source archive, renamed) | [GitHub archive](https://github.com/memryx/mx_accl_frigate/archive/refs/tags/v2.1.0.zip) |
|
||||
| [AXERA AXEngine](/configuration/object_detectors#axera) | 0.1.3 | `axengine-0.1.3-py3-none-any.whl` | [GitHub release](https://github.com/AXERA-TECH/pyaxengine/releases/tag/0.1.3-frigate) |
|
||||
| [Axelera Metis](/configuration/object_detectors#axelera-metis) | 1.8.0 | `axelera_runtime-1.8.0-cp311-cp311-manylinux_2_27_x86_64.manylinux_2_28_x86_64.whl` on x86, `axelera_runtime-1.8.0-cp311-cp311-manylinux_2_27_aarch64.manylinux_2_28_aarch64.whl` on arm64, plus `axelera_firmware-1.8.0-py3-none-any.whl` on both | [Axelera Artifactory PyPI](https://software.axelera.ai/artifactory/#web/ui/redirect/pypi/axelera-pypi/simple) |
|
||||
| [DEEPX NPU](/configuration/object_detectors#deepx-npu) | 3.5.0 | `libdxrt-bin_3.5.0_amd64.deb` on x86, `libdxrt-bin_3.5.0_arm64.deb` on arm64 (Frigate installs the `dx_engine` wheel the package carries) | [GitHub](https://github.com/DEEPX-AI/dx_rt/tree/v3.5.0/release/3.5.0) |
|
||||
|
||||
If the container cannot reach GitHub, provide the files yourself:
|
||||
|
||||
1. Download the files for your architecture on a machine with internet access.
|
||||
2. Place them, with exactly the file names listed above, in `/config/model_cache/runtimes/<detector>/`, where `<detector>` is the detector named in your config's `devices` (`hailo`, `memryx`, `axengine`, or `axelera`).
|
||||
2. Place them, with exactly the file names listed above, in `/config/model_cache/runtimes/<detector>/`, where `<detector>` is the detector named in your config's `devices` (`hailo`, `memryx`, `axengine`, `axelera`, or `deepx`).
|
||||
3. Start Frigate. Files whose checksum matches are installed without any download; a file with the wrong checksum is discarded and downloaded again, so a failed startup log names the file to replace.
|
||||
|
||||
The `GITHUB_ENDPOINT` mirror variable below applies to these downloads as well.
|
||||
|
||||
DEEPX pins the runtime package rather than a wheel, so seed the `.deb`. Frigate takes the `dx_engine` wheel and the libraries out of it and keeps the package in the cache, so reinstalling after a container is recreated needs no download.
|
||||
|
||||
### Preventing Model Downloads
|
||||
|
||||
If you have already downloaded all required models and want to prevent Frigate from attempting any outbound connections to HuggingFace or the Transformers library, set the following environment variables on your Frigate container:
|
||||
@@ -114,7 +117,7 @@ See [Frigate+](/integrations/plus) for details.
|
||||
|
||||
### Generative AI
|
||||
|
||||
When a Generative AI provider is configured, Frigate sends images and prompts to the configured provider for event descriptions, chat, and camera monitoring. Available providers:
|
||||
When a Generative AI provider is configured, Frigate sends images and prompts to the configured provider for the various features that are enabled. Available providers:
|
||||
|
||||
| Provider | Internet Required |
|
||||
| ------------- | --------------------------------------------------------------- |
|
||||
|
||||
@@ -5,7 +5,7 @@ title: Updating
|
||||
|
||||
# Updating Frigate
|
||||
|
||||
The current stable version of Frigate is **0.18.2**. The release notes and any breaking changes for this version can be found on the [Frigate GitHub releases page](https://github.com/blakeblackshear/frigate/releases/tag/v0.18.2).
|
||||
The current stable version of Frigate is **0.18.3**. The release notes and any breaking changes for this version can be found on the [Frigate GitHub releases page](https://github.com/blakeblackshear/frigate/releases/tag/v0.18.3).
|
||||
|
||||
Keeping Frigate up to date ensures you benefit from the latest features, performance improvements, and bug fixes. The update process varies slightly depending on your installation method (Docker, Home Assistant App, etc.). Below are instructions for the most common setups.
|
||||
|
||||
@@ -31,21 +31,21 @@ If you’re running Frigate via Docker (recommended method), follow these steps:
|
||||
|
||||
2. **Update and Pull the Latest Image**:
|
||||
- If using Docker Compose:
|
||||
- Edit your `docker-compose.yml` file to specify the desired version tag (e.g., `0.18.2` instead of `0.17.1`). For example:
|
||||
- Edit your `docker-compose.yml` file to specify the desired version tag (e.g., `0.18.3` instead of `0.17.1`). For example:
|
||||
```yaml
|
||||
services:
|
||||
frigate:
|
||||
image: ghcr.io/blakeblackshear/frigate:0.18.2
|
||||
image: ghcr.io/blakeblackshear/frigate:0.18.3
|
||||
```
|
||||
- Then pull the image:
|
||||
```bash
|
||||
docker pull ghcr.io/blakeblackshear/frigate:0.18.2
|
||||
docker pull ghcr.io/blakeblackshear/frigate:0.18.3
|
||||
```
|
||||
- **Note for `stable` Tag Users**: If your `docker-compose.yml` uses the `stable` tag (e.g., `ghcr.io/blakeblackshear/frigate:stable`), you don’t need to update the tag manually. The `stable` tag always points to the latest stable release after pulling.
|
||||
- If using `docker run`:
|
||||
- Pull the image with the appropriate tag (e.g., `0.18.2`, `0.18.2-tensorrt`, or `stable`):
|
||||
- Pull the image with the appropriate tag (e.g., `0.18.3`, `0.18.3-tensorrt`, or `stable`):
|
||||
```bash
|
||||
docker pull ghcr.io/blakeblackshear/frigate:0.18.2
|
||||
docker pull ghcr.io/blakeblackshear/frigate:0.18.3
|
||||
```
|
||||
|
||||
3. **Start the Container**:
|
||||
@@ -100,7 +100,7 @@ If an update causes issues:
|
||||
1. Stop Frigate.
|
||||
2. Restore your backed-up config file and database.
|
||||
3. Revert to the previous image version:
|
||||
- For Docker: Specify an older tag (e.g., `ghcr.io/blakeblackshear/frigate:0.18.1`) in your `docker run` command.
|
||||
- For Docker: Specify an older tag (e.g., `ghcr.io/blakeblackshear/frigate:0.18.2`) in your `docker run` command.
|
||||
- For Docker Compose: Edit your `docker-compose.yml`, specify the older version tag (e.g., `ghcr.io/blakeblackshear/frigate:0.16.4`), and re-run `docker compose up -d`.
|
||||
- For Home Assistant: Restore from the app/addon backup you took before you updated.
|
||||
4. Verify the old version is running again.
|
||||
|
||||
@@ -13,60 +13,92 @@ Please use your own knowledge to assess and vet them before you install anything
|
||||
|
||||
:::
|
||||
|
||||
## [Advanced Camera Card (formerly known as Frigate Card](https://card.camera/#/README)
|
||||
## Cameras and Streaming
|
||||
|
||||
The [Advanced Camera Card](https://card.camera/#/README) is a Home Assistant dashboard card with deep Frigate integration.
|
||||
Tools that help get video from your cameras into Frigate, or change how Frigate's video is delivered.
|
||||
|
||||
## [cctvQL](https://github.com/arunrajiah/cctvql)
|
||||
### [frigate-abr](https://github.com/007hacky007/frigate-abr)
|
||||
|
||||
[frigate-abr](https://github.com/007hacky007/frigate-abr) is a drop-in Docker image of Frigate that adds adaptive bitrate (ABR) playback for recordings: a sidecar transcodes footage to lower quality tiers on demand, for reviewing over slow remote connections. Segments are transcoded when played and cached, so no additional stream is recorded. Frigate itself is not modified.
|
||||
|
||||
### [reostream](https://github.com/VoltTech21/reostream)
|
||||
|
||||
[reostream](https://github.com/VoltTech21/reostream) is a proxy for Reolink cameras that pulls video over Reolink's own protocol (the one the Reolink app and NVR use) instead of the camera's RTSP server, and serves it back as RTSP for go2rtc and Frigate. It helps models whose RTSP stream smears, drops frames or loses full resolution, and supports two-way talk.
|
||||
|
||||
### [Scrypted - Frigate bridge plugin](https://github.com/apocaliss92/scrypted-frigate-bridge)
|
||||
|
||||
[Scrypted - Frigate bridge](https://github.com/apocaliss92/scrypted-frigate-bridge) is a plugin that allows you to ingest Frigate detections, motion, videoclips on Scrypted as well as provide templates to export rebroadcast configurations on Frigate.
|
||||
|
||||
### [Strix](https://github.com/eduard256/Strix)
|
||||
|
||||
[Strix](https://github.com/eduard256/Strix) auto-discovers working stream URLs for IP cameras and generates ready-to-use Frigate configs. It tests thousands of URL patterns against your camera and supports cameras without RTSP or ONVIF. 67K+ camera models from 3.6K+ brands.
|
||||
|
||||
## Events and Media
|
||||
|
||||
Tools that enrich, query, or back up the events, snapshots, and reviews Frigate produces.
|
||||
|
||||
### [cctvQL](https://github.com/arunrajiah/cctvql)
|
||||
|
||||
[cctvQL](https://github.com/arunrajiah/cctvql) is a natural language query layer for Frigate and other CCTV systems. It connects to Frigate's REST API and MQTT broker to let you ask conversational questions about cameras and events (e.g. "Was there motion at the front door last night?"), with support for real-time event streaming, anomaly detection, PTZ control, alert rules, and a Home Assistant custom component.
|
||||
|
||||
## [Double Take](https://github.com/skrashevich/double-take)
|
||||
### [Double Take](https://github.com/skrashevich/double-take)
|
||||
|
||||
[Double Take](https://github.com/skrashevich/double-take) provides a unified UI and API for processing and training images for facial recognition.
|
||||
It supports automatically setting the sub labels in Frigate for person objects that are detected and recognized.
|
||||
This is a fork (with fixed errors and new features) of [original Double Take](https://github.com/jakowenko/double-take) project which, unfortunately, isn't being maintained by author.
|
||||
|
||||
## [frigate-abr](https://github.com/007hacky007/frigate-abr)
|
||||
|
||||
[frigate-abr](https://github.com/007hacky007/frigate-abr) is a drop-in Docker image of Frigate that adds adaptive bitrate (ABR) playback for recordings: a sidecar transcodes footage to lower quality tiers on demand, for reviewing over slow remote connections. Segments are transcoded when played and cached, so no additional stream is recorded. Frigate itself is not modified.
|
||||
|
||||
## [Frigate Notify](https://github.com/0x2142/frigate-notify)
|
||||
|
||||
[Frigate Notify](https://github.com/0x2142/frigate-notify) is a simple app designed to send notifications from Frigate to your favorite platforms. Intended to be used with standalone Frigate installations - Home Assistant not required, MQTT is optional but recommended.
|
||||
|
||||
## [Frigate Notify Alert](https://github.com/Sysoev86/frigate-notify-alert)
|
||||
|
||||
[Frigate Notify Alert](https://github.com/Sysoev86/frigate-notify-alert) sends Frigate events to Telegram as a photo + video media group. It supports multiple camera groups (each notifying its own chat), optional zone filtering (notify only when an object enters a chosen zone), and in-chat buttons to pause notifications for a set time. Works with standalone Frigate over MQTT; Home Assistant not required.
|
||||
|
||||
## [Frigate Snap-Sync](https://github.com/thequantumphysicist/frigate-snap-sync/)
|
||||
### [Frigate Snap-Sync](https://github.com/thequantumphysicist/frigate-snap-sync/)
|
||||
|
||||
[Frigate Snap-Sync](https://github.com/thequantumphysicist/frigate-snap-sync/) is a program that works in tandem with Frigate. It responds to Frigate when a snapshot or a review is made (and more can be added), and uploads them to one or more remote server(s) of your choice.
|
||||
|
||||
## [Frigate telegram](https://github.com/OldTyT/frigate-telegram)
|
||||
## Notifications
|
||||
|
||||
Standalone apps that send Frigate events to messaging platforms without requiring Home Assistant. For notifications through Home Assistant, see [Camera AutoNotify](#camera-autonotify).
|
||||
|
||||
### [Frigate Notify](https://github.com/0x2142/frigate-notify)
|
||||
|
||||
[Frigate Notify](https://github.com/0x2142/frigate-notify) is a simple app designed to send notifications from Frigate to your favorite platforms. Intended to be used with standalone Frigate installations - Home Assistant not required, MQTT is optional but recommended.
|
||||
|
||||
### [Frigate Notify Alert](https://github.com/Sysoev86/frigate-notify-alert)
|
||||
|
||||
[Frigate Notify Alert](https://github.com/Sysoev86/frigate-notify-alert) sends Frigate events to Telegram as a photo + video media group. It supports multiple camera groups (each notifying its own chat), optional zone filtering (notify only when an object enters a chosen zone), and in-chat buttons to pause notifications for a set time. Works with standalone Frigate over MQTT; Home Assistant not required.
|
||||
|
||||
### [Frigate telegram](https://github.com/OldTyT/frigate-telegram)
|
||||
|
||||
[Frigate telegram](https://github.com/OldTyT/frigate-telegram) makes it possible to send events from Frigate to Telegram. Events are sent as a message with a text description, video, and thumbnail.
|
||||
|
||||
## [FrigatePiP](https://github.com/maciejgornicz/frigate-pip)
|
||||
## Clients and Viewers
|
||||
|
||||
Apps and displays for viewing Frigate outside of its built-in web UI.
|
||||
|
||||
### [FrigatePiP](https://github.com/maciejgornicz/frigate-pip)
|
||||
|
||||
[FrigatePiP](https://github.com/maciejgornicz/frigate-pip) pops up a small picture-in-picture window with a camera's live video in a corner of the screen when Frigate detects an object, and closes it when the activity ends. It runs as a Windows tray app and on Linux (desktop windows, a console framebuffer, a terminal or tmux popups), receives events over Frigate's WebSocket or MQTT and plays the go2rtc RTSP stream with hardware decoding and camera audio.
|
||||
|
||||
## [kiosk-monitor](https://github.com/extremeshok/kiosk-monitor)
|
||||
### [kiosk-monitor](https://github.com/extremeshok/kiosk-monitor)
|
||||
|
||||
[kiosk-monitor](https://github.com/extremeshok/kiosk-monitor) is a Raspberry Pi watchdog that runs Chromium fullscreen on a Frigate dashboard (optionally with VLC on a second monitor for an RTSP camera stream), auto-restarts on frozen screens or unreachable URLs, and ships a Birdseye-aware Chromium helper that auto-sizes the grid to the display.
|
||||
|
||||
## [Periscope](https://github.com/maksz42/periscope)
|
||||
### [Periscope](https://github.com/maksz42/periscope)
|
||||
|
||||
[Periscope](https://github.com/maksz42/periscope) is a lightweight Android app that turns old devices into live viewers for Frigate. It works on Android 2.2 and above, including Android TV. It supports authentication and HTTPS.
|
||||
|
||||
## [reostream](https://github.com/VoltTech21/reostream)
|
||||
### [yuFriEye](https://apps.apple.com/app/id6832456692)
|
||||
|
||||
[reostream](https://github.com/VoltTech21/reostream) is a proxy for Reolink cameras that pulls video over Reolink's own protocol (the one the Reolink app and NVR use) instead of the camera's RTSP server, and serves it back as RTSP for go2rtc and Frigate. It helps models whose RTSP stream smears, drops frames or loses full resolution, and supports two-way talk.
|
||||
[yuFriEye](https://apps.apple.com/app/id6832456692) is a free native iOS, iPadOS and macOS client for Frigate. It shows the live camera grid with low-latency go2rtc streams, alerts and detections with clip playback and motion boxes, recordings by day with continuous playback, Frigate and go2rtc logs, and supports multiple servers with local and remote addresses. Works with or without Frigate authentication; no account or data collection.
|
||||
|
||||
## [Scrypted - Frigate bridge plugin](https://github.com/apocaliss92/scrypted-frigate-bridge)
|
||||
## Home Assistant
|
||||
|
||||
[Scrypted - Frigate bridge](https://github.com/apocaliss92/scrypted-frigate-bridge) is a plugin that allows you to ingest Frigate detections, motion, videoclips on Scrypted as well as provide templates to export rebroadcast configurations on Frigate.
|
||||
Cards and Home Assistant Marketplace integrations that build on the [Frigate Home Assistant integration](/integrations/home-assistant).
|
||||
|
||||
## [Strix](https://github.com/eduard256/Strix)
|
||||
### [Advanced Camera Card (formerly known as Frigate Card)](https://card.camera/#/README)
|
||||
|
||||
[Strix](https://github.com/eduard256/Strix) auto-discovers working stream URLs for IP cameras and generates ready-to-use Frigate configs. It tests thousands of URL patterns against your camera and supports cameras without RTSP or ONVIF. 67K+ camera models from 3.6K+ brands.
|
||||
The [Advanced Camera Card](https://card.camera/#/README) is a Home Assistant dashboard card with deep Frigate integration.
|
||||
|
||||
### [Auto Arm](https://autoarm.rhizomatics.org.uk)
|
||||
|
||||
Home Assistant Marketplace integration to automatically manage alarm state based on time of day, occupancy, sun state, physical buttons etc. Can synchronize Frigate profiles to alarm state, so for example use `disarmed` profile to reduce noisy notifications when occupied during the day.
|
||||
|
||||
### [Camera AutoNotify](https://camera-autonotify.rhizomatics.org.uk)
|
||||
|
||||
Home Assistant Marketplace integration to set up notifications for Frigate cameras without use of blueprints or automations. Triggered by camera events and optionally by GenAI reviews, with option for daily/periodic GenAI Review Report emailed, and alerts if Frigate or any cameras are unavailable. Integration with [Supernotify](https://supernotify.rhizomatics.org.uk/) to auto configure mobile devices and customize notifications for alarm state, occupancy etc.
|
||||
|
||||
@@ -0,0 +1,121 @@
|
||||
---
|
||||
id: choosing_a_model
|
||||
title: Choosing a model
|
||||
---
|
||||
|
||||
Frigate+ offers several model types, sizes, and input resolutions. This page compares their accuracy and speed to help you decide which one to request. Make sure the model type you choose is supported by your detector, as shown in the [supported detector types](./index.md#supported-detector-types) table.
|
||||
|
||||
## Recommendations
|
||||
|
||||
- **YOLOv9-s at 320** is the balanced default if your hardware runs it well. It detects about twice as many objects as MobileDet, and 15 more per 100 than YOLO-NAS-s at 320, at the same false alarm rate.
|
||||
- **Moving up a size at 320** helps more than moving to 640 for most cameras. YOLOv9-m at 320 detects more objects than YOLOv9-s at 640 (60% vs 59%) with lower GPU latency.
|
||||
- **640 input** is rarely needed. Frigate doesn't run detection on the full frame. It crops a region around motion, at least 320 pixels wide for any model, and resizes it to the model's input size. Most regions are small, so a 640 model usually receives an upscaled crop and does worse than a 320 model given the same crop at its native size. 640 models detect small objects better only within a large region. See [object size and input resolution](#object-size-and-input-resolution) for details.
|
||||
- **YOLOv9-c** gains little over YOLOv9-m: about 2 points of detection rate at 320 and none at 640, with more latency. On CPU it takes 1.4 to 1.7 times as long as YOLOv9-m.
|
||||
- **YOLOv9-t at 640** is no better than YOLOv9-s at 320 (55% vs 54%) and is slower on both GPU and CPU.
|
||||
- **YOLO-NAS-s** and **MobileDet** are only worth considering on hardware that can't run YOLOv9. Everywhere else, a YOLOv9 model of similar speed is more accurate.
|
||||
|
||||
Results on your own hardware and cameras will differ, so test with the base models before requesting a model.
|
||||
|
||||
### Thresholds
|
||||
|
||||
Each model's threshold for 95% precision is listed in the [accuracy](#accuracy) table. YOLOv9 models reach it at about 0.70 to 0.77. MobileDet (0.82) and YOLO-NAS-s (0.86 to 0.89) need higher thresholds, so with Frigate's default threshold they produce more false positives than the YOLOv9 models. See [object filters](../configuration/object_filters.md#object-scores) for how to adjust thresholds.
|
||||
|
||||
## How these were measured
|
||||
|
||||
The numbers on this page are for the 2026.3 base models.
|
||||
|
||||
- **Images:** 10,947 images from the Frigate+ validation set, from real Frigate cameras. Images that share a source with training images are excluded.
|
||||
- **Processing:** every model runs through Frigate's own detector code and post-processing (Frigate 0.18.2), exactly as deployed.
|
||||
- **Labels:** results cover the 12 most common labels: `car`, `person`, `waste_bin`, `license_plate`, `dog`, `cat`, `face`, `bicycle`, `bird`, `deer`, `bbq_grill`, and `package`.
|
||||
- **Single frames:** each image is scored on its own. In Frigate, an object has to score well across several frames before it becomes a tracked object, so brief one-frame mistakes rarely reach you. Use these numbers to compare models with each other, not as event rates.
|
||||
|
||||
**Detection rate at 95% precision** is the main accuracy number. It's the share of real objects a model detects when its threshold is set so that 95% of its detections are correct (about 1 false detection in 20). Every model is held to the same false alarm rate, so the detection rates compare directly. The threshold that achieves this is shown too, because it differs between models.
|
||||
|
||||
## Accuracy
|
||||
|
||||
| Model | Input | Detection rate at 95% precision | Missed objects per 100 | Threshold for 95% precision | AP50 |
|
||||
| ---------- | ----- | ------------------------------- | ---------------------- | --------------------------- | ---- |
|
||||
| MobileDet | 320 | 24% | 76 | 0.82 | 0.47 |
|
||||
| YOLO-NAS-s | 320 | 39% | 61 | 0.86 | 0.44 |
|
||||
| YOLO-NAS-s | 640 | 48% | 52 | 0.89 | 0.55 |
|
||||
| YOLOv9-t | 320 | 45% | 55 | 0.69 | 0.44 |
|
||||
| YOLOv9-t | 640 | 55% | 45 | 0.70 | 0.54 |
|
||||
| YOLOv9-s | 320 | 54% | 46 | 0.74 | 0.54 |
|
||||
| YOLOv9-s | 640 | 59% | 41 | 0.75 | 0.61 |
|
||||
| YOLOv9-m | 320 | 60% | 40 | 0.75 | 0.58 |
|
||||
| YOLOv9-m | 640 | 64% | 36 | 0.77 | 0.64 |
|
||||
| YOLOv9-c | 320 | 62% | 38 | 0.75 | 0.60 |
|
||||
| YOLOv9-c | 640 | 63% | 37 | 0.77 | 0.64 |
|
||||
|
||||
AP50 is the standard COCO metric (IoU 0.5) averaged over the 12 labels. It summarizes accuracy across every threshold, while the detection rate describes one realistic setting.
|
||||
|
||||
:::note
|
||||
|
||||
These AP50 numbers can't be compared to the COCO results published for YOLOv9, YOLO-NAS, and other models. Those results are measured on the COCO dataset, while these are measured on images from security cameras, with a different set of labels (several, such as `license_plate`, `face`, and `package`, aren't in COCO) and through Frigate's own post-processing. Published COCO results also usually report mAP averaged over IoU 0.5 to 0.95 rather than AP50. Use these numbers only to compare Frigate+ models with each other.
|
||||
|
||||
:::
|
||||
|
||||
### By object size
|
||||
|
||||
AP50 by object size:
|
||||
|
||||
| Model | Input | Small | Medium | Large |
|
||||
| ---------- | ----- | ----- | ------ | ----- |
|
||||
| MobileDet | 320 | 0.23 | 0.62 | 0.71 |
|
||||
| YOLO-NAS-s | 320 | 0.23 | 0.57 | 0.60 |
|
||||
| YOLO-NAS-s | 640 | 0.42 | 0.63 | 0.58 |
|
||||
| YOLOv9-t | 320 | 0.22 | 0.60 | 0.67 |
|
||||
| YOLOv9-t | 640 | 0.42 | 0.63 | 0.57 |
|
||||
| YOLOv9-s | 320 | 0.35 | 0.70 | 0.73 |
|
||||
| YOLOv9-s | 640 | 0.51 | 0.69 | 0.69 |
|
||||
| YOLOv9-m | 320 | 0.40 | 0.73 | 0.74 |
|
||||
| YOLOv9-m | 640 | 0.54 | 0.71 | 0.72 |
|
||||
| YOLOv9-c | 320 | 0.44 | 0.73 | 0.77 |
|
||||
| YOLOv9-c | 640 | 0.54 | 0.71 | 0.74 |
|
||||
|
||||
In these single-image results, 640 input mostly helps small objects, such as distant people, license plates, and faces, and doesn't help medium and large objects. For example, license plate AP50 rises from 0.32 to 0.55 for YOLOv9-s. These numbers overstate the benefit of 640 in Frigate, as explained below.
|
||||
|
||||
#### Object size and input resolution
|
||||
|
||||
Frigate doesn't send the full camera frame to the model. It crops a region around motion or a tracked object, at least 320 pixels wide for any model, and resizes it to the model's input size. Most regions are small, so a 640 model usually receives a crop upscaled from 320 pixels, which adds no detail and performs worse than a 320 model given the same crop at its native size. A 640 model detects small objects better only when the region is large.
|
||||
|
||||
640 input can still help in scenes with large objects in the foreground and small objects in the background at the same time, such as a doorbell camera that sees a person on the porch and another person across the street. The region has to be large enough to fit the nearby person, so the distant person is small within it. Frigate already handles much of this case: when an object is small relative to the region it was detected in, Frigate runs a separate detection on a smaller region around it.
|
||||
|
||||
### By label
|
||||
|
||||
AP50 by label:
|
||||
|
||||
| Label | MobileDet 320 | YOLO-NAS-s 320 | YOLOv9-t 320 | YOLOv9-s 320 | YOLOv9-m 320 | YOLOv9-c 320 | YOLO-NAS-s 640 | YOLOv9-t 640 | YOLOv9-s 640 | YOLOv9-m 640 | YOLOv9-c 640 |
|
||||
| --------------- | ------------- | -------------- | ------------ | ------------ | ------------ | ------------ | -------------- | ------------ | ------------ | ------------ | ------------ |
|
||||
| `car` | 0.73 | 0.72 | 0.70 | 0.77 | 0.81 | 0.82 | 0.82 | 0.79 | 0.83 | 0.85 | 0.84 |
|
||||
| `person` | 0.65 | 0.62 | 0.62 | 0.72 | 0.75 | 0.76 | 0.71 | 0.69 | 0.76 | 0.78 | 0.77 |
|
||||
| `waste_bin` | 0.52 | 0.49 | 0.49 | 0.55 | 0.57 | 0.58 | 0.60 | 0.60 | 0.62 | 0.62 | 0.63 |
|
||||
| `license_plate` | 0.31 | 0.31 | 0.23 | 0.32 | 0.36 | 0.39 | 0.55 | 0.46 | 0.55 | 0.60 | 0.61 |
|
||||
| `dog` | 0.38 | 0.35 | 0.39 | 0.53 | 0.53 | 0.57 | 0.40 | 0.48 | 0.53 | 0.55 | 0.58 |
|
||||
| `cat` | 0.41 | 0.37 | 0.39 | 0.51 | 0.57 | 0.59 | 0.43 | 0.46 | 0.58 | 0.61 | 0.62 |
|
||||
| `face` | 0.39 | 0.41 | 0.23 | 0.33 | 0.42 | 0.45 | 0.60 | 0.43 | 0.57 | 0.63 | 0.63 |
|
||||
| `bicycle` | 0.46 | 0.43 | 0.40 | 0.51 | 0.56 | 0.55 | 0.54 | 0.49 | 0.58 | 0.62 | 0.60 |
|
||||
| `bird` | 0.30 | 0.18 | 0.33 | 0.42 | 0.47 | 0.50 | 0.23 | 0.30 | 0.39 | 0.43 | 0.38 |
|
||||
| `deer` | 0.51 | 0.50 | 0.51 | 0.62 | 0.69 | 0.71 | 0.59 | 0.56 | 0.60 | 0.70 | 0.67 |
|
||||
| `bbq_grill` | 0.68 | 0.60 | 0.69 | 0.77 | 0.78 | 0.81 | 0.74 | 0.74 | 0.81 | 0.83 | 0.84 |
|
||||
| `package` | 0.35 | 0.28 | 0.34 | 0.46 | 0.47 | 0.49 | 0.39 | 0.43 | 0.50 | 0.48 | 0.50 |
|
||||
|
||||
## Speed
|
||||
|
||||
Average time per detection in milliseconds, measured through Frigate's detector code and including post-processing. Lower is better. A blank cell means that combination was not measured.
|
||||
|
||||
| Model | Input | NVIDIA RTX 5060 Ti (ONNX, CUDA) | Intel i9-13900K (OpenVINO, CPU) | Intel i9-13900K (ONNX, CPU) | Intel i9-13900K (TFLite, CPU) |
|
||||
| ---------- | ----- | ------------------------------- | ------------------------------- | --------------------------- | ----------------------------- |
|
||||
| MobileDet | 320 | | | | 8.4 |
|
||||
| YOLO-NAS-s | 320 | 4.9 | 8.4 | 8.9 | |
|
||||
| YOLO-NAS-s | 640 | 7.1 | 29.6 | 28.6 | |
|
||||
| YOLOv9-t | 320 | 2.9 | 4.3 | 6.5 | |
|
||||
| YOLOv9-t | 640 | 5.0 | 12.9 | 17.0 | |
|
||||
| YOLOv9-s | 320 | 3.9 | 9.3 | 11.5 | |
|
||||
| YOLOv9-s | 640 | 6.3 | 33.1 | 32.6 | |
|
||||
| YOLOv9-m | 320 | 5.2 | 23.2 | 19.8 | |
|
||||
| YOLOv9-m | 640 | 10.1 | 88.1 | 69.5 | |
|
||||
| YOLOv9-c | 320 | 5.4 | 38.8 | 27.5 | |
|
||||
| YOLOv9-c | 640 | 11.1 | 147.8 | 99.5 | |
|
||||
|
||||
CPU times vary by about ±15% between runs. Speeds on other hardware, such as Google Coral, Hailo, Intel iGPUs and NPUs, AMD GPUs, and Rockchip NPUs, are not included here. Test the base models on your own hardware to compare speeds.
|
||||
@@ -17,7 +17,7 @@ For more detailed recommendations, you can refer to the docs on [annotating](./a
|
||||
|
||||
## Step 2: Submit a model request
|
||||
|
||||
Once you have an initial set of verified images, you can request a model on the Models page. For guidance on choosing a model type, refer to [this part of the documentation](./index.md#available-model-types). If you are unsure which type to request, you can test the base model for each version from the "Base Models" tab. For most hardware, `yolov9` is recommended; `mobiledet` is a legacy model type and will be removed in 2027. Each model request requires 1 of the 12 trainings that you receive with your annual subscription. This model will support all [label types available](./index.md#available-label-types) even if you do not submit any examples for those labels. Model creation can take up to 36 hours.
|
||||
Once you have an initial set of verified images, you can request a model on the Models page. For guidance on choosing a model type, refer to [available model types](./index.md#available-model-types) and [choosing a model](./choosing_a_model.md). If you are unsure which type to request, you can test the base model for each version from the "Base Models" tab. For most hardware, `yolov9` is recommended; `mobiledet` is a legacy model type and will be removed in 2027. Each model request requires 1 of the 12 trainings that you receive with your annual subscription. This model will support all [label types available](./index.md#available-label-types) even if you do not submit any examples for those labels. Model creation can take up to 36 hours.
|
||||

|
||||
|
||||
## Step 3: Set your model
|
||||
|
||||
+10
-10
@@ -13,12 +13,12 @@ Information on how to integrate Frigate+ with Frigate can be found in the [integ
|
||||
|
||||
There are three model types offered in Frigate+, `yolov9`, `yolonas`, and `mobiledet` (legacy). All of these models are object detection models and are trained to detect the same set of labels [listed below](#available-label-types).
|
||||
|
||||
Not all model types are supported by all detectors, so it's important to choose a model type to match your detector as shown in the table under [supported detector types](#supported-detector-types). You can test model types for compatibility and speed on your hardware by using the base models.
|
||||
Not all model types are supported by all detectors, so it's important to choose a model type to match your detector as shown in the table under [supported detector types](#supported-detector-types). You can test model types for compatibility and speed on your hardware by using the base models. For accuracy and speed comparisons between model types, sizes, and resolutions, see [choosing a model](./choosing_a_model.md).
|
||||
|
||||
| Model Type | Description |
|
||||
| ----------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `yolov9` | A leading SOTA (state of the art) object detection model with similar performance to yolonas, but on a wider range of hardware options. Runs on most hardware. |
|
||||
| `yolonas` | A newer architecture that offers slightly higher accuracy and improved detection of small objects. Runs on Intel, NVidia GPUs, and AMD GPUs. |
|
||||
| ----------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
||||
| `yolov9` | A leading SOTA (state of the art) object detection model. More accurate than yolonas at similar speeds, and runs on a wider range of hardware. Runs on most hardware. |
|
||||
| `yolonas` | An alternative architecture for hardware that can't run yolov9. Runs on Intel, NVidia GPUs, and AMD GPUs. |
|
||||
| `mobiledet` | Legacy. Based on the same architecture as the default model included with Frigate. Runs on Google Coral devices and CPUs. |
|
||||
|
||||
:::warning
|
||||
@@ -29,14 +29,14 @@ Not all model types are supported by all detectors, so it's important to choose
|
||||
|
||||
### YOLOv9 Details
|
||||
|
||||
YOLOv9 models are available in `t`, `s`, `c`, and `edgetpu` variants, and an `m` size is coming soon. When requesting a `yolov9` model, you will be prompted to choose a variant. If you want the model to be compatible with a Google Coral, you will need to choose the `edgetpu` variant, which requires Frigate 0.17 or later. If you are unsure what variant to choose, you should perform some tests with the base models to find the performance level that suits you. The `s` size is most similar to the current `yolonas` models in terms of inference times and accuracy, and a good place to start is the `320x320` resolution model for `yolov9s`. The `c` size is larger and offers higher accuracy at the cost of slower inference, so it is best suited to more powerful hardware such as GPUs.
|
||||
YOLOv9 models are available in `t`, `s`, `m`, `c`, and `edgetpu` variants. When requesting a `yolov9` model, you will be prompted to choose a variant. If you want the model to be compatible with a Google Coral, you will need to choose the `edgetpu` variant, which requires Frigate 0.17 or later. If you are unsure what variant to choose, you should perform some tests with the base models to find the performance level that suits you. The `s` size has similar inference times to the current `yolonas` models with noticeably higher accuracy, and a good place to start is the `320x320` resolution model for `yolov9s`. The `m` size offers higher accuracy at the cost of slower inference, so it is best suited to more powerful hardware such as GPUs. The `c` size is slower still and offers little accuracy gain over `m`. See [choosing a model](./choosing_a_model.md) for detailed accuracy and speed comparisons.
|
||||
|
||||
| Variant | Size | Parameters | Speed and accuracy | Best suited for |
|
||||
| --------- | -------------------- | ---------- | ----------------------------------------------------------- | -------------------------------------------------- |
|
||||
| --------- | ------- | ---------- | ------------------------------------------------------------- | -------------------------------------------------- |
|
||||
| `t` | Tiny | ~2.0M | Fastest inference, lowest accuracy | Low power hardware or a large number of cameras |
|
||||
| `s` | Small | ~7.1M | Balanced. Similar inference times and accuracy to `yolonas` | Most users. Start with `320x320` |
|
||||
| `m` | Medium (coming soon) | ~20.0M | Slower than `s` with higher accuracy | Mid-range GPUs and NPUs |
|
||||
| `c` | Compact | ~25.3M | Highest accuracy, slowest inference | More powerful hardware such as GPUs |
|
||||
| `s` | Small | ~7.1M | Balanced. Similar inference times to `yolonas`, more accurate | Most users. Start with `320x320` |
|
||||
| `m` | Medium | ~20.0M | Slower than `s` with higher accuracy | Mid-range GPUs and NPUs |
|
||||
| `c` | Compact | ~25.3M | Similar accuracy to `m`, slowest inference | More powerful hardware such as GPUs |
|
||||
| `edgetpu` | N/A | N/A | Optimized to run on the Coral's Edge TPU | Google Coral devices only (requires Frigate 0.17+) |
|
||||
|
||||
Parameter counts are for the standard YOLOv9 architectures. Actual inference times depend on your hardware and the input resolution you choose, so test with the base models before requesting a model.
|
||||
@@ -49,7 +49,7 @@ When switching to YOLOv9, you may need to adjust your thresholds for some object
|
||||
|
||||
#### Hailo Support
|
||||
|
||||
If you have a Hailo device, you will need to specify the hardware you have when submitting a model request because they are not cross compatible. Hailo models are available for the `t`, `s`, and `c` variants on Hailo8, Hailo8L, and Hailo8R devices. Please test using the available base models before submitting your model request.
|
||||
If you have a Hailo device, you will need to specify the hardware you have when submitting a model request because they are not cross compatible. Hailo models are available for the `t`, `s`, `m`, and `c` variants on Hailo8, Hailo8L, and Hailo8R devices. Please test using the available base models before submitting your model request.
|
||||
|
||||
#### Rockchip (RKNN) Support
|
||||
|
||||
|
||||
@@ -4,7 +4,7 @@ import type { Config, PluginConfig } from "@docusaurus/types";
|
||||
import type * as OpenApiPlugin from "docusaurus-plugin-openapi-docs";
|
||||
|
||||
// Bump when a new stable release ships
|
||||
const STABLE_VERSION = "0.18";
|
||||
const STABLE_VERSION = "0.19";
|
||||
|
||||
const config: Config = {
|
||||
title: "Frigate",
|
||||
|
||||
@@ -162,6 +162,7 @@ const sidebars: SidebarsConfig = {
|
||||
],
|
||||
"Frigate+": [
|
||||
"plus/index",
|
||||
"plus/choosing_a_model",
|
||||
"plus/annotating",
|
||||
"plus/first_model",
|
||||
"plus/faq",
|
||||
|
||||
+23
-1
@@ -683,6 +683,15 @@
|
||||
"title": "FeaturesSection",
|
||||
"type": "object"
|
||||
},
|
||||
"FfmpegSource": {
|
||||
"enum": [
|
||||
"default",
|
||||
"bundled",
|
||||
"custom"
|
||||
],
|
||||
"title": "FfmpegSource",
|
||||
"type": "string"
|
||||
},
|
||||
"FpsBucket": {
|
||||
"enum": [
|
||||
"le_5",
|
||||
@@ -1017,6 +1026,17 @@
|
||||
"description": "CPU architecture",
|
||||
"x-public": true
|
||||
},
|
||||
"custom_go2rtc": {
|
||||
"description": "Whether an executable /config/go2rtc build exists",
|
||||
"title": "Custom Go2Rtc",
|
||||
"type": "boolean",
|
||||
"x-public": true
|
||||
},
|
||||
"ffmpeg": {
|
||||
"$ref": "#/$defs/FfmpegSource",
|
||||
"description": "Configured global ffmpeg.path: the default build, another bundled version, or a custom path",
|
||||
"x-public": true
|
||||
},
|
||||
"image_variant": {
|
||||
"$ref": "#/$defs/ImageVariant",
|
||||
"description": "Published image the install runs",
|
||||
@@ -1054,7 +1074,9 @@
|
||||
"install_type",
|
||||
"arch",
|
||||
"kernel",
|
||||
"run_as_root"
|
||||
"run_as_root",
|
||||
"custom_go2rtc",
|
||||
"ffmpeg"
|
||||
],
|
||||
"title": "InstallSection",
|
||||
"type": "object"
|
||||
|
||||
Vendored
+23
-1
@@ -3148,6 +3148,25 @@ paths:
|
||||
- frigateUserAuth: []
|
||||
x-required-role: any
|
||||
description: '**Access:** Any authenticated user.'
|
||||
/plus/validate:
|
||||
post:
|
||||
tags:
|
||||
- App
|
||||
summary: Validate Plus Key
|
||||
description: |-
|
||||
**Access:** Admin role required.
|
||||
|
||||
Validate the configured Frigate+ API key with the Frigate+ server.
|
||||
operationId: validate_plus_key_plus_validate_post
|
||||
responses:
|
||||
'200':
|
||||
description: Successful Response
|
||||
content:
|
||||
application/json:
|
||||
schema: {}
|
||||
security:
|
||||
- frigateAdminAuth: []
|
||||
x-required-role: admin
|
||||
/recognized_license_plates:
|
||||
get:
|
||||
tags:
|
||||
@@ -5826,6 +5845,10 @@ paths:
|
||||
tags:
|
||||
- Media
|
||||
summary: Mjpeg Feed
|
||||
description: |-
|
||||
**Access:** Authenticated user with access to the referenced camera.
|
||||
|
||||
An MJPEG stream of the camera's latest processed frame, intended for debugging only. Every frame of every open stream is color converted, annotated, resized, and JPEG encoded in Frigate's main process, which adds load to the system and can slow down Frigate's processing. It is strictly not recommended to view this stream continuously, such as on a dashboard. For live viewing, use a go2rtc restream instead. The frame rate and resolution can be raised with the fps and height parameters, for example ?fps=10&height=1080, at the cost of additional load.
|
||||
operationId: mjpeg_feed__camera_name__get
|
||||
parameters:
|
||||
- name: camera_name
|
||||
@@ -5913,7 +5936,6 @@ paths:
|
||||
security:
|
||||
- frigateUserAuth: []
|
||||
x-required-role: camera
|
||||
description: '**Access:** Authenticated user with access to the referenced camera.'
|
||||
/{camera_name}/ptz/info:
|
||||
get:
|
||||
tags:
|
||||
|
||||
@@ -139,7 +139,8 @@ def collect(ctx: ReportContext) -> FeaturesSection:
|
||||
restream=config.birdseye.restream,
|
||||
),
|
||||
mqtt=config.mqtt.enabled,
|
||||
notifications=config.notifications.enabled,
|
||||
notifications=config.notifications.enabled
|
||||
or any(camera.notifications.enabled for camera in cameras),
|
||||
auth=config.auth.enabled,
|
||||
proxy_auth=config.proxy.header_map.user is not None,
|
||||
tls=config.tls.enabled,
|
||||
|
||||
@@ -6,7 +6,15 @@ import re
|
||||
|
||||
from frigate.analytics.collectors.common import closed
|
||||
from frigate.analytics.context import ReportContext
|
||||
from frigate.analytics.schema import Arch, ImageVariant, InstallSection, InstallType
|
||||
from frigate.analytics.schema import (
|
||||
Arch,
|
||||
FfmpegSource,
|
||||
ImageVariant,
|
||||
InstallSection,
|
||||
InstallType,
|
||||
)
|
||||
from frigate.const import CONFIG_DIR, DEFAULT_FFMPEG_VERSION, INCLUDED_FFMPEG_VERSIONS
|
||||
from frigate.util.config import is_valid_ffmpeg_path
|
||||
from frigate.version import VERSION
|
||||
|
||||
KERNEL_PATTERN = re.compile(r"^(\d{1,3})\.(\d{1,3})")
|
||||
@@ -54,6 +62,17 @@ def kernel(release: str) -> str:
|
||||
return f"{match.group(1)}.{match.group(2)}" if match else "unknown"
|
||||
|
||||
|
||||
def ffmpeg_source(path: str) -> FfmpegSource:
|
||||
"""Classify the configured ffmpeg.path, applying resolve_ffmpeg_path's alias fallbacks."""
|
||||
if path.startswith("/") and is_valid_ffmpeg_path(path):
|
||||
return FfmpegSource.custom
|
||||
|
||||
if path != DEFAULT_FFMPEG_VERSION and path in INCLUDED_FFMPEG_VERSIONS:
|
||||
return FfmpegSource.bundled
|
||||
|
||||
return FfmpegSource.default
|
||||
|
||||
|
||||
def collect(ctx: ReportContext) -> InstallSection:
|
||||
"""Describe the Frigate version, image, install method, and platform."""
|
||||
return InstallSection(
|
||||
@@ -63,4 +82,6 @@ def collect(ctx: ReportContext) -> InstallSection:
|
||||
arch=arch(platform.machine()),
|
||||
kernel=kernel(platform.release()),
|
||||
run_as_root=os.geteuid() == 0,
|
||||
custom_go2rtc=os.access(os.path.join(CONFIG_DIR, "go2rtc"), os.X_OK),
|
||||
ffmpeg=ffmpeg_source(ctx.config.ffmpeg.path),
|
||||
)
|
||||
|
||||
@@ -47,6 +47,12 @@ class Arch(StrEnum):
|
||||
other = "other"
|
||||
|
||||
|
||||
class FfmpegSource(StrEnum):
|
||||
default = "default"
|
||||
bundled = "bundled"
|
||||
custom = "custom"
|
||||
|
||||
|
||||
class GpuVendor(StrEnum):
|
||||
intel = "intel"
|
||||
amd = "amd"
|
||||
@@ -201,6 +207,10 @@ class InstallSection(AnalyticsModel):
|
||||
"Host kernel as major.minor", pattern=r"^(\d{1,3}\.\d{1,3}|unknown)$"
|
||||
)
|
||||
run_as_root: bool = metric("Whether the main process runs as root")
|
||||
custom_go2rtc: bool = metric("Whether an executable /config/go2rtc build exists")
|
||||
ffmpeg: FfmpegSource = metric(
|
||||
"Configured global ffmpeg.path: the default build, another bundled version, or a custom path"
|
||||
)
|
||||
|
||||
|
||||
class GpuInfo(AnalyticsModel):
|
||||
|
||||
+29
-2
@@ -45,7 +45,7 @@ from frigate.config.camera.updater import (
|
||||
CameraConfigUpdateEnum,
|
||||
CameraConfigUpdateTopic,
|
||||
)
|
||||
from frigate.const import REDACTED_CREDENTIAL_SENTINEL
|
||||
from frigate.const import REDACTED_CREDENTIAL_SENTINEL, REPLAY_CAMERA_PREFIX
|
||||
from frigate.ffmpeg_presets import FFMPEG_HWACCEL_VAAPI, _gpu_selector
|
||||
from frigate.genai import PROVIDERS, load_providers
|
||||
from frigate.jobs.media_sync import (
|
||||
@@ -54,7 +54,7 @@ from frigate.jobs.media_sync import (
|
||||
start_media_sync_job,
|
||||
)
|
||||
from frigate.models import Event, Timeline
|
||||
from frigate.plus import load_plus_model_info
|
||||
from frigate.plus import PlusKeyStatus, load_plus_model_info
|
||||
from frigate.stats.prometheus import get_metrics, update_metrics
|
||||
from frigate.types import JobStatusTypesEnum
|
||||
from frigate.util.builtin import (
|
||||
@@ -627,6 +627,7 @@ def _restricted_go2rtc_response(
|
||||
Go2rtcStreamIssue.invalid_placeholder,
|
||||
"Invalid variable placeholder in go2rtc stream",
|
||||
),
|
||||
(Go2rtcStreamIssue.invalid_name, "Invalid go2rtc stream name"),
|
||||
):
|
||||
names = [name for name, found in issues.items() if found == issue]
|
||||
if names:
|
||||
@@ -978,6 +979,17 @@ def _config_set_in_memory(request: Request, body: AppConfigSetBody) -> JSONRespo
|
||||
status_code=400,
|
||||
)
|
||||
|
||||
# an unresolvable scene would crash the threads that look up the model
|
||||
detect_update = sections.get("detect")
|
||||
if isinstance(detect_update, dict) and "scene" in detect_update:
|
||||
try:
|
||||
config._resolve_camera_model(cam_name, detect_update["scene"])
|
||||
except (TypeError, ValueError):
|
||||
return JSONResponse(
|
||||
content={"success": False, "message": "Invalid detect scene"},
|
||||
status_code=400,
|
||||
)
|
||||
|
||||
for section_name, update in sections.items():
|
||||
err = apply_section_update(camera_config, section_name, update)
|
||||
if err is not None:
|
||||
@@ -986,6 +998,11 @@ def _config_set_in_memory(request: Request, body: AppConfigSetBody) -> JSONRespo
|
||||
status_code=400,
|
||||
)
|
||||
|
||||
# the model is resolved again from the scene when the replay
|
||||
# camera is recycled by the refresh below
|
||||
if "detect" in sections and cam_name.startswith(REPLAY_CAMERA_PREFIX):
|
||||
config.drop_camera_model(cam_name)
|
||||
|
||||
# Publish ZMQ updates so processing threads pick up changes
|
||||
if body.update_topic and body.update_topic.startswith("config/cameras/"):
|
||||
_, _, camera, field = body.update_topic.split("/")
|
||||
@@ -1674,6 +1691,16 @@ def plusModels(request: Request, filterByCurrentModelDetector: bool = False):
|
||||
return JSONResponse(content=validModels)
|
||||
|
||||
|
||||
@router.post("/plus/validate", dependencies=[Depends(require_role(["admin"]))])
|
||||
async def validate_plus_key(request: Request):
|
||||
"""Validate the configured Frigate+ API key with the Frigate+ server."""
|
||||
status = await request.app.frigate_config.plus_api.validate_key()
|
||||
|
||||
return JSONResponse(
|
||||
content={"success": status == PlusKeyStatus.valid, "status": status.value}
|
||||
)
|
||||
|
||||
|
||||
@router.get(
|
||||
"/recognized_license_plates", dependencies=[Depends(allow_any_authenticated())]
|
||||
)
|
||||
|
||||
+14
-1
@@ -39,6 +39,7 @@ from frigate.config import AuthConfig, ProxyConfig
|
||||
from frigate.const import CONFIG_DIR, JWT_SECRET_ENV_VAR, PASSWORD_HASH_ALGORITHM
|
||||
from frigate.models import User
|
||||
from frigate.notices import raise_notice
|
||||
from frigate.util.live_streams import is_transcode_stream_name
|
||||
from frigate.util.origin import origin_allowed
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -739,6 +740,13 @@ def auth(request: Request):
|
||||
int(request.headers.get("x-server-port", default=0))
|
||||
== request.app.auth_internal_port
|
||||
):
|
||||
# go2rtc runs the producer an unknown src describes for any caller
|
||||
deny_status = deny_response_for_go2rtc_stream(
|
||||
request.headers.get("x-original-url"), None, request
|
||||
)
|
||||
if deny_status is not None:
|
||||
return Response("", status_code=deny_status)
|
||||
|
||||
success_response.headers["remote-user"] = "anonymous"
|
||||
success_response.headers["remote-role"] = "admin"
|
||||
return success_response
|
||||
@@ -1275,7 +1283,12 @@ def _is_existing_go2rtc_stream(request: Request, stream_name: str) -> bool:
|
||||
"""
|
||||
frigate_config = request.app.frigate_config
|
||||
|
||||
if _get_stream_owner_cameras(request, stream_name):
|
||||
# live.streams values are free-form config, so only names Frigate controls
|
||||
# skip the lookup
|
||||
if any(
|
||||
stream_name == camera or is_transcode_stream_name(camera, stream_name)
|
||||
for camera in frigate_config.cameras
|
||||
):
|
||||
return True
|
||||
|
||||
config_streams = getattr(frigate_config.go2rtc, "streams", None) or {}
|
||||
|
||||
+4
-4
@@ -306,7 +306,7 @@ async def _execute_search_objects_semantic(
|
||||
visual_distances: dict[str, float] = {}
|
||||
description_distances: dict[str, float] = {}
|
||||
try:
|
||||
rows = context.search_thumbnail(semantic_query)
|
||||
rows = await asyncio.to_thread(context.search_thumbnail, semantic_query)
|
||||
visual_distances = {row[0]: row[1] for row in rows}
|
||||
except Exception:
|
||||
logger.exception(
|
||||
@@ -314,7 +314,7 @@ async def _execute_search_objects_semantic(
|
||||
)
|
||||
|
||||
try:
|
||||
rows = context.search_description(semantic_query)
|
||||
rows = await asyncio.to_thread(context.search_description, semantic_query)
|
||||
description_distances = {row[0]: row[1] for row in rows}
|
||||
except Exception:
|
||||
logger.exception(
|
||||
@@ -448,7 +448,7 @@ async def _execute_find_similar_objects(
|
||||
|
||||
try:
|
||||
if similarity_mode in ("visual", "fused"):
|
||||
rows = context.search_thumbnail(anchor)
|
||||
rows = await asyncio.to_thread(context.search_thumbnail, anchor)
|
||||
visual_distances = {row[0]: row[1] for row in rows}
|
||||
|
||||
if similarity_mode in ("semantic", "fused"):
|
||||
@@ -457,7 +457,7 @@ async def _execute_find_similar_objects(
|
||||
or anchor.sub_label
|
||||
or anchor.label
|
||||
)
|
||||
rows = context.search_description(query_text)
|
||||
rows = await asyncio.to_thread(context.search_description, query_text)
|
||||
description_distances = {row[0]: row[1] for row in rows}
|
||||
except Exception:
|
||||
logger.exception("Similarity search failed")
|
||||
|
||||
@@ -9,8 +9,8 @@ class MediaRecordingsSummaryQueryParams(BaseModel):
|
||||
|
||||
class MediaRecordingsAvailabilityQueryParams(BaseModel):
|
||||
cameras: str = "all"
|
||||
before: float | SkipJsonSchema[None] = None
|
||||
after: float | SkipJsonSchema[None] = None
|
||||
before: float | SkipJsonSchema[None] = Field(default=None, allow_inf_nan=False)
|
||||
after: float | SkipJsonSchema[None] = Field(default=None, allow_inf_nan=False)
|
||||
scale: int = Field(default=30, ge=1)
|
||||
|
||||
|
||||
|
||||
+16
-25
@@ -199,18 +199,14 @@ def events(
|
||||
sub_label_clauses.append(Event.sub_label.is_null())
|
||||
|
||||
for label in filtered_sub_labels:
|
||||
lowered = label.lower()
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) == lowered
|
||||
) # include exact matches (case-insensitive)
|
||||
# SQLite LOWER() only folds ASCII, so lower both sides in SQL to
|
||||
# keep non-ASCII names matching exactly
|
||||
stored = fn.LOWER(Event.sub_label.cast("text"))
|
||||
sub_label_clauses.append(stored == fn.LOWER(label))
|
||||
|
||||
# include this label when part of a list (LIKE is case-insensitive in sqlite for ASCII)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*{lowered},*"
|
||||
)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*, {lowered}*"
|
||||
)
|
||||
# include this label when part of a list
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*{label},*"))
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*, {label}*"))
|
||||
|
||||
sub_label_clause = reduce(operator.or_, sub_label_clauses)
|
||||
clauses.append(sub_label_clause)
|
||||
@@ -633,18 +629,14 @@ def events_search(
|
||||
sub_label_clauses.append(Event.sub_label.is_null())
|
||||
|
||||
for label in filtered_sub_labels:
|
||||
lowered = label.lower()
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) == lowered
|
||||
) # include exact matches (case-insensitive)
|
||||
# SQLite LOWER() only folds ASCII, so lower both sides in SQL to
|
||||
# keep non-ASCII names matching exactly
|
||||
stored = fn.LOWER(Event.sub_label.cast("text"))
|
||||
sub_label_clauses.append(stored == fn.LOWER(label))
|
||||
|
||||
# include this label when part of a list (LIKE is case-insensitive in sqlite for ASCII)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*{lowered},*"
|
||||
)
|
||||
sub_label_clauses.append(
|
||||
fn.LOWER(Event.sub_label.cast("text")) % f"*, {lowered}*"
|
||||
)
|
||||
# include this label when part of a list
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*{label},*"))
|
||||
sub_label_clauses.append(stored % fn.LOWER(f"*, {label}*"))
|
||||
|
||||
event_filters.append(reduce(operator.or_, sub_label_clauses))
|
||||
|
||||
@@ -1569,9 +1561,8 @@ async def set_description(
|
||||
if len(new_description) > 0:
|
||||
# If semantic search is enabled, update the index
|
||||
if request.app.frigate_config.semantic_search.enabled:
|
||||
context.update_description(
|
||||
event_id,
|
||||
new_description,
|
||||
await asyncio.to_thread(
|
||||
context.update_description, event_id, new_description
|
||||
)
|
||||
else:
|
||||
# embeddings are always cleaned up so they don't outlive their description
|
||||
|
||||
+21
-6
@@ -109,7 +109,19 @@ def _resolve_cache_age(max_cache_age: int) -> int:
|
||||
return max_cache_age.default
|
||||
|
||||
|
||||
@router.get("/{camera_name}", dependencies=[Depends(require_camera_access)])
|
||||
@router.get(
|
||||
"/{camera_name}",
|
||||
dependencies=[Depends(require_camera_access)],
|
||||
description=(
|
||||
"An MJPEG stream of the camera's latest processed frame, intended for debugging only. "
|
||||
"Every frame of every open stream is color converted, annotated, resized, and JPEG "
|
||||
"encoded in Frigate's main process, which adds load to the system and can slow down "
|
||||
"Frigate's processing. It is strictly not recommended to view this stream "
|
||||
"continuously, such as on a dashboard. For live viewing, use a go2rtc restream "
|
||||
"instead. The frame rate and resolution can be raised with the fps and height "
|
||||
"parameters, for example ?fps=10&height=1080, at the cost of additional load."
|
||||
),
|
||||
)
|
||||
async def mjpeg_feed(
|
||||
request: Request,
|
||||
camera_name: str,
|
||||
@@ -154,10 +166,13 @@ def imagestream(
|
||||
time.sleep(1 / fps)
|
||||
frame = detected_frames_processor.get_current_frame(camera_name, draw_options)
|
||||
if frame is None:
|
||||
frame = np.zeros((height, int(height * 16 / 9), 3), np.uint8)
|
||||
frame = np.zeros((360, 640, 3), np.uint8)
|
||||
|
||||
width = int(height * frame.shape[1] / frame.shape[0])
|
||||
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_LINEAR)
|
||||
frame_height = min(height, frame.shape[0])
|
||||
width = int(frame_height * frame.shape[1] / frame.shape[0])
|
||||
frame = cv2.resize(
|
||||
frame, dsize=(width, frame_height), interpolation=cv2.INTER_LINEAR
|
||||
)
|
||||
|
||||
ret, jpg = cv2.imencode(".jpg", frame, [int(cv2.IMWRITE_JPEG_QUALITY), 70])
|
||||
yield (
|
||||
@@ -266,7 +281,7 @@ async def latest_frame(
|
||||
status_code=500,
|
||||
)
|
||||
|
||||
height = int(params.height or str(frame.shape[0]))
|
||||
height = min(params.height or frame.shape[0], frame.shape[0])
|
||||
width = int(height * frame.shape[1] / frame.shape[0])
|
||||
|
||||
if height < 1 or width < 1:
|
||||
@@ -308,7 +323,7 @@ async def latest_frame(
|
||||
|
||||
frame = cv2.cvtColor(frame, cv2.COLOR_YUV2BGR_I420)
|
||||
|
||||
height = int(params.height or str(frame.shape[0]))
|
||||
height = min(params.height or frame.shape[0], frame.shape[0])
|
||||
width = int(height * frame.shape[1] / frame.shape[0])
|
||||
|
||||
frame = cv2.resize(frame, dsize=(width, height), interpolation=cv2.INTER_AREA)
|
||||
|
||||
@@ -17,10 +17,10 @@ import re
|
||||
from enum import Enum
|
||||
from urllib.parse import unquote
|
||||
|
||||
from peewee import DoesNotExist
|
||||
from peewee import DoesNotExist, Field
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.const import EXPORT_DIR
|
||||
from frigate.const import CLIPS_DIR, EXPORT_DIR
|
||||
from frigate.models import Export, User
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
@@ -151,6 +151,7 @@ def _resolve_clip(
|
||||
# /clips/thumbs/{cam}/... → camera
|
||||
# /clips/previews/{cam}/... → camera
|
||||
# /clips/review/thumb-{cam}-{review_id}.webp → camera (parsed)
|
||||
# /clips/export/{export_id}.{ext} → camera (DB lookup)
|
||||
# /clips/faces/... → admin-only
|
||||
# /clips/genai-requests/... → admin-only
|
||||
# /clips/preview_restart_cache/... → admin-only
|
||||
@@ -175,6 +176,11 @@ def _resolve_clip(
|
||||
return MediaAuthResolution.CAMERA, camera
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
|
||||
if second == "export" and len(parts) == 3:
|
||||
return _export_camera(
|
||||
Export.thumb_path, os.path.join(CLIPS_DIR, "export", parts[2])
|
||||
)
|
||||
|
||||
if second in ("faces", "genai-requests", "preview_restart_cache"):
|
||||
return MediaAuthResolution.ADMIN_ONLY, None
|
||||
|
||||
@@ -234,15 +240,19 @@ def _resolve_export(
|
||||
if len(parts) != 2:
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
|
||||
filename = parts[1]
|
||||
full_path = os.path.join(EXPORT_DIR, filename)
|
||||
return _export_camera(Export.video_path, os.path.join(EXPORT_DIR, parts[1]))
|
||||
|
||||
|
||||
def _export_camera(
|
||||
field: Field, full_path: str
|
||||
) -> tuple[MediaAuthResolution, str | None]:
|
||||
try:
|
||||
export = Export.get(Export.video_path == full_path)
|
||||
export = Export.get(field == full_path)
|
||||
return MediaAuthResolution.CAMERA, export.camera
|
||||
except DoesNotExist:
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
except Exception as e:
|
||||
logger.warning("Export DB lookup failed for %s: %s", filename, e)
|
||||
logger.warning("Export DB lookup failed for %s: %s", full_path, e)
|
||||
return MediaAuthResolution.UNRESOLVED_MEDIA, None
|
||||
|
||||
|
||||
|
||||
+29
-35
@@ -2,6 +2,7 @@
|
||||
|
||||
import datetime as dt
|
||||
import logging
|
||||
import math
|
||||
from datetime import datetime, timedelta
|
||||
from functools import reduce
|
||||
from pathlib import Path
|
||||
@@ -443,45 +444,38 @@ async def no_recordings(
|
||||
else:
|
||||
covered.append((rec_start, rec_end))
|
||||
|
||||
# Iterate through time segments and check if each has any recording
|
||||
no_recording_segments = []
|
||||
current = after
|
||||
current_gap_start = None
|
||||
idx = 0
|
||||
covered_count = len(covered)
|
||||
# A scale-sized bucket counts as empty when it fits inside a gap between
|
||||
# covered intervals. Walking the gaps keeps the work proportional to the
|
||||
# recordings found rather than to the requested span.
|
||||
bucket_count = math.ceil((before - after) / scale)
|
||||
gaps: list[list[float]] = []
|
||||
free_start = -math.inf
|
||||
|
||||
while current < before:
|
||||
segment_end = min(current + scale, before)
|
||||
for rec_start, rec_end in covered + [(math.inf, math.inf)]:
|
||||
first = 0 if free_start <= after else math.ceil((free_start - after) / scale)
|
||||
|
||||
# Advance past covered intervals that end before this segment begins;
|
||||
# they cannot overlap this or any later segment.
|
||||
while idx < covered_count and covered[idx][1] <= current:
|
||||
idx += 1
|
||||
|
||||
# A covered interval overlaps the segment when it starts before the
|
||||
# segment ends (its end is already known to be > current).
|
||||
has_recording = idx < covered_count and covered[idx][0] < segment_end
|
||||
|
||||
if not has_recording:
|
||||
# This segment has no recordings
|
||||
if current_gap_start is None:
|
||||
current_gap_start = current # Start a new gap
|
||||
if rec_start >= before:
|
||||
last = bucket_count - 1
|
||||
else:
|
||||
# This segment has recordings
|
||||
if current_gap_start is not None:
|
||||
# End the current gap and append it
|
||||
no_recording_segments.append(
|
||||
{"start_time": int(current_gap_start), "end_time": int(current)}
|
||||
)
|
||||
current_gap_start = None
|
||||
last = min(math.floor((rec_start - after) / scale), bucket_count) - 1
|
||||
|
||||
current = segment_end
|
||||
if first <= last:
|
||||
gap_start = after + first * scale
|
||||
gap_end = before if last == bucket_count - 1 else after + (last + 1) * scale
|
||||
|
||||
# Append the last gap if it exists
|
||||
if current_gap_start is not None:
|
||||
no_recording_segments.append(
|
||||
{"start_time": int(current_gap_start), "end_time": int(before)}
|
||||
)
|
||||
if gaps and gaps[-1][1] == gap_start:
|
||||
gaps[-1][1] = gap_end
|
||||
else:
|
||||
gaps.append([gap_start, gap_end])
|
||||
|
||||
free_start = rec_end
|
||||
if free_start >= before:
|
||||
break
|
||||
|
||||
no_recording_segments = [
|
||||
{"start_time": int(gap_start), "end_time": int(gap_end)}
|
||||
for gap_start, gap_end in gaps
|
||||
]
|
||||
|
||||
return JSONResponse(content=no_recording_segments)
|
||||
|
||||
@@ -495,7 +489,7 @@ async def no_recordings(
|
||||
Recordings can be filtered by cameras and kept based on motion, objects, or audio attributes.
|
||||
""",
|
||||
)
|
||||
async def delete_recordings(
|
||||
def delete_recordings(
|
||||
start: float = PathParam(..., description="Start timestamp (unix)"),
|
||||
end: float = PathParam(..., description="End timestamp (unix)"),
|
||||
params: RecordingsDeleteQueryParams = Depends(),
|
||||
|
||||
+13
-5
@@ -1,5 +1,6 @@
|
||||
"""Review apis."""
|
||||
|
||||
import asyncio
|
||||
import datetime
|
||||
import logging
|
||||
from functools import reduce
|
||||
@@ -82,12 +83,19 @@ async def review(
|
||||
reviewed = params.reviewed
|
||||
limit = params.limit
|
||||
severity = params.severity
|
||||
before = params.before or datetime.datetime.now().timestamp()
|
||||
after = (
|
||||
params.after
|
||||
or (datetime.datetime.now() - datetime.timedelta(hours=24)).timestamp()
|
||||
before = (
|
||||
params.before
|
||||
if params.before is not None
|
||||
else datetime.datetime.now().timestamp()
|
||||
)
|
||||
|
||||
if params.after is not None:
|
||||
after = params.after
|
||||
elif params.before is not None:
|
||||
after = 0
|
||||
else:
|
||||
after = (datetime.datetime.now() - datetime.timedelta(hours=24)).timestamp()
|
||||
|
||||
clauses = [
|
||||
(ReviewSegment.start_time < before)
|
||||
& ((ReviewSegment.end_time.is_null(True)) | (ReviewSegment.end_time > after))
|
||||
@@ -790,7 +798,7 @@ async def regenerate_review_description(request: Request, review_id: str):
|
||||
)
|
||||
|
||||
context: EmbeddingsContext = request.app.embeddings
|
||||
context.regenerate_review_description(review_id)
|
||||
await asyncio.to_thread(context.regenerate_review_description, review_id)
|
||||
|
||||
return JSONResponse(
|
||||
content={
|
||||
|
||||
+2
-9
@@ -76,7 +76,7 @@ from frigate.models import (
|
||||
from frigate.notices import install_registry
|
||||
from frigate.notices.registry import NoticeRegistry
|
||||
from frigate.object_detection.base import ObjectDetectProcess
|
||||
from frigate.object_detection.util import detection_frame_size
|
||||
from frigate.object_detection.util import create_detection_input_shm
|
||||
from frigate.output.output import OutputProcess
|
||||
from frigate.ptz.autotrack import PtzAutoTracker
|
||||
from frigate.ptz.onvif import OnvifController
|
||||
@@ -399,14 +399,7 @@ class FrigateApp:
|
||||
model = self.config.model_for_camera(name)
|
||||
model_cameras[model.scene].append(name)
|
||||
|
||||
try:
|
||||
shm_in = UntrackedSharedMemory(
|
||||
name=name,
|
||||
create=True,
|
||||
size=detection_frame_size(model),
|
||||
)
|
||||
except FileExistsError:
|
||||
shm_in = UntrackedSharedMemory(name=name)
|
||||
shm_in = create_detection_input_shm(name, self.config.models)
|
||||
|
||||
try:
|
||||
shm_out = UntrackedSharedMemory(
|
||||
|
||||
@@ -16,7 +16,7 @@ from frigate.config.camera.updater import (
|
||||
)
|
||||
from frigate.const import REPLAY_CAMERA_PREFIX
|
||||
from frigate.models import Regions
|
||||
from frigate.object_detection.util import detection_frame_size
|
||||
from frigate.object_detection.util import create_detection_input_shm
|
||||
from frigate.util.builtin import empty_and_close_queue
|
||||
from frigate.util.image import SharedMemoryFrameManager, UntrackedSharedMemory
|
||||
from frigate.util.object import get_camera_regions_grid
|
||||
@@ -127,13 +127,10 @@ class CameraMaintainer(threading.Thread):
|
||||
max(model.width, model.height),
|
||||
)
|
||||
|
||||
create_detection_input_shm(name, self.config.models)
|
||||
|
||||
try:
|
||||
UntrackedSharedMemory(name=f"out-{name}", create=True, size=20 * 6 * 4)
|
||||
UntrackedSharedMemory(
|
||||
name=name,
|
||||
create=True,
|
||||
size=detection_frame_size(model),
|
||||
)
|
||||
except FileExistsError:
|
||||
pass
|
||||
|
||||
|
||||
@@ -296,7 +296,8 @@ class CameraState:
|
||||
return frame_copy
|
||||
|
||||
def finished(self, obj_id: str) -> None:
|
||||
del self.tracked_objects[obj_id]
|
||||
# state rebuilt after a resolution or scene change no longer has the object
|
||||
self.tracked_objects.pop(obj_id, None)
|
||||
|
||||
def on(self, event_type: str, callback: Callable[..., Any]) -> None:
|
||||
self.callbacks[event_type].append(callback)
|
||||
|
||||
@@ -3,6 +3,8 @@
|
||||
from enum import Enum
|
||||
from typing import Any
|
||||
|
||||
from frigate.const import FAST_QUEUE_TIMEOUT
|
||||
|
||||
from .zmq_proxy import Publisher, Subscriber
|
||||
|
||||
|
||||
@@ -33,7 +35,7 @@ class DetectionSubscriber(Subscriber):
|
||||
super().__init__(topic)
|
||||
|
||||
def check_for_update(
|
||||
self, timeout: float | None = None
|
||||
self, timeout: float | None = FAST_QUEUE_TIMEOUT
|
||||
) -> tuple[str, Any] | tuple[None, None] | None:
|
||||
return super().check_for_update(timeout)
|
||||
|
||||
|
||||
@@ -581,6 +581,7 @@ class WebPushClient(Communicator):
|
||||
sorted_objects.add(obj)
|
||||
|
||||
sorted_objects.update(payload["after"]["data"]["sub_labels"])
|
||||
sorted_objects.update(payload["after"]["data"]["audio"])
|
||||
|
||||
image = f"{payload['after']['thumb_path'].replace(BASE_DIR, '')}"
|
||||
ended = state == "end" or state == "genai"
|
||||
@@ -617,7 +618,14 @@ class WebPushClient(Communicator):
|
||||
else:
|
||||
formatted_zone_names.append(titlecase(zone_name.replace("_", " ")))
|
||||
|
||||
title = f"{titlecase(', '.join(sorted_objects).replace('_', ' '))}{' was' if state == 'end' else ''} detected in {', '.join(formatted_zone_names)}"
|
||||
object_names = titlecase(
|
||||
", ".join(sorted(sorted_objects)).replace("_", " ")
|
||||
)
|
||||
title = f"{object_names}{' was' if state == 'end' else ''} detected"
|
||||
|
||||
if formatted_zone_names:
|
||||
title += f" in {', '.join(formatted_zone_names)}"
|
||||
|
||||
message = f"Detected on {camera_name}"
|
||||
|
||||
if ended:
|
||||
|
||||
@@ -39,6 +39,7 @@ from frigate.util.image import create_mask
|
||||
from frigate.util.live_streams import (
|
||||
default_transcode_source,
|
||||
is_transcode_stream_name,
|
||||
is_valid_go2rtc_stream_name,
|
||||
transcode_stream_name,
|
||||
transcode_streams,
|
||||
)
|
||||
@@ -314,6 +315,11 @@ def apply_live_transcode_streams(
|
||||
f"Camera {camera_config.name} has transcoded streams enabled, but its source {transcode.source} is not a go2rtc stream."
|
||||
)
|
||||
|
||||
if not is_valid_go2rtc_stream_name(transcode.source):
|
||||
raise ValueError(
|
||||
f"Camera {camera_config.name} transcodes go2rtc stream {transcode.source}, whose name contains '#', whitespace or quotes."
|
||||
)
|
||||
|
||||
generated = transcode_streams(
|
||||
camera_config.name,
|
||||
transcode.source,
|
||||
|
||||
@@ -84,3 +84,13 @@ class MqttConfig(FrigateBaseModel):
|
||||
if (self.user is None) != (self.password is None):
|
||||
raise ValueError("Password must be provided with username.")
|
||||
return self
|
||||
|
||||
@model_validator(mode="after")
|
||||
def tls_insecure_requires_tls(self) -> Self:
|
||||
"""Reject TLS verification settings without TLS when MQTT is enabled."""
|
||||
if self.enabled and self.tls_insecure is not None and self.tls_ca_certs is None:
|
||||
raise ValueError(
|
||||
"tls_insecure requires tls_ca_certs. Remove tls_insecure for plaintext "
|
||||
"MQTT, or set tls_ca_certs to a CA certificate path to enable TLS."
|
||||
)
|
||||
return self
|
||||
|
||||
@@ -35,6 +35,7 @@ from frigate.data_processing.types import PostProcessDataEnum
|
||||
from frigate.genai import GenAIClient
|
||||
from frigate.genai.manager import GenAIClientManager
|
||||
from frigate.models import Event, Recordings, ReviewSegment
|
||||
from frigate.output.preview import is_camera_preview_frame
|
||||
from frigate.util.builtin import EventsPerSecond, InferenceSpeed
|
||||
from frigate.util.image import get_image_from_recording
|
||||
from frigate.util.recording_coverage import recording_overlap
|
||||
@@ -68,6 +69,9 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
||||
self.review_desc_dps = EventsPerSecond()
|
||||
self.review_desc_dps.start()
|
||||
|
||||
# one review's ffmpeg extraction at a time, as on the maintainer loop
|
||||
self._frame_extraction_lock = threading.Lock()
|
||||
|
||||
def calculate_frame_count(
|
||||
self,
|
||||
camera: str,
|
||||
@@ -179,53 +183,72 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
||||
):
|
||||
return
|
||||
|
||||
image_source = camera_config.review.genai.image_source
|
||||
frame_mode = camera_config.review.genai.frame_mode
|
||||
threading.Thread(
|
||||
target=self._describe_finished_review,
|
||||
name=f"review_description_{id}",
|
||||
daemon=True,
|
||||
args=(
|
||||
camera_config,
|
||||
final_data,
|
||||
camera_config.review.genai.image_source,
|
||||
),
|
||||
).start()
|
||||
|
||||
def _describe_finished_review(
|
||||
self,
|
||||
camera_config: CameraConfig,
|
||||
final_data: dict[str, Any],
|
||||
image_source: ImageSourceEnum,
|
||||
preview_fallback: bool = True,
|
||||
named_objects: list[tuple[str, str]] | None = None,
|
||||
) -> None:
|
||||
"""Gather frames for a finished review item and start its description.
|
||||
|
||||
Runs off the maintainer loop since recording frames shell out to ffmpeg
|
||||
once per frame.
|
||||
"""
|
||||
camera = final_data["camera"]
|
||||
id = final_data["id"]
|
||||
genai_config = camera_config.review.genai
|
||||
frames: list[tuple[bytes, float]] = []
|
||||
|
||||
if image_source == ImageSourceEnum.recordings:
|
||||
buffer_extension = get_recording_buffer_extension(
|
||||
final_data["end_time"] - final_data["start_time"]
|
||||
)
|
||||
final_data["start_time"] -= buffer_extension
|
||||
final_data["end_time"] += buffer_extension
|
||||
|
||||
with self._frame_extraction_lock:
|
||||
frames = self.get_recording_frames(
|
||||
camera,
|
||||
final_data["start_time"],
|
||||
final_data["end_time"],
|
||||
final_data["start_time"] - buffer_extension,
|
||||
final_data["end_time"] + buffer_extension,
|
||||
height=480, # Use 480p for good balance between quality and token usage
|
||||
frame_mode=frame_mode,
|
||||
frame_mode=genai_config.frame_mode,
|
||||
)
|
||||
|
||||
if frames:
|
||||
if genai_config.debug_save_thumbnails:
|
||||
self.save_debug_recording_frames(id, frames)
|
||||
elif not preview_fallback:
|
||||
logger.error("No recording frames are available for review item %s", id)
|
||||
return
|
||||
else:
|
||||
logger.warning(
|
||||
"No recording frames found for %s, falling back to preview frames",
|
||||
camera,
|
||||
)
|
||||
|
||||
if not frames:
|
||||
# Fallback to preview frames if no recordings available
|
||||
logger.warning(
|
||||
f"No recording frames found for {camera}, falling back to preview frames"
|
||||
)
|
||||
frames = self.get_preview_frames_as_bytes(
|
||||
camera,
|
||||
final_data["start_time"],
|
||||
final_data["end_time"],
|
||||
final_data["thumb_path"],
|
||||
id,
|
||||
camera_config.review.genai.debug_save_thumbnails,
|
||||
frame_mode,
|
||||
)
|
||||
elif camera_config.review.genai.debug_save_thumbnails:
|
||||
self.save_debug_recording_frames(id, frames)
|
||||
else:
|
||||
# Use preview frames
|
||||
frames = self.get_preview_frames_as_bytes(
|
||||
camera,
|
||||
final_data["start_time"],
|
||||
final_data["end_time"],
|
||||
final_data["thumb_path"],
|
||||
id,
|
||||
camera_config.review.genai.debug_save_thumbnails,
|
||||
frame_mode,
|
||||
genai_config.debug_save_thumbnails,
|
||||
genai_config.frame_mode,
|
||||
)
|
||||
|
||||
self.start_analysis(camera_config, final_data, frames)
|
||||
self.start_analysis(camera_config, final_data, frames, named_objects)
|
||||
|
||||
def handle_request(self, topic: str, request_data: dict[str, Any]) -> str | None:
|
||||
if topic == EmbeddingsRequestEnum.regenerate_review_description.value:
|
||||
@@ -419,31 +442,12 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
||||
logger.error("Review item %s has not ended yet", review_id)
|
||||
return
|
||||
|
||||
buffer_extension = get_recording_buffer_extension(
|
||||
final_data["end_time"] - final_data["start_time"]
|
||||
)
|
||||
frames = self.get_recording_frames(
|
||||
str(review.camera),
|
||||
final_data["start_time"] - buffer_extension,
|
||||
final_data["end_time"] + buffer_extension,
|
||||
height=480,
|
||||
frame_mode=camera_config.review.genai.frame_mode,
|
||||
)
|
||||
|
||||
if not frames:
|
||||
logger.error(
|
||||
"No recording frames are available for review item %s", review_id
|
||||
)
|
||||
return
|
||||
|
||||
if camera_config.review.genai.debug_save_thumbnails:
|
||||
self.save_debug_recording_frames(review_id, frames)
|
||||
|
||||
self.start_analysis(
|
||||
self._describe_finished_review(
|
||||
camera_config,
|
||||
final_data,
|
||||
frames,
|
||||
get_named_objects(
|
||||
ImageSourceEnum.recordings,
|
||||
preview_fallback=False,
|
||||
named_objects=get_named_objects(
|
||||
final_data["data"].get("detections") or [],
|
||||
self.config.all_attributes,
|
||||
),
|
||||
@@ -525,7 +529,7 @@ class ReviewDescriptionProcessor(PostProcessorApi):
|
||||
camera_files = [
|
||||
entry.name
|
||||
for entry in os.scandir(preview_dir)
|
||||
if entry.name.startswith(file_start)
|
||||
if is_camera_preview_frame(entry.name, camera)
|
||||
]
|
||||
camera_files.sort()
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from frigate.config.classification import CustomClassificationConfig
|
||||
from frigate.const import CLIPS_DIR, MODEL_CACHE_DIR
|
||||
from frigate.log import suppress_stderr_during
|
||||
from frigate.util.builtin import EventsPerSecond, InferenceSpeed, load_labels
|
||||
from frigate.util.classification import resize_classification_image
|
||||
from frigate.util.file import trim_oldest_files
|
||||
from frigate.util.image import calculate_region
|
||||
from frigate.util.object import box_overlaps
|
||||
@@ -275,7 +276,7 @@ class CustomStateClassificationProcessor(DeferredRealtimeProcessorApi):
|
||||
cropped_frame = rgb[y1:y2, x1:x2]
|
||||
|
||||
try:
|
||||
resized_frame = cv2.resize(cropped_frame, (224, 224))
|
||||
resized_frame = resize_classification_image(cropped_frame)
|
||||
except Exception:
|
||||
logger.warning("Failed to resize image for state classification")
|
||||
return
|
||||
@@ -583,7 +584,7 @@ class CustomObjectClassificationProcessor(DeferredRealtimeProcessorApi):
|
||||
crop = rgb[y:y2, x:x2]
|
||||
|
||||
try:
|
||||
resized_crop = cv2.resize(crop, (224, 224))
|
||||
resized_crop = resize_classification_image(crop)
|
||||
except Exception:
|
||||
logger.warning("Failed to resize image for object classification")
|
||||
return
|
||||
|
||||
@@ -153,6 +153,8 @@ def get_ort_session_options(
|
||||
sess_options = ort.SessionOptions()
|
||||
|
||||
if cpu:
|
||||
# ORT reads the CPU arena flag from session options, not provider options.
|
||||
sess_options.enable_cpu_mem_arena = False
|
||||
# idle intra-op threads otherwise spin for ~1s after every run, keeping
|
||||
# most cores busy while an enrichment runs even once a second
|
||||
sess_options.add_session_config_entry("session.intra_op.allow_spinning", "0")
|
||||
|
||||
@@ -16,14 +16,20 @@ from pydantic import ConfigDict, Field, field_validator
|
||||
from frigate.detectors.detection_api import DetectionApi
|
||||
from frigate.detectors.detector_config import BaseDetectorConfig, ModelTypeEnum
|
||||
from frigate.util.model import post_process_yolo, post_process_yolox
|
||||
from frigate.util.runtime_deps import Artifact, ArtifactKind, RuntimeManifest
|
||||
from frigate.util.runtime_deps import (
|
||||
ArchiveDest,
|
||||
ArchiveMapping,
|
||||
Artifact,
|
||||
ArtifactKind,
|
||||
RuntimeManifest,
|
||||
)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
DETECTOR_KEY = "deepx"
|
||||
|
||||
# Installed at first start; DEEPX's PyPI wheels match the libdxrt-bin build.
|
||||
DXRT_VERSION = "3.4.0"
|
||||
# Installed at first start; the wheel ships inside the libdxrt-bin package.
|
||||
DXRT_VERSION = "3.5.0"
|
||||
|
||||
# Where the host dxrtd accepts clients; a container cannot reach its abstract
|
||||
# socket, and a mounted socket file pins a stale inode after a daemon restart.
|
||||
@@ -70,10 +76,13 @@ PPU_ANCHORS_BY_SCALES = {
|
||||
),
|
||||
}
|
||||
|
||||
# .dxnn: "DXNN", a 4-byte LE version, then a JSON index padded to
|
||||
# DXNN_HEADER_SIZE; every offset in the index counts from there.
|
||||
# .dxnn v7/v8: "DXNN", a 4-byte LE version, then a JSON index padded to
|
||||
# DXNN_HEADER_SIZE, offsets relative to it. v9 prefixes the index length.
|
||||
DXNN_MAGIC = b"DXNN"
|
||||
DXNN_HEADER_SIZE = 8192
|
||||
DXNN_PRELUDE_SIZE = 32
|
||||
DXNN_V9_VERSION = 9
|
||||
DXNN_MAX_HEADER_SIZE = 16 * 1024 * 1024
|
||||
# The graph DX-COM keeps for visualisation, an ONNX ModelProto beside the
|
||||
# encrypted model; only its nodes are read, for how the box tensor was built.
|
||||
DXNN_GRAPH_SECTION = "vis_npu_models"
|
||||
@@ -103,32 +112,45 @@ MULTIPART_CLASSES = 80
|
||||
MULTIPART_CHANNELS = 3 * (5 + MULTIPART_CLASSES)
|
||||
|
||||
|
||||
# PyPI URLs carry a per-file digest, so a version bump rewrites them whole.
|
||||
# The wheel links against the runtime libraries the package ships.
|
||||
DEEPX_LIBS = ArchiveMapping(
|
||||
"./usr/local/lib/",
|
||||
ArchiveDest.lib,
|
||||
include=("libdxrt.so*", "libonnxruntime.so*"),
|
||||
)
|
||||
|
||||
# The deb carries a wheel per CPython ABI; `member` picks this image's and
|
||||
# `member_sha256` pins it. Only the wheel and DEEPX_LIBS are kept out of it.
|
||||
DEEPX_MANIFEST = RuntimeManifest(
|
||||
name=DETECTOR_KEY,
|
||||
version=DXRT_VERSION,
|
||||
artifacts=(
|
||||
Artifact(
|
||||
url=(
|
||||
"https://files.pythonhosted.org/packages/de/45/"
|
||||
"1ca593e1c4ed868618658e07adeffc1fb44b92655d1ba48a6c76942616ee/"
|
||||
"dx_engine-3.4.0-cp311-cp311-manylinux_2_27_aarch64.whl"
|
||||
"https://github.com/DEEPX-AI/dx_rt/raw/refs/tags/v3.5.0/"
|
||||
"release/3.5.0/libdxrt-bin_3.5.0_arm64.deb"
|
||||
),
|
||||
sha256="ec4188e0a598a164bc04312482f70159be1a3d888284dcf52746054138101ec7",
|
||||
kind=ArtifactKind.wheel,
|
||||
sha256="f7c942ddfa325f435de3ab9a42b32b322f97dacff7f3468a37e32a6386a03681",
|
||||
kind=ArtifactKind.deb,
|
||||
machines=("aarch64",),
|
||||
mappings=(DEEPX_LIBS,),
|
||||
member="dx_engine-3.5.0-cp311-cp311-*.whl",
|
||||
member_sha256="276e1860af91ab3f937047fe8c4f59c169b4a5ed191f1c1cb606f89045c6967a",
|
||||
),
|
||||
Artifact(
|
||||
url=(
|
||||
"https://files.pythonhosted.org/packages/b0/32/"
|
||||
"d52b33d5b85f7d8565e3e2d153f19db6d506cd5504339f31c6553eae06c6/"
|
||||
"dx_engine-3.4.0-cp311-cp311-manylinux_2_27_x86_64.whl"
|
||||
"https://github.com/DEEPX-AI/dx_rt/raw/refs/tags/v3.5.0/"
|
||||
"release/3.5.0/libdxrt-bin_3.5.0_amd64.deb"
|
||||
),
|
||||
sha256="161fde8428fc8aea95c560d878bc68e8d1c657c18a0eb04840de4bd212f3477f",
|
||||
kind=ArtifactKind.wheel,
|
||||
sha256="c1993416e43059fb4751b2fd093d4232ab2ae8e67a5ec4156c79889e66260f64",
|
||||
kind=ArtifactKind.deb,
|
||||
machines=("x86_64",),
|
||||
mappings=(DEEPX_LIBS,),
|
||||
member="dx_engine-3.5.0-cp311-cp311-*.whl",
|
||||
member_sha256="ec5b80970271ac6d236fa4bc3277e425d6d8bcb89a977f7c236ac0431dd60558",
|
||||
),
|
||||
),
|
||||
preload=("libonnxruntime.so.1", "libdxrt.so"),
|
||||
import_check="dx_engine",
|
||||
)
|
||||
|
||||
@@ -408,17 +430,32 @@ def read_ppu_layout(path: str) -> PpuLayout | None:
|
||||
is none to read."""
|
||||
try:
|
||||
with open(path, "rb") as model:
|
||||
header = model.read(DXNN_HEADER_SIZE)
|
||||
if header[:4] != DXNN_MAGIC:
|
||||
prelude = model.read(DXNN_PRELUDE_SIZE)
|
||||
if prelude[:4] != DXNN_MAGIC:
|
||||
return None
|
||||
|
||||
index = json.JSONDecoder().raw_decode(
|
||||
header[8:].decode("utf-8", "replace")
|
||||
)[0]
|
||||
version = struct.unpack_from("<I", prelude, 4)[0]
|
||||
|
||||
if version >= DXNN_V9_VERSION:
|
||||
header_length = struct.unpack_from("<Q", prelude, 8)[0]
|
||||
|
||||
if header_length > DXNN_MAX_HEADER_SIZE:
|
||||
return None
|
||||
|
||||
raw_index = model.read(header_length)
|
||||
data_offset = DXNN_PRELUDE_SIZE + header_length
|
||||
else:
|
||||
model.seek(8)
|
||||
raw_index = model.read(DXNN_HEADER_SIZE - 8)
|
||||
data_offset = DXNN_HEADER_SIZE
|
||||
|
||||
decoder = json.JSONDecoder()
|
||||
index = decoder.raw_decode(raw_index.decode("utf-8", "replace"))[0]
|
||||
|
||||
data = index["data"]
|
||||
|
||||
def section(entry: dict) -> bytes:
|
||||
model.seek(DXNN_HEADER_SIZE + int(entry["offset"]))
|
||||
model.seek(data_offset + int(entry["offset"]))
|
||||
return model.read(int(entry["size"]))
|
||||
|
||||
anchor_based = None
|
||||
|
||||
@@ -68,6 +68,10 @@ class GenAIEmbedding:
|
||||
f"Invalid embedding_type '{embedding_type}'. Must be 'text' or 'vision'."
|
||||
)
|
||||
|
||||
# Callers index the result, so an empty provider response must raise
|
||||
if not embeddings:
|
||||
raise ValueError(f"Empty {embedding_type} embedding response from provider")
|
||||
|
||||
result = []
|
||||
for emb in embeddings:
|
||||
arr = np.asarray(emb, dtype=np.float32)
|
||||
|
||||
@@ -42,6 +42,7 @@ def should_update_db(prev_event: dict[str, Any], current_event: dict[str, Any])
|
||||
or prev_event["recognized_license_plate"]
|
||||
!= current_event["recognized_license_plate"]
|
||||
or prev_event["path_data"] != current_event["path_data"]
|
||||
or prev_event["max_severity"] != current_event["max_severity"]
|
||||
):
|
||||
return True
|
||||
return False
|
||||
|
||||
@@ -9,6 +9,7 @@ import time
|
||||
from collections.abc import AsyncGenerator
|
||||
from typing import Any
|
||||
|
||||
import numpy as np
|
||||
from google import genai
|
||||
from google.genai import errors, types
|
||||
from google.genai.types import FunctionCallingConfigMode
|
||||
@@ -16,7 +17,7 @@ from PIL import Image
|
||||
|
||||
from frigate.config import GenAIProviderEnum
|
||||
from frigate.genai import GenAIClient, register_genai_provider
|
||||
from frigate.genai.utils import interleave_images
|
||||
from frigate.genai.utils import interleave_images, to_jpeg
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
@@ -29,6 +30,9 @@ GEMINI_MAX_INLINE_BYTES = 15 * 1024 * 1024
|
||||
COUNT_TOKENS_TIMEOUT_MS = 5000
|
||||
COUNT_TOKENS_RETRY_INTERVAL = 300
|
||||
|
||||
# sqlite-vec stores thumbnail and description embeddings as FLOAT[768].
|
||||
GEMINI_EMBEDDING_DIM = 768
|
||||
|
||||
|
||||
def _decode_thought_signature(value: Any) -> bytes | None:
|
||||
"""Decode a base64-encoded thought_signature carried across conversation turns."""
|
||||
@@ -103,11 +107,13 @@ class GeminiClient(GenAIClient):
|
||||
provider: genai.Client
|
||||
_image_token_cache: dict[tuple[int, int], int]
|
||||
_image_token_retry_at: float
|
||||
_capabilities_cache: dict[str, dict[str, bool]] | None = None
|
||||
|
||||
def _init_provider(self) -> genai.Client:
|
||||
"""Initialize the client."""
|
||||
self._image_token_cache = {}
|
||||
self._image_token_retry_at = 0.0
|
||||
self._capabilities_cache = None
|
||||
|
||||
# Merge provider_options into HttpOptions
|
||||
http_options_dict: dict[str, Any] = {
|
||||
@@ -232,13 +238,41 @@ class GeminiClient(GenAIClient):
|
||||
|
||||
return transcript or None
|
||||
|
||||
@staticmethod
|
||||
def _capabilities_from_models(models: Any) -> dict[str, dict[str, bool]]:
|
||||
"""Build a per-model capability map from Gemini's models.list() entries."""
|
||||
capabilities: dict[str, dict[str, bool]] = {}
|
||||
for m in models:
|
||||
name = getattr(m, "name", None) or ""
|
||||
if not name:
|
||||
continue
|
||||
actions = getattr(m, "supported_actions", None) or []
|
||||
flags = {"supports_embeddings": "embedContent" in actions}
|
||||
capabilities[name] = flags
|
||||
capabilities[name.removeprefix("models/")] = flags
|
||||
return capabilities
|
||||
|
||||
def list_models(self) -> list[str]:
|
||||
"""Return available model names from Gemini."""
|
||||
try:
|
||||
return sorted(m.name or "" for m in self.provider.models.list())
|
||||
models = list(self.provider.models.list())
|
||||
except Exception as e:
|
||||
logger.warning("Failed to list Gemini models: %s", e)
|
||||
return []
|
||||
self._capabilities_cache = self._capabilities_from_models(models)
|
||||
return sorted(m.name or "" for m in models)
|
||||
|
||||
def list_model_capabilities(self) -> dict[str, dict[str, bool]]:
|
||||
"""Report per-model capabilities from Gemini's model list."""
|
||||
if self._capabilities_cache is not None:
|
||||
return self._capabilities_cache
|
||||
try:
|
||||
models = list(self.provider.models.list())
|
||||
except Exception as e:
|
||||
logger.debug("Failed to query Gemini model capabilities: %s", e)
|
||||
return {}
|
||||
self._capabilities_cache = self._capabilities_from_models(models)
|
||||
return self._capabilities_cache
|
||||
|
||||
def get_context_size(self) -> int:
|
||||
"""Get the context window size for Gemini."""
|
||||
@@ -310,6 +344,103 @@ class GeminiClient(GenAIClient):
|
||||
|
||||
return total
|
||||
|
||||
@property
|
||||
def supports_embeddings(self) -> bool:
|
||||
"""Whether Gemini reports embedContent support for the configured model."""
|
||||
capabilities = self.list_model_capabilities().get(self._embedding_model_name())
|
||||
return bool(capabilities and capabilities.get("supports_embeddings"))
|
||||
|
||||
def _embedding_model_name(self) -> str:
|
||||
"""Model id for embed_content, without a ``models/`` prefix."""
|
||||
return self.genai_config.model.removeprefix("models/")
|
||||
|
||||
def _vector_from_embed(self, result: Any) -> np.ndarray:
|
||||
"""Read the single embedding vector from an embed_content response."""
|
||||
embeddings = getattr(result, "embeddings", None) or []
|
||||
values = embeddings[0].values if embeddings else None
|
||||
if not values:
|
||||
raise ValueError("Gemini embeddings response had no vector")
|
||||
return np.asarray(values, dtype=np.float32)
|
||||
|
||||
def _embed_one(self, model: str, contents: Any) -> np.ndarray:
|
||||
"""One embed_content call. API failures become ValueError.
|
||||
|
||||
``_embed_thumbnail`` only catches ValueError. Returning an empty
|
||||
list makes the caller index ``[0]`` and can stop the embeddings
|
||||
process.
|
||||
"""
|
||||
try:
|
||||
result = self.provider.models.embed_content(
|
||||
model=model,
|
||||
contents=contents,
|
||||
config=types.EmbedContentConfig(
|
||||
output_dimensionality=GEMINI_EMBEDDING_DIM
|
||||
),
|
||||
)
|
||||
except Exception as e:
|
||||
logger.warning("Gemini embeddings request failed: %s", e)
|
||||
raise ValueError("Gemini embeddings request failed") from e
|
||||
|
||||
return self._vector_from_embed(result)
|
||||
|
||||
def embed(
|
||||
self,
|
||||
texts: list[str] | None = None,
|
||||
images: list[bytes] | None = None,
|
||||
) -> list[np.ndarray]:
|
||||
"""Embed each text or image on its own.
|
||||
|
||||
gemini-embedding-2 returns one vector per request. Several parts
|
||||
in one contents list are aggregated into that single vector, so
|
||||
each description, search query, and thumbnail is its own call.
|
||||
|
||||
Stored descriptions and search queries share this text path, so
|
||||
both get the search-query prefix and stay in one format. A text
|
||||
that already starts with ``task:`` is sent unchanged. Images are
|
||||
not prefixed. The API accepts PNG and JPEG only, and Frigate
|
||||
stores thumbnails as WebP, so each image is transcoded first.
|
||||
Requested length is 768, matching the semantic search tables.
|
||||
|
||||
Args:
|
||||
texts: Strings to embed.
|
||||
images: Encoded images, typically WebP thumbnails.
|
||||
|
||||
Returns:
|
||||
One float32 vector per input, length 768.
|
||||
|
||||
Raises:
|
||||
ValueError: An image cannot be converted, the response has
|
||||
no vector, or the request fails.
|
||||
"""
|
||||
texts = texts or []
|
||||
images = images or []
|
||||
if not texts and not images:
|
||||
return []
|
||||
|
||||
model = self._embedding_model_name()
|
||||
vectors: list[np.ndarray] = []
|
||||
|
||||
for text in texts:
|
||||
content = (
|
||||
text
|
||||
if text.startswith("task:")
|
||||
else f"task: search result | query: {text}"
|
||||
)
|
||||
vectors.append(self._embed_one(model, content))
|
||||
|
||||
for image in images:
|
||||
jpeg = to_jpeg(image)
|
||||
if jpeg is None:
|
||||
raise ValueError("thumbnail could not be converted to JPEG")
|
||||
vectors.append(
|
||||
self._embed_one(
|
||||
model,
|
||||
[types.Part.from_bytes(data=jpeg, mime_type="image/jpeg")],
|
||||
)
|
||||
)
|
||||
|
||||
return vectors
|
||||
|
||||
def chat_with_tools(
|
||||
self,
|
||||
messages: list[dict[str, Any]],
|
||||
|
||||
@@ -39,6 +39,28 @@ def _stats_from_openai_usage(usage: Any) -> dict[str, Any] | None:
|
||||
return stats or None
|
||||
|
||||
|
||||
def _context_size_from_model(model: Any) -> int | None:
|
||||
"""Read the context window from an OpenAI-compatible /models entry.
|
||||
|
||||
vLLM reports ``max_model_len``. OpenRouter reports ``context_length`` as the
|
||||
largest window any of its providers offers, and ``top_provider.context_length``
|
||||
for the provider it routes to first. The latter can be smaller, so it is
|
||||
preferred to avoid sending more than the serving provider accepts.
|
||||
"""
|
||||
top_provider = getattr(model, "top_provider", None)
|
||||
candidates = (
|
||||
getattr(model, "max_model_len", None),
|
||||
top_provider.get("context_length") if isinstance(top_provider, dict) else None,
|
||||
getattr(model, "context_length", None),
|
||||
)
|
||||
|
||||
for value in candidates:
|
||||
if isinstance(value, int) and value > 0:
|
||||
return value
|
||||
|
||||
return None
|
||||
|
||||
|
||||
@register_genai_provider(GenAIProviderEnum.openai)
|
||||
class OpenAIClient(GenAIClient):
|
||||
"""Generative AI client for Frigate using OpenAI."""
|
||||
@@ -225,8 +247,9 @@ class OpenAIClient(GenAIClient):
|
||||
models = self.provider.models.list()
|
||||
for model in models.data:
|
||||
if model.id == self.genai_config.model:
|
||||
if hasattr(model, "max_model_len") and model.max_model_len:
|
||||
self.context_size = model.max_model_len
|
||||
context_size = _context_size_from_model(model)
|
||||
if context_size:
|
||||
self.context_size = context_size
|
||||
logger.debug(
|
||||
f"Retrieved context size {self.context_size} for model {self.genai_config.model}"
|
||||
)
|
||||
|
||||
@@ -187,16 +187,35 @@ def build_review_description_response_format(concerns: list[str]) -> dict[str, A
|
||||
|
||||
Strips the `time` field (populated server-side) and drops
|
||||
`other_concerns` when no concerns are configured.
|
||||
|
||||
Every remaining property must be listed in `required` because strict
|
||||
providers (OpenAI) reject a schema with any optional property.
|
||||
"""
|
||||
schema = ReviewMetadata.model_json_schema()
|
||||
schema.get("properties", {}).pop("time", None)
|
||||
properties = schema.setdefault("properties", {})
|
||||
required = schema.setdefault("required", [])
|
||||
properties.pop("time", None)
|
||||
|
||||
if "time" in schema.get("required", []):
|
||||
schema["required"].remove("time")
|
||||
if not concerns:
|
||||
schema.get("properties", {}).pop("other_concerns", None)
|
||||
if "other_concerns" in schema.get("required", []):
|
||||
schema["required"].remove("other_concerns")
|
||||
if "time" in required:
|
||||
required.remove("time")
|
||||
|
||||
if concerns:
|
||||
# The model field is nullable with a default so stored metadata
|
||||
# without concerns still parses. For generation, require a plain list
|
||||
# instead; the model returns an empty list when no concern applies.
|
||||
properties["other_concerns"] = {
|
||||
"type": "array",
|
||||
"items": {"type": "string"},
|
||||
"description": properties["other_concerns"]["description"],
|
||||
}
|
||||
|
||||
if "other_concerns" not in required:
|
||||
required.append("other_concerns")
|
||||
else:
|
||||
properties.pop("other_concerns", None)
|
||||
|
||||
if "other_concerns" in required:
|
||||
required.remove("other_concerns")
|
||||
|
||||
return {
|
||||
"type": "json_schema",
|
||||
|
||||
@@ -16,18 +16,21 @@ from abc import ABC, abstractmethod
|
||||
from dataclasses import dataclass
|
||||
from typing import TYPE_CHECKING, Any, Optional, cast
|
||||
|
||||
from peewee import ModelSelect
|
||||
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config.camera.updater import CameraConfigUpdatePublisher
|
||||
from frigate.const import REPLAY_CAMERA_PREFIX, REPLAY_DIR
|
||||
from frigate.const import (
|
||||
REPLAY_CAMERA_PREFIX,
|
||||
REPLAY_DIR,
|
||||
STREAM_TYPE_MAIN,
|
||||
STREAM_TYPE_SUB,
|
||||
)
|
||||
from frigate.jobs.export import JobStatePublisher
|
||||
from frigate.jobs.job import Job
|
||||
from frigate.jobs.manager import job_is_running, set_current_job
|
||||
from frigate.models import Export, Recordings
|
||||
from frigate.models import Export
|
||||
from frigate.types import JobStatusTypesEnum
|
||||
from frigate.util.ffmpeg import run_ffmpeg_with_progress
|
||||
from frigate.util.recording_coverage import recording_overlap
|
||||
from frigate.util.recording_coverage import resolve_coverage
|
||||
|
||||
if TYPE_CHECKING:
|
||||
from frigate.debug_replay import DebugReplayManager
|
||||
@@ -94,24 +97,6 @@ class DebugReplayJob(Job):
|
||||
}
|
||||
|
||||
|
||||
def query_recordings(source_camera: str, start_ts: float, end_ts: float) -> ModelSelect:
|
||||
"""Return the Recordings query for the time range.
|
||||
|
||||
Module-level so tests can patch it without instantiating a runner.
|
||||
"""
|
||||
query = (
|
||||
Recordings.select(
|
||||
Recordings.path,
|
||||
Recordings.start_time,
|
||||
Recordings.end_time,
|
||||
)
|
||||
.where(recording_overlap(start_ts, end_ts))
|
||||
.where(Recordings.camera == source_camera)
|
||||
.order_by(Recordings.start_time.asc())
|
||||
)
|
||||
return cast(ModelSelect, query)
|
||||
|
||||
|
||||
class NoRecordingsError(ValueError):
|
||||
"""Raised when no recordings exist in the requested time range."""
|
||||
|
||||
@@ -156,7 +141,8 @@ class RecordingDebugReplaySource(DebugReplaySource):
|
||||
|
||||
Feeds ffmpeg the internal VOD endpoint so segments with mismatched
|
||||
SPS/PPS (e.g. across day/night transitions) stitch cleanly via HLS
|
||||
discontinuities.
|
||||
discontinuities. The playlist is pinned to one stream because the
|
||||
stream-copied clip cannot change codec or resolution mid-file.
|
||||
"""
|
||||
|
||||
def __init__(
|
||||
@@ -170,6 +156,7 @@ class RecordingDebugReplaySource(DebugReplaySource):
|
||||
self._start_ts = start_ts
|
||||
self._end_ts = end_ts
|
||||
self._internal_port = internal_port
|
||||
self._stream_type = STREAM_TYPE_MAIN
|
||||
|
||||
@property
|
||||
def source_camera(self) -> str:
|
||||
@@ -187,7 +174,19 @@ class RecordingDebugReplaySource(DebugReplaySource):
|
||||
if self._end_ts <= self._start_ts:
|
||||
raise ValueError("End time must be after start time")
|
||||
|
||||
if not query_recordings(self._camera, self._start_ts, self._end_ts).count():
|
||||
# the VOD resolver decides what the pinned playlist serves, so it
|
||||
# also decides the stream; a row merely touching the range has no
|
||||
# interval and must not win
|
||||
intervals = resolve_coverage(self._camera, self._start_ts, self._end_ts)
|
||||
|
||||
if any(interval.main for interval in intervals):
|
||||
self._stream_type = STREAM_TYPE_MAIN
|
||||
return
|
||||
|
||||
if any(interval.sub for interval in intervals):
|
||||
self._stream_type = STREAM_TYPE_SUB
|
||||
return
|
||||
|
||||
raise NoRecordingsError(
|
||||
f"No recordings found for camera '{self._camera}' in the specified time range"
|
||||
)
|
||||
@@ -195,7 +194,8 @@ class RecordingDebugReplaySource(DebugReplaySource):
|
||||
def ffmpeg_input_args(self, working_dir: str) -> list[str]:
|
||||
playlist_url = (
|
||||
f"http://127.0.0.1:{self._internal_port}/vod/{self._camera}"
|
||||
f"/start/{self._start_ts}/end/{self._end_ts}/index.m3u8"
|
||||
f"/{self._stream_type}/start/{self._start_ts}/end/{self._end_ts}"
|
||||
"/index.m3u8"
|
||||
)
|
||||
return [
|
||||
"-protocol_whitelist",
|
||||
|
||||
@@ -6,8 +6,10 @@ import threading
|
||||
import time
|
||||
from collections.abc import Callable, Generator, Iterable
|
||||
from concurrent.futures import Future, ThreadPoolExecutor, as_completed
|
||||
from contextlib import closing
|
||||
from dataclasses import asdict, dataclass, field
|
||||
from datetime import datetime
|
||||
from itertools import islice
|
||||
from typing import Any
|
||||
|
||||
import cv2
|
||||
@@ -611,24 +613,49 @@ class MotionSearchRunner(threading.Thread):
|
||||
|
||||
def _detect_with_progress(
|
||||
self,
|
||||
indexed_frames: list[tuple[int, np.ndarray]],
|
||||
frames: Iterable[np.ndarray],
|
||||
timestamp_fn: Callable[[int], float],
|
||||
) -> list[MotionSearchResult]:
|
||||
"""Run detection while firing throttled progress as frames are scanned."""
|
||||
) -> tuple[list[MotionSearchResult], int]:
|
||||
"""Run detection while firing throttled progress as frames are scanned.
|
||||
|
||||
Returns ``(results, frame_count)``.
|
||||
"""
|
||||
frame_count = 0
|
||||
|
||||
def _gen() -> Generator[tuple[int, np.ndarray], None, None]:
|
||||
for i, frame in indexed_frames:
|
||||
nonlocal frame_count
|
||||
for i, frame in enumerate(frames):
|
||||
frame_count = i + 1
|
||||
if not self._should_stop():
|
||||
self._emit_progress(timestamp_fn(i))
|
||||
yield i, frame
|
||||
|
||||
return detect_motion_scaled(
|
||||
results = detect_motion_scaled(
|
||||
_gen(),
|
||||
self.scaled_mask,
|
||||
self.job.threshold,
|
||||
self.job.min_area,
|
||||
timestamp_fn,
|
||||
)
|
||||
return results, frame_count
|
||||
|
||||
def _decode_vod(
|
||||
self, vod_url: str, keyframes: bool
|
||||
) -> Generator[np.ndarray, None, None]:
|
||||
return iter_vod_frames(
|
||||
self.ffmpeg_path,
|
||||
vod_url,
|
||||
self.scaled[0],
|
||||
self.scaled[1],
|
||||
self.channels,
|
||||
self.decode_args,
|
||||
self.crop,
|
||||
self.scaled,
|
||||
True,
|
||||
self._should_stop,
|
||||
skip_nonkey=keyframes,
|
||||
fps_rate=None if keyframes else self.fps_rate,
|
||||
)
|
||||
|
||||
def _process_run(
|
||||
self, run: list[Recordings]
|
||||
@@ -639,7 +666,8 @@ class MotionSearchRunner(threading.Thread):
|
||||
are all decoded anyway) paired with its probed PTS; if the decoded and
|
||||
probed counts disagree (the decoder ignored ``-skip_frame nokey`` or the
|
||||
stream is corrupt) this run re-runs in the fixed-cadence fallback.
|
||||
Returns ``(results, frame_count)``.
|
||||
Frames stream through detection, so a run never holds more than the
|
||||
current and previous frame. Returns ``(results, frame_count)``.
|
||||
"""
|
||||
run_start: float = run[0].start_time # type: ignore[assignment]
|
||||
run_end: float = run[-1].end_time # type: ignore[assignment]
|
||||
@@ -650,35 +678,21 @@ class MotionSearchRunner(threading.Thread):
|
||||
kf_pts = probe_vod_keyframe_pts(
|
||||
self.ffprobe_path, vod_url, self._should_stop
|
||||
)
|
||||
frames = list(
|
||||
iter_vod_frames(
|
||||
self.ffmpeg_path,
|
||||
vod_url,
|
||||
self.scaled[0],
|
||||
self.scaled[1],
|
||||
self.channels,
|
||||
self.decode_args,
|
||||
self.crop,
|
||||
self.scaled,
|
||||
True,
|
||||
self._should_stop,
|
||||
skip_nonkey=True,
|
||||
fps_rate=None,
|
||||
)
|
||||
)
|
||||
if kf_pts and len(frames) == len(kf_pts):
|
||||
|
||||
if kf_pts:
|
||||
abs_times = [stream_time_to_absolute(time_map, p) for p in kf_pts]
|
||||
indexed = list(enumerate(frames))
|
||||
|
||||
def _ts_kf(i: int) -> float:
|
||||
return abs_times[i]
|
||||
with closing(self._decode_vod(vod_url, keyframes=True)) as frames:
|
||||
results, frame_count = self._detect_with_progress(
|
||||
islice(frames, len(abs_times)), abs_times.__getitem__
|
||||
)
|
||||
extra_frames = next(frames, None) is not None
|
||||
|
||||
results = self._detect_with_progress(indexed, _ts_kf)
|
||||
return results, len(frames)
|
||||
if frame_count == len(abs_times) and not extra_frames:
|
||||
return results, frame_count
|
||||
|
||||
logger.debug(
|
||||
"Keyframe count mismatch (%d decoded vs %d probed), using cadence",
|
||||
len(frames),
|
||||
"Keyframe decode did not match %d probed keyframes, using cadence",
|
||||
len(kf_pts),
|
||||
)
|
||||
|
||||
@@ -688,29 +702,12 @@ class MotionSearchRunner(threading.Thread):
|
||||
self, vod_url: str, time_map: list[tuple[float, float, float]]
|
||||
) -> tuple[list[MotionSearchResult], int]:
|
||||
"""Fixed-cadence fallback: fps-filtered VOD decode, evenly spaced times."""
|
||||
frames = list(
|
||||
iter_vod_frames(
|
||||
self.ffmpeg_path,
|
||||
vod_url,
|
||||
self.scaled[0],
|
||||
self.scaled[1],
|
||||
self.channels,
|
||||
self.decode_args,
|
||||
self.crop,
|
||||
self.scaled,
|
||||
True,
|
||||
self._should_stop,
|
||||
skip_nonkey=False,
|
||||
fps_rate=self.fps_rate,
|
||||
)
|
||||
)
|
||||
indexed = list(enumerate(frames))
|
||||
|
||||
def _ts_fps(i: int) -> float:
|
||||
return stream_time_to_absolute(time_map, i / self.fps_rate)
|
||||
|
||||
results = self._detect_with_progress(indexed, _ts_fps)
|
||||
return results, len(frames)
|
||||
with closing(self._decode_vod(vod_url, keyframes=False)) as frames:
|
||||
return self._detect_with_progress(frames, _ts_fps)
|
||||
|
||||
def _merge_run(
|
||||
self,
|
||||
|
||||
@@ -113,6 +113,23 @@ class AsyncLocalObjectDetector(BaseLocalDetector):
|
||||
return self.detect_api.receive_output()
|
||||
|
||||
|
||||
def map_input_frame(
|
||||
frame_manager: SharedMemoryFrameManager, camera: str, model: ModelConfig
|
||||
) -> np.ndarray | None:
|
||||
"""Map a camera's detection input segment as this model's input tensor.
|
||||
|
||||
The segment is sized for the largest configured model, so it can be larger
|
||||
than this model's input.
|
||||
"""
|
||||
buf = frame_manager.write(camera)
|
||||
shape = (1, model.height, model.width, 3)
|
||||
|
||||
if buf is None or len(buf) < model.height * model.width * 3:
|
||||
return None
|
||||
|
||||
return np.ndarray(shape, dtype=np.uint8, buffer=buf)
|
||||
|
||||
|
||||
class DetectorRunner(FrigateProcess):
|
||||
def __init__(
|
||||
self,
|
||||
@@ -154,14 +171,10 @@ class DetectorRunner(FrigateProcess):
|
||||
connection_id = self.detection_queue.get(timeout=1)
|
||||
except queue.Empty:
|
||||
continue
|
||||
input_frame = frame_manager.get(
|
||||
input_frame = map_input_frame(
|
||||
frame_manager,
|
||||
connection_id,
|
||||
(
|
||||
1,
|
||||
self.detector_config.model.height, # type: ignore[union-attr]
|
||||
self.detector_config.model.width, # type: ignore[union-attr]
|
||||
3,
|
||||
),
|
||||
self.detector_config.model, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
if input_frame is None:
|
||||
@@ -227,14 +240,10 @@ class AsyncDetectorRunner(FrigateProcess):
|
||||
continue
|
||||
|
||||
assert self._frame_manager is not None
|
||||
input_frame = self._frame_manager.get(
|
||||
input_frame = map_input_frame(
|
||||
self._frame_manager,
|
||||
connection_id,
|
||||
(
|
||||
1,
|
||||
self.detector_config.model.height, # type: ignore[union-attr]
|
||||
self.detector_config.model.width, # type: ignore[union-attr]
|
||||
3,
|
||||
),
|
||||
self.detector_config.model, # type: ignore[arg-type]
|
||||
)
|
||||
|
||||
if input_frame is None:
|
||||
|
||||
@@ -6,18 +6,39 @@ import threading
|
||||
from numpy import ndarray
|
||||
|
||||
from frigate.detectors.detector_config import InputTensorEnum, ModelConfig
|
||||
from frigate.util.image import UntrackedSharedMemory
|
||||
|
||||
|
||||
def detection_frame_size(model: ModelConfig) -> int:
|
||||
"""Get the shared memory size a camera needs to hand frames to a model.
|
||||
def create_detection_input_shm(
|
||||
camera: str, models: list[ModelConfig]
|
||||
) -> UntrackedSharedMemory:
|
||||
"""Create the shared memory a camera hands detection frames through.
|
||||
|
||||
It is sized for the largest model so a camera re-added under the same name
|
||||
with another scene can reuse it. Detectors keep mappings of it, so it is
|
||||
never unlinked while they run.
|
||||
|
||||
Args:
|
||||
model: The model the camera runs on
|
||||
camera: Name of the camera
|
||||
models: Every configured model
|
||||
|
||||
Returns:
|
||||
Size in bytes of one model input frame
|
||||
The camera's detection input segment
|
||||
"""
|
||||
return model.height * model.width * 3
|
||||
size = max(model.height * model.width * 3 for model in models)
|
||||
|
||||
try:
|
||||
return UntrackedSharedMemory(name=camera, create=True, size=size)
|
||||
except FileExistsError:
|
||||
shm = UntrackedSharedMemory(name=camera)
|
||||
|
||||
if shm.size >= size:
|
||||
return shm
|
||||
|
||||
# left by an earlier run with smaller models, so no detector maps it yet
|
||||
shm.close()
|
||||
shm.unlink()
|
||||
return UntrackedSharedMemory(name=camera, create=True, size=size)
|
||||
|
||||
|
||||
class RequestStore:
|
||||
|
||||
@@ -379,7 +379,7 @@ def move_preview_frames(loc: str) -> None:
|
||||
src,
|
||||
dst,
|
||||
)
|
||||
except shutil.Error:
|
||||
except OSError:
|
||||
logger.error(
|
||||
"Failed to move preview restart cache from %s to %s",
|
||||
src,
|
||||
|
||||
+81
-1
@@ -3,9 +3,11 @@ import json
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
from enum import Enum
|
||||
from pathlib import Path
|
||||
from typing import Any
|
||||
from typing import Any, TypeGuard
|
||||
|
||||
import aiohttp
|
||||
import cv2
|
||||
import requests
|
||||
from numpy import ndarray
|
||||
@@ -17,6 +19,17 @@ from frigate.const import MODEL_CACHE_DIR, PLUS_API_HOST, PLUS_ENV_VAR
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
PLUS_VALIDATE_TIMEOUT = 10
|
||||
|
||||
|
||||
class PlusKeyStatus(str, Enum):
|
||||
"""Result of validating a Frigate+ API key with the server."""
|
||||
|
||||
valid = "valid"
|
||||
invalid = "invalid"
|
||||
unreachable = "unreachable"
|
||||
not_set = "not_set"
|
||||
|
||||
|
||||
def add_hailo_alias(model_info: dict[str, Any]) -> dict[str, Any]:
|
||||
"""Name the hailo detector by its current key as well as its old one.
|
||||
@@ -72,6 +85,19 @@ def get_jpg_bytes(image: ndarray, max_dim: int, quality: int) -> bytes:
|
||||
return jpg_bytes if isinstance(jpg_bytes, bytes) else b""
|
||||
|
||||
|
||||
def _is_usable_token(token_data: Any) -> TypeGuard[dict[str, Any]]:
|
||||
"""Whether a Frigate+ token response has a usable token and expiry."""
|
||||
if not isinstance(token_data, dict):
|
||||
return False
|
||||
|
||||
expires = token_data.get("expires")
|
||||
return (
|
||||
isinstance(token_data.get("accessToken"), str)
|
||||
and isinstance(expires, (int, float))
|
||||
and not isinstance(expires, bool)
|
||||
)
|
||||
|
||||
|
||||
class PlusApi:
|
||||
def __init__(self) -> None:
|
||||
self.host = PLUS_API_HOST
|
||||
@@ -153,6 +179,60 @@ class PlusApi:
|
||||
def is_active(self) -> bool:
|
||||
return self._is_active
|
||||
|
||||
async def validate_key(self) -> PlusKeyStatus:
|
||||
"""Check the configured API key against the Frigate+ server.
|
||||
|
||||
The key format is checked at startup, but only the server can tell
|
||||
whether the key is actually valid. This requests a fresh token so the
|
||||
result reflects the key's current state rather than a cached token.
|
||||
|
||||
Returns:
|
||||
The key's status as reported by the Frigate+ server
|
||||
"""
|
||||
if self.key is None:
|
||||
return PlusKeyStatus.not_set
|
||||
|
||||
key_id, _, secret = self.key.partition(":")
|
||||
|
||||
# Use a single request with a timeout instead of the retrying session,
|
||||
# since this is user initiated and should fail fast when unreachable.
|
||||
# trust_env honors proxy settings, matching the other Frigate+ requests.
|
||||
try:
|
||||
async with aiohttp.ClientSession(
|
||||
timeout=aiohttp.ClientTimeout(total=PLUS_VALIDATE_TIMEOUT),
|
||||
trust_env=True,
|
||||
) as session:
|
||||
async with session.get(
|
||||
f"{self.host}/v1/auth/token",
|
||||
auth=aiohttp.BasicAuth(key_id, secret),
|
||||
) as r:
|
||||
status = r.status
|
||||
token_data = await r.json(content_type=None) if r.ok else None
|
||||
except (aiohttp.ClientError, TimeoutError) as err:
|
||||
logger.warning("Unable to reach Frigate+ to validate API key: %s", err)
|
||||
return PlusKeyStatus.unreachable
|
||||
except ValueError:
|
||||
logger.warning("Invalid response validating Frigate+ API key")
|
||||
return PlusKeyStatus.unreachable
|
||||
|
||||
if status in (401, 403):
|
||||
return PlusKeyStatus.invalid
|
||||
|
||||
if status >= 400:
|
||||
logger.warning(
|
||||
"Unexpected response validating Frigate+ API key: %s", status
|
||||
)
|
||||
return PlusKeyStatus.unreachable
|
||||
|
||||
# Keep the cached token unless the reply is a usable one, so an
|
||||
# unexpected response can't break later Frigate+ requests
|
||||
if not _is_usable_token(token_data):
|
||||
logger.warning("Invalid response validating Frigate+ API key")
|
||||
return PlusKeyStatus.unreachable
|
||||
|
||||
self._token_data = token_data
|
||||
return PlusKeyStatus.valid
|
||||
|
||||
def upload_image(self, image: ndarray, camera: str) -> str:
|
||||
r = self._get("image/signed_urls")
|
||||
if not r.ok:
|
||||
|
||||
+46
-51
@@ -318,7 +318,13 @@ class PtzAutoTracker(threading.Thread):
|
||||
) = map(float, camera_config.onvif.autotracking.movement_weights)
|
||||
|
||||
if startup and camera_config.onvif.autotracking.calibrate_on_startup:
|
||||
try:
|
||||
await self._calibrate_camera(camera)
|
||||
except Exception:
|
||||
logger.exception(f"{camera}: Autotracker calibration failed")
|
||||
self.calibrating[camera] = False
|
||||
self._disable(camera, "calibration failed")
|
||||
return
|
||||
|
||||
self.dispatcher.publish(f"{camera}/ptz_autotracker/active", "OFF", retain=False)
|
||||
self.autotracker_init[camera] = True
|
||||
@@ -585,26 +591,36 @@ class PtzAutoTracker(threading.Thread):
|
||||
|
||||
def _predict_movement_time(self, camera, pan, tilt):
|
||||
combined_movement = abs(pan) + abs(tilt)
|
||||
input_data = np.array([self.intercept[camera], combined_movement])
|
||||
input_data = np.array([1, combined_movement])
|
||||
|
||||
return np.dot(self.move_coefficients[camera], input_data)
|
||||
|
||||
def _predict_area_after_time(self, camera, time):
|
||||
return np.dot(
|
||||
self.tracked_object_metrics[camera]["area_coefficients"],
|
||||
[self.tracked_object_history[camera][-1]["frame_time"] + time],
|
||||
)
|
||||
|
||||
def _predict_target_box(self, camera, predicted_time):
|
||||
target_box = self.tracked_object_metrics[camera]["target_box"]
|
||||
tom = self.tracked_object_metrics[camera]
|
||||
target_box = tom["target_box"]
|
||||
|
||||
if not predicted_time:
|
||||
return target_box
|
||||
|
||||
frame_shape = self.config.cameras[camera].frame_shape
|
||||
camera_config = self.config.cameras[camera]
|
||||
left, top, right, bottom = self.tracked_object_history[camera][-1]["box"]
|
||||
size = max(right - left, bottom - top)
|
||||
|
||||
return target_box + self._predict_area_after_time(camera, predicted_time) / (
|
||||
frame_shape[0] * frame_shape[1]
|
||||
if size <= 0:
|
||||
return target_box
|
||||
|
||||
# the corner velocities diverge as the object approaches the camera
|
||||
frames = camera_config.detect.fps * predicted_time
|
||||
velocity = tom["velocity"]
|
||||
predicted_size = max(
|
||||
right - left + frames * (velocity[2] - velocity[0]),
|
||||
bottom - top + frames * (velocity[3] - velocity[1]),
|
||||
1,
|
||||
)
|
||||
|
||||
# target_box is the squared size raised to the zoom factor
|
||||
return target_box * (predicted_size / size) ** (
|
||||
2 * camera_config.onvif.autotracking.zoom_factor
|
||||
)
|
||||
|
||||
def _calculate_tracked_object_metrics(self, camera, obj):
|
||||
@@ -660,26 +676,6 @@ class PtzAutoTracker(threading.Thread):
|
||||
|
||||
filtered_areas = remove_outliers(areas) if len(areas) > 3 else areas
|
||||
|
||||
# Filter entries that are not touching the frame edge
|
||||
filtered_areas_not_touching_edge = [
|
||||
entry
|
||||
for entry in filtered_areas
|
||||
if self._touching_frame_edges(camera, entry["box"]) == 0
|
||||
]
|
||||
|
||||
# Calculate regression for area change predictions
|
||||
if len(filtered_areas_not_touching_edge):
|
||||
X = np.array(
|
||||
[item["frame_time"] for item in filtered_areas_not_touching_edge]
|
||||
)
|
||||
y = np.array([item["area"] for item in filtered_areas_not_touching_edge])
|
||||
|
||||
tom["area_coefficients"] = np.linalg.lstsq(X.reshape(-1, 1), y, rcond=None)[
|
||||
0
|
||||
]
|
||||
else:
|
||||
tom["area_coefficients"] = np.array([0])
|
||||
|
||||
weights = np.arange(1, len(filtered_areas) + 1)
|
||||
weighted_area = np.average(
|
||||
[item["area"] for item in filtered_areas], weights=weights
|
||||
@@ -744,6 +740,8 @@ class PtzAutoTracker(threading.Thread):
|
||||
continue
|
||||
|
||||
else:
|
||||
pan_tilt_times = None
|
||||
|
||||
if (
|
||||
camera_config.onvif.autotracking.zooming
|
||||
== ZoomingModeEnum.relative
|
||||
@@ -755,17 +753,28 @@ class PtzAutoTracker(threading.Thread):
|
||||
|
||||
await self._wait_until_stopped(camera, metrics)
|
||||
|
||||
# _zoom_absolute resets the metrics timestamps
|
||||
pan_tilt_times = (
|
||||
metrics.start_time.value,
|
||||
metrics.stop_time.value,
|
||||
)
|
||||
|
||||
if zoom > 0 and metrics.zoom_level.value != zoom:
|
||||
await self.onvif._zoom_absolute(camera, zoom, 1)
|
||||
|
||||
await self._wait_until_stopped(camera, metrics)
|
||||
|
||||
start_time, stop_time = pan_tilt_times or (
|
||||
metrics.start_time.value,
|
||||
metrics.stop_time.value,
|
||||
)
|
||||
|
||||
if camera_config.onvif.autotracking.movement_weights:
|
||||
logger.debug(
|
||||
f"{camera}: Predicted movement time: {self._predict_movement_time(camera, pan, tilt)}"
|
||||
)
|
||||
logger.debug(
|
||||
f"{camera}: Actual movement time: {metrics.stop_time.value - metrics.start_time.value}"
|
||||
f"{camera}: Actual movement time: {stop_time - start_time}"
|
||||
)
|
||||
|
||||
# save metrics for better estimate calculations
|
||||
@@ -781,8 +790,8 @@ class PtzAutoTracker(threading.Thread):
|
||||
{
|
||||
"pan": pan,
|
||||
"tilt": tilt,
|
||||
"start_timestamp": metrics.start_time.value,
|
||||
"end_timestamp": metrics.stop_time.value,
|
||||
"start_timestamp": start_time,
|
||||
"end_timestamp": stop_time,
|
||||
}
|
||||
)
|
||||
|
||||
@@ -845,7 +854,6 @@ class PtzAutoTracker(threading.Thread):
|
||||
# Thresholds
|
||||
x_mags_thresh = camera_width / camera_fps / 2
|
||||
y_mags_thresh = camera_height / camera_fps / 2
|
||||
dir_thresh = 0.93
|
||||
delta_thresh = 20
|
||||
var_thresh = 10
|
||||
|
||||
@@ -863,24 +871,12 @@ class PtzAutoTracker(threading.Thread):
|
||||
stdev_list = np.std(velocities, axis=0)
|
||||
high_variances = np.any(stdev_list > var_thresh)
|
||||
|
||||
# Check direction difference
|
||||
# the corners of an object moving toward or away from the camera move
|
||||
# in different directions, so the delta bounds how far they may differ
|
||||
velocities = np.round(velocities)
|
||||
invalid_dirs = False
|
||||
if np.all(np.linalg.norm(velocities, axis=1)):
|
||||
cosine_sim = np.dot(velocities[0], velocities[1]) / (
|
||||
np.linalg.norm(velocities[0]) * np.linalg.norm(velocities[1])
|
||||
)
|
||||
dir_thresh = 0.6 if np.all(delta < delta_thresh / 2) else dir_thresh
|
||||
invalid_dirs = cosine_sim < dir_thresh
|
||||
|
||||
# Combine
|
||||
invalid = (
|
||||
invalid_x_mags
|
||||
or invalid_y_mags
|
||||
or invalid_dirs
|
||||
or invalid_delta
|
||||
or high_variances
|
||||
)
|
||||
invalid = invalid_x_mags or invalid_y_mags or invalid_delta or high_variances
|
||||
|
||||
if invalid:
|
||||
logger.debug(
|
||||
@@ -891,7 +887,6 @@ class PtzAutoTracker(threading.Thread):
|
||||
for var_name, is_invalid in [
|
||||
("invalid_x_mags", invalid_x_mags),
|
||||
("invalid_y_mags", invalid_y_mags),
|
||||
("invalid_dirs", invalid_dirs),
|
||||
("invalid_delta", invalid_delta),
|
||||
("high_variances", high_variances),
|
||||
]
|
||||
|
||||
@@ -30,6 +30,7 @@ from frigate.const import (
|
||||
UPSERT_REVIEW_SEGMENT,
|
||||
)
|
||||
from frigate.models import ReviewSegment
|
||||
from frigate.review.severity import get_review_severity
|
||||
from frigate.review.types import SeverityEnum
|
||||
from frigate.track.object_processing import ManualEventState
|
||||
from frigate.util.image import SharedMemoryFrameManager, calculate_16_9_crop
|
||||
@@ -217,57 +218,21 @@ class ActiveObjects:
|
||||
}
|
||||
|
||||
for o in all_objects:
|
||||
if (
|
||||
o["motionless_count"] >= camera_config.detect.stationary.threshold
|
||||
and not o["pending_loitering"]
|
||||
):
|
||||
# no stationary objects unless loitering
|
||||
continue
|
||||
|
||||
if o["position_changes"] == 0:
|
||||
# object must have moved at least once
|
||||
continue
|
||||
|
||||
if o["frame_time"] != frame_time:
|
||||
# object must be detected in this frame
|
||||
continue
|
||||
|
||||
if o["false_positive"]:
|
||||
# object must not be a false positive
|
||||
continue
|
||||
|
||||
if (
|
||||
o["label"] in camera_config.review.alerts.labels
|
||||
and (
|
||||
not camera_config.review.alerts.required_zones
|
||||
or (
|
||||
len(o["current_zones"]) > 0
|
||||
and set(o["current_zones"])
|
||||
& set(camera_config.review.alerts.required_zones)
|
||||
severity = get_review_severity(
|
||||
camera_config,
|
||||
label=o["label"],
|
||||
current_zones=o["current_zones"],
|
||||
false_positive=o["false_positive"],
|
||||
detected=o["frame_time"] == frame_time,
|
||||
position_changes=o["position_changes"],
|
||||
motionless_count=o["motionless_count"],
|
||||
pending_loitering=o["pending_loitering"],
|
||||
)
|
||||
)
|
||||
and camera_config.review.alerts.enabled
|
||||
):
|
||||
|
||||
if severity == SeverityEnum.alert:
|
||||
self.categorized_objects["alerts"].append(o)
|
||||
continue
|
||||
|
||||
if (
|
||||
(
|
||||
camera_config.review.detections.labels is None
|
||||
or o["label"] in camera_config.review.detections.labels
|
||||
)
|
||||
and (
|
||||
not camera_config.review.detections.required_zones
|
||||
or (
|
||||
len(o["current_zones"]) > 0
|
||||
and set(o["current_zones"])
|
||||
& set(camera_config.review.detections.required_zones)
|
||||
)
|
||||
)
|
||||
and camera_config.review.detections.enabled
|
||||
):
|
||||
elif severity == SeverityEnum.detection:
|
||||
self.categorized_objects["detections"].append(o)
|
||||
continue
|
||||
|
||||
def has_active_objects(self) -> bool:
|
||||
return (
|
||||
@@ -1007,6 +972,13 @@ class ReviewSegmentMaintainer(threading.Thread):
|
||||
)
|
||||
)
|
||||
elif topic == DetectionTypeEnum.api:
|
||||
# the event's segment has already ended
|
||||
if manual_info["state"] == ManualEventState.end:
|
||||
self.indefinite_events[camera].pop(
|
||||
manual_info["event_id"], None
|
||||
)
|
||||
continue
|
||||
|
||||
severity = self.get_manual_event_severity(
|
||||
camera, manual_info["label"]
|
||||
)
|
||||
|
||||
@@ -0,0 +1,80 @@
|
||||
"""Rules for which review severity a tracked object qualifies for."""
|
||||
|
||||
from typing import cast
|
||||
|
||||
from frigate.config import CameraConfig
|
||||
from frigate.review.types import SeverityEnum
|
||||
|
||||
|
||||
def get_review_severity(
|
||||
camera_config: CameraConfig,
|
||||
*,
|
||||
label: str,
|
||||
current_zones: list[str],
|
||||
false_positive: bool,
|
||||
detected: bool,
|
||||
position_changes: int,
|
||||
motionless_count: int,
|
||||
pending_loitering: bool,
|
||||
) -> SeverityEnum | None:
|
||||
"""Get the review severity a tracked object qualifies for on the current frame.
|
||||
|
||||
Review segments and a tracked object's max_severity both use this, so an
|
||||
object is only reported as an alert or detection when it could actually
|
||||
create or extend a review segment of that severity.
|
||||
|
||||
Args:
|
||||
camera_config: Config for the camera the object is on
|
||||
label: The object's label
|
||||
current_zones: Zones the object is in on the current frame
|
||||
false_positive: Whether the object is still considered a false positive
|
||||
detected: Whether the object was detected on the current frame
|
||||
position_changes: Number of times the object has changed position
|
||||
motionless_count: Number of frames the object has not moved
|
||||
pending_loitering: Whether the object is in a loitering zone but has
|
||||
not met the loitering time yet
|
||||
|
||||
Returns:
|
||||
The severity the object qualifies for, or None if it does not qualify
|
||||
"""
|
||||
# always populated from detect fps when the config is loaded
|
||||
stationary_threshold = cast(int, camera_config.detect.stationary.threshold)
|
||||
|
||||
# stationary objects don't count unless they are loitering
|
||||
if motionless_count >= stationary_threshold and not pending_loitering:
|
||||
return None
|
||||
|
||||
# object must have moved at least once
|
||||
if position_changes == 0:
|
||||
return None
|
||||
|
||||
if not detected or false_positive:
|
||||
return None
|
||||
|
||||
review_config = camera_config.review
|
||||
zones = set(current_zones)
|
||||
|
||||
if (
|
||||
review_config.alerts.enabled
|
||||
and label in review_config.alerts.labels
|
||||
and (
|
||||
not review_config.alerts.required_zones
|
||||
or zones & set(review_config.alerts.required_zones)
|
||||
)
|
||||
):
|
||||
return SeverityEnum.alert
|
||||
|
||||
if (
|
||||
review_config.detections.enabled
|
||||
and (
|
||||
review_config.detections.labels is None
|
||||
or label in review_config.detections.labels
|
||||
)
|
||||
and (
|
||||
not review_config.detections.required_zones
|
||||
or zones & set(review_config.detections.required_zones)
|
||||
)
|
||||
):
|
||||
return SeverityEnum.detection
|
||||
|
||||
return None
|
||||
@@ -1,7 +1,10 @@
|
||||
import datetime
|
||||
import logging
|
||||
import os
|
||||
import struct
|
||||
import tempfile
|
||||
import unittest
|
||||
import zoneinfo
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi import Request
|
||||
@@ -20,6 +23,13 @@ from frigate.models import Event, Recordings, ReviewSegment
|
||||
from frigate.review.types import SeverityEnum
|
||||
from frigate.test.const import TEST_DB, TEST_DB_CLEANUPS, TEST_DB_PRAGMAS
|
||||
|
||||
# Minimal TZif file for a zone fixed at UTC+0 named "UTC".
|
||||
UTC_TZIF = (
|
||||
struct.pack(">4s16x6l", b"TZif", 0, 0, 0, 0, 1, 4)
|
||||
+ struct.pack(">lBB", 0, 0, 0)
|
||||
+ b"UTC\0"
|
||||
)
|
||||
|
||||
|
||||
class AuthTestClient(TestClient):
|
||||
"""TestClient that automatically adds auth headers to all requests."""
|
||||
@@ -36,6 +46,23 @@ class AuthTestClient(TestClient):
|
||||
|
||||
|
||||
class BaseTestHttp(unittest.TestCase):
|
||||
@classmethod
|
||||
def setUpClass(cls):
|
||||
super().setUpClass()
|
||||
|
||||
# Docker mounts of the host's /etc/localtime can overwrite the system
|
||||
# zoneinfo/Etc/UTC file with a local zone. Shadow "UTC" with a known
|
||||
# good file so the API's ZoneInfo("UTC") is real UTC.
|
||||
tz_dir = tempfile.TemporaryDirectory()
|
||||
with open(os.path.join(tz_dir.name, "UTC"), "wb") as f:
|
||||
f.write(UTC_TZIF)
|
||||
|
||||
zoneinfo.reset_tzpath(to=[tz_dir.name, *zoneinfo.TZPATH])
|
||||
zoneinfo.ZoneInfo.clear_cache()
|
||||
cls.addClassCleanup(tz_dir.cleanup)
|
||||
cls.addClassCleanup(zoneinfo.ZoneInfo.clear_cache)
|
||||
cls.addClassCleanup(zoneinfo.reset_tzpath)
|
||||
|
||||
def setUp(self, models):
|
||||
# setup clean database for each test run
|
||||
migrate_db = SqliteDatabase(TEST_DB, pragmas=TEST_DB_PRAGMAS)
|
||||
|
||||
@@ -4,6 +4,7 @@ from unittest.mock import Mock, patch
|
||||
|
||||
import frigate.genai
|
||||
from frigate.config import GenAIProviderEnum
|
||||
from frigate.config.config import RuntimeFilterConfig
|
||||
from frigate.const import MODEL_CACHE_DIR, REDACTED_CREDENTIAL_SENTINEL
|
||||
from frigate.genai import GenAIClient
|
||||
from frigate.models import Event, Recordings, ReviewSegment
|
||||
@@ -98,6 +99,72 @@ class TestHttpApp(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
assert app.frigate_config.cameras["front_door"].objects.track == ["person"]
|
||||
|
||||
def test_config_set_in_memory_adds_filters_for_new_tracked_labels(self):
|
||||
self.minimal_config["cameras"]["front_door"]["objects"] = {
|
||||
"track": ["person"],
|
||||
}
|
||||
app = super().create_app()
|
||||
app.config_publisher = Mock()
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
response = client.put(
|
||||
"/config/set",
|
||||
json={
|
||||
"requires_restart": 0,
|
||||
"skip_save": True,
|
||||
"update_topic": "config/cameras/front_door/objects",
|
||||
"config_data": {
|
||||
"cameras": {
|
||||
"front_door": {"objects": {"track": ["person", "cat"]}}
|
||||
}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
filters = app.frigate_config.cameras["front_door"].objects.filters
|
||||
assert isinstance(filters["cat"], RuntimeFilterConfig)
|
||||
|
||||
@patch("frigate.detectors.detector_config.load_labels")
|
||||
def test_config_set_in_memory_rebinds_replay_model_on_scene_change(
|
||||
self, mock_labels
|
||||
):
|
||||
mock_labels.return_value = {}
|
||||
replay = "_replay_front_door"
|
||||
self.minimal_config["models"] = [
|
||||
{"devices": ["cpu"]},
|
||||
{"scene": "thermal", "devices": ["openvino:CPU"], "width": 300},
|
||||
]
|
||||
self.minimal_config["cameras"][replay] = self.minimal_config["cameras"].pop(
|
||||
"front_door"
|
||||
)
|
||||
app = super().create_app()
|
||||
app.config_publisher = Mock()
|
||||
assert app.frigate_config.model_for_camera(replay).scene == "default"
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
response = client.put(
|
||||
"/config/set",
|
||||
json={
|
||||
"requires_restart": 0,
|
||||
"skip_save": True,
|
||||
"update_topic": f"config/cameras/{replay}/detect",
|
||||
"config_data": {
|
||||
"cameras": {replay: {"detect": {"scene": "thermal"}}}
|
||||
},
|
||||
},
|
||||
)
|
||||
|
||||
assert response.status_code == 200
|
||||
assert app.frigate_config.cameras[replay].detect.scene == "thermal"
|
||||
assert app.frigate_config.model_for_camera(replay).scene == "thermal"
|
||||
topics = [
|
||||
call.args[0].update_type.name
|
||||
for call in app.config_publisher.publish_update.call_args_list
|
||||
]
|
||||
assert topics[0] == "detect"
|
||||
assert topics[-1] == "refresh"
|
||||
|
||||
####################################################################################################################
|
||||
################################### Credential redaction sentinel ################################################
|
||||
####################################################################################################################
|
||||
|
||||
@@ -5,6 +5,7 @@ import tempfile
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, Mock, patch
|
||||
|
||||
import requests
|
||||
import ruamel.yaml
|
||||
from fastapi import Request
|
||||
|
||||
@@ -234,6 +235,72 @@ class TestAuthInternalPort(BaseTestHttp):
|
||||
finally:
|
||||
os.unlink(config_path)
|
||||
|
||||
@patch(
|
||||
"frigate.api.auth.requests.get",
|
||||
side_effect=requests.ConnectionError("go2rtc unavailable"),
|
||||
)
|
||||
def test_internal_port_rejects_unknown_go2rtc_src(self, _mock_get):
|
||||
app = self._create_app()
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
for url in (
|
||||
"/live/mse/api/ws?src=exec:id",
|
||||
"/live/webrtc/api/ws?src=ffmpeg:x%23raw=-f",
|
||||
"/api/go2rtc/webrtc?src=front_door&src=unknown",
|
||||
):
|
||||
resp = client.get(
|
||||
"/auth",
|
||||
headers={"x-server-port": "5000", "x-original-url": url},
|
||||
)
|
||||
self.assertEqual(resp.status_code, 403, url)
|
||||
|
||||
def test_internal_port_allows_existing_go2rtc_stream(self):
|
||||
app = self._create_app()
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
resp = client.get(
|
||||
"/auth",
|
||||
headers={
|
||||
"x-server-port": "5000",
|
||||
"x-original-url": "/live/mse/api/ws?src=front_door",
|
||||
},
|
||||
)
|
||||
|
||||
self.assertEqual(resp.status_code, 202)
|
||||
self.assertEqual(resp.headers["remote-role"], "admin")
|
||||
|
||||
def test_internal_port_skips_go2rtc_check_for_other_paths(self):
|
||||
app = self._create_app()
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
for url in ("/api/stats", "/api/go2rtc/streams?src=unknown"):
|
||||
resp = client.get(
|
||||
"/auth",
|
||||
headers={"x-server-port": "5000", "x-original-url": url},
|
||||
)
|
||||
self.assertEqual(resp.status_code, 202, url)
|
||||
|
||||
@patch(
|
||||
"frigate.api.auth.requests.get",
|
||||
side_effect=requests.ConnectionError("go2rtc unavailable"),
|
||||
)
|
||||
def test_live_stream_value_is_not_trusted_as_a_go2rtc_stream(self, _mock_get):
|
||||
src = "ffmpeg:x#raw=-f"
|
||||
self.minimal_config["cameras"]["front_door"]["live"] = {
|
||||
"streams": {"Main": src}
|
||||
}
|
||||
app = self._create_app()
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
resp = client.get(
|
||||
"/auth",
|
||||
headers={
|
||||
"x-server-port": "5000",
|
||||
"x-original-url": "/live/mse/api/ws?src=ffmpeg:x%23raw=-f",
|
||||
},
|
||||
)
|
||||
self.assertEqual(resp.status_code, 403)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
@@ -151,6 +151,19 @@ class TestConfigGo2rtcStreamRestrictions(BaseTestHttp):
|
||||
assert resp.status_code == 200, resp.text
|
||||
assert _EXISTING_SRC in self._read_config()
|
||||
|
||||
def test_set_rejects_stream_name_with_ffmpeg_params(self):
|
||||
before = self._read_config()
|
||||
resp = self._set_streams(
|
||||
{"x#raw=-f#raw=mpegts#raw=/tmp/x": "rtsp://10.0.0.2:554/video"}
|
||||
)
|
||||
assert resp.status_code == 400
|
||||
assert "Invalid go2rtc stream name" in resp.json()["message"]
|
||||
assert self._read_config() == before
|
||||
|
||||
def test_set_allows_plain_stream_names(self):
|
||||
resp = self._set_streams({"back-yard.main_2": "rtsp://10.0.0.2:554/video"})
|
||||
assert resp.status_code == 200, resp.text
|
||||
|
||||
def test_set_allows_injected_source_when_override_set(self):
|
||||
with patch("frigate.util.services._GO2RTC_ARBITRARY_EXEC_ENV", "true"):
|
||||
resp = self._set_streams({"new_stream": [_INJECTED_SRC]})
|
||||
|
||||
@@ -485,6 +485,40 @@ class TestHttpApp(BaseTestHttp):
|
||||
assert sub_labels
|
||||
assert sub_labels == [sub_label]
|
||||
|
||||
def test_get_event_list_filter_sub_labels(self):
|
||||
sub_labels = {
|
||||
"1.cyrillic": "Кузнецова Ира",
|
||||
"2.joined": "Ира, Bob",
|
||||
"3.ascii": "Alice",
|
||||
"4.none": None,
|
||||
}
|
||||
mock_embeddings = Mock()
|
||||
mock_embeddings.search_thumbnail.return_value = [(id, 0.1) for id in sub_labels]
|
||||
|
||||
self.app.frigate_config.semantic_search.enabled = True
|
||||
self.app.embeddings = mock_embeddings
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
for id, sub_label in sub_labels.items():
|
||||
super().insert_mock_event(id)
|
||||
Event.update(sub_label=sub_label).where(Event.id == id).execute()
|
||||
|
||||
search_params = {"search_type": "similarity", "event_id": "1.cyrillic"}
|
||||
|
||||
for path, params in (("/events", {}), ("/events/search", search_params)):
|
||||
|
||||
def ids(query: str) -> set[str]:
|
||||
events = client.get(
|
||||
path, params={**params, "sub_labels": query}
|
||||
).json()
|
||||
return {event["id"] for event in events}
|
||||
|
||||
assert ids("Кузнецова Ира") == {"1.cyrillic"}
|
||||
assert ids("Ира") == {"2.joined"}
|
||||
assert ids("bob") == {"2.joined"}
|
||||
assert ids("ALICE") == {"3.ascii"}
|
||||
assert ids("None") == {"4.none"}
|
||||
|
||||
####################################################################################################################
|
||||
################################### GET /metrics Endpoint #########################################################
|
||||
####################################################################################################################
|
||||
|
||||
@@ -1,11 +1,13 @@
|
||||
"""Tests for credential scrubbing in the ffprobe API."""
|
||||
"""Tests for the ffprobe API."""
|
||||
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import patch
|
||||
|
||||
from fastapi.testclient import TestClient
|
||||
|
||||
from frigate.test.http_api.base_http_test import AuthTestClient, BaseTestHttp
|
||||
from frigate.util.services import ffprobe_stream
|
||||
|
||||
|
||||
class TestHttpFfprobe(BaseTestHttp):
|
||||
@@ -35,3 +37,17 @@ class TestHttpFfprobe(BaseTestHttp):
|
||||
self.assertEqual(len(lines), 2)
|
||||
self.assertNotIn("hunter2", " ".join(lines))
|
||||
self.assertEqual(lines[1], "rtsp://*:*@10.0.0.1:554/video: Connection refused")
|
||||
|
||||
|
||||
class TestFfprobeStream(unittest.TestCase):
|
||||
def test_requests_codec_type(self):
|
||||
ffmpeg = SimpleNamespace(ffprobe_path="ffprobe")
|
||||
done = SimpleNamespace(returncode=0, stdout=b"{}", stderr=b"")
|
||||
|
||||
for detailed in (False, True):
|
||||
with patch("frigate.util.services.sp.run", return_value=done) as run:
|
||||
ffprobe_stream(ffmpeg, "rtsp://10.0.0.1/live", detailed=detailed)
|
||||
|
||||
cmd = run.call_args.args[0]
|
||||
entries = cmd[cmd.index("-show_entries") + 1]
|
||||
self.assertIn("codec_type", entries.removeprefix("stream=").split(","))
|
||||
|
||||
@@ -4,9 +4,11 @@ import threading
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from dataclasses import dataclass
|
||||
from datetime import UTC, datetime, timedelta
|
||||
from unittest.mock import patch
|
||||
from unittest.mock import MagicMock, patch
|
||||
from zoneinfo import ZoneInfo
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
from fastapi import Request
|
||||
|
||||
from frigate.api.auth import get_allowed_cameras_for_filter, get_current_user
|
||||
@@ -588,6 +590,47 @@ class TestHttpMedia(BaseTestHttp):
|
||||
response = client.get("/recordings/unavailable", params={"scale": 0})
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_recordings_unavailable_large_span(self):
|
||||
"""A wide span at a fine scale returns its gaps without stepping per bucket."""
|
||||
with AuthTestClient(self.app) as client:
|
||||
self._insert_recording("only", 1000, 1100)
|
||||
|
||||
response = client.get(
|
||||
"/recordings/unavailable",
|
||||
params={"after": 1, "before": 10**12, "scale": 1},
|
||||
)
|
||||
assert response.status_code == 200
|
||||
assert response.json() == [
|
||||
{"start_time": 1, "end_time": 1000},
|
||||
{"start_time": 1100, "end_time": 10**12},
|
||||
]
|
||||
|
||||
for param in ("before", "after"):
|
||||
for bound in ("inf", "-inf", "nan"):
|
||||
response = client.get(
|
||||
"/recordings/unavailable", params={param: bound}
|
||||
)
|
||||
assert response.status_code == 422
|
||||
|
||||
def test_latest_frame_height_capped_at_source(self):
|
||||
"""A requested height above the frame height returns the frame unscaled."""
|
||||
frame = np.zeros((90, 160, 3), np.uint8)
|
||||
processor = MagicMock()
|
||||
processor.get_current_frame.return_value = frame
|
||||
processor.get_current_frame_time.return_value = datetime.now().timestamp()
|
||||
self.app.detected_frames_processor = processor
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
for height, expected in ((45, (45, 80)), (5000, (90, 160))):
|
||||
response = client.get(
|
||||
"/front_door/latest.jpg", params={"height": height}
|
||||
)
|
||||
assert response.status_code == 200
|
||||
image = cv2.imdecode(
|
||||
np.frombuffer(response.content, np.uint8), cv2.IMREAD_COLOR
|
||||
)
|
||||
assert image.shape[:2] == expected
|
||||
|
||||
def test_recordings_summary_day_attribution_by_start_time(self):
|
||||
"""
|
||||
A recording spanning midnight marks only its start day.
|
||||
|
||||
@@ -0,0 +1,51 @@
|
||||
"""Tests for the Frigate+ API endpoints."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
from frigate.models import Event
|
||||
from frigate.plus import PlusKeyStatus
|
||||
from frigate.test.http_api.base_http_test import AuthTestClient, BaseTestHttp
|
||||
|
||||
|
||||
class TestHttpPlusValidate(BaseTestHttp):
|
||||
def setUp(self):
|
||||
super().setUp([Event])
|
||||
|
||||
def _validate(self, status: PlusKeyStatus) -> dict:
|
||||
app = self.create_app()
|
||||
|
||||
with patch.object(
|
||||
app.frigate_config.plus_api, "validate_key", return_value=status
|
||||
):
|
||||
with AuthTestClient(app) as client:
|
||||
response = client.post("/plus/validate")
|
||||
|
||||
self.assertEqual(response.status_code, 200)
|
||||
return response.json()
|
||||
|
||||
def test_a_valid_key(self):
|
||||
self.assertEqual(
|
||||
self._validate(PlusKeyStatus.valid), {"success": True, "status": "valid"}
|
||||
)
|
||||
|
||||
def test_an_invalid_key(self):
|
||||
self.assertEqual(
|
||||
self._validate(PlusKeyStatus.invalid),
|
||||
{"success": False, "status": "invalid"},
|
||||
)
|
||||
|
||||
def test_viewers_cannot_validate(self):
|
||||
app = self.create_app()
|
||||
|
||||
with AuthTestClient(app) as client:
|
||||
response = client.post(
|
||||
"/plus/validate",
|
||||
headers={"remote-user": "viewer", "remote-role": "viewer"},
|
||||
)
|
||||
|
||||
self.assertEqual(response.status_code, 403)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
@@ -1,4 +1,4 @@
|
||||
from datetime import datetime, timedelta
|
||||
from datetime import UTC, datetime, timedelta
|
||||
|
||||
from fastapi import Request
|
||||
from peewee import DoesNotExist
|
||||
@@ -9,6 +9,11 @@ from frigate.review.types import SeverityEnum
|
||||
from frigate.test.http_api.base_http_test import AuthTestClient, BaseTestHttp
|
||||
|
||||
|
||||
def utc_day(dt: datetime) -> str:
|
||||
"""Return the UTC calendar day the summary endpoint buckets dt into."""
|
||||
return dt.astimezone(UTC).strftime("%Y-%m-%d")
|
||||
|
||||
|
||||
class TestHttpReview(BaseTestHttp):
|
||||
def setUp(self):
|
||||
super().setUp([Event, Recordings, ReviewSegment, UserReviewStatus])
|
||||
@@ -89,6 +94,37 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response_json[0]["id"] == id
|
||||
assert response_json[0]["has_been_reviewed"] == False
|
||||
|
||||
def test_get_review_before_only_has_no_lower_bound(self):
|
||||
now = datetime.now().timestamp()
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
id = "123456.random"
|
||||
super().insert_mock_review_segment(id, now - 72 * 3600, now - 71 * 3600)
|
||||
response = client.get("/review", params={"before": now - 48 * 3600})
|
||||
assert response.status_code == 200
|
||||
assert [r["id"] for r in response.json()] == [id]
|
||||
|
||||
def test_get_review_after_zero_is_not_defaulted(self):
|
||||
now = datetime.now().timestamp()
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
id = "123456.random"
|
||||
super().insert_mock_review_segment(id, now - 72 * 3600, now - 71 * 3600)
|
||||
response = client.get("/review", params={"after": 0})
|
||||
assert response.status_code == 200
|
||||
assert [r["id"] for r in response.json()] == [id]
|
||||
|
||||
def test_get_review_no_bounds_defaults_to_last_24_hours(self):
|
||||
now = datetime.now().timestamp()
|
||||
|
||||
with AuthTestClient(self.app) as client:
|
||||
super().insert_mock_review_segment(
|
||||
"123456.random", now - 72 * 3600, now - 71 * 3600
|
||||
)
|
||||
response = client.get("/review", params={"limit": 10})
|
||||
assert response.status_code == 200
|
||||
assert response.json() == []
|
||||
|
||||
def test_get_review_with_time_filter_no_matches(self):
|
||||
"""Test that review items outside the range are not returned."""
|
||||
now = datetime.now().timestamp()
|
||||
@@ -331,7 +367,7 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response_json["last24Hours"]["total_alert"] == 1
|
||||
assert response_json["last24Hours"]["total_detection"] == 0
|
||||
|
||||
today_formatted = datetime.today().strftime("%Y-%m-%d")
|
||||
today_formatted = utc_day(datetime.now())
|
||||
assert response_json[today_formatted]["total_alert"] == 1
|
||||
assert response_json[today_formatted]["total_detection"] == 0
|
||||
|
||||
@@ -348,7 +384,7 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
# e.g. '2024-11-24'
|
||||
today_formatted = datetime.today().strftime("%Y-%m-%d")
|
||||
today_formatted = utc_day(datetime.now())
|
||||
expected_response = {
|
||||
"last24Hours": {
|
||||
"reviewed_alert": 0,
|
||||
@@ -373,7 +409,7 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
# e.g. '2024-11-24'
|
||||
today_formatted = datetime.today().strftime("%Y-%m-%d")
|
||||
today_formatted = utc_day(datetime.now())
|
||||
expected_response = {
|
||||
"last24Hours": {
|
||||
"reviewed_alert": 0,
|
||||
@@ -408,9 +444,9 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
# e.g. '2024-11-24'
|
||||
today_formatted = now.strftime("%Y-%m-%d")
|
||||
today_formatted = utc_day(now)
|
||||
# e.g. '2024-11-19'
|
||||
five_days_ago_formatted = five_days_ago.strftime("%Y-%m-%d")
|
||||
five_days_ago_formatted = utc_day(five_days_ago)
|
||||
expected_response = {
|
||||
"last24Hours": {
|
||||
"reviewed_alert": 0,
|
||||
@@ -460,9 +496,9 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
# e.g. '2024-11-24'
|
||||
today_formatted = now.strftime("%Y-%m-%d")
|
||||
today_formatted = utc_day(now)
|
||||
# e.g. '2024-11-19'
|
||||
five_days_ago_formatted = five_days_ago.strftime("%Y-%m-%d")
|
||||
five_days_ago_formatted = utc_day(five_days_ago)
|
||||
expected_response = {
|
||||
"last24Hours": {
|
||||
"reviewed_alert": 0,
|
||||
@@ -518,7 +554,7 @@ class TestHttpReview(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
response_json = response.json()
|
||||
# e.g. '2024-11-19'
|
||||
five_days_ago_formatted = five_days_ago.strftime("%Y-%m-%d")
|
||||
five_days_ago_formatted = utc_day(five_days_ago)
|
||||
expected_response = {
|
||||
"last24Hours": {
|
||||
"reviewed_alert": None,
|
||||
|
||||
@@ -100,6 +100,17 @@ class TestFeaturesCollector(unittest.TestCase):
|
||||
self.assertEqual(section.users, {"admin": 1, "viewer": 1, "custom": 1})
|
||||
self.assertEqual((section.camera_groups, section.profiles), (1, 0))
|
||||
self.assertFalse(section.plus_api_key)
|
||||
self.assertFalse(section.notifications)
|
||||
|
||||
def test_camera_notifications_count_as_on(self):
|
||||
config = {
|
||||
**CONFIG,
|
||||
"cameras": {"front": {**FRONT_CAMERA, "notifications": {"enabled": True}}},
|
||||
}
|
||||
|
||||
section = features.collect(make_context(make_config(config), {}))
|
||||
|
||||
self.assertTrue(section.notifications)
|
||||
|
||||
|
||||
class TestFeatureMappings(unittest.TestCase):
|
||||
|
||||
@@ -12,6 +12,7 @@ from frigate.analytics.collectors.common import closed, histogram, rate
|
||||
from frigate.analytics.schema import (
|
||||
Arch,
|
||||
DecodeFamily,
|
||||
FfmpegSource,
|
||||
GpuVendor,
|
||||
HardwareKey,
|
||||
ImageVariant,
|
||||
@@ -56,6 +57,36 @@ class TestInstallCollector(unittest.TestCase):
|
||||
self.assertEqual(section.arch, Arch.aarch64)
|
||||
self.assertEqual(section.kernel, "6.8")
|
||||
self.assertFalse(section.run_as_root)
|
||||
self.assertEqual(section.ffmpeg, FfmpegSource.default)
|
||||
|
||||
def test_ffmpeg_source_follows_path_resolution(self):
|
||||
with (
|
||||
patch.object(install, "DEFAULT_FFMPEG_VERSION", "8.0"),
|
||||
patch.object(install, "INCLUDED_FFMPEG_VERSIONS", ["8.0", "7.0"]),
|
||||
):
|
||||
self.assertEqual(install.ffmpeg_source("default"), FfmpegSource.default)
|
||||
self.assertEqual(install.ffmpeg_source("8.0"), FfmpegSource.default)
|
||||
self.assertEqual(install.ffmpeg_source("4.4"), FfmpegSource.default)
|
||||
self.assertEqual(install.ffmpeg_source("7.0"), FfmpegSource.bundled)
|
||||
self.assertEqual(
|
||||
install.ffmpeg_source("/config/custom-ffmpeg"), FfmpegSource.custom
|
||||
)
|
||||
self.assertEqual(
|
||||
install.ffmpeg_source("/config/a b; rm"), FfmpegSource.default
|
||||
)
|
||||
|
||||
def test_custom_go2rtc_needs_an_executable_binary(self):
|
||||
with tempfile.TemporaryDirectory() as config_dir:
|
||||
binary = os.path.join(config_dir, "go2rtc")
|
||||
|
||||
with patch.object(install, "CONFIG_DIR", config_dir):
|
||||
self.assertFalse(install.collect(make_context()).custom_go2rtc)
|
||||
|
||||
open(binary, "w").close()
|
||||
self.assertFalse(install.collect(make_context()).custom_go2rtc)
|
||||
|
||||
os.chmod(binary, 0o755)
|
||||
self.assertTrue(install.collect(make_context()).custom_go2rtc)
|
||||
|
||||
def test_image_variant_is_dev_when_unset_and_other_when_unknown(self):
|
||||
self.assertEqual(install.image_variant(None), ImageVariant.dev)
|
||||
|
||||
@@ -25,6 +25,8 @@ INSTALL = InstallSection(
|
||||
arch="x86_64",
|
||||
kernel="6.8",
|
||||
run_as_root=False,
|
||||
custom_go2rtc=False,
|
||||
ffmpeg="default",
|
||||
)
|
||||
|
||||
|
||||
|
||||
@@ -1,10 +1,12 @@
|
||||
"""Regression tests for runtime camera add and delete handling."""
|
||||
|
||||
import asyncio
|
||||
import os
|
||||
import tempfile
|
||||
import threading
|
||||
import unittest
|
||||
from types import SimpleNamespace
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
# LicensePlatePostProcessor is imported via the maintainer rather than from
|
||||
# data_processing.post.license_plate, which circularly imports back through
|
||||
@@ -16,6 +18,7 @@ from frigate.embeddings.maintainer import (
|
||||
from frigate.ptz.autotrack import PtzAutoTracker
|
||||
from frigate.review.maintainer import ReviewSegmentMaintainer
|
||||
from frigate.track.object_processing import TrackedObjectProcessor
|
||||
from frigate.util import camera_cleanup
|
||||
|
||||
|
||||
def _make_processor() -> TrackedObjectProcessor:
|
||||
@@ -231,3 +234,33 @@ class TestCameraStateAccessors(unittest.TestCase):
|
||||
processor = _make_processor()
|
||||
|
||||
self.assertEqual(processor.get_current_frame_time("deleted_cam"), 0.0)
|
||||
|
||||
|
||||
class TestCameraFileCleanup(unittest.TestCase):
|
||||
def test_delete_keeps_media_of_camera_sharing_name_prefix(self):
|
||||
own = [
|
||||
"front-1700000000.123456-abc123.jpg",
|
||||
"front-1700000000.123456-abc123-clean.webp",
|
||||
"review/thumb-front-1700000000.5-abc123.webp",
|
||||
]
|
||||
other = [
|
||||
"front-door-1700000000.123456-def456.jpg",
|
||||
"front-door-1700000000.123456-def456-clean.webp",
|
||||
"review/thumb-front-door-1700000000.5-def456.webp",
|
||||
]
|
||||
|
||||
with tempfile.TemporaryDirectory() as clips:
|
||||
os.makedirs(os.path.join(clips, "review"))
|
||||
for name in own + other:
|
||||
open(os.path.join(clips, name), "w").close()
|
||||
|
||||
with patch.multiple(
|
||||
camera_cleanup, CLIPS_DIR=clips, RECORD_DIR=clips, THUMB_DIR=clips
|
||||
):
|
||||
camera_cleanup.cleanup_camera_files("front")
|
||||
|
||||
remaining = [
|
||||
n for n in own + other if os.path.exists(os.path.join(clips, n))
|
||||
]
|
||||
|
||||
self.assertEqual(remaining, other)
|
||||
|
||||
@@ -0,0 +1,198 @@
|
||||
"""Training and inference must give a classification model the same input.
|
||||
|
||||
The realtime processor saves the crop at its own size for the user to
|
||||
categorise, and resizes it to the model input for inference. Training later
|
||||
loads the saved crop from the dataset. If the two resize it differently, the
|
||||
model learns pixels it never sees live.
|
||||
"""
|
||||
|
||||
import math
|
||||
import os
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import cv2
|
||||
import numpy as np
|
||||
|
||||
# Mock TFLite before importing the classification processor
|
||||
_MOCK_MODULES = [
|
||||
"tflite_runtime",
|
||||
"tflite_runtime.interpreter",
|
||||
"ai_edge_litert",
|
||||
"ai_edge_litert.interpreter",
|
||||
]
|
||||
for mod in _MOCK_MODULES:
|
||||
if mod not in sys.modules:
|
||||
sys.modules[mod] = MagicMock()
|
||||
|
||||
import frigate.util.classification as classification # noqa: E402
|
||||
from frigate.data_processing.real_time.custom_classification import ( # noqa: E402
|
||||
CustomStateClassificationProcessor,
|
||||
)
|
||||
|
||||
CAMERA = "cam"
|
||||
MODEL_NAME = "parity"
|
||||
FRAME_WIDTH = 1280
|
||||
FRAME_HEIGHT = 720
|
||||
# Below, near and above the 224 px model input, so crops are both upscaled
|
||||
# and downscaled. 79 px is the crop size this was found on.
|
||||
CROP_SIZES = (64, 79, 224, 600)
|
||||
|
||||
|
||||
class _TrainingStopped(Exception):
|
||||
pass
|
||||
|
||||
|
||||
def _frame() -> np.ndarray:
|
||||
"""A fixed random I420 frame."""
|
||||
return np.random.default_rng(0).integers(
|
||||
0, 256, (FRAME_HEIGHT * 3 // 2, FRAME_WIDTH), dtype=np.uint8
|
||||
)
|
||||
|
||||
|
||||
def _square_crop(size: int, x: int = 100, y: int = 60) -> list[float]:
|
||||
"""Relative crop coordinates for a size x size px crop at (x, y).
|
||||
|
||||
The half pixel keeps the processor's int() truncation on the intended
|
||||
pixel.
|
||||
"""
|
||||
return [
|
||||
(x + 0.5) / FRAME_WIDTH,
|
||||
(y + 0.5) / FRAME_HEIGHT,
|
||||
(x + size + 0.5) / FRAME_WIDTH,
|
||||
(y + size + 0.5) / FRAME_HEIGHT,
|
||||
]
|
||||
|
||||
|
||||
def _inference_input_and_saved_crop(
|
||||
frame: np.ndarray, crop: list[float]
|
||||
) -> tuple[np.ndarray, np.ndarray]:
|
||||
"""Run the state processor on a frame.
|
||||
|
||||
Returns the image it classifies and the crop it saves for training.
|
||||
"""
|
||||
height = frame.shape[0] * 2 // 3
|
||||
width = frame.shape[1]
|
||||
|
||||
config = MagicMock()
|
||||
config.cameras[CAMERA].detect.width = width
|
||||
config.cameras[CAMERA].detect.height = height
|
||||
model_config = MagicMock()
|
||||
model_config.name = MODEL_NAME
|
||||
model_config.state_config.cameras = {CAMERA: MagicMock(crop=crop)}
|
||||
model_config.state_config.interval = 1
|
||||
|
||||
with tempfile.TemporaryDirectory() as model_cache:
|
||||
with patch(
|
||||
"frigate.data_processing.real_time.custom_classification.MODEL_CACHE_DIR",
|
||||
model_cache,
|
||||
):
|
||||
processor = CustomStateClassificationProcessor(
|
||||
config, model_config, MagicMock(), None
|
||||
)
|
||||
|
||||
try:
|
||||
tasks = []
|
||||
processor._enqueue_task = tasks.append
|
||||
processor.last_run = -math.inf
|
||||
processor.process_frame({"camera": CAMERA, "motion": []}, frame)
|
||||
finally:
|
||||
processor.shutdown()
|
||||
|
||||
assert len(tasks) == 1, "processor did not classify the frame"
|
||||
_, _, _, resized_frame, crop_bgr = tasks[0]
|
||||
return resized_frame, crop_bgr
|
||||
|
||||
|
||||
def _training_batch(dataset_crop_bgr: np.ndarray) -> np.ndarray:
|
||||
"""Run the training process up to the first batch it would train on."""
|
||||
with tempfile.TemporaryDirectory() as root:
|
||||
clips_dir = os.path.join(root, "clips")
|
||||
model_cache = os.path.join(root, "model_cache")
|
||||
|
||||
# Two classes are required. Both get the same image, so every image
|
||||
# in the batch must match the inference input regardless of shuffling.
|
||||
for class_name in ("a", "b"):
|
||||
class_dir = os.path.join(clips_dir, MODEL_NAME, "dataset", class_name)
|
||||
os.makedirs(class_dir)
|
||||
cv2.imwrite(os.path.join(class_dir, "crop.png"), dataset_crop_bgr)
|
||||
|
||||
import tensorflow as tf
|
||||
|
||||
captured = []
|
||||
|
||||
def fit(train_gen, *args, **kwargs):
|
||||
# read the batch now, while the training images still exist
|
||||
captured.append(train_gen[0][0])
|
||||
raise _TrainingStopped()
|
||||
|
||||
model = MagicMock()
|
||||
model.fit.side_effect = fit
|
||||
|
||||
process = classification.ClassificationTrainingProcess(MODEL_NAME)
|
||||
process.BASE_WEIGHT_URL = ""
|
||||
|
||||
with (
|
||||
patch.object(classification, "CLIPS_DIR", clips_dir),
|
||||
patch.object(classification, "MODEL_CACHE_DIR", model_cache),
|
||||
patch.object(tf.keras.applications, "MobileNetV2"),
|
||||
patch.object(tf.keras.models, "Sequential", return_value=model),
|
||||
):
|
||||
process._ClassificationTrainingProcess__train_classification_model()
|
||||
|
||||
assert captured, "training did not reach model.fit"
|
||||
return captured[0]
|
||||
|
||||
|
||||
class TestTrainingMatchesInference(unittest.TestCase):
|
||||
def test_training_input_matches_inference_input(self):
|
||||
frame = _frame()
|
||||
|
||||
for size in CROP_SIZES:
|
||||
with self.subTest(crop_size=size):
|
||||
inference_input, saved_crop = _inference_input_and_saved_crop(
|
||||
frame, _square_crop(size)
|
||||
)
|
||||
|
||||
# Saved training crops are webp, which cv2 writes losslessly
|
||||
# by default, and categorising converts them to png. Writing
|
||||
# png here gives the same dataset pixels.
|
||||
batch = _training_batch(saved_crop)
|
||||
|
||||
# training rescales by 1/255; the quantised model takes uint8
|
||||
# input
|
||||
training_input = np.rint(batch * 255.0).astype(np.uint8)
|
||||
|
||||
self.assertEqual(training_input.shape[1:], inference_input.shape)
|
||||
for image in training_input:
|
||||
np.testing.assert_array_equal(image, inference_input)
|
||||
|
||||
|
||||
class TestPrepareTrainingDataset(unittest.TestCase):
|
||||
def test_skips_files_that_are_not_images(self):
|
||||
with (
|
||||
tempfile.TemporaryDirectory() as dataset_dir,
|
||||
tempfile.TemporaryDirectory() as output_dir,
|
||||
):
|
||||
os.makedirs(os.path.join(dataset_dir, "open"))
|
||||
cv2.imwrite(
|
||||
os.path.join(dataset_dir, "open", "a.png"),
|
||||
np.zeros((79, 79, 3), dtype=np.uint8),
|
||||
)
|
||||
|
||||
with open(os.path.join(dataset_dir, "open", "broken.png"), "w") as f:
|
||||
f.write("not an image")
|
||||
|
||||
with open(os.path.join(dataset_dir, ".training_metadata.json"), "w") as f:
|
||||
f.write("{}")
|
||||
|
||||
classification.prepare_training_dataset(dataset_dir, output_dir)
|
||||
|
||||
self.assertEqual(os.listdir(output_dir), ["open"])
|
||||
self.assertEqual(os.listdir(os.path.join(output_dir, "open")), ["a.png"])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -1,5 +1,6 @@
|
||||
"""Tests for migrating detectors and model into the models list."""
|
||||
|
||||
import errno
|
||||
import logging
|
||||
import os
|
||||
import tempfile
|
||||
@@ -240,6 +241,42 @@ class TestMigrateConfigFile(unittest.TestCase):
|
||||
with open(self.config_file) as f:
|
||||
return YAML().load(f)
|
||||
|
||||
def test_a_failed_write_leaves_the_original_config(self):
|
||||
original = "mqtt:\n enabled: false\ncameras: {}\n"
|
||||
with open(self.config_file, "w") as f:
|
||||
f.write(original)
|
||||
|
||||
with (
|
||||
patch.object(YAML, "dump", side_effect=RuntimeError),
|
||||
self.assertRaises(RuntimeError),
|
||||
):
|
||||
migrate_frigate_config(self.config_file)
|
||||
|
||||
with open(self.config_file) as f:
|
||||
self.assertEqual(f.read(), original)
|
||||
|
||||
def test_a_file_bind_mount_is_written_in_place(self):
|
||||
with patch(
|
||||
"frigate.util.config.os.replace",
|
||||
side_effect=OSError(errno.EBUSY, "Device or resource busy"),
|
||||
):
|
||||
migrated = self._migrate("mqtt:\n enabled: false\ncameras: {}\n")
|
||||
|
||||
self.assertEqual(migrated["version"], CURRENT_CONFIG_VERSION)
|
||||
self.assertFalse(os.path.exists(f"{self.config_file}.tmp"))
|
||||
|
||||
def test_a_symlinked_config_migrates_its_target(self):
|
||||
target = os.path.join(self.temp_dir.name, "frigate.yml")
|
||||
with open(target, "w") as f:
|
||||
f.write("mqtt:\n enabled: false\ncameras: {}\n")
|
||||
os.symlink(target, self.config_file)
|
||||
|
||||
migrate_frigate_config(self.config_file)
|
||||
|
||||
self.assertTrue(os.path.islink(self.config_file))
|
||||
with open(target) as f:
|
||||
self.assertEqual(YAML().load(f)["version"], CURRENT_CONFIG_VERSION)
|
||||
|
||||
def test_migrates_a_config_already_stamped_with_the_current_version(self):
|
||||
# 0.19 is unreleased, so a dev config can be current and still use
|
||||
# the pre-models keys
|
||||
|
||||
@@ -18,6 +18,7 @@ from frigate.jobs.debug_replay import (
|
||||
from frigate.jobs.export import JobStatePublisher
|
||||
from frigate.jobs.manager import _completed_jobs, _current_jobs
|
||||
from frigate.types import JobStatusTypesEnum
|
||||
from frigate.util.recording_coverage import CoverageInterval
|
||||
|
||||
|
||||
def _reset_job_manager() -> None:
|
||||
@@ -77,6 +78,31 @@ class TestDebugReplayJob(unittest.TestCase):
|
||||
self.assertEqual(results["end_ts"], 200.0)
|
||||
|
||||
|
||||
class TestRecordingDebugReplaySource(unittest.TestCase):
|
||||
def _source_url(self, intervals: list[CoverageInterval]) -> str:
|
||||
source = RecordingDebugReplaySource(
|
||||
source_camera="front", start_ts=100.0, end_ts=200.0, internal_port=5000
|
||||
)
|
||||
with patch(
|
||||
"frigate.jobs.debug_replay.resolve_coverage", return_value=intervals
|
||||
):
|
||||
source.validate()
|
||||
return source.ffmpeg_input_args("/tmp")[-1]
|
||||
|
||||
def test_pins_main_when_main_has_recordings(self) -> None:
|
||||
url = self._source_url(
|
||||
[
|
||||
CoverageInterval(100.0, 150.0, None, MagicMock()),
|
||||
CoverageInterval(150.0, 200.0, MagicMock(), MagicMock()),
|
||||
]
|
||||
)
|
||||
self.assertIn("/vod/front/main/start/100.0/end/200.0/", url)
|
||||
|
||||
def test_falls_back_to_sub_without_main_recordings(self) -> None:
|
||||
url = self._source_url([CoverageInterval(100.0, 200.0, None, MagicMock())])
|
||||
self.assertIn("/vod/front/sub/start/100.0/end/200.0/", url)
|
||||
|
||||
|
||||
class TestStartDebugReplayJob(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
_reset_job_manager()
|
||||
@@ -87,9 +113,7 @@ class TestStartDebugReplayJob(unittest.TestCase):
|
||||
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
|
||||
self.publisher = MagicMock()
|
||||
|
||||
self.recordings_qs = MagicMock()
|
||||
self.recordings_qs.count.return_value = 1
|
||||
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
|
||||
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
|
||||
|
||||
def tearDown(self) -> None:
|
||||
runner = get_active_runner()
|
||||
@@ -127,9 +151,7 @@ class TestStartDebugReplayJob(unittest.TestCase):
|
||||
)
|
||||
|
||||
def test_rejects_when_no_recordings(self) -> None:
|
||||
empty_qs = MagicMock()
|
||||
empty_qs.count.return_value = 0
|
||||
with patch("frigate.jobs.debug_replay.query_recordings", return_value=empty_qs):
|
||||
with patch("frigate.jobs.debug_replay.resolve_coverage", return_value=[]):
|
||||
with self.assertRaises(NoRecordingsError):
|
||||
start_debug_replay_job(
|
||||
source=RecordingDebugReplaySource(
|
||||
@@ -152,8 +174,8 @@ class TestStartDebugReplayJob(unittest.TestCase):
|
||||
|
||||
with (
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.query_recordings",
|
||||
return_value=self.recordings_qs,
|
||||
"frigate.jobs.debug_replay.resolve_coverage",
|
||||
return_value=self.coverage,
|
||||
),
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
|
||||
@@ -192,8 +214,8 @@ class TestStartDebugReplayJob(unittest.TestCase):
|
||||
|
||||
with (
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.query_recordings",
|
||||
return_value=self.recordings_qs,
|
||||
"frigate.jobs.debug_replay.resolve_coverage",
|
||||
return_value=self.coverage,
|
||||
),
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
|
||||
@@ -242,9 +264,7 @@ class TestRunnerHappyPath(unittest.TestCase):
|
||||
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
|
||||
self.publisher = MagicMock()
|
||||
|
||||
self.recordings_qs = MagicMock()
|
||||
self.recordings_qs.count.return_value = 1
|
||||
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
|
||||
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
|
||||
|
||||
def tearDown(self) -> None:
|
||||
runner = get_active_runner()
|
||||
@@ -272,8 +292,8 @@ class TestRunnerHappyPath(unittest.TestCase):
|
||||
|
||||
with (
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.query_recordings",
|
||||
return_value=self.recordings_qs,
|
||||
"frigate.jobs.debug_replay.resolve_coverage",
|
||||
return_value=self.coverage,
|
||||
),
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
|
||||
@@ -325,9 +345,7 @@ class TestRunnerFailurePath(unittest.TestCase):
|
||||
self.frigate_config.cameras = {"front": MagicMock()}
|
||||
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
|
||||
self.publisher = MagicMock()
|
||||
self.recordings_qs = MagicMock()
|
||||
self.recordings_qs.count.return_value = 1
|
||||
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
|
||||
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
|
||||
|
||||
def tearDown(self) -> None:
|
||||
runner = get_active_runner()
|
||||
@@ -350,8 +368,8 @@ class TestRunnerFailurePath(unittest.TestCase):
|
||||
|
||||
with (
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.query_recordings",
|
||||
return_value=self.recordings_qs,
|
||||
"frigate.jobs.debug_replay.resolve_coverage",
|
||||
return_value=self.coverage,
|
||||
),
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
|
||||
@@ -399,9 +417,7 @@ class TestRunnerCancellation(unittest.TestCase):
|
||||
self.frigate_config.cameras = {"front": MagicMock()}
|
||||
self.frigate_config.ffmpeg.ffmpeg_path = "/bin/true"
|
||||
self.publisher = MagicMock()
|
||||
self.recordings_qs = MagicMock()
|
||||
self.recordings_qs.count.return_value = 1
|
||||
self.recordings_qs.__iter__.return_value = iter([MagicMock(path="/tmp/r1.mp4")])
|
||||
self.coverage = [CoverageInterval(100.0, 200.0, MagicMock(), None)]
|
||||
|
||||
def tearDown(self) -> None:
|
||||
runner = get_active_runner()
|
||||
@@ -431,8 +447,8 @@ class TestRunnerCancellation(unittest.TestCase):
|
||||
|
||||
with (
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.query_recordings",
|
||||
return_value=self.recordings_qs,
|
||||
"frigate.jobs.debug_replay.resolve_coverage",
|
||||
return_value=self.coverage,
|
||||
),
|
||||
patch(
|
||||
"frigate.jobs.debug_replay.run_ffmpeg_with_progress",
|
||||
|
||||
@@ -6,6 +6,7 @@ import struct
|
||||
import sys
|
||||
import tempfile
|
||||
import unittest
|
||||
import zlib
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
import numpy as np
|
||||
@@ -19,6 +20,8 @@ from frigate.detectors.device import (
|
||||
)
|
||||
from frigate.detectors.plugins.deepx import (
|
||||
DEEPX_MANIFEST,
|
||||
DXNN_MAX_HEADER_SIZE,
|
||||
DXNN_PRELUDE_SIZE,
|
||||
DXRT_VERSION,
|
||||
PPU_RECORD_SIZE,
|
||||
DeepxDetector,
|
||||
@@ -33,6 +36,7 @@ from frigate.detectors.plugins.deepx import (
|
||||
resolve_device,
|
||||
validate_yolox_outputs,
|
||||
)
|
||||
from frigate.util.runtime_deps import ArtifactKind
|
||||
|
||||
|
||||
def model_with_type(model_type) -> ModelConfig:
|
||||
@@ -135,7 +139,13 @@ def onnx_box_graph(box_format: str) -> bytes:
|
||||
|
||||
|
||||
def write_dxnn(
|
||||
directory, ppu, layers, name="model.dxnn", table=True, box_format=None
|
||||
directory,
|
||||
ppu,
|
||||
layers,
|
||||
name="model.dxnn",
|
||||
table=True,
|
||||
box_format=None,
|
||||
version=None,
|
||||
) -> str:
|
||||
"""A minimal .dxnn as DX-RT's parsers read it: the container header, a
|
||||
compile_config carrying `ppu`, and either the PPU tensor table with one
|
||||
@@ -145,7 +155,9 @@ def write_dxnn(
|
||||
anchor-free scale has one entry, and grid_h 1 means a flattened
|
||||
(1, cells, channels) tensor. `box_format`, "centre" or "corner", adds
|
||||
the compiled graph that says how the head writes its boxes, along with
|
||||
the compile_config layer naming the node the PPU reads them from."""
|
||||
the compile_config layer naming the node the PPU reads them from.
|
||||
`version` overrides the format, 9 replacing the padded index with a
|
||||
length-prefixed one."""
|
||||
if box_format is not None and "layer" not in ppu:
|
||||
ppu = dict(ppu, layer=[{"bbox": PPU_BBOX_NODE, "cls_conf": "/head/Sigmoid"}])
|
||||
|
||||
@@ -209,9 +221,12 @@ def write_dxnn(
|
||||
}
|
||||
}
|
||||
|
||||
if version is None:
|
||||
version = 8 if table else 7
|
||||
|
||||
index = json.dumps(
|
||||
{
|
||||
"version": 8 if table else 7,
|
||||
"version": version,
|
||||
"signature": "DXNN",
|
||||
"size": 8192,
|
||||
"data": data,
|
||||
@@ -220,8 +235,17 @@ def write_dxnn(
|
||||
|
||||
path = os.path.join(directory, name)
|
||||
with open(path, "wb") as model:
|
||||
model.write(b"DXNN" + struct.pack("<I", 8))
|
||||
if version >= 9:
|
||||
model.write(b"DXNN")
|
||||
model.write(struct.pack("<I", version))
|
||||
model.write(struct.pack("<Q", len(index)))
|
||||
model.write(struct.pack("<I", zlib.crc32(index)))
|
||||
model.write(b"\0" * 12) # flags and reserved bytes
|
||||
model.write(index)
|
||||
else:
|
||||
model.write(b"DXNN" + struct.pack("<I", version))
|
||||
model.write(index.ljust(8192 - 8, b"\0"))
|
||||
|
||||
model.write(compile_config + part + graph)
|
||||
|
||||
return path
|
||||
@@ -324,6 +348,40 @@ class TestDeepxModelFile(unittest.TestCase):
|
||||
with self.subTest(graph=graph):
|
||||
self.assertIsNone(self.layout(ppu, layers, **kwargs).centre_boxes)
|
||||
|
||||
def test_a_v9_file_is_read_from_its_variable_length_index(self):
|
||||
cases = {
|
||||
"table": (ANCHOR_BASED_PPU, THREE_SCALE_ANCHORS, {"table": True}),
|
||||
"no table: compile_config sits past the index": (
|
||||
{"num_classes": 80},
|
||||
THREE_SCALE_ANCHORS,
|
||||
{"table": False},
|
||||
),
|
||||
}
|
||||
|
||||
for kind, (ppu, layers, kwargs) in cases.items():
|
||||
with self.subTest(kind=kind):
|
||||
self.assertEqual(
|
||||
self.layout(ppu, layers, version=9, **kwargs),
|
||||
PpuLayout(anchor_based=True, grids=((80, 80), (40, 40), (20, 20))),
|
||||
)
|
||||
|
||||
def test_a_v9_index_shorter_than_it_claims_is_refused(self):
|
||||
path = write_dxnn(self.tmp.name, ANCHOR_BASED_PPU, [(80, 80, 3)], version=9)
|
||||
|
||||
with open(path, "r+b") as model:
|
||||
model.truncate(DXNN_PRELUDE_SIZE + 8)
|
||||
|
||||
self.assertIsNone(read_ppu_layout(path))
|
||||
|
||||
def test_a_v9_index_larger_than_the_cap_is_refused(self):
|
||||
path = write_dxnn(self.tmp.name, ANCHOR_BASED_PPU, [(80, 80, 3)], version=9)
|
||||
|
||||
with open(path, "r+b") as model:
|
||||
model.seek(8)
|
||||
model.write(struct.pack("<Q", DXNN_MAX_HEADER_SIZE + 1))
|
||||
|
||||
self.assertIsNone(read_ppu_layout(path))
|
||||
|
||||
def test_nothing_is_read_from_a_model_without_ppu_metadata(self):
|
||||
self.assertIsNone(read_ppu_layout(os.path.join(self.tmp.name, "missing")))
|
||||
|
||||
@@ -607,15 +665,20 @@ class TestDeepxConfig(unittest.TestCase):
|
||||
self.assertEqual(config.device, "PCIe:0")
|
||||
self.assertEqual(config.model.model_type, ModelTypeEnum.yologeneric)
|
||||
|
||||
def test_the_runtime_manifest_pins_its_wheels_to_the_version(self):
|
||||
"""A PyPI path carries a per-file digest, so bumping DXRT_VERSION has
|
||||
to rewrite the whole URL; a stale one installs the old wheel and fails
|
||||
the sha256 on every user's first start."""
|
||||
def test_the_runtime_manifest_pins_the_package_and_wheel_to_the_version(self):
|
||||
"""The deb carries the wheel, so bumping DXRT_VERSION has to rewrite
|
||||
the package URL, both digests and the wheel member together."""
|
||||
self.assertEqual(DEEPX_MANIFEST.version, DXRT_VERSION)
|
||||
|
||||
for artifact in DEEPX_MANIFEST.artifacts:
|
||||
with self.subTest(url=artifact.url):
|
||||
self.assertIn(f"dx_engine-{DXRT_VERSION}-", artifact.url)
|
||||
self.assertIs(artifact.kind, ArtifactKind.deb)
|
||||
self.assertIn(f"libdxrt-bin_{DXRT_VERSION}_", artifact.url)
|
||||
self.assertIn(f"dx_engine-{DXRT_VERSION}-cp311-", artifact.member)
|
||||
self.assertEqual(len(artifact.member_sha256), 64)
|
||||
self.assertTrue(artifact.mappings)
|
||||
|
||||
self.assertIn("libdxrt.so", DEEPX_MANIFEST.preload)
|
||||
|
||||
def test_a_model_less_config_still_validates(self):
|
||||
config = DeepxDetectorConfig(type="deepx")
|
||||
|
||||
@@ -59,10 +59,18 @@ class TestGetOrtSessionOptions(unittest.TestCase):
|
||||
ort.GraphOptimizationLevel.ORT_ENABLE_ALL,
|
||||
)
|
||||
|
||||
def test_only_cpu_enrichment_models_disable_the_cpu_arena(self):
|
||||
for model_type in EnrichmentModelTypeEnum:
|
||||
for cpu in [False, True]:
|
||||
with self.subTest(model_type=model_type, cpu=cpu):
|
||||
options = get_ort_session_options(model_type.value, cpu=cpu)
|
||||
self.assertEqual(options.enable_cpu_mem_arena, not cpu)
|
||||
|
||||
def test_detector_models_use_defaults(self):
|
||||
for model_type in [None, ModelTypeEnum.rfdetr.value]:
|
||||
with self.subTest(model_type=model_type):
|
||||
self.assertIsNone(get_ort_session_options(model_type, cpu=True))
|
||||
for cpu in [False, True]:
|
||||
with self.subTest(model_type=model_type, cpu=cpu):
|
||||
self.assertIsNone(get_ort_session_options(model_type, cpu=cpu))
|
||||
|
||||
|
||||
class TestCudaGraphRunner(unittest.TestCase):
|
||||
|
||||
@@ -0,0 +1,73 @@
|
||||
"""Tests for the detection subscriber's default receive timeout."""
|
||||
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import threading
|
||||
import time
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
|
||||
import zmq
|
||||
|
||||
from frigate.comms import zmq_proxy
|
||||
from frigate.comms.detections_updater import DetectionSubscriber, DetectionTypeEnum
|
||||
|
||||
|
||||
class TestDetectionSubscriberTimeout(unittest.TestCase):
|
||||
def setUp(self) -> None:
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.address = f"ipc://{os.path.join(tmp.name, 'proxy_sub')}"
|
||||
|
||||
def _subscriber(self) -> DetectionSubscriber:
|
||||
with patch.object(zmq_proxy, "SOCKET_SUB", self.address):
|
||||
return DetectionSubscriber(DetectionTypeEnum.video.value)
|
||||
|
||||
def test_default_check_returns_when_nothing_is_published(self) -> None:
|
||||
subscriber = self._subscriber()
|
||||
results: list = []
|
||||
thread = threading.Thread(
|
||||
target=lambda: results.append(subscriber.check_for_update()),
|
||||
daemon=True,
|
||||
)
|
||||
thread.start()
|
||||
thread.join(timeout=5)
|
||||
|
||||
# a blocked check still owns the socket, so only stop it after returning
|
||||
self.assertFalse(
|
||||
thread.is_alive(), "check_for_update blocked with nothing published"
|
||||
)
|
||||
subscriber.stop()
|
||||
self.assertEqual(results, [(None, None)])
|
||||
|
||||
def test_default_check_returns_queued_detection(self) -> None:
|
||||
context = zmq.Context()
|
||||
publisher = context.socket(zmq.PUB)
|
||||
publisher.bind(self.address)
|
||||
subscriber = self._subscriber()
|
||||
self.addCleanup(context.destroy, linger=0)
|
||||
self.addCleanup(subscriber.stop)
|
||||
|
||||
# wait for the subscription to reach the publisher before relying on it
|
||||
deadline = time.monotonic() + 5
|
||||
while True:
|
||||
publisher.send_string(f"detection/video {json.dumps('ready')}")
|
||||
|
||||
if subscriber.check_for_update(timeout=0.05) == ("video", "ready"):
|
||||
break
|
||||
|
||||
self.assertLess(time.monotonic(), deadline, "subscription never joined")
|
||||
|
||||
# drop any late readiness messages so only the real one is queued
|
||||
while subscriber.check_for_update(timeout=0.05) != (None, None):
|
||||
pass
|
||||
|
||||
publisher.send_string(f"detection/video {json.dumps(['front', 1.0])}")
|
||||
time.sleep(0.1)
|
||||
|
||||
self.assertEqual(subscriber.check_for_update(), ("video", ["front", 1.0]))
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
+80
-14
@@ -194,15 +194,16 @@ class TestEnvVars(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self._original_env_vars = dict(FRIGATE_ENV_VARS)
|
||||
self._original_environ = os.environ.copy()
|
||||
names_patch = patch.object(env, "_CONTAINER_ENV_NAMES", frozenset())
|
||||
names_patch.start()
|
||||
self.addCleanup(names_patch.stop)
|
||||
|
||||
def tearDown(self):
|
||||
FRIGATE_ENV_VARS.clear()
|
||||
FRIGATE_ENV_VARS.update(self._original_env_vars)
|
||||
env._CONFIG_ENV_VARS.clear()
|
||||
# Clean up any env vars we set
|
||||
for key in list(os.environ.keys()):
|
||||
if key not in self._original_environ:
|
||||
del os.environ[key]
|
||||
os.environ.clear()
|
||||
os.environ.update(self._original_environ)
|
||||
|
||||
def _make_context(self, install: bool):
|
||||
"""Create a mock ValidationInfo with the given install flag."""
|
||||
@@ -215,10 +216,10 @@ class TestEnvVars(unittest.TestCase):
|
||||
return mock
|
||||
|
||||
def test_install_sets_os_environ(self):
|
||||
"""validate_env_vars with install=True sets os.environ."""
|
||||
"""validate_env_vars with install=True sets allowed names in os.environ."""
|
||||
ctx = self._make_context(install=True)
|
||||
validate_env_vars({"MY_CUSTOM_VAR": "value123"}, ctx)
|
||||
self.assertEqual(os.environ.get("MY_CUSTOM_VAR"), "value123")
|
||||
validate_env_vars({"SHM_MAX_FRAMES": "75"}, ctx)
|
||||
self.assertEqual(os.environ.get("SHM_MAX_FRAMES"), "75")
|
||||
|
||||
def test_install_updates_frigate_env_vars(self):
|
||||
"""validate_env_vars with install=True updates FRIGATE_ENV_VARS for FRIGATE_ keys."""
|
||||
@@ -229,9 +230,9 @@ class TestEnvVars(unittest.TestCase):
|
||||
def test_install_skips_non_frigate_in_env_vars_dict(self):
|
||||
"""Non-FRIGATE_ keys are set in os.environ but not in FRIGATE_ENV_VARS."""
|
||||
ctx = self._make_context(install=True)
|
||||
validate_env_vars({"OTHER_VAR": "value"}, ctx)
|
||||
self.assertEqual(os.environ.get("OTHER_VAR"), "value")
|
||||
self.assertNotIn("OTHER_VAR", FRIGATE_ENV_VARS)
|
||||
validate_env_vars({"USE_FP16": "False"}, ctx)
|
||||
self.assertEqual(os.environ.get("USE_FP16"), "False")
|
||||
self.assertNotIn("USE_FP16", FRIGATE_ENV_VARS)
|
||||
|
||||
def test_no_install_does_not_set(self):
|
||||
"""validate_env_vars without install=True does not modify state."""
|
||||
@@ -258,10 +259,10 @@ class TestEnvVars(unittest.TestCase):
|
||||
ctx = self._make_context(install=True)
|
||||
with patch("frigate.util.services.os.path.isfile", return_value=False):
|
||||
for key in ("GO2RTC_ALLOW_ARBITRARY_EXEC", "go2rtc_allow_arbitrary_exec"):
|
||||
validate_env_vars({key: "true", "OTHER_VAR": "value"}, ctx)
|
||||
validate_env_vars({key: "true", "USE_FP16": "False"}, ctx)
|
||||
self.assertNotIn(key, os.environ)
|
||||
self.assertFalse(is_go2rtc_arbitrary_exec_allowed())
|
||||
self.assertEqual(os.environ.get("OTHER_VAR"), "value")
|
||||
self.assertEqual(os.environ.get("USE_FP16"), "False")
|
||||
|
||||
def test_install_keeps_container_go2rtc_exec_override(self):
|
||||
"""An override set in the container environment is left untouched."""
|
||||
@@ -307,17 +308,82 @@ class TestVariableSources(unittest.TestCase):
|
||||
self.assertEqual(env.FRIGATE_ENV_VARS["FRIGATE_CAM_PASS"], "hunter2")
|
||||
|
||||
def test_config_env_vars_do_not_become_container_env(self):
|
||||
"""environment_vars writes os.environ but must not gain env precedence."""
|
||||
"""environment_vars FRIGATE_ keys stay out of os.environ and env precedence."""
|
||||
env.apply_config_env_vars({"FRIGATE_CAM_PASS": "from_config"})
|
||||
self.assertEqual(os.environ["FRIGATE_CAM_PASS"], "from_config")
|
||||
self.assertNotIn("FRIGATE_CAM_PASS", os.environ)
|
||||
self.assertNotIn("FRIGATE_CAM_PASS", env._CONTAINER_ENV)
|
||||
|
||||
def test_non_frigate_config_env_vars_only_set_os_environ(self):
|
||||
"""Unprefixed environment_vars keys reach os.environ but not substitution."""
|
||||
with patch.object(env, "_CONTAINER_ENV_NAMES", frozenset()):
|
||||
env.apply_config_env_vars({"LIBVA_DRIVER_NAME": "i965"})
|
||||
self.assertEqual(os.environ["LIBVA_DRIVER_NAME"], "i965")
|
||||
self.assertNotIn("LIBVA_DRIVER_NAME", env.FRIGATE_ENV_VARS)
|
||||
|
||||
def test_rejected_names_warn_and_are_not_exported(self):
|
||||
"""Names off the allowlist log a warning without the value."""
|
||||
for key in ("MY_CUSTOM_VAR", "LD_PRELOAD", "LIGHTER_ANE_EP", "PATH"):
|
||||
with self.subTest(key=key):
|
||||
original = os.environ.get(key)
|
||||
with self.assertLogs("frigate.util.env", level="WARNING") as logs:
|
||||
env.apply_config_env_vars({key: "/config/evil.so"})
|
||||
self.assertEqual(os.environ.get(key), original)
|
||||
self.assertEqual(len(logs.output), 1)
|
||||
self.assertIn(key, logs.output[0])
|
||||
self.assertIn("container environment", logs.output[0])
|
||||
self.assertNotIn("evil", logs.output[0])
|
||||
|
||||
def test_allowed_name_with_bad_value_is_rejected(self):
|
||||
"""LIBVA_DRIVER_NAME cannot carry a path."""
|
||||
with patch.object(env, "_CONTAINER_ENV_NAMES", frozenset()):
|
||||
with self.assertLogs("frigate.util.env", level="WARNING"):
|
||||
env.apply_config_env_vars({"LIBVA_DRIVER_NAME": "../x"})
|
||||
self.assertNotEqual(os.environ.get("LIBVA_DRIVER_NAME"), "../x")
|
||||
|
||||
def test_unsupported_values_are_rejected_without_crashing(self):
|
||||
"""Non-ASCII digits and NUL bytes never reach os.environ."""
|
||||
os.environ.pop("SHM_MAX_FRAMES", None)
|
||||
os.environ.pop("HF_ENDPOINT", None)
|
||||
with patch.object(env, "_CONTAINER_ENV_NAMES", frozenset()):
|
||||
with self.assertLogs("frigate.util.env", level="WARNING") as logs:
|
||||
env.apply_config_env_vars(
|
||||
{"SHM_MAX_FRAMES": "\u0663\u0664", "HF_ENDPOINT": "https://x\x00"}
|
||||
)
|
||||
self.assertEqual(len(logs.output), 2)
|
||||
self.assertNotIn("SHM_MAX_FRAMES", os.environ)
|
||||
self.assertNotIn("HF_ENDPOINT", os.environ)
|
||||
|
||||
def test_container_env_wins_over_allowed_name(self):
|
||||
"""A name the container set is left as the container set it."""
|
||||
os.environ["LIBVA_DRIVER_NAME"] = "iHD"
|
||||
with patch.object(
|
||||
env, "_CONTAINER_ENV_NAMES", frozenset({"LIBVA_DRIVER_NAME"})
|
||||
):
|
||||
env.apply_config_env_vars({"LIBVA_DRIVER_NAME": "i965"})
|
||||
self.assertEqual(os.environ["LIBVA_DRIVER_NAME"], "iHD")
|
||||
|
||||
def test_second_apply_is_not_blocked_by_first(self):
|
||||
"""A safe-mode reload can change a value the first load exported."""
|
||||
with patch.object(env, "_CONTAINER_ENV_NAMES", frozenset()):
|
||||
env.apply_config_env_vars({"LIBVA_DRIVER_NAME": "i965"})
|
||||
env.apply_config_env_vars({"LIBVA_DRIVER_NAME": "radeonsi"})
|
||||
self.assertEqual(os.environ["LIBVA_DRIVER_NAME"], "radeonsi")
|
||||
|
||||
def test_run_as_root_is_substitutable_but_not_exported(self):
|
||||
"""FRIGATE_RUN_AS_ROOT from the config never reaches os.environ."""
|
||||
os.environ.pop("FRIGATE_RUN_AS_ROOT", None)
|
||||
with patch.object(env, "_CONTAINER_ENV_NAMES", frozenset()):
|
||||
env.apply_config_env_vars({"FRIGATE_RUN_AS_ROOT": "true"})
|
||||
self.assertNotIn("FRIGATE_RUN_AS_ROOT", os.environ)
|
||||
self.assertEqual(env.substitute_frigate_vars("{FRIGATE_RUN_AS_ROOT}"), "true")
|
||||
|
||||
def test_jwt_secret_is_exported(self):
|
||||
"""Auth reads FRIGATE_JWT_SECRET from os.environ."""
|
||||
os.environ.pop("FRIGATE_JWT_SECRET", None)
|
||||
with patch.object(env, "_CONTAINER_ENV_NAMES", frozenset()):
|
||||
env.apply_config_env_vars({"FRIGATE_JWT_SECRET": "s3cret"})
|
||||
self.assertEqual(os.environ["FRIGATE_JWT_SECRET"], "s3cret")
|
||||
|
||||
def test_collision_warns_once_naming_the_winner(self):
|
||||
"""A key from two sources logs one warning naming the source that won."""
|
||||
with patch.dict(env._CONTAINER_ENV, {"FRIGATE_MQTT_HOST": "from_env"}):
|
||||
|
||||
@@ -0,0 +1,42 @@
|
||||
"""When tracked object updates are written to the database."""
|
||||
|
||||
import unittest
|
||||
from typing import Any
|
||||
|
||||
from frigate.events.maintainer import should_update_db
|
||||
|
||||
|
||||
def _event(**overrides: Any) -> dict[str, Any]:
|
||||
return {
|
||||
"end_time": None,
|
||||
"has_clip": False,
|
||||
"has_snapshot": True,
|
||||
"top_score": 0.8,
|
||||
"entered_zones": ["porch"],
|
||||
"average_estimated_speed": 0,
|
||||
"velocity_angle": 0,
|
||||
"recognized_license_plate": None,
|
||||
"path_data": [],
|
||||
"max_severity": None,
|
||||
**overrides,
|
||||
}
|
||||
|
||||
|
||||
class TestShouldUpdateDb(unittest.TestCase):
|
||||
def test_unchanged_saved_event_is_not_updated(self):
|
||||
self.assertFalse(should_update_db(_event(), _event()))
|
||||
|
||||
def test_max_severity_change_updates_saved_event(self):
|
||||
self.assertTrue(should_update_db(_event(), _event(max_severity="alert")))
|
||||
|
||||
def test_max_severity_change_ignored_when_not_saved(self):
|
||||
self.assertFalse(
|
||||
should_update_db(
|
||||
_event(has_snapshot=False),
|
||||
_event(has_snapshot=False, max_severity="alert"),
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user