@hyperframes/producer 0.9.99 → 0.9.101
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/distributed.js +436 -210
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/index.js +485 -259
- package/dist/public-server.js +323 -97
- package/dist/services/render/stages/runtimeAudio.d.ts +34 -0
- package/package.json +8 -8
package/dist/index.js
CHANGED
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
|
|
11
11
|
import {
|
|
12
12
|
existsSync as existsSync22,
|
|
13
|
-
mkdirSync as
|
|
13
|
+
mkdirSync as mkdirSync14,
|
|
14
14
|
readdirSync as readdirSync6,
|
|
15
15
|
rmSync as rmSync13,
|
|
16
16
|
statSync as statSync10,
|
|
17
|
-
writeFileSync as
|
|
17
|
+
writeFileSync as writeFileSync8,
|
|
18
18
|
copyFileSync as copyFileSync5,
|
|
19
19
|
appendFileSync
|
|
20
20
|
} from "fs";
|
|
@@ -361,7 +361,7 @@ import {
|
|
|
361
361
|
referenceBackgroundResult,
|
|
362
362
|
createReferenceBackgroundRecorder
|
|
363
363
|
} from "@hyperframes/engine";
|
|
364
|
-
import { join as
|
|
364
|
+
import { join as join36, dirname as dirname16, resolve as resolve10 } from "path";
|
|
365
365
|
import { fromEmptyFolder } from "@hyperframes/parsers/ff-binaries";
|
|
366
366
|
import { totalmem as totalmem2 } from "node:os";
|
|
367
367
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
@@ -11080,8 +11080,8 @@ async function runCompileStage(input) {
|
|
|
11080
11080
|
}
|
|
11081
11081
|
|
|
11082
11082
|
// src/services/render/stages/probeStage.ts
|
|
11083
|
-
import { createHash as
|
|
11084
|
-
import { basename as basename7, join as
|
|
11083
|
+
import { createHash as createHash8 } from "node:crypto";
|
|
11084
|
+
import { basename as basename7, join as join25 } from "node:path";
|
|
11085
11085
|
import { parseHTML as parseHTML6 } from "@hyperframes/parsers/linkedom";
|
|
11086
11086
|
import {
|
|
11087
11087
|
closeCaptureSession as closeCaptureSession4,
|
|
@@ -11134,6 +11134,211 @@ function resolveCaptureSurface(input, quality) {
|
|
|
11134
11134
|
};
|
|
11135
11135
|
}
|
|
11136
11136
|
|
|
11137
|
+
// src/services/render/stages/runtimeAudio.ts
|
|
11138
|
+
import { createHash as createHash7 } from "node:crypto";
|
|
11139
|
+
import { mkdirSync as mkdirSync11, writeFileSync as writeFileSync6 } from "node:fs";
|
|
11140
|
+
import { join as join24 } from "node:path";
|
|
11141
|
+
var RUNTIME_AUDIO_SUBDIR = "__hf_runtime_audio";
|
|
11142
|
+
var MAX_INLINE_AUDIO_BYTES = 64 * 1024 * 1024;
|
|
11143
|
+
var MAX_TOTAL_INLINE_AUDIO_BYTES = 128 * 1024 * 1024;
|
|
11144
|
+
var MIME_EXTENSIONS = {
|
|
11145
|
+
"audio/wav": ".wav",
|
|
11146
|
+
"audio/wave": ".wav",
|
|
11147
|
+
"audio/x-wav": ".wav",
|
|
11148
|
+
"audio/mpeg": ".mp3",
|
|
11149
|
+
"audio/mp3": ".mp3",
|
|
11150
|
+
"audio/ogg": ".ogg",
|
|
11151
|
+
"audio/webm": ".webm",
|
|
11152
|
+
"audio/aac": ".m4a",
|
|
11153
|
+
"audio/mp4": ".m4a",
|
|
11154
|
+
"audio/m4a": ".m4a",
|
|
11155
|
+
"audio/x-m4a": ".m4a",
|
|
11156
|
+
"audio/flac": ".flac",
|
|
11157
|
+
"audio/x-flac": ".flac"
|
|
11158
|
+
};
|
|
11159
|
+
var BASE64_BODY = /^[A-Za-z0-9+/]*={0,2}$/;
|
|
11160
|
+
function extensionForMime(mimeType) {
|
|
11161
|
+
const normalized = mimeType.split(";", 1)[0]?.trim().toLowerCase() ?? "";
|
|
11162
|
+
return MIME_EXTENSIONS[normalized] ?? ".bin";
|
|
11163
|
+
}
|
|
11164
|
+
function sameOriginBlobPrefix(fileServerUrl) {
|
|
11165
|
+
try {
|
|
11166
|
+
return `blob:${new URL(fileServerUrl).origin}/`.toLowerCase();
|
|
11167
|
+
} catch {
|
|
11168
|
+
return null;
|
|
11169
|
+
}
|
|
11170
|
+
}
|
|
11171
|
+
function decodeBase64Within(raw, maxBytes) {
|
|
11172
|
+
const compact = raw.replace(/\s+/g, "");
|
|
11173
|
+
if (compact.length === 0 || compact.length % 4 === 1) return null;
|
|
11174
|
+
const maxChars = Math.ceil(maxBytes / 3) * 4;
|
|
11175
|
+
if (compact.length > maxChars || !BASE64_BODY.test(compact)) return null;
|
|
11176
|
+
const bytes = Buffer.from(compact, "base64");
|
|
11177
|
+
return bytes.byteLength > 0 && bytes.byteLength <= maxBytes ? bytes : null;
|
|
11178
|
+
}
|
|
11179
|
+
function decodePercentWithin(payload, maxBytes) {
|
|
11180
|
+
if (payload.length > maxBytes * 3) return null;
|
|
11181
|
+
try {
|
|
11182
|
+
const bytes = Buffer.from(decodeURIComponent(payload), "utf8");
|
|
11183
|
+
return bytes.byteLength > 0 && bytes.byteLength <= maxBytes ? bytes : null;
|
|
11184
|
+
} catch {
|
|
11185
|
+
return null;
|
|
11186
|
+
}
|
|
11187
|
+
}
|
|
11188
|
+
function parseDataHeader(header) {
|
|
11189
|
+
const parts = header.split(";").map((part) => part.trim()).filter(Boolean);
|
|
11190
|
+
const isBase64 = parts.at(-1)?.toLowerCase() === "base64";
|
|
11191
|
+
const first = parts[0] ?? "";
|
|
11192
|
+
const isMime = Boolean(first) && !first.includes("=") && first.toLowerCase() !== "base64";
|
|
11193
|
+
return { isBase64, mimeType: isMime ? first.toLowerCase() : "" };
|
|
11194
|
+
}
|
|
11195
|
+
function decodeDataAudioUri(uri, maxBytes) {
|
|
11196
|
+
const comma = uri.indexOf(",");
|
|
11197
|
+
if (comma < 5) return { ok: false, reason: "malformed_data_uri" };
|
|
11198
|
+
const payload = uri.slice(comma + 1);
|
|
11199
|
+
if (!payload) return { ok: false, reason: "empty" };
|
|
11200
|
+
const { isBase64, mimeType } = parseDataHeader(uri.slice(5, comma));
|
|
11201
|
+
const bytes = isBase64 ? decodeBase64Within(payload, maxBytes) : decodePercentWithin(payload, maxBytes);
|
|
11202
|
+
return bytes ? { ok: true, bytes, mimeType } : { ok: false, reason: "invalid_or_too_large" };
|
|
11203
|
+
}
|
|
11204
|
+
function writeRuntimeAudio(compiledDir, bytes, mimeType) {
|
|
11205
|
+
const digest = createHash7("sha256").update(bytes).digest("hex").slice(0, 16);
|
|
11206
|
+
const filename = `${digest}${extensionForMime(mimeType)}`;
|
|
11207
|
+
const dir = join24(compiledDir, RUNTIME_AUDIO_SUBDIR);
|
|
11208
|
+
mkdirSync11(dir, { recursive: true });
|
|
11209
|
+
const target = join24(dir, filename);
|
|
11210
|
+
try {
|
|
11211
|
+
writeFileSync6(target, bytes, { flag: "wx" });
|
|
11212
|
+
} catch (error) {
|
|
11213
|
+
if (error.code !== "EEXIST") throw error;
|
|
11214
|
+
}
|
|
11215
|
+
return `${RUNTIME_AUDIO_SUBDIR}/${filename}`;
|
|
11216
|
+
}
|
|
11217
|
+
async function readBlobFromPage(page, url, maxBytes) {
|
|
11218
|
+
const result = await page.evaluate(
|
|
11219
|
+
async (blobUrl, limit) => {
|
|
11220
|
+
try {
|
|
11221
|
+
const response = await fetch(blobUrl);
|
|
11222
|
+
if (!response.ok) return { ok: false, reason: `status_${response.status}` };
|
|
11223
|
+
const blob = await response.blob();
|
|
11224
|
+
if (blob.size <= 0) return { ok: false, reason: "empty" };
|
|
11225
|
+
if (blob.size > limit) return { ok: false, reason: "too_large" };
|
|
11226
|
+
const dataUrl = await new Promise((resolve15, reject) => {
|
|
11227
|
+
const reader = new FileReader();
|
|
11228
|
+
reader.onload = () => resolve15(String(reader.result ?? ""));
|
|
11229
|
+
reader.onerror = () => reject(reader.error ?? new Error("read failed"));
|
|
11230
|
+
reader.readAsDataURL(blob);
|
|
11231
|
+
});
|
|
11232
|
+
const comma = dataUrl.indexOf(",");
|
|
11233
|
+
return comma < 0 ? { ok: false, reason: "invalid_data_url" } : { ok: true, base64: dataUrl.slice(comma + 1), mimeType: blob.type || "" };
|
|
11234
|
+
} catch {
|
|
11235
|
+
return { ok: false, reason: "fetch_failed" };
|
|
11236
|
+
}
|
|
11237
|
+
},
|
|
11238
|
+
url,
|
|
11239
|
+
maxBytes
|
|
11240
|
+
);
|
|
11241
|
+
if (!result || typeof result !== "object") return { ok: false, reason: "invalid_response" };
|
|
11242
|
+
const typed = result;
|
|
11243
|
+
if (typed.ok === true && typeof typed.base64 === "string") {
|
|
11244
|
+
return {
|
|
11245
|
+
ok: true,
|
|
11246
|
+
base64: typed.base64,
|
|
11247
|
+
mimeType: typeof typed.mimeType === "string" ? typed.mimeType : ""
|
|
11248
|
+
};
|
|
11249
|
+
}
|
|
11250
|
+
const reason = typed.ok === false && typeof typed.reason === "string" ? typed.reason : "read_failed";
|
|
11251
|
+
return { ok: false, reason };
|
|
11252
|
+
}
|
|
11253
|
+
async function materializeOneBlob(audio, page, compiledDir, clipLimit, log, assertNotAborted) {
|
|
11254
|
+
if (clipLimit <= 0) {
|
|
11255
|
+
log?.warn("[Probe] Runtime audio byte limit reached; cannot materialize blob", {
|
|
11256
|
+
id: audio.id
|
|
11257
|
+
});
|
|
11258
|
+
return null;
|
|
11259
|
+
}
|
|
11260
|
+
const read2 = await readBlobFromPage(page, audio.src, clipLimit);
|
|
11261
|
+
assertNotAborted?.();
|
|
11262
|
+
if (!read2.ok) {
|
|
11263
|
+
log?.warn("[Probe] Could not materialize blob audio source", {
|
|
11264
|
+
id: audio.id,
|
|
11265
|
+
reason: read2.reason
|
|
11266
|
+
});
|
|
11267
|
+
return null;
|
|
11268
|
+
}
|
|
11269
|
+
const bytes = decodeBase64Within(read2.base64, clipLimit);
|
|
11270
|
+
if (!bytes) {
|
|
11271
|
+
log?.warn("[Probe] Blob audio payload was empty, invalid, or exceeded limit", {
|
|
11272
|
+
id: audio.id
|
|
11273
|
+
});
|
|
11274
|
+
return null;
|
|
11275
|
+
}
|
|
11276
|
+
return { path: writeRuntimeAudio(compiledDir, bytes, read2.mimeType), bytes: bytes.byteLength };
|
|
11277
|
+
}
|
|
11278
|
+
async function materializeBlobAudioSources(input) {
|
|
11279
|
+
const prefix = sameOriginBlobPrefix(input.fileServerUrl);
|
|
11280
|
+
if (!prefix) return;
|
|
11281
|
+
const maxPerClip = input.limits?.maxPerClipBytes ?? MAX_INLINE_AUDIO_BYTES;
|
|
11282
|
+
let remaining = input.limits?.maxTotalBytes ?? MAX_TOTAL_INLINE_AUDIO_BYTES;
|
|
11283
|
+
const cachedByUrl = /* @__PURE__ */ new Map();
|
|
11284
|
+
for (const audio of input.audios) {
|
|
11285
|
+
if (!/^blob:/i.test(audio.src)) continue;
|
|
11286
|
+
const cached = cachedByUrl.get(audio.src);
|
|
11287
|
+
if (cached) {
|
|
11288
|
+
audio.src = cached;
|
|
11289
|
+
continue;
|
|
11290
|
+
}
|
|
11291
|
+
if (!audio.src.toLowerCase().startsWith(prefix)) {
|
|
11292
|
+
input.log?.warn("[Probe] Skipping cross-origin blob audio source", { id: audio.id });
|
|
11293
|
+
continue;
|
|
11294
|
+
}
|
|
11295
|
+
const written = await materializeOneBlob(
|
|
11296
|
+
audio,
|
|
11297
|
+
input.page,
|
|
11298
|
+
input.compiledDir,
|
|
11299
|
+
Math.min(maxPerClip, remaining),
|
|
11300
|
+
input.log,
|
|
11301
|
+
input.assertNotAborted
|
|
11302
|
+
);
|
|
11303
|
+
if (!written) continue;
|
|
11304
|
+
remaining -= written.bytes;
|
|
11305
|
+
cachedByUrl.set(audio.src, written.path);
|
|
11306
|
+
audio.src = written.path;
|
|
11307
|
+
}
|
|
11308
|
+
}
|
|
11309
|
+
function materializeDataAudioSources(input) {
|
|
11310
|
+
const maxPerClip = input.limits?.maxPerClipBytes ?? MAX_INLINE_AUDIO_BYTES;
|
|
11311
|
+
let remaining = input.limits?.maxTotalBytes ?? MAX_TOTAL_INLINE_AUDIO_BYTES;
|
|
11312
|
+
const cachedByUri = /* @__PURE__ */ new Map();
|
|
11313
|
+
for (const audio of input.audios) {
|
|
11314
|
+
if (!/^data:/i.test(audio.src)) continue;
|
|
11315
|
+
const cached = cachedByUri.get(audio.src);
|
|
11316
|
+
if (cached) {
|
|
11317
|
+
audio.src = cached;
|
|
11318
|
+
continue;
|
|
11319
|
+
}
|
|
11320
|
+
const clipLimit = Math.min(maxPerClip, remaining);
|
|
11321
|
+
if (clipLimit <= 0) {
|
|
11322
|
+
input.log?.warn("[Probe] Inline audio byte limit reached; cannot materialize data URI", {
|
|
11323
|
+
id: audio.id
|
|
11324
|
+
});
|
|
11325
|
+
continue;
|
|
11326
|
+
}
|
|
11327
|
+
const decoded = decodeDataAudioUri(audio.src, clipLimit);
|
|
11328
|
+
if (!decoded.ok) {
|
|
11329
|
+
input.log?.warn("[Probe] Could not materialize data audio source", {
|
|
11330
|
+
id: audio.id,
|
|
11331
|
+
reason: decoded.reason
|
|
11332
|
+
});
|
|
11333
|
+
continue;
|
|
11334
|
+
}
|
|
11335
|
+
remaining -= decoded.bytes.byteLength;
|
|
11336
|
+
const relativePath = writeRuntimeAudio(input.compiledDir, decoded.bytes, decoded.mimeType);
|
|
11337
|
+
cachedByUri.set(audio.src, relativePath);
|
|
11338
|
+
audio.src = relativePath;
|
|
11339
|
+
}
|
|
11340
|
+
}
|
|
11341
|
+
|
|
11137
11342
|
// src/services/render/stages/probeStage.ts
|
|
11138
11343
|
var FRAME_BOUNDARY_EPSILON = 1e-3;
|
|
11139
11344
|
function durationToFrameCount(duration, fps) {
|
|
@@ -11320,6 +11525,7 @@ function hasRuntimeMediaChanges(html) {
|
|
|
11320
11525
|
if (insertedMedia) return true;
|
|
11321
11526
|
const managed = managedMediaElements(document2, false);
|
|
11322
11527
|
if (managed.length === 0) return false;
|
|
11528
|
+
if (scriptBodies.some((script) => /\bcreateObjectURL\s*\(/.test(script))) return true;
|
|
11323
11529
|
const managedIds = new Set(managed.map((m) => m.element.getAttribute("id")).filter(Boolean));
|
|
11324
11530
|
const selectors = /* @__PURE__ */ new Set();
|
|
11325
11531
|
let work = 0;
|
|
@@ -11360,7 +11566,7 @@ function reportedLengthSource(source) {
|
|
|
11360
11566
|
if (!source) return null;
|
|
11361
11567
|
if (source.from !== "media") return { from: source.from };
|
|
11362
11568
|
const name = basename7(source.src.split(/[?#]/, 1)[0] ?? "");
|
|
11363
|
-
const srcHash =
|
|
11569
|
+
const srcHash = createHash8("sha256").update(name).digest("hex").slice(0, 12);
|
|
11364
11570
|
return { from: "media", tag: source.tag, trimmed: source.trimmed, srcHash };
|
|
11365
11571
|
}
|
|
11366
11572
|
var STOPPED = "Preparing the render stopped while ";
|
|
@@ -11435,7 +11641,7 @@ async function runProbeStage(input) {
|
|
|
11435
11641
|
});
|
|
11436
11642
|
fileServer = await createFileServer({
|
|
11437
11643
|
projectDir,
|
|
11438
|
-
compiledDir:
|
|
11644
|
+
compiledDir: join25(workDir, "compiled"),
|
|
11439
11645
|
port: 0,
|
|
11440
11646
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
11441
11647
|
fps: job.config.fps,
|
|
@@ -11449,7 +11655,7 @@ async function runProbeStage(input) {
|
|
|
11449
11655
|
composition.videos,
|
|
11450
11656
|
compiled.html,
|
|
11451
11657
|
projectDir,
|
|
11452
|
-
|
|
11658
|
+
join25(workDir, "compiled")
|
|
11453
11659
|
),
|
|
11454
11660
|
recordReferenceBackground: input.recordReferenceBackground,
|
|
11455
11661
|
width,
|
|
@@ -11478,7 +11684,7 @@ async function runProbeStage(input) {
|
|
|
11478
11684
|
log.info("Creating capture session...", { attempt, maxAttempts: PROBE_MAX_ATTEMPTS });
|
|
11479
11685
|
probeSession = await createCaptureSession4(
|
|
11480
11686
|
fileServer.url,
|
|
11481
|
-
|
|
11687
|
+
join25(workDir, "probe"),
|
|
11482
11688
|
captureOpts,
|
|
11483
11689
|
null,
|
|
11484
11690
|
probeCfg
|
|
@@ -11564,7 +11770,7 @@ async function runProbeStage(input) {
|
|
|
11564
11770
|
});
|
|
11565
11771
|
probeSession = await createCaptureSession4(
|
|
11566
11772
|
fileServer.url,
|
|
11567
|
-
|
|
11773
|
+
join25(workDir, "probe-screenshot"),
|
|
11568
11774
|
captureOpts,
|
|
11569
11775
|
null,
|
|
11570
11776
|
{ ...probeCfg, forceScreenshot: true }
|
|
@@ -11608,7 +11814,7 @@ async function runProbeStage(input) {
|
|
|
11608
11814
|
compiled,
|
|
11609
11815
|
resolutions,
|
|
11610
11816
|
projectDir,
|
|
11611
|
-
|
|
11817
|
+
join25(workDir, "downloads"),
|
|
11612
11818
|
job.config.allowOutsideProjectAssets ? void 0 : projectDir,
|
|
11613
11819
|
{ includeScripts: job.config.includeOutsideScripts }
|
|
11614
11820
|
);
|
|
@@ -11757,6 +11963,21 @@ async function runProbeStage(input) {
|
|
|
11757
11963
|
}
|
|
11758
11964
|
}
|
|
11759
11965
|
}
|
|
11966
|
+
if (fileServer && composition.audios.length > 0) {
|
|
11967
|
+
const compiledDir = join25(workDir, "compiled");
|
|
11968
|
+
const serverUrl = fileServer.url;
|
|
11969
|
+
await probeStep(
|
|
11970
|
+
"reading runtime audio from the browser",
|
|
11971
|
+
() => materializeBlobAudioSources({
|
|
11972
|
+
page: session.page,
|
|
11973
|
+
fileServerUrl: serverUrl,
|
|
11974
|
+
audios: composition.audios,
|
|
11975
|
+
compiledDir,
|
|
11976
|
+
log,
|
|
11977
|
+
assertNotAborted
|
|
11978
|
+
})
|
|
11979
|
+
);
|
|
11980
|
+
}
|
|
11760
11981
|
if (composition.audios.length > 0) {
|
|
11761
11982
|
log.info("Discovering audio volume automation...", {
|
|
11762
11983
|
audioCount: composition.audios.length
|
|
@@ -11805,6 +12026,11 @@ async function runProbeStage(input) {
|
|
|
11805
12026
|
}
|
|
11806
12027
|
}
|
|
11807
12028
|
}
|
|
12029
|
+
materializeDataAudioSources({
|
|
12030
|
+
audios: composition.audios,
|
|
12031
|
+
compiledDir: join25(workDir, "compiled"),
|
|
12032
|
+
log
|
|
12033
|
+
});
|
|
11808
12034
|
dropMediaOutsideProject({
|
|
11809
12035
|
projectDir,
|
|
11810
12036
|
workDir,
|
|
@@ -11814,7 +12040,7 @@ async function runProbeStage(input) {
|
|
|
11814
12040
|
});
|
|
11815
12041
|
await preflightCompositionAssetMediaTypes({
|
|
11816
12042
|
projectDir,
|
|
11817
|
-
compiledDir:
|
|
12043
|
+
compiledDir: join25(workDir, "compiled"),
|
|
11818
12044
|
composition,
|
|
11819
12045
|
signal: abortSignal
|
|
11820
12046
|
});
|
|
@@ -11982,7 +12208,7 @@ function validateDistributedDuration(input) {
|
|
|
11982
12208
|
|
|
11983
12209
|
// src/services/render/stages/extractVideosStage.ts
|
|
11984
12210
|
import { existsSync as existsSync14 } from "node:fs";
|
|
11985
|
-
import { join as
|
|
12211
|
+
import { join as join26 } from "node:path";
|
|
11986
12212
|
import {
|
|
11987
12213
|
classifyVideoExtractionError,
|
|
11988
12214
|
createFrameLookupTable as createFrameLookupTable3,
|
|
@@ -12352,7 +12578,7 @@ async function runExtractVideosStage(input) {
|
|
|
12352
12578
|
// because short boundary counts can differ by one frame.
|
|
12353
12579
|
{
|
|
12354
12580
|
fps: job.config.fps,
|
|
12355
|
-
outputDir:
|
|
12581
|
+
outputDir: join26(compiledDir, "__hyperframes_video_frames"),
|
|
12356
12582
|
format: job.config.videoFrameFormat ?? "auto",
|
|
12357
12583
|
toneMapHdrToSdr: rendersSdrOnly(job.config, composition),
|
|
12358
12584
|
timelineEnd: composition.duration,
|
|
@@ -12360,7 +12586,7 @@ async function runExtractVideosStage(input) {
|
|
|
12360
12586
|
collectProbeFailures: extractionPolicy.failureMode === "enforce",
|
|
12361
12587
|
deferRangeExtraction,
|
|
12362
12588
|
shownBoxes,
|
|
12363
|
-
contentKeyedDirs: [
|
|
12589
|
+
contentKeyedDirs: [join26(compiledDir, REMOTE_MEDIA_SUBDIR)],
|
|
12364
12590
|
urlByAbsentLocalPath,
|
|
12365
12591
|
assetRoots,
|
|
12366
12592
|
onProgress: ({ planned = 0, done = 0 }) => {
|
|
@@ -12452,7 +12678,7 @@ async function remoteProbeSource(video, input) {
|
|
|
12452
12678
|
if (!isPublicHttpsUrl(video.src)) return null;
|
|
12453
12679
|
if (!resolveRestrictPageNetwork()) return video.src;
|
|
12454
12680
|
if (!video.hasAudio || video.hidden) return null;
|
|
12455
|
-
const downloadDir = input.downloadDir ??
|
|
12681
|
+
const downloadDir = input.downloadDir ?? join26(input.compiledDir, REMOTE_MEDIA_SUBDIR);
|
|
12456
12682
|
try {
|
|
12457
12683
|
return await downloadToTemp2(video.src, downloadDir, void 0, input.signal, void 0, {
|
|
12458
12684
|
onTelemetry: writeUrlDownloadTelemetry2
|
|
@@ -12577,7 +12803,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
12577
12803
|
|
|
12578
12804
|
// src/services/render/stages/audioStage.ts
|
|
12579
12805
|
import { existsSync as existsSync17 } from "node:fs";
|
|
12580
|
-
import { join as
|
|
12806
|
+
import { join as join29 } from "node:path";
|
|
12581
12807
|
import {
|
|
12582
12808
|
MIXED_AUDIO_FILENAME,
|
|
12583
12809
|
audioFailureDiagnostics,
|
|
@@ -12589,7 +12815,7 @@ import {
|
|
|
12589
12815
|
|
|
12590
12816
|
// src/services/render/audioDeliveryLimit.ts
|
|
12591
12817
|
import { existsSync as existsSync16 } from "node:fs";
|
|
12592
|
-
import { dirname as dirname13, join as
|
|
12818
|
+
import { dirname as dirname13, join as join28 } from "node:path";
|
|
12593
12819
|
import {
|
|
12594
12820
|
applyAudioFxChain,
|
|
12595
12821
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -12600,7 +12826,7 @@ import {
|
|
|
12600
12826
|
// src/services/render/audioPadTrim.ts
|
|
12601
12827
|
import { ffmpegCwd as ffmpegCwd2, localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
12602
12828
|
import { spawn } from "node:child_process";
|
|
12603
|
-
import { dirname as dirname12, join as
|
|
12829
|
+
import { dirname as dirname12, join as join27 } from "node:path";
|
|
12604
12830
|
import {
|
|
12605
12831
|
DEFAULT_CONFIG,
|
|
12606
12832
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -12881,7 +13107,7 @@ async function constrainAacTruePeak(input) {
|
|
|
12881
13107
|
}
|
|
12882
13108
|
async function cutSource(input, scratchDir, attenuationDb) {
|
|
12883
13109
|
if (!input.sourcePath || !input.rewriteSource) return true;
|
|
12884
|
-
const cutPath =
|
|
13110
|
+
const cutPath = join27(scratchDir, "source.wav");
|
|
12885
13111
|
try {
|
|
12886
13112
|
const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
|
|
12887
13113
|
if (!result.success) throw new Error(result.error);
|
|
@@ -12896,7 +13122,7 @@ async function enforceAacTruePeak(input) {
|
|
|
12896
13122
|
let scratchDir;
|
|
12897
13123
|
try {
|
|
12898
13124
|
scratchDir = createStagingDir3(dirname12(input.audioPath), ".true-peak-");
|
|
12899
|
-
const correctedPath =
|
|
13125
|
+
const correctedPath = join27(scratchDir, "audio.m4a");
|
|
12900
13126
|
const measurements = [];
|
|
12901
13127
|
let attenuationDb = 0;
|
|
12902
13128
|
let sourcePeakDbfs;
|
|
@@ -13120,7 +13346,7 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
13120
13346
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
13121
13347
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
13122
13348
|
const alternating = ["a", "b"].map(
|
|
13123
|
-
(k) =>
|
|
13349
|
+
(k) => join28(dirname13(sourcePath), `audio-source-limited-${k}.wav`)
|
|
13124
13350
|
);
|
|
13125
13351
|
let encodedFrom;
|
|
13126
13352
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -13193,7 +13419,7 @@ function runAudioStage(input) {
|
|
|
13193
13419
|
}
|
|
13194
13420
|
async function runAudioStageScoped(input) {
|
|
13195
13421
|
const stageStart = Date.now();
|
|
13196
|
-
const pcmSourcePath =
|
|
13422
|
+
const pcmSourcePath = join29(input.workDir, "audio-source.wav");
|
|
13197
13423
|
const seconds = (frames) => frames * input.fps.den / input.fps.num;
|
|
13198
13424
|
const duration = seconds(input.totalFrames);
|
|
13199
13425
|
const window2 = input.frameWindow && {
|
|
@@ -13263,7 +13489,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
|
13263
13489
|
assertNotAborted,
|
|
13264
13490
|
log
|
|
13265
13491
|
} = input;
|
|
13266
|
-
const audioOutputPath =
|
|
13492
|
+
const audioOutputPath = join29(workDir, MIXED_AUDIO_FILENAME);
|
|
13267
13493
|
let hasAudio = false;
|
|
13268
13494
|
let audioError;
|
|
13269
13495
|
let audioFailures;
|
|
@@ -13345,7 +13571,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
|
13345
13571
|
|
|
13346
13572
|
// src/services/render/stages/captureStage.ts
|
|
13347
13573
|
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
13348
|
-
import { join as
|
|
13574
|
+
import { join as join30 } from "node:path";
|
|
13349
13575
|
import {
|
|
13350
13576
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
13351
13577
|
frameFileExtension,
|
|
@@ -13419,13 +13645,13 @@ function measureCaptureFrameBytes(workDir, framesDir) {
|
|
|
13419
13645
|
if (!existsSync18(workDir)) return total;
|
|
13420
13646
|
for (const attempt of readdirSync4(workDir)) {
|
|
13421
13647
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
13422
|
-
total += sampleDirectoryBytes(
|
|
13648
|
+
total += sampleDirectoryBytes(join30(workDir, attempt));
|
|
13423
13649
|
continue;
|
|
13424
13650
|
}
|
|
13425
13651
|
if (!/^capture-attempt-\d+$/.test(attempt)) continue;
|
|
13426
|
-
const attemptDir =
|
|
13652
|
+
const attemptDir = join30(workDir, attempt);
|
|
13427
13653
|
for (const name of readdirSync4(attemptDir)) {
|
|
13428
|
-
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(
|
|
13654
|
+
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join30(attemptDir, name));
|
|
13429
13655
|
}
|
|
13430
13656
|
}
|
|
13431
13657
|
return total;
|
|
@@ -13741,8 +13967,8 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13741
13967
|
}
|
|
13742
13968
|
|
|
13743
13969
|
// src/services/render/stages/captureHdrStage.ts
|
|
13744
|
-
import { existsSync as existsSync20, mkdirSync as
|
|
13745
|
-
import { join as
|
|
13970
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync12 } from "node:fs";
|
|
13971
|
+
import { join as join34 } from "node:path";
|
|
13746
13972
|
import {
|
|
13747
13973
|
closeCaptureSession as closeCaptureSession7,
|
|
13748
13974
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
@@ -13814,7 +14040,7 @@ function createHdrImageTransferCache(options = {}) {
|
|
|
13814
14040
|
}
|
|
13815
14041
|
|
|
13816
14042
|
// src/services/render/stages/captureHdrSequentialLoop.ts
|
|
13817
|
-
import { join as
|
|
14043
|
+
import { join as join31 } from "node:path";
|
|
13818
14044
|
import {
|
|
13819
14045
|
TRANSITIONS as TRANSITIONS2,
|
|
13820
14046
|
crossfade
|
|
@@ -13948,7 +14174,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13948
14174
|
);
|
|
13949
14175
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
13950
14176
|
writeFileExclusiveSync(
|
|
13951
|
-
|
|
14177
|
+
join31(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
13952
14178
|
normalCanvas
|
|
13953
14179
|
);
|
|
13954
14180
|
}
|
|
@@ -13980,7 +14206,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13980
14206
|
}
|
|
13981
14207
|
|
|
13982
14208
|
// src/services/render/stages/captureHdrHybridLoop.ts
|
|
13983
|
-
import { join as
|
|
14209
|
+
import { join as join33 } from "node:path";
|
|
13984
14210
|
import {
|
|
13985
14211
|
TRANSITIONS as TRANSITIONS3,
|
|
13986
14212
|
closeCaptureSession as closeCaptureSession6,
|
|
@@ -13994,7 +14220,7 @@ import {
|
|
|
13994
14220
|
// src/services/shaderTransitionWorkerPool.ts
|
|
13995
14221
|
import { Worker as Worker2 } from "node:worker_threads";
|
|
13996
14222
|
import { fileURLToPath as fileURLToPath4, pathToFileURL } from "node:url";
|
|
13997
|
-
import { dirname as dirname14, join as
|
|
14223
|
+
import { dirname as dirname14, join as join32 } from "node:path";
|
|
13998
14224
|
import { createRequire } from "node:module";
|
|
13999
14225
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
14000
14226
|
import { existsSync as existsSync19 } from "node:fs";
|
|
@@ -14008,9 +14234,9 @@ function resolveWorkerEntry(explicit) {
|
|
|
14008
14234
|
return { path: override, isTs };
|
|
14009
14235
|
}
|
|
14010
14236
|
const moduleDir = dirname14(fileURLToPath4(import.meta.url));
|
|
14011
|
-
const jsPath =
|
|
14237
|
+
const jsPath = join32(moduleDir, "shaderTransitionWorker.js");
|
|
14012
14238
|
if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
|
|
14013
|
-
const tsPath =
|
|
14239
|
+
const tsPath = join32(moduleDir, "shaderTransitionWorker.ts");
|
|
14014
14240
|
return { path: tsPath, isTs: true };
|
|
14015
14241
|
}
|
|
14016
14242
|
function buildExecArgv(entryIsTs) {
|
|
@@ -14390,7 +14616,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14390
14616
|
);
|
|
14391
14617
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14392
14618
|
writeFileExclusiveSync(
|
|
14393
|
-
|
|
14619
|
+
join33(debugDumpDir, `frame_${String(i).padStart(4, "0")}_final_rgb48le.bin`),
|
|
14394
14620
|
canvas
|
|
14395
14621
|
);
|
|
14396
14622
|
}
|
|
@@ -14599,9 +14825,9 @@ async function runCaptureHdrStage(input) {
|
|
|
14599
14825
|
if (hdrVideoFrameSources.has(v.id)) hdrVideoEndTimes.set(v.id, v.end);
|
|
14600
14826
|
}
|
|
14601
14827
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
14602
|
-
const debugDumpDir = debugDumpEnabled ?
|
|
14828
|
+
const debugDumpDir = debugDumpEnabled ? join34(framesDir, "debug-composite") : null;
|
|
14603
14829
|
if (debugDumpDir && !existsSync20(debugDumpDir)) {
|
|
14604
|
-
|
|
14830
|
+
mkdirSync12(debugDumpDir, { recursive: true });
|
|
14605
14831
|
}
|
|
14606
14832
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
14607
14833
|
const hdrTargetTransfer = compositeTransfer === "srgb" ? void 0 : compositeTransfer;
|
|
@@ -14764,15 +14990,15 @@ async function runCaptureHdrStage(input) {
|
|
|
14764
14990
|
import {
|
|
14765
14991
|
copyFileSync as copyFileSync4,
|
|
14766
14992
|
existsSync as existsSync21,
|
|
14767
|
-
mkdirSync as
|
|
14993
|
+
mkdirSync as mkdirSync13,
|
|
14768
14994
|
readdirSync as readdirSync5,
|
|
14769
14995
|
readFileSync as readFileSync10,
|
|
14770
14996
|
rmSync as rmSync12,
|
|
14771
14997
|
statSync as statSync9,
|
|
14772
|
-
writeFileSync as
|
|
14998
|
+
writeFileSync as writeFileSync7
|
|
14773
14999
|
} from "node:fs";
|
|
14774
15000
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
14775
|
-
import { dirname as dirname15, join as
|
|
15001
|
+
import { dirname as dirname15, join as join35 } from "node:path";
|
|
14776
15002
|
import {
|
|
14777
15003
|
encodeFramesChunkedConcat,
|
|
14778
15004
|
encodeFramesFromDir,
|
|
@@ -14865,7 +15091,7 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
|
|
|
14865
15091
|
const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
|
|
14866
15092
|
return gifEncodeFailure(startTime, outputPath, error);
|
|
14867
15093
|
}
|
|
14868
|
-
|
|
15094
|
+
writeFileSync7(outputPath, gif);
|
|
14869
15095
|
return null;
|
|
14870
15096
|
}
|
|
14871
15097
|
async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
@@ -14991,7 +15217,7 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
14991
15217
|
await new Promise((resolve15) => wake = resolve15);
|
|
14992
15218
|
}
|
|
14993
15219
|
if (signal.aborted) return;
|
|
14994
|
-
const mergedPath =
|
|
15220
|
+
const mergedPath = join35(input.framesDir, formatCaptureFrameName(next, "jpg"));
|
|
14995
15221
|
const frame = await readLandedFrame(landed.get(next), mergedPath);
|
|
14996
15222
|
landed.delete(next);
|
|
14997
15223
|
if (!await stream.writeFrame(frame)) {
|
|
@@ -15066,7 +15292,7 @@ async function runEncodeStage(input) {
|
|
|
15066
15292
|
const stage5Start = Date.now();
|
|
15067
15293
|
if (isPngSequence) {
|
|
15068
15294
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
15069
|
-
if (!existsSync21(outputPath))
|
|
15295
|
+
if (!existsSync21(outputPath)) mkdirSync13(outputPath, { recursive: true });
|
|
15070
15296
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
15071
15297
|
if (captured.length === 0) {
|
|
15072
15298
|
throw new Error(
|
|
@@ -15074,11 +15300,11 @@ async function runEncodeStage(input) {
|
|
|
15074
15300
|
);
|
|
15075
15301
|
}
|
|
15076
15302
|
captured.forEach((name, i) => {
|
|
15077
|
-
const dst =
|
|
15078
|
-
copyFileSync4(
|
|
15303
|
+
const dst = join35(outputPath, formatExportFrameName(i, "png"));
|
|
15304
|
+
copyFileSync4(join35(framesDir, name), dst);
|
|
15079
15305
|
});
|
|
15080
15306
|
if (hasAudio && audioOutputPath && existsSync21(audioOutputPath)) {
|
|
15081
|
-
copyFileSync4(audioOutputPath,
|
|
15307
|
+
copyFileSync4(audioOutputPath, join35(outputPath, MIXED_AUDIO_FILENAME2));
|
|
15082
15308
|
log.info(
|
|
15083
15309
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
15084
15310
|
);
|
|
@@ -15098,7 +15324,7 @@ async function runEncodeStage(input) {
|
|
|
15098
15324
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
15099
15325
|
fps: job.config.fps,
|
|
15100
15326
|
loop,
|
|
15101
|
-
palettePath:
|
|
15327
|
+
palettePath: join35(dirname15(videoOnlyPath), "gif-palette.png"),
|
|
15102
15328
|
preserveAlpha: needsAlpha,
|
|
15103
15329
|
signal: abortSignal,
|
|
15104
15330
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -15309,7 +15535,7 @@ function sampleDirectoryBytes(dir) {
|
|
|
15309
15535
|
continue;
|
|
15310
15536
|
}
|
|
15311
15537
|
for (const name of entries) {
|
|
15312
|
-
const full =
|
|
15538
|
+
const full = join36(current, name);
|
|
15313
15539
|
try {
|
|
15314
15540
|
const st = statSync10(full);
|
|
15315
15541
|
if (st.isDirectory()) {
|
|
@@ -15474,7 +15700,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
15474
15700
|
const ranges = [];
|
|
15475
15701
|
let rangeStart = null;
|
|
15476
15702
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
15477
|
-
const framePath =
|
|
15703
|
+
const framePath = join36(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
15478
15704
|
const missing = !existsSync22(framePath) || statSync10(framePath).size <= 8;
|
|
15479
15705
|
if (missing && rangeStart === null) {
|
|
15480
15706
|
rangeStart = frameIndex;
|
|
@@ -15491,7 +15717,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
15491
15717
|
function buildMissingFrameRetryBatches(ranges, maxWorkers, workDir, attempt, rangeStart = 0, stride = 1) {
|
|
15492
15718
|
const workersPerBatch = Math.max(1, Math.floor(maxWorkers));
|
|
15493
15719
|
const batches = [];
|
|
15494
|
-
const outputDirFor = (batchIndex, workerId) =>
|
|
15720
|
+
const outputDirFor = (batchIndex, workerId) => join36(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
|
|
15495
15721
|
if (stride > 1) {
|
|
15496
15722
|
const spans = /* @__PURE__ */ new Map();
|
|
15497
15723
|
for (const range of ranges) {
|
|
@@ -15551,8 +15777,8 @@ function getNextRetryWorkerCount(currentWorkers) {
|
|
|
15551
15777
|
return Math.max(1, Math.floor(currentWorkers / 2));
|
|
15552
15778
|
}
|
|
15553
15779
|
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir3()) {
|
|
15554
|
-
if (platform2 === "win32" || platform2 === "darwin") return
|
|
15555
|
-
return
|
|
15780
|
+
if (platform2 === "win32" || platform2 === "darwin") return join36(systemTempDir, "hf-render-");
|
|
15781
|
+
return join36(dirname16(outputPath), `work-${jobId}-`);
|
|
15556
15782
|
}
|
|
15557
15783
|
var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
|
|
15558
15784
|
function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
|
|
@@ -15607,7 +15833,7 @@ The composition is too large for the available memory. To reduce memory pressure
|
|
|
15607
15833
|
function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
15608
15834
|
let captured = 0;
|
|
15609
15835
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
15610
|
-
const framePath =
|
|
15836
|
+
const framePath = join36(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
15611
15837
|
if (existsSync22(framePath)) captured++;
|
|
15612
15838
|
}
|
|
15613
15839
|
return captured;
|
|
@@ -15633,7 +15859,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15633
15859
|
reason: attempt === 0 ? "initial" : pendingTransientRetry ? "transient-retry" : "retry"
|
|
15634
15860
|
});
|
|
15635
15861
|
pendingTransientRetry = false;
|
|
15636
|
-
const attemptWorkDir =
|
|
15862
|
+
const attemptWorkDir = join36(options.workDir, `capture-attempt-${attempt}`);
|
|
15637
15863
|
const batches = missingRanges ? buildMissingFrameRetryBatches(
|
|
15638
15864
|
missingRanges,
|
|
15639
15865
|
currentWorkers,
|
|
@@ -16281,7 +16507,7 @@ function deVerifyFallbackTelemetry(err) {
|
|
|
16281
16507
|
}
|
|
16282
16508
|
function resolveRenderDebugDir() {
|
|
16283
16509
|
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve10(process.env.PRODUCER_RENDERS_DIR, "..") : resolve10(dirname16(fileURLToPath5(import.meta.url)), "../..");
|
|
16284
|
-
return
|
|
16510
|
+
return join36(producerRoot, ".debug");
|
|
16285
16511
|
}
|
|
16286
16512
|
function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
16287
16513
|
return fromEmptyFolder(
|
|
@@ -16301,11 +16527,11 @@ async function renderJob(job, projectDir, outputPath, progressSink, abortSignal,
|
|
|
16301
16527
|
validateChromaSubsamplingConfig(job.config);
|
|
16302
16528
|
const debugDir = resolveRenderDebugDir();
|
|
16303
16529
|
const outputDir = dirname16(outputPath);
|
|
16304
|
-
if (!existsSync22(outputDir))
|
|
16305
|
-
const workDir = job.config.debug ?
|
|
16530
|
+
if (!existsSync22(outputDir)) mkdirSync14(outputDir, { recursive: true });
|
|
16531
|
+
const workDir = job.config.debug ? join36(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
16306
16532
|
const pipelineStart = Date.now();
|
|
16307
16533
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
16308
|
-
const logPath = job.config.debug ?
|
|
16534
|
+
const logPath = job.config.debug ? join36(workDir, "render.log") : null;
|
|
16309
16535
|
const execution = new RenderExecutionContext({
|
|
16310
16536
|
request: { renderJobId: job.id, projectDir, outputPath },
|
|
16311
16537
|
logger: logPath ? createRenderFileLogger(logPath, baseLog) : baseLog,
|
|
@@ -16382,7 +16608,7 @@ async function executeRenderPipeline(input) {
|
|
|
16382
16608
|
imageDecodeFailures: 0
|
|
16383
16609
|
};
|
|
16384
16610
|
let hdrPerf;
|
|
16385
|
-
const perfOutputPath =
|
|
16611
|
+
const perfOutputPath = join36(workDir, "perf-summary.json");
|
|
16386
16612
|
const cfg = { ...job.config.producerConfig ?? resolveConfig2() };
|
|
16387
16613
|
const observability = new RenderObservabilityRecorder({
|
|
16388
16614
|
pipelineStartMs: pipelineStart,
|
|
@@ -16461,7 +16687,7 @@ async function executeRenderPipeline(input) {
|
|
|
16461
16687
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
16462
16688
|
assertNotAborted();
|
|
16463
16689
|
assertConfiguredFfmpegBinariesExist();
|
|
16464
|
-
if (!existsSync22(workDir))
|
|
16690
|
+
if (!existsSync22(workDir)) mkdirSync14(workDir, { recursive: true });
|
|
16465
16691
|
if (job.config.debug) {
|
|
16466
16692
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
16467
16693
|
}
|
|
@@ -16490,7 +16716,7 @@ async function executeRenderPipeline(input) {
|
|
|
16490
16716
|
requestedWorkers: job.config.workers ?? "auto"
|
|
16491
16717
|
});
|
|
16492
16718
|
const entryFile = job.config.entryFile || "index.html";
|
|
16493
|
-
const htmlPath =
|
|
16719
|
+
const htmlPath = join36(projectDir, entryFile);
|
|
16494
16720
|
if (!existsSync22(htmlPath)) {
|
|
16495
16721
|
throw new Error(`Entry file not found: ${htmlPath}`);
|
|
16496
16722
|
}
|
|
@@ -16588,7 +16814,7 @@ async function executeRenderPipeline(input) {
|
|
|
16588
16814
|
const largerThanCanvas = await oversizedVideos(
|
|
16589
16815
|
composition.videos,
|
|
16590
16816
|
projectDir,
|
|
16591
|
-
|
|
16817
|
+
join36(workDir, "compiled"),
|
|
16592
16818
|
{ width: outputWidth, height: outputHeight }
|
|
16593
16819
|
);
|
|
16594
16820
|
const probeResult = await observeRenderStage(
|
|
@@ -16688,7 +16914,7 @@ async function executeRenderPipeline(input) {
|
|
|
16688
16914
|
canvas: { width, height },
|
|
16689
16915
|
page: probeSession.page,
|
|
16690
16916
|
projectDir,
|
|
16691
|
-
compiledDir:
|
|
16917
|
+
compiledDir: join36(workDir, "compiled")
|
|
16692
16918
|
});
|
|
16693
16919
|
if (videoLayerPlan.videoId === void 0) {
|
|
16694
16920
|
log.info(`[Render] Video layer passthrough off: ${videoLayerPlan.reason}`);
|
|
@@ -16706,7 +16932,7 @@ async function executeRenderPipeline(input) {
|
|
|
16706
16932
|
updateJobStatus(job, "preprocessing", "Extracting video frames", 10, onProgress, {
|
|
16707
16933
|
code: "extract_video"
|
|
16708
16934
|
});
|
|
16709
|
-
const compiledDir =
|
|
16935
|
+
const compiledDir = join36(workDir, "compiled");
|
|
16710
16936
|
const segmentsCapture = (layeredOrEffectRoute) => shouldSegmentCapture({
|
|
16711
16937
|
env: process.env,
|
|
16712
16938
|
durationSeconds: probeResult.duration,
|
|
@@ -16848,7 +17074,7 @@ async function executeRenderPipeline(input) {
|
|
|
16848
17074
|
try {
|
|
16849
17075
|
fileServer = await createFileServer({
|
|
16850
17076
|
projectDir,
|
|
16851
|
-
compiledDir:
|
|
17077
|
+
compiledDir: join36(workDir, "compiled"),
|
|
16852
17078
|
port: 0,
|
|
16853
17079
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
16854
17080
|
fps: job.config.fps,
|
|
@@ -16868,8 +17094,8 @@ async function executeRenderPipeline(input) {
|
|
|
16868
17094
|
if (!activeFileServer) {
|
|
16869
17095
|
throw new Error("File server failed to initialize before frame capture");
|
|
16870
17096
|
}
|
|
16871
|
-
const framesDir =
|
|
16872
|
-
if (!existsSync22(framesDir))
|
|
17097
|
+
const framesDir = join36(workDir, "captured-frames");
|
|
17098
|
+
if (!existsSync22(framesDir)) mkdirSync14(framesDir, { recursive: true });
|
|
16873
17099
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
16874
17100
|
code: "start_browsers"
|
|
16875
17101
|
});
|
|
@@ -17248,7 +17474,7 @@ async function executeRenderPipeline(input) {
|
|
|
17248
17474
|
softwareOutcome = await runCaptureCalibration({
|
|
17249
17475
|
...calibrationInput,
|
|
17250
17476
|
cfg: calibrationCaptureConfig({ ...cfg, browserGpuMode: "software" }),
|
|
17251
|
-
workDir:
|
|
17477
|
+
workDir: join36(workDir, "software-gpu"),
|
|
17252
17478
|
forceScreenshot: applyConcreteGpuScreenshotClamp(
|
|
17253
17479
|
captureForceScreenshot,
|
|
17254
17480
|
"software",
|
|
@@ -17535,7 +17761,7 @@ async function executeRenderPipeline(input) {
|
|
|
17535
17761
|
hls: ".mp4"
|
|
17536
17762
|
};
|
|
17537
17763
|
const videoExt = FORMAT_EXT[outputFormat] ?? ".mp4";
|
|
17538
|
-
const videoOnlyPath =
|
|
17764
|
+
const videoOnlyPath = join36(workDir, `video-only${videoExt}`);
|
|
17539
17765
|
let usePageSideCompositingForTransitions = (cfg.enablePageSideCompositing || isGif) && compiled.hasShaderTransitions && !hasHdrContent && outputSupportsPageSideShaderCompositing(outputFormat);
|
|
17540
17766
|
if (usePageSideCompositingForTransitions) {
|
|
17541
17767
|
activeFileServer.addPreHeadScript(HF_PAGE_SIDE_COMPOSITING_STUB);
|
|
@@ -18292,7 +18518,7 @@ async function executeRenderPipeline(input) {
|
|
|
18292
18518
|
"drawElement capture failed; retrying with a fresh screenshot session"
|
|
18293
18519
|
);
|
|
18294
18520
|
rmSync13(framesDir, { recursive: true, force: true });
|
|
18295
|
-
|
|
18521
|
+
mkdirSync14(framesDir, { recursive: true });
|
|
18296
18522
|
resetCaptureAttemptProgress(job);
|
|
18297
18523
|
dedupPerfs.length = 0;
|
|
18298
18524
|
cfg.useDrawElement = false;
|
|
@@ -18471,7 +18697,7 @@ async function executeRenderPipeline(input) {
|
|
|
18471
18697
|
job.perfSummary = perfSummary;
|
|
18472
18698
|
if (job.config.debug) {
|
|
18473
18699
|
try {
|
|
18474
|
-
|
|
18700
|
+
writeFileSync8(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
|
|
18475
18701
|
} catch (err) {
|
|
18476
18702
|
log.debug("Failed to write perf summary", {
|
|
18477
18703
|
perfOutputPath,
|
|
@@ -18481,7 +18707,7 @@ async function executeRenderPipeline(input) {
|
|
|
18481
18707
|
}
|
|
18482
18708
|
if (job.config.debug) {
|
|
18483
18709
|
if (!isPngSequence && !isHls && existsSync22(stagedOutputPath)) {
|
|
18484
|
-
const debugOutput =
|
|
18710
|
+
const debugOutput = join36(workDir, `output${videoExt}`);
|
|
18485
18711
|
copyFileSync5(stagedOutputPath, debugOutput);
|
|
18486
18712
|
}
|
|
18487
18713
|
}
|
|
@@ -18600,15 +18826,15 @@ import {
|
|
|
18600
18826
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD4,
|
|
18601
18827
|
referenceBackgroundResult as referenceBackgroundResult6
|
|
18602
18828
|
} from "@hyperframes/engine";
|
|
18603
|
-
import { mkdirSync as
|
|
18604
|
-
import { join as
|
|
18829
|
+
import { mkdirSync as mkdirSync22, mkdtempSync, readFileSync as readFileSync16, rmSync as rmSync19 } from "node:fs";
|
|
18830
|
+
import { join as join50 } from "node:path";
|
|
18605
18831
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
18606
18832
|
|
|
18607
18833
|
// src/services/distributed/mp4Stitch.ts
|
|
18608
|
-
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as
|
|
18834
|
+
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync15, rmSync as rmSync14 } from "node:fs";
|
|
18609
18835
|
import { open } from "node:fs/promises";
|
|
18610
18836
|
import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
|
|
18611
|
-
import { basename as basename8, dirname as dirname17, join as
|
|
18837
|
+
import { basename as basename8, dirname as dirname17, join as join37 } from "node:path";
|
|
18612
18838
|
import { finished, pipeline } from "node:stream/promises";
|
|
18613
18839
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
18614
18840
|
function boxAt(src, off, at, limit) {
|
|
@@ -18973,15 +19199,15 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
18973
19199
|
const sourcePaths = audioPath ? [audioPath, ...chunkPaths] : chunkPaths;
|
|
18974
19200
|
const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
|
|
18975
19201
|
const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
|
|
18976
|
-
|
|
19202
|
+
mkdirSync15(dirname17(outputPath), { recursive: true });
|
|
18977
19203
|
const workDir = createStagingDir4(dirname17(outputPath), `${basename8(outputPath)}.stitch-`);
|
|
18978
|
-
const out = createWriteStream(
|
|
19204
|
+
const out = createWriteStream(join37(workDir, "out.mp4"));
|
|
18979
19205
|
try {
|
|
18980
19206
|
out.write(header);
|
|
18981
19207
|
for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
|
|
18982
19208
|
out.end();
|
|
18983
19209
|
await finished(out);
|
|
18984
|
-
renameWithRetry6(
|
|
19210
|
+
renameWithRetry6(join37(workDir, "out.mp4"), outputPath);
|
|
18985
19211
|
} finally {
|
|
18986
19212
|
out.destroy();
|
|
18987
19213
|
rmSync14(workDir, { recursive: true, force: true });
|
|
@@ -19000,11 +19226,11 @@ import {
|
|
|
19000
19226
|
cpSync as cpSync2,
|
|
19001
19227
|
existsSync as existsSync27,
|
|
19002
19228
|
linkSync,
|
|
19003
|
-
mkdirSync as
|
|
19229
|
+
mkdirSync as mkdirSync18,
|
|
19004
19230
|
rmSync as rmSync15,
|
|
19005
|
-
writeFileSync as
|
|
19231
|
+
writeFileSync as writeFileSync11
|
|
19006
19232
|
} from "node:fs";
|
|
19007
|
-
import { extname as extname6, isAbsolute as isAbsolute5, join as
|
|
19233
|
+
import { extname as extname6, isAbsolute as isAbsolute5, join as join45, relative as relative8, sep as sep5 } from "node:path";
|
|
19008
19234
|
import {
|
|
19009
19235
|
fpsToNumber as fpsToNumber9,
|
|
19010
19236
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
@@ -19021,7 +19247,7 @@ import {
|
|
|
19021
19247
|
} from "@hyperframes/engine";
|
|
19022
19248
|
|
|
19023
19249
|
// src/services/distributed/planFrameCost.ts
|
|
19024
|
-
import { join as
|
|
19250
|
+
import { join as join40 } from "node:path";
|
|
19025
19251
|
import {
|
|
19026
19252
|
closeCaptureSession as closeCaptureSession9,
|
|
19027
19253
|
createCaptureSession as createCaptureSession9,
|
|
@@ -19031,7 +19257,7 @@ import {
|
|
|
19031
19257
|
|
|
19032
19258
|
// src/services/distributed/chunkFrames.ts
|
|
19033
19259
|
import { existsSync as existsSync24, readdirSync as readdirSync7 } from "node:fs";
|
|
19034
|
-
import { extname as extname4, join as
|
|
19260
|
+
import { extname as extname4, join as join39 } from "node:path";
|
|
19035
19261
|
import {
|
|
19036
19262
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
19037
19263
|
createVideoFrameInjector as createVideoFrameInjector3,
|
|
@@ -19040,7 +19266,7 @@ import {
|
|
|
19040
19266
|
|
|
19041
19267
|
// src/services/distributed/shared.ts
|
|
19042
19268
|
import { execFile as execFileCallback } from "node:child_process";
|
|
19043
|
-
import { dirname as dirname18, join as
|
|
19269
|
+
import { dirname as dirname18, join as join38 } from "node:path";
|
|
19044
19270
|
import { existsSync as existsSync23, readFileSync as readFileSync11 } from "node:fs";
|
|
19045
19271
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
19046
19272
|
import { promisify as promisify2 } from "node:util";
|
|
@@ -19056,7 +19282,7 @@ function isPlanAudioArtifactPath(path) {
|
|
|
19056
19282
|
}
|
|
19057
19283
|
function resolvePlanAudioPath(planDir) {
|
|
19058
19284
|
for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
|
|
19059
|
-
const candidate =
|
|
19285
|
+
const candidate = join38(planDir, name);
|
|
19060
19286
|
if (existsSync23(candidate)) return candidate;
|
|
19061
19287
|
}
|
|
19062
19288
|
return null;
|
|
@@ -19321,7 +19547,7 @@ function readProducerVersion() {
|
|
|
19321
19547
|
const startDir = dirname18(fileURLToPath6(import.meta.url));
|
|
19322
19548
|
let current = startDir;
|
|
19323
19549
|
for (let i = 0; i < 10; i++) {
|
|
19324
|
-
const candidate =
|
|
19550
|
+
const candidate = join38(current, "package.json");
|
|
19325
19551
|
if (existsSync23(candidate)) {
|
|
19326
19552
|
try {
|
|
19327
19553
|
const pkg = JSON.parse(readFileSync11(candidate, "utf-8"));
|
|
@@ -19376,7 +19602,7 @@ function frameNumberFromFileName(name) {
|
|
|
19376
19602
|
function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
|
|
19377
19603
|
const result = [];
|
|
19378
19604
|
for (const v of videos) {
|
|
19379
|
-
const outputDir =
|
|
19605
|
+
const outputDir = join39(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
|
|
19380
19606
|
if (!existsSync24(outputDir)) {
|
|
19381
19607
|
throw new Error(
|
|
19382
19608
|
`[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
|
|
@@ -19395,7 +19621,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
|
|
|
19395
19621
|
if (!frameName) continue;
|
|
19396
19622
|
const frameNumber = indexMode === "sparse-v2" ? frameNumberFromFileName(frameName) : null;
|
|
19397
19623
|
const frameIndex = frameNumber === null ? i : frameNumber - 1;
|
|
19398
|
-
framePaths.set(frameIndex,
|
|
19624
|
+
framePaths.set(frameIndex, join39(outputDir, frameName));
|
|
19399
19625
|
}
|
|
19400
19626
|
result.push({
|
|
19401
19627
|
videoId: v.videoId,
|
|
@@ -19476,7 +19702,7 @@ async function extractDeferredVideoFramesForChunk(input) {
|
|
|
19476
19702
|
sourceOf: (video) => {
|
|
19477
19703
|
const range = planned.get(video.videoId).deferredRange;
|
|
19478
19704
|
const remoteUrl = remoteSources[range.sourcePath];
|
|
19479
|
-
const sourcePath = remoteUrl ??
|
|
19705
|
+
const sourcePath = remoteUrl ?? join39(input.planDir, ...range.sourcePath.split("/"));
|
|
19480
19706
|
if (remoteUrl === void 0 && !existsSync24(sourcePath)) {
|
|
19481
19707
|
throw new RenderChunkValidationError(
|
|
19482
19708
|
MISSING_PLAN_ARTIFACT,
|
|
@@ -19507,12 +19733,12 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
19507
19733
|
planVideos,
|
|
19508
19734
|
frames: sampled,
|
|
19509
19735
|
fps: fpsRatio,
|
|
19510
|
-
outputRoot:
|
|
19736
|
+
outputRoot: join40(workDir, "frame-cost-video-frames"),
|
|
19511
19737
|
cfg: input.cfg
|
|
19512
19738
|
})
|
|
19513
19739
|
];
|
|
19514
19740
|
const lookup = extracted.length > 0 ? createFrameLookupTable4(planVideos.videos, extracted, resolveRenderFpsConfig(fpsRatio).value) : null;
|
|
19515
|
-
const compiledDir =
|
|
19741
|
+
const compiledDir = join40(planDir, "compiled");
|
|
19516
19742
|
const fileServer = await createFileServer({
|
|
19517
19743
|
projectDir: compiledDir,
|
|
19518
19744
|
compiledDir,
|
|
@@ -19524,7 +19750,7 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
19524
19750
|
try {
|
|
19525
19751
|
session = await createCaptureSession9(
|
|
19526
19752
|
fileServer.url,
|
|
19527
|
-
|
|
19753
|
+
join40(workDir, "frame-cost"),
|
|
19528
19754
|
buildChunkCaptureOptions({
|
|
19529
19755
|
dimensions: { ...input, fpsNum: fps, fpsDen: 1 },
|
|
19530
19756
|
encoder: input,
|
|
@@ -19621,7 +19847,7 @@ function buildWeightedChunkSlices(weights, chunkCount, minFrames, maxFrames) {
|
|
|
19621
19847
|
}
|
|
19622
19848
|
|
|
19623
19849
|
// src/services/render/planReferenceBackground.ts
|
|
19624
|
-
import { join as
|
|
19850
|
+
import { join as join41 } from "node:path";
|
|
19625
19851
|
import {
|
|
19626
19852
|
closeCaptureSession as closeCaptureSession10,
|
|
19627
19853
|
createCaptureSession as createCaptureSession10,
|
|
@@ -19634,14 +19860,14 @@ async function readPlanReferenceBackground(input) {
|
|
|
19634
19860
|
try {
|
|
19635
19861
|
server = await createFileServer({
|
|
19636
19862
|
projectDir: input.projectDir,
|
|
19637
|
-
compiledDir:
|
|
19863
|
+
compiledDir: join41(input.workDir, "compiled"),
|
|
19638
19864
|
port: 0,
|
|
19639
19865
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
19640
19866
|
fps: input.options.fps
|
|
19641
19867
|
});
|
|
19642
19868
|
session = await createCaptureSession10(
|
|
19643
19869
|
server.url,
|
|
19644
|
-
|
|
19870
|
+
join41(input.workDir, "reference"),
|
|
19645
19871
|
{
|
|
19646
19872
|
...input.options,
|
|
19647
19873
|
requiresWebGpu: false
|
|
@@ -19677,8 +19903,8 @@ async function readPlanReferenceBackground(input) {
|
|
|
19677
19903
|
}
|
|
19678
19904
|
|
|
19679
19905
|
// src/services/render/stages/freezePlan.ts
|
|
19680
|
-
import { existsSync as existsSync25, mkdirSync as
|
|
19681
|
-
import { join as
|
|
19906
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync16, readFileSync as readFileSync12, readdirSync as readdirSync8, writeFileSync as writeFileSync9 } from "node:fs";
|
|
19907
|
+
import { join as join42, relative as relative6, resolve as resolve11 } from "node:path";
|
|
19682
19908
|
import {
|
|
19683
19909
|
REFERENCE_BACKGROUND_FIELD,
|
|
19684
19910
|
referenceBackgroundResult as referenceBackgroundResult3
|
|
@@ -19776,12 +20002,12 @@ function readPlanProtocolV1(planJson, capabilities = DISTRIBUTED_RENDER_CAPABILI
|
|
|
19776
20002
|
}
|
|
19777
20003
|
|
|
19778
20004
|
// src/services/render/stages/planHash.ts
|
|
19779
|
-
import { createHash as
|
|
20005
|
+
import { createHash as createHash9 } from "node:crypto";
|
|
19780
20006
|
import { closeSync as closeSync6, createReadStream as createReadStream5, openSync as openSync6, readSync as readSync5 } from "node:fs";
|
|
19781
20007
|
var PLAN_HASH_SCHEMA_PREFIX = "hyperframes-plan-hash-v1\0";
|
|
19782
20008
|
var FIELD_DELIMITER = Buffer.from([0]);
|
|
19783
20009
|
function computePlanHash(input) {
|
|
19784
|
-
const hash =
|
|
20010
|
+
const hash = createHash9("sha256");
|
|
19785
20011
|
hash.update(PLAN_HASH_SCHEMA_PREFIX, "utf8");
|
|
19786
20012
|
hash.update(input.compositionHtml);
|
|
19787
20013
|
hash.update(FIELD_DELIMITER);
|
|
@@ -19828,12 +20054,12 @@ function canonicalJsonStringify(value) {
|
|
|
19828
20054
|
throw new TypeError(`canonicalJsonStringify: unsupported value type ${typeof value}`);
|
|
19829
20055
|
}
|
|
19830
20056
|
function sha256Hex(bytes) {
|
|
19831
|
-
const h =
|
|
20057
|
+
const h = createHash9("sha256");
|
|
19832
20058
|
h.update(bytes);
|
|
19833
20059
|
return h.digest("hex");
|
|
19834
20060
|
}
|
|
19835
20061
|
function sha256File(path) {
|
|
19836
|
-
const hash =
|
|
20062
|
+
const hash = createHash9("sha256");
|
|
19837
20063
|
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
19838
20064
|
const fd = openSync6(path, "r");
|
|
19839
20065
|
try {
|
|
@@ -19848,7 +20074,7 @@ function sha256File(path) {
|
|
|
19848
20074
|
return hash.digest("hex");
|
|
19849
20075
|
}
|
|
19850
20076
|
async function sha256FileAsync(path) {
|
|
19851
|
-
const hash =
|
|
20077
|
+
const hash = createHash9("sha256");
|
|
19852
20078
|
for await (const chunk of createReadStream5(path, { highWaterMark: 1024 * 1024 })) {
|
|
19853
20079
|
hash.update(chunk);
|
|
19854
20080
|
}
|
|
@@ -19896,7 +20122,7 @@ function listPlanFiles(planDir) {
|
|
|
19896
20122
|
function walk(dir) {
|
|
19897
20123
|
const entries = readdirSync8(dir, { withFileTypes: true });
|
|
19898
20124
|
for (const entry of entries) {
|
|
19899
|
-
const full =
|
|
20125
|
+
const full = join42(dir, entry.name);
|
|
19900
20126
|
if (entry.isDirectory()) {
|
|
19901
20127
|
walk(full);
|
|
19902
20128
|
} else if (entry.isFile()) {
|
|
@@ -19937,15 +20163,15 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
|
|
|
19937
20163
|
function writePlanRemoteFiles(planDir, files) {
|
|
19938
20164
|
if (files.length === 0) return;
|
|
19939
20165
|
const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
|
|
19940
|
-
|
|
20166
|
+
writeFileSync9(join42(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
|
|
19941
20167
|
}
|
|
19942
20168
|
function readPlanRemoteFiles(planDir) {
|
|
19943
|
-
const path =
|
|
20169
|
+
const path = join42(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
|
|
19944
20170
|
return existsSync25(path) ? JSON.parse(readFileSync12(path, "utf-8")) : [];
|
|
19945
20171
|
}
|
|
19946
20172
|
function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
19947
|
-
const planJsonPath =
|
|
19948
|
-
const encoderJsonPath =
|
|
20173
|
+
const planJsonPath = join42(planDir, "plan.json");
|
|
20174
|
+
const encoderJsonPath = join42(planDir, "meta", "encoder.json");
|
|
19949
20175
|
if (!existsSync25(planJsonPath)) {
|
|
19950
20176
|
throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
|
|
19951
20177
|
}
|
|
@@ -19982,18 +20208,18 @@ async function freezePlan(input) {
|
|
|
19982
20208
|
if (!existsSync25(planDir)) {
|
|
19983
20209
|
throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
|
|
19984
20210
|
}
|
|
19985
|
-
const metaDir =
|
|
19986
|
-
if (!existsSync25(metaDir))
|
|
19987
|
-
|
|
19988
|
-
|
|
20211
|
+
const metaDir = join42(planDir, "meta");
|
|
20212
|
+
if (!existsSync25(metaDir)) mkdirSync16(metaDir, { recursive: true });
|
|
20213
|
+
writeFileSync9(
|
|
20214
|
+
join42(metaDir, "composition.json"),
|
|
19989
20215
|
`${JSON.stringify(composition, null, 2)}
|
|
19990
20216
|
`,
|
|
19991
20217
|
"utf-8"
|
|
19992
20218
|
);
|
|
19993
20219
|
const encoderForCanonical = stripUndefined(encoder);
|
|
19994
20220
|
const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
|
|
19995
|
-
|
|
19996
|
-
|
|
20221
|
+
writeFileSync9(join42(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
|
|
20222
|
+
writeFileSync9(join42(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
|
|
19997
20223
|
`, "utf-8");
|
|
19998
20224
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
19999
20225
|
const planHash = computePlanHash({
|
|
@@ -20018,8 +20244,8 @@ async function freezePlan(input) {
|
|
|
20018
20244
|
duration: durationSeconds,
|
|
20019
20245
|
hasAudio
|
|
20020
20246
|
};
|
|
20021
|
-
const planJsonPath =
|
|
20022
|
-
|
|
20247
|
+
const planJsonPath = join42(planDir, "plan.json");
|
|
20248
|
+
writeFileSync9(planJsonPath, `${JSON.stringify(planJson, null, 2)}
|
|
20023
20249
|
`, "utf-8");
|
|
20024
20250
|
return { planJsonPath, planHash };
|
|
20025
20251
|
}
|
|
@@ -20060,9 +20286,9 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
|
|
|
20060
20286
|
}
|
|
20061
20287
|
|
|
20062
20288
|
// src/services/distributed/chunkAudio.ts
|
|
20063
|
-
import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as
|
|
20064
|
-
import { writeFileSync as
|
|
20065
|
-
import { join as
|
|
20289
|
+
import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync17, openSync as openSync7, readFileSync as readFileSync13 } from "node:fs";
|
|
20290
|
+
import { writeFileSync as writeFileSync10, writeSync } from "node:fs";
|
|
20291
|
+
import { join as join43 } from "node:path";
|
|
20066
20292
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
20067
20293
|
function audioCutForChunk(grid, chunks, index, fps) {
|
|
20068
20294
|
const firstPacketAt = (frame) => Math.min(
|
|
@@ -20150,7 +20376,7 @@ async function writeChunkAudioSlices(input) {
|
|
|
20150
20376
|
});
|
|
20151
20377
|
const bytes = readFileSync13(input.audioPath);
|
|
20152
20378
|
const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
|
|
20153
|
-
|
|
20379
|
+
mkdirSync17(join43(input.planDir, SLICE_DIR), { recursive: true });
|
|
20154
20380
|
input.chunks.forEach((_, index) => {
|
|
20155
20381
|
const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
|
|
20156
20382
|
if (!cut) return;
|
|
@@ -20158,17 +20384,17 @@ async function writeChunkAudioSlices(input) {
|
|
|
20158
20384
|
const start = offsets[cut.firstPacket];
|
|
20159
20385
|
layout.partStarts[index] = start;
|
|
20160
20386
|
const end = offsets[last] + track.sizes[last];
|
|
20161
|
-
|
|
20387
|
+
writeFileSync10(join43(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
|
|
20162
20388
|
});
|
|
20163
20389
|
const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
|
|
20164
|
-
|
|
20165
|
-
|
|
20390
|
+
writeFileSync10(join43(input.planDir, SLICE_FRAME), Buffer.concat(frame));
|
|
20391
|
+
writeFileSync10(join43(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
|
|
20166
20392
|
}
|
|
20167
20393
|
function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
20168
|
-
const layoutPath =
|
|
20394
|
+
const layoutPath = join43(planDir, SLICE_LAYOUT);
|
|
20169
20395
|
if (!existsSync26(layoutPath)) return resolvePlanAudioPath(planDir);
|
|
20170
20396
|
const layout = JSON.parse(readFileSync13(layoutPath, "utf-8"));
|
|
20171
|
-
const frame = readFileSync13(
|
|
20397
|
+
const frame = readFileSync13(join43(planDir, SLICE_FRAME));
|
|
20172
20398
|
const fd = openSync7(scratchPath, "w");
|
|
20173
20399
|
try {
|
|
20174
20400
|
writeSync(fd, frame, 0, layout.payloadStart, 0);
|
|
@@ -20181,7 +20407,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
|
20181
20407
|
);
|
|
20182
20408
|
const start = layout.partStarts[chunkIndex];
|
|
20183
20409
|
if (start !== void 0) {
|
|
20184
|
-
const part = readFileSync13(
|
|
20410
|
+
const part = readFileSync13(join43(planDir, chunkAudioSlicePath(chunkIndex)));
|
|
20185
20411
|
writeSync(fd, part, 0, part.length, start);
|
|
20186
20412
|
}
|
|
20187
20413
|
ftruncateSync(fd, layout.sizeBytes);
|
|
@@ -20235,9 +20461,9 @@ async function muxChunkWithAudio(input) {
|
|
|
20235
20461
|
}
|
|
20236
20462
|
|
|
20237
20463
|
// src/services/distributed/planSize.ts
|
|
20238
|
-
import { createHash as
|
|
20464
|
+
import { createHash as createHash10 } from "node:crypto";
|
|
20239
20465
|
import { lstatSync as lstatSync4, readdirSync as readdirSync9 } from "node:fs";
|
|
20240
|
-
import { extname as extname5, join as
|
|
20466
|
+
import { extname as extname5, join as join44, relative as relative7 } from "node:path";
|
|
20241
20467
|
var MAX_TOP_COMPONENTS = 10;
|
|
20242
20468
|
var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
20243
20469
|
".aac",
|
|
@@ -20265,7 +20491,7 @@ var PLAN_ROOT_CATEGORY = {
|
|
|
20265
20491
|
"plan.json": "metadata"
|
|
20266
20492
|
};
|
|
20267
20493
|
function hashComponent(value) {
|
|
20268
|
-
return
|
|
20494
|
+
return createHash10("sha256").update(value).digest("hex").slice(0, 12);
|
|
20269
20495
|
}
|
|
20270
20496
|
function classifyFile(segments, rootKind) {
|
|
20271
20497
|
const rootName = segments[0] ?? "";
|
|
@@ -20349,7 +20575,7 @@ function walkRegularFiles(dir, visit) {
|
|
|
20349
20575
|
return;
|
|
20350
20576
|
}
|
|
20351
20577
|
for (const entry of entries) {
|
|
20352
|
-
const full =
|
|
20578
|
+
const full = join44(dir, entry.name);
|
|
20353
20579
|
if (entry.isDirectory()) {
|
|
20354
20580
|
walkRegularFiles(full, visit);
|
|
20355
20581
|
} else if (entry.isFile()) {
|
|
@@ -20565,13 +20791,13 @@ function assertPositiveInteger2(name, value) {
|
|
|
20565
20791
|
}
|
|
20566
20792
|
var FREEZE_OWNED_PLAN_FILES = [
|
|
20567
20793
|
"plan.json",
|
|
20568
|
-
|
|
20569
|
-
|
|
20570
|
-
|
|
20794
|
+
join45("meta", "composition.json"),
|
|
20795
|
+
join45("meta", "encoder.json"),
|
|
20796
|
+
join45("meta", "chunks.json")
|
|
20571
20797
|
];
|
|
20572
20798
|
function removeFreezeOwnedPlanFiles(planDir) {
|
|
20573
20799
|
for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
|
|
20574
|
-
rmSync15(
|
|
20800
|
+
rmSync15(join45(planDir, relativePath), { force: true });
|
|
20575
20801
|
}
|
|
20576
20802
|
}
|
|
20577
20803
|
function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
|
|
@@ -20729,19 +20955,19 @@ function createVideoSourceShipper(input) {
|
|
|
20729
20955
|
const known = shipped.get(srcPath);
|
|
20730
20956
|
if (known) return known;
|
|
20731
20957
|
const stagedRel = pathInside(input.workVideoFramesDir, srcPath);
|
|
20732
|
-
const current = stagedRel === null ? srcPath :
|
|
20958
|
+
const current = stagedRel === null ? srcPath : join45(input.planDir, "video-frames", stagedRel);
|
|
20733
20959
|
let result = null;
|
|
20734
20960
|
for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
|
|
20735
20961
|
const rel = pathInside(root, srcPath);
|
|
20736
|
-
if (rel !== null && (existsSync27(
|
|
20962
|
+
if (rel !== null && (existsSync27(join45(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
|
|
20737
20963
|
result = ["compiled", ...rel.split(sep5)].join("/");
|
|
20738
20964
|
break;
|
|
20739
20965
|
}
|
|
20740
20966
|
}
|
|
20741
20967
|
if (result === null) {
|
|
20742
20968
|
result = `video-sources/${shipped.size}${extname6(current)}`;
|
|
20743
|
-
const destination =
|
|
20744
|
-
|
|
20969
|
+
const destination = join45(input.planDir, ...result.split("/"));
|
|
20970
|
+
mkdirSync18(join45(input.planDir, "video-sources"), { recursive: true });
|
|
20745
20971
|
try {
|
|
20746
20972
|
linkSync(current, destination);
|
|
20747
20973
|
} catch {
|
|
@@ -20761,7 +20987,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20761
20987
|
useGpu: false,
|
|
20762
20988
|
browserGpuMode: "software"
|
|
20763
20989
|
});
|
|
20764
|
-
if (!existsSync27(planDir))
|
|
20990
|
+
if (!existsSync27(planDir)) mkdirSync18(planDir, { recursive: true });
|
|
20765
20991
|
const log = config.logger ?? defaultLogger;
|
|
20766
20992
|
const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
|
|
20767
20993
|
const abortSignal = config.abortSignal;
|
|
@@ -20795,15 +21021,15 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20795
21021
|
includeOutsideScripts: options.includeOutsideScripts === true
|
|
20796
21022
|
});
|
|
20797
21023
|
const entryFile = config.entryFile ?? "index.html";
|
|
20798
|
-
const htmlPath =
|
|
21024
|
+
const htmlPath = join45(projectDir, entryFile);
|
|
20799
21025
|
if (!existsSync27(htmlPath)) {
|
|
20800
21026
|
throw new Error(`[plan] entry file not found: ${htmlPath}`);
|
|
20801
21027
|
}
|
|
20802
|
-
const workDir =
|
|
21028
|
+
const workDir = join45(planDir, ".plan-work");
|
|
20803
21029
|
rmSync15(workDir, { recursive: true, force: true });
|
|
20804
|
-
|
|
20805
|
-
const compiledDir =
|
|
20806
|
-
|
|
21030
|
+
mkdirSync18(workDir, { recursive: true });
|
|
21031
|
+
const compiledDir = join45(workDir, "compiled");
|
|
21032
|
+
mkdirSync18(compiledDir, { recursive: true });
|
|
20807
21033
|
let stageStarted = Date.now();
|
|
20808
21034
|
cpSync2(projectDir, compiledDir, {
|
|
20809
21035
|
recursive: true,
|
|
@@ -20822,10 +21048,10 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20822
21048
|
}
|
|
20823
21049
|
});
|
|
20824
21050
|
logPlanStage(log, "copy", stageStarted);
|
|
20825
|
-
const finalCompiledDir =
|
|
21051
|
+
const finalCompiledDir = join45(planDir, "compiled");
|
|
20826
21052
|
const needsAlpha = outputNeedsAlpha(config.format);
|
|
20827
21053
|
const remoteFiles = Object.entries(options.remoteFiles ?? {});
|
|
20828
|
-
const remoteLocalPath = (rel) =>
|
|
21054
|
+
const remoteLocalPath = (rel) => join45(projectDir, ...rel.split("/"));
|
|
20829
21055
|
for (const [, file] of remoteFiles) {
|
|
20830
21056
|
declareContentAddressedUrl(file.url, file.sha256);
|
|
20831
21057
|
if (file.probeFactsUrl) declareProbeFactsUrl(file.url, file.probeFactsUrl);
|
|
@@ -21030,15 +21256,15 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
21030
21256
|
let stageStarted = Date.now();
|
|
21031
21257
|
const extractResult = await extractPlanVideos(c, options.deferVideoExtraction);
|
|
21032
21258
|
logPlanStage(log, "extract", stageStarted);
|
|
21033
|
-
const stagedVideoFrames =
|
|
21034
|
-
const videoFramesDst =
|
|
21259
|
+
const stagedVideoFrames = join45(compiledDir, "__hyperframes_video_frames");
|
|
21260
|
+
const videoFramesDst = join45(planDir, "video-frames");
|
|
21035
21261
|
if (existsSync27(videoFramesDst)) rmSync15(videoFramesDst, { recursive: true, force: true });
|
|
21036
|
-
const videoSourcesDir =
|
|
21262
|
+
const videoSourcesDir = join45(planDir, "video-sources");
|
|
21037
21263
|
rmSync15(videoSourcesDir, { recursive: true, force: true });
|
|
21038
21264
|
if (existsSync27(stagedVideoFrames)) {
|
|
21039
21265
|
renameWithRetry7(stagedVideoFrames, videoFramesDst);
|
|
21040
21266
|
} else {
|
|
21041
|
-
|
|
21267
|
+
mkdirSync18(videoFramesDst, { recursive: true });
|
|
21042
21268
|
}
|
|
21043
21269
|
if (existsSync27(finalCompiledDir)) rmSync15(finalCompiledDir, { recursive: true, force: true });
|
|
21044
21270
|
renameWithRetry7(compiledDir, finalCompiledDir);
|
|
@@ -21070,7 +21296,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
21070
21296
|
};
|
|
21071
21297
|
})
|
|
21072
21298
|
});
|
|
21073
|
-
|
|
21299
|
+
mkdirSync18(join45(planDir, "meta"), { recursive: true });
|
|
21074
21300
|
writePlanRemoteFiles(
|
|
21075
21301
|
planDir,
|
|
21076
21302
|
remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
|
|
@@ -21079,8 +21305,8 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
21079
21305
|
sizeBytes
|
|
21080
21306
|
}))
|
|
21081
21307
|
);
|
|
21082
|
-
|
|
21083
|
-
|
|
21308
|
+
writeFileSync11(
|
|
21309
|
+
join45(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
|
|
21084
21310
|
JSON.stringify(planVideosJson, null, 2),
|
|
21085
21311
|
"utf-8"
|
|
21086
21312
|
);
|
|
@@ -21160,7 +21386,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
21160
21386
|
if (audioResult?.audioError) {
|
|
21161
21387
|
applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
|
|
21162
21388
|
}
|
|
21163
|
-
const planAudioPath =
|
|
21389
|
+
const planAudioPath = join45(planDir, PLAN_AUDIO_RELATIVE_PATH);
|
|
21164
21390
|
if (audioResult?.hasAudio && existsSync27(audioResult.audioOutputPath)) {
|
|
21165
21391
|
renameWithRetry7(audioResult.audioOutputPath, planAudioPath);
|
|
21166
21392
|
}
|
|
@@ -21286,8 +21512,8 @@ async function plan(projectDir, config, planDir, options = {}) {
|
|
|
21286
21512
|
|
|
21287
21513
|
// src/services/distributed/renderChunk.ts
|
|
21288
21514
|
import { randomBytes } from "node:crypto";
|
|
21289
|
-
import { existsSync as existsSync30, mkdirSync as
|
|
21290
|
-
import { join as
|
|
21515
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync21, readFileSync as readFileSync15, readdirSync as readdirSync11, rmSync as rmSync18, writeFileSync as writeFileSync14 } from "node:fs";
|
|
21516
|
+
import { join as join49 } from "node:path";
|
|
21291
21517
|
import {
|
|
21292
21518
|
assertSwiftShader,
|
|
21293
21519
|
BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
|
|
@@ -21315,15 +21541,15 @@ import {
|
|
|
21315
21541
|
copyFileSync as copyFileSync8,
|
|
21316
21542
|
existsSync as existsSync29,
|
|
21317
21543
|
lstatSync as lstatSync5,
|
|
21318
|
-
mkdirSync as
|
|
21544
|
+
mkdirSync as mkdirSync20,
|
|
21319
21545
|
readFileSync as readFileSync14,
|
|
21320
21546
|
readdirSync as readdirSync10,
|
|
21321
21547
|
rmSync as rmSync17,
|
|
21322
21548
|
statSync as statSync12,
|
|
21323
|
-
writeFileSync as
|
|
21549
|
+
writeFileSync as writeFileSync13
|
|
21324
21550
|
} from "node:fs";
|
|
21325
21551
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
21326
|
-
import { dirname as dirname20, isAbsolute as isAbsolute6, join as
|
|
21552
|
+
import { dirname as dirname20, isAbsolute as isAbsolute6, join as join48, relative as relative9, resolve as resolve12, sep as sep6 } from "node:path";
|
|
21327
21553
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
21328
21554
|
import {
|
|
21329
21555
|
createFrameLookupTable as createFrameLookupTable5,
|
|
@@ -21336,13 +21562,13 @@ import {
|
|
|
21336
21562
|
copyFileSync as copyFileSync7,
|
|
21337
21563
|
existsSync as existsSync28,
|
|
21338
21564
|
linkSync as linkSync2,
|
|
21339
|
-
mkdirSync as
|
|
21565
|
+
mkdirSync as mkdirSync19,
|
|
21340
21566
|
rmSync as rmSync16,
|
|
21341
21567
|
statSync as statSync11,
|
|
21342
|
-
writeFileSync as
|
|
21568
|
+
writeFileSync as writeFileSync12
|
|
21343
21569
|
} from "node:fs";
|
|
21344
21570
|
import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
|
|
21345
|
-
import { dirname as dirname19, join as
|
|
21571
|
+
import { dirname as dirname19, join as join47 } from "node:path";
|
|
21346
21572
|
|
|
21347
21573
|
// src/services/distributed/planV2Errors.ts
|
|
21348
21574
|
var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
|
|
@@ -21357,7 +21583,7 @@ var PlanV2IntegrityError = class extends Error {
|
|
|
21357
21583
|
};
|
|
21358
21584
|
|
|
21359
21585
|
// src/services/distributed/planV2Layout.ts
|
|
21360
|
-
import { join as
|
|
21586
|
+
import { join as join46 } from "node:path";
|
|
21361
21587
|
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
21362
21588
|
function assertPlanV2Sha256(value, field) {
|
|
21363
21589
|
if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
|
|
@@ -21367,7 +21593,7 @@ function assertPlanV2Sha256(value, field) {
|
|
|
21367
21593
|
}
|
|
21368
21594
|
function planV2BlobPath(root, sha256) {
|
|
21369
21595
|
const digest = assertPlanV2Sha256(sha256, "artifact sha256");
|
|
21370
|
-
return
|
|
21596
|
+
return join46(root, "artifacts", "sha256", digest.slice(0, 2), digest);
|
|
21371
21597
|
}
|
|
21372
21598
|
|
|
21373
21599
|
// src/services/distributed/planV2Publisher.ts
|
|
@@ -21403,7 +21629,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
21403
21629
|
}
|
|
21404
21630
|
this.destinationDir = destinationDir;
|
|
21405
21631
|
this.#linkFile = options.linkFile ?? linkSync2;
|
|
21406
|
-
|
|
21632
|
+
mkdirSync19(dirname19(destinationDir), { recursive: true });
|
|
21407
21633
|
this.temporaryDir = createStagingDir5(dirname19(destinationDir), ".plan-v2-publish-");
|
|
21408
21634
|
}
|
|
21409
21635
|
async putBlob(blob) {
|
|
@@ -21416,9 +21642,9 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
21416
21642
|
}
|
|
21417
21643
|
const destinationPath = planV2BlobPath(this.temporaryDir, digest);
|
|
21418
21644
|
if (existsSync28(destinationPath)) return;
|
|
21419
|
-
|
|
21645
|
+
mkdirSync19(dirname19(destinationPath), { recursive: true });
|
|
21420
21646
|
const stagingDir = createStagingDir5(dirname19(destinationPath), ".plan-v2-blob-");
|
|
21421
|
-
const temporaryPath =
|
|
21647
|
+
const temporaryPath = join47(stagingDir, "blob");
|
|
21422
21648
|
try {
|
|
21423
21649
|
try {
|
|
21424
21650
|
this.#linkFile(blob.sourcePath, temporaryPath);
|
|
@@ -21439,7 +21665,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
21439
21665
|
);
|
|
21440
21666
|
}
|
|
21441
21667
|
}
|
|
21442
|
-
|
|
21668
|
+
writeFileSync12(join47(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
|
|
21443
21669
|
renameWithRetry8(this.temporaryDir, this.destinationDir);
|
|
21444
21670
|
this.#committed = true;
|
|
21445
21671
|
}
|
|
@@ -21485,7 +21711,7 @@ function listFiles(root) {
|
|
|
21485
21711
|
const rootResolved = resolve12(root);
|
|
21486
21712
|
function walk(dir) {
|
|
21487
21713
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
21488
|
-
const absolutePath =
|
|
21714
|
+
const absolutePath = join48(dir, entry.name);
|
|
21489
21715
|
if (entry.isDirectory()) {
|
|
21490
21716
|
walk(absolutePath);
|
|
21491
21717
|
} else if (entry.isFile()) {
|
|
@@ -21512,13 +21738,13 @@ function assertValidExtractionCacheCompleteSentinel(path) {
|
|
|
21512
21738
|
}
|
|
21513
21739
|
}
|
|
21514
21740
|
function validateExtractionCacheCompleteSentinels(executionPlanDir) {
|
|
21515
|
-
const videoRoot =
|
|
21741
|
+
const videoRoot = join48(executionPlanDir, "video-frames");
|
|
21516
21742
|
if (!existsSync29(videoRoot)) return;
|
|
21517
21743
|
for (const videoEntry of readdirSync10(videoRoot, { withFileTypes: true })) {
|
|
21518
21744
|
if (!videoEntry.isDirectory()) continue;
|
|
21519
|
-
const videoDir =
|
|
21745
|
+
const videoDir = join48(videoRoot, videoEntry.name);
|
|
21520
21746
|
if (readdirSync10(videoDir).includes(EXTRACTION_CACHE_COMPLETE_SENTINEL)) {
|
|
21521
|
-
const sentinelPath =
|
|
21747
|
+
const sentinelPath = join48(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
|
|
21522
21748
|
assertValidExtractionCacheCompleteSentinel(sentinelPath);
|
|
21523
21749
|
}
|
|
21524
21750
|
}
|
|
@@ -21565,7 +21791,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
21565
21791
|
if (video.deferredRange) {
|
|
21566
21792
|
const framePaths2 = /* @__PURE__ */ new Map();
|
|
21567
21793
|
for (let index = 0; index < video.totalFrames; index++) {
|
|
21568
|
-
framePaths2.set(index,
|
|
21794
|
+
framePaths2.set(index, join48(outputDir, String(index)));
|
|
21569
21795
|
}
|
|
21570
21796
|
return { ...video, outputDir, framePaths: framePaths2, ownedByLookup: false };
|
|
21571
21797
|
}
|
|
@@ -21573,7 +21799,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
21573
21799
|
const framePaths = /* @__PURE__ */ new Map();
|
|
21574
21800
|
for (const frameName of frameNames) {
|
|
21575
21801
|
if (frameName === EXTRACTION_CACHE_COMPLETE_SENTINEL) {
|
|
21576
|
-
assertValidExtractionCacheCompleteSentinel(
|
|
21802
|
+
assertValidExtractionCacheCompleteSentinel(join48(outputDir, frameName));
|
|
21577
21803
|
continue;
|
|
21578
21804
|
}
|
|
21579
21805
|
const match = /(\d+)(?=\.[^.]+$)/.exec(frameName);
|
|
@@ -21592,7 +21818,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
21592
21818
|
`duplicate extracted frame index ${frameIndex} in ${outputDir}`
|
|
21593
21819
|
);
|
|
21594
21820
|
}
|
|
21595
|
-
framePaths.set(frameIndex,
|
|
21821
|
+
framePaths.set(frameIndex, join48(outputDir, frameName));
|
|
21596
21822
|
}
|
|
21597
21823
|
return {
|
|
21598
21824
|
...video,
|
|
@@ -21613,11 +21839,11 @@ function parsePlanVideosJson2(value) {
|
|
|
21613
21839
|
}
|
|
21614
21840
|
}
|
|
21615
21841
|
function materializeExtractedVideoDirectories(planDir) {
|
|
21616
|
-
const videosPath =
|
|
21842
|
+
const videosPath = join48(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21617
21843
|
if (!existsSync29(videosPath)) return;
|
|
21618
21844
|
const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
|
|
21619
21845
|
for (const video of videos.extracted) {
|
|
21620
|
-
|
|
21846
|
+
mkdirSync20(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
|
|
21621
21847
|
}
|
|
21622
21848
|
}
|
|
21623
21849
|
function parseChunkSlices(value) {
|
|
@@ -21647,13 +21873,13 @@ function parseChunkSlices(value) {
|
|
|
21647
21873
|
});
|
|
21648
21874
|
}
|
|
21649
21875
|
function buildVideoChunkDependencies(executionPlanDir, dimensions) {
|
|
21650
|
-
const videoRoot =
|
|
21876
|
+
const videoRoot = join48(executionPlanDir, "video-frames");
|
|
21651
21877
|
const hasExtractedFrames = existsSync29(videoRoot) && listFiles(videoRoot).length > 0;
|
|
21652
|
-
const videosPath =
|
|
21878
|
+
const videosPath = join48(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21653
21879
|
if (!existsSync29(videosPath)) {
|
|
21654
21880
|
return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
|
|
21655
21881
|
}
|
|
21656
|
-
const chunksPath =
|
|
21882
|
+
const chunksPath = join48(executionPlanDir, "meta", "chunks.json");
|
|
21657
21883
|
const videos = readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21658
21884
|
const chunks = readJsonFile(chunksPath, "meta/chunks.json");
|
|
21659
21885
|
const parsedVideos = parsePlanVideosJson2(videos);
|
|
@@ -21708,9 +21934,9 @@ function computeManifestHash(manifest) {
|
|
|
21708
21934
|
}
|
|
21709
21935
|
function writeBlob(sourcePath, destinationPath) {
|
|
21710
21936
|
if (existsSync29(destinationPath)) return;
|
|
21711
|
-
|
|
21937
|
+
mkdirSync20(dirname20(destinationPath), { recursive: true });
|
|
21712
21938
|
const temporaryDir = createStagingDir6(dirname20(destinationPath), ".plan-v2-blob-");
|
|
21713
|
-
const temporaryPath =
|
|
21939
|
+
const temporaryPath = join48(temporaryDir, "blob");
|
|
21714
21940
|
try {
|
|
21715
21941
|
copyFileSync8(sourcePath, temporaryPath);
|
|
21716
21942
|
renameWithRetry9(temporaryPath, destinationPath);
|
|
@@ -21746,7 +21972,7 @@ async function putTasks(tasks) {
|
|
|
21746
21972
|
if (failure) throw failure.reason;
|
|
21747
21973
|
}
|
|
21748
21974
|
function buildPlanV2Publication(executionPlanDir, digests) {
|
|
21749
|
-
const executionPlanPath =
|
|
21975
|
+
const executionPlanPath = join48(executionPlanDir, "plan.json");
|
|
21750
21976
|
if (!existsSync29(executionPlanPath)) {
|
|
21751
21977
|
throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
|
|
21752
21978
|
}
|
|
@@ -21774,7 +22000,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
21774
22000
|
}
|
|
21775
22001
|
validateExtractionCacheCompleteSentinels(executionPlanDir);
|
|
21776
22002
|
const videoDependencyPlan = buildVideoChunkDependencies(executionPlanDir, dimensions);
|
|
21777
|
-
const encoder = readJsonFile(
|
|
22003
|
+
const encoder = readJsonFile(join48(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
|
|
21778
22004
|
const files = listFiles(executionPlanDir);
|
|
21779
22005
|
const chunkAudio = !isRecord3(encoder) || encoder.chunksCarryAudio !== true ? "none" : files.some((file) => chunkAudioSliceTarget(file.path) !== null) ? "sliced" : "whole";
|
|
21780
22006
|
for (const file of files) {
|
|
@@ -21834,14 +22060,14 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
|
21834
22060
|
if (publication.storedBlobs.length > 0) {
|
|
21835
22061
|
throw new PlanV2IntegrityError("a local plan v2 directory cannot reference remote files");
|
|
21836
22062
|
}
|
|
21837
|
-
|
|
22063
|
+
mkdirSync20(dirname20(planV2Dir), { recursive: true });
|
|
21838
22064
|
const tempDir = createStagingDir6(dirname20(planV2Dir), ".plan-v2-build-");
|
|
21839
22065
|
try {
|
|
21840
22066
|
for (const blob of publication.blobs) {
|
|
21841
22067
|
writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
|
|
21842
22068
|
}
|
|
21843
|
-
|
|
21844
|
-
|
|
22069
|
+
writeFileSync13(
|
|
22070
|
+
join48(tempDir, "plan.json"),
|
|
21845
22071
|
canonicalJsonStringify(publication.manifest),
|
|
21846
22072
|
"utf-8"
|
|
21847
22073
|
);
|
|
@@ -21893,7 +22119,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
21893
22119
|
// artifactTargets ships every compiled/ file to all chunks, so each is in the manifest.
|
|
21894
22120
|
whileAudioMixes: () => putBlobs(
|
|
21895
22121
|
publisher,
|
|
21896
|
-
listFiles(
|
|
22122
|
+
listFiles(join48(stagingRoot, "compiled")).map(
|
|
21897
22123
|
(file) => publishBlobFor(file.absolutePath, digests)
|
|
21898
22124
|
)
|
|
21899
22125
|
),
|
|
@@ -21934,7 +22160,7 @@ function resultFromManifest(planV2Dir, manifest) {
|
|
|
21934
22160
|
isRecord3(executionPlan) ? executionPlan[REFERENCE_BACKGROUND_FIELD3] : void 0
|
|
21935
22161
|
),
|
|
21936
22162
|
planDir: planV2Dir,
|
|
21937
|
-
manifestPath:
|
|
22163
|
+
manifestPath: join48(planV2Dir, "plan.json"),
|
|
21938
22164
|
planProtocol: PLAN_PROTOCOL_V2,
|
|
21939
22165
|
planHash: manifest.planHash,
|
|
21940
22166
|
sourcePlanV1Hash: getPlanV2ExecutionPlanHash(manifest),
|
|
@@ -22070,7 +22296,7 @@ function parsePlanV2Manifest(value) {
|
|
|
22070
22296
|
return parsed;
|
|
22071
22297
|
}
|
|
22072
22298
|
function readPlanV2Manifest(planV2Dir) {
|
|
22073
|
-
const manifestPath =
|
|
22299
|
+
const manifestPath = join48(planV2Dir, "plan.json");
|
|
22074
22300
|
if (!existsSync29(manifestPath)) {
|
|
22075
22301
|
throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
|
|
22076
22302
|
}
|
|
@@ -22115,17 +22341,17 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
22115
22341
|
artifact,
|
|
22116
22342
|
sourcePath: verifyBlob(planV2Dir, artifact)
|
|
22117
22343
|
}));
|
|
22118
|
-
|
|
22344
|
+
mkdirSync20(dirname20(destinationDir), { recursive: true });
|
|
22119
22345
|
const tempDir = createStagingDir6(dirname20(destinationDir), ".plan-v2-materialize-");
|
|
22120
22346
|
try {
|
|
22121
22347
|
for (const { artifact, sourcePath } of verified) {
|
|
22122
|
-
const destinationPath =
|
|
22123
|
-
|
|
22348
|
+
const destinationPath = join48(tempDir, ...artifact.path.split("/"));
|
|
22349
|
+
mkdirSync20(dirname20(destinationPath), { recursive: true });
|
|
22124
22350
|
copyFileSync8(sourcePath, destinationPath);
|
|
22125
22351
|
}
|
|
22126
22352
|
if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
|
|
22127
|
-
|
|
22128
|
-
|
|
22353
|
+
writeFileSync13(
|
|
22354
|
+
join48(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
|
|
22129
22355
|
canonicalJsonStringify({
|
|
22130
22356
|
manifest,
|
|
22131
22357
|
target,
|
|
@@ -22148,7 +22374,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
22148
22374
|
// Join the artifact's OWN name, not the current constant: a plan written
|
|
22149
22375
|
// before the container change carries the legacy name, and materializing it
|
|
22150
22376
|
// under the new one would point at a file that was never written.
|
|
22151
|
-
audioPath: target.role === "assembler" ? audioArtifact ?
|
|
22377
|
+
audioPath: target.role === "assembler" ? audioArtifact ? join48(destinationDir, audioArtifact.path) : null : null
|
|
22152
22378
|
};
|
|
22153
22379
|
}
|
|
22154
22380
|
function assertRemoteSources(remoteSources, artifacts) {
|
|
@@ -22167,7 +22393,7 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
|
|
|
22167
22393
|
return readValidatedPlanV2Materialization(planDir, expectedTarget)?.manifest ?? null;
|
|
22168
22394
|
}
|
|
22169
22395
|
function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
22170
|
-
const markerPath =
|
|
22396
|
+
const markerPath = join48(planDir, PLAN_V2_MATERIALIZATION_MARKER);
|
|
22171
22397
|
if (!existsSync29(markerPath)) return null;
|
|
22172
22398
|
const marker = readJsonFile(markerPath, "materialization marker");
|
|
22173
22399
|
if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
|
|
@@ -22185,7 +22411,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
|
22185
22411
|
assertRemoteSources(remoteSources, required);
|
|
22186
22412
|
for (const artifact of required) {
|
|
22187
22413
|
if (Object.hasOwn(remoteSources, artifact.path)) continue;
|
|
22188
|
-
const path =
|
|
22414
|
+
const path = join48(planDir, ...artifact.path.split("/"));
|
|
22189
22415
|
if (!existsSync29(path) || statSync12(path).size !== artifact.sizeBytes) {
|
|
22190
22416
|
throw new PlanV2IntegrityError(
|
|
22191
22417
|
`materialized artifact missing or truncated: ${artifact.path}`
|
|
@@ -22317,7 +22543,7 @@ function hashChunkOutput(outputPath, kind) {
|
|
|
22317
22543
|
if (kind === "file") return sha256Hex(readFileSync15(outputPath));
|
|
22318
22544
|
const entries = readdirSync11(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
|
|
22319
22545
|
const lines = entries.map(
|
|
22320
|
-
(name) => `${name}\0${sha256Hex(readFileSync15(
|
|
22546
|
+
(name) => `${name}\0${sha256Hex(readFileSync15(join49(outputPath, name)))}`
|
|
22321
22547
|
);
|
|
22322
22548
|
return sha256Hex(lines.join("\0"));
|
|
22323
22549
|
}
|
|
@@ -22334,9 +22560,9 @@ function resolveLockedVp9CpuUsed(lockedEncoder) {
|
|
|
22334
22560
|
async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
22335
22561
|
const start = Date.now();
|
|
22336
22562
|
const log = defaultLogger;
|
|
22337
|
-
const planJsonPath =
|
|
22338
|
-
const encoderJsonPath =
|
|
22339
|
-
const chunksJsonPath =
|
|
22563
|
+
const planJsonPath = join49(planDir, "plan.json");
|
|
22564
|
+
const encoderJsonPath = join49(planDir, "meta", "encoder.json");
|
|
22565
|
+
const chunksJsonPath = join49(planDir, "meta", "chunks.json");
|
|
22340
22566
|
if (!existsSync30(planJsonPath)) {
|
|
22341
22567
|
throw new RenderChunkValidationError(
|
|
22342
22568
|
MISSING_PLAN_ARTIFACT,
|
|
@@ -22362,7 +22588,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22362
22588
|
}
|
|
22363
22589
|
const encoder = JSON.parse(readFileSync15(encoderJsonPath, "utf-8"));
|
|
22364
22590
|
const chunks = JSON.parse(readFileSync15(chunksJsonPath, "utf-8"));
|
|
22365
|
-
const videosJsonPath =
|
|
22591
|
+
const videosJsonPath = join49(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
22366
22592
|
let planVideos = null;
|
|
22367
22593
|
if (existsSync30(videosJsonPath)) {
|
|
22368
22594
|
try {
|
|
@@ -22394,7 +22620,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22394
22620
|
}
|
|
22395
22621
|
const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
|
|
22396
22622
|
const framesInChunk = range.endFrame - range.startFrame;
|
|
22397
|
-
const compiledDir =
|
|
22623
|
+
const compiledDir = join49(planDir, "compiled");
|
|
22398
22624
|
if (!existsSync30(compiledDir)) {
|
|
22399
22625
|
throw new RenderChunkValidationError(
|
|
22400
22626
|
MISSING_PLAN_ARTIFACT,
|
|
@@ -22452,9 +22678,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22452
22678
|
forceScreenshotExplicitlyOptedOut: !encoder.forceScreenshot
|
|
22453
22679
|
};
|
|
22454
22680
|
const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
22455
|
-
|
|
22456
|
-
const framesDir =
|
|
22457
|
-
|
|
22681
|
+
mkdirSync21(workDir, { recursive: true });
|
|
22682
|
+
const framesDir = join49(workDir, "captured-frames");
|
|
22683
|
+
mkdirSync21(framesDir, { recursive: true });
|
|
22458
22684
|
const videoFramesDir = `${workDir}.video-frames`;
|
|
22459
22685
|
const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
|
|
22460
22686
|
const chunkFps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
@@ -22478,7 +22704,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22478
22704
|
dimensions: plan2.dimensions,
|
|
22479
22705
|
encoder,
|
|
22480
22706
|
videoCount: planVideos?.videos.length ?? 0,
|
|
22481
|
-
html: readFileSync15(
|
|
22707
|
+
html: readFileSync15(join49(compiledDir, "index.html"), "utf-8"),
|
|
22482
22708
|
// The plan ships a deferred source only to chunks that show it; don't wait on the rest.
|
|
22483
22709
|
skipReadinessVideoIds: deferredVideos.filter(
|
|
22484
22710
|
(video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
|
|
@@ -22648,10 +22874,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22648
22874
|
const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
|
|
22649
22875
|
const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
|
|
22650
22876
|
if (isPngSequence) {
|
|
22651
|
-
if (!existsSync30(outputChunkPath))
|
|
22877
|
+
if (!existsSync30(outputChunkPath)) mkdirSync21(outputChunkPath, { recursive: true });
|
|
22652
22878
|
} else {
|
|
22653
|
-
const outDir =
|
|
22654
|
-
if (!existsSync30(outDir))
|
|
22879
|
+
const outDir = join49(outputChunkPath, "..");
|
|
22880
|
+
if (!existsSync30(outDir)) mkdirSync21(outDir, { recursive: true });
|
|
22655
22881
|
}
|
|
22656
22882
|
const encodeInput = {
|
|
22657
22883
|
job,
|
|
@@ -22772,7 +22998,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22772
22998
|
resetForScreenshotRetry: () => {
|
|
22773
22999
|
rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
22774
23000
|
boxesMeasured();
|
|
22775
|
-
|
|
23001
|
+
mkdirSync21(framesDir, { recursive: true });
|
|
22776
23002
|
capturePerfs.length = 0;
|
|
22777
23003
|
captureAttempts.length = 0;
|
|
22778
23004
|
job.framesRendered = 0;
|
|
@@ -22864,7 +23090,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22864
23090
|
producerVersion: plan2.producerVersion,
|
|
22865
23091
|
ffmpegVersion
|
|
22866
23092
|
};
|
|
22867
|
-
|
|
23093
|
+
writeFileSync14(perfPath, `${JSON.stringify(perfPayload, null, 2)}
|
|
22868
23094
|
`, "utf-8");
|
|
22869
23095
|
try {
|
|
22870
23096
|
rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
@@ -22927,11 +23153,11 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22927
23153
|
if (config.cfr === true) {
|
|
22928
23154
|
throw new RenderSpanUnsupportedError("--start/--end cannot be combined with a cfr re-encode.");
|
|
22929
23155
|
}
|
|
22930
|
-
const workDir = mkdtempSync(
|
|
23156
|
+
const workDir = mkdtempSync(join50(tmpdir5(), "hf-render-span-"));
|
|
22931
23157
|
try {
|
|
22932
|
-
const planDir =
|
|
22933
|
-
const partsDir =
|
|
22934
|
-
|
|
23158
|
+
const planDir = join50(workDir, "plan");
|
|
23159
|
+
const partsDir = join50(workDir, "parts");
|
|
23160
|
+
mkdirSync22(partsDir, { recursive: true });
|
|
22935
23161
|
const planned = await plan(
|
|
22936
23162
|
projectDir,
|
|
22937
23163
|
{ ...config, rejectOnSystemFonts: false, failClosedFontFetch: false },
|
|
@@ -22949,7 +23175,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22949
23175
|
planned.totalFrames
|
|
22950
23176
|
);
|
|
22951
23177
|
const slices = JSON.parse(
|
|
22952
|
-
readFileSync16(
|
|
23178
|
+
readFileSync16(join50(planDir, "meta", "chunks.json"), "utf-8")
|
|
22953
23179
|
);
|
|
22954
23180
|
const parts = [];
|
|
22955
23181
|
for (const slice of slices) {
|
|
@@ -22959,7 +23185,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22959
23185
|
};
|
|
22960
23186
|
if (range.endFrame <= range.startFrame) continue;
|
|
22961
23187
|
throwIfAborted(config.abortSignal);
|
|
22962
|
-
const part =
|
|
23188
|
+
const part = join50(partsDir, `part-${String(parts.length).padStart(4, "0")}.mp4`);
|
|
22963
23189
|
await renderChunk(planDir, slice.index, part, { frameRange: range });
|
|
22964
23190
|
parts.push(part);
|
|
22965
23191
|
}
|
|
@@ -23638,16 +23864,16 @@ import {
|
|
|
23638
23864
|
existsSync as existsSync33,
|
|
23639
23865
|
fstatSync as fstatSync5,
|
|
23640
23866
|
lstatSync as lstatSync6,
|
|
23641
|
-
mkdirSync as
|
|
23867
|
+
mkdirSync as mkdirSync23,
|
|
23642
23868
|
openSync as openSync9,
|
|
23643
23869
|
statSync as statSync14,
|
|
23644
23870
|
mkdtempSync as mkdtempSync2,
|
|
23645
|
-
writeFileSync as
|
|
23871
|
+
writeFileSync as writeFileSync15,
|
|
23646
23872
|
rmSync as rmSync20,
|
|
23647
23873
|
createReadStream as createReadStream6
|
|
23648
23874
|
} from "node:fs";
|
|
23649
23875
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23650
|
-
import { basename as basename9, resolve as resolve14, dirname as dirname23, join as
|
|
23876
|
+
import { basename as basename9, resolve as resolve14, dirname as dirname23, join as join53 } from "node:path";
|
|
23651
23877
|
import { homedir, tmpdir as tmpdir6 } from "node:os";
|
|
23652
23878
|
import { parseArgs } from "node:util";
|
|
23653
23879
|
import { isIP } from "node:net";
|
|
@@ -23673,7 +23899,7 @@ import {
|
|
|
23673
23899
|
closeSync as closeSync8,
|
|
23674
23900
|
constants as constants4
|
|
23675
23901
|
} from "node:fs";
|
|
23676
|
-
import { resolve as resolve13, join as
|
|
23902
|
+
import { resolve as resolve13, join as join51, relative as relative10, isAbsolute as isAbsolute7, sep as sep7, dirname as dirname21 } from "node:path";
|
|
23677
23903
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
23678
23904
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
23679
23905
|
function isStringRecord(value) {
|
|
@@ -23745,7 +23971,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
|
23745
23971
|
}
|
|
23746
23972
|
}
|
|
23747
23973
|
return {
|
|
23748
|
-
error: `No HTML entry file found in project directory: ${
|
|
23974
|
+
error: `No HTML entry file found in project directory: ${join51(absProjectDir, preferredEntryFile || "index.html")}`
|
|
23749
23975
|
};
|
|
23750
23976
|
}
|
|
23751
23977
|
function prepareHyperframeLintBody(body, isAllowedEntry) {
|
|
@@ -23814,7 +24040,7 @@ function freeLintSlot() {
|
|
|
23814
24040
|
function resolveLintWorkerEntry() {
|
|
23815
24041
|
const here = dirname21(fileURLToPath7(import.meta.url));
|
|
23816
24042
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
23817
|
-
const candidate =
|
|
24043
|
+
const candidate = join51(here, name);
|
|
23818
24044
|
if (existsSync31(candidate)) return candidate;
|
|
23819
24045
|
}
|
|
23820
24046
|
return void 0;
|
|
@@ -23885,7 +24111,7 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
23885
24111
|
// src/services/healthWorker.ts
|
|
23886
24112
|
import { Worker as Worker4 } from "node:worker_threads";
|
|
23887
24113
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
23888
|
-
import { dirname as dirname22, join as
|
|
24114
|
+
import { dirname as dirname22, join as join52 } from "node:path";
|
|
23889
24115
|
import { existsSync as existsSync32 } from "node:fs";
|
|
23890
24116
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
23891
24117
|
async function startHealthWorker(options = {}) {
|
|
@@ -23961,7 +24187,7 @@ function defaultLogger2() {
|
|
|
23961
24187
|
}
|
|
23962
24188
|
function resolveWorkerEntry2() {
|
|
23963
24189
|
const here = dirname22(fileURLToPath8(import.meta.url));
|
|
23964
|
-
const candidates = [
|
|
24190
|
+
const candidates = [join52(here, "healthWorkerThread.js"), join52(here, "healthWorkerThread.ts")];
|
|
23965
24191
|
for (const candidate of candidates) {
|
|
23966
24192
|
if (existsSync32(candidate)) return candidate;
|
|
23967
24193
|
}
|
|
@@ -24126,11 +24352,11 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
24126
24352
|
function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
24127
24353
|
const { input, cleanupProjectDir } = prepared;
|
|
24128
24354
|
const serverNamed = input.outputPath == null;
|
|
24129
|
-
const outputCandidate = input.outputPath ??
|
|
24355
|
+
const outputCandidate = input.outputPath ?? join53(rendersDir, `${basename9(resolve14(input.projectDir))}-${crypto.randomUUID()}.mp4`);
|
|
24130
24356
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, outputCandidate, rendersDir, log);
|
|
24131
24357
|
const outputDir = dirname23(absoluteOutputPath);
|
|
24132
24358
|
if (confineOutput) {
|
|
24133
|
-
|
|
24359
|
+
mkdirSync23(rendersDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
24134
24360
|
if (!isSafePath4(rendersDir, absoluteOutputPath)) {
|
|
24135
24361
|
throw new Error("outputPath must be inside the renders directory");
|
|
24136
24362
|
}
|
|
@@ -24141,7 +24367,7 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
24141
24367
|
);
|
|
24142
24368
|
}
|
|
24143
24369
|
}
|
|
24144
|
-
if (!existsSync33(outputDir))
|
|
24370
|
+
if (!existsSync33(outputDir)) mkdirSync23(outputDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
24145
24371
|
return { input, cleanupProjectDir, absoluteOutputPath, serverNamed };
|
|
24146
24372
|
}
|
|
24147
24373
|
var STICKY_BIT = 512;
|
|
@@ -24252,8 +24478,8 @@ async function resolveInlineRenderHtml(body) {
|
|
|
24252
24478
|
}
|
|
24253
24479
|
function materializeInlineProject(html, options) {
|
|
24254
24480
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
|
|
24255
|
-
const tempProjectDir = mkdtempSync2(
|
|
24256
|
-
|
|
24481
|
+
const tempProjectDir = mkdtempSync2(join53(tempRoot, "producer-project-"));
|
|
24482
|
+
writeFileSync15(join53(tempProjectDir, "index.html"), html, "utf-8");
|
|
24257
24483
|
return {
|
|
24258
24484
|
prepared: {
|
|
24259
24485
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -24465,7 +24691,7 @@ function createRenderHandlers(options = {}) {
|
|
|
24465
24691
|
const log = options.logger ?? defaultLogger;
|
|
24466
24692
|
const getRequestId = options.getRequestId ?? ((c) => c.req.header("x-request-id") || crypto.randomUUID());
|
|
24467
24693
|
const outputUrlPrefix = options.outputUrlPrefix ?? "/outputs";
|
|
24468
|
-
const rendersDir = options.rendersDir ?? process.env.PRODUCER_RENDERS_DIR ?? mkdtempSync2(
|
|
24694
|
+
const rendersDir = options.rendersDir ?? process.env.PRODUCER_RENDERS_DIR ?? mkdtempSync2(join53(tmpdir6(), "hyperframes-renders-"));
|
|
24469
24695
|
const policy = options.confineRequests ? resolveRenderRequestPolicy(options) : void 0;
|
|
24470
24696
|
const artifactTtlMs = options.artifactTtlMs ?? Number(process.env.PRODUCER_OUTPUT_ARTIFACT_TTL_MS || 15 * 60 * 1e3);
|
|
24471
24697
|
const store = createArtifactStore(artifactTtlMs, log);
|
|
@@ -24843,12 +25069,12 @@ function serverAuth(options, hostname2, port) {
|
|
|
24843
25069
|
);
|
|
24844
25070
|
}
|
|
24845
25071
|
const file = resolve14(
|
|
24846
|
-
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() ||
|
|
25072
|
+
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join53(homedir(), ".hyperframes", "producer", `${port}.token`)
|
|
24847
25073
|
);
|
|
24848
25074
|
const token = crypto.randomBytes(32).toString("base64url");
|
|
24849
|
-
|
|
25075
|
+
mkdirSync23(dirname23(file), { recursive: true, mode: 448 });
|
|
24850
25076
|
rmSync20(file, { force: true });
|
|
24851
|
-
|
|
25077
|
+
writeFileSync15(file, `${token}
|
|
24852
25078
|
`, { flag: "wx", mode: 384 });
|
|
24853
25079
|
return { token, generatedFile: file };
|
|
24854
25080
|
}
|
|
@@ -24928,7 +25154,7 @@ import { quantizeTimeToFrame, MEDIA_VISUAL_STYLE_PROPERTIES } from "@hyperframes
|
|
|
24928
25154
|
// src/services/distributed/planV2Execution.ts
|
|
24929
25155
|
import { mkdtempSync as mkdtempSync3, rmSync as rmSync22 } from "node:fs";
|
|
24930
25156
|
import { tmpdir as tmpdir7 } from "node:os";
|
|
24931
|
-
import { join as
|
|
25157
|
+
import { join as join55 } from "node:path";
|
|
24932
25158
|
|
|
24933
25159
|
// src/services/distributed/assemble.ts
|
|
24934
25160
|
import {
|
|
@@ -24938,14 +25164,14 @@ import {
|
|
|
24938
25164
|
import {
|
|
24939
25165
|
cpSync as cpSync3,
|
|
24940
25166
|
existsSync as existsSync34,
|
|
24941
|
-
mkdirSync as
|
|
25167
|
+
mkdirSync as mkdirSync24,
|
|
24942
25168
|
readFileSync as readFileSync18,
|
|
24943
25169
|
readdirSync as readdirSync12,
|
|
24944
25170
|
rmSync as rmSync21,
|
|
24945
25171
|
statSync as statSync15
|
|
24946
25172
|
} from "node:fs";
|
|
24947
25173
|
import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
|
|
24948
|
-
import { basename as basename10, dirname as dirname24, join as
|
|
25174
|
+
import { basename as basename10, dirname as dirname24, join as join54 } from "node:path";
|
|
24949
25175
|
import {
|
|
24950
25176
|
appendRateCapArgs as appendRateCapArgs2,
|
|
24951
25177
|
writeVideoConcatList,
|
|
@@ -24995,7 +25221,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24995
25221
|
const format = plan2.dimensions.format;
|
|
24996
25222
|
const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
|
|
24997
25223
|
if (!existsSync34(dirname24(outputPath))) {
|
|
24998
|
-
|
|
25224
|
+
mkdirSync24(dirname24(outputPath), { recursive: true });
|
|
24999
25225
|
}
|
|
25000
25226
|
const workDir = createStagingDir7(dirname24(outputPath), `${basename10(outputPath)}.assemble-work-`);
|
|
25001
25227
|
const fps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
@@ -25017,7 +25243,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
25017
25243
|
};
|
|
25018
25244
|
try {
|
|
25019
25245
|
const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
|
|
25020
|
-
const finalPath =
|
|
25246
|
+
const finalPath = join54(workDir, `output.${format}`);
|
|
25021
25247
|
const audio = audioPath !== null && existsSync34(audioPath) ? audioPath : null;
|
|
25022
25248
|
await writeJoined(ctx, videoSources, audio, finalPath);
|
|
25023
25249
|
renameWithRetry10(finalPath, outputPath);
|
|
@@ -25046,8 +25272,8 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
25046
25272
|
};
|
|
25047
25273
|
}
|
|
25048
25274
|
function readAssemblePlan(planDir, chunkPaths) {
|
|
25049
|
-
const planJsonPath =
|
|
25050
|
-
const chunksJsonPath =
|
|
25275
|
+
const planJsonPath = join54(planDir, "plan.json");
|
|
25276
|
+
const chunksJsonPath = join54(planDir, "meta", "chunks.json");
|
|
25051
25277
|
if (!existsSync34(planJsonPath)) {
|
|
25052
25278
|
throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
|
|
25053
25279
|
}
|
|
@@ -25102,7 +25328,7 @@ function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
|
|
|
25102
25328
|
return args;
|
|
25103
25329
|
}
|
|
25104
25330
|
async function reencodeCfr(ctx, chunkPaths, encoder) {
|
|
25105
|
-
const cfrOutputPath =
|
|
25331
|
+
const cfrOutputPath = join54(ctx.workDir, `cfr.${ctx.format}`);
|
|
25106
25332
|
const cfrArgs = cfrEncodeArgs(videoInputArgs(ctx, chunkPaths), encoder, ctx.fpsArg);
|
|
25107
25333
|
appendRenderProvenanceArgs2(cfrArgs, cfrOutputPath);
|
|
25108
25334
|
cfrArgs.push("-y", cfrOutputPath);
|
|
@@ -25129,7 +25355,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
25129
25355
|
);
|
|
25130
25356
|
return;
|
|
25131
25357
|
}
|
|
25132
|
-
const paddedAudioPath =
|
|
25358
|
+
const paddedAudioPath = join54(ctx.workDir, "audio-padded.m4a");
|
|
25133
25359
|
const padTrimResult = await ctx.timed(
|
|
25134
25360
|
"audioMs",
|
|
25135
25361
|
() => padOrTrimAudioToVideoFrameCount({
|
|
@@ -25204,11 +25430,11 @@ function stitchesSeparateAudio(planDir) {
|
|
|
25204
25430
|
return lockedAudio(planDir).separateAudio === true;
|
|
25205
25431
|
}
|
|
25206
25432
|
function planFormat(planDir) {
|
|
25207
|
-
const plan2 = JSON.parse(readFileSync18(
|
|
25433
|
+
const plan2 = JSON.parse(readFileSync18(join54(planDir, "plan.json"), "utf-8"));
|
|
25208
25434
|
return plan2.dimensions.format;
|
|
25209
25435
|
}
|
|
25210
25436
|
function lockedAudio(planDir) {
|
|
25211
|
-
const encoderJsonPath =
|
|
25437
|
+
const encoderJsonPath = join54(planDir, "meta", "encoder.json");
|
|
25212
25438
|
if (!existsSync34(encoderJsonPath)) return {};
|
|
25213
25439
|
return JSON.parse(readFileSync18(encoderJsonPath, "utf-8"));
|
|
25214
25440
|
}
|
|
@@ -25218,7 +25444,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
25218
25444
|
`[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.`
|
|
25219
25445
|
);
|
|
25220
25446
|
}
|
|
25221
|
-
const encoderJsonPath =
|
|
25447
|
+
const encoderJsonPath = join54(planDir, "meta", "encoder.json");
|
|
25222
25448
|
if (!existsSync34(encoderJsonPath)) {
|
|
25223
25449
|
throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
|
|
25224
25450
|
}
|
|
@@ -25232,7 +25458,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
25232
25458
|
}
|
|
25233
25459
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
25234
25460
|
if (existsSync34(outputPath)) rmSync21(outputPath, { recursive: true, force: true });
|
|
25235
|
-
|
|
25461
|
+
mkdirSync24(outputPath, { recursive: true });
|
|
25236
25462
|
let globalIdx = 0;
|
|
25237
25463
|
for (const chunkDir of chunkPaths) {
|
|
25238
25464
|
if (!statSync15(chunkDir).isDirectory()) {
|
|
@@ -25245,8 +25471,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
25245
25471
|
throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
|
|
25246
25472
|
}
|
|
25247
25473
|
for (const frame of frames) {
|
|
25248
|
-
const dst =
|
|
25249
|
-
cpSync3(
|
|
25474
|
+
const dst = join54(outputPath, formatExportFrameName(globalIdx, "png"));
|
|
25475
|
+
cpSync3(join54(chunkDir, frame), dst);
|
|
25250
25476
|
globalIdx += 1;
|
|
25251
25477
|
}
|
|
25252
25478
|
}
|
|
@@ -25256,13 +25482,13 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
25256
25482
|
);
|
|
25257
25483
|
}
|
|
25258
25484
|
if (audioPath !== null && existsSync34(audioPath)) {
|
|
25259
|
-
const sidecar =
|
|
25485
|
+
const sidecar = join54(outputPath, MIXED_AUDIO_FILENAME4);
|
|
25260
25486
|
cpSync3(audioPath, sidecar);
|
|
25261
25487
|
}
|
|
25262
25488
|
let fileSize = 0;
|
|
25263
25489
|
for (const name of readdirSync12(outputPath)) {
|
|
25264
25490
|
try {
|
|
25265
|
-
fileSize += statSync15(
|
|
25491
|
+
fileSize += statSync15(join54(outputPath, name)).size;
|
|
25266
25492
|
} catch {
|
|
25267
25493
|
}
|
|
25268
25494
|
}
|
|
@@ -25276,8 +25502,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
25276
25502
|
|
|
25277
25503
|
// src/services/distributed/planV2Execution.ts
|
|
25278
25504
|
async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
25279
|
-
const workRoot = mkdtempSync3(
|
|
25280
|
-
const materializedPlanDir =
|
|
25505
|
+
const workRoot = mkdtempSync3(join55(tmpdir7(), "hf-plan-v2-chunk-"));
|
|
25506
|
+
const materializedPlanDir = join55(workRoot, "plan");
|
|
25281
25507
|
try {
|
|
25282
25508
|
materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
|
|
25283
25509
|
return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
|
|
@@ -25286,8 +25512,8 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
|
25286
25512
|
}
|
|
25287
25513
|
}
|
|
25288
25514
|
async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
25289
|
-
const workRoot = mkdtempSync3(
|
|
25290
|
-
const materializedPlanDir =
|
|
25515
|
+
const workRoot = mkdtempSync3(join55(tmpdir7(), "hf-plan-v2-assembler-"));
|
|
25516
|
+
const materializedPlanDir = join55(workRoot, "plan");
|
|
25291
25517
|
try {
|
|
25292
25518
|
const materialized = materializePlanV2Target(
|
|
25293
25519
|
planV2Dir,
|