Skip to content

Commit c6f87f5

Browse files
fix(cli): check copies only the stretch of a video it plays and stops after 2 minutes of copies (#7182)
* fix(cli): check stops after 2 minutes of video copies and says how to finish * fix(cli): check copies only the stretch of a video the composition plays * docs(cli): check copies only the played stretch of a long video * docs(cli): shorten two comments on the copy window * fix(cli): finding crops and frames get the same copy windows as the check * fix(cli): drop a comment the ratchet counts * refactor(studio-server): keep runFfmpeg under the complexity gate
1 parent 21e2038 commit c6f87f5

10 files changed

Lines changed: 403 additions & 23 deletions

File tree

‎docs/packages/cli.mdx‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1258,10 +1258,11 @@ cover every finding from the full check.
12581258
| `--prepare-media` | Only make the browser-playable video copies, then exit: no browser, no report. `--json` lists each file as `ready`, `cached` or `failed`; exit 1 if any failed |
12591259

12601260
A video Chrome cannot decode (HEVC, ProRes) is copied once, and the first check waits
1261-
for it. A source longer than 22 seconds is copied in 15-second pieces that are kept, so a
1261+
for it for up to 2 minutes; past that, check stops with a `media_copies_unfinished` finding that names
1262+
each unfinished file and its progress. Run `--prepare-media` (no time limit) to finish them. When every use of a long video in the composition has a known `data-duration` (on the video or the element that times it, no `loop`), check copies only that stretch from the start of the file, rounded up to whole 15-second pieces, instead of the whole file. A source longer than 22 seconds is copied in 15-second pieces that are kept, so a
12621263
copy that is stopped continues from its finished pieces on the next run. While it works, the
12631264
check prints each copy's progress to stderr every 10 seconds (stdout stays clean for `--json`),
1264-
and ends a copy only when it makes no progress for 3 minutes (`HYPERFRAMES_PROXY_STALL_MS`).
1265+
and ends a copy that makes no progress for 3 minutes (`HYPERFRAMES_PROXY_STALL_MS`).
12651266
For a long project, run `hyperframes check --prepare-media` first, then the check itself finds
12661267
every copy ready.
12671268

‎packages/cli/src/utils/checkBrowser.test.ts‎

Lines changed: 85 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ import {
2828
} from "./checkBrowser.js";
2929
import { CheckDeadline } from "./checkDeadline.js";
3030
import { closeManagedBrowser } from "../browser/launch.js";
31+
import { serveStaticProjectHtml } from "./staticProjectServer.js";
3132
import type { ProjectDir } from "./project.js";
3233

3334
const mocks = vi.hoisted(() => ({
@@ -53,6 +54,10 @@ const mocks = vi.hoisted(() => ({
5354
) => Promise<string>
5455
>(),
5556
FfmpegUnavailableError: class FfmpegUnavailableError extends Error {},
57+
proxyLimits: [] as Array<number | undefined>,
58+
proxyWindowSeconds: vi.fn(
59+
async (_sourcePath: string, _neededSeconds: number): Promise<number | undefined> => undefined,
60+
),
5661
getProxyCachePath: vi.fn(
5762
(projectDir: string, sourcePath: string, _variant?: string, _box?: unknown) =>
5863
`${sourcePath}.proxy.mp4`,
@@ -126,12 +131,14 @@ vi.mock("@hyperframes/studio-server/media-codec-map", async (importOriginal) =>
126131
vi.mock("@hyperframes/studio-server/proxy-transcoder", () => ({
127132
FfmpegUnavailableError: mocks.FfmpegUnavailableError,
128133
getProxyCachePath: mocks.getProxyCachePath,
134+
proxyWindowSeconds: mocks.proxyWindowSeconds,
129135
resolveProxies: (
130136
projectDir: string,
131137
sources: Array<{
132138
sourcePath: string;
133139
variant: string;
134140
box?: { width: number; height: number };
141+
limitSeconds?: number;
135142
}>,
136143
onSettled: (index: number) => void = () => {},
137144
onProgress: (
@@ -141,6 +148,7 @@ vi.mock("@hyperframes/studio-server/proxy-transcoder", () => ({
141148
signal?: AbortSignal,
142149
) => {
143150
mocks.proxySignal = signal;
151+
mocks.proxyLimits = sources.map(({ limitSeconds }) => limitSeconds);
144152
mocks.proxyProgress.feed?.(onProgress);
145153
return Promise.allSettled(
146154
sources.map(({ sourcePath, variant, box }, index) =>
@@ -1441,6 +1449,7 @@ describe("preResolveHostileMediaProxies", () => {
14411449
join(projectDir, "clip.mp4"),
14421450
"h264",
14431451
box,
1452+
undefined,
14441453
);
14451454
});
14461455

@@ -1480,6 +1489,7 @@ describe("preResolveHostileMediaProxies", () => {
14801489
],
14811490
failedPaths: new Set(["/clip.mp4"]),
14821491
files: [{ file: "clip.mp4", state: "failed", reason: "ffmpeg exited with code 1" }],
1492+
limits: new Map(),
14831493
});
14841494
expect(errorSpy).toHaveBeenCalledWith(
14851495
expect.stringContaining("media proxy pre-resolve: 0/1 ready, 1 failed"),
@@ -1572,6 +1582,61 @@ describe("preResolveHostileMediaProxies", () => {
15721582
}
15731583
});
15741584

1585+
it("copies only the stretch of a long video the composition plays", async () => {
1586+
const projectDir = mkProjectDir();
1587+
mocks.scanProjectMediaCodecMap.mockResolvedValue({
1588+
"/clip.mov": {
1589+
codecName: "hevc",
1590+
browserHostile: true,
1591+
representativeMime: null,
1592+
hasAlpha: false,
1593+
},
1594+
});
1595+
mocks.proxyWindowSeconds.mockResolvedValue(30);
1596+
mocks.resolveProxy.mockResolvedValue("/cache/clip.mov.mp4");
1597+
const html =
1598+
'<html><body><video src="clip.mov" data-start="0" data-duration="12" data-media-start="3"></video></body></html>';
1599+
1600+
const { limits } = await preResolveHostileMediaProxies(projectDir, html);
1601+
1602+
expect(mocks.proxyWindowSeconds).toHaveBeenCalledWith(join(projectDir, "clip.mov"), 15);
1603+
expect(mocks.proxyLimits).toEqual([30]);
1604+
expect(limits).toEqual(new Map([[join(projectDir, "clip.mov"), 30]]));
1605+
});
1606+
1607+
it("stops a check whose copies outrun the copy budget, naming each file and the way to finish", async () => {
1608+
vi.useFakeTimers();
1609+
try {
1610+
const projectDir = mkProjectDir();
1611+
mocks.scanProjectMediaCodecMap.mockResolvedValue({
1612+
"/clip.mov": {
1613+
codecName: "hevc",
1614+
browserHostile: true,
1615+
representativeMime: null,
1616+
hasAlpha: false,
1617+
},
1618+
});
1619+
mocks.resolveProxy.mockImplementation(
1620+
() =>
1621+
new Promise<string>((_, reject) =>
1622+
mocks.proxySignal?.addEventListener("abort", () => reject(new Error("aborted"))),
1623+
),
1624+
);
1625+
mocks.proxyProgress.feed = (report) => report(0, { doneSeconds: 30, totalSeconds: 120 });
1626+
vi.spyOn(console, "error").mockImplementation(() => undefined);
1627+
1628+
const pending = preResolveHostileMediaProxies(projectDir, "<html></html>", undefined, 60_000);
1629+
const outcome = expect(pending).rejects.toThrow(
1630+
/clip\.mov 25%.*hyperframes check --prepare-media/s,
1631+
);
1632+
await vi.advanceTimersByTimeAsync(60_000);
1633+
await outcome;
1634+
} finally {
1635+
mocks.proxyProgress.feed = undefined;
1636+
vi.useRealTimers();
1637+
}
1638+
});
1639+
15751640
it("stops reporting a copy once it is done, so a finished one is not read as stuck", async () => {
15761641
vi.useFakeTimers();
15771642
try {
@@ -1683,6 +1748,7 @@ describe("preResolveHostileMediaProxies", () => {
16831748
findings: [],
16841749
failedPaths: new Set(),
16851750
files: [],
1751+
limits: new Map(),
16861752
});
16871753

16881754
expect(errorSpy).toHaveBeenCalledWith(
@@ -2231,6 +2297,25 @@ describe("finding frame capture", () => {
22312297
}
22322298
});
22332299

2300+
it("serves the page the same copy windows the check made, so a capture starts no full copy", async () => {
2301+
const dir = mkdtempSync(join(tmpdir(), "finding-frames-windows-"));
2302+
installSessionMock(fakePage());
2303+
mocks.bundleWithLocalizedFonts.mockResolvedValueOnce(
2304+
'<html><body><video src="clip.mov" data-duration="5"></video></body></html>',
2305+
);
2306+
mocks.proxyWindowSeconds.mockResolvedValue(30);
2307+
try {
2308+
await captureFindingFrames({ ...PROJECT, dir }, DEFAULT_CHECK_OPTIONS, [
2309+
{ time: 1, filename: "a.png" },
2310+
]);
2311+
expect(vi.mocked(serveStaticProjectHtml).mock.calls.at(-1)?.[5]).toEqual(
2312+
new Map([[join(dir, "clip.mov"), 30]]),
2313+
);
2314+
} finally {
2315+
rmSync(dir, { recursive: true, force: true });
2316+
}
2317+
});
2318+
22342319
it("closes the session when a later screenshot fails", async () => {
22352320
const dir = mkdtempSync(join(tmpdir(), "finding-frames-failure-"));
22362321
const page = fakePage();

0 commit comments

Comments
 (0)