diff --git a/web/e2e/specs/settings/hwaccel-args.spec.ts b/web/e2e/specs/settings/hwaccel-args.spec.ts index 5c8e7988b7..4e217ca53c 100644 --- a/web/e2e/specs/settings/hwaccel-args.spec.ts +++ b/web/e2e/specs/settings/hwaccel-args.spec.ts @@ -158,6 +158,47 @@ test.describe("hwaccel args widget @medium", () => { }); }); + 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("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"); diff --git a/web/src/components/config-form/theme/widgets/FfmpegArgsWidget.tsx b/web/src/components/config-form/theme/widgets/FfmpegArgsWidget.tsx index 67140f2114..e00ca4fef4 100644 --- a/web/src/components/config-form/theme/widgets/FfmpegArgsWidget.tsx +++ b/web/src/components/config-form/theme/widgets/FfmpegArgsWidget.tsx @@ -251,12 +251,19 @@ export function FfmpegArgsWidget(props: WidgetProps) { id, ].join(":"); + // An empty manual box is no change, so the form falls back to the saved + // value while Manual stays chosen. const chosenMode = useCallback( (current: unknown) => { const chosen = chosenModes.get(modeKey); - return chosen && isEqual(chosen.value, current) ? chosen.mode : undefined; + if (!chosen) return undefined; + const emptyManual = chosen.mode === "manual" && chosen.value === ""; + return isEqual(chosen.value, current) || + (emptyManual && isEqual(current, savedValue)) + ? chosen.mode + : undefined; }, - [modeKey], + [modeKey, savedValue], ); // A remount mounts the replacement before the timer fires, so only leaving @@ -337,14 +344,34 @@ export function FfmpegArgsWidget(props: WidgetProps) { return; } - if (mode === "preset" || mode === "auto") { - choose(nextMode, ""); + // Start from the saved manual args, if any, so a switch back to Manual + // shows them instead of an empty box. + if (mode === "preset" || mode === "auto" || mode === "disabled") { + const savedIsManual = + resolveMode( + savedValue, + presetOptions, + defaultMode, + allowInherit, + hwaccelModes, + ) === "manual"; + choose(nextMode, savedIsManual ? normalizeManualText(savedValue) : ""); return; } choose(nextMode, normalizeManualText(value)); }, - [choose, isInherited, mode, presetOptions, savedValue, value], + [ + allowInherit, + choose, + defaultMode, + hwaccelModes, + isInherited, + mode, + presetOptions, + savedValue, + value, + ], ); const handlePresetChange = useCallback( @@ -358,7 +385,10 @@ export function FfmpegArgsWidget(props: WidgetProps) { [choose], ); - const manualValue = normalizeManualText(value); + const manualValue = + mode === "manual" && chosenModes.get(modeKey)?.value === "" + ? "" + : normalizeManualText(value); const presetValue = typeof value === "string" && presetOptions.includes(value) ? value : ""; const fallbackDescriptionKey = useMemo(() => {