@hyperframes/producer 0.9.93 → 0.9.95
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/compileWorker.js +24 -13
- package/dist/distributed.js +82 -54
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +67 -67
- package/dist/index.js +445 -275
- package/dist/public-server.js +349 -179
- package/dist/services/render/captureCost.d.ts +4 -1
- package/dist/services/render/frameWindow.d.ts +17 -0
- package/dist/services/render/gpuChoice.d.ts +15 -0
- package/dist/services/render/stages/audioStage.d.ts +6 -1
- package/dist/services/render/stages/captureHdrFrameShared.d.ts +4 -1
- package/dist/services/renderOrchestrator.d.ts +5 -0
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -10,11 +10,11 @@ import {
|
|
|
10
10
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
|
|
11
11
|
import {
|
|
12
12
|
existsSync as existsSync22,
|
|
13
|
-
mkdirSync as
|
|
13
|
+
mkdirSync as mkdirSync13,
|
|
14
14
|
readdirSync as readdirSync6,
|
|
15
15
|
rmSync as rmSync13,
|
|
16
16
|
statSync as statSync10,
|
|
17
|
-
writeFileSync as
|
|
17
|
+
writeFileSync as writeFileSync7,
|
|
18
18
|
copyFileSync as copyFileSync5,
|
|
19
19
|
appendFileSync
|
|
20
20
|
} from "fs";
|
|
@@ -339,6 +339,7 @@ import {
|
|
|
339
339
|
LOW_MEMORY_TOTAL_MB_THRESHOLD,
|
|
340
340
|
assertConfiguredFfmpegBinariesExist,
|
|
341
341
|
resolveBrowserGpuMode,
|
|
342
|
+
probedHardwareGpu,
|
|
342
343
|
resolveHeadlessShellPath,
|
|
343
344
|
compositionRequiresWebGpu as compositionRequiresWebGpu2,
|
|
344
345
|
applyConcreteGpuScreenshotClamp,
|
|
@@ -360,7 +361,8 @@ import {
|
|
|
360
361
|
referenceBackgroundResult,
|
|
361
362
|
createReferenceBackgroundRecorder
|
|
362
363
|
} from "@hyperframes/engine";
|
|
363
|
-
import { join as join35, dirname as
|
|
364
|
+
import { join as join35, dirname as dirname16, resolve as resolve10 } from "path";
|
|
365
|
+
import { fromEmptyFolder } from "@hyperframes/parsers/ff-binaries";
|
|
364
366
|
import { totalmem as totalmem2 } from "node:os";
|
|
365
367
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
366
368
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -390,7 +392,7 @@ import {
|
|
|
390
392
|
serviceWorkerScriptFetch
|
|
391
393
|
} from "@hyperframes/core/studio-preview-mark";
|
|
392
394
|
import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
|
|
393
|
-
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
|
395
|
+
import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
|
|
394
396
|
import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
|
|
395
397
|
import { openRangeEnd } from "@hyperframes/studio-server/media-range";
|
|
396
398
|
|
|
@@ -532,7 +534,7 @@ import {
|
|
|
532
534
|
} from "node:path";
|
|
533
535
|
import { statSync } from "node:fs";
|
|
534
536
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
535
|
-
import { isSafePath } from "@hyperframes/core/safe-path";
|
|
537
|
+
import { isPrivateFileUnder, isSafePath, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
|
536
538
|
import {
|
|
537
539
|
isCopiedOutsideFileType,
|
|
538
540
|
isPrivateOutsideFile,
|
|
@@ -559,7 +561,10 @@ function escapesAssetRoot(path, assetRoot) {
|
|
|
559
561
|
return assetRoot !== void 0 && !isSafePath(assetRoot, path);
|
|
560
562
|
}
|
|
561
563
|
function outsideAssetRefusal(projectDir, path, policy = {}) {
|
|
562
|
-
if (!linksOutside(projectDir, path))
|
|
564
|
+
if (!linksOutside(projectDir, path)) {
|
|
565
|
+
const privateByAnotherSpelling = !isPathInside(path, projectDir) && isPrivateFileUnder(projectDir, path, isStudioPrivatePath);
|
|
566
|
+
return privateByAnotherSpelling ? "blocklisted" : null;
|
|
567
|
+
}
|
|
563
568
|
if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
|
|
564
569
|
const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
|
|
565
570
|
if (folder || isUploadedOutsideFileType(path)) return null;
|
|
@@ -1185,7 +1190,7 @@ function createFileServer(options) {
|
|
|
1185
1190
|
const candidate = join2(root, relativePath);
|
|
1186
1191
|
const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
|
|
1187
1192
|
if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
|
|
1188
|
-
if (
|
|
1193
|
+
if (isPrivateFileUnder2(root, candidate, isStudioPrivatePath2)) continue;
|
|
1189
1194
|
const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
|
|
1190
1195
|
if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut, outsidePolicy)) continue;
|
|
1191
1196
|
file = openRegularFile(candidate);
|
|
@@ -1267,13 +1272,13 @@ function createFileServer(options) {
|
|
|
1267
1272
|
if (!streamOwnsFd) closeSync(fd);
|
|
1268
1273
|
}
|
|
1269
1274
|
});
|
|
1270
|
-
return new Promise((
|
|
1275
|
+
return new Promise((resolve15, reject) => {
|
|
1271
1276
|
const connections = /* @__PURE__ */ new Set();
|
|
1272
1277
|
const server = serve({ fetch: app.fetch, port, hostname: "127.0.0.1" }, (info) => {
|
|
1273
1278
|
const bound = port === 0 ? settleOnBrowserSafePort(server, "127.0.0.1") : Promise.resolve(info.port);
|
|
1274
1279
|
bound.then((boundPort) => {
|
|
1275
1280
|
listeningPort = boundPort;
|
|
1276
|
-
|
|
1281
|
+
resolve15({
|
|
1277
1282
|
url: `http://localhost:${boundPort}`,
|
|
1278
1283
|
port: boundPort,
|
|
1279
1284
|
addPreHeadScript: (script) => {
|
|
@@ -1964,8 +1969,8 @@ var OrderedRenderEventPublisher = class {
|
|
|
1964
1969
|
let timer;
|
|
1965
1970
|
const drained = await Promise.race([
|
|
1966
1971
|
this.tail.then(() => true),
|
|
1967
|
-
new Promise((
|
|
1968
|
-
timer = setTimeout(() =>
|
|
1972
|
+
new Promise((resolve15) => {
|
|
1973
|
+
timer = setTimeout(() => resolve15(false), FLUSH_TIMEOUT_MS);
|
|
1969
1974
|
})
|
|
1970
1975
|
]);
|
|
1971
1976
|
clearTimeout(timer);
|
|
@@ -2641,6 +2646,7 @@ import {
|
|
|
2641
2646
|
concatVideoFiles,
|
|
2642
2647
|
createCaptureSession as createCaptureSession2,
|
|
2643
2648
|
getCapturePerfSummary as getCapturePerfSummary2,
|
|
2649
|
+
retainCapturePerf as retainCapturePerf3,
|
|
2644
2650
|
initializeSession as initializeSession2,
|
|
2645
2651
|
prepareCaptureSessionForReuse as prepareCaptureSessionForReuse2,
|
|
2646
2652
|
resolveDeVerifyMinDb as resolveDeVerifyMinDb2,
|
|
@@ -2654,7 +2660,7 @@ import { CaptureFailure, classifyCaptureFailure } from "@hyperframes/engine";
|
|
|
2654
2660
|
// src/services/render/perfSummary.ts
|
|
2655
2661
|
import { arch, platform, totalmem } from "node:os";
|
|
2656
2662
|
import { fpsToNumber as fpsToNumber2 } from "@hyperframes/core";
|
|
2657
|
-
import { hostCpuCount } from "@hyperframes/engine";
|
|
2663
|
+
import { hostCpuCount, retainCapturePerf } from "@hyperframes/engine";
|
|
2658
2664
|
|
|
2659
2665
|
// src/services/render/hdrPerf.ts
|
|
2660
2666
|
function createHdrPerfCollector() {
|
|
@@ -2770,7 +2776,7 @@ function worstSubTimelineWaitOutcome(perfs) {
|
|
|
2770
2776
|
}
|
|
2771
2777
|
function pushWorkerDedupPerfs(results, sink) {
|
|
2772
2778
|
for (const r of results) {
|
|
2773
|
-
if (r.perf) sink
|
|
2779
|
+
if (r.perf) retainCapturePerf(sink, r.perf);
|
|
2774
2780
|
}
|
|
2775
2781
|
}
|
|
2776
2782
|
function capturedBeyondViewport(perfs, fallback) {
|
|
@@ -4129,12 +4135,12 @@ function distributeLayeredHybridFrameRanges(totalFrames, workerCount) {
|
|
|
4129
4135
|
}
|
|
4130
4136
|
return ranges;
|
|
4131
4137
|
}
|
|
4132
|
-
function partitionTransitionFrames(transitionRanges, totalFrames) {
|
|
4138
|
+
function partitionTransitionFrames(transitionRanges, totalFrames, firstFrame = 0) {
|
|
4133
4139
|
const frames = /* @__PURE__ */ new Set();
|
|
4134
4140
|
if (totalFrames <= 0) return frames;
|
|
4135
4141
|
for (const range of transitionRanges) {
|
|
4136
|
-
const start = Math.max(
|
|
4137
|
-
const end = Math.min(totalFrames - 1, range.endFrame);
|
|
4142
|
+
const start = Math.max(firstFrame, range.startFrame);
|
|
4143
|
+
const end = Math.min(firstFrame + totalFrames - 1, range.endFrame);
|
|
4138
4144
|
for (let i = start; i <= end; i++) frames.add(i);
|
|
4139
4145
|
}
|
|
4140
4146
|
return frames;
|
|
@@ -4344,6 +4350,18 @@ function cleanupEndedHdrVideos(args) {
|
|
|
4344
4350
|
}
|
|
4345
4351
|
}
|
|
4346
4352
|
}
|
|
4353
|
+
function transitionAtFrame(transitionRanges, frame) {
|
|
4354
|
+
return transitionRanges.find((t) => frame >= t.startFrame && frame <= t.endFrame);
|
|
4355
|
+
}
|
|
4356
|
+
function cleanupHdrVideosEndedBefore(firstFrame, fps, transitionRanges, state) {
|
|
4357
|
+
for (let frame = 0; frame < firstFrame; frame++) {
|
|
4358
|
+
cleanupEndedHdrVideos({
|
|
4359
|
+
...state,
|
|
4360
|
+
time: frame * fps.den / fps.num,
|
|
4361
|
+
activeTransition: transitionAtFrame(transitionRanges, frame)
|
|
4362
|
+
});
|
|
4363
|
+
}
|
|
4364
|
+
}
|
|
4347
4365
|
|
|
4348
4366
|
// src/services/render/segmentPlan.ts
|
|
4349
4367
|
import { join as join9 } from "node:path";
|
|
@@ -4596,6 +4614,7 @@ import {
|
|
|
4596
4614
|
distributeFramesInterleaved,
|
|
4597
4615
|
executeParallelCapture,
|
|
4598
4616
|
getCapturePerfSummary,
|
|
4617
|
+
retainCapturePerf as retainCapturePerf2,
|
|
4599
4618
|
psnrDb,
|
|
4600
4619
|
resolveDeVerifyMinDb,
|
|
4601
4620
|
recaptureDrawElementFrameForVerify,
|
|
@@ -4677,7 +4696,7 @@ var SequentialCaptureStallError = class extends Error {
|
|
|
4677
4696
|
}
|
|
4678
4697
|
};
|
|
4679
4698
|
function raceAgainstStall(promise, deadlineMs, input, signal) {
|
|
4680
|
-
return new Promise((
|
|
4699
|
+
return new Promise((resolve15, reject) => {
|
|
4681
4700
|
const clock = createStallClock();
|
|
4682
4701
|
const trip = () => reject(
|
|
4683
4702
|
signal?.aborted ? new Error(
|
|
@@ -4702,7 +4721,7 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
|
|
|
4702
4721
|
promise.then(
|
|
4703
4722
|
(value) => {
|
|
4704
4723
|
clearTimeout(timer);
|
|
4705
|
-
|
|
4724
|
+
resolve15(value);
|
|
4706
4725
|
},
|
|
4707
4726
|
(error) => {
|
|
4708
4727
|
clearTimeout(timer);
|
|
@@ -5324,7 +5343,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5324
5343
|
);
|
|
5325
5344
|
}
|
|
5326
5345
|
}
|
|
5327
|
-
dedupPerfs
|
|
5346
|
+
retainCapturePerf2(dedupPerfs, getCapturePerfSummary(session));
|
|
5328
5347
|
} catch (error) {
|
|
5329
5348
|
lastBrowserConsole = session.browserConsoleBuffer;
|
|
5330
5349
|
if (!resumesAfterStall(error, abortSignal, resume, resumes)) {
|
|
@@ -5624,7 +5643,7 @@ async function openSegmentWorkersTogether(run, workersToCloseLater) {
|
|
|
5624
5643
|
if (failure && failure.status === "rejected") throw failure.reason;
|
|
5625
5644
|
}
|
|
5626
5645
|
async function recycleWorkerSession(run, worker, why) {
|
|
5627
|
-
run.input.dedupPerfs
|
|
5646
|
+
retainCapturePerf3(run.input.dedupPerfs, getCapturePerfSummary2(worker.ctx.session));
|
|
5628
5647
|
const memory = worker.ctx.session.chromeMemory?.stats();
|
|
5629
5648
|
await run.deps.closeSession(worker.ctx.session);
|
|
5630
5649
|
const { frames } = worker.ctx;
|
|
@@ -5753,7 +5772,8 @@ async function runCaptureSegmentedStage(input) {
|
|
|
5753
5772
|
assertNotAborted();
|
|
5754
5773
|
await openSegmentWorkersTogether(run, workers);
|
|
5755
5774
|
const outcomes = await Promise.allSettled(workers.map((w) => runWorkerLoop(w)));
|
|
5756
|
-
for (const worker of workers)
|
|
5775
|
+
for (const worker of workers)
|
|
5776
|
+
retainCapturePerf3(dedupPerfs, getCapturePerfSummary2(worker.ctx.session));
|
|
5757
5777
|
const failure = outcomes.find((o) => o.status === "rejected");
|
|
5758
5778
|
if (failure && failure.status === "rejected") throw failure.reason;
|
|
5759
5779
|
} catch (error) {
|
|
@@ -6001,10 +6021,15 @@ function estimateMeasuredCaptureCostMultiplier(samples) {
|
|
|
6001
6021
|
function shouldCalibrateSoftwareGpu(requestedMode, resolvedMode, hardware) {
|
|
6002
6022
|
return requestedMode === "auto" && resolvedMode === "hardware" && hardware !== void 0 && hardware.multiplier > 1 && hardware.p95Ms !== void 0;
|
|
6003
6023
|
}
|
|
6004
|
-
function
|
|
6005
|
-
if (hardware
|
|
6024
|
+
function settleAutoGpuChoice(hardware, software) {
|
|
6025
|
+
if (hardware?.p95Ms === void 0) return void 0;
|
|
6026
|
+
if (hardware.multiplier <= 1) return "hardware";
|
|
6027
|
+
if (software?.p95Ms === void 0) return void 0;
|
|
6006
6028
|
return software.p95Ms < hardware.p95Ms ? "software" : "hardware";
|
|
6007
6029
|
}
|
|
6030
|
+
function pickAutoGpuModeFromCalibration(hardware, software) {
|
|
6031
|
+
return settleAutoGpuChoice(hardware, software) ?? "hardware";
|
|
6032
|
+
}
|
|
6008
6033
|
function selectCaptureCalibrationFrames(totalFrames) {
|
|
6009
6034
|
if (totalFrames <= 0) return [];
|
|
6010
6035
|
const lastFrame = totalFrames - 1;
|
|
@@ -6019,8 +6044,8 @@ function selectCaptureCalibrationFrames(totalFrames) {
|
|
|
6019
6044
|
new Set(candidates.map((frame) => Math.max(0, Math.min(lastFrame, frame))))
|
|
6020
6045
|
).sort((a, b) => a - b);
|
|
6021
6046
|
}
|
|
6022
|
-
async function measureCaptureCostFromSession(session, totalFrames, fps, log) {
|
|
6023
|
-
const sampledFrames = selectCaptureCalibrationFrames(totalFrames);
|
|
6047
|
+
async function measureCaptureCostFromSession(session, totalFrames, fps, log, firstFrame = 0) {
|
|
6048
|
+
const sampledFrames = selectCaptureCalibrationFrames(totalFrames).map((i) => firstFrame + i);
|
|
6024
6049
|
const samples = [];
|
|
6025
6050
|
const totalSamples = sampledFrames.length;
|
|
6026
6051
|
const savedStaticFrames = session.staticFrames;
|
|
@@ -6116,7 +6141,13 @@ async function runCaptureCalibration(input) {
|
|
|
6116
6141
|
}
|
|
6117
6142
|
assertNotAborted();
|
|
6118
6143
|
log.info("Calibration session ready, capturing test frames...");
|
|
6119
|
-
const result = await measureCaptureCostFromSession(
|
|
6144
|
+
const result = await measureCaptureCostFromSession(
|
|
6145
|
+
session,
|
|
6146
|
+
totalFrames,
|
|
6147
|
+
fps,
|
|
6148
|
+
log,
|
|
6149
|
+
job.frameWindow?.startFrame
|
|
6150
|
+
);
|
|
6120
6151
|
logCaptureCalibrationResult(result, log);
|
|
6121
6152
|
return result;
|
|
6122
6153
|
};
|
|
@@ -6677,6 +6708,57 @@ function resolveVideoCaptureBeyondViewport(videoCount) {
|
|
|
6677
6708
|
return true;
|
|
6678
6709
|
}
|
|
6679
6710
|
|
|
6711
|
+
// src/services/render/gpuChoice.ts
|
|
6712
|
+
import { mkdirSync as mkdirSync7, readFileSync as readFileSync5, renameSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6713
|
+
import { dirname as dirname6 } from "node:path";
|
|
6714
|
+
function gpuChoiceStore(cfg, gpu) {
|
|
6715
|
+
if (!cfg.gpuChoiceFile || !cfg.hyperframesVersion || !gpu) return void 0;
|
|
6716
|
+
return { file: cfg.gpuChoiceFile, key: `${cfg.hyperframesVersion} | ${gpu}` };
|
|
6717
|
+
}
|
|
6718
|
+
function readGpuChoice(store) {
|
|
6719
|
+
let record;
|
|
6720
|
+
try {
|
|
6721
|
+
record = JSON.parse(readFileSync5(store.file, "utf8"));
|
|
6722
|
+
} catch {
|
|
6723
|
+
return void 0;
|
|
6724
|
+
}
|
|
6725
|
+
if (record?.key !== store.key) return void 0;
|
|
6726
|
+
return record.mode === "software" || record.mode === "hardware" ? record.mode : void 0;
|
|
6727
|
+
}
|
|
6728
|
+
function writeGpuChoice(store, mode, measured) {
|
|
6729
|
+
mkdirSync7(dirname6(store.file), { recursive: true });
|
|
6730
|
+
const temp = `${store.file}.${process.pid}.tmp`;
|
|
6731
|
+
const record = { key: store.key, mode, ...measured, measuredAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
6732
|
+
writeFileSync3(temp, `${JSON.stringify(record, null, 2)}
|
|
6733
|
+
`);
|
|
6734
|
+
renameSync(temp, store.file);
|
|
6735
|
+
}
|
|
6736
|
+
|
|
6737
|
+
// src/services/render/frameWindow.ts
|
|
6738
|
+
function resolveFrameWindow(range, fps, filmFrames) {
|
|
6739
|
+
const frameAt = (seconds) => Math.round(seconds * fps.num / fps.den);
|
|
6740
|
+
const startFrame = frameAt(range.startSeconds);
|
|
6741
|
+
const endFrame = Math.min(
|
|
6742
|
+
range.endSeconds === void 0 ? filmFrames : frameAt(range.endSeconds),
|
|
6743
|
+
filmFrames
|
|
6744
|
+
);
|
|
6745
|
+
if (!(endFrame > startFrame)) {
|
|
6746
|
+
throw new Error(
|
|
6747
|
+
`The range ${range.startSeconds}s to ${range.endSeconds ?? "the end"}s holds no frame: the film has ${filmFrames} frames at ${fps.num}/${fps.den} fps.`
|
|
6748
|
+
);
|
|
6749
|
+
}
|
|
6750
|
+
return { startFrame, endFrame };
|
|
6751
|
+
}
|
|
6752
|
+
function windowStartFrame(frameWindow) {
|
|
6753
|
+
return frameWindow?.startFrame ?? 0;
|
|
6754
|
+
}
|
|
6755
|
+
function assertRangeSupported(frameWindow, route) {
|
|
6756
|
+
if (!frameWindow || route === "sdr_disk" || route === "hdr_layered") return;
|
|
6757
|
+
throw new Error(
|
|
6758
|
+
`This composition renders on the "${route}" capture route, which renders the whole film only; render it without a start or end.`
|
|
6759
|
+
);
|
|
6760
|
+
}
|
|
6761
|
+
|
|
6680
6762
|
// src/services/render/observability.ts
|
|
6681
6763
|
import { createHash as createHash3 } from "node:crypto";
|
|
6682
6764
|
import { redactTelemetryString } from "@hyperframes/core";
|
|
@@ -7048,7 +7130,7 @@ function emitFallbackCaptureProfile(recorder, perfSummaries, env = process.env)
|
|
|
7048
7130
|
}
|
|
7049
7131
|
|
|
7050
7132
|
// src/services/render/videoFrameCoverage.ts
|
|
7051
|
-
import { parseHTML } from "linkedom";
|
|
7133
|
+
import { parseHTML } from "@hyperframes/parsers/linkedom";
|
|
7052
7134
|
import {
|
|
7053
7135
|
fpsToNumber as fpsToNumber5,
|
|
7054
7136
|
normalizeRateSpec,
|
|
@@ -7063,7 +7145,6 @@ var SHORT_CLIP_ONE_FRAME_TOLERANCE_MIN_EXPECTED_FRAMES = 14;
|
|
|
7063
7145
|
var SHORT_CLIP_ONE_FRAME_TOLERANCE_MAX_EXPECTED_FRAMES = 20;
|
|
7064
7146
|
var VideoFrameCoverageError = class extends Error {
|
|
7065
7147
|
// Read structurally by isVideoFrameCoverageError and cross-module callers.
|
|
7066
|
-
// fallow-ignore-next-line unused-class-member
|
|
7067
7148
|
hyperframesVideoFrameCoverageError = true;
|
|
7068
7149
|
threshold;
|
|
7069
7150
|
worst;
|
|
@@ -7166,8 +7247,8 @@ function requireOutputDimensions(expected, width, height) {
|
|
|
7166
7247
|
}
|
|
7167
7248
|
|
|
7168
7249
|
// src/services/render/stages/compileStage.ts
|
|
7169
|
-
import { existsSync as existsSync13, writeFileSync as
|
|
7170
|
-
import { join as join23, relative as relative5 } from "node:path";
|
|
7250
|
+
import { existsSync as existsSync13, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7251
|
+
import { join as join23, relative as relative5, resolve as resolve9 } from "node:path";
|
|
7171
7252
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
7172
7253
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
7173
7254
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
@@ -7176,7 +7257,8 @@ import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperf
|
|
|
7176
7257
|
|
|
7177
7258
|
// src/services/compileInWorker.ts
|
|
7178
7259
|
import { existsSync as existsSync12, rmSync as rmSync11 } from "node:fs";
|
|
7179
|
-
import {
|
|
7260
|
+
import { ffmpegCwd } from "@hyperframes/parsers/ff-binaries";
|
|
7261
|
+
import { dirname as dirname11, isAbsolute as isAbsolute4, join as join22, relative as relative4, resolve as resolvePath } from "node:path";
|
|
7180
7262
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7181
7263
|
import { Worker } from "node:worker_threads";
|
|
7182
7264
|
|
|
@@ -7196,17 +7278,17 @@ import {
|
|
|
7196
7278
|
stylesheetLinkMatches
|
|
7197
7279
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7198
7280
|
import { createHash as createHash6 } from "node:crypto";
|
|
7199
|
-
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as
|
|
7200
|
-
import { join as join21, dirname as
|
|
7201
|
-
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7281
|
+
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync10, readFileSync as readFileSync9, statSync as statSync8 } from "fs";
|
|
7282
|
+
import { join as join21, dirname as dirname10, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7283
|
+
import { parseHTML as parseHTML5 } from "@hyperframes/parsers/linkedom";
|
|
7202
7284
|
|
|
7203
7285
|
// src/services/bundledScripts.ts
|
|
7204
|
-
import { existsSync as existsSync8, readFileSync as
|
|
7286
|
+
import { existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
|
|
7205
7287
|
import { join as join17 } from "node:path";
|
|
7206
7288
|
import { GSAP_CDN_VERSION } from "@hyperframes/core/gsap-cdn";
|
|
7207
7289
|
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
7208
7290
|
var DEFAULT_CDN_GSAP_3 = /^https:\/\/cdn\.jsdelivr\.net\/npm\/gsap@(3\.\d+\.\d+)\/dist\/([A-Za-z]+\.min\.js)$/;
|
|
7209
|
-
var read = (file) => existsSync8(file) ?
|
|
7291
|
+
var read = (file) => existsSync8(file) ? readFileSync6(file) : null;
|
|
7210
7292
|
function bundledScript(url) {
|
|
7211
7293
|
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
7212
7294
|
const [, version, file] = DEFAULT_CDN_GSAP_3.exec(url) ?? [];
|
|
@@ -7247,6 +7329,7 @@ import { gsapCdnDist, normalizeGsapBaseUrl } from "@hyperframes/core/gsap-cdn";
|
|
|
7247
7329
|
import {
|
|
7248
7330
|
assignBundledRuntimeCompositionIds,
|
|
7249
7331
|
assignMediaRenderIds,
|
|
7332
|
+
dropAuthoredCompositionFiles,
|
|
7250
7333
|
emitVariablesByCompScript,
|
|
7251
7334
|
inlineSubCompositions as inlineSubCompositionsShared,
|
|
7252
7335
|
ensureExternalLinkTag,
|
|
@@ -7280,7 +7363,7 @@ import {
|
|
|
7280
7363
|
readTextFile,
|
|
7281
7364
|
resolveCompositionSrc
|
|
7282
7365
|
} from "@hyperframes/parsers/asset-resolution";
|
|
7283
|
-
import { isPrivateFileUnder as
|
|
7366
|
+
import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
|
|
7284
7367
|
import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
|
|
7285
7368
|
import {
|
|
7286
7369
|
assertCompositionFileSize,
|
|
@@ -7291,7 +7374,7 @@ import {
|
|
|
7291
7374
|
} from "@hyperframes/core/compiler";
|
|
7292
7375
|
|
|
7293
7376
|
// src/services/renderMediaCollector.ts
|
|
7294
|
-
import { parseHTML as parseHTML2 } from "linkedom";
|
|
7377
|
+
import { parseHTML as parseHTML2 } from "@hyperframes/parsers/linkedom";
|
|
7295
7378
|
import {
|
|
7296
7379
|
MEDIA_RENDER_ID_ATTR,
|
|
7297
7380
|
normalizeRateSpec as normalizeRateSpec2,
|
|
@@ -7483,9 +7566,9 @@ import {
|
|
|
7483
7566
|
|
|
7484
7567
|
// src/services/animatedGifPrep.ts
|
|
7485
7568
|
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
7486
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as
|
|
7487
|
-
import { dirname as
|
|
7488
|
-
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7569
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync7, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
|
|
7570
|
+
import { dirname as dirname7, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7571
|
+
import { parseHTML as parseHTML3 } from "@hyperframes/parsers/linkedom";
|
|
7489
7572
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
7490
7573
|
import {
|
|
7491
7574
|
DEFAULT_VP9_CPU_USED,
|
|
@@ -7537,7 +7620,11 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7537
7620
|
resolve6(options.downloadDir, normalizedBase)
|
|
7538
7621
|
];
|
|
7539
7622
|
const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
|
|
7540
|
-
const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(
|
|
7623
|
+
const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(
|
|
7624
|
+
candidate,
|
|
7625
|
+
[options.projectDir, options.downloadDir],
|
|
7626
|
+
options.allowOutsideFiles
|
|
7627
|
+
) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
|
|
7541
7628
|
return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
|
|
7542
7629
|
}
|
|
7543
7630
|
function isUsableFile(path) {
|
|
@@ -7666,11 +7753,11 @@ async function runAnimatedGifTranscode(request) {
|
|
|
7666
7753
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
7667
7754
|
}
|
|
7668
7755
|
async function ensurePreparedWebm(input) {
|
|
7669
|
-
if (!existsSync9(
|
|
7670
|
-
|
|
7756
|
+
if (!existsSync9(dirname7(input.cachePath))) {
|
|
7757
|
+
mkdirSync8(dirname7(input.cachePath), { recursive: true });
|
|
7671
7758
|
}
|
|
7672
|
-
if (!existsSync9(
|
|
7673
|
-
|
|
7759
|
+
if (!existsSync9(dirname7(input.outputPath))) {
|
|
7760
|
+
mkdirSync8(dirname7(input.outputPath), { recursive: true });
|
|
7674
7761
|
}
|
|
7675
7762
|
if (!isUsableFile(input.cachePath)) {
|
|
7676
7763
|
const tmpPath = `${input.cachePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
@@ -7771,7 +7858,7 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7771
7858
|
if (!hasGifExtension(src)) continue;
|
|
7772
7859
|
const sourcePath = resolveLocalImageSourcePath(src, options);
|
|
7773
7860
|
if (!sourcePath) continue;
|
|
7774
|
-
const bytes =
|
|
7861
|
+
const bytes = readFileSync7(sourcePath);
|
|
7775
7862
|
const metadata = parseAnimatedGifMetadata(bytes);
|
|
7776
7863
|
if (!metadata?.animated) continue;
|
|
7777
7864
|
const loopOverride = readLoopOverride(img);
|
|
@@ -7823,16 +7910,16 @@ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypt
|
|
|
7823
7910
|
import {
|
|
7824
7911
|
closeSync as closeSync5,
|
|
7825
7912
|
copyFileSync as copyFileSync3,
|
|
7826
|
-
mkdirSync as
|
|
7913
|
+
mkdirSync as mkdirSync9,
|
|
7827
7914
|
openSync as openSync5,
|
|
7828
|
-
readFileSync as
|
|
7915
|
+
readFileSync as readFileSync8,
|
|
7829
7916
|
readSync as readSync3,
|
|
7830
7917
|
rmSync as rmSync10,
|
|
7831
7918
|
statSync as statSync7,
|
|
7832
|
-
writeFileSync as
|
|
7919
|
+
writeFileSync as writeFileSync4
|
|
7833
7920
|
} from "node:fs";
|
|
7834
|
-
import { dirname as
|
|
7835
|
-
import { parseHTML as parseHTML4 } from "linkedom";
|
|
7921
|
+
import { dirname as dirname8, join as join19, resolve as resolve7 } from "node:path";
|
|
7922
|
+
import { parseHTML as parseHTML4 } from "@hyperframes/parsers/linkedom";
|
|
7836
7923
|
import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
|
|
7837
7924
|
|
|
7838
7925
|
// src/services/heifRotation.ts
|
|
@@ -7900,10 +7987,10 @@ var Semaphore = class {
|
|
|
7900
7987
|
this.active++;
|
|
7901
7988
|
return () => this.release();
|
|
7902
7989
|
}
|
|
7903
|
-
return new Promise((
|
|
7990
|
+
return new Promise((resolve15) => {
|
|
7904
7991
|
this.queue.push(() => {
|
|
7905
7992
|
this.active++;
|
|
7906
|
-
|
|
7993
|
+
resolve15(() => this.release());
|
|
7907
7994
|
});
|
|
7908
7995
|
});
|
|
7909
7996
|
}
|
|
@@ -8016,7 +8103,7 @@ function primaryGrid(probed) {
|
|
|
8016
8103
|
async function convertHeifToJpeg(request) {
|
|
8017
8104
|
const probed = await probeJson(request.inputPath, true);
|
|
8018
8105
|
const grid = primaryGrid(probed);
|
|
8019
|
-
const rotation = readHeifPrimaryRotation(
|
|
8106
|
+
const rotation = readHeifPrimaryRotation(readFileSync8(request.inputPath));
|
|
8020
8107
|
const filters = [];
|
|
8021
8108
|
let inputs = [];
|
|
8022
8109
|
let size = probed.streams?.[0];
|
|
@@ -8080,7 +8167,7 @@ function resolveImageSource(src, options) {
|
|
|
8080
8167
|
const path = resolveLocalImageSourcePath(src, options);
|
|
8081
8168
|
const head = path ? readHead(path) : null;
|
|
8082
8169
|
if (!path || !head || !isHeifBytes(head)) return null;
|
|
8083
|
-
return { path, bytes:
|
|
8170
|
+
return { path, bytes: readFileSync8(path), label: `"${splitUrlSuffix(src).basePath}"` };
|
|
8084
8171
|
}
|
|
8085
8172
|
function isUsableFile2(path) {
|
|
8086
8173
|
try {
|
|
@@ -8090,14 +8177,14 @@ function isUsableFile2(path) {
|
|
|
8090
8177
|
}
|
|
8091
8178
|
}
|
|
8092
8179
|
async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
8093
|
-
|
|
8094
|
-
|
|
8180
|
+
mkdirSync9(dirname8(cachePath), { recursive: true });
|
|
8181
|
+
mkdirSync9(dirname8(outputPath), { recursive: true });
|
|
8095
8182
|
if (!isUsableFile2(cachePath)) {
|
|
8096
8183
|
const tmpPath = `${cachePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
8097
8184
|
const inlinePath = `${tmpPath}.heic`;
|
|
8098
8185
|
const inputPath = source.path ?? inlinePath;
|
|
8099
8186
|
try {
|
|
8100
|
-
if (!source.path)
|
|
8187
|
+
if (!source.path) writeFileSync4(inlinePath, source.bytes);
|
|
8101
8188
|
await (options.transcode ?? convertHeifToJpeg)({
|
|
8102
8189
|
inputPath,
|
|
8103
8190
|
outputPath: tmpPath,
|
|
@@ -8170,7 +8257,7 @@ import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position
|
|
|
8170
8257
|
|
|
8171
8258
|
// src/services/assetMediaType.ts
|
|
8172
8259
|
import { existsSync as existsSync10 } from "node:fs";
|
|
8173
|
-
import { dirname as
|
|
8260
|
+
import { dirname as dirname9, join as join20 } from "node:path";
|
|
8174
8261
|
import {
|
|
8175
8262
|
fingerprintElementId,
|
|
8176
8263
|
isHttpUrl as isHttpUrl2,
|
|
@@ -8224,7 +8311,7 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
|
|
|
8224
8311
|
]);
|
|
8225
8312
|
}
|
|
8226
8313
|
function mediaAssetRoots(projectDir, compiledDir) {
|
|
8227
|
-
return [projectDir, compiledDir, join20(
|
|
8314
|
+
return [projectDir, compiledDir, join20(dirname9(compiledDir), "downloads")];
|
|
8228
8315
|
}
|
|
8229
8316
|
function dropMediaOutsideProject(input) {
|
|
8230
8317
|
const { projectDir, workDir, composition, log } = input;
|
|
@@ -8233,7 +8320,7 @@ function dropMediaOutsideProject(input) {
|
|
|
8233
8320
|
const staysInside = ({ id, src }) => {
|
|
8234
8321
|
if (!src || isHttpUrl2(src)) return true;
|
|
8235
8322
|
const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
|
|
8236
|
-
if (isPrivateUnderAssetRoots2(path, roots)) {
|
|
8323
|
+
if (isPrivateUnderAssetRoots2(path, roots, input.allowOutsideProjectAssets)) {
|
|
8237
8324
|
log.warn(`[Render] Media "${id}" source is missing: it is a private project file`, { src });
|
|
8238
8325
|
return false;
|
|
8239
8326
|
}
|
|
@@ -8403,7 +8490,7 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
|
|
|
8403
8490
|
throw new EmptyCompositionError([{ srcPath, detail: OUTSIDE_COMPOSITION_NEEDS_FLAG }]);
|
|
8404
8491
|
}
|
|
8405
8492
|
}
|
|
8406
|
-
var isPrivateCompositionFile = (projectDir, filePath) =>
|
|
8493
|
+
var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder3(projectDir, filePath, isStudioPrivatePath3);
|
|
8407
8494
|
function compositionSrcsIn(html) {
|
|
8408
8495
|
const { document: document2 } = parseHTML5(html);
|
|
8409
8496
|
const mounts = [];
|
|
@@ -8705,7 +8792,7 @@ var AssetDownloads = class {
|
|
|
8705
8792
|
}
|
|
8706
8793
|
async download(url, destDir) {
|
|
8707
8794
|
while (this.running >= ASSET_DOWNLOADS_AT_ONCE) {
|
|
8708
|
-
await new Promise((
|
|
8795
|
+
await new Promise((resolve15) => this.queued.push(resolve15));
|
|
8709
8796
|
}
|
|
8710
8797
|
if (this.signal?.aborted) {
|
|
8711
8798
|
this.queued.shift()?.();
|
|
@@ -8729,7 +8816,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8729
8816
|
let filePath = src;
|
|
8730
8817
|
if (isHttpUrl(src)) {
|
|
8731
8818
|
const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8732
|
-
if (!existsSync11(remoteDir))
|
|
8819
|
+
if (!existsSync11(remoteDir)) mkdirSync10(remoteDir, { recursive: true });
|
|
8733
8820
|
run?.assets.reserve([src]);
|
|
8734
8821
|
try {
|
|
8735
8822
|
filePath = await downloadAsset(src, remoteDir, run?.assets);
|
|
@@ -8740,7 +8827,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8740
8827
|
} else {
|
|
8741
8828
|
filePath = decodedUrlPath(src);
|
|
8742
8829
|
if (!filePath.startsWith("/")) filePath = join21(baseDir, filePath);
|
|
8743
|
-
if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir])) {
|
|
8830
|
+
if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir], assetRoot === void 0)) {
|
|
8744
8831
|
return { duration: null, resolvedPath: filePath };
|
|
8745
8832
|
}
|
|
8746
8833
|
filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
|
|
@@ -8923,7 +9010,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
8923
9010
|
const { html: compiledSub } = await compileHtmlFile(
|
|
8924
9011
|
rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
|
|
8925
9012
|
projectDir,
|
|
8926
|
-
|
|
9013
|
+
dirname10(item.filePath),
|
|
8927
9014
|
downloadDir,
|
|
8928
9015
|
void 0,
|
|
8929
9016
|
urlByAbsentLocalPath,
|
|
@@ -9094,6 +9181,7 @@ function coalesceHeadStylesAndBodyScripts(html) {
|
|
|
9094
9181
|
}
|
|
9095
9182
|
function inlineSubCompositions(html, subCompositions, projectDir, variableOverrides, assetRoot, outsideFiles, budget) {
|
|
9096
9183
|
const { document: document2 } = parseHTML5(html);
|
|
9184
|
+
dropAuthoredCompositionFiles(document2);
|
|
9097
9185
|
budget.chargeElements(ENTRY_PAGE, document2.querySelectorAll("*").length);
|
|
9098
9186
|
const head = document2.querySelector("head");
|
|
9099
9187
|
const body = document2.querySelector("body");
|
|
@@ -9496,7 +9584,7 @@ var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
|
9496
9584
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, assets, extraRewrite) {
|
|
9497
9585
|
assets?.reserve(urlSet);
|
|
9498
9586
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
9499
|
-
if (!existsSync11(remoteDir))
|
|
9587
|
+
if (!existsSync11(remoteDir)) mkdirSync10(remoteDir, { recursive: true });
|
|
9500
9588
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
9501
9589
|
await Promise.all(
|
|
9502
9590
|
[...urlSet].map(async (url) => {
|
|
@@ -9693,11 +9781,11 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
9693
9781
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
9694
9782
|
const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
9695
9783
|
if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
9696
|
-
for (const face of extractFontFaceBlocks(
|
|
9784
|
+
for (const face of extractFontFaceBlocks(readFileSync9(sheet, "utf8"))) {
|
|
9697
9785
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
9698
9786
|
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
9699
9787
|
const path = decodedUrlPath(url);
|
|
9700
|
-
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(
|
|
9788
|
+
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname10(sheet), path);
|
|
9701
9789
|
return isPathInside(file, projectDir) && existsSync11(file);
|
|
9702
9790
|
});
|
|
9703
9791
|
if (family && shipsFile) families.push(family);
|
|
@@ -10143,7 +10231,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
|
|
|
10143
10231
|
for (const video of videos) {
|
|
10144
10232
|
if (isHttpUrl(video.src)) continue;
|
|
10145
10233
|
const videoPath = resolve8(projectDir, video.src);
|
|
10146
|
-
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
|
|
10234
|
+
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir], assetRoot === void 0))
|
|
10147
10235
|
continue;
|
|
10148
10236
|
advised.add(videoPath);
|
|
10149
10237
|
const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
|
|
@@ -10609,7 +10697,7 @@ function resolveCompileWorkerEntry(explicit, log) {
|
|
|
10609
10697
|
}
|
|
10610
10698
|
return void 0;
|
|
10611
10699
|
}
|
|
10612
|
-
const sibling = join22(
|
|
10700
|
+
const sibling = join22(dirname11(fileURLToPath3(import.meta.url)), "compileWorker.js");
|
|
10613
10701
|
return existsSync12(sibling) ? sibling : void 0;
|
|
10614
10702
|
}
|
|
10615
10703
|
function rebuildError({ name, message, stack, props }) {
|
|
@@ -10624,9 +10712,15 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10624
10712
|
if (!entry) return compileForRender(projectDir, htmlPath, downloadDir, options);
|
|
10625
10713
|
abortSignal?.throwIfAborted();
|
|
10626
10714
|
const timeoutMs = worker.timeoutMs ?? compileTimeoutMs();
|
|
10627
|
-
return new Promise((
|
|
10715
|
+
return new Promise((resolve15, reject) => {
|
|
10628
10716
|
const thread = new Worker(entry, {
|
|
10629
|
-
workerData: {
|
|
10717
|
+
workerData: {
|
|
10718
|
+
projectDir,
|
|
10719
|
+
htmlPath,
|
|
10720
|
+
downloadDir,
|
|
10721
|
+
options: cloneable,
|
|
10722
|
+
emptyFolder: ffmpegCwd() !== void 0
|
|
10723
|
+
}
|
|
10630
10724
|
});
|
|
10631
10725
|
const children = /* @__PURE__ */ new Map();
|
|
10632
10726
|
const scratchRoots = [downloadDir, options.animatedGifCacheDir].flatMap(
|
|
@@ -10680,7 +10774,7 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10680
10774
|
log?.[message.level](message.message ?? "", message.meta);
|
|
10681
10775
|
} else if (message.type === "result" && message.compiled) {
|
|
10682
10776
|
const { compiled } = message;
|
|
10683
|
-
settle(() =>
|
|
10777
|
+
settle(() => resolve15(compiled));
|
|
10684
10778
|
retire(ADVISORY_GRACE_MS);
|
|
10685
10779
|
} else if (message.type === "error" && message.error) {
|
|
10686
10780
|
const { error } = message;
|
|
@@ -10712,7 +10806,7 @@ async function compileForRenderInWorker(projectDir, htmlPath, downloadDir, optio
|
|
|
10712
10806
|
// src/services/render/stages/compileStage.ts
|
|
10713
10807
|
function animatedGifCacheDir(extractCacheDir) {
|
|
10714
10808
|
try {
|
|
10715
|
-
const root = extractCacheDir && privateCacheRoot(extractCacheDir);
|
|
10809
|
+
const root = extractCacheDir && privateCacheRoot(resolve9(extractCacheDir));
|
|
10716
10810
|
return root ? join23(root, "animated-gif") : void 0;
|
|
10717
10811
|
} catch {
|
|
10718
10812
|
return void 0;
|
|
@@ -10761,7 +10855,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10761
10855
|
);
|
|
10762
10856
|
}
|
|
10763
10857
|
const wrapperPath = join23(workDir, "standalone-entry.html");
|
|
10764
|
-
|
|
10858
|
+
writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
|
|
10765
10859
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
10766
10860
|
return wrapperPath;
|
|
10767
10861
|
}
|
|
@@ -10919,7 +11013,7 @@ async function runCompileStage(input) {
|
|
|
10919
11013
|
// src/services/render/stages/probeStage.ts
|
|
10920
11014
|
import { createHash as createHash7 } from "node:crypto";
|
|
10921
11015
|
import { basename as basename7, join as join24 } from "node:path";
|
|
10922
|
-
import { parseHTML as parseHTML6 } from "linkedom";
|
|
11016
|
+
import { parseHTML as parseHTML6 } from "@hyperframes/parsers/linkedom";
|
|
10923
11017
|
import {
|
|
10924
11018
|
closeCaptureSession as closeCaptureSession4,
|
|
10925
11019
|
compositionRequiresWebGpu,
|
|
@@ -12426,7 +12520,7 @@ import {
|
|
|
12426
12520
|
|
|
12427
12521
|
// src/services/render/audioDeliveryLimit.ts
|
|
12428
12522
|
import { existsSync as existsSync16 } from "node:fs";
|
|
12429
|
-
import { dirname as
|
|
12523
|
+
import { dirname as dirname13, join as join27 } from "node:path";
|
|
12430
12524
|
import {
|
|
12431
12525
|
applyAudioFxChain,
|
|
12432
12526
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -12435,9 +12529,9 @@ import {
|
|
|
12435
12529
|
} from "@hyperframes/engine";
|
|
12436
12530
|
|
|
12437
12531
|
// src/services/render/audioPadTrim.ts
|
|
12438
|
-
import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
12532
|
+
import { ffmpegCwd as ffmpegCwd2, localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
12439
12533
|
import { spawn } from "node:child_process";
|
|
12440
|
-
import { dirname as
|
|
12534
|
+
import { dirname as dirname12, join as join26 } from "node:path";
|
|
12441
12535
|
import {
|
|
12442
12536
|
DEFAULT_CONFIG,
|
|
12443
12537
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -12732,7 +12826,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
|
|
|
12732
12826
|
async function enforceAacTruePeak(input) {
|
|
12733
12827
|
let scratchDir;
|
|
12734
12828
|
try {
|
|
12735
|
-
scratchDir = createStagingDir3(
|
|
12829
|
+
scratchDir = createStagingDir3(dirname12(input.audioPath), ".true-peak-");
|
|
12736
12830
|
const correctedPath = join26(scratchDir, "audio.m4a");
|
|
12737
12831
|
const measurements = [];
|
|
12738
12832
|
let attenuationDb = 0;
|
|
@@ -12906,6 +13000,7 @@ async function spawnFfprobeJson(args, env, signal) {
|
|
|
12906
13000
|
const proc = spawn(getFfprobeBinary(), args, {
|
|
12907
13001
|
...env && { env },
|
|
12908
13002
|
stdio: ["ignore", "pipe", "pipe"],
|
|
13003
|
+
cwd: ffmpegCwd2(),
|
|
12909
13004
|
windowsHide: true
|
|
12910
13005
|
});
|
|
12911
13006
|
trackChildProcess(proc);
|
|
@@ -12956,7 +13051,7 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
12956
13051
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
12957
13052
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
12958
13053
|
const alternating = ["a", "b"].map(
|
|
12959
|
-
(k) => join27(
|
|
13054
|
+
(k) => join27(dirname13(sourcePath), `audio-source-limited-${k}.wav`)
|
|
12960
13055
|
);
|
|
12961
13056
|
let encodedFrom;
|
|
12962
13057
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -13030,10 +13125,15 @@ function runAudioStage(input) {
|
|
|
13030
13125
|
async function runAudioStageScoped(input) {
|
|
13031
13126
|
const stageStart = Date.now();
|
|
13032
13127
|
const pcmSourcePath = join28(input.workDir, "audio-source.wav");
|
|
13033
|
-
const
|
|
13128
|
+
const seconds = (frames) => frames * input.fps.den / input.fps.num;
|
|
13129
|
+
const duration = seconds(input.totalFrames);
|
|
13130
|
+
const window2 = input.frameWindow && {
|
|
13131
|
+
startSeconds: seconds(input.frameWindow.startFrame),
|
|
13132
|
+
durationSeconds: seconds(input.frameWindow.endFrame - input.frameWindow.startFrame)
|
|
13133
|
+
};
|
|
13034
13134
|
let deliverySourcePath;
|
|
13035
13135
|
try {
|
|
13036
|
-
const result = await mixAudioForDelivery(input, duration, pcmSourcePath);
|
|
13136
|
+
const result = await mixAudioForDelivery(input, duration, pcmSourcePath, window2);
|
|
13037
13137
|
let audioLoweredDb;
|
|
13038
13138
|
if (result.hasAudio) {
|
|
13039
13139
|
const guardStart = Date.now();
|
|
@@ -13041,7 +13141,7 @@ async function runAudioStageScoped(input) {
|
|
|
13041
13141
|
input,
|
|
13042
13142
|
result.audioOutputPath,
|
|
13043
13143
|
pcmSourcePath,
|
|
13044
|
-
duration
|
|
13144
|
+
window2?.durationSeconds ?? duration
|
|
13045
13145
|
);
|
|
13046
13146
|
audioLoweredDb = guard.loweredDb;
|
|
13047
13147
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
@@ -13079,7 +13179,7 @@ async function guardDeliveryPeaks(input, audioPath, sourcePath, duration) {
|
|
|
13079
13179
|
if (!peak.success) throw encoderFailureError("Audio true-peak check failed", peak);
|
|
13080
13180
|
return { loweredDb: peak.loweredDb, sourceStale: peak.sourceStale };
|
|
13081
13181
|
}
|
|
13082
|
-
async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
13182
|
+
async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
13083
13183
|
const {
|
|
13084
13184
|
projectDir,
|
|
13085
13185
|
workDir,
|
|
@@ -13116,6 +13216,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
13116
13216
|
urlByAbsentLocalPath,
|
|
13117
13217
|
audioSidecarUrlByLocalPath,
|
|
13118
13218
|
keepEncoderInputAt: pcmSourcePath,
|
|
13219
|
+
window: window2,
|
|
13119
13220
|
assetRoots: input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir)
|
|
13120
13221
|
},
|
|
13121
13222
|
compiledDir
|
|
@@ -13187,6 +13288,7 @@ import {
|
|
|
13187
13288
|
completeDeferredDrawElementInit as completeDeferredDrawElementInit3,
|
|
13188
13289
|
createCaptureSession as createCaptureSession5,
|
|
13189
13290
|
getCapturePerfSummary as getCapturePerfSummary3,
|
|
13291
|
+
retainCapturePerf as retainCapturePerf4,
|
|
13190
13292
|
initializeSession as initializeSession5,
|
|
13191
13293
|
prepareCaptureSessionForReuse as prepareCaptureSessionForReuse3
|
|
13192
13294
|
} from "@hyperframes/engine";
|
|
@@ -13523,7 +13625,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13523
13625
|
assertNotAborted();
|
|
13524
13626
|
const absoluteIdx = rangeStart + i;
|
|
13525
13627
|
const time = absoluteIdx * job.config.fps.den / job.config.fps.num;
|
|
13526
|
-
const { encodeResult } = await captureFrameToBufferPipelined2(session,
|
|
13628
|
+
const { encodeResult } = await captureFrameToBufferPipelined2(session, absoluteIdx, time);
|
|
13527
13629
|
await drainPrev();
|
|
13528
13630
|
prev = { fileIndex: i, encodeResult };
|
|
13529
13631
|
}
|
|
@@ -13533,7 +13635,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13533
13635
|
assertNotAborted();
|
|
13534
13636
|
const absoluteIdx = rangeStart + i;
|
|
13535
13637
|
const time = absoluteIdx * job.config.fps.den / job.config.fps.num;
|
|
13536
|
-
await captureFrame(session,
|
|
13638
|
+
await captureFrame(session, absoluteIdx, time, i);
|
|
13537
13639
|
reportFrame(i);
|
|
13538
13640
|
}
|
|
13539
13641
|
}
|
|
@@ -13548,11 +13650,11 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13548
13650
|
},
|
|
13549
13651
|
false
|
|
13550
13652
|
);
|
|
13551
|
-
dedupPerfs
|
|
13653
|
+
retainCapturePerf4(dedupPerfs, getCapturePerfSummary3(session));
|
|
13552
13654
|
}
|
|
13553
13655
|
|
|
13554
13656
|
// src/services/render/stages/captureHdrStage.ts
|
|
13555
|
-
import { existsSync as existsSync20, mkdirSync as
|
|
13657
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync11 } from "node:fs";
|
|
13556
13658
|
import { join as join33 } from "node:path";
|
|
13557
13659
|
import {
|
|
13558
13660
|
closeCaptureSession as closeCaptureSession7,
|
|
@@ -13664,9 +13766,18 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13664
13766
|
output: Buffer.alloc(bufSize)
|
|
13665
13767
|
} : null;
|
|
13666
13768
|
const normalCanvas = Buffer.alloc(bufSize);
|
|
13769
|
+
const firstFrame = windowStartFrame(job.frameWindow);
|
|
13770
|
+
cleanupHdrVideosEndedBefore(firstFrame, job.config.fps, transitionRanges, {
|
|
13771
|
+
hdrVideoEndTimes,
|
|
13772
|
+
cleanedUpVideos,
|
|
13773
|
+
hdrVideoFrameSources,
|
|
13774
|
+
sceneElements,
|
|
13775
|
+
log
|
|
13776
|
+
});
|
|
13667
13777
|
for (let i = 0; i < totalFrames; i++) {
|
|
13668
13778
|
assertNotAborted();
|
|
13669
|
-
const
|
|
13779
|
+
const frame = firstFrame + i;
|
|
13780
|
+
const time = frame * job.config.fps.den / job.config.fps.num;
|
|
13670
13781
|
if (hdrPerf) hdrPerf.frames += 1;
|
|
13671
13782
|
const stackingInfo = await seekInjectAndQueryStacking(
|
|
13672
13783
|
domSession.page,
|
|
@@ -13678,11 +13789,11 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13678
13789
|
"frameInjectMs",
|
|
13679
13790
|
"stackingQueryMs"
|
|
13680
13791
|
);
|
|
13681
|
-
const activeTransition = transitionRanges
|
|
13792
|
+
const activeTransition = transitionAtFrame(transitionRanges, frame);
|
|
13682
13793
|
if (i % 30 === 0 && (log.isLevelEnabled?.("debug") ?? true)) {
|
|
13683
13794
|
const hdrEl = stackingInfo.find((e) => e.isHdr);
|
|
13684
13795
|
log.debug("[Render] HDR layer composite frame", {
|
|
13685
|
-
frame
|
|
13796
|
+
frame,
|
|
13686
13797
|
time: time.toFixed(2),
|
|
13687
13798
|
hdrElement: hdrEl ? { z: hdrEl.zIndex, visible: hdrEl.visible, width: hdrEl.width } : null,
|
|
13688
13799
|
stackingCount: stackingInfo.length,
|
|
@@ -13692,7 +13803,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13692
13803
|
if (activeTransition && transitionBuffers) {
|
|
13693
13804
|
if (hdrPerf) hdrPerf.transitionFrames += 1;
|
|
13694
13805
|
const transitionTimingStart = Date.now();
|
|
13695
|
-
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (
|
|
13806
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (frame - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
13696
13807
|
const sceneAIds = new Set(sceneElements[activeTransition.fromScene] ?? []);
|
|
13697
13808
|
const sceneBIds = new Set(sceneElements[activeTransition.toScene] ?? []);
|
|
13698
13809
|
timeHdrPhase(hdrPerf, "canvasClearMs", () => {
|
|
@@ -13721,7 +13832,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13721
13832
|
hdrTargetTransfer,
|
|
13722
13833
|
hdrPerf,
|
|
13723
13834
|
log,
|
|
13724
|
-
frameIdx:
|
|
13835
|
+
frameIdx: frame
|
|
13725
13836
|
});
|
|
13726
13837
|
}
|
|
13727
13838
|
const shaderName = activeTransition.shader;
|
|
@@ -13746,7 +13857,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13746
13857
|
await timeHdrPhaseAsync(
|
|
13747
13858
|
hdrPerf,
|
|
13748
13859
|
"normalCompositeMs",
|
|
13749
|
-
() => compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, void 0,
|
|
13860
|
+
() => compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, void 0, frame)
|
|
13750
13861
|
);
|
|
13751
13862
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
13752
13863
|
writeFileExclusiveSync(
|
|
@@ -13796,7 +13907,7 @@ import {
|
|
|
13796
13907
|
// src/services/shaderTransitionWorkerPool.ts
|
|
13797
13908
|
import { Worker as Worker2 } from "node:worker_threads";
|
|
13798
13909
|
import { fileURLToPath as fileURLToPath4, pathToFileURL } from "node:url";
|
|
13799
|
-
import { dirname as
|
|
13910
|
+
import { dirname as dirname14, join as join31 } from "node:path";
|
|
13800
13911
|
import { createRequire } from "node:module";
|
|
13801
13912
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
13802
13913
|
import { existsSync as existsSync19 } from "node:fs";
|
|
@@ -13809,7 +13920,7 @@ function resolveWorkerEntry(explicit) {
|
|
|
13809
13920
|
const isTs = override.endsWith(".ts");
|
|
13810
13921
|
return { path: override, isTs };
|
|
13811
13922
|
}
|
|
13812
|
-
const moduleDir =
|
|
13923
|
+
const moduleDir = dirname14(fileURLToPath4(import.meta.url));
|
|
13813
13924
|
const jsPath = join31(moduleDir, "shaderTransitionWorker.js");
|
|
13814
13925
|
if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
|
|
13815
13926
|
const tsPath = join31(moduleDir, "shaderTransitionWorker.ts");
|
|
@@ -13955,8 +14066,8 @@ async function createShaderTransitionWorkerPool(opts) {
|
|
|
13955
14066
|
if (terminated) {
|
|
13956
14067
|
throw new Error("shader-blend pool already terminated");
|
|
13957
14068
|
}
|
|
13958
|
-
return new Promise((
|
|
13959
|
-
const task = traceEnabled ? { req, resolve:
|
|
14069
|
+
return new Promise((resolve15, reject) => {
|
|
14070
|
+
const task = traceEnabled ? { req, resolve: resolve15, reject, enqueuedAtMs: Date.now(), traceId: ++nextTaskId } : { req, resolve: resolve15, reject };
|
|
13960
14071
|
const idle = slots.find((s) => !s.busy && !s.dead);
|
|
13961
14072
|
if (idle) {
|
|
13962
14073
|
queue.unshift(task);
|
|
@@ -14017,7 +14128,8 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14017
14128
|
assertNotAborted,
|
|
14018
14129
|
onProgress
|
|
14019
14130
|
} = input;
|
|
14020
|
-
const
|
|
14131
|
+
const firstFrame = windowStartFrame(job.frameWindow);
|
|
14132
|
+
const transitionFramesSet = partitionTransitionFrames(transitionRanges, totalFrames, firstFrame);
|
|
14021
14133
|
const hasTransitions = transitionRanges.length > 0;
|
|
14022
14134
|
const bufSize = width * height * 6;
|
|
14023
14135
|
const workerSessions = [];
|
|
@@ -14108,8 +14220,9 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14108
14220
|
for (let i = range.start; i < range.end; i++) {
|
|
14109
14221
|
throwIfFailed();
|
|
14110
14222
|
assertNotAborted();
|
|
14111
|
-
const
|
|
14112
|
-
const
|
|
14223
|
+
const frame = firstFrame + i;
|
|
14224
|
+
const time = frame * job.config.fps.den / job.config.fps.num;
|
|
14225
|
+
const activeTransition = transitionFramesSet.has(frame) ? transitionAtFrame(transitionRanges, frame) : void 0;
|
|
14113
14226
|
if (activeTransition && ring) {
|
|
14114
14227
|
const slot = nextRingIdx;
|
|
14115
14228
|
nextRingIdx = (nextRingIdx + 1) % TRANSITION_RING_DEPTH;
|
|
@@ -14120,7 +14233,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14120
14233
|
if (!buffers) continue;
|
|
14121
14234
|
await captureTransitionFrameOnWorker({
|
|
14122
14235
|
session,
|
|
14123
|
-
frameIdx:
|
|
14236
|
+
frameIdx: frame,
|
|
14124
14237
|
time,
|
|
14125
14238
|
transition: activeTransition,
|
|
14126
14239
|
buffers,
|
|
@@ -14135,7 +14248,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14135
14248
|
hdrPerf,
|
|
14136
14249
|
log
|
|
14137
14250
|
});
|
|
14138
|
-
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (
|
|
14251
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (frame - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
14139
14252
|
const frameIdx = i;
|
|
14140
14253
|
const shaderName = activeTransition.shader;
|
|
14141
14254
|
const dispatch = (async () => {
|
|
@@ -14186,7 +14299,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14186
14299
|
await timeHdrPhaseAsync(
|
|
14187
14300
|
hdrPerf,
|
|
14188
14301
|
"normalCompositeMs",
|
|
14189
|
-
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0,
|
|
14302
|
+
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, frame)
|
|
14190
14303
|
);
|
|
14191
14304
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14192
14305
|
writeFileExclusiveSync(
|
|
@@ -14396,7 +14509,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14396
14509
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
14397
14510
|
const debugDumpDir = debugDumpEnabled ? join33(framesDir, "debug-composite") : null;
|
|
14398
14511
|
if (debugDumpDir && !existsSync20(debugDumpDir)) {
|
|
14399
|
-
|
|
14512
|
+
mkdirSync11(debugDumpDir, { recursive: true });
|
|
14400
14513
|
}
|
|
14401
14514
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
14402
14515
|
const hdrTargetTransfer = compositeTransfer === "srgb" ? void 0 : compositeTransfer;
|
|
@@ -14424,7 +14537,11 @@ async function runCaptureHdrStage(input) {
|
|
|
14424
14537
|
hdrPerf
|
|
14425
14538
|
};
|
|
14426
14539
|
const effectiveWorkerCount = Math.max(1, workerCount);
|
|
14427
|
-
const transitionFrameCount = partitionTransitionFrames(
|
|
14540
|
+
const transitionFrameCount = partitionTransitionFrames(
|
|
14541
|
+
transitionRanges,
|
|
14542
|
+
totalFrames,
|
|
14543
|
+
windowStartFrame(job.frameWindow)
|
|
14544
|
+
).size;
|
|
14428
14545
|
const useHybrid = shouldUseHybridLayeredPath({
|
|
14429
14546
|
hasHdrContent,
|
|
14430
14547
|
transitionFramesCount: transitionFrameCount,
|
|
@@ -14555,15 +14672,15 @@ async function runCaptureHdrStage(input) {
|
|
|
14555
14672
|
import {
|
|
14556
14673
|
copyFileSync as copyFileSync4,
|
|
14557
14674
|
existsSync as existsSync21,
|
|
14558
|
-
mkdirSync as
|
|
14675
|
+
mkdirSync as mkdirSync12,
|
|
14559
14676
|
readdirSync as readdirSync5,
|
|
14560
|
-
readFileSync as
|
|
14677
|
+
readFileSync as readFileSync10,
|
|
14561
14678
|
rmSync as rmSync12,
|
|
14562
14679
|
statSync as statSync9,
|
|
14563
|
-
writeFileSync as
|
|
14680
|
+
writeFileSync as writeFileSync6
|
|
14564
14681
|
} from "node:fs";
|
|
14565
14682
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
14566
|
-
import { dirname as
|
|
14683
|
+
import { dirname as dirname15, join as join34 } from "node:path";
|
|
14567
14684
|
import {
|
|
14568
14685
|
encodeFramesChunkedConcat,
|
|
14569
14686
|
encodeFramesFromDir,
|
|
@@ -14651,12 +14768,12 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
|
|
|
14651
14768
|
const error = formatFfmpegError(result.exitCode, result.stderr);
|
|
14652
14769
|
return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
|
|
14653
14770
|
}
|
|
14654
|
-
const gif =
|
|
14771
|
+
const gif = readFileSync10(outputPath);
|
|
14655
14772
|
if (!clearGifFramesBeforeNext(gif)) {
|
|
14656
14773
|
const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
|
|
14657
14774
|
return gifEncodeFailure(startTime, outputPath, error);
|
|
14658
14775
|
}
|
|
14659
|
-
|
|
14776
|
+
writeFileSync6(outputPath, gif);
|
|
14660
14777
|
return null;
|
|
14661
14778
|
}
|
|
14662
14779
|
async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
@@ -14684,7 +14801,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
14684
14801
|
return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
|
|
14685
14802
|
}
|
|
14686
14803
|
}
|
|
14687
|
-
if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(
|
|
14804
|
+
if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(readFileSync10(outputPath)) !== false) {
|
|
14688
14805
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
14689
14806
|
if (failure) return failure;
|
|
14690
14807
|
}
|
|
@@ -14779,7 +14896,7 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
14779
14896
|
const stream = await encoder;
|
|
14780
14897
|
for (let next = 0; next < totalFrames; next++) {
|
|
14781
14898
|
while (!landed.has(next) && !captureDone && !signal.aborted) {
|
|
14782
|
-
await new Promise((
|
|
14899
|
+
await new Promise((resolve15) => wake = resolve15);
|
|
14783
14900
|
}
|
|
14784
14901
|
if (signal.aborted) return;
|
|
14785
14902
|
const mergedPath = join34(input.framesDir, formatCaptureFrameName(next, "jpg"));
|
|
@@ -14857,7 +14974,7 @@ async function runEncodeStage(input) {
|
|
|
14857
14974
|
const stage5Start = Date.now();
|
|
14858
14975
|
if (isPngSequence) {
|
|
14859
14976
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
14860
|
-
if (!existsSync21(outputPath))
|
|
14977
|
+
if (!existsSync21(outputPath)) mkdirSync12(outputPath, { recursive: true });
|
|
14861
14978
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
14862
14979
|
if (captured.length === 0) {
|
|
14863
14980
|
throw new Error(
|
|
@@ -14889,7 +15006,7 @@ async function runEncodeStage(input) {
|
|
|
14889
15006
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
14890
15007
|
fps: job.config.fps,
|
|
14891
15008
|
loop,
|
|
14892
|
-
palettePath: join34(
|
|
15009
|
+
palettePath: join34(dirname15(videoOnlyPath), "gif-palette.png"),
|
|
14893
15010
|
preserveAlpha: needsAlpha,
|
|
14894
15011
|
signal: abortSignal,
|
|
14895
15012
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -15343,7 +15460,7 @@ function getNextRetryWorkerCount(currentWorkers) {
|
|
|
15343
15460
|
}
|
|
15344
15461
|
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir3()) {
|
|
15345
15462
|
if (platform2 === "win32" || platform2 === "darwin") return join35(systemTempDir, "hf-render-");
|
|
15346
|
-
return join35(
|
|
15463
|
+
return join35(dirname16(outputPath), `work-${jobId}-`);
|
|
15347
15464
|
}
|
|
15348
15465
|
var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
|
|
15349
15466
|
function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
|
|
@@ -16071,16 +16188,28 @@ function deVerifyFallbackTelemetry(err) {
|
|
|
16071
16188
|
};
|
|
16072
16189
|
}
|
|
16073
16190
|
function resolveRenderDebugDir() {
|
|
16074
|
-
const producerRoot = process.env.PRODUCER_RENDERS_DIR ?
|
|
16191
|
+
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve10(process.env.PRODUCER_RENDERS_DIR, "..") : resolve10(dirname16(fileURLToPath5(import.meta.url)), "../..");
|
|
16075
16192
|
return join35(producerRoot, ".debug");
|
|
16076
16193
|
}
|
|
16077
|
-
|
|
16194
|
+
function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
16195
|
+
return fromEmptyFolder(
|
|
16196
|
+
() => renderJob(
|
|
16197
|
+
job,
|
|
16198
|
+
resolve10(projectDir),
|
|
16199
|
+
resolve10(outputPath),
|
|
16200
|
+
progressSink,
|
|
16201
|
+
abortSignal,
|
|
16202
|
+
assertRenderActive
|
|
16203
|
+
)
|
|
16204
|
+
);
|
|
16205
|
+
}
|
|
16206
|
+
async function renderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
16078
16207
|
validateHlsRenderConfig(job.config);
|
|
16079
16208
|
validateDeliveryEncoderConfig(job.config);
|
|
16080
16209
|
validateChromaSubsamplingConfig(job.config);
|
|
16081
16210
|
const debugDir = resolveRenderDebugDir();
|
|
16082
|
-
const outputDir =
|
|
16083
|
-
if (!existsSync22(outputDir))
|
|
16211
|
+
const outputDir = dirname16(outputPath);
|
|
16212
|
+
if (!existsSync22(outputDir)) mkdirSync13(outputDir, { recursive: true });
|
|
16084
16213
|
const workDir = job.config.debug ? join35(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
16085
16214
|
const pipelineStart = Date.now();
|
|
16086
16215
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
@@ -16237,7 +16366,7 @@ async function executeRenderPipeline(input) {
|
|
|
16237
16366
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
16238
16367
|
assertNotAborted();
|
|
16239
16368
|
assertConfiguredFfmpegBinariesExist();
|
|
16240
|
-
if (!existsSync22(workDir))
|
|
16369
|
+
if (!existsSync22(workDir)) mkdirSync13(workDir, { recursive: true });
|
|
16241
16370
|
if (job.config.debug) {
|
|
16242
16371
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
16243
16372
|
}
|
|
@@ -16406,15 +16535,18 @@ async function executeRenderPipeline(input) {
|
|
|
16406
16535
|
if (resolvedCaptureBeyondViewport !== void 0) {
|
|
16407
16536
|
updateCaptureObservability({ captureBeyondViewport: resolvedCaptureBeyondViewport });
|
|
16408
16537
|
}
|
|
16409
|
-
job.duration = probeResult.duration;
|
|
16410
|
-
job.totalFrames = probeResult.totalFrames;
|
|
16411
|
-
const totalFrames = probeResult.totalFrames;
|
|
16412
|
-
captureTotalFrames = totalFrames;
|
|
16413
16538
|
validateRenderDuration({
|
|
16414
16539
|
duration: probeResult.duration,
|
|
16415
|
-
totalFrames,
|
|
16540
|
+
totalFrames: probeResult.totalFrames,
|
|
16416
16541
|
fps: fpsToNumber8(job.config.fps)
|
|
16417
16542
|
});
|
|
16543
|
+
const frameWindow = job.config.range ? resolveFrameWindow(job.config.range, job.config.fps, probeResult.totalFrames) : void 0;
|
|
16544
|
+
job.frameWindow = frameWindow;
|
|
16545
|
+
if (frameWindow) cfg.enableStreamingEncode = false;
|
|
16546
|
+
const totalFrames = frameWindow ? frameWindow.endFrame - frameWindow.startFrame : probeResult.totalFrames;
|
|
16547
|
+
job.totalFrames = totalFrames;
|
|
16548
|
+
job.duration = frameWindow ? totalFrames * job.config.fps.den / job.config.fps.num : probeResult.duration;
|
|
16549
|
+
captureTotalFrames = totalFrames;
|
|
16418
16550
|
const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(
|
|
16419
16551
|
probeSession.page,
|
|
16420
16552
|
largerThanCanvas,
|
|
@@ -16595,6 +16727,7 @@ async function executeRenderPipeline(input) {
|
|
|
16595
16727
|
workDir,
|
|
16596
16728
|
compiledDir,
|
|
16597
16729
|
totalFrames: probeResult.totalFrames,
|
|
16730
|
+
...frameWindow && { frameWindow },
|
|
16598
16731
|
fps: job.config.fps,
|
|
16599
16732
|
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
|
|
16600
16733
|
audioGain: cfg.audioGain,
|
|
@@ -16641,7 +16774,7 @@ async function executeRenderPipeline(input) {
|
|
|
16641
16774
|
throw new Error("File server failed to initialize before frame capture");
|
|
16642
16775
|
}
|
|
16643
16776
|
const framesDir = join35(workDir, "captured-frames");
|
|
16644
|
-
if (!existsSync22(framesDir))
|
|
16777
|
+
if (!existsSync22(framesDir)) mkdirSync13(framesDir, { recursive: true });
|
|
16645
16778
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
16646
16779
|
code: "start_browsers"
|
|
16647
16780
|
});
|
|
@@ -16649,6 +16782,23 @@ async function executeRenderPipeline(input) {
|
|
|
16649
16782
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
16650
16783
|
browserTimeout: cfg.browserTimeout
|
|
16651
16784
|
});
|
|
16785
|
+
const closeProbeSession = async () => {
|
|
16786
|
+
if (!probeSession) return;
|
|
16787
|
+
lastBrowserConsole = probeSession.browserConsoleBuffer;
|
|
16788
|
+
await closeCaptureSession8(probeSession).catch(() => {
|
|
16789
|
+
});
|
|
16790
|
+
probeSession = null;
|
|
16791
|
+
};
|
|
16792
|
+
const gpuStore = cfg.browserGpuMode === "auto" && resolvedBrowserGpuMode === "hardware" ? gpuChoiceStore(cfg, await probedHardwareGpu()) : void 0;
|
|
16793
|
+
const storedGpuChoice = gpuStore && readGpuChoice(gpuStore);
|
|
16794
|
+
if (gpuStore && storedGpuChoice === "software") {
|
|
16795
|
+
log.info("[Render] Auto GPU mode: rendering in software, as measured on this machine.", {
|
|
16796
|
+
file: gpuStore.file
|
|
16797
|
+
});
|
|
16798
|
+
cfg.browserGpuMode = "software";
|
|
16799
|
+
resolvedBrowserGpuMode = "software";
|
|
16800
|
+
await closeProbeSession();
|
|
16801
|
+
}
|
|
16652
16802
|
startingFrameCapture();
|
|
16653
16803
|
captureForceScreenshot = applyConcreteGpuScreenshotClamp(
|
|
16654
16804
|
captureForceScreenshot,
|
|
@@ -16885,6 +17035,10 @@ async function executeRenderPipeline(input) {
|
|
|
16885
17035
|
totalMemoryMb: Math.round(totalmem2() / (1024 * 1024)),
|
|
16886
17036
|
minMemoryMb: deParallelMinMemoryMb
|
|
16887
17037
|
});
|
|
17038
|
+
if (frameWindow) {
|
|
17039
|
+
deInversionEligible = false;
|
|
17040
|
+
deParallelRouterEligible = false;
|
|
17041
|
+
}
|
|
16888
17042
|
if (probeSession === null && (deInversionEligible || deParallelRouterEligible)) {
|
|
16889
17043
|
try {
|
|
16890
17044
|
probeSession = await createCaptureSession8(
|
|
@@ -16949,7 +17103,9 @@ async function executeRenderPipeline(input) {
|
|
|
16949
17103
|
return "beginFrame";
|
|
16950
17104
|
}
|
|
16951
17105
|
});
|
|
16952
|
-
|
|
17106
|
+
const sizeByCalibration = job.config.workers === void 0 && totalFrames >= 60 && !htmlInCanvasDetected && !cfg.lowMemoryMode && !deInversionEligible && !deParallelRouterEligible;
|
|
17107
|
+
const measureGpuChoice = gpuStore !== void 0 && storedGpuChoice === void 0;
|
|
17108
|
+
if (sizeByCalibration || measureGpuChoice) {
|
|
16953
17109
|
updateJobStatus(job, "rendering", "Measuring capture speed", 25, onProgress, {
|
|
16954
17110
|
code: "start_browsers"
|
|
16955
17111
|
});
|
|
@@ -16989,7 +17145,7 @@ async function executeRenderPipeline(input) {
|
|
|
16989
17145
|
probeSession
|
|
16990
17146
|
});
|
|
16991
17147
|
probeSession = result.probeSession;
|
|
16992
|
-
if (shouldCalibrateSoftwareGpu(
|
|
17148
|
+
if (storedGpuChoice === void 0 && shouldCalibrateSoftwareGpu(
|
|
16993
17149
|
cfg.browserGpuMode,
|
|
16994
17150
|
resolvedBrowserGpuMode,
|
|
16995
17151
|
result.calibration?.estimate
|
|
@@ -17014,7 +17170,7 @@ async function executeRenderPipeline(input) {
|
|
|
17014
17170
|
calibrationFrames?.release();
|
|
17015
17171
|
}
|
|
17016
17172
|
startingFrameCapture();
|
|
17017
|
-
captureCalibration = outcome.calibration;
|
|
17173
|
+
if (sizeByCalibration) captureCalibration = outcome.calibration;
|
|
17018
17174
|
calibrationEvaluateTimedOut = outcome.calibrationEvaluateTimedOut;
|
|
17019
17175
|
captureForceScreenshot = outcome.forceScreenshot;
|
|
17020
17176
|
updateCaptureObservability({ forceScreenshot: captureForceScreenshot });
|
|
@@ -17034,19 +17190,31 @@ async function executeRenderPipeline(input) {
|
|
|
17034
17190
|
);
|
|
17035
17191
|
cfg.browserGpuMode = "software";
|
|
17036
17192
|
resolvedBrowserGpuMode = "software";
|
|
17037
|
-
captureCalibration = softwareOutcome.calibration;
|
|
17193
|
+
if (sizeByCalibration) captureCalibration = softwareOutcome.calibration;
|
|
17038
17194
|
captureForceScreenshot = softwareOutcome.forceScreenshot;
|
|
17039
|
-
|
|
17040
|
-
lastBrowserConsole = probeSession.browserConsoleBuffer;
|
|
17041
|
-
await closeCaptureSession8(probeSession).catch(() => {
|
|
17042
|
-
});
|
|
17043
|
-
probeSession = null;
|
|
17044
|
-
}
|
|
17195
|
+
await closeProbeSession();
|
|
17045
17196
|
updateCaptureObservability({
|
|
17046
17197
|
browserGpuMode: resolvedBrowserGpuMode,
|
|
17047
17198
|
forceScreenshot: captureForceScreenshot
|
|
17048
17199
|
});
|
|
17049
17200
|
}
|
|
17201
|
+
const settledGpuChoice = measureGpuChoice ? settleAutoGpuChoice(outcome.calibration?.estimate, softwareOutcome?.calibration?.estimate) : void 0;
|
|
17202
|
+
if (gpuStore && settledGpuChoice) {
|
|
17203
|
+
try {
|
|
17204
|
+
writeGpuChoice(gpuStore, settledGpuChoice, {
|
|
17205
|
+
hardwareP95Ms: outcome.calibration?.estimate.p95Ms,
|
|
17206
|
+
softwareP95Ms: softwareOutcome?.calibration?.estimate.p95Ms
|
|
17207
|
+
});
|
|
17208
|
+
} catch (error) {
|
|
17209
|
+
log.warn(
|
|
17210
|
+
"[Render] Could not save the measured GPU choice; the next render measures again.",
|
|
17211
|
+
{
|
|
17212
|
+
file: gpuStore.file,
|
|
17213
|
+
error: error instanceof Error ? error.message : String(error)
|
|
17214
|
+
}
|
|
17215
|
+
);
|
|
17216
|
+
}
|
|
17217
|
+
}
|
|
17050
17218
|
observability.checkpoint("capture_calibration", "resolved", {
|
|
17051
17219
|
forceScreenshot: captureForceScreenshot,
|
|
17052
17220
|
browserGpuMode: resolvedBrowserGpuMode,
|
|
@@ -17402,6 +17570,7 @@ async function executeRenderPipeline(input) {
|
|
|
17402
17570
|
});
|
|
17403
17571
|
const syncCapturePlan = () => {
|
|
17404
17572
|
assertMotionBlurSupported(job.config.motionBlur, capturePlan.kind);
|
|
17573
|
+
assertRangeSupported(job.frameWindow, capturePlan.kind);
|
|
17405
17574
|
assertOutputScaleSupported(deviceScaleFactor, capturePlan.kind);
|
|
17406
17575
|
workerCount = capturePlan.workerCount;
|
|
17407
17576
|
captureForceScreenshot = capturePlan.forceScreenshot;
|
|
@@ -17987,6 +18156,7 @@ async function executeRenderPipeline(input) {
|
|
|
17987
18156
|
framesDir,
|
|
17988
18157
|
job,
|
|
17989
18158
|
totalFrames,
|
|
18159
|
+
...job.frameWindow && { frameRange: job.frameWindow },
|
|
17990
18160
|
cfg,
|
|
17991
18161
|
plan: diskPlan,
|
|
17992
18162
|
log,
|
|
@@ -18027,7 +18197,7 @@ async function executeRenderPipeline(input) {
|
|
|
18027
18197
|
"drawElement capture failed; retrying with a fresh screenshot session"
|
|
18028
18198
|
);
|
|
18029
18199
|
rmSync13(framesDir, { recursive: true, force: true });
|
|
18030
|
-
|
|
18200
|
+
mkdirSync13(framesDir, { recursive: true });
|
|
18031
18201
|
resetCaptureAttemptProgress(job);
|
|
18032
18202
|
dedupPerfs.length = 0;
|
|
18033
18203
|
cfg.useDrawElement = false;
|
|
@@ -18206,7 +18376,7 @@ async function executeRenderPipeline(input) {
|
|
|
18206
18376
|
job.perfSummary = perfSummary;
|
|
18207
18377
|
if (job.config.debug) {
|
|
18208
18378
|
try {
|
|
18209
|
-
|
|
18379
|
+
writeFileSync7(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
|
|
18210
18380
|
} catch (err) {
|
|
18211
18381
|
log.debug("Failed to write perf summary", {
|
|
18212
18382
|
perfOutputPath,
|
|
@@ -18335,15 +18505,15 @@ import {
|
|
|
18335
18505
|
REFERENCE_BACKGROUND_FIELD as REFERENCE_BACKGROUND_FIELD4,
|
|
18336
18506
|
referenceBackgroundResult as referenceBackgroundResult6
|
|
18337
18507
|
} from "@hyperframes/engine";
|
|
18338
|
-
import { mkdirSync as
|
|
18508
|
+
import { mkdirSync as mkdirSync21, mkdtempSync, readFileSync as readFileSync16, rmSync as rmSync19 } from "node:fs";
|
|
18339
18509
|
import { join as join49 } from "node:path";
|
|
18340
18510
|
import { tmpdir as tmpdir5 } from "node:os";
|
|
18341
18511
|
|
|
18342
18512
|
// src/services/distributed/mp4Stitch.ts
|
|
18343
|
-
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as
|
|
18513
|
+
import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync14, rmSync as rmSync14 } from "node:fs";
|
|
18344
18514
|
import { open } from "node:fs/promises";
|
|
18345
18515
|
import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
|
|
18346
|
-
import { basename as basename8, dirname as
|
|
18516
|
+
import { basename as basename8, dirname as dirname17, join as join36 } from "node:path";
|
|
18347
18517
|
import { finished, pipeline } from "node:stream/promises";
|
|
18348
18518
|
import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
|
|
18349
18519
|
function boxAt(src, off, at, limit) {
|
|
@@ -18708,8 +18878,8 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
|
|
|
18708
18878
|
const sourcePaths = audioPath ? [audioPath, ...chunkPaths] : chunkPaths;
|
|
18709
18879
|
const layouts = await Promise.all(sourcePaths.map((path) => readMp4Layout(fileRange(path))));
|
|
18710
18880
|
const header = audioPath ? buildStitchedHeader(layouts.slice(1), layouts[0]) : buildStitchedHeader(layouts);
|
|
18711
|
-
|
|
18712
|
-
const workDir = createStagingDir4(
|
|
18881
|
+
mkdirSync14(dirname17(outputPath), { recursive: true });
|
|
18882
|
+
const workDir = createStagingDir4(dirname17(outputPath), `${basename8(outputPath)}.stitch-`);
|
|
18713
18883
|
const out = createWriteStream(join36(workDir, "out.mp4"));
|
|
18714
18884
|
try {
|
|
18715
18885
|
out.write(header);
|
|
@@ -18735,9 +18905,9 @@ import {
|
|
|
18735
18905
|
cpSync as cpSync2,
|
|
18736
18906
|
existsSync as existsSync27,
|
|
18737
18907
|
linkSync,
|
|
18738
|
-
mkdirSync as
|
|
18908
|
+
mkdirSync as mkdirSync17,
|
|
18739
18909
|
rmSync as rmSync15,
|
|
18740
|
-
writeFileSync as
|
|
18910
|
+
writeFileSync as writeFileSync10
|
|
18741
18911
|
} from "node:fs";
|
|
18742
18912
|
import { extname as extname6, isAbsolute as isAbsolute5, join as join44, relative as relative8, sep as sep5 } from "node:path";
|
|
18743
18913
|
import {
|
|
@@ -18775,8 +18945,8 @@ import {
|
|
|
18775
18945
|
|
|
18776
18946
|
// src/services/distributed/shared.ts
|
|
18777
18947
|
import { execFile as execFileCallback } from "node:child_process";
|
|
18778
|
-
import { dirname as
|
|
18779
|
-
import { existsSync as existsSync23, readFileSync as
|
|
18948
|
+
import { dirname as dirname18, join as join37 } from "node:path";
|
|
18949
|
+
import { existsSync as existsSync23, readFileSync as readFileSync11 } from "node:fs";
|
|
18780
18950
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
18781
18951
|
import { promisify as promisify2 } from "node:util";
|
|
18782
18952
|
import {
|
|
@@ -19053,13 +19223,13 @@ function buildSyntheticRenderJob(input) {
|
|
|
19053
19223
|
var cachedProducerVersion = null;
|
|
19054
19224
|
function readProducerVersion() {
|
|
19055
19225
|
if (cachedProducerVersion !== null) return cachedProducerVersion;
|
|
19056
|
-
const startDir =
|
|
19226
|
+
const startDir = dirname18(fileURLToPath6(import.meta.url));
|
|
19057
19227
|
let current = startDir;
|
|
19058
19228
|
for (let i = 0; i < 10; i++) {
|
|
19059
19229
|
const candidate = join37(current, "package.json");
|
|
19060
19230
|
if (existsSync23(candidate)) {
|
|
19061
19231
|
try {
|
|
19062
|
-
const pkg = JSON.parse(
|
|
19232
|
+
const pkg = JSON.parse(readFileSync11(candidate, "utf-8"));
|
|
19063
19233
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
19064
19234
|
cachedProducerVersion = pkg.version;
|
|
19065
19235
|
return pkg.version;
|
|
@@ -19067,7 +19237,7 @@ function readProducerVersion() {
|
|
|
19067
19237
|
} catch {
|
|
19068
19238
|
}
|
|
19069
19239
|
}
|
|
19070
|
-
const parent =
|
|
19240
|
+
const parent = dirname18(current);
|
|
19071
19241
|
if (parent === current) break;
|
|
19072
19242
|
current = parent;
|
|
19073
19243
|
}
|
|
@@ -19412,8 +19582,8 @@ async function readPlanReferenceBackground(input) {
|
|
|
19412
19582
|
}
|
|
19413
19583
|
|
|
19414
19584
|
// src/services/render/stages/freezePlan.ts
|
|
19415
|
-
import { existsSync as existsSync25, mkdirSync as
|
|
19416
|
-
import { join as join41, relative as relative6, resolve as
|
|
19585
|
+
import { existsSync as existsSync25, mkdirSync as mkdirSync15, readFileSync as readFileSync12, readdirSync as readdirSync8, writeFileSync as writeFileSync8 } from "node:fs";
|
|
19586
|
+
import { join as join41, relative as relative6, resolve as resolve11 } from "node:path";
|
|
19417
19587
|
import {
|
|
19418
19588
|
REFERENCE_BACKGROUND_FIELD,
|
|
19419
19589
|
referenceBackgroundResult as referenceBackgroundResult3
|
|
@@ -19627,7 +19797,7 @@ function stripUndefined(value) {
|
|
|
19627
19797
|
}
|
|
19628
19798
|
function listPlanFiles(planDir) {
|
|
19629
19799
|
const results = [];
|
|
19630
|
-
const rootResolved =
|
|
19800
|
+
const rootResolved = resolve11(planDir);
|
|
19631
19801
|
function walk(dir) {
|
|
19632
19802
|
const entries = readdirSync8(dir, { withFileTypes: true });
|
|
19633
19803
|
for (const entry of entries) {
|
|
@@ -19652,7 +19822,7 @@ function collectPlanAssetShas(planDir, digests) {
|
|
|
19652
19822
|
const assets = [];
|
|
19653
19823
|
for (const file of files) {
|
|
19654
19824
|
if (file.planRelativePath === COMPILED_INDEX_RELATIVE_PATH) {
|
|
19655
|
-
compositionHtml =
|
|
19825
|
+
compositionHtml = readFileSync12(file.absolutePath);
|
|
19656
19826
|
continue;
|
|
19657
19827
|
}
|
|
19658
19828
|
if (HASH_EXCLUDED_PLAN_FILES.has(file.planRelativePath)) continue;
|
|
@@ -19672,11 +19842,11 @@ var PLAN_REMOTE_FILES_RELATIVE_PATH = "meta/remote-files.json";
|
|
|
19672
19842
|
function writePlanRemoteFiles(planDir, files) {
|
|
19673
19843
|
if (files.length === 0) return;
|
|
19674
19844
|
const sorted = [...files].sort((a, b) => a.path < b.path ? -1 : 1);
|
|
19675
|
-
|
|
19845
|
+
writeFileSync8(join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH), JSON.stringify(sorted), "utf-8");
|
|
19676
19846
|
}
|
|
19677
19847
|
function readPlanRemoteFiles(planDir) {
|
|
19678
19848
|
const path = join41(planDir, PLAN_REMOTE_FILES_RELATIVE_PATH);
|
|
19679
|
-
return existsSync25(path) ? JSON.parse(
|
|
19849
|
+
return existsSync25(path) ? JSON.parse(readFileSync12(path, "utf-8")) : [];
|
|
19680
19850
|
}
|
|
19681
19851
|
function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
19682
19852
|
const planJsonPath = join41(planDir, "plan.json");
|
|
@@ -19687,8 +19857,8 @@ function recomputePlanHashFromPlanDir(planDir, digests) {
|
|
|
19687
19857
|
if (!existsSync25(encoderJsonPath)) {
|
|
19688
19858
|
throw new Error(`[freezePlan] meta/encoder.json missing: ${encoderJsonPath}`);
|
|
19689
19859
|
}
|
|
19690
|
-
const planJson = JSON.parse(
|
|
19691
|
-
const encoderConfigCanonicalJson =
|
|
19860
|
+
const planJson = JSON.parse(readFileSync12(planJsonPath, "utf-8"));
|
|
19861
|
+
const encoderConfigCanonicalJson = readFileSync12(encoderJsonPath, "utf-8");
|
|
19692
19862
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
19693
19863
|
return computePlanHash({
|
|
19694
19864
|
compositionHtml,
|
|
@@ -19718,8 +19888,8 @@ async function freezePlan(input) {
|
|
|
19718
19888
|
throw new Error(`[freezePlan] planDir does not exist: ${planDir}`);
|
|
19719
19889
|
}
|
|
19720
19890
|
const metaDir = join41(planDir, "meta");
|
|
19721
|
-
if (!existsSync25(metaDir))
|
|
19722
|
-
|
|
19891
|
+
if (!existsSync25(metaDir)) mkdirSync15(metaDir, { recursive: true });
|
|
19892
|
+
writeFileSync8(
|
|
19723
19893
|
join41(metaDir, "composition.json"),
|
|
19724
19894
|
`${JSON.stringify(composition, null, 2)}
|
|
19725
19895
|
`,
|
|
@@ -19727,8 +19897,8 @@ async function freezePlan(input) {
|
|
|
19727
19897
|
);
|
|
19728
19898
|
const encoderForCanonical = stripUndefined(encoder);
|
|
19729
19899
|
const encoderConfigCanonicalJson = canonicalJsonStringify(encoderForCanonical);
|
|
19730
|
-
|
|
19731
|
-
|
|
19900
|
+
writeFileSync8(join41(metaDir, "encoder.json"), encoderConfigCanonicalJson, "utf-8");
|
|
19901
|
+
writeFileSync8(join41(metaDir, "chunks.json"), `${JSON.stringify(chunks, null, 2)}
|
|
19732
19902
|
`, "utf-8");
|
|
19733
19903
|
const { compositionHtml, assets } = collectPlanAssetShas(planDir, digests);
|
|
19734
19904
|
const planHash = computePlanHash({
|
|
@@ -19754,7 +19924,7 @@ async function freezePlan(input) {
|
|
|
19754
19924
|
hasAudio
|
|
19755
19925
|
};
|
|
19756
19926
|
const planJsonPath = join41(planDir, "plan.json");
|
|
19757
|
-
|
|
19927
|
+
writeFileSync8(planJsonPath, `${JSON.stringify(planJson, null, 2)}
|
|
19758
19928
|
`, "utf-8");
|
|
19759
19929
|
return { planJsonPath, planHash };
|
|
19760
19930
|
}
|
|
@@ -19795,8 +19965,8 @@ function applyRuntimeEnvSnapshot(snapshot, env = process.env) {
|
|
|
19795
19965
|
}
|
|
19796
19966
|
|
|
19797
19967
|
// src/services/distributed/chunkAudio.ts
|
|
19798
|
-
import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as
|
|
19799
|
-
import { writeFileSync as
|
|
19968
|
+
import { closeSync as closeSync7, existsSync as existsSync26, ftruncateSync, mkdirSync as mkdirSync16, openSync as openSync7, readFileSync as readFileSync13 } from "node:fs";
|
|
19969
|
+
import { writeFileSync as writeFileSync9, writeSync } from "node:fs";
|
|
19800
19970
|
import { join as join42 } from "node:path";
|
|
19801
19971
|
import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFailure4, runFfmpeg as runFfmpeg7 } from "@hyperframes/engine";
|
|
19802
19972
|
function audioCutForChunk(grid, chunks, index, fps) {
|
|
@@ -19883,9 +20053,9 @@ async function writeChunkAudioSlices(input) {
|
|
|
19883
20053
|
offset += track.sizes[offsets.length - 1];
|
|
19884
20054
|
}
|
|
19885
20055
|
});
|
|
19886
|
-
const bytes =
|
|
20056
|
+
const bytes = readFileSync13(input.audioPath);
|
|
19887
20057
|
const layout = { sizeBytes: bytes.length, payloadStart, payloadEnd, partStarts: {} };
|
|
19888
|
-
|
|
20058
|
+
mkdirSync16(join42(input.planDir, SLICE_DIR), { recursive: true });
|
|
19889
20059
|
input.chunks.forEach((_, index) => {
|
|
19890
20060
|
const cut = audioCutForChunk(grid, input.chunks, index, input.fps);
|
|
19891
20061
|
if (!cut) return;
|
|
@@ -19893,17 +20063,17 @@ async function writeChunkAudioSlices(input) {
|
|
|
19893
20063
|
const start = offsets[cut.firstPacket];
|
|
19894
20064
|
layout.partStarts[index] = start;
|
|
19895
20065
|
const end = offsets[last] + track.sizes[last];
|
|
19896
|
-
|
|
20066
|
+
writeFileSync9(join42(input.planDir, chunkAudioSlicePath(index)), bytes.subarray(start, end));
|
|
19897
20067
|
});
|
|
19898
20068
|
const frame = [bytes.subarray(0, payloadStart), bytes.subarray(payloadEnd)];
|
|
19899
|
-
|
|
19900
|
-
|
|
20069
|
+
writeFileSync9(join42(input.planDir, SLICE_FRAME), Buffer.concat(frame));
|
|
20070
|
+
writeFileSync9(join42(input.planDir, SLICE_LAYOUT), JSON.stringify(layout));
|
|
19901
20071
|
}
|
|
19902
20072
|
function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
19903
20073
|
const layoutPath = join42(planDir, SLICE_LAYOUT);
|
|
19904
20074
|
if (!existsSync26(layoutPath)) return resolvePlanAudioPath(planDir);
|
|
19905
|
-
const layout = JSON.parse(
|
|
19906
|
-
const frame =
|
|
20075
|
+
const layout = JSON.parse(readFileSync13(layoutPath, "utf-8"));
|
|
20076
|
+
const frame = readFileSync13(join42(planDir, SLICE_FRAME));
|
|
19907
20077
|
const fd = openSync7(scratchPath, "w");
|
|
19908
20078
|
try {
|
|
19909
20079
|
writeSync(fd, frame, 0, layout.payloadStart, 0);
|
|
@@ -19916,7 +20086,7 @@ function chunkAudioSource(planDir, chunkIndex, scratchPath) {
|
|
|
19916
20086
|
);
|
|
19917
20087
|
const start = layout.partStarts[chunkIndex];
|
|
19918
20088
|
if (start !== void 0) {
|
|
19919
|
-
const part =
|
|
20089
|
+
const part = readFileSync13(join42(planDir, chunkAudioSlicePath(chunkIndex)));
|
|
19920
20090
|
writeSync(fd, part, 0, part.length, start);
|
|
19921
20091
|
}
|
|
19922
20092
|
ftruncateSync(fd, layout.sizeBytes);
|
|
@@ -20476,7 +20646,7 @@ function createVideoSourceShipper(input) {
|
|
|
20476
20646
|
if (result === null) {
|
|
20477
20647
|
result = `video-sources/${shipped.size}${extname6(current)}`;
|
|
20478
20648
|
const destination = join44(input.planDir, ...result.split("/"));
|
|
20479
|
-
|
|
20649
|
+
mkdirSync17(join44(input.planDir, "video-sources"), { recursive: true });
|
|
20480
20650
|
try {
|
|
20481
20651
|
linkSync(current, destination);
|
|
20482
20652
|
} catch {
|
|
@@ -20496,7 +20666,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20496
20666
|
useGpu: false,
|
|
20497
20667
|
browserGpuMode: "software"
|
|
20498
20668
|
});
|
|
20499
|
-
if (!existsSync27(planDir))
|
|
20669
|
+
if (!existsSync27(planDir)) mkdirSync17(planDir, { recursive: true });
|
|
20500
20670
|
const log = config.logger ?? defaultLogger;
|
|
20501
20671
|
const sizeLimitBytes = options.executionPlanSizeLimitBytes ?? config.planDirSizeLimitBytes ?? PLAN_DIR_SIZE_LIMIT_BYTES;
|
|
20502
20672
|
const abortSignal = config.abortSignal;
|
|
@@ -20536,9 +20706,9 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
|
|
|
20536
20706
|
}
|
|
20537
20707
|
const workDir = join44(planDir, ".plan-work");
|
|
20538
20708
|
rmSync15(workDir, { recursive: true, force: true });
|
|
20539
|
-
|
|
20709
|
+
mkdirSync17(workDir, { recursive: true });
|
|
20540
20710
|
const compiledDir = join44(workDir, "compiled");
|
|
20541
|
-
|
|
20711
|
+
mkdirSync17(compiledDir, { recursive: true });
|
|
20542
20712
|
let stageStarted = Date.now();
|
|
20543
20713
|
cpSync2(projectDir, compiledDir, {
|
|
20544
20714
|
recursive: true,
|
|
@@ -20773,7 +20943,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20773
20943
|
if (existsSync27(stagedVideoFrames)) {
|
|
20774
20944
|
renameWithRetry7(stagedVideoFrames, videoFramesDst);
|
|
20775
20945
|
} else {
|
|
20776
|
-
|
|
20946
|
+
mkdirSync17(videoFramesDst, { recursive: true });
|
|
20777
20947
|
}
|
|
20778
20948
|
if (existsSync27(finalCompiledDir)) rmSync15(finalCompiledDir, { recursive: true, force: true });
|
|
20779
20949
|
renameWithRetry7(compiledDir, finalCompiledDir);
|
|
@@ -20805,7 +20975,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20805
20975
|
};
|
|
20806
20976
|
})
|
|
20807
20977
|
});
|
|
20808
|
-
|
|
20978
|
+
mkdirSync17(join44(planDir, "meta"), { recursive: true });
|
|
20809
20979
|
writePlanRemoteFiles(
|
|
20810
20980
|
planDir,
|
|
20811
20981
|
remoteFiles.map(([rel, { sha256, sizeBytes }]) => ({
|
|
@@ -20814,7 +20984,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
|
|
|
20814
20984
|
sizeBytes
|
|
20815
20985
|
}))
|
|
20816
20986
|
);
|
|
20817
|
-
|
|
20987
|
+
writeFileSync10(
|
|
20818
20988
|
join44(planDir, PLAN_VIDEOS_META_RELATIVE_PATH),
|
|
20819
20989
|
JSON.stringify(planVideosJson, null, 2),
|
|
20820
20990
|
"utf-8"
|
|
@@ -21021,7 +21191,7 @@ async function plan(projectDir, config, planDir, options = {}) {
|
|
|
21021
21191
|
|
|
21022
21192
|
// src/services/distributed/renderChunk.ts
|
|
21023
21193
|
import { randomBytes } from "node:crypto";
|
|
21024
|
-
import { existsSync as existsSync30, mkdirSync as
|
|
21194
|
+
import { existsSync as existsSync30, mkdirSync as mkdirSync20, readFileSync as readFileSync15, readdirSync as readdirSync11, rmSync as rmSync18, writeFileSync as writeFileSync13 } from "node:fs";
|
|
21025
21195
|
import { join as join48 } from "node:path";
|
|
21026
21196
|
import {
|
|
21027
21197
|
assertSwiftShader,
|
|
@@ -21050,15 +21220,15 @@ import {
|
|
|
21050
21220
|
copyFileSync as copyFileSync8,
|
|
21051
21221
|
existsSync as existsSync29,
|
|
21052
21222
|
lstatSync as lstatSync5,
|
|
21053
|
-
mkdirSync as
|
|
21054
|
-
readFileSync as
|
|
21223
|
+
mkdirSync as mkdirSync19,
|
|
21224
|
+
readFileSync as readFileSync14,
|
|
21055
21225
|
readdirSync as readdirSync10,
|
|
21056
21226
|
rmSync as rmSync17,
|
|
21057
21227
|
statSync as statSync12,
|
|
21058
|
-
writeFileSync as
|
|
21228
|
+
writeFileSync as writeFileSync12
|
|
21059
21229
|
} from "node:fs";
|
|
21060
21230
|
import { tmpdir as tmpdir4 } from "node:os";
|
|
21061
|
-
import { dirname as
|
|
21231
|
+
import { dirname as dirname20, isAbsolute as isAbsolute6, join as join47, relative as relative9, resolve as resolve12, sep as sep6 } from "node:path";
|
|
21062
21232
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
21063
21233
|
import {
|
|
21064
21234
|
createFrameLookupTable as createFrameLookupTable5,
|
|
@@ -21071,13 +21241,13 @@ import {
|
|
|
21071
21241
|
copyFileSync as copyFileSync7,
|
|
21072
21242
|
existsSync as existsSync28,
|
|
21073
21243
|
linkSync as linkSync2,
|
|
21074
|
-
mkdirSync as
|
|
21244
|
+
mkdirSync as mkdirSync18,
|
|
21075
21245
|
rmSync as rmSync16,
|
|
21076
21246
|
statSync as statSync11,
|
|
21077
|
-
writeFileSync as
|
|
21247
|
+
writeFileSync as writeFileSync11
|
|
21078
21248
|
} from "node:fs";
|
|
21079
21249
|
import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
|
|
21080
|
-
import { dirname as
|
|
21250
|
+
import { dirname as dirname19, join as join46 } from "node:path";
|
|
21081
21251
|
|
|
21082
21252
|
// src/services/distributed/planV2Errors.ts
|
|
21083
21253
|
var PLAN_V2_INTEGRITY_UNRECOVERABLE = "PLAN_V2_INTEGRITY_UNRECOVERABLE";
|
|
@@ -21138,8 +21308,8 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
21138
21308
|
}
|
|
21139
21309
|
this.destinationDir = destinationDir;
|
|
21140
21310
|
this.#linkFile = options.linkFile ?? linkSync2;
|
|
21141
|
-
|
|
21142
|
-
this.temporaryDir = createStagingDir5(
|
|
21311
|
+
mkdirSync18(dirname19(destinationDir), { recursive: true });
|
|
21312
|
+
this.temporaryDir = createStagingDir5(dirname19(destinationDir), ".plan-v2-publish-");
|
|
21143
21313
|
}
|
|
21144
21314
|
async putBlob(blob) {
|
|
21145
21315
|
const digest = assertPlanV2Sha256(blob.sha256, "published blob sha256");
|
|
@@ -21151,8 +21321,8 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
21151
21321
|
}
|
|
21152
21322
|
const destinationPath = planV2BlobPath(this.temporaryDir, digest);
|
|
21153
21323
|
if (existsSync28(destinationPath)) return;
|
|
21154
|
-
|
|
21155
|
-
const stagingDir = createStagingDir5(
|
|
21324
|
+
mkdirSync18(dirname19(destinationPath), { recursive: true });
|
|
21325
|
+
const stagingDir = createStagingDir5(dirname19(destinationPath), ".plan-v2-blob-");
|
|
21156
21326
|
const temporaryPath = join46(stagingDir, "blob");
|
|
21157
21327
|
try {
|
|
21158
21328
|
try {
|
|
@@ -21174,7 +21344,7 @@ var LocalPlanV2ArtifactPublisher = class {
|
|
|
21174
21344
|
);
|
|
21175
21345
|
}
|
|
21176
21346
|
}
|
|
21177
|
-
|
|
21347
|
+
writeFileSync11(join46(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
|
|
21178
21348
|
renameWithRetry8(this.temporaryDir, this.destinationDir);
|
|
21179
21349
|
this.#committed = true;
|
|
21180
21350
|
}
|
|
@@ -21200,7 +21370,7 @@ function isNonNegativeIntegerArray(value) {
|
|
|
21200
21370
|
return Array.isArray(value) && value.every((item) => typeof item === "number" && Number.isInteger(item) && item >= 0);
|
|
21201
21371
|
}
|
|
21202
21372
|
function readJsonFile(path, label) {
|
|
21203
|
-
const contents =
|
|
21373
|
+
const contents = readFileSync14(path, "utf-8");
|
|
21204
21374
|
try {
|
|
21205
21375
|
const parsed = JSON.parse(contents);
|
|
21206
21376
|
return parsed;
|
|
@@ -21217,7 +21387,7 @@ function assertSafeRelativePath(path) {
|
|
|
21217
21387
|
}
|
|
21218
21388
|
function listFiles(root) {
|
|
21219
21389
|
const files = [];
|
|
21220
|
-
const rootResolved =
|
|
21390
|
+
const rootResolved = resolve12(root);
|
|
21221
21391
|
function walk(dir) {
|
|
21222
21392
|
for (const entry of readdirSync10(dir, { withFileTypes: true })) {
|
|
21223
21393
|
const absolutePath = join47(dir, entry.name);
|
|
@@ -21263,8 +21433,8 @@ function isExtractionCacheCompleteSentinelPath(path) {
|
|
|
21263
21433
|
return segments.length === 3 && segments[0] === "video-frames" && segments[1] !== "" && segments[2] === EXTRACTION_CACHE_COMPLETE_SENTINEL;
|
|
21264
21434
|
}
|
|
21265
21435
|
function resolveExtractedVideoOutputDir(planDir, videoId) {
|
|
21266
|
-
const videoRoot =
|
|
21267
|
-
const outputDir =
|
|
21436
|
+
const videoRoot = resolve12(planDir, "video-frames");
|
|
21437
|
+
const outputDir = resolve12(videoRoot, mediaIdPathSegment4(videoId));
|
|
21268
21438
|
if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep6}`)) {
|
|
21269
21439
|
throw new PlanV2IntegrityError(`unsafe extracted video id: ${JSON.stringify(videoId)}`);
|
|
21270
21440
|
}
|
|
@@ -21352,7 +21522,7 @@ function materializeExtractedVideoDirectories(planDir) {
|
|
|
21352
21522
|
if (!existsSync29(videosPath)) return;
|
|
21353
21523
|
const videos = parsePlanVideosJson2(readJsonFile(videosPath, PLAN_VIDEOS_META_RELATIVE_PATH));
|
|
21354
21524
|
for (const video of videos.extracted) {
|
|
21355
|
-
|
|
21525
|
+
mkdirSync19(resolveExtractedVideoOutputDir(planDir, video.videoId), { recursive: true });
|
|
21356
21526
|
}
|
|
21357
21527
|
}
|
|
21358
21528
|
function parseChunkSlices(value) {
|
|
@@ -21425,7 +21595,7 @@ function collectChunkVideoDependencies(input) {
|
|
|
21425
21595
|
for (let frame = chunk.startFrame; frame < chunk.endFrame; frame++) {
|
|
21426
21596
|
const globalTime = frame * input.fpsDen / input.fpsNum;
|
|
21427
21597
|
for (const [videoId, payload] of input.table.getActiveFramePayloads(globalTime)) {
|
|
21428
|
-
const path = input.deferredSources.get(videoId) ?? relative9(
|
|
21598
|
+
const path = input.deferredSources.get(videoId) ?? relative9(resolve12(input.executionPlanDir), payload.framePath).split(sep6).join("/");
|
|
21429
21599
|
assertSafeRelativePath(path);
|
|
21430
21600
|
const indexes = mutable.get(path) ?? /* @__PURE__ */ new Set();
|
|
21431
21601
|
indexes.add(chunk.index);
|
|
@@ -21443,8 +21613,8 @@ function computeManifestHash(manifest) {
|
|
|
21443
21613
|
}
|
|
21444
21614
|
function writeBlob(sourcePath, destinationPath) {
|
|
21445
21615
|
if (existsSync29(destinationPath)) return;
|
|
21446
|
-
|
|
21447
|
-
const temporaryDir = createStagingDir6(
|
|
21616
|
+
mkdirSync19(dirname20(destinationPath), { recursive: true });
|
|
21617
|
+
const temporaryDir = createStagingDir6(dirname20(destinationPath), ".plan-v2-blob-");
|
|
21448
21618
|
const temporaryPath = join47(temporaryDir, "blob");
|
|
21449
21619
|
try {
|
|
21450
21620
|
copyFileSync8(sourcePath, temporaryPath);
|
|
@@ -21569,13 +21739,13 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
|
|
|
21569
21739
|
if (publication.storedBlobs.length > 0) {
|
|
21570
21740
|
throw new PlanV2IntegrityError("a local plan v2 directory cannot reference remote files");
|
|
21571
21741
|
}
|
|
21572
|
-
|
|
21573
|
-
const tempDir = createStagingDir6(
|
|
21742
|
+
mkdirSync19(dirname20(planV2Dir), { recursive: true });
|
|
21743
|
+
const tempDir = createStagingDir6(dirname20(planV2Dir), ".plan-v2-build-");
|
|
21574
21744
|
try {
|
|
21575
21745
|
for (const blob of publication.blobs) {
|
|
21576
21746
|
writeBlob(blob.sourcePath, planV2BlobPath(tempDir, blob.sha256));
|
|
21577
21747
|
}
|
|
21578
|
-
|
|
21748
|
+
writeFileSync12(
|
|
21579
21749
|
join47(tempDir, "plan.json"),
|
|
21580
21750
|
canonicalJsonStringify(publication.manifest),
|
|
21581
21751
|
"utf-8"
|
|
@@ -21657,7 +21827,7 @@ async function planV2(projectDir, config, planV2Dir) {
|
|
|
21657
21827
|
}
|
|
21658
21828
|
const publisher = new LocalPlanV2ArtifactPublisher(planV2Dir);
|
|
21659
21829
|
const manifest = await planV2WithPublisher(projectDir, config, publisher, {
|
|
21660
|
-
stagingParentDir:
|
|
21830
|
+
stagingParentDir: dirname20(planV2Dir)
|
|
21661
21831
|
});
|
|
21662
21832
|
return resultFromManifest(planV2Dir, manifest);
|
|
21663
21833
|
}
|
|
@@ -21850,16 +22020,16 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
|
|
|
21850
22020
|
artifact,
|
|
21851
22021
|
sourcePath: verifyBlob(planV2Dir, artifact)
|
|
21852
22022
|
}));
|
|
21853
|
-
|
|
21854
|
-
const tempDir = createStagingDir6(
|
|
22023
|
+
mkdirSync19(dirname20(destinationDir), { recursive: true });
|
|
22024
|
+
const tempDir = createStagingDir6(dirname20(destinationDir), ".plan-v2-materialize-");
|
|
21855
22025
|
try {
|
|
21856
22026
|
for (const { artifact, sourcePath } of verified) {
|
|
21857
22027
|
const destinationPath = join47(tempDir, ...artifact.path.split("/"));
|
|
21858
|
-
|
|
22028
|
+
mkdirSync19(dirname20(destinationPath), { recursive: true });
|
|
21859
22029
|
copyFileSync8(sourcePath, destinationPath);
|
|
21860
22030
|
}
|
|
21861
22031
|
if (target.role === "chunk") materializeExtractedVideoDirectories(tempDir);
|
|
21862
|
-
|
|
22032
|
+
writeFileSync12(
|
|
21863
22033
|
join47(tempDir, PLAN_V2_MATERIALIZATION_MARKER),
|
|
21864
22034
|
canonicalJsonStringify({
|
|
21865
22035
|
manifest,
|
|
@@ -22049,10 +22219,10 @@ async function beginFrameSessionNeedsScreenshotFallback(session, probe = probeBe
|
|
|
22049
22219
|
return !await probe(session.page, timeoutMs, probeTick, session.beginFrameIntervalMs);
|
|
22050
22220
|
}
|
|
22051
22221
|
function hashChunkOutput(outputPath, kind) {
|
|
22052
|
-
if (kind === "file") return sha256Hex(
|
|
22222
|
+
if (kind === "file") return sha256Hex(readFileSync15(outputPath));
|
|
22053
22223
|
const entries = readdirSync11(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
|
|
22054
22224
|
const lines = entries.map(
|
|
22055
|
-
(name) => `${name}\0${sha256Hex(
|
|
22225
|
+
(name) => `${name}\0${sha256Hex(readFileSync15(join48(outputPath, name)))}`
|
|
22056
22226
|
);
|
|
22057
22227
|
return sha256Hex(lines.join("\0"));
|
|
22058
22228
|
}
|
|
@@ -22078,7 +22248,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22078
22248
|
`[renderChunk] planDir is missing required artifact: ${planJsonPath}`
|
|
22079
22249
|
);
|
|
22080
22250
|
}
|
|
22081
|
-
const plan2 = JSON.parse(
|
|
22251
|
+
const plan2 = JSON.parse(readFileSync15(planJsonPath, "utf-8"));
|
|
22082
22252
|
readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.chunk);
|
|
22083
22253
|
const planHashStarted = Date.now();
|
|
22084
22254
|
const v2Materialization = readValidatedPlanV2Materialization(planDir, {
|
|
@@ -22095,13 +22265,13 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22095
22265
|
);
|
|
22096
22266
|
}
|
|
22097
22267
|
}
|
|
22098
|
-
const encoder = JSON.parse(
|
|
22099
|
-
const chunks = JSON.parse(
|
|
22268
|
+
const encoder = JSON.parse(readFileSync15(encoderJsonPath, "utf-8"));
|
|
22269
|
+
const chunks = JSON.parse(readFileSync15(chunksJsonPath, "utf-8"));
|
|
22100
22270
|
const videosJsonPath = join48(planDir, PLAN_VIDEOS_META_RELATIVE_PATH);
|
|
22101
22271
|
let planVideos = null;
|
|
22102
22272
|
if (existsSync30(videosJsonPath)) {
|
|
22103
22273
|
try {
|
|
22104
|
-
planVideos = validatePlanVideosForChunk(JSON.parse(
|
|
22274
|
+
planVideos = validatePlanVideosForChunk(JSON.parse(readFileSync15(videosJsonPath, "utf-8")));
|
|
22105
22275
|
} catch (err) {
|
|
22106
22276
|
if (err instanceof RenderChunkValidationError) throw err;
|
|
22107
22277
|
throw new RenderChunkValidationError(
|
|
@@ -22187,9 +22357,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22187
22357
|
forceScreenshotExplicitlyOptedOut: !encoder.forceScreenshot
|
|
22188
22358
|
};
|
|
22189
22359
|
const workDir = `${outputChunkPath}.work.${process.pid}.${randomBytes(4).toString("hex")}`;
|
|
22190
|
-
|
|
22360
|
+
mkdirSync20(workDir, { recursive: true });
|
|
22191
22361
|
const framesDir = join48(workDir, "captured-frames");
|
|
22192
|
-
|
|
22362
|
+
mkdirSync20(framesDir, { recursive: true });
|
|
22193
22363
|
const videoFramesDir = `${workDir}.video-frames`;
|
|
22194
22364
|
const chunkFrameNumbers = Array.from({ length: framesInChunk }, (_, i) => range.startFrame + i);
|
|
22195
22365
|
const chunkFps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
@@ -22213,7 +22383,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22213
22383
|
dimensions: plan2.dimensions,
|
|
22214
22384
|
encoder,
|
|
22215
22385
|
videoCount: planVideos?.videos.length ?? 0,
|
|
22216
|
-
html:
|
|
22386
|
+
html: readFileSync15(join48(compiledDir, "index.html"), "utf-8"),
|
|
22217
22387
|
// The plan ships a deferred source only to chunks that show it; don't wait on the rest.
|
|
22218
22388
|
skipReadinessVideoIds: deferredVideos.filter(
|
|
22219
22389
|
(video) => !shownFrames.get(video.videoId)?.size || remoteVideoIds.has(video.videoId)
|
|
@@ -22247,8 +22417,8 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22247
22417
|
const verifyInWorker = chunkWorkerCount > 1 && !forceScreenshotForChunk;
|
|
22248
22418
|
let boxesMeasured;
|
|
22249
22419
|
let boxesFailed;
|
|
22250
|
-
const boxesReady = new Promise((
|
|
22251
|
-
boxesMeasured =
|
|
22420
|
+
const boxesReady = new Promise((resolve15, reject) => {
|
|
22421
|
+
boxesMeasured = resolve15;
|
|
22252
22422
|
boxesFailed = reject;
|
|
22253
22423
|
});
|
|
22254
22424
|
boxesReady.catch(() => {
|
|
@@ -22383,10 +22553,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22383
22553
|
const effectiveBitrate = encoder.crf != null ? void 0 : encoder.bitrate;
|
|
22384
22554
|
const videoOnlyPath = encoder.chunksCarryAudio ? `${outputChunkPath}.video.mp4` : outputChunkPath;
|
|
22385
22555
|
if (isPngSequence) {
|
|
22386
|
-
if (!existsSync30(outputChunkPath))
|
|
22556
|
+
if (!existsSync30(outputChunkPath)) mkdirSync20(outputChunkPath, { recursive: true });
|
|
22387
22557
|
} else {
|
|
22388
22558
|
const outDir = join48(outputChunkPath, "..");
|
|
22389
|
-
if (!existsSync30(outDir))
|
|
22559
|
+
if (!existsSync30(outDir)) mkdirSync20(outDir, { recursive: true });
|
|
22390
22560
|
}
|
|
22391
22561
|
const encodeInput = {
|
|
22392
22562
|
job,
|
|
@@ -22507,7 +22677,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22507
22677
|
resetForScreenshotRetry: () => {
|
|
22508
22678
|
rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
22509
22679
|
boxesMeasured();
|
|
22510
|
-
|
|
22680
|
+
mkdirSync20(framesDir, { recursive: true });
|
|
22511
22681
|
capturePerfs.length = 0;
|
|
22512
22682
|
captureAttempts.length = 0;
|
|
22513
22683
|
job.framesRendered = 0;
|
|
@@ -22599,7 +22769,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
22599
22769
|
producerVersion: plan2.producerVersion,
|
|
22600
22770
|
ffmpegVersion
|
|
22601
22771
|
};
|
|
22602
|
-
|
|
22772
|
+
writeFileSync13(perfPath, `${JSON.stringify(perfPayload, null, 2)}
|
|
22603
22773
|
`, "utf-8");
|
|
22604
22774
|
try {
|
|
22605
22775
|
rmSync18(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
|
|
@@ -22666,7 +22836,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22666
22836
|
try {
|
|
22667
22837
|
const planDir = join49(workDir, "plan");
|
|
22668
22838
|
const partsDir = join49(workDir, "parts");
|
|
22669
|
-
|
|
22839
|
+
mkdirSync21(partsDir, { recursive: true });
|
|
22670
22840
|
const planned = await plan(
|
|
22671
22841
|
projectDir,
|
|
22672
22842
|
{ ...config, rejectOnSystemFonts: false, failClosedFontFetch: false },
|
|
@@ -22684,7 +22854,7 @@ async function renderSpan(projectDir, config, span, outputPath, options = {}) {
|
|
|
22684
22854
|
planned.totalFrames
|
|
22685
22855
|
);
|
|
22686
22856
|
const slices = JSON.parse(
|
|
22687
|
-
|
|
22857
|
+
readFileSync16(join49(planDir, "meta", "chunks.json"), "utf-8")
|
|
22688
22858
|
);
|
|
22689
22859
|
const parts = [];
|
|
22690
22860
|
for (const slice of slices) {
|
|
@@ -23356,16 +23526,16 @@ import {
|
|
|
23356
23526
|
existsSync as existsSync33,
|
|
23357
23527
|
fstatSync as fstatSync5,
|
|
23358
23528
|
lstatSync as lstatSync6,
|
|
23359
|
-
mkdirSync as
|
|
23529
|
+
mkdirSync as mkdirSync22,
|
|
23360
23530
|
openSync as openSync9,
|
|
23361
23531
|
statSync as statSync14,
|
|
23362
23532
|
mkdtempSync as mkdtempSync2,
|
|
23363
|
-
writeFileSync as
|
|
23533
|
+
writeFileSync as writeFileSync14,
|
|
23364
23534
|
rmSync as rmSync20,
|
|
23365
23535
|
createReadStream as createReadStream6
|
|
23366
23536
|
} from "node:fs";
|
|
23367
23537
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
23368
|
-
import { basename as basename9, resolve as
|
|
23538
|
+
import { basename as basename9, resolve as resolve14, dirname as dirname23, join as join52 } from "node:path";
|
|
23369
23539
|
import { homedir, tmpdir as tmpdir6 } from "node:os";
|
|
23370
23540
|
import { parseArgs } from "node:util";
|
|
23371
23541
|
import { isIP } from "node:net";
|
|
@@ -23384,14 +23554,14 @@ import { foreignWritablePath } from "@hyperframes/core/cache-dir";
|
|
|
23384
23554
|
// src/services/hyperframeLint.ts
|
|
23385
23555
|
import {
|
|
23386
23556
|
existsSync as existsSync31,
|
|
23387
|
-
readFileSync as
|
|
23557
|
+
readFileSync as readFileSync17,
|
|
23388
23558
|
statSync as statSync13,
|
|
23389
23559
|
openSync as openSync8,
|
|
23390
23560
|
fstatSync as fstatSync4,
|
|
23391
23561
|
closeSync as closeSync8,
|
|
23392
23562
|
constants as constants4
|
|
23393
23563
|
} from "node:fs";
|
|
23394
|
-
import { resolve as
|
|
23564
|
+
import { resolve as resolve13, join as join50, relative as relative10, isAbsolute as isAbsolute7, sep as sep7, dirname as dirname21 } from "node:path";
|
|
23395
23565
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
23396
23566
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
23397
23567
|
function isStringRecord(value) {
|
|
@@ -23431,7 +23601,7 @@ function readEntryHtml(filePath) {
|
|
|
23431
23601
|
}
|
|
23432
23602
|
try {
|
|
23433
23603
|
if (!fstatSync4(fd).isFile()) return null;
|
|
23434
|
-
return
|
|
23604
|
+
return readFileSync17(fd, "utf-8");
|
|
23435
23605
|
} finally {
|
|
23436
23606
|
closeSync8(fd);
|
|
23437
23607
|
}
|
|
@@ -23441,7 +23611,7 @@ function leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry) {
|
|
|
23441
23611
|
return entryRelativePath === ".." || entryRelativePath.startsWith(`..${sep7}`) || isAbsolute7(entryRelativePath) || isAllowedEntry !== void 0 && !isAllowedEntry(absoluteEntryPath);
|
|
23442
23612
|
}
|
|
23443
23613
|
function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
23444
|
-
const absProjectDir =
|
|
23614
|
+
const absProjectDir = resolve13(projectDir);
|
|
23445
23615
|
if (!existsSync31(absProjectDir) || !statSync13(absProjectDir).isDirectory()) {
|
|
23446
23616
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
23447
23617
|
}
|
|
@@ -23449,7 +23619,7 @@ function readProjectEntryFile(projectDir, preferredEntryFile, isAllowedEntry) {
|
|
|
23449
23619
|
(value) => typeof value === "string" && value.trim().length > 0
|
|
23450
23620
|
);
|
|
23451
23621
|
for (const entryFile of entryCandidates) {
|
|
23452
|
-
const absoluteEntryPath =
|
|
23622
|
+
const absoluteEntryPath = resolve13(absProjectDir, entryFile);
|
|
23453
23623
|
if (leavesProject(absProjectDir, absoluteEntryPath, isAllowedEntry)) {
|
|
23454
23624
|
return { error: `Entry file must stay inside project directory: ${entryFile}` };
|
|
23455
23625
|
}
|
|
@@ -23509,16 +23679,16 @@ function takeLintSlot(limit, waitMs) {
|
|
|
23509
23679
|
running++;
|
|
23510
23680
|
return Promise.resolve(true);
|
|
23511
23681
|
}
|
|
23512
|
-
return new Promise((
|
|
23682
|
+
return new Promise((resolve15) => {
|
|
23513
23683
|
const entry = () => {
|
|
23514
23684
|
clearTimeout(timer);
|
|
23515
23685
|
running++;
|
|
23516
|
-
|
|
23686
|
+
resolve15(true);
|
|
23517
23687
|
};
|
|
23518
23688
|
const timer = setTimeout(
|
|
23519
23689
|
() => {
|
|
23520
23690
|
waiting.splice(waiting.indexOf(entry), 1);
|
|
23521
|
-
|
|
23691
|
+
resolve15(false);
|
|
23522
23692
|
},
|
|
23523
23693
|
Math.max(0, waitMs)
|
|
23524
23694
|
);
|
|
@@ -23530,7 +23700,7 @@ function freeLintSlot() {
|
|
|
23530
23700
|
waiting.shift()?.();
|
|
23531
23701
|
}
|
|
23532
23702
|
function resolveLintWorkerEntry() {
|
|
23533
|
-
const here =
|
|
23703
|
+
const here = dirname21(fileURLToPath7(import.meta.url));
|
|
23534
23704
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
23535
23705
|
const candidate = join50(here, name);
|
|
23536
23706
|
if (existsSync31(candidate)) return candidate;
|
|
@@ -23603,7 +23773,7 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
23603
23773
|
// src/services/healthWorker.ts
|
|
23604
23774
|
import { Worker as Worker4 } from "node:worker_threads";
|
|
23605
23775
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
23606
|
-
import { dirname as
|
|
23776
|
+
import { dirname as dirname22, join as join51 } from "node:path";
|
|
23607
23777
|
import { existsSync as existsSync32 } from "node:fs";
|
|
23608
23778
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
23609
23779
|
async function startHealthWorker(options = {}) {
|
|
@@ -23622,12 +23792,12 @@ async function startHealthWorker(options = {}) {
|
|
|
23622
23792
|
stdout: false,
|
|
23623
23793
|
stderr: false
|
|
23624
23794
|
});
|
|
23625
|
-
await new Promise((
|
|
23795
|
+
await new Promise((resolve15, reject) => {
|
|
23626
23796
|
const onMessage = (msg) => {
|
|
23627
23797
|
if (msg?.type === "listening") {
|
|
23628
23798
|
worker.off("error", onError);
|
|
23629
23799
|
worker.off("message", onMessage);
|
|
23630
|
-
|
|
23800
|
+
resolve15();
|
|
23631
23801
|
} else if (msg?.type === "listen-error") {
|
|
23632
23802
|
worker.off("error", onError);
|
|
23633
23803
|
worker.off("message", onMessage);
|
|
@@ -23678,7 +23848,7 @@ function defaultLogger2() {
|
|
|
23678
23848
|
};
|
|
23679
23849
|
}
|
|
23680
23850
|
function resolveWorkerEntry2() {
|
|
23681
|
-
const here =
|
|
23851
|
+
const here = dirname22(fileURLToPath8(import.meta.url));
|
|
23682
23852
|
const candidates = [join51(here, "healthWorkerThread.js"), join51(here, "healthWorkerThread.ts")];
|
|
23683
23853
|
for (const candidate of candidates) {
|
|
23684
23854
|
if (existsSync32(candidate)) return candidate;
|
|
@@ -23844,11 +24014,11 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
23844
24014
|
function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
23845
24015
|
const { input, cleanupProjectDir } = prepared;
|
|
23846
24016
|
const serverNamed = input.outputPath == null;
|
|
23847
|
-
const outputCandidate = input.outputPath ?? join52(rendersDir, `${basename9(
|
|
24017
|
+
const outputCandidate = input.outputPath ?? join52(rendersDir, `${basename9(resolve14(input.projectDir))}-${crypto.randomUUID()}.mp4`);
|
|
23848
24018
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, outputCandidate, rendersDir, log);
|
|
23849
|
-
const outputDir =
|
|
24019
|
+
const outputDir = dirname23(absoluteOutputPath);
|
|
23850
24020
|
if (confineOutput) {
|
|
23851
|
-
|
|
24021
|
+
mkdirSync22(rendersDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
23852
24022
|
if (!isSafePath4(rendersDir, absoluteOutputPath)) {
|
|
23853
24023
|
throw new Error("outputPath must be inside the renders directory");
|
|
23854
24024
|
}
|
|
@@ -23859,14 +24029,14 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
23859
24029
|
);
|
|
23860
24030
|
}
|
|
23861
24031
|
}
|
|
23862
|
-
if (!existsSync33(outputDir))
|
|
24032
|
+
if (!existsSync33(outputDir)) mkdirSync22(outputDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
23863
24033
|
return { input, cleanupProjectDir, absoluteOutputPath, serverNamed };
|
|
23864
24034
|
}
|
|
23865
24035
|
var STICKY_BIT = 512;
|
|
23866
24036
|
var SERVER_FOLDER_MODE = 493;
|
|
23867
24037
|
function folderAnotherAccountCanChange(dir, rendersDir) {
|
|
23868
24038
|
const foreign = foreignWritablePath(dir, rendersDir);
|
|
23869
|
-
const stickyRoot = foreign ===
|
|
24039
|
+
const stickyRoot = foreign === resolve14(rendersDir) && (lstatSync6(foreign).mode & STICKY_BIT) !== 0;
|
|
23870
24040
|
return stickyRoot ? void 0 : foreign;
|
|
23871
24041
|
}
|
|
23872
24042
|
function prepareRenderJob(prepared, rendersDir, log, confineOutput) {
|
|
@@ -23927,7 +24097,7 @@ function validateOutputResolutionOverride(body) {
|
|
|
23927
24097
|
var MAX_PREVIEW_HTML_BYTES = 20 * 1024 * 1024;
|
|
23928
24098
|
function resolveRenderRequestPolicy(options) {
|
|
23929
24099
|
return {
|
|
23930
|
-
projectsDir:
|
|
24100
|
+
projectsDir: resolve14(
|
|
23931
24101
|
options.projectsDir ?? (process.env.PRODUCER_PROJECTS_DIR || process.cwd())
|
|
23932
24102
|
),
|
|
23933
24103
|
allowDebug: options.allowDebug ?? process.env.PRODUCER_ALLOW_DEBUG === "1"
|
|
@@ -23942,13 +24112,13 @@ function isAllowedEntryPath(policy, projectDir, path) {
|
|
|
23942
24112
|
function prepareProjectDirectory(projectDir, options, policy) {
|
|
23943
24113
|
const candidate = nonEmptyString(projectDir);
|
|
23944
24114
|
if (!candidate) return null;
|
|
23945
|
-
const absProjectDir = policy ?
|
|
24115
|
+
const absProjectDir = policy ? resolve14(policy.projectsDir, candidate) : resolve14(candidate);
|
|
23946
24116
|
const shown = policy ? candidate : absProjectDir;
|
|
23947
24117
|
if (policy && !isAllowedProjectPath(policy.projectsDir, absProjectDir) || !existsSync33(absProjectDir) || !statSync14(absProjectDir).isDirectory()) {
|
|
23948
24118
|
return { error: `Project directory not found: ${shown}` };
|
|
23949
24119
|
}
|
|
23950
24120
|
const entry = options.entryFile || "index.html";
|
|
23951
|
-
const entryPath =
|
|
24121
|
+
const entryPath = resolve14(absProjectDir, entry);
|
|
23952
24122
|
if (policy && !isAllowedEntryPath(policy, absProjectDir, entryPath) || !existsSync33(entryPath)) {
|
|
23953
24123
|
return { error: `Entry file "${entry}" not found in project directory: ${shown}` };
|
|
23954
24124
|
}
|
|
@@ -23971,7 +24141,7 @@ async function resolveInlineRenderHtml(body) {
|
|
|
23971
24141
|
function materializeInlineProject(html, options) {
|
|
23972
24142
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir6();
|
|
23973
24143
|
const tempProjectDir = mkdtempSync2(join52(tempRoot, "producer-project-"));
|
|
23974
|
-
|
|
24144
|
+
writeFileSync14(join52(tempProjectDir, "index.html"), html, "utf-8");
|
|
23975
24145
|
return {
|
|
23976
24146
|
prepared: {
|
|
23977
24147
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -23999,7 +24169,7 @@ function resolveOutputPath(projectDir, outputCandidate, rendersDir, log) {
|
|
|
23999
24169
|
try {
|
|
24000
24170
|
return resolveRenderPaths(projectDir, outputCandidate, rendersDir).absoluteOutputPath;
|
|
24001
24171
|
} catch (error) {
|
|
24002
|
-
const fallbackPath =
|
|
24172
|
+
const fallbackPath = resolve14(rendersDir, `producer-fallback-${Date.now()}.mp4`);
|
|
24003
24173
|
log.warn("Failed to resolve output path, using fallback", {
|
|
24004
24174
|
fallback: fallbackPath,
|
|
24005
24175
|
error: error instanceof Error ? error.message : String(error)
|
|
@@ -24206,7 +24376,7 @@ function createRenderHandlers(options = {}) {
|
|
|
24206
24376
|
const lintProjectDir = nonEmptyString(body.projectDir);
|
|
24207
24377
|
let isAllowedEntry;
|
|
24208
24378
|
if (policy && lintProjectDir) {
|
|
24209
|
-
const absProjectDir =
|
|
24379
|
+
const absProjectDir = resolve14(policy.projectsDir, lintProjectDir);
|
|
24210
24380
|
if (!isAllowedProjectPath(policy.projectsDir, absProjectDir)) {
|
|
24211
24381
|
const error = `Project directory not found: ${lintProjectDir}`;
|
|
24212
24382
|
return c.json({ success: false, requestId, error }, 400);
|
|
@@ -24560,13 +24730,13 @@ function serverAuth(options, hostname2, port) {
|
|
|
24560
24730
|
`Refusing to listen on ${hostname2} without an auth token. Set authToken or PRODUCER_AUTH_TOKEN, or listen on a loopback address.`
|
|
24561
24731
|
);
|
|
24562
24732
|
}
|
|
24563
|
-
const file =
|
|
24733
|
+
const file = resolve14(
|
|
24564
24734
|
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join52(homedir(), ".hyperframes", "producer", `${port}.token`)
|
|
24565
24735
|
);
|
|
24566
24736
|
const token = crypto.randomBytes(32).toString("base64url");
|
|
24567
|
-
|
|
24737
|
+
mkdirSync22(dirname23(file), { recursive: true, mode: 448 });
|
|
24568
24738
|
rmSync20(file, { force: true });
|
|
24569
|
-
|
|
24739
|
+
writeFileSync14(file, `${token}
|
|
24570
24740
|
`, { flag: "wx", mode: 384 });
|
|
24571
24741
|
return { token, generatedFile: file };
|
|
24572
24742
|
}
|
|
@@ -24620,7 +24790,7 @@ function startServer(options = {}) {
|
|
|
24620
24790
|
process.on("SIGINT", () => shutdown("SIGINT"));
|
|
24621
24791
|
return server;
|
|
24622
24792
|
}
|
|
24623
|
-
var entryScript = process.argv[1] ?
|
|
24793
|
+
var entryScript = process.argv[1] ? resolve14(process.argv[1]) : "";
|
|
24624
24794
|
var isPublicServerEntry = entryScript.endsWith("/public-server.js") || entryScript.endsWith("/src/server.ts");
|
|
24625
24795
|
if (isPublicServerEntry) {
|
|
24626
24796
|
const { values } = parseArgs({
|
|
@@ -24656,14 +24826,14 @@ import {
|
|
|
24656
24826
|
import {
|
|
24657
24827
|
cpSync as cpSync3,
|
|
24658
24828
|
existsSync as existsSync34,
|
|
24659
|
-
mkdirSync as
|
|
24660
|
-
readFileSync as
|
|
24829
|
+
mkdirSync as mkdirSync23,
|
|
24830
|
+
readFileSync as readFileSync18,
|
|
24661
24831
|
readdirSync as readdirSync12,
|
|
24662
24832
|
rmSync as rmSync21,
|
|
24663
24833
|
statSync as statSync15
|
|
24664
24834
|
} from "node:fs";
|
|
24665
24835
|
import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
|
|
24666
|
-
import { basename as basename10, dirname as
|
|
24836
|
+
import { basename as basename10, dirname as dirname24, join as join53 } from "node:path";
|
|
24667
24837
|
import {
|
|
24668
24838
|
appendRateCapArgs as appendRateCapArgs2,
|
|
24669
24839
|
writeVideoConcatList,
|
|
@@ -24712,10 +24882,10 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
|
|
|
24712
24882
|
}
|
|
24713
24883
|
const format = plan2.dimensions.format;
|
|
24714
24884
|
const cfrEncoder = cfr ? readCfrEncoder(planDir, format) : null;
|
|
24715
|
-
if (!existsSync34(
|
|
24716
|
-
|
|
24885
|
+
if (!existsSync34(dirname24(outputPath))) {
|
|
24886
|
+
mkdirSync23(dirname24(outputPath), { recursive: true });
|
|
24717
24887
|
}
|
|
24718
|
-
const workDir = createStagingDir7(
|
|
24888
|
+
const workDir = createStagingDir7(dirname24(outputPath), `${basename10(outputPath)}.assemble-work-`);
|
|
24719
24889
|
const fps = { num: plan2.dimensions.fpsNum, den: plan2.dimensions.fpsDen };
|
|
24720
24890
|
const stageMs = {};
|
|
24721
24891
|
const ctx = {
|
|
@@ -24769,13 +24939,13 @@ function readAssemblePlan(planDir, chunkPaths) {
|
|
|
24769
24939
|
if (!existsSync34(planJsonPath)) {
|
|
24770
24940
|
throw new Error(`[assemble] planDir missing plan.json: ${planJsonPath}`);
|
|
24771
24941
|
}
|
|
24772
|
-
const plan2 = JSON.parse(
|
|
24942
|
+
const plan2 = JSON.parse(readFileSync18(planJsonPath, "utf-8"));
|
|
24773
24943
|
readPlanProtocolV1(plan2, DISTRIBUTED_RENDER_CAPABILITIES.roles.assembler);
|
|
24774
24944
|
validatePlanV2MaterializedTarget(planDir, { role: "assembler" });
|
|
24775
24945
|
if (!existsSync34(chunksJsonPath)) {
|
|
24776
24946
|
throw new Error(`[assemble] planDir missing meta/chunks.json: ${chunksJsonPath}`);
|
|
24777
24947
|
}
|
|
24778
|
-
const chunks = JSON.parse(
|
|
24948
|
+
const chunks = JSON.parse(readFileSync18(chunksJsonPath, "utf-8"));
|
|
24779
24949
|
if (chunkPaths.length !== chunks.length) {
|
|
24780
24950
|
throw new Error(
|
|
24781
24951
|
`[assemble] chunkPaths length (${chunkPaths.length}) does not match chunks.json length (${chunks.length}). Adapters must pass one path per chunk, ordered by index.`
|
|
@@ -24922,13 +25092,13 @@ function stitchesSeparateAudio(planDir) {
|
|
|
24922
25092
|
return lockedAudio(planDir).separateAudio === true;
|
|
24923
25093
|
}
|
|
24924
25094
|
function planFormat(planDir) {
|
|
24925
|
-
const plan2 = JSON.parse(
|
|
25095
|
+
const plan2 = JSON.parse(readFileSync18(join53(planDir, "plan.json"), "utf-8"));
|
|
24926
25096
|
return plan2.dimensions.format;
|
|
24927
25097
|
}
|
|
24928
25098
|
function lockedAudio(planDir) {
|
|
24929
25099
|
const encoderJsonPath = join53(planDir, "meta", "encoder.json");
|
|
24930
25100
|
if (!existsSync34(encoderJsonPath)) return {};
|
|
24931
|
-
return JSON.parse(
|
|
25101
|
+
return JSON.parse(readFileSync18(encoderJsonPath, "utf-8"));
|
|
24932
25102
|
}
|
|
24933
25103
|
function readCfrEncoder(planDir, format) {
|
|
24934
25104
|
if (format !== "mp4") {
|
|
@@ -24940,7 +25110,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
24940
25110
|
if (!existsSync34(encoderJsonPath)) {
|
|
24941
25111
|
throw new Error(`[assemble] planDir missing meta/encoder.json: ${encoderJsonPath}`);
|
|
24942
25112
|
}
|
|
24943
|
-
const encoderJson = JSON.parse(
|
|
25113
|
+
const encoderJson = JSON.parse(readFileSync18(encoderJsonPath, "utf-8"));
|
|
24944
25114
|
if (encoderJson.encoder === "libx265-software") {
|
|
24945
25115
|
throw new Error(
|
|
24946
25116
|
`[assemble] cfr=true is not yet supported with codec: "h265". The cfr re-encode pass uses libx264 and would silently transcode the h265 chunks. Either disable cfr or render with codec: "h264".`
|
|
@@ -24950,7 +25120,7 @@ function readCfrEncoder(planDir, format) {
|
|
|
24950
25120
|
}
|
|
24951
25121
|
function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, startTimeMs) {
|
|
24952
25122
|
if (existsSync34(outputPath)) rmSync21(outputPath, { recursive: true, force: true });
|
|
24953
|
-
|
|
25123
|
+
mkdirSync23(outputPath, { recursive: true });
|
|
24954
25124
|
let globalIdx = 0;
|
|
24955
25125
|
for (const chunkDir of chunkPaths) {
|
|
24956
25126
|
if (!statSync15(chunkDir).isDirectory()) {
|
|
@@ -25025,7 +25195,7 @@ async function assembleV2(planV2Dir, chunkPaths, outputPath, options) {
|
|
|
25025
25195
|
}
|
|
25026
25196
|
|
|
25027
25197
|
// src/services/distributed/projectHash.ts
|
|
25028
|
-
import { isPrivateFileUnder as
|
|
25198
|
+
import { isPrivateFileUnder as isPrivateFileUnder4, isStudioPrivatePath as isStudioPrivatePath4 } from "@hyperframes/core/safe-path";
|
|
25029
25199
|
var READ_CHUNK_BYTES = 256 * 1024;
|
|
25030
25200
|
|
|
25031
25201
|
// src/services/distributed/audioSidecar.ts
|