Skip to content

Commit ad4d3fa

Browse files
fix(producer): convert HEIC images to JPEG at compile time (#6455)
* fix(producer): convert HEIC images to JPEG at compile time Tiled HEIC photos probe as several video streams, so the media-type preflight rejected them as image:video, and Chrome cannot decode HEIC. Sniff the ftyp brands of every <img>, join and rotate the tile grid with ffmpeg, verify the declared size, and swap in a cached JPEG. * fix(producer): shorten the HEIC prep comments * fix(producer): name host tool failures and keep a failed HEIC preview image as authored Also: HEIC tests run in the integration lane; the primary grid is picked by default disposition. * chore(producer): raise the package size budget for the HEIC prep
1 parent 95aba51 commit ad4d3fa

15 files changed

Lines changed: 827 additions & 13 deletions

File tree

‎packages/cli/src/server/studioServer.ts‎

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -569,11 +569,21 @@ export function createStudioServer(options: StudioServerOptions): StudioServer {
569569
const { injectDeterministicFontFaces } = await import("@hyperframes/core/fonts/embed");
570570
const { prepareAnimatedGifInputs } =
571571
await import("../../../producer/src/services/animatedGifPrep.js");
572+
const { prepareHeifImageInputs } =
573+
await import("../../../producer/src/services/heifImagePrep.js");
572574
const { downloadToTemp, writeUrlDownloadTelemetry } =
573575
await import("../../../producer/src/utils/urlDownloader.js");
574576
const gifOutputDir = join(project.dir, ".hyperframes", "prepared-assets", "gif");
575577
const gifDownloadDir = join(project.dir, ".hyperframes", "prepared-assets", "downloads");
576-
const prepared = await prepareAnimatedGifInputs(html, {
578+
const heifOutputDir = join(project.dir, ".hyperframes", "prepared-assets", "heif");
579+
const { html: htmlWithJpegs } = await prepareHeifImageInputs(html, {
580+
projectDir: project.dir,
581+
downloadDir: gifDownloadDir,
582+
outputDir: heifOutputDir,
583+
outputSrcPrefix: ".hyperframes/prepared-assets/heif",
584+
onFailure: (error) => console.warn(`[studio] ${error.message}`),
585+
});
586+
const prepared = await prepareAnimatedGifInputs(htmlWithJpegs, {
577587
projectDir: project.dir,
578588
downloadDir: gifDownloadDir,
579589
outputDir: gifOutputDir,

‎packages/engine/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,7 @@ export {
341341
PROBE_FACTS_VERSION,
342342
buildProbeFactsText,
343343
probeMediaProfile,
344+
runFfprobe,
344345
analyzeKeyframeIntervals,
345346
type VideoMetadata,
346347
type AudioMetadata,

‎packages/engine/src/utils/ffprobe.ts‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ function sanitizeFfprobeDiagnostic(stderr: string, filePath: string): string {
5656
}
5757

5858
/** Spawn ffprobe with given args, return stdout. Throws on non-zero exit or missing binary. */
59-
async function runFfprobe(
59+
export async function runFfprobe(
6060
filePath: string,
6161
argsWithoutInput: string[],
6262
signal?: AbortSignal,

‎packages/producer/scripts/test-classification.mjs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,8 @@ const INTEGRATION_TEST_FILES = new Set([
1515
"src/regression-harness-audio.test.ts",
1616
"src/services/bundleScriptPolicy.test.ts",
1717
"src/services/coreRuntimeBrowser.test.ts",
18+
"src/services/heifImagePrep.test.ts",
19+
"src/services/htmlCompiler.heif.test.ts",
1820
"src/services/vfxDeterminism.test.ts",
1921
"src/services/distributed/assemble.test.ts",
2022
"src/services/distributed/chunkBoundary.test.ts",

‎packages/producer/src/index.ts‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ export {
8989
} from "./services/fileServer.js";
9090

9191
export { prepareAnimatedGifInputs } from "./services/animatedGifPrep.js";
92+
export { prepareHeifImageInputs } from "./services/heifImagePrep.js";
9293

9394
// ── Video frame injection (Hyperframes-specific hook) ───────────────────────
9495
export { createVideoFrameInjector } from "@hyperframes/engine";

‎packages/producer/src/server.ts‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,8 @@ const DEFAULT_SERVER_FPS = { num: 30, den: 1 } as const;
127127
const SSE_KEEPALIVE_MS = 30_000;
128128
const SAFE_RENDER_ERROR_CODES = new Set<string>([
129129
"ASSET_MEDIA_TYPE_MISMATCH",
130+
"HEIF_IMAGE_CONVERSION_FAILED",
131+
"HEIF_TOOL_UNAVAILABLE",
130132
"NOT_MEDIA_PAYLOAD",
131133
"INVALID_VIDEO_METADATA",
132134
"VIDEO_SOURCE_UNRENDERABLE",

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,15 +46,15 @@ export interface PrepareAnimatedGifInputsResult {
4646
preparedGifs: PreparedAnimatedGif[];
4747
}
4848

49-
function splitUrlSuffix(src: string): { basePath: string; suffix: string } {
49+
export function splitUrlSuffix(src: string): { basePath: string; suffix: string } {
5050
const queryIdx = src.indexOf("?");
5151
const hashIdx = src.indexOf("#");
5252
if (queryIdx < 0 && hashIdx < 0) return { basePath: src, suffix: "" };
5353
const cutIdx = queryIdx < 0 ? hashIdx : hashIdx < 0 ? queryIdx : Math.min(queryIdx, hashIdx);
5454
return { basePath: src.slice(0, cutIdx), suffix: src.slice(cutIdx) };
5555
}
5656

57-
function normalizeRelPath(path: string): string {
57+
export function normalizeRelPath(path: string): string {
5858
return path.replace(/\\/g, "/").replace(/^\/+/, "");
5959
}
6060

@@ -76,7 +76,7 @@ function readLoopOverride(el: Element): boolean | null {
7676
return null;
7777
}
7878

79-
function resolveGifSourcePath(
79+
export function resolveLocalImageSourcePath(
8080
src: string,
8181
options: Pick<PrepareAnimatedGifInputsOptions, "projectDir" | "downloadDir" | "sourceAssets">,
8282
): string | null {
@@ -380,7 +380,7 @@ export async function prepareAnimatedGifInputs(
380380
const img = images[i]!;
381381
const src = (img.getAttribute("src") || "").trim();
382382
if (!hasGifExtension(src)) continue;
383-
const sourcePath = resolveGifSourcePath(src, options);
383+
const sourcePath = resolveLocalImageSourcePath(src, options);
384384
if (!sourcePath) continue;
385385

386386
const bytes = readFileSync(sourcePath);

0 commit comments

Comments
 (0)