/** * FFmpeg args widget -- MEDIUM tier. * * Global hwaccel offers Auto (writes "auto") and Disabled (writes []). * Cameras offer Disabled next to "Inherit from global setting". * Global input and record args offer Default, and record_sub offers * "Same as record" (writes []). */ 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> = {}, ) { 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", "preset-record-generic-audio-aac"], 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("Preset then Disabled then Manual stays on Manual", async ({ frigateApp, }) => { await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await radio(frigateApp, "root_hwaccel_args", "disabled").click(); const manual = radio(frigateApp, "root_hwaccel_args", "manual"); await manual.click(); await expect(manual).toBeChecked(); await expect(manualInput(frigateApp)).toHaveValue(""); }); test("Auto then Manual starts with an empty box", async ({ frigateApp }) => { await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await radio(frigateApp, "root_hwaccel_args", "auto").click(); const manual = radio(frigateApp, "root_hwaccel_args", "manual"); await manual.click(); await expect(manual).toBeChecked(); await expect(manualInput(frigateApp)).toHaveValue(""); }); test("switching back to Manual shows the saved manual args", async ({ frigateApp, }) => { await openSettings(frigateApp, "/settings?page=globalFfmpeg", { ffmpeg: { hwaccel_args: "-hwaccel vaapi" }, }); const manual = radio(frigateApp, "root_hwaccel_args", "manual"); for (const from of ["preset", "disabled", "auto"]) { await radio(frigateApp, "root_hwaccel_args", from).click(); await manual.click(); await expect(manual).toBeChecked(); await expect(manualInput(frigateApp)).toHaveValue("-hwaccel vaapi"); } }); test("an input's Manual does not take the camera's saved args", async ({ frigateApp, }) => { await openSettings( frigateApp, "/settings?page=cameraFfmpeg&camera=front_door", { cameras: { front_door: { ffmpeg: { input_args: "-rtsp_transport tcp", inputs: [ { path: "rtsp://10.0.0.1:554/video", roles: ["record", "detect"], input_args: "-rtsp_transport udp", }, ], }, }, }, }, ); const field = "root_inputs_0_input_args"; await expect(manualInput(frigateApp, field)).toHaveValue( "-rtsp_transport udp", ); await radio(frigateApp, field, "preset").click(); await radio(frigateApp, field, "manual").click(); await expect(radio(frigateApp, field, "manual")).toBeChecked(); await expect(manualInput(frigateApp, field)).toHaveValue( "-rtsp_transport udp", ); }); test("a cleared input box does not carry to the next input after a delete", async ({ frigateApp, }) => { await openSettings( frigateApp, "/settings?page=cameraFfmpeg&camera=front_door", { cameras: { front_door: { ffmpeg: { inputs: [ { path: "rtsp://10.0.0.1:554/main", roles: ["record"], input_args: "-first 1", }, { path: "rtsp://10.0.0.1:554/sub", roles: ["detect"], input_args: "-second 2", }, ], }, }, }, }, ); const field = "root_inputs_0_input_args"; await manualInput(frigateApp, field).fill(""); await frigateApp.page .getByRole("button", { name: "Delete", exact: true }) .first() .click(); await expect(manualInput(frigateApp, field)).toHaveValue("-second 2"); }); test("a deleted input's args don't return on an input with the same path", async ({ frigateApp, }) => { await openSettings( frigateApp, "/settings?page=cameraFfmpeg&camera=front_door", { cameras: { front_door: { ffmpeg: { inputs: [ { path: "rtsp://10.0.0.1:554/video", roles: ["record"], input_args: "-rtsp_transport tcp", }, { path: "rtsp://10.0.0.1:554/video", roles: ["detect"], input_args: "-rtsp_transport udp", }, ], }, }, }, }, ); await frigateApp.page .getByRole("button", { name: "Delete", exact: true }) .first() .click(); const field = "root_inputs_0_input_args"; await expect(manualInput(frigateApp, field)).toHaveValue( "-rtsp_transport udp", ); await radio(frigateApp, field, "preset").click(); await radio(frigateApp, field, "manual").click(); await expect(manualInput(frigateApp, field)).toHaveValue(""); }); test("a cleared Manual hwaccel box stays Manual across a camera switch", async ({ frigateApp, }) => { await openSettings( frigateApp, "/settings?page=cameraFfmpeg&camera=front_door", { cameras: { front_door: { ffmpeg: { hwaccel_args: "-hw g" } } } }, ); // Another edit keeps the form dirty, so the cleared "" stays pending. await frigateApp.page .getByRole("switch", { name: "Apple compatibility" }) .click(); await manualInput(frigateApp).fill(""); await frigateApp.page .getByRole("button", { name: "Select a camera" }) .click(); await frigateApp.page.getByRole("switch", { name: "Backyard" }).click(); await frigateApp.page .getByRole("button", { name: "Select a camera" }) .click(); await frigateApp.page.getByRole("switch", { name: "Front Door" }).click(); await expect( radio(frigateApp, "root_hwaccel_args", "manual"), ).toBeChecked(); await expect(manualInput(frigateApp)).toHaveValue(""); }); test("Inherit on a list-valued camera field shows Inherit", async ({ frigateApp, }) => { const capture = await openSettings( frigateApp, "/settings?page=cameraFfmpeg&camera=front_door", { cameras: { front_door: { ffmpeg: { hwaccel_args: [], input_args: ["-a", "1"] }, }, }, }, ); for (const field of ["root_hwaccel_args", "root_input_args"]) { const inherit = radio(frigateApp, field, "inherit"); await inherit.click(); await expect(inherit).toBeChecked(); } await save(frigateApp).click(); await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({ config_data: { cameras: { front_door: { ffmpeg: { hwaccel_args: "", input_args: "" } }, }, }, }); }); test("a saved list round-trips through Manual unchanged", 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 radio(frigateApp, "root_hwaccel_args", "disabled").click(); await expect(save(frigateApp)).toBeEnabled(); await manual.click(); await expect(manual).toBeChecked(); await expect(manualInput(frigateApp)).toHaveValue("-hwaccel vaapi"); await expect(save(frigateApp)).toBeDisabled(); }); 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(); }); }); const DEFAULT_MODE = "default"; const DEFAULTED_FIELDS = ["root_input_args", "root_output_args_record"]; const RECORD_SUB = "root_output_args_record_sub"; const showOutputArgs = (app: FrigateApp) => app.page.getByText("Output arguments", { exact: true }).first().click(); const showGlobalArgs = async (app: FrigateApp) => { await app.page .getByRole("button", { name: /Advanced/ }) .first() .click(); await showOutputArgs(app); }; const switchSection = (app: FrigateApp, name: string) => app.page .locator('[data-sidebar="menu-sub-button"]', { hasText: new RegExp(`^${name}$`), }) .click(); test.describe("ffmpeg default args @medium", () => { test("global defaults show Default", async ({ frigateApp }) => { await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { await expect(radio(frigateApp, field, DEFAULT_MODE)).toBeChecked(); } }); test("global Default on defaults sends no delete", async ({ frigateApp }) => { const capture = await openSettings( frigateApp, "/settings?page=globalFfmpeg", ); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { const unset = radio(frigateApp, field, DEFAULT_MODE); await radio(frigateApp, field, "manual").click(); await manualInput(frigateApp, field).fill("-x 1"); await unset.click(); await expect(unset).toBeChecked(); } await frigateApp.page .getByRole("switch", { name: "Apple compatibility" }) .click(); await save(frigateApp).click(); await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({ config_data: { ffmpeg: { apple_compatibility: true } }, }); const { ffmpeg } = ( capture.saved() as { config_data: { ffmpeg: Record } } ).config_data; expect(ffmpeg).not.toHaveProperty("input_args"); expect(ffmpeg).not.toHaveProperty("output_args"); }); test("Default then Manual starts with an empty box", async ({ frigateApp, }) => { await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { const manual = radio(frigateApp, field, "manual"); await manual.click(); await expect(manual).toBeChecked(); await expect(manualInput(frigateApp, field)).toHaveValue(""); } await expect(save(frigateApp)).toBeDisabled(); }); test("global Default on defaults stays across a section switch", async ({ frigateApp, }) => { test.skip(frigateApp.isMobile, "the section sidebar is desktop only"); await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { await radio(frigateApp, field, "manual").click(); await manualInput(frigateApp, field).fill("-x 1"); await radio(frigateApp, field, DEFAULT_MODE).click(); } await switchSection(frigateApp, "Recording"); await switchSection(frigateApp, "FFmpeg"); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { await expect(radio(frigateApp, field, DEFAULT_MODE)).toBeChecked(); } await expect(save(frigateApp)).toBeDisabled(); }); test("global Default on saved args deletes them", async ({ frigateApp }) => { test.skip(frigateApp.isMobile, "the section sidebar is desktop only"); const capture = await openSettings( frigateApp, "/settings?page=globalFfmpeg", { ffmpeg: { input_args: "-in 1", output_args: { record: "-out 1" } } }, ); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { await radio(frigateApp, field, DEFAULT_MODE).click(); } await switchSection(frigateApp, "Recording"); await switchSection(frigateApp, "FFmpeg"); await showGlobalArgs(frigateApp); for (const field of DEFAULTED_FIELDS) { await expect(radio(frigateApp, field, DEFAULT_MODE)).toBeChecked(); } await save(frigateApp).click(); await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({ config_data: { ffmpeg: { input_args: "", output_args: { record: "" } }, }, }); }); test("Same as record on defaults leaves nothing to save", async ({ frigateApp, }) => { await openSettings(frigateApp, "/settings?page=globalFfmpeg"); await showGlobalArgs(frigateApp); const sameAsRecord = radio(frigateApp, RECORD_SUB, "inherit"); await expect(sameAsRecord).toBeChecked(); await radio(frigateApp, RECORD_SUB, "preset").click(); await expect(save(frigateApp)).toBeEnabled(); await sameAsRecord.click(); await expect(sameAsRecord).toBeChecked(); await expect(save(frigateApp)).toBeDisabled(); }); test("global Same as record on saved args saves an empty list", async ({ frigateApp, }) => { const capture = await openSettings( frigateApp, "/settings?page=globalFfmpeg", { ffmpeg: { output_args: { record_sub: "preset-record-generic" } } }, ); await showGlobalArgs(frigateApp); await radio(frigateApp, RECORD_SUB, "inherit").click(); await save(frigateApp).click(); await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({ config_data: { ffmpeg: { output_args: { record_sub: [] } } }, }); }); test("camera Same as record over a global value saves an empty list", async ({ frigateApp, }) => { const recordSub = { output_args: { record_sub: "preset-record-generic" } }; const capture = await openSettings( frigateApp, "/settings?page=cameraFfmpeg&camera=front_door", { ffmpeg: recordSub, cameras: { front_door: { ffmpeg: recordSub } } }, ); const sameAsRecord = radio(frigateApp, RECORD_SUB, "inherit"); await showOutputArgs(frigateApp); await sameAsRecord.click(); await frigateApp.page .getByRole("button", { name: "Select a camera" }) .click(); await frigateApp.page.getByRole("switch", { name: "Backyard" }).click(); await frigateApp.page .getByRole("button", { name: "Select a camera" }) .click(); await frigateApp.page.getByRole("switch", { name: "Front Door" }).click(); await expect(radio(frigateApp, "root_input_args", "inherit")).toBeVisible(); if (!(await sameAsRecord.isVisible())) { await showOutputArgs(frigateApp); } await expect(sameAsRecord).toBeChecked(); await save(frigateApp).click(); await expect.poll(capture.saved, { timeout: 5_000 }).toMatchObject({ config_data: { cameras: { front_door: { ffmpeg: { output_args: { record_sub: [] } } }, }, }, }); }); });