Skip to content
Merged
20 changes: 5 additions & 15 deletions packages/cli/src/cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,34 +22,24 @@ for (const stream of [process.stdout, process.stderr]) {
}

// ── Worker entry path bootstrap (must run before any producer/engine load) ──
// The hf#677 worker_threads pools (`pngDecodeBlitWorkerPool`,
// `shaderTransitionWorkerPool`) live in the producer package and try to
// resolve their worker entry by probing for sibling `.js` files next to
// The shaderTransitionWorkerPool lives in the producer package and resolves
// its worker entry by probing for a sibling `.js` file next to
// `import.meta.url`. When this CLI is bundled by tsup, the producer code is
// inlined into `cli.js`, but `import.meta.url` resolves to the producer's
// own dist path (NOT cli.js) on some module-graph layouts — so the sibling
// probe lands in a directory that does not contain the bundled workers.
// We emit the worker entries next to cli.js (see tsup.config.ts) and tell
// the pools where to find them via the published env-var overrides. The
// pools have an explicit `workerEntryPath` factory option as the canonical
// API, but setting the env vars here covers every call site without having
// to thread the path through the renderOrchestrator → captureHdrStage →
// captureHdrHybridLoop chain.
// probe lands in a directory that does not contain the bundled worker.
// We emit the worker entry next to cli.js (see tsup.config.ts) and tell
// the pool where to find it via the published env-var override.
import { dirname, join } from "node:path";
import { fileURLToPath } from "node:url";
import { existsSync } from "node:fs";

// fallow-ignore-next-line complexity
(() => {
const here = dirname(fileURLToPath(import.meta.url));
const shader = join(here, "shaderTransitionWorker.js");
const png = join(here, "pngDecodeBlitWorker.js");
if (!process.env.HF_SHADER_WORKER_ENTRY && existsSync(shader)) {
process.env.HF_SHADER_WORKER_ENTRY = shader;
}
if (!process.env.HF_PNG_DECODE_BLIT_WORKER_ENTRY && existsSync(png)) {
process.env.HF_PNG_DECODE_BLIT_WORKER_ENTRY = png;
}
})();

// ── Fast-path exits ─────────────────────────────────────────────────────────
Expand Down
16 changes: 0 additions & 16 deletions packages/cli/tsup.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,8 @@ const pkg = JSON.parse(readFileSync(new URL("./package.json", import.meta.url),
};

export default defineConfig({
// hf#732 lever-4: emit BOTH the CLI bundle and the PNG decode + alpha-blit
// worker entry. The producer's `pngDecodeBlitWorkerPool` instantiates a
// Node `worker_threads` Worker via `new Worker(<path>)`, which is a
// filesystem load — it cannot share the parent module graph. The pool's
// path resolver probes for `pngDecodeBlitWorker.js` next to its own loaded
// module (which lives inside `dist/cli.js` after the producer is
// `noExternal`'d and bundled in). Without this entry the file would not
// exist at runtime and the pool would either crash or silently fall back
// to inline decode/blit, killing the perf gain.
entry: {
cli: "src/cli.ts",
pngDecodeBlitWorker: "../producer/src/services/pngDecodeBlitWorker.ts",
// hf#677/#732: shader-blend worker. Same `new Worker(<path>)`
// bundling rationale as `pngDecodeBlitWorker` above.
shaderTransitionWorker: "../producer/src/services/shaderTransitionWorker.ts",
},
format: ["esm"],
Expand Down Expand Up @@ -96,10 +84,6 @@ var __dirname = __hf_dirname(__filename);`,
"@hyperframes/aws-lambda/sdk": resolve(__dirname, "../aws-lambda/src/sdk/index.ts"),
// Same for the GCP adapter's SDK subpath barrel.
"@hyperframes/gcp-cloud-run/sdk": resolve(__dirname, "../gcp-cloud-run/src/sdk/index.ts"),
// hf#732 lever-4: alias for the PNG decode+blit worker's import.
// `alphaBlit.ts` is import-free (only zlib) so the worker survives
// the worker_thread loader boundary directly via this TS source.
"@hyperframes/engine/alpha-blit": resolve(__dirname, "../engine/src/utils/alphaBlit.ts"),
// hf#677 follow-up: the shader-blend worker imports from
// `@hyperframes/engine/shader-transitions` (subpath export) — a
// standalone TS file with zero internal imports that survives the
Expand Down
5 changes: 0 additions & 5 deletions packages/producer/build.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,6 @@ const sharedOpts = {
await Promise.all([
build({ ...sharedOpts, entryPoints: ["src/index.ts"], outfile: "dist/index.js" }),
build({ ...sharedOpts, entryPoints: ["src/server.ts"], outfile: "dist/public-server.js" }),
build({
...sharedOpts,
entryPoints: ["src/services/pngDecodeBlitWorker.ts"],
outfile: "dist/services/pngDecodeBlitWorker.js",
}),
build({
...sharedOpts,
entryPoints: ["src/services/shaderTransitionWorker.ts"],
Expand Down
2 changes: 1 addition & 1 deletion packages/producer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export {
} from "./services/fileServer.js";

// ── Video frame injection (Hyperframes-specific hook) ───────────────────────
export { createVideoFrameInjector } from "./services/videoFrameInjector.js";
export { createVideoFrameInjector } from "@hyperframes/engine";

// ── Configuration ───────────────────────────────────────────────────────────
export { resolveConfig, DEFAULT_CONFIG, type ProducerConfig } from "./config.js";
Expand Down
3 changes: 2 additions & 1 deletion packages/producer/src/services/distributed/assemble.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ import { dirname, join } from "node:path";
import { applyFaststart, muxVideoWithAudio, runFfmpeg } from "@hyperframes/engine";
import { fpsToFfmpegArg } from "@hyperframes/core";
import { defaultLogger, type ProducerLogger } from "../../logger.js";
import { formatExportFrameName } from "../../utils/paths.js";
import { padOrTrimAudioToVideoFrameCount } from "../render/audioPadTrim.js";
import type { ChunkSliceJson } from "../render/stages/freezePlan.js";
import type { DistributedFormat } from "./shared.js";
Expand Down Expand Up @@ -397,7 +398,7 @@ function mergePngFrameDirs(
throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
}
for (const frame of frames) {
const dst = join(outputPath, `frame_${String(globalIdx + 1).padStart(6, "0")}.png`);
const dst = join(outputPath, formatExportFrameName(globalIdx, "png"));
cpSync(join(chunkDir, frame), dst);
globalIdx += 1;
}
Expand Down
Loading
Loading