Skip to content
Open
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
Original file line number Diff line number Diff line change
@@ -1,5 +1,60 @@
import { describe, expect, it } from "vitest";
import { estimateHdrExtractionBytes } from "./captureHdrResources.js";
import { mkdtempSync, rmSync, writeFileSync } from "node:fs";
import { tmpdir } from "node:os";
import { join } from "node:path";
import { estimateHdrExtractionBytes, planHdrResources } from "./captureHdrResources.js";
import type { CompositionMetadata } from "../shared.js";

function videoComposition(src: string): CompositionMetadata {
return {
duration: 5,
width: 1920,
height: 1080,
audios: [],
images: [],
videos: [{ id: "a-roll", src, start: 0, end: 5, mediaStart: 0, loop: false, hasAudio: false }],
};
}

describe("planHdrResources non-ASCII src resolution (PRINFRA-349)", () => {
it("decodes a percent-encoded CJK <video src> back to the real on-disk path", () => {
const projectDir = mkdtempSync(join(tmpdir(), "hf-hdr-cjk-"));
try {
const realName = "视频1.mp4";
writeFileSync(join(projectDir, realName), "x");
// The compiled DOM carries the URL-encoded attribute value.
const encoded = encodeURIComponent(realName); // %E8%A7%86%E9%A2%911.mp4
const prep = planHdrResources({
composition: videoComposition(encoded),
nativeHdrVideoIds: new Set(["a-roll"]),
nativeHdrImageIds: new Set(),
projectDir,
compiledDir: projectDir,
});
// Must be the decoded filesystem path ffmpeg can open, not the %-encoded string.
expect(prep.hdrVideoSrcPaths.get("a-roll")).toBe(join(projectDir, realName));
} finally {
rmSync(projectDir, { recursive: true, force: true });
}
});

it("leaves an ASCII src untouched", () => {
const projectDir = mkdtempSync(join(tmpdir(), "hf-hdr-ascii-"));
try {
writeFileSync(join(projectDir, "clip.mp4"), "x");
const prep = planHdrResources({
composition: videoComposition("clip.mp4"),
nativeHdrVideoIds: new Set(["a-roll"]),
nativeHdrImageIds: new Set(),
projectDir,
compiledDir: projectDir,
});
expect(prep.hdrVideoSrcPaths.get("a-roll")).toBe(join(projectDir, "clip.mp4"));
} finally {
rmSync(projectDir, { recursive: true, force: true });
}
});
});

describe("estimateHdrExtractionBytes", () => {
it("sums 6 bytes per pixel per frame across videos", () => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ import {
normalizeObjectFit,
queryElementStacking,
resampleRgb48leObjectFit,
resolveProjectRelativeSrc,
runFfmpeg,
} from "@hyperframes/engine";
import { fpsToFfmpegArg, fpsToNumber } from "@hyperframes/core";
Expand Down Expand Up @@ -67,7 +68,6 @@ export function planHdrResources(args: {
nativeHdrImageIds: Set<string>;
projectDir: string;
compiledDir: string;
existsSync: (p: string) => boolean;
}): HdrResourcePrep {
const { composition, nativeHdrVideoIds, nativeHdrImageIds, projectDir, compiledDir } = args;
const hdrVideoIds = composition.videos
Expand All @@ -76,12 +76,14 @@ export function planHdrResources(args: {
const hdrVideoSrcPaths = new Map<string, string>();
for (const v of composition.videos) {
if (!hdrVideoIds.includes(v.id)) continue;
let srcPath = v.src;
if (!srcPath.startsWith("/")) {
const fromCompiled = join(compiledDir, srcPath);
srcPath = args.existsSync(fromCompiled) ? fromCompiled : join(projectDir, srcPath);
}
hdrVideoSrcPaths.set(v.id, srcPath);
// Resolve via the shared SDR resolver so a percent-encoded `<video src>`
// (`视频1.mp4` → `%E8%A7%86%E9%A2%911.mp4` in the compiled DOM URL) decodes
// back to the real on-disk filename before ffmpeg sees it. The old
// hand-rolled join passed the encoded string straight through, so HDR
// pre-extraction failed with "No such file" on non-ASCII media
// (PRINFRA-349 symptom c). resolveProjectRelativeSrc also handles query
// strings, origin-root URLs, and `..` traversal identically to the SDR path.
hdrVideoSrcPaths.set(v.id, resolveProjectRelativeSrc(v.src, projectDir, compiledDir));
}
const hdrVideoStartTimes = new Map<string, number>();
for (const v of composition.videos) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,6 @@ export async function runCaptureHdrStage(
nativeHdrImageIds,
projectDir,
compiledDir,
existsSync,
});

const domSession = await createCaptureSession(
Expand Down
Loading