replace hwaccel None with Auto and Disabled

Choosing None for the global hardware acceleration args sent undefined, which deleted the key, so the backend default `auto` turned detection back on (VAAPI on Intel hosts). On a config without the key the save returned a 500 from the update_yaml KeyError.

Global hwaccel now offers Auto, which writes `auto`, and Disabled, which writes `[]`. Cameras get Disabled next to Inherit from global setting, and `""` and `[]` both display as Disabled. Camera-level Inherit restores the saved value instead of sending a delete for a key that may not be in the YAML, and camera export also counts as inherited when it matches the camera's own hwaccel value, since that's what the backend falls back to. The mode choice survives the remount RJSF does when the value flips between a string and a list, and every ffmpeg args field forces the split layout so a list value no longer stacks. The docs now say what Auto detects and how to turn decoding off.
This commit is contained in:
Josh Hawkins
2026-12-01 23:05:01 -06:00
parent 31038a9e14
commit c1f9a3ddbd
6 changed files with 563 additions and 137 deletions
+341
View File
@@ -0,0 +1,341 @@
/**
* Hardware acceleration args widget -- MEDIUM tier.
*
* Global hwaccel offers Auto (writes "auto") and Disabled (writes []).
* Cameras offer Disabled next to "Inherit from global setting".
*/
import { readFileSync } from "node:fs";
import { resolve, dirname } from "node:path";
import { fileURLToPath } from "node:url";
import { test, expect, type FrigateApp } from "../../fixtures/frigate-test";
import {
configFactory,
type DeepPartial,
} from "../../fixtures/mock-data/config";
const __dirname = dirname(fileURLToPath(import.meta.url));
const CONFIG_SCHEMA = JSON.parse(
readFileSync(
resolve(__dirname, "../../fixtures/mock-data/config-schema.json"),
"utf-8",
),
);
const MANUAL_WARNING = "Manual hardware acceleration arguments are not";
async function openSettings(
app: FrigateApp,
url: string,
overrides: DeepPartial<ReturnType<typeof configFactory>> = {},
) {
const { page } = app;
const config = configFactory(overrides);
let lastSaved: unknown = null;
await page.route("**/api/config/schema.json", (route) =>
route.fulfill({ json: CONFIG_SCHEMA }),
);
await page.route("**/api/config", (route) => route.fulfill({ json: config }));
await page.route("**/api/config/raw_paths", (route) =>
route.fulfill({ json: { cameras: {}, go2rtc: { streams: {} } } }),
);
await page.route("**/api/config/set", async (route) => {
lastSaved = route.request().postDataJSON();
await route.fulfill({ json: { success: true, require_restart: false } });
});
await page.route("**/api/ffmpeg/presets", (route) =>
route.fulfill({
json: {
hwaccel_args: ["preset-vaapi", "preset-nvidia"],
input_args: ["preset-rtsp-generic"],
output_args: { record: ["preset-record-generic"], detect: [] },
},
}),
);
await app.goto(url);
return { saved: () => lastSaved };
}
const radio = (app: FrigateApp, field: string, mode: string) =>
app.page.locator(`[id="${field}-${mode}"]`);
const manualInput = (app: FrigateApp, field = "root_hwaccel_args") =>
app.page.locator(`input[id="${field}"]`);
const save = (app: FrigateApp) =>
app.page.getByRole("button", { name: "Save", exact: true });
test.describe("hwaccel args widget @medium", () => {
test("global resolved preset shows Preset, Auto saves the literal auto", async ({
frigateApp,
}) => {
const capture = await openSettings(
frigateApp,
"/settings?page=globalFfmpeg",
);
await expect(
radio(frigateApp, "root_hwaccel_args", "preset"),
).toBeChecked();
await radio(frigateApp, "root_hwaccel_args", "auto").click();
await expect(
frigateApp.page.getByText("Frigate detects Nvidia or VAAPI hardware"),
).toBeVisible();
await save(frigateApp).click();
await expect
.poll(capture.saved, { timeout: 5_000 })
.toMatchObject({ config_data: { ffmpeg: { hwaccel_args: "auto" } } });
});
test("global Disabled saves an empty list", async ({ frigateApp }) => {
const capture = await openSettings(
frigateApp,
"/settings?page=globalFfmpeg",
);
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
await save(frigateApp).click();
await expect
.poll(capture.saved, { timeout: 5_000 })
.toMatchObject({ config_data: { ffmpeg: { hwaccel_args: [] } } });
});
test("global empty list shows Disabled", async ({ frigateApp }) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
ffmpeg: { hwaccel_args: [] },
});
await expect(
radio(frigateApp, "root_hwaccel_args", "disabled"),
).toBeChecked();
});
test("global empty string shows Disabled", async ({ frigateApp }) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
ffmpeg: { hwaccel_args: "" },
});
await expect(
radio(frigateApp, "root_hwaccel_args", "disabled"),
).toBeChecked();
await expect(frigateApp.page.getByText(MANUAL_WARNING)).toHaveCount(0);
});
test("clearing manual args keeps Manual selected", async ({ frigateApp }) => {
await openSettings(frigateApp, "/settings?page=globalFfmpeg", {
ffmpeg: { hwaccel_args: "-hwaccel vaapi" },
});
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
await expect(manual).toBeChecked();
await frigateApp.page.locator('input[id="root_hwaccel_args"]').fill("");
await expect(manual).toBeChecked();
await expect(manualInput(frigateApp)).toHaveValue("");
});
test("saved Disabled switches to Manual and saves typed args", async ({
frigateApp,
}) => {
const capture = await openSettings(
frigateApp,
"/settings?page=globalFfmpeg",
{ ffmpeg: { hwaccel_args: [] } },
);
const manual = radio(frigateApp, "root_hwaccel_args", "manual");
await manual.click();
await expect(manual).toBeChecked();
await manualInput(frigateApp).fill("-hwaccel none");
await expect(manual).toBeChecked();
await save(frigateApp).click();
await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({
config_data: { ffmpeg: { hwaccel_args: "-hwaccel none" } },
});
});
test("Disabled keeps the side-by-side layout", async ({ frigateApp }) => {
test.skip(frigateApp.isMobile, "the layout stacks on narrow screens");
await openSettings(frigateApp, "/settings?page=globalFfmpeg");
const label = frigateApp.page
.getByText("Hardware acceleration arguments", { exact: true })
.first();
const auto = radio(frigateApp, "root_hwaccel_args", "auto");
const before = await auto.boundingBox();
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
await expect(
radio(frigateApp, "root_hwaccel_args", "disabled"),
).toBeChecked();
const labelBox = await label.boundingBox();
const after = await auto.boundingBox();
expect(after!.x).toBeGreaterThan(labelBox!.x + labelBox!.width);
expect(after!.x).toBeCloseTo(before!.x, 0);
});
test("camera Disabled overrides the global preset", async ({
frigateApp,
}) => {
const capture = await openSettings(
frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door",
);
await expect(
radio(frigateApp, "root_hwaccel_args", "inherit"),
).toBeChecked();
await expect(radio(frigateApp, "root_hwaccel_args", "auto")).toHaveCount(0);
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
await save(frigateApp).click();
await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({
config_data: {
cameras: { front_door: { ffmpeg: { hwaccel_args: [] } } },
},
});
});
test("camera with an explicit empty list shows Disabled", async ({
frigateApp,
}) => {
await openSettings(
frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door",
{ cameras: { front_door: { ffmpeg: { hwaccel_args: [] } } } },
);
await expect(
radio(frigateApp, "root_hwaccel_args", "disabled"),
).toBeChecked();
});
test("camera with an empty string shows Disabled", async ({ frigateApp }) => {
await openSettings(
frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door",
{ cameras: { front_door: { ffmpeg: { hwaccel_args: "" } } } },
);
await expect(
radio(frigateApp, "root_hwaccel_args", "disabled"),
).toBeChecked();
await expect(
frigateApp.page.getByText("Frigate detects Nvidia or VAAPI hardware"),
).toHaveCount(0);
});
test("camera saved Disabled switches to Preset", async ({ frigateApp }) => {
await openSettings(
frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door",
{ cameras: { front_door: { ffmpeg: { hwaccel_args: [] } } } },
);
const preset = radio(frigateApp, "root_hwaccel_args", "preset");
await preset.click();
await expect(preset).toBeChecked();
await expect(
frigateApp.page.locator('button[id="root_hwaccel_args"]'),
).toContainText("VAAPI");
});
test("a mode choice does not follow to another camera", async ({
frigateApp,
}) => {
await openSettings(
frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door",
);
// Both cameras hold the global preset, so only the key separates them.
const preset = radio(frigateApp, "root_hwaccel_args", "preset");
await preset.click();
await expect(preset).toBeChecked();
await frigateApp.page
.getByRole("button", { name: "Select a camera" })
.click();
await frigateApp.page.getByRole("switch", { name: "Backyard" }).click();
await expect(
radio(frigateApp, "root_hwaccel_args", "inherit"),
).toBeChecked();
});
test("camera Disabled then Inherit leaves nothing to save", async ({
frigateApp,
}) => {
await openSettings(
frigateApp,
"/settings?page=cameraFfmpeg&camera=front_door",
);
const inherit = radio(frigateApp, "root_hwaccel_args", "inherit");
await expect(inherit).toBeChecked();
await radio(frigateApp, "root_hwaccel_args", "disabled").click();
await expect(save(frigateApp)).toBeEnabled();
await inherit.click();
await expect(inherit).toBeChecked();
await expect(save(frigateApp)).toBeDisabled();
});
test("global export Same as FFmpeg saves auto without the detect hint", async ({
frigateApp,
}) => {
const capture = await openSettings(
frigateApp,
"/settings?page=globalRecording",
);
await frigateApp.page
.getByRole("button", { name: /Advanced/ })
.first()
.click();
const sameAsFfmpeg = radio(frigateApp, "root_export_hwaccel_args", "auto");
await expect(
frigateApp.page.getByText("Same as FFmpeg hardware acceleration"),
).toBeVisible();
await sameAsFfmpeg.click();
await expect(sameAsFfmpeg).toBeChecked();
await expect(
frigateApp.page.getByText("Frigate detects Nvidia or VAAPI hardware"),
).toHaveCount(0);
await save(frigateApp).click();
await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({
config_data: { record: { export: { hwaccel_args: "auto" } } },
});
});
test("camera export following a Disabled camera shows Inherit", async ({
frigateApp,
}) => {
await openSettings(
frigateApp,
"/settings?page=cameraRecording&camera=front_door",
{
cameras: {
front_door: {
ffmpeg: { hwaccel_args: [] },
record: { export: { hwaccel_args: [] } },
},
},
},
);
await frigateApp.page
.getByRole("button", { name: /Advanced/ })
.first()
.click();
await expect(
radio(frigateApp, "root_export_hwaccel_args", "inherit"),
).toBeChecked();
});
});