mirror of
https://github.com/blakeblackshear/frigate.git
synced 2026-11-29 08:47:08 +03:00
track where each camera's detect resolution came from
The health tab's stream check told users to set the detect resolution whenever a probe returned no size, even when they had already set it, and a camera running on the 1280x720 fallback after a failed startup probe was never flagged unless the stream check was run by hand. The config now records whether the resolution came from the config, a startup probe, or the fallback, and /api/config exposes it per camera. The stream check skips the probe warning when the resolution is set, a camera on the fallback gets a detect settings warning that also shows on the health tab, and cloning detect from a fallback camera no longer copies the fallback size.
This commit is contained in:
@@ -336,6 +336,8 @@ def config(request: Request):
|
||||
for cmd in camera_dict["ffmpeg_cmds"]:
|
||||
cmd["cmd"] = clean_camera_user_pass(" ".join(cmd["cmd"]))
|
||||
|
||||
camera_dict["detect_resolution_source"] = camera.detect_resolution_source
|
||||
|
||||
# masking misses vendor-specific credentials in paths and args, and the
|
||||
# non-admin UI never reads them
|
||||
if not is_admin:
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
import os
|
||||
from enum import Enum
|
||||
from typing import Literal
|
||||
|
||||
from pydantic import Field, PrivateAttr, model_validator
|
||||
|
||||
@@ -208,6 +209,12 @@ class CameraConfig(FrigateBaseModel):
|
||||
|
||||
_ffmpeg_cmds: list[dict[str, list[str]]] = PrivateAttr()
|
||||
|
||||
# "config" when set by the user, "probed" from the stream at startup, or
|
||||
# "default" when the probe failed and the fallback size is in use
|
||||
_detect_resolution_source: Literal["config", "probed", "default"] = PrivateAttr(
|
||||
default="config"
|
||||
)
|
||||
|
||||
def __init__(self, **config):
|
||||
# Set zone colors
|
||||
if "zones" in config:
|
||||
@@ -249,6 +256,10 @@ class CameraConfig(FrigateBaseModel):
|
||||
def ffmpeg_cmds(self) -> list[dict[str, list[str]]]:
|
||||
return self._ffmpeg_cmds
|
||||
|
||||
@property
|
||||
def detect_resolution_source(self) -> Literal["config", "probed", "default"]:
|
||||
return self._detect_resolution_source
|
||||
|
||||
def get_formatted_name(self) -> str:
|
||||
"""Return the friendly name if set, otherwise return a formatted version of the camera name."""
|
||||
if self.friendly_name:
|
||||
|
||||
@@ -1213,6 +1213,11 @@ class FrigateConfig(FrigateBaseModel):
|
||||
if stream_info.get("height")
|
||||
else DEFAULT_DETECT_DIMENSIONS["height"]
|
||||
)
|
||||
camera_config._detect_resolution_source = (
|
||||
"probed"
|
||||
if stream_info.get("width") and stream_info.get("height")
|
||||
else "default"
|
||||
)
|
||||
|
||||
# Warn if detect fps > 10
|
||||
if camera_config.detect.fps > 10 and camera_config.type != "lpr":
|
||||
|
||||
@@ -280,6 +280,7 @@ class TestHttpApp(BaseTestHttp):
|
||||
assert camera["ffmpeg"]["inputs"][0]["input_args"] == auth_header
|
||||
assert camera["ffmpeg"]["input_args"] == auth_header
|
||||
assert camera["ffmpeg_cmds"]
|
||||
assert camera["detect_resolution_source"] == "config"
|
||||
assert config["go2rtc"]["streams"]["front_door"][0] == secret_path
|
||||
assert "webtorrent" in config["go2rtc"]
|
||||
|
||||
|
||||
@@ -2483,5 +2483,45 @@ class TestFfmpegPath(unittest.TestCase):
|
||||
)
|
||||
|
||||
|
||||
class TestDetectResolutionSource(unittest.TestCase):
|
||||
def setUp(self):
|
||||
self.config = {
|
||||
"mqtt": {"host": "mqtt"},
|
||||
"cameras": {
|
||||
"back": {
|
||||
"ffmpeg": {
|
||||
"inputs": [
|
||||
{"path": "rtsp://10.0.0.1:554/video", "roles": ["detect"]}
|
||||
]
|
||||
},
|
||||
}
|
||||
},
|
||||
}
|
||||
|
||||
def test_set_in_config(self):
|
||||
self.config["cameras"]["back"]["detect"] = {"width": 1920, "height": 1080}
|
||||
camera = FrigateConfig(**self.config).cameras["back"]
|
||||
assert camera.detect_resolution_source == "config"
|
||||
|
||||
def test_set_globally(self):
|
||||
self.config["detect"] = {"width": 1920, "height": 1080}
|
||||
camera = FrigateConfig(**self.config).cameras["back"]
|
||||
assert camera.detect_resolution_source == "config"
|
||||
|
||||
@patch(
|
||||
"frigate.config.config.stream_info_retriever.get_stream_info",
|
||||
return_value={"width": 2560, "height": 1440, "fourcc": "h264"},
|
||||
)
|
||||
def test_probed_from_stream(self, _):
|
||||
camera = FrigateConfig(**self.config).cameras["back"]
|
||||
assert camera.detect_resolution_source == "probed"
|
||||
assert (camera.detect.width, camera.detect.height) == (2560, 1440)
|
||||
|
||||
def test_probe_failed_uses_default(self):
|
||||
camera = FrigateConfig(**self.config).cameras["back"]
|
||||
assert camera.detect_resolution_source == "default"
|
||||
assert (camera.detect.width, camera.detect.height) == (1280, 720)
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
unittest.main(verbosity=2)
|
||||
|
||||
@@ -52,22 +52,25 @@ export function deepMerge<T extends Record<string, unknown>>(
|
||||
export const BASE_CONFIG = {
|
||||
...configSnapshot,
|
||||
version: "0.15.0-test",
|
||||
// injected by the /config endpoint rather than the Pydantic model, so it
|
||||
// is absent from the snapshot
|
||||
// injected by the /config endpoint rather than the Pydantic model, so they
|
||||
// are absent from the snapshot, as is each camera's detect_resolution_source
|
||||
plus: { enabled: false },
|
||||
cameras: {
|
||||
...configSnapshot.cameras,
|
||||
front_door: {
|
||||
...configSnapshot.cameras.front_door,
|
||||
friendly_name: "Front Door",
|
||||
detect_resolution_source: "config",
|
||||
},
|
||||
backyard: {
|
||||
...configSnapshot.cameras.backyard,
|
||||
friendly_name: "Backyard",
|
||||
detect_resolution_source: "config",
|
||||
},
|
||||
garage: {
|
||||
...configSnapshot.cameras.garage,
|
||||
friendly_name: "Garage",
|
||||
detect_resolution_source: "config",
|
||||
},
|
||||
},
|
||||
};
|
||||
|
||||
@@ -19,8 +19,19 @@
|
||||
* and no PUT. That path is covered by unit-level review and manual QA.
|
||||
*/
|
||||
|
||||
import { readFileSync } from "node:fs";
|
||||
import { resolve, dirname } from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { test, expect } from "../fixtures/frigate-test";
|
||||
|
||||
const __dirname = dirname(fileURLToPath(import.meta.url));
|
||||
const CONFIG_SCHEMA = JSON.parse(
|
||||
readFileSync(
|
||||
resolve(__dirname, "../fixtures/mock-data/config-schema.json"),
|
||||
"utf-8",
|
||||
),
|
||||
);
|
||||
|
||||
async function openCloneDialog(frigateApp: {
|
||||
page: import("@playwright/test").Page;
|
||||
}) {
|
||||
@@ -137,6 +148,43 @@ test.describe("Camera clone dialog @medium @mobile", () => {
|
||||
).toBeVisible({ timeout: 8_000 });
|
||||
});
|
||||
|
||||
test("does not copy a fallback detect resolution to a new camera", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
await frigateApp.installDefaults({
|
||||
config: {
|
||||
cameras: { front_door: { detect_resolution_source: "default" } },
|
||||
},
|
||||
});
|
||||
// section payloads need the schema, which the default mock leaves empty
|
||||
await frigateApp.page.route("**/api/config/schema.json", (route) =>
|
||||
route.fulfill({ json: CONFIG_SCHEMA }),
|
||||
);
|
||||
const requests: unknown[] = [];
|
||||
await frigateApp.page.route("**/api/config/set", async (route) => {
|
||||
requests.push(route.request().postDataJSON());
|
||||
await route.fulfill({ json: { success: true, require_restart: false } });
|
||||
});
|
||||
|
||||
await frigateApp.goto("/settings?page=cameraManagement");
|
||||
await openCloneDialog(frigateApp);
|
||||
await selectSource(frigateApp, "Front Door");
|
||||
await frigateApp.page
|
||||
.getByPlaceholder(/e\.g\., back_door or Back Door/i)
|
||||
.fill("clone_target_two");
|
||||
await frigateApp.page.getByRole("button", { name: /^Clone$/i }).click();
|
||||
|
||||
await expect.poll(() => requests.length, { timeout: 10_000 }).toBe(1);
|
||||
const body = requests[0] as {
|
||||
config_data: {
|
||||
cameras: { clone_target_two: { detect?: Record<string, unknown> } };
|
||||
};
|
||||
};
|
||||
const detect = body.config_data.cameras.clone_target_two.detect ?? {};
|
||||
expect(detect).not.toHaveProperty("width");
|
||||
expect(detect).not.toHaveProperty("height");
|
||||
});
|
||||
|
||||
test("selects multiple existing destination cameras via a switch popover", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
|
||||
@@ -1072,6 +1072,76 @@ test.describe("System — Health notices sources @medium", () => {
|
||||
).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("a camera on the fallback detect resolution is flagged", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
await frigateApp.installDefaults({
|
||||
config: { cameras: { garage: { detect_resolution_source: "default" } } },
|
||||
stats: QUIET_STATS,
|
||||
});
|
||||
await frigateApp.goto("/system#health");
|
||||
|
||||
const row = frigateApp.page.getByTestId(
|
||||
"health-problem-config:detect:detect-resolution-not-probed:camera.garage",
|
||||
);
|
||||
await expect(row).toBeVisible({ timeout: 15_000 });
|
||||
await expect(row).toHaveAttribute("data-severity", "warning");
|
||||
await expect(
|
||||
frigateApp.page.getByTestId(
|
||||
"health-problem-config:detect:detect-resolution-not-probed:camera.front_door",
|
||||
),
|
||||
).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("an unprobeable resolution is only flagged when Frigate must probe it", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
const noSize = [
|
||||
{
|
||||
return_code: 0,
|
||||
stderr: "",
|
||||
stdout: {
|
||||
streams: [
|
||||
{ codec_type: "video", codec_name: "h264" },
|
||||
{ codec_type: "audio", codec_name: "aac" },
|
||||
],
|
||||
},
|
||||
},
|
||||
];
|
||||
await frigateApp.installDefaults({
|
||||
config: {
|
||||
cameras: {
|
||||
backyard: { detect_resolution_source: "probed" },
|
||||
front_door: { detect_resolution_source: "default" },
|
||||
},
|
||||
},
|
||||
ffprobe: { backyard: noSize, front_door: noSize, garage: noSize },
|
||||
stats: QUIET_STATS,
|
||||
});
|
||||
await frigateApp.goto("/system#health");
|
||||
|
||||
await frigateApp.page
|
||||
.getByRole("button", { name: "Run stream checks" })
|
||||
.click();
|
||||
|
||||
await expect(
|
||||
frigateApp.page.getByTestId(
|
||||
"health-problem-stream:backyard:0:resolution-unknown",
|
||||
),
|
||||
).toBeVisible({ timeout: 15_000 });
|
||||
await expect(
|
||||
frigateApp.page.getByTestId(
|
||||
"health-problem-stream:garage:0:resolution-unknown",
|
||||
),
|
||||
).toHaveCount(0);
|
||||
// the startup probe's own row already covers this camera
|
||||
await expect(
|
||||
frigateApp.page.getByTestId(
|
||||
"health-problem-stream:front_door:0:resolution-unknown",
|
||||
),
|
||||
).toHaveCount(0);
|
||||
});
|
||||
|
||||
test("wizard-only Reolink advice stays off the tab", async ({
|
||||
frigateApp,
|
||||
}) => {
|
||||
|
||||
@@ -2028,6 +2028,7 @@
|
||||
},
|
||||
"detect": {
|
||||
"fpsGreaterThanFive": "Setting the detect FPS higher than 5 is not recommended. Higher values may cause performance issues and will not provide any benefit.",
|
||||
"resolutionNotProbed": "Frigate could not probe the resolution of this camera's detect stream, so it is using a default of 1280x720, which may not match the camera. Set the detect width and height to match the stream.",
|
||||
"disabled": "Object detection is disabled. Snapshots, review items, and enrichments such as face recognition, license plate recognition, and Generative AI will not function.",
|
||||
"runtimeDisabled": "Object detection is enabled in your config, but it is currently turned off for this camera. Snapshots, review items, and enrichments such as face recognition, license plate recognition, and Generative AI will not function until it is turned back on from the camera's live view, or until the active profile stops disabling it.",
|
||||
"sceneWithoutModel": "No detection model is configured for this scene, so this camera falls back to the Default model. Add a model for this scene to give the camera its own.",
|
||||
|
||||
@@ -18,6 +18,17 @@ const detect: SectionConfigOverrides = {
|
||||
condition: (ctx) =>
|
||||
ctx.level === "camera" && ctx.formData?.enabled === false,
|
||||
},
|
||||
{
|
||||
key: "detect-resolution-not-probed",
|
||||
health: true,
|
||||
messageKey: "configMessages.detect.resolutionNotProbed",
|
||||
severity: "warning",
|
||||
// profiles hide width and height
|
||||
condition: (ctx) =>
|
||||
ctx.level === "camera" &&
|
||||
!ctx.profileName &&
|
||||
ctx.fullCameraConfig?.detect_resolution_source === "default",
|
||||
},
|
||||
],
|
||||
fieldMessages: [
|
||||
{
|
||||
|
||||
@@ -36,6 +36,8 @@ export interface FaceRecognitionConfig {
|
||||
export type SearchModel = "jinav1" | "jinav2" | (string & NonNullable<unknown>);
|
||||
export type SearchModelSize = "small" | "large";
|
||||
|
||||
export type DetectResolutionSource = "config" | "probed" | "default";
|
||||
|
||||
export type LiveTranscodeQuality = {
|
||||
height: number;
|
||||
bitrate: number;
|
||||
@@ -116,6 +118,7 @@ export interface CameraConfig {
|
||||
cmd: string;
|
||||
roles: string[];
|
||||
}[];
|
||||
detect_resolution_source?: DetectResolutionSource;
|
||||
live: {
|
||||
height: number;
|
||||
quality: number;
|
||||
|
||||
@@ -672,9 +672,14 @@ export function buildClonedCameraPayloads({
|
||||
formData: sourceSectionValue as ConfigSectionData,
|
||||
},
|
||||
);
|
||||
// a fallback detect size would become an explicit value on the target
|
||||
const fallbackDetect =
|
||||
section === "detect" && sourceCfg.detect_resolution_source === "default"
|
||||
? ["width", "height"]
|
||||
: [];
|
||||
let pendingSectionValue: unknown = sanitizeSectionData(
|
||||
cloneDeep(sourceSectionValue) as ConfigSectionData,
|
||||
resolvedHiddenFields,
|
||||
[...resolvedHiddenFields, ...fallbackDetect],
|
||||
);
|
||||
|
||||
if (FILTER_SECTION_DEFS[section]) {
|
||||
|
||||
@@ -58,6 +58,10 @@ export function streamHealth(
|
||||
checked += 1;
|
||||
const link = `/settings?page=cameraFfmpeg&camera=${encodeURIComponent(name)}`;
|
||||
const copiesAudio = recordCopiesAudio(camera);
|
||||
// a set resolution needs no probe, and a failed startup probe has its own row
|
||||
const resolutionCovered =
|
||||
camera.detect_resolution_source === "config" ||
|
||||
camera.detect_resolution_source === "default";
|
||||
let flagged = false;
|
||||
|
||||
if (check.error) {
|
||||
@@ -125,7 +129,8 @@ export function streamHealth(
|
||||
(issue): issue is StreamIssue & { type: "warning" | "error" } =>
|
||||
issue.type !== "good" &&
|
||||
!WIZARD_ONLY_RULES.has(issue.rule) &&
|
||||
(issue.rule !== "audio-codec-record" || copiesAudio),
|
||||
(issue.rule !== "audio-codec-record" || copiesAudio) &&
|
||||
(issue.rule !== "resolution-unknown" || !resolutionCovered),
|
||||
)
|
||||
.forEach((issue) => {
|
||||
flagged = true;
|
||||
|
||||
Reference in New Issue
Block a user