@hyperframes/producer 0.9.29 → 0.9.31
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 +320 -301
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.js +377 -358
- package/dist/public-server.js +181 -162
- package/dist/services/bundledScripts.d.ts +4 -0
- package/package.json +7 -7
package/dist/distributed.js
CHANGED
|
@@ -8,13 +8,13 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
|
|
|
8
8
|
import {
|
|
9
9
|
copyFileSync as copyFileSync6,
|
|
10
10
|
cpSync as cpSync2,
|
|
11
|
-
existsSync as
|
|
11
|
+
existsSync as existsSync20,
|
|
12
12
|
linkSync,
|
|
13
13
|
mkdirSync as mkdirSync10,
|
|
14
14
|
rmSync as rmSync7,
|
|
15
15
|
writeFileSync as writeFileSync8
|
|
16
16
|
} from "node:fs";
|
|
17
|
-
import { extname as extname4, isAbsolute as isAbsolute3, join as
|
|
17
|
+
import { extname as extname4, isAbsolute as isAbsolute3, join as join26, relative as relative5, sep as sep3 } from "node:path";
|
|
18
18
|
import {
|
|
19
19
|
fpsToNumber as fpsToNumber9,
|
|
20
20
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
@@ -71,7 +71,7 @@ var defaultLogger = createConsoleLogger("info");
|
|
|
71
71
|
// src/services/renderOrchestrator.ts
|
|
72
72
|
import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
|
|
73
73
|
import {
|
|
74
|
-
existsSync as
|
|
74
|
+
existsSync as existsSync15,
|
|
75
75
|
mkdirSync as mkdirSync6,
|
|
76
76
|
readdirSync as readdirSync3,
|
|
77
77
|
rmSync as rmSync5,
|
|
@@ -128,7 +128,7 @@ import {
|
|
|
128
128
|
referenceBackgroundResult,
|
|
129
129
|
createReferenceBackgroundRecorder
|
|
130
130
|
} from "@hyperframes/engine";
|
|
131
|
-
import { join as
|
|
131
|
+
import { join as join17, dirname as dirname10, resolve as resolve7 } from "path";
|
|
132
132
|
import { randomUUID } from "crypto";
|
|
133
133
|
|
|
134
134
|
// src/services/fileServer.ts
|
|
@@ -2144,8 +2144,8 @@ import {
|
|
|
2144
2144
|
} from "@hyperframes/engine";
|
|
2145
2145
|
|
|
2146
2146
|
// src/services/render/stages/compileStage.ts
|
|
2147
|
-
import { existsSync as
|
|
2148
|
-
import { join as
|
|
2147
|
+
import { existsSync as existsSync9, writeFileSync as writeFileSync3 } from "node:fs";
|
|
2148
|
+
import { join as join9 } from "node:path";
|
|
2149
2149
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
2150
2150
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
2151
2151
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
@@ -2153,9 +2153,23 @@ import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolu
|
|
|
2153
2153
|
// src/services/htmlCompiler.ts
|
|
2154
2154
|
import { decodedUrlPath as decodedUrlPath2 } from "@hyperframes/parsers/asset-paths";
|
|
2155
2155
|
import { createHash as createHash4 } from "node:crypto";
|
|
2156
|
-
import { createReadStream as createReadStream2, existsSync as
|
|
2157
|
-
import { join as
|
|
2156
|
+
import { createReadStream as createReadStream2, existsSync as existsSync8, mkdirSync as mkdirSync4, readFileSync as readFileSync5 } from "fs";
|
|
2157
|
+
import { join as join8, dirname as dirname6, resolve as resolve6, basename as basename3, relative as relative2, sep as sep2 } from "path";
|
|
2158
2158
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
2159
|
+
|
|
2160
|
+
// src/services/bundledScripts.ts
|
|
2161
|
+
import { existsSync as existsSync5, readFileSync as readFileSync2 } from "node:fs";
|
|
2162
|
+
import { join as join5 } from "node:path";
|
|
2163
|
+
import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
|
|
2164
|
+
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
2165
|
+
function bundledScript(url) {
|
|
2166
|
+
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
2167
|
+
if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
|
|
2168
|
+
const file = join5(dir, "gsap.min.js");
|
|
2169
|
+
return existsSync5(file) ? readFileSync2(file) : null;
|
|
2170
|
+
}
|
|
2171
|
+
|
|
2172
|
+
// src/services/htmlCompiler.ts
|
|
2159
2173
|
import {
|
|
2160
2174
|
COMPOSITION_SOURCE_URL,
|
|
2161
2175
|
compileTimingAttrs,
|
|
@@ -2177,7 +2191,7 @@ import {
|
|
|
2177
2191
|
import { MAX_AUDIO_GAIN } from "@hyperframes/core/audio-gain";
|
|
2178
2192
|
import { readPlaybackRate } from "@hyperframes/parsers/media-duration";
|
|
2179
2193
|
import { resolveRateSpec } from "@hyperframes/core/speed-ramp";
|
|
2180
|
-
import { gsapCdnDist, normalizeGsapBaseUrl } from "@hyperframes/core/gsap-cdn";
|
|
2194
|
+
import { gsapCdnDist as gsapCdnDist2, normalizeGsapBaseUrl } from "@hyperframes/core/gsap-cdn";
|
|
2181
2195
|
import {
|
|
2182
2196
|
assignBundledRuntimeCompositionIds,
|
|
2183
2197
|
assignMediaRenderIds,
|
|
@@ -2400,8 +2414,8 @@ import {
|
|
|
2400
2414
|
|
|
2401
2415
|
// src/services/animatedGifPrep.ts
|
|
2402
2416
|
import { createHash as createHash2 } from "node:crypto";
|
|
2403
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
2404
|
-
import { dirname as dirname4, isAbsolute as isAbsolute2, join as
|
|
2417
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync6, mkdirSync as mkdirSync2, readFileSync as readFileSync3, rmSync as rmSync2, statSync as statSync2 } from "node:fs";
|
|
2418
|
+
import { dirname as dirname4, isAbsolute as isAbsolute2, join as join6, resolve as resolve4 } from "node:path";
|
|
2405
2419
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
2406
2420
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
2407
2421
|
import { DEFAULT_VP9_CPU_USED, runFfmpeg as runFfmpeg2, renameWithRetry as renameWithRetry3 } from "@hyperframes/engine";
|
|
@@ -2439,14 +2453,14 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
2439
2453
|
const { basePath } = splitUrlSuffix(trimmed);
|
|
2440
2454
|
const normalizedBase = normalizeRelPath(basePath);
|
|
2441
2455
|
const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
|
|
2442
|
-
if (mapped &&
|
|
2456
|
+
if (mapped && existsSync6(mapped)) return mapped;
|
|
2443
2457
|
if (isHttpUrl(trimmed)) return null;
|
|
2444
2458
|
const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
|
|
2445
2459
|
const candidates = [
|
|
2446
2460
|
isAbsolute2(basePath) ? basePath : resolve4(options.projectDir, projectRelative),
|
|
2447
2461
|
resolve4(options.downloadDir, normalizedBase)
|
|
2448
2462
|
];
|
|
2449
|
-
return candidates.find((candidate) =>
|
|
2463
|
+
return candidates.find((candidate) => existsSync6(candidate)) ?? null;
|
|
2450
2464
|
}
|
|
2451
2465
|
function isUsableFile(path) {
|
|
2452
2466
|
try {
|
|
@@ -2557,10 +2571,10 @@ async function runAnimatedGifTranscode(request) {
|
|
|
2557
2571
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
2558
2572
|
}
|
|
2559
2573
|
async function ensurePreparedWebm(input) {
|
|
2560
|
-
if (!
|
|
2574
|
+
if (!existsSync6(dirname4(input.cachePath))) {
|
|
2561
2575
|
mkdirSync2(dirname4(input.cachePath), { recursive: true });
|
|
2562
2576
|
}
|
|
2563
|
-
if (!
|
|
2577
|
+
if (!existsSync6(dirname4(input.outputPath))) {
|
|
2564
2578
|
mkdirSync2(dirname4(input.outputPath), { recursive: true });
|
|
2565
2579
|
}
|
|
2566
2580
|
if (!isUsableFile(input.cachePath)) {
|
|
@@ -2644,7 +2658,7 @@ function replaceImageWithVideo(input) {
|
|
|
2644
2658
|
return video;
|
|
2645
2659
|
}
|
|
2646
2660
|
async function prepareAnimatedGifInputs(html, options) {
|
|
2647
|
-
const outputDir = options.outputDir ??
|
|
2661
|
+
const outputDir = options.outputDir ?? join6(options.downloadDir, PREPARED_GIF_SUBDIR);
|
|
2648
2662
|
const outputSrcPrefix = normalizeRelPath(options.outputSrcPrefix ?? PREPARED_GIF_SUBDIR);
|
|
2649
2663
|
const cacheDir = options.cacheDir ?? outputDir;
|
|
2650
2664
|
const { document: document2 } = parseHTML3(html);
|
|
@@ -2658,7 +2672,7 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
2658
2672
|
if (!hasGifExtension(src)) continue;
|
|
2659
2673
|
const sourcePath = resolveLocalImageSourcePath(src, options);
|
|
2660
2674
|
if (!sourcePath) continue;
|
|
2661
|
-
const bytes =
|
|
2675
|
+
const bytes = readFileSync3(sourcePath);
|
|
2662
2676
|
const metadata = parseAnimatedGifMetadata(bytes);
|
|
2663
2677
|
if (!metadata?.animated) continue;
|
|
2664
2678
|
const loopOverride = readLoopOverride(img);
|
|
@@ -2671,8 +2685,8 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
2671
2685
|
);
|
|
2672
2686
|
const hash = computePreparedGifHash(bytes, loopIterations, padSeconds);
|
|
2673
2687
|
const filename = `${CACHE_SCHEMA}-${hash.slice(0, 24)}.webm`;
|
|
2674
|
-
const cachePath =
|
|
2675
|
-
const outputPath =
|
|
2688
|
+
const cachePath = join6(cacheDir, filename);
|
|
2689
|
+
const outputPath = join6(outputDir, filename);
|
|
2676
2690
|
const outputSrc = `${outputSrcPrefix}/${filename}`;
|
|
2677
2691
|
await ensurePreparedWebm({
|
|
2678
2692
|
sourcePath,
|
|
@@ -2711,13 +2725,13 @@ import {
|
|
|
2711
2725
|
copyFileSync as copyFileSync3,
|
|
2712
2726
|
mkdirSync as mkdirSync3,
|
|
2713
2727
|
openSync as openSync2,
|
|
2714
|
-
readFileSync as
|
|
2728
|
+
readFileSync as readFileSync4,
|
|
2715
2729
|
readSync,
|
|
2716
2730
|
rmSync as rmSync3,
|
|
2717
2731
|
statSync as statSync3,
|
|
2718
2732
|
writeFileSync as writeFileSync2
|
|
2719
2733
|
} from "node:fs";
|
|
2720
|
-
import { dirname as dirname5, join as
|
|
2734
|
+
import { dirname as dirname5, join as join7, resolve as resolve5 } from "node:path";
|
|
2721
2735
|
import { parseHTML as parseHTML4 } from "linkedom";
|
|
2722
2736
|
import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe } from "@hyperframes/engine";
|
|
2723
2737
|
|
|
@@ -2895,7 +2909,7 @@ function primaryGrid(probed) {
|
|
|
2895
2909
|
async function convertHeifToJpeg(request) {
|
|
2896
2910
|
const probed = await probeJson(request.inputPath, true);
|
|
2897
2911
|
const grid = primaryGrid(probed);
|
|
2898
|
-
const rotation = readHeifPrimaryRotation(
|
|
2912
|
+
const rotation = readHeifPrimaryRotation(readFileSync4(request.inputPath));
|
|
2899
2913
|
const filters = [];
|
|
2900
2914
|
let inputs = [];
|
|
2901
2915
|
let size = probed.streams?.[0];
|
|
@@ -2953,7 +2967,7 @@ function resolveImageSource(src, options) {
|
|
|
2953
2967
|
const path = resolveLocalImageSourcePath(src, options);
|
|
2954
2968
|
const head = path ? readHead(path) : null;
|
|
2955
2969
|
if (!path || !head || !isHeifBytes(head)) return null;
|
|
2956
|
-
return { path, bytes:
|
|
2970
|
+
return { path, bytes: readFileSync4(path), label: `"${splitUrlSuffix(src).basePath}"` };
|
|
2957
2971
|
}
|
|
2958
2972
|
function isUsableFile2(path) {
|
|
2959
2973
|
try {
|
|
@@ -2991,7 +3005,7 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
|
2991
3005
|
}
|
|
2992
3006
|
}
|
|
2993
3007
|
async function prepareHeifImageInputs(html, options) {
|
|
2994
|
-
const outputDir = options.outputDir ??
|
|
3008
|
+
const outputDir = options.outputDir ?? join7(options.downloadDir, PREPARED_HEIF_SUBDIR);
|
|
2995
3009
|
const outputSrcPrefix = normalizeRelPath(options.outputSrcPrefix ?? PREPARED_HEIF_SUBDIR);
|
|
2996
3010
|
const cacheDir = options.cacheDir ?? outputDir;
|
|
2997
3011
|
const preparedAssets = /* @__PURE__ */ new Map();
|
|
@@ -3012,7 +3026,7 @@ async function prepareHeifImageInputs(html, options) {
|
|
|
3012
3026
|
await Promise.all(
|
|
3013
3027
|
[...unique].map(
|
|
3014
3028
|
([filename, source]) => withMediaProbeSlot(
|
|
3015
|
-
() => ensurePreparedJpeg(source,
|
|
3029
|
+
() => ensurePreparedJpeg(source, join7(cacheDir, filename), join7(outputDir, filename), options)
|
|
3016
3030
|
).catch((error) => {
|
|
3017
3031
|
if (!options.onFailure) throw error;
|
|
3018
3032
|
failed.add(filename);
|
|
@@ -3024,8 +3038,8 @@ async function prepareHeifImageInputs(html, options) {
|
|
|
3024
3038
|
if (failed.has(filename)) continue;
|
|
3025
3039
|
const outputSrc = `${outputSrcPrefix}/${filename}`;
|
|
3026
3040
|
img.setAttribute("src", outputSrc);
|
|
3027
|
-
preparedAssets.set(outputSrc,
|
|
3028
|
-
preparedImages.push({ sourceSrc: src, outputSrc, outputPath:
|
|
3041
|
+
preparedAssets.set(outputSrc, join7(outputDir, filename));
|
|
3042
|
+
preparedImages.push({ sourceSrc: src, outputSrc, outputPath: join7(outputDir, filename) });
|
|
3029
3043
|
}
|
|
3030
3044
|
return { html: document2.toString(), preparedAssets, preparedImages };
|
|
3031
3045
|
}
|
|
@@ -3035,7 +3049,7 @@ import { createStudioPositionSeekReapplyScript } from "@hyperframes/studio-serve
|
|
|
3035
3049
|
import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
|
|
3036
3050
|
|
|
3037
3051
|
// src/services/assetMediaType.ts
|
|
3038
|
-
import { existsSync as
|
|
3052
|
+
import { existsSync as existsSync7 } from "node:fs";
|
|
3039
3053
|
import {
|
|
3040
3054
|
fingerprintElementId,
|
|
3041
3055
|
isNotMediaPayload,
|
|
@@ -3108,7 +3122,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
3108
3122
|
input.projectDir,
|
|
3109
3123
|
input.compiledDir
|
|
3110
3124
|
);
|
|
3111
|
-
if (!
|
|
3125
|
+
if (!existsSync7(resolvedPath)) continue;
|
|
3112
3126
|
byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
|
|
3113
3127
|
}
|
|
3114
3128
|
const mismatches = [];
|
|
@@ -3361,8 +3375,8 @@ function detectShaderTransitionUsage(html) {
|
|
|
3361
3375
|
async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, downloadDir, tagName, elementIdentity, log, urlByAbsentLocalPath, probes) {
|
|
3362
3376
|
let filePath = src;
|
|
3363
3377
|
if (isHttpUrl(src)) {
|
|
3364
|
-
const remoteDir =
|
|
3365
|
-
if (!
|
|
3378
|
+
const remoteDir = join8(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
3379
|
+
if (!existsSync8(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
|
|
3366
3380
|
try {
|
|
3367
3381
|
filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
|
|
3368
3382
|
onTelemetry: logRemoteDownloadTelemetry
|
|
@@ -3372,10 +3386,10 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
|
|
|
3372
3386
|
}
|
|
3373
3387
|
} else {
|
|
3374
3388
|
filePath = decodedUrlPath2(src);
|
|
3375
|
-
if (!filePath.startsWith("/")) filePath =
|
|
3389
|
+
if (!filePath.startsWith("/")) filePath = join8(baseDir, filePath);
|
|
3376
3390
|
filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
|
|
3377
3391
|
}
|
|
3378
|
-
if (!isHttpUrl(filePath) && !
|
|
3392
|
+
if (!isHttpUrl(filePath) && !existsSync8(filePath)) {
|
|
3379
3393
|
return { duration: null, resolvedPath: filePath };
|
|
3380
3394
|
}
|
|
3381
3395
|
const withSrcContext = (error) => {
|
|
@@ -3724,7 +3738,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
3724
3738
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
3725
3739
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
3726
3740
|
// against its own directory, project-root refs stay as authored.
|
|
3727
|
-
assetExists: (path) =>
|
|
3741
|
+
assetExists: (path) => existsSync8(resolve6(projectDir, path)),
|
|
3728
3742
|
// Preserve the authored root wrapper as a child of the host, matching
|
|
3729
3743
|
// the preview bundler's shape (htmlBundler.ts's prepareFlattenedInnerRoot,
|
|
3730
3744
|
// which the runtime compositionLoader mirrors with its own copy for the
|
|
@@ -3869,12 +3883,17 @@ async function inlineExternalScripts(html) {
|
|
|
3869
3883
|
if (externalScripts.length === 0) return html;
|
|
3870
3884
|
const downloads = await Promise.allSettled(
|
|
3871
3885
|
externalScripts.map(async ({ el, src }) => {
|
|
3886
|
+
const integrity = el.getAttribute("integrity") || "";
|
|
3887
|
+
const bundled = bundledScript(src);
|
|
3888
|
+
if (bundled && matchesScriptIntegrity(bundled, integrity)) {
|
|
3889
|
+
return { src, text: new TextDecoder().decode(bundled) };
|
|
3890
|
+
}
|
|
3872
3891
|
const response = await fetch(src, {
|
|
3873
3892
|
signal: AbortSignal.timeout(15e3)
|
|
3874
3893
|
});
|
|
3875
3894
|
if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
|
|
3876
3895
|
const bytes = new Uint8Array(await response.arrayBuffer());
|
|
3877
|
-
if (!matchesScriptIntegrity(bytes,
|
|
3896
|
+
if (!matchesScriptIntegrity(bytes, integrity)) {
|
|
3878
3897
|
throw new ScriptIntegrityError(`Subresource integrity mismatch for ${src}`);
|
|
3879
3898
|
}
|
|
3880
3899
|
return { src, text: new TextDecoder().decode(bytes) };
|
|
@@ -3915,7 +3934,7 @@ function collectExternalAssets(html, projectDir) {
|
|
|
3915
3934
|
if (isPathInside2(absPath, absProjectDir)) {
|
|
3916
3935
|
return null;
|
|
3917
3936
|
}
|
|
3918
|
-
if (!
|
|
3937
|
+
if (!existsSync8(absPath)) return null;
|
|
3919
3938
|
const safeKey = toExternalAssetKey(absPath);
|
|
3920
3939
|
externalAssets.set(safeKey, absPath);
|
|
3921
3940
|
return safeKey;
|
|
@@ -3965,7 +3984,7 @@ var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["
|
|
|
3965
3984
|
var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
|
|
3966
3985
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
3967
3986
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
3968
|
-
if (!
|
|
3987
|
+
if (!existsSync8(remoteDir)) mkdirSync4(remoteDir, { recursive: true });
|
|
3969
3988
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
3970
3989
|
await Promise.all(
|
|
3971
3990
|
[...urlSet].map(async (url) => {
|
|
@@ -4012,7 +4031,7 @@ async function localizeRemoteMediaSources(html, downloadDir) {
|
|
|
4012
4031
|
return downloadAndRewriteUrls(
|
|
4013
4032
|
urlSet,
|
|
4014
4033
|
html,
|
|
4015
|
-
|
|
4034
|
+
join8(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4016
4035
|
"Remote media download failed",
|
|
4017
4036
|
"Localized remote media source(s)"
|
|
4018
4037
|
);
|
|
@@ -4027,7 +4046,7 @@ async function localizeRemoteImageSources(html, downloadDir) {
|
|
|
4027
4046
|
return downloadAndRewriteUrls(
|
|
4028
4047
|
urlSet,
|
|
4029
4048
|
html,
|
|
4030
|
-
|
|
4049
|
+
join8(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4031
4050
|
"Remote image download failed",
|
|
4032
4051
|
"Localized remote image source(s)"
|
|
4033
4052
|
);
|
|
@@ -4043,7 +4062,7 @@ async function localizeRemoteBackgroundImages(html, downloadDir) {
|
|
|
4043
4062
|
return downloadAndRewriteUrls(
|
|
4044
4063
|
urlSet,
|
|
4045
4064
|
html,
|
|
4046
|
-
|
|
4065
|
+
join8(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4047
4066
|
"Remote background-image download failed",
|
|
4048
4067
|
"Localized remote background-image(s)",
|
|
4049
4068
|
// Quoted url('..')/url("..") are rewritten by downloadAndRewriteUrls' default
|
|
@@ -4148,13 +4167,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
4148
4167
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
4149
4168
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
4150
4169
|
const sheet = resolve6(projectDir, decodedUrlPath2(href).replace(/^(?:\.?\/)+/, ""));
|
|
4151
|
-
if (!isPathInside2(sheet, projectDir) || !
|
|
4152
|
-
for (const face of extractFontFaceBlocks(
|
|
4170
|
+
if (!isPathInside2(sheet, projectDir) || !existsSync8(sheet)) continue;
|
|
4171
|
+
for (const face of extractFontFaceBlocks(readFileSync5(sheet, "utf8"))) {
|
|
4153
4172
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
4154
4173
|
const shipsFile = [...face.matchAll(LOCAL_FONTFACE_URL_RE)].some(([, url = ""]) => {
|
|
4155
4174
|
const path = decodedUrlPath2(url);
|
|
4156
4175
|
const file = path.startsWith("/") ? resolve6(projectDir, `.${path}`) : resolve6(dirname6(sheet), path);
|
|
4157
|
-
return isPathInside2(file, projectDir) &&
|
|
4176
|
+
return isPathInside2(file, projectDir) && existsSync8(file);
|
|
4158
4177
|
});
|
|
4159
4178
|
if (family && shipsFile) families.push(family);
|
|
4160
4179
|
}
|
|
@@ -4195,7 +4214,7 @@ function localizeFontFaceUrls(html, downloadDir) {
|
|
|
4195
4214
|
return downloadAndRewriteUrls(
|
|
4196
4215
|
collectFontFaceUrls(html),
|
|
4197
4216
|
html,
|
|
4198
|
-
|
|
4217
|
+
join8(downloadDir, REMOTE_MEDIA_SUBDIR),
|
|
4199
4218
|
"Remote font download failed",
|
|
4200
4219
|
"Localized remote font face(s)",
|
|
4201
4220
|
(h, url, relPath) => h.replaceAll(`url(${url})`, `url("${relPath}")`)
|
|
@@ -4279,7 +4298,7 @@ async function embedLocalFontFaces(html, projectDir) {
|
|
|
4279
4298
|
}
|
|
4280
4299
|
function renderGsapDist() {
|
|
4281
4300
|
try {
|
|
4282
|
-
return
|
|
4301
|
+
return gsapCdnDist2(void 0, normalizeGsapBaseUrl(process.env.HYPERFRAMES_GSAP_BASE_URL));
|
|
4283
4302
|
} catch (cause) {
|
|
4284
4303
|
throw new Error(
|
|
4285
4304
|
"Invalid HYPERFRAMES_GSAP_BASE_URL: use an absolute HTTPS npm mirror root (plain HTTP only for localhost) without credentials, query, or fragment",
|
|
@@ -4289,7 +4308,7 @@ function renderGsapDist() {
|
|
|
4289
4308
|
}
|
|
4290
4309
|
function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
4291
4310
|
let gsapDist;
|
|
4292
|
-
const exists = (path) =>
|
|
4311
|
+
const exists = (path) => existsSync8(resolve6(projectDir, path));
|
|
4293
4312
|
return html.replace(
|
|
4294
4313
|
/(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
|
|
4295
4314
|
(full, prefix, src, file, suffix) => {
|
|
@@ -4306,7 +4325,7 @@ function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
|
|
|
4306
4325
|
const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
|
|
4307
4326
|
if (!entryPath.includes("/")) return html;
|
|
4308
4327
|
const { document: document2 } = parseHTML5(html);
|
|
4309
|
-
const assetExists = (path) =>
|
|
4328
|
+
const assetExists = (path) => existsSync8(resolve6(projectDir, path));
|
|
4310
4329
|
rewriteAssetPaths(
|
|
4311
4330
|
document2.querySelectorAll("[src], [href], [srcset]"),
|
|
4312
4331
|
entryPath,
|
|
@@ -4872,11 +4891,11 @@ function adaptAspectAgnosticResolution(requested, aspectAgnostic, width, height,
|
|
|
4872
4891
|
}
|
|
4873
4892
|
function resolveEntryHtmlPath(input) {
|
|
4874
4893
|
const { projectDir, workDir, entryFile, log } = input;
|
|
4875
|
-
const htmlPath =
|
|
4894
|
+
const htmlPath = join9(projectDir, entryFile);
|
|
4876
4895
|
const rawEntry = readTextFile2(htmlPath);
|
|
4877
4896
|
if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
|
|
4878
|
-
const projectIndexPath =
|
|
4879
|
-
if (!
|
|
4897
|
+
const projectIndexPath = join9(projectDir, "index.html");
|
|
4898
|
+
if (!existsSync9(projectIndexPath)) {
|
|
4880
4899
|
throw new Error(
|
|
4881
4900
|
`Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
|
|
4882
4901
|
);
|
|
@@ -4891,7 +4910,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
4891
4910
|
`Entry file "${entryFile}" is not mounted from index.html via data-composition-src, so it cannot be rendered independently.`
|
|
4892
4911
|
);
|
|
4893
4912
|
}
|
|
4894
|
-
const wrapperPath =
|
|
4913
|
+
const wrapperPath = join9(workDir, "standalone-entry.html");
|
|
4895
4914
|
writeFileSync3(wrapperPath, standaloneHtml, "utf-8");
|
|
4896
4915
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
4897
4916
|
return wrapperPath;
|
|
@@ -4912,7 +4931,7 @@ async function runCompileStage(input) {
|
|
|
4912
4931
|
} = input;
|
|
4913
4932
|
const htmlPath = resolveEntryHtmlPath({ projectDir, workDir, entryFile, log });
|
|
4914
4933
|
const compileStart = Date.now();
|
|
4915
|
-
const compiled = await compileForRender(projectDir, htmlPath,
|
|
4934
|
+
const compiled = await compileForRender(projectDir, htmlPath, join9(workDir, "downloads"), {
|
|
4916
4935
|
log,
|
|
4917
4936
|
failClosedFontFetch: failClosedFontFetch === true,
|
|
4918
4937
|
allowSystemFontCapture,
|
|
@@ -4920,7 +4939,7 @@ async function runCompileStage(input) {
|
|
|
4920
4939
|
variables: input.variables,
|
|
4921
4940
|
urlByAbsentLocalPath: input.urlByAbsentLocalPath,
|
|
4922
4941
|
pageMotionBlur: input.pageMotionBlur,
|
|
4923
|
-
animatedGifCacheDir: cfg.extractCacheDir ?
|
|
4942
|
+
animatedGifCacheDir: cfg.extractCacheDir ? join9(cfg.extractCacheDir, "animated-gif") : void 0,
|
|
4924
4943
|
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout
|
|
4925
4944
|
});
|
|
4926
4945
|
assertNotAborted();
|
|
@@ -4977,7 +4996,7 @@ async function runCompileStage(input) {
|
|
|
4977
4996
|
};
|
|
4978
4997
|
await preflightCompositionAssetMediaTypes({
|
|
4979
4998
|
projectDir,
|
|
4980
|
-
compiledDir:
|
|
4999
|
+
compiledDir: join9(workDir, "compiled"),
|
|
4981
5000
|
composition,
|
|
4982
5001
|
signal: abortSignal
|
|
4983
5002
|
});
|
|
@@ -5023,7 +5042,7 @@ async function runCompileStage(input) {
|
|
|
5023
5042
|
|
|
5024
5043
|
// src/services/render/stages/probeStage.ts
|
|
5025
5044
|
import { createHash as createHash5 } from "node:crypto";
|
|
5026
|
-
import { basename as basename4, join as
|
|
5045
|
+
import { basename as basename4, join as join10 } from "node:path";
|
|
5027
5046
|
import { parseHTML as parseHTML6 } from "linkedom";
|
|
5028
5047
|
import {
|
|
5029
5048
|
closeCaptureSession as closeCaptureSession4,
|
|
@@ -5232,7 +5251,7 @@ async function runProbeStage(input) {
|
|
|
5232
5251
|
});
|
|
5233
5252
|
fileServer = await createFileServer({
|
|
5234
5253
|
projectDir,
|
|
5235
|
-
compiledDir:
|
|
5254
|
+
compiledDir: join10(workDir, "compiled"),
|
|
5236
5255
|
port: 0,
|
|
5237
5256
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
5238
5257
|
fps: job.config.fps
|
|
@@ -5262,7 +5281,7 @@ async function runProbeStage(input) {
|
|
|
5262
5281
|
log.info("Creating capture session...", { attempt, maxAttempts: PROBE_MAX_ATTEMPTS });
|
|
5263
5282
|
probeSession = await createCaptureSession4(
|
|
5264
5283
|
fileServer.url,
|
|
5265
|
-
|
|
5284
|
+
join10(workDir, "probe"),
|
|
5266
5285
|
captureOpts,
|
|
5267
5286
|
null,
|
|
5268
5287
|
probeCfg
|
|
@@ -5347,7 +5366,7 @@ async function runProbeStage(input) {
|
|
|
5347
5366
|
});
|
|
5348
5367
|
probeSession = await createCaptureSession4(
|
|
5349
5368
|
fileServer.url,
|
|
5350
|
-
|
|
5369
|
+
join10(workDir, "probe-screenshot"),
|
|
5351
5370
|
captureOpts,
|
|
5352
5371
|
null,
|
|
5353
5372
|
{ ...probeCfg, forceScreenshot: true }
|
|
@@ -5385,7 +5404,7 @@ async function runProbeStage(input) {
|
|
|
5385
5404
|
compiled,
|
|
5386
5405
|
resolutions,
|
|
5387
5406
|
projectDir,
|
|
5388
|
-
|
|
5407
|
+
join10(workDir, "downloads")
|
|
5389
5408
|
);
|
|
5390
5409
|
assertNotAborted();
|
|
5391
5410
|
composition.videos = compiled.videos;
|
|
@@ -5576,7 +5595,7 @@ async function runProbeStage(input) {
|
|
|
5576
5595
|
}
|
|
5577
5596
|
await preflightCompositionAssetMediaTypes({
|
|
5578
5597
|
projectDir,
|
|
5579
|
-
compiledDir:
|
|
5598
|
+
compiledDir: join10(workDir, "compiled"),
|
|
5580
5599
|
composition,
|
|
5581
5600
|
signal: abortSignal
|
|
5582
5601
|
});
|
|
@@ -5742,8 +5761,8 @@ function validateDistributedDuration(input) {
|
|
|
5742
5761
|
}
|
|
5743
5762
|
|
|
5744
5763
|
// src/services/render/stages/extractVideosStage.ts
|
|
5745
|
-
import { existsSync as
|
|
5746
|
-
import { join as
|
|
5764
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
5765
|
+
import { join as join11 } from "node:path";
|
|
5747
5766
|
import {
|
|
5748
5767
|
classifyVideoExtractionError,
|
|
5749
5768
|
createFrameLookupTable as createFrameLookupTable3,
|
|
@@ -6017,7 +6036,7 @@ async function runExtractVideosStage(input) {
|
|
|
6017
6036
|
const probeFailures = await Promise.all(
|
|
6018
6037
|
composition.videos.map(async (v) => {
|
|
6019
6038
|
const videoPath = resolveProjectRelativeSrc3(v.src, projectDir, compiledDir);
|
|
6020
|
-
if (!
|
|
6039
|
+
if (!existsSync10(videoPath)) return null;
|
|
6021
6040
|
try {
|
|
6022
6041
|
const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata3(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata3(videoPath), {
|
|
6023
6042
|
signal: abortSignal,
|
|
@@ -6055,7 +6074,7 @@ async function runExtractVideosStage(input) {
|
|
|
6055
6074
|
const probed = await Promise.all(
|
|
6056
6075
|
composition.images.map(async (img) => {
|
|
6057
6076
|
const imgPath = resolveProjectRelativeSrc3(img.src, projectDir, compiledDir);
|
|
6058
|
-
if (!
|
|
6077
|
+
if (!existsSync10(imgPath)) return null;
|
|
6059
6078
|
const colorSpace = await probeColorSpaceSafely(imgPath, log);
|
|
6060
6079
|
if (isHdrColorSpace2(colorSpace)) {
|
|
6061
6080
|
nativeHdrImageIds.add(img.id);
|
|
@@ -6089,14 +6108,14 @@ async function runExtractVideosStage(input) {
|
|
|
6089
6108
|
// because short boundary counts can differ by one frame.
|
|
6090
6109
|
{
|
|
6091
6110
|
fps: job.config.fps,
|
|
6092
|
-
outputDir:
|
|
6111
|
+
outputDir: join11(compiledDir, "__hyperframes_video_frames"),
|
|
6093
6112
|
format: job.config.videoFrameFormat ?? "auto",
|
|
6094
6113
|
toneMapHdrToSdr: rendersSdrOnly(job.config, composition),
|
|
6095
6114
|
timelineEnd: composition.duration,
|
|
6096
6115
|
maxTransientRetries: extractionPolicy.maxTransientRetries,
|
|
6097
6116
|
collectProbeFailures: extractionPolicy.failureMode === "enforce",
|
|
6098
6117
|
deferRangeExtraction,
|
|
6099
|
-
contentKeyedDirs: [
|
|
6118
|
+
contentKeyedDirs: [join11(compiledDir, REMOTE_MEDIA_SUBDIR)],
|
|
6100
6119
|
urlByAbsentLocalPath,
|
|
6101
6120
|
onProgress: ({ planned = 0, done = 0 }) => {
|
|
6102
6121
|
framesPlanned += planned;
|
|
@@ -6175,7 +6194,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
6175
6194
|
videos.map(async (video) => {
|
|
6176
6195
|
const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc3(video.src, projectDir, compiledDir);
|
|
6177
6196
|
const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
|
|
6178
|
-
if (!isHttpUrl2(readFrom) && !
|
|
6197
|
+
if (!isHttpUrl2(readFrom) && !existsSync10(readFrom)) return null;
|
|
6179
6198
|
const metadata = await extractMediaMetadata3(readFrom);
|
|
6180
6199
|
const window2 = await resolveFinalFrameExtractionWindow2(
|
|
6181
6200
|
readFrom,
|
|
@@ -6203,8 +6222,8 @@ import {
|
|
|
6203
6222
|
} from "@hyperframes/engine";
|
|
6204
6223
|
|
|
6205
6224
|
// src/services/render/stages/audioStage.ts
|
|
6206
|
-
import { existsSync as
|
|
6207
|
-
import { join as
|
|
6225
|
+
import { existsSync as existsSync12 } from "node:fs";
|
|
6226
|
+
import { join as join14 } from "node:path";
|
|
6208
6227
|
import {
|
|
6209
6228
|
MIXED_AUDIO_FILENAME,
|
|
6210
6229
|
audioFailureDiagnostics,
|
|
@@ -6214,8 +6233,8 @@ import {
|
|
|
6214
6233
|
} from "@hyperframes/engine";
|
|
6215
6234
|
|
|
6216
6235
|
// src/services/render/audioDeliveryLimit.ts
|
|
6217
|
-
import { existsSync as
|
|
6218
|
-
import { dirname as dirname8, join as
|
|
6236
|
+
import { existsSync as existsSync11 } from "node:fs";
|
|
6237
|
+
import { dirname as dirname8, join as join13 } from "node:path";
|
|
6219
6238
|
import {
|
|
6220
6239
|
applyAudioFxChain,
|
|
6221
6240
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -6225,7 +6244,7 @@ import {
|
|
|
6225
6244
|
|
|
6226
6245
|
// src/services/render/audioPadTrim.ts
|
|
6227
6246
|
import { spawn } from "node:child_process";
|
|
6228
|
-
import { dirname as dirname7, join as
|
|
6247
|
+
import { dirname as dirname7, join as join12 } from "node:path";
|
|
6229
6248
|
import {
|
|
6230
6249
|
DEFAULT_CONFIG,
|
|
6231
6250
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -6505,7 +6524,7 @@ async function constrainAacTruePeak(input) {
|
|
|
6505
6524
|
}
|
|
6506
6525
|
async function cutSource(input, scratchDir, attenuationDb) {
|
|
6507
6526
|
if (!input.sourcePath || !input.rewriteSource) return true;
|
|
6508
|
-
const cutPath =
|
|
6527
|
+
const cutPath = join12(scratchDir, "source.wav");
|
|
6509
6528
|
try {
|
|
6510
6529
|
const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
|
|
6511
6530
|
if (!result.success) throw new Error(result.error);
|
|
@@ -6520,7 +6539,7 @@ async function enforceAacTruePeak(input) {
|
|
|
6520
6539
|
let scratchDir;
|
|
6521
6540
|
try {
|
|
6522
6541
|
scratchDir = createStagingDir3(dirname7(input.audioPath), ".true-peak-");
|
|
6523
|
-
const correctedPath =
|
|
6542
|
+
const correctedPath = join12(scratchDir, "audio.m4a");
|
|
6524
6543
|
const measurements = [];
|
|
6525
6544
|
let attenuationDb = 0;
|
|
6526
6545
|
let sourcePeakDbfs;
|
|
@@ -6723,14 +6742,14 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
6723
6742
|
applyChain: applyAudioFxChain,
|
|
6724
6743
|
encode: encodeAac2,
|
|
6725
6744
|
rename: renameWithRetry6,
|
|
6726
|
-
sourceExists:
|
|
6745
|
+
sourceExists: existsSync11
|
|
6727
6746
|
}) {
|
|
6728
6747
|
const { audioPath, sourcePath, signal, timeoutMs } = input;
|
|
6729
6748
|
if (!deps.sourceExists(sourcePath)) return { success: true };
|
|
6730
6749
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
6731
6750
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
6732
6751
|
const alternating = ["a", "b"].map(
|
|
6733
|
-
(k) =>
|
|
6752
|
+
(k) => join13(dirname8(sourcePath), `audio-source-limited-${k}.wav`)
|
|
6734
6753
|
);
|
|
6735
6754
|
let encodedFrom;
|
|
6736
6755
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -6802,7 +6821,7 @@ function runAudioStage(input) {
|
|
|
6802
6821
|
}
|
|
6803
6822
|
async function runAudioStageScoped(input) {
|
|
6804
6823
|
const stageStart = Date.now();
|
|
6805
|
-
const pcmSourcePath =
|
|
6824
|
+
const pcmSourcePath = join14(input.workDir, "audio-source.wav");
|
|
6806
6825
|
const duration = input.totalFrames * input.fps.den / input.fps.num;
|
|
6807
6826
|
let deliverySourcePath;
|
|
6808
6827
|
try {
|
|
@@ -6818,7 +6837,7 @@ async function runAudioStageScoped(input) {
|
|
|
6818
6837
|
);
|
|
6819
6838
|
audioLoweredDb = guard.loweredDb;
|
|
6820
6839
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
6821
|
-
if (input.keepDeliverySource && !guard.sourceStale &&
|
|
6840
|
+
if (input.keepDeliverySource && !guard.sourceStale && existsSync12(pcmSourcePath)) {
|
|
6822
6841
|
deliverySourcePath = pcmSourcePath;
|
|
6823
6842
|
}
|
|
6824
6843
|
}
|
|
@@ -6867,7 +6886,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
6867
6886
|
assertNotAborted,
|
|
6868
6887
|
log
|
|
6869
6888
|
} = input;
|
|
6870
|
-
const audioOutputPath =
|
|
6889
|
+
const audioOutputPath = join14(workDir, MIXED_AUDIO_FILENAME);
|
|
6871
6890
|
let hasAudio = false;
|
|
6872
6891
|
let audioError;
|
|
6873
6892
|
let audioFailures;
|
|
@@ -6878,7 +6897,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
6878
6897
|
audioResult = await processCompositionAudio(
|
|
6879
6898
|
audios,
|
|
6880
6899
|
projectDir,
|
|
6881
|
-
|
|
6900
|
+
join14(workDir, "audio-work"),
|
|
6882
6901
|
audioOutputPath,
|
|
6883
6902
|
duration,
|
|
6884
6903
|
abortSignal,
|
|
@@ -6946,8 +6965,8 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
6946
6965
|
}
|
|
6947
6966
|
|
|
6948
6967
|
// src/services/render/stages/captureStage.ts
|
|
6949
|
-
import { existsSync as
|
|
6950
|
-
import { join as
|
|
6968
|
+
import { existsSync as existsSync13, readdirSync, statfsSync } from "node:fs";
|
|
6969
|
+
import { join as join15 } from "node:path";
|
|
6951
6970
|
import {
|
|
6952
6971
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
6953
6972
|
frameFileExtension,
|
|
@@ -6998,16 +7017,16 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
|
|
|
6998
7017
|
}
|
|
6999
7018
|
function measureCaptureFrameBytes(workDir, framesDir) {
|
|
7000
7019
|
let total = sampleDirectoryBytes(framesDir);
|
|
7001
|
-
if (!
|
|
7020
|
+
if (!existsSync13(workDir)) return total;
|
|
7002
7021
|
for (const attempt of readdirSync(workDir)) {
|
|
7003
7022
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
7004
|
-
total += sampleDirectoryBytes(
|
|
7023
|
+
total += sampleDirectoryBytes(join15(workDir, attempt));
|
|
7005
7024
|
continue;
|
|
7006
7025
|
}
|
|
7007
7026
|
if (!/^capture-attempt-\d+$/.test(attempt)) continue;
|
|
7008
|
-
const attemptDir =
|
|
7027
|
+
const attemptDir = join15(workDir, attempt);
|
|
7009
7028
|
for (const name of readdirSync(attemptDir)) {
|
|
7010
|
-
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(
|
|
7029
|
+
if (/^worker-\d+$/.test(name)) total += sampleDirectoryBytes(join15(attemptDir, name));
|
|
7011
7030
|
}
|
|
7012
7031
|
}
|
|
7013
7032
|
return total;
|
|
@@ -7339,16 +7358,16 @@ import {
|
|
|
7339
7358
|
// src/services/render/stages/encodeStage.ts
|
|
7340
7359
|
import {
|
|
7341
7360
|
copyFileSync as copyFileSync4,
|
|
7342
|
-
existsSync as
|
|
7361
|
+
existsSync as existsSync14,
|
|
7343
7362
|
mkdirSync as mkdirSync5,
|
|
7344
7363
|
readdirSync as readdirSync2,
|
|
7345
|
-
readFileSync as
|
|
7364
|
+
readFileSync as readFileSync6,
|
|
7346
7365
|
rmSync as rmSync4,
|
|
7347
7366
|
statSync as statSync4,
|
|
7348
7367
|
writeFileSync as writeFileSync4
|
|
7349
7368
|
} from "node:fs";
|
|
7350
7369
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
7351
|
-
import { dirname as dirname9, join as
|
|
7370
|
+
import { dirname as dirname9, join as join16 } from "node:path";
|
|
7352
7371
|
import {
|
|
7353
7372
|
encodeFramesChunkedConcat,
|
|
7354
7373
|
encodeFramesFromDir,
|
|
@@ -7436,7 +7455,7 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
|
|
|
7436
7455
|
const error = formatFfmpegError(result.exitCode, result.stderr);
|
|
7437
7456
|
return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
|
|
7438
7457
|
}
|
|
7439
|
-
const gif =
|
|
7458
|
+
const gif = readFileSync6(outputPath);
|
|
7440
7459
|
if (!clearGifFramesBeforeNext(gif)) {
|
|
7441
7460
|
const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
|
|
7442
7461
|
return gifEncodeFailure(startTime, outputPath, error);
|
|
@@ -7469,11 +7488,11 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
7469
7488
|
return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
|
|
7470
7489
|
}
|
|
7471
7490
|
}
|
|
7472
|
-
if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(
|
|
7491
|
+
if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(readFileSync6(outputPath)) !== false) {
|
|
7473
7492
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
7474
7493
|
if (failure) return failure;
|
|
7475
7494
|
}
|
|
7476
|
-
const fileSize =
|
|
7495
|
+
const fileSize = existsSync14(outputPath) ? statSync4(outputPath).size : 0;
|
|
7477
7496
|
return {
|
|
7478
7497
|
success: true,
|
|
7479
7498
|
outputPath,
|
|
@@ -7559,7 +7578,7 @@ function encodeWhileCapturing(input, totalFrames) {
|
|
|
7559
7578
|
await new Promise((resolve10) => wake = resolve10);
|
|
7560
7579
|
}
|
|
7561
7580
|
if (signal.aborted) return;
|
|
7562
|
-
const mergedPath =
|
|
7581
|
+
const mergedPath = join16(input.framesDir, formatCaptureFrameName(next, "jpg"));
|
|
7563
7582
|
const frame = await readLandedFrame(landed.get(next), mergedPath);
|
|
7564
7583
|
landed.delete(next);
|
|
7565
7584
|
if (!await stream.writeFrame(frame)) {
|
|
@@ -7634,7 +7653,7 @@ async function runEncodeStage(input) {
|
|
|
7634
7653
|
const stage5Start = Date.now();
|
|
7635
7654
|
if (isPngSequence) {
|
|
7636
7655
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
7637
|
-
if (!
|
|
7656
|
+
if (!existsSync14(outputPath)) mkdirSync5(outputPath, { recursive: true });
|
|
7638
7657
|
const captured = readdirSync2(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
7639
7658
|
if (captured.length === 0) {
|
|
7640
7659
|
throw new Error(
|
|
@@ -7642,11 +7661,11 @@ async function runEncodeStage(input) {
|
|
|
7642
7661
|
);
|
|
7643
7662
|
}
|
|
7644
7663
|
captured.forEach((name, i) => {
|
|
7645
|
-
const dst =
|
|
7646
|
-
copyFileSync4(
|
|
7664
|
+
const dst = join16(outputPath, formatExportFrameName(i, "png"));
|
|
7665
|
+
copyFileSync4(join16(framesDir, name), dst);
|
|
7647
7666
|
});
|
|
7648
|
-
if (hasAudio && audioOutputPath &&
|
|
7649
|
-
copyFileSync4(audioOutputPath,
|
|
7667
|
+
if (hasAudio && audioOutputPath && existsSync14(audioOutputPath)) {
|
|
7668
|
+
copyFileSync4(audioOutputPath, join16(outputPath, MIXED_AUDIO_FILENAME2));
|
|
7650
7669
|
log.info(
|
|
7651
7670
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
7652
7671
|
);
|
|
@@ -7666,7 +7685,7 @@ async function runEncodeStage(input) {
|
|
|
7666
7685
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
7667
7686
|
fps: job.config.fps,
|
|
7668
7687
|
loop,
|
|
7669
|
-
palettePath:
|
|
7688
|
+
palettePath: join16(dirname9(videoOnlyPath), "gif-palette.png"),
|
|
7670
7689
|
preserveAlpha: needsAlpha,
|
|
7671
7690
|
signal: abortSignal,
|
|
7672
7691
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -7725,7 +7744,7 @@ function sampleDirectoryBytes(dir) {
|
|
|
7725
7744
|
continue;
|
|
7726
7745
|
}
|
|
7727
7746
|
for (const name of entries) {
|
|
7728
|
-
const full =
|
|
7747
|
+
const full = join17(current, name);
|
|
7729
7748
|
try {
|
|
7730
7749
|
const st = statSync5(full);
|
|
7731
7750
|
if (st.isDirectory()) {
|
|
@@ -7807,8 +7826,8 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
7807
7826
|
const ranges = [];
|
|
7808
7827
|
let rangeStart = null;
|
|
7809
7828
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
7810
|
-
const framePath =
|
|
7811
|
-
const missing = !
|
|
7829
|
+
const framePath = join17(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
7830
|
+
const missing = !existsSync15(framePath) || statSync5(framePath).size <= 8;
|
|
7812
7831
|
if (missing && rangeStart === null) {
|
|
7813
7832
|
rangeStart = frameIndex;
|
|
7814
7833
|
} else if (!missing && rangeStart !== null) {
|
|
@@ -7824,7 +7843,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
7824
7843
|
function buildMissingFrameRetryBatches(ranges, maxWorkers, workDir, attempt, rangeStart = 0, stride = 1) {
|
|
7825
7844
|
const workersPerBatch = Math.max(1, Math.floor(maxWorkers));
|
|
7826
7845
|
const batches = [];
|
|
7827
|
-
const outputDirFor = (batchIndex, workerId) =>
|
|
7846
|
+
const outputDirFor = (batchIndex, workerId) => join17(workDir, `retry-${attempt}-batch-${batchIndex}-worker-${workerId}`);
|
|
7828
7847
|
if (stride > 1) {
|
|
7829
7848
|
const spans = /* @__PURE__ */ new Map();
|
|
7830
7849
|
for (const range of ranges) {
|
|
@@ -7897,8 +7916,8 @@ function isRecoverableParallelCaptureError(error) {
|
|
|
7897
7916
|
function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
7898
7917
|
let captured = 0;
|
|
7899
7918
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
7900
|
-
const framePath =
|
|
7901
|
-
if (
|
|
7919
|
+
const framePath = join17(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
7920
|
+
if (existsSync15(framePath)) captured++;
|
|
7902
7921
|
}
|
|
7903
7922
|
return captured;
|
|
7904
7923
|
}
|
|
@@ -7923,7 +7942,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
7923
7942
|
reason: attempt === 0 ? "initial" : pendingTransientRetry ? "transient-retry" : "retry"
|
|
7924
7943
|
});
|
|
7925
7944
|
pendingTransientRetry = false;
|
|
7926
|
-
const attemptWorkDir =
|
|
7945
|
+
const attemptWorkDir = join17(options.workDir, `capture-attempt-${attempt}`);
|
|
7927
7946
|
const batches = missingRanges ? buildMissingFrameRetryBatches(
|
|
7928
7947
|
missingRanges,
|
|
7929
7948
|
currentWorkers,
|
|
@@ -8116,7 +8135,7 @@ function explainStreamingEncodeGate(cfg, outputFormat, workerCount, durationSeco
|
|
|
8116
8135
|
var DEFAULT_SEGMENTED_MIN_SECONDS = Number.POSITIVE_INFINITY;
|
|
8117
8136
|
|
|
8118
8137
|
// src/services/distributed/planFrameCost.ts
|
|
8119
|
-
import { join as
|
|
8138
|
+
import { join as join20 } from "node:path";
|
|
8120
8139
|
import {
|
|
8121
8140
|
closeCaptureSession as closeCaptureSession9,
|
|
8122
8141
|
createCaptureSession as createCaptureSession9,
|
|
@@ -8125,8 +8144,8 @@ import {
|
|
|
8125
8144
|
} from "@hyperframes/engine";
|
|
8126
8145
|
|
|
8127
8146
|
// src/services/distributed/chunkFrames.ts
|
|
8128
|
-
import { existsSync as
|
|
8129
|
-
import { extname as extname2, join as
|
|
8147
|
+
import { existsSync as existsSync17, readdirSync as readdirSync4 } from "node:fs";
|
|
8148
|
+
import { extname as extname2, join as join19 } from "node:path";
|
|
8130
8149
|
import {
|
|
8131
8150
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
8132
8151
|
createVideoFrameInjector as createVideoFrameInjector3
|
|
@@ -8134,8 +8153,8 @@ import {
|
|
|
8134
8153
|
|
|
8135
8154
|
// src/services/distributed/shared.ts
|
|
8136
8155
|
import { execFile as execFileCallback } from "node:child_process";
|
|
8137
|
-
import { dirname as dirname11, join as
|
|
8138
|
-
import { existsSync as
|
|
8156
|
+
import { dirname as dirname11, join as join18 } from "node:path";
|
|
8157
|
+
import { existsSync as existsSync16, readFileSync as readFileSync7 } from "node:fs";
|
|
8139
8158
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
8140
8159
|
import { promisify as promisify2 } from "node:util";
|
|
8141
8160
|
import {
|
|
@@ -8150,8 +8169,8 @@ function isPlanAudioArtifactPath(path) {
|
|
|
8150
8169
|
}
|
|
8151
8170
|
function resolvePlanAudioPath(planDir) {
|
|
8152
8171
|
for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
|
|
8153
|
-
const candidate =
|
|
8154
|
-
if (
|
|
8172
|
+
const candidate = join18(planDir, name);
|
|
8173
|
+
if (existsSync16(candidate)) return candidate;
|
|
8155
8174
|
}
|
|
8156
8175
|
return null;
|
|
8157
8176
|
}
|
|
@@ -8411,10 +8430,10 @@ function readProducerVersion() {
|
|
|
8411
8430
|
const startDir = dirname11(fileURLToPath3(import.meta.url));
|
|
8412
8431
|
let current = startDir;
|
|
8413
8432
|
for (let i = 0; i < 10; i++) {
|
|
8414
|
-
const candidate =
|
|
8415
|
-
if (
|
|
8433
|
+
const candidate = join18(current, "package.json");
|
|
8434
|
+
if (existsSync16(candidate)) {
|
|
8416
8435
|
try {
|
|
8417
|
-
const pkg = JSON.parse(
|
|
8436
|
+
const pkg = JSON.parse(readFileSync7(candidate, "utf-8"));
|
|
8418
8437
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
8419
8438
|
cachedProducerVersion = pkg.version;
|
|
8420
8439
|
return pkg.version;
|
|
@@ -8466,8 +8485,8 @@ function frameNumberFromFileName(name) {
|
|
|
8466
8485
|
function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
|
|
8467
8486
|
const result = [];
|
|
8468
8487
|
for (const v of videos) {
|
|
8469
|
-
const outputDir =
|
|
8470
|
-
if (!
|
|
8488
|
+
const outputDir = join19(planDir, "video-frames", v.videoId);
|
|
8489
|
+
if (!existsSync17(outputDir)) {
|
|
8471
8490
|
throw new Error(
|
|
8472
8491
|
`[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
|
|
8473
8492
|
);
|
|
@@ -8485,7 +8504,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
|
|
|
8485
8504
|
if (!frameName) continue;
|
|
8486
8505
|
const frameNumber = indexMode === "sparse-v2" ? frameNumberFromFileName(frameName) : null;
|
|
8487
8506
|
const frameIndex = frameNumber === null ? i : frameNumber - 1;
|
|
8488
|
-
framePaths.set(frameIndex,
|
|
8507
|
+
framePaths.set(frameIndex, join19(outputDir, frameName));
|
|
8489
8508
|
}
|
|
8490
8509
|
result.push({
|
|
8491
8510
|
videoId: v.videoId,
|
|
@@ -8565,8 +8584,8 @@ async function extractDeferredVideoFramesForChunk(input) {
|
|
|
8565
8584
|
sourceOf: (video) => {
|
|
8566
8585
|
const range = planned.get(video.videoId).deferredRange;
|
|
8567
8586
|
const remoteUrl = remoteSources[range.sourcePath];
|
|
8568
|
-
const sourcePath = remoteUrl ??
|
|
8569
|
-
if (remoteUrl === void 0 && !
|
|
8587
|
+
const sourcePath = remoteUrl ?? join19(input.planDir, ...range.sourcePath.split("/"));
|
|
8588
|
+
if (remoteUrl === void 0 && !existsSync17(sourcePath)) {
|
|
8570
8589
|
throw new RenderChunkValidationError(
|
|
8571
8590
|
MISSING_PLAN_ARTIFACT,
|
|
8572
8591
|
`[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
|
|
@@ -8596,12 +8615,12 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
8596
8615
|
planVideos,
|
|
8597
8616
|
frames: sampled,
|
|
8598
8617
|
fps: fpsRatio,
|
|
8599
|
-
outputRoot:
|
|
8618
|
+
outputRoot: join20(workDir, "frame-cost-video-frames"),
|
|
8600
8619
|
cfg: input.cfg
|
|
8601
8620
|
})
|
|
8602
8621
|
];
|
|
8603
8622
|
const lookup = extracted.length > 0 ? createFrameLookupTable4(planVideos.videos, extracted, resolveRenderFpsConfig(fpsRatio).value) : null;
|
|
8604
|
-
const compiledDir =
|
|
8623
|
+
const compiledDir = join20(planDir, "compiled");
|
|
8605
8624
|
const fileServer = await createFileServer({
|
|
8606
8625
|
projectDir: compiledDir,
|
|
8607
8626
|
compiledDir,
|
|
@@ -8613,7 +8632,7 @@ async function measurePlanSecondsPerFrame(input) {
|
|
|
8613
8632
|
try {
|
|
8614
8633
|
session = await createCaptureSession9(
|
|
8615
8634
|
fileServer.url,
|
|
8616
|
-
|
|
8635
|
+
join20(workDir, "frame-cost"),
|
|
8617
8636
|
buildChunkCaptureOptions({
|
|
8618
8637
|
dimensions: { ...input, fpsNum: fps, fpsDen: 1 },
|
|
8619
8638
|
encoder: input,
|
|
@@ -8710,7 +8729,7 @@ function buildWeightedChunkSlices(weights, chunkCount, minFrames, maxFrames) {
|
|
|
8710
8729
|
}
|
|
8711
8730
|
|
|
8712
8731
|
// src/services/render/planReferenceBackground.ts
|
|
8713
|
-
import { join as
|
|
8732
|
+
import { join as join21 } from "node:path";
|
|
8714
8733
|
import {
|
|
8715
8734
|
closeCaptureSession as closeCaptureSession10,
|
|
8716
8735
|
createCaptureSession as createCaptureSession10,
|
|
@@ -8723,14 +8742,14 @@ async function readPlanReferenceBackground(input) {
|
|
|
8723
8742
|
try {
|
|
8724
8743
|
server = await createFileServer({
|
|
8725
8744
|
projectDir: input.projectDir,
|
|
8726
|
-
compiledDir:
|
|
8745
|
+
compiledDir: join21(input.workDir, "compiled"),
|
|
8727
8746
|
port: 0,
|
|
8728
8747
|
preHeadScripts: [VIRTUAL_TIME_SHIM],
|
|
8729
8748
|
fps: input.options.fps
|
|
8730
8749
|
});
|
|
8731
8750
|
session = await createCaptureSession10(
|
|
8732
8751
|
server.url,
|
|
8733
|
-
|
|
8752
|
+
join21(input.workDir, "reference"),
|
|
8734
8753
|
{
|
|
8735
8754
|
...input.options,
|
|
8736
8755
|
requiresWebGpu: false
|
|
@@ -8766,8 +8785,8 @@ async function readPlanReferenceBackground(input) {
|
|
|
8766
8785
|
}
|
|
8767
8786
|
|
|
8768
8787
|
// src/services/render/stages/freezePlan.ts
|
|
8769
|
-
import { existsSync as
|
|
8770
|
-
import { join as
|
|
8788
|
+
import { existsSync as existsSync18, mkdirSync as mkdirSync7, readFileSync as readFileSync8, readdirSync as readdirSync5, writeFileSync as writeFileSync6 } from "node:fs";
|
|
8789
|
+
import { join as join22, relative as relative3, resolve as resolve8 } from "node:path";
|
|
8771
8790
|
import {
|
|
8772
8791
|
REFERENCE_BACKGROUND_FIELD,
|
|
8773
8792
|
referenceBackgroundResult as referenceBackgroundResult3
|
|
@@ -8960,7 +8979,7 @@ function planFileSha256(absolutePath, digests) {
|
|
|
8960
8979
|
return sha256;
|
|
8961
8980
|
}
|
|
8962
8981
|
async function prehashPlanFiles(dir, digests) {
|
|
8963
|
-
if (!
|
|
8982
|
+
if (!existsSync18(dir)) return;
|
|
8964
8983
|
for (const { absolutePath } of listPlanFiles(dir)) {
|
|
8965
8984
|
if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
|
|
8966
8985
|
}
|
|
@@ -8985,7 +9004,7 @@ function listPlanFiles(planDir) {
|
|
|
8985
9004
|
function walk(dir) {
|
|
8986
9005
|
const entries = readdirSync5(dir, { withFileTypes: true });
|
|
8987
9006
|
for (const entry of entries) {
|
|
8988
|
-
const full =
|
|
9007
|
+
const full = join22(dir, entry.name);
|
|
8989
9008
|
if (entry.isDirectory()) {
|
|
8990
9009
|
walk(full);
|
|
8991
9010
|
} else if (entry.isFile()) {
|
|
@@ -9006,7 +9025,7 @@ function collectPlanAssetShas(planDir, digests) {
|
|
|
9006
9025
|
const assets = [];
|
|
9007
9026
|
for (const file of files) {
|
|
9008
9027
|
if (file.planRelativePath === COMPILED_INDEX_RELATIVE_PATH) {
|
|
9009
|
-
compositionHtml =
|
|
9028
|
+
compositionHtml = readFileSync8(file.absolutePath);
|
|
9010
9029
|
continue;
|
|
9011
9030
|
}
|
|
9012
9031
|
if (HASH_EXCLUDED_PLAN_FILES.has(file.planRelativePath)) continue;
|
|
@@ -9026,23 +9045,23 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
|
|
|
9026
9045
|
function writePlanRemoteFiles(planDir, files) {
|
|
9027
9046
|
if (files.length === 0) return;
|
|
9028
9047
|
const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
|
|
9029
|
-
writeFileSync6(
|
|
9048
|
+
writeFileSync6(join22(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
|
|
9030
9049
|
}
|
|
9031
9050
|
function readPlanRemoteFiles(planDir) {
|
|
9032
|
-
const path =
|
|
9033
|
-
return
|
|
9051
|
+
const path = join22(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
|
|
9052
|
+
return existsSync18(path) ? JSON.parse(readFileSync8(path, "utf-8")) : [];
|
|
9034
9053
|
}
|
|
9035
9054
|
function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
9036
|
-
const planJsonPath =
|
|
9037
|
-
const encoderJsonPath =
|
|
9038
|
-
if (!
|
|
9055
|
+
const planJsonPath = join22(planDir, "plan.json");
|
|
9056
|
+
const encoderJsonPath = join22(planDir, "meta", "encoder.json");
|
|
9057
|
+
if (!existsSync18(planJsonPath)) {
|
|
9039
9058
|
throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
|
|
9040
9059
|
}
|
|
9041
|
-
if (!
|
|
9060
|
+
if (!existsSync18(encoderJsonPath)) {
|
|
9042
9061
|
throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
|
|
9043
9062
|
}
|
|
9044
|
-
const planJson = JSON.parse(
|
|
9045
|
-
const encoderConfigCanonicalJson =
|
|
9063
|
+
const planJson = JSON.parse(readFileSync8(planJsonPath, "utf-8"));
|
|
9064
|
+
const encoderConfigCanonicalJson = readFileSync8(encoderJsonPath, "utf-8");
|
|
9046
9065
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
9047
9066
|
return computePlanHash({
|
|
9048
9067
|
compositionHtml,
|
|
@@ -9068,21 +9087,21 @@ async function freezePlan(input) {
|
|
|
9068
9087
|
hasAudio,
|
|
9069
9088
|
digests
|
|
9070
9089
|
} = input;
|
|
9071
|
-
if (!
|
|
9090
|
+
if (!existsSync18(planDir)) {
|
|
9072
9091
|
throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
|
|
9073
9092
|
}
|
|
9074
|
-
const metaDir =
|
|
9075
|
-
if (!
|
|
9093
|
+
const metaDir = join22(planDir, "meta");
|
|
9094
|
+
if (!existsSync18(metaDir)) mkdirSync7(metaDir, { recursive: true });
|
|
9076
9095
|
writeFileSync6(
|
|
9077
|
-
|
|
9096
|
+
join22(metaDir, "composition.json"),
|
|
9078
9097
|
`${JSON.stringify(composition, null, 2)}
|
|
9079
9098
|
`,
|
|
9080
9099
|
"utf-8"
|
|
9081
9100
|
);
|
|
9082
9101
|
const encoderForCanonical = stripUndefined(encoder);
|
|
9083
9102
|
const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
|
|
9084
|
-
writeFileSync6(
|
|
9085
|
-
writeFileSync6(
|
|
9103
|
+
writeFileSync6(join22(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
|
|
9104
|
+
writeFileSync6(join22(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
|
|
9086
9105
|
`, "utf-8");
|
|
9087
9106
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
9088
9107
|
const planHash = computePlanHash({
|
|
@@ -9107,7 +9126,7 @@ async function freezePlan(input) {
|
|
|
9107
9126
|
duration: durationSeconds,
|
|
9108
9127
|
hasAudio
|
|
9109
9128
|
};
|
|
9110
|
-
const planJsonPath =
|
|
9129
|
+
const planJsonPath = join22(planDir, "plan.json");
|
|
9111
9130
|
writeFileSync6(planJsonPath, `${JSON.stringify(planJson, null, 2)}
|
|
9112
9131
|
`, "utf-8");
|
|
9113
9132
|
return { planJsonPath, planHash };
|
|
@@ -9149,16 +9168,16 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
|
|
|
9149
9168
|
}
|
|
9150
9169
|
|
|
9151
9170
|
// src/services/distributed/chunkAudio.ts
|
|
9152
|
-
import { closeSync as closeSync4, existsSync as
|
|
9171
|
+
import { closeSync as closeSync4, existsSync as existsSync19, ftruncateSync, mkdirSync as mkdirSync9, openSync as openSync4, readFileSync as readFileSync9 } from "node:fs";
|
|
9153
9172
|
import { writeFileSync as writeFileSync7, writeSync } from "node:fs";
|
|
9154
|
-
import { join as
|
|
9173
|
+
import { join as join24 } from "node:path";
|
|
9155
9174
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
9156
9175
|
|
|
9157
9176
|
// src/services/distributed/mp4Stitch.ts
|
|
9158
9177
|
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync8, rmSync as rmSync6 } from "node:fs";
|
|
9159
9178
|
import { open } from "node:fs/promises";
|
|
9160
9179
|
import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
|
|
9161
|
-
import { basename as basename5, dirname as dirname12, join as
|
|
9180
|
+
import { basename as basename5, dirname as dirname12, join as join23 } from "node:path";
|
|
9162
9181
|
import { finished, pipeline } from "node:stream/promises";
|
|
9163
9182
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
9164
9183
|
function boxAt(src, off, at, limit) {
|
|
@@ -9525,13 +9544,13 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
9525
9544
|
const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
|
|
9526
9545
|
mkdirSync8(dirname12(outputPath), { recursive: true });
|
|
9527
9546
|
const workDir = createStagingDir4(dirname12(outputPath), `${basename5(outputPath)}.stitch-`);
|
|
9528
|
-
const out = createWriteStream(
|
|
9547
|
+
const out = createWriteStream(join23(workDir, "out.mp4"));
|
|
9529
9548
|
try {
|
|
9530
9549
|
out.write(header);
|
|
9531
9550
|
for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
|
|
9532
9551
|
out.end();
|
|
9533
9552
|
await finished(out);
|
|
9534
|
-
renameWithRetry7(
|
|
9553
|
+
renameWithRetry7(join23(workDir, "out.mp4"), outputPath);
|
|
9535
9554
|
} finally {
|
|
9536
9555
|
out.destroy();
|
|
9537
9556
|
rmSync6(workDir, { recursive: true, force: true });
|
|
@@ -9623,9 +9642,9 @@ async function writeChunkAudioSlices(input) {
|
|
|
9623
9642
|
offset += track.sizes[offsets.length - 1];
|
|
9624
9643
|
}
|
|
9625
9644
|
});
|
|
9626
|
-
const bytes =
|
|
9645
|
+
const bytes = readFileSync9(input.audioPath);
|
|
9627
9646
|
const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
|
|
9628
|
-
mkdirSync9(
|
|
9647
|
+
mkdirSync9(join24(input.planDir, SLICE_DIR), { recursive: true });
|
|
9629
9648
|
input.chunks.forEach((_, index) => {
|
|
9630
9649
|
const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
|
|
9631
9650
|
if (!cut) return;
|
|
@@ -9633,17 +9652,17 @@ async function writeChunkAudioSlices(input) {
|
|
|
9633
9652
|
const start = offsets[cut.firstPacket];
|
|
9634
9653
|
layout.partStarts[index] = start;
|
|
9635
9654
|
const end = offsets[last] + track.sizes[last];
|
|
9636
|
-
writeFileSync7(
|
|
9655
|
+
writeFileSync7(join24(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
|
|
9637
9656
|
});
|
|
9638
9657
|
const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
|
|
9639
|
-
writeFileSync7(
|
|
9640
|
-
writeFileSync7(
|
|
9658
|
+
writeFileSync7(join24(input.planDir, SLICE_FRAME), Buffer.concat(frame));
|
|
9659
|
+
writeFileSync7(join24(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
|
|
9641
9660
|
}
|
|
9642
9661
|
function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
9643
|
-
const layoutPath =
|
|
9644
|
-
if (!
|
|
9645
|
-
const layout = JSON.parse(
|
|
9646
|
-
const frame =
|
|
9662
|
+
const layoutPath = join24(planDir, SLICE_LAYOUT);
|
|
9663
|
+
if (!existsSync19(layoutPath)) return resolvePlanAudioPath(planDir);
|
|
9664
|
+
const layout = JSON.parse(readFileSync9(layoutPath, "utf-8"));
|
|
9665
|
+
const frame = readFileSync9(join24(planDir, SLICE_FRAME));
|
|
9647
9666
|
const fd = openSync4(scratchPath, "w");
|
|
9648
9667
|
try {
|
|
9649
9668
|
writeSync(fd, frame, 0, layout.payloadStart, 0);
|
|
@@ -9656,7 +9675,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
|
9656
9675
|
);
|
|
9657
9676
|
const start = layout.partStarts[chunkIndex];
|
|
9658
9677
|
if (start !== void 0) {
|
|
9659
|
-
const part =
|
|
9678
|
+
const part = readFileSync9(join24(planDir, chunkAudioSlicePath(chunkIndex)));
|
|
9660
9679
|
writeSync(fd, part, 0, part.length, start);
|
|
9661
9680
|
}
|
|
9662
9681
|
ftruncateSync(fd, layout.sizeBytes);
|
|
@@ -9712,7 +9731,7 @@ async function muxChunkWithAudio(input) {
|
|
|
9712
9731
|
// src/services/distributed/planSize.ts
|
|
9713
9732
|
import { createHash as createHash7 } from "node:crypto";
|
|
9714
9733
|
import { lstatSync, readdirSync as readdirSync6 } from "node:fs";
|
|
9715
|
-
import { extname as extname3, join as
|
|
9734
|
+
import { extname as extname3, join as join25, relative as relative4 } from "node:path";
|
|
9716
9735
|
var MAX_TOP_COMPONENTS = 10;
|
|
9717
9736
|
var SOURCE_MEDIA_EXTENSIONS = /* @__PURE__ */ new Set([
|
|
9718
9737
|
".aac",
|
|
@@ -9824,7 +9843,7 @@ function walkRegularFiles(dir, visit) {
|
|
|
9824
9843
|
return;
|
|
9825
9844
|
}
|
|
9826
9845
|
for (const entry of entries) {
|
|
9827
|
-
const full =
|
|
9846
|
+
const full = join25(dir, entry.name);
|
|
9828
9847
|
if (entry.isDirectory()) {
|
|
9829
9848
|
walkRegularFiles(full, visit);
|
|
9830
9849
|
} else if (entry.isFile()) {
|
|
@@ -10044,13 +10063,13 @@ function assertPositiveInteger(name, value) {
|
|
|
10044
10063
|
}
|
|
10045
10064
|
var FREEZE_OWNED_PLAN_FILES = [
|
|
10046
10065
|
"plan.json",
|
|
10047
|
-
|
|
10048
|
-
|
|
10049
|
-
|
|
10066
|
+
join26("meta", "composition.json"),
|
|
10067
|
+
join26("meta", "encoder.json"),
|
|
10068
|
+
join26("meta", "chunks.json")
|
|
10050
10069
|
];
|
|
10051
10070
|
function removeFreezeOwnedPlanFiles(planDir) {
|
|
10052
10071
|
for (const relativePath of FREEZE_OWNED_PLAN_FILES) {
|
|
10053
|
-
rmSync7(
|
|
10072
|
+
rmSync7(join26(planDir, relativePath), { force: true });
|
|
10054
10073
|
}
|
|
10055
10074
|
}
|
|
10056
10075
|
function buildChunkSlices(totalFrames, chunkCount, effectiveChunkSize) {
|
|
@@ -10205,19 +10224,19 @@ function createVideoSourceShipper(input) {
|
|
|
10205
10224
|
const known = shipped.get(srcPath);
|
|
10206
10225
|
if (known) return known;
|
|
10207
10226
|
const stagedRel = pathInside(input.workVideoFramesDir, srcPath);
|
|
10208
|
-
const current = stagedRel === null ? srcPath :
|
|
10227
|
+
const current = stagedRel === null ? srcPath : join26(input.planDir, "video-frames", stagedRel);
|
|
10209
10228
|
let result = null;
|
|
10210
10229
|
for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
|
|
10211
10230
|
const rel = pathInside(root, srcPath);
|
|
10212
|
-
if (rel !== null && (
|
|
10231
|
+
if (rel !== null && (existsSync20(join26(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
|
|
10213
10232
|
result = ["compiled", ...rel.split(sep3)].join("/");
|
|
10214
10233
|
break;
|
|
10215
10234
|
}
|
|
10216
10235
|
}
|
|
10217
10236
|
if (result === null) {
|
|
10218
10237
|
result = `video-sources/${shipped.size}${extname4(current)}`;
|
|
10219
|
-
const destination =
|
|
10220
|
-
mkdirSync10(
|
|
10238
|
+
const destination = join26(input.planDir, ...result.split("/"));
|
|
10239
|
+
mkdirSync10(join26(input.planDir, "video-sources"), { recursive: true });
|
|
10221
10240
|
try {
|
|
10222
10241
|
linkSync(current, destination);
|
|
10223
10242
|
} catch {
|
|
@@ -10237,7 +10256,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
10237
10256
|
useGpu: false,
|
|
10238
10257
|
browserGpuMode: "software"
|
|
10239
10258
|
});
|
|
10240
|
-
if (!
|
|
10259
|
+
if (!existsSync20(planDir)) mkdirSync10(planDir, { recursive: true });
|
|
10241
10260
|
const log = config.logger ?? defaultLogger;
|
|
10242
10261
|
const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
|
|
10243
10262
|
const abortSignal = config.abortSignal;
|
|
@@ -10267,14 +10286,14 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
10267
10286
|
pageMotionBlur: config.pageMotionBlur
|
|
10268
10287
|
});
|
|
10269
10288
|
const entryFile = config.entryFile ?? "index.html";
|
|
10270
|
-
const htmlPath =
|
|
10271
|
-
if (!
|
|
10289
|
+
const htmlPath = join26(projectDir, entryFile);
|
|
10290
|
+
if (!existsSync20(htmlPath)) {
|
|
10272
10291
|
throw new Error(`[plan] entry file not found: ${htmlPath}`);
|
|
10273
10292
|
}
|
|
10274
|
-
const workDir =
|
|
10293
|
+
const workDir = join26(planDir, ".plan-work");
|
|
10275
10294
|
rmSync7(workDir, { recursive: true, force: true });
|
|
10276
10295
|
mkdirSync10(workDir, { recursive: true });
|
|
10277
|
-
const compiledDir =
|
|
10296
|
+
const compiledDir = join26(workDir, "compiled");
|
|
10278
10297
|
mkdirSync10(compiledDir, { recursive: true });
|
|
10279
10298
|
let stageStarted = Date.now();
|
|
10280
10299
|
cpSync2(projectDir, compiledDir, {
|
|
@@ -10288,10 +10307,10 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
10288
10307
|
}
|
|
10289
10308
|
});
|
|
10290
10309
|
logPlanStage(log, "copy", stageStarted);
|
|
10291
|
-
const finalCompiledDir =
|
|
10310
|
+
const finalCompiledDir = join26(planDir, "compiled");
|
|
10292
10311
|
const needsAlpha = outputNeedsAlpha(config.format);
|
|
10293
10312
|
const remoteFiles = Object.entries(options.remoteFiles ?? {});
|
|
10294
|
-
const remoteLocalPath = (rel) =>
|
|
10313
|
+
const remoteLocalPath = (rel) => join26(projectDir, ...rel.split("/"));
|
|
10295
10314
|
for (const [, file] of remoteFiles) {
|
|
10296
10315
|
declareContentAddressedUrl(file.url, file.sha256);
|
|
10297
10316
|
if (file.probeFactsUrl) declareProbeFactsUrl(file.url, file.probeFactsUrl);
|
|
@@ -10494,17 +10513,17 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
10494
10513
|
let stageStarted = Date.now();
|
|
10495
10514
|
const extractResult = await extractPlanVideos(c, options.deferVideoExtraction);
|
|
10496
10515
|
logPlanStage(log, "extract", stageStarted);
|
|
10497
|
-
const stagedVideoFrames =
|
|
10498
|
-
const videoFramesDst =
|
|
10499
|
-
if (
|
|
10500
|
-
const videoSourcesDir =
|
|
10516
|
+
const stagedVideoFrames = join26(compiledDir, "__hyperframes_video_frames");
|
|
10517
|
+
const videoFramesDst = join26(planDir, "video-frames");
|
|
10518
|
+
if (existsSync20(videoFramesDst)) rmSync7(videoFramesDst, { recursive: true, force: true });
|
|
10519
|
+
const videoSourcesDir = join26(planDir, "video-sources");
|
|
10501
10520
|
rmSync7(videoSourcesDir, { recursive: true, force: true });
|
|
10502
|
-
if (
|
|
10521
|
+
if (existsSync20(stagedVideoFrames)) {
|
|
10503
10522
|
renameWithRetry8(stagedVideoFrames, videoFramesDst);
|
|
10504
10523
|
} else {
|
|
10505
10524
|
mkdirSync10(videoFramesDst, { recursive: true });
|
|
10506
10525
|
}
|
|
10507
|
-
if (
|
|
10526
|
+
if (existsSync20(finalCompiledDir)) rmSync7(finalCompiledDir, { recursive: true, force: true });
|
|
10508
10527
|
renameWithRetry8(compiledDir, finalCompiledDir);
|
|
10509
10528
|
const shipVideoSource = createVideoSourceShipper({
|
|
10510
10529
|
planDir,
|
|
@@ -10534,7 +10553,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
10534
10553
|
};
|
|
10535
10554
|
})
|
|
10536
10555
|
});
|
|
10537
|
-
mkdirSync10(
|
|
10556
|
+
mkdirSync10(join26(planDir, "meta"), { recursive: true });
|
|
10538
10557
|
writePlanRemoteFiles(
|
|
10539
10558
|
planDir,
|
|
10540
10559
|
remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
|
|
@@ -10544,7 +10563,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
10544
10563
|
}))
|
|
10545
10564
|
);
|
|
10546
10565
|
writeFileSync8(
|
|
10547
|
-
|
|
10566
|
+
join26(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
|
|
10548
10567
|
JSON.stringify(planVideosJson, null, 2),
|
|
10549
10568
|
"utf-8"
|
|
10550
10569
|
);
|
|
@@ -10624,11 +10643,11 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
10624
10643
|
if (audioResult?.audioError) {
|
|
10625
10644
|
applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
|
|
10626
10645
|
}
|
|
10627
|
-
const planAudioPath =
|
|
10628
|
-
if (audioResult?.hasAudio &&
|
|
10646
|
+
const planAudioPath = join26(planDir, PLAN_AUDIO_RELATIVE_PATH);
|
|
10647
|
+
if (audioResult?.hasAudio && existsSync20(audioResult.audioOutputPath)) {
|
|
10629
10648
|
renameWithRetry8(audioResult.audioOutputPath, planAudioPath);
|
|
10630
10649
|
}
|
|
10631
|
-
if (chunksCarryAudio &&
|
|
10650
|
+
if (chunksCarryAudio && existsSync20(planAudioPath)) {
|
|
10632
10651
|
if (options.sliceChunkAudio) {
|
|
10633
10652
|
stageStarted = Date.now();
|
|
10634
10653
|
await writeChunkAudioSlices({
|
|
@@ -10741,7 +10760,7 @@ async function buildPlanAudio(projectDir, config, workRoot, outputPath, options
|
|
|
10741
10760
|
if (mixed.audioError) {
|
|
10742
10761
|
applyDistributedAudioWarningPolicy(c.job, mixed.audioError, mixed.audioFailures, c.log);
|
|
10743
10762
|
}
|
|
10744
|
-
if (!mixed.hasAudio || !
|
|
10763
|
+
if (!mixed.hasAudio || !existsSync20(mixed.audioOutputPath)) return { hasAudio: false };
|
|
10745
10764
|
renameWithRetry8(mixed.audioOutputPath, outputPath);
|
|
10746
10765
|
return { hasAudio: true };
|
|
10747
10766
|
} finally {
|
|
@@ -10756,24 +10775,24 @@ import {
|
|
|
10756
10775
|
} from "@hyperframes/engine";
|
|
10757
10776
|
import {
|
|
10758
10777
|
copyFileSync as copyFileSync8,
|
|
10759
|
-
existsSync as
|
|
10778
|
+
existsSync as existsSync22,
|
|
10760
10779
|
lstatSync as lstatSync2,
|
|
10761
10780
|
mkdirSync as mkdirSync12,
|
|
10762
|
-
readFileSync as
|
|
10781
|
+
readFileSync as readFileSync10,
|
|
10763
10782
|
readdirSync as readdirSync7,
|
|
10764
10783
|
rmSync as rmSync9,
|
|
10765
10784
|
statSync as statSync7,
|
|
10766
10785
|
writeFileSync as writeFileSync10
|
|
10767
10786
|
} from "node:fs";
|
|
10768
10787
|
import { tmpdir } from "node:os";
|
|
10769
|
-
import { dirname as dirname14, isAbsolute as isAbsolute4, join as
|
|
10788
|
+
import { dirname as dirname14, isAbsolute as isAbsolute4, join as join29, relative as relative6, resolve as resolve9, sep as sep4 } from "node:path";
|
|
10770
10789
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
10771
10790
|
import { createFrameLookupTable as createFrameLookupTable5, renameWithRetry as renameWithRetry10 } from "@hyperframes/engine";
|
|
10772
10791
|
|
|
10773
10792
|
// src/services/distributed/planV2Publisher.ts
|
|
10774
10793
|
import {
|
|
10775
10794
|
copyFileSync as copyFileSync7,
|
|
10776
|
-
existsSync as
|
|
10795
|
+
existsSync as existsSync21,
|
|
10777
10796
|
linkSync as linkSync2,
|
|
10778
10797
|
mkdirSync as mkdirSync11,
|
|
10779
10798
|
rmSync as rmSync8,
|
|
@@ -10781,7 +10800,7 @@ import {
|
|
|
10781
10800
|
writeFileSync as writeFileSync9
|
|
10782
10801
|
} from "node:fs";
|
|
10783
10802
|
import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
|
|
10784
|
-
import { dirname as dirname13, join as
|
|
10803
|
+
import { dirname as dirname13, join as join28 } from "node:path";
|
|
10785
10804
|
|
|
10786
10805
|
// src/services/distributed/planV2Errors.ts
|
|
10787
10806
|
var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
|
|
@@ -10796,7 +10815,7 @@ var PlanV2IntegrityError = class extends Error {
|
|
|
10796
10815
|
};
|
|
10797
10816
|
|
|
10798
10817
|
// src/services/distributed/planV2Layout.ts
|
|
10799
|
-
import { join as
|
|
10818
|
+
import { join as join27 } from "node:path";
|
|
10800
10819
|
var SHA256_PATTERN = /^[0-9a-f]{64}$/;
|
|
10801
10820
|
function assertPlanV2Sha256(value, field) {
|
|
10802
10821
|
if (typeof value !== "string" || !SHA256_PATTERN.test(value)) {
|
|
@@ -10806,7 +10825,7 @@ function assertPlanV2Sha256(value, field) {
|
|
|
10806
10825
|
}
|
|
10807
10826
|
function planV2BlobPath(root, sha256) {
|
|
10808
10827
|
const digest = assertPlanV2Sha256(sha256, "artifact sha256");
|
|
10809
|
-
return
|
|
10828
|
+
return join27(root, "artifacts", "sha256", digest.slice(0, 2), digest);
|
|
10810
10829
|
}
|
|
10811
10830
|
|
|
10812
10831
|
// src/services/distributed/planV2Publisher.ts
|
|
@@ -10842,7 +10861,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
10842
10861
|
#linkFile;
|
|
10843
10862
|
#committed = false;
|
|
10844
10863
|
constructor(destinationDir, options = {}) {
|
|
10845
|
-
if (
|
|
10864
|
+
if (existsSync21(destinationDir)) {
|
|
10846
10865
|
throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
|
|
10847
10866
|
}
|
|
10848
10867
|
this.destinationDir = destinationDir;
|
|
@@ -10859,10 +10878,10 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
10859
10878
|
);
|
|
10860
10879
|
}
|
|
10861
10880
|
const destinationPath = planV2BlobPath(this.temporaryDir, digest);
|
|
10862
|
-
if (
|
|
10881
|
+
if (existsSync21(destinationPath)) return;
|
|
10863
10882
|
mkdirSync11(dirname13(destinationPath), { recursive: true });
|
|
10864
10883
|
const stagingDir = createStagingDir5(dirname13(destinationPath), ".plan-v2-blob-");
|
|
10865
|
-
const temporaryPath =
|
|
10884
|
+
const temporaryPath = join28(stagingDir, "blob");
|
|
10866
10885
|
try {
|
|
10867
10886
|
try {
|
|
10868
10887
|
this.#linkFile(blob.sourcePath, temporaryPath);
|
|
@@ -10877,13 +10896,13 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
10877
10896
|
}
|
|
10878
10897
|
async commitManifest(manifestBytes) {
|
|
10879
10898
|
for (const digest of new Set(manifestDigests(manifestBytes))) {
|
|
10880
|
-
if (!
|
|
10899
|
+
if (!existsSync21(planV2BlobPath(this.temporaryDir, digest))) {
|
|
10881
10900
|
throw new PlanV2IntegrityError(
|
|
10882
10901
|
`cannot commit manifest before referenced blob is durable: ${digest}`
|
|
10883
10902
|
);
|
|
10884
10903
|
}
|
|
10885
10904
|
}
|
|
10886
|
-
writeFileSync9(
|
|
10905
|
+
writeFileSync9(join28(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
|
|
10887
10906
|
renameWithRetry9(this.temporaryDir, this.destinationDir);
|
|
10888
10907
|
this.#committed = true;
|
|
10889
10908
|
}
|
|
@@ -10909,7 +10928,7 @@ function isNonNegativeIntegerArray(value) {
|
|
|
10909
10928
|
return Array.isArray(value) && value.every((item) => typeof item === "number" && Number.isInteger(item) && item >= 0);
|
|
10910
10929
|
}
|
|
10911
10930
|
function readJsonFile(path, label) {
|
|
10912
|
-
const contents =
|
|
10931
|
+
const contents = readFileSync10(path, "utf-8");
|
|
10913
10932
|
try {
|
|
10914
10933
|
const parsed = JSON.parse(contents);
|
|
10915
10934
|
return parsed;
|
|
@@ -10929,7 +10948,7 @@ function listFiles(root) {
|
|
|
10929
10948
|
const rootResolved = resolve9(root);
|
|
10930
10949
|
function walk(dir) {
|
|
10931
10950
|
for (const entry of readdirSync7(dir, { withFileTypes: true })) {
|
|
10932
|
-
const absolutePath =
|
|
10951
|
+
const absolutePath = join29(dir, entry.name);
|
|
10933
10952
|
if (entry.isDirectory()) {
|
|
10934
10953
|
walk(absolutePath);
|
|
10935
10954
|
} else if (entry.isFile()) {
|
|
@@ -10956,13 +10975,13 @@ function assertValidExtractionCacheCompleteSentinel(path) {
|
|
|
10956
10975
|
}
|
|
10957
10976
|
}
|
|
10958
10977
|
function validateExtractionCacheCompleteSentinels(executionPlanDir) {
|
|
10959
|
-
const videoRoot =
|
|
10960
|
-
if (!
|
|
10978
|
+
const videoRoot = join29(executionPlanDir, "video-frames");
|
|
10979
|
+
if (!existsSync22(videoRoot)) return;
|
|
10961
10980
|
for (const videoEntry of readdirSync7(videoRoot, { withFileTypes: true })) {
|
|
10962
10981
|
if (!videoEntry.isDirectory()) continue;
|
|
10963
|
-
const videoDir =
|
|
10982
|
+
const videoDir = join29(videoRoot, videoEntry.name);
|
|
10964
10983
|
if (readdirSync7(videoDir).includes(EXTRACTION_CACHE_COMPLETE_SENTINEL)) {
|
|
10965
|
-
const sentinelPath =
|
|
10984
|
+
const sentinelPath = join29(videoDir, EXTRACTION_CACHE_COMPLETE_SENTINEL);
|
|
10966
10985
|
assertValidExtractionCacheCompleteSentinel(sentinelPath);
|
|
10967
10986
|
}
|
|
10968
10987
|
}
|
|
@@ -11009,7 +11028,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
11009
11028
|
if (video.deferredRange) {
|
|
11010
11029
|
const framePaths2 = /* @__PURE__ */ new Map();
|
|
11011
11030
|
for (let index = 0; index < video.totalFrames; index++) {
|
|
11012
|
-
framePaths2.set(index,
|
|
11031
|
+
framePaths2.set(index, join29(outputDir, String(index)));
|
|
11013
11032
|
}
|
|
11014
11033
|
return { ...video, outputDir, framePaths: framePaths2, ownedByLookup: false };
|
|
11015
11034
|
}
|
|
@@ -11017,7 +11036,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
11017
11036
|
const framePaths = /* @__PURE__ */ new Map();
|
|
11018
11037
|
for (const frameName of frameNames) {
|
|
11019
11038
|
if (frameName === EXTRACTION_CACHE_COMPLETE_SENTINEL) {
|
|
11020
|
-
assertValidExtractionCacheCompleteSentinel(
|
|
11039
|
+
assertValidExtractionCacheCompleteSentinel(join29(outputDir, frameName));
|
|
11021
11040
|
continue;
|
|
11022
11041
|
}
|
|
11023
11042
|
const match = /(\d+)(?=\.[^.]+$)/.exec(frameName);
|
|
@@ -11036,7 +11055,7 @@ function listVideoFramePaths(executionPlanDir, videos) {
|
|
|
11036
11055
|
`duplicate extracted frame index ${frameIndex} in ${outputDir}`
|
|
11037
11056
|
);
|
|
11038
11057
|
}
|
|
11039
|
-
framePaths.set(frameIndex,
|
|
11058
|
+
framePaths.set(frameIndex, join29(outputDir, frameName));
|
|
11040
11059
|
}
|
|
11041
11060
|
return {
|
|
11042
11061
|
...video,
|
|
@@ -11057,8 +11076,8 @@ function parsePlanVideosJson2(value) {
|
|
|
11057
11076
|
}
|
|
11058
11077
|
}
|
|
11059
11078
|
function materializeExtractedVideoDirectories(planDir) {
|
|
11060
|
-
const videosPath =
|
|
11061
|
-
if (!
|
|
11079
|
+
const videosPath = join29(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
11080
|
+
if (!existsSync22(videosPath)) return;
|
|
11062
11081
|
const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
|
|
11063
11082
|
for (const video of videos.extracted) {
|
|
11064
11083
|
mkdirSync12(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
|
|
@@ -11091,13 +11110,13 @@ function parseChunkSlices(value) {
|
|
|
11091
11110
|
});
|
|
11092
11111
|
}
|
|
11093
11112
|
function buildVideoChunkDependencies(executionPlanDir, dimensions) {
|
|
11094
|
-
const videoRoot =
|
|
11095
|
-
const hasExtractedFrames =
|
|
11096
|
-
const videosPath =
|
|
11097
|
-
if (!
|
|
11113
|
+
const videoRoot = join29(executionPlanDir, "video-frames");
|
|
11114
|
+
const hasExtractedFrames = existsSync22(videoRoot) && listFiles(videoRoot).length > 0;
|
|
11115
|
+
const videosPath = join29(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
11116
|
+
if (!existsSync22(videosPath)) {
|
|
11098
11117
|
return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
|
|
11099
11118
|
}
|
|
11100
|
-
const chunksPath =
|
|
11119
|
+
const chunksPath = join29(executionPlanDir, "meta", "chunks.json");
|
|
11101
11120
|
const videos = readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
11102
11121
|
const chunks = readJsonFile(chunksPath, "meta/chunks.json");
|
|
11103
11122
|
const parsedVideos = parsePlanVideosJson2(videos);
|
|
@@ -11151,10 +11170,10 @@ function computeManifestHash(manifest) {
|
|
|
11151
11170
|
return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
|
|
11152
11171
|
}
|
|
11153
11172
|
function writeBlob(sourcePath, destinationPath) {
|
|
11154
|
-
if (
|
|
11173
|
+
if (existsSync22(destinationPath)) return;
|
|
11155
11174
|
mkdirSync12(dirname14(destinationPath), { recursive: true });
|
|
11156
11175
|
const temporaryDir = createStagingDir6(dirname14(destinationPath), ".plan-v2-blob-");
|
|
11157
|
-
const temporaryPath =
|
|
11176
|
+
const temporaryPath = join29(temporaryDir, "blob");
|
|
11158
11177
|
try {
|
|
11159
11178
|
copyFileSync8(sourcePath, temporaryPath);
|
|
11160
11179
|
renameWithRetry10(temporaryPath, destinationPath);
|
|
@@ -11190,8 +11209,8 @@ async function putTasks(tasks) {
|
|
|
11190
11209
|
if (failure) throw failure.reason;
|
|
11191
11210
|
}
|
|
11192
11211
|
function buildPlanV2Publication(executionPlanDir, digests) {
|
|
11193
|
-
const executionPlanPath =
|
|
11194
|
-
if (!
|
|
11212
|
+
const executionPlanPath = join29(executionPlanDir, "plan.json");
|
|
11213
|
+
if (!existsSync22(executionPlanPath)) {
|
|
11195
11214
|
throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
|
|
11196
11215
|
}
|
|
11197
11216
|
const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
|
|
@@ -11218,7 +11237,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
11218
11237
|
}
|
|
11219
11238
|
validateExtractionCacheCompleteSentinels(executionPlanDir);
|
|
11220
11239
|
const videoDependencyPlan = buildVideoChunkDependencies(executionPlanDir, dimensions);
|
|
11221
|
-
const encoder = readJsonFile(
|
|
11240
|
+
const encoder = readJsonFile(join29(executionPlanDir, "meta", "encoder.json"), "meta/encoder.json");
|
|
11222
11241
|
const files = listFiles(executionPlanDir);
|
|
11223
11242
|
const chunkAudio = !isRecord3(encoder) || encoder.chunksCarryAudio !== true ? "none" : files.some((file) => chunkAudioSliceTarget(file.path) !== null) ? "sliced" : "whole";
|
|
11224
11243
|
for (const file of files) {
|
|
@@ -11271,7 +11290,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
11271
11290
|
};
|
|
11272
11291
|
}
|
|
11273
11292
|
function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
11274
|
-
if (
|
|
11293
|
+
if (existsSync22(planV2Dir)) {
|
|
11275
11294
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
11276
11295
|
}
|
|
11277
11296
|
const publication = buildPlanV2Publication(executionPlanDir);
|
|
@@ -11285,7 +11304,7 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
|
11285
11304
|
writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
|
|
11286
11305
|
}
|
|
11287
11306
|
writeFileSync10(
|
|
11288
|
-
|
|
11307
|
+
join29(tempDir, "plan.json"),
|
|
11289
11308
|
canonicalJsonStringify(publication.manifest),
|
|
11290
11309
|
"utf-8"
|
|
11291
11310
|
);
|
|
@@ -11337,7 +11356,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
11337
11356
|
// artifactTargets ships every compiled/ file to all chunks, so each is in the manifest.
|
|
11338
11357
|
whileAudioMixes: () => putBlobs(
|
|
11339
11358
|
publisher,
|
|
11340
|
-
listFiles(
|
|
11359
|
+
listFiles(join29(stagingRoot, "compiled")).map(
|
|
11341
11360
|
(file) => publishBlobFor(file.absolutePath, digests)
|
|
11342
11361
|
)
|
|
11343
11362
|
),
|
|
@@ -11357,7 +11376,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
11357
11376
|
}
|
|
11358
11377
|
}
|
|
11359
11378
|
async function planV2(projectDir, config, planV2Dir) {
|
|
11360
|
-
if (
|
|
11379
|
+
if (existsSync22(planV2Dir)) {
|
|
11361
11380
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
11362
11381
|
}
|
|
11363
11382
|
const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
|
|
@@ -11374,7 +11393,7 @@ function resultFromManifest(planV2Dir, manifest) {
|
|
|
11374
11393
|
isRecord3(executionPlan) ? executionPlan[REFERENCE_BACKGROUND_FIELD3] : void 0
|
|
11375
11394
|
),
|
|
11376
11395
|
planDir: planV2Dir,
|
|
11377
|
-
manifestPath:
|
|
11396
|
+
manifestPath: join29(planV2Dir, "plan.json"),
|
|
11378
11397
|
planProtocol: PLAN_PROTOCOL_V2,
|
|
11379
11398
|
planHash: manifest.planHash,
|
|
11380
11399
|
sourcePlanV1Hash: getPlanV2ExecutionPlanHash(manifest),
|
|
@@ -11510,8 +11529,8 @@ function parsePlanV2Manifest(value) {
|
|
|
11510
11529
|
return parsed;
|
|
11511
11530
|
}
|
|
11512
11531
|
function readPlanV2Manifest(planV2Dir) {
|
|
11513
|
-
const manifestPath =
|
|
11514
|
-
if (!
|
|
11532
|
+
const manifestPath = join29(planV2Dir, "plan.json");
|
|
11533
|
+
if (!existsSync22(manifestPath)) {
|
|
11515
11534
|
throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
|
|
11516
11535
|
}
|
|
11517
11536
|
const value = readJsonFile(manifestPath, "v2 manifest");
|
|
@@ -11530,7 +11549,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
|
|
|
11530
11549
|
}
|
|
11531
11550
|
function verifyBlob(planV2Dir, artifact) {
|
|
11532
11551
|
const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
|
|
11533
|
-
if (!
|
|
11552
|
+
if (!existsSync22(sourcePath)) {
|
|
11534
11553
|
throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
|
|
11535
11554
|
}
|
|
11536
11555
|
const stats = statSync7(sourcePath);
|
|
@@ -11543,7 +11562,7 @@ function verifyBlob(planV2Dir, artifact) {
|
|
|
11543
11562
|
return sourcePath;
|
|
11544
11563
|
}
|
|
11545
11564
|
function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
|
|
11546
|
-
if (
|
|
11565
|
+
if (existsSync22(destinationDir)) {
|
|
11547
11566
|
throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
|
|
11548
11567
|
}
|
|
11549
11568
|
const manifest = readPlanV2Manifest(planV2Dir);
|
|
@@ -11559,13 +11578,13 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
11559
11578
|
const tempDir = createStagingDir6(dirname14(destinationDir), ".plan-v2-materialize-");
|
|
11560
11579
|
try {
|
|
11561
11580
|
for (const { artifact, sourcePath } of verified) {
|
|
11562
|
-
const destinationPath =
|
|
11581
|
+
const destinationPath = join29(tempDir, ...artifact.path.split("/"));
|
|
11563
11582
|
mkdirSync12(dirname14(destinationPath), { recursive: true });
|
|
11564
11583
|
copyFileSync8(sourcePath, destinationPath);
|
|
11565
11584
|
}
|
|
11566
11585
|
if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
|
|
11567
11586
|
writeFileSync10(
|
|
11568
|
-
|
|
11587
|
+
join29(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
|
|
11569
11588
|
canonicalJsonStringify({
|
|
11570
11589
|
manifest,
|
|
11571
11590
|
target,
|
|
@@ -11588,7 +11607,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
11588
11607
|
// Join the artifact's OWN name, not the current constant: a plan written
|
|
11589
11608
|
// before the container change carries the legacy name, and materializing it
|
|
11590
11609
|
// under the new one would point at a file that was never written.
|
|
11591
|
-
audioPath: target.role === "assembler" ? audioArtifact ?
|
|
11610
|
+
audioPath: target.role === "assembler" ? audioArtifact ? join29(destinationDir, audioArtifact.path) : null : null
|
|
11592
11611
|
};
|
|
11593
11612
|
}
|
|
11594
11613
|
function assertRemoteSources(remoteSources, artifacts) {
|
|
@@ -11607,8 +11626,8 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
|
|
|
11607
11626
|
return readValidatedPlanV2Materialization(planDir, expectedTarget)?.manifest ?? null;
|
|
11608
11627
|
}
|
|
11609
11628
|
function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
11610
|
-
const markerPath =
|
|
11611
|
-
if (!
|
|
11629
|
+
const markerPath = join29(planDir, PLAN_V2_MATERIALIZATION_MARKER);
|
|
11630
|
+
if (!existsSync22(markerPath)) return null;
|
|
11612
11631
|
const marker = readJsonFile(markerPath, "materialization marker");
|
|
11613
11632
|
if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
|
|
11614
11633
|
throw new PlanV2IntegrityError("malformed materialization marker");
|
|
@@ -11625,8 +11644,8 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
|
11625
11644
|
assertRemoteSources(remoteSources, required);
|
|
11626
11645
|
for (const artifact of required) {
|
|
11627
11646
|
if (Object.hasOwn(remoteSources, artifact.path)) continue;
|
|
11628
|
-
const path =
|
|
11629
|
-
if (!
|
|
11647
|
+
const path = join29(planDir, ...artifact.path.split("/"));
|
|
11648
|
+
if (!existsSync22(path) || statSync7(path).size !== artifact.sizeBytes) {
|
|
11630
11649
|
throw new PlanV2IntegrityError(
|
|
11631
11650
|
`materialized artifact missing or truncated: ${artifact.path}`
|
|
11632
11651
|
);
|
|
@@ -11641,7 +11660,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
|
11641
11660
|
// src/services/distributed/planV2Execution.ts
|
|
11642
11661
|
import { mkdtempSync, rmSync as rmSync12 } from "node:fs";
|
|
11643
11662
|
import { tmpdir as tmpdir2 } from "node:os";
|
|
11644
|
-
import { join as
|
|
11663
|
+
import { join as join32 } from "node:path";
|
|
11645
11664
|
|
|
11646
11665
|
// src/services/distributed/assemble.ts
|
|
11647
11666
|
import {
|
|
@@ -11650,15 +11669,15 @@ import {
|
|
|
11650
11669
|
} from "@hyperframes/engine";
|
|
11651
11670
|
import {
|
|
11652
11671
|
cpSync as cpSync3,
|
|
11653
|
-
existsSync as
|
|
11672
|
+
existsSync as existsSync23,
|
|
11654
11673
|
mkdirSync as mkdirSync13,
|
|
11655
|
-
readFileSync as
|
|
11674
|
+
readFileSync as readFileSync11,
|
|
11656
11675
|
readdirSync as readdirSync8,
|
|
11657
11676
|
rmSync as rmSync10,
|
|
11658
11677
|
statSync as statSync8,
|
|
11659
11678
|
writeFileSync as writeFileSync11
|
|
11660
11679
|
} from "node:fs";
|
|
11661
|
-
import { basename as basename6, dirname as dirname15, join as
|
|
11680
|
+
import { basename as basename6, dirname as dirname15, join as join30 } from "node:path";
|
|
11662
11681
|
import {
|
|
11663
11682
|
appendRateCapArgs as appendRateCapArgs2,
|
|
11664
11683
|
appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
|
|
@@ -11705,7 +11724,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
11705
11724
|
}
|
|
11706
11725
|
const format = plan.dimensions.format;
|
|
11707
11726
|
const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
|
|
11708
|
-
if (!
|
|
11727
|
+
if (!existsSync23(dirname15(outputPath))) {
|
|
11709
11728
|
mkdirSync13(dirname15(outputPath), { recursive: true });
|
|
11710
11729
|
}
|
|
11711
11730
|
const workDir = createStagingDir7(dirname15(outputPath), `${basename6(outputPath)}.assemble-work-`);
|
|
@@ -11728,8 +11747,8 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
11728
11747
|
};
|
|
11729
11748
|
try {
|
|
11730
11749
|
const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
|
|
11731
|
-
const finalPath =
|
|
11732
|
-
const audio = audioPath !== null &&
|
|
11750
|
+
const finalPath = join30(workDir, `output.${format}`);
|
|
11751
|
+
const audio = audioPath !== null && existsSync23(audioPath) ? audioPath : null;
|
|
11733
11752
|
await writeJoined(ctx, videoSources, audio, finalPath);
|
|
11734
11753
|
renameWithRetry11(finalPath, outputPath);
|
|
11735
11754
|
log.info("[assemble] stage timings", {
|
|
@@ -11747,7 +11766,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
11747
11766
|
});
|
|
11748
11767
|
}
|
|
11749
11768
|
}
|
|
11750
|
-
const fileSize =
|
|
11769
|
+
const fileSize = existsSync23(outputPath) ? statSync8(outputPath).size : 0;
|
|
11751
11770
|
return {
|
|
11752
11771
|
...referenceBackgroundResult6(plan[REFERENCE_BACKGROUND_FIELD4]),
|
|
11753
11772
|
outputPath,
|
|
@@ -11757,18 +11776,18 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
11757
11776
|
};
|
|
11758
11777
|
}
|
|
11759
11778
|
function readAssemblePlan(planDir, chunkPaths) {
|
|
11760
|
-
const planJsonPath =
|
|
11761
|
-
const chunksJsonPath =
|
|
11762
|
-
if (!
|
|
11779
|
+
const planJsonPath = join30(planDir, "plan.json");
|
|
11780
|
+
const chunksJsonPath = join30(planDir, "meta", "chunks.json");
|
|
11781
|
+
if (!existsSync23(planJsonPath)) {
|
|
11763
11782
|
throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
|
|
11764
11783
|
}
|
|
11765
|
-
const plan = JSON.parse(
|
|
11784
|
+
const plan = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
|
|
11766
11785
|
readPlanProtocolV1(plan, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
|
|
11767
11786
|
validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
|
|
11768
|
-
if (!
|
|
11787
|
+
if (!existsSync23(chunksJsonPath)) {
|
|
11769
11788
|
throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
|
|
11770
11789
|
}
|
|
11771
|
-
const chunks = JSON.parse(
|
|
11790
|
+
const chunks = JSON.parse(readFileSync11(chunksJsonPath, "utf-8"));
|
|
11772
11791
|
if (chunkPaths.length !== chunks.length) {
|
|
11773
11792
|
throw new Error(
|
|
11774
11793
|
`[assemble] chunkPaths length (${chunkPaths.length}) does not match chunks.json length (${chunks.length}). Adapters must pass one path per chunk, ordered by index.`
|
|
@@ -11780,7 +11799,7 @@ function readAssemblePlan(planDir, chunkPaths) {
|
|
|
11780
11799
|
}
|
|
11781
11800
|
}
|
|
11782
11801
|
for (const path of chunkPaths.flat()) {
|
|
11783
|
-
if (!
|
|
11802
|
+
if (!existsSync23(path)) {
|
|
11784
11803
|
throw new Error(`[assemble] chunk path does not exist: ${path}`);
|
|
11785
11804
|
}
|
|
11786
11805
|
}
|
|
@@ -11809,7 +11828,7 @@ function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
|
|
|
11809
11828
|
return args;
|
|
11810
11829
|
}
|
|
11811
11830
|
async function reencodeCfr(ctx, chunkPaths, encoder) {
|
|
11812
|
-
const cfrOutputPath =
|
|
11831
|
+
const cfrOutputPath = join30(ctx.workDir, `cfr.${ctx.format}`);
|
|
11813
11832
|
const cfrArgs = cfrEncodeArgs(videoInputArgs(ctx, chunkPaths), encoder, ctx.fpsArg);
|
|
11814
11833
|
appendRenderProvenanceArgs2(cfrArgs, cfrOutputPath);
|
|
11815
11834
|
cfrArgs.push("-y", cfrOutputPath);
|
|
@@ -11836,7 +11855,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
11836
11855
|
);
|
|
11837
11856
|
return;
|
|
11838
11857
|
}
|
|
11839
|
-
const paddedAudioPath =
|
|
11858
|
+
const paddedAudioPath = join30(ctx.workDir, "audio-padded.m4a");
|
|
11840
11859
|
const padTrimResult = await ctx.timed(
|
|
11841
11860
|
"audioMs",
|
|
11842
11861
|
() => padOrTrimAudioToVideoFrameCount({
|
|
@@ -11876,7 +11895,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
11876
11895
|
}
|
|
11877
11896
|
}
|
|
11878
11897
|
function concatDemuxerInput(chunkPaths, workDir, fpsArg) {
|
|
11879
|
-
const listPath =
|
|
11898
|
+
const listPath = join30(workDir, "concat-list.txt");
|
|
11880
11899
|
const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
|
|
11881
11900
|
writeFileSync11(listPath, `${body}
|
|
11882
11901
|
`, "utf-8");
|
|
@@ -11914,13 +11933,13 @@ function stitchesSeparateAudio(planDir) {
|
|
|
11914
11933
|
return lockedAudio(planDir).separateAudio === true;
|
|
11915
11934
|
}
|
|
11916
11935
|
function planFormat(planDir) {
|
|
11917
|
-
const plan = JSON.parse(
|
|
11936
|
+
const plan = JSON.parse(readFileSync11(join30(planDir, "plan.json"), "utf-8"));
|
|
11918
11937
|
return plan.dimensions.format;
|
|
11919
11938
|
}
|
|
11920
11939
|
function lockedAudio(planDir) {
|
|
11921
|
-
const encoderJsonPath =
|
|
11922
|
-
if (!
|
|
11923
|
-
return JSON.parse(
|
|
11940
|
+
const encoderJsonPath = join30(planDir, "meta", "encoder.json");
|
|
11941
|
+
if (!existsSync23(encoderJsonPath)) return {};
|
|
11942
|
+
return JSON.parse(readFileSync11(encoderJsonPath, "utf-8"));
|
|
11924
11943
|
}
|
|
11925
11944
|
function readCfrEncoder(planDir, format) {
|
|
11926
11945
|
if (format !== "mp4") {
|
|
@@ -11928,11 +11947,11 @@ function readCfrEncoder(planDir, format) {
|
|
|
11928
11947
|
`[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.`
|
|
11929
11948
|
);
|
|
11930
11949
|
}
|
|
11931
|
-
const encoderJsonPath =
|
|
11932
|
-
if (!
|
|
11950
|
+
const encoderJsonPath = join30(planDir, "meta", "encoder.json");
|
|
11951
|
+
if (!existsSync23(encoderJsonPath)) {
|
|
11933
11952
|
throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
|
|
11934
11953
|
}
|
|
11935
|
-
const encoderJson = JSON.parse(
|
|
11954
|
+
const encoderJson = JSON.parse(readFileSync11(encoderJsonPath, "utf-8"));
|
|
11936
11955
|
if (encoderJson.encoder === "libx265-software") {
|
|
11937
11956
|
throw new Error(
|
|
11938
11957
|
`[assemble] cfr=true is not yet supported with codec: "h265". The cfr re-encode pass uses libx264 and would silently transcode the h265 chunks. Either disable cfr or render with codec: "h264".`
|
|
@@ -11941,7 +11960,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
11941
11960
|
return encoderJson;
|
|
11942
11961
|
}
|
|
11943
11962
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
11944
|
-
if (
|
|
11963
|
+
if (existsSync23(outputPath)) rmSync10(outputPath, { recursive: true, force: true });
|
|
11945
11964
|
mkdirSync13(outputPath, { recursive: true });
|
|
11946
11965
|
let globalIdx = 0;
|
|
11947
11966
|
for (const chunkDir of chunkPaths) {
|
|
@@ -11955,8 +11974,8 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
11955
11974
|
throw new Error(`[assemble] png-sequence chunk has no frames: ${chunkDir}`);
|
|
11956
11975
|
}
|
|
11957
11976
|
for (const frame of frames) {
|
|
11958
|
-
const dst =
|
|
11959
|
-
cpSync3(
|
|
11977
|
+
const dst = join30(outputPath, formatExportFrameName(globalIdx, "png"));
|
|
11978
|
+
cpSync3(join30(chunkDir, frame), dst);
|
|
11960
11979
|
globalIdx += 1;
|
|
11961
11980
|
}
|
|
11962
11981
|
}
|
|
@@ -11965,14 +11984,14 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
11965
11984
|
`[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
|
|
11966
11985
|
);
|
|
11967
11986
|
}
|
|
11968
|
-
if (audioPath !== null &&
|
|
11969
|
-
const sidecar =
|
|
11987
|
+
if (audioPath !== null && existsSync23(audioPath)) {
|
|
11988
|
+
const sidecar = join30(outputPath, MIXED_AUDIO_FILENAME4);
|
|
11970
11989
|
cpSync3(audioPath, sidecar);
|
|
11971
11990
|
}
|
|
11972
11991
|
let fileSize = 0;
|
|
11973
11992
|
for (const name of readdirSync8(outputPath)) {
|
|
11974
11993
|
try {
|
|
11975
|
-
fileSize += statSync8(
|
|
11994
|
+
fileSize += statSync8(join30(outputPath, name)).size;
|
|
11976
11995
|
} catch {
|
|
11977
11996
|
}
|
|
11978
11997
|
}
|
|
@@ -11986,9 +12005,9 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
11986
12005
|
|
|
11987
12006
|
// src/services/distributed/renderChunk.ts
|
|
11988
12007
|
import { randomBytes } from "node:crypto";
|
|
11989
|
-
import { existsSync as
|
|
12008
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync12 } from "node:fs";
|
|
11990
12009
|
import { cpus } from "node:os";
|
|
11991
|
-
import { join as
|
|
12010
|
+
import { join as join31 } from "node:path";
|
|
11992
12011
|
import {
|
|
11993
12012
|
assertSwiftShader,
|
|
11994
12013
|
BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
|
|
@@ -12120,10 +12139,10 @@ async function beginFrameSessionNeedsScreenshotFallback(session, probe = probeBe
|
|
|
12120
12139
|
return !await probe(session.page, timeoutMs, probeTick, session.beginFrameIntervalMs);
|
|
12121
12140
|
}
|
|
12122
12141
|
function hashChunkOutput(outputPath, kind) {
|
|
12123
|
-
if (kind === "file") return sha256Hex(
|
|
12142
|
+
if (kind === "file") return sha256Hex(readFileSync12(outputPath));
|
|
12124
12143
|
const entries = readdirSync9(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
|
|
12125
12144
|
const lines = entries.map(
|
|
12126
|
-
(name) => `${name}\0${sha256Hex(
|
|
12145
|
+
(name) => `${name}\0${sha256Hex(readFileSync12(join31(outputPath, name)))}`
|
|
12127
12146
|
);
|
|
12128
12147
|
return sha256Hex(lines.join("\0"));
|
|
12129
12148
|
}
|
|
@@ -12140,16 +12159,16 @@ function resolveLockedVp9CpuUsed(lockedEncoder) {
|
|
|
12140
12159
|
async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
12141
12160
|
const start = Date.now();
|
|
12142
12161
|
const log = defaultLogger;
|
|
12143
|
-
const planJsonPath =
|
|
12144
|
-
const encoderJsonPath =
|
|
12145
|
-
const chunksJsonPath =
|
|
12146
|
-
if (!
|
|
12162
|
+
const planJsonPath = join31(planDir, "plan.json");
|
|
12163
|
+
const encoderJsonPath = join31(planDir, "meta", "encoder.json");
|
|
12164
|
+
const chunksJsonPath = join31(planDir, "meta", "chunks.json");
|
|
12165
|
+
if (!existsSync24(planJsonPath)) {
|
|
12147
12166
|
throw new RenderChunkValidationError(
|
|
12148
12167
|
MISSING_PLAN_ARTIFACT,
|
|
12149
12168
|
`[renderChunk] planDir is missing required artifact: ${planJsonPath}`
|
|
12150
12169
|
);
|
|
12151
12170
|
}
|
|
12152
|
-
const plan = JSON.parse(
|
|
12171
|
+
const plan = JSON.parse(readFileSync12(planJsonPath, "utf-8"));
|
|
12153
12172
|
readPlanProtocolV1(plan, DISTRIBUTED_RENDER_CAPABILITIES.roles.chunk);
|
|
12154
12173
|
const planHashStarted = Date.now();
|
|
12155
12174
|
const v2Materialization = readValidatedPlanV2Materialization(planDir, {
|
|
@@ -12159,20 +12178,20 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
12159
12178
|
const v2Manifest = v2Materialization?.manifest ?? null;
|
|
12160
12179
|
const remoteSources = v2Materialization?.remoteSources ?? {};
|
|
12161
12180
|
for (const required of [encoderJsonPath, chunksJsonPath]) {
|
|
12162
|
-
if (!
|
|
12181
|
+
if (!existsSync24(required)) {
|
|
12163
12182
|
throw new RenderChunkValidationError(
|
|
12164
12183
|
MISSING_PLAN_ARTIFACT,
|
|
12165
12184
|
`[renderChunk] planDir is missing required artifact: ${required}`
|
|
12166
12185
|
);
|
|
12167
12186
|
}
|
|
12168
12187
|
}
|
|
12169
|
-
const encoder = JSON.parse(
|
|
12170
|
-
const chunks = JSON.parse(
|
|
12171
|
-
const videosJsonPath =
|
|
12188
|
+
const encoder = JSON.parse(readFileSync12(encoderJsonPath, "utf-8"));
|
|
12189
|
+
const chunks = JSON.parse(readFileSync12(chunksJsonPath, "utf-8"));
|
|
12190
|
+
const videosJsonPath = join31(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
12172
12191
|
let planVideos = null;
|
|
12173
|
-
if (
|
|
12192
|
+
if (existsSync24(videosJsonPath)) {
|
|
12174
12193
|
try {
|
|
12175
|
-
planVideos = validatePlanVideosForChunk(JSON.parse(
|
|
12194
|
+
planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync12(videosJsonPath, "utf-8")));
|
|
12176
12195
|
} catch (err) {
|
|
12177
12196
|
if (err instanceof RenderChunkValidationError) throw err;
|
|
12178
12197
|
throw new RenderChunkValidationError(
|
|
@@ -12200,8 +12219,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
12200
12219
|
}
|
|
12201
12220
|
const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
|
|
12202
12221
|
const framesInChunk = range.endFrame - range.startFrame;
|
|
12203
|
-
const compiledDir =
|
|
12204
|
-
if (!
|
|
12222
|
+
const compiledDir = join31(planDir, "compiled");
|
|
12223
|
+
if (!existsSync24(compiledDir)) {
|
|
12205
12224
|
throw new RenderChunkValidationError(
|
|
12206
12225
|
MISSING_PLAN_ARTIFACT,
|
|
12207
12226
|
`[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
|
|
@@ -12259,7 +12278,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
12259
12278
|
};
|
|
12260
12279
|
const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
12261
12280
|
mkdirSync14(workDir, { recursive: true });
|
|
12262
|
-
const framesDir =
|
|
12281
|
+
const framesDir = join31(workDir, "captured-frames");
|
|
12263
12282
|
mkdirSync14(framesDir, { recursive: true });
|
|
12264
12283
|
const videoFramesDir = `${workDir}.video-frames`;
|
|
12265
12284
|
const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
|
|
@@ -12284,7 +12303,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
12284
12303
|
dimensions: plan.dimensions,
|
|
12285
12304
|
encoder,
|
|
12286
12305
|
videoCount: planVideos?.videos.length ?? 0,
|
|
12287
|
-
html:
|
|
12306
|
+
html: readFileSync12(join31(compiledDir, "index.html"), "utf-8"),
|
|
12288
12307
|
// The plan ships a deferred source only to chunks that show it; don't wait on the rest.
|
|
12289
12308
|
skipReadinessVideoIds: deferredVideos.filter(
|
|
12290
12309
|
(video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
|
|
@@ -12452,10 +12471,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
12452
12471
|
const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
|
|
12453
12472
|
const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
|
|
12454
12473
|
if (isPngSequence) {
|
|
12455
|
-
if (!
|
|
12474
|
+
if (!existsSync24(outputChunkPath)) mkdirSync14(outputChunkPath, { recursive: true });
|
|
12456
12475
|
} else {
|
|
12457
|
-
const outDir =
|
|
12458
|
-
if (!
|
|
12476
|
+
const outDir = join31(outputChunkPath, "..");
|
|
12477
|
+
if (!existsSync24(outDir)) mkdirSync14(outDir, { recursive: true });
|
|
12459
12478
|
}
|
|
12460
12479
|
const encodeInput = {
|
|
12461
12480
|
job,
|
|
@@ -12698,8 +12717,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
12698
12717
|
|
|
12699
12718
|
// src/services/distributed/planV2Execution.ts
|
|
12700
12719
|
async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
12701
|
-
const workRoot = mkdtempSync(
|
|
12702
|
-
const materializedPlanDir =
|
|
12720
|
+
const workRoot = mkdtempSync(join32(tmpdir2(), "hf-plan-v2-chunk-"));
|
|
12721
|
+
const materializedPlanDir = join32(workRoot, "plan");
|
|
12703
12722
|
try {
|
|
12704
12723
|
materializePlanV2Target(planV2Dir, { role: "chunk", chunkIndex }, materializedPlanDir);
|
|
12705
12724
|
return await renderChunk(materializedPlanDir, chunkIndex, outputChunkPath, options);
|
|
@@ -12708,8 +12727,8 @@ async function renderChunkV2(planV2Dir, chunkIndex, outputChunkPath, options) {
|
|
|
12708
12727
|
}
|
|
12709
12728
|
}
|
|
12710
12729
|
async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
12711
|
-
const workRoot = mkdtempSync(
|
|
12712
|
-
const materializedPlanDir =
|
|
12730
|
+
const workRoot = mkdtempSync(join32(tmpdir2(), "hf-plan-v2-assembler-"));
|
|
12731
|
+
const materializedPlanDir = join32(workRoot, "plan");
|
|
12713
12732
|
try {
|
|
12714
12733
|
const materialized = materializePlanV2Target(
|
|
12715
12734
|
planV2Dir,
|
|
@@ -13015,7 +13034,7 @@ function validateIntDimension(field, value) {
|
|
|
13015
13034
|
// src/services/distributed/projectHash.ts
|
|
13016
13035
|
import { closeSync as closeSync5, openSync as openSync5, readdirSync as readdirSync10, readSync as readSync4, realpathSync as realpathSync2, statSync as statSync9 } from "node:fs";
|
|
13017
13036
|
import { createHash as createHash8 } from "node:crypto";
|
|
13018
|
-
import { join as
|
|
13037
|
+
import { join as join33 } from "node:path";
|
|
13019
13038
|
var SITE_ID_SCHEME = "site-v2\0";
|
|
13020
13039
|
var READ_CHUNK_BYTES = 256 * 1024;
|
|
13021
13040
|
function listSiteFiles(projectDir) {
|
|
@@ -13024,7 +13043,7 @@ function listSiteFiles(projectDir) {
|
|
|
13024
13043
|
function walk(dir, rel) {
|
|
13025
13044
|
for (const name of readdirSync10(dir).sort()) {
|
|
13026
13045
|
if (rel === "" && PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(name)) continue;
|
|
13027
|
-
const full =
|
|
13046
|
+
const full = join33(dir, name);
|
|
13028
13047
|
const relPath = rel === "" ? name : `${rel}/${name}`;
|
|
13029
13048
|
let stat;
|
|
13030
13049
|
try {
|
|
@@ -13054,7 +13073,7 @@ function hashProjectDir(projectDir, files = listSiteFiles(projectDir)) {
|
|
|
13054
13073
|
for (const rel of files) {
|
|
13055
13074
|
hash.update(rel);
|
|
13056
13075
|
hash.update("\0");
|
|
13057
|
-
const fd = openSync5(
|
|
13076
|
+
const fd = openSync5(join33(projectDir, rel), "r");
|
|
13058
13077
|
try {
|
|
13059
13078
|
let read;
|
|
13060
13079
|
while ((read = readSync4(fd, chunk, 0, chunk.length, null)) > 0) {
|