@hyperframes/producer 0.9.86 → 0.9.88
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compileWorker.js +3210 -0
- package/dist/distributed.js +401 -279
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.js +476 -353
- package/dist/public-server.js +284 -163
- package/dist/services/compileInWorker.d.ts +10 -0
- package/dist/services/compileWorker.d.ts +1 -0
- package/dist/services/distributed/chunkFrames.d.ts +1 -0
- package/dist/services/render/deferredVideoFrames.d.ts +1 -0
- package/dist/services/render/shared.d.ts +3 -3
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -9,7 +9,7 @@ import {
|
|
|
9
9
|
// src/services/renderOrchestrator.ts
|
|
10
10
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
|
|
11
11
|
import {
|
|
12
|
-
existsSync as
|
|
12
|
+
existsSync as existsSync22,
|
|
13
13
|
mkdirSync as mkdirSync12,
|
|
14
14
|
readdirSync as readdirSync6,
|
|
15
15
|
rmSync as rmSync12,
|
|
@@ -360,10 +360,10 @@ import {
|
|
|
360
360
|
referenceBackgroundResult,
|
|
361
361
|
createReferenceBackgroundRecorder
|
|
362
362
|
} from "@hyperframes/engine";
|
|
363
|
-
import { join as
|
|
363
|
+
import { join as join35, dirname as dirname15, resolve as resolve9 } from "path";
|
|
364
364
|
import { totalmem as totalmem2 } from "node:os";
|
|
365
365
|
import { randomUUID } from "crypto";
|
|
366
|
-
import { fileURLToPath as
|
|
366
|
+
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
367
367
|
|
|
368
368
|
// src/services/fileServer.ts
|
|
369
369
|
import { Hono } from "hono";
|
|
@@ -1641,12 +1641,12 @@ var workerPhasesByJob = /* @__PURE__ */ new WeakMap();
|
|
|
1641
1641
|
function forgetWorkerPhases(job) {
|
|
1642
1642
|
workerPhasesByJob.delete(job);
|
|
1643
1643
|
}
|
|
1644
|
-
var
|
|
1645
|
-
function
|
|
1646
|
-
|
|
1644
|
+
var captureActivityByJob = /* @__PURE__ */ new WeakMap();
|
|
1645
|
+
function noteCaptureActivity(job) {
|
|
1646
|
+
captureActivityByJob.set(job, (captureActivityByJob.get(job) ?? 0) + 1);
|
|
1647
1647
|
}
|
|
1648
|
-
function
|
|
1649
|
-
return
|
|
1648
|
+
function captureActivity(job) {
|
|
1649
|
+
return captureActivityByJob.get(job) ?? 0;
|
|
1650
1650
|
}
|
|
1651
1651
|
function describeWorkerPhases(job) {
|
|
1652
1652
|
const phases = workerPhasesByJob.get(job);
|
|
@@ -6256,7 +6256,8 @@ async function extractDeferredFrames(input) {
|
|
|
6256
6256
|
outputDir: input.outputRoot,
|
|
6257
6257
|
format: range.format,
|
|
6258
6258
|
frameRanges: contiguousRuns(indexes),
|
|
6259
|
-
shownBox: input.shownBoxes?.get(video.videoId)
|
|
6259
|
+
shownBox: input.shownBoxes?.get(video.videoId),
|
|
6260
|
+
...input.onProgress && { onProgress: input.onProgress }
|
|
6260
6261
|
},
|
|
6261
6262
|
input.signal,
|
|
6262
6263
|
input.cfg
|
|
@@ -7132,14 +7133,20 @@ function requireOutputDimensions(expected, width, height) {
|
|
|
7132
7133
|
}
|
|
7133
7134
|
|
|
7134
7135
|
// src/services/render/stages/compileStage.ts
|
|
7135
|
-
import { existsSync as
|
|
7136
|
-
import { join as
|
|
7136
|
+
import { existsSync as existsSync13, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7137
|
+
import { join as join23, relative as relative4 } from "node:path";
|
|
7137
7138
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
7138
7139
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
7139
7140
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
7140
7141
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
7141
7142
|
import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperframes/core/compiler";
|
|
7142
7143
|
|
|
7144
|
+
// src/services/compileInWorker.ts
|
|
7145
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
7146
|
+
import { dirname as dirname10, join as join22 } from "node:path";
|
|
7147
|
+
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7148
|
+
import { Worker } from "node:worker_threads";
|
|
7149
|
+
|
|
7143
7150
|
// src/services/htmlCompiler.ts
|
|
7144
7151
|
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
7145
7152
|
import {
|
|
@@ -10455,11 +10462,119 @@ async function recompileWithResolutions(compiled, resolutions, projectDir, downl
|
|
|
10455
10462
|
};
|
|
10456
10463
|
}
|
|
10457
10464
|
|
|
10465
|
+
// src/services/compileInWorker.ts
|
|
10466
|
+
var DEFAULT_COMPILE_TIMEOUT_MS = 10 * 60 * 1e3;
|
|
10467
|
+
var TERMINATE_GRACE_MS = 2e3;
|
|
10468
|
+
var ADVISORY_GRACE_MS = 3e4;
|
|
10469
|
+
var MAX_TIMER_MS = 2 ** 31 - 1;
|
|
10470
|
+
var CompileTimeoutError = class extends Error {
|
|
10471
|
+
code = "COMPILE_TIMEOUT";
|
|
10472
|
+
owner = "user";
|
|
10473
|
+
retryable = false;
|
|
10474
|
+
publicMetadata;
|
|
10475
|
+
constructor(timeoutMs) {
|
|
10476
|
+
super(
|
|
10477
|
+
`Compiling the composition took longer than ${Math.round(timeoutMs / 1e3)} s, so it was stopped. Very large pages, or pages with very many style rules or media tags, are the usual cause.`
|
|
10478
|
+
);
|
|
10479
|
+
this.name = "CompileTimeoutError";
|
|
10480
|
+
this.publicMetadata = { timeoutMs };
|
|
10481
|
+
}
|
|
10482
|
+
};
|
|
10483
|
+
function compileTimeoutMs() {
|
|
10484
|
+
const fromEnv = Number(process.env.HYPERFRAMES_COMPILE_TIMEOUT_MS);
|
|
10485
|
+
return Number.isInteger(fromEnv) && fromEnv > 0 ? Math.min(fromEnv, MAX_TIMER_MS) : DEFAULT_COMPILE_TIMEOUT_MS;
|
|
10486
|
+
}
|
|
10487
|
+
var warnedMissingEntry = false;
|
|
10488
|
+
function resolveCompileWorkerEntry(explicit, log) {
|
|
10489
|
+
if (explicit) return explicit;
|
|
10490
|
+
const fromEnv = process.env.HF_COMPILE_WORKER_ENTRY;
|
|
10491
|
+
if (fromEnv) {
|
|
10492
|
+
if (existsSync12(fromEnv)) return fromEnv;
|
|
10493
|
+
if (!warnedMissingEntry) {
|
|
10494
|
+
warnedMissingEntry = true;
|
|
10495
|
+
log?.warn(
|
|
10496
|
+
"[Compiler] HF_COMPILE_WORKER_ENTRY names a missing file, so compiles run on the main thread with no deadline",
|
|
10497
|
+
{ entry: fromEnv }
|
|
10498
|
+
);
|
|
10499
|
+
}
|
|
10500
|
+
return void 0;
|
|
10501
|
+
}
|
|
10502
|
+
const sibling = join22(dirname10(fileURLToPath3(import.meta.url)), "compileWorker.js");
|
|
10503
|
+
return existsSync12(sibling) ? sibling : void 0;
|
|
10504
|
+
}
|
|
10505
|
+
function rebuildError({ name, message, stack, props }) {
|
|
10506
|
+
const error = Object.assign(new Error(message), props);
|
|
10507
|
+
error.name = name;
|
|
10508
|
+
if (stack) error.stack = stack;
|
|
10509
|
+
return error;
|
|
10510
|
+
}
|
|
10511
|
+
async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, options = {}, worker = {}) {
|
|
10512
|
+
const { log, abortSignal, ...cloneable } = options;
|
|
10513
|
+
const entry = resolveCompileWorkerEntry(worker.entry, log);
|
|
10514
|
+
if (!entry) return compileForRender(projectDir, htmlPath, downloadDir, options);
|
|
10515
|
+
abortSignal?.throwIfAborted();
|
|
10516
|
+
const timeoutMs = worker.timeoutMs ?? compileTimeoutMs();
|
|
10517
|
+
return new Promise((resolve14, reject) => {
|
|
10518
|
+
const thread = new Worker(entry, {
|
|
10519
|
+
workerData: { projectDir, htmlPath, downloadDir, options: cloneable }
|
|
10520
|
+
});
|
|
10521
|
+
let settled = false;
|
|
10522
|
+
const settle = (finish) => {
|
|
10523
|
+
if (settled) return;
|
|
10524
|
+
settled = true;
|
|
10525
|
+
clearTimeout(timer);
|
|
10526
|
+
abortSignal?.removeEventListener("abort", onAbort);
|
|
10527
|
+
finish();
|
|
10528
|
+
};
|
|
10529
|
+
const stop = () => {
|
|
10530
|
+
thread.postMessage({ type: "abort" });
|
|
10531
|
+
setTimeout(() => void thread.terminate(), TERMINATE_GRACE_MS).unref();
|
|
10532
|
+
};
|
|
10533
|
+
const timer = setTimeout(() => {
|
|
10534
|
+
stop();
|
|
10535
|
+
settle(() => reject(new CompileTimeoutError(timeoutMs)));
|
|
10536
|
+
}, timeoutMs);
|
|
10537
|
+
const onAbort = () => {
|
|
10538
|
+
stop();
|
|
10539
|
+
settle(() => reject(abortSignal?.reason ?? new Error("Compile aborted")));
|
|
10540
|
+
};
|
|
10541
|
+
abortSignal?.addEventListener("abort", onAbort, { once: true });
|
|
10542
|
+
const retire = (graceMs) => {
|
|
10543
|
+
thread.unref();
|
|
10544
|
+
setTimeout(() => void thread.terminate(), graceMs).unref();
|
|
10545
|
+
};
|
|
10546
|
+
thread.on(
|
|
10547
|
+
"message",
|
|
10548
|
+
(message) => {
|
|
10549
|
+
if (message.type === "log" && message.level) {
|
|
10550
|
+
log?.[message.level](message.message ?? "", message.meta);
|
|
10551
|
+
} else if (message.type === "result" && message.compiled) {
|
|
10552
|
+
const { compiled } = message;
|
|
10553
|
+
settle(() => resolve14(compiled));
|
|
10554
|
+
retire(ADVISORY_GRACE_MS);
|
|
10555
|
+
} else if (message.type === "error" && message.error) {
|
|
10556
|
+
const { error } = message;
|
|
10557
|
+
settle(() => reject(rebuildError(error)));
|
|
10558
|
+
thread.postMessage({ type: "abort" });
|
|
10559
|
+
retire(TERMINATE_GRACE_MS);
|
|
10560
|
+
}
|
|
10561
|
+
}
|
|
10562
|
+
);
|
|
10563
|
+
thread.on("error", (error) => settle(() => reject(error)));
|
|
10564
|
+
thread.on(
|
|
10565
|
+
"exit",
|
|
10566
|
+
(code) => settle(
|
|
10567
|
+
() => reject(new Error(`The compile worker exited with code ${code} before answering`))
|
|
10568
|
+
)
|
|
10569
|
+
);
|
|
10570
|
+
});
|
|
10571
|
+
}
|
|
10572
|
+
|
|
10458
10573
|
// src/services/render/stages/compileStage.ts
|
|
10459
10574
|
function animatedGifCacheDir(extractCacheDir) {
|
|
10460
10575
|
try {
|
|
10461
10576
|
const root = extractCacheDir && privateCacheRoot(extractCacheDir);
|
|
10462
|
-
return root ?
|
|
10577
|
+
return root ? join23(root, "animated-gif") : void 0;
|
|
10463
10578
|
} catch {
|
|
10464
10579
|
return void 0;
|
|
10465
10580
|
}
|
|
@@ -10487,11 +10602,11 @@ function resolveEntryHtmlPath(input) {
|
|
|
10487
10602
|
assertCompositionFileSize2(path, relative4(projectDir, path));
|
|
10488
10603
|
return readTextFile2(path);
|
|
10489
10604
|
};
|
|
10490
|
-
const htmlPath =
|
|
10605
|
+
const htmlPath = join23(projectDir, entryFile);
|
|
10491
10606
|
const rawEntry = readEntry(htmlPath);
|
|
10492
10607
|
if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
|
|
10493
|
-
const projectIndexPath =
|
|
10494
|
-
if (!
|
|
10608
|
+
const projectIndexPath = join23(projectDir, "index.html");
|
|
10609
|
+
if (!existsSync13(projectIndexPath)) {
|
|
10495
10610
|
throw new Error(
|
|
10496
10611
|
`Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
|
|
10497
10612
|
);
|
|
@@ -10506,7 +10621,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10506
10621
|
`Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`
|
|
10507
10622
|
);
|
|
10508
10623
|
}
|
|
10509
|
-
const wrapperPath =
|
|
10624
|
+
const wrapperPath = join23(workDir, "standalone-entry.html");
|
|
10510
10625
|
writeFileSync4(wrapperPath, standaloneHtml, "utf-8");
|
|
10511
10626
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
10512
10627
|
return wrapperPath;
|
|
@@ -10536,19 +10651,24 @@ async function runCompileStage(input) {
|
|
|
10536
10651
|
const assetRoot = job.config.allowOutsideProjectAssets ? void 0 : projectDir;
|
|
10537
10652
|
const htmlPath = resolveEntryHtmlPath({ projectDir, workDir, entryFile, log, assetRoot });
|
|
10538
10653
|
const compileStart = Date.now();
|
|
10539
|
-
const compiled = await
|
|
10540
|
-
|
|
10541
|
-
|
|
10542
|
-
|
|
10543
|
-
|
|
10544
|
-
|
|
10545
|
-
|
|
10546
|
-
|
|
10547
|
-
|
|
10548
|
-
|
|
10549
|
-
|
|
10550
|
-
|
|
10551
|
-
|
|
10654
|
+
const compiled = await compileForRenderInWorker(
|
|
10655
|
+
projectDir,
|
|
10656
|
+
htmlPath,
|
|
10657
|
+
join23(workDir, "downloads"),
|
|
10658
|
+
{
|
|
10659
|
+
log,
|
|
10660
|
+
failClosedFontFetch: failClosedFontFetch === true,
|
|
10661
|
+
allowSystemFontCapture,
|
|
10662
|
+
abortSignal,
|
|
10663
|
+
variables: input.variables,
|
|
10664
|
+
urlByAbsentLocalPath: input.urlByAbsentLocalPath,
|
|
10665
|
+
pageMotionBlur: input.pageMotionBlur,
|
|
10666
|
+
animatedGifCacheDir: animatedGifCacheDir(cfg.extractCacheDir),
|
|
10667
|
+
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
|
|
10668
|
+
allowOutsideProjectAssets: job.config.allowOutsideProjectAssets,
|
|
10669
|
+
includeOutsideScripts: job.config.includeOutsideScripts
|
|
10670
|
+
}
|
|
10671
|
+
);
|
|
10552
10672
|
assertNotAborted();
|
|
10553
10673
|
const compileOnlyMs = Date.now() - compileStart;
|
|
10554
10674
|
let deCompileGate;
|
|
@@ -10611,7 +10731,7 @@ async function runCompileStage(input) {
|
|
|
10611
10731
|
});
|
|
10612
10732
|
await preflightCompositionAssetMediaTypes({
|
|
10613
10733
|
projectDir,
|
|
10614
|
-
compiledDir:
|
|
10734
|
+
compiledDir: join23(workDir, "compiled"),
|
|
10615
10735
|
composition,
|
|
10616
10736
|
signal: abortSignal
|
|
10617
10737
|
});
|
|
@@ -10659,7 +10779,7 @@ async function runCompileStage(input) {
|
|
|
10659
10779
|
|
|
10660
10780
|
// src/services/render/stages/probeStage.ts
|
|
10661
10781
|
import { createHash as createHash7 } from "node:crypto";
|
|
10662
|
-
import { basename as basename7, join as
|
|
10782
|
+
import { basename as basename7, join as join24 } from "node:path";
|
|
10663
10783
|
import { parseHTML as parseHTML6 } from "linkedom";
|
|
10664
10784
|
import {
|
|
10665
10785
|
closeCaptureSession as closeCaptureSession4,
|
|
@@ -11013,7 +11133,7 @@ async function runProbeStage(input) {
|
|
|
11013
11133
|
});
|
|
11014
11134
|
fileServer = await createFileServer({
|
|
11015
11135
|
projectDir,
|
|
11016
|
-
compiledDir:
|
|
11136
|
+
compiledDir: join24(workDir, "compiled"),
|
|
11017
11137
|
port: 0,
|
|
11018
11138
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
11019
11139
|
fps: job.config.fps,
|
|
@@ -11027,7 +11147,7 @@ async function runProbeStage(input) {
|
|
|
11027
11147
|
composition.videos,
|
|
11028
11148
|
compiled.html,
|
|
11029
11149
|
projectDir,
|
|
11030
|
-
|
|
11150
|
+
join24(workDir, "compiled")
|
|
11031
11151
|
),
|
|
11032
11152
|
recordReferenceBackground: input.recordReferenceBackground,
|
|
11033
11153
|
width,
|
|
@@ -11047,7 +11167,7 @@ async function runProbeStage(input) {
|
|
|
11047
11167
|
staticDedupMemo,
|
|
11048
11168
|
compositionHash: computeCompositionObservabilityHash(compiled.html),
|
|
11049
11169
|
deferStaticDedup: true,
|
|
11050
|
-
onStaticDedupActivity: () =>
|
|
11170
|
+
onStaticDedupActivity: () => noteCaptureActivity(job)
|
|
11051
11171
|
};
|
|
11052
11172
|
const PROBE_MAX_ATTEMPTS = 2;
|
|
11053
11173
|
for (let attempt = 1; attempt <= PROBE_MAX_ATTEMPTS; attempt++) {
|
|
@@ -11056,7 +11176,7 @@ async function runProbeStage(input) {
|
|
|
11056
11176
|
log.info("Creating capture session...", { attempt, maxAttempts: PROBE_MAX_ATTEMPTS });
|
|
11057
11177
|
probeSession = await createCaptureSession4(
|
|
11058
11178
|
fileServer.url,
|
|
11059
|
-
|
|
11179
|
+
join24(workDir, "probe"),
|
|
11060
11180
|
captureOpts,
|
|
11061
11181
|
null,
|
|
11062
11182
|
probeCfg
|
|
@@ -11142,7 +11262,7 @@ async function runProbeStage(input) {
|
|
|
11142
11262
|
});
|
|
11143
11263
|
probeSession = await createCaptureSession4(
|
|
11144
11264
|
fileServer.url,
|
|
11145
|
-
|
|
11265
|
+
join24(workDir, "probe-screenshot"),
|
|
11146
11266
|
captureOpts,
|
|
11147
11267
|
null,
|
|
11148
11268
|
{ ...probeCfg, forceScreenshot: true }
|
|
@@ -11186,7 +11306,7 @@ async function runProbeStage(input) {
|
|
|
11186
11306
|
compiled,
|
|
11187
11307
|
resolutions,
|
|
11188
11308
|
projectDir,
|
|
11189
|
-
|
|
11309
|
+
join24(workDir, "downloads"),
|
|
11190
11310
|
job.config.allowOutsideProjectAssets ? void 0 : projectDir,
|
|
11191
11311
|
{ includeScripts: job.config.includeOutsideScripts }
|
|
11192
11312
|
);
|
|
@@ -11392,7 +11512,7 @@ async function runProbeStage(input) {
|
|
|
11392
11512
|
});
|
|
11393
11513
|
await preflightCompositionAssetMediaTypes({
|
|
11394
11514
|
projectDir,
|
|
11395
|
-
compiledDir:
|
|
11515
|
+
compiledDir: join24(workDir, "compiled"),
|
|
11396
11516
|
composition,
|
|
11397
11517
|
signal: abortSignal
|
|
11398
11518
|
});
|
|
@@ -11559,8 +11679,8 @@ function validateDistributedDuration(input) {
|
|
|
11559
11679
|
}
|
|
11560
11680
|
|
|
11561
11681
|
// src/services/render/stages/extractVideosStage.ts
|
|
11562
|
-
import { existsSync as
|
|
11563
|
-
import { join as
|
|
11682
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
11683
|
+
import { join as join25 } from "node:path";
|
|
11564
11684
|
import {
|
|
11565
11685
|
classifyVideoExtractionError,
|
|
11566
11686
|
createFrameLookupTable as createFrameLookupTable3,
|
|
@@ -11930,7 +12050,7 @@ async function runExtractVideosStage(input) {
|
|
|
11930
12050
|
// because short boundary counts can differ by one frame.
|
|
11931
12051
|
{
|
|
11932
12052
|
fps: job.config.fps,
|
|
11933
|
-
outputDir:
|
|
12053
|
+
outputDir: join25(compiledDir, "__hyperframes_video_frames"),
|
|
11934
12054
|
format: job.config.videoFrameFormat ?? "auto",
|
|
11935
12055
|
toneMapHdrToSdr: rendersSdrOnly(job.config, composition),
|
|
11936
12056
|
timelineEnd: composition.duration,
|
|
@@ -11938,7 +12058,7 @@ async function runExtractVideosStage(input) {
|
|
|
11938
12058
|
collectProbeFailures: extractionPolicy.failureMode === "enforce",
|
|
11939
12059
|
deferRangeExtraction,
|
|
11940
12060
|
shownBoxes,
|
|
11941
|
-
contentKeyedDirs: [
|
|
12061
|
+
contentKeyedDirs: [join25(compiledDir, REMOTE_MEDIA_SUBDIR)],
|
|
11942
12062
|
urlByAbsentLocalPath,
|
|
11943
12063
|
assetRoots,
|
|
11944
12064
|
onProgress: ({ planned = 0, done = 0 }) => {
|
|
@@ -12018,7 +12138,7 @@ function isPublicHttpsUrl(url) {
|
|
|
12018
12138
|
}
|
|
12019
12139
|
}
|
|
12020
12140
|
function opensLocally(path, assetRoots) {
|
|
12021
|
-
return
|
|
12141
|
+
return existsSync14(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
|
|
12022
12142
|
}
|
|
12023
12143
|
function localProbeSource(src, input) {
|
|
12024
12144
|
const path = resolveProjectRelativeSrc5(src, input.projectDir, input.compiledDir);
|
|
@@ -12030,7 +12150,7 @@ async function remoteProbeSource(video, input) {
|
|
|
12030
12150
|
if (!isPublicHttpsUrl(video.src)) return null;
|
|
12031
12151
|
if (!resolveRestrictPageNetwork()) return video.src;
|
|
12032
12152
|
if (!video.hasAudio || video.hidden) return null;
|
|
12033
|
-
const downloadDir = input.downloadDir ??
|
|
12153
|
+
const downloadDir = input.downloadDir ?? join25(input.compiledDir, REMOTE_MEDIA_SUBDIR);
|
|
12034
12154
|
try {
|
|
12035
12155
|
return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
|
|
12036
12156
|
onTelemetry: writeUrlDownloadTelemetry2
|
|
@@ -12071,7 +12191,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
12071
12191
|
}
|
|
12072
12192
|
|
|
12073
12193
|
// src/services/render/videoLayerPassthroughPlan.ts
|
|
12074
|
-
import { existsSync as
|
|
12194
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
12075
12195
|
import {
|
|
12076
12196
|
buildVideoLayerInput,
|
|
12077
12197
|
isHttpUrl as isHttpUrl4,
|
|
@@ -12139,7 +12259,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
12139
12259
|
const { video } = q;
|
|
12140
12260
|
if (isHttpUrl4(video.src)) return { reason: "remote_source" };
|
|
12141
12261
|
const path = resolveProjectRelativeSrc6(video.src, input.projectDir, input.compiledDir);
|
|
12142
|
-
if (!
|
|
12262
|
+
if (!existsSync15(path)) return { reason: "source_missing" };
|
|
12143
12263
|
const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
|
|
12144
12264
|
if ("reason" in layout) return layout;
|
|
12145
12265
|
const layer = await buildVideoLayerInput(
|
|
@@ -12154,8 +12274,8 @@ async function planVideoLayerPassthrough(input) {
|
|
|
12154
12274
|
}
|
|
12155
12275
|
|
|
12156
12276
|
// src/services/render/stages/audioStage.ts
|
|
12157
|
-
import { existsSync as
|
|
12158
|
-
import { join as
|
|
12277
|
+
import { existsSync as existsSync17 } from "node:fs";
|
|
12278
|
+
import { join as join28 } from "node:path";
|
|
12159
12279
|
import {
|
|
12160
12280
|
MIXED_AUDIO_FILENAME,
|
|
12161
12281
|
audioFailureDiagnostics,
|
|
@@ -12166,8 +12286,8 @@ import {
|
|
|
12166
12286
|
} from "@hyperframes/engine";
|
|
12167
12287
|
|
|
12168
12288
|
// src/services/render/audioDeliveryLimit.ts
|
|
12169
|
-
import { existsSync as
|
|
12170
|
-
import { dirname as
|
|
12289
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
12290
|
+
import { dirname as dirname12, join as join27 } from "node:path";
|
|
12171
12291
|
import {
|
|
12172
12292
|
applyAudioFxChain,
|
|
12173
12293
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -12178,7 +12298,7 @@ import {
|
|
|
12178
12298
|
// src/services/render/audioPadTrim.ts
|
|
12179
12299
|
import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
12180
12300
|
import { spawn } from "node:child_process";
|
|
12181
|
-
import { dirname as
|
|
12301
|
+
import { dirname as dirname11, join as join26 } from "node:path";
|
|
12182
12302
|
import {
|
|
12183
12303
|
DEFAULT_CONFIG,
|
|
12184
12304
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -12459,7 +12579,7 @@ async function constrainAacTruePeak(input) {
|
|
|
12459
12579
|
}
|
|
12460
12580
|
async function cutSource(input, scratchDir, attenuationDb) {
|
|
12461
12581
|
if (!input.sourcePath || !input.rewriteSource) return true;
|
|
12462
|
-
const cutPath =
|
|
12582
|
+
const cutPath = join26(scratchDir, "source.wav");
|
|
12463
12583
|
try {
|
|
12464
12584
|
const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
|
|
12465
12585
|
if (!result.success) throw new Error(result.error);
|
|
@@ -12473,8 +12593,8 @@ async function cutSource(input, scratchDir, attenuationDb) {
|
|
|
12473
12593
|
async function enforceAacTruePeak(input) {
|
|
12474
12594
|
let scratchDir;
|
|
12475
12595
|
try {
|
|
12476
|
-
scratchDir = createStagingDir3(
|
|
12477
|
-
const correctedPath =
|
|
12596
|
+
scratchDir = createStagingDir3(dirname11(input.audioPath), ".true-peak-");
|
|
12597
|
+
const correctedPath = join26(scratchDir, "audio.m4a");
|
|
12478
12598
|
const measurements = [];
|
|
12479
12599
|
let attenuationDb = 0;
|
|
12480
12600
|
let sourcePeakDbfs;
|
|
@@ -12690,14 +12810,14 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
12690
12810
|
applyChain: applyAudioFxChain,
|
|
12691
12811
|
encode: encodeAac2,
|
|
12692
12812
|
rename: renameWithRetry5,
|
|
12693
|
-
sourceExists:
|
|
12813
|
+
sourceExists: existsSync16
|
|
12694
12814
|
}) {
|
|
12695
12815
|
const { audioPath, sourcePath, signal, timeoutMs } = input;
|
|
12696
12816
|
if (!deps.sourceExists(sourcePath)) return { success: true };
|
|
12697
12817
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
12698
12818
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
12699
12819
|
const alternating = ["a", "b"].map(
|
|
12700
|
-
(k) =>
|
|
12820
|
+
(k) => join27(dirname12(sourcePath), `audio-source-limited-${k}.wav`)
|
|
12701
12821
|
);
|
|
12702
12822
|
let encodedFrom;
|
|
12703
12823
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -12770,7 +12890,7 @@ function runAudioStage(input) {
|
|
|
12770
12890
|
}
|
|
12771
12891
|
async function runAudioStageScoped(input) {
|
|
12772
12892
|
const stageStart = Date.now();
|
|
12773
|
-
const pcmSourcePath =
|
|
12893
|
+
const pcmSourcePath = join28(input.workDir, "audio-source.wav");
|
|
12774
12894
|
const duration = input.totalFrames * input.fps.den / input.fps.num;
|
|
12775
12895
|
let deliverySourcePath;
|
|
12776
12896
|
try {
|
|
@@ -12786,7 +12906,7 @@ async function runAudioStageScoped(input) {
|
|
|
12786
12906
|
);
|
|
12787
12907
|
audioLoweredDb = guard.loweredDb;
|
|
12788
12908
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
12789
|
-
if (input.keepDeliverySource && !guard.sourceStale &&
|
|
12909
|
+
if (input.keepDeliverySource && !guard.sourceStale && existsSync17(pcmSourcePath)) {
|
|
12790
12910
|
deliverySourcePath = pcmSourcePath;
|
|
12791
12911
|
}
|
|
12792
12912
|
}
|
|
@@ -12835,7 +12955,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
12835
12955
|
assertNotAborted,
|
|
12836
12956
|
log
|
|
12837
12957
|
} = input;
|
|
12838
|
-
const audioOutputPath =
|
|
12958
|
+
const audioOutputPath = join28(workDir, MIXED_AUDIO_FILENAME);
|
|
12839
12959
|
let hasAudio = false;
|
|
12840
12960
|
let audioError;
|
|
12841
12961
|
let audioFailures;
|
|
@@ -12915,8 +13035,8 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
12915
13035
|
}
|
|
12916
13036
|
|
|
12917
13037
|
// src/services/render/stages/captureStage.ts
|
|
12918
|
-
import { existsSync as
|
|
12919
|
-
import { join as
|
|
13038
|
+
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
13039
|
+
import { join as join29 } from "node:path";
|
|
12920
13040
|
import {
|
|
12921
13041
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
12922
13042
|
frameFileExtension,
|
|
@@ -12986,16 +13106,16 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
|
|
|
12986
13106
|
}
|
|
12987
13107
|
function measureCaptureFrameBytes(workDir, framesDir) {
|
|
12988
13108
|
let total = sampleDirectoryBytes(framesDir);
|
|
12989
|
-
if (!
|
|
13109
|
+
if (!existsSync18(workDir)) return total;
|
|
12990
13110
|
for (const attempt of readdirSync4(workDir)) {
|
|
12991
13111
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
12992
|
-
total += sampleDirectoryBytes(
|
|
13112
|
+
total += sampleDirectoryBytes(join29(workDir, attempt));
|
|
12993
13113
|
continue;
|
|
12994
13114
|
}
|
|
12995
13115
|
if (!/^capture-attempt-\d+$/.test(attempt)) continue;
|
|
12996
|
-
const attemptDir =
|
|
13116
|
+
const attemptDir = join29(workDir, attempt);
|
|
12997
13117
|
for (const name of readdirSync4(attemptDir)) {
|
|
12998
|
-
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(
|
|
13118
|
+
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join29(attemptDir, name));
|
|
12999
13119
|
}
|
|
13000
13120
|
}
|
|
13001
13121
|
return total;
|
|
@@ -13293,8 +13413,8 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13293
13413
|
}
|
|
13294
13414
|
|
|
13295
13415
|
// src/services/render/stages/captureHdrStage.ts
|
|
13296
|
-
import { existsSync as
|
|
13297
|
-
import { join as
|
|
13416
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync10 } from "node:fs";
|
|
13417
|
+
import { join as join33 } from "node:path";
|
|
13298
13418
|
import {
|
|
13299
13419
|
closeCaptureSession as closeCaptureSession7,
|
|
13300
13420
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
@@ -13366,7 +13486,7 @@ function createHdrImageTransferCache(options = {}) {
|
|
|
13366
13486
|
}
|
|
13367
13487
|
|
|
13368
13488
|
// src/services/render/stages/captureHdrSequentialLoop.ts
|
|
13369
|
-
import { join as
|
|
13489
|
+
import { join as join30 } from "node:path";
|
|
13370
13490
|
import {
|
|
13371
13491
|
TRANSITIONS,
|
|
13372
13492
|
crossfade
|
|
@@ -13491,7 +13611,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13491
13611
|
);
|
|
13492
13612
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
13493
13613
|
writeFileExclusiveSync(
|
|
13494
|
-
|
|
13614
|
+
join30(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
13495
13615
|
normalCanvas
|
|
13496
13616
|
);
|
|
13497
13617
|
}
|
|
@@ -13523,7 +13643,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13523
13643
|
}
|
|
13524
13644
|
|
|
13525
13645
|
// src/services/render/stages/captureHdrHybridLoop.ts
|
|
13526
|
-
import { join as
|
|
13646
|
+
import { join as join32 } from "node:path";
|
|
13527
13647
|
import {
|
|
13528
13648
|
TRANSITIONS as TRANSITIONS2,
|
|
13529
13649
|
closeCaptureSession as closeCaptureSession6,
|
|
@@ -13535,12 +13655,12 @@ import {
|
|
|
13535
13655
|
} from "@hyperframes/engine";
|
|
13536
13656
|
|
|
13537
13657
|
// src/services/shaderTransitionWorkerPool.ts
|
|
13538
|
-
import { Worker } from "node:worker_threads";
|
|
13539
|
-
import { fileURLToPath as
|
|
13540
|
-
import { dirname as
|
|
13658
|
+
import { Worker as Worker2 } from "node:worker_threads";
|
|
13659
|
+
import { fileURLToPath as fileURLToPath4, pathToFileURL } from "node:url";
|
|
13660
|
+
import { dirname as dirname13, join as join31 } from "node:path";
|
|
13541
13661
|
import { createRequire } from "node:module";
|
|
13542
13662
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
13543
|
-
import { existsSync as
|
|
13663
|
+
import { existsSync as existsSync19 } from "node:fs";
|
|
13544
13664
|
function resolveWorkerEntry(explicit) {
|
|
13545
13665
|
if (explicit && explicit.length > 0) {
|
|
13546
13666
|
return { path: explicit, isTs: explicit.endsWith(".ts") };
|
|
@@ -13550,10 +13670,10 @@ function resolveWorkerEntry(explicit) {
|
|
|
13550
13670
|
const isTs = override.endsWith(".ts");
|
|
13551
13671
|
return { path: override, isTs };
|
|
13552
13672
|
}
|
|
13553
|
-
const moduleDir =
|
|
13554
|
-
const jsPath =
|
|
13555
|
-
if (
|
|
13556
|
-
const tsPath =
|
|
13673
|
+
const moduleDir = dirname13(fileURLToPath4(import.meta.url));
|
|
13674
|
+
const jsPath = join31(moduleDir, "shaderTransitionWorker.js");
|
|
13675
|
+
if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
|
|
13676
|
+
const tsPath = join31(moduleDir, "shaderTransitionWorker.ts");
|
|
13557
13677
|
return { path: tsPath, isTs: true };
|
|
13558
13678
|
}
|
|
13559
13679
|
function buildExecArgv(entryIsTs) {
|
|
@@ -13674,7 +13794,7 @@ async function createShaderTransitionWorkerPool(opts) {
|
|
|
13674
13794
|
};
|
|
13675
13795
|
try {
|
|
13676
13796
|
for (let i = 0; i < size; i++) {
|
|
13677
|
-
const worker = new
|
|
13797
|
+
const worker = new Worker2(entry, { execArgv });
|
|
13678
13798
|
const slot = { worker, busy: false, current: null, dead: false };
|
|
13679
13799
|
worker.on("message", (msg) => onWorkerMessage(slot, msg));
|
|
13680
13800
|
worker.on(
|
|
@@ -13921,7 +14041,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
13921
14041
|
);
|
|
13922
14042
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
13923
14043
|
writeFileExclusiveSync(
|
|
13924
|
-
|
|
14044
|
+
join32(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
13925
14045
|
canvas
|
|
13926
14046
|
);
|
|
13927
14047
|
}
|
|
@@ -14117,8 +14237,8 @@ async function runCaptureHdrStage(input) {
|
|
|
14117
14237
|
if (hdrVideoFrameSources.has(v.id)) hdrVideoEndTimes.set(v.id, v.end);
|
|
14118
14238
|
}
|
|
14119
14239
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
14120
|
-
const debugDumpDir = debugDumpEnabled ?
|
|
14121
|
-
if (debugDumpDir && !
|
|
14240
|
+
const debugDumpDir = debugDumpEnabled ? join33(framesDir, "debug-composite") : null;
|
|
14241
|
+
if (debugDumpDir && !existsSync20(debugDumpDir)) {
|
|
14122
14242
|
mkdirSync10(debugDumpDir, { recursive: true });
|
|
14123
14243
|
}
|
|
14124
14244
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
@@ -14277,7 +14397,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14277
14397
|
// src/services/render/stages/encodeStage.ts
|
|
14278
14398
|
import {
|
|
14279
14399
|
copyFileSync as copyFileSync4,
|
|
14280
|
-
existsSync as
|
|
14400
|
+
existsSync as existsSync21,
|
|
14281
14401
|
mkdirSync as mkdirSync11,
|
|
14282
14402
|
readdirSync as readdirSync5,
|
|
14283
14403
|
readFileSync as readFileSync9,
|
|
@@ -14286,7 +14406,7 @@ import {
|
|
|
14286
14406
|
writeFileSync as writeFileSync5
|
|
14287
14407
|
} from "node:fs";
|
|
14288
14408
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
14289
|
-
import { dirname as
|
|
14409
|
+
import { dirname as dirname14, join as join34 } from "node:path";
|
|
14290
14410
|
import {
|
|
14291
14411
|
encodeFramesChunkedConcat,
|
|
14292
14412
|
encodeFramesFromDir,
|
|
@@ -14411,7 +14531,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
14411
14531
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
14412
14532
|
if (failure) return failure;
|
|
14413
14533
|
}
|
|
14414
|
-
const fileSize =
|
|
14534
|
+
const fileSize = existsSync21(outputPath) ? statSync9(outputPath).size : 0;
|
|
14415
14535
|
return {
|
|
14416
14536
|
success: true,
|
|
14417
14537
|
outputPath,
|
|
@@ -14505,7 +14625,7 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
14505
14625
|
await new Promise((resolve14) => wake = resolve14);
|
|
14506
14626
|
}
|
|
14507
14627
|
if (signal.aborted) return;
|
|
14508
|
-
const mergedPath =
|
|
14628
|
+
const mergedPath = join34(input.framesDir, formatCaptureFrameName(next, "jpg"));
|
|
14509
14629
|
const frame = await readLandedFrame(landed.get(next), mergedPath);
|
|
14510
14630
|
landed.delete(next);
|
|
14511
14631
|
if (!await stream.writeFrame(frame)) {
|
|
@@ -14580,7 +14700,7 @@ async function runEncodeStage(input) {
|
|
|
14580
14700
|
const stage5Start = Date.now();
|
|
14581
14701
|
if (isPngSequence) {
|
|
14582
14702
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
14583
|
-
if (!
|
|
14703
|
+
if (!existsSync21(outputPath)) mkdirSync11(outputPath, { recursive: true });
|
|
14584
14704
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
14585
14705
|
if (captured.length === 0) {
|
|
14586
14706
|
throw new Error(
|
|
@@ -14588,11 +14708,11 @@ async function runEncodeStage(input) {
|
|
|
14588
14708
|
);
|
|
14589
14709
|
}
|
|
14590
14710
|
captured.forEach((name, i) => {
|
|
14591
|
-
const dst =
|
|
14592
|
-
copyFileSync4(
|
|
14711
|
+
const dst = join34(outputPath, formatExportFrameName(i, "png"));
|
|
14712
|
+
copyFileSync4(join34(framesDir, name), dst);
|
|
14593
14713
|
});
|
|
14594
|
-
if (hasAudio && audioOutputPath &&
|
|
14595
|
-
copyFileSync4(audioOutputPath,
|
|
14714
|
+
if (hasAudio && audioOutputPath && existsSync21(audioOutputPath)) {
|
|
14715
|
+
copyFileSync4(audioOutputPath, join34(outputPath, MIXED_AUDIO_FILENAME2));
|
|
14596
14716
|
log.info(
|
|
14597
14717
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
14598
14718
|
);
|
|
@@ -14612,7 +14732,7 @@ async function runEncodeStage(input) {
|
|
|
14612
14732
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
14613
14733
|
fps: job.config.fps,
|
|
14614
14734
|
loop,
|
|
14615
|
-
palettePath:
|
|
14735
|
+
palettePath: join34(dirname14(videoOnlyPath), "gif-palette.png"),
|
|
14616
14736
|
preserveAlpha: needsAlpha,
|
|
14617
14737
|
signal: abortSignal,
|
|
14618
14738
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -14823,7 +14943,7 @@ function sampleDirectoryBytes(dir) {
|
|
|
14823
14943
|
continue;
|
|
14824
14944
|
}
|
|
14825
14945
|
for (const name of entries) {
|
|
14826
|
-
const full =
|
|
14946
|
+
const full = join35(current, name);
|
|
14827
14947
|
try {
|
|
14828
14948
|
const st = statSync10(full);
|
|
14829
14949
|
if (st.isDirectory()) {
|
|
@@ -14981,8 +15101,8 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
14981
15101
|
const ranges = [];
|
|
14982
15102
|
let rangeStart = null;
|
|
14983
15103
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14984
|
-
const framePath =
|
|
14985
|
-
const missing = !
|
|
15104
|
+
const framePath = join35(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
15105
|
+
const missing = !existsSync22(framePath) || statSync10(framePath).size <= 8;
|
|
14986
15106
|
if (missing && rangeStart === null) {
|
|
14987
15107
|
rangeStart = frameIndex;
|
|
14988
15108
|
} else if (!missing && rangeStart !== null) {
|
|
@@ -14998,7 +15118,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
14998
15118
|
function buildMissingFrameRetryBatches(ranges, maxWorkers, workDir, attempt, rangeStart = 0, stride = 1) {
|
|
14999
15119
|
const workersPerBatch = Math.max(1, Math.floor(maxWorkers));
|
|
15000
15120
|
const batches = [];
|
|
15001
|
-
const outputDirFor = (batchIndex, workerId) =>
|
|
15121
|
+
const outputDirFor = (batchIndex, workerId) => join35(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
|
|
15002
15122
|
if (stride > 1) {
|
|
15003
15123
|
const spans = /* @__PURE__ */ new Map();
|
|
15004
15124
|
for (const range of ranges) {
|
|
@@ -15058,8 +15178,8 @@ function getNextRetryWorkerCount(currentWorkers) {
|
|
|
15058
15178
|
return Math.max(1, Math.floor(currentWorkers / 2));
|
|
15059
15179
|
}
|
|
15060
15180
|
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir3()) {
|
|
15061
|
-
if (platform2 === "win32" || platform2 === "darwin") return
|
|
15062
|
-
return
|
|
15181
|
+
if (platform2 === "win32" || platform2 === "darwin") return join35(systemTempDir, "hf-render-");
|
|
15182
|
+
return join35(dirname15(outputPath), `work-${jobId}-`);
|
|
15063
15183
|
}
|
|
15064
15184
|
var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
|
|
15065
15185
|
function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
|
|
@@ -15090,7 +15210,7 @@ function frameStallRule(job, totalFrames, probeStartupMs) {
|
|
|
15090
15210
|
tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
|
|
15091
15211
|
detail: () => describeWorkerPhases(job),
|
|
15092
15212
|
attemptOpened: () => forgetWorkerPhases(job),
|
|
15093
|
-
activity: () =>
|
|
15213
|
+
activity: () => captureActivity(job)
|
|
15094
15214
|
};
|
|
15095
15215
|
}
|
|
15096
15216
|
function isRecoverableParallelCaptureError(error) {
|
|
@@ -15114,8 +15234,8 @@ The composition is too large for the available memory. To reduce memory pressure
|
|
|
15114
15234
|
function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
15115
15235
|
let captured = 0;
|
|
15116
15236
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
15117
|
-
const framePath =
|
|
15118
|
-
if (
|
|
15237
|
+
const framePath = join35(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
15238
|
+
if (existsSync22(framePath)) captured++;
|
|
15119
15239
|
}
|
|
15120
15240
|
return captured;
|
|
15121
15241
|
}
|
|
@@ -15140,7 +15260,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15140
15260
|
reason: attempt === 0 ? "initial" : pendingTransientRetry ? "transient-retry" : "retry"
|
|
15141
15261
|
});
|
|
15142
15262
|
pendingTransientRetry = false;
|
|
15143
|
-
const attemptWorkDir =
|
|
15263
|
+
const attemptWorkDir = join35(options.workDir, `capture-attempt-${attempt}`);
|
|
15144
15264
|
const batches = missingRanges ? buildMissingFrameRetryBatches(
|
|
15145
15265
|
missingRanges,
|
|
15146
15266
|
currentWorkers,
|
|
@@ -15787,20 +15907,20 @@ function deVerifyFallbackTelemetry(err) {
|
|
|
15787
15907
|
};
|
|
15788
15908
|
}
|
|
15789
15909
|
function resolveRenderDebugDir() {
|
|
15790
|
-
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(
|
|
15791
|
-
return
|
|
15910
|
+
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(dirname15(fileURLToPath5(import.meta.url)), "../..");
|
|
15911
|
+
return join35(producerRoot, ".debug");
|
|
15792
15912
|
}
|
|
15793
15913
|
async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
15794
15914
|
validateHlsRenderConfig(job.config);
|
|
15795
15915
|
validateDeliveryEncoderConfig(job.config);
|
|
15796
15916
|
validateChromaSubsamplingConfig(job.config);
|
|
15797
15917
|
const debugDir = resolveRenderDebugDir();
|
|
15798
|
-
const outputDir =
|
|
15799
|
-
if (!
|
|
15800
|
-
const workDir = job.config.debug ?
|
|
15918
|
+
const outputDir = dirname15(outputPath);
|
|
15919
|
+
if (!existsSync22(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
15920
|
+
const workDir = job.config.debug ? join35(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
15801
15921
|
const pipelineStart = Date.now();
|
|
15802
15922
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
15803
|
-
const logPath = job.config.debug ?
|
|
15923
|
+
const logPath = job.config.debug ? join35(workDir, "render.log") : null;
|
|
15804
15924
|
const execution = new RenderExecutionContext({
|
|
15805
15925
|
request: { renderJobId: job.id, projectDir, outputPath },
|
|
15806
15926
|
logger: logPath ? createRenderFileLogger(logPath, baseLog) : baseLog,
|
|
@@ -15877,7 +15997,7 @@ async function executeRenderPipeline(input) {
|
|
|
15877
15997
|
imageDecodeFailures: 0
|
|
15878
15998
|
};
|
|
15879
15999
|
let hdrPerf;
|
|
15880
|
-
const perfOutputPath =
|
|
16000
|
+
const perfOutputPath = join35(workDir, "perf-summary.json");
|
|
15881
16001
|
const cfg = { ...job.config.producerConfig ?? resolveConfig2() };
|
|
15882
16002
|
const observability = new RenderObservabilityRecorder({
|
|
15883
16003
|
pipelineStartMs: pipelineStart,
|
|
@@ -15953,7 +16073,7 @@ async function executeRenderPipeline(input) {
|
|
|
15953
16073
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
15954
16074
|
assertNotAborted();
|
|
15955
16075
|
assertConfiguredFfmpegBinariesExist();
|
|
15956
|
-
if (!
|
|
16076
|
+
if (!existsSync22(workDir)) mkdirSync12(workDir, { recursive: true });
|
|
15957
16077
|
if (job.config.debug) {
|
|
15958
16078
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
15959
16079
|
}
|
|
@@ -15982,8 +16102,8 @@ async function executeRenderPipeline(input) {
|
|
|
15982
16102
|
requestedWorkers: job.config.workers ?? "auto"
|
|
15983
16103
|
});
|
|
15984
16104
|
const entryFile = job.config.entryFile || "index.html";
|
|
15985
|
-
const htmlPath =
|
|
15986
|
-
if (!
|
|
16105
|
+
const htmlPath = join35(projectDir, entryFile);
|
|
16106
|
+
if (!existsSync22(htmlPath)) {
|
|
15987
16107
|
throw new Error(`Entry file not found: ${htmlPath}`);
|
|
15988
16108
|
}
|
|
15989
16109
|
assertNotAborted();
|
|
@@ -16080,7 +16200,7 @@ async function executeRenderPipeline(input) {
|
|
|
16080
16200
|
const largerThanCanvas = await oversizedVideos(
|
|
16081
16201
|
composition.videos,
|
|
16082
16202
|
projectDir,
|
|
16083
|
-
|
|
16203
|
+
join35(workDir, "compiled"),
|
|
16084
16204
|
{ width: outputWidth, height: outputHeight }
|
|
16085
16205
|
);
|
|
16086
16206
|
const probeResult = await observeRenderStage(
|
|
@@ -16177,7 +16297,7 @@ async function executeRenderPipeline(input) {
|
|
|
16177
16297
|
canvas: { width, height },
|
|
16178
16298
|
page: probeSession.page,
|
|
16179
16299
|
projectDir,
|
|
16180
|
-
compiledDir:
|
|
16300
|
+
compiledDir: join35(workDir, "compiled")
|
|
16181
16301
|
});
|
|
16182
16302
|
if (videoLayerPlan.videoId === void 0) {
|
|
16183
16303
|
log.info(`[Render] Video layer passthrough off: ${videoLayerPlan.reason}`);
|
|
@@ -16195,7 +16315,7 @@ async function executeRenderPipeline(input) {
|
|
|
16195
16315
|
updateJobStatus(job, "preprocessing", "Extracting video frames", 10, onProgress, {
|
|
16196
16316
|
code: "extract_video"
|
|
16197
16317
|
});
|
|
16198
|
-
const compiledDir =
|
|
16318
|
+
const compiledDir = join35(workDir, "compiled");
|
|
16199
16319
|
const segmentsCapture = (layeredOrEffectRoute) => shouldSegmentCapture({
|
|
16200
16320
|
env: process.env,
|
|
16201
16321
|
durationSeconds: probeResult.duration,
|
|
@@ -16336,7 +16456,7 @@ async function executeRenderPipeline(input) {
|
|
|
16336
16456
|
try {
|
|
16337
16457
|
fileServer = await createFileServer({
|
|
16338
16458
|
projectDir,
|
|
16339
|
-
compiledDir:
|
|
16459
|
+
compiledDir: join35(workDir, "compiled"),
|
|
16340
16460
|
port: 0,
|
|
16341
16461
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
16342
16462
|
fps: job.config.fps,
|
|
@@ -16356,8 +16476,8 @@ async function executeRenderPipeline(input) {
|
|
|
16356
16476
|
if (!activeFileServer) {
|
|
16357
16477
|
throw new Error("File server failed to initialize before frame capture");
|
|
16358
16478
|
}
|
|
16359
|
-
const framesDir =
|
|
16360
|
-
if (!
|
|
16479
|
+
const framesDir = join35(workDir, "captured-frames");
|
|
16480
|
+
if (!existsSync22(framesDir)) mkdirSync12(framesDir, { recursive: true });
|
|
16361
16481
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
16362
16482
|
code: "start_browsers"
|
|
16363
16483
|
});
|
|
@@ -16418,7 +16538,7 @@ async function executeRenderPipeline(input) {
|
|
|
16418
16538
|
subTimelineWaitMemo,
|
|
16419
16539
|
staticDedupMemo,
|
|
16420
16540
|
compositionHash,
|
|
16421
|
-
onStaticDedupActivity: () =>
|
|
16541
|
+
onStaticDedupActivity: () => noteCaptureActivity(job),
|
|
16422
16542
|
// Probe-resolved duration: drawElement self-verification derives its
|
|
16423
16543
|
// sample frame indices from this so they land inside the drained range.
|
|
16424
16544
|
compositionDurationSeconds: job.duration,
|
|
@@ -16937,7 +17057,7 @@ async function executeRenderPipeline(input) {
|
|
|
16937
17057
|
hls: ".mp4"
|
|
16938
17058
|
};
|
|
16939
17059
|
const videoExt = FORMAT_EXT[outputFormat] ?? ".mp4";
|
|
16940
|
-
const videoOnlyPath =
|
|
17060
|
+
const videoOnlyPath = join35(workDir, `video-only${videoExt}`);
|
|
16941
17061
|
let usePageSideCompositingForTransitions = (cfg.enablePageSideCompositing || isGif) && compiled.hasShaderTransitions && !hasHdrContent && outputSupportsPageSideShaderCompositing(outputFormat);
|
|
16942
17062
|
if (usePageSideCompositingForTransitions) {
|
|
16943
17063
|
activeFileServer.addPreHeadScript(HF_PAGE_SIDE_COMPOSITING_STUB);
|
|
@@ -17799,7 +17919,7 @@ async function executeRenderPipeline(input) {
|
|
|
17799
17919
|
})
|
|
17800
17920
|
);
|
|
17801
17921
|
const totalElapsed = Date.now() - pipelineStart;
|
|
17802
|
-
const tmpPeakBytes =
|
|
17922
|
+
const tmpPeakBytes = existsSync22(workDir) ? sampleDirectoryBytes(workDir) : 0;
|
|
17803
17923
|
recordTransientRetryObservability();
|
|
17804
17924
|
observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
|
|
17805
17925
|
const observabilitySummary = observability.summary({
|
|
@@ -17880,8 +18000,8 @@ async function executeRenderPipeline(input) {
|
|
|
17880
18000
|
}
|
|
17881
18001
|
}
|
|
17882
18002
|
if (job.config.debug) {
|
|
17883
|
-
if (!isPngSequence && !isHls &&
|
|
17884
|
-
const debugOutput =
|
|
18003
|
+
if (!isPngSequence && !isHls && existsSync22(stagedOutputPath)) {
|
|
18004
|
+
const debugOutput = join35(workDir, `output${videoExt}`);
|
|
17885
18005
|
copyFileSync5(stagedOutputPath, debugOutput);
|
|
17886
18006
|
}
|
|
17887
18007
|
}
|
|
@@ -18000,14 +18120,14 @@ import {
|
|
|
18000
18120
|
referenceBackgroundResult as referenceBackgroundResult6
|
|
18001
18121
|
} from "@hyperframes/engine";
|
|
18002
18122
|
import { mkdirSync as mkdirSync20, mkdtempSync, readFileSync as readFileSync15, rmSync as rmSync18 } from "node:fs";
|
|
18003
|
-
import { join as
|
|
18123
|
+
import { join as join49 } from "node:path";
|
|
18004
18124
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
18005
18125
|
|
|
18006
18126
|
// src/services/distributed/mp4Stitch.ts
|
|
18007
18127
|
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync13 } from "node:fs";
|
|
18008
18128
|
import { open } from "node:fs/promises";
|
|
18009
18129
|
import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
|
|
18010
|
-
import { basename as basename8, dirname as
|
|
18130
|
+
import { basename as basename8, dirname as dirname16, join as join36 } from "node:path";
|
|
18011
18131
|
import { finished, pipeline } from "node:stream/promises";
|
|
18012
18132
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
18013
18133
|
function boxAt(src, off, at, limit) {
|
|
@@ -18372,15 +18492,15 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
18372
18492
|
const sourcePaths = audioPath ? [audioPath, ...chunkPaths] : chunkPaths;
|
|
18373
18493
|
const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
|
|
18374
18494
|
const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
|
|
18375
|
-
mkdirSync13(
|
|
18376
|
-
const workDir = createStagingDir4(
|
|
18377
|
-
const out = createWriteStream(
|
|
18495
|
+
mkdirSync13(dirname16(outputPath), { recursive: true });
|
|
18496
|
+
const workDir = createStagingDir4(dirname16(outputPath), `${basename8(outputPath)}.stitch-`);
|
|
18497
|
+
const out = createWriteStream(join36(workDir, "out.mp4"));
|
|
18378
18498
|
try {
|
|
18379
18499
|
out.write(header);
|
|
18380
18500
|
for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
|
|
18381
18501
|
out.end();
|
|
18382
18502
|
await finished(out);
|
|
18383
|
-
renameWithRetry6(
|
|
18503
|
+
renameWithRetry6(join36(workDir, "out.mp4"), outputPath);
|
|
18384
18504
|
} finally {
|
|
18385
18505
|
out.destroy();
|
|
18386
18506
|
rmSync13(workDir, { recursive: true, force: true });
|
|
@@ -18397,13 +18517,13 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
|
|
|
18397
18517
|
import {
|
|
18398
18518
|
copyFileSync as copyFileSync6,
|
|
18399
18519
|
cpSync as cpSync2,
|
|
18400
|
-
existsSync as
|
|
18520
|
+
existsSync as existsSync27,
|
|
18401
18521
|
linkSync,
|
|
18402
18522
|
mkdirSync as mkdirSync16,
|
|
18403
18523
|
rmSync as rmSync14,
|
|
18404
18524
|
writeFileSync as writeFileSync9
|
|
18405
18525
|
} from "node:fs";
|
|
18406
|
-
import { extname as extname6, isAbsolute as isAbsolute4, join as
|
|
18526
|
+
import { extname as extname6, isAbsolute as isAbsolute4, join as join44, relative as relative7, sep as sep5 } from "node:path";
|
|
18407
18527
|
import {
|
|
18408
18528
|
fpsToNumber as fpsToNumber9,
|
|
18409
18529
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
@@ -18420,7 +18540,7 @@ import {
|
|
|
18420
18540
|
} from "@hyperframes/engine";
|
|
18421
18541
|
|
|
18422
18542
|
// src/services/distributed/planFrameCost.ts
|
|
18423
|
-
import { join as
|
|
18543
|
+
import { join as join39 } from "node:path";
|
|
18424
18544
|
import {
|
|
18425
18545
|
closeCaptureSession as closeCaptureSession9,
|
|
18426
18546
|
createCaptureSession as createCaptureSession9,
|
|
@@ -18429,8 +18549,8 @@ import {
|
|
|
18429
18549
|
} from "@hyperframes/engine";
|
|
18430
18550
|
|
|
18431
18551
|
// src/services/distributed/chunkFrames.ts
|
|
18432
|
-
import { existsSync as
|
|
18433
|
-
import { extname as extname4, join as
|
|
18552
|
+
import { existsSync as existsSync24, readdirSync as readdirSync7 } from "node:fs";
|
|
18553
|
+
import { extname as extname4, join as join38 } from "node:path";
|
|
18434
18554
|
import {
|
|
18435
18555
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
18436
18556
|
createVideoFrameInjector as createVideoFrameInjector3,
|
|
@@ -18439,9 +18559,9 @@ import {
|
|
|
18439
18559
|
|
|
18440
18560
|
// src/services/distributed/shared.ts
|
|
18441
18561
|
import { execFile as execFileCallback } from "node:child_process";
|
|
18442
|
-
import { dirname as
|
|
18443
|
-
import { existsSync as
|
|
18444
|
-
import { fileURLToPath as
|
|
18562
|
+
import { dirname as dirname17, join as join37 } from "node:path";
|
|
18563
|
+
import { existsSync as existsSync23, readFileSync as readFileSync10 } from "node:fs";
|
|
18564
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
18445
18565
|
import { promisify as promisify2 } from "node:util";
|
|
18446
18566
|
import {
|
|
18447
18567
|
getFfmpegBinary,
|
|
@@ -18455,8 +18575,8 @@ function isPlanAudioArtifactPath(path) {
|
|
|
18455
18575
|
}
|
|
18456
18576
|
function resolvePlanAudioPath(planDir) {
|
|
18457
18577
|
for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
|
|
18458
|
-
const candidate =
|
|
18459
|
-
if (
|
|
18578
|
+
const candidate = join37(planDir, name);
|
|
18579
|
+
if (existsSync23(candidate)) return candidate;
|
|
18460
18580
|
}
|
|
18461
18581
|
return null;
|
|
18462
18582
|
}
|
|
@@ -18717,11 +18837,11 @@ function buildSyntheticRenderJob(input) {
|
|
|
18717
18837
|
var cachedProducerVersion = null;
|
|
18718
18838
|
function readProducerVersion() {
|
|
18719
18839
|
if (cachedProducerVersion !== null) return cachedProducerVersion;
|
|
18720
|
-
const startDir =
|
|
18840
|
+
const startDir = dirname17(fileURLToPath6(import.meta.url));
|
|
18721
18841
|
let current = startDir;
|
|
18722
18842
|
for (let i = 0; i < 10; i++) {
|
|
18723
|
-
const candidate =
|
|
18724
|
-
if (
|
|
18843
|
+
const candidate = join37(current, "package.json");
|
|
18844
|
+
if (existsSync23(candidate)) {
|
|
18725
18845
|
try {
|
|
18726
18846
|
const pkg = JSON.parse(readFileSync10(candidate, "utf-8"));
|
|
18727
18847
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
@@ -18731,7 +18851,7 @@ function readProducerVersion() {
|
|
|
18731
18851
|
} catch {
|
|
18732
18852
|
}
|
|
18733
18853
|
}
|
|
18734
|
-
const parent =
|
|
18854
|
+
const parent = dirname17(current);
|
|
18735
18855
|
if (parent === current) break;
|
|
18736
18856
|
current = parent;
|
|
18737
18857
|
}
|
|
@@ -18775,8 +18895,8 @@ function frameNumberFromFileName(name) {
|
|
|
18775
18895
|
function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
|
|
18776
18896
|
const result = [];
|
|
18777
18897
|
for (const v of videos) {
|
|
18778
|
-
const outputDir =
|
|
18779
|
-
if (!
|
|
18898
|
+
const outputDir = join38(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
|
|
18899
|
+
if (!existsSync24(outputDir)) {
|
|
18780
18900
|
throw new Error(
|
|
18781
18901
|
`[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
|
|
18782
18902
|
);
|
|
@@ -18794,7 +18914,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
|
|
|
18794
18914
|
if (!frameName) continue;
|
|
18795
18915
|
const frameNumber = indexMode === "sparse-v2" ? frameNumberFromFileName(frameName) : null;
|
|
18796
18916
|
const frameIndex = frameNumber === null ? i : frameNumber - 1;
|
|
18797
|
-
framePaths.set(frameIndex,
|
|
18917
|
+
framePaths.set(frameIndex, join38(outputDir, frameName));
|
|
18798
18918
|
}
|
|
18799
18919
|
result.push({
|
|
18800
18920
|
videoId: v.videoId,
|
|
@@ -18871,11 +18991,12 @@ async function extractDeferredVideoFramesForChunk(input) {
|
|
|
18871
18991
|
outputRoot: input.outputRoot,
|
|
18872
18992
|
cfg: input.cfg,
|
|
18873
18993
|
shownBoxes: input.shownBoxes,
|
|
18994
|
+
...input.onProgress && { onProgress: input.onProgress },
|
|
18874
18995
|
sourceOf: (video) => {
|
|
18875
18996
|
const range = planned.get(video.videoId).deferredRange;
|
|
18876
18997
|
const remoteUrl = remoteSources[range.sourcePath];
|
|
18877
|
-
const sourcePath = remoteUrl ??
|
|
18878
|
-
if (remoteUrl === void 0 && !
|
|
18998
|
+
const sourcePath = remoteUrl ?? join38(input.planDir, ...range.sourcePath.split("/"));
|
|
18999
|
+
if (remoteUrl === void 0 && !existsSync24(sourcePath)) {
|
|
18879
19000
|
throw new RenderChunkValidationError(
|
|
18880
19001
|
MISSING_PLAN_ARTIFACT,
|
|
18881
19002
|
`[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
|
|
@@ -18905,12 +19026,12 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
18905
19026
|
planVideos,
|
|
18906
19027
|
frames: sampled,
|
|
18907
19028
|
fps: fpsRatio,
|
|
18908
|
-
outputRoot:
|
|
19029
|
+
outputRoot: join39(workDir, "frame-cost-video-frames"),
|
|
18909
19030
|
cfg: input.cfg
|
|
18910
19031
|
})
|
|
18911
19032
|
];
|
|
18912
19033
|
const lookup = extracted.length > 0 ? createFrameLookupTable4(planVideos.videos, extracted, resolveRenderFpsConfig(fpsRatio).value) : null;
|
|
18913
|
-
const compiledDir =
|
|
19034
|
+
const compiledDir = join39(planDir, "compiled");
|
|
18914
19035
|
const fileServer = await createFileServer({
|
|
18915
19036
|
projectDir: compiledDir,
|
|
18916
19037
|
compiledDir,
|
|
@@ -18922,7 +19043,7 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
18922
19043
|
try {
|
|
18923
19044
|
session = await createCaptureSession9(
|
|
18924
19045
|
fileServer.url,
|
|
18925
|
-
|
|
19046
|
+
join39(workDir, "frame-cost"),
|
|
18926
19047
|
buildChunkCaptureOptions({
|
|
18927
19048
|
dimensions: { ...input, fpsNum: fps, fpsDen: 1 },
|
|
18928
19049
|
encoder: input,
|
|
@@ -19019,7 +19140,7 @@ function buildWeightedChunkSlices(weights, chunkCount, minFrames, maxFrames) {
|
|
|
19019
19140
|
}
|
|
19020
19141
|
|
|
19021
19142
|
// src/services/render/planReferenceBackground.ts
|
|
19022
|
-
import { join as
|
|
19143
|
+
import { join as join40 } from "node:path";
|
|
19023
19144
|
import {
|
|
19024
19145
|
closeCaptureSession as closeCaptureSession10,
|
|
19025
19146
|
createCaptureSession as createCaptureSession10,
|
|
@@ -19032,14 +19153,14 @@ async function readPlanReferenceBackground(input) {
|
|
|
19032
19153
|
try {
|
|
19033
19154
|
server = await createFileServer({
|
|
19034
19155
|
projectDir: input.projectDir,
|
|
19035
|
-
compiledDir:
|
|
19156
|
+
compiledDir: join40(input.workDir, "compiled"),
|
|
19036
19157
|
port: 0,
|
|
19037
19158
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
19038
19159
|
fps: input.options.fps
|
|
19039
19160
|
});
|
|
19040
19161
|
session = await createCaptureSession10(
|
|
19041
19162
|
server.url,
|
|
19042
|
-
|
|
19163
|
+
join40(input.workDir, "reference"),
|
|
19043
19164
|
{
|
|
19044
19165
|
...input.options,
|
|
19045
19166
|
requiresWebGpu: false
|
|
@@ -19075,8 +19196,8 @@ async function readPlanReferenceBackground(input) {
|
|
|
19075
19196
|
}
|
|
19076
19197
|
|
|
19077
19198
|
// src/services/render/stages/freezePlan.ts
|
|
19078
|
-
import { existsSync as
|
|
19079
|
-
import { join as
|
|
19199
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync7 } from "node:fs";
|
|
19200
|
+
import { join as join41, relative as relative5, resolve as resolve10 } from "node:path";
|
|
19080
19201
|
import {
|
|
19081
19202
|
REFERENCE_BACKGROUND_FIELD,
|
|
19082
19203
|
referenceBackgroundResult as referenceBackgroundResult3
|
|
@@ -19269,7 +19390,7 @@ function planFileSha256(absolutePath, digests) {
|
|
|
19269
19390
|
return sha256;
|
|
19270
19391
|
}
|
|
19271
19392
|
async function prehashPlanFiles(dir, digests) {
|
|
19272
|
-
if (!
|
|
19393
|
+
if (!existsSync25(dir)) return;
|
|
19273
19394
|
for (const { absolutePath } of listPlanFiles(dir)) {
|
|
19274
19395
|
if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
|
|
19275
19396
|
}
|
|
@@ -19294,7 +19415,7 @@ function listPlanFiles(planDir) {
|
|
|
19294
19415
|
function walk(dir) {
|
|
19295
19416
|
const entries = readdirSync8(dir, { withFileTypes: true });
|
|
19296
19417
|
for (const entry of entries) {
|
|
19297
|
-
const full =
|
|
19418
|
+
const full = join41(dir, entry.name);
|
|
19298
19419
|
if (entry.isDirectory()) {
|
|
19299
19420
|
walk(full);
|
|
19300
19421
|
} else if (entry.isFile()) {
|
|
@@ -19335,19 +19456,19 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
|
|
|
19335
19456
|
function writePlanRemoteFiles(planDir, files) {
|
|
19336
19457
|
if (files.length === 0) return;
|
|
19337
19458
|
const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
|
|
19338
|
-
writeFileSync7(
|
|
19459
|
+
writeFileSync7(join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
|
|
19339
19460
|
}
|
|
19340
19461
|
function readPlanRemoteFiles(planDir) {
|
|
19341
|
-
const path =
|
|
19342
|
-
return
|
|
19462
|
+
const path = join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
|
|
19463
|
+
return existsSync25(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
|
|
19343
19464
|
}
|
|
19344
19465
|
function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
19345
|
-
const planJsonPath =
|
|
19346
|
-
const encoderJsonPath =
|
|
19347
|
-
if (!
|
|
19466
|
+
const planJsonPath = join41(planDir, "plan.json");
|
|
19467
|
+
const encoderJsonPath = join41(planDir, "meta", "encoder.json");
|
|
19468
|
+
if (!existsSync25(planJsonPath)) {
|
|
19348
19469
|
throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
|
|
19349
19470
|
}
|
|
19350
|
-
if (!
|
|
19471
|
+
if (!existsSync25(encoderJsonPath)) {
|
|
19351
19472
|
throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
|
|
19352
19473
|
}
|
|
19353
19474
|
const planJson = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
|
|
@@ -19377,21 +19498,21 @@ async function freezePlan(input) {
|
|
|
19377
19498
|
hasAudio,
|
|
19378
19499
|
digests
|
|
19379
19500
|
} = input;
|
|
19380
|
-
if (!
|
|
19501
|
+
if (!existsSync25(planDir)) {
|
|
19381
19502
|
throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
|
|
19382
19503
|
}
|
|
19383
|
-
const metaDir =
|
|
19384
|
-
if (!
|
|
19504
|
+
const metaDir = join41(planDir, "meta");
|
|
19505
|
+
if (!existsSync25(metaDir)) mkdirSync14(metaDir, { recursive: true });
|
|
19385
19506
|
writeFileSync7(
|
|
19386
|
-
|
|
19507
|
+
join41(metaDir, "composition.json"),
|
|
19387
19508
|
`${JSON.stringify(composition, null, 2)}
|
|
19388
19509
|
`,
|
|
19389
19510
|
"utf-8"
|
|
19390
19511
|
);
|
|
19391
19512
|
const encoderForCanonical = stripUndefined(encoder);
|
|
19392
19513
|
const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
|
|
19393
|
-
writeFileSync7(
|
|
19394
|
-
writeFileSync7(
|
|
19514
|
+
writeFileSync7(join41(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
|
|
19515
|
+
writeFileSync7(join41(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
|
|
19395
19516
|
`, "utf-8");
|
|
19396
19517
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
19397
19518
|
const planHash = computePlanHash({
|
|
@@ -19416,7 +19537,7 @@ async function freezePlan(input) {
|
|
|
19416
19537
|
duration: durationSeconds,
|
|
19417
19538
|
hasAudio
|
|
19418
19539
|
};
|
|
19419
|
-
const planJsonPath =
|
|
19540
|
+
const planJsonPath = join41(planDir, "plan.json");
|
|
19420
19541
|
writeFileSync7(planJsonPath, `${JSON.stringify(planJson, null, 2)}
|
|
19421
19542
|
`, "utf-8");
|
|
19422
19543
|
return { planJsonPath, planHash };
|
|
@@ -19458,9 +19579,9 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
|
|
|
19458
19579
|
}
|
|
19459
19580
|
|
|
19460
19581
|
// src/services/distributed/chunkAudio.ts
|
|
19461
|
-
import { closeSync as closeSync7, existsSync as
|
|
19582
|
+
import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync7, readFileSync as readFileSync12 } from "node:fs";
|
|
19462
19583
|
import { writeFileSync as writeFileSync8, writeSync } from "node:fs";
|
|
19463
|
-
import { join as
|
|
19584
|
+
import { join as join42 } from "node:path";
|
|
19464
19585
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
19465
19586
|
function audioCutForChunk(grid, chunks, index, fps) {
|
|
19466
19587
|
const firstPacketAt = (frame) => Math.min(
|
|
@@ -19548,7 +19669,7 @@ async function writeChunkAudioSlices(input) {
|
|
|
19548
19669
|
});
|
|
19549
19670
|
const bytes = readFileSync12(input.audioPath);
|
|
19550
19671
|
const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
|
|
19551
|
-
mkdirSync15(
|
|
19672
|
+
mkdirSync15(join42(input.planDir, SLICE_DIR), { recursive: true });
|
|
19552
19673
|
input.chunks.forEach((_, index) => {
|
|
19553
19674
|
const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
|
|
19554
19675
|
if (!cut) return;
|
|
@@ -19556,17 +19677,17 @@ async function writeChunkAudioSlices(input) {
|
|
|
19556
19677
|
const start = offsets[cut.firstPacket];
|
|
19557
19678
|
layout.partStarts[index] = start;
|
|
19558
19679
|
const end = offsets[last] + track.sizes[last];
|
|
19559
|
-
writeFileSync8(
|
|
19680
|
+
writeFileSync8(join42(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
|
|
19560
19681
|
});
|
|
19561
19682
|
const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
|
|
19562
|
-
writeFileSync8(
|
|
19563
|
-
writeFileSync8(
|
|
19683
|
+
writeFileSync8(join42(input.planDir, SLICE_FRAME), Buffer.concat(frame));
|
|
19684
|
+
writeFileSync8(join42(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
|
|
19564
19685
|
}
|
|
19565
19686
|
function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
19566
|
-
const layoutPath =
|
|
19567
|
-
if (!
|
|
19687
|
+
const layoutPath = join42(planDir, SLICE_LAYOUT);
|
|
19688
|
+
if (!existsSync26(layoutPath)) return resolvePlanAudioPath(planDir);
|
|
19568
19689
|
const layout = JSON.parse(readFileSync12(layoutPath, "utf-8"));
|
|
19569
|
-
const frame = readFileSync12(
|
|
19690
|
+
const frame = readFileSync12(join42(planDir, SLICE_FRAME));
|
|
19570
19691
|
const fd = openSync7(scratchPath, "w");
|
|
19571
19692
|
try {
|
|
19572
19693
|
writeSync(fd, frame, 0, layout.payloadStart, 0);
|
|
@@ -19579,7 +19700,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
|
19579
19700
|
);
|
|
19580
19701
|
const start = layout.partStarts[chunkIndex];
|
|
19581
19702
|
if (start !== void 0) {
|
|
19582
|
-
const part = readFileSync12(
|
|
19703
|
+
const part = readFileSync12(join42(planDir, chunkAudioSlicePath(chunkIndex)));
|
|
19583
19704
|
writeSync(fd, part, 0, part.length, start);
|
|
19584
19705
|
}
|
|
19585
19706
|
ftruncateSync(fd, layout.sizeBytes);
|
|
@@ -19635,7 +19756,7 @@ async function muxChunkWithAudio(input) {
|
|
|
19635
19756
|
// src/services/distributed/planSize.ts
|
|
19636
19757
|
import { createHash as createHash9 } from "node:crypto";
|
|
19637
19758
|
import { lstatSync as lstatSync4, readdirSync as readdirSync9 } from "node:fs";
|
|
19638
|
-
import { extname as extname5, join as
|
|
19759
|
+
import { extname as extname5, join as join43, relative as relative6 } from "node:path";
|
|
19639
19760
|
var MAX_TOP_COMPONENTS = 10;
|
|
19640
19761
|
var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
19641
19762
|
".aac",
|
|
@@ -19747,7 +19868,7 @@ function walkRegularFiles(dir, visit) {
|
|
|
19747
19868
|
return;
|
|
19748
19869
|
}
|
|
19749
19870
|
for (const entry of entries) {
|
|
19750
|
-
const full =
|
|
19871
|
+
const full = join43(dir, entry.name);
|
|
19751
19872
|
if (entry.isDirectory()) {
|
|
19752
19873
|
walkRegularFiles(full, visit);
|
|
19753
19874
|
} else if (entry.isFile()) {
|
|
@@ -19963,13 +20084,13 @@ function assertPositiveInteger2(name, value) {
|
|
|
19963
20084
|
}
|
|
19964
20085
|
var FREEZE_OWNED_PLAN_FILES = [
|
|
19965
20086
|
"plan.json",
|
|
19966
|
-
|
|
19967
|
-
|
|
19968
|
-
|
|
20087
|
+
join44("meta", "composition.json"),
|
|
20088
|
+
join44("meta", "encoder.json"),
|
|
20089
|
+
join44("meta", "chunks.json")
|
|
19969
20090
|
];
|
|
19970
20091
|
function removeFreezeOwnedPlanFiles(planDir) {
|
|
19971
20092
|
for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
|
|
19972
|
-
rmSync14(
|
|
20093
|
+
rmSync14(join44(planDir, relativePath), { force: true });
|
|
19973
20094
|
}
|
|
19974
20095
|
}
|
|
19975
20096
|
function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
|
|
@@ -20127,19 +20248,19 @@ function createVideoSourceShipper(input) {
|
|
|
20127
20248
|
const known = shipped.get(srcPath);
|
|
20128
20249
|
if (known) return known;
|
|
20129
20250
|
const stagedRel = pathInside(input.workVideoFramesDir, srcPath);
|
|
20130
|
-
const current = stagedRel === null ? srcPath :
|
|
20251
|
+
const current = stagedRel === null ? srcPath : join44(input.planDir, "video-frames", stagedRel);
|
|
20131
20252
|
let result = null;
|
|
20132
20253
|
for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
|
|
20133
20254
|
const rel = pathInside(root, srcPath);
|
|
20134
|
-
if (rel !== null && (
|
|
20255
|
+
if (rel !== null && (existsSync27(join44(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
|
|
20135
20256
|
result = ["compiled", ...rel.split(sep5)].join("/");
|
|
20136
20257
|
break;
|
|
20137
20258
|
}
|
|
20138
20259
|
}
|
|
20139
20260
|
if (result === null) {
|
|
20140
20261
|
result = `video-sources/${shipped.size}${extname6(current)}`;
|
|
20141
|
-
const destination =
|
|
20142
|
-
mkdirSync16(
|
|
20262
|
+
const destination = join44(input.planDir, ...result.split("/"));
|
|
20263
|
+
mkdirSync16(join44(input.planDir, "video-sources"), { recursive: true });
|
|
20143
20264
|
try {
|
|
20144
20265
|
linkSync(current, destination);
|
|
20145
20266
|
} catch {
|
|
@@ -20159,7 +20280,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20159
20280
|
useGpu: false,
|
|
20160
20281
|
browserGpuMode: "software"
|
|
20161
20282
|
});
|
|
20162
|
-
if (!
|
|
20283
|
+
if (!existsSync27(planDir)) mkdirSync16(planDir, { recursive: true });
|
|
20163
20284
|
const log = config.logger ?? defaultLogger;
|
|
20164
20285
|
const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
|
|
20165
20286
|
const abortSignal = config.abortSignal;
|
|
@@ -20193,14 +20314,14 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20193
20314
|
includeOutsideScripts: options.includeOutsideScripts === true
|
|
20194
20315
|
});
|
|
20195
20316
|
const entryFile = config.entryFile ?? "index.html";
|
|
20196
|
-
const htmlPath =
|
|
20197
|
-
if (!
|
|
20317
|
+
const htmlPath = join44(projectDir, entryFile);
|
|
20318
|
+
if (!existsSync27(htmlPath)) {
|
|
20198
20319
|
throw new Error(`[plan] entry file not found: ${htmlPath}`);
|
|
20199
20320
|
}
|
|
20200
|
-
const workDir =
|
|
20321
|
+
const workDir = join44(planDir, ".plan-work");
|
|
20201
20322
|
rmSync14(workDir, { recursive: true, force: true });
|
|
20202
20323
|
mkdirSync16(workDir, { recursive: true });
|
|
20203
|
-
const compiledDir =
|
|
20324
|
+
const compiledDir = join44(workDir, "compiled");
|
|
20204
20325
|
mkdirSync16(compiledDir, { recursive: true });
|
|
20205
20326
|
let stageStarted = Date.now();
|
|
20206
20327
|
cpSync2(projectDir, compiledDir, {
|
|
@@ -20220,10 +20341,10 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20220
20341
|
}
|
|
20221
20342
|
});
|
|
20222
20343
|
logPlanStage(log, "copy", stageStarted);
|
|
20223
|
-
const finalCompiledDir =
|
|
20344
|
+
const finalCompiledDir = join44(planDir, "compiled");
|
|
20224
20345
|
const needsAlpha = outputNeedsAlpha(config.format);
|
|
20225
20346
|
const remoteFiles = Object.entries(options.remoteFiles ?? {});
|
|
20226
|
-
const remoteLocalPath = (rel) =>
|
|
20347
|
+
const remoteLocalPath = (rel) => join44(projectDir, ...rel.split("/"));
|
|
20227
20348
|
for (const [, file] of remoteFiles) {
|
|
20228
20349
|
declareContentAddressedUrl(file.url, file.sha256);
|
|
20229
20350
|
if (file.probeFactsUrl) declareProbeFactsUrl(file.url, file.probeFactsUrl);
|
|
@@ -20428,17 +20549,17 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20428
20549
|
let stageStarted = Date.now();
|
|
20429
20550
|
const extractResult = await extractPlanVideos(c, options.deferVideoExtraction);
|
|
20430
20551
|
logPlanStage(log, "extract", stageStarted);
|
|
20431
|
-
const stagedVideoFrames =
|
|
20432
|
-
const videoFramesDst =
|
|
20433
|
-
if (
|
|
20434
|
-
const videoSourcesDir =
|
|
20552
|
+
const stagedVideoFrames = join44(compiledDir, "__hyperframes_video_frames");
|
|
20553
|
+
const videoFramesDst = join44(planDir, "video-frames");
|
|
20554
|
+
if (existsSync27(videoFramesDst)) rmSync14(videoFramesDst, { recursive: true, force: true });
|
|
20555
|
+
const videoSourcesDir = join44(planDir, "video-sources");
|
|
20435
20556
|
rmSync14(videoSourcesDir, { recursive: true, force: true });
|
|
20436
|
-
if (
|
|
20557
|
+
if (existsSync27(stagedVideoFrames)) {
|
|
20437
20558
|
renameWithRetry7(stagedVideoFrames, videoFramesDst);
|
|
20438
20559
|
} else {
|
|
20439
20560
|
mkdirSync16(videoFramesDst, { recursive: true });
|
|
20440
20561
|
}
|
|
20441
|
-
if (
|
|
20562
|
+
if (existsSync27(finalCompiledDir)) rmSync14(finalCompiledDir, { recursive: true, force: true });
|
|
20442
20563
|
renameWithRetry7(compiledDir, finalCompiledDir);
|
|
20443
20564
|
const shipVideoSource = createVideoSourceShipper({
|
|
20444
20565
|
planDir,
|
|
@@ -20468,7 +20589,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20468
20589
|
};
|
|
20469
20590
|
})
|
|
20470
20591
|
});
|
|
20471
|
-
mkdirSync16(
|
|
20592
|
+
mkdirSync16(join44(planDir, "meta"), { recursive: true });
|
|
20472
20593
|
writePlanRemoteFiles(
|
|
20473
20594
|
planDir,
|
|
20474
20595
|
remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
|
|
@@ -20478,7 +20599,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20478
20599
|
}))
|
|
20479
20600
|
);
|
|
20480
20601
|
writeFileSync9(
|
|
20481
|
-
|
|
20602
|
+
join44(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
|
|
20482
20603
|
JSON.stringify(planVideosJson, null, 2),
|
|
20483
20604
|
"utf-8"
|
|
20484
20605
|
);
|
|
@@ -20558,11 +20679,11 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20558
20679
|
if (audioResult?.audioError) {
|
|
20559
20680
|
applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
|
|
20560
20681
|
}
|
|
20561
|
-
const planAudioPath =
|
|
20562
|
-
if (audioResult?.hasAudio &&
|
|
20682
|
+
const planAudioPath = join44(planDir, PLAN_AUDIO_RELATIVE_PATH);
|
|
20683
|
+
if (audioResult?.hasAudio && existsSync27(audioResult.audioOutputPath)) {
|
|
20563
20684
|
renameWithRetry7(audioResult.audioOutputPath, planAudioPath);
|
|
20564
20685
|
}
|
|
20565
|
-
if (chunksCarryAudio &&
|
|
20686
|
+
if (chunksCarryAudio && existsSync27(planAudioPath)) {
|
|
20566
20687
|
if (options.sliceChunkAudio) {
|
|
20567
20688
|
stageStarted = Date.now();
|
|
20568
20689
|
await writeChunkAudioSlices({
|
|
@@ -20684,8 +20805,8 @@ async function plan(projectDir, config, planDir, options = {}) {
|
|
|
20684
20805
|
|
|
20685
20806
|
// src/services/distributed/renderChunk.ts
|
|
20686
20807
|
import { randomBytes } from "node:crypto";
|
|
20687
|
-
import { existsSync as
|
|
20688
|
-
import { join as
|
|
20808
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync12 } from "node:fs";
|
|
20809
|
+
import { join as join48 } from "node:path";
|
|
20689
20810
|
import {
|
|
20690
20811
|
assertSwiftShader,
|
|
20691
20812
|
BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
|
|
@@ -20711,7 +20832,7 @@ import {
|
|
|
20711
20832
|
} from "@hyperframes/engine";
|
|
20712
20833
|
import {
|
|
20713
20834
|
copyFileSync as copyFileSync8,
|
|
20714
|
-
existsSync as
|
|
20835
|
+
existsSync as existsSync29,
|
|
20715
20836
|
lstatSync as lstatSync5,
|
|
20716
20837
|
mkdirSync as mkdirSync18,
|
|
20717
20838
|
readFileSync as readFileSync13,
|
|
@@ -20721,7 +20842,7 @@ import {
|
|
|
20721
20842
|
writeFileSync as writeFileSync11
|
|
20722
20843
|
} from "node:fs";
|
|
20723
20844
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
20724
|
-
import { dirname as
|
|
20845
|
+
import { dirname as dirname19, isAbsolute as isAbsolute5, join as join47, relative as relative8, resolve as resolve11, sep as sep6 } from "node:path";
|
|
20725
20846
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
20726
20847
|
import {
|
|
20727
20848
|
createFrameLookupTable as createFrameLookupTable5,
|
|
@@ -20732,7 +20853,7 @@ import {
|
|
|
20732
20853
|
// src/services/distributed/planV2Publisher.ts
|
|
20733
20854
|
import {
|
|
20734
20855
|
copyFileSync as copyFileSync7,
|
|
20735
|
-
existsSync as
|
|
20856
|
+
existsSync as existsSync28,
|
|
20736
20857
|
linkSync as linkSync2,
|
|
20737
20858
|
mkdirSync as mkdirSync17,
|
|
20738
20859
|
rmSync as rmSync15,
|
|
@@ -20740,7 +20861,7 @@ import {
|
|
|
20740
20861
|
writeFileSync as writeFileSync10
|
|
20741
20862
|
} from "node:fs";
|
|
20742
20863
|
import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
|
|
20743
|
-
import { dirname as
|
|
20864
|
+
import { dirname as dirname18, join as join46 } from "node:path";
|
|
20744
20865
|
|
|
20745
20866
|
// src/services/distributed/planV2Errors.ts
|
|
20746
20867
|
var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
|
|
@@ -20755,7 +20876,7 @@ var PlanV2IntegrityError = class extends Error {
|
|
|
20755
20876
|
};
|
|
20756
20877
|
|
|
20757
20878
|
// src/services/distributed/planV2Layout.ts
|
|
20758
|
-
import { join as
|
|
20879
|
+
import { join as join45 } from "node:path";
|
|
20759
20880
|
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
20760
20881
|
function assertPlanV2Sha256(value, field) {
|
|
20761
20882
|
if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
|
|
@@ -20765,7 +20886,7 @@ function assertPlanV2Sha256(value, field) {
|
|
|
20765
20886
|
}
|
|
20766
20887
|
function planV2BlobPath(root, sha256) {
|
|
20767
20888
|
const digest = assertPlanV2Sha256(sha256, "artifact sha256");
|
|
20768
|
-
return
|
|
20889
|
+
return join45(root, "artifacts", "sha256", digest.slice(0, 2), digest);
|
|
20769
20890
|
}
|
|
20770
20891
|
|
|
20771
20892
|
// src/services/distributed/planV2Publisher.ts
|
|
@@ -20796,13 +20917,13 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20796
20917
|
#linkFile;
|
|
20797
20918
|
#committed = false;
|
|
20798
20919
|
constructor(destinationDir, options = {}) {
|
|
20799
|
-
if (
|
|
20920
|
+
if (existsSync28(destinationDir)) {
|
|
20800
20921
|
throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
|
|
20801
20922
|
}
|
|
20802
20923
|
this.destinationDir = destinationDir;
|
|
20803
20924
|
this.#linkFile = options.linkFile ?? linkSync2;
|
|
20804
|
-
mkdirSync17(
|
|
20805
|
-
this.temporaryDir = createStagingDir5(
|
|
20925
|
+
mkdirSync17(dirname18(destinationDir), { recursive: true });
|
|
20926
|
+
this.temporaryDir = createStagingDir5(dirname18(destinationDir), ".plan-v2-publish-");
|
|
20806
20927
|
}
|
|
20807
20928
|
async putBlob(blob) {
|
|
20808
20929
|
const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
|
|
@@ -20813,10 +20934,10 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20813
20934
|
);
|
|
20814
20935
|
}
|
|
20815
20936
|
const destinationPath = planV2BlobPath(this.temporaryDir, digest);
|
|
20816
|
-
if (
|
|
20817
|
-
mkdirSync17(
|
|
20818
|
-
const stagingDir = createStagingDir5(
|
|
20819
|
-
const temporaryPath =
|
|
20937
|
+
if (existsSync28(destinationPath)) return;
|
|
20938
|
+
mkdirSync17(dirname18(destinationPath), { recursive: true });
|
|
20939
|
+
const stagingDir = createStagingDir5(dirname18(destinationPath), ".plan-v2-blob-");
|
|
20940
|
+
const temporaryPath = join46(stagingDir, "blob");
|
|
20820
20941
|
try {
|
|
20821
20942
|
try {
|
|
20822
20943
|
this.#linkFile(blob.sourcePath, temporaryPath);
|
|
@@ -20831,13 +20952,13 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20831
20952
|
}
|
|
20832
20953
|
async commitManifest(manifestBytes) {
|
|
20833
20954
|
for (const digest of new Set(manifestDigests(manifestBytes))) {
|
|
20834
|
-
if (!
|
|
20955
|
+
if (!existsSync28(planV2BlobPath(this.temporaryDir, digest))) {
|
|
20835
20956
|
throw new PlanV2IntegrityError(
|
|
20836
20957
|
`cannot commit manifest before referenced blob is durable: ${digest}`
|
|
20837
20958
|
);
|
|
20838
20959
|
}
|
|
20839
20960
|
}
|
|
20840
|
-
writeFileSync10(
|
|
20961
|
+
writeFileSync10(join46(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
|
|
20841
20962
|
renameWithRetry8(this.temporaryDir, this.destinationDir);
|
|
20842
20963
|
this.#committed = true;
|
|
20843
20964
|
}
|
|
@@ -20883,7 +21004,7 @@ function listFiles(root) {
|
|
|
20883
21004
|
const rootResolved = resolve11(root);
|
|
20884
21005
|
function walk(dir) {
|
|
20885
21006
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
20886
|
-
const absolutePath =
|
|
21007
|
+
const absolutePath = join47(dir, entry.name);
|
|
20887
21008
|
if (entry.isDirectory()) {
|
|
20888
21009
|
walk(absolutePath);
|
|
20889
21010
|
} else if (entry.isFile()) {
|
|
@@ -20910,13 +21031,13 @@ function assertValidExtractionCacheCompleteSentinel(path) {
|
|
|
20910
21031
|
}
|
|
20911
21032
|
}
|
|
20912
21033
|
function validateExtractionCacheCompleteSentinels(executionPlanDir) {
|
|
20913
|
-
const videoRoot =
|
|
20914
|
-
if (!
|
|
21034
|
+
const videoRoot = join47(executionPlanDir, "video-frames");
|
|
21035
|
+
if (!existsSync29(videoRoot)) return;
|
|
20915
21036
|
for (const videoEntry of readdirSync10(videoRoot, { withFileTypes: true })) {
|
|
20916
21037
|
if (!videoEntry.isDirectory()) continue;
|
|
20917
|
-
const videoDir =
|
|
21038
|
+
const videoDir = join47(videoRoot, videoEntry.name);
|
|
20918
21039
|
if (readdirSync10(videoDir).includes(EXTRACTION_CACHE_COMPLETE_SENTINEL)) {
|
|
20919
|
-
const sentinelPath =
|
|
21040
|
+
const sentinelPath = join47(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
|
|
20920
21041
|
assertValidExtractionCacheCompleteSentinel(sentinelPath);
|
|
20921
21042
|
}
|
|
20922
21043
|
}
|
|
@@ -20963,7 +21084,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
20963
21084
|
if (video.deferredRange) {
|
|
20964
21085
|
const framePaths2 = /* @__PURE__ */ new Map();
|
|
20965
21086
|
for (let index = 0; index < video.totalFrames; index++) {
|
|
20966
|
-
framePaths2.set(index,
|
|
21087
|
+
framePaths2.set(index, join47(outputDir, String(index)));
|
|
20967
21088
|
}
|
|
20968
21089
|
return { ...video, outputDir, framePaths: framePaths2, ownedByLookup: false };
|
|
20969
21090
|
}
|
|
@@ -20971,7 +21092,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
20971
21092
|
const framePaths = /* @__PURE__ */ new Map();
|
|
20972
21093
|
for (const frameName of frameNames) {
|
|
20973
21094
|
if (frameName === EXTRACTION_CACHE_COMPLETE_SENTINEL) {
|
|
20974
|
-
assertValidExtractionCacheCompleteSentinel(
|
|
21095
|
+
assertValidExtractionCacheCompleteSentinel(join47(outputDir, frameName));
|
|
20975
21096
|
continue;
|
|
20976
21097
|
}
|
|
20977
21098
|
const match = /(\d+)(?=\.[^.]+$)/.exec(frameName);
|
|
@@ -20990,7 +21111,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
20990
21111
|
`duplicate extracted frame index ${frameIndex} in ${outputDir}`
|
|
20991
21112
|
);
|
|
20992
21113
|
}
|
|
20993
|
-
framePaths.set(frameIndex,
|
|
21114
|
+
framePaths.set(frameIndex, join47(outputDir, frameName));
|
|
20994
21115
|
}
|
|
20995
21116
|
return {
|
|
20996
21117
|
...video,
|
|
@@ -21011,8 +21132,8 @@ function parsePlanVideosJson2(value) {
|
|
|
21011
21132
|
}
|
|
21012
21133
|
}
|
|
21013
21134
|
function materializeExtractedVideoDirectories(planDir) {
|
|
21014
|
-
const videosPath =
|
|
21015
|
-
if (!
|
|
21135
|
+
const videosPath = join47(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21136
|
+
if (!existsSync29(videosPath)) return;
|
|
21016
21137
|
const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
|
|
21017
21138
|
for (const video of videos.extracted) {
|
|
21018
21139
|
mkdirSync18(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
|
|
@@ -21045,13 +21166,13 @@ function parseChunkSlices(value) {
|
|
|
21045
21166
|
});
|
|
21046
21167
|
}
|
|
21047
21168
|
function buildVideoChunkDependencies(executionPlanDir, dimensions) {
|
|
21048
|
-
const videoRoot =
|
|
21049
|
-
const hasExtractedFrames =
|
|
21050
|
-
const videosPath =
|
|
21051
|
-
if (!
|
|
21169
|
+
const videoRoot = join47(executionPlanDir, "video-frames");
|
|
21170
|
+
const hasExtractedFrames = existsSync29(videoRoot) && listFiles(videoRoot).length > 0;
|
|
21171
|
+
const videosPath = join47(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21172
|
+
if (!existsSync29(videosPath)) {
|
|
21052
21173
|
return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
|
|
21053
21174
|
}
|
|
21054
|
-
const chunksPath =
|
|
21175
|
+
const chunksPath = join47(executionPlanDir, "meta", "chunks.json");
|
|
21055
21176
|
const videos = readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21056
21177
|
const chunks = readJsonFile(chunksPath, "meta/chunks.json");
|
|
21057
21178
|
const parsedVideos = parsePlanVideosJson2(videos);
|
|
@@ -21105,10 +21226,10 @@ function computeManifestHash(manifest) {
|
|
|
21105
21226
|
return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
|
|
21106
21227
|
}
|
|
21107
21228
|
function writeBlob(sourcePath, destinationPath) {
|
|
21108
|
-
if (
|
|
21109
|
-
mkdirSync18(
|
|
21110
|
-
const temporaryDir = createStagingDir6(
|
|
21111
|
-
const temporaryPath =
|
|
21229
|
+
if (existsSync29(destinationPath)) return;
|
|
21230
|
+
mkdirSync18(dirname19(destinationPath), { recursive: true });
|
|
21231
|
+
const temporaryDir = createStagingDir6(dirname19(destinationPath), ".plan-v2-blob-");
|
|
21232
|
+
const temporaryPath = join47(temporaryDir, "blob");
|
|
21112
21233
|
try {
|
|
21113
21234
|
copyFileSync8(sourcePath, temporaryPath);
|
|
21114
21235
|
renameWithRetry9(temporaryPath, destinationPath);
|
|
@@ -21144,8 +21265,8 @@ async function putTasks(tasks) {
|
|
|
21144
21265
|
if (failure) throw failure.reason;
|
|
21145
21266
|
}
|
|
21146
21267
|
function buildPlanV2Publication(executionPlanDir, digests) {
|
|
21147
|
-
const executionPlanPath =
|
|
21148
|
-
if (!
|
|
21268
|
+
const executionPlanPath = join47(executionPlanDir, "plan.json");
|
|
21269
|
+
if (!existsSync29(executionPlanPath)) {
|
|
21149
21270
|
throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
|
|
21150
21271
|
}
|
|
21151
21272
|
const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
|
|
@@ -21172,7 +21293,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
21172
21293
|
}
|
|
21173
21294
|
validateExtractionCacheCompleteSentinels(executionPlanDir);
|
|
21174
21295
|
const videoDependencyPlan = buildVideoChunkDependencies(executionPlanDir, dimensions);
|
|
21175
|
-
const encoder = readJsonFile(
|
|
21296
|
+
const encoder = readJsonFile(join47(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
|
|
21176
21297
|
const files = listFiles(executionPlanDir);
|
|
21177
21298
|
const chunkAudio = !isRecord3(encoder) || encoder.chunksCarryAudio !== true ? "none" : files.some((file) => chunkAudioSliceTarget(file.path) !== null) ? "sliced" : "whole";
|
|
21178
21299
|
for (const file of files) {
|
|
@@ -21225,21 +21346,21 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
21225
21346
|
};
|
|
21226
21347
|
}
|
|
21227
21348
|
function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
21228
|
-
if (
|
|
21349
|
+
if (existsSync29(planV2Dir)) {
|
|
21229
21350
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
21230
21351
|
}
|
|
21231
21352
|
const publication = buildPlanV2Publication(executionPlanDir);
|
|
21232
21353
|
if (publication.storedBlobs.length > 0) {
|
|
21233
21354
|
throw new PlanV2IntegrityError("a local plan v2 directory cannot reference remote files");
|
|
21234
21355
|
}
|
|
21235
|
-
mkdirSync18(
|
|
21236
|
-
const tempDir = createStagingDir6(
|
|
21356
|
+
mkdirSync18(dirname19(planV2Dir), { recursive: true });
|
|
21357
|
+
const tempDir = createStagingDir6(dirname19(planV2Dir), ".plan-v2-build-");
|
|
21237
21358
|
try {
|
|
21238
21359
|
for (const blob of publication.blobs) {
|
|
21239
21360
|
writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
|
|
21240
21361
|
}
|
|
21241
21362
|
writeFileSync11(
|
|
21242
|
-
|
|
21363
|
+
join47(tempDir, "plan.json"),
|
|
21243
21364
|
canonicalJsonStringify(publication.manifest),
|
|
21244
21365
|
"utf-8"
|
|
21245
21366
|
);
|
|
@@ -21291,7 +21412,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
21291
21412
|
// artifactTargets ships every compiled/ file to all chunks, so each is in the manifest.
|
|
21292
21413
|
whileAudioMixes: () => putBlobs(
|
|
21293
21414
|
publisher,
|
|
21294
|
-
listFiles(
|
|
21415
|
+
listFiles(join47(stagingRoot, "compiled")).map(
|
|
21295
21416
|
(file) => publishBlobFor(file.absolutePath, digests)
|
|
21296
21417
|
)
|
|
21297
21418
|
),
|
|
@@ -21315,12 +21436,12 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
21315
21436
|
}
|
|
21316
21437
|
}
|
|
21317
21438
|
async function planV2(projectDir, config, planV2Dir) {
|
|
21318
|
-
if (
|
|
21439
|
+
if (existsSync29(planV2Dir)) {
|
|
21319
21440
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
21320
21441
|
}
|
|
21321
21442
|
const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
|
|
21322
21443
|
const manifest = await planV2WithPublisher(projectDir, config, publisher, {
|
|
21323
|
-
stagingParentDir:
|
|
21444
|
+
stagingParentDir: dirname19(planV2Dir)
|
|
21324
21445
|
});
|
|
21325
21446
|
return resultFromManifest(planV2Dir, manifest);
|
|
21326
21447
|
}
|
|
@@ -21332,7 +21453,7 @@ function resultFromManifest(planV2Dir, manifest) {
|
|
|
21332
21453
|
isRecord3(executionPlan) ? executionPlan[REFERENCE_BACKGROUND_FIELD3] : void 0
|
|
21333
21454
|
),
|
|
21334
21455
|
planDir: planV2Dir,
|
|
21335
|
-
manifestPath:
|
|
21456
|
+
manifestPath: join47(planV2Dir, "plan.json"),
|
|
21336
21457
|
planProtocol: PLAN_PROTOCOL_V2,
|
|
21337
21458
|
planHash: manifest.planHash,
|
|
21338
21459
|
sourcePlanV1Hash: getPlanV2ExecutionPlanHash(manifest),
|
|
@@ -21468,8 +21589,8 @@ function parsePlanV2Manifest(value) {
|
|
|
21468
21589
|
return parsed;
|
|
21469
21590
|
}
|
|
21470
21591
|
function readPlanV2Manifest(planV2Dir) {
|
|
21471
|
-
const manifestPath =
|
|
21472
|
-
if (!
|
|
21592
|
+
const manifestPath = join47(planV2Dir, "plan.json");
|
|
21593
|
+
if (!existsSync29(manifestPath)) {
|
|
21473
21594
|
throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
|
|
21474
21595
|
}
|
|
21475
21596
|
const value = readJsonFile(manifestPath, "v2 manifest");
|
|
@@ -21488,7 +21609,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
|
|
|
21488
21609
|
}
|
|
21489
21610
|
function verifyBlob(planV2Dir, artifact) {
|
|
21490
21611
|
const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
|
|
21491
|
-
if (!
|
|
21612
|
+
if (!existsSync29(sourcePath)) {
|
|
21492
21613
|
throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
|
|
21493
21614
|
}
|
|
21494
21615
|
const stats = statSync12(sourcePath);
|
|
@@ -21501,7 +21622,7 @@ function verifyBlob(planV2Dir, artifact) {
|
|
|
21501
21622
|
return sourcePath;
|
|
21502
21623
|
}
|
|
21503
21624
|
function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
|
|
21504
|
-
if (
|
|
21625
|
+
if (existsSync29(destinationDir)) {
|
|
21505
21626
|
throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
|
|
21506
21627
|
}
|
|
21507
21628
|
const manifest = readPlanV2Manifest(planV2Dir);
|
|
@@ -21513,17 +21634,17 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
21513
21634
|
artifact,
|
|
21514
21635
|
sourcePath: verifyBlob(planV2Dir, artifact)
|
|
21515
21636
|
}));
|
|
21516
|
-
mkdirSync18(
|
|
21517
|
-
const tempDir = createStagingDir6(
|
|
21637
|
+
mkdirSync18(dirname19(destinationDir), { recursive: true });
|
|
21638
|
+
const tempDir = createStagingDir6(dirname19(destinationDir), ".plan-v2-materialize-");
|
|
21518
21639
|
try {
|
|
21519
21640
|
for (const { artifact, sourcePath } of verified) {
|
|
21520
|
-
const destinationPath =
|
|
21521
|
-
mkdirSync18(
|
|
21641
|
+
const destinationPath = join47(tempDir, ...artifact.path.split("/"));
|
|
21642
|
+
mkdirSync18(dirname19(destinationPath), { recursive: true });
|
|
21522
21643
|
copyFileSync8(sourcePath, destinationPath);
|
|
21523
21644
|
}
|
|
21524
21645
|
if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
|
|
21525
21646
|
writeFileSync11(
|
|
21526
|
-
|
|
21647
|
+
join47(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
|
|
21527
21648
|
canonicalJsonStringify({
|
|
21528
21649
|
manifest,
|
|
21529
21650
|
target,
|
|
@@ -21546,7 +21667,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
21546
21667
|
// Join the artifact's OWN name, not the current constant: a plan written
|
|
21547
21668
|
// before the container change carries the legacy name, and materializing it
|
|
21548
21669
|
// under the new one would point at a file that was never written.
|
|
21549
|
-
audioPath: target.role === "assembler" ? audioArtifact ?
|
|
21670
|
+
audioPath: target.role === "assembler" ? audioArtifact ? join47(destinationDir, audioArtifact.path) : null : null
|
|
21550
21671
|
};
|
|
21551
21672
|
}
|
|
21552
21673
|
function assertRemoteSources(remoteSources, artifacts) {
|
|
@@ -21565,8 +21686,8 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
|
|
|
21565
21686
|
return readValidatedPlanV2Materialization(planDir, expectedTarget)?.manifest ?? null;
|
|
21566
21687
|
}
|
|
21567
21688
|
function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
21568
|
-
const markerPath =
|
|
21569
|
-
if (!
|
|
21689
|
+
const markerPath = join47(planDir, PLAN_V2_MATERIALIZATION_MARKER);
|
|
21690
|
+
if (!existsSync29(markerPath)) return null;
|
|
21570
21691
|
const marker = readJsonFile(markerPath, "materialization marker");
|
|
21571
21692
|
if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
|
|
21572
21693
|
throw new PlanV2IntegrityError("malformed materialization marker");
|
|
@@ -21583,8 +21704,8 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
|
21583
21704
|
assertRemoteSources(remoteSources, required);
|
|
21584
21705
|
for (const artifact of required) {
|
|
21585
21706
|
if (Object.hasOwn(remoteSources, artifact.path)) continue;
|
|
21586
|
-
const path =
|
|
21587
|
-
if (!
|
|
21707
|
+
const path = join47(planDir, ...artifact.path.split("/"));
|
|
21708
|
+
if (!existsSync29(path) || statSync12(path).size !== artifact.sizeBytes) {
|
|
21588
21709
|
throw new PlanV2IntegrityError(
|
|
21589
21710
|
`materialized artifact missing or truncated: ${artifact.path}`
|
|
21590
21711
|
);
|
|
@@ -21715,7 +21836,7 @@ function hashChunkOutput(outputPath, kind) {
|
|
|
21715
21836
|
if (kind === "file") return sha256Hex(readFileSync14(outputPath));
|
|
21716
21837
|
const entries = readdirSync11(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
|
|
21717
21838
|
const lines = entries.map(
|
|
21718
|
-
(name) => `${name}\0${sha256Hex(readFileSync14(
|
|
21839
|
+
(name) => `${name}\0${sha256Hex(readFileSync14(join48(outputPath, name)))}`
|
|
21719
21840
|
);
|
|
21720
21841
|
return sha256Hex(lines.join("\0"));
|
|
21721
21842
|
}
|
|
@@ -21732,10 +21853,10 @@ function resolveLockedVp9CpuUsed(lockedEncoder) {
|
|
|
21732
21853
|
async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
21733
21854
|
const start = Date.now();
|
|
21734
21855
|
const log = defaultLogger;
|
|
21735
|
-
const planJsonPath =
|
|
21736
|
-
const encoderJsonPath =
|
|
21737
|
-
const chunksJsonPath =
|
|
21738
|
-
if (!
|
|
21856
|
+
const planJsonPath = join48(planDir, "plan.json");
|
|
21857
|
+
const encoderJsonPath = join48(planDir, "meta", "encoder.json");
|
|
21858
|
+
const chunksJsonPath = join48(planDir, "meta", "chunks.json");
|
|
21859
|
+
if (!existsSync30(planJsonPath)) {
|
|
21739
21860
|
throw new RenderChunkValidationError(
|
|
21740
21861
|
MISSING_PLAN_ARTIFACT,
|
|
21741
21862
|
`[renderChunk] planDir is missing required artifact: ${planJsonPath}`
|
|
@@ -21751,7 +21872,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21751
21872
|
const v2Manifest = v2Materialization?.manifest ?? null;
|
|
21752
21873
|
const remoteSources = v2Materialization?.remoteSources ?? {};
|
|
21753
21874
|
for (const required of [encoderJsonPath, chunksJsonPath]) {
|
|
21754
|
-
if (!
|
|
21875
|
+
if (!existsSync30(required)) {
|
|
21755
21876
|
throw new RenderChunkValidationError(
|
|
21756
21877
|
MISSING_PLAN_ARTIFACT,
|
|
21757
21878
|
`[renderChunk] planDir is missing required artifact: ${required}`
|
|
@@ -21760,9 +21881,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21760
21881
|
}
|
|
21761
21882
|
const encoder = JSON.parse(readFileSync14(encoderJsonPath, "utf-8"));
|
|
21762
21883
|
const chunks = JSON.parse(readFileSync14(chunksJsonPath, "utf-8"));
|
|
21763
|
-
const videosJsonPath =
|
|
21884
|
+
const videosJsonPath = join48(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21764
21885
|
let planVideos = null;
|
|
21765
|
-
if (
|
|
21886
|
+
if (existsSync30(videosJsonPath)) {
|
|
21766
21887
|
try {
|
|
21767
21888
|
planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync14(videosJsonPath, "utf-8")));
|
|
21768
21889
|
} catch (err) {
|
|
@@ -21792,8 +21913,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21792
21913
|
}
|
|
21793
21914
|
const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
|
|
21794
21915
|
const framesInChunk = range.endFrame - range.startFrame;
|
|
21795
|
-
const compiledDir =
|
|
21796
|
-
if (!
|
|
21916
|
+
const compiledDir = join48(planDir, "compiled");
|
|
21917
|
+
if (!existsSync30(compiledDir)) {
|
|
21797
21918
|
throw new RenderChunkValidationError(
|
|
21798
21919
|
MISSING_PLAN_ARTIFACT,
|
|
21799
21920
|
`[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
|
|
@@ -21851,7 +21972,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21851
21972
|
};
|
|
21852
21973
|
const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
21853
21974
|
mkdirSync19(workDir, { recursive: true });
|
|
21854
|
-
const framesDir =
|
|
21975
|
+
const framesDir = join48(workDir, "captured-frames");
|
|
21855
21976
|
mkdirSync19(framesDir, { recursive: true });
|
|
21856
21977
|
const videoFramesDir = `${workDir}.video-frames`;
|
|
21857
21978
|
const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
|
|
@@ -21876,7 +21997,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21876
21997
|
dimensions: plan2.dimensions,
|
|
21877
21998
|
encoder,
|
|
21878
21999
|
videoCount: planVideos?.videos.length ?? 0,
|
|
21879
|
-
html: readFileSync14(
|
|
22000
|
+
html: readFileSync14(join48(compiledDir, "index.html"), "utf-8"),
|
|
21880
22001
|
// The plan ships a deferred source only to chunks that show it; don't wait on the rest.
|
|
21881
22002
|
skipReadinessVideoIds: deferredVideos.filter(
|
|
21882
22003
|
(video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
|
|
@@ -21885,7 +22006,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21885
22006
|
deferredVideos.filter((video) => remoteVideoIds.has(video.videoId))
|
|
21886
22007
|
)
|
|
21887
22008
|
});
|
|
21888
|
-
captureOptions.onStaticDedupActivity = () =>
|
|
22009
|
+
captureOptions.onStaticDedupActivity = () => noteCaptureActivity(job);
|
|
21889
22010
|
const captureFrames = effectiveChunkFrames(framesInChunk, slice.captureCost);
|
|
21890
22011
|
const chunkWorkerCount = resolveChunkCaptureWorkers(
|
|
21891
22012
|
captureFrames,
|
|
@@ -22002,7 +22123,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22002
22123
|
outputRoot: videoFramesDir,
|
|
22003
22124
|
cfg,
|
|
22004
22125
|
remoteSources,
|
|
22005
|
-
shownBoxes
|
|
22126
|
+
shownBoxes,
|
|
22127
|
+
onProgress: () => noteCaptureActivity(job)
|
|
22006
22128
|
}).then((frames) => {
|
|
22007
22129
|
videoExtractMs = Date.now() - extractStarted;
|
|
22008
22130
|
return frames;
|
|
@@ -22045,10 +22167,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22045
22167
|
const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
|
|
22046
22168
|
const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
|
|
22047
22169
|
if (isPngSequence) {
|
|
22048
|
-
if (!
|
|
22170
|
+
if (!existsSync30(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
|
|
22049
22171
|
} else {
|
|
22050
|
-
const outDir =
|
|
22051
|
-
if (!
|
|
22172
|
+
const outDir = join48(outputChunkPath, "..");
|
|
22173
|
+
if (!existsSync30(outDir)) mkdirSync19(outDir, { recursive: true });
|
|
22052
22174
|
}
|
|
22053
22175
|
const encodeInput = {
|
|
22054
22176
|
job,
|
|
@@ -22324,10 +22446,10 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22324
22446
|
if (config.cfr === true) {
|
|
22325
22447
|
throw new RenderSpanUnsupportedError("--start/--end cannot be combined with a cfr re-encode.");
|
|
22326
22448
|
}
|
|
22327
|
-
const workDir = mkdtempSync(
|
|
22449
|
+
const workDir = mkdtempSync(join49(tmpdir5(), "hf-render-span-"));
|
|
22328
22450
|
try {
|
|
22329
|
-
const planDir =
|
|
22330
|
-
const partsDir =
|
|
22451
|
+
const planDir = join49(workDir, "plan");
|
|
22452
|
+
const partsDir = join49(workDir, "parts");
|
|
22331
22453
|
mkdirSync20(partsDir, { recursive: true });
|
|
22332
22454
|
const planned = await plan(
|
|
22333
22455
|
projectDir,
|
|
@@ -22346,7 +22468,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22346
22468
|
planned.totalFrames
|
|
22347
22469
|
);
|
|
22348
22470
|
const slices = JSON.parse(
|
|
22349
|
-
readFileSync15(
|
|
22471
|
+
readFileSync15(join49(planDir, "meta", "chunks.json"), "utf-8")
|
|
22350
22472
|
);
|
|
22351
22473
|
const parts = [];
|
|
22352
22474
|
for (const slice of slices) {
|
|
@@ -22356,7 +22478,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22356
22478
|
};
|
|
22357
22479
|
if (range.endFrame <= range.startFrame) continue;
|
|
22358
22480
|
throwIfAborted(config.abortSignal);
|
|
22359
|
-
const part =
|
|
22481
|
+
const part = join49(partsDir, `part-${String(parts.length).padStart(4, "0")}.mp4`);
|
|
22360
22482
|
await renderChunk(planDir, slice.index, part, { frameRange: range });
|
|
22361
22483
|
parts.push(part);
|
|
22362
22484
|
}
|
|
@@ -22388,7 +22510,8 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
22388
22510
|
"PAGE_NEVER_READY",
|
|
22389
22511
|
"VARIABLES_INVALID",
|
|
22390
22512
|
"OUTPUT_DIMENSIONS_MISMATCH",
|
|
22391
|
-
"COMPOSITION_TOO_LARGE"
|
|
22513
|
+
"COMPOSITION_TOO_LARGE",
|
|
22514
|
+
"COMPILE_TIMEOUT"
|
|
22392
22515
|
]);
|
|
22393
22516
|
function extractSafeRenderErrorCode(error) {
|
|
22394
22517
|
if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
|
|
@@ -23012,7 +23135,7 @@ import {
|
|
|
23012
23135
|
|
|
23013
23136
|
// src/server.ts
|
|
23014
23137
|
import {
|
|
23015
|
-
existsSync as
|
|
23138
|
+
existsSync as existsSync33,
|
|
23016
23139
|
mkdirSync as mkdirSync21,
|
|
23017
23140
|
statSync as statSync14,
|
|
23018
23141
|
mkdtempSync as mkdtempSync2,
|
|
@@ -23020,7 +23143,7 @@ import {
|
|
|
23020
23143
|
rmSync as rmSync19,
|
|
23021
23144
|
createReadStream as createReadStream6
|
|
23022
23145
|
} from "node:fs";
|
|
23023
|
-
import { resolve as resolve13, dirname as
|
|
23146
|
+
import { resolve as resolve13, dirname as dirname22, join as join52 } from "node:path";
|
|
23024
23147
|
import { tmpdir as tmpdir6 } from "node:os";
|
|
23025
23148
|
import { parseArgs } from "node:util";
|
|
23026
23149
|
import { isIP } from "node:net";
|
|
@@ -23037,7 +23160,7 @@ import { isSafePath as isSafePath4 } from "@hyperframes/core/safe-path";
|
|
|
23037
23160
|
|
|
23038
23161
|
// src/services/hyperframeLint.ts
|
|
23039
23162
|
import {
|
|
23040
|
-
existsSync as
|
|
23163
|
+
existsSync as existsSync31,
|
|
23041
23164
|
readFileSync as readFileSync16,
|
|
23042
23165
|
statSync as statSync13,
|
|
23043
23166
|
openSync as openSync8,
|
|
@@ -23045,9 +23168,9 @@ import {
|
|
|
23045
23168
|
closeSync as closeSync8,
|
|
23046
23169
|
constants as constants4
|
|
23047
23170
|
} from "node:fs";
|
|
23048
|
-
import { resolve as resolve12, join as
|
|
23049
|
-
import { fileURLToPath as
|
|
23050
|
-
import { Worker as
|
|
23171
|
+
import { resolve as resolve12, join as join50, relative as relative9, isAbsolute as isAbsolute6, sep as sep7, dirname as dirname20 } from "node:path";
|
|
23172
|
+
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
23173
|
+
import { Worker as Worker3 } from "node:worker_threads";
|
|
23051
23174
|
function isStringRecord(value) {
|
|
23052
23175
|
if (!value || typeof value !== "object" || Array.isArray(value)) {
|
|
23053
23176
|
return false;
|
|
@@ -23096,7 +23219,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
|
23096
23219
|
}
|
|
23097
23220
|
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
23098
23221
|
const absProjectDir = resolve12(projectDir);
|
|
23099
|
-
if (!
|
|
23222
|
+
if (!existsSync31(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
|
|
23100
23223
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
23101
23224
|
}
|
|
23102
23225
|
const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
|
|
@@ -23117,7 +23240,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
|
23117
23240
|
}
|
|
23118
23241
|
}
|
|
23119
23242
|
return {
|
|
23120
|
-
error: `No HTML entry file found in project directory: ${
|
|
23243
|
+
error: `No HTML entry file found in project directory: ${join50(absProjectDir, preferredEntryFile || "index.html")}`
|
|
23121
23244
|
};
|
|
23122
23245
|
}
|
|
23123
23246
|
function prepareHyperframeLintBody(body, isAllowedEntry) {
|
|
@@ -23184,10 +23307,10 @@ function freeLintSlot() {
|
|
|
23184
23307
|
waiting.shift()?.();
|
|
23185
23308
|
}
|
|
23186
23309
|
function resolveLintWorkerEntry() {
|
|
23187
|
-
const here =
|
|
23310
|
+
const here = dirname20(fileURLToPath7(import.meta.url));
|
|
23188
23311
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
23189
|
-
const candidate =
|
|
23190
|
-
if (
|
|
23312
|
+
const candidate = join50(here, name);
|
|
23313
|
+
if (existsSync31(candidate)) return candidate;
|
|
23191
23314
|
}
|
|
23192
23315
|
return void 0;
|
|
23193
23316
|
}
|
|
@@ -23220,7 +23343,7 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
23220
23343
|
return new Promise((resolvePromise, reject) => {
|
|
23221
23344
|
let worker;
|
|
23222
23345
|
try {
|
|
23223
|
-
worker = new
|
|
23346
|
+
worker = new Worker3(entry, {
|
|
23224
23347
|
workerData: {
|
|
23225
23348
|
html: prepared.html,
|
|
23226
23349
|
opts: { filePath: prepared.entryFile, compSrcPath: prepared.entryFile }
|
|
@@ -23255,10 +23378,10 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
23255
23378
|
}
|
|
23256
23379
|
|
|
23257
23380
|
// src/services/healthWorker.ts
|
|
23258
|
-
import { Worker as
|
|
23259
|
-
import { fileURLToPath as
|
|
23260
|
-
import { dirname as
|
|
23261
|
-
import { existsSync as
|
|
23381
|
+
import { Worker as Worker4 } from "node:worker_threads";
|
|
23382
|
+
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
23383
|
+
import { dirname as dirname21, join as join51 } from "node:path";
|
|
23384
|
+
import { existsSync as existsSync32 } from "node:fs";
|
|
23262
23385
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
23263
23386
|
async function startHealthWorker(options = {}) {
|
|
23264
23387
|
const log = options.logger ?? defaultLogger2();
|
|
@@ -23269,7 +23392,7 @@ async function startHealthWorker(options = {}) {
|
|
|
23269
23392
|
"[healthWorker] could not resolve worker entry. Pass options.workerEntry or ensure healthWorkerThread.{js,ts} is co-located."
|
|
23270
23393
|
);
|
|
23271
23394
|
}
|
|
23272
|
-
const worker = new
|
|
23395
|
+
const worker = new Worker4(entry, {
|
|
23273
23396
|
workerData: { port },
|
|
23274
23397
|
// Keep stdio inherited so the worker's console logs land in the pod logs
|
|
23275
23398
|
// alongside the main thread's.
|
|
@@ -23332,10 +23455,10 @@ function defaultLogger2() {
|
|
|
23332
23455
|
};
|
|
23333
23456
|
}
|
|
23334
23457
|
function resolveWorkerEntry2() {
|
|
23335
|
-
const here =
|
|
23336
|
-
const candidates = [
|
|
23458
|
+
const here = dirname21(fileURLToPath8(import.meta.url));
|
|
23459
|
+
const candidates = [join51(here, "healthWorkerThread.js"), join51(here, "healthWorkerThread.ts")];
|
|
23337
23460
|
for (const candidate of candidates) {
|
|
23338
|
-
if (
|
|
23461
|
+
if (existsSync32(candidate)) return candidate;
|
|
23339
23462
|
}
|
|
23340
23463
|
return void 0;
|
|
23341
23464
|
}
|
|
@@ -23504,8 +23627,8 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
23504
23627
|
throw new Error("outputPath must be inside the renders directory");
|
|
23505
23628
|
}
|
|
23506
23629
|
}
|
|
23507
|
-
const outputDir =
|
|
23508
|
-
if (!
|
|
23630
|
+
const outputDir = dirname22(absoluteOutputPath);
|
|
23631
|
+
if (!existsSync33(outputDir)) mkdirSync21(outputDir, { recursive: true });
|
|
23509
23632
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
23510
23633
|
}
|
|
23511
23634
|
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
@@ -23583,12 +23706,12 @@ function prepareProjectDirectory(projectDir, options, policy) {
|
|
|
23583
23706
|
if (!candidate) return null;
|
|
23584
23707
|
const absProjectDir = policy ? resolve13(policy.projectsDir, candidate) : resolve13(candidate);
|
|
23585
23708
|
const shown = policy ? candidate : absProjectDir;
|
|
23586
|
-
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !
|
|
23709
|
+
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync33(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
|
|
23587
23710
|
return { error: `Project directory not found: ${shown}` };
|
|
23588
23711
|
}
|
|
23589
23712
|
const entry = options.entryFile || "index.html";
|
|
23590
23713
|
const entryPath = resolve13(absProjectDir, entry);
|
|
23591
|
-
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !
|
|
23714
|
+
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync33(entryPath)) {
|
|
23592
23715
|
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
23593
23716
|
}
|
|
23594
23717
|
return { prepared: { input: { projectDir: absProjectDir, ...options } } };
|
|
@@ -23609,8 +23732,8 @@ async function resolveInlineRenderHtml(body) {
|
|
|
23609
23732
|
}
|
|
23610
23733
|
function materializeInlineProject(html, options) {
|
|
23611
23734
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
|
|
23612
|
-
const tempProjectDir = mkdtempSync2(
|
|
23613
|
-
writeFileSync13(
|
|
23735
|
+
const tempProjectDir = mkdtempSync2(join52(tempRoot, "producer-project-"));
|
|
23736
|
+
writeFileSync13(join52(tempProjectDir, "index.html"), html, "utf-8");
|
|
23614
23737
|
return {
|
|
23615
23738
|
prepared: {
|
|
23616
23739
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -23686,7 +23809,7 @@ function publicPerfSummary(job) {
|
|
|
23686
23809
|
return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
|
|
23687
23810
|
}
|
|
23688
23811
|
function outputFileSize(path) {
|
|
23689
|
-
return
|
|
23812
|
+
return existsSync33(path) ? statSync14(path).size : 0;
|
|
23690
23813
|
}
|
|
23691
23814
|
function createBlockingProgressReporter(log, requestId) {
|
|
23692
23815
|
let lastLoggedPct = -10;
|
|
@@ -24013,7 +24136,7 @@ function createRenderHandlers(options = {}) {
|
|
|
24013
24136
|
if (!artifact) {
|
|
24014
24137
|
return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
|
|
24015
24138
|
}
|
|
24016
|
-
if (!
|
|
24139
|
+
if (!existsSync33(artifact.path)) {
|
|
24017
24140
|
store.delete(token);
|
|
24018
24141
|
return c.json({ success: false, error: "Output artifact file missing" }, 404);
|
|
24019
24142
|
}
|
|
@@ -24204,7 +24327,7 @@ import { quantizeTimeToFrame, MEDIA_VISUAL_STYLE_PROPERTIES } from "@hyperframes
|
|
|
24204
24327
|
// src/services/distributed/planV2Execution.ts
|
|
24205
24328
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync21 } from "node:fs";
|
|
24206
24329
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
24207
|
-
import { join as
|
|
24330
|
+
import { join as join54 } from "node:path";
|
|
24208
24331
|
|
|
24209
24332
|
// src/services/distributed/assemble.ts
|
|
24210
24333
|
import {
|
|
@@ -24213,7 +24336,7 @@ import {
|
|
|
24213
24336
|
} from "@hyperframes/engine";
|
|
24214
24337
|
import {
|
|
24215
24338
|
cpSync as cpSync3,
|
|
24216
|
-
existsSync as
|
|
24339
|
+
existsSync as existsSync34,
|
|
24217
24340
|
mkdirSync as mkdirSync22,
|
|
24218
24341
|
readFileSync as readFileSync17,
|
|
24219
24342
|
readdirSync as readdirSync12,
|
|
@@ -24221,7 +24344,7 @@ import {
|
|
|
24221
24344
|
statSync as statSync15
|
|
24222
24345
|
} from "node:fs";
|
|
24223
24346
|
import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
|
|
24224
|
-
import { basename as basename9, dirname as
|
|
24347
|
+
import { basename as basename9, dirname as dirname23, join as join53 } from "node:path";
|
|
24225
24348
|
import {
|
|
24226
24349
|
appendRateCapArgs as appendRateCapArgs2,
|
|
24227
24350
|
writeVideoConcatList,
|
|
@@ -24270,10 +24393,10 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24270
24393
|
}
|
|
24271
24394
|
const format = plan2.dimensions.format;
|
|
24272
24395
|
const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
|
|
24273
|
-
if (!
|
|
24274
|
-
mkdirSync22(
|
|
24396
|
+
if (!existsSync34(dirname23(outputPath))) {
|
|
24397
|
+
mkdirSync22(dirname23(outputPath), { recursive: true });
|
|
24275
24398
|
}
|
|
24276
|
-
const workDir = createStagingDir7(
|
|
24399
|
+
const workDir = createStagingDir7(dirname23(outputPath), `${basename9(outputPath)}.assemble-work-`);
|
|
24277
24400
|
const fps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
24278
24401
|
const stageMs = {};
|
|
24279
24402
|
const ctx = {
|
|
@@ -24293,8 +24416,8 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24293
24416
|
};
|
|
24294
24417
|
try {
|
|
24295
24418
|
const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
|
|
24296
|
-
const finalPath =
|
|
24297
|
-
const audio = audioPath !== null &&
|
|
24419
|
+
const finalPath = join53(workDir, `output.${format}`);
|
|
24420
|
+
const audio = audioPath !== null && existsSync34(audioPath) ? audioPath : null;
|
|
24298
24421
|
await writeJoined(ctx, videoSources, audio, finalPath);
|
|
24299
24422
|
renameWithRetry10(finalPath, outputPath);
|
|
24300
24423
|
log.info("[assemble] stage timings", {
|
|
@@ -24312,7 +24435,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24312
24435
|
});
|
|
24313
24436
|
}
|
|
24314
24437
|
}
|
|
24315
|
-
const fileSize =
|
|
24438
|
+
const fileSize = existsSync34(outputPath) ? statSync15(outputPath).size : 0;
|
|
24316
24439
|
return {
|
|
24317
24440
|
...referenceBackgroundResult8(plan2[REFERENCE_BACKGROUND_FIELD6]),
|
|
24318
24441
|
outputPath,
|
|
@@ -24322,15 +24445,15 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24322
24445
|
};
|
|
24323
24446
|
}
|
|
24324
24447
|
function readAssemblePlan(planDir, chunkPaths) {
|
|
24325
|
-
const planJsonPath =
|
|
24326
|
-
const chunksJsonPath =
|
|
24327
|
-
if (!
|
|
24448
|
+
const planJsonPath = join53(planDir, "plan.json");
|
|
24449
|
+
const chunksJsonPath = join53(planDir, "meta", "chunks.json");
|
|
24450
|
+
if (!existsSync34(planJsonPath)) {
|
|
24328
24451
|
throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
|
|
24329
24452
|
}
|
|
24330
24453
|
const plan2 = JSON.parse(readFileSync17(planJsonPath, "utf-8"));
|
|
24331
24454
|
readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
|
|
24332
24455
|
validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
|
|
24333
|
-
if (!
|
|
24456
|
+
if (!existsSync34(chunksJsonPath)) {
|
|
24334
24457
|
throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
|
|
24335
24458
|
}
|
|
24336
24459
|
const chunks = JSON.parse(readFileSync17(chunksJsonPath, "utf-8"));
|
|
@@ -24345,7 +24468,7 @@ function readAssemblePlan(planDir, chunkPaths) {
|
|
|
24345
24468
|
}
|
|
24346
24469
|
}
|
|
24347
24470
|
for (const path of chunkPaths.flat()) {
|
|
24348
|
-
if (!
|
|
24471
|
+
if (!existsSync34(path)) {
|
|
24349
24472
|
throw new Error(`[assemble] chunk path does not exist: ${path}`);
|
|
24350
24473
|
}
|
|
24351
24474
|
}
|
|
@@ -24378,7 +24501,7 @@ function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
|
|
|
24378
24501
|
return args;
|
|
24379
24502
|
}
|
|
24380
24503
|
async function reencodeCfr(ctx, chunkPaths, encoder) {
|
|
24381
|
-
const cfrOutputPath =
|
|
24504
|
+
const cfrOutputPath = join53(ctx.workDir, `cfr.${ctx.format}`);
|
|
24382
24505
|
const cfrArgs = cfrEncodeArgs(videoInputArgs(ctx, chunkPaths), encoder, ctx.fpsArg);
|
|
24383
24506
|
appendRenderProvenanceArgs2(cfrArgs, cfrOutputPath);
|
|
24384
24507
|
cfrArgs.push("-y", cfrOutputPath);
|
|
@@ -24405,7 +24528,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
24405
24528
|
);
|
|
24406
24529
|
return;
|
|
24407
24530
|
}
|
|
24408
|
-
const paddedAudioPath =
|
|
24531
|
+
const paddedAudioPath = join53(ctx.workDir, "audio-padded.m4a");
|
|
24409
24532
|
const padTrimResult = await ctx.timed(
|
|
24410
24533
|
"audioMs",
|
|
24411
24534
|
() => padOrTrimAudioToVideoFrameCount({
|
|
@@ -24480,12 +24603,12 @@ function stitchesSeparateAudio(planDir) {
|
|
|
24480
24603
|
return lockedAudio(planDir).separateAudio === true;
|
|
24481
24604
|
}
|
|
24482
24605
|
function planFormat(planDir) {
|
|
24483
|
-
const plan2 = JSON.parse(readFileSync17(
|
|
24606
|
+
const plan2 = JSON.parse(readFileSync17(join53(planDir, "plan.json"), "utf-8"));
|
|
24484
24607
|
return plan2.dimensions.format;
|
|
24485
24608
|
}
|
|
24486
24609
|
function lockedAudio(planDir) {
|
|
24487
|
-
const encoderJsonPath =
|
|
24488
|
-
if (!
|
|
24610
|
+
const encoderJsonPath = join53(planDir, "meta", "encoder.json");
|
|
24611
|
+
if (!existsSync34(encoderJsonPath)) return {};
|
|
24489
24612
|
return JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
|
|
24490
24613
|
}
|
|
24491
24614
|
function readCfrEncoder(planDir, format) {
|
|
@@ -24494,8 +24617,8 @@ function readCfrEncoder(planDir, format) {
|
|
|
24494
24617
|
`[assemble] cfr=true is only supported for format="mp4" (got "${format}"). Stream-copy paths for webm and mov already produce exact avg_frame_rate; cfr re-encode is not needed.`
|
|
24495
24618
|
);
|
|
24496
24619
|
}
|
|
24497
|
-
const encoderJsonPath =
|
|
24498
|
-
if (!
|
|
24620
|
+
const encoderJsonPath = join53(planDir, "meta", "encoder.json");
|
|
24621
|
+
if (!existsSync34(encoderJsonPath)) {
|
|
24499
24622
|
throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
|
|
24500
24623
|
}
|
|
24501
24624
|
const encoderJson = JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
|
|
@@ -24507,7 +24630,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
24507
24630
|
return encoderJson;
|
|
24508
24631
|
}
|
|
24509
24632
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
24510
|
-
if (
|
|
24633
|
+
if (existsSync34(outputPath)) rmSync20(outputPath, { recursive: true, force: true });
|
|
24511
24634
|
mkdirSync22(outputPath, { recursive: true });
|
|
24512
24635
|
let globalIdx = 0;
|
|
24513
24636
|
for (const chunkDir of chunkPaths) {
|
|
@@ -24521,8 +24644,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
24521
24644
|
throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
|
|
24522
24645
|
}
|
|
24523
24646
|
for (const frame of frames) {
|
|
24524
|
-
const dst =
|
|
24525
|
-
cpSync3(
|
|
24647
|
+
const dst = join53(outputPath, formatExportFrameName(globalIdx, "png"));
|
|
24648
|
+
cpSync3(join53(chunkDir, frame), dst);
|
|
24526
24649
|
globalIdx += 1;
|
|
24527
24650
|
}
|
|
24528
24651
|
}
|
|
@@ -24531,14 +24654,14 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
24531
24654
|
`[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
|
|
24532
24655
|
);
|
|
24533
24656
|
}
|
|
24534
|
-
if (audioPath !== null &&
|
|
24535
|
-
const sidecar =
|
|
24657
|
+
if (audioPath !== null && existsSync34(audioPath)) {
|
|
24658
|
+
const sidecar = join53(outputPath, MIXED_AUDIO_FILENAME4);
|
|
24536
24659
|
cpSync3(audioPath, sidecar);
|
|
24537
24660
|
}
|
|
24538
24661
|
let fileSize = 0;
|
|
24539
24662
|
for (const name of readdirSync12(outputPath)) {
|
|
24540
24663
|
try {
|
|
24541
|
-
fileSize += statSync15(
|
|
24664
|
+
fileSize += statSync15(join53(outputPath, name)).size;
|
|
24542
24665
|
} catch {
|
|
24543
24666
|
}
|
|
24544
24667
|
}
|
|
@@ -24552,8 +24675,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
24552
24675
|
|
|
24553
24676
|
// src/services/distributed/planV2Execution.ts
|
|
24554
24677
|
async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
24555
|
-
const workRoot = mkdtempSync3(
|
|
24556
|
-
const materializedPlanDir =
|
|
24678
|
+
const workRoot = mkdtempSync3(join54(tmpdir7(), "hf-plan-v2-chunk-"));
|
|
24679
|
+
const materializedPlanDir = join54(workRoot, "plan");
|
|
24557
24680
|
try {
|
|
24558
24681
|
materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
|
|
24559
24682
|
return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
|
|
@@ -24562,8 +24685,8 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
|
24562
24685
|
}
|
|
24563
24686
|
}
|
|
24564
24687
|
async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
24565
|
-
const workRoot = mkdtempSync3(
|
|
24566
|
-
const materializedPlanDir =
|
|
24688
|
+
const workRoot = mkdtempSync3(join54(tmpdir7(), "hf-plan-v2-assembler-"));
|
|
24689
|
+
const materializedPlanDir = join54(workRoot, "plan");
|
|
24567
24690
|
try {
|
|
24568
24691
|
const materialized = materializePlanV2Target(
|
|
24569
24692
|
planV2Dir,
|