Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 6 additions & 2 deletions Capycut-Code/packages/openfilm/src/render.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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. */
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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}`]]));
Expand Down Expand Up @@ -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}`);
Expand All @@ -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 } });
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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([]);
Expand Down Expand Up @@ -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(() => {
Expand Down