@hyperframes/producer 0.9.92 → 0.9.94
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 +18 -11
- package/dist/distributed.js +41 -27
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/index.js +435 -234
- package/dist/public-server.js +347 -146
- package/dist/services/render/captureCost.d.ts +8 -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/public-server.js
CHANGED
|
@@ -23,16 +23,16 @@ import {
|
|
|
23
23
|
existsSync as existsSync26,
|
|
24
24
|
fstatSync as fstatSync5,
|
|
25
25
|
lstatSync as lstatSync4,
|
|
26
|
-
mkdirSync as
|
|
26
|
+
mkdirSync as mkdirSync14,
|
|
27
27
|
openSync as openSync7,
|
|
28
28
|
statSync as statSync12,
|
|
29
29
|
mkdtempSync,
|
|
30
|
-
writeFileSync as
|
|
30
|
+
writeFileSync as writeFileSync8,
|
|
31
31
|
rmSync as rmSync14,
|
|
32
32
|
createReadStream as createReadStream4
|
|
33
33
|
} from "node:fs";
|
|
34
34
|
import { AsyncLocalStorage } from "node:async_hooks";
|
|
35
|
-
import { basename as basename8, resolve as resolve11, dirname as
|
|
35
|
+
import { basename as basename8, resolve as resolve11, dirname as dirname20, join as join40 } from "node:path";
|
|
36
36
|
import { homedir, tmpdir as tmpdir4 } from "node:os";
|
|
37
37
|
import { parseArgs } from "node:util";
|
|
38
38
|
import { isIP } from "node:net";
|
|
@@ -52,11 +52,11 @@ import { foreignWritablePath } from "@hyperframes/core/cache-dir";
|
|
|
52
52
|
import { audioFailureDiagnostics as audioFailureDiagnostics2, cpuBudget } from "@hyperframes/engine";
|
|
53
53
|
import {
|
|
54
54
|
existsSync as existsSync22,
|
|
55
|
-
mkdirSync as
|
|
55
|
+
mkdirSync as mkdirSync13,
|
|
56
56
|
readdirSync as readdirSync6,
|
|
57
57
|
rmSync as rmSync13,
|
|
58
58
|
statSync as statSync10,
|
|
59
|
-
writeFileSync as
|
|
59
|
+
writeFileSync as writeFileSync7,
|
|
60
60
|
copyFileSync as copyFileSync5,
|
|
61
61
|
appendFileSync
|
|
62
62
|
} from "fs";
|
|
@@ -381,6 +381,7 @@ import {
|
|
|
381
381
|
LOW_MEMORY_TOTAL_MB_THRESHOLD,
|
|
382
382
|
assertConfiguredFfmpegBinariesExist,
|
|
383
383
|
resolveBrowserGpuMode,
|
|
384
|
+
probedHardwareGpu,
|
|
384
385
|
resolveHeadlessShellPath,
|
|
385
386
|
compositionRequiresWebGpu as compositionRequiresWebGpu2,
|
|
386
387
|
applyConcreteGpuScreenshotClamp,
|
|
@@ -402,7 +403,7 @@ import {
|
|
|
402
403
|
referenceBackgroundResult,
|
|
403
404
|
createReferenceBackgroundRecorder
|
|
404
405
|
} from "@hyperframes/engine";
|
|
405
|
-
import { join as join35, dirname as
|
|
406
|
+
import { join as join35, dirname as dirname16, resolve as resolve9 } from "path";
|
|
406
407
|
import { totalmem as totalmem2 } from "node:os";
|
|
407
408
|
import { randomUUID as randomUUID3 } from "crypto";
|
|
408
409
|
import { fileURLToPath as fileURLToPath5 } from "url";
|
|
@@ -432,7 +433,7 @@ import {
|
|
|
432
433
|
serviceWorkerScriptFetch
|
|
433
434
|
} from "@hyperframes/core/studio-preview-mark";
|
|
434
435
|
import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
|
|
435
|
-
import { isPrivateFileUnder, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
|
436
|
+
import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
|
|
436
437
|
import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
|
|
437
438
|
import { openRangeEnd } from "@hyperframes/studio-server/media-range";
|
|
438
439
|
|
|
@@ -574,7 +575,7 @@ import {
|
|
|
574
575
|
} from "node:path";
|
|
575
576
|
import { statSync } from "node:fs";
|
|
576
577
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
577
|
-
import { isSafePath } from "@hyperframes/core/safe-path";
|
|
578
|
+
import { isPrivateFileUnder, isSafePath, isStudioPrivatePath } from "@hyperframes/core/safe-path";
|
|
578
579
|
import {
|
|
579
580
|
isCopiedOutsideFileType,
|
|
580
581
|
isPrivateOutsideFile,
|
|
@@ -601,7 +602,10 @@ function escapesAssetRoot(path, assetRoot) {
|
|
|
601
602
|
return assetRoot !== void 0 && !isSafePath(assetRoot, path);
|
|
602
603
|
}
|
|
603
604
|
function outsideAssetRefusal(projectDir, path, policy = {}) {
|
|
604
|
-
if (!linksOutside(projectDir, path))
|
|
605
|
+
if (!linksOutside(projectDir, path)) {
|
|
606
|
+
const privateByAnotherSpelling = !isPathInside(path, projectDir) && isPrivateFileUnder(projectDir, path, isStudioPrivatePath);
|
|
607
|
+
return privateByAnotherSpelling ? "blocklisted" : null;
|
|
608
|
+
}
|
|
605
609
|
if (isPrivateOutsideFile(projectDir, path)) return "blocklisted";
|
|
606
610
|
const folder = statSync(path, { throwIfNoEntry: false })?.isDirectory();
|
|
607
611
|
if (folder || isUploadedOutsideFileType(path)) return null;
|
|
@@ -1227,7 +1231,7 @@ function createFileServer(options) {
|
|
|
1227
1231
|
const candidate = join2(root, relativePath);
|
|
1228
1232
|
const resolveSymlinks = !allowOutsideProjectAssets && root !== compiledDir;
|
|
1229
1233
|
if (!isPathInside2(candidate, root, { resolveSymlinks })) continue;
|
|
1230
|
-
if (
|
|
1234
|
+
if (isPrivateFileUnder2(root, candidate, isStudioPrivatePath2)) continue;
|
|
1231
1235
|
const checksLinks = allowOutsideProjectAssets && root !== compiledDir;
|
|
1232
1236
|
if (checksLinks && refusesOutsideLink(root, candidate, warnLeftOut, outsidePolicy)) continue;
|
|
1233
1237
|
file = openRegularFile(candidate);
|
|
@@ -4167,12 +4171,12 @@ function distributeLayeredHybridFrameRanges(totalFrames, workerCount) {
|
|
|
4167
4171
|
}
|
|
4168
4172
|
return ranges;
|
|
4169
4173
|
}
|
|
4170
|
-
function partitionTransitionFrames(transitionRanges, totalFrames) {
|
|
4174
|
+
function partitionTransitionFrames(transitionRanges, totalFrames, firstFrame = 0) {
|
|
4171
4175
|
const frames = /* @__PURE__ */ new Set();
|
|
4172
4176
|
if (totalFrames <= 0) return frames;
|
|
4173
4177
|
for (const range of transitionRanges) {
|
|
4174
|
-
const start = Math.max(
|
|
4175
|
-
const end = Math.min(totalFrames - 1, range.endFrame);
|
|
4178
|
+
const start = Math.max(firstFrame, range.startFrame);
|
|
4179
|
+
const end = Math.min(firstFrame + totalFrames - 1, range.endFrame);
|
|
4176
4180
|
for (let i = start; i <= end; i++) frames.add(i);
|
|
4177
4181
|
}
|
|
4178
4182
|
return frames;
|
|
@@ -4382,6 +4386,18 @@ function cleanupEndedHdrVideos(args) {
|
|
|
4382
4386
|
}
|
|
4383
4387
|
}
|
|
4384
4388
|
}
|
|
4389
|
+
function transitionAtFrame(transitionRanges, frame) {
|
|
4390
|
+
return transitionRanges.find((t) => frame >= t.startFrame && frame <= t.endFrame);
|
|
4391
|
+
}
|
|
4392
|
+
function cleanupHdrVideosEndedBefore(firstFrame, fps, transitionRanges, state) {
|
|
4393
|
+
for (let frame = 0; frame < firstFrame; frame++) {
|
|
4394
|
+
cleanupEndedHdrVideos({
|
|
4395
|
+
...state,
|
|
4396
|
+
time: frame * fps.den / fps.num,
|
|
4397
|
+
activeTransition: transitionAtFrame(transitionRanges, frame)
|
|
4398
|
+
});
|
|
4399
|
+
}
|
|
4400
|
+
}
|
|
4385
4401
|
|
|
4386
4402
|
// src/services/render/segmentPlan.ts
|
|
4387
4403
|
import { join as join9 } from "node:path";
|
|
@@ -6036,6 +6052,18 @@ function estimateMeasuredCaptureCostMultiplier(samples) {
|
|
|
6036
6052
|
medianMs
|
|
6037
6053
|
};
|
|
6038
6054
|
}
|
|
6055
|
+
function shouldCalibrateSoftwareGpu(requestedMode, resolvedMode, hardware) {
|
|
6056
|
+
return requestedMode === "auto" && resolvedMode === "hardware" && hardware !== void 0 && hardware.multiplier > 1 && hardware.p95Ms !== void 0;
|
|
6057
|
+
}
|
|
6058
|
+
function settleAutoGpuChoice(hardware, software) {
|
|
6059
|
+
if (hardware?.p95Ms === void 0) return void 0;
|
|
6060
|
+
if (hardware.multiplier <= 1) return "hardware";
|
|
6061
|
+
if (software?.p95Ms === void 0) return void 0;
|
|
6062
|
+
return software.p95Ms < hardware.p95Ms ? "software" : "hardware";
|
|
6063
|
+
}
|
|
6064
|
+
function pickAutoGpuModeFromCalibration(hardware, software) {
|
|
6065
|
+
return settleAutoGpuChoice(hardware, software) ?? "hardware";
|
|
6066
|
+
}
|
|
6039
6067
|
function selectCaptureCalibrationFrames(totalFrames) {
|
|
6040
6068
|
if (totalFrames <= 0) return [];
|
|
6041
6069
|
const lastFrame = totalFrames - 1;
|
|
@@ -6050,8 +6078,8 @@ function selectCaptureCalibrationFrames(totalFrames) {
|
|
|
6050
6078
|
new Set(candidates.map((frame) => Math.max(0, Math.min(lastFrame, frame))))
|
|
6051
6079
|
).sort((a, b) => a - b);
|
|
6052
6080
|
}
|
|
6053
|
-
async function measureCaptureCostFromSession(session, totalFrames, fps, log) {
|
|
6054
|
-
const sampledFrames = selectCaptureCalibrationFrames(totalFrames);
|
|
6081
|
+
async function measureCaptureCostFromSession(session, totalFrames, fps, log, firstFrame = 0) {
|
|
6082
|
+
const sampledFrames = selectCaptureCalibrationFrames(totalFrames).map((i) => firstFrame + i);
|
|
6055
6083
|
const samples = [];
|
|
6056
6084
|
const totalSamples = sampledFrames.length;
|
|
6057
6085
|
const savedStaticFrames = session.staticFrames;
|
|
@@ -6147,7 +6175,13 @@ async function runCaptureCalibration(input) {
|
|
|
6147
6175
|
}
|
|
6148
6176
|
assertNotAborted();
|
|
6149
6177
|
log.info("Calibration session ready, capturing test frames...");
|
|
6150
|
-
const result = await measureCaptureCostFromSession(
|
|
6178
|
+
const result = await measureCaptureCostFromSession(
|
|
6179
|
+
session,
|
|
6180
|
+
totalFrames,
|
|
6181
|
+
fps,
|
|
6182
|
+
log,
|
|
6183
|
+
job.frameWindow?.startFrame
|
|
6184
|
+
);
|
|
6151
6185
|
logCaptureCalibrationResult(result, log);
|
|
6152
6186
|
return result;
|
|
6153
6187
|
};
|
|
@@ -6708,6 +6742,57 @@ function resolveVideoCaptureBeyondViewport(videoCount) {
|
|
|
6708
6742
|
return true;
|
|
6709
6743
|
}
|
|
6710
6744
|
|
|
6745
|
+
// src/services/render/gpuChoice.ts
|
|
6746
|
+
import { mkdirSync as mkdirSync7, readFileSync as readFileSync5, renameSync, writeFileSync as writeFileSync3 } from "node:fs";
|
|
6747
|
+
import { dirname as dirname6 } from "node:path";
|
|
6748
|
+
function gpuChoiceStore(cfg, gpu) {
|
|
6749
|
+
if (!cfg.gpuChoiceFile || !cfg.hyperframesVersion || !gpu) return void 0;
|
|
6750
|
+
return { file: cfg.gpuChoiceFile, key: `${cfg.hyperframesVersion} | ${gpu}` };
|
|
6751
|
+
}
|
|
6752
|
+
function readGpuChoice(store) {
|
|
6753
|
+
let record;
|
|
6754
|
+
try {
|
|
6755
|
+
record = JSON.parse(readFileSync5(store.file, "utf8"));
|
|
6756
|
+
} catch {
|
|
6757
|
+
return void 0;
|
|
6758
|
+
}
|
|
6759
|
+
if (record?.key !== store.key) return void 0;
|
|
6760
|
+
return record.mode === "software" || record.mode === "hardware" ? record.mode : void 0;
|
|
6761
|
+
}
|
|
6762
|
+
function writeGpuChoice(store, mode, measured) {
|
|
6763
|
+
mkdirSync7(dirname6(store.file), { recursive: true });
|
|
6764
|
+
const temp = `${store.file}.${process.pid}.tmp`;
|
|
6765
|
+
const record = { key: store.key, mode, ...measured, measuredAt: (/* @__PURE__ */ new Date()).toISOString() };
|
|
6766
|
+
writeFileSync3(temp, `${JSON.stringify(record, null, 2)}
|
|
6767
|
+
`);
|
|
6768
|
+
renameSync(temp, store.file);
|
|
6769
|
+
}
|
|
6770
|
+
|
|
6771
|
+
// src/services/render/frameWindow.ts
|
|
6772
|
+
function resolveFrameWindow(range, fps, filmFrames) {
|
|
6773
|
+
const frameAt = (seconds) => Math.round(seconds * fps.num / fps.den);
|
|
6774
|
+
const startFrame = frameAt(range.startSeconds);
|
|
6775
|
+
const endFrame = Math.min(
|
|
6776
|
+
range.endSeconds === void 0 ? filmFrames : frameAt(range.endSeconds),
|
|
6777
|
+
filmFrames
|
|
6778
|
+
);
|
|
6779
|
+
if (!(endFrame > startFrame)) {
|
|
6780
|
+
throw new Error(
|
|
6781
|
+
`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.`
|
|
6782
|
+
);
|
|
6783
|
+
}
|
|
6784
|
+
return { startFrame, endFrame };
|
|
6785
|
+
}
|
|
6786
|
+
function windowStartFrame(frameWindow) {
|
|
6787
|
+
return frameWindow?.startFrame ?? 0;
|
|
6788
|
+
}
|
|
6789
|
+
function assertRangeSupported(frameWindow, route) {
|
|
6790
|
+
if (!frameWindow || route === "sdr_disk" || route === "hdr_layered") return;
|
|
6791
|
+
throw new Error(
|
|
6792
|
+
`This composition renders on the "${route}" capture route, which renders the whole film only; render it without a start or end.`
|
|
6793
|
+
);
|
|
6794
|
+
}
|
|
6795
|
+
|
|
6711
6796
|
// src/services/render/observability.ts
|
|
6712
6797
|
import { createHash as createHash3 } from "node:crypto";
|
|
6713
6798
|
import { redactTelemetryString } from "@hyperframes/core";
|
|
@@ -7079,7 +7164,7 @@ function emitFallbackCaptureProfile(recorder, perfSummaries, env = process.env)
|
|
|
7079
7164
|
}
|
|
7080
7165
|
|
|
7081
7166
|
// src/services/render/videoFrameCoverage.ts
|
|
7082
|
-
import { parseHTML } from "linkedom";
|
|
7167
|
+
import { parseHTML } from "@hyperframes/parsers/linkedom";
|
|
7083
7168
|
import {
|
|
7084
7169
|
fpsToNumber as fpsToNumber5,
|
|
7085
7170
|
normalizeRateSpec,
|
|
@@ -7094,7 +7179,6 @@ var SHORT_CLIP_ONE_FRAME_TOLERANCE_MIN_EXPECTED_FRAMES = 14;
|
|
|
7094
7179
|
var SHORT_CLIP_ONE_FRAME_TOLERANCE_MAX_EXPECTED_FRAMES = 20;
|
|
7095
7180
|
var VideoFrameCoverageError = class extends Error {
|
|
7096
7181
|
// Read structurally by isVideoFrameCoverageError and cross-module callers.
|
|
7097
|
-
// fallow-ignore-next-line unused-class-member
|
|
7098
7182
|
hyperframesVideoFrameCoverageError = true;
|
|
7099
7183
|
threshold;
|
|
7100
7184
|
worst;
|
|
@@ -7181,7 +7265,7 @@ function countAuthoredTimedClips(html) {
|
|
|
7181
7265
|
}
|
|
7182
7266
|
|
|
7183
7267
|
// src/services/render/stages/compileStage.ts
|
|
7184
|
-
import { existsSync as existsSync13, writeFileSync as
|
|
7268
|
+
import { existsSync as existsSync13, writeFileSync as writeFileSync5 } from "node:fs";
|
|
7185
7269
|
import { join as join23, relative as relative5 } from "node:path";
|
|
7186
7270
|
import { privateCacheRoot } from "@hyperframes/engine";
|
|
7187
7271
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
@@ -7191,7 +7275,7 @@ import { assertCompositionFileSize as assertCompositionFileSize2 } from "@hyperf
|
|
|
7191
7275
|
|
|
7192
7276
|
// src/services/compileInWorker.ts
|
|
7193
7277
|
import { existsSync as existsSync12, rmSync as rmSync11 } from "node:fs";
|
|
7194
|
-
import { dirname as
|
|
7278
|
+
import { dirname as dirname11, isAbsolute as isAbsolute4, join as join22, relative as relative4, resolve as resolvePath } from "node:path";
|
|
7195
7279
|
import { fileURLToPath as fileURLToPath3 } from "node:url";
|
|
7196
7280
|
import { Worker } from "node:worker_threads";
|
|
7197
7281
|
|
|
@@ -7211,17 +7295,17 @@ import {
|
|
|
7211
7295
|
stylesheetLinkMatches
|
|
7212
7296
|
} from "@hyperframes/parsers/css-url-scans";
|
|
7213
7297
|
import { createHash as createHash6 } from "node:crypto";
|
|
7214
|
-
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as
|
|
7215
|
-
import { join as join21, dirname as
|
|
7216
|
-
import { parseHTML as parseHTML5 } from "linkedom";
|
|
7298
|
+
import { createReadStream as createReadStream3, existsSync as existsSync11, mkdirSync as mkdirSync10, readFileSync as readFileSync9, statSync as statSync8 } from "fs";
|
|
7299
|
+
import { join as join21, dirname as dirname10, resolve as resolve8, basename as basename6, relative as relative3, sep as sep4 } from "path";
|
|
7300
|
+
import { parseHTML as parseHTML5 } from "@hyperframes/parsers/linkedom";
|
|
7217
7301
|
|
|
7218
7302
|
// src/services/bundledScripts.ts
|
|
7219
|
-
import { existsSync as existsSync8, readFileSync as
|
|
7303
|
+
import { existsSync as existsSync8, readFileSync as readFileSync6 } from "node:fs";
|
|
7220
7304
|
import { join as join17 } from "node:path";
|
|
7221
7305
|
import { GSAP_CDN_VERSION } from "@hyperframes/core/gsap-cdn";
|
|
7222
7306
|
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
7223
7307
|
var DEFAULT_CDN_GSAP_3 = /^https:\/\/cdn\.jsdelivr\.net\/npm\/gsap@(3\.\d+\.\d+)\/dist\/([A-Za-z]+\.min\.js)$/;
|
|
7224
|
-
var read = (file) => existsSync8(file) ?
|
|
7308
|
+
var read = (file) => existsSync8(file) ? readFileSync6(file) : null;
|
|
7225
7309
|
function bundledScript(url) {
|
|
7226
7310
|
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
7227
7311
|
const [, version, file] = DEFAULT_CDN_GSAP_3.exec(url) ?? [];
|
|
@@ -7295,7 +7379,7 @@ import {
|
|
|
7295
7379
|
readTextFile,
|
|
7296
7380
|
resolveCompositionSrc
|
|
7297
7381
|
} from "@hyperframes/parsers/asset-resolution";
|
|
7298
|
-
import { isPrivateFileUnder as
|
|
7382
|
+
import { isPrivateFileUnder as isPrivateFileUnder3, isStudioPrivatePath as isStudioPrivatePath3 } from "@hyperframes/core/safe-path";
|
|
7299
7383
|
import { linksOutside as linksOutside2 } from "@hyperframes/studio-server/outside-file";
|
|
7300
7384
|
import {
|
|
7301
7385
|
assertCompositionFileSize,
|
|
@@ -7306,7 +7390,7 @@ import {
|
|
|
7306
7390
|
} from "@hyperframes/core/compiler";
|
|
7307
7391
|
|
|
7308
7392
|
// src/services/renderMediaCollector.ts
|
|
7309
|
-
import { parseHTML as parseHTML2 } from "linkedom";
|
|
7393
|
+
import { parseHTML as parseHTML2 } from "@hyperframes/parsers/linkedom";
|
|
7310
7394
|
import {
|
|
7311
7395
|
MEDIA_RENDER_ID_ATTR,
|
|
7312
7396
|
normalizeRateSpec as normalizeRateSpec2,
|
|
@@ -7498,9 +7582,9 @@ import {
|
|
|
7498
7582
|
|
|
7499
7583
|
// src/services/animatedGifPrep.ts
|
|
7500
7584
|
import { createHash as createHash4, randomUUID } from "node:crypto";
|
|
7501
|
-
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as
|
|
7502
|
-
import { dirname as
|
|
7503
|
-
import { parseHTML as parseHTML3 } from "linkedom";
|
|
7585
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync8, readFileSync as readFileSync7, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
|
|
7586
|
+
import { dirname as dirname7, isAbsolute as isAbsolute3, join as join18, resolve as resolve6 } from "node:path";
|
|
7587
|
+
import { parseHTML as parseHTML3 } from "@hyperframes/parsers/linkedom";
|
|
7504
7588
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
7505
7589
|
import {
|
|
7506
7590
|
DEFAULT_VP9_CPU_USED,
|
|
@@ -7552,7 +7636,11 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
7552
7636
|
resolve6(options.downloadDir, normalizedBase)
|
|
7553
7637
|
];
|
|
7554
7638
|
const assetRoot = options.allowOutsideFiles ? void 0 : options.projectDir;
|
|
7555
|
-
const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(
|
|
7639
|
+
const allowed = (candidate) => !namesAnotherNetworkRoot(options.projectDir, candidate) && !isPrivateUnderAssetRoots(
|
|
7640
|
+
candidate,
|
|
7641
|
+
[options.projectDir, options.downloadDir],
|
|
7642
|
+
options.allowOutsideFiles
|
|
7643
|
+
) && (!escapesAssetRoot(candidate, assetRoot) && outsideAssetRefusal(options.projectDir, candidate) !== "blocklisted" || !escapesAssetRoot(candidate, options.downloadDir));
|
|
7556
7644
|
return candidates.find((candidate) => allowed(candidate) && existsSync9(candidate)) ?? null;
|
|
7557
7645
|
}
|
|
7558
7646
|
function isUsableFile(path) {
|
|
@@ -7681,11 +7769,11 @@ async function runAnimatedGifTranscode(request) {
|
|
|
7681
7769
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
7682
7770
|
}
|
|
7683
7771
|
async function ensurePreparedWebm(input) {
|
|
7684
|
-
if (!existsSync9(
|
|
7685
|
-
|
|
7772
|
+
if (!existsSync9(dirname7(input.cachePath))) {
|
|
7773
|
+
mkdirSync8(dirname7(input.cachePath), { recursive: true });
|
|
7686
7774
|
}
|
|
7687
|
-
if (!existsSync9(
|
|
7688
|
-
|
|
7775
|
+
if (!existsSync9(dirname7(input.outputPath))) {
|
|
7776
|
+
mkdirSync8(dirname7(input.outputPath), { recursive: true });
|
|
7689
7777
|
}
|
|
7690
7778
|
if (!isUsableFile(input.cachePath)) {
|
|
7691
7779
|
const tmpPath = `${input.cachePath}.tmp-${process.pid}-${randomUUID()}`;
|
|
@@ -7786,7 +7874,7 @@ async function prepareAnimatedGifInputs(html, options) {
|
|
|
7786
7874
|
if (!hasGifExtension(src)) continue;
|
|
7787
7875
|
const sourcePath = resolveLocalImageSourcePath(src, options);
|
|
7788
7876
|
if (!sourcePath) continue;
|
|
7789
|
-
const bytes =
|
|
7877
|
+
const bytes = readFileSync7(sourcePath);
|
|
7790
7878
|
const metadata = parseAnimatedGifMetadata(bytes);
|
|
7791
7879
|
if (!metadata?.animated) continue;
|
|
7792
7880
|
const loopOverride = readLoopOverride(img);
|
|
@@ -7838,16 +7926,16 @@ import { createHash as createHash5, randomUUID as randomUUID2 } from "node:crypt
|
|
|
7838
7926
|
import {
|
|
7839
7927
|
closeSync as closeSync5,
|
|
7840
7928
|
copyFileSync as copyFileSync3,
|
|
7841
|
-
mkdirSync as
|
|
7929
|
+
mkdirSync as mkdirSync9,
|
|
7842
7930
|
openSync as openSync5,
|
|
7843
|
-
readFileSync as
|
|
7931
|
+
readFileSync as readFileSync8,
|
|
7844
7932
|
readSync as readSync3,
|
|
7845
7933
|
rmSync as rmSync10,
|
|
7846
7934
|
statSync as statSync7,
|
|
7847
|
-
writeFileSync as
|
|
7935
|
+
writeFileSync as writeFileSync4
|
|
7848
7936
|
} from "node:fs";
|
|
7849
|
-
import { dirname as
|
|
7850
|
-
import { parseHTML as parseHTML4 } from "linkedom";
|
|
7937
|
+
import { dirname as dirname8, join as join19, resolve as resolve7 } from "node:path";
|
|
7938
|
+
import { parseHTML as parseHTML4 } from "@hyperframes/parsers/linkedom";
|
|
7851
7939
|
import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
|
|
7852
7940
|
|
|
7853
7941
|
// src/services/heifRotation.ts
|
|
@@ -8031,7 +8119,7 @@ function primaryGrid(probed) {
|
|
|
8031
8119
|
async function convertHeifToJpeg(request) {
|
|
8032
8120
|
const probed = await probeJson(request.inputPath, true);
|
|
8033
8121
|
const grid = primaryGrid(probed);
|
|
8034
|
-
const rotation = readHeifPrimaryRotation(
|
|
8122
|
+
const rotation = readHeifPrimaryRotation(readFileSync8(request.inputPath));
|
|
8035
8123
|
const filters = [];
|
|
8036
8124
|
let inputs = [];
|
|
8037
8125
|
let size = probed.streams?.[0];
|
|
@@ -8095,7 +8183,7 @@ function resolveImageSource(src, options) {
|
|
|
8095
8183
|
const path = resolveLocalImageSourcePath(src, options);
|
|
8096
8184
|
const head = path ? readHead(path) : null;
|
|
8097
8185
|
if (!path || !head || !isHeifBytes(head)) return null;
|
|
8098
|
-
return { path, bytes:
|
|
8186
|
+
return { path, bytes: readFileSync8(path), label: `"${splitUrlSuffix(src).basePath}"` };
|
|
8099
8187
|
}
|
|
8100
8188
|
function isUsableFile2(path) {
|
|
8101
8189
|
try {
|
|
@@ -8105,14 +8193,14 @@ function isUsableFile2(path) {
|
|
|
8105
8193
|
}
|
|
8106
8194
|
}
|
|
8107
8195
|
async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
|
|
8108
|
-
|
|
8109
|
-
|
|
8196
|
+
mkdirSync9(dirname8(cachePath), { recursive: true });
|
|
8197
|
+
mkdirSync9(dirname8(outputPath), { recursive: true });
|
|
8110
8198
|
if (!isUsableFile2(cachePath)) {
|
|
8111
8199
|
const tmpPath = `${cachePath}.tmp-${process.pid}-${randomUUID2()}`;
|
|
8112
8200
|
const inlinePath = `${tmpPath}.heic`;
|
|
8113
8201
|
const inputPath = source.path ?? inlinePath;
|
|
8114
8202
|
try {
|
|
8115
|
-
if (!source.path)
|
|
8203
|
+
if (!source.path) writeFileSync4(inlinePath, source.bytes);
|
|
8116
8204
|
await (options.transcode ?? convertHeifToJpeg)({
|
|
8117
8205
|
inputPath,
|
|
8118
8206
|
outputPath: tmpPath,
|
|
@@ -8185,7 +8273,7 @@ import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position
|
|
|
8185
8273
|
|
|
8186
8274
|
// src/services/assetMediaType.ts
|
|
8187
8275
|
import { existsSync as existsSync10 } from "node:fs";
|
|
8188
|
-
import { dirname as
|
|
8276
|
+
import { dirname as dirname9, join as join20 } from "node:path";
|
|
8189
8277
|
import {
|
|
8190
8278
|
fingerprintElementId,
|
|
8191
8279
|
isHttpUrl as isHttpUrl2,
|
|
@@ -8239,7 +8327,7 @@ function assertAssetMediaTypeProfile(expected, profile, elementIdentity) {
|
|
|
8239
8327
|
]);
|
|
8240
8328
|
}
|
|
8241
8329
|
function mediaAssetRoots(projectDir, compiledDir) {
|
|
8242
|
-
return [projectDir, compiledDir, join20(
|
|
8330
|
+
return [projectDir, compiledDir, join20(dirname9(compiledDir), "downloads")];
|
|
8243
8331
|
}
|
|
8244
8332
|
function dropMediaOutsideProject(input) {
|
|
8245
8333
|
const { projectDir, workDir, composition, log } = input;
|
|
@@ -8248,7 +8336,7 @@ function dropMediaOutsideProject(input) {
|
|
|
8248
8336
|
const staysInside = ({ id, src }) => {
|
|
8249
8337
|
if (!src || isHttpUrl2(src)) return true;
|
|
8250
8338
|
const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
|
|
8251
|
-
if (isPrivateUnderAssetRoots2(path, roots)) {
|
|
8339
|
+
if (isPrivateUnderAssetRoots2(path, roots, input.allowOutsideProjectAssets)) {
|
|
8252
8340
|
log.warn(`[Render] Media "${id}" source is missing: it is a private project file`, { src });
|
|
8253
8341
|
return false;
|
|
8254
8342
|
}
|
|
@@ -8418,7 +8506,7 @@ function assertOutsideMarkupAsked(projectDir, filePath, srcPath, assetRoot, outs
|
|
|
8418
8506
|
throw new EmptyCompositionError([{ srcPath, detail: OUTSIDE_COMPOSITION_NEEDS_FLAG }]);
|
|
8419
8507
|
}
|
|
8420
8508
|
}
|
|
8421
|
-
var isPrivateCompositionFile = (projectDir, filePath) =>
|
|
8509
|
+
var isPrivateCompositionFile = (projectDir, filePath) => isPrivateFileUnder3(projectDir, filePath, isStudioPrivatePath3);
|
|
8422
8510
|
function compositionSrcsIn(html) {
|
|
8423
8511
|
const { document: document2 } = parseHTML5(html);
|
|
8424
8512
|
const mounts = [];
|
|
@@ -8744,7 +8832,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8744
8832
|
let filePath = src;
|
|
8745
8833
|
if (isHttpUrl(src)) {
|
|
8746
8834
|
const remoteDir = join21(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
8747
|
-
if (!existsSync11(remoteDir))
|
|
8835
|
+
if (!existsSync11(remoteDir)) mkdirSync10(remoteDir, { recursive: true });
|
|
8748
8836
|
run?.assets.reserve([src]);
|
|
8749
8837
|
try {
|
|
8750
8838
|
filePath = await downloadAsset(src, remoteDir, run?.assets);
|
|
@@ -8755,7 +8843,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, projectDir, b
|
|
|
8755
8843
|
} else {
|
|
8756
8844
|
filePath = decodedUrlPath(src);
|
|
8757
8845
|
if (!filePath.startsWith("/")) filePath = join21(baseDir, filePath);
|
|
8758
|
-
if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir])) {
|
|
8846
|
+
if (escapesAssetRoot(filePath, assetRoot) || isPrivateUnderAssetRoots3(filePath, [projectDir, downloadDir], assetRoot === void 0)) {
|
|
8759
8847
|
return { duration: null, resolvedPath: filePath };
|
|
8760
8848
|
}
|
|
8761
8849
|
filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
|
|
@@ -8938,7 +9026,7 @@ async function parseSubCompositions(html, projectDir, downloadDir, visited = /*
|
|
|
8938
9026
|
const { html: compiledSub } = await compileHtmlFile(
|
|
8939
9027
|
rewriteUnresolvableGsapToCdn(item.rawSubHtml, projectDir, item.srcPath),
|
|
8940
9028
|
projectDir,
|
|
8941
|
-
|
|
9029
|
+
dirname10(item.filePath),
|
|
8942
9030
|
downloadDir,
|
|
8943
9031
|
void 0,
|
|
8944
9032
|
urlByAbsentLocalPath,
|
|
@@ -9511,7 +9599,7 @@ var REMOTE_MEDIA_SUBDIR = "_remote_media";
|
|
|
9511
9599
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, assets, extraRewrite) {
|
|
9512
9600
|
assets?.reserve(urlSet);
|
|
9513
9601
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
9514
|
-
if (!existsSync11(remoteDir))
|
|
9602
|
+
if (!existsSync11(remoteDir)) mkdirSync10(remoteDir, { recursive: true });
|
|
9515
9603
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
9516
9604
|
await Promise.all(
|
|
9517
9605
|
[...urlSet].map(async (url) => {
|
|
@@ -9708,11 +9796,11 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
9708
9796
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
9709
9797
|
const sheet = resolve8(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
9710
9798
|
if (!isPathInside(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
9711
|
-
for (const face of extractFontFaceBlocks(
|
|
9799
|
+
for (const face of extractFontFaceBlocks(readFileSync9(sheet, "utf8"))) {
|
|
9712
9800
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
9713
9801
|
const shipsFile = [...localFontFaceUrlMatches(face)].some(({ parts: [, url = ""] }) => {
|
|
9714
9802
|
const path = decodedUrlPath(url);
|
|
9715
|
-
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(
|
|
9803
|
+
const file = path.startsWith("/") ? resolve8(projectDir, `.${path}`) : resolve8(dirname10(sheet), path);
|
|
9716
9804
|
return isPathInside(file, projectDir) && existsSync11(file);
|
|
9717
9805
|
});
|
|
9718
9806
|
if (family && shipsFile) families.push(family);
|
|
@@ -10155,7 +10243,7 @@ async function compileWithAssets(projectDir, htmlPath, downloadDir, options, ass
|
|
|
10155
10243
|
for (const video of videos) {
|
|
10156
10244
|
if (isHttpUrl(video.src)) continue;
|
|
10157
10245
|
const videoPath = resolve8(projectDir, video.src);
|
|
10158
|
-
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir]))
|
|
10246
|
+
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath) || !existsSync11(videoPath) || escapesAssetRoot(videoPath, assetRoot) || isPrivateUnderAssetRoots3(videoPath, [projectDir, downloadDir], assetRoot === void 0))
|
|
10159
10247
|
continue;
|
|
10160
10248
|
advised.add(videoPath);
|
|
10161
10249
|
const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
|
|
@@ -10621,7 +10709,7 @@ function resolveCompileWorkerEntry(explicit, log) {
|
|
|
10621
10709
|
}
|
|
10622
10710
|
return void 0;
|
|
10623
10711
|
}
|
|
10624
|
-
const sibling = join22(
|
|
10712
|
+
const sibling = join22(dirname11(fileURLToPath3(import.meta.url)), "compileWorker.js");
|
|
10625
10713
|
return existsSync12(sibling) ? sibling : void 0;
|
|
10626
10714
|
}
|
|
10627
10715
|
function rebuildError({ name, message, stack, props }) {
|
|
@@ -10773,7 +10861,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
10773
10861
|
);
|
|
10774
10862
|
}
|
|
10775
10863
|
const wrapperPath = join23(workDir, "standalone-entry.html");
|
|
10776
|
-
|
|
10864
|
+
writeFileSync5(wrapperPath, standaloneHtml, "utf-8");
|
|
10777
10865
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
10778
10866
|
return wrapperPath;
|
|
10779
10867
|
}
|
|
@@ -10931,7 +11019,7 @@ async function runCompileStage(input) {
|
|
|
10931
11019
|
// src/services/render/stages/probeStage.ts
|
|
10932
11020
|
import { createHash as createHash7 } from "node:crypto";
|
|
10933
11021
|
import { basename as basename7, join as join24 } from "node:path";
|
|
10934
|
-
import { parseHTML as parseHTML6 } from "linkedom";
|
|
11022
|
+
import { parseHTML as parseHTML6 } from "@hyperframes/parsers/linkedom";
|
|
10935
11023
|
import {
|
|
10936
11024
|
closeCaptureSession as closeCaptureSession4,
|
|
10937
11025
|
compositionRequiresWebGpu,
|
|
@@ -12401,7 +12489,7 @@ import {
|
|
|
12401
12489
|
|
|
12402
12490
|
// src/services/render/audioDeliveryLimit.ts
|
|
12403
12491
|
import { existsSync as existsSync16 } from "node:fs";
|
|
12404
|
-
import { dirname as
|
|
12492
|
+
import { dirname as dirname13, join as join27 } from "node:path";
|
|
12405
12493
|
import {
|
|
12406
12494
|
applyAudioFxChain,
|
|
12407
12495
|
describeFfmpegFailure as describeFfmpegFailure3,
|
|
@@ -12412,7 +12500,7 @@ import {
|
|
|
12412
12500
|
// src/services/render/audioPadTrim.ts
|
|
12413
12501
|
import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
|
|
12414
12502
|
import { spawn } from "node:child_process";
|
|
12415
|
-
import { dirname as
|
|
12503
|
+
import { dirname as dirname12, join as join26 } from "node:path";
|
|
12416
12504
|
import {
|
|
12417
12505
|
DEFAULT_CONFIG,
|
|
12418
12506
|
describeFfmpegFailure as describeFfmpegFailure2,
|
|
@@ -12707,7 +12795,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
|
|
|
12707
12795
|
async function enforceAacTruePeak(input) {
|
|
12708
12796
|
let scratchDir;
|
|
12709
12797
|
try {
|
|
12710
|
-
scratchDir = createStagingDir3(
|
|
12798
|
+
scratchDir = createStagingDir3(dirname12(input.audioPath), ".true-peak-");
|
|
12711
12799
|
const correctedPath = join26(scratchDir, "audio.m4a");
|
|
12712
12800
|
const measurements = [];
|
|
12713
12801
|
let attenuationDb = 0;
|
|
@@ -12931,7 +13019,7 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
12931
13019
|
const peak = await deps.measure(audioPath, { timeoutMs, signal });
|
|
12932
13020
|
if (peak <= AAC_DELIVERY_TRUE_PEAK_DBFS) return { success: true };
|
|
12933
13021
|
const alternating = ["a", "b"].map(
|
|
12934
|
-
(k) => join27(
|
|
13022
|
+
(k) => join27(dirname13(sourcePath), `audio-source-limited-${k}.wav`)
|
|
12935
13023
|
);
|
|
12936
13024
|
let encodedFrom;
|
|
12937
13025
|
let ceiling = AAC_DELIVERY_TRUE_PEAK_DBFS;
|
|
@@ -13005,10 +13093,15 @@ function runAudioStage(input) {
|
|
|
13005
13093
|
async function runAudioStageScoped(input) {
|
|
13006
13094
|
const stageStart = Date.now();
|
|
13007
13095
|
const pcmSourcePath = join28(input.workDir, "audio-source.wav");
|
|
13008
|
-
const
|
|
13096
|
+
const seconds = (frames) => frames * input.fps.den / input.fps.num;
|
|
13097
|
+
const duration = seconds(input.totalFrames);
|
|
13098
|
+
const window2 = input.frameWindow && {
|
|
13099
|
+
startSeconds: seconds(input.frameWindow.startFrame),
|
|
13100
|
+
durationSeconds: seconds(input.frameWindow.endFrame - input.frameWindow.startFrame)
|
|
13101
|
+
};
|
|
13009
13102
|
let deliverySourcePath;
|
|
13010
13103
|
try {
|
|
13011
|
-
const result = await mixAudioForDelivery(input, duration, pcmSourcePath);
|
|
13104
|
+
const result = await mixAudioForDelivery(input, duration, pcmSourcePath, window2);
|
|
13012
13105
|
let audioLoweredDb;
|
|
13013
13106
|
if (result.hasAudio) {
|
|
13014
13107
|
const guardStart = Date.now();
|
|
@@ -13016,7 +13109,7 @@ async function runAudioStageScoped(input) {
|
|
|
13016
13109
|
input,
|
|
13017
13110
|
result.audioOutputPath,
|
|
13018
13111
|
pcmSourcePath,
|
|
13019
|
-
duration
|
|
13112
|
+
window2?.durationSeconds ?? duration
|
|
13020
13113
|
);
|
|
13021
13114
|
audioLoweredDb = guard.loweredDb;
|
|
13022
13115
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
@@ -13054,7 +13147,7 @@ async function guardDeliveryPeaks(input, audioPath, sourcePath, duration) {
|
|
|
13054
13147
|
if (!peak.success) throw encoderFailureError("Audio true-peak check failed", peak);
|
|
13055
13148
|
return { loweredDb: peak.loweredDb, sourceStale: peak.sourceStale };
|
|
13056
13149
|
}
|
|
13057
|
-
async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
13150
|
+
async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
13058
13151
|
const {
|
|
13059
13152
|
projectDir,
|
|
13060
13153
|
workDir,
|
|
@@ -13091,6 +13184,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
13091
13184
|
urlByAbsentLocalPath,
|
|
13092
13185
|
audioSidecarUrlByLocalPath,
|
|
13093
13186
|
keepEncoderInputAt: pcmSourcePath,
|
|
13187
|
+
window: window2,
|
|
13094
13188
|
assetRoots: input.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir)
|
|
13095
13189
|
},
|
|
13096
13190
|
compiledDir
|
|
@@ -13498,7 +13592,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13498
13592
|
assertNotAborted();
|
|
13499
13593
|
const absoluteIdx = rangeStart + i;
|
|
13500
13594
|
const time = absoluteIdx * job.config.fps.den / job.config.fps.num;
|
|
13501
|
-
const { encodeResult } = await captureFrameToBufferPipelined2(session,
|
|
13595
|
+
const { encodeResult } = await captureFrameToBufferPipelined2(session, absoluteIdx, time);
|
|
13502
13596
|
await drainPrev();
|
|
13503
13597
|
prev = { fileIndex: i, encodeResult };
|
|
13504
13598
|
}
|
|
@@ -13508,7 +13602,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13508
13602
|
assertNotAborted();
|
|
13509
13603
|
const absoluteIdx = rangeStart + i;
|
|
13510
13604
|
const time = absoluteIdx * job.config.fps.den / job.config.fps.num;
|
|
13511
|
-
await captureFrame(session,
|
|
13605
|
+
await captureFrame(session, absoluteIdx, time, i);
|
|
13512
13606
|
reportFrame(i);
|
|
13513
13607
|
}
|
|
13514
13608
|
}
|
|
@@ -13527,7 +13621,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
13527
13621
|
}
|
|
13528
13622
|
|
|
13529
13623
|
// src/services/render/stages/captureHdrStage.ts
|
|
13530
|
-
import { existsSync as existsSync20, mkdirSync as
|
|
13624
|
+
import { existsSync as existsSync20, mkdirSync as mkdirSync11 } from "node:fs";
|
|
13531
13625
|
import { join as join33 } from "node:path";
|
|
13532
13626
|
import {
|
|
13533
13627
|
closeCaptureSession as closeCaptureSession7,
|
|
@@ -13639,9 +13733,18 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13639
13733
|
output: Buffer.alloc(bufSize)
|
|
13640
13734
|
} : null;
|
|
13641
13735
|
const normalCanvas = Buffer.alloc(bufSize);
|
|
13736
|
+
const firstFrame = windowStartFrame(job.frameWindow);
|
|
13737
|
+
cleanupHdrVideosEndedBefore(firstFrame, job.config.fps, transitionRanges, {
|
|
13738
|
+
hdrVideoEndTimes,
|
|
13739
|
+
cleanedUpVideos,
|
|
13740
|
+
hdrVideoFrameSources,
|
|
13741
|
+
sceneElements,
|
|
13742
|
+
log
|
|
13743
|
+
});
|
|
13642
13744
|
for (let i = 0; i < totalFrames; i++) {
|
|
13643
13745
|
assertNotAborted();
|
|
13644
|
-
const
|
|
13746
|
+
const frame = firstFrame + i;
|
|
13747
|
+
const time = frame * job.config.fps.den / job.config.fps.num;
|
|
13645
13748
|
if (hdrPerf) hdrPerf.frames += 1;
|
|
13646
13749
|
const stackingInfo = await seekInjectAndQueryStacking(
|
|
13647
13750
|
domSession.page,
|
|
@@ -13653,11 +13756,11 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13653
13756
|
"frameInjectMs",
|
|
13654
13757
|
"stackingQueryMs"
|
|
13655
13758
|
);
|
|
13656
|
-
const activeTransition = transitionRanges
|
|
13759
|
+
const activeTransition = transitionAtFrame(transitionRanges, frame);
|
|
13657
13760
|
if (i % 30 === 0 && (log.isLevelEnabled?.("debug") ?? true)) {
|
|
13658
13761
|
const hdrEl = stackingInfo.find((e) => e.isHdr);
|
|
13659
13762
|
log.debug("[Render] HDR layer composite frame", {
|
|
13660
|
-
frame
|
|
13763
|
+
frame,
|
|
13661
13764
|
time: time.toFixed(2),
|
|
13662
13765
|
hdrElement: hdrEl ? { z: hdrEl.zIndex, visible: hdrEl.visible, width: hdrEl.width } : null,
|
|
13663
13766
|
stackingCount: stackingInfo.length,
|
|
@@ -13667,7 +13770,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13667
13770
|
if (activeTransition && transitionBuffers) {
|
|
13668
13771
|
if (hdrPerf) hdrPerf.transitionFrames += 1;
|
|
13669
13772
|
const transitionTimingStart = Date.now();
|
|
13670
|
-
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (
|
|
13773
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (frame - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
13671
13774
|
const sceneAIds = new Set(sceneElements[activeTransition.fromScene] ?? []);
|
|
13672
13775
|
const sceneBIds = new Set(sceneElements[activeTransition.toScene] ?? []);
|
|
13673
13776
|
timeHdrPhase(hdrPerf, "canvasClearMs", () => {
|
|
@@ -13696,7 +13799,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13696
13799
|
hdrTargetTransfer,
|
|
13697
13800
|
hdrPerf,
|
|
13698
13801
|
log,
|
|
13699
|
-
frameIdx:
|
|
13802
|
+
frameIdx: frame
|
|
13700
13803
|
});
|
|
13701
13804
|
}
|
|
13702
13805
|
const shaderName = activeTransition.shader;
|
|
@@ -13721,7 +13824,7 @@ async function runSequentialLayeredFrameLoop(input) {
|
|
|
13721
13824
|
await timeHdrPhaseAsync(
|
|
13722
13825
|
hdrPerf,
|
|
13723
13826
|
"normalCompositeMs",
|
|
13724
|
-
() => compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, void 0,
|
|
13827
|
+
() => compositeHdrFrame(hdrCompositeCtx, normalCanvas, time, stackingInfo, void 0, frame)
|
|
13725
13828
|
);
|
|
13726
13829
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
13727
13830
|
writeFileExclusiveSync(
|
|
@@ -13771,7 +13874,7 @@ import {
|
|
|
13771
13874
|
// src/services/shaderTransitionWorkerPool.ts
|
|
13772
13875
|
import { Worker as Worker2 } from "node:worker_threads";
|
|
13773
13876
|
import { fileURLToPath as fileURLToPath4, pathToFileURL } from "node:url";
|
|
13774
|
-
import { dirname as
|
|
13877
|
+
import { dirname as dirname14, join as join31 } from "node:path";
|
|
13775
13878
|
import { createRequire } from "node:module";
|
|
13776
13879
|
import { usableCpuCount } from "@hyperframes/engine";
|
|
13777
13880
|
import { existsSync as existsSync19 } from "node:fs";
|
|
@@ -13784,7 +13887,7 @@ function resolveWorkerEntry(explicit) {
|
|
|
13784
13887
|
const isTs = override.endsWith(".ts");
|
|
13785
13888
|
return { path: override, isTs };
|
|
13786
13889
|
}
|
|
13787
|
-
const moduleDir =
|
|
13890
|
+
const moduleDir = dirname14(fileURLToPath4(import.meta.url));
|
|
13788
13891
|
const jsPath = join31(moduleDir, "shaderTransitionWorker.js");
|
|
13789
13892
|
if (existsSync19(jsPath)) return { path: jsPath, isTs: false };
|
|
13790
13893
|
const tsPath = join31(moduleDir, "shaderTransitionWorker.ts");
|
|
@@ -13992,7 +14095,8 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
13992
14095
|
assertNotAborted,
|
|
13993
14096
|
onProgress
|
|
13994
14097
|
} = input;
|
|
13995
|
-
const
|
|
14098
|
+
const firstFrame = windowStartFrame(job.frameWindow);
|
|
14099
|
+
const transitionFramesSet = partitionTransitionFrames(transitionRanges, totalFrames, firstFrame);
|
|
13996
14100
|
const hasTransitions = transitionRanges.length > 0;
|
|
13997
14101
|
const bufSize = width * height * 6;
|
|
13998
14102
|
const workerSessions = [];
|
|
@@ -14083,8 +14187,9 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14083
14187
|
for (let i = range.start; i < range.end; i++) {
|
|
14084
14188
|
throwIfFailed();
|
|
14085
14189
|
assertNotAborted();
|
|
14086
|
-
const
|
|
14087
|
-
const
|
|
14190
|
+
const frame = firstFrame + i;
|
|
14191
|
+
const time = frame * job.config.fps.den / job.config.fps.num;
|
|
14192
|
+
const activeTransition = transitionFramesSet.has(frame) ? transitionAtFrame(transitionRanges, frame) : void 0;
|
|
14088
14193
|
if (activeTransition && ring) {
|
|
14089
14194
|
const slot = nextRingIdx;
|
|
14090
14195
|
nextRingIdx = (nextRingIdx + 1) % TRANSITION_RING_DEPTH;
|
|
@@ -14095,7 +14200,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14095
14200
|
if (!buffers) continue;
|
|
14096
14201
|
await captureTransitionFrameOnWorker({
|
|
14097
14202
|
session,
|
|
14098
|
-
frameIdx:
|
|
14203
|
+
frameIdx: frame,
|
|
14099
14204
|
time,
|
|
14100
14205
|
transition: activeTransition,
|
|
14101
14206
|
buffers,
|
|
@@ -14110,7 +14215,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14110
14215
|
hdrPerf,
|
|
14111
14216
|
log
|
|
14112
14217
|
});
|
|
14113
|
-
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (
|
|
14218
|
+
const progress = activeTransition.endFrame === activeTransition.startFrame ? 1 : (frame - activeTransition.startFrame) / (activeTransition.endFrame - activeTransition.startFrame);
|
|
14114
14219
|
const frameIdx = i;
|
|
14115
14220
|
const shaderName = activeTransition.shader;
|
|
14116
14221
|
const dispatch = (async () => {
|
|
@@ -14161,7 +14266,7 @@ async function runHybridLayeredFrameLoop(input) {
|
|
|
14161
14266
|
await timeHdrPhaseAsync(
|
|
14162
14267
|
hdrPerf,
|
|
14163
14268
|
"normalCompositeMs",
|
|
14164
|
-
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0,
|
|
14269
|
+
() => compositeHdrFrame(wctx, canvas, time, stackingInfo, void 0, frame)
|
|
14165
14270
|
);
|
|
14166
14271
|
if (debugDumpEnabled && debugDumpDir && i % 30 === 0) {
|
|
14167
14272
|
writeFileExclusiveSync(
|
|
@@ -14371,7 +14476,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14371
14476
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
14372
14477
|
const debugDumpDir = debugDumpEnabled ? join33(framesDir, "debug-composite") : null;
|
|
14373
14478
|
if (debugDumpDir && !existsSync20(debugDumpDir)) {
|
|
14374
|
-
|
|
14479
|
+
mkdirSync11(debugDumpDir, { recursive: true });
|
|
14375
14480
|
}
|
|
14376
14481
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
14377
14482
|
const hdrTargetTransfer = compositeTransfer === "srgb" ? void 0 : compositeTransfer;
|
|
@@ -14399,7 +14504,11 @@ async function runCaptureHdrStage(input) {
|
|
|
14399
14504
|
hdrPerf
|
|
14400
14505
|
};
|
|
14401
14506
|
const effectiveWorkerCount = Math.max(1, workerCount);
|
|
14402
|
-
const transitionFrameCount = partitionTransitionFrames(
|
|
14507
|
+
const transitionFrameCount = partitionTransitionFrames(
|
|
14508
|
+
transitionRanges,
|
|
14509
|
+
totalFrames,
|
|
14510
|
+
windowStartFrame(job.frameWindow)
|
|
14511
|
+
).size;
|
|
14403
14512
|
const useHybrid = shouldUseHybridLayeredPath({
|
|
14404
14513
|
hasHdrContent,
|
|
14405
14514
|
transitionFramesCount: transitionFrameCount,
|
|
@@ -14530,15 +14639,15 @@ async function runCaptureHdrStage(input) {
|
|
|
14530
14639
|
import {
|
|
14531
14640
|
copyFileSync as copyFileSync4,
|
|
14532
14641
|
existsSync as existsSync21,
|
|
14533
|
-
mkdirSync as
|
|
14642
|
+
mkdirSync as mkdirSync12,
|
|
14534
14643
|
readdirSync as readdirSync5,
|
|
14535
|
-
readFileSync as
|
|
14644
|
+
readFileSync as readFileSync10,
|
|
14536
14645
|
rmSync as rmSync12,
|
|
14537
14646
|
statSync as statSync9,
|
|
14538
|
-
writeFileSync as
|
|
14647
|
+
writeFileSync as writeFileSync6
|
|
14539
14648
|
} from "node:fs";
|
|
14540
14649
|
import { readFile as readFile2 } from "node:fs/promises";
|
|
14541
|
-
import { dirname as
|
|
14650
|
+
import { dirname as dirname15, join as join34 } from "node:path";
|
|
14542
14651
|
import {
|
|
14543
14652
|
encodeFramesChunkedConcat,
|
|
14544
14653
|
encodeFramesFromDir,
|
|
@@ -14626,12 +14735,12 @@ async function reencodeWithClearedWholeFrames(argsInput, run, startTime) {
|
|
|
14626
14735
|
const error = formatFfmpegError(result.exitCode, result.stderr);
|
|
14627
14736
|
return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
|
|
14628
14737
|
}
|
|
14629
|
-
const gif =
|
|
14738
|
+
const gif = readFileSync10(outputPath);
|
|
14630
14739
|
if (!clearGifFramesBeforeNext(gif)) {
|
|
14631
14740
|
const error = "[FFmpeg] GIF output could not be parsed to clear its frames";
|
|
14632
14741
|
return gifEncodeFailure(startTime, outputPath, error);
|
|
14633
14742
|
}
|
|
14634
|
-
|
|
14743
|
+
writeFileSync6(outputPath, gif);
|
|
14635
14744
|
return null;
|
|
14636
14745
|
}
|
|
14637
14746
|
async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
@@ -14659,7 +14768,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
14659
14768
|
return gifEncodeFailure(startTime, outputPath, error, result.failureReason);
|
|
14660
14769
|
}
|
|
14661
14770
|
}
|
|
14662
|
-
if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(
|
|
14771
|
+
if (input.preserveAlpha && gifClearsAfterLeavingFrameInPlace(readFileSync10(outputPath)) !== false) {
|
|
14663
14772
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
14664
14773
|
if (failure) return failure;
|
|
14665
14774
|
}
|
|
@@ -14832,7 +14941,7 @@ async function runEncodeStage(input) {
|
|
|
14832
14941
|
const stage5Start = Date.now();
|
|
14833
14942
|
if (isPngSequence) {
|
|
14834
14943
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
14835
|
-
if (!existsSync21(outputPath))
|
|
14944
|
+
if (!existsSync21(outputPath)) mkdirSync12(outputPath, { recursive: true });
|
|
14836
14945
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
14837
14946
|
if (captured.length === 0) {
|
|
14838
14947
|
throw new Error(
|
|
@@ -14864,7 +14973,7 @@ async function runEncodeStage(input) {
|
|
|
14864
14973
|
const encodeResult2 = await encodeGifFromDir(framesDir, framePattern2, outputPath, {
|
|
14865
14974
|
fps: job.config.fps,
|
|
14866
14975
|
loop,
|
|
14867
|
-
palettePath: join34(
|
|
14976
|
+
palettePath: join34(dirname15(videoOnlyPath), "gif-palette.png"),
|
|
14868
14977
|
preserveAlpha: needsAlpha,
|
|
14869
14978
|
signal: abortSignal,
|
|
14870
14979
|
timeout: engineCfg.ffmpegEncodeTimeout
|
|
@@ -15318,7 +15427,7 @@ function getNextRetryWorkerCount(currentWorkers) {
|
|
|
15318
15427
|
}
|
|
15319
15428
|
function resolveRenderWorkDirPrefix(outputPath, jobId, platform2 = process.platform, systemTempDir = tmpdir3()) {
|
|
15320
15429
|
if (platform2 === "win32" || platform2 === "darwin") return join35(systemTempDir, "hf-render-");
|
|
15321
|
-
return join35(
|
|
15430
|
+
return join35(dirname16(outputPath), `work-${jobId}-`);
|
|
15322
15431
|
}
|
|
15323
15432
|
var MAX_TRANSIENT_CAPTURE_RETRIES = 1;
|
|
15324
15433
|
function isTransientCaptureRetryEligible(failureKind, missing, retriesUsed) {
|
|
@@ -16046,7 +16155,7 @@ function deVerifyFallbackTelemetry(err) {
|
|
|
16046
16155
|
};
|
|
16047
16156
|
}
|
|
16048
16157
|
function resolveRenderDebugDir() {
|
|
16049
|
-
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(
|
|
16158
|
+
const producerRoot = process.env.PRODUCER_RENDERS_DIR ? resolve9(process.env.PRODUCER_RENDERS_DIR, "..") : resolve9(dirname16(fileURLToPath5(import.meta.url)), "../..");
|
|
16050
16159
|
return join35(producerRoot, ".debug");
|
|
16051
16160
|
}
|
|
16052
16161
|
async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
@@ -16054,8 +16163,8 @@ async function executeRenderJob(job, projectDir, outputPath, progressSink, abort
|
|
|
16054
16163
|
validateDeliveryEncoderConfig(job.config);
|
|
16055
16164
|
validateChromaSubsamplingConfig(job.config);
|
|
16056
16165
|
const debugDir = resolveRenderDebugDir();
|
|
16057
|
-
const outputDir =
|
|
16058
|
-
if (!existsSync22(outputDir))
|
|
16166
|
+
const outputDir = dirname16(outputPath);
|
|
16167
|
+
if (!existsSync22(outputDir)) mkdirSync13(outputDir, { recursive: true });
|
|
16059
16168
|
const workDir = job.config.debug ? join35(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
16060
16169
|
const pipelineStart = Date.now();
|
|
16061
16170
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
@@ -16212,7 +16321,7 @@ async function executeRenderPipeline(input) {
|
|
|
16212
16321
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
16213
16322
|
assertNotAborted();
|
|
16214
16323
|
assertConfiguredFfmpegBinariesExist();
|
|
16215
|
-
if (!existsSync22(workDir))
|
|
16324
|
+
if (!existsSync22(workDir)) mkdirSync13(workDir, { recursive: true });
|
|
16216
16325
|
if (job.config.debug) {
|
|
16217
16326
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
16218
16327
|
}
|
|
@@ -16381,15 +16490,18 @@ async function executeRenderPipeline(input) {
|
|
|
16381
16490
|
if (resolvedCaptureBeyondViewport !== void 0) {
|
|
16382
16491
|
updateCaptureObservability({ captureBeyondViewport: resolvedCaptureBeyondViewport });
|
|
16383
16492
|
}
|
|
16384
|
-
job.duration = probeResult.duration;
|
|
16385
|
-
job.totalFrames = probeResult.totalFrames;
|
|
16386
|
-
const totalFrames = probeResult.totalFrames;
|
|
16387
|
-
captureTotalFrames = totalFrames;
|
|
16388
16493
|
validateRenderDuration({
|
|
16389
16494
|
duration: probeResult.duration,
|
|
16390
|
-
totalFrames,
|
|
16495
|
+
totalFrames: probeResult.totalFrames,
|
|
16391
16496
|
fps: fpsToNumber8(job.config.fps)
|
|
16392
16497
|
});
|
|
16498
|
+
const frameWindow = job.config.range ? resolveFrameWindow(job.config.range, job.config.fps, probeResult.totalFrames) : void 0;
|
|
16499
|
+
job.frameWindow = frameWindow;
|
|
16500
|
+
if (frameWindow) cfg.enableStreamingEncode = false;
|
|
16501
|
+
const totalFrames = frameWindow ? frameWindow.endFrame - frameWindow.startFrame : probeResult.totalFrames;
|
|
16502
|
+
job.totalFrames = totalFrames;
|
|
16503
|
+
job.duration = frameWindow ? totalFrames * job.config.fps.den / job.config.fps.num : probeResult.duration;
|
|
16504
|
+
captureTotalFrames = totalFrames;
|
|
16393
16505
|
const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(
|
|
16394
16506
|
probeSession.page,
|
|
16395
16507
|
largerThanCanvas,
|
|
@@ -16570,6 +16682,7 @@ async function executeRenderPipeline(input) {
|
|
|
16570
16682
|
workDir,
|
|
16571
16683
|
compiledDir,
|
|
16572
16684
|
totalFrames: probeResult.totalFrames,
|
|
16685
|
+
...frameWindow && { frameWindow },
|
|
16573
16686
|
fps: job.config.fps,
|
|
16574
16687
|
ffmpegProcessTimeout: cfg.ffmpegProcessTimeout,
|
|
16575
16688
|
audioGain: cfg.audioGain,
|
|
@@ -16616,14 +16729,31 @@ async function executeRenderPipeline(input) {
|
|
|
16616
16729
|
throw new Error("File server failed to initialize before frame capture");
|
|
16617
16730
|
}
|
|
16618
16731
|
const framesDir = join35(workDir, "captured-frames");
|
|
16619
|
-
if (!existsSync22(framesDir))
|
|
16732
|
+
if (!existsSync22(framesDir)) mkdirSync13(framesDir, { recursive: true });
|
|
16620
16733
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
16621
16734
|
code: "start_browsers"
|
|
16622
16735
|
});
|
|
16623
|
-
|
|
16736
|
+
let resolvedBrowserGpuMode = await resolveBrowserGpuMode(cfg.browserGpuMode, {
|
|
16624
16737
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
16625
16738
|
browserTimeout: cfg.browserTimeout
|
|
16626
16739
|
});
|
|
16740
|
+
const closeProbeSession = async () => {
|
|
16741
|
+
if (!probeSession) return;
|
|
16742
|
+
lastBrowserConsole = probeSession.browserConsoleBuffer;
|
|
16743
|
+
await closeCaptureSession8(probeSession).catch(() => {
|
|
16744
|
+
});
|
|
16745
|
+
probeSession = null;
|
|
16746
|
+
};
|
|
16747
|
+
const gpuStore = cfg.browserGpuMode === "auto" && resolvedBrowserGpuMode === "hardware" ? gpuChoiceStore(cfg, await probedHardwareGpu()) : void 0;
|
|
16748
|
+
const storedGpuChoice = gpuStore && readGpuChoice(gpuStore);
|
|
16749
|
+
if (gpuStore && storedGpuChoice === "software") {
|
|
16750
|
+
log.info("[Render] Auto GPU mode: rendering in software, as measured on this machine.", {
|
|
16751
|
+
file: gpuStore.file
|
|
16752
|
+
});
|
|
16753
|
+
cfg.browserGpuMode = "software";
|
|
16754
|
+
resolvedBrowserGpuMode = "software";
|
|
16755
|
+
await closeProbeSession();
|
|
16756
|
+
}
|
|
16627
16757
|
startingFrameCapture();
|
|
16628
16758
|
captureForceScreenshot = applyConcreteGpuScreenshotClamp(
|
|
16629
16759
|
captureForceScreenshot,
|
|
@@ -16860,6 +16990,10 @@ async function executeRenderPipeline(input) {
|
|
|
16860
16990
|
totalMemoryMb: Math.round(totalmem2() / (1024 * 1024)),
|
|
16861
16991
|
minMemoryMb: deParallelMinMemoryMb
|
|
16862
16992
|
});
|
|
16993
|
+
if (frameWindow) {
|
|
16994
|
+
deInversionEligible = false;
|
|
16995
|
+
deParallelRouterEligible = false;
|
|
16996
|
+
}
|
|
16863
16997
|
if (probeSession === null && (deInversionEligible || deParallelRouterEligible)) {
|
|
16864
16998
|
try {
|
|
16865
16999
|
probeSession = await createCaptureSession8(
|
|
@@ -16924,7 +17058,9 @@ async function executeRenderPipeline(input) {
|
|
|
16924
17058
|
return "beginFrame";
|
|
16925
17059
|
}
|
|
16926
17060
|
});
|
|
16927
|
-
|
|
17061
|
+
const sizeByCalibration = job.config.workers === void 0 && totalFrames >= 60 && !htmlInCanvasDetected && !cfg.lowMemoryMode && !deInversionEligible && !deParallelRouterEligible;
|
|
17062
|
+
const measureGpuChoice = gpuStore !== void 0 && storedGpuChoice === void 0;
|
|
17063
|
+
if (sizeByCalibration || measureGpuChoice) {
|
|
16928
17064
|
updateJobStatus(job, "rendering", "Measuring capture speed", 25, onProgress, {
|
|
16929
17065
|
code: "start_browsers"
|
|
16930
17066
|
});
|
|
@@ -16933,6 +17069,16 @@ async function executeRenderPipeline(input) {
|
|
|
16933
17069
|
"calibration"
|
|
16934
17070
|
) : void 0;
|
|
16935
17071
|
let outcome;
|
|
17072
|
+
let softwareOutcome;
|
|
17073
|
+
const calibrationInput = {
|
|
17074
|
+
fileServer: activeFileServer,
|
|
17075
|
+
log,
|
|
17076
|
+
job,
|
|
17077
|
+
totalFrames,
|
|
17078
|
+
buildCaptureOptions: buildPrepCaptureOptions,
|
|
17079
|
+
createRenderVideoFrameInjector: calibrationFrames ? calibrationFrames.injector : createRenderVideoFrameInjector,
|
|
17080
|
+
assertNotAborted
|
|
17081
|
+
};
|
|
16936
17082
|
try {
|
|
16937
17083
|
outcome = await observeRenderStage(
|
|
16938
17084
|
observability,
|
|
@@ -16945,38 +17091,91 @@ async function executeRenderPipeline(input) {
|
|
|
16945
17091
|
// ts=1784019503.
|
|
16946
17092
|
stagePhase: "calibrating"
|
|
16947
17093
|
}),
|
|
16948
|
-
() =>
|
|
16949
|
-
|
|
16950
|
-
|
|
16951
|
-
|
|
16952
|
-
|
|
16953
|
-
|
|
16954
|
-
|
|
16955
|
-
|
|
16956
|
-
probeSession
|
|
16957
|
-
|
|
16958
|
-
|
|
16959
|
-
|
|
16960
|
-
|
|
17094
|
+
async () => {
|
|
17095
|
+
const result = await runCaptureCalibration({
|
|
17096
|
+
...calibrationInput,
|
|
17097
|
+
cfg: calibrationCaptureConfig(cfg),
|
|
17098
|
+
workDir,
|
|
17099
|
+
forceScreenshot: captureForceScreenshot,
|
|
17100
|
+
probeSession
|
|
17101
|
+
});
|
|
17102
|
+
probeSession = result.probeSession;
|
|
17103
|
+
if (storedGpuChoice === void 0 && shouldCalibrateSoftwareGpu(
|
|
17104
|
+
cfg.browserGpuMode,
|
|
17105
|
+
resolvedBrowserGpuMode,
|
|
17106
|
+
result.calibration?.estimate
|
|
17107
|
+
)) {
|
|
17108
|
+
softwareOutcome = await runCaptureCalibration({
|
|
17109
|
+
...calibrationInput,
|
|
17110
|
+
cfg: calibrationCaptureConfig({ ...cfg, browserGpuMode: "software" }),
|
|
17111
|
+
workDir: join35(workDir, "software-gpu"),
|
|
17112
|
+
forceScreenshot: applyConcreteGpuScreenshotClamp(
|
|
17113
|
+
captureForceScreenshot,
|
|
17114
|
+
"software",
|
|
17115
|
+
cfg
|
|
17116
|
+
),
|
|
17117
|
+
probeSession: null
|
|
17118
|
+
});
|
|
17119
|
+
}
|
|
17120
|
+
return result;
|
|
17121
|
+
},
|
|
16961
17122
|
{ heartbeatMessage: "browser calibrating (frames not started)" }
|
|
16962
17123
|
);
|
|
16963
17124
|
} finally {
|
|
16964
17125
|
calibrationFrames?.release();
|
|
16965
17126
|
}
|
|
16966
17127
|
startingFrameCapture();
|
|
16967
|
-
captureCalibration = outcome.calibration;
|
|
17128
|
+
if (sizeByCalibration) captureCalibration = outcome.calibration;
|
|
16968
17129
|
calibrationEvaluateTimedOut = outcome.calibrationEvaluateTimedOut;
|
|
16969
17130
|
captureForceScreenshot = outcome.forceScreenshot;
|
|
16970
17131
|
updateCaptureObservability({ forceScreenshot: captureForceScreenshot });
|
|
16971
|
-
probeSession = outcome.probeSession;
|
|
16972
17132
|
if (outcome.lastBrowserConsole.length > 0) {
|
|
16973
17133
|
lastBrowserConsole = outcome.lastBrowserConsole;
|
|
16974
17134
|
}
|
|
17135
|
+
if (softwareOutcome && outcome.calibration && pickAutoGpuModeFromCalibration(
|
|
17136
|
+
outcome.calibration.estimate,
|
|
17137
|
+
softwareOutcome.calibration?.estimate
|
|
17138
|
+
) === "software") {
|
|
17139
|
+
log.warn(
|
|
17140
|
+
"[Render] Auto GPU mode: software capture measured faster than the hardware GPU, rendering in software.",
|
|
17141
|
+
{
|
|
17142
|
+
hardwareP95Ms: outcome.calibration.estimate.p95Ms,
|
|
17143
|
+
softwareP95Ms: softwareOutcome.calibration?.estimate.p95Ms
|
|
17144
|
+
}
|
|
17145
|
+
);
|
|
17146
|
+
cfg.browserGpuMode = "software";
|
|
17147
|
+
resolvedBrowserGpuMode = "software";
|
|
17148
|
+
if (sizeByCalibration) captureCalibration = softwareOutcome.calibration;
|
|
17149
|
+
captureForceScreenshot = softwareOutcome.forceScreenshot;
|
|
17150
|
+
await closeProbeSession();
|
|
17151
|
+
updateCaptureObservability({
|
|
17152
|
+
browserGpuMode: resolvedBrowserGpuMode,
|
|
17153
|
+
forceScreenshot: captureForceScreenshot
|
|
17154
|
+
});
|
|
17155
|
+
}
|
|
17156
|
+
const settledGpuChoice = measureGpuChoice ? settleAutoGpuChoice(outcome.calibration?.estimate, softwareOutcome?.calibration?.estimate) : void 0;
|
|
17157
|
+
if (gpuStore && settledGpuChoice) {
|
|
17158
|
+
try {
|
|
17159
|
+
writeGpuChoice(gpuStore, settledGpuChoice, {
|
|
17160
|
+
hardwareP95Ms: outcome.calibration?.estimate.p95Ms,
|
|
17161
|
+
softwareP95Ms: softwareOutcome?.calibration?.estimate.p95Ms
|
|
17162
|
+
});
|
|
17163
|
+
} catch (error) {
|
|
17164
|
+
log.warn(
|
|
17165
|
+
"[Render] Could not save the measured GPU choice; the next render measures again.",
|
|
17166
|
+
{
|
|
17167
|
+
file: gpuStore.file,
|
|
17168
|
+
error: error instanceof Error ? error.message : String(error)
|
|
17169
|
+
}
|
|
17170
|
+
);
|
|
17171
|
+
}
|
|
17172
|
+
}
|
|
16975
17173
|
observability.checkpoint("capture_calibration", "resolved", {
|
|
16976
17174
|
forceScreenshot: captureForceScreenshot,
|
|
16977
|
-
|
|
16978
|
-
|
|
16979
|
-
|
|
17175
|
+
browserGpuMode: resolvedBrowserGpuMode,
|
|
17176
|
+
multiplier: captureCalibration?.estimate.multiplier ?? null,
|
|
17177
|
+
p95Ms: captureCalibration?.estimate.p95Ms ?? null,
|
|
17178
|
+
medianMs: captureCalibration?.estimate.medianMs ?? null
|
|
16980
17179
|
});
|
|
16981
17180
|
} else {
|
|
16982
17181
|
observability.checkpoint("capture_calibration", "skipped", {
|
|
@@ -17326,6 +17525,7 @@ async function executeRenderPipeline(input) {
|
|
|
17326
17525
|
});
|
|
17327
17526
|
const syncCapturePlan = () => {
|
|
17328
17527
|
assertMotionBlurSupported(job.config.motionBlur, capturePlan.kind);
|
|
17528
|
+
assertRangeSupported(job.frameWindow, capturePlan.kind);
|
|
17329
17529
|
assertOutputScaleSupported(deviceScaleFactor, capturePlan.kind);
|
|
17330
17530
|
workerCount = capturePlan.workerCount;
|
|
17331
17531
|
captureForceScreenshot = capturePlan.forceScreenshot;
|
|
@@ -17911,6 +18111,7 @@ async function executeRenderPipeline(input) {
|
|
|
17911
18111
|
framesDir,
|
|
17912
18112
|
job,
|
|
17913
18113
|
totalFrames,
|
|
18114
|
+
...job.frameWindow && { frameRange: job.frameWindow },
|
|
17914
18115
|
cfg,
|
|
17915
18116
|
plan: diskPlan,
|
|
17916
18117
|
log,
|
|
@@ -17951,7 +18152,7 @@ async function executeRenderPipeline(input) {
|
|
|
17951
18152
|
"drawElement capture failed; retrying with a fresh screenshot session"
|
|
17952
18153
|
);
|
|
17953
18154
|
rmSync13(framesDir, { recursive: true, force: true });
|
|
17954
|
-
|
|
18155
|
+
mkdirSync13(framesDir, { recursive: true });
|
|
17955
18156
|
resetCaptureAttemptProgress(job);
|
|
17956
18157
|
dedupPerfs.length = 0;
|
|
17957
18158
|
cfg.useDrawElement = false;
|
|
@@ -18130,7 +18331,7 @@ async function executeRenderPipeline(input) {
|
|
|
18130
18331
|
job.perfSummary = perfSummary;
|
|
18131
18332
|
if (job.config.debug) {
|
|
18132
18333
|
try {
|
|
18133
|
-
|
|
18334
|
+
writeFileSync7(perfOutputPath, JSON.stringify(perfSummary, null, 2), "utf-8");
|
|
18134
18335
|
} catch (err) {
|
|
18135
18336
|
log.debug("Failed to write perf summary", {
|
|
18136
18337
|
perfOutputPath,
|
|
@@ -18257,14 +18458,14 @@ async function executeRenderPipeline(input) {
|
|
|
18257
18458
|
// src/services/hyperframeLint.ts
|
|
18258
18459
|
import {
|
|
18259
18460
|
existsSync as existsSync23,
|
|
18260
|
-
readFileSync as
|
|
18461
|
+
readFileSync as readFileSync11,
|
|
18261
18462
|
statSync as statSync11,
|
|
18262
18463
|
openSync as openSync6,
|
|
18263
18464
|
fstatSync as fstatSync4,
|
|
18264
18465
|
closeSync as closeSync6,
|
|
18265
18466
|
constants as constants4
|
|
18266
18467
|
} from "node:fs";
|
|
18267
|
-
import { resolve as resolve10, join as join36, relative as relative6, isAbsolute as isAbsolute5, sep as sep5, dirname as
|
|
18468
|
+
import { resolve as resolve10, join as join36, relative as relative6, isAbsolute as isAbsolute5, sep as sep5, dirname as dirname17 } from "node:path";
|
|
18268
18469
|
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
18269
18470
|
import { Worker as Worker3 } from "node:worker_threads";
|
|
18270
18471
|
function isStringRecord(value) {
|
|
@@ -18304,7 +18505,7 @@ function readEntryHtml(filePath) {
|
|
|
18304
18505
|
}
|
|
18305
18506
|
try {
|
|
18306
18507
|
if (!fstatSync4(fd).isFile()) return null;
|
|
18307
|
-
return
|
|
18508
|
+
return readFileSync11(fd, "utf-8");
|
|
18308
18509
|
} finally {
|
|
18309
18510
|
closeSync6(fd);
|
|
18310
18511
|
}
|
|
@@ -18403,7 +18604,7 @@ function freeLintSlot() {
|
|
|
18403
18604
|
waiting.shift()?.();
|
|
18404
18605
|
}
|
|
18405
18606
|
function resolveLintWorkerEntry() {
|
|
18406
|
-
const here =
|
|
18607
|
+
const here = dirname17(fileURLToPath6(import.meta.url));
|
|
18407
18608
|
for (const name of ["hyperframeLintWorker.js", "hyperframeLintWorker.ts"]) {
|
|
18408
18609
|
const candidate = join36(here, name);
|
|
18409
18610
|
if (existsSync23(candidate)) return candidate;
|
|
@@ -18476,7 +18677,7 @@ async function runHyperframeLint(prepared, options = {}) {
|
|
|
18476
18677
|
// src/services/healthWorker.ts
|
|
18477
18678
|
import { Worker as Worker4 } from "node:worker_threads";
|
|
18478
18679
|
import { fileURLToPath as fileURLToPath7 } from "node:url";
|
|
18479
|
-
import { dirname as
|
|
18680
|
+
import { dirname as dirname18, join as join37 } from "node:path";
|
|
18480
18681
|
import { existsSync as existsSync24 } from "node:fs";
|
|
18481
18682
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
18482
18683
|
async function startHealthWorker(options = {}) {
|
|
@@ -18551,7 +18752,7 @@ function defaultLogger2() {
|
|
|
18551
18752
|
};
|
|
18552
18753
|
}
|
|
18553
18754
|
function resolveWorkerEntry2() {
|
|
18554
|
-
const here =
|
|
18755
|
+
const here = dirname18(fileURLToPath7(import.meta.url));
|
|
18555
18756
|
const candidates = [join37(here, "healthWorkerThread.js"), join37(here, "healthWorkerThread.ts")];
|
|
18556
18757
|
for (const candidate of candidates) {
|
|
18557
18758
|
if (existsSync24(candidate)) return candidate;
|
|
@@ -18627,8 +18828,8 @@ import {
|
|
|
18627
18828
|
|
|
18628
18829
|
// src/services/distributed/shared.ts
|
|
18629
18830
|
import { execFile as execFileCallback } from "node:child_process";
|
|
18630
|
-
import { dirname as
|
|
18631
|
-
import { existsSync as existsSync25, readFileSync as
|
|
18831
|
+
import { dirname as dirname19, join as join38 } from "node:path";
|
|
18832
|
+
import { existsSync as existsSync25, readFileSync as readFileSync12 } from "node:fs";
|
|
18632
18833
|
import { fileURLToPath as fileURLToPath8 } from "node:url";
|
|
18633
18834
|
import { promisify as promisify2 } from "node:util";
|
|
18634
18835
|
import {
|
|
@@ -18640,13 +18841,13 @@ var execFile = promisify2(execFileCallback);
|
|
|
18640
18841
|
var cachedProducerVersion = null;
|
|
18641
18842
|
function readProducerVersion() {
|
|
18642
18843
|
if (cachedProducerVersion !== null) return cachedProducerVersion;
|
|
18643
|
-
const startDir =
|
|
18844
|
+
const startDir = dirname19(fileURLToPath8(import.meta.url));
|
|
18644
18845
|
let current = startDir;
|
|
18645
18846
|
for (let i = 0; i < 10; i++) {
|
|
18646
18847
|
const candidate = join38(current, "package.json");
|
|
18647
18848
|
if (existsSync25(candidate)) {
|
|
18648
18849
|
try {
|
|
18649
|
-
const pkg = JSON.parse(
|
|
18850
|
+
const pkg = JSON.parse(readFileSync12(candidate, "utf-8"));
|
|
18650
18851
|
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
18651
18852
|
cachedProducerVersion = pkg.version;
|
|
18652
18853
|
return pkg.version;
|
|
@@ -18654,7 +18855,7 @@ function readProducerVersion() {
|
|
|
18654
18855
|
} catch {
|
|
18655
18856
|
}
|
|
18656
18857
|
}
|
|
18657
|
-
const parent =
|
|
18858
|
+
const parent = dirname19(current);
|
|
18658
18859
|
if (parent === current) break;
|
|
18659
18860
|
current = parent;
|
|
18660
18861
|
}
|
|
@@ -19167,9 +19368,9 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
19167
19368
|
const serverNamed = input.outputPath == null;
|
|
19168
19369
|
const outputCandidate = input.outputPath ?? join40(rendersDir, `${basename8(resolve11(input.projectDir))}-${crypto.randomUUID()}.mp4`);
|
|
19169
19370
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, outputCandidate, rendersDir, log);
|
|
19170
|
-
const outputDir =
|
|
19371
|
+
const outputDir = dirname20(absoluteOutputPath);
|
|
19171
19372
|
if (confineOutput) {
|
|
19172
|
-
|
|
19373
|
+
mkdirSync14(rendersDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
19173
19374
|
if (!isSafePath4(rendersDir, absoluteOutputPath)) {
|
|
19174
19375
|
throw new Error("outputPath must be inside the renders directory");
|
|
19175
19376
|
}
|
|
@@ -19180,7 +19381,7 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log, confineOutput) {
|
|
|
19180
19381
|
);
|
|
19181
19382
|
}
|
|
19182
19383
|
}
|
|
19183
|
-
if (!existsSync26(outputDir))
|
|
19384
|
+
if (!existsSync26(outputDir)) mkdirSync14(outputDir, { recursive: true, mode: SERVER_FOLDER_MODE });
|
|
19184
19385
|
return { input, cleanupProjectDir, absoluteOutputPath, serverNamed };
|
|
19185
19386
|
}
|
|
19186
19387
|
var STICKY_BIT = 512;
|
|
@@ -19292,7 +19493,7 @@ async function resolveInlineRenderHtml(body) {
|
|
|
19292
19493
|
function materializeInlineProject(html, options) {
|
|
19293
19494
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir4();
|
|
19294
19495
|
const tempProjectDir = mkdtempSync(join40(tempRoot, "producer-project-"));
|
|
19295
|
-
|
|
19496
|
+
writeFileSync8(join40(tempProjectDir, "index.html"), html, "utf-8");
|
|
19296
19497
|
return {
|
|
19297
19498
|
prepared: {
|
|
19298
19499
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -19885,9 +20086,9 @@ function serverAuth(options, hostname2, port) {
|
|
|
19885
20086
|
options.authTokenFile?.trim() || process.env.PRODUCER_AUTH_TOKEN_FILE?.trim() || join40(homedir(), ".hyperframes", "producer", `${port}.token`)
|
|
19886
20087
|
);
|
|
19887
20088
|
const token = crypto.randomBytes(32).toString("base64url");
|
|
19888
|
-
|
|
20089
|
+
mkdirSync14(dirname20(file), { recursive: true, mode: 448 });
|
|
19889
20090
|
rmSync14(file, { force: true });
|
|
19890
|
-
|
|
20091
|
+
writeFileSync8(file, `${token}
|
|
19891
20092
|
`, { flag: "wx", mode: 384 });
|
|
19892
20093
|
return { token, generatedFile: file };
|
|
19893
20094
|
}
|