@hyperframes/producer 0.9.69 → 0.9.70
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 +69 -56
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/index.js +304 -258
- package/dist/public-server.js +193 -149
- package/dist/services/render/audioPadTrim.d.ts +2 -1
- package/dist/services/render/segmentManifest.d.ts +3 -4
- package/dist/services/renderOrchestrator.d.ts +1 -1
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -9,12 +9,12 @@ import {
|
|
|
9
9
|
// src/services/renderOrchestrator.ts
|
|
10
10
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, usableCpuCount as usableCpuCount2 } from "@hyperframes/engine";
|
|
11
11
|
import {
|
|
12
|
-
existsSync as
|
|
12
|
+
existsSync as existsSync21,
|
|
13
13
|
mkdirSync as mkdirSync12,
|
|
14
14
|
readdirSync as readdirSync6,
|
|
15
15
|
rmSync as rmSync12,
|
|
16
16
|
statSync as statSync10,
|
|
17
|
-
writeFileSync as
|
|
17
|
+
writeFileSync as writeFileSync6,
|
|
18
18
|
copyFileSync as copyFileSync5,
|
|
19
19
|
appendFileSync
|
|
20
20
|
} from "fs";
|
|
@@ -2593,7 +2593,7 @@ function replanAfterFailure(plan2, failure) {
|
|
|
2593
2593
|
}
|
|
2594
2594
|
|
|
2595
2595
|
// src/services/render/stages/captureSegmentedStage.ts
|
|
2596
|
-
import { existsSync as
|
|
2596
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync4, rmSync as rmSync6, statSync as statSync4 } from "node:fs";
|
|
2597
2597
|
import { join as join12 } from "node:path";
|
|
2598
2598
|
import {
|
|
2599
2599
|
captureFrameToBuffer as captureFrameToBuffer2,
|
|
@@ -4325,16 +4325,25 @@ function createSegmentQueue(slices) {
|
|
|
4325
4325
|
// src/services/render/segmentManifest.ts
|
|
4326
4326
|
import { createHash as createHash2, createHmac, timingSafeEqual } from "node:crypto";
|
|
4327
4327
|
import {
|
|
4328
|
+
closeSync as closeSync4,
|
|
4329
|
+
constants as constants3,
|
|
4328
4330
|
createReadStream as createReadStream2,
|
|
4329
|
-
|
|
4331
|
+
fstatSync as fstatSync3,
|
|
4330
4332
|
lstatSync as lstatSync3,
|
|
4331
4333
|
mkdirSync as mkdirSync3,
|
|
4332
|
-
|
|
4333
|
-
|
|
4334
|
+
openSync as openSync4,
|
|
4335
|
+
readFileSync as readFileSync4
|
|
4334
4336
|
} from "node:fs";
|
|
4335
4337
|
import { join as join10 } from "node:path";
|
|
4338
|
+
import {
|
|
4339
|
+
assertPrivateCachePath,
|
|
4340
|
+
ensurePrivateCacheDir,
|
|
4341
|
+
hyperframesCacheDir
|
|
4342
|
+
} from "@hyperframes/core/cache-dir";
|
|
4343
|
+
import { isSafePath as isSafePath2, realpath } from "@hyperframes/core/safe-path";
|
|
4344
|
+
import { isPathInside as isPathInside3 } from "@hyperframes/parsers/asset-paths";
|
|
4336
4345
|
import { previewToken } from "@hyperframes/core/preview-proof";
|
|
4337
|
-
import {
|
|
4346
|
+
import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
|
|
4338
4347
|
var MANIFEST_FILENAME = "segments.json";
|
|
4339
4348
|
function computeSegmentPlanHash(input) {
|
|
4340
4349
|
const ordered = [
|
|
@@ -4360,8 +4369,20 @@ function computeSegmentPlanHash(input) {
|
|
|
4360
4369
|
if (delivery.some((v) => v !== "")) ordered.push(...delivery.map(String));
|
|
4361
4370
|
return createHash2("sha256").update(ordered.join(" ")).digest("hex").slice(0, 16);
|
|
4362
4371
|
}
|
|
4363
|
-
function segmentDirFor(
|
|
4364
|
-
|
|
4372
|
+
function segmentDirFor(projectDir, planHash) {
|
|
4373
|
+
const root = hyperframesCacheDir();
|
|
4374
|
+
const projectKey = createHash2("sha256").update(realpath(projectDir)).digest("hex");
|
|
4375
|
+
const parent = join10(root, "segments", projectKey);
|
|
4376
|
+
const dir = join10(parent, planHash);
|
|
4377
|
+
if (isPathInside3(root, projectDir) || isSafePath2(projectDir, root) || isSafePath2(projectDir, parent) || isSafePath2(projectDir, dir)) {
|
|
4378
|
+
throw new Error("Segmented capture requires HYPERFRAMES_CACHE_DIR outside the project.");
|
|
4379
|
+
}
|
|
4380
|
+
assertPrivateCachePath(root, root);
|
|
4381
|
+
ensurePrivateCacheDir(parent, root);
|
|
4382
|
+
if (!isSafePath2(parent, dir) || lstatSync3(dir, { throwIfNoEntry: false })?.isSymbolicLink()) {
|
|
4383
|
+
throw new Error("Invalid segment cache directory");
|
|
4384
|
+
}
|
|
4385
|
+
return dir;
|
|
4365
4386
|
}
|
|
4366
4387
|
function hasNumber(value, key) {
|
|
4367
4388
|
return key in value && typeof Reflect.get(value, key) === "number";
|
|
@@ -4380,12 +4401,22 @@ function isManifest(value) {
|
|
|
4380
4401
|
}
|
|
4381
4402
|
function readSegmentManifest(segmentDir) {
|
|
4382
4403
|
const path = join10(segmentDir, MANIFEST_FILENAME);
|
|
4383
|
-
|
|
4404
|
+
let fd;
|
|
4384
4405
|
try {
|
|
4385
|
-
|
|
4406
|
+
fd = openSync4(
|
|
4407
|
+
path,
|
|
4408
|
+
constants3.O_RDONLY | (constants3.O_NOFOLLOW ?? 0) | (constants3.O_NONBLOCK ?? 0)
|
|
4409
|
+
);
|
|
4410
|
+
const opened = fstatSync3(fd);
|
|
4411
|
+
if (!opened.isFile() || opened.nlink !== 1) return null;
|
|
4412
|
+
const named = lstatSync3(path);
|
|
4413
|
+
if (!named.isFile() || named.dev !== opened.dev || named.ino !== opened.ino) return null;
|
|
4414
|
+
const parsed = JSON.parse(readFileSync4(fd, "utf-8"));
|
|
4386
4415
|
return isManifest(parsed) ? parsed : null;
|
|
4387
4416
|
} catch {
|
|
4388
4417
|
return null;
|
|
4418
|
+
} finally {
|
|
4419
|
+
if (fd !== void 0) closeSync4(fd);
|
|
4389
4420
|
}
|
|
4390
4421
|
}
|
|
4391
4422
|
function segmentManifestKey(token = previewToken()) {
|
|
@@ -4418,9 +4449,11 @@ async function hashSegmentFile(path) {
|
|
|
4418
4449
|
}
|
|
4419
4450
|
function writeSegmentManifest(segmentDir, manifest, key) {
|
|
4420
4451
|
mkdirSync3(segmentDir, { recursive: true });
|
|
4421
|
-
|
|
4422
|
-
|
|
4423
|
-
|
|
4452
|
+
replaceFileAtomically(
|
|
4453
|
+
join10(segmentDir, MANIFEST_FILENAME),
|
|
4454
|
+
JSON.stringify(signSegmentManifest(manifest, key), null, 2),
|
|
4455
|
+
384
|
|
4456
|
+
);
|
|
4424
4457
|
}
|
|
4425
4458
|
async function probeSegmentFrameCount(path, probe) {
|
|
4426
4459
|
try {
|
|
@@ -4440,19 +4473,27 @@ function plannedSlice(entry, plan2) {
|
|
|
4440
4473
|
}
|
|
4441
4474
|
return slice;
|
|
4442
4475
|
}
|
|
4443
|
-
function
|
|
4444
|
-
|
|
4445
|
-
|
|
4476
|
+
async function matchesSegmentFile(path, entry) {
|
|
4477
|
+
try {
|
|
4478
|
+
const stat = lstatSync3(path, { throwIfNoEntry: false });
|
|
4479
|
+
if (!stat?.isFile() || stat.nlink !== 1 || stat.size <= 0 || stat.size !== entry.bytes) {
|
|
4480
|
+
return false;
|
|
4481
|
+
}
|
|
4482
|
+
return await hashSegmentFile(path) === entry.sha256;
|
|
4483
|
+
} catch {
|
|
4484
|
+
return false;
|
|
4485
|
+
}
|
|
4446
4486
|
}
|
|
4447
4487
|
async function validateCompletedSegments(manifest, check) {
|
|
4448
4488
|
const ok = /* @__PURE__ */ new Set();
|
|
4449
|
-
if (manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key))
|
|
4489
|
+
if (manifest.totalFrames !== check.totalFrames || manifest.segmentFrames !== check.segmentFrames || manifest.planHash !== check.expectedHash || !hasValidMac(manifest, check.key))
|
|
4490
|
+
return ok;
|
|
4491
|
+
const plan2 = planSegments(check.totalFrames, check.segmentFrames);
|
|
4450
4492
|
for (const entry of manifest.completed) {
|
|
4451
|
-
const slice = plannedSlice(entry,
|
|
4493
|
+
const slice = plannedSlice(entry, plan2);
|
|
4452
4494
|
if (!slice) continue;
|
|
4453
4495
|
const path = segmentOutputPath(check.segmentDir, slice.index);
|
|
4454
|
-
if (!
|
|
4455
|
-
if (await hashSegmentFile(path) !== entry.sha256) continue;
|
|
4496
|
+
if (entry.path !== path || !await matchesSegmentFile(path, entry)) continue;
|
|
4456
4497
|
const frames = await check.probeFrames(path);
|
|
4457
4498
|
if (frames !== slice.endFrame - slice.startFrame) continue;
|
|
4458
4499
|
ok.add(slice.index);
|
|
@@ -5343,6 +5384,7 @@ async function captureSegment(ctx, segment) {
|
|
|
5343
5384
|
}
|
|
5344
5385
|
async function captureSegmentToEncoder(ctx, segment) {
|
|
5345
5386
|
const segmentPath = segmentOutputPath(ctx.segmentDir, segment.index);
|
|
5387
|
+
rmSync6(segmentPath, { force: true });
|
|
5346
5388
|
let encoder;
|
|
5347
5389
|
try {
|
|
5348
5390
|
encoder = await ctx.spawnEncoder(
|
|
@@ -5371,8 +5413,8 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
5371
5413
|
path: segmentPath,
|
|
5372
5414
|
// Recorded so resume can prove the file on disk is the one that
|
|
5373
5415
|
// finished; absent only in unit tests, whose fake encoder writes none.
|
|
5374
|
-
bytes:
|
|
5375
|
-
sha256:
|
|
5416
|
+
bytes: existsSync7(segmentPath) ? statSync4(segmentPath).size : 0,
|
|
5417
|
+
sha256: existsSync7(segmentPath) ? await hashSegmentFile(segmentPath) : ""
|
|
5376
5418
|
});
|
|
5377
5419
|
return encodeResult;
|
|
5378
5420
|
} finally {
|
|
@@ -7051,7 +7093,7 @@ function requireOutputDimensions(expected, width, height) {
|
|
|
7051
7093
|
}
|
|
7052
7094
|
|
|
7053
7095
|
// src/services/render/stages/compileStage.ts
|
|
7054
|
-
import { existsSync as
|
|
7096
|
+
import { existsSync as existsSync12, writeFileSync as writeFileSync4 } from "node:fs";
|
|
7055
7097
|
import { join as join22, relative as relative4 } from "node:path";
|
|
7056
7098
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
7057
7099
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
@@ -7063,7 +7105,7 @@ import { statSync as statSync6 } from "node:fs";
|
|
|
7063
7105
|
var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
|
|
7064
7106
|
var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
|
|
7065
7107
|
var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
|
|
7066
|
-
var MAX_EXPANDED_COMPOSITION_BYTES =
|
|
7108
|
+
var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
|
|
7067
7109
|
var MAX_COMPOSITION_MOUNTS = 1e4;
|
|
7068
7110
|
var CompositionTooLargeError = class extends Error {
|
|
7069
7111
|
constructor(message, publicMetadata) {
|
|
@@ -7160,12 +7202,12 @@ import {
|
|
|
7160
7202
|
stylesheetLinkMatches
|
|
7161
7203
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7162
7204
|
import { createHash as createHash6 } from "node:crypto";
|
|
7163
|
-
import { createReadStream as createReadStream3, existsSync as
|
|
7205
|
+
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
7164
7206
|
import { join as join21, dirname as dirname9, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7165
7207
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7166
7208
|
|
|
7167
7209
|
// src/services/bundledScripts.ts
|
|
7168
|
-
import { existsSync as
|
|
7210
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
|
|
7169
7211
|
import { join as join17 } from "node:path";
|
|
7170
7212
|
import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
|
|
7171
7213
|
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
@@ -7173,7 +7215,7 @@ function bundledScript(url) {
|
|
|
7173
7215
|
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
7174
7216
|
if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
|
|
7175
7217
|
const file = join17(dir, "gsap.min.js");
|
|
7176
|
-
return
|
|
7218
|
+
return existsSync8(file) ? readFileSync5(file) : null;
|
|
7177
7219
|
}
|
|
7178
7220
|
|
|
7179
7221
|
// src/services/htmlCompiler.ts
|
|
@@ -7431,7 +7473,7 @@ import {
|
|
|
7431
7473
|
|
|
7432
7474
|
// src/services/animatedGifPrep.ts
|
|
7433
7475
|
import { createHash as createHash4 } from "node:crypto";
|
|
7434
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
7476
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync7 } from "node:fs";
|
|
7435
7477
|
import { dirname as dirname6, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7436
7478
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7437
7479
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
@@ -7439,7 +7481,7 @@ import {
|
|
|
7439
7481
|
DEFAULT_VP9_CPU_USED,
|
|
7440
7482
|
isPrivateUnderAssetRoots,
|
|
7441
7483
|
runFfmpeg as runFfmpeg2,
|
|
7442
|
-
renameWithRetry as
|
|
7484
|
+
renameWithRetry as renameWithRetry2,
|
|
7443
7485
|
urlInputArgs as urlInputArgs2
|
|
7444
7486
|
} from "@hyperframes/engine";
|
|
7445
7487
|
import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
|
|
@@ -7477,7 +7519,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7477
7519
|
const { basePath } = splitUrlSuffix(trimmed);
|
|
7478
7520
|
const normalizedBase = normalizeRelPath(basePath);
|
|
7479
7521
|
const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
|
|
7480
|
-
if (mapped &&
|
|
7522
|
+
if (mapped && existsSync9(mapped)) return mapped;
|
|
7481
7523
|
if (isHttpUrl(trimmed)) return null;
|
|
7482
7524
|
const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
|
|
7483
7525
|
const candidates = [
|
|
@@ -7486,7 +7528,7 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7486
7528
|
];
|
|
7487
7529
|
const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
|
|
7488
7530
|
const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(candidate, [options.projectDir, options.downloadDir]) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
|
|
7489
|
-
return candidates.find((candidate) => allowed(candidate) &&
|
|
7531
|
+
return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
|
|
7490
7532
|
}
|
|
7491
7533
|
function isUsableFile(path) {
|
|
7492
7534
|
try {
|
|
@@ -7598,10 +7640,10 @@ async function runAnimatedGifTranscode(request) {
|
|
|
7598
7640
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
7599
7641
|
}
|
|
7600
7642
|
async function ensurePreparedWebm(input) {
|
|
7601
|
-
if (!
|
|
7643
|
+
if (!existsSync9(dirname6(input.cachePath))) {
|
|
7602
7644
|
mkdirSync7(dirname6(input.cachePath), { recursive: true });
|
|
7603
7645
|
}
|
|
7604
|
-
if (!
|
|
7646
|
+
if (!existsSync9(dirname6(input.outputPath))) {
|
|
7605
7647
|
mkdirSync7(dirname6(input.outputPath), { recursive: true });
|
|
7606
7648
|
}
|
|
7607
7649
|
if (!isUsableFile(input.cachePath)) {
|
|
@@ -7624,7 +7666,7 @@ async function ensurePreparedWebm(input) {
|
|
|
7624
7666
|
throw new Error("Animated GIF transcode produced an empty output");
|
|
7625
7667
|
}
|
|
7626
7668
|
if (!isUsableFile(input.cachePath)) {
|
|
7627
|
-
|
|
7669
|
+
renameWithRetry2(tmpPath, input.cachePath);
|
|
7628
7670
|
} else {
|
|
7629
7671
|
rmSync9(tmpPath, { force: true });
|
|
7630
7672
|
}
|
|
@@ -7748,19 +7790,19 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7748
7790
|
// src/services/heifImagePrep.ts
|
|
7749
7791
|
import { createHash as createHash5 } from "node:crypto";
|
|
7750
7792
|
import {
|
|
7751
|
-
closeSync as
|
|
7793
|
+
closeSync as closeSync5,
|
|
7752
7794
|
copyFileSync as copyFileSync3,
|
|
7753
7795
|
mkdirSync as mkdirSync8,
|
|
7754
|
-
openSync as
|
|
7796
|
+
openSync as openSync5,
|
|
7755
7797
|
readFileSync as readFileSync7,
|
|
7756
7798
|
readSync as readSync3,
|
|
7757
7799
|
rmSync as rmSync10,
|
|
7758
7800
|
statSync as statSync8,
|
|
7759
|
-
writeFileSync as
|
|
7801
|
+
writeFileSync as writeFileSync3
|
|
7760
7802
|
} from "node:fs";
|
|
7761
7803
|
import { dirname as dirname7, join as join19, resolve as resolve7 } from "node:path";
|
|
7762
7804
|
import { parseHTML as parseHTML4 } from "linkedom";
|
|
7763
|
-
import { renameWithRetry as
|
|
7805
|
+
import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
|
|
7764
7806
|
|
|
7765
7807
|
// src/services/heifRotation.ts
|
|
7766
7808
|
function* boxes(buf, start, end) {
|
|
@@ -7907,13 +7949,13 @@ function isHeifBytes(head) {
|
|
|
7907
7949
|
function readHead(path) {
|
|
7908
7950
|
let fd;
|
|
7909
7951
|
try {
|
|
7910
|
-
fd =
|
|
7952
|
+
fd = openSync5(path, "r");
|
|
7911
7953
|
const buf = Buffer.alloc(4096);
|
|
7912
7954
|
return buf.subarray(0, readSync3(fd, buf, 0, buf.length, 0));
|
|
7913
7955
|
} catch {
|
|
7914
7956
|
return null;
|
|
7915
7957
|
} finally {
|
|
7916
|
-
if (fd !== void 0)
|
|
7958
|
+
if (fd !== void 0) closeSync5(fd);
|
|
7917
7959
|
}
|
|
7918
7960
|
}
|
|
7919
7961
|
async function probeJson(path, withGroups) {
|
|
@@ -8012,14 +8054,14 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
|
8012
8054
|
const inlinePath = `${tmpPath}.heic`;
|
|
8013
8055
|
const inputPath = source.path ?? inlinePath;
|
|
8014
8056
|
try {
|
|
8015
|
-
if (!source.path)
|
|
8057
|
+
if (!source.path) writeFileSync3(inlinePath, source.bytes);
|
|
8016
8058
|
await (options.transcode ?? convertHeifToJpeg)({
|
|
8017
8059
|
inputPath,
|
|
8018
8060
|
outputPath: tmpPath,
|
|
8019
8061
|
timeoutMs: options.timeoutMs
|
|
8020
8062
|
});
|
|
8021
8063
|
if (!isUsableFile2(tmpPath)) throw new Error("conversion produced an empty file");
|
|
8022
|
-
|
|
8064
|
+
renameWithRetry3(tmpPath, cachePath);
|
|
8023
8065
|
} catch (error) {
|
|
8024
8066
|
const reason = error instanceof Error ? error.message : String(error);
|
|
8025
8067
|
throw TOOL_FAILURE_RE.test(reason) ? new HeifToolUnavailableError(source.label, reason) : new HeifImageConversionError(source.label, reason);
|
|
@@ -8080,7 +8122,7 @@ import {
|
|
|
8080
8122
|
import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
|
|
8081
8123
|
|
|
8082
8124
|
// src/services/assetMediaType.ts
|
|
8083
|
-
import { existsSync as
|
|
8125
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
8084
8126
|
import { dirname as dirname8, join as join20 } from "node:path";
|
|
8085
8127
|
import {
|
|
8086
8128
|
fingerprintElementId,
|
|
@@ -8193,7 +8235,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
8193
8235
|
input.projectDir,
|
|
8194
8236
|
input.compiledDir
|
|
8195
8237
|
);
|
|
8196
|
-
if (!
|
|
8238
|
+
if (!existsSync10(resolvedPath)) continue;
|
|
8197
8239
|
byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
|
|
8198
8240
|
}
|
|
8199
8241
|
const mismatches = [];
|
|
@@ -8490,7 +8532,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8490
8532
|
let filePath = src;
|
|
8491
8533
|
if (isHttpUrl(src)) {
|
|
8492
8534
|
const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8493
|
-
if (!
|
|
8535
|
+
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8494
8536
|
try {
|
|
8495
8537
|
filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
|
|
8496
8538
|
onTelemetry: logRemoteDownloadTelemetry
|
|
@@ -8509,7 +8551,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8509
8551
|
return { duration: null, resolvedPath: filePath };
|
|
8510
8552
|
}
|
|
8511
8553
|
}
|
|
8512
|
-
if (!isHttpUrl(filePath) && !
|
|
8554
|
+
if (!isHttpUrl(filePath) && !existsSync11(filePath)) {
|
|
8513
8555
|
return { duration: null, resolvedPath: filePath };
|
|
8514
8556
|
}
|
|
8515
8557
|
const withSrcContext = (error) => {
|
|
@@ -9141,7 +9183,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
9141
9183
|
return null;
|
|
9142
9184
|
}
|
|
9143
9185
|
const onShare = namesAnotherNetworkRoot2(absProjectDir, absPath);
|
|
9144
|
-
if (!onShare && !
|
|
9186
|
+
if (!onShare && !existsSync11(absPath)) return null;
|
|
9145
9187
|
const refusal = onShare ? "network_share" : outsideAssetRefusal(absProjectDir, absPath, policy);
|
|
9146
9188
|
if (refusal) {
|
|
9147
9189
|
if (!leftOut.has(trimmed)) log.warn(`[Compiler] ${leftOutOfRender(file, trimmed, refusal)}`);
|
|
@@ -9194,7 +9236,7 @@ function collectExternalAssets(html, projectDir, log = defaultLogger, file = "in
|
|
|
9194
9236
|
var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
9195
9237
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
9196
9238
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
9197
|
-
if (!
|
|
9239
|
+
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
9198
9240
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
9199
9241
|
await Promise.all(
|
|
9200
9242
|
[...urlSet].map(async (url) => {
|
|
@@ -9380,13 +9422,13 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
9380
9422
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
9381
9423
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
9382
9424
|
const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
9383
|
-
if (!isPathInside(sheet, projectDir) || !
|
|
9425
|
+
if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
9384
9426
|
for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
|
|
9385
9427
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
9386
9428
|
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
9387
9429
|
const path = decodedUrlPath(url);
|
|
9388
9430
|
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname9(sheet), path);
|
|
9389
|
-
return isPathInside(file, projectDir) &&
|
|
9431
|
+
return isPathInside(file, projectDir) && existsSync11(file);
|
|
9390
9432
|
});
|
|
9391
9433
|
if (family && shipsFile) families.push(family);
|
|
9392
9434
|
}
|
|
@@ -9538,7 +9580,7 @@ function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
|
9538
9580
|
let gsapDist;
|
|
9539
9581
|
const exists = (path) => {
|
|
9540
9582
|
const file = resolve8(projectDir, path);
|
|
9541
|
-
return !namesAnotherNetworkRoot2(projectDir, file) &&
|
|
9583
|
+
return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
|
|
9542
9584
|
};
|
|
9543
9585
|
return replaceGsapDistScripts(html, (full, prefix, src, file, suffix) => {
|
|
9544
9586
|
if (/^https?:\/\//i.test(src)) return full;
|
|
@@ -9774,7 +9816,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
9774
9816
|
for (const video of videos) {
|
|
9775
9817
|
if (isHttpUrl(video.src)) continue;
|
|
9776
9818
|
const videoPath = resolve8(projectDir, video.src);
|
|
9777
|
-
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !
|
|
9819
|
+
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
|
|
9778
9820
|
continue;
|
|
9779
9821
|
advised.add(videoPath);
|
|
9780
9822
|
const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
|
|
@@ -10221,7 +10263,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10221
10263
|
const rawEntry = readEntry(htmlPath);
|
|
10222
10264
|
if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
|
|
10223
10265
|
const projectIndexPath = join22(projectDir, "index.html");
|
|
10224
|
-
if (!
|
|
10266
|
+
if (!existsSync12(projectIndexPath)) {
|
|
10225
10267
|
throw new Error(
|
|
10226
10268
|
`Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
|
|
10227
10269
|
);
|
|
@@ -10237,7 +10279,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10237
10279
|
);
|
|
10238
10280
|
}
|
|
10239
10281
|
const wrapperPath = join22(workDir, "standalone-entry.html");
|
|
10240
|
-
|
|
10282
|
+
writeFileSync4(wrapperPath, standaloneHtml, "utf-8");
|
|
10241
10283
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
10242
10284
|
return wrapperPath;
|
|
10243
10285
|
}
|
|
@@ -11230,7 +11272,7 @@ function validateDistributedDuration(input) {
|
|
|
11230
11272
|
}
|
|
11231
11273
|
|
|
11232
11274
|
// src/services/render/stages/extractVideosStage.ts
|
|
11233
|
-
import { existsSync as
|
|
11275
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
11234
11276
|
import { join as join24 } from "node:path";
|
|
11235
11277
|
import {
|
|
11236
11278
|
classifyVideoExtractionError,
|
|
@@ -11683,7 +11725,7 @@ function isPublicHttpsUrl(url) {
|
|
|
11683
11725
|
}
|
|
11684
11726
|
}
|
|
11685
11727
|
function opensLocally(path, assetRoots) {
|
|
11686
|
-
return
|
|
11728
|
+
return existsSync13(path) && (!assetRoots || assetRootsRefusal(path, assetRoots) === null);
|
|
11687
11729
|
}
|
|
11688
11730
|
function localProbeSource(src, input) {
|
|
11689
11731
|
const path = resolveProjectRelativeSrc4(src, input.projectDir, input.compiledDir);
|
|
@@ -11736,7 +11778,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
11736
11778
|
}
|
|
11737
11779
|
|
|
11738
11780
|
// src/services/render/videoLayerPassthroughPlan.ts
|
|
11739
|
-
import { existsSync as
|
|
11781
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
11740
11782
|
import {
|
|
11741
11783
|
buildVideoLayerInput,
|
|
11742
11784
|
isHttpUrl as isHttpUrl4,
|
|
@@ -11804,7 +11846,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
11804
11846
|
const { video } = q;
|
|
11805
11847
|
if (isHttpUrl4(video.src)) return { reason: "remote_source" };
|
|
11806
11848
|
const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
|
|
11807
|
-
if (!
|
|
11849
|
+
if (!existsSync14(path)) return { reason: "source_missing" };
|
|
11808
11850
|
const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
|
|
11809
11851
|
if ("reason" in layout) return layout;
|
|
11810
11852
|
const layer = await buildVideoLayerInput(
|
|
@@ -11819,7 +11861,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
11819
11861
|
}
|
|
11820
11862
|
|
|
11821
11863
|
// src/services/render/stages/audioStage.ts
|
|
11822
|
-
import { existsSync as
|
|
11864
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
11823
11865
|
import { join as join27 } from "node:path";
|
|
11824
11866
|
import {
|
|
11825
11867
|
MIXED_AUDIO_FILENAME,
|
|
@@ -11831,16 +11873,17 @@ import {
|
|
|
11831
11873
|
} from "@hyperframes/engine";
|
|
11832
11874
|
|
|
11833
11875
|
// src/services/render/audioDeliveryLimit.ts
|
|
11834
|
-
import { existsSync as
|
|
11876
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
11835
11877
|
import { dirname as dirname11, join as join26 } from "node:path";
|
|
11836
11878
|
import {
|
|
11837
11879
|
applyAudioFxChain,
|
|
11838
11880
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
11839
11881
|
encodeAac as encodeAac2,
|
|
11840
|
-
renameWithRetry as
|
|
11882
|
+
renameWithRetry as renameWithRetry5
|
|
11841
11883
|
} from "@hyperframes/engine";
|
|
11842
11884
|
|
|
11843
11885
|
// src/services/render/audioPadTrim.ts
|
|
11886
|
+
import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
11844
11887
|
import { spawn } from "node:child_process";
|
|
11845
11888
|
import { dirname as dirname10, join as join25 } from "node:path";
|
|
11846
11889
|
import {
|
|
@@ -11851,7 +11894,7 @@ import {
|
|
|
11851
11894
|
getFfprobeBinary,
|
|
11852
11895
|
ManagedChildProcess,
|
|
11853
11896
|
removeScratch,
|
|
11854
|
-
renameWithRetry as
|
|
11897
|
+
renameWithRetry as renameWithRetry4,
|
|
11855
11898
|
runFfmpeg as runFfmpeg5,
|
|
11856
11899
|
trackChildProcess,
|
|
11857
11900
|
withPublicOnlyProxy
|
|
@@ -11992,10 +12035,10 @@ function sanitizeProbeFailure(reason, paths) {
|
|
|
11992
12035
|
}
|
|
11993
12036
|
async function padOrTrimAudioToVideoFrameCount(input) {
|
|
11994
12037
|
const probeVideo = input.probeVideoFrameInfo ?? ((videoPath) => defaultProbeVideoFrameInfo(videoPath, input.signal));
|
|
11995
|
-
const probeAudio = input.probeAudioInfo ?? defaultProbeAudioInfo;
|
|
12038
|
+
const probeAudio = input.probeAudioInfo ?? ((path, signal) => defaultProbeAudioInfo(path, signal, input.audioContainer));
|
|
11996
12039
|
const timeoutMs = input.timeoutMs ?? DEFAULT_CONFIG.ffmpegProcessTimeout;
|
|
11997
12040
|
const runner = input.runFfmpeg ?? ((args) => defaultRunFfmpeg(args, timeoutMs, input.signal));
|
|
11998
|
-
const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath);
|
|
12041
|
+
const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath, input.audioContainer);
|
|
11999
12042
|
const probeTruePeak = input.probeAudioTruePeakDbfs ?? (input.runFfmpeg || input.encodeAac ? void 0 : (audioPath, signal) => measureTruePeakDbfs(audioPath, { timeoutMs, signal }));
|
|
12000
12043
|
const [videoResult, audioResult] = await Promise.allSettled([
|
|
12001
12044
|
probeVideo(input.videoPath),
|
|
@@ -12043,7 +12086,7 @@ async function padOrTrimAudioToVideoFrameCount(input) {
|
|
|
12043
12086
|
);
|
|
12044
12087
|
try {
|
|
12045
12088
|
for (const step of plan2.steps) {
|
|
12046
|
-
const ffmpegResult = step.kind === "copy" ? await runner(step.args) : await encode(
|
|
12089
|
+
const ffmpegResult = step.kind === "copy" ? await runner([...localContainerInputArgs(input.audioContainer), ...step.args]) : await encode(
|
|
12047
12090
|
input.sourcePath ?? input.audioPath,
|
|
12048
12091
|
input.outputPath,
|
|
12049
12092
|
targetDurationSeconds,
|
|
@@ -12127,7 +12170,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
|
|
|
12127
12170
|
try {
|
|
12128
12171
|
const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
|
|
12129
12172
|
if (!result.success) throw new Error(result.error);
|
|
12130
|
-
|
|
12173
|
+
renameWithRetry4(cutPath, input.sourcePath, { copyFallback: true });
|
|
12131
12174
|
return true;
|
|
12132
12175
|
} catch {
|
|
12133
12176
|
removeScratch(input.sourcePath);
|
|
@@ -12154,7 +12197,7 @@ async function enforceAacTruePeak(input) {
|
|
|
12154
12197
|
if (truePeakDbfs <= AAC_DELIVERY_TRUE_PEAK_DBFS) {
|
|
12155
12198
|
if (measuredPath !== correctedPath) return { success: true };
|
|
12156
12199
|
const sourceCut = await cutSource(input, scratchDir, attenuationDb);
|
|
12157
|
-
|
|
12200
|
+
renameWithRetry4(correctedPath, input.audioPath, { copyFallback: true });
|
|
12158
12201
|
const loweredDb = Number((-attenuationDb).toFixed(2));
|
|
12159
12202
|
return sourceCut ? { success: true, loweredDb } : { success: true, loweredDb, sourceStale: true };
|
|
12160
12203
|
}
|
|
@@ -12209,7 +12252,8 @@ function failResult(outputPath, target, source, error) {
|
|
|
12209
12252
|
error
|
|
12210
12253
|
};
|
|
12211
12254
|
}
|
|
12212
|
-
async function defaultProbeVideoFrameInfo(videoPath, signal) {
|
|
12255
|
+
async function defaultProbeVideoFrameInfo(videoPath, signal, container) {
|
|
12256
|
+
const inputArgs = localContainerInputArgs(container);
|
|
12213
12257
|
const fastInfo = await runFfprobeJson(
|
|
12214
12258
|
[
|
|
12215
12259
|
"-v",
|
|
@@ -12220,6 +12264,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
|
|
|
12220
12264
|
"stream=nb_frames,r_frame_rate",
|
|
12221
12265
|
"-of",
|
|
12222
12266
|
"json",
|
|
12267
|
+
...inputArgs,
|
|
12223
12268
|
"--",
|
|
12224
12269
|
videoPath
|
|
12225
12270
|
],
|
|
@@ -12241,6 +12286,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
|
|
|
12241
12286
|
"stream=nb_read_packets,r_frame_rate",
|
|
12242
12287
|
"-of",
|
|
12243
12288
|
"json",
|
|
12289
|
+
...inputArgs,
|
|
12244
12290
|
"--",
|
|
12245
12291
|
videoPath
|
|
12246
12292
|
],
|
|
@@ -12263,8 +12309,8 @@ function parseFrameRate(rate) {
|
|
|
12263
12309
|
}
|
|
12264
12310
|
return { fpsNum, fpsDen };
|
|
12265
12311
|
}
|
|
12266
|
-
async function defaultProbeAudioInfo(audioPath, signal) {
|
|
12267
|
-
const metadata = await extractAudioMetadata3(audioPath, { signal });
|
|
12312
|
+
async function defaultProbeAudioInfo(audioPath, signal, inputContainer) {
|
|
12313
|
+
const metadata = await extractAudioMetadata3(audioPath, { signal, inputContainer });
|
|
12268
12314
|
return {
|
|
12269
12315
|
durationSeconds: metadata.durationSeconds,
|
|
12270
12316
|
sampleRate: metadata.sampleRate,
|
|
@@ -12275,9 +12321,9 @@ async function defaultProbeAudioInfo(audioPath, signal) {
|
|
|
12275
12321
|
async function defaultRunFfmpeg(args, timeoutMs, signal) {
|
|
12276
12322
|
return toStepResult(await runFfmpeg5(args, { signal, timeout: timeoutMs }), timeoutMs);
|
|
12277
12323
|
}
|
|
12278
|
-
function defaultAacEncoder(timeoutMs, signal, pcmSourcePath) {
|
|
12324
|
+
function defaultAacEncoder(timeoutMs, signal, pcmSourcePath, inputContainer) {
|
|
12279
12325
|
return async (inputPath, outputPath, durationSeconds, filter) => {
|
|
12280
|
-
const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1 };
|
|
12326
|
+
const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1, inputContainer };
|
|
12281
12327
|
return toStepResult(
|
|
12282
12328
|
await encodeAac(pcmSourcePath ?? inputPath, outputPath, durationSeconds, options),
|
|
12283
12329
|
timeoutMs
|
|
@@ -12350,8 +12396,8 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
12350
12396
|
measure: measureTruePeakDbfs,
|
|
12351
12397
|
applyChain: applyAudioFxChain,
|
|
12352
12398
|
encode: encodeAac2,
|
|
12353
|
-
rename:
|
|
12354
|
-
sourceExists:
|
|
12399
|
+
rename: renameWithRetry5,
|
|
12400
|
+
sourceExists: existsSync15
|
|
12355
12401
|
}) {
|
|
12356
12402
|
const { audioPath, sourcePath, signal, timeoutMs } = input;
|
|
12357
12403
|
if (!deps.sourceExists(sourcePath)) return { success: true };
|
|
@@ -12447,7 +12493,7 @@ async function runAudioStageScoped(input) {
|
|
|
12447
12493
|
);
|
|
12448
12494
|
audioLoweredDb = guard.loweredDb;
|
|
12449
12495
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
12450
|
-
if (input.keepDeliverySource && !guard.sourceStale &&
|
|
12496
|
+
if (input.keepDeliverySource && !guard.sourceStale && existsSync16(pcmSourcePath)) {
|
|
12451
12497
|
deliverySourcePath = pcmSourcePath;
|
|
12452
12498
|
}
|
|
12453
12499
|
}
|
|
@@ -12576,7 +12622,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
12576
12622
|
}
|
|
12577
12623
|
|
|
12578
12624
|
// src/services/render/stages/captureStage.ts
|
|
12579
|
-
import { existsSync as
|
|
12625
|
+
import { existsSync as existsSync17, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
12580
12626
|
import { join as join28 } from "node:path";
|
|
12581
12627
|
import {
|
|
12582
12628
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
@@ -12647,7 +12693,7 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
|
|
|
12647
12693
|
}
|
|
12648
12694
|
function measureCaptureFrameBytes(workDir, framesDir) {
|
|
12649
12695
|
let total = sampleDirectoryBytes(framesDir);
|
|
12650
|
-
if (!
|
|
12696
|
+
if (!existsSync17(workDir)) return total;
|
|
12651
12697
|
for (const attempt of readdirSync4(workDir)) {
|
|
12652
12698
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
12653
12699
|
total += sampleDirectoryBytes(join28(workDir, attempt));
|
|
@@ -12954,7 +13000,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
12954
13000
|
}
|
|
12955
13001
|
|
|
12956
13002
|
// src/services/render/stages/captureHdrStage.ts
|
|
12957
|
-
import { existsSync as
|
|
13003
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync10 } from "node:fs";
|
|
12958
13004
|
import { join as join32 } from "node:path";
|
|
12959
13005
|
import {
|
|
12960
13006
|
closeCaptureSession as closeCaptureSession7,
|
|
@@ -13201,7 +13247,7 @@ import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
|
13201
13247
|
import { dirname as dirname12, join as join30 } from "node:path";
|
|
13202
13248
|
import { createRequire } from "node:module";
|
|
13203
13249
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
13204
|
-
import { existsSync as
|
|
13250
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
13205
13251
|
function resolveWorkerEntry(explicit) {
|
|
13206
13252
|
if (explicit && explicit.length > 0) {
|
|
13207
13253
|
return { path: explicit, isTs: explicit.endsWith(".ts") };
|
|
@@ -13213,7 +13259,7 @@ function resolveWorkerEntry(explicit) {
|
|
|
13213
13259
|
}
|
|
13214
13260
|
const moduleDir = dirname12(fileURLToPath3(import.meta.url));
|
|
13215
13261
|
const jsPath = join30(moduleDir, "shaderTransitionWorker.js");
|
|
13216
|
-
if (
|
|
13262
|
+
if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
|
|
13217
13263
|
const tsPath = join30(moduleDir, "shaderTransitionWorker.ts");
|
|
13218
13264
|
return { path: tsPath, isTs: true };
|
|
13219
13265
|
}
|
|
@@ -13779,7 +13825,7 @@ async function runCaptureHdrStage(input) {
|
|
|
13779
13825
|
}
|
|
13780
13826
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
13781
13827
|
const debugDumpDir = debugDumpEnabled ? join32(framesDir, "debug-composite") : null;
|
|
13782
|
-
if (debugDumpDir && !
|
|
13828
|
+
if (debugDumpDir && !existsSync19(debugDumpDir)) {
|
|
13783
13829
|
mkdirSync10(debugDumpDir, { recursive: true });
|
|
13784
13830
|
}
|
|
13785
13831
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
@@ -13938,13 +13984,13 @@ async function runCaptureHdrStage(input) {
|
|
|
13938
13984
|
// src/services/render/stages/encodeStage.ts
|
|
13939
13985
|
import {
|
|
13940
13986
|
copyFileSync as copyFileSync4,
|
|
13941
|
-
existsSync as
|
|
13987
|
+
existsSync as existsSync20,
|
|
13942
13988
|
mkdirSync as mkdirSync11,
|
|
13943
13989
|
readdirSync as readdirSync5,
|
|
13944
13990
|
readFileSync as readFileSync9,
|
|
13945
13991
|
rmSync as rmSync11,
|
|
13946
13992
|
statSync as statSync9,
|
|
13947
|
-
writeFileSync as
|
|
13993
|
+
writeFileSync as writeFileSync5
|
|
13948
13994
|
} from "node:fs";
|
|
13949
13995
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
13950
13996
|
import { dirname as dirname13, join as join33 } from "node:path";
|
|
@@ -14040,7 +14086,7 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
|
|
|
14040
14086
|
const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
|
|
14041
14087
|
return gifEncodeFailure(startTime, outputPath, error);
|
|
14042
14088
|
}
|
|
14043
|
-
|
|
14089
|
+
writeFileSync5(outputPath, gif);
|
|
14044
14090
|
return null;
|
|
14045
14091
|
}
|
|
14046
14092
|
async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
@@ -14072,7 +14118,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
14072
14118
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
14073
14119
|
if (failure) return failure;
|
|
14074
14120
|
}
|
|
14075
|
-
const fileSize =
|
|
14121
|
+
const fileSize = existsSync20(outputPath) ? statSync9(outputPath).size : 0;
|
|
14076
14122
|
return {
|
|
14077
14123
|
success: true,
|
|
14078
14124
|
outputPath,
|
|
@@ -14241,7 +14287,7 @@ async function runEncodeStage(input) {
|
|
|
14241
14287
|
const stage5Start = Date.now();
|
|
14242
14288
|
if (isPngSequence) {
|
|
14243
14289
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
14244
|
-
if (!
|
|
14290
|
+
if (!existsSync20(outputPath)) mkdirSync11(outputPath, { recursive: true });
|
|
14245
14291
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
14246
14292
|
if (captured.length === 0) {
|
|
14247
14293
|
throw new Error(
|
|
@@ -14252,7 +14298,7 @@ async function runEncodeStage(input) {
|
|
|
14252
14298
|
const dst = join33(outputPath, formatExportFrameName(i, "png"));
|
|
14253
14299
|
copyFileSync4(join33(framesDir, name), dst);
|
|
14254
14300
|
});
|
|
14255
|
-
if (hasAudio && audioOutputPath &&
|
|
14301
|
+
if (hasAudio && audioOutputPath && existsSync20(audioOutputPath)) {
|
|
14256
14302
|
copyFileSync4(audioOutputPath, join33(outputPath, MIXED_AUDIO_FILENAME2));
|
|
14257
14303
|
log.info(
|
|
14258
14304
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
@@ -14643,7 +14689,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
14643
14689
|
let rangeStart = null;
|
|
14644
14690
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14645
14691
|
const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
14646
|
-
const missing = !
|
|
14692
|
+
const missing = !existsSync21(framePath) || statSync10(framePath).size <= 8;
|
|
14647
14693
|
if (missing && rangeStart === null) {
|
|
14648
14694
|
rangeStart = frameIndex;
|
|
14649
14695
|
} else if (!missing && rangeStart !== null) {
|
|
@@ -14776,7 +14822,7 @@ function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
|
14776
14822
|
let captured = 0;
|
|
14777
14823
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
14778
14824
|
const framePath = join34(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
14779
|
-
if (
|
|
14825
|
+
if (existsSync21(framePath)) captured++;
|
|
14780
14826
|
}
|
|
14781
14827
|
return captured;
|
|
14782
14828
|
}
|
|
@@ -15457,7 +15503,7 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
|
|
|
15457
15503
|
validateChromaSubsamplingConfig(job.config);
|
|
15458
15504
|
const debugDir = resolveRenderDebugDir();
|
|
15459
15505
|
const outputDir = dirname14(outputPath);
|
|
15460
|
-
if (!
|
|
15506
|
+
if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
15461
15507
|
const workDir = job.config.debug ? join34(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
15462
15508
|
const pipelineStart = Date.now();
|
|
15463
15509
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
@@ -15614,7 +15660,7 @@ async function executeRenderPipeline(input) {
|
|
|
15614
15660
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
15615
15661
|
assertNotAborted();
|
|
15616
15662
|
assertConfiguredFfmpegBinariesExist();
|
|
15617
|
-
if (!
|
|
15663
|
+
if (!existsSync21(workDir)) mkdirSync12(workDir, { recursive: true });
|
|
15618
15664
|
if (job.config.debug) {
|
|
15619
15665
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
15620
15666
|
}
|
|
@@ -15644,7 +15690,7 @@ async function executeRenderPipeline(input) {
|
|
|
15644
15690
|
});
|
|
15645
15691
|
const entryFile = job.config.entryFile || "index.html";
|
|
15646
15692
|
const htmlPath = join34(projectDir, entryFile);
|
|
15647
|
-
if (!
|
|
15693
|
+
if (!existsSync21(htmlPath)) {
|
|
15648
15694
|
throw new Error(`Entry file not found: ${htmlPath}`);
|
|
15649
15695
|
}
|
|
15650
15696
|
assertNotAborted();
|
|
@@ -16012,7 +16058,7 @@ async function executeRenderPipeline(input) {
|
|
|
16012
16058
|
throw new Error("File server failed to initialize before frame capture");
|
|
16013
16059
|
}
|
|
16014
16060
|
const framesDir = join34(workDir, "captured-frames");
|
|
16015
|
-
if (!
|
|
16061
|
+
if (!existsSync21(framesDir)) mkdirSync12(framesDir, { recursive: true });
|
|
16016
16062
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
16017
16063
|
code: "start_browsers"
|
|
16018
16064
|
});
|
|
@@ -16909,29 +16955,8 @@ async function executeRenderPipeline(input) {
|
|
|
16909
16955
|
pageMotionBlur: job.config.pageMotionBlur,
|
|
16910
16956
|
captureQuality: captureOptions.quality
|
|
16911
16957
|
});
|
|
16912
|
-
const segmentDir = segmentDirFor(
|
|
16958
|
+
const segmentDir = segmentDirFor(projectDir, segmentPlanHash);
|
|
16913
16959
|
const manifestKey = loadResumeKeyOrWarn(job.config.resumeSegments === true, log);
|
|
16914
|
-
let completedSegments = /* @__PURE__ */ new Set();
|
|
16915
|
-
if (job.config.resumeSegments === true) {
|
|
16916
|
-
const existing = readSegmentManifest(segmentDir);
|
|
16917
|
-
if (existing) {
|
|
16918
|
-
completedSegments = await validateCompletedSegments(existing, {
|
|
16919
|
-
expectedHash: segmentPlanHash,
|
|
16920
|
-
segmentDir,
|
|
16921
|
-
plan: planSegments(totalFrames, segmentFrames),
|
|
16922
|
-
key: manifestKey,
|
|
16923
|
-
probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
|
|
16924
|
-
});
|
|
16925
|
-
log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
|
|
16926
|
-
segmentDir
|
|
16927
|
-
});
|
|
16928
|
-
}
|
|
16929
|
-
if (completedSegments.size === 0) {
|
|
16930
|
-
rmSync12(segmentDir, { recursive: true, force: true });
|
|
16931
|
-
}
|
|
16932
|
-
} else {
|
|
16933
|
-
rmSync12(segmentDir, { recursive: true, force: true });
|
|
16934
|
-
}
|
|
16935
16960
|
const emptySegmentManifest = () => ({
|
|
16936
16961
|
version: 1,
|
|
16937
16962
|
planHash: segmentPlanHash,
|
|
@@ -16939,7 +16964,26 @@ async function executeRenderPipeline(input) {
|
|
|
16939
16964
|
segmentFrames,
|
|
16940
16965
|
completed: []
|
|
16941
16966
|
});
|
|
16942
|
-
let segmentManifest =
|
|
16967
|
+
let segmentManifest = emptySegmentManifest();
|
|
16968
|
+
let completedSegments = /* @__PURE__ */ new Set();
|
|
16969
|
+
const existing = job.config.resumeSegments ? readSegmentManifest(segmentDir) : null;
|
|
16970
|
+
if (existing) {
|
|
16971
|
+
completedSegments = await validateCompletedSegments(existing, {
|
|
16972
|
+
expectedHash: segmentPlanHash,
|
|
16973
|
+
segmentDir,
|
|
16974
|
+
totalFrames,
|
|
16975
|
+
segmentFrames,
|
|
16976
|
+
key: manifestKey,
|
|
16977
|
+
probeFrames: (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
|
|
16978
|
+
});
|
|
16979
|
+
segmentManifest.completed = existing.completed.filter(
|
|
16980
|
+
(entry) => completedSegments.has(entry.index)
|
|
16981
|
+
);
|
|
16982
|
+
log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
|
|
16983
|
+
segmentDir
|
|
16984
|
+
});
|
|
16985
|
+
}
|
|
16986
|
+
if (completedSegments.size === 0) rmSync12(segmentDir, { recursive: true, force: true });
|
|
16943
16987
|
const invokeSegmented = () => {
|
|
16944
16988
|
if (capturePlan.kind !== "sdr_segmented") {
|
|
16945
16989
|
throw new Error(`Cannot invoke segmented stage with ${capturePlan.kind} plan`);
|
|
@@ -17456,7 +17500,7 @@ async function executeRenderPipeline(input) {
|
|
|
17456
17500
|
})
|
|
17457
17501
|
);
|
|
17458
17502
|
const totalElapsed = Date.now() - pipelineStart;
|
|
17459
|
-
const tmpPeakBytes =
|
|
17503
|
+
const tmpPeakBytes = existsSync21(workDir) ? sampleDirectoryBytes(workDir) : 0;
|
|
17460
17504
|
recordTransientRetryObservability();
|
|
17461
17505
|
observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
|
|
17462
17506
|
const observabilitySummary = observability.summary({
|
|
@@ -17528,7 +17572,7 @@ async function executeRenderPipeline(input) {
|
|
|
17528
17572
|
job.perfSummary = perfSummary;
|
|
17529
17573
|
if (job.config.debug) {
|
|
17530
17574
|
try {
|
|
17531
|
-
|
|
17575
|
+
writeFileSync6(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
|
|
17532
17576
|
} catch (err) {
|
|
17533
17577
|
log.debug("Failed to write perf summary", {
|
|
17534
17578
|
perfOutputPath,
|
|
@@ -17537,7 +17581,7 @@ async function executeRenderPipeline(input) {
|
|
|
17537
17581
|
}
|
|
17538
17582
|
}
|
|
17539
17583
|
if (job.config.debug) {
|
|
17540
|
-
if (!isPngSequence && !isHls &&
|
|
17584
|
+
if (!isPngSequence && !isHls && existsSync21(stagedOutputPath)) {
|
|
17541
17585
|
const debugOutput = join34(workDir, `output${videoExt}`);
|
|
17542
17586
|
copyFileSync5(stagedOutputPath, debugOutput);
|
|
17543
17587
|
}
|
|
@@ -17663,7 +17707,7 @@ import { tmpdir as tmpdir5 } from "node:os";
|
|
|
17663
17707
|
// src/services/distributed/mp4Stitch.ts
|
|
17664
17708
|
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync13, rmSync as rmSync13 } from "node:fs";
|
|
17665
17709
|
import { open } from "node:fs/promises";
|
|
17666
|
-
import { renameWithRetry as
|
|
17710
|
+
import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
|
|
17667
17711
|
import { basename as basename8, dirname as dirname15, join as join35 } from "node:path";
|
|
17668
17712
|
import { finished, pipeline } from "node:stream/promises";
|
|
17669
17713
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
@@ -18037,7 +18081,7 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
18037
18081
|
for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
|
|
18038
18082
|
out.end();
|
|
18039
18083
|
await finished(out);
|
|
18040
|
-
|
|
18084
|
+
renameWithRetry6(join35(workDir, "out.mp4"), outputPath);
|
|
18041
18085
|
} finally {
|
|
18042
18086
|
out.destroy();
|
|
18043
18087
|
rmSync13(workDir, { recursive: true, force: true });
|
|
@@ -18054,25 +18098,25 @@ import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframe
|
|
|
18054
18098
|
import {
|
|
18055
18099
|
copyFileSync as copyFileSync6,
|
|
18056
18100
|
cpSync as cpSync2,
|
|
18057
|
-
existsSync as
|
|
18101
|
+
existsSync as existsSync26,
|
|
18058
18102
|
linkSync,
|
|
18059
18103
|
mkdirSync as mkdirSync16,
|
|
18060
18104
|
rmSync as rmSync14,
|
|
18061
|
-
writeFileSync as
|
|
18105
|
+
writeFileSync as writeFileSync9
|
|
18062
18106
|
} from "node:fs";
|
|
18063
18107
|
import { extname as extname6, isAbsolute as isAbsolute4, join as join43, relative as relative7, sep as sep5 } from "node:path";
|
|
18064
18108
|
import {
|
|
18065
18109
|
fpsToNumber as fpsToNumber9,
|
|
18066
18110
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
18067
18111
|
} from "@hyperframes/core";
|
|
18068
|
-
import { isSafePath as
|
|
18112
|
+
import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
|
|
18069
18113
|
import {
|
|
18070
18114
|
getEncoderPreset as getEncoderPreset4,
|
|
18071
18115
|
keyframeIntervalToGopSize as keyframeIntervalToGopSize3,
|
|
18072
18116
|
normalizeVp9CpuUsed,
|
|
18073
18117
|
resolveConfig as resolveConfig3,
|
|
18074
18118
|
declareContentAddressedUrl,
|
|
18075
|
-
renameWithRetry as
|
|
18119
|
+
renameWithRetry as renameWithRetry7,
|
|
18076
18120
|
declareProbeFactsUrl
|
|
18077
18121
|
} from "@hyperframes/engine";
|
|
18078
18122
|
|
|
@@ -18086,7 +18130,7 @@ import {
|
|
|
18086
18130
|
} from "@hyperframes/engine";
|
|
18087
18131
|
|
|
18088
18132
|
// src/services/distributed/chunkFrames.ts
|
|
18089
|
-
import { existsSync as
|
|
18133
|
+
import { existsSync as existsSync23, readdirSync as readdirSync7 } from "node:fs";
|
|
18090
18134
|
import { extname as extname4, join as join37 } from "node:path";
|
|
18091
18135
|
import {
|
|
18092
18136
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
@@ -18097,7 +18141,7 @@ import {
|
|
|
18097
18141
|
// src/services/distributed/shared.ts
|
|
18098
18142
|
import { execFile as execFileCallback } from "node:child_process";
|
|
18099
18143
|
import { dirname as dirname16, join as join36 } from "node:path";
|
|
18100
|
-
import { existsSync as
|
|
18144
|
+
import { existsSync as existsSync22, readFileSync as readFileSync10 } from "node:fs";
|
|
18101
18145
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
18102
18146
|
import { promisify as promisify2 } from "node:util";
|
|
18103
18147
|
import {
|
|
@@ -18113,7 +18157,7 @@ function isPlanAudioArtifactPath(path) {
|
|
|
18113
18157
|
function resolvePlanAudioPath(planDir) {
|
|
18114
18158
|
for (const name of [PLAN_AUDIO_RELATIVE_PATH, PLAN_AUDIO_LEGACY_RELATIVE_PATH]) {
|
|
18115
18159
|
const candidate = join36(planDir, name);
|
|
18116
|
-
if (
|
|
18160
|
+
if (existsSync22(candidate)) return candidate;
|
|
18117
18161
|
}
|
|
18118
18162
|
return null;
|
|
18119
18163
|
}
|
|
@@ -18378,7 +18422,7 @@ function readProducerVersion() {
|
|
|
18378
18422
|
let current = startDir;
|
|
18379
18423
|
for (let i = 0; i < 10; i++) {
|
|
18380
18424
|
const candidate = join36(current, "package.json");
|
|
18381
|
-
if (
|
|
18425
|
+
if (existsSync22(candidate)) {
|
|
18382
18426
|
try {
|
|
18383
18427
|
const pkg = JSON.parse(readFileSync10(candidate, "utf-8"));
|
|
18384
18428
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
@@ -18433,7 +18477,7 @@ function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v
|
|
|
18433
18477
|
const result = [];
|
|
18434
18478
|
for (const v of videos) {
|
|
18435
18479
|
const outputDir = join37(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
|
|
18436
|
-
if (!
|
|
18480
|
+
if (!existsSync23(outputDir)) {
|
|
18437
18481
|
throw new Error(
|
|
18438
18482
|
`[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
|
|
18439
18483
|
);
|
|
@@ -18532,7 +18576,7 @@ async function extractDeferredVideoFramesForChunk(input) {
|
|
|
18532
18576
|
const range = planned.get(video.videoId).deferredRange;
|
|
18533
18577
|
const remoteUrl = remoteSources[range.sourcePath];
|
|
18534
18578
|
const sourcePath = remoteUrl ?? join37(input.planDir, ...range.sourcePath.split("/"));
|
|
18535
|
-
if (remoteUrl === void 0 && !
|
|
18579
|
+
if (remoteUrl === void 0 && !existsSync23(sourcePath)) {
|
|
18536
18580
|
throw new RenderChunkValidationError(
|
|
18537
18581
|
MISSING_PLAN_ARTIFACT,
|
|
18538
18582
|
`[renderChunk] planDir is missing the source for video ${JSON.stringify(video.videoId)}: ${range.sourcePath}`
|
|
@@ -18732,7 +18776,7 @@ async function readPlanReferenceBackground(input) {
|
|
|
18732
18776
|
}
|
|
18733
18777
|
|
|
18734
18778
|
// src/services/render/stages/freezePlan.ts
|
|
18735
|
-
import { existsSync as
|
|
18779
|
+
import { existsSync as existsSync24, mkdirSync as mkdirSync14, readFileSync as readFileSync11, readdirSync as readdirSync8, writeFileSync as writeFileSync7 } from "node:fs";
|
|
18736
18780
|
import { join as join40, relative as relative5, resolve as resolve10 } from "node:path";
|
|
18737
18781
|
import {
|
|
18738
18782
|
REFERENCE_BACKGROUND_FIELD,
|
|
@@ -18832,7 +18876,7 @@ function readPlanProtocolV1(planJson, capabilities = DISTRIBUTED_RENDER_CAPABILI
|
|
|
18832
18876
|
|
|
18833
18877
|
// src/services/render/stages/planHash.ts
|
|
18834
18878
|
import { createHash as createHash8 } from "node:crypto";
|
|
18835
|
-
import { closeSync as
|
|
18879
|
+
import { closeSync as closeSync6, createReadStream as createReadStream5, openSync as openSync6, readSync as readSync5 } from "node:fs";
|
|
18836
18880
|
var PLAN_HASH_SCHEMA_PREFIX = "hyperframes-plan-hash-v1\0";
|
|
18837
18881
|
var FIELD_DELIMITER = Buffer.from([0]);
|
|
18838
18882
|
function computePlanHash(input) {
|
|
@@ -18890,7 +18934,7 @@ function sha256Hex(bytes) {
|
|
|
18890
18934
|
function sha256File(path) {
|
|
18891
18935
|
const hash = createHash8("sha256");
|
|
18892
18936
|
const buffer = Buffer.allocUnsafe(1024 * 1024);
|
|
18893
|
-
const fd =
|
|
18937
|
+
const fd = openSync6(path, "r");
|
|
18894
18938
|
try {
|
|
18895
18939
|
let bytesRead = 0;
|
|
18896
18940
|
do {
|
|
@@ -18898,7 +18942,7 @@ function sha256File(path) {
|
|
|
18898
18942
|
if (bytesRead > 0) hash.update(buffer.subarray(0, bytesRead));
|
|
18899
18943
|
} while (bytesRead > 0);
|
|
18900
18944
|
} finally {
|
|
18901
|
-
|
|
18945
|
+
closeSync6(fd);
|
|
18902
18946
|
}
|
|
18903
18947
|
return hash.digest("hex");
|
|
18904
18948
|
}
|
|
@@ -18926,7 +18970,7 @@ function planFileSha256(absolutePath, digests) {
|
|
|
18926
18970
|
return sha256;
|
|
18927
18971
|
}
|
|
18928
18972
|
async function prehashPlanFiles(dir, digests) {
|
|
18929
|
-
if (!
|
|
18973
|
+
if (!existsSync24(dir)) return;
|
|
18930
18974
|
for (const { absolutePath } of listPlanFiles(dir)) {
|
|
18931
18975
|
if (!digests.has(absolutePath)) digests.set(absolutePath, await sha256FileAsync(absolutePath));
|
|
18932
18976
|
}
|
|
@@ -18992,19 +19036,19 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
|
|
|
18992
19036
|
function writePlanRemoteFiles(planDir, files) {
|
|
18993
19037
|
if (files.length === 0) return;
|
|
18994
19038
|
const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
|
|
18995
|
-
|
|
19039
|
+
writeFileSync7(join40(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
|
|
18996
19040
|
}
|
|
18997
19041
|
function readPlanRemoteFiles(planDir) {
|
|
18998
19042
|
const path = join40(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
|
|
18999
|
-
return
|
|
19043
|
+
return existsSync24(path) ? JSON.parse(readFileSync11(path, "utf-8")) : [];
|
|
19000
19044
|
}
|
|
19001
19045
|
function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
19002
19046
|
const planJsonPath = join40(planDir, "plan.json");
|
|
19003
19047
|
const encoderJsonPath = join40(planDir, "meta", "encoder.json");
|
|
19004
|
-
if (!
|
|
19048
|
+
if (!existsSync24(planJsonPath)) {
|
|
19005
19049
|
throw new Error(`[freezePlan] plan.json missing: ${planJsonPath}`);
|
|
19006
19050
|
}
|
|
19007
|
-
if (!
|
|
19051
|
+
if (!existsSync24(encoderJsonPath)) {
|
|
19008
19052
|
throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
|
|
19009
19053
|
}
|
|
19010
19054
|
const planJson = JSON.parse(readFileSync11(planJsonPath, "utf-8"));
|
|
@@ -19034,12 +19078,12 @@ async function freezePlan(input) {
|
|
|
19034
19078
|
hasAudio,
|
|
19035
19079
|
digests
|
|
19036
19080
|
} = input;
|
|
19037
|
-
if (!
|
|
19081
|
+
if (!existsSync24(planDir)) {
|
|
19038
19082
|
throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
|
|
19039
19083
|
}
|
|
19040
19084
|
const metaDir = join40(planDir, "meta");
|
|
19041
|
-
if (!
|
|
19042
|
-
|
|
19085
|
+
if (!existsSync24(metaDir)) mkdirSync14(metaDir, { recursive: true });
|
|
19086
|
+
writeFileSync7(
|
|
19043
19087
|
join40(metaDir, "composition.json"),
|
|
19044
19088
|
`${JSON.stringify(composition, null, 2)}
|
|
19045
19089
|
`,
|
|
@@ -19047,8 +19091,8 @@ async function freezePlan(input) {
|
|
|
19047
19091
|
);
|
|
19048
19092
|
const encoderForCanonical = stripUndefined(encoder);
|
|
19049
19093
|
const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
|
|
19050
|
-
|
|
19051
|
-
|
|
19094
|
+
writeFileSync7(join40(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
|
|
19095
|
+
writeFileSync7(join40(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
|
|
19052
19096
|
`, "utf-8");
|
|
19053
19097
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
19054
19098
|
const planHash = computePlanHash({
|
|
@@ -19074,7 +19118,7 @@ async function freezePlan(input) {
|
|
|
19074
19118
|
hasAudio
|
|
19075
19119
|
};
|
|
19076
19120
|
const planJsonPath = join40(planDir, "plan.json");
|
|
19077
|
-
|
|
19121
|
+
writeFileSync7(planJsonPath, `${JSON.stringify(planJson, null, 2)}
|
|
19078
19122
|
`, "utf-8");
|
|
19079
19123
|
return { planJsonPath, planHash };
|
|
19080
19124
|
}
|
|
@@ -19115,8 +19159,8 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
|
|
|
19115
19159
|
}
|
|
19116
19160
|
|
|
19117
19161
|
// src/services/distributed/chunkAudio.ts
|
|
19118
|
-
import { closeSync as
|
|
19119
|
-
import { writeFileSync as
|
|
19162
|
+
import { closeSync as closeSync7, existsSync as existsSync25, ftruncateSync, mkdirSync as mkdirSync15, openSync as openSync7, readFileSync as readFileSync12 } from "node:fs";
|
|
19163
|
+
import { writeFileSync as writeFileSync8, writeSync } from "node:fs";
|
|
19120
19164
|
import { join as join41 } from "node:path";
|
|
19121
19165
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
19122
19166
|
function audioCutForChunk(grid, chunks, index, fps) {
|
|
@@ -19213,18 +19257,18 @@ async function writeChunkAudioSlices(input) {
|
|
|
19213
19257
|
const start = offsets[cut.firstPacket];
|
|
19214
19258
|
layout.partStarts[index] = start;
|
|
19215
19259
|
const end = offsets[last] + track.sizes[last];
|
|
19216
|
-
|
|
19260
|
+
writeFileSync8(join41(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
|
|
19217
19261
|
});
|
|
19218
19262
|
const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
|
|
19219
|
-
|
|
19220
|
-
|
|
19263
|
+
writeFileSync8(join41(input.planDir, SLICE_FRAME), Buffer.concat(frame));
|
|
19264
|
+
writeFileSync8(join41(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
|
|
19221
19265
|
}
|
|
19222
19266
|
function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
19223
19267
|
const layoutPath = join41(planDir, SLICE_LAYOUT);
|
|
19224
|
-
if (!
|
|
19268
|
+
if (!existsSync25(layoutPath)) return resolvePlanAudioPath(planDir);
|
|
19225
19269
|
const layout = JSON.parse(readFileSync12(layoutPath, "utf-8"));
|
|
19226
19270
|
const frame = readFileSync12(join41(planDir, SLICE_FRAME));
|
|
19227
|
-
const fd =
|
|
19271
|
+
const fd = openSync7(scratchPath, "w");
|
|
19228
19272
|
try {
|
|
19229
19273
|
writeSync(fd, frame, 0, layout.payloadStart, 0);
|
|
19230
19274
|
writeSync(
|
|
@@ -19241,7 +19285,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
|
19241
19285
|
}
|
|
19242
19286
|
ftruncateSync(fd, layout.sizeBytes);
|
|
19243
19287
|
} finally {
|
|
19244
|
-
|
|
19288
|
+
closeSync7(fd);
|
|
19245
19289
|
}
|
|
19246
19290
|
return scratchPath;
|
|
19247
19291
|
}
|
|
@@ -19788,7 +19832,7 @@ function createVideoSourceShipper(input) {
|
|
|
19788
19832
|
let result = null;
|
|
19789
19833
|
for (const root of stagedRel === null ? [input.workCompiledDir, input.projectDir] : []) {
|
|
19790
19834
|
const rel = pathInside(root, srcPath);
|
|
19791
|
-
if (rel !== null && (
|
|
19835
|
+
if (rel !== null && (existsSync26(join43(input.planDir, "compiled", rel)) || input.isRemote(srcPath))) {
|
|
19792
19836
|
result = ["compiled", ...rel.split(sep5)].join("/");
|
|
19793
19837
|
break;
|
|
19794
19838
|
}
|
|
@@ -19816,7 +19860,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
19816
19860
|
useGpu: false,
|
|
19817
19861
|
browserGpuMode: "software"
|
|
19818
19862
|
});
|
|
19819
|
-
if (!
|
|
19863
|
+
if (!existsSync26(planDir)) mkdirSync16(planDir, { recursive: true });
|
|
19820
19864
|
const log = config.logger ?? defaultLogger;
|
|
19821
19865
|
const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
|
|
19822
19866
|
const abortSignal = config.abortSignal;
|
|
@@ -19851,7 +19895,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
19851
19895
|
});
|
|
19852
19896
|
const entryFile = config.entryFile ?? "index.html";
|
|
19853
19897
|
const htmlPath = join43(projectDir, entryFile);
|
|
19854
|
-
if (!
|
|
19898
|
+
if (!existsSync26(htmlPath)) {
|
|
19855
19899
|
throw new Error(`[plan] entry file not found: ${htmlPath}`);
|
|
19856
19900
|
}
|
|
19857
19901
|
const workDir = join43(planDir, ".plan-work");
|
|
@@ -19871,7 +19915,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
19871
19915
|
const warn = (line) => log.warn(`[Plan] ${line}`);
|
|
19872
19916
|
const policy = { includeScripts: job.config.includeOutsideScripts };
|
|
19873
19917
|
if (refusesOutsideLink(projectDir, src, warn, policy)) return false;
|
|
19874
|
-
} else if (!
|
|
19918
|
+
} else if (!isSafePath3(projectDir, src)) return false;
|
|
19875
19919
|
const firstSegment = rel.split(sep5, 1)[0];
|
|
19876
19920
|
return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
|
|
19877
19921
|
}
|
|
@@ -20087,16 +20131,16 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20087
20131
|
logPlanStage(log, "extract", stageStarted);
|
|
20088
20132
|
const stagedVideoFrames = join43(compiledDir, "__hyperframes_video_frames");
|
|
20089
20133
|
const videoFramesDst = join43(planDir, "video-frames");
|
|
20090
|
-
if (
|
|
20134
|
+
if (existsSync26(videoFramesDst)) rmSync14(videoFramesDst, { recursive: true, force: true });
|
|
20091
20135
|
const videoSourcesDir = join43(planDir, "video-sources");
|
|
20092
20136
|
rmSync14(videoSourcesDir, { recursive: true, force: true });
|
|
20093
|
-
if (
|
|
20094
|
-
|
|
20137
|
+
if (existsSync26(stagedVideoFrames)) {
|
|
20138
|
+
renameWithRetry7(stagedVideoFrames, videoFramesDst);
|
|
20095
20139
|
} else {
|
|
20096
20140
|
mkdirSync16(videoFramesDst, { recursive: true });
|
|
20097
20141
|
}
|
|
20098
|
-
if (
|
|
20099
|
-
|
|
20142
|
+
if (existsSync26(finalCompiledDir)) rmSync14(finalCompiledDir, { recursive: true, force: true });
|
|
20143
|
+
renameWithRetry7(compiledDir, finalCompiledDir);
|
|
20100
20144
|
const shipVideoSource = createVideoSourceShipper({
|
|
20101
20145
|
planDir,
|
|
20102
20146
|
projectDir,
|
|
@@ -20134,7 +20178,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20134
20178
|
sizeBytes
|
|
20135
20179
|
}))
|
|
20136
20180
|
);
|
|
20137
|
-
|
|
20181
|
+
writeFileSync9(
|
|
20138
20182
|
join43(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
|
|
20139
20183
|
JSON.stringify(planVideosJson, null, 2),
|
|
20140
20184
|
"utf-8"
|
|
@@ -20216,10 +20260,10 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20216
20260
|
applyDistributedAudioWarningPolicy(job, audioResult.audioError, audioResult.audioFailures, log);
|
|
20217
20261
|
}
|
|
20218
20262
|
const planAudioPath = join43(planDir, PLAN_AUDIO_RELATIVE_PATH);
|
|
20219
|
-
if (audioResult?.hasAudio &&
|
|
20220
|
-
|
|
20263
|
+
if (audioResult?.hasAudio && existsSync26(audioResult.audioOutputPath)) {
|
|
20264
|
+
renameWithRetry7(audioResult.audioOutputPath, planAudioPath);
|
|
20221
20265
|
}
|
|
20222
|
-
if (chunksCarryAudio &&
|
|
20266
|
+
if (chunksCarryAudio && existsSync26(planAudioPath)) {
|
|
20223
20267
|
if (options.sliceChunkAudio) {
|
|
20224
20268
|
stageStarted = Date.now();
|
|
20225
20269
|
await writeChunkAudioSlices({
|
|
@@ -20341,7 +20385,7 @@ async function plan(projectDir, config, planDir, options = {}) {
|
|
|
20341
20385
|
|
|
20342
20386
|
// src/services/distributed/renderChunk.ts
|
|
20343
20387
|
import { randomBytes } from "node:crypto";
|
|
20344
|
-
import { existsSync as
|
|
20388
|
+
import { existsSync as existsSync29, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync12 } from "node:fs";
|
|
20345
20389
|
import { join as join47 } from "node:path";
|
|
20346
20390
|
import {
|
|
20347
20391
|
assertSwiftShader,
|
|
@@ -20368,14 +20412,14 @@ import {
|
|
|
20368
20412
|
} from "@hyperframes/engine";
|
|
20369
20413
|
import {
|
|
20370
20414
|
copyFileSync as copyFileSync8,
|
|
20371
|
-
existsSync as
|
|
20415
|
+
existsSync as existsSync28,
|
|
20372
20416
|
lstatSync as lstatSync5,
|
|
20373
20417
|
mkdirSync as mkdirSync18,
|
|
20374
20418
|
readFileSync as readFileSync13,
|
|
20375
20419
|
readdirSync as readdirSync10,
|
|
20376
20420
|
rmSync as rmSync16,
|
|
20377
20421
|
statSync as statSync12,
|
|
20378
|
-
writeFileSync as
|
|
20422
|
+
writeFileSync as writeFileSync11
|
|
20379
20423
|
} from "node:fs";
|
|
20380
20424
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
20381
20425
|
import { dirname as dirname18, isAbsolute as isAbsolute5, join as join46, relative as relative8, resolve as resolve11, sep as sep6 } from "node:path";
|
|
@@ -20383,20 +20427,20 @@ import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
|
20383
20427
|
import {
|
|
20384
20428
|
createFrameLookupTable as createFrameLookupTable5,
|
|
20385
20429
|
mediaIdPathSegment as mediaIdPathSegment4,
|
|
20386
|
-
renameWithRetry as
|
|
20430
|
+
renameWithRetry as renameWithRetry9
|
|
20387
20431
|
} from "@hyperframes/engine";
|
|
20388
20432
|
|
|
20389
20433
|
// src/services/distributed/planV2Publisher.ts
|
|
20390
20434
|
import {
|
|
20391
20435
|
copyFileSync as copyFileSync7,
|
|
20392
|
-
existsSync as
|
|
20436
|
+
existsSync as existsSync27,
|
|
20393
20437
|
linkSync as linkSync2,
|
|
20394
20438
|
mkdirSync as mkdirSync17,
|
|
20395
20439
|
rmSync as rmSync15,
|
|
20396
20440
|
statSync as statSync11,
|
|
20397
|
-
writeFileSync as
|
|
20441
|
+
writeFileSync as writeFileSync10
|
|
20398
20442
|
} from "node:fs";
|
|
20399
|
-
import { renameWithRetry as
|
|
20443
|
+
import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
|
|
20400
20444
|
import { dirname as dirname17, join as join45 } from "node:path";
|
|
20401
20445
|
|
|
20402
20446
|
// src/services/distributed/planV2Errors.ts
|
|
@@ -20453,7 +20497,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20453
20497
|
#linkFile;
|
|
20454
20498
|
#committed = false;
|
|
20455
20499
|
constructor(destinationDir, options = {}) {
|
|
20456
|
-
if (
|
|
20500
|
+
if (existsSync27(destinationDir)) {
|
|
20457
20501
|
throw new PlanV2IntegrityError(`output directory already exists: ${destinationDir}`);
|
|
20458
20502
|
}
|
|
20459
20503
|
this.destinationDir = destinationDir;
|
|
@@ -20470,7 +20514,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20470
20514
|
);
|
|
20471
20515
|
}
|
|
20472
20516
|
const destinationPath = planV2BlobPath(this.temporaryDir, digest);
|
|
20473
|
-
if (
|
|
20517
|
+
if (existsSync27(destinationPath)) return;
|
|
20474
20518
|
mkdirSync17(dirname17(destinationPath), { recursive: true });
|
|
20475
20519
|
const stagingDir = createStagingDir5(dirname17(destinationPath), ".plan-v2-blob-");
|
|
20476
20520
|
const temporaryPath = join45(stagingDir, "blob");
|
|
@@ -20481,21 +20525,21 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
20481
20525
|
if (!cannotHardLink(error)) throw error;
|
|
20482
20526
|
copyFileSync7(blob.sourcePath, temporaryPath);
|
|
20483
20527
|
}
|
|
20484
|
-
|
|
20528
|
+
renameWithRetry8(temporaryPath, destinationPath);
|
|
20485
20529
|
} finally {
|
|
20486
20530
|
rmSync15(stagingDir, { recursive: true, force: true });
|
|
20487
20531
|
}
|
|
20488
20532
|
}
|
|
20489
20533
|
async commitManifest(manifestBytes) {
|
|
20490
20534
|
for (const digest of new Set(manifestDigests(manifestBytes))) {
|
|
20491
|
-
if (!
|
|
20535
|
+
if (!existsSync27(planV2BlobPath(this.temporaryDir, digest))) {
|
|
20492
20536
|
throw new PlanV2IntegrityError(
|
|
20493
20537
|
`cannot commit manifest before referenced blob is durable: ${digest}`
|
|
20494
20538
|
);
|
|
20495
20539
|
}
|
|
20496
20540
|
}
|
|
20497
|
-
|
|
20498
|
-
|
|
20541
|
+
writeFileSync10(join45(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
|
|
20542
|
+
renameWithRetry8(this.temporaryDir, this.destinationDir);
|
|
20499
20543
|
this.#committed = true;
|
|
20500
20544
|
}
|
|
20501
20545
|
async abort() {
|
|
@@ -20568,7 +20612,7 @@ function assertValidExtractionCacheCompleteSentinel(path) {
|
|
|
20568
20612
|
}
|
|
20569
20613
|
function validateExtractionCacheCompleteSentinels(executionPlanDir) {
|
|
20570
20614
|
const videoRoot = join46(executionPlanDir, "video-frames");
|
|
20571
|
-
if (!
|
|
20615
|
+
if (!existsSync28(videoRoot)) return;
|
|
20572
20616
|
for (const videoEntry of readdirSync10(videoRoot, { withFileTypes: true })) {
|
|
20573
20617
|
if (!videoEntry.isDirectory()) continue;
|
|
20574
20618
|
const videoDir = join46(videoRoot, videoEntry.name);
|
|
@@ -20669,7 +20713,7 @@ function parsePlanVideosJson2(value) {
|
|
|
20669
20713
|
}
|
|
20670
20714
|
function materializeExtractedVideoDirectories(planDir) {
|
|
20671
20715
|
const videosPath = join46(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
20672
|
-
if (!
|
|
20716
|
+
if (!existsSync28(videosPath)) return;
|
|
20673
20717
|
const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
|
|
20674
20718
|
for (const video of videos.extracted) {
|
|
20675
20719
|
mkdirSync18(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
|
|
@@ -20703,9 +20747,9 @@ function parseChunkSlices(value) {
|
|
|
20703
20747
|
}
|
|
20704
20748
|
function buildVideoChunkDependencies(executionPlanDir, dimensions) {
|
|
20705
20749
|
const videoRoot = join46(executionPlanDir, "video-frames");
|
|
20706
|
-
const hasExtractedFrames =
|
|
20750
|
+
const hasExtractedFrames = existsSync28(videoRoot) && listFiles(videoRoot).length > 0;
|
|
20707
20751
|
const videosPath = join46(executionPlanDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
20708
|
-
if (!
|
|
20752
|
+
if (!existsSync28(videosPath)) {
|
|
20709
20753
|
return hasExtractedFrames ? { mode: "full-source-pack", dependencies: null } : { mode: "exact-rendered-frames", dependencies: /* @__PURE__ */ new Map() };
|
|
20710
20754
|
}
|
|
20711
20755
|
const chunksPath = join46(executionPlanDir, "meta", "chunks.json");
|
|
@@ -20762,13 +20806,13 @@ function computeManifestHash(manifest) {
|
|
|
20762
20806
|
return sha256Hex(`${PLAN_V2_HASH_PREFIX}${canonicalJsonStringify(manifestPayload(manifest))}`);
|
|
20763
20807
|
}
|
|
20764
20808
|
function writeBlob(sourcePath, destinationPath) {
|
|
20765
|
-
if (
|
|
20809
|
+
if (existsSync28(destinationPath)) return;
|
|
20766
20810
|
mkdirSync18(dirname18(destinationPath), { recursive: true });
|
|
20767
20811
|
const temporaryDir = createStagingDir6(dirname18(destinationPath), ".plan-v2-blob-");
|
|
20768
20812
|
const temporaryPath = join46(temporaryDir, "blob");
|
|
20769
20813
|
try {
|
|
20770
20814
|
copyFileSync8(sourcePath, temporaryPath);
|
|
20771
|
-
|
|
20815
|
+
renameWithRetry9(temporaryPath, destinationPath);
|
|
20772
20816
|
} finally {
|
|
20773
20817
|
rmSync16(temporaryDir, { recursive: true, force: true });
|
|
20774
20818
|
}
|
|
@@ -20802,7 +20846,7 @@ async function putTasks(tasks) {
|
|
|
20802
20846
|
}
|
|
20803
20847
|
function buildPlanV2Publication(executionPlanDir, digests) {
|
|
20804
20848
|
const executionPlanPath = join46(executionPlanDir, "plan.json");
|
|
20805
|
-
if (!
|
|
20849
|
+
if (!existsSync28(executionPlanPath)) {
|
|
20806
20850
|
throw new PlanV2IntegrityError(`execution plan is missing plan.json: ${executionPlanPath}`);
|
|
20807
20851
|
}
|
|
20808
20852
|
const executionPlanValue = readJsonFile(executionPlanPath, "execution plan.json");
|
|
@@ -20882,7 +20926,7 @@ function buildPlanV2Publication(executionPlanDir, digests) {
|
|
|
20882
20926
|
};
|
|
20883
20927
|
}
|
|
20884
20928
|
function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
20885
|
-
if (
|
|
20929
|
+
if (existsSync28(planV2Dir)) {
|
|
20886
20930
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
20887
20931
|
}
|
|
20888
20932
|
const publication = buildPlanV2Publication(executionPlanDir);
|
|
@@ -20895,12 +20939,12 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
|
20895
20939
|
for (const blob of publication.blobs) {
|
|
20896
20940
|
writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
|
|
20897
20941
|
}
|
|
20898
|
-
|
|
20942
|
+
writeFileSync11(
|
|
20899
20943
|
join46(tempDir, "plan.json"),
|
|
20900
20944
|
canonicalJsonStringify(publication.manifest),
|
|
20901
20945
|
"utf-8"
|
|
20902
20946
|
);
|
|
20903
|
-
|
|
20947
|
+
renameWithRetry9(tempDir, planV2Dir);
|
|
20904
20948
|
return resultFromManifest(planV2Dir, publication.manifest);
|
|
20905
20949
|
} catch (error) {
|
|
20906
20950
|
rmSync16(tempDir, { recursive: true, force: true });
|
|
@@ -20972,7 +21016,7 @@ async function planV2WithPublisher(projectDir, config, publisher, options = {})
|
|
|
20972
21016
|
}
|
|
20973
21017
|
}
|
|
20974
21018
|
async function planV2(projectDir, config, planV2Dir) {
|
|
20975
|
-
if (
|
|
21019
|
+
if (existsSync28(planV2Dir)) {
|
|
20976
21020
|
throw new PlanV2IntegrityError(`output directory already exists: ${planV2Dir}`);
|
|
20977
21021
|
}
|
|
20978
21022
|
const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
|
|
@@ -21126,7 +21170,7 @@ function parsePlanV2Manifest(value) {
|
|
|
21126
21170
|
}
|
|
21127
21171
|
function readPlanV2Manifest(planV2Dir) {
|
|
21128
21172
|
const manifestPath = join46(planV2Dir, "plan.json");
|
|
21129
|
-
if (!
|
|
21173
|
+
if (!existsSync28(manifestPath)) {
|
|
21130
21174
|
throw new PlanV2IntegrityError(`missing v2 manifest: ${manifestPath}`);
|
|
21131
21175
|
}
|
|
21132
21176
|
const value = readJsonFile(manifestPath, "v2 manifest");
|
|
@@ -21145,7 +21189,7 @@ function listPlanV2ArtifactsForTarget(manifest, target) {
|
|
|
21145
21189
|
}
|
|
21146
21190
|
function verifyBlob(planV2Dir, artifact) {
|
|
21147
21191
|
const sourcePath = planV2BlobPath(planV2Dir, artifact.sha256);
|
|
21148
|
-
if (!
|
|
21192
|
+
if (!existsSync28(sourcePath)) {
|
|
21149
21193
|
throw new PlanV2IntegrityError(`missing content-addressed artifact ${artifact.sha256}`);
|
|
21150
21194
|
}
|
|
21151
21195
|
const stats = statSync12(sourcePath);
|
|
@@ -21158,7 +21202,7 @@ function verifyBlob(planV2Dir, artifact) {
|
|
|
21158
21202
|
return sourcePath;
|
|
21159
21203
|
}
|
|
21160
21204
|
function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}) {
|
|
21161
|
-
if (
|
|
21205
|
+
if (existsSync28(destinationDir)) {
|
|
21162
21206
|
throw new PlanV2IntegrityError(`materialization destination already exists: ${destinationDir}`);
|
|
21163
21207
|
}
|
|
21164
21208
|
const manifest = readPlanV2Manifest(planV2Dir);
|
|
@@ -21179,7 +21223,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
21179
21223
|
copyFileSync8(sourcePath, destinationPath);
|
|
21180
21224
|
}
|
|
21181
21225
|
if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
|
|
21182
|
-
|
|
21226
|
+
writeFileSync11(
|
|
21183
21227
|
join46(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
|
|
21184
21228
|
canonicalJsonStringify({
|
|
21185
21229
|
manifest,
|
|
@@ -21188,7 +21232,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
21188
21232
|
}),
|
|
21189
21233
|
"utf-8"
|
|
21190
21234
|
);
|
|
21191
|
-
|
|
21235
|
+
renameWithRetry9(tempDir, destinationDir);
|
|
21192
21236
|
} catch (error) {
|
|
21193
21237
|
rmSync16(tempDir, { recursive: true, force: true });
|
|
21194
21238
|
throw error;
|
|
@@ -21223,7 +21267,7 @@ function validatePlanV2MaterializedTarget(planDir, expectedTarget) {
|
|
|
21223
21267
|
}
|
|
21224
21268
|
function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
21225
21269
|
const markerPath = join46(planDir, PLAN_V2_MATERIALIZATION_MARKER);
|
|
21226
|
-
if (!
|
|
21270
|
+
if (!existsSync28(markerPath)) return null;
|
|
21227
21271
|
const marker = readJsonFile(markerPath, "materialization marker");
|
|
21228
21272
|
if (!isRecord3(marker) || !isRecord3(marker.manifest) || !isRecord3(marker.target)) {
|
|
21229
21273
|
throw new PlanV2IntegrityError("malformed materialization marker");
|
|
@@ -21241,7 +21285,7 @@ function readValidatedPlanV2Materialization(planDir, expectedTarget) {
|
|
|
21241
21285
|
for (const artifact of required) {
|
|
21242
21286
|
if (Object.hasOwn(remoteSources, artifact.path)) continue;
|
|
21243
21287
|
const path = join46(planDir, ...artifact.path.split("/"));
|
|
21244
|
-
if (!
|
|
21288
|
+
if (!existsSync28(path) || statSync12(path).size !== artifact.sizeBytes) {
|
|
21245
21289
|
throw new PlanV2IntegrityError(
|
|
21246
21290
|
`materialized artifact missing or truncated: ${artifact.path}`
|
|
21247
21291
|
);
|
|
@@ -21392,7 +21436,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21392
21436
|
const planJsonPath = join47(planDir, "plan.json");
|
|
21393
21437
|
const encoderJsonPath = join47(planDir, "meta", "encoder.json");
|
|
21394
21438
|
const chunksJsonPath = join47(planDir, "meta", "chunks.json");
|
|
21395
|
-
if (!
|
|
21439
|
+
if (!existsSync29(planJsonPath)) {
|
|
21396
21440
|
throw new RenderChunkValidationError(
|
|
21397
21441
|
MISSING_PLAN_ARTIFACT,
|
|
21398
21442
|
`[renderChunk] planDir is missing required artifact: ${planJsonPath}`
|
|
@@ -21408,7 +21452,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21408
21452
|
const v2Manifest = v2Materialization?.manifest ?? null;
|
|
21409
21453
|
const remoteSources = v2Materialization?.remoteSources ?? {};
|
|
21410
21454
|
for (const required of [encoderJsonPath, chunksJsonPath]) {
|
|
21411
|
-
if (!
|
|
21455
|
+
if (!existsSync29(required)) {
|
|
21412
21456
|
throw new RenderChunkValidationError(
|
|
21413
21457
|
MISSING_PLAN_ARTIFACT,
|
|
21414
21458
|
`[renderChunk] planDir is missing required artifact: ${required}`
|
|
@@ -21419,7 +21463,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21419
21463
|
const chunks = JSON.parse(readFileSync14(chunksJsonPath, "utf-8"));
|
|
21420
21464
|
const videosJsonPath = join47(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
21421
21465
|
let planVideos = null;
|
|
21422
|
-
if (
|
|
21466
|
+
if (existsSync29(videosJsonPath)) {
|
|
21423
21467
|
try {
|
|
21424
21468
|
planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync14(videosJsonPath, "utf-8")));
|
|
21425
21469
|
} catch (err) {
|
|
@@ -21450,7 +21494,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21450
21494
|
const range = resolveChunkFrameRange(slice, chunkIndex, options?.frameRange);
|
|
21451
21495
|
const framesInChunk = range.endFrame - range.startFrame;
|
|
21452
21496
|
const compiledDir = join47(planDir, "compiled");
|
|
21453
|
-
if (!
|
|
21497
|
+
if (!existsSync29(compiledDir)) {
|
|
21454
21498
|
throw new RenderChunkValidationError(
|
|
21455
21499
|
MISSING_PLAN_ARTIFACT,
|
|
21456
21500
|
`[renderChunk] planDir missing compiled/ directory: ${compiledDir}`
|
|
@@ -21702,10 +21746,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21702
21746
|
const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
|
|
21703
21747
|
const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
|
|
21704
21748
|
if (isPngSequence) {
|
|
21705
|
-
if (!
|
|
21749
|
+
if (!existsSync29(outputChunkPath)) mkdirSync19(outputChunkPath, { recursive: true });
|
|
21706
21750
|
} else {
|
|
21707
21751
|
const outDir = join47(outputChunkPath, "..");
|
|
21708
|
-
if (!
|
|
21752
|
+
if (!existsSync29(outDir)) mkdirSync19(outDir, { recursive: true });
|
|
21709
21753
|
}
|
|
21710
21754
|
const encodeInput = {
|
|
21711
21755
|
job,
|
|
@@ -21918,7 +21962,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
21918
21962
|
producerVersion: plan2.producerVersion,
|
|
21919
21963
|
ffmpegVersion
|
|
21920
21964
|
};
|
|
21921
|
-
|
|
21965
|
+
writeFileSync12(perfPath, `${JSON.stringify(perfPayload, null, 2)}
|
|
21922
21966
|
`, "utf-8");
|
|
21923
21967
|
try {
|
|
21924
21968
|
rmSync17(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
@@ -22669,11 +22713,11 @@ import {
|
|
|
22669
22713
|
|
|
22670
22714
|
// src/server.ts
|
|
22671
22715
|
import {
|
|
22672
|
-
existsSync as
|
|
22716
|
+
existsSync as existsSync32,
|
|
22673
22717
|
mkdirSync as mkdirSync21,
|
|
22674
22718
|
statSync as statSync14,
|
|
22675
22719
|
mkdtempSync as mkdtempSync2,
|
|
22676
|
-
writeFileSync as
|
|
22720
|
+
writeFileSync as writeFileSync13,
|
|
22677
22721
|
rmSync as rmSync19,
|
|
22678
22722
|
createReadStream as createReadStream6
|
|
22679
22723
|
} from "node:fs";
|
|
@@ -22690,17 +22734,17 @@ import {
|
|
|
22690
22734
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD5,
|
|
22691
22735
|
referenceBackgroundResult as referenceBackgroundResult7
|
|
22692
22736
|
} from "@hyperframes/engine";
|
|
22693
|
-
import { isSafePath as
|
|
22737
|
+
import { isSafePath as isSafePath4 } from "@hyperframes/core/safe-path";
|
|
22694
22738
|
|
|
22695
22739
|
// src/services/hyperframeLint.ts
|
|
22696
22740
|
import {
|
|
22697
|
-
existsSync as
|
|
22741
|
+
existsSync as existsSync30,
|
|
22698
22742
|
readFileSync as readFileSync16,
|
|
22699
22743
|
statSync as statSync13,
|
|
22700
|
-
openSync as
|
|
22701
|
-
fstatSync as
|
|
22702
|
-
closeSync as
|
|
22703
|
-
constants as
|
|
22744
|
+
openSync as openSync8,
|
|
22745
|
+
fstatSync as fstatSync4,
|
|
22746
|
+
closeSync as closeSync8,
|
|
22747
|
+
constants as constants4
|
|
22704
22748
|
} from "node:fs";
|
|
22705
22749
|
import { resolve as resolve12, join as join49, relative as relative9, isAbsolute as isAbsolute6, sep as sep7, dirname as dirname19 } from "node:path";
|
|
22706
22750
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
@@ -22733,7 +22777,7 @@ function pickEntryFile(files, preferredEntryFile) {
|
|
|
22733
22777
|
function readEntryHtml(filePath) {
|
|
22734
22778
|
let fd;
|
|
22735
22779
|
try {
|
|
22736
|
-
fd =
|
|
22780
|
+
fd = openSync8(filePath, constants4.O_RDONLY | constants4.O_NONBLOCK);
|
|
22737
22781
|
} catch (error) {
|
|
22738
22782
|
if (error instanceof Error && "code" in error && (error.code === "ENOENT" || error.code === "ENOTDIR"))
|
|
22739
22783
|
return null;
|
|
@@ -22741,10 +22785,10 @@ function readEntryHtml(filePath) {
|
|
|
22741
22785
|
throw error;
|
|
22742
22786
|
}
|
|
22743
22787
|
try {
|
|
22744
|
-
if (!
|
|
22788
|
+
if (!fstatSync4(fd).isFile()) return null;
|
|
22745
22789
|
return readFileSync16(fd, "utf-8");
|
|
22746
22790
|
} finally {
|
|
22747
|
-
|
|
22791
|
+
closeSync8(fd);
|
|
22748
22792
|
}
|
|
22749
22793
|
}
|
|
22750
22794
|
function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
@@ -22753,7 +22797,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
|
22753
22797
|
}
|
|
22754
22798
|
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
22755
22799
|
const absProjectDir = resolve12(projectDir);
|
|
22756
|
-
if (!
|
|
22800
|
+
if (!existsSync30(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
|
|
22757
22801
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
22758
22802
|
}
|
|
22759
22803
|
const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
|
|
@@ -22844,7 +22888,7 @@ function resolveLintWorkerEntry() {
|
|
|
22844
22888
|
const here = dirname19(fileURLToPath6(import.meta.url));
|
|
22845
22889
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
22846
22890
|
const candidate = join49(here, name);
|
|
22847
|
-
if (
|
|
22891
|
+
if (existsSync30(candidate)) return candidate;
|
|
22848
22892
|
}
|
|
22849
22893
|
return void 0;
|
|
22850
22894
|
}
|
|
@@ -22915,7 +22959,7 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
22915
22959
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
22916
22960
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
22917
22961
|
import { dirname as dirname20, join as join50 } from "node:path";
|
|
22918
|
-
import { existsSync as
|
|
22962
|
+
import { existsSync as existsSync31 } from "node:fs";
|
|
22919
22963
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
22920
22964
|
async function startHealthWorker(options = {}) {
|
|
22921
22965
|
const log = options.logger ?? defaultLogger2();
|
|
@@ -22992,7 +23036,7 @@ function resolveWorkerEntry2() {
|
|
|
22992
23036
|
const here = dirname20(fileURLToPath7(import.meta.url));
|
|
22993
23037
|
const candidates = [join50(here, "healthWorkerThread.js"), join50(here, "healthWorkerThread.ts")];
|
|
22994
23038
|
for (const candidate of candidates) {
|
|
22995
|
-
if (
|
|
23039
|
+
if (existsSync31(candidate)) return candidate;
|
|
22996
23040
|
}
|
|
22997
23041
|
return void 0;
|
|
22998
23042
|
}
|
|
@@ -23157,12 +23201,12 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
23157
23201
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
|
|
23158
23202
|
if (confineOutput) {
|
|
23159
23203
|
mkdirSync21(rendersDir, { recursive: true });
|
|
23160
|
-
if (!
|
|
23204
|
+
if (!isSafePath4(rendersDir, absoluteOutputPath)) {
|
|
23161
23205
|
throw new Error("outputPath must be inside the renders directory");
|
|
23162
23206
|
}
|
|
23163
23207
|
}
|
|
23164
23208
|
const outputDir = dirname21(absoluteOutputPath);
|
|
23165
|
-
if (!
|
|
23209
|
+
if (!existsSync32(outputDir)) mkdirSync21(outputDir, { recursive: true });
|
|
23166
23210
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
23167
23211
|
}
|
|
23168
23212
|
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
@@ -23230,22 +23274,22 @@ function resolveRenderRequestPolicy(options) {
|
|
|
23230
23274
|
};
|
|
23231
23275
|
}
|
|
23232
23276
|
function isAllowedProjectPath(projectsDir, path) {
|
|
23233
|
-
return
|
|
23277
|
+
return isSafePath4(projectsDir, path) && !isSafePath4(resolveRenderDebugDir(), path);
|
|
23234
23278
|
}
|
|
23235
23279
|
function isAllowedEntryPath(policy, projectDir, path) {
|
|
23236
|
-
return
|
|
23280
|
+
return isSafePath4(projectDir, path) && isAllowedProjectPath(policy.projectsDir, path);
|
|
23237
23281
|
}
|
|
23238
23282
|
function prepareProjectDirectory(projectDir, options, policy) {
|
|
23239
23283
|
const candidate = nonEmptyString(projectDir);
|
|
23240
23284
|
if (!candidate) return null;
|
|
23241
23285
|
const absProjectDir = policy ? resolve13(policy.projectsDir, candidate) : resolve13(candidate);
|
|
23242
23286
|
const shown = policy ? candidate : absProjectDir;
|
|
23243
|
-
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !
|
|
23287
|
+
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync32(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
|
|
23244
23288
|
return { error: `Project directory not found: ${shown}` };
|
|
23245
23289
|
}
|
|
23246
23290
|
const entry = options.entryFile || "index.html";
|
|
23247
23291
|
const entryPath = resolve13(absProjectDir, entry);
|
|
23248
|
-
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !
|
|
23292
|
+
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync32(entryPath)) {
|
|
23249
23293
|
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
23250
23294
|
}
|
|
23251
23295
|
return { prepared: { input: { projectDir: absProjectDir, ...options } } };
|
|
@@ -23267,7 +23311,7 @@ async function resolveInlineRenderHtml(body) {
|
|
|
23267
23311
|
function materializeInlineProject(html, options) {
|
|
23268
23312
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
|
|
23269
23313
|
const tempProjectDir = mkdtempSync2(join51(tempRoot, "producer-project-"));
|
|
23270
|
-
|
|
23314
|
+
writeFileSync13(join51(tempProjectDir, "index.html"), html, "utf-8");
|
|
23271
23315
|
return {
|
|
23272
23316
|
prepared: {
|
|
23273
23317
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -23343,7 +23387,7 @@ function publicPerfSummary(job) {
|
|
|
23343
23387
|
return job.perfSummary ? { ...job.perfSummary, renderId: void 0 } : null;
|
|
23344
23388
|
}
|
|
23345
23389
|
function outputFileSize(path) {
|
|
23346
|
-
return
|
|
23390
|
+
return existsSync32(path) ? statSync14(path).size : 0;
|
|
23347
23391
|
}
|
|
23348
23392
|
function createBlockingProgressReporter(log, requestId) {
|
|
23349
23393
|
let lastLoggedPct = -10;
|
|
@@ -23670,7 +23714,7 @@ function createRenderHandlers(options = {}) {
|
|
|
23670
23714
|
if (!artifact) {
|
|
23671
23715
|
return c.json({ success: false, error: "Output artifact not found or expired" }, 404);
|
|
23672
23716
|
}
|
|
23673
|
-
if (!
|
|
23717
|
+
if (!existsSync32(artifact.path)) {
|
|
23674
23718
|
store.delete(token);
|
|
23675
23719
|
return c.json({ success: false, error: "Output artifact file missing" }, 404);
|
|
23676
23720
|
}
|
|
@@ -23870,17 +23914,18 @@ import {
|
|
|
23870
23914
|
} from "@hyperframes/engine";
|
|
23871
23915
|
import {
|
|
23872
23916
|
cpSync as cpSync3,
|
|
23873
|
-
existsSync as
|
|
23917
|
+
existsSync as existsSync33,
|
|
23874
23918
|
mkdirSync as mkdirSync22,
|
|
23875
23919
|
readFileSync as readFileSync17,
|
|
23876
23920
|
readdirSync as readdirSync12,
|
|
23877
23921
|
rmSync as rmSync20,
|
|
23878
|
-
statSync as statSync15
|
|
23879
|
-
writeFileSync as writeFileSync15
|
|
23922
|
+
statSync as statSync15
|
|
23880
23923
|
} from "node:fs";
|
|
23924
|
+
import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
|
|
23881
23925
|
import { basename as basename9, dirname as dirname22, join as join52 } from "node:path";
|
|
23882
23926
|
import {
|
|
23883
23927
|
appendRateCapArgs as appendRateCapArgs2,
|
|
23928
|
+
writeVideoConcatList,
|
|
23884
23929
|
appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
|
|
23885
23930
|
concatListInputArgs,
|
|
23886
23931
|
describeFfmpegFailure as describeFfmpegFailure5,
|
|
@@ -23890,7 +23935,7 @@ import {
|
|
|
23890
23935
|
resolveConfig as resolveConfig7,
|
|
23891
23936
|
runFfmpeg as runFfmpeg8,
|
|
23892
23937
|
appendSoftwareEncoderThreadsArg,
|
|
23893
|
-
renameWithRetry as
|
|
23938
|
+
renameWithRetry as renameWithRetry10
|
|
23894
23939
|
} from "@hyperframes/engine";
|
|
23895
23940
|
import { fpsToFfmpegArg as fpsToFfmpegArg3 } from "@hyperframes/core";
|
|
23896
23941
|
import { createStagingDir as createStagingDir7 } from "@hyperframes/core/atomic-file";
|
|
@@ -23926,7 +23971,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23926
23971
|
}
|
|
23927
23972
|
const format = plan2.dimensions.format;
|
|
23928
23973
|
const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
|
|
23929
|
-
if (!
|
|
23974
|
+
if (!existsSync33(dirname22(outputPath))) {
|
|
23930
23975
|
mkdirSync22(dirname22(outputPath), { recursive: true });
|
|
23931
23976
|
}
|
|
23932
23977
|
const workDir = createStagingDir7(dirname22(outputPath), `${basename9(outputPath)}.assemble-work-`);
|
|
@@ -23950,9 +23995,9 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23950
23995
|
try {
|
|
23951
23996
|
const videoSources = cfrEncoder ? [await reencodeCfr(ctx, chunkPaths, cfrEncoder)] : chunkPaths;
|
|
23952
23997
|
const finalPath = join52(workDir, `output.${format}`);
|
|
23953
|
-
const audio = audioPath !== null &&
|
|
23998
|
+
const audio = audioPath !== null && existsSync33(audioPath) ? audioPath : null;
|
|
23954
23999
|
await writeJoined(ctx, videoSources, audio, finalPath);
|
|
23955
|
-
|
|
24000
|
+
renameWithRetry10(finalPath, outputPath);
|
|
23956
24001
|
log.info("[assemble] stage timings", {
|
|
23957
24002
|
...stageMs,
|
|
23958
24003
|
chunks: chunkPaths.length,
|
|
@@ -23968,7 +24013,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23968
24013
|
});
|
|
23969
24014
|
}
|
|
23970
24015
|
}
|
|
23971
|
-
const fileSize =
|
|
24016
|
+
const fileSize = existsSync33(outputPath) ? statSync15(outputPath).size : 0;
|
|
23972
24017
|
return {
|
|
23973
24018
|
...referenceBackgroundResult8(plan2[REFERENCE_BACKGROUND_FIELD6]),
|
|
23974
24019
|
outputPath,
|
|
@@ -23980,13 +24025,13 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
23980
24025
|
function readAssemblePlan(planDir, chunkPaths) {
|
|
23981
24026
|
const planJsonPath = join52(planDir, "plan.json");
|
|
23982
24027
|
const chunksJsonPath = join52(planDir, "meta", "chunks.json");
|
|
23983
|
-
if (!
|
|
24028
|
+
if (!existsSync33(planJsonPath)) {
|
|
23984
24029
|
throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
|
|
23985
24030
|
}
|
|
23986
24031
|
const plan2 = JSON.parse(readFileSync17(planJsonPath, "utf-8"));
|
|
23987
24032
|
readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
|
|
23988
24033
|
validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
|
|
23989
|
-
if (!
|
|
24034
|
+
if (!existsSync33(chunksJsonPath)) {
|
|
23990
24035
|
throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
|
|
23991
24036
|
}
|
|
23992
24037
|
const chunks = JSON.parse(readFileSync17(chunksJsonPath, "utf-8"));
|
|
@@ -24001,14 +24046,18 @@ function readAssemblePlan(planDir, chunkPaths) {
|
|
|
24001
24046
|
}
|
|
24002
24047
|
}
|
|
24003
24048
|
for (const path of chunkPaths.flat()) {
|
|
24004
|
-
if (!
|
|
24049
|
+
if (!existsSync33(path)) {
|
|
24005
24050
|
throw new Error(`[assemble] chunk path does not exist: ${path}`);
|
|
24006
24051
|
}
|
|
24007
24052
|
}
|
|
24008
24053
|
return plan2;
|
|
24009
24054
|
}
|
|
24010
24055
|
function videoInputArgs(ctx, videoSources) {
|
|
24011
|
-
return videoSources.length === 1 ? [
|
|
24056
|
+
return videoSources.length === 1 ? [
|
|
24057
|
+
...localContainerInputArgs2(ctx.format === "webm" ? "matroska" : "mov"),
|
|
24058
|
+
"-i",
|
|
24059
|
+
videoSources[0]
|
|
24060
|
+
] : ["-r", ctx.fpsArg, ...concatListInputArgs(writeVideoConcatList(ctx.workDir, videoSources))];
|
|
24012
24061
|
}
|
|
24013
24062
|
function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
|
|
24014
24063
|
const args = [
|
|
@@ -24062,8 +24111,9 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
24062
24111
|
"audioMs",
|
|
24063
24112
|
() => padOrTrimAudioToVideoFrameCount({
|
|
24064
24113
|
videoPath: videoSources[0],
|
|
24065
|
-
probeVideoFrameInfo: () => probeJoinedFrameInfo(videoSources, ctx
|
|
24114
|
+
probeVideoFrameInfo: () => probeJoinedFrameInfo(videoSources, ctx),
|
|
24066
24115
|
audioPath,
|
|
24116
|
+
audioContainer: "mov",
|
|
24067
24117
|
outputPath: paddedAudioPath,
|
|
24068
24118
|
signal: ctx.signal,
|
|
24069
24119
|
timeoutMs: ctx.timeout
|
|
@@ -24086,6 +24136,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
24086
24136
|
ctx.signal,
|
|
24087
24137
|
{
|
|
24088
24138
|
audioCodec: "aac",
|
|
24139
|
+
audioContainer: "mov",
|
|
24089
24140
|
ffmpegProcessTimeout: ctx.timeout,
|
|
24090
24141
|
videoInputArgs: videoInputArgs(ctx, videoSources)
|
|
24091
24142
|
},
|
|
@@ -24096,21 +24147,16 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
|
|
|
24096
24147
|
throw encoderFailureError("[assemble] audio mux failed", muxResult);
|
|
24097
24148
|
}
|
|
24098
24149
|
}
|
|
24099
|
-
function
|
|
24100
|
-
const listPath = join52(workDir, "concat-list.txt");
|
|
24101
|
-
const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
|
|
24102
|
-
writeFileSync15(listPath, `${body}
|
|
24103
|
-
`, "utf-8");
|
|
24104
|
-
return ["-r", fpsArg, ...concatListInputArgs(listPath)];
|
|
24105
|
-
}
|
|
24106
|
-
async function probeJoinedFrameInfo(videoPaths, fps, signal) {
|
|
24150
|
+
async function probeJoinedFrameInfo(videoPaths, ctx) {
|
|
24107
24151
|
const infos = await Promise.all(
|
|
24108
|
-
videoPaths.map(
|
|
24152
|
+
videoPaths.map(
|
|
24153
|
+
(path) => defaultProbeVideoFrameInfo(path, ctx.signal, ctx.format === "webm" ? "matroska" : "mov")
|
|
24154
|
+
)
|
|
24109
24155
|
);
|
|
24110
24156
|
return {
|
|
24111
24157
|
frameCount: infos.reduce((sum2, info) => sum2 + info.frameCount, 0),
|
|
24112
|
-
fpsNum: fps.num,
|
|
24113
|
-
fpsDen: fps.den
|
|
24158
|
+
fpsNum: ctx.fps.num,
|
|
24159
|
+
fpsDen: ctx.fps.den
|
|
24114
24160
|
};
|
|
24115
24161
|
}
|
|
24116
24162
|
async function runAssembleFfmpeg(args, step, signal, timeout) {
|
|
@@ -24140,7 +24186,7 @@ function planFormat(planDir) {
|
|
|
24140
24186
|
}
|
|
24141
24187
|
function lockedAudio(planDir) {
|
|
24142
24188
|
const encoderJsonPath = join52(planDir, "meta", "encoder.json");
|
|
24143
|
-
if (!
|
|
24189
|
+
if (!existsSync33(encoderJsonPath)) return {};
|
|
24144
24190
|
return JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
|
|
24145
24191
|
}
|
|
24146
24192
|
function readCfrEncoder(planDir, format) {
|
|
@@ -24150,7 +24196,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
24150
24196
|
);
|
|
24151
24197
|
}
|
|
24152
24198
|
const encoderJsonPath = join52(planDir, "meta", "encoder.json");
|
|
24153
|
-
if (!
|
|
24199
|
+
if (!existsSync33(encoderJsonPath)) {
|
|
24154
24200
|
throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
|
|
24155
24201
|
}
|
|
24156
24202
|
const encoderJson = JSON.parse(readFileSync17(encoderJsonPath, "utf-8"));
|
|
@@ -24162,7 +24208,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
24162
24208
|
return encoderJson;
|
|
24163
24209
|
}
|
|
24164
24210
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
24165
|
-
if (
|
|
24211
|
+
if (existsSync33(outputPath)) rmSync20(outputPath, { recursive: true, force: true });
|
|
24166
24212
|
mkdirSync22(outputPath, { recursive: true });
|
|
24167
24213
|
let globalIdx = 0;
|
|
24168
24214
|
for (const chunkDir of chunkPaths) {
|
|
@@ -24186,7 +24232,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
|
|
|
24186
24232
|
`[assemble] png-sequence frame count mismatch: merged ${globalIdx} frames vs plan.totalFrames=${totalFrames}. Using on-disk count.`
|
|
24187
24233
|
);
|
|
24188
24234
|
}
|
|
24189
|
-
if (audioPath !== null &&
|
|
24235
|
+
if (audioPath !== null && existsSync33(audioPath)) {
|
|
24190
24236
|
const sidecar = join52(outputPath, MIXED_AUDIO_FILENAME4);
|
|
24191
24237
|
cpSync3(audioPath, sidecar);
|
|
24192
24238
|
}
|