@hyperframes/producer 0.9.31 → 0.9.32
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/README.md +1 -0
- package/dist/distributed.js +61 -15
- package/dist/index.js +182 -40
- package/dist/public-server.js +203 -50
- package/dist/renderRequest.d.ts +1 -0
- package/dist/server.d.ts +1 -0
- package/dist/services/distributed/projectHash.d.ts +1 -1
- package/dist/services/render/captureImageFormat.d.ts +14 -3
- package/dist/services/render/chromaSubsampling.d.ts +18 -0
- package/dist/services/render/shared.d.ts +1 -1
- package/dist/services/renderOrchestrator.d.ts +6 -2
- package/package.json +7 -7
package/dist/index.js
CHANGED
|
@@ -980,6 +980,33 @@ function resolveDeliveryEncoderOptions(config) {
|
|
|
980
980
|
return { maxBitrate, bufferSize, ...gop };
|
|
981
981
|
}
|
|
982
982
|
|
|
983
|
+
// src/services/render/chromaSubsampling.ts
|
|
984
|
+
function validateChromaSubsamplingConfig(config) {
|
|
985
|
+
if (config.chromaSubsampling !== "444") return;
|
|
986
|
+
const format = config.format ?? "mp4";
|
|
987
|
+
if (format !== "mp4") {
|
|
988
|
+
throw new Error(
|
|
989
|
+
`[Render] chromaSubsampling "444" supports format "mp4" only (got "${format}"). WebM, MOV and GIF use their own pixel formats, and HLS targets broad playback. Use --format mp4, or drop --chroma-subsampling 444.`
|
|
990
|
+
);
|
|
991
|
+
}
|
|
992
|
+
if (config.hdrMode === "force-hdr") {
|
|
993
|
+
throw new Error(
|
|
994
|
+
`[Render] chromaSubsampling "444" is SDR only; HDR output stays 10-bit 4:2:0 H.265. Drop --hdr, or drop --chroma-subsampling 444.`
|
|
995
|
+
);
|
|
996
|
+
}
|
|
997
|
+
if (config.useGpu === true) {
|
|
998
|
+
throw new Error(
|
|
999
|
+
`[Render] chromaSubsampling "444" requires the software encoder (libx264); GPU encoders do not reliably support 4:4:4. Re-run without --gpu.`
|
|
1000
|
+
);
|
|
1001
|
+
}
|
|
1002
|
+
}
|
|
1003
|
+
function assertChromaSubsamplingSdr(config, hasHdrContent) {
|
|
1004
|
+
if (config.chromaSubsampling !== "444" || !hasHdrContent) return;
|
|
1005
|
+
throw new Error(
|
|
1006
|
+
`[Render] chromaSubsampling "444" is SDR only, but this composition has HDR sources. Re-run with --sdr (hdrMode "force-sdr"), or drop --chroma-subsampling 444.`
|
|
1007
|
+
);
|
|
1008
|
+
}
|
|
1009
|
+
|
|
983
1010
|
// src/services/render/shared.ts
|
|
984
1011
|
import {
|
|
985
1012
|
copyFileSync,
|
|
@@ -995,6 +1022,9 @@ import {
|
|
|
995
1022
|
CANVAS_DIMENSIONS,
|
|
996
1023
|
checkOutputResolutionCompatibility
|
|
997
1024
|
} from "@hyperframes/core";
|
|
1025
|
+
import {
|
|
1026
|
+
mediaIdPathSegment
|
|
1027
|
+
} from "@hyperframes/engine";
|
|
998
1028
|
|
|
999
1029
|
// src/utils/paths.ts
|
|
1000
1030
|
import {
|
|
@@ -1089,6 +1119,10 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
|
|
|
1089
1119
|
writeFileSync(join3(compileDir, "index.html"), compiled.html, "utf-8");
|
|
1090
1120
|
for (const [srcPath, html] of compiled.subCompositions) {
|
|
1091
1121
|
const outPath = join3(compileDir, srcPath);
|
|
1122
|
+
if (!isPathInside2(outPath, compileDir)) {
|
|
1123
|
+
console.warn(`[Render] Skipping sub-composition with unsafe path: ${srcPath}`);
|
|
1124
|
+
continue;
|
|
1125
|
+
}
|
|
1092
1126
|
mkdirSync(dirname2(outPath), { recursive: true });
|
|
1093
1127
|
writeFileSync(outPath, html, "utf-8");
|
|
1094
1128
|
}
|
|
@@ -1350,7 +1384,7 @@ function materializeExtractedFramesForCompiledDir(extracted, compiledDir, option
|
|
|
1350
1384
|
for (const ext of extracted) {
|
|
1351
1385
|
const resolvedOut = pathModule.resolve(ext.outputDir);
|
|
1352
1386
|
if (isPathInside2(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
|
|
1353
|
-
const linkPath = pathModule.join(compiledFrameRoot, ext.videoId);
|
|
1387
|
+
const linkPath = pathModule.join(compiledFrameRoot, mediaIdPathSegment(ext.videoId));
|
|
1354
1388
|
if (!fileSystem.existsSync(linkPath)) {
|
|
1355
1389
|
fileSystem.mkdirSync(pathModule.dirname(linkPath), { recursive: true });
|
|
1356
1390
|
stageExtractedFrameDir(
|
|
@@ -5425,6 +5459,7 @@ import { dirname as dirname5, join as join11 } from "node:path";
|
|
|
5425
5459
|
import {
|
|
5426
5460
|
createFrameLookupTable,
|
|
5427
5461
|
extractVideoFramesRange,
|
|
5462
|
+
mediaIdPathSegment as mediaIdPathSegment2,
|
|
5428
5463
|
runVideoExtractionWithRetry
|
|
5429
5464
|
} from "@hyperframes/engine";
|
|
5430
5465
|
function contiguousRuns(sortedIndexes) {
|
|
@@ -5465,7 +5500,7 @@ async function extractDeferredFrames(input) {
|
|
|
5465
5500
|
const shown = shownDeferredFrameIndexes(input, input.frames, input.fps);
|
|
5466
5501
|
return Promise.all(
|
|
5467
5502
|
deferred.map(async (video) => {
|
|
5468
|
-
const outputDir = join11(input.outputRoot, video.videoId);
|
|
5503
|
+
const outputDir = join11(input.outputRoot, mediaIdPathSegment2(video.videoId));
|
|
5469
5504
|
const indexes = [...shown.get(video.videoId) ?? []].sort((a, b) => a - b);
|
|
5470
5505
|
if (indexes.length === 0) {
|
|
5471
5506
|
return { ...video, outputDir, framePaths: /* @__PURE__ */ new Map(), ownedByLookup: false };
|
|
@@ -9114,6 +9149,14 @@ function resolveEntryHtmlPath(input) {
|
|
|
9114
9149
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
9115
9150
|
return wrapperPath;
|
|
9116
9151
|
}
|
|
9152
|
+
function applyChroma444Gate(cfg, chromaSubsampling, gate, log) {
|
|
9153
|
+
if (!cfg.useDrawElement || chromaSubsampling !== "444") return gate;
|
|
9154
|
+
cfg.useDrawElement = false;
|
|
9155
|
+
log.info(
|
|
9156
|
+
"[Render] Fast capture: chromaSubsampling 444 captures lossless PNG frames, so disabling drawElementImage for this render. Capture uses the platform's baseline route."
|
|
9157
|
+
);
|
|
9158
|
+
return "chroma_444";
|
|
9159
|
+
}
|
|
9117
9160
|
async function runCompileStage(input) {
|
|
9118
9161
|
const {
|
|
9119
9162
|
projectDir,
|
|
@@ -9165,6 +9208,7 @@ async function runCompileStage(input) {
|
|
|
9165
9208
|
"[Render] Fast capture: composition uses shader transitions, so disabling drawElementImage so page-side compositing stays available."
|
|
9166
9209
|
);
|
|
9167
9210
|
}
|
|
9211
|
+
deCompileGate = applyChroma444Gate(cfg, job.config.chromaSubsampling, deCompileGate, log);
|
|
9168
9212
|
if (!cfg.useDrawElement && cfg.pageSideCompositingAutoDisabled) {
|
|
9169
9213
|
cfg.enablePageSideCompositing = true;
|
|
9170
9214
|
cfg.pageSideCompositingAutoDisabled = false;
|
|
@@ -9276,11 +9320,19 @@ function isActionableProbeFailure(line) {
|
|
|
9276
9320
|
|
|
9277
9321
|
// src/services/render/captureImageFormat.ts
|
|
9278
9322
|
function resolveCaptureImageFormat(input) {
|
|
9279
|
-
return input.needsAlpha || input.motionBlur ? "png" : "jpeg";
|
|
9323
|
+
return input.needsAlpha || input.motionBlur || input.chromaSubsampling === "444" ? "png" : "jpeg";
|
|
9280
9324
|
}
|
|
9281
9325
|
function resolveCaptureJpegQuality(quality) {
|
|
9282
9326
|
return quality === "draft" ? 80 : 100;
|
|
9283
9327
|
}
|
|
9328
|
+
function resolveCaptureSurface(input, quality) {
|
|
9329
|
+
const format = resolveCaptureImageFormat(input);
|
|
9330
|
+
return {
|
|
9331
|
+
format,
|
|
9332
|
+
quality: format === "png" ? void 0 : resolveCaptureJpegQuality(quality),
|
|
9333
|
+
transparent: input.needsAlpha
|
|
9334
|
+
};
|
|
9335
|
+
}
|
|
9284
9336
|
|
|
9285
9337
|
// src/services/render/stages/probeStage.ts
|
|
9286
9338
|
var FRAME_BOUNDARY_EPSILON = 1e-3;
|
|
@@ -9457,15 +9509,15 @@ async function runProbeStage(input) {
|
|
|
9457
9509
|
});
|
|
9458
9510
|
assertNotAborted();
|
|
9459
9511
|
const motionBlur = job.config.motionBlur;
|
|
9460
|
-
const captureFormat = resolveCaptureImageFormat({ needsAlpha, motionBlur });
|
|
9461
9512
|
const captureOpts = {
|
|
9462
9513
|
recordReferenceBackground: input.recordReferenceBackground,
|
|
9463
9514
|
width,
|
|
9464
9515
|
height,
|
|
9465
9516
|
fps: job.config.fps,
|
|
9466
|
-
|
|
9467
|
-
|
|
9468
|
-
|
|
9517
|
+
...resolveCaptureSurface(
|
|
9518
|
+
{ needsAlpha, motionBlur, chromaSubsampling: job.config.chromaSubsampling },
|
|
9519
|
+
job.config.quality
|
|
9520
|
+
),
|
|
9469
9521
|
variables: job.config.variables,
|
|
9470
9522
|
deviceScaleFactor,
|
|
9471
9523
|
motionBlur,
|
|
@@ -13379,13 +13431,20 @@ function resetCaptureAttemptProgress(job) {
|
|
|
13379
13431
|
job.framesRendered = 0;
|
|
13380
13432
|
}
|
|
13381
13433
|
var FIRST_FRAME_STALL_MS = 3e5;
|
|
13434
|
+
var FIRST_FRAME_STARTUP_FACTOR = 2;
|
|
13435
|
+
var FIRST_FRAME_STALL_CEILING_MS = 9e5;
|
|
13382
13436
|
var TAIL_STALL_MS = FIRST_FRAME_STALL_MS;
|
|
13383
|
-
function
|
|
13437
|
+
function firstFrameWindowMs(probeStartupMs) {
|
|
13438
|
+
const fromStartup = (probeStartupMs ?? 0) * FIRST_FRAME_STARTUP_FACTOR;
|
|
13439
|
+
if (!Number.isFinite(fromStartup)) return FIRST_FRAME_STALL_MS;
|
|
13440
|
+
return Math.max(FIRST_FRAME_STALL_MS, Math.min(FIRST_FRAME_STALL_CEILING_MS, fromStartup));
|
|
13441
|
+
}
|
|
13442
|
+
function frameStallRule(job, totalFrames, probeStartupMs) {
|
|
13384
13443
|
const noProgressMs = resolveCaptureStallTimeoutMs();
|
|
13385
13444
|
return {
|
|
13386
13445
|
progress: () => job.framesRendered ?? 0,
|
|
13387
13446
|
noProgressMs,
|
|
13388
|
-
firstProgressMs: Math.max(
|
|
13447
|
+
firstProgressMs: Math.max(firstFrameWindowMs(probeStartupMs), noProgressMs),
|
|
13389
13448
|
complete: () => (job.framesRendered ?? 0) >= totalFrames,
|
|
13390
13449
|
tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
|
|
13391
13450
|
detail: () => describeWorkerPhases(job),
|
|
@@ -14077,6 +14136,7 @@ function resolveRenderDebugDir() {
|
|
|
14077
14136
|
async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
14078
14137
|
validateHlsRenderConfig(job.config);
|
|
14079
14138
|
validateDeliveryEncoderConfig(job.config);
|
|
14139
|
+
validateChromaSubsamplingConfig(job.config);
|
|
14080
14140
|
const debugDir = resolveRenderDebugDir();
|
|
14081
14141
|
const outputDir = dirname13(outputPath);
|
|
14082
14142
|
if (!existsSync22(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
@@ -14614,18 +14674,28 @@ async function executeRenderPipeline(input) {
|
|
|
14614
14674
|
forceScreenshot: captureForceScreenshot
|
|
14615
14675
|
});
|
|
14616
14676
|
const videoCaptureBeyondViewport = resolveVideoCaptureBeyondViewport(composition.videos.length);
|
|
14617
|
-
const
|
|
14618
|
-
|
|
14619
|
-
|
|
14620
|
-
|
|
14677
|
+
const captureSurface = resolveCaptureSurface(
|
|
14678
|
+
{
|
|
14679
|
+
needsAlpha,
|
|
14680
|
+
motionBlur: job.config.motionBlur,
|
|
14681
|
+
chromaSubsampling: job.config.chromaSubsampling
|
|
14682
|
+
},
|
|
14683
|
+
job.config.quality
|
|
14684
|
+
);
|
|
14685
|
+
if (job.config.chromaSubsampling === "444") {
|
|
14686
|
+
log.info("[Render] Capture: png (chromaSubsampling 444, lossless)");
|
|
14687
|
+
}
|
|
14621
14688
|
const captureOptions = {
|
|
14622
14689
|
width,
|
|
14623
14690
|
height,
|
|
14624
14691
|
fps: job.config.fps,
|
|
14625
|
-
|
|
14626
|
-
|
|
14627
|
-
|
|
14628
|
-
|
|
14692
|
+
...captureSurface,
|
|
14693
|
+
...videoLayer ? {
|
|
14694
|
+
format: "png",
|
|
14695
|
+
quality: void 0,
|
|
14696
|
+
transparent: true,
|
|
14697
|
+
hiddenElementIds: [videoLayer.videoId]
|
|
14698
|
+
} : {},
|
|
14629
14699
|
variables: job.config.variables,
|
|
14630
14700
|
deviceScaleFactor,
|
|
14631
14701
|
motionBlur: job.config.motionBlur,
|
|
@@ -14732,6 +14802,7 @@ async function executeRenderPipeline(input) {
|
|
|
14732
14802
|
);
|
|
14733
14803
|
const nativeHdrIds = /* @__PURE__ */ new Set([...nativeHdrVideoIds, ...nativeHdrImageIds]);
|
|
14734
14804
|
const hasHdrContent = Boolean(effectiveHdr && nativeHdrIds.size > 0);
|
|
14805
|
+
assertChromaSubsamplingSdr(job.config, hasHdrContent);
|
|
14735
14806
|
if (hasHdrContent) assertOutputScaleSupported(deviceScaleFactor, "hdr_layered");
|
|
14736
14807
|
routePageMotionBlur = pageMotionBlurForRoute({ hasHdrContent, useLayeredComposite: false });
|
|
14737
14808
|
const deSingleMinFrames = resolveDeSingleMinFrames(process.env);
|
|
@@ -15314,7 +15385,9 @@ async function executeRenderPipeline(input) {
|
|
|
15314
15385
|
usePageSideCompositing: capturePlan.usePageSideCompositing,
|
|
15315
15386
|
hasHdrContent: capturePlan.hasHdrContent,
|
|
15316
15387
|
hasShaderTransitions: compiled.hasShaderTransitions,
|
|
15317
|
-
isPngSequence
|
|
15388
|
+
isPngSequence,
|
|
15389
|
+
captureImageFormat: captureOptions.format ?? "jpeg",
|
|
15390
|
+
chromaSubsampling: job.config.chromaSubsampling ?? "420"
|
|
15318
15391
|
});
|
|
15319
15392
|
const encoderHdr = hasHdrContent ? effectiveHdr : void 0;
|
|
15320
15393
|
const presetFormat = outputFormat === "webm" || outputFormat === "mov" ? outputFormat : "mp4";
|
|
@@ -15322,7 +15395,8 @@ async function executeRenderPipeline(input) {
|
|
|
15322
15395
|
job.config.quality,
|
|
15323
15396
|
presetFormat,
|
|
15324
15397
|
encoderHdr,
|
|
15325
|
-
job.config.proresProfile
|
|
15398
|
+
job.config.proresProfile,
|
|
15399
|
+
job.config.chromaSubsampling
|
|
15326
15400
|
);
|
|
15327
15401
|
if (job.config.crf != null && job.config.videoBitrate) {
|
|
15328
15402
|
log.warn(
|
|
@@ -15404,7 +15478,7 @@ async function executeRenderPipeline(input) {
|
|
|
15404
15478
|
onProgress
|
|
15405
15479
|
});
|
|
15406
15480
|
},
|
|
15407
|
-
{ stall: frameStallRule(job, totalFrames) }
|
|
15481
|
+
{ stall: frameStallRule(job, totalFrames, perfStages.browserProbeMs) }
|
|
15408
15482
|
);
|
|
15409
15483
|
lastBrowserConsole = hdrRes.lastBrowserConsole;
|
|
15410
15484
|
layeredCaptureWarnings.push(...hdrRes.warnings);
|
|
@@ -15856,7 +15930,7 @@ async function executeRenderPipeline(input) {
|
|
|
15856
15930
|
interleaveFrames: overlap !== null,
|
|
15857
15931
|
openAttempt
|
|
15858
15932
|
}),
|
|
15859
|
-
{ stall: frameStallRule(job, totalFrames) }
|
|
15933
|
+
{ stall: frameStallRule(job, totalFrames, perfStages.browserProbeMs) }
|
|
15860
15934
|
);
|
|
15861
15935
|
let captureRes;
|
|
15862
15936
|
try {
|
|
@@ -16615,7 +16689,8 @@ import { existsSync as existsSync24, readdirSync as readdirSync7 } from "node:fs
|
|
|
16615
16689
|
import { extname as extname4, join as join34 } from "node:path";
|
|
16616
16690
|
import {
|
|
16617
16691
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
16618
|
-
createVideoFrameInjector as createVideoFrameInjector3
|
|
16692
|
+
createVideoFrameInjector as createVideoFrameInjector3,
|
|
16693
|
+
mediaIdPathSegment as mediaIdPathSegment3
|
|
16619
16694
|
} from "@hyperframes/engine";
|
|
16620
16695
|
|
|
16621
16696
|
// src/services/distributed/shared.ts
|
|
@@ -16952,7 +17027,7 @@ function frameNumberFromFileName(name) {
|
|
|
16952
17027
|
function rebuildExtractedFramesFromPlanDir(planDir, videos, indexMode = "dense-v1") {
|
|
16953
17028
|
const result = [];
|
|
16954
17029
|
for (const v of videos) {
|
|
16955
|
-
const outputDir = join34(planDir, "video-frames", v.videoId);
|
|
17030
|
+
const outputDir = join34(planDir, "video-frames", mediaIdPathSegment3(v.videoId));
|
|
16956
17031
|
if (!existsSync24(outputDir)) {
|
|
16957
17032
|
throw new Error(
|
|
16958
17033
|
`[renderChunk] planDir missing extracted video frames for ${JSON.stringify(v.videoId)}: ${outputDir} not present. plan() should have written frames here; the planDir is malformed.`
|
|
@@ -18881,7 +18956,11 @@ import {
|
|
|
18881
18956
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
18882
18957
|
import { dirname as dirname17, isAbsolute as isAbsolute4, join as join43, relative as relative6, resolve as resolve10, sep as sep4 } from "node:path";
|
|
18883
18958
|
import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
|
|
18884
|
-
import {
|
|
18959
|
+
import {
|
|
18960
|
+
createFrameLookupTable as createFrameLookupTable5,
|
|
18961
|
+
mediaIdPathSegment as mediaIdPathSegment4,
|
|
18962
|
+
renameWithRetry as renameWithRetry10
|
|
18963
|
+
} from "@hyperframes/engine";
|
|
18885
18964
|
|
|
18886
18965
|
// src/services/distributed/planV2Publisher.ts
|
|
18887
18966
|
import {
|
|
@@ -19086,7 +19165,7 @@ function isExtractionCacheCompleteSentinelPath(path) {
|
|
|
19086
19165
|
}
|
|
19087
19166
|
function resolveExtractedVideoOutputDir(planDir, videoId) {
|
|
19088
19167
|
const videoRoot = resolve10(planDir, "video-frames");
|
|
19089
|
-
const outputDir = resolve10(videoRoot, videoId);
|
|
19168
|
+
const outputDir = resolve10(videoRoot, mediaIdPathSegment4(videoId));
|
|
19090
19169
|
if (outputDir === videoRoot || !outputDir.startsWith(`${videoRoot}${sep4}`)) {
|
|
19091
19170
|
throw new PlanV2IntegrityError(`unsafe extracted video id: ${JSON.stringify(videoId)}`);
|
|
19092
19171
|
}
|
|
@@ -20309,7 +20388,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
|
|
|
20309
20388
|
openAttempt,
|
|
20310
20389
|
verifyFirstSession: forceScreenshot || !verifyInWorker ? void 0 : verifyFirstWorker
|
|
20311
20390
|
}),
|
|
20312
|
-
{ stall: frameStallRule(job, framesInChunk) }
|
|
20391
|
+
{ stall: frameStallRule(job, framesInChunk, void 0) }
|
|
20313
20392
|
).catch(async (captureError) => {
|
|
20314
20393
|
await overlap.current?.abort();
|
|
20315
20394
|
overlap.current = null;
|
|
@@ -20741,6 +20820,13 @@ function validateDistributedRenderConfig(config) {
|
|
|
20741
20820
|
`distributed mode supports only ${ALLOWED_HDR_MODES.join(", ")}; got ${String(config.hdrMode)}`
|
|
20742
20821
|
);
|
|
20743
20822
|
}
|
|
20823
|
+
const chromaSubsampling = config.chromaSubsampling;
|
|
20824
|
+
if (chromaSubsampling !== void 0 && chromaSubsampling !== "420") {
|
|
20825
|
+
throw new InvalidConfigError(
|
|
20826
|
+
"config.chromaSubsampling",
|
|
20827
|
+
`distributed mode encodes 4:2:0 only; got ${String(chromaSubsampling)}`
|
|
20828
|
+
);
|
|
20829
|
+
}
|
|
20744
20830
|
if (config.variables !== void 0) {
|
|
20745
20831
|
validateVariablesPayload(config.variables);
|
|
20746
20832
|
}
|
|
@@ -20924,6 +21010,7 @@ function assertRequestOptionScalars(options) {
|
|
|
20924
21010
|
assertOptionalEnum(options, "proresProfile", PRORES_PROFILE_NAMES2);
|
|
20925
21011
|
assertOptionalEnum(options, "strictness", ["strict", "best-effort"]);
|
|
20926
21012
|
assertOptionalEnum(options, "hdrMode", ["auto", "force-hdr", "force-sdr"]);
|
|
21013
|
+
assertOptionalEnum(options, "chromaSubsampling", ["420", "444"]);
|
|
20927
21014
|
assertOptionalEnum(options, "pageMotionBlur", ["off"]);
|
|
20928
21015
|
if (options.videoFrameFormat !== void 0 && !isVideoFrameFormat2(options.videoFrameFormat)) {
|
|
20929
21016
|
throw new Error("Render request videoFrameFormat is invalid");
|
|
@@ -21012,6 +21099,11 @@ function distributedConfigFromRequest(request, runtime = {}) {
|
|
|
21012
21099
|
if (options.hdrMode === "force-hdr") {
|
|
21013
21100
|
throw new Error("Distributed render does not support force-hdr");
|
|
21014
21101
|
}
|
|
21102
|
+
if (options.chromaSubsampling === "444") {
|
|
21103
|
+
throw new Error(
|
|
21104
|
+
"Distributed render does not support chromaSubsampling 444: chunk workers and the assemble encode 4:2:0"
|
|
21105
|
+
);
|
|
21106
|
+
}
|
|
21015
21107
|
return {
|
|
21016
21108
|
fps: distributedFps(options.fps),
|
|
21017
21109
|
width: distributed.width,
|
|
@@ -21418,7 +21510,15 @@ function parseRenderOptions(body) {
|
|
|
21418
21510
|
const format = parseServerFormat(body.format);
|
|
21419
21511
|
const outputDynamicRange = parseServerOutputDynamicRange(body.outputDynamicRange) ?? fromRenderHdrMode(parseLegacyServerHdrMode(body.hdrMode));
|
|
21420
21512
|
const encoder = parseEncoderOptions(body, format ?? "mp4");
|
|
21421
|
-
const {
|
|
21513
|
+
const {
|
|
21514
|
+
crf,
|
|
21515
|
+
videoBitrate,
|
|
21516
|
+
videoFrameFormat,
|
|
21517
|
+
keyframeIntervalSeconds,
|
|
21518
|
+
maxBitrate,
|
|
21519
|
+
bufferSize,
|
|
21520
|
+
chromaSubsampling
|
|
21521
|
+
} = encoder.ok ? encoder.options : {};
|
|
21422
21522
|
const { variables, outputResolution, outputResolutionAspectAgnostic } = parseRenderOverrides(body);
|
|
21423
21523
|
return {
|
|
21424
21524
|
outputPath,
|
|
@@ -21431,6 +21531,7 @@ function parseRenderOptions(body) {
|
|
|
21431
21531
|
keyframeIntervalSeconds,
|
|
21432
21532
|
maxBitrate,
|
|
21433
21533
|
bufferSize,
|
|
21534
|
+
chromaSubsampling,
|
|
21434
21535
|
useGpu,
|
|
21435
21536
|
debug,
|
|
21436
21537
|
forceScreenshot,
|
|
@@ -21470,6 +21571,7 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
21470
21571
|
keyframeIntervalSeconds: input.keyframeIntervalSeconds,
|
|
21471
21572
|
maxBitrate: input.maxBitrate,
|
|
21472
21573
|
bufferSize: input.bufferSize,
|
|
21574
|
+
chromaSubsampling: input.chromaSubsampling,
|
|
21473
21575
|
useGpu: input.useGpu,
|
|
21474
21576
|
debug: input.debug,
|
|
21475
21577
|
strictness: input.strictness,
|
|
@@ -21491,12 +21593,25 @@ function resolvePreparedRenderOutput(prepared, rendersDir, log) {
|
|
|
21491
21593
|
if (!existsSync33(outputDir)) mkdirSync21(outputDir, { recursive: true });
|
|
21492
21594
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
21493
21595
|
}
|
|
21596
|
+
function prepareRenderJob(prepared, rendersDir, log) {
|
|
21597
|
+
try {
|
|
21598
|
+
const output = resolvePreparedRenderOutput(prepared, rendersDir, log);
|
|
21599
|
+
const job = createRenderJob(buildRenderJobConfig(output.input, output.absoluteOutputPath, log));
|
|
21600
|
+
return { ...output, job };
|
|
21601
|
+
} catch (error) {
|
|
21602
|
+
cleanupTempDir(prepared.cleanupProjectDir, log);
|
|
21603
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
21604
|
+
}
|
|
21605
|
+
}
|
|
21494
21606
|
function validateRenderOverrides(body) {
|
|
21495
21607
|
const encoder = parseEncoderOptions(body, parseServerFormat(body.format) ?? "mp4");
|
|
21496
21608
|
if (!encoder.ok) return encoder.error;
|
|
21497
21609
|
if (body.maxRenderMs !== void 0 && (typeof body.maxRenderMs !== "number" || !Number.isInteger(body.maxRenderMs) || body.maxRenderMs < 0)) {
|
|
21498
21610
|
return "maxRenderMs must be a non-negative integer number of milliseconds";
|
|
21499
21611
|
}
|
|
21612
|
+
if (typeof body.workers === "number" && (!Number.isInteger(body.workers) || body.workers < 1)) {
|
|
21613
|
+
return "workers must be a positive integer";
|
|
21614
|
+
}
|
|
21500
21615
|
if (body.variables !== void 0 && !isPlainObject2(body.variables)) {
|
|
21501
21616
|
return 'variables must be a JSON object keyed by variable id (e.g. {"title":"Hello"})';
|
|
21502
21617
|
}
|
|
@@ -21511,6 +21626,9 @@ function validateRenderOverrides(body) {
|
|
|
21511
21626
|
if (outputDynamicRange !== void 0 && legacyHdrMode !== void 0 && outputDynamicRange !== fromRenderHdrMode(legacyHdrMode)) {
|
|
21512
21627
|
return "outputDynamicRange and legacy hdrMode must describe the same output policy";
|
|
21513
21628
|
}
|
|
21629
|
+
if (body.chromaSubsampling === "444" && outputDynamicRange === "hdr") {
|
|
21630
|
+
return 'chromaSubsampling "444" is SDR only, not outputDynamicRange "hdr"';
|
|
21631
|
+
}
|
|
21514
21632
|
return validateOutputResolutionOverride(body);
|
|
21515
21633
|
}
|
|
21516
21634
|
function validateOutputResolutionOverride(body) {
|
|
@@ -21774,11 +21892,11 @@ function createRenderHandlers(options = {}) {
|
|
|
21774
21892
|
if ("error" in preparedResult) {
|
|
21775
21893
|
return c.json({ success: false, requestId, error: preparedResult.error }, 400);
|
|
21776
21894
|
}
|
|
21777
|
-
const
|
|
21778
|
-
|
|
21779
|
-
|
|
21780
|
-
|
|
21781
|
-
|
|
21895
|
+
const preparedJob = prepareRenderJob(preparedResult.prepared, rendersDir, log);
|
|
21896
|
+
if ("error" in preparedJob) {
|
|
21897
|
+
return c.json({ success: false, requestId, error: preparedJob.error }, 400);
|
|
21898
|
+
}
|
|
21899
|
+
const { job, input, cleanupProjectDir, absoluteOutputPath } = preparedJob;
|
|
21782
21900
|
const release = await renderSemaphore.acquire();
|
|
21783
21901
|
log.info("render started", {
|
|
21784
21902
|
requestId,
|
|
@@ -21786,7 +21904,6 @@ function createRenderHandlers(options = {}) {
|
|
|
21786
21904
|
fps: input.fps,
|
|
21787
21905
|
quality: input.quality
|
|
21788
21906
|
});
|
|
21789
|
-
const job = createRenderJob(buildRenderJobConfig(input, absoluteOutputPath, log));
|
|
21790
21907
|
try {
|
|
21791
21908
|
await executeRenderJob(
|
|
21792
21909
|
job,
|
|
@@ -21854,13 +21971,20 @@ function createRenderHandlers(options = {}) {
|
|
|
21854
21971
|
const t0 = Date.now();
|
|
21855
21972
|
const prepared = await prepareSseRenderRequest(c, stream, requestId);
|
|
21856
21973
|
if (!prepared) return;
|
|
21857
|
-
const
|
|
21858
|
-
|
|
21859
|
-
|
|
21860
|
-
|
|
21861
|
-
|
|
21974
|
+
const preparedJob = prepareRenderJob(prepared, rendersDir, log);
|
|
21975
|
+
if ("error" in preparedJob) {
|
|
21976
|
+
await stream.writeSSE({
|
|
21977
|
+
data: JSON.stringify({
|
|
21978
|
+
type: "error",
|
|
21979
|
+
requestId,
|
|
21980
|
+
error: preparedJob.error,
|
|
21981
|
+
stage: "validation"
|
|
21982
|
+
})
|
|
21983
|
+
});
|
|
21984
|
+
return;
|
|
21985
|
+
}
|
|
21986
|
+
const { job, input, cleanupProjectDir, absoluteOutputPath } = preparedJob;
|
|
21862
21987
|
log.info("render-stream started", { requestId, projectDir: input.projectDir });
|
|
21863
|
-
const job = createRenderJob(buildRenderJobConfig(input, absoluteOutputPath, log));
|
|
21864
21988
|
const abortController = new AbortController();
|
|
21865
21989
|
const onRequestAbort = () => abortController.abort(new RenderCancelledError("request_aborted"));
|
|
21866
21990
|
c.req.raw.signal.addEventListener("abort", onRequestAbort, { once: true });
|
|
@@ -21904,7 +22028,8 @@ function createRenderHandlers(options = {}) {
|
|
|
21904
22028
|
videoDurationSeconds: job.duration ?? null,
|
|
21905
22029
|
outcome: job.outcome ?? "completed",
|
|
21906
22030
|
warnings: job.warnings,
|
|
21907
|
-
perf: job.perfSummary ?? null
|
|
22031
|
+
perf: job.perfSummary ?? null,
|
|
22032
|
+
producerVersion: readProducerVersion()
|
|
21908
22033
|
})
|
|
21909
22034
|
});
|
|
21910
22035
|
} catch (error) {
|
|
@@ -21949,9 +22074,26 @@ function createRenderHandlers(options = {}) {
|
|
|
21949
22074
|
});
|
|
21950
22075
|
return { render, renderStream, lint, health, outputs, queue };
|
|
21951
22076
|
}
|
|
22077
|
+
function isCrossOriginBrowserRequest(c) {
|
|
22078
|
+
const fetchSite = c.req.header("sec-fetch-site");
|
|
22079
|
+
if (fetchSite) return fetchSite !== "same-origin" && fetchSite !== "none";
|
|
22080
|
+
const origin = c.req.header("origin");
|
|
22081
|
+
if (!origin) return false;
|
|
22082
|
+
try {
|
|
22083
|
+
return new URL(origin).host !== c.req.header("host");
|
|
22084
|
+
} catch {
|
|
22085
|
+
return true;
|
|
22086
|
+
}
|
|
22087
|
+
}
|
|
21952
22088
|
function createProducerApp(options = {}) {
|
|
21953
22089
|
const app = new Hono2();
|
|
21954
22090
|
const handlers = createRenderHandlers(options);
|
|
22091
|
+
app.post("*", async (c, next) => {
|
|
22092
|
+
if (isCrossOriginBrowserRequest(c)) {
|
|
22093
|
+
return c.json({ success: false, error: "Cross-origin requests are not allowed" }, 403);
|
|
22094
|
+
}
|
|
22095
|
+
await next();
|
|
22096
|
+
});
|
|
21955
22097
|
app.get("/health", handlers.health);
|
|
21956
22098
|
app.post("/render", handlers.render);
|
|
21957
22099
|
app.post("/render/stream", handlers.renderStream);
|