Skip to content

Commit eac396a

Browse files
vanceingallsclaude
andcommitted
fix(hdr): address review feedback across stack
- Tolerate per-image HDR probe failures; warn on missing paths. - Warn when HDR <img> source is animated (stills-only for now). - Namespace HDR image frame dirs as hdr_img_<id> to avoid collisions. - Drop image id from HDR layer set when extraction fails. - Promote HDR frame extraction failure from info to warn. - Rename hdrVideoStartTimes → hdrLayerStartTimes. - Make CompiledComposition.images optional. - Fix NaN data-duration slipping through parseImageElements. - Remove dead setAttribute mutation in parseImageElements. Co-Authored-By: Claude Opus 4.6 (1M context) <[email protected]>
1 parent ee239fe commit eac396a

3 files changed

Lines changed: 41 additions & 23 deletions

File tree

‎packages/engine/src/services/videoFrameExtractor.ts‎

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -114,13 +114,15 @@ export function parseImageElements(html: string): ImageElement[] {
114114
const src = el.getAttribute("src");
115115
if (!src) continue;
116116
const id = el.getAttribute("id") || `hf-img-${autoIdCounter++}`;
117-
if (!el.getAttribute("id")) {
118-
el.setAttribute("id", id);
119-
}
120117
const start = parseFloat(el.getAttribute("data-start") ?? "0");
121118
const duration = parseFloat(el.getAttribute("data-duration") ?? "0");
122-
if (duration <= 0) continue;
123-
images.push({ id, src, start, end: start + duration });
119+
if (!Number.isFinite(duration) || duration <= 0) continue;
120+
images.push({
121+
id,
122+
src,
123+
start: Number.isFinite(start) ? start : 0,
124+
end: (Number.isFinite(start) ? start : 0) + duration,
125+
});
124126
}
125127
return images;
126128
}

‎packages/producer/src/services/htmlCompiler.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ export interface CompiledComposition {
4343
subCompositions: Map<string, string>;
4444
videos: VideoElement[];
4545
audios: AudioElement[];
46-
images: ImageElement[];
46+
images?: ImageElement[];
4747
unresolvedCompositions: UnresolvedElement[];
4848
/** Assets that resolve outside projectDir. Keys are the path used in HTML, values are absolute filesystem paths. */
4949
externalAssets: Map<string, string>;

‎packages/producer/src/services/renderOrchestrator.ts‎

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -650,7 +650,7 @@ export async function executeRenderJob(
650650
duration: compiled.staticDuration,
651651
videos: compiled.videos,
652652
audios: compiled.audios,
653-
images: compiled.images,
653+
images: compiled.images ?? [],
654654
width: compiled.width,
655655
height: compiled.height,
656656
};
@@ -922,7 +922,9 @@ export async function executeRenderJob(
922922
);
923923
}
924924

925-
// Probe images for HDR color space (also gated by --hdr)
925+
// Probe images for HDR color space (also gated by --hdr). Tolerates per-image
926+
// probe failures (corrupt file, unsupported format) so one bad image doesn't
927+
// abort the render — mirrors the video probe path.
926928
if (job.config.hdr && composition.images.length > 0) {
927929
await Promise.all(
928930
composition.images.map(async (img) => {
@@ -933,11 +935,25 @@ export async function executeRenderJob(
933935
: join(projectDir, imgPath);
934936
imgPath = fromCompiled;
935937
}
936-
if (!existsSync(imgPath)) return;
937-
const meta = await extractVideoMetadata(imgPath);
938-
if (isHdrColorSpace(meta.colorSpace)) {
939-
nativeHdrVideoIds.add(img.id);
940-
videoTransfers.set(img.id, detectTransfer(meta.colorSpace));
938+
if (!existsSync(imgPath)) {
939+
log.warn(`HDR probe skipped — image not found: ${img.src} (id=${img.id})`);
940+
return;
941+
}
942+
try {
943+
const meta = await extractVideoMetadata(imgPath);
944+
if (isHdrColorSpace(meta.colorSpace)) {
945+
if (meta.fps > 0 || meta.durationSeconds > 0.05) {
946+
log.warn(
947+
`HDR image ${img.id} appears animated (fps=${meta.fps}, duration=${meta.durationSeconds.toFixed(3)}s). Only the first frame will be used — HDR <img> currently supports still images only.`,
948+
);
949+
}
950+
nativeHdrVideoIds.add(img.id);
951+
videoTransfers.set(img.id, detectTransfer(meta.colorSpace));
952+
}
953+
} catch (err) {
954+
log.warn(
955+
`HDR probe failed for ${img.id}: ${err instanceof Error ? err.message : String(err)}`,
956+
);
941957
}
942958
}),
943959
);
@@ -1193,20 +1209,20 @@ export async function executeRenderJob(
11931209
// visible at t=0 (e.g., data-start > 0) need to be queried at their own
11941210
// start time so their layout dimensions are available.
11951211
const hdrExtractionDims = new Map<string, { width: number; height: number }>();
1196-
const hdrVideoStartTimes = new Map<string, number>();
1212+
const hdrLayerStartTimes = new Map<string, number>();
11971213
for (const v of composition.videos) {
11981214
if (hdrVideoIds.includes(v.id)) {
1199-
hdrVideoStartTimes.set(v.id, v.start);
1215+
hdrLayerStartTimes.set(v.id, v.start);
12001216
}
12011217
}
12021218
for (const img of composition.images) {
12031219
if (nativeHdrVideoIds.has(img.id)) {
1204-
hdrVideoStartTimes.set(img.id, img.start);
1220+
hdrLayerStartTimes.set(img.id, img.start);
12051221
}
12061222
}
12071223

12081224
// Collect unique start times to minimize seek operations
1209-
const uniqueStartTimes = [...new Set(hdrVideoStartTimes.values())].sort((a, b) => a - b);
1225+
const uniqueStartTimes = [...new Set(hdrLayerStartTimes.values())].sort((a, b) => a - b);
12101226
for (const seekTime of uniqueStartTimes) {
12111227
await domSession.page.evaluate((t: number) => {
12121228
if (window.__hf && typeof window.__hf.seek === "function") window.__hf.seek(t);
@@ -1276,7 +1292,7 @@ export async function executeRenderJob(
12761292
const fromCompiled = join(compiledDir, imgPath);
12771293
imgPath = existsSync(fromCompiled) ? fromCompiled : join(projectDir, imgPath);
12781294
}
1279-
const frameDir = join(framesDir, `hdr_${img.id}`);
1295+
const frameDir = join(framesDir, `hdr_img_${img.id}`);
12801296
mkdirSync(frameDir, { recursive: true });
12811297
const dims = hdrExtractionDims.get(img.id) ?? { width, height };
12821298
const imgResult = await runFfmpeg(
@@ -1297,9 +1313,9 @@ export async function executeRenderJob(
12971313
{ signal: abortSignal },
12981314
);
12991315
if (!imgResult.success) {
1300-
log.debug(`HDR image extraction failed for ${img.id}`, {
1301-
error: imgResult.stderr.slice(-200),
1302-
});
1316+
log.warn(`HDR image extraction failed for ${img.id}: ${imgResult.stderr.slice(-200)}`);
1317+
nativeHdrVideoIds.delete(img.id);
1318+
continue;
13031319
}
13041320
hdrFrameDirs.set(img.id, frameDir);
13051321
}
@@ -1404,7 +1420,7 @@ export async function executeRenderJob(
14041420
time,
14051421
job.config.fps,
14061422
hdrFrameDirs,
1407-
hdrVideoStartTimes,
1423+
hdrLayerStartTimes,
14081424
width,
14091425
height,
14101426
log,
@@ -1610,7 +1626,7 @@ export async function executeRenderJob(
16101626
time,
16111627
job.config.fps,
16121628
hdrFrameDirs,
1613-
hdrVideoStartTimes,
1629+
hdrLayerStartTimes,
16141630
width,
16151631
height,
16161632
log,

0 commit comments

Comments
 (0)