mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-20 04:23:01 +03:00
Compare commits
93
Commits
52d469ed20
...
dev
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
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 |
@@ -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:
|
||||
|
||||
@@ -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
|
||||
@@ -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
|
||||
|
||||
@@ -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,7 +2,7 @@
|
||||
|
||||
set -euxo pipefail
|
||||
|
||||
NGINX_VERSION="1.27.4"
|
||||
NGINX_VERSION="1.30.7"
|
||||
VOD_MODULE_VERSION="v1.9.1"
|
||||
SET_MISC_MODULE_VERSION="v0.33"
|
||||
NGX_DEVEL_KIT_VERSION="v0.3.3"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
ruff == 0.17.3
|
||||
ruff == 0.17.4
|
||||
|
||||
# types
|
||||
types-peewee == 4.0.*
|
||||
|
||||
@@ -47,9 +47,9 @@ onnxruntime == 1.31.*
|
||||
# Embeddings
|
||||
transformers == 5.22.*
|
||||
# Generative AI
|
||||
google-genai == 2.34.*
|
||||
google-genai == 3.2.*
|
||||
ollama == 0.6.*
|
||||
openai == 3.46.*
|
||||
openai == 3.49.*
|
||||
# push notifications
|
||||
py-vapid == 1.9.6
|
||||
pywebpush == 2.5.*
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
@@ -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
|
||||
|
||||
@@ -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):
|
||||
|
||||
+28
-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 (
|
||||
@@ -979,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:
|
||||
@@ -987,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("/")
|
||||
@@ -1675,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())]
|
||||
)
|
||||
|
||||
+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")
|
||||
|
||||
+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
|
||||
|
||||
+13
-1
@@ -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,
|
||||
|
||||
+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)
|
||||
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -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}"
|
||||
)
|
||||
|
||||
@@ -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",
|
||||
|
||||
@@ -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:
|
||||
|
||||
+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),
|
||||
]
|
||||
|
||||
@@ -1007,6 +1007,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"]
|
||||
)
|
||||
|
||||
@@ -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)
|
||||
|
||||
@@ -98,6 +98,46 @@ class TestHttpApp(BaseTestHttp):
|
||||
assert response.status_code == 200
|
||||
assert app.frigate_config.cameras["front_door"].objects.track == ["person"]
|
||||
|
||||
@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 ################################################
|
||||
####################################################################################################################
|
||||
|
||||
@@ -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(","))
|
||||
|
||||
@@ -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()
|
||||
@@ -5,6 +5,7 @@ per-camera gating those processors apply once they exist.
|
||||
"""
|
||||
|
||||
import sys
|
||||
import threading
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
@@ -19,6 +20,8 @@ for mod in _MOCK_MODULES:
|
||||
if mod not in sys.modules:
|
||||
sys.modules[mod] = MagicMock()
|
||||
|
||||
from frigate.config.camera.review import ImageSourceEnum # noqa: E402
|
||||
|
||||
# imported from the maintainer to avoid tripping the circular import between
|
||||
# the maintainer and the processor modules
|
||||
from frigate.embeddings.maintainer import ( # noqa: E402
|
||||
@@ -211,3 +214,58 @@ class TestObjectDescriptionCameraGating(unittest.TestCase):
|
||||
|
||||
mock_create_thumbnail.assert_called_once()
|
||||
self.assertEqual(len(processor.tracked_events["1234.5-abcdef"]), 1)
|
||||
|
||||
|
||||
class TestReviewDescriptionOffLoop(unittest.TestCase):
|
||||
"""Frame extraction for a finished review must not block process_data."""
|
||||
|
||||
def test_recording_frames_extracted_off_the_caller_thread(self):
|
||||
camera = MagicMock()
|
||||
camera.review.genai.enabled = True
|
||||
camera.review.genai.alerts = True
|
||||
camera.review.genai.image_source = ImageSourceEnum.recordings
|
||||
camera.review.genai.debug_save_thumbnails = False
|
||||
config = MagicMock()
|
||||
config.cameras = {"front": camera}
|
||||
processor = ReviewDescriptionProcessor(
|
||||
config, MagicMock(), MagicMock(), MagicMock()
|
||||
)
|
||||
|
||||
release = threading.Event()
|
||||
extracted = threading.Event()
|
||||
analyzed = threading.Event()
|
||||
|
||||
def slow_frames(*args, **kwargs):
|
||||
release.wait(5)
|
||||
extracted.set()
|
||||
return [(b"jpg", 1.0)]
|
||||
|
||||
with (
|
||||
patch.object(processor, "get_recording_frames", side_effect=slow_frames),
|
||||
patch.object(
|
||||
processor, "start_analysis", side_effect=lambda *a, **k: analyzed.set()
|
||||
) as start_analysis,
|
||||
):
|
||||
processor.process_data(
|
||||
{
|
||||
"type": "end",
|
||||
"after": {
|
||||
"id": "1234.5-abcdef",
|
||||
"camera": "front",
|
||||
"severity": "alert",
|
||||
"start_time": 100.0,
|
||||
"end_time": 110.0,
|
||||
},
|
||||
},
|
||||
PostProcessDataEnum.review,
|
||||
)
|
||||
|
||||
self.assertFalse(extracted.is_set())
|
||||
release.set()
|
||||
self.assertTrue(extracted.wait(5))
|
||||
|
||||
self.assertTrue(analyzed.wait(5))
|
||||
start_analysis.assert_called_once()
|
||||
final_data = start_analysis.call_args.args[1]
|
||||
self.assertEqual(final_data["start_time"], 100.0)
|
||||
self.assertEqual(final_data["end_time"], 110.0)
|
||||
|
||||
@@ -327,6 +327,76 @@ class TestOpenAIProvider(unittest.TestCase):
|
||||
async_client.close.assert_awaited_once()
|
||||
|
||||
|
||||
class TestOpenAIContextSize(unittest.TestCase):
|
||||
"""Context size lookup from an OpenAI-compatible /models endpoint."""
|
||||
|
||||
# Neither model name contains "gpt", so the name-based default is 8192 and
|
||||
# any other value must have come from the /models response.
|
||||
MODEL = "google/gemini-2.5-flash"
|
||||
|
||||
def _client_with_models(self, *entries, provider_options=None):
|
||||
client = _make_client(
|
||||
"openai",
|
||||
model=self.MODEL,
|
||||
api_key="k",
|
||||
base_url="https://openrouter.ai/api/v1",
|
||||
provider_options=provider_options or {},
|
||||
)
|
||||
client.provider.models.list = MagicMock(
|
||||
return_value=SimpleNamespace(data=list(entries))
|
||||
)
|
||||
return client
|
||||
|
||||
def test_vllm_max_model_len(self):
|
||||
client = self._client_with_models(
|
||||
SimpleNamespace(id=self.MODEL, max_model_len=32768)
|
||||
)
|
||||
self.assertEqual(client.get_context_size(), 32768)
|
||||
|
||||
def test_openrouter_prefers_top_provider_context_length(self):
|
||||
# The top-level value is the largest any provider offers; the routed
|
||||
# provider's smaller window is the one requests must fit in.
|
||||
client = self._client_with_models(
|
||||
SimpleNamespace(id="other/model", context_length=4096),
|
||||
SimpleNamespace(
|
||||
id=self.MODEL,
|
||||
context_length=1048576,
|
||||
top_provider={"context_length": 262144},
|
||||
),
|
||||
)
|
||||
self.assertEqual(client.get_context_size(), 262144)
|
||||
|
||||
def test_openrouter_falls_back_to_context_length(self):
|
||||
client = self._client_with_models(
|
||||
SimpleNamespace(
|
||||
id=self.MODEL,
|
||||
context_length=1048576,
|
||||
top_provider={"context_length": None},
|
||||
)
|
||||
)
|
||||
self.assertEqual(client.get_context_size(), 1048576)
|
||||
|
||||
def test_default_when_model_reports_no_context(self):
|
||||
client = self._client_with_models(SimpleNamespace(id=self.MODEL))
|
||||
self.assertEqual(client.get_context_size(), 8192)
|
||||
|
||||
def test_provider_options_override_api(self):
|
||||
client = self._client_with_models(
|
||||
SimpleNamespace(id=self.MODEL, context_length=1048576),
|
||||
provider_options={"context_size": 16000},
|
||||
)
|
||||
self.assertEqual(client.get_context_size(), 16000)
|
||||
client.provider.models.list.assert_not_called()
|
||||
|
||||
def test_result_is_cached(self):
|
||||
client = self._client_with_models(
|
||||
SimpleNamespace(id=self.MODEL, context_length=1048576)
|
||||
)
|
||||
client.get_context_size()
|
||||
client.get_context_size()
|
||||
client.provider.models.list.assert_called_once()
|
||||
|
||||
|
||||
# ---------------------------------------------------------------------------
|
||||
# Gemini
|
||||
# ---------------------------------------------------------------------------
|
||||
@@ -1286,6 +1356,154 @@ class TestImageTokenEstimate(unittest.TestCase):
|
||||
self.assertEqual(client._image_token_cache, {})
|
||||
|
||||
|
||||
class TestGeminiEmbeddings(unittest.TestCase):
|
||||
"""gemini-embedding-2 via embed_content. No network, no real images."""
|
||||
|
||||
@staticmethod
|
||||
def _webp_bytes():
|
||||
import io
|
||||
|
||||
from PIL import Image
|
||||
|
||||
buf = io.BytesIO()
|
||||
Image.new("RGB", (8, 8), (10, 20, 30)).save(buf, format="WEBP")
|
||||
return buf.getvalue()
|
||||
|
||||
@staticmethod
|
||||
def _vector(value: float):
|
||||
return SimpleNamespace(embeddings=[SimpleNamespace(values=[value] * 768)])
|
||||
|
||||
def _client(self, model="models/gemini-embedding-2"):
|
||||
client = _make_client("gemini", model=model, api_key="k")
|
||||
client.provider = MagicMock()
|
||||
return client
|
||||
|
||||
def test_supports_embeddings_checks_supported_actions(self):
|
||||
models = [
|
||||
SimpleNamespace(
|
||||
name="models/gemini-2.5-flash",
|
||||
supported_actions=["generateContent"],
|
||||
),
|
||||
SimpleNamespace(
|
||||
name="models/gemini-embedding-2",
|
||||
supported_actions=["embedContent", "countTokens"],
|
||||
),
|
||||
]
|
||||
|
||||
client = self._client(model="models/gemini-embedding-2")
|
||||
client.provider.models.list.return_value = models
|
||||
self.assertTrue(client.supports_embeddings)
|
||||
self.assertEqual(
|
||||
client.list_model_capabilities(),
|
||||
{
|
||||
"models/gemini-2.5-flash": {"supports_embeddings": False},
|
||||
"gemini-2.5-flash": {"supports_embeddings": False},
|
||||
"models/gemini-embedding-2": {"supports_embeddings": True},
|
||||
"gemini-embedding-2": {"supports_embeddings": True},
|
||||
},
|
||||
)
|
||||
client.provider.models.list.assert_called_once()
|
||||
|
||||
unprefixed = self._client(model="gemini-embedding-2")
|
||||
unprefixed.provider.models.list.return_value = models
|
||||
self.assertTrue(unprefixed.supports_embeddings)
|
||||
|
||||
chat_client = self._client(model="models/gemini-2.5-flash")
|
||||
chat_client.provider.models.list.return_value = models
|
||||
self.assertFalse(chat_client.supports_embeddings)
|
||||
|
||||
def test_capability_lookup_failure_is_not_cached(self):
|
||||
client = self._client()
|
||||
client.provider.models.list.side_effect = [
|
||||
RuntimeError("offline"),
|
||||
[
|
||||
SimpleNamespace(
|
||||
name="models/gemini-embedding-2",
|
||||
supported_actions=["embedContent"],
|
||||
)
|
||||
],
|
||||
]
|
||||
|
||||
self.assertFalse(client.supports_embeddings)
|
||||
self.assertTrue(client.supports_embeddings)
|
||||
|
||||
def test_one_request_per_text_and_image(self):
|
||||
client = self._client()
|
||||
client.provider.models.embed_content.side_effect = [
|
||||
self._vector(0.1),
|
||||
self._vector(0.2),
|
||||
]
|
||||
|
||||
result = client.embed(texts=["a person walking"], images=[self._webp_bytes()])
|
||||
|
||||
calls = client.provider.models.embed_content.call_args_list
|
||||
self.assertEqual(len(calls), 2)
|
||||
self.assertEqual(calls[0].kwargs["model"], "gemini-embedding-2")
|
||||
self.assertEqual(
|
||||
calls[0].kwargs["contents"],
|
||||
"task: search result | query: a person walking",
|
||||
)
|
||||
self.assertEqual(calls[0].kwargs["config"].output_dimensionality, 768)
|
||||
parts = calls[1].kwargs["contents"]
|
||||
self.assertEqual(len(parts), 1)
|
||||
self.assertEqual(parts[0].inline_data.mime_type, "image/jpeg")
|
||||
self.assertTrue(parts[0].inline_data.data.startswith(b"\xff\xd8\xff"))
|
||||
self.assertEqual(calls[1].kwargs["model"], "gemini-embedding-2")
|
||||
self.assertEqual(len(result), 2)
|
||||
self.assertEqual(len(result[0]), 768)
|
||||
self.assertEqual(result[0].dtype.name, "float32")
|
||||
self.assertAlmostEqual(float(result[1][0]), 0.2, places=5)
|
||||
|
||||
def test_prepared_task_prefix_is_kept(self):
|
||||
client = self._client(model="gemini-embedding-2")
|
||||
client.provider.models.embed_content.return_value = self._vector(0.3)
|
||||
prepared = "task: search result | query: already prepared"
|
||||
|
||||
client.embed(texts=[prepared])
|
||||
|
||||
contents = client.provider.models.embed_content.call_args.kwargs["contents"]
|
||||
self.assertEqual(contents, prepared)
|
||||
self.assertEqual(
|
||||
client.provider.models.embed_content.call_args.kwargs["model"],
|
||||
"gemini-embedding-2",
|
||||
)
|
||||
|
||||
def test_empty_input_makes_no_request(self):
|
||||
client = self._client()
|
||||
|
||||
self.assertEqual(client.embed(), [])
|
||||
client.provider.models.embed_content.assert_not_called()
|
||||
|
||||
def test_api_error_raises_value_error(self):
|
||||
client = self._client()
|
||||
client.provider.models.embed_content.side_effect = RuntimeError("rejected")
|
||||
|
||||
with self.assertRaises(ValueError) as caught:
|
||||
client.embed(texts=["hello"])
|
||||
|
||||
self.assertEqual(str(caught.exception), "Gemini embeddings request failed")
|
||||
|
||||
def test_bad_image_is_not_sent(self):
|
||||
client = self._client()
|
||||
|
||||
with self.assertRaises(ValueError) as caught:
|
||||
client.embed(images=[b"this is not an image"])
|
||||
|
||||
self.assertEqual(
|
||||
str(caught.exception), "thumbnail could not be converted to JPEG"
|
||||
)
|
||||
client.provider.models.embed_content.assert_not_called()
|
||||
|
||||
def test_missing_vector_raises(self):
|
||||
client = self._client()
|
||||
client.provider.models.embed_content.return_value = SimpleNamespace(
|
||||
embeddings=[]
|
||||
)
|
||||
|
||||
with self.assertRaises(ValueError):
|
||||
client.embed(texts=["hello"])
|
||||
|
||||
|
||||
class TestBaseClientTranscribe(unittest.TestCase):
|
||||
"""Providers that don't implement the role must be inert, not broken."""
|
||||
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
"""Tests for the go2rtc ffmpeg and ngrok options applied at startup."""
|
||||
"""Tests for the go2rtc exec-related options applied at startup."""
|
||||
|
||||
import unittest
|
||||
from unittest.mock import patch
|
||||
@@ -24,6 +24,18 @@ class TestApplyGo2rtcFfmpegConfig(unittest.TestCase):
|
||||
assert apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH) == []
|
||||
assert config["ffmpeg"] == {"bin": FFMPEG_PATH}
|
||||
|
||||
def test_limits_exec_and_echo_to_ffmpeg(self):
|
||||
config = {}
|
||||
apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH)
|
||||
assert config["exec"] == {"allow_paths": [FFMPEG_PATH]}
|
||||
assert config["echo"] == {"allow_paths": [FFMPEG_PATH]}
|
||||
|
||||
def test_forces_exec_allowlist_override(self):
|
||||
config = {"exec": {"allow_paths": ["/bin/bash"]}, "echo": {}}
|
||||
assert apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH) == ["exec", "echo"]
|
||||
assert config["exec"] == {"allow_paths": [FFMPEG_PATH]}
|
||||
assert config["echo"] == {"allow_paths": [FFMPEG_PATH]}
|
||||
|
||||
def test_forces_bin_override(self):
|
||||
config = {"ffmpeg": {"bin": "/bin/sh", "global": "-c 'id' x"}}
|
||||
assert apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH) == ["ffmpeg.bin"]
|
||||
@@ -34,10 +46,10 @@ class TestApplyGo2rtcFfmpegConfig(unittest.TestCase):
|
||||
assert apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH) == []
|
||||
assert config["ffmpeg"]["global"] == "-vaapi_device /dev/dri/renderD128"
|
||||
|
||||
def test_drops_ngrok(self):
|
||||
def test_disables_ngrok(self):
|
||||
config = {"ngrok": {"command": "/bin/sh -c id"}}
|
||||
assert apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH) == ["ngrok"]
|
||||
assert "ngrok" not in config
|
||||
assert config["ngrok"] == {"command": ""}
|
||||
|
||||
def test_allows_bin_and_ngrok_when_override_set(self):
|
||||
config = {
|
||||
@@ -48,6 +60,8 @@ class TestApplyGo2rtcFfmpegConfig(unittest.TestCase):
|
||||
assert apply_go2rtc_ffmpeg_config(config, FFMPEG_PATH) == []
|
||||
assert config["ffmpeg"]["bin"] == "/usr/bin/ffmpeg"
|
||||
assert config["ngrok"] == {"command": "ngrok tcp 8555"}
|
||||
assert "exec" not in config
|
||||
assert "echo" not in config
|
||||
|
||||
|
||||
class TestRestrictedGo2rtcVarExpansion(unittest.TestCase):
|
||||
|
||||
@@ -0,0 +1,24 @@
|
||||
"""Tests for MQTT TLS configuration validation."""
|
||||
|
||||
import unittest
|
||||
from contextlib import nullcontext
|
||||
|
||||
from pydantic import ValidationError
|
||||
|
||||
from frigate.config import MqttConfig
|
||||
|
||||
|
||||
class TestMqttTls(unittest.TestCase):
|
||||
def test_tls_insecure_requires_tls_only_when_enabled(self) -> None:
|
||||
"""Require TLS for either explicit verification flag only if MQTT is enabled."""
|
||||
for enabled in (True, False):
|
||||
for insecure in (True, False):
|
||||
expected = (
|
||||
self.assertRaisesRegex(
|
||||
ValidationError, "tls_insecure requires tls_ca_certs"
|
||||
)
|
||||
if enabled
|
||||
else nullcontext()
|
||||
)
|
||||
with self.subTest(enabled=enabled, tls_insecure=insecure), expected:
|
||||
MqttConfig(enabled=enabled, tls_insecure=insecure)
|
||||
+138
-1
@@ -1,12 +1,17 @@
|
||||
"""Tests for Frigate+ model metadata."""
|
||||
|
||||
import asyncio
|
||||
import json
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from unittest.mock import MagicMock, patch
|
||||
|
||||
from frigate.plus import PlusApi, load_plus_model_info
|
||||
import aiohttp
|
||||
from aiohttp import web
|
||||
from aiohttp.test_utils import TestServer
|
||||
|
||||
from frigate.plus import PlusApi, PlusKeyStatus, load_plus_model_info
|
||||
|
||||
|
||||
class TestHailoAlias(unittest.TestCase):
|
||||
@@ -75,5 +80,137 @@ class TestLoadPlusModelInfo(unittest.TestCase):
|
||||
self.assertIsNone(load_plus_model_info("bad"))
|
||||
|
||||
|
||||
class TestValidateKey(unittest.IsolatedAsyncioTestCase):
|
||||
"""The key format is checked locally, but only the server knows if it is valid."""
|
||||
|
||||
CACHED_TOKEN = {"accessToken": "cached", "expires": 2000000000}
|
||||
|
||||
async def _serve(self, handler) -> str:
|
||||
"""Serve the token endpoint locally and return its base url."""
|
||||
app = web.Application()
|
||||
app.router.add_get("/v1/auth/token", handler)
|
||||
server = TestServer(app)
|
||||
await server.start_server()
|
||||
self.addAsyncCleanup(server.close)
|
||||
return str(server.make_url("")).rstrip("/")
|
||||
|
||||
def _api(self, host: str, key: str | None = "id:secret") -> PlusApi:
|
||||
api = PlusApi.__new__(PlusApi)
|
||||
api.host = host
|
||||
api.key = key
|
||||
api._token_data = dict(self.CACHED_TOKEN)
|
||||
return api
|
||||
|
||||
async def _validate(self, handler) -> tuple[PlusKeyStatus, PlusApi]:
|
||||
api = self._api(await self._serve(handler))
|
||||
return await api.validate_key(), api
|
||||
|
||||
def _replies(self, status: int = 200, body: object = None, text: str | None = None):
|
||||
async def handler(request: web.Request) -> web.Response:
|
||||
self.auth = request.headers.get("Authorization")
|
||||
if text is not None:
|
||||
return web.Response(status=status, text=text)
|
||||
return web.json_response(body, status=status)
|
||||
|
||||
return handler
|
||||
|
||||
async def test_an_accepted_key_is_valid(self):
|
||||
token = {"accessToken": "fresh", "expires": 2000000500.5}
|
||||
status, api = await self._validate(self._replies(body=token))
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.valid)
|
||||
self.assertEqual(api._token_data, token)
|
||||
self.assertEqual(self.auth, aiohttp.BasicAuth("id", "secret").encode())
|
||||
|
||||
async def test_a_rejected_key_is_invalid(self):
|
||||
for code in (401, 403):
|
||||
status, api = await self._validate(self._replies(code, {"error": "no"}))
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.invalid)
|
||||
self.assertEqual(api._token_data, self.CACHED_TOKEN)
|
||||
|
||||
async def test_a_server_error_is_not_reported_as_invalid(self):
|
||||
status, _ = await self._validate(self._replies(500, {"error": "down"}))
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.unreachable)
|
||||
|
||||
async def test_unusable_replies_keep_the_cached_token(self):
|
||||
# a successful reply without a usable token must not replace one that
|
||||
# later Frigate+ requests depend on
|
||||
for body in (
|
||||
None,
|
||||
[],
|
||||
{},
|
||||
{"accessToken": "t"},
|
||||
{"expires": 2000000000},
|
||||
{"accessToken": 1, "expires": 2000000000},
|
||||
{"accessToken": "t", "expires": "soon"},
|
||||
{"accessToken": "t", "expires": True},
|
||||
):
|
||||
with self.subTest(body=body):
|
||||
status, api = await self._validate(self._replies(body=body))
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.unreachable)
|
||||
self.assertEqual(api._token_data, self.CACHED_TOKEN)
|
||||
|
||||
async def test_a_non_json_reply_keeps_the_cached_token(self):
|
||||
status, api = await self._validate(self._replies(text="<html>"))
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.unreachable)
|
||||
self.assertEqual(api._token_data, self.CACHED_TOKEN)
|
||||
|
||||
async def test_a_connection_failure_is_unreachable(self):
|
||||
# serve and stop, so the port refuses connections
|
||||
server = TestServer(web.Application())
|
||||
await server.start_server()
|
||||
host = str(server.make_url("")).rstrip("/")
|
||||
await server.close()
|
||||
api = self._api(host)
|
||||
|
||||
self.assertEqual(await api.validate_key(), PlusKeyStatus.unreachable)
|
||||
|
||||
async def test_a_slow_server_times_out_as_unreachable(self):
|
||||
async def slow(request: web.Request) -> web.Response:
|
||||
await asyncio.sleep(5)
|
||||
return web.json_response(self.CACHED_TOKEN)
|
||||
|
||||
with patch("frigate.plus.PLUS_VALIDATE_TIMEOUT", 0.1):
|
||||
status, _ = await self._validate(slow)
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.unreachable)
|
||||
|
||||
async def test_the_request_goes_through_a_configured_proxy(self):
|
||||
# installs that reach Frigate+ through a proxy must validate the same way
|
||||
token = {"accessToken": "proxied", "expires": 2000000000}
|
||||
proxied = []
|
||||
|
||||
async def proxy(request: web.Request) -> web.Response:
|
||||
proxied.append(str(request.url))
|
||||
return web.json_response(token)
|
||||
|
||||
proxy_url = await self._serve(proxy)
|
||||
api = self._api("http://plus.invalid")
|
||||
|
||||
with patch.dict(
|
||||
os.environ, {"HTTP_PROXY": proxy_url, "NO_PROXY": ""}, clear=False
|
||||
):
|
||||
status = await api.validate_key()
|
||||
|
||||
self.assertEqual(status, PlusKeyStatus.valid)
|
||||
self.assertEqual(proxied, ["http://plus.invalid/v1/auth/token"])
|
||||
|
||||
async def test_no_key_is_not_sent_to_the_server(self):
|
||||
requests_seen = []
|
||||
|
||||
async def handler(request: web.Request) -> web.Response:
|
||||
requests_seen.append(request)
|
||||
return web.json_response(self.CACHED_TOKEN)
|
||||
|
||||
api = self._api(await self._serve(handler), key=None)
|
||||
|
||||
self.assertEqual(await api.validate_key(), PlusKeyStatus.not_set)
|
||||
self.assertEqual(requests_seen, [])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
@@ -11,11 +11,14 @@ KeyError on the autotracker thread or silently keep the wrong state:
|
||||
running its motion estimator for a camera that could not autotrack.
|
||||
"""
|
||||
|
||||
import asyncio
|
||||
import unittest
|
||||
from unittest.mock import MagicMock
|
||||
from unittest.mock import AsyncMock, MagicMock
|
||||
|
||||
import numpy as np
|
||||
|
||||
from frigate.camera import PTZMetrics
|
||||
from frigate.config import FrigateConfig
|
||||
from frigate.config import FrigateConfig, ZoomingModeEnum
|
||||
from frigate.config.camera.updater import CameraConfigUpdateEnum
|
||||
from frigate.ptz.autotrack import PtzAutoTracker, calculate_max_target_box
|
||||
|
||||
@@ -123,6 +126,147 @@ class TestAutotrackerDisable(unittest.TestCase):
|
||||
self.assertIs(payload, autotracking)
|
||||
|
||||
|
||||
class TestAutotrackerPrediction(unittest.TestCase):
|
||||
def test_movement_time_uses_the_fitted_intercept_unchanged(self) -> None:
|
||||
tracker = _make_tracker()
|
||||
tracker.intercept = {CAMERA: 0.5}
|
||||
tracker.move_coefficients = {CAMERA: [0.3, 0.8]}
|
||||
|
||||
self.assertAlmostEqual(tracker._predict_movement_time(CAMERA, 0.25, 0.25), 0.7)
|
||||
|
||||
def test_shrinking_box_keeps_a_positive_target_box(self) -> None:
|
||||
# 60 px shrinking 6 px/frame reaches zero after 2 s at 5 fps
|
||||
target_box = self._target_box_for((0, 0, 60, 60), [3, 3, -3, -3], 2.0)
|
||||
|
||||
self.assertGreater(target_box, 0)
|
||||
self.assertTrue(np.isfinite(target_box))
|
||||
|
||||
def test_approaching_object_keeps_its_velocity(self) -> None:
|
||||
# the box grows, so the corners move in opposite directions
|
||||
tracker = _make_tracker()
|
||||
obj = MagicMock()
|
||||
obj.obj_data = {"estimate_velocity": np.array([[-3.0, -4.0], [3.0, 1.0]])}
|
||||
|
||||
valid, velocity = tracker._get_valid_velocity(CAMERA, obj)
|
||||
|
||||
self.assertTrue(valid)
|
||||
self.assertEqual(list(velocity), [-3, -4, 3, 1])
|
||||
|
||||
def test_corners_that_disagree_too_much_are_rejected(self) -> None:
|
||||
tracker = _make_tracker()
|
||||
obj = MagicMock()
|
||||
obj.obj_data = {"estimate_velocity": np.array([[-15.0, 0.0], [15.0, 0.0]])}
|
||||
|
||||
valid, velocity = tracker._get_valid_velocity(CAMERA, obj)
|
||||
|
||||
self.assertFalse(valid)
|
||||
self.assertFalse(np.any(velocity))
|
||||
|
||||
def _target_box(self, velocity: list[float], predicted_time: float) -> float:
|
||||
return self._target_box_for((900, 400, 1000, 600), velocity, predicted_time)
|
||||
|
||||
def _target_box_for(
|
||||
self,
|
||||
box: tuple[int, int, int, int],
|
||||
velocity: list[float],
|
||||
predicted_time: float,
|
||||
) -> float:
|
||||
tracker = _make_tracker()
|
||||
tracker.tracked_object_history = {CAMERA: [{"box": box}]}
|
||||
tracker.tracked_object_metrics = {
|
||||
CAMERA: {"target_box": 0.2, "velocity": np.array(velocity)}
|
||||
}
|
||||
|
||||
return tracker._predict_target_box(CAMERA, predicted_time)
|
||||
|
||||
def test_target_box_grows_with_an_approaching_object(self) -> None:
|
||||
# the 200px height gains 4px per frame at 5 fps for 1 second
|
||||
zoom_factor = 0.3
|
||||
|
||||
self.assertAlmostEqual(
|
||||
self._target_box([-1, -2, 1, 2], 1.0),
|
||||
0.2 * (220 / 200) ** (2 * zoom_factor),
|
||||
)
|
||||
|
||||
def test_target_box_is_unchanged_without_growth_or_time(self) -> None:
|
||||
self.assertAlmostEqual(self._target_box([5, 0, 5, 0], 1.0), 0.2)
|
||||
self.assertEqual(self._target_box([-1, -2, 1, 2], 0), 0.2)
|
||||
|
||||
|
||||
class TestAutotrackerCalibrationFailure(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_calibration_failure_disables_autotracking(self) -> None:
|
||||
tracker = _make_tracker()
|
||||
camera_config = tracker.config.cameras[CAMERA]
|
||||
camera_config.onvif.autotracking.calibrate_on_startup = True
|
||||
tracker.tracked_object_history = {}
|
||||
tracker.tracked_object_metrics = {}
|
||||
tracker.move_metrics = {}
|
||||
tracker.intercept = {}
|
||||
tracker.move_coefficients = {}
|
||||
tracker.zoom_time = {}
|
||||
tracker.move_queues = {}
|
||||
tracker.move_queue_locks = {}
|
||||
tracker.onvif.loop = asyncio.get_running_loop()
|
||||
tracker.onvif.cams = {CAMERA: {"init": True, "features": ["pt-r-fov"]}}
|
||||
tracker.onvif.get_service_capabilities = AsyncMock(return_value=True)
|
||||
tracker.onvif.get_camera_status = AsyncMock()
|
||||
tracker._process_move_queue = AsyncMock()
|
||||
tracker._calibrate_camera = AsyncMock(side_effect=RuntimeError("disconnected"))
|
||||
tracker.autotracker_init[CAMERA] = False
|
||||
|
||||
with self.assertLogs("frigate.ptz.autotrack", level="ERROR"):
|
||||
await tracker._autotracker_setup(camera_config, CAMERA, startup=True)
|
||||
|
||||
self.assertFalse(camera_config.onvif.autotracking.enabled)
|
||||
self.assertFalse(tracker.autotracker_init[CAMERA])
|
||||
self.assertFalse(tracker.calibrating[CAMERA])
|
||||
|
||||
|
||||
class TestAutotrackerMoveQueue(unittest.IsolatedAsyncioTestCase):
|
||||
async def test_absolute_zoom_does_not_overwrite_the_pan_tilt_sample(self) -> None:
|
||||
tracker = _make_tracker()
|
||||
autotracking = tracker.config.cameras[CAMERA].onvif.autotracking
|
||||
autotracking.zooming = ZoomingModeEnum.absolute
|
||||
autotracking.calibrate_on_startup = True
|
||||
metrics = tracker.ptz_metrics[CAMERA]
|
||||
|
||||
tracker.stop_event = MagicMock()
|
||||
tracker.stop_event.is_set.side_effect = [False, True]
|
||||
tracker.move_queues = {CAMERA: asyncio.Queue()}
|
||||
tracker.move_queue_locks = {CAMERA: asyncio.Lock()}
|
||||
tracker.intercept = {CAMERA: 0.5}
|
||||
tracker.move_metrics = {CAMERA: []}
|
||||
tracker._wait_until_stopped = AsyncMock()
|
||||
tracker._calculate_move_coefficients = MagicMock()
|
||||
|
||||
async def move_relative(*_args) -> None:
|
||||
metrics.start_time.value = 100.0
|
||||
metrics.stop_time.value = 102.0
|
||||
|
||||
async def zoom_absolute(*_args) -> None:
|
||||
metrics.start_time.value = 103.0
|
||||
metrics.stop_time.value = 0
|
||||
|
||||
tracker.onvif._move_relative = AsyncMock(side_effect=move_relative)
|
||||
tracker.onvif._zoom_absolute = AsyncMock(side_effect=zoom_absolute)
|
||||
|
||||
tracker.move_queues[CAMERA].put_nowait((50.0, 0.5, 0.5, 0.5))
|
||||
await tracker._process_move_queue(CAMERA)
|
||||
|
||||
tracker.onvif._zoom_absolute.assert_awaited_once()
|
||||
self.assertEqual(
|
||||
tracker.move_metrics[CAMERA],
|
||||
[
|
||||
{
|
||||
"pan": 0.5,
|
||||
"tilt": 0.5,
|
||||
"start_timestamp": 100.0,
|
||||
"end_timestamp": 102.0,
|
||||
}
|
||||
],
|
||||
)
|
||||
|
||||
|
||||
class TestMaxTargetBox(unittest.TestCase):
|
||||
def test_follows_zoom_factor(self) -> None:
|
||||
self.assertAlmostEqual(calculate_max_target_box(0.5), 0.6**2)
|
||||
|
||||
@@ -862,20 +862,41 @@ class TestSplitDetectionLabels(ReviewFlowTestCase):
|
||||
|
||||
class TestManualEvents(ReviewFlowTestCase):
|
||||
def manual_event(
|
||||
self, event_id: str, frame_time: float, sub_label: str | None = None
|
||||
self,
|
||||
event_id: str,
|
||||
frame_time: float,
|
||||
sub_label: str | None = None,
|
||||
state: ManualEventState = ManualEventState.complete,
|
||||
) -> tuple[str, tuple[Any, ...]]:
|
||||
"""Build a completed manual event as published by the object processor."""
|
||||
"""Build a manual event as published by the object processor."""
|
||||
return (
|
||||
DetectionTypeEnum.api.value,
|
||||
(
|
||||
CAMERA,
|
||||
frame_time,
|
||||
{
|
||||
"state": ManualEventState.complete,
|
||||
"state": state,
|
||||
"label": "person",
|
||||
"sub_label": sub_label,
|
||||
"event_id": event_id,
|
||||
"end_time": frame_time + 5,
|
||||
"end_time": (
|
||||
frame_time + 5 if state == ManualEventState.complete else None
|
||||
),
|
||||
},
|
||||
),
|
||||
)
|
||||
|
||||
def end_event(self, event_id: str, end_time: float) -> tuple[str, tuple[Any, ...]]:
|
||||
"""Build the end message the events API publishes, which has no label."""
|
||||
return (
|
||||
DetectionTypeEnum.api.value,
|
||||
(
|
||||
CAMERA,
|
||||
end_time,
|
||||
{
|
||||
"state": ManualEventState.end,
|
||||
"event_id": event_id,
|
||||
"end_time": end_time,
|
||||
},
|
||||
),
|
||||
)
|
||||
@@ -900,6 +921,41 @@ class TestManualEvents(ReviewFlowTestCase):
|
||||
self.assertCountEqual(data["objects"], ["dog", "person-verified", "person"])
|
||||
self.assertEqual(data["sub_labels"], ["Bob"])
|
||||
|
||||
def test_ending_event_after_its_segment_closed_is_ignored(self) -> None:
|
||||
self.feed_messages(self.manual_event("m1", 1, state=ManualEventState.start))
|
||||
self.maintainer.config_subscriber.check_for_updates.side_effect = [
|
||||
{"record": [CAMERA]}
|
||||
]
|
||||
self.feed()
|
||||
self.maintainer.config_subscriber.check_for_updates.side_effect = None
|
||||
self.feed_messages(self.end_event("m1", 20), self.manual_event("m2", 30))
|
||||
|
||||
self.assertEqual(self.non_update_summary(), [("end", "alert")])
|
||||
segment = self.maintainer.active_review_segments[CAMERA]
|
||||
self.assertEqual(segment.detections, {"m2": "person"})
|
||||
|
||||
def test_ending_event_after_its_segment_ended_early_clears_it(self) -> None:
|
||||
# a completed event ends the indefinite event's segment early
|
||||
self.feed_messages(
|
||||
self.manual_event("m1", 1, state=ManualEventState.start),
|
||||
self.manual_event("m2", 2),
|
||||
)
|
||||
self.feed((8, []), (8 + self.alert_cutoff, []))
|
||||
self.assertIsNone(self.maintainer.active_review_segments.get(CAMERA))
|
||||
|
||||
self.feed_messages(
|
||||
self.end_event("m1", 100),
|
||||
self.manual_event("m3", 200, state=ManualEventState.start),
|
||||
self.end_event("m3", 210),
|
||||
)
|
||||
self.feed((210 + self.alert_cutoff + 1, []))
|
||||
|
||||
self.assertEqual(self.maintainer.indefinite_events[CAMERA], {})
|
||||
self.assertIsNone(self.maintainer.active_review_segments.get(CAMERA))
|
||||
self.assertEqual(
|
||||
self.non_update_summary(), [("end", "alert"), ("end", "alert")]
|
||||
)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
"""Tests for reading Rockchip GPU and NPU load as root and as a non-root user."""
|
||||
|
||||
import builtins
|
||||
import os
|
||||
import tempfile
|
||||
import unittest
|
||||
from pathlib import Path
|
||||
from unittest.mock import patch
|
||||
|
||||
from frigate.util import services
|
||||
from frigate.util.services import get_rockchip_gpu_stats, get_rockchip_npu_stats
|
||||
|
||||
NPU_LOAD = "NPU load: Core0: 10%, Core1: 20%, Core2: 30%,\n"
|
||||
RGA_LOAD = (
|
||||
"num of scheduler = 2\n"
|
||||
"================= load ==================\n"
|
||||
"scheduler[0]: rga3\n\t load = 40%\n"
|
||||
"scheduler[1]: rga2\n\t load = 60%\n"
|
||||
)
|
||||
|
||||
|
||||
class TestRockchipStats(unittest.TestCase):
|
||||
def setUp(self):
|
||||
services._rockchip_load_warning_logged = False
|
||||
|
||||
tmp = tempfile.TemporaryDirectory()
|
||||
self.addCleanup(tmp.cleanup)
|
||||
self.debugfs = Path(tmp.name, "debugfs")
|
||||
self.bound = Path(tmp.name, "rockchip")
|
||||
self.debugfs.mkdir()
|
||||
|
||||
for name, value in (
|
||||
("ROCKCHIP_DEBUGFS_DIR", str(self.debugfs)),
|
||||
("ROCKCHIP_LOAD_DIR", str(self.bound)),
|
||||
):
|
||||
patcher = patch.object(services, name, value)
|
||||
patcher.start()
|
||||
self.addCleanup(patcher.stop)
|
||||
|
||||
warn = patch.object(services.logger, "warning")
|
||||
self.warn = warn.start()
|
||||
self.addCleanup(warn.stop)
|
||||
|
||||
def _write(self, base: Path, driver: str, content: str) -> None:
|
||||
Path(base, driver).mkdir(parents=True, exist_ok=True)
|
||||
Path(base, driver, "load").write_text(content)
|
||||
|
||||
def _deny_debugfs(self):
|
||||
"""Fail opens under debugfs the way its root-only directory does."""
|
||||
debugfs = str(self.debugfs)
|
||||
|
||||
def guarded_open(path, *args, **kwargs):
|
||||
if os.fspath(path).startswith(debugfs):
|
||||
raise PermissionError(13, "Permission denied", path)
|
||||
return builtins.open(path, *args, **kwargs)
|
||||
|
||||
return patch("frigate.util.services.open", guarded_open, create=True)
|
||||
|
||||
def test_reads_debugfs_when_accessible(self):
|
||||
self._write(self.debugfs, "rknpu", NPU_LOAD)
|
||||
self._write(self.debugfs, "rkrga", RGA_LOAD)
|
||||
|
||||
self.assertEqual(20.0, get_rockchip_npu_stats()["npu"])
|
||||
self.assertEqual("50.0%", get_rockchip_gpu_stats()["gpu"])
|
||||
self.warn.assert_not_called()
|
||||
|
||||
def test_missing_drivers_report_nothing_without_warning(self):
|
||||
self.assertIsNone(get_rockchip_npu_stats())
|
||||
self.assertIsNone(get_rockchip_gpu_stats())
|
||||
self.warn.assert_not_called()
|
||||
|
||||
def test_reads_bound_files_when_debugfs_is_denied(self):
|
||||
self._write(self.debugfs, "rknpu", NPU_LOAD)
|
||||
self._write(self.debugfs, "rkrga", RGA_LOAD)
|
||||
self._write(self.bound, "rknpu", NPU_LOAD)
|
||||
self._write(self.bound, "rkrga", RGA_LOAD)
|
||||
|
||||
with self._deny_debugfs():
|
||||
self.assertEqual(20.0, get_rockchip_npu_stats()["npu"])
|
||||
self.assertEqual("50.0%", get_rockchip_gpu_stats()["gpu"])
|
||||
|
||||
self.warn.assert_not_called()
|
||||
|
||||
def test_warns_once_when_denied_and_nothing_is_bound(self):
|
||||
self._write(self.debugfs, "rknpu", NPU_LOAD)
|
||||
self._write(self.debugfs, "rkrga", RGA_LOAD)
|
||||
|
||||
with self._deny_debugfs():
|
||||
for _ in range(2):
|
||||
self.assertIsNone(get_rockchip_npu_stats())
|
||||
self.assertIsNone(get_rockchip_gpu_stats())
|
||||
|
||||
self.warn.assert_called_once()
|
||||
|
||||
def test_binding_only_the_present_driver_does_not_warn(self):
|
||||
# a board without RGA in debugfs binds only the NPU load file
|
||||
self._write(self.debugfs, "rknpu", NPU_LOAD)
|
||||
self._write(self.bound, "rknpu", NPU_LOAD)
|
||||
|
||||
with self._deny_debugfs():
|
||||
self.assertEqual(20.0, get_rockchip_npu_stats()["npu"])
|
||||
self.assertIsNone(get_rockchip_gpu_stats())
|
||||
|
||||
self.warn.assert_not_called()
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main()
|
||||
@@ -140,6 +140,9 @@ class TestLoadRegistry(unittest.TestCase):
|
||||
spinning = None
|
||||
|
||||
self.assertEqual(spinning, expected)
|
||||
self.assertEqual(
|
||||
options.enable_cpu_mem_arena, provider != "CPUExecutionProvider"
|
||||
)
|
||||
|
||||
|
||||
class TestLoadedDeviceSnapshot(unittest.TestCase):
|
||||
@@ -321,6 +324,36 @@ class TestLighterANE(unittest.TestCase):
|
||||
ane.assert_not_called()
|
||||
|
||||
|
||||
class TestTensorRTProvider(unittest.TestCase):
|
||||
def _trt_options(self, env):
|
||||
with (
|
||||
patch.object(
|
||||
model_util.ort,
|
||||
"get_available_providers",
|
||||
return_value=["TensorrtExecutionProvider", "CPUExecutionProvider"],
|
||||
),
|
||||
patch.object(model_util.os, "makedirs"),
|
||||
patch.dict(os.environ, env, clear=False),
|
||||
):
|
||||
if "USE_FP16" not in env:
|
||||
os.environ.pop("USE_FP16", None)
|
||||
providers, options = model_util.get_ort_providers(device="Tensorrt")
|
||||
|
||||
return options[providers.index("TensorrtExecutionProvider")]
|
||||
|
||||
def test_fp16_is_disabled_by_default(self):
|
||||
self.assertFalse(self._trt_options({})["trt_fp16_enable"])
|
||||
|
||||
def test_use_fp16_enables_fp16(self):
|
||||
for value in ("true", "True", "TRUE"):
|
||||
with self.subTest(value=value):
|
||||
options = self._trt_options({"USE_FP16": value})
|
||||
self.assertTrue(options["trt_fp16_enable"])
|
||||
|
||||
def test_use_fp16_false_keeps_fp16_disabled(self):
|
||||
self.assertFalse(self._trt_options({"USE_FP16": "False"})["trt_fp16_enable"])
|
||||
|
||||
|
||||
class TestMIGraphX(unittest.TestCase):
|
||||
"""AMD's MIGraphX plugin provider, selected through its devices in the ROCm image."""
|
||||
|
||||
@@ -530,4 +563,4 @@ class TestMIGraphX(unittest.TestCase):
|
||||
providers, options = model_util.get_ort_providers()
|
||||
|
||||
self.assertEqual(providers, ["CPUExecutionProvider"])
|
||||
self.assertEqual(options, [{"enable_cpu_mem_arena": False}])
|
||||
self.assertEqual(options, [{}])
|
||||
|
||||
@@ -91,6 +91,7 @@ class TrackedObjectProcessor(threading.Thread):
|
||||
CameraConfigUpdateEnum.enabled,
|
||||
CameraConfigUpdateEnum.motion,
|
||||
CameraConfigUpdateEnum.objects,
|
||||
CameraConfigUpdateEnum.refresh,
|
||||
CameraConfigUpdateEnum.remove,
|
||||
CameraConfigUpdateEnum.timestamp_style,
|
||||
CameraConfigUpdateEnum.zones,
|
||||
@@ -784,6 +785,21 @@ class TrackedObjectProcessor(threading.Thread):
|
||||
|
||||
self.requestor.send_data(UPDATE_CAMERA_ACTIVITY, self.camera_activity)
|
||||
|
||||
# a replay camera recycled onto another scene's model needs new state
|
||||
for camera in updated_topics.get("refresh", []):
|
||||
camera_state = self.camera_states.get(camera)
|
||||
|
||||
if (
|
||||
camera_state is None
|
||||
or camera_state.model is self.config.model_for_camera(camera)
|
||||
):
|
||||
continue
|
||||
|
||||
self.force_end_all_events(camera, camera_state)
|
||||
camera_state.shutdown()
|
||||
self.frame_manager.close_camera(camera)
|
||||
self.create_camera_state(camera)
|
||||
|
||||
# manage camera disabled state
|
||||
for camera, config in self.config.cameras.items():
|
||||
if not config.enabled_in_config:
|
||||
|
||||
@@ -9,6 +9,7 @@ import queue
|
||||
import re
|
||||
import shlex
|
||||
import struct
|
||||
import threading
|
||||
import time
|
||||
import urllib.parse
|
||||
from collections import deque
|
||||
@@ -42,6 +43,7 @@ class EventsPerSecond:
|
||||
self._max_events = max_events
|
||||
self._last_n_seconds = last_n_seconds
|
||||
self._timestamps: deque[float] = deque(maxlen=max_events)
|
||||
self._lock = threading.Lock()
|
||||
|
||||
def start(self) -> None:
|
||||
self._start = time.monotonic()
|
||||
@@ -71,6 +73,9 @@ class EventsPerSecond:
|
||||
# remove aged out timestamps
|
||||
def expire_timestamps(self, now: float) -> None:
|
||||
threshold = now - self._last_n_seconds
|
||||
|
||||
# update() and eps() can run on different threads
|
||||
with self._lock:
|
||||
while self._timestamps and self._timestamps[0] < threshold:
|
||||
self._timestamps.popleft()
|
||||
|
||||
|
||||
@@ -1,8 +1,8 @@
|
||||
"""Utilities for cleaning up camera data from database and filesystem."""
|
||||
|
||||
import glob
|
||||
import logging
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
|
||||
from frigate.const import CLIPS_DIR, RECORD_DIR, THUMB_DIR
|
||||
@@ -126,33 +126,39 @@ def cleanup_camera_files(
|
||||
except Exception as e:
|
||||
logger.error("Failed to remove %s: %s", dir_path, e)
|
||||
|
||||
# Remove event snapshot files
|
||||
for snapshot in glob.glob(os.path.join(CLIPS_DIR, f"{camera_name}-*.jpg")):
|
||||
try:
|
||||
os.remove(snapshot)
|
||||
except Exception as e:
|
||||
logger.error("Failed to remove snapshot %s: %s", snapshot, e)
|
||||
# Match the whole file name so deleting "front" keeps the files of "front-door"
|
||||
media_id = r"[\d.]+-[a-z0-9]{6}"
|
||||
camera = re.escape(camera_name)
|
||||
media_patterns = [
|
||||
(
|
||||
CLIPS_DIR,
|
||||
re.compile(rf"{camera}-{media_id}(\.jpg|-clean\.webp|-clean\.png)"),
|
||||
),
|
||||
(
|
||||
os.path.join(CLIPS_DIR, "review"),
|
||||
re.compile(rf"thumb-{camera}-{media_id}\.webp"),
|
||||
),
|
||||
]
|
||||
|
||||
for snapshot in glob.glob(os.path.join(CLIPS_DIR, f"{camera_name}-*-clean.webp")):
|
||||
try:
|
||||
os.remove(snapshot)
|
||||
except Exception as e:
|
||||
logger.error("Failed to remove snapshot %s: %s", snapshot, e)
|
||||
for directory, pattern in media_patterns:
|
||||
if not os.path.isdir(directory):
|
||||
continue
|
||||
|
||||
for snapshot in glob.glob(os.path.join(CLIPS_DIR, f"{camera_name}-*-clean.png")):
|
||||
try:
|
||||
os.remove(snapshot)
|
||||
except Exception as e:
|
||||
logger.error("Failed to remove snapshot %s: %s", snapshot, e)
|
||||
files = os.listdir(directory)
|
||||
except OSError as e:
|
||||
logger.error("Failed to list %s: %s", directory, e)
|
||||
continue
|
||||
|
||||
# Remove review thumbnail files
|
||||
for thumb in glob.glob(
|
||||
os.path.join(CLIPS_DIR, "review", f"thumb-{camera_name}-*.webp")
|
||||
):
|
||||
for file in files:
|
||||
if not pattern.fullmatch(file):
|
||||
continue
|
||||
|
||||
path = os.path.join(directory, file)
|
||||
try:
|
||||
os.remove(thumb)
|
||||
os.remove(path)
|
||||
except Exception as e:
|
||||
logger.error("Failed to remove review thumbnail %s: %s", thumb, e)
|
||||
logger.error("Failed to remove media file %s: %s", path, e)
|
||||
|
||||
# Remove export files if requested
|
||||
if export_paths:
|
||||
|
||||
@@ -6,6 +6,7 @@ import logging
|
||||
import os
|
||||
import random
|
||||
import shutil
|
||||
import tempfile
|
||||
from collections import defaultdict
|
||||
|
||||
import cv2
|
||||
@@ -38,10 +39,48 @@ BATCH_SIZE = 16
|
||||
EPOCHS = 50
|
||||
LEARNING_RATE = 0.001
|
||||
TRAINING_METADATA_FILE = ".training_metadata.json"
|
||||
CLASSIFICATION_INPUT_SIZE = (224, 224)
|
||||
|
||||
logger = logging.getLogger(__name__)
|
||||
|
||||
|
||||
def resize_classification_image(image: np.ndarray) -> np.ndarray:
|
||||
"""Resize an image to the classification model input size.
|
||||
|
||||
Training and inference both need to use this, otherwise the model is
|
||||
trained on different pixels than the ones it is later run on.
|
||||
"""
|
||||
return cv2.resize(image, CLASSIFICATION_INPUT_SIZE)
|
||||
|
||||
|
||||
def prepare_training_dataset(dataset_dir: str, output_dir: str) -> None:
|
||||
"""Write a copy of the dataset that is resized the same way as inference.
|
||||
|
||||
The dataset holds crops at their original size. Keras would resize them
|
||||
with nearest neighbor while inference uses cv2, so the images are resized
|
||||
here and Keras is given images that are already the model input size.
|
||||
"""
|
||||
for class_name in os.listdir(dataset_dir):
|
||||
class_dir = os.path.join(dataset_dir, class_name)
|
||||
|
||||
if not os.path.isdir(class_dir):
|
||||
continue
|
||||
|
||||
output_class_dir = os.path.join(output_dir, class_name)
|
||||
os.makedirs(output_class_dir, exist_ok=True)
|
||||
|
||||
for file in os.listdir(class_dir):
|
||||
img = cv2.imread(os.path.join(class_dir, file))
|
||||
|
||||
if img is None:
|
||||
continue
|
||||
|
||||
output_path = os.path.join(output_class_dir, file)
|
||||
|
||||
if not cv2.imwrite(output_path, resize_classification_image(img)):
|
||||
raise OSError(f"Failed to write training image {output_path}")
|
||||
|
||||
|
||||
def write_training_metadata(model_name: str, image_count: int) -> None:
|
||||
"""
|
||||
Write training metadata to a hidden file in the model's clips directory.
|
||||
@@ -160,7 +199,7 @@ class ClassificationTrainingProcess(FrigateProcess):
|
||||
for path in image_paths[:300]:
|
||||
img = cv2.imread(path)
|
||||
img = cv2.cvtColor(img, cv2.COLOR_BGR2RGB)
|
||||
img = cv2.resize(img, (224, 224))
|
||||
img = resize_classification_image(img)
|
||||
img_array = np.array(img, dtype=np.float32) / 255.0
|
||||
img_array = img_array[None, ...]
|
||||
yield [img_array]
|
||||
@@ -232,11 +271,13 @@ class ClassificationTrainingProcess(FrigateProcess):
|
||||
metrics=["accuracy"],
|
||||
)
|
||||
|
||||
# create training set
|
||||
# create training set, resized the same way as inference
|
||||
with tempfile.TemporaryDirectory() as training_dir:
|
||||
prepare_training_dataset(dataset_dir, training_dir)
|
||||
datagen = ImageDataGenerator(rescale=1.0 / 255, validation_split=0.2)
|
||||
train_gen = datagen.flow_from_directory(
|
||||
dataset_dir,
|
||||
target_size=(224, 224),
|
||||
training_dir,
|
||||
target_size=CLASSIFICATION_INPUT_SIZE,
|
||||
batch_size=BATCH_SIZE,
|
||||
class_mode="categorical",
|
||||
subset="training",
|
||||
@@ -258,6 +299,7 @@ class ClassificationTrainingProcess(FrigateProcess):
|
||||
# train the model
|
||||
logger.debug(f"Training {self.model_name} for {EPOCHS} epochs...")
|
||||
model.fit(train_gen, epochs=EPOCHS, verbose=0)
|
||||
|
||||
logger.debug(f"Converting {self.model_name} to TFLite...")
|
||||
|
||||
# convert model to tflite
|
||||
@@ -602,7 +644,7 @@ def _extract_keyframes(
|
||||
return idx, None
|
||||
|
||||
cropped = img[y1_clipped:y2_clipped, x1_clipped:x2_clipped]
|
||||
resized = cv2.resize(cropped, (224, 224))
|
||||
resized = resize_classification_image(cropped)
|
||||
|
||||
output_path = os.path.join(output_dir, f"frame_{idx:04d}.jpg")
|
||||
cv2.imwrite(output_path, resized)
|
||||
@@ -880,7 +922,7 @@ def _extract_event_thumbnails(
|
||||
if img is None:
|
||||
continue
|
||||
|
||||
resized = cv2.resize(img, (224, 224))
|
||||
resized = resize_classification_image(img)
|
||||
output_path = os.path.join(output_dir, f"thumbnail_{idx:04d}.jpg")
|
||||
cv2.imwrite(output_path, resized)
|
||||
image_paths.append(output_path)
|
||||
|
||||
+33
-18
@@ -1,6 +1,8 @@
|
||||
"""configuration utils."""
|
||||
|
||||
import asyncio
|
||||
import contextlib
|
||||
import errno
|
||||
import ipaddress
|
||||
import logging
|
||||
import os
|
||||
@@ -212,6 +214,28 @@ def find_config_file() -> str:
|
||||
return config_path
|
||||
|
||||
|
||||
def _write_config(config_file: str, yaml: YAML, config: dict[str, Any]) -> None:
|
||||
config_file = os.path.realpath(config_file)
|
||||
st = os.stat(config_file)
|
||||
tmp_file = f"{config_file}.tmp"
|
||||
with open(tmp_file, "w") as f:
|
||||
yaml.dump(config, f)
|
||||
os.chmod(tmp_file, st.st_mode)
|
||||
|
||||
with contextlib.suppress(PermissionError):
|
||||
os.chown(tmp_file, st.st_uid, st.st_gid)
|
||||
|
||||
try:
|
||||
os.replace(tmp_file, config_file)
|
||||
except OSError as e:
|
||||
if e.errno != errno.EBUSY:
|
||||
raise
|
||||
|
||||
# a file bind mount can't be renamed over, so write it in place
|
||||
shutil.copyfile(tmp_file, config_file)
|
||||
os.remove(tmp_file)
|
||||
|
||||
|
||||
def migrate_frigate_config(config_file: str):
|
||||
"""handle migrating the frigate config."""
|
||||
logger.info("Checking if frigate config needs migration...")
|
||||
@@ -259,8 +283,7 @@ def migrate_frigate_config(config_file: str):
|
||||
if previous_version < "0.14":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.14...")
|
||||
new_config = migrate_014(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.14"
|
||||
|
||||
logger.info("Migrating export file names...")
|
||||
@@ -277,56 +300,48 @@ def migrate_frigate_config(config_file: str):
|
||||
if previous_version < "0.15-0":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.15-0...")
|
||||
new_config = migrate_015_0(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.15-0"
|
||||
|
||||
if previous_version < "0.15-1":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.15-1...")
|
||||
new_config = migrate_015_1(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.15-1"
|
||||
|
||||
if previous_version < "0.16-0":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.16-0...")
|
||||
new_config = migrate_016_0(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.16-0"
|
||||
|
||||
if previous_version < "0.17-0":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.17-0...")
|
||||
new_config = migrate_017_0(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.17-0"
|
||||
|
||||
if previous_version < "0.18-0":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.18-0...")
|
||||
new_config = migrate_018_0(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.18-0"
|
||||
|
||||
if previous_version < "0.19-0":
|
||||
logger.info(f"Migrating frigate config from {previous_version} to 0.19-0...")
|
||||
new_config = migrate_019_0(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
previous_version = "0.19-0"
|
||||
|
||||
if needs_models:
|
||||
logger.info("Migrating frigate detectors and model to models...")
|
||||
new_config = migrate_models(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
|
||||
if needs_detector_rename:
|
||||
logger.info("Migrating renamed frigate detectors...")
|
||||
new_config = rename_hailo_detector(new_config)
|
||||
with open(config_file, "w") as f:
|
||||
yaml.dump(new_config, f)
|
||||
_write_config(config_file, yaml, new_config)
|
||||
|
||||
logger.info("Finished frigate config migration...")
|
||||
|
||||
|
||||
+4
-16
@@ -318,17 +318,9 @@ def post_process_yolox(
|
||||
def get_ort_providers(
|
||||
force_cpu: bool = False,
|
||||
device: str | None = "AUTO",
|
||||
requires_fp16: bool = False,
|
||||
) -> tuple[list[str], list[dict[str, Any]]]:
|
||||
if force_cpu:
|
||||
return (
|
||||
["CPUExecutionProvider"],
|
||||
[
|
||||
{
|
||||
"enable_cpu_mem_arena": False,
|
||||
}
|
||||
],
|
||||
)
|
||||
return ["CPUExecutionProvider"], [{}]
|
||||
|
||||
providers = []
|
||||
options = []
|
||||
@@ -357,8 +349,8 @@ def get_ort_providers(
|
||||
options.append(
|
||||
{
|
||||
"device_id": device_id,
|
||||
"trt_fp16_enable": requires_fp16
|
||||
and os.environ.get("USE_FP16", "True") != "False",
|
||||
"trt_fp16_enable": os.environ.get("USE_FP16", "False").lower()
|
||||
== "true",
|
||||
"trt_timing_cache_enable": True,
|
||||
"trt_engine_cache_enable": True,
|
||||
"trt_timing_cache_path": os.path.join(
|
||||
@@ -390,11 +382,7 @@ def get_ort_providers(
|
||||
continue
|
||||
elif provider == "CPUExecutionProvider":
|
||||
providers.append(provider)
|
||||
options.append(
|
||||
{
|
||||
"enable_cpu_mem_arena": False,
|
||||
}
|
||||
)
|
||||
options.append({})
|
||||
elif provider == "AzureExecutionProvider":
|
||||
# Skip Azure provider - not typically available on local hardware
|
||||
# and prevents fallback to OpenVINO when it's the first provider
|
||||
|
||||
@@ -26,6 +26,8 @@ import sys
|
||||
import tarfile
|
||||
import tempfile
|
||||
import zipfile
|
||||
from collections.abc import Iterator
|
||||
from contextlib import contextmanager
|
||||
from dataclasses import dataclass
|
||||
from enum import StrEnum
|
||||
from pathlib import Path
|
||||
@@ -50,6 +52,7 @@ class RuntimeDependencyError(RuntimeError):
|
||||
class ArtifactKind(StrEnum):
|
||||
wheel = "wheel"
|
||||
archive = "archive"
|
||||
deb = "deb" # a Debian package that carries a wheel
|
||||
|
||||
|
||||
class ArchiveDest(StrEnum):
|
||||
@@ -82,6 +85,10 @@ class Artifact:
|
||||
filename: str | None = None
|
||||
mappings: tuple[ArchiveMapping, ...] = ()
|
||||
machines: tuple[str, ...] = ()
|
||||
# basename glob for the wheel a `deb` carries
|
||||
member: str = ""
|
||||
# sha256 of that wheel, pinning the pip input like a wheel artifact does
|
||||
member_sha256: str = ""
|
||||
|
||||
@property
|
||||
def name(self) -> str:
|
||||
@@ -228,6 +235,106 @@ def _stage(path: Path, artifact: Artifact, staging: Path) -> Path:
|
||||
return staged
|
||||
|
||||
|
||||
@contextmanager
|
||||
def _deb_contents(path: Path) -> Iterator[tarfile.TarFile]:
|
||||
"""Stream the filesystem tarball inside a Debian package.
|
||||
|
||||
dpkg-deb decompresses data.tar to stdout, so no archive hits the disk.
|
||||
"""
|
||||
stderr = tempfile.TemporaryFile()
|
||||
|
||||
try:
|
||||
process = subprocess.Popen(
|
||||
["dpkg-deb", "--fsys-tarfile", str(path)],
|
||||
stdout=subprocess.PIPE,
|
||||
stderr=stderr,
|
||||
)
|
||||
except FileNotFoundError as err:
|
||||
stderr.close()
|
||||
raise RuntimeDependencyError(
|
||||
f"dpkg-deb is required to unpack {path.name}; the Frigate image "
|
||||
"ships it as part of dpkg"
|
||||
) from err
|
||||
|
||||
try:
|
||||
assert process.stdout is not None
|
||||
with tarfile.open(fileobj=process.stdout, mode="r|") as archive:
|
||||
yield archive
|
||||
finally:
|
||||
if process.stdout is not None:
|
||||
process.stdout.close()
|
||||
|
||||
returncode = process.wait()
|
||||
stderr.seek(0)
|
||||
message = stderr.read().decode("utf-8", "replace").strip()
|
||||
stderr.close()
|
||||
|
||||
if returncode != 0:
|
||||
raise RuntimeDependencyError(
|
||||
f"Unable to unpack {path.name}: {message[-2000:] or 'dpkg-deb failed'}"
|
||||
)
|
||||
|
||||
|
||||
def _install_deb(path: Path, artifact: Artifact, staging: Path) -> list[str]:
|
||||
"""Install a Debian package's mapped files and the wheel it carries.
|
||||
|
||||
The rest of the package belongs on the host, not in the image. The
|
||||
package itself stays in the cache so later reinstalls need no download.
|
||||
"""
|
||||
machine = platform.machine()
|
||||
mappings = [m for m in artifact.mappings if not m.machines or machine in m.machines]
|
||||
written: list[str] = []
|
||||
wheel: Path | None = None
|
||||
|
||||
with _deb_contents(path) as archive:
|
||||
for member in archive:
|
||||
if not (member.isfile() or member.issym()):
|
||||
continue
|
||||
|
||||
for mapping, relative in _mappings_for(member.name, mappings):
|
||||
dest = _safe_dest(_dest_root(mapping), relative)
|
||||
|
||||
if member.issym():
|
||||
_write_symlink(dest, member.linkname)
|
||||
else:
|
||||
source = archive.extractfile(member)
|
||||
assert source is not None
|
||||
with source:
|
||||
_write_member(dest, source, member.mode)
|
||||
|
||||
written.append(str(dest))
|
||||
|
||||
if not artifact.member or wheel is not None or not member.isfile():
|
||||
continue
|
||||
|
||||
name = os.path.basename(member.name)
|
||||
|
||||
if not fnmatch.fnmatch(name, artifact.member):
|
||||
continue
|
||||
|
||||
source = archive.extractfile(member)
|
||||
assert source is not None
|
||||
wheel = staging / name
|
||||
|
||||
with source, open(wheel, "wb") as f:
|
||||
shutil.copyfileobj(source, f)
|
||||
|
||||
if artifact.member and wheel is None:
|
||||
raise RuntimeDependencyError(
|
||||
f"{path.name} does not contain a file matching {artifact.member}"
|
||||
)
|
||||
|
||||
if wheel is not None:
|
||||
if artifact.member_sha256 and sha256_of(wheel) != artifact.member_sha256:
|
||||
raise RuntimeDependencyError(
|
||||
f"Checksum mismatch for the wheel carried by {path.name}"
|
||||
)
|
||||
|
||||
_install_wheel(wheel)
|
||||
|
||||
return written
|
||||
|
||||
|
||||
def _install_wheel(path: Path) -> None:
|
||||
result = subprocess.run(
|
||||
[
|
||||
@@ -518,13 +625,16 @@ def ensure_installed(manifest: RuntimeManifest) -> None:
|
||||
_remove_stamped_files(stamp)
|
||||
staging = Path(tempfile.mkdtemp(prefix=f"frigate-{manifest.name}-"))
|
||||
files: list[str] = []
|
||||
artifacts = _artifacts_for_machine(manifest)
|
||||
|
||||
try:
|
||||
for artifact in _artifacts_for_machine(manifest):
|
||||
for artifact in artifacts:
|
||||
staged = _stage(_fetch(artifact, cache), artifact, staging)
|
||||
|
||||
if artifact.kind is ArtifactKind.wheel:
|
||||
_install_wheel(staged)
|
||||
elif artifact.kind is ArtifactKind.deb:
|
||||
files.extend(_install_deb(staged, artifact, staging))
|
||||
else:
|
||||
files.extend(_extract_archive(staged, artifact))
|
||||
except (OSError, tarfile.TarError, zipfile.BadZipFile) as err:
|
||||
|
||||
+77
-19
@@ -744,12 +744,60 @@ def get_openvino_npu_stats() -> dict[str, str] | None:
|
||||
return None
|
||||
|
||||
|
||||
ROCKCHIP_DEBUGFS_DIR = "/sys/kernel/debug"
|
||||
# debugfs is root-only, so a non-root install binds the driver load files here
|
||||
ROCKCHIP_LOAD_DIR = "/rockchip"
|
||||
|
||||
_rockchip_load_warning_logged = False
|
||||
|
||||
|
||||
def _read_rockchip_load(driver: str) -> str | None:
|
||||
"""Read a Rockchip driver's load file.
|
||||
|
||||
The kernel makes debugfs readable only by root, so when Frigate isn't
|
||||
root the file is read from where the compose file binds it instead.
|
||||
|
||||
Args:
|
||||
driver: The driver's debugfs directory, rknpu or rkrga
|
||||
|
||||
Returns:
|
||||
The file's contents, or None if neither location could be read
|
||||
"""
|
||||
global _rockchip_load_warning_logged
|
||||
|
||||
denied = False
|
||||
for base in (ROCKCHIP_DEBUGFS_DIR, ROCKCHIP_LOAD_DIR):
|
||||
try:
|
||||
with open(os.path.join(base, driver, "load")) as f:
|
||||
return f.read()
|
||||
except PermissionError:
|
||||
denied = True
|
||||
except OSError:
|
||||
continue
|
||||
|
||||
# a board without one of the drivers binds only the file it has, so
|
||||
# warn only when nothing is bound at all
|
||||
if (
|
||||
denied
|
||||
and not _rockchip_load_warning_logged
|
||||
and not os.path.isdir(ROCKCHIP_LOAD_DIR)
|
||||
):
|
||||
logger.warning(
|
||||
"Rockchip GPU and NPU usage stats are unavailable because %s is only "
|
||||
"readable by root; bind the load files into the container to enable "
|
||||
"them, see https://docs.frigate.video/frigate/installation#rockchip-platform",
|
||||
ROCKCHIP_DEBUGFS_DIR,
|
||||
)
|
||||
_rockchip_load_warning_logged = True
|
||||
|
||||
return None
|
||||
|
||||
|
||||
def get_rockchip_gpu_stats() -> dict[str, str | float] | None:
|
||||
"""Get GPU stats using rk."""
|
||||
try:
|
||||
with open("/sys/kernel/debug/rkrga/load") as f:
|
||||
content = f.read()
|
||||
except FileNotFoundError:
|
||||
content = _read_rockchip_load("rkrga")
|
||||
|
||||
if content is None:
|
||||
return None
|
||||
|
||||
load_values = []
|
||||
@@ -776,9 +824,10 @@ def get_rockchip_gpu_stats() -> dict[str, str | float] | None:
|
||||
|
||||
def get_rockchip_npu_stats() -> dict[str, float | str] | None:
|
||||
"""Get NPU stats using rk."""
|
||||
try:
|
||||
with open("/sys/kernel/debug/rknpu/load") as f:
|
||||
npu_output = f.read()
|
||||
npu_output = _read_rockchip_load("rknpu")
|
||||
|
||||
if npu_output is None:
|
||||
return None
|
||||
|
||||
if "Core0:" in npu_output:
|
||||
# multi core NPU
|
||||
@@ -786,8 +835,6 @@ def get_rockchip_npu_stats() -> dict[str, float | str] | None:
|
||||
else:
|
||||
# single core NPU
|
||||
core_loads = re.findall(r"NPU load:\s+(\d+)%", npu_output)
|
||||
except FileNotFoundError:
|
||||
core_loads = None
|
||||
|
||||
if not core_loads:
|
||||
return None
|
||||
@@ -1235,14 +1282,15 @@ def find_restricted_go2rtc_stream_changes(
|
||||
|
||||
|
||||
# go2rtc runs `ffmpeg.bin` and `ngrok.command`, and every other `ffmpeg` key is a
|
||||
# template of ffmpeg arguments that `#video=<name>` and friends can reference
|
||||
_GO2RTC_EXEC_SECTIONS = ("ffmpeg", "ngrok")
|
||||
# template of ffmpeg arguments that `#video=<name>` and friends can reference.
|
||||
# `exec.allow_paths` and `echo.allow_paths` choose the binaries go2rtc may run.
|
||||
_GO2RTC_EXEC_SECTIONS = ("ffmpeg", "ngrok", "exec", "echo")
|
||||
|
||||
|
||||
def find_restricted_go2rtc_exec_changes(
|
||||
old_go2rtc: dict[str, Any] | None, new_go2rtc: dict[str, Any] | None
|
||||
) -> list[str]:
|
||||
"""Return the go2rtc ffmpeg and ngrok keys added or changed through the API.
|
||||
"""Return the go2rtc exec-related keys added or changed through the API.
|
||||
|
||||
These are only accepted with arbitrary exec enabled. Keys already in the
|
||||
saved config are left alone, the same as stream sources.
|
||||
@@ -1274,10 +1322,11 @@ def find_restricted_go2rtc_exec_changes(
|
||||
def apply_go2rtc_ffmpeg_config(
|
||||
go2rtc_config: dict[str, Any], ffmpeg_path: str
|
||||
) -> list[str]:
|
||||
"""Set go2rtc's ffmpeg binary for startup.
|
||||
"""Set go2rtc's ffmpeg binary and exec allowlist for startup.
|
||||
|
||||
Unless arbitrary exec is enabled, `ffmpeg.bin` is forced to Frigate's ffmpeg
|
||||
and `ngrok` is removed. Templates in the saved config are kept.
|
||||
Unless arbitrary exec is enabled, `ffmpeg.bin` is forced to Frigate's ffmpeg,
|
||||
`ngrok` is disabled, and go2rtc may only run Frigate's ffmpeg from `exec:` and
|
||||
`echo:` sources. Templates in the saved config are kept.
|
||||
|
||||
Returns:
|
||||
The keys that were overridden or removed
|
||||
@@ -1295,9 +1344,18 @@ def apply_go2rtc_ffmpeg_config(
|
||||
restricted.append("ffmpeg.bin")
|
||||
ffmpeg["bin"] = ffmpeg_path
|
||||
|
||||
if "ngrok" in go2rtc_config and not allowed:
|
||||
restricted.append("ngrok")
|
||||
del go2rtc_config["ngrok"]
|
||||
# go2rtc merges its config files and this one loads last, so setting these
|
||||
# keys also overrides the HomeKit file and anything saved through its API
|
||||
if not allowed:
|
||||
forced = {
|
||||
"ngrok": {"command": ""},
|
||||
"exec": {"allow_paths": [ffmpeg_path]},
|
||||
"echo": {"allow_paths": [ffmpeg_path]},
|
||||
}
|
||||
for key, value in forced.items():
|
||||
if key in go2rtc_config and go2rtc_config[key] != value:
|
||||
restricted.append(key)
|
||||
go2rtc_config[key] = value
|
||||
|
||||
return restricted
|
||||
|
||||
@@ -1307,7 +1365,7 @@ def ffprobe_stream(ffmpeg, path: str, detailed: bool = False) -> sp.CompletedPro
|
||||
clean_path = escape_special_characters(path)
|
||||
|
||||
# Base entries that are always included
|
||||
stream_entries = "codec_long_name,width,height,bit_rate,duration,display_aspect_ratio,avg_frame_rate"
|
||||
stream_entries = "codec_type,codec_long_name,width,height,bit_rate,duration,display_aspect_ratio,avg_frame_rate"
|
||||
|
||||
# Additional detailed entries
|
||||
if detailed:
|
||||
|
||||
@@ -159,6 +159,292 @@ test.describe("Export Page - Overview @high", () => {
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Export Page - Case Card Menu @high", () => {
|
||||
async function openCaseMenu(frigateApp: FrigateApp) {
|
||||
await frigateApp.goto("/export");
|
||||
await frigateApp.page
|
||||
.getByRole("button", { name: "Case options" })
|
||||
.first()
|
||||
.click();
|
||||
const menu = frigateApp.page.getByRole("menu");
|
||||
await expect(menu).toBeVisible();
|
||||
return menu;
|
||||
}
|
||||
|
||||
test("menu offers share, download, edit, and delete", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Share case" }),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Download case" }),
|
||||
).toHaveAttribute("href", /api\/cases\/case-001\/download$/);
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Edit case" }),
|
||||
).toBeVisible();
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Delete case" }),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test("edit opens a prefilled dialog without opening the case", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
await menu.getByRole("menuitem", { name: "Edit case" }).click();
|
||||
|
||||
const dialog = frigateApp.page
|
||||
.getByRole("dialog")
|
||||
.filter({ hasText: "Edit Case" });
|
||||
await expect(dialog).toBeVisible();
|
||||
await expect(dialog.locator("input")).toHaveValue(
|
||||
"Package Theft Investigation",
|
||||
);
|
||||
await expect(
|
||||
frigateApp.page.getByRole("heading", {
|
||||
name: "Package Theft Investigation",
|
||||
}),
|
||||
).toBeHidden();
|
||||
});
|
||||
|
||||
test("delete opens the confirmation dialog", async ({ frigateApp }) => {
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
await menu.getByRole("menuitem", { name: "Delete case" }).click();
|
||||
|
||||
const dialog = frigateApp.page
|
||||
.getByRole("alertdialog")
|
||||
.filter({ hasText: "Delete Case" });
|
||||
await expect(dialog).toBeVisible();
|
||||
await expect(dialog.getByText(/Package Theft Investigation/)).toBeVisible();
|
||||
});
|
||||
|
||||
test("share sends a link that opens the case", async ({ frigateApp }) => {
|
||||
await frigateApp.page.addInitScript(() => {
|
||||
Object.defineProperty(navigator, "share", {
|
||||
configurable: true,
|
||||
value: (data: ShareData) => {
|
||||
(window as unknown as { sharedUrl?: string }).sharedUrl = data.url;
|
||||
return Promise.resolve();
|
||||
},
|
||||
});
|
||||
});
|
||||
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
await menu.getByRole("menuitem", { name: "Share case" }).click();
|
||||
|
||||
const sharedUrl = await frigateApp.page.evaluate(
|
||||
() => (window as unknown as { sharedUrl?: string }).sharedUrl,
|
||||
);
|
||||
expect(sharedUrl).toMatch(/\/export\?caseId=case-001$/);
|
||||
|
||||
await frigateApp.goto("/export?caseId=case-001");
|
||||
await expect(
|
||||
frigateApp.page.getByRole("heading", {
|
||||
name: "Package Theft Investigation",
|
||||
}),
|
||||
).toBeVisible();
|
||||
});
|
||||
|
||||
test("deleting via the card menu leaves body interactive", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
const initialCases = [
|
||||
{
|
||||
id: "case-001",
|
||||
name: "Package Theft Investigation",
|
||||
description: "",
|
||||
created_at: 1775407931.3863528,
|
||||
updated_at: 1775483531.3863528,
|
||||
},
|
||||
];
|
||||
let deleted = false;
|
||||
|
||||
await frigateApp.page.route(/\/api\/cases(?:$|\?|\/)/, async (route) => {
|
||||
const method = route.request().method();
|
||||
|
||||
if (method === "DELETE") {
|
||||
deleted = true;
|
||||
return route.fulfill({ json: { success: true } });
|
||||
}
|
||||
|
||||
if (method === "GET") {
|
||||
return route.fulfill({ json: deleted ? [] : initialCases });
|
||||
}
|
||||
|
||||
return route.fallback();
|
||||
});
|
||||
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
await menu.getByRole("menuitem", { name: "Delete case" }).click();
|
||||
|
||||
const dialog = frigateApp.page.getByRole("alertdialog");
|
||||
await dialog.getByRole("button", { name: /^delete$/i }).click();
|
||||
|
||||
await expect(dialog).toBeHidden();
|
||||
await expect(
|
||||
frigateApp.page.getByText("Package Theft Investigation", { exact: true }),
|
||||
).toBeHidden();
|
||||
await waitForBodyInteractive(frigateApp.page, 5_000);
|
||||
await expectBodyInteractive(frigateApp.page);
|
||||
});
|
||||
|
||||
test("download is disabled while a case export is still encoding", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
await frigateApp.page.route("**/api/export**", (route) =>
|
||||
route.fulfill({
|
||||
json: [
|
||||
{
|
||||
id: "export-done",
|
||||
camera: "front_door",
|
||||
name: "Finished",
|
||||
date: 1775490731,
|
||||
video_path: "/exports/export-done.mp4",
|
||||
thumb_path: "/exports/export-done-thumb.jpg",
|
||||
in_progress: false,
|
||||
export_case_id: "case-001",
|
||||
},
|
||||
{
|
||||
id: "export-encoding",
|
||||
camera: "backyard",
|
||||
name: "Still Encoding",
|
||||
date: 1775490732,
|
||||
video_path: "/exports/export-encoding.mp4",
|
||||
thumb_path: "",
|
||||
in_progress: true,
|
||||
export_case_id: "case-001",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
const download = menu.getByRole("menuitem", { name: "Download case" });
|
||||
await expect(download).toHaveAttribute("data-disabled", "");
|
||||
await expect(download).not.toHaveAttribute("href");
|
||||
|
||||
const box = await download.boundingBox();
|
||||
expect(box).not.toBeNull();
|
||||
await frigateApp.page.mouse.click(
|
||||
box!.x + box!.width / 2,
|
||||
box!.y + box!.height / 2,
|
||||
);
|
||||
await expect(
|
||||
frigateApp.page.getByRole("heading", {
|
||||
name: "Package Theft Investigation",
|
||||
}),
|
||||
).toBeHidden();
|
||||
|
||||
await frigateApp.page.keyboard.press("Escape");
|
||||
await frigateApp.goto("/export?caseId=case-001");
|
||||
await expect(
|
||||
frigateApp.page.getByRole("button", { name: "Download" }),
|
||||
).toBeDisabled();
|
||||
});
|
||||
|
||||
test("download is disabled while a case export job is queued", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
await frigateApp.page.route("**/api/jobs/export", (route) =>
|
||||
route.fulfill({
|
||||
json: [
|
||||
{
|
||||
id: "job-queued",
|
||||
job_type: "export",
|
||||
status: "queued",
|
||||
camera: "front_door",
|
||||
name: "Queued Sample",
|
||||
export_case_id: "case-001",
|
||||
request_start_time: 1775407931,
|
||||
request_end_time: 1775408531,
|
||||
start_time: null,
|
||||
end_time: null,
|
||||
error_message: null,
|
||||
results: null,
|
||||
current_step: null,
|
||||
progress_percent: 0,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Download case" }),
|
||||
).toHaveAttribute("data-disabled", "");
|
||||
});
|
||||
|
||||
test("download stays disabled for a running job on a filtered-out camera", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
await frigateApp.page.route("**/api/export**", (route) =>
|
||||
route.fulfill({
|
||||
json: [
|
||||
{
|
||||
id: "export-front",
|
||||
camera: "front_door",
|
||||
name: "Front Finished",
|
||||
date: 1775490731,
|
||||
video_path: "/exports/export-front.mp4",
|
||||
thumb_path: "",
|
||||
in_progress: false,
|
||||
export_case_id: "case-001",
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
await frigateApp.page.route("**/api/jobs/export", (route) =>
|
||||
route.fulfill({
|
||||
json: [
|
||||
{
|
||||
id: "job-backyard",
|
||||
job_type: "export",
|
||||
status: "running",
|
||||
camera: "backyard",
|
||||
name: "Backyard Running",
|
||||
export_case_id: "case-001",
|
||||
request_start_time: 1775407931,
|
||||
request_end_time: 1775408531,
|
||||
start_time: 1775407932,
|
||||
end_time: null,
|
||||
error_message: null,
|
||||
results: null,
|
||||
current_step: "encoding",
|
||||
progress_percent: 10,
|
||||
},
|
||||
],
|
||||
}),
|
||||
);
|
||||
|
||||
await frigateApp.goto("/export?cameras=front_door");
|
||||
await frigateApp.page
|
||||
.getByRole("button", { name: "Case options" })
|
||||
.first()
|
||||
.click();
|
||||
await expect(
|
||||
frigateApp.page.getByRole("menuitem", { name: "Download case" }),
|
||||
).toHaveAttribute("data-disabled", "");
|
||||
});
|
||||
|
||||
test("viewers only see share and download", async ({ frigateApp }) => {
|
||||
await frigateApp.installDefaults({ profile: viewerProfile() });
|
||||
const menu = await openCaseMenu(frigateApp);
|
||||
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Share case" }),
|
||||
).toBeVisible();
|
||||
await expect(menu.getByRole("menuitem", { name: "Edit case" })).toHaveCount(
|
||||
0,
|
||||
);
|
||||
await expect(
|
||||
menu.getByRole("menuitem", { name: "Delete case" }),
|
||||
).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Export Page - Case Detail @high", () => {
|
||||
test("opening a case shows its detail view and associated export", async ({
|
||||
frigateApp,
|
||||
|
||||
@@ -7,6 +7,10 @@
|
||||
*/
|
||||
|
||||
import { test, expect, type FrigateApp } from "../fixtures/frigate-test";
|
||||
import {
|
||||
activeSessionStatus,
|
||||
noSessionStatus,
|
||||
} from "../fixtures/mock-data/debug-replay";
|
||||
|
||||
// the selection is seeded around the playback position, so land near the
|
||||
// live edge
|
||||
@@ -183,6 +187,114 @@ test.describe("Debug Replay from History @high", () => {
|
||||
});
|
||||
});
|
||||
|
||||
// both layouts render the same form, so these run on desktop and mobile
|
||||
test.describe("Debug Replay form with an active session @high", () => {
|
||||
test("shows a banner that stops the running session", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
let active = true;
|
||||
let stopCalled = false;
|
||||
|
||||
await frigateApp.installDefaults();
|
||||
await frigateApp.page.route("**/api/debug_replay/status", (route) =>
|
||||
route.fulfill({
|
||||
json: active
|
||||
? activeSessionStatus({ sourceCamera: "front_door" })
|
||||
: noSessionStatus(),
|
||||
}),
|
||||
);
|
||||
await frigateApp.page.route("**/api/debug_replay/stop", (route) => {
|
||||
if (route.request().method() === "POST") {
|
||||
stopCalled = true;
|
||||
active = false;
|
||||
}
|
||||
return route.fulfill({ json: { success: true } });
|
||||
});
|
||||
await openRecordingView(frigateApp);
|
||||
|
||||
const form = await openDebugReplayForm(frigateApp);
|
||||
const banner = form.getByRole("alert");
|
||||
const startButton = form.getByRole("button", { name: "Start Replay" });
|
||||
|
||||
await expect(banner).toContainText(
|
||||
"A debug replay session is already running for Front Door",
|
||||
{ timeout: 5_000 },
|
||||
);
|
||||
await expect(startButton).toBeDisabled();
|
||||
|
||||
await banner.getByRole("button", { name: "Stop Replay" }).click();
|
||||
|
||||
await expect.poll(() => stopCalled, { timeout: 5_000 }).toBe(true);
|
||||
await expect(banner).toBeHidden({ timeout: 5_000 });
|
||||
await expect(startButton).toBeEnabled();
|
||||
});
|
||||
|
||||
test.describe("after the session already ended", () => {
|
||||
// the stop endpoint answers 400 when no session is active, which
|
||||
// Chromium echoes to the console; the text carries no URL, so match the
|
||||
// 400 echo itself
|
||||
test.use({
|
||||
expectedErrors: [
|
||||
/^Failed to load resource: the server responded with a status of 400\b/,
|
||||
],
|
||||
});
|
||||
|
||||
test("stopping clears the banner", async ({ frigateApp }) => {
|
||||
let active = true;
|
||||
|
||||
await frigateApp.installDefaults();
|
||||
await frigateApp.page.route("**/api/debug_replay/status", (route) =>
|
||||
route.fulfill({
|
||||
json: active ? activeSessionStatus() : noSessionStatus(),
|
||||
}),
|
||||
);
|
||||
// the server tore the session down after the form loaded its status,
|
||||
// e.g. because startup failed
|
||||
await frigateApp.page.route("**/api/debug_replay/stop", (route) => {
|
||||
active = false;
|
||||
return route.fulfill({
|
||||
status: 400,
|
||||
json: { success: false, message: "No active replay session" },
|
||||
});
|
||||
});
|
||||
await openRecordingView(frigateApp);
|
||||
|
||||
const form = await openDebugReplayForm(frigateApp);
|
||||
const banner = form.getByRole("alert");
|
||||
|
||||
await expect(banner).toBeVisible({ timeout: 5_000 });
|
||||
await banner.getByRole("button", { name: "Stop Replay" }).click();
|
||||
|
||||
await expect(banner).toBeHidden({ timeout: 5_000 });
|
||||
await expect(
|
||||
form.getByRole("button", { name: "Start Replay" }),
|
||||
).toBeEnabled();
|
||||
await expect(
|
||||
frigateApp.page.getByText(/Failed to stop debug replay/),
|
||||
).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test("shows no banner when nothing is running", async ({ frigateApp }) => {
|
||||
await frigateApp.installDefaults();
|
||||
await frigateApp.page.route("**/api/debug_replay/status", (route) =>
|
||||
route.fulfill({ json: noSessionStatus() }),
|
||||
);
|
||||
await openRecordingView(frigateApp);
|
||||
|
||||
const statusLoaded = frigateApp.page.waitForResponse(
|
||||
"**/api/debug_replay/status",
|
||||
);
|
||||
const form = await openDebugReplayForm(frigateApp);
|
||||
await statusLoaded;
|
||||
|
||||
await expect(
|
||||
form.getByRole("button", { name: "Start Replay" }),
|
||||
).toBeEnabled();
|
||||
await expect(form.getByRole("alert")).toHaveCount(0);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Debug Replay from History — mobile @high @mobile", () => {
|
||||
test("a reselected range lands once and stays put", async ({
|
||||
frigateApp,
|
||||
|
||||
@@ -228,3 +228,89 @@ test.describe("Review — mobile @critical @mobile", () => {
|
||||
await expect(frigateApp.page).toHaveURL(/\/$/);
|
||||
});
|
||||
});
|
||||
|
||||
test.describe("Review select all @high @mobile", () => {
|
||||
// Three unreviewed alerts so that selecting one item leaves more to select.
|
||||
const now = Date.now() / 1000;
|
||||
const selectAllReviews = Array.from({ length: 3 }, (_, i) => ({
|
||||
id: `select-all-review-${i}`,
|
||||
camera: "front_door",
|
||||
start_time: now - 600 - i * 300,
|
||||
end_time: now - 580 - i * 300,
|
||||
has_been_reviewed: false,
|
||||
severity: "alert",
|
||||
thumb_path: `/clips/front_door/select-all-review-${i}-thumb.jpg`,
|
||||
data: {
|
||||
audio: [],
|
||||
detections: [`person-${i}`],
|
||||
objects: ["person"],
|
||||
sub_labels: [],
|
||||
significant_motion_areas: [],
|
||||
zones: ["front_yard"],
|
||||
},
|
||||
}));
|
||||
|
||||
test.beforeEach(async ({ frigateApp }) => {
|
||||
await frigateApp.page.route(/\/api\/review(\?|$)/, (route) =>
|
||||
route.fulfill({ json: selectAllReviews }),
|
||||
);
|
||||
await frigateApp.page.route(/\/api\/review\/summary/, (route) =>
|
||||
route.fulfill({
|
||||
json: {
|
||||
last24Hours: {
|
||||
reviewed_alert: 0,
|
||||
reviewed_detection: 0,
|
||||
total_alert: selectAllReviews.length,
|
||||
total_detection: 0,
|
||||
},
|
||||
},
|
||||
}),
|
||||
);
|
||||
});
|
||||
|
||||
test("mobile action group selects every review item", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
test.skip(!frigateApp.isMobile, "Mobile-only");
|
||||
|
||||
await frigateApp.goto("/review");
|
||||
const review = new ReviewPage(frigateApp.page, false);
|
||||
const thumbnail = review.reviewItems.first().locator("img").first();
|
||||
await expect(thumbnail).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// The mobile project uses an iOS user agent, where a long press
|
||||
// (touchstart held past the use-contextmenu delay) starts selection.
|
||||
await thumbnail.dispatchEvent("touchstart");
|
||||
await expect(frigateApp.page.getByText(/1.*selected/i)).toBeVisible({
|
||||
timeout: 5_000,
|
||||
});
|
||||
|
||||
const selectAll = frigateApp.page.getByText("All", { exact: true });
|
||||
await expect(selectAll).toBeVisible();
|
||||
await selectAll.click();
|
||||
|
||||
await expect(frigateApp.page.getByText(/3.*selected/i)).toBeVisible();
|
||||
// Nothing is left to select, so the control goes away.
|
||||
await expect(selectAll).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("desktop action group has no select all control", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
test.skip(frigateApp.isMobile, "Desktop-only");
|
||||
|
||||
await frigateApp.goto("/review");
|
||||
const review = new ReviewPage(frigateApp.page, true);
|
||||
await expect(review.reviewItems.first()).toBeVisible({ timeout: 10_000 });
|
||||
|
||||
// PreviewThumbnailPlayer reads e.metaKey to start multi-select.
|
||||
await review.reviewItems.first().click({ modifiers: ["Meta"] });
|
||||
await expect(frigateApp.page.getByText(/1.*selected/i)).toBeVisible({
|
||||
timeout: 5_000,
|
||||
});
|
||||
|
||||
await expect(frigateApp.page.getByText("All", { exact: true })).toHaveCount(
|
||||
0,
|
||||
);
|
||||
});
|
||||
});
|
||||
|
||||
Generated
+314
-231
File diff suppressed because it is too large
Load Diff
+16
-15
@@ -22,7 +22,7 @@
|
||||
},
|
||||
"dependencies": {
|
||||
"@cycjimmy/jsmpeg-player": "^7.0.0",
|
||||
"@hookform/resolvers": "^7.0.3",
|
||||
"@hookform/resolvers": "^7.0.6",
|
||||
"@radix-ui/react-alert-dialog": "^1.2.1",
|
||||
"@radix-ui/react-aspect-ratio": "^1.2.0",
|
||||
"@radix-ui/react-checkbox": "^1.4.1",
|
||||
@@ -49,23 +49,24 @@
|
||||
"@rjsf/shadcn": "^6.11.1",
|
||||
"@rjsf/utils": "^6.10.1",
|
||||
"@rjsf/validator-ajv8": "^6.11.1",
|
||||
"apexcharts": "^8.7.0",
|
||||
"axios": "^1.21.0",
|
||||
"apexcharts": "^8.8.1",
|
||||
"axios": "^1.21.1",
|
||||
"class-variance-authority": "^0.7.1",
|
||||
"clsx": "^2.1.1",
|
||||
"cmdk": "^1.0.0",
|
||||
"copy-to-clipboard": "^4.0.2",
|
||||
"date-fns": "^4.4.0",
|
||||
"date-fns-tz": "^3.2.0",
|
||||
"framer-motion": "^14.9.1",
|
||||
"framer-motion": "^14.12.0",
|
||||
"heic-to": "^1.6.7",
|
||||
"hls.js": "^1.7.4",
|
||||
"i18next": "^26.7.1",
|
||||
"i18next": "^27.1.1",
|
||||
"i18next-http-backend": "^4.0.10",
|
||||
"idb-keyval": "^6.3.0",
|
||||
"js-yaml": "^5.5.0",
|
||||
"konva": "^10.9.1",
|
||||
"lodash": "^4.18.1",
|
||||
"lucide-react": "^1.69.0",
|
||||
"lucide-react": "^1.72.0",
|
||||
"monaco-yaml": "^5.5.1",
|
||||
"next-themes": "^0.4.6",
|
||||
"nosleep.js": "^0.12.0",
|
||||
@@ -74,10 +75,10 @@
|
||||
"react-day-picker": "^10.0.2",
|
||||
"react-device-detect": "^2.2.3",
|
||||
"react-dom": "^19.3.1",
|
||||
"react-dropzone": "^20.1.4",
|
||||
"react-dropzone": "^20.2.0",
|
||||
"react-grid-layout": "^2.3.0",
|
||||
"react-hook-form": "^7.91.0",
|
||||
"react-i18next": "^17.1.12",
|
||||
"react-hook-form": "^7.92.0",
|
||||
"react-i18next": "^18.0.1",
|
||||
"react-icons": "^5.7.0",
|
||||
"react-konva": "^19.3.2",
|
||||
"react-markdown": "^10.1.0",
|
||||
@@ -85,7 +86,7 @@
|
||||
"react-swipeable": "^7.0.2",
|
||||
"react-zoom-pan-pinch": "3.4.4",
|
||||
"remark-gfm": "^4.0.0",
|
||||
"scroll-into-view-if-needed": "^3.1.0",
|
||||
"scroll-into-view-if-needed": "^3.2.0",
|
||||
"sonner": "^2.0.8",
|
||||
"swr": "^2.5.1",
|
||||
"tailwind-merge": "^2.6.1",
|
||||
@@ -99,13 +100,13 @@
|
||||
},
|
||||
"devDependencies": {
|
||||
"@eslint/js": "^10.0.1",
|
||||
"@playwright/test": "^1.64.1",
|
||||
"@playwright/test": "^1.65.0",
|
||||
"@types/js-yaml": "^4.0.9",
|
||||
"@types/lodash": "^4.17.27",
|
||||
"@types/node": "^26.6.6",
|
||||
"@types/react": "^19.3.0",
|
||||
"@types/react-dom": "^19.3.0",
|
||||
"@vitejs/plugin-react": "^6.2.1",
|
||||
"@vitejs/plugin-react": "^6.3.0",
|
||||
"autoprefixer": "^10.6.2",
|
||||
"esbuild": "^0.28.2",
|
||||
"eslint": "^10.14.0",
|
||||
@@ -118,12 +119,12 @@
|
||||
"monaco-editor": "^0.53.0",
|
||||
"patch-package": "^8.0.1",
|
||||
"postcss": "^8.5.32",
|
||||
"prettier": "^3.9.10",
|
||||
"prettier": "^3.10.1",
|
||||
"prettier-plugin-tailwindcss": "^0.8.1",
|
||||
"tailwindcss": "^3.4.19",
|
||||
"typescript": "^6.0.3",
|
||||
"typescript-eslint": "^8.72.1",
|
||||
"vite": "^8.3.6"
|
||||
"typescript-eslint": "^8.72.2",
|
||||
"vite": "^8.3.8"
|
||||
},
|
||||
"overrides": {
|
||||
"@radix-ui/react-compose-refs": "1.1.2",
|
||||
|
||||
@@ -1289,8 +1289,6 @@
|
||||
},
|
||||
"apiKey": {
|
||||
"title": "Ключ API Frigate+",
|
||||
"validated": "Ключ API Frigate+ выяўлены і правераны",
|
||||
"notValidated": "Ключ API Frigate+ не выяўлены або не правераны",
|
||||
"desc": "Ключ API Frigate+ уключае інтэграцыю з сэрвісам Frigate+.",
|
||||
"plusLink": "Падрабязней пра Frigate+"
|
||||
},
|
||||
|
||||
@@ -1086,8 +1086,6 @@
|
||||
},
|
||||
"apiKey": {
|
||||
"title": "Frigate+ API ključ",
|
||||
"validated": "Frigate+ API ključ je detektovan i validiran",
|
||||
"notValidated": "Frigate+ API ključ nije detektovan ili nije validiran",
|
||||
"desc": "Frigate+ API ključ omogućava integraciju sa uslugom Frigate+.",
|
||||
"plusLink": "Pročitajte više o Frigate+"
|
||||
},
|
||||
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user