mirror of
https://github.com/heygen-com/hyperframes.git
synced 2026-11-18 16:08:56 +00:00
fix(cli): check says it is making video copies instead of going silent for minutes (#5953)
A check on a project whose videos Chrome cannot decode (HEVC, HDR) first transcodes each of them, which on phone footage takes minutes and printed nothing until it was done.
This commit is contained in:
@@ -30,6 +30,7 @@ const mocks = vi.hoisted(() => ({
|
||||
resolveProxy:
|
||||
vi.fn<(projectDir: string, absoluteSourcePath: string, variant?: string) => Promise<string>>(),
|
||||
FfmpegUnavailableError: class FfmpegUnavailableError extends Error {},
|
||||
getProxyCachePath: vi.fn((projectDir: string, sourcePath: string) => `${sourcePath}.proxy.mp4`),
|
||||
scanProjectMediaCodecMap: vi.fn<
|
||||
(...args: unknown[]) => Promise<
|
||||
Record<
|
||||
@@ -84,9 +85,16 @@ vi.mock("@hyperframes/studio-server/media-codec-map", async (importOriginal) =>
|
||||
}));
|
||||
vi.mock("@hyperframes/studio-server/proxy-transcoder", () => ({
|
||||
FfmpegUnavailableError: mocks.FfmpegUnavailableError,
|
||||
resolveProxies: (projectDir: string, sources: Array<{ sourcePath: string; variant: string }>) =>
|
||||
getProxyCachePath: mocks.getProxyCachePath,
|
||||
resolveProxies: (
|
||||
projectDir: string,
|
||||
sources: Array<{ sourcePath: string; variant: string }>,
|
||||
onSettled: () => void = () => {},
|
||||
) =>
|
||||
Promise.allSettled(
|
||||
sources.map(({ sourcePath, variant }) => mocks.resolveProxy(projectDir, sourcePath, variant)),
|
||||
sources.map(({ sourcePath, variant }) =>
|
||||
mocks.resolveProxy(projectDir, sourcePath, variant).finally(onSettled),
|
||||
),
|
||||
),
|
||||
}));
|
||||
|
||||
@@ -1172,17 +1180,47 @@ describe("preResolveHostileMediaProxies", () => {
|
||||
|
||||
await preResolveHostileMediaProxies(projectDir, "<html></html>");
|
||||
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy).toHaveBeenCalledWith(
|
||||
expect(errorSpy.mock.calls.map(([line]) => line)).toEqual([
|
||||
expect.stringMatching(/^\[hyperframes\] Making browser-playable copies of 1 video /),
|
||||
"[hyperframes] browser-playable copies: 1/1",
|
||||
expect.stringMatching(
|
||||
/^\[hyperframes\] media proxy pre-resolve: 1\/1 ready, 0 failed \(\d+ms\)$/,
|
||||
),
|
||||
);
|
||||
]);
|
||||
expect(infoSpy).not.toHaveBeenCalled();
|
||||
expect(logSpy).not.toHaveBeenCalled();
|
||||
expect(stdoutSpy).not.toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("says it is making copies, and counts them, only when some are not made yet", async () => {
|
||||
const projectDir = mkProjectDir();
|
||||
const codec = {
|
||||
codecName: "hevc",
|
||||
browserHostile: true,
|
||||
representativeMime: null,
|
||||
hasAlpha: false,
|
||||
};
|
||||
mocks.scanProjectMediaCodecMap.mockResolvedValue({ "/a.mov": codec, "/b.mov": codec });
|
||||
mocks.resolveProxy.mockResolvedValue("/cache/copy.mp4");
|
||||
const errorSpy = vi.spyOn(console, "error").mockImplementation(() => undefined);
|
||||
|
||||
writeFileSync(join(projectDir, "a.mov.proxy.mp4"), "");
|
||||
await preResolveHostileMediaProxies(projectDir, "<html></html>");
|
||||
expect(errorSpy.mock.calls.map(([line]) => String(line).slice(0, 48))).toEqual([
|
||||
"[hyperframes] Making browser-playable copies of ",
|
||||
"[hyperframes] browser-playable copies: 1/2",
|
||||
"[hyperframes] browser-playable copies: 2/2",
|
||||
"[hyperframes] media proxy pre-resolve: 2/2 ready",
|
||||
]);
|
||||
expect(errorSpy.mock.calls[0]![0]).toContain("copies of 1 video Chrome");
|
||||
|
||||
errorSpy.mockClear();
|
||||
writeFileSync(join(projectDir, "b.mov.proxy.mp4"), "");
|
||||
await preResolveHostileMediaProxies(projectDir, "<html></html>");
|
||||
expect(errorSpy).toHaveBeenCalledTimes(1);
|
||||
expect(errorSpy.mock.calls[0]![0]).toMatch(/^\[hyperframes\] media proxy pre-resolve: 2\/2/);
|
||||
});
|
||||
|
||||
it("writes a scan failure to stderr and leaves stdout untouched", async () => {
|
||||
const projectDir = mkProjectDir();
|
||||
mocks.scanProjectMediaCodecMap.mockRejectedValue(new Error("ffprobe not found"));
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
import type { CheckDeadline } from "./checkDeadline.js";
|
||||
import { BrowserCleanupError, closeManagedBrowser } from "../browser/launch.js";
|
||||
import { checkSnapshotDirectory } from "./checkSnapshotDirectory.js";
|
||||
import { mkdirSync, writeFileSync } from "node:fs";
|
||||
import { existsSync, mkdirSync, writeFileSync } from "node:fs";
|
||||
import os from "node:os";
|
||||
import { join, resolve } from "node:path";
|
||||
import type { Browser, Page } from "puppeteer-core";
|
||||
@@ -39,6 +39,7 @@ import {
|
||||
} from "@hyperframes/studio-server/media-codec-map";
|
||||
import {
|
||||
FfmpegUnavailableError,
|
||||
getProxyCachePath,
|
||||
resolveProxies,
|
||||
} from "@hyperframes/studio-server/proxy-transcoder";
|
||||
import { rectToBbox } from "./checkTypes.js";
|
||||
@@ -165,12 +166,22 @@ export async function preResolveHostileMediaProxies(
|
||||
variant: proxyVariantFor(facts),
|
||||
};
|
||||
});
|
||||
const results = await resolveProxies(projectDir, sources);
|
||||
const total = hostileEntries.length;
|
||||
const toMake = sources.filter((source) => !proxyCached(projectDir, source)).length;
|
||||
if (toMake > 0) {
|
||||
console.error(
|
||||
`[hyperframes] Making browser-playable copies of ${toMake} video${toMake === 1 ? "" : "s"} Chrome cannot decode. Only the first check of these files waits for this; later checks reuse the copies.`,
|
||||
);
|
||||
}
|
||||
let settled = 0;
|
||||
const results = await resolveProxies(projectDir, sources, () => {
|
||||
settled += 1;
|
||||
if (toMake > 0) console.error(`[hyperframes] browser-playable copies: ${settled}/${total}`);
|
||||
});
|
||||
const failures = sources.flatMap((source, index) => {
|
||||
const result = results[index]!;
|
||||
return result.status === "rejected" ? [{ ...source, reason: result.reason }] : [];
|
||||
});
|
||||
const total = hostileEntries.length;
|
||||
console.error(
|
||||
`[hyperframes] media proxy pre-resolve: ${total - failures.length}/${total} ready, ${failures.length} failed (${Date.now() - startedAt}ms)`,
|
||||
);
|
||||
@@ -192,6 +203,17 @@ export async function preResolveHostileMediaProxies(
|
||||
return { findings, failedPaths: new Set(failures.map(({ pathname }) => pathname)) };
|
||||
}
|
||||
|
||||
function proxyCached(
|
||||
projectDir: string,
|
||||
source: { sourcePath: string; variant: ReturnType<typeof proxyVariantFor> },
|
||||
): boolean {
|
||||
try {
|
||||
return existsSync(getProxyCachePath(projectDir, source.sourcePath, source.variant));
|
||||
} catch {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
interface ProxyPreResolution {
|
||||
findings: RuntimeDraft[];
|
||||
/** Root-relative paths of the videos whose copy failed. */
|
||||
|
||||
Reference in New Issue
Block a user