From b6bcfc24972c81a6928eb8dbdbb00dd816deba27 Mon Sep 17 00:00:00 2001 From: Rehan Date: Fri, 27 Nov 2026 13:25:27 +0500 Subject: [PATCH] fix(openfilm): handle mixed PNG alpha on FFmpeg 9.1 and deflake caption test Fix the two failures on main in CI run 44950194416. Windows: transparent ProRes/WebM export failed on FFmpeg 9.1 Chromium omits PNG's alpha plane for an entirely opaque frame, so a render that has transparency on some frames sends rgba followed by rgb24. Alpha exports pass -reinit_filter 0 on purpose, to keep tmix and select from being reset, so FFmpeg cannot rebuild the graph. FFmpeg 9.1 now errors when crop receives a format change: Frame size or format changed without filter graph reinitialization crop supports dynamic frame size but not dynamic frame format. scale does support both, so normalize PNG frames before the crop with: scale=iw:ih:flags=neighbor,format=rgba The scale is 1:1 with nearest neighbours, so it resamples nothing; it only gives rgb24 frames an opaque alpha plane and makes every frame rgba before the crop. The final pixel-format conversion stays after the crop, as before. Verified with clip-export-regressions.test.mjs: 10/10 pass on FFmpeg 9.1.0 (the same essentials build CI installs) and 10/10 on 9.0.2. macOS: caption group move timed out The test waits for 185 selection frames after Cmd+A: 183 caption cues and 2 media clips. It had a 15 s budget, but the failing macOS runs took 19.7 s and 23.8 s on a shard that was about twice as slow as the other runners. It also pressed Cmd+A after waiting only for the cues, not for the second media clip, so select-all could be built from a half-loaded timeline. Finally, selected was a dependency of the timeline keydown effect, so every clip click rebuilt the global listener and a Cmd+A arriving during that swap could be lost. Wait for both media clips before Cmd+A, raise the wait budget to 60 s and the test timeout to 180 s, and read the selection through the existing selectedRef so the listener stays registered across picks. Verified locally (caption test passes in about 5 s); the next macOS CI run confirms the runner-load behaviour. --- Capycut-Code/packages/openfilm/src/render.mjs | 8 ++++++-- .../packages/openfilm/studio/caption-group-move.test.mjs | 9 ++++++--- .../openfilm/studio/ui/src/components/Timeline.tsx | 6 +++--- 3 files changed, 15 insertions(+), 8 deletions(-) diff --git a/Capycut-Code/packages/openfilm/src/render.mjs b/Capycut-Code/packages/openfilm/src/render.mjs index 060619d6..8f07bd30 100644 --- a/Capycut-Code/packages/openfilm/src/render.mjs +++ b/Capycut-Code/packages/openfilm/src/render.mjs @@ -728,8 +728,12 @@ async function encode({ film, a, b, file }, { fps, rate, samples, shutter, alpha /* a 4:2:0 picture wants even dimensions. A --scale between two pixels (1920 x .667) makes the browser's surface 1281 wide: the file was written, and every strict H.264 encoder after it said `width not divisible by 2`. Crop the odd last column or row on the way in: scaling 1281 to 1280 would resample the whole frame, a crop keeps - every pixel as drawn. An even size is left alone. */ - const even = 'crop=trunc(iw/2)*2:trunc(ih/2)*2:0:0,'; + every pixel as drawn. An even size is left alone. + Chromium leaves PNG's alpha plane out of an entirely opaque frame, so a page that turns opaque mid-render sends + rgb24 after rgba. With `-reinit_filter 0` (below, to keep tmix) ffmpeg 9.1's crop refuses a format change without + a graph reinitialization; a 1:1 scale to rgba converts every frame to one format first, resampling nothing + (nearest at the same size), so the crop still sees every pixel as drawn before the final conversion. */ + const even = `${still === 'png' ? 'scale=iw:ih:flags=neighbor,format=rgba,' : ''}crop=trunc(iw/2)*2:trunc(ih/2)*2:0:0,`; const blur = samples > 1 ? `tmix=frames=${samples},select='eq(mod(n\\,${samples})\\,${samples - 1})',setpts=N/((${ffmpegRate(rate)})*TB),` : ''; /* Chromium omits PNG's alpha plane for an entirely opaque frame. Reinitializing on that format change resets tmix and select's frame index, losing samples or even every frame of a short transparent export. */ diff --git a/Capycut-Code/packages/openfilm/studio/caption-group-move.test.mjs b/Capycut-Code/packages/openfilm/studio/caption-group-move.test.mjs index e1d703b9..84b12351 100644 --- a/Capycut-Code/packages/openfilm/studio/caption-group-move.test.mjs +++ b/Capycut-Code/packages/openfilm/studio/caption-group-move.test.mjs @@ -9,7 +9,7 @@ import { readVtt, writeVtt } from '../src/captions.mjs'; import { openProject } from './server/projects.mjs'; import { startStudio } from './server/server.mjs'; -test('unlocked caption tracks move with a mixed selection, with one undo for media and captions', { timeout: 90_000 }, async () => { +test('unlocked caption tracks move with a mixed selection, with one undo for media and captions', { timeout: 180_000 }, async () => { const scratch = await mkdtemp(join(tmpdir(), 'of-caption-group-')); const names = ['HOME', 'SHARED_HOME', 'LIBRARY', 'SAVED', 'EXPORTS']; const saved = new Map(names.map(n => [`OPENFILM_${n}`, process.env[`OPENFILM_${n}`]])); @@ -48,8 +48,9 @@ test('unlocked caption tracks move with a mixed selection, with one undo for med const shots = async () => (await film()).tracks.find(t => t.clips.some(c => c.id === 'one')).clips; const cues = async () => readVtt(await readFile(join(root, 'captions.vtt'), 'utf8')).cues; const until = async (check, why) => { - /* a move of 183 cues and their media is saved in one write, which a slow machine takes seconds over */ - for (let i = 0; i < 300; i++) { if (await check()) return; await page.waitForTimeout(50); } + /* a move of 183 cues and their media is saved in one write, and selecting them redraws 185 blocks: both take + seconds on a loaded CI machine, and a 15 s budget has timed out on macOS */ + for (let i = 0; i < 600; i++) { if (await check()) return; await page.waitForTimeout(100); } assert.fail(why); }; await page.goto(`${studio.origin}/projects/${project.id}?key=${studio.key}`); @@ -59,6 +60,8 @@ test('unlocked caption tracks move with a mixed selection, with one undo for med /* The two VTT files load independently. Wait for the row that participates in the drag. */ await lockedCue.waitFor(); await until(async () => await unlockedCues.count() === 183, 'the unlocked caption cues are ready to select'); + /* both media clips are in the timeline before ⌘A, so the selection cannot be built from a half-loaded track */ + await until(async () => await page.locator('[data-block-kind="mg"]').count() === 2, 'both media clips are ready to select'); const body = await clip.boundingBox(); assert.ok(body, 'the movable clip is drawn'); await clip.click({ position: { x: body.width / 4, y: 10 } }); diff --git a/Capycut-Code/packages/openfilm/studio/ui/src/components/Timeline.tsx b/Capycut-Code/packages/openfilm/studio/ui/src/components/Timeline.tsx index aa91ba47..db4da6ca 100644 --- a/Capycut-Code/packages/openfilm/studio/ui/src/components/Timeline.tsx +++ b/Capycut-Code/packages/openfilm/studio/ui/src/components/Timeline.tsx @@ -2433,8 +2433,8 @@ export const Timeline = React.memo(function Timeline({ /* A popover can unmount during capture. Its consumed Escape still belongs to it after its DOM is gone. */ if (e.defaultPrevented || isTypingTarget(e.target)) return; if ((e.target as Element | null)?.closest?.('[role="dialog"]')) return; - const picked = tracks.flatMap((tr) => tr.blocks).filter((b) => selected.includes(b.id) && b.loc); - if (e.key === 'Escape' && (selected.length || gap || pickedTransition || range) && !e.metaKey && !e.ctrlKey && !e.altKey + const picked = tracks.flatMap((tr) => tr.blocks).filter((b) => selectedRef.current.includes(b.id) && b.loc); + if (e.key === 'Escape' && (selectedRef.current.length || gap || pickedTransition || range) && !e.metaKey && !e.ctrlKey && !e.altKey && !document.querySelector('[role="menu"], [role="listbox"], [data-popover-panel]')) { e.preventDefault(); setSelected([]); @@ -2501,7 +2501,7 @@ export const Timeline = React.memo(function Timeline({ window.addEventListener('keydown', onKey); return () => window.removeEventListener('keydown', onKey); /* the playhead is read from a ref: as a dependency the listener would be swapped twenty times a second */ - }, [onRemove, onRemoveMany, onEditOps, onCopy, onPaste, hasClipboard, removeMany, rippleRemove, magnetRemove, selected, tracks, setSelected, playable, zoomByStable, zoomToStable, gap, closeGap, pickedTransition, onTransition, onPickTransition, range, onRangeChange, t]); + }, [onRemove, onRemoveMany, onEditOps, onCopy, onPaste, hasClipboard, removeMany, rippleRemove, magnetRemove, tracks, setSelected, playable, zoomByStable, zoomToStable, gap, closeGap, pickedTransition, onTransition, onPickTransition, range, onRangeChange, t]); /* whether the last press was on the timeline (for ⌘A); capture phase, since presses here are often stopped */ React.useEffect(() => {