@hyperframes/producer 0.10.4 → 0.10.6
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/distributed.js +63 -32
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +66 -66
- package/dist/index.js +138 -45
- package/dist/public-server.js +135 -39
- package/dist/services/render/captureCost.d.ts +4 -0
- package/dist/services/render/captureStageError.d.ts +1 -0
- package/dist/services/render/stages/captureEncoder.d.ts +3 -0
- package/dist/services/render/stages/captureSegmentedStage.d.ts +3 -2
- package/dist/services/render/stages/captureStreamingStage.d.ts +4 -3
- package/dist/services/render/stages/encodeStage.d.ts +1 -26
- package/dist/services/renderOrchestrator.d.ts +2 -0
- package/package.json +8 -8
package/dist/public-server.js
CHANGED
|
@@ -380,7 +380,7 @@ import {
|
|
|
380
380
|
getSystemTotalMb,
|
|
381
381
|
LOW_MEMORY_TOTAL_MB_THRESHOLD,
|
|
382
382
|
assertConfiguredFfmpegBinariesExist,
|
|
383
|
-
resolveBrowserGpuMode,
|
|
383
|
+
resolveBrowserGpuMode as resolveBrowserGpuMode2,
|
|
384
384
|
probedHardwareGpu,
|
|
385
385
|
resolveHeadlessShellPath,
|
|
386
386
|
compositionRequiresWebGpu as compositionRequiresWebGpu2,
|
|
@@ -388,7 +388,8 @@ import {
|
|
|
388
388
|
explainDrawElementDisabled,
|
|
389
389
|
chromeMajorCeiling,
|
|
390
390
|
scaleProtocolTimeoutForComposition,
|
|
391
|
-
|
|
391
|
+
captureMemoryRetryWorkers as captureMemoryRetryWorkers2,
|
|
392
|
+
classifyCaptureFailure as classifyCaptureFailure4,
|
|
392
393
|
cloneCaptureWarning,
|
|
393
394
|
isMemoryExhaustionError as isMemoryExhaustionError2,
|
|
394
395
|
isTransientBrowserError as isTransientBrowserError2,
|
|
@@ -2625,8 +2626,7 @@ import {
|
|
|
2625
2626
|
initializeSession as initializeSession2,
|
|
2626
2627
|
prepareCaptureSessionForReuse as prepareCaptureSessionForReuse2,
|
|
2627
2628
|
resolveDeVerifyMinDb as resolveDeVerifyMinDb2,
|
|
2628
|
-
shouldDisableBrowserPoolForParallelWorker
|
|
2629
|
-
spawnStreamingEncoder as spawnStreamingEncoder2
|
|
2629
|
+
shouldDisableBrowserPoolForParallelWorker
|
|
2630
2630
|
} from "@hyperframes/engine";
|
|
2631
2631
|
|
|
2632
2632
|
// src/services/render/captureStageError.ts
|
|
@@ -2998,6 +2998,7 @@ function buildRenderPerfSummary(input) {
|
|
|
2998
2998
|
// src/services/render/captureStageError.ts
|
|
2999
2999
|
var CaptureStageError = class extends CaptureFailure {
|
|
3000
3000
|
browserConsole;
|
|
3001
|
+
memoryRetryUsed = false;
|
|
3001
3002
|
constructor(input) {
|
|
3002
3003
|
const classified = classifyCaptureFailure(input.cause);
|
|
3003
3004
|
super({
|
|
@@ -4585,6 +4586,8 @@ import {
|
|
|
4585
4586
|
captureFrameToBuffer,
|
|
4586
4587
|
captureFrameToBufferPipelined,
|
|
4587
4588
|
captureFramesBatchPipelined,
|
|
4589
|
+
captureMemoryRetryWorkers,
|
|
4590
|
+
classifyCaptureFailure as classifyCaptureFailure2,
|
|
4588
4591
|
closeCaptureSession,
|
|
4589
4592
|
createCaptureSession,
|
|
4590
4593
|
createFrameReorderBuffer,
|
|
@@ -4598,8 +4601,7 @@ import {
|
|
|
4598
4601
|
recaptureDrawElementFrameForVerify,
|
|
4599
4602
|
completeDeferredDrawElementInit,
|
|
4600
4603
|
initializeSession,
|
|
4601
|
-
prepareCaptureSessionForReuse
|
|
4602
|
-
spawnStreamingEncoder
|
|
4604
|
+
prepareCaptureSessionForReuse
|
|
4603
4605
|
} from "@hyperframes/engine";
|
|
4604
4606
|
|
|
4605
4607
|
// src/services/render/stallClock.ts
|
|
@@ -4621,6 +4623,17 @@ function createStallClock(now = () => Date.now()) {
|
|
|
4621
4623
|
};
|
|
4622
4624
|
}
|
|
4623
4625
|
|
|
4626
|
+
// src/services/render/stages/captureEncoder.ts
|
|
4627
|
+
import { spawnStreamingEncoder } from "@hyperframes/engine";
|
|
4628
|
+
function spawnCaptureEncoder(...[outputPath, options, signal, config]) {
|
|
4629
|
+
return spawnStreamingEncoder(
|
|
4630
|
+
outputPath,
|
|
4631
|
+
{ ...options, belowNormalPriority: true },
|
|
4632
|
+
signal,
|
|
4633
|
+
config
|
|
4634
|
+
);
|
|
4635
|
+
}
|
|
4636
|
+
|
|
4624
4637
|
// src/services/render/stages/captureStreamingStage.ts
|
|
4625
4638
|
var DEFAULT_CAPTURE_STALL_MS = 6e4;
|
|
4626
4639
|
var SESSION_INIT_STALL_MS = 3e5;
|
|
@@ -5020,7 +5033,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5020
5033
|
let streamingEncoder = null;
|
|
5021
5034
|
let streamingEncoderClosed = false;
|
|
5022
5035
|
try {
|
|
5023
|
-
streamingEncoder = await
|
|
5036
|
+
streamingEncoder = await spawnCaptureEncoder(
|
|
5024
5037
|
videoOnlyPath,
|
|
5025
5038
|
streamingEncoderOptions,
|
|
5026
5039
|
abortSignal,
|
|
@@ -5064,6 +5077,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
5064
5077
|
let writtenFrames = 0;
|
|
5065
5078
|
let resumeFrom = 0;
|
|
5066
5079
|
let resumes = 0;
|
|
5080
|
+
let memoryRetryUsed = false;
|
|
5067
5081
|
let workerResults;
|
|
5068
5082
|
for (; ; ) {
|
|
5069
5083
|
const parallelReorder = createFrameReorderBuffer(resumeFrom, totalFrames);
|
|
@@ -5195,6 +5209,25 @@ async function runCaptureStreamingStage(input) {
|
|
|
5195
5209
|
resumes++;
|
|
5196
5210
|
continue;
|
|
5197
5211
|
}
|
|
5212
|
+
const stop = parallelDrainError ?? err;
|
|
5213
|
+
const memoryStop = abortSignal?.aborted !== true && captureLabel === "screenshot" && classifyCaptureFailure2(stop).kind === "memory_exhaustion";
|
|
5214
|
+
const fitWorkers = memoryStop && !memoryRetryUsed ? captureMemoryRetryWorkers(stop) : void 0;
|
|
5215
|
+
if (workerCount > 1 && fitWorkers !== void 0) {
|
|
5216
|
+
memoryRetryUsed = true;
|
|
5217
|
+
const nextWorkers = Math.min(fitWorkers, workerCount - 1);
|
|
5218
|
+
log.warn(
|
|
5219
|
+
"[Render] Capture stopped before memory ran out; resuming from the first unwritten frame with fewer workers.",
|
|
5220
|
+
{ fromWorkers: workerCount, toWorkers: nextWorkers, resumeFrom: writtenFrames }
|
|
5221
|
+
);
|
|
5222
|
+
workerCount = nextWorkers;
|
|
5223
|
+
resumeFrom = writtenFrames;
|
|
5224
|
+
continue;
|
|
5225
|
+
}
|
|
5226
|
+
if (memoryStop && memoryRetryUsed) {
|
|
5227
|
+
const failure = poolFailure(stop, probeSession);
|
|
5228
|
+
if (failure instanceof CaptureStageError) failure.memoryRetryUsed = true;
|
|
5229
|
+
throw failure;
|
|
5230
|
+
}
|
|
5198
5231
|
if (parallelDrainError) throw poolFailure(parallelDrainError, probeSession);
|
|
5199
5232
|
if (stalled && abortSignal?.aborted !== true) {
|
|
5200
5233
|
throw new ParallelCaptureStallError({
|
|
@@ -5525,7 +5558,7 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
5525
5558
|
}
|
|
5526
5559
|
}
|
|
5527
5560
|
var DEFAULT_DEPS = {
|
|
5528
|
-
spawnEncoder:
|
|
5561
|
+
spawnEncoder: spawnCaptureEncoder,
|
|
5529
5562
|
captureFrame: captureFrameToBuffer2,
|
|
5530
5563
|
concat: concatVideoFiles,
|
|
5531
5564
|
// Through the import binding, not captured: a value captured at module load
|
|
@@ -5910,10 +5943,13 @@ import { fpsToNumber as fpsToNumber4 } from "@hyperframes/core";
|
|
|
5910
5943
|
import {
|
|
5911
5944
|
calculateOptimalWorkers,
|
|
5912
5945
|
captureFrameToBuffer as captureFrameToBuffer3,
|
|
5946
|
+
clearStaticDedupAnchor,
|
|
5913
5947
|
closeCaptureSession as closeCaptureSession3,
|
|
5914
5948
|
computeWorkerSizing,
|
|
5915
5949
|
createCaptureSession as createCaptureSession3,
|
|
5916
|
-
initializeSession as initializeSession3
|
|
5950
|
+
initializeSession as initializeSession3,
|
|
5951
|
+
readChromeCpuSeconds,
|
|
5952
|
+
resolveBrowserGpuMode
|
|
5917
5953
|
} from "@hyperframes/engine";
|
|
5918
5954
|
var CAPTURE_CALIBRATION_TARGET_MS = 600;
|
|
5919
5955
|
var MAX_MEASURED_CAPTURE_COST_MULTIPLIER = 8;
|
|
@@ -5953,13 +5989,20 @@ function combineCaptureCostEstimates(staticCost, measuredCost) {
|
|
|
5953
5989
|
multiplier: measuredCost.multiplier,
|
|
5954
5990
|
reasons: [...measuredCost.reasons, ...staticCost.reasons],
|
|
5955
5991
|
p95Ms: measuredCost.p95Ms,
|
|
5956
|
-
medianMs: measuredCost.medianMs
|
|
5992
|
+
medianMs: measuredCost.medianMs,
|
|
5993
|
+
// A hint names work the samples can miss, such as a shader transition between two of them.
|
|
5994
|
+
coresPerWorker: staticCost.multiplier > 1 ? void 0 : measuredCost.coresPerWorker,
|
|
5995
|
+
browserRssMb: measuredCost.browserRssMb
|
|
5957
5996
|
};
|
|
5958
5997
|
}
|
|
5959
5998
|
function buildHeapAdvisoryWarning(sizing, requestedWorkers) {
|
|
5960
5999
|
if (requestedWorkers !== void 0 || !sizing.exceedsHeapAdvisory) return void 0;
|
|
5961
6000
|
return `[Render] ${sizing.workers} capture workers may exceed this process's V8 heap (limit ${sizing.heapLimitMb}MB supports ~${sizing.heapBasedWorkers}). If the render dies with "JavaScript heap out of memory", raise the heap (NODE_OPTIONS=--max-old-space-size=8192) or pass --workers ${sizing.heapBasedWorkers}.`;
|
|
5962
6001
|
}
|
|
6002
|
+
function coresToSizeBy(cost, protocolTimeout) {
|
|
6003
|
+
if (cost.browserRssMb === void 0) return void 0;
|
|
6004
|
+
return 2 * (cost.p95Ms ?? Infinity) < protocolTimeout ? cost.coresPerWorker : void 0;
|
|
6005
|
+
}
|
|
5963
6006
|
function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled, log = defaultLogger, measuredCaptureCost, onSizing) {
|
|
5964
6007
|
const reasonCodes = new Set(compiled.renderModeHints.reasons.map((r) => r.code));
|
|
5965
6008
|
if (reasonCodes.has("htmlInCanvas")) {
|
|
@@ -5981,7 +6024,9 @@ function resolveRenderWorkerCount(totalFrames, requestedWorkers, cfg, compiled,
|
|
|
5981
6024
|
);
|
|
5982
6025
|
const sizing = computeWorkerSizing(totalFrames, requestedWorkers, {
|
|
5983
6026
|
...cfg,
|
|
5984
|
-
captureCostMultiplier: captureCost.multiplier
|
|
6027
|
+
captureCostMultiplier: captureCost.multiplier,
|
|
6028
|
+
measuredCoresPerWorker: coresToSizeBy(captureCost, cfg.protocolTimeout),
|
|
6029
|
+
measuredBrowserRssMb: captureCost.browserRssMb
|
|
5985
6030
|
});
|
|
5986
6031
|
onSizing?.(sizing);
|
|
5987
6032
|
const workerCount = sizing.workers;
|
|
@@ -6080,7 +6125,7 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
|
|
|
6080
6125
|
}
|
|
6081
6126
|
} finally {
|
|
6082
6127
|
session.staticFrames = savedStaticFrames;
|
|
6083
|
-
session
|
|
6128
|
+
clearStaticDedupAnchor(session);
|
|
6084
6129
|
}
|
|
6085
6130
|
const estimate = estimateMeasuredCaptureCostMultiplier(samples);
|
|
6086
6131
|
if (estimate.p95Ms !== void 0) {
|
|
@@ -6091,11 +6136,20 @@ async function measureCaptureCostFromSession(session, totalFrames, fps, log, fir
|
|
|
6091
6136
|
samples
|
|
6092
6137
|
};
|
|
6093
6138
|
}
|
|
6139
|
+
function chromeCoresUsed(before, after, elapsedMs) {
|
|
6140
|
+
if (!before || !after || elapsedMs <= 0) return void 0;
|
|
6141
|
+
for (const pid of before.keys()) if (!after.has(pid)) return void 0;
|
|
6142
|
+
const total = (cpu) => [...cpu.values()].reduce((a, b) => a + b, 0);
|
|
6143
|
+
const cores = (total(after) - total(before)) / (elapsedMs / 1e3);
|
|
6144
|
+
return cores > 0 ? cores : void 0;
|
|
6145
|
+
}
|
|
6094
6146
|
function logCaptureCalibrationResult(calibration, log) {
|
|
6095
6147
|
if (calibration.estimate.multiplier > 1) {
|
|
6096
6148
|
log.warn("[Render] Measured slow frame capture during auto-worker calibration.", {
|
|
6097
6149
|
multiplier: calibration.estimate.multiplier,
|
|
6098
6150
|
p95Ms: calibration.estimate.p95Ms,
|
|
6151
|
+
coresPerWorker: calibration.estimate.coresPerWorker,
|
|
6152
|
+
browserRssMb: calibration.estimate.browserRssMb,
|
|
6099
6153
|
sampledFrames: calibration.samples.map((sample) => sample.frameIndex),
|
|
6100
6154
|
sampleMs: calibration.samples.map((sample) => Math.round(sample.captureTimeMs))
|
|
6101
6155
|
});
|
|
@@ -6159,6 +6213,12 @@ async function runCaptureCalibration(input) {
|
|
|
6159
6213
|
}
|
|
6160
6214
|
assertNotAborted();
|
|
6161
6215
|
log.info("Calibration session ready, capturing test frames...");
|
|
6216
|
+
const readCpu = () => readChromeCpuSeconds(() => session.browser.target().createCDPSession()).catch(
|
|
6217
|
+
() => void 0
|
|
6218
|
+
);
|
|
6219
|
+
const softwareGpu = await resolveBrowserGpuMode(sessionCfg.browserGpuMode) === "software";
|
|
6220
|
+
const cpuBefore = softwareGpu ? await readCpu() : void 0;
|
|
6221
|
+
const startedAt = performance.now();
|
|
6162
6222
|
const result = await measureCaptureCostFromSession(
|
|
6163
6223
|
session,
|
|
6164
6224
|
totalFrames,
|
|
@@ -6166,6 +6226,15 @@ async function runCaptureCalibration(input) {
|
|
|
6166
6226
|
log,
|
|
6167
6227
|
job.frameWindow?.startFrame
|
|
6168
6228
|
);
|
|
6229
|
+
const elapsedMs = performance.now() - startedAt;
|
|
6230
|
+
const cpuAfter = cpuBefore && await readCpu();
|
|
6231
|
+
result.estimate.coresPerWorker = chromeCoresUsed(cpuBefore, cpuAfter, elapsedMs);
|
|
6232
|
+
if (result.estimate.coresPerWorker !== void 0) {
|
|
6233
|
+
const before = session.chromeMemory?.stats().samples ?? 0;
|
|
6234
|
+
await session.chromeMemory?.sampleOnce();
|
|
6235
|
+
const memory = session.chromeMemory?.stats();
|
|
6236
|
+
if (memory && memory.samples > before) result.estimate.browserRssMb = memory.rssLastMb;
|
|
6237
|
+
}
|
|
6169
6238
|
logCaptureCalibrationResult(result, log);
|
|
6170
6239
|
return result;
|
|
6171
6240
|
};
|
|
@@ -13491,7 +13560,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath, window2) {
|
|
|
13491
13560
|
import { existsSync as existsSync18, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
13492
13561
|
import { join as join30 } from "node:path";
|
|
13493
13562
|
import {
|
|
13494
|
-
classifyCaptureFailure as
|
|
13563
|
+
classifyCaptureFailure as classifyCaptureFailure3,
|
|
13495
13564
|
frameFileExtension,
|
|
13496
13565
|
captureFrame,
|
|
13497
13566
|
captureFrameToBufferPipelined as captureFrameToBufferPipelined2,
|
|
@@ -13798,7 +13867,7 @@ function resolveCaptureRange(frameRange, totalFrames) {
|
|
|
13798
13867
|
return { rangeStart: frameRange?.startFrame ?? 0, rangeEnd: frameRange?.endFrame ?? totalFrames };
|
|
13799
13868
|
}
|
|
13800
13869
|
function planTransientResume(error, ctx) {
|
|
13801
|
-
const failure =
|
|
13870
|
+
const failure = classifyCaptureFailure3(error, { signal: ctx.abortSignal });
|
|
13802
13871
|
const missing = findMissingFrameRanges(ctx.rangeFrames, ctx.framesDir, ctx.frameExt);
|
|
13803
13872
|
const [firstMissing] = missing;
|
|
13804
13873
|
if (!firstMissing) return null;
|
|
@@ -13894,8 +13963,7 @@ import {
|
|
|
13894
13963
|
cloneCaptureWarnings as cloneCaptureWarnings2,
|
|
13895
13964
|
createCaptureSession as createCaptureSession7,
|
|
13896
13965
|
initTransparentBackground as initTransparentBackground2,
|
|
13897
|
-
initializeSession as initializeSession7
|
|
13898
|
-
spawnStreamingEncoder as spawnStreamingEncoder3
|
|
13966
|
+
initializeSession as initializeSession7
|
|
13899
13967
|
} from "@hyperframes/engine";
|
|
13900
13968
|
import { fpsToNumber as fpsToNumber7 } from "@hyperframes/core";
|
|
13901
13969
|
|
|
@@ -14686,7 +14754,7 @@ async function runCaptureHdrStage(input) {
|
|
|
14686
14754
|
}))
|
|
14687
14755
|
});
|
|
14688
14756
|
}
|
|
14689
|
-
hdrEncoder = await
|
|
14757
|
+
hdrEncoder = await spawnCaptureEncoder(
|
|
14690
14758
|
videoOnlyPath,
|
|
14691
14759
|
{
|
|
14692
14760
|
fps: job.config.fps,
|
|
@@ -14925,8 +14993,7 @@ import {
|
|
|
14925
14993
|
formatFfmpegError,
|
|
14926
14994
|
MIXED_AUDIO_FILENAME as MIXED_AUDIO_FILENAME2,
|
|
14927
14995
|
resolveConfig,
|
|
14928
|
-
runFfmpeg as runFfmpeg6
|
|
14929
|
-
spawnStreamingEncoder as spawnStreamingEncoder4
|
|
14996
|
+
runFfmpeg as runFfmpeg6
|
|
14930
14997
|
} from "@hyperframes/engine";
|
|
14931
14998
|
import {
|
|
14932
14999
|
clearGifFramesBeforeNext,
|
|
@@ -15066,10 +15133,7 @@ function startEncodeProgress(job, stage, onProgress) {
|
|
|
15066
15133
|
function resolveEngineConfig(input) {
|
|
15067
15134
|
return input.engineConfig ?? input.job.config.producerConfig ?? resolveConfig();
|
|
15068
15135
|
}
|
|
15069
|
-
function
|
|
15070
|
-
return Math.max(1, Math.floor(cpuCount) - Math.floor(workerCount));
|
|
15071
|
-
}
|
|
15072
|
-
function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
15136
|
+
function videoEncoderOptions(input, engineCfg) {
|
|
15073
15137
|
const { job, preset } = input;
|
|
15074
15138
|
return {
|
|
15075
15139
|
fps: job.config.fps,
|
|
@@ -15089,8 +15153,7 @@ function videoEncoderOptions(input, engineCfg, softwareEncoderThreads) {
|
|
|
15089
15153
|
// keyframes that survive `-f concat -c copy` at assemble time. In-process
|
|
15090
15154
|
// renders leave both undefined → preserves the existing open-GOP output.
|
|
15091
15155
|
lockGopForChunkConcat: input.lockGopForChunkConcat === true,
|
|
15092
|
-
gopSize: input.gopSize
|
|
15093
|
-
softwareEncoderThreads
|
|
15156
|
+
gopSize: input.gopSize
|
|
15094
15157
|
};
|
|
15095
15158
|
}
|
|
15096
15159
|
function canEncodeWhileCapturing(input, workerCount, cpuCount) {
|
|
@@ -15106,9 +15169,8 @@ async function readLandedFrame(workerPath, mergedPath) {
|
|
|
15106
15169
|
}
|
|
15107
15170
|
return readFile2(mergedPath);
|
|
15108
15171
|
}
|
|
15109
|
-
function encodeWhileCapturing(input, totalFrames
|
|
15172
|
+
function encodeWhileCapturing(input, totalFrames) {
|
|
15110
15173
|
const engineCfg = resolveEngineConfig(input);
|
|
15111
|
-
const softwareEncoderThreads = captureBudget ? overlapEncoderThreads(captureBudget.workerCount, captureBudget.cpuCount) : void 0;
|
|
15112
15174
|
const stop = new AbortController();
|
|
15113
15175
|
const signal = input.abortSignal ? AbortSignal.any([input.abortSignal, stop.signal]) : stop.signal;
|
|
15114
15176
|
const landed = /* @__PURE__ */ new Map();
|
|
@@ -15121,10 +15183,10 @@ function encodeWhileCapturing(input, totalFrames, captureBudget) {
|
|
|
15121
15183
|
};
|
|
15122
15184
|
signal.addEventListener("abort", nudge, { once: true });
|
|
15123
15185
|
let reportFed = null;
|
|
15124
|
-
const encoder =
|
|
15186
|
+
const encoder = spawnCaptureEncoder(
|
|
15125
15187
|
input.videoOnlyPath,
|
|
15126
15188
|
{
|
|
15127
|
-
...videoEncoderOptions(input, engineCfg
|
|
15189
|
+
...videoEncoderOptions(input, engineCfg),
|
|
15128
15190
|
imageFormat: "jpeg"
|
|
15129
15191
|
},
|
|
15130
15192
|
signal,
|
|
@@ -15505,8 +15567,14 @@ var RenderQualityError = class extends Error {
|
|
|
15505
15567
|
);
|
|
15506
15568
|
this.warnings = warnings;
|
|
15507
15569
|
this.name = "RenderQualityError";
|
|
15570
|
+
const failed = warnings.filter((warning) => warning.code === "sub_timeline_script_failure");
|
|
15571
|
+
if (failed.length > 0 && failed.every((warning) => warning.details?.scriptThrew === true)) {
|
|
15572
|
+
this.code = "COMPOSITION_SCRIPT_FAILED";
|
|
15573
|
+
}
|
|
15508
15574
|
}
|
|
15509
15575
|
warnings;
|
|
15576
|
+
/** Set only when the composition's own script threw: rendering it again fails the same way. */
|
|
15577
|
+
code;
|
|
15510
15578
|
};
|
|
15511
15579
|
var MIN_CPUS_TO_CAPTURE_DURING_MIX = 4;
|
|
15512
15580
|
function applyRenderWarningPolicy(job, captureWarnings, log = defaultLogger) {
|
|
@@ -15736,7 +15804,7 @@ function isRecoverableParallelCaptureError(error) {
|
|
|
15736
15804
|
if (error instanceof RenderStageStalledError) return true;
|
|
15737
15805
|
const message = normalizeErrorMessage(error);
|
|
15738
15806
|
if (!message.includes("[Parallel] Capture failed")) return false;
|
|
15739
|
-
const kind =
|
|
15807
|
+
const kind = classifyCaptureFailure4(error).kind;
|
|
15740
15808
|
return kind === "transient_browser" || kind === "protocol_timeout";
|
|
15741
15809
|
}
|
|
15742
15810
|
function describeMemoryExhaustion(error, ctx) {
|
|
@@ -15768,6 +15836,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15768
15836
|
let attempt = 0;
|
|
15769
15837
|
let transientRetriesUsed = 0;
|
|
15770
15838
|
let initializationRetriesUsed = 0;
|
|
15839
|
+
let memoryRetriesUsed = 0;
|
|
15771
15840
|
let pendingTransientRetry = false;
|
|
15772
15841
|
const rangeStart = options.frameRangeStart ?? 0;
|
|
15773
15842
|
while (true) {
|
|
@@ -15867,7 +15936,7 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15867
15936
|
attempt++;
|
|
15868
15937
|
} catch (caught) {
|
|
15869
15938
|
const error = attemptSignal?.aborted && !options.abortSignal?.aborted ? attemptSignal.reason : caught;
|
|
15870
|
-
const failure =
|
|
15939
|
+
const failure = classifyCaptureFailure4(error, { signal: options.abortSignal });
|
|
15871
15940
|
if (failure.kind === "cancelled") {
|
|
15872
15941
|
throw error;
|
|
15873
15942
|
}
|
|
@@ -15917,6 +15986,24 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
|
|
|
15917
15986
|
pendingTransientRetry = true;
|
|
15918
15987
|
continue;
|
|
15919
15988
|
}
|
|
15989
|
+
const fitWorkers = memoryRetriesUsed === 0 && failure.kind === "memory_exhaustion" ? captureMemoryRetryWorkers2(error) : void 0;
|
|
15990
|
+
if (options.allowRetry && currentWorkers > 1 && fitWorkers !== void 0) {
|
|
15991
|
+
memoryRetriesUsed++;
|
|
15992
|
+
const nextWorkers2 = Math.min(fitWorkers, currentWorkers - 1);
|
|
15993
|
+
options.log.warn(
|
|
15994
|
+
"[Render] Capture stopped before memory ran out; retrying missing frames with fewer workers.",
|
|
15995
|
+
{
|
|
15996
|
+
fromWorkers: currentWorkers,
|
|
15997
|
+
toWorkers: nextWorkers2,
|
|
15998
|
+
missingFrames: remainingCount,
|
|
15999
|
+
error: failure.message
|
|
16000
|
+
}
|
|
16001
|
+
);
|
|
16002
|
+
currentWorkers = nextWorkers2;
|
|
16003
|
+
missingRanges = remaining;
|
|
16004
|
+
attempt++;
|
|
16005
|
+
continue;
|
|
16006
|
+
}
|
|
15920
16007
|
if (!madeProgress) {
|
|
15921
16008
|
options.log.warn(
|
|
15922
16009
|
"[Render] Capture attempt made no forward progress; composition is likely structurally broken, not retrying.",
|
|
@@ -17026,7 +17113,7 @@ async function executeRenderPipeline(input) {
|
|
|
17026
17113
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
17027
17114
|
code: "start_browsers"
|
|
17028
17115
|
});
|
|
17029
|
-
let resolvedBrowserGpuMode = await
|
|
17116
|
+
let resolvedBrowserGpuMode = await resolveBrowserGpuMode2(cfg.browserGpuMode, {
|
|
17030
17117
|
chromePath: resolveHeadlessShellPath(cfg),
|
|
17031
17118
|
browserTimeout: cfg.browserTimeout
|
|
17032
17119
|
});
|
|
@@ -18246,6 +18333,7 @@ async function executeRenderPipeline(input) {
|
|
|
18246
18333
|
const isParallelStall = isParallelCaptureStallError(err);
|
|
18247
18334
|
const isEncoderDeath = isRetryableEncoderDeath(err);
|
|
18248
18335
|
const isCancellation = err instanceof RenderCancelledError || executionSignal.aborted === true;
|
|
18336
|
+
if (err instanceof CaptureStageError && err.memoryRetryUsed) throw err;
|
|
18249
18337
|
if (!shouldRetryViaPinnedFallback({
|
|
18250
18338
|
isVerifyError,
|
|
18251
18339
|
isDeCaptureError,
|
|
@@ -18389,10 +18477,7 @@ async function executeRenderPipeline(input) {
|
|
|
18389
18477
|
assertNotAborted,
|
|
18390
18478
|
onProgress
|
|
18391
18479
|
};
|
|
18392
|
-
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames
|
|
18393
|
-
workerCount: capturePlan.workerCount,
|
|
18394
|
-
cpuCount: cpuBudget()
|
|
18395
|
-
}) : null;
|
|
18480
|
+
const overlap = !cfg.useDrawElement && workerSizing !== void 0 && canEncodeWhileCapturing(encodeInput, capturePlan.workerCount, cpuBudget()) ? encodeWhileCapturing(encodeInput, totalFrames) : null;
|
|
18396
18481
|
const captureFrameStart = Date.now();
|
|
18397
18482
|
const invokeDiskCapture = (diskPlan) => observeRenderStage(
|
|
18398
18483
|
observability,
|
|
@@ -19514,7 +19599,8 @@ var SAFE_RENDER_ERROR_CODES = /* @__PURE__ */ new Set([
|
|
|
19514
19599
|
"VARIABLES_INVALID",
|
|
19515
19600
|
"OUTPUT_DIMENSIONS_MISMATCH",
|
|
19516
19601
|
"COMPOSITION_TOO_LARGE",
|
|
19517
|
-
"COMPILE_TIMEOUT"
|
|
19602
|
+
"COMPILE_TIMEOUT",
|
|
19603
|
+
"COMPOSITION_SCRIPT_FAILED"
|
|
19518
19604
|
]);
|
|
19519
19605
|
function extractSafeRenderErrorCode(error) {
|
|
19520
19606
|
if (typeof error !== "object" || error === null || !("code" in error)) return void 0;
|
|
@@ -19969,6 +20055,14 @@ function createSseProgressReporter(stream, requestId) {
|
|
|
19969
20055
|
});
|
|
19970
20056
|
};
|
|
19971
20057
|
}
|
|
20058
|
+
function renderFailureLogFields(job, safeError) {
|
|
20059
|
+
const failedPhase = job.errorDetails?.observability?.failedPhase;
|
|
20060
|
+
const errorCode = safeError?.errorCode;
|
|
20061
|
+
return {
|
|
20062
|
+
...failedPhase ? { failedPhase } : {},
|
|
20063
|
+
...errorCode ? { errorCode } : {}
|
|
20064
|
+
};
|
|
20065
|
+
}
|
|
19972
20066
|
async function writeRenderStreamFailure(input) {
|
|
19973
20067
|
const { error, job, stream, requestId, startedAtMs, log } = input;
|
|
19974
20068
|
if (error instanceof RenderCancelledError) {
|
|
@@ -19990,7 +20084,8 @@ async function writeRenderStreamFailure(input) {
|
|
|
19990
20084
|
requestId,
|
|
19991
20085
|
elapsedMs,
|
|
19992
20086
|
error: errorMsg,
|
|
19993
|
-
stage: job.currentStage
|
|
20087
|
+
stage: job.currentStage,
|
|
20088
|
+
...renderFailureLogFields(job, safeError)
|
|
19994
20089
|
});
|
|
19995
20090
|
await stream.writeSSE({
|
|
19996
20091
|
data: JSON.stringify({
|
|
@@ -20135,7 +20230,8 @@ function createRenderHandlers(options = {}) {
|
|
|
20135
20230
|
requestId,
|
|
20136
20231
|
durationMs,
|
|
20137
20232
|
error: errorMsg,
|
|
20138
|
-
stage: job.currentStage
|
|
20233
|
+
stage: job.currentStage,
|
|
20234
|
+
...renderFailureLogFields(job, safeError)
|
|
20139
20235
|
});
|
|
20140
20236
|
return c.json(
|
|
20141
20237
|
{
|
|
@@ -18,6 +18,9 @@ export interface CaptureCostEstimate {
|
|
|
18
18
|
reasons: string[];
|
|
19
19
|
p95Ms?: number;
|
|
20
20
|
medianMs?: number;
|
|
21
|
+
coresPerWorker?: number;
|
|
22
|
+
/** The browser's memory after the samples, which a page can allocate on its first drawn frame. */
|
|
23
|
+
browserRssMb?: number;
|
|
21
24
|
}
|
|
22
25
|
export interface CaptureCalibrationSample {
|
|
23
26
|
frameIndex: number;
|
|
@@ -74,6 +77,7 @@ firstFrame?: number): Promise<{
|
|
|
74
77
|
estimate: CaptureCostEstimate;
|
|
75
78
|
samples: CaptureCalibrationSample[];
|
|
76
79
|
}>;
|
|
80
|
+
export declare function chromeCoresUsed(before: ReadonlyMap<number, number> | undefined, after: ReadonlyMap<number, number> | undefined, elapsedMs: number): number | undefined;
|
|
77
81
|
export declare function logCaptureCalibrationResult(calibration: {
|
|
78
82
|
estimate: CaptureCostEstimate;
|
|
79
83
|
samples: CaptureCalibrationSample[];
|
|
@@ -2,6 +2,7 @@ import { CaptureFailure } from "@hyperframes/engine";
|
|
|
2
2
|
import { EncoderInterruptedError } from "./encoderInterruption.js";
|
|
3
3
|
export declare class CaptureStageError extends CaptureFailure {
|
|
4
4
|
readonly browserConsole: string[];
|
|
5
|
+
memoryRetryUsed: boolean;
|
|
5
6
|
constructor(input: {
|
|
6
7
|
cause: unknown;
|
|
7
8
|
browserConsole: string[];
|
|
@@ -0,0 +1,3 @@
|
|
|
1
|
+
import { spawnStreamingEncoder } from "@hyperframes/engine";
|
|
2
|
+
/** Starts an encoder that runs while frames are still being captured, one step below the capture's priority. */
|
|
3
|
+
export declare function spawnCaptureEncoder(...[outputPath, options, signal, config]: Parameters<typeof spawnStreamingEncoder>): ReturnType<typeof spawnStreamingEncoder>;
|
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
import { captureFrameToBuffer, closeCaptureSession, concatVideoFiles,
|
|
1
|
+
import { captureFrameToBuffer, closeCaptureSession, concatVideoFiles, type BeforeCaptureHook, type CaptureOptions, type CapturePerfSummary, type CaptureSession, type EngineConfig } from "@hyperframes/engine";
|
|
2
2
|
import type { FileServerHandle } from "../../fileServer.js";
|
|
3
3
|
import type { ProducerLogger } from "../../../logger.js";
|
|
4
4
|
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
|
|
5
5
|
import type { SdrSegmentedCapturePlan } from "../capturePlan.js";
|
|
6
6
|
import type { SegmentVideoFrames } from "../segmentVideoFrames.js";
|
|
7
7
|
import { type StreamingEncoderOptions } from "./captureStreamingStage.js";
|
|
8
|
+
import { spawnCaptureEncoder } from "./captureEncoder.js";
|
|
8
9
|
export interface SegmentedStageDeps {
|
|
9
|
-
spawnEncoder: typeof
|
|
10
|
+
spawnEncoder: typeof spawnCaptureEncoder;
|
|
10
11
|
captureFrame: typeof captureFrameToBuffer;
|
|
11
12
|
concat: typeof concatVideoFiles;
|
|
12
13
|
closeSession: typeof closeCaptureSession;
|
|
@@ -38,10 +38,11 @@
|
|
|
38
38
|
* Safe at runtime; a subsequent change will move the capture helpers
|
|
39
39
|
* into a shared module so the stages can import without reaching back.
|
|
40
40
|
*/
|
|
41
|
-
import { type BeforeCaptureHook, type CaptureOptions, type CapturePerfSummary, type CaptureSession, type EngineConfig
|
|
41
|
+
import { type BeforeCaptureHook, type CaptureOptions, type CapturePerfSummary, type CaptureSession, type EngineConfig } from "@hyperframes/engine";
|
|
42
42
|
import type { FileServerHandle } from "../../fileServer.js";
|
|
43
43
|
import type { ProducerLogger } from "../../../logger.js";
|
|
44
44
|
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
|
|
45
|
+
import { spawnCaptureEncoder } from "./captureEncoder.js";
|
|
45
46
|
import type { SdrStreamingCapturePlan } from "../capturePlan.js";
|
|
46
47
|
export declare function resolveCaptureStallTimeoutMs(): number;
|
|
47
48
|
export type StalledSession = {
|
|
@@ -72,7 +73,7 @@ export declare function createSessionInitBudget(input: {
|
|
|
72
73
|
* passes it through so the stage doesn't have to reach back for the
|
|
73
74
|
* preset's internal shape.
|
|
74
75
|
*/
|
|
75
|
-
export type StreamingEncoderOptions = Parameters<typeof
|
|
76
|
+
export type StreamingEncoderOptions = Parameters<typeof spawnCaptureEncoder>[1];
|
|
76
77
|
export interface CaptureStreamingStageInput {
|
|
77
78
|
fileServer: FileServerHandle;
|
|
78
79
|
workDir: string;
|
|
@@ -91,7 +92,7 @@ export interface CaptureStreamingStageInput {
|
|
|
91
92
|
probeSession: CaptureSession | null;
|
|
92
93
|
/** For the spawn-failure log message context only. */
|
|
93
94
|
outputFormat: string;
|
|
94
|
-
/** Pre-built encoder options; passed straight to `
|
|
95
|
+
/** Pre-built encoder options; passed straight to `spawnCaptureEncoder`. */
|
|
95
96
|
streamingEncoderOptions: StreamingEncoderOptions;
|
|
96
97
|
/**
|
|
97
98
|
* What the parallel workers capture with — "drawElement", "BeginFrame" or
|
|
@@ -32,7 +32,6 @@
|
|
|
32
32
|
* stage's encode if it fails.
|
|
33
33
|
*/
|
|
34
34
|
import { getEncoderPreset, type EngineConfig, type LandedFrame } from "@hyperframes/engine";
|
|
35
|
-
import { type Fps } from "@hyperframes/core";
|
|
36
35
|
import type { ProducerLogger } from "../../../logger.js";
|
|
37
36
|
import type { ProgressCallback, RenderJob } from "../../renderOrchestrator.js";
|
|
38
37
|
export interface EncodeStageInput {
|
|
@@ -105,27 +104,6 @@ export interface EncodeStageResult {
|
|
|
105
104
|
/** Wall-clock ms for the encode (or png-copy) phase. */
|
|
106
105
|
encodeMs: number;
|
|
107
106
|
}
|
|
108
|
-
export declare function overlapEncoderThreads(workerCount: number, cpuCount: number): number;
|
|
109
|
-
export declare function videoEncoderOptions(input: VideoEncodeInput, engineCfg: Pick<EngineConfig, "vp9CpuUsed">, softwareEncoderThreads?: number): {
|
|
110
|
-
fps: Fps;
|
|
111
|
-
width: number;
|
|
112
|
-
height: number;
|
|
113
|
-
codec: "h264" | "vp9" | "h265" | "prores";
|
|
114
|
-
preset: string;
|
|
115
|
-
quality: number;
|
|
116
|
-
bitrate: string | undefined;
|
|
117
|
-
maxBitrate: string | undefined;
|
|
118
|
-
bufferSize: string | undefined;
|
|
119
|
-
pixelFormat: string;
|
|
120
|
-
vp9CpuUsed: number;
|
|
121
|
-
useGpu: boolean | undefined;
|
|
122
|
-
hdr: {
|
|
123
|
-
transfer: import("@hyperframes/engine").HdrTransfer;
|
|
124
|
-
} | undefined;
|
|
125
|
-
lockGopForChunkConcat: boolean;
|
|
126
|
-
gopSize: number | undefined;
|
|
127
|
-
softwareEncoderThreads: number | undefined;
|
|
128
|
-
};
|
|
129
107
|
/**
|
|
130
108
|
* h264 from JPEG only, software or GPU: the streaming encoder then runs the disk encoder's
|
|
131
109
|
* arguments. Needs a core the capture workers leave free.
|
|
@@ -145,8 +123,5 @@ export interface EncodeWhileCapturing {
|
|
|
145
123
|
* Feeds frames 0, 1, 2… to the encoder as each lands; capture never waits on it.
|
|
146
124
|
* On failure `finish` re-runs `runEncodeStage` on the same frames.
|
|
147
125
|
*/
|
|
148
|
-
export declare function encodeWhileCapturing(input: VideoEncodeInput, totalFrames: number
|
|
149
|
-
workerCount: number;
|
|
150
|
-
cpuCount: number;
|
|
151
|
-
}): EncodeWhileCapturing;
|
|
126
|
+
export declare function encodeWhileCapturing(input: VideoEncodeInput, totalFrames: number): EncodeWhileCapturing;
|
|
152
127
|
export declare function runEncodeStage(input: EncodeStageInput): Promise<EncodeStageResult>;
|
|
@@ -486,6 +486,8 @@ export interface RenderJob extends Partial<ReferenceBackgroundResult> {
|
|
|
486
486
|
export type ProgressCallback = (job: RenderJob, message: string) => void | Promise<void>;
|
|
487
487
|
export declare class RenderQualityError extends Error {
|
|
488
488
|
readonly warnings: readonly RenderWarning[];
|
|
489
|
+
/** Set only when the composition's own script threw: rendering it again fails the same way. */
|
|
490
|
+
readonly code?: "COMPOSITION_SCRIPT_FAILED";
|
|
489
491
|
constructor(warnings: readonly RenderWarning[]);
|
|
490
492
|
}
|
|
491
493
|
export declare function applyRenderWarningPolicy(job: RenderJob, captureWarnings: readonly CaptureWarning[], log?: ProducerLogger): void;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@hyperframes/producer",
|
|
3
|
-
"version": "0.10.
|
|
3
|
+
"version": "0.10.6",
|
|
4
4
|
"description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
|
|
5
5
|
"repository": {
|
|
6
6
|
"type": "git",
|
|
@@ -35,12 +35,12 @@
|
|
|
35
35
|
"postcss": "^8.4.0",
|
|
36
36
|
"puppeteer": "~25.13.0",
|
|
37
37
|
"puppeteer-core": "^25.13.0",
|
|
38
|
-
"@hyperframes/
|
|
39
|
-
"@hyperframes/
|
|
40
|
-
"@hyperframes/
|
|
41
|
-
"@hyperframes/
|
|
42
|
-
"@hyperframes/
|
|
43
|
-
"@hyperframes/
|
|
38
|
+
"@hyperframes/engine": "0.10.6",
|
|
39
|
+
"@hyperframes/parsers": "0.10.6",
|
|
40
|
+
"@hyperframes/studio-server": "0.10.6",
|
|
41
|
+
"@hyperframes/share": "0.10.6",
|
|
42
|
+
"@hyperframes/lint": "0.10.6",
|
|
43
|
+
"@hyperframes/core": "0.10.6"
|
|
44
44
|
},
|
|
45
45
|
"devDependencies": {
|
|
46
46
|
"@types/node": "^25.0.10",
|
|
@@ -49,7 +49,7 @@
|
|
|
49
49
|
"tsx": "^4.21.0",
|
|
50
50
|
"typescript": "^5.7.2",
|
|
51
51
|
"vitest": "^4.1.12",
|
|
52
|
-
"@hyperframes/aws-lambda": "0.10.
|
|
52
|
+
"@hyperframes/aws-lambda": "0.10.6"
|
|
53
53
|
},
|
|
54
54
|
"engines": {
|
|
55
55
|
"node": ">=22.19.0"
|