@hyperframes/producer 0.9.31 → 0.9.33
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 +271 -175
- package/dist/hyperframe.manifest.json +1 -1
- package/dist/hyperframe.runtime.iife.js +42 -42
- package/dist/index.js +416 -218
- package/dist/public-server.js +364 -156
- 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/observability.d.ts +2 -0
- package/dist/services/render/shared.d.ts +4 -1
- package/dist/services/render/stages/probeStage.d.ts +2 -1
- package/dist/services/renderOrchestrator.d.ts +6 -2
- package/dist/utils/paths.d.ts +0 -2
- package/package.json +7 -7
package/dist/public-server.js
CHANGED
|
@@ -10,7 +10,7 @@ import {
|
|
|
10
10
|
rmSync as rmSync13,
|
|
11
11
|
createReadStream as createReadStream3
|
|
12
12
|
} from "node:fs";
|
|
13
|
-
import { resolve as resolve10, dirname as
|
|
13
|
+
import { resolve as resolve10, dirname as dirname16, join as join36 } from "node:path";
|
|
14
14
|
import { tmpdir as tmpdir3 } from "node:os";
|
|
15
15
|
import { parseArgs } from "node:util";
|
|
16
16
|
import crypto from "node:crypto";
|
|
@@ -26,7 +26,7 @@ import {
|
|
|
26
26
|
// src/services/renderOrchestrator.ts
|
|
27
27
|
import { audioFailureDiagnostics as audioFailureDiagnostics2 } from "@hyperframes/engine";
|
|
28
28
|
import {
|
|
29
|
-
existsSync as
|
|
29
|
+
existsSync as existsSync21,
|
|
30
30
|
mkdirSync as mkdirSync12,
|
|
31
31
|
readdirSync as readdirSync6,
|
|
32
32
|
rmSync as rmSync12,
|
|
@@ -223,7 +223,9 @@ function createConsoleLogger(level = "info") {
|
|
|
223
223
|
}
|
|
224
224
|
};
|
|
225
225
|
}
|
|
226
|
-
var defaultLogger = createConsoleLogger(
|
|
226
|
+
var defaultLogger = createConsoleLogger(
|
|
227
|
+
process.env.HF_DEBUG_RENDER === "1" ? "debug" : "info"
|
|
228
|
+
);
|
|
227
229
|
|
|
228
230
|
// src/services/fileServer.ts
|
|
229
231
|
var readFileAsync = promisify(readFile);
|
|
@@ -994,11 +996,38 @@ function resolveDeliveryEncoderOptions(config) {
|
|
|
994
996
|
return { maxBitrate, bufferSize, ...gop };
|
|
995
997
|
}
|
|
996
998
|
|
|
999
|
+
// src/services/render/chromaSubsampling.ts
|
|
1000
|
+
function validateChromaSubsamplingConfig(config) {
|
|
1001
|
+
if (config.chromaSubsampling !== "444") return;
|
|
1002
|
+
const format = config.format ?? "mp4";
|
|
1003
|
+
if (format !== "mp4") {
|
|
1004
|
+
throw new Error(
|
|
1005
|
+
`[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.`
|
|
1006
|
+
);
|
|
1007
|
+
}
|
|
1008
|
+
if (config.hdrMode === "force-hdr") {
|
|
1009
|
+
throw new Error(
|
|
1010
|
+
`[Render] chromaSubsampling "444" is SDR only; HDR output stays 10-bit 4:2:0 H.265. Drop --hdr, or drop --chroma-subsampling 444.`
|
|
1011
|
+
);
|
|
1012
|
+
}
|
|
1013
|
+
if (config.useGpu === true) {
|
|
1014
|
+
throw new Error(
|
|
1015
|
+
`[Render] chromaSubsampling "444" requires the software encoder (libx264); GPU encoders do not reliably support 4:4:4. Re-run without --gpu.`
|
|
1016
|
+
);
|
|
1017
|
+
}
|
|
1018
|
+
}
|
|
1019
|
+
function assertChromaSubsamplingSdr(config, hasHdrContent) {
|
|
1020
|
+
if (config.chromaSubsampling !== "444" || !hasHdrContent) return;
|
|
1021
|
+
throw new Error(
|
|
1022
|
+
`[Render] chromaSubsampling "444" is SDR only, but this composition has HDR sources. Re-run with --sdr (hdrMode "force-sdr"), or drop --chroma-subsampling 444.`
|
|
1023
|
+
);
|
|
1024
|
+
}
|
|
1025
|
+
|
|
997
1026
|
// src/services/render/shared.ts
|
|
998
1027
|
import {
|
|
999
1028
|
copyFileSync,
|
|
1000
1029
|
cpSync,
|
|
1001
|
-
existsSync as
|
|
1030
|
+
existsSync as existsSync3,
|
|
1002
1031
|
mkdirSync,
|
|
1003
1032
|
rmSync,
|
|
1004
1033
|
symlinkSync,
|
|
@@ -1009,6 +1038,9 @@ import {
|
|
|
1009
1038
|
CANVAS_DIMENSIONS,
|
|
1010
1039
|
checkOutputResolutionCompatibility
|
|
1011
1040
|
} from "@hyperframes/core";
|
|
1041
|
+
import {
|
|
1042
|
+
mediaIdPathSegment
|
|
1043
|
+
} from "@hyperframes/engine";
|
|
1012
1044
|
|
|
1013
1045
|
// src/utils/paths.ts
|
|
1014
1046
|
import {
|
|
@@ -1018,9 +1050,7 @@ import {
|
|
|
1018
1050
|
relative as nodeRelative,
|
|
1019
1051
|
isAbsolute as nodeIsAbsolute
|
|
1020
1052
|
} from "node:path";
|
|
1021
|
-
import { existsSync as existsSync3 } from "node:fs";
|
|
1022
1053
|
import { fileURLToPath as fileURLToPath2 } from "node:url";
|
|
1023
|
-
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
1024
1054
|
var DEFAULT_RENDERS_DIR = process.env.PRODUCER_RENDERS_DIR ?? // fileURLToPath (not URL.pathname): on Windows .pathname is "/D:/..." which
|
|
1025
1055
|
// resolves to a bogus renders dir.
|
|
1026
1056
|
nodeResolve(fileURLToPath2(import.meta.url), "../../..", "renders");
|
|
@@ -1058,13 +1088,6 @@ function resolveRenderPaths(projectDir, outputPath, rendersDir = DEFAULT_RENDERS
|
|
|
1058
1088
|
const absoluteOutputPath = nodeResolve(resolvedOutputPath);
|
|
1059
1089
|
return { absoluteProjectDir, absoluteOutputPath };
|
|
1060
1090
|
}
|
|
1061
|
-
function resolveCompositionSrc(projectDir, src) {
|
|
1062
|
-
const rooted = (value) => nodeResolve(projectDir, value.replace(/^(?:\.?[\\/])+/, ""));
|
|
1063
|
-
const decoded = rooted(decodedUrlPath(src));
|
|
1064
|
-
if (!isPathInside2(decoded, projectDir)) return null;
|
|
1065
|
-
const raw = rooted(src);
|
|
1066
|
-
return !existsSync3(decoded) && isPathInside2(raw, projectDir) && existsSync3(raw) ? raw : decoded;
|
|
1067
|
-
}
|
|
1068
1091
|
|
|
1069
1092
|
// src/services/render/shared.ts
|
|
1070
1093
|
var BROWSER_MEDIA_EPSILON = 1e-4;
|
|
@@ -1103,6 +1126,10 @@ function writeCompiledArtifacts(compiled, workDir, includeSummary) {
|
|
|
1103
1126
|
writeFileSync(join3(compileDir, "index.html"), compiled.html, "utf-8");
|
|
1104
1127
|
for (const [srcPath, html] of compiled.subCompositions) {
|
|
1105
1128
|
const outPath = join3(compileDir, srcPath);
|
|
1129
|
+
if (!isPathInside2(outPath, compileDir)) {
|
|
1130
|
+
console.warn(`[Render] Skipping sub-composition with unsafe path: ${srcPath}`);
|
|
1131
|
+
continue;
|
|
1132
|
+
}
|
|
1106
1133
|
mkdirSync(dirname2(outPath), { recursive: true });
|
|
1107
1134
|
writeFileSync(outPath, html, "utf-8");
|
|
1108
1135
|
}
|
|
@@ -1235,6 +1262,13 @@ var workerPhasesByJob = /* @__PURE__ */ new WeakMap();
|
|
|
1235
1262
|
function forgetWorkerPhases(job) {
|
|
1236
1263
|
workerPhasesByJob.delete(job);
|
|
1237
1264
|
}
|
|
1265
|
+
var staticDedupActivityByJob = /* @__PURE__ */ new WeakMap();
|
|
1266
|
+
function noteStaticDedupActivity(job) {
|
|
1267
|
+
staticDedupActivityByJob.set(job, (staticDedupActivityByJob.get(job) ?? 0) + 1);
|
|
1268
|
+
}
|
|
1269
|
+
function staticDedupActivity(job) {
|
|
1270
|
+
return staticDedupActivityByJob.get(job) ?? 0;
|
|
1271
|
+
}
|
|
1238
1272
|
function describeWorkerPhases(job) {
|
|
1239
1273
|
const phases = workerPhasesByJob.get(job);
|
|
1240
1274
|
if (!phases?.size) return void 0;
|
|
@@ -1268,7 +1302,7 @@ var materializePathModule = {
|
|
|
1268
1302
|
isAbsolute
|
|
1269
1303
|
};
|
|
1270
1304
|
var materializeFileSystem = {
|
|
1271
|
-
existsSync:
|
|
1305
|
+
existsSync: existsSync3,
|
|
1272
1306
|
mkdirSync,
|
|
1273
1307
|
symlinkSync,
|
|
1274
1308
|
cpSync,
|
|
@@ -1364,7 +1398,7 @@ function materializeExtractedFramesForCompiledDir(extracted, compiledDir, option
|
|
|
1364
1398
|
for (const ext of extracted) {
|
|
1365
1399
|
const resolvedOut = pathModule.resolve(ext.outputDir);
|
|
1366
1400
|
if (isPathInside2(resolvedOut, resolvedCompiledDir, { pathModule })) continue;
|
|
1367
|
-
const linkPath = pathModule.join(compiledFrameRoot, ext.videoId);
|
|
1401
|
+
const linkPath = pathModule.join(compiledFrameRoot, mediaIdPathSegment(ext.videoId));
|
|
1368
1402
|
if (!fileSystem.existsSync(linkPath)) {
|
|
1369
1403
|
fileSystem.mkdirSync(pathModule.dirname(linkPath), { recursive: true });
|
|
1370
1404
|
stageExtractedFrameDir(
|
|
@@ -1570,7 +1604,7 @@ var RenderExecutionContext = class {
|
|
|
1570
1604
|
};
|
|
1571
1605
|
|
|
1572
1606
|
// src/services/render/artifactTransaction.ts
|
|
1573
|
-
import { closeSync as closeSync2, existsSync as
|
|
1607
|
+
import { closeSync as closeSync2, existsSync as existsSync5, fstatSync as fstatSync2, openSync as openSync2, readSync, readdirSync as readdirSync2, rmSync as rmSync3 } from "node:fs";
|
|
1574
1608
|
import { basename as basename4, dirname as dirname4, extname as extname2, join as join5, resolve as resolve4 } from "node:path";
|
|
1575
1609
|
import { HLS_MASTER_PLAYLIST, HLS_VIDEO_PLAYLIST, renameWithRetry } from "@hyperframes/engine";
|
|
1576
1610
|
|
|
@@ -1583,7 +1617,7 @@ import {
|
|
|
1583
1617
|
|
|
1584
1618
|
// src/services/render/renderDirOwner.ts
|
|
1585
1619
|
import {
|
|
1586
|
-
existsSync as
|
|
1620
|
+
existsSync as existsSync4,
|
|
1587
1621
|
lstatSync,
|
|
1588
1622
|
readFileSync as readFileSync2,
|
|
1589
1623
|
readdirSync,
|
|
@@ -1658,7 +1692,7 @@ function newestWriteMs(path) {
|
|
|
1658
1692
|
}
|
|
1659
1693
|
function isAbandoned(dir, ownerlessIdleMs, now) {
|
|
1660
1694
|
try {
|
|
1661
|
-
if (!lstatSync(dir).isDirectory() ||
|
|
1695
|
+
if (!lstatSync(dir).isDirectory() || existsSync4(join4(dir, TRANSACTION_BACKUP))) return false;
|
|
1662
1696
|
const owner = ownerState(dir);
|
|
1663
1697
|
if (owner === "gone") return true;
|
|
1664
1698
|
return owner === "none" && ownerlessIdleMs !== void 0 && now - newestWriteMs(dir) >= ownerlessIdleMs;
|
|
@@ -1690,7 +1724,7 @@ function createRenderWorkDir(prefix, outputDir) {
|
|
|
1690
1724
|
|
|
1691
1725
|
// src/services/render/artifactTransaction.ts
|
|
1692
1726
|
var defaultFileSystem = {
|
|
1693
|
-
existsSync:
|
|
1727
|
+
existsSync: existsSync5,
|
|
1694
1728
|
renameSync: (source, destination) => renameWithRetry(source, destination),
|
|
1695
1729
|
rmSync: rmSync3
|
|
1696
1730
|
};
|
|
@@ -1844,7 +1878,7 @@ var ArtifactTransaction = class {
|
|
|
1844
1878
|
async assertDirectoryExpectation(expected, files) {
|
|
1845
1879
|
for (const required of expected.requiredFiles ?? []) {
|
|
1846
1880
|
const path = join5(this.stagingPath, required);
|
|
1847
|
-
if (!
|
|
1881
|
+
if (!existsSync5(path)) {
|
|
1848
1882
|
throw new Error(`Render artifact directory is missing ${required}: ${this.stagingPath}`);
|
|
1849
1883
|
}
|
|
1850
1884
|
assertReadableNonEmptyFile(path);
|
|
@@ -2093,7 +2127,7 @@ function replanAfterFailure(plan, failure) {
|
|
|
2093
2127
|
}
|
|
2094
2128
|
|
|
2095
2129
|
// src/services/render/stages/captureSegmentedStage.ts
|
|
2096
|
-
import { existsSync as
|
|
2130
|
+
import { existsSync as existsSync6, mkdirSync as mkdirSync3, rmSync as rmSync6, statSync as statSync3 } from "node:fs";
|
|
2097
2131
|
import { join as join9 } from "node:path";
|
|
2098
2132
|
import {
|
|
2099
2133
|
captureFrameToBuffer as captureFrameToBuffer2,
|
|
@@ -4439,7 +4473,7 @@ async function runCaptureStreamingStage(input) {
|
|
|
4439
4473
|
const session = probeSession ?? await openSession();
|
|
4440
4474
|
captureBeyondViewport = session.options.captureBeyondViewport;
|
|
4441
4475
|
if (probeSession) {
|
|
4442
|
-
prepareCaptureSessionForReuse(session, framesDir, videoInjector);
|
|
4476
|
+
await prepareCaptureSessionForReuse(session, framesDir, videoInjector);
|
|
4443
4477
|
probeSession = null;
|
|
4444
4478
|
}
|
|
4445
4479
|
let riskSession = null;
|
|
@@ -4697,7 +4731,7 @@ async function captureSegmentToEncoder(ctx, segment) {
|
|
|
4697
4731
|
path: segmentPath,
|
|
4698
4732
|
// Recorded so resume can prove the file on disk is the one that
|
|
4699
4733
|
// finished; absent only in unit tests, whose fake encoder writes none.
|
|
4700
|
-
bytes:
|
|
4734
|
+
bytes: existsSync6(segmentPath) ? statSync3(segmentPath).size : 0
|
|
4701
4735
|
});
|
|
4702
4736
|
return encodeResult;
|
|
4703
4737
|
} finally {
|
|
@@ -4744,8 +4778,13 @@ function defaultSessionFactory(input) {
|
|
|
4744
4778
|
};
|
|
4745
4779
|
const session = probeSession ?? await openSession();
|
|
4746
4780
|
if (probeSession) {
|
|
4747
|
-
|
|
4781
|
+
const reused = probeSession;
|
|
4748
4782
|
probeSession = null;
|
|
4783
|
+
await openSegmentedSessionReuse(input, reused, injector).catch(async (error) => {
|
|
4784
|
+
await closeCaptureSession2(reused).catch(() => {
|
|
4785
|
+
});
|
|
4786
|
+
throw error;
|
|
4787
|
+
});
|
|
4749
4788
|
}
|
|
4750
4789
|
try {
|
|
4751
4790
|
if (!session.isInitialized) await withinInitBudget(initializeSession2(session), session);
|
|
@@ -4759,8 +4798,8 @@ function defaultSessionFactory(input) {
|
|
|
4759
4798
|
}
|
|
4760
4799
|
};
|
|
4761
4800
|
}
|
|
4762
|
-
function openSegmentedSessionReuse(input, session, injector) {
|
|
4763
|
-
prepareCaptureSessionForReuse2(session, input.framesDir, injector());
|
|
4801
|
+
async function openSegmentedSessionReuse(input, session, injector) {
|
|
4802
|
+
await prepareCaptureSessionForReuse2(session, input.framesDir, injector());
|
|
4764
4803
|
}
|
|
4765
4804
|
async function openSegmentedSession(input, injector) {
|
|
4766
4805
|
const captureCfg = input.cfg.forceScreenshot === input.plan.forceScreenshot ? input.cfg : { ...input.cfg, forceScreenshot: input.plan.forceScreenshot };
|
|
@@ -5438,6 +5477,7 @@ import { dirname as dirname5, join as join11 } from "node:path";
|
|
|
5438
5477
|
import {
|
|
5439
5478
|
createFrameLookupTable,
|
|
5440
5479
|
extractVideoFramesRange,
|
|
5480
|
+
mediaIdPathSegment as mediaIdPathSegment2,
|
|
5441
5481
|
runVideoExtractionWithRetry
|
|
5442
5482
|
} from "@hyperframes/engine";
|
|
5443
5483
|
function contiguousRuns(sortedIndexes) {
|
|
@@ -5478,7 +5518,7 @@ async function extractDeferredFrames(input) {
|
|
|
5478
5518
|
const shown = shownDeferredFrameIndexes(input, input.frames, input.fps);
|
|
5479
5519
|
return Promise.all(
|
|
5480
5520
|
deferred.map(async (video) => {
|
|
5481
|
-
const outputDir = join11(input.outputRoot, video.videoId);
|
|
5521
|
+
const outputDir = join11(input.outputRoot, mediaIdPathSegment2(video.videoId));
|
|
5482
5522
|
const indexes = [...shown.get(video.videoId) ?? []].sort((a, b) => a - b);
|
|
5483
5523
|
if (indexes.length === 0) {
|
|
5484
5524
|
return { ...video, outputDir, framePaths: /* @__PURE__ */ new Map(), ownedByLookup: false };
|
|
@@ -5697,7 +5737,7 @@ function trackSegmentFramePeak(frames, rootDir, onPeak) {
|
|
|
5697
5737
|
|
|
5698
5738
|
// src/services/render/segmentManifest.ts
|
|
5699
5739
|
import { createHash as createHash2 } from "node:crypto";
|
|
5700
|
-
import { existsSync as
|
|
5740
|
+
import { existsSync as existsSync7, mkdirSync as mkdirSync6, readFileSync as readFileSync4, statSync as statSync5, writeFileSync as writeFileSync3 } from "node:fs";
|
|
5701
5741
|
import { join as join14 } from "node:path";
|
|
5702
5742
|
import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
|
|
5703
5743
|
var MANIFEST_FILENAME = "segments.json";
|
|
@@ -5745,7 +5785,7 @@ function isManifest(value) {
|
|
|
5745
5785
|
}
|
|
5746
5786
|
function readSegmentManifest(segmentDir) {
|
|
5747
5787
|
const path = join14(segmentDir, MANIFEST_FILENAME);
|
|
5748
|
-
if (!
|
|
5788
|
+
if (!existsSync7(path)) return null;
|
|
5749
5789
|
try {
|
|
5750
5790
|
const parsed = JSON.parse(readFileSync4(path, "utf-8"));
|
|
5751
5791
|
return isManifest(parsed) ? parsed : null;
|
|
@@ -5774,7 +5814,7 @@ async function validateCompletedSegments(manifest, expectedHash, probeFrames) {
|
|
|
5774
5814
|
const ok = /* @__PURE__ */ new Set();
|
|
5775
5815
|
if (manifest.planHash !== expectedHash) return ok;
|
|
5776
5816
|
for (const entry of manifest.completed) {
|
|
5777
|
-
if (!
|
|
5817
|
+
if (!existsSync7(entry.path)) continue;
|
|
5778
5818
|
const size = statSync5(entry.path).size;
|
|
5779
5819
|
if (size <= 0 || size !== entry.bytes) continue;
|
|
5780
5820
|
const frames = await probeFrames(entry.path);
|
|
@@ -6142,26 +6182,26 @@ var STALL_POLL_MS = 5e3;
|
|
|
6142
6182
|
function watchStall(phase, rule) {
|
|
6143
6183
|
const detail = rule.detail ?? (() => void 0);
|
|
6144
6184
|
let last = rule.progress();
|
|
6185
|
+
let lastActivity = rule.activity?.();
|
|
6145
6186
|
let budgetMs = rule.firstProgressMs;
|
|
6146
6187
|
const silence = createStallClock();
|
|
6147
6188
|
const pollMs = Math.min(STALL_POLL_MS, rule.noProgressMs, rule.firstProgressMs);
|
|
6148
6189
|
let attempt;
|
|
6149
6190
|
let timer;
|
|
6150
6191
|
let inTail = false;
|
|
6192
|
+
const activityMoved = () => {
|
|
6193
|
+
const activity = rule.activity?.();
|
|
6194
|
+
if (activity === lastActivity) return false;
|
|
6195
|
+
lastActivity = activity;
|
|
6196
|
+
return true;
|
|
6197
|
+
};
|
|
6151
6198
|
const restartWindow = (ms) => {
|
|
6152
6199
|
last = rule.progress();
|
|
6153
6200
|
budgetMs = ms;
|
|
6154
6201
|
silence.reset();
|
|
6155
6202
|
};
|
|
6156
6203
|
const tripped = new Promise((_, reject) => {
|
|
6157
|
-
|
|
6158
|
-
const current = rule.progress();
|
|
6159
|
-
if (rule.complete?.() && !inTail) {
|
|
6160
|
-
inTail = true;
|
|
6161
|
-
return restartWindow(rule.tailMs ?? rule.noProgressMs);
|
|
6162
|
-
}
|
|
6163
|
-
if (current !== last) return restartWindow(rule.noProgressMs);
|
|
6164
|
-
if (silence.idle(pollMs) < budgetMs) return;
|
|
6204
|
+
const trip = (current) => {
|
|
6165
6205
|
const error = new RenderStageStalledError(phase, budgetMs, current, detail());
|
|
6166
6206
|
if (attempt && !attempt.signal.aborted) {
|
|
6167
6207
|
attempt.abort(error);
|
|
@@ -6169,6 +6209,16 @@ function watchStall(phase, rule) {
|
|
|
6169
6209
|
}
|
|
6170
6210
|
clearInterval(timer);
|
|
6171
6211
|
reject(error);
|
|
6212
|
+
};
|
|
6213
|
+
timer = setInterval(() => {
|
|
6214
|
+
const current = rule.progress();
|
|
6215
|
+
if (rule.complete?.() && !inTail) {
|
|
6216
|
+
inTail = true;
|
|
6217
|
+
return restartWindow(rule.tailMs ?? rule.noProgressMs);
|
|
6218
|
+
}
|
|
6219
|
+
if (current !== last) return restartWindow(rule.noProgressMs);
|
|
6220
|
+
if (activityMoved()) return silence.reset();
|
|
6221
|
+
if (silence.idle(pollMs) >= budgetMs) trip(current);
|
|
6172
6222
|
}, pollMs);
|
|
6173
6223
|
});
|
|
6174
6224
|
const openAttempt = (parent) => {
|
|
@@ -6353,21 +6403,21 @@ function countAuthoredTimedClips(html) {
|
|
|
6353
6403
|
}
|
|
6354
6404
|
|
|
6355
6405
|
// src/services/render/stages/compileStage.ts
|
|
6356
|
-
import { existsSync as
|
|
6406
|
+
import { existsSync as existsSync12, writeFileSync as writeFileSync5 } from "node:fs";
|
|
6357
6407
|
import { join as join19 } from "node:path";
|
|
6358
6408
|
import { suggestMatchingPreset } from "@hyperframes/core";
|
|
6359
6409
|
import { extractStandaloneEntryFromIndex, isTemplateEntry } from "@hyperframes/core/compiler";
|
|
6360
6410
|
import { readTextFile as readTextFile2 } from "@hyperframes/parsers/asset-resolution";
|
|
6361
6411
|
|
|
6362
6412
|
// src/services/htmlCompiler.ts
|
|
6363
|
-
import { decodedUrlPath
|
|
6413
|
+
import { decodedUrlPath } from "@hyperframes/parsers/asset-paths";
|
|
6364
6414
|
import { createHash as createHash6 } from "node:crypto";
|
|
6365
|
-
import { createReadStream as createReadStream2, existsSync as
|
|
6415
|
+
import { createReadStream as createReadStream2, existsSync as existsSync11, mkdirSync as mkdirSync9, readFileSync as readFileSync8 } from "fs";
|
|
6366
6416
|
import { join as join18, dirname as dirname8, resolve as resolve7, basename as basename5, relative as relative2, sep as sep2 } from "path";
|
|
6367
6417
|
import { parseHTML as parseHTML5 } from "linkedom";
|
|
6368
6418
|
|
|
6369
6419
|
// src/services/bundledScripts.ts
|
|
6370
|
-
import { existsSync as
|
|
6420
|
+
import { existsSync as existsSync8, readFileSync as readFileSync5 } from "node:fs";
|
|
6371
6421
|
import { join as join15 } from "node:path";
|
|
6372
6422
|
import { gsapCdnDist } from "@hyperframes/core/gsap-cdn";
|
|
6373
6423
|
var GSAP_VENDOR_DIR_ENV = "HYPERFRAMES_GSAP_VENDOR_DIR";
|
|
@@ -6375,7 +6425,7 @@ function bundledScript(url) {
|
|
|
6375
6425
|
const dir = process.env[GSAP_VENDOR_DIR_ENV];
|
|
6376
6426
|
if (!dir || url !== `${gsapCdnDist()}gsap.min.js`) return null;
|
|
6377
6427
|
const file = join15(dir, "gsap.min.js");
|
|
6378
|
-
return
|
|
6428
|
+
return existsSync8(file) ? readFileSync5(file) : null;
|
|
6379
6429
|
}
|
|
6380
6430
|
|
|
6381
6431
|
// src/services/htmlCompiler.ts
|
|
@@ -6415,6 +6465,7 @@ import {
|
|
|
6415
6465
|
emitRootCompositionVariableStyles,
|
|
6416
6466
|
readDeclaredDefaults,
|
|
6417
6467
|
parseHostVariableValues,
|
|
6468
|
+
boundMediaSrc,
|
|
6418
6469
|
headStyleRuns,
|
|
6419
6470
|
isAlwaysAppliedStyle,
|
|
6420
6471
|
dedupeFontFaceRules,
|
|
@@ -6429,8 +6480,10 @@ import {
|
|
|
6429
6480
|
} from "@hyperframes/parsers/sub-composition-validity";
|
|
6430
6481
|
import {
|
|
6431
6482
|
isUnresolvedAssetPlaceholder,
|
|
6483
|
+
namesAnotherNetworkRoot as namesAnotherNetworkRoot2,
|
|
6432
6484
|
readProjectFile,
|
|
6433
|
-
readTextFile
|
|
6485
|
+
readTextFile,
|
|
6486
|
+
resolveCompositionSrc
|
|
6434
6487
|
} from "@hyperframes/parsers/asset-resolution";
|
|
6435
6488
|
|
|
6436
6489
|
// src/services/renderMediaCollector.ts
|
|
@@ -6623,11 +6676,12 @@ import {
|
|
|
6623
6676
|
|
|
6624
6677
|
// src/services/animatedGifPrep.ts
|
|
6625
6678
|
import { createHash as createHash4 } from "node:crypto";
|
|
6626
|
-
import { copyFileSync as copyFileSync2, existsSync as
|
|
6679
|
+
import { copyFileSync as copyFileSync2, existsSync as existsSync9, mkdirSync as mkdirSync7, readFileSync as readFileSync6, rmSync as rmSync9, statSync as statSync6 } from "node:fs";
|
|
6627
6680
|
import { dirname as dirname6, isAbsolute as isAbsolute2, join as join16, resolve as resolve5 } from "node:path";
|
|
6628
6681
|
import { parseHTML as parseHTML3 } from "linkedom";
|
|
6629
6682
|
import { parseAnimatedGifMetadata } from "@hyperframes/core";
|
|
6630
6683
|
import { DEFAULT_VP9_CPU_USED, runFfmpeg as runFfmpeg2, renameWithRetry as renameWithRetry3 } from "@hyperframes/engine";
|
|
6684
|
+
import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
|
|
6631
6685
|
var PREPARED_GIF_SUBDIR = "_animated_gif";
|
|
6632
6686
|
var CACHE_SCHEMA = "hfgif-v1";
|
|
6633
6687
|
function splitUrlSuffix(src) {
|
|
@@ -6662,14 +6716,15 @@ function resolveLocalImageSourcePath(src, options) {
|
|
|
6662
6716
|
const { basePath } = splitUrlSuffix(trimmed);
|
|
6663
6717
|
const normalizedBase = normalizeRelPath(basePath);
|
|
6664
6718
|
const mapped = options.sourceAssets?.get(trimmed) ?? options.sourceAssets?.get(basePath) ?? options.sourceAssets?.get(normalizedBase);
|
|
6665
|
-
if (mapped &&
|
|
6719
|
+
if (mapped && existsSync9(mapped)) return mapped;
|
|
6666
6720
|
if (isHttpUrl(trimmed)) return null;
|
|
6721
|
+
const protocolRelativeUrlOnShare = basePath.startsWith("/") && namesAnotherNetworkRoot(options.projectDir, basePath);
|
|
6667
6722
|
const projectRelative = basePath.startsWith("/") ? basePath.slice(1) : basePath;
|
|
6668
6723
|
const candidates = [
|
|
6669
|
-
isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative),
|
|
6724
|
+
...protocolRelativeUrlOnShare ? [] : [isAbsolute2(basePath) ? basePath : resolve5(options.projectDir, projectRelative)],
|
|
6670
6725
|
resolve5(options.downloadDir, normalizedBase)
|
|
6671
6726
|
];
|
|
6672
|
-
return candidates.find((candidate) =>
|
|
6727
|
+
return candidates.find((candidate) => existsSync9(candidate)) ?? null;
|
|
6673
6728
|
}
|
|
6674
6729
|
function isUsableFile(path) {
|
|
6675
6730
|
try {
|
|
@@ -6780,10 +6835,10 @@ async function runAnimatedGifTranscode(request) {
|
|
|
6780
6835
|
throw result.error ?? new Error(`Animated GIF transcode failed (${result.exitCode}): ${result.stderr.slice(-500)}`);
|
|
6781
6836
|
}
|
|
6782
6837
|
async function ensurePreparedWebm(input) {
|
|
6783
|
-
if (!
|
|
6838
|
+
if (!existsSync9(dirname6(input.cachePath))) {
|
|
6784
6839
|
mkdirSync7(dirname6(input.cachePath), { recursive: true });
|
|
6785
6840
|
}
|
|
6786
|
-
if (!
|
|
6841
|
+
if (!existsSync9(dirname6(input.outputPath))) {
|
|
6787
6842
|
mkdirSync7(dirname6(input.outputPath), { recursive: true });
|
|
6788
6843
|
}
|
|
6789
6844
|
if (!isUsableFile(input.cachePath)) {
|
|
@@ -7258,7 +7313,7 @@ import { createStudioPositionSeekReapplyScript } from "@hyperframes/studio-serve
|
|
|
7258
7313
|
import { getPositionEditsRenderScript } from "@hyperframes/core/runtime/position-edits-render";
|
|
7259
7314
|
|
|
7260
7315
|
// src/services/assetMediaType.ts
|
|
7261
|
-
import { existsSync as
|
|
7316
|
+
import { existsSync as existsSync10 } from "node:fs";
|
|
7262
7317
|
import {
|
|
7263
7318
|
fingerprintElementId,
|
|
7264
7319
|
isNotMediaPayload,
|
|
@@ -7331,7 +7386,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
7331
7386
|
input.projectDir,
|
|
7332
7387
|
input.compiledDir
|
|
7333
7388
|
);
|
|
7334
|
-
if (!
|
|
7389
|
+
if (!existsSync10(resolvedPath)) continue;
|
|
7335
7390
|
byPath.set(resolvedPath, [...byPath.get(resolvedPath) ?? [], reference]);
|
|
7336
7391
|
}
|
|
7337
7392
|
const mismatches = [];
|
|
@@ -7371,7 +7426,7 @@ async function preflightCompositionAssetMediaTypes(input) {
|
|
|
7371
7426
|
|
|
7372
7427
|
// src/services/htmlCompiler.ts
|
|
7373
7428
|
function logRemoteDownloadTelemetry(event) {
|
|
7374
|
-
defaultLogger.
|
|
7429
|
+
defaultLogger.debug("[Compiler] Remote asset download integrity", { ...event });
|
|
7375
7430
|
}
|
|
7376
7431
|
var INFERRED_MEDIA_DURATION_ATTR = "data-hf-inferred-duration";
|
|
7377
7432
|
function parseSubCompHtmlForValidity(html) {
|
|
@@ -7585,7 +7640,7 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
|
|
|
7585
7640
|
let filePath = src;
|
|
7586
7641
|
if (isHttpUrl(src)) {
|
|
7587
7642
|
const remoteDir = join18(downloadDir, REMOTE_MEDIA_SUBDIR);
|
|
7588
|
-
if (!
|
|
7643
|
+
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
7589
7644
|
try {
|
|
7590
7645
|
filePath = await downloadToTemp(src, remoteDir, void 0, void 0, void 0, {
|
|
7591
7646
|
onTelemetry: logRemoteDownloadTelemetry
|
|
@@ -7594,11 +7649,14 @@ async function resolveMediaDuration(src, mediaStart, playbackRate, baseDir, down
|
|
|
7594
7649
|
return { duration: null, resolvedPath: src };
|
|
7595
7650
|
}
|
|
7596
7651
|
} else {
|
|
7597
|
-
filePath =
|
|
7652
|
+
filePath = decodedUrlPath(src);
|
|
7598
7653
|
if (!filePath.startsWith("/")) filePath = join18(baseDir, filePath);
|
|
7599
7654
|
filePath = urlByAbsentLocalPath?.get(filePath) ?? filePath;
|
|
7655
|
+
if (!isHttpUrl(filePath) && namesAnotherNetworkRoot2(baseDir, filePath)) {
|
|
7656
|
+
return { duration: null, resolvedPath: filePath };
|
|
7657
|
+
}
|
|
7600
7658
|
}
|
|
7601
|
-
if (!isHttpUrl(filePath) && !
|
|
7659
|
+
if (!isHttpUrl(filePath) && !existsSync11(filePath)) {
|
|
7602
7660
|
return { duration: null, resolvedPath: filePath };
|
|
7603
7661
|
}
|
|
7604
7662
|
const withSrcContext = (error) => {
|
|
@@ -7947,7 +8005,7 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
|
|
|
7947
8005
|
parseHtml: (htmlStr) => parseHTML5(htmlStr).document,
|
|
7948
8006
|
// Mirrors the preview bundler: a sub-composition's SIBLING assets resolve
|
|
7949
8007
|
// against its own directory, project-root refs stay as authored.
|
|
7950
|
-
assetExists: (path) =>
|
|
8008
|
+
assetExists: (path) => existsSync11(resolve7(projectDir, path)),
|
|
7951
8009
|
// Preserve the authored root wrapper as a child of the host, matching
|
|
7952
8010
|
// the preview bundler's shape (htmlBundler.ts's prepareFlattenedInnerRoot,
|
|
7953
8011
|
// which the runtime compositionLoader mirrors with its own copy for the
|
|
@@ -8123,7 +8181,7 @@ ${safeText}
|
|
|
8123
8181
|
//# sourceURL=${new URL(src).href}
|
|
8124
8182
|
`;
|
|
8125
8183
|
el.replaceWith(inlineScript);
|
|
8126
|
-
defaultLogger.
|
|
8184
|
+
defaultLogger.debug(`[Compiler] Inlined CDN script: ${src}`);
|
|
8127
8185
|
} else {
|
|
8128
8186
|
if (download.reason instanceof ScriptIntegrityError) throw download.reason;
|
|
8129
8187
|
defaultLogger.warn(
|
|
@@ -8143,7 +8201,7 @@ function collectExternalAssets(html, projectDir) {
|
|
|
8143
8201
|
if (isPathInside2(absPath, absProjectDir)) {
|
|
8144
8202
|
return null;
|
|
8145
8203
|
}
|
|
8146
|
-
if (!
|
|
8204
|
+
if (!existsSync11(absPath)) return null;
|
|
8147
8205
|
const safeKey = toExternalAssetKey(absPath);
|
|
8148
8206
|
externalAssets.set(safeKey, absPath);
|
|
8149
8207
|
return safeKey;
|
|
@@ -8178,7 +8236,7 @@ function collectExternalAssets(html, projectDir) {
|
|
|
8178
8236
|
if (rewritten !== style) el.setAttribute("style", rewritten);
|
|
8179
8237
|
}
|
|
8180
8238
|
if (externalAssets.size > 0) {
|
|
8181
|
-
defaultLogger.
|
|
8239
|
+
defaultLogger.debug(
|
|
8182
8240
|
`[Compiler] Found ${externalAssets.size} asset(s) outside project directory, will copy to render output`
|
|
8183
8241
|
);
|
|
8184
8242
|
}
|
|
@@ -8193,7 +8251,7 @@ var REMOTE_SOURCE_TAG_RE = /<source\b[^>]*?\bsrc\s*=\s*["'](https?:\/\/[^"']+)["
|
|
|
8193
8251
|
var REMOTE_IMG_TAG_RE = /<img\b[^>]*?(?<![\w-])src\s*=\s*["'](https?:\/\/[^"']+)["'][^>]*>/gi;
|
|
8194
8252
|
async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLabel, extraRewrite) {
|
|
8195
8253
|
if (urlSet.size === 0) return { html, remoteMediaAssets: /* @__PURE__ */ new Map() };
|
|
8196
|
-
if (!
|
|
8254
|
+
if (!existsSync11(remoteDir)) mkdirSync9(remoteDir, { recursive: true });
|
|
8197
8255
|
const urlToLocal = /* @__PURE__ */ new Map();
|
|
8198
8256
|
await Promise.all(
|
|
8199
8257
|
[...urlSet].map(async (url) => {
|
|
@@ -8225,7 +8283,7 @@ async function downloadAndRewriteUrls(urlSet, html, remoteDir, warnLabel, logLab
|
|
|
8225
8283
|
result = result.replaceAll(`"${url}"`, `"${relPath}"`).replaceAll(`'${url}'`, `'${relPath}'`);
|
|
8226
8284
|
if (extraRewrite) result = extraRewrite(result, url, relPath);
|
|
8227
8285
|
}
|
|
8228
|
-
defaultLogger.
|
|
8286
|
+
defaultLogger.debug(`[Compiler] ${logLabel} ${urlToLocal.size} to ${REMOTE_MEDIA_SUBDIR}/`);
|
|
8229
8287
|
return { html: result, remoteMediaAssets };
|
|
8230
8288
|
}
|
|
8231
8289
|
async function localizeRemoteMediaSources(html, downloadDir) {
|
|
@@ -8362,7 +8420,7 @@ async function inlineExternalFontStylesheets(html) {
|
|
|
8362
8420
|
${fontFaceBlocks.join("\n")}
|
|
8363
8421
|
</style>`;
|
|
8364
8422
|
result = result.replace(fullMatch, inlineStyle);
|
|
8365
|
-
defaultLogger.
|
|
8423
|
+
defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
|
|
8366
8424
|
count: fontFaceBlocks.length,
|
|
8367
8425
|
urlFingerprint: identity.urlFingerprint,
|
|
8368
8426
|
host: identity.host
|
|
@@ -8375,14 +8433,14 @@ function projectStylesheetFontFamilies(html, projectDir) {
|
|
|
8375
8433
|
for (const [tag] of html.matchAll(/<link\b[^>]*\brel=["']stylesheet["'][^>]*>/gi)) {
|
|
8376
8434
|
const href = /\bhref=["']([^"']+)["']/i.exec(tag)?.[1];
|
|
8377
8435
|
if (!href || /^(?:[a-z][a-z\d+.-]*:|\/\/)/i.test(href)) continue;
|
|
8378
|
-
const sheet = resolve7(projectDir,
|
|
8379
|
-
if (!isPathInside2(sheet, projectDir) || !
|
|
8436
|
+
const sheet = resolve7(projectDir, decodedUrlPath(href).replace(/^(?:\.?\/)+/, ""));
|
|
8437
|
+
if (!isPathInside2(sheet, projectDir) || !existsSync11(sheet)) continue;
|
|
8380
8438
|
for (const face of extractFontFaceBlocks(readFileSync8(sheet, "utf8"))) {
|
|
8381
8439
|
const family = /font-family\s*:\s*([^;}]+)/i.exec(face)?.[1]?.trim().replace(/^['"]|['"]$/g, "");
|
|
8382
8440
|
const shipsFile = [...face.matchAll(LOCAL_FONTFACE_URL_RE)].some(([, url = ""]) => {
|
|
8383
|
-
const path =
|
|
8441
|
+
const path = decodedUrlPath(url);
|
|
8384
8442
|
const file = path.startsWith("/") ? resolve7(projectDir, `.${path}`) : resolve7(dirname8(sheet), path);
|
|
8385
|
-
return isPathInside2(file, projectDir) &&
|
|
8443
|
+
return isPathInside2(file, projectDir) && existsSync11(file);
|
|
8386
8444
|
});
|
|
8387
8445
|
if (family && shipsFile) families.push(family);
|
|
8388
8446
|
}
|
|
@@ -8481,7 +8539,7 @@ async function embedLocalFontFaces(html, projectDir) {
|
|
|
8481
8539
|
const font = await readLocalFont(absPath);
|
|
8482
8540
|
if (font.kind === "file-backed") {
|
|
8483
8541
|
fileBackedAbsolutePaths.add(absPath);
|
|
8484
|
-
defaultLogger.
|
|
8542
|
+
defaultLogger.debug(
|
|
8485
8543
|
`[Compiler] Kept large local font file-backed: ${localPath} (> ${(MAX_LOCAL_FONT_DATA_URI_BYTES / 1024 / 1024).toFixed(1)} MB)`
|
|
8486
8544
|
);
|
|
8487
8545
|
embeddedPaths.add(localPath);
|
|
@@ -8489,7 +8547,7 @@ async function embedLocalFontFaces(html, projectDir) {
|
|
|
8489
8547
|
}
|
|
8490
8548
|
dataUri = await toDataUri(font.buffer, ext, { compressToWoff2: false });
|
|
8491
8549
|
dataUriByAbsolutePath.set(absPath, dataUri);
|
|
8492
|
-
defaultLogger.
|
|
8550
|
+
defaultLogger.debug(
|
|
8493
8551
|
`[Compiler] Embedded local font file: ${localPath} (${(font.buffer.length / 1024).toFixed(0)} KB \u2192 data URI)`
|
|
8494
8552
|
);
|
|
8495
8553
|
}
|
|
@@ -8517,14 +8575,17 @@ function renderGsapDist() {
|
|
|
8517
8575
|
}
|
|
8518
8576
|
function rewriteUnresolvableGsapToCdn(html, projectDir, compSrcPath) {
|
|
8519
8577
|
let gsapDist;
|
|
8520
|
-
const exists = (path) =>
|
|
8578
|
+
const exists = (path) => {
|
|
8579
|
+
const file = resolve7(projectDir, path);
|
|
8580
|
+
return !namesAnotherNetworkRoot2(projectDir, file) && existsSync11(file);
|
|
8581
|
+
};
|
|
8521
8582
|
return html.replace(
|
|
8522
8583
|
/(<script\b[^>]*\bsrc=["'])([^"']*gsap[^"']*\/dist\/([^"']+))(["'][^>]*>)/gi,
|
|
8523
8584
|
(full, prefix, src, file, suffix) => {
|
|
8524
8585
|
if (/^https?:\/\//i.test(src)) return full;
|
|
8525
8586
|
if (exists(compSrcPath ? rewriteAssetPath(compSrcPath, src, exists) : src)) return full;
|
|
8526
8587
|
gsapDist ??= renderGsapDist();
|
|
8527
|
-
defaultLogger.
|
|
8588
|
+
defaultLogger.debug(`[Compiler] Rewriting missing gsap script: ${src} \u2192 ${gsapDist}${file}`);
|
|
8528
8589
|
return `${prefix}${gsapDist}${file}${suffix}`;
|
|
8529
8590
|
}
|
|
8530
8591
|
);
|
|
@@ -8534,7 +8595,7 @@ function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
|
|
|
8534
8595
|
const entryPath = relative2(projectDir, htmlPath).replace(/\\/g, "/");
|
|
8535
8596
|
if (!entryPath.includes("/")) return html;
|
|
8536
8597
|
const { document: document2 } = parseHTML5(html);
|
|
8537
|
-
const assetExists = (path) =>
|
|
8598
|
+
const assetExists = (path) => existsSync11(resolve7(projectDir, path));
|
|
8538
8599
|
rewriteAssetPaths(
|
|
8539
8600
|
document2.querySelectorAll("[src], [href], [srcset]"),
|
|
8540
8601
|
entryPath,
|
|
@@ -8554,11 +8615,29 @@ function rebaseDirectEntryAssetPaths(html, projectDir, htmlPath) {
|
|
|
8554
8615
|
}
|
|
8555
8616
|
return document2.toString();
|
|
8556
8617
|
}
|
|
8618
|
+
function bindVariableMediaSources(html, variables) {
|
|
8619
|
+
if (!html.includes("data-var-src")) return html;
|
|
8620
|
+
const { document: document2 } = parseHTML5(html);
|
|
8621
|
+
const declared = {};
|
|
8622
|
+
for (const el of document2.querySelectorAll("[data-composition-variables]")) {
|
|
8623
|
+
Object.assign(declared, readDeclaredDefaults(el));
|
|
8624
|
+
}
|
|
8625
|
+
const values = { ...declared, ...variables };
|
|
8626
|
+
let changed = false;
|
|
8627
|
+
for (const el of document2.querySelectorAll("video[data-var-src], audio[data-var-src]")) {
|
|
8628
|
+
if (el.closest("[data-variable-values]")) continue;
|
|
8629
|
+
const src = boundMediaSrc(el, values);
|
|
8630
|
+
if (src === null || el.getAttribute("src") === src) continue;
|
|
8631
|
+
el.setAttribute("src", src);
|
|
8632
|
+
changed = true;
|
|
8633
|
+
}
|
|
8634
|
+
return changed ? document2.toString() : html;
|
|
8635
|
+
}
|
|
8557
8636
|
async function compileForRender(projectDir, htmlPath, downloadDir, options = {}) {
|
|
8558
8637
|
const entryHtml = rebaseDirectEntryAssetPaths(readTextFile(htmlPath), projectDir, htmlPath);
|
|
8559
|
-
const rawHtml =
|
|
8560
|
-
rewriteUnresolvableGsapToCdn(entryHtml, projectDir),
|
|
8561
|
-
|
|
8638
|
+
const rawHtml = bindVariableMediaSources(
|
|
8639
|
+
normalizeCompositionSrcs(rewriteUnresolvableGsapToCdn(entryHtml, projectDir), projectDir),
|
|
8640
|
+
options.variables ?? {}
|
|
8562
8641
|
);
|
|
8563
8642
|
assertSubCompositionsUsable(rawHtml, projectDir);
|
|
8564
8643
|
const probes = /* @__PURE__ */ new Map();
|
|
@@ -8642,7 +8721,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
8642
8721
|
timeoutMs: options.ffmpegProcessTimeout
|
|
8643
8722
|
});
|
|
8644
8723
|
if (preparedHeifImages.length > 0) {
|
|
8645
|
-
defaultLogger.
|
|
8724
|
+
defaultLogger.debug(`[Compiler] Converted ${preparedHeifImages.length} HEIC image(s) to JPEG`);
|
|
8646
8725
|
}
|
|
8647
8726
|
const gifSourceAssets = new Map(remoteImageAssets);
|
|
8648
8727
|
const {
|
|
@@ -8657,7 +8736,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
8657
8736
|
timeoutMs: options.ffmpegProcessTimeout
|
|
8658
8737
|
});
|
|
8659
8738
|
if (preparedGifs.length > 0) {
|
|
8660
|
-
defaultLogger.
|
|
8739
|
+
defaultLogger.debug(`[Compiler] Prepared ${preparedGifs.length} animated GIF input(s) as WebM`);
|
|
8661
8740
|
}
|
|
8662
8741
|
const embeddedHtml = await embedLocalFontFaces(htmlWithPreparedGifs, projectDir);
|
|
8663
8742
|
const { html, externalAssets } = collectExternalAssets(embeddedHtml, projectDir);
|
|
@@ -8685,7 +8764,7 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
|
|
|
8685
8764
|
for (const video of videos) {
|
|
8686
8765
|
if (isHttpUrl(video.src)) continue;
|
|
8687
8766
|
const videoPath = resolve7(projectDir, video.src);
|
|
8688
|
-
if (advised.has(videoPath)) continue;
|
|
8767
|
+
if (advised.has(videoPath) || namesAnotherNetworkRoot2(projectDir, videoPath)) continue;
|
|
8689
8768
|
advised.add(videoPath);
|
|
8690
8769
|
const reencode = `ffmpeg -i "${video.src}" -c:v libx264 -r 30 -g 30 -keyint_min 30 -movflags +faststart -c:a copy output.mp4`;
|
|
8691
8770
|
(async () => {
|
|
@@ -9104,7 +9183,7 @@ function resolveEntryHtmlPath(input) {
|
|
|
9104
9183
|
const rawEntry = readTextFile2(htmlPath);
|
|
9105
9184
|
if (entryFile === "index.html" || !isTemplateEntry(rawEntry)) return htmlPath;
|
|
9106
9185
|
const projectIndexPath = join19(projectDir, "index.html");
|
|
9107
|
-
if (!
|
|
9186
|
+
if (!existsSync12(projectIndexPath)) {
|
|
9108
9187
|
throw new Error(
|
|
9109
9188
|
`Template entry file "${entryFile}" requires a project index.html to extract its render shell.`
|
|
9110
9189
|
);
|
|
@@ -9124,6 +9203,14 @@ function resolveEntryHtmlPath(input) {
|
|
|
9124
9203
|
log.info("Extracted standalone entry from index.html host context", { entryFile });
|
|
9125
9204
|
return wrapperPath;
|
|
9126
9205
|
}
|
|
9206
|
+
function applyChroma444Gate(cfg, chromaSubsampling, gate, log) {
|
|
9207
|
+
if (!cfg.useDrawElement || chromaSubsampling !== "444") return gate;
|
|
9208
|
+
cfg.useDrawElement = false;
|
|
9209
|
+
log.info(
|
|
9210
|
+
"[Render] Fast capture: chromaSubsampling 444 captures lossless PNG frames, so disabling drawElementImage for this render. Capture uses the platform's baseline route."
|
|
9211
|
+
);
|
|
9212
|
+
return "chroma_444";
|
|
9213
|
+
}
|
|
9127
9214
|
async function runCompileStage(input) {
|
|
9128
9215
|
const {
|
|
9129
9216
|
projectDir,
|
|
@@ -9175,6 +9262,7 @@ async function runCompileStage(input) {
|
|
|
9175
9262
|
"[Render] Fast capture: composition uses shader transitions, so disabling drawElementImage so page-side compositing stays available."
|
|
9176
9263
|
);
|
|
9177
9264
|
}
|
|
9265
|
+
deCompileGate = applyChroma444Gate(cfg, job.config.chromaSubsampling, deCompileGate, log);
|
|
9178
9266
|
if (!cfg.useDrawElement && cfg.pageSideCompositingAutoDisabled) {
|
|
9179
9267
|
cfg.enablePageSideCompositing = true;
|
|
9180
9268
|
cfg.pageSideCompositingAutoDisabled = false;
|
|
@@ -9286,11 +9374,19 @@ function isActionableProbeFailure(line) {
|
|
|
9286
9374
|
|
|
9287
9375
|
// src/services/render/captureImageFormat.ts
|
|
9288
9376
|
function resolveCaptureImageFormat(input) {
|
|
9289
|
-
return input.needsAlpha || input.motionBlur ? "png" : "jpeg";
|
|
9377
|
+
return input.needsAlpha || input.motionBlur || input.chromaSubsampling === "444" ? "png" : "jpeg";
|
|
9290
9378
|
}
|
|
9291
9379
|
function resolveCaptureJpegQuality(quality) {
|
|
9292
9380
|
return quality === "draft" ? 80 : 100;
|
|
9293
9381
|
}
|
|
9382
|
+
function resolveCaptureSurface(input, quality) {
|
|
9383
|
+
const format = resolveCaptureImageFormat(input);
|
|
9384
|
+
return {
|
|
9385
|
+
format,
|
|
9386
|
+
quality: format === "png" ? void 0 : resolveCaptureJpegQuality(quality),
|
|
9387
|
+
transparent: input.needsAlpha
|
|
9388
|
+
};
|
|
9389
|
+
}
|
|
9294
9390
|
|
|
9295
9391
|
// src/services/render/stages/probeStage.ts
|
|
9296
9392
|
var FRAME_BOUNDARY_EPSILON = 1e-3;
|
|
@@ -9420,7 +9516,8 @@ async function runProbeStage(input) {
|
|
|
9420
9516
|
height,
|
|
9421
9517
|
needsAlpha,
|
|
9422
9518
|
deviceScaleFactor,
|
|
9423
|
-
subTimelineWaitMemo
|
|
9519
|
+
subTimelineWaitMemo,
|
|
9520
|
+
staticDedupMemo
|
|
9424
9521
|
} = input;
|
|
9425
9522
|
let { compiled } = input;
|
|
9426
9523
|
const probeCfg = cfg.forceScreenshot === forceScreenshot ? cfg : { ...cfg, forceScreenshot };
|
|
@@ -9467,21 +9564,25 @@ async function runProbeStage(input) {
|
|
|
9467
9564
|
});
|
|
9468
9565
|
assertNotAborted();
|
|
9469
9566
|
const motionBlur = job.config.motionBlur;
|
|
9470
|
-
const captureFormat = resolveCaptureImageFormat({ needsAlpha, motionBlur });
|
|
9471
9567
|
const captureOpts = {
|
|
9472
9568
|
recordReferenceBackground: input.recordReferenceBackground,
|
|
9473
9569
|
width,
|
|
9474
9570
|
height,
|
|
9475
9571
|
fps: job.config.fps,
|
|
9476
|
-
|
|
9477
|
-
|
|
9478
|
-
|
|
9572
|
+
...resolveCaptureSurface(
|
|
9573
|
+
{ needsAlpha, motionBlur, chromaSubsampling: job.config.chromaSubsampling },
|
|
9574
|
+
job.config.quality
|
|
9575
|
+
),
|
|
9479
9576
|
variables: job.config.variables,
|
|
9480
9577
|
deviceScaleFactor,
|
|
9481
9578
|
motionBlur,
|
|
9482
9579
|
pageMotionBlur: job.config.pageMotionBlur,
|
|
9483
9580
|
requiresWebGpu: compositionRequiresWebGpu(compiled.html),
|
|
9484
|
-
subTimelineWaitMemo
|
|
9581
|
+
subTimelineWaitMemo,
|
|
9582
|
+
staticDedupMemo,
|
|
9583
|
+
compositionHash: computeCompositionObservabilityHash(compiled.html),
|
|
9584
|
+
deferStaticDedup: true,
|
|
9585
|
+
onStaticDedupActivity: () => noteStaticDedupActivity(job)
|
|
9485
9586
|
};
|
|
9486
9587
|
const PROBE_MAX_ATTEMPTS = 2;
|
|
9487
9588
|
for (let attempt = 1; attempt <= PROBE_MAX_ATTEMPTS; attempt++) {
|
|
@@ -9938,7 +10039,7 @@ function validateRenderDuration(input) {
|
|
|
9938
10039
|
}
|
|
9939
10040
|
|
|
9940
10041
|
// src/services/render/stages/extractVideosStage.ts
|
|
9941
|
-
import { existsSync as
|
|
10042
|
+
import { existsSync as existsSync13 } from "node:fs";
|
|
9942
10043
|
import { join as join21 } from "node:path";
|
|
9943
10044
|
import {
|
|
9944
10045
|
classifyVideoExtractionError,
|
|
@@ -10208,7 +10309,7 @@ async function runExtractVideosStage(input) {
|
|
|
10208
10309
|
const probeFailures = await Promise.all(
|
|
10209
10310
|
composition.videos.map(async (v) => {
|
|
10210
10311
|
const videoPath = resolveProjectRelativeSrc3(v.src, projectDir, compiledDir);
|
|
10211
|
-
if (!
|
|
10312
|
+
if (!existsSync13(videoPath)) return null;
|
|
10212
10313
|
try {
|
|
10213
10314
|
const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata3(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata3(videoPath), {
|
|
10214
10315
|
signal: abortSignal,
|
|
@@ -10246,7 +10347,7 @@ async function runExtractVideosStage(input) {
|
|
|
10246
10347
|
const probed = await Promise.all(
|
|
10247
10348
|
composition.images.map(async (img) => {
|
|
10248
10349
|
const imgPath = resolveProjectRelativeSrc3(img.src, projectDir, compiledDir);
|
|
10249
|
-
if (!
|
|
10350
|
+
if (!existsSync13(imgPath)) return null;
|
|
10250
10351
|
const colorSpace = await probeColorSpaceSafely(imgPath, log);
|
|
10251
10352
|
if (isHdrColorSpace2(colorSpace)) {
|
|
10252
10353
|
nativeHdrImageIds.add(img.id);
|
|
@@ -10366,7 +10467,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
10366
10467
|
videos.map(async (video) => {
|
|
10367
10468
|
const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc3(video.src, projectDir, compiledDir);
|
|
10368
10469
|
const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
|
|
10369
|
-
if (!isHttpUrl2(readFrom) && !
|
|
10470
|
+
if (!isHttpUrl2(readFrom) && !existsSync13(readFrom)) return null;
|
|
10370
10471
|
const metadata = await extractMediaMetadata3(readFrom);
|
|
10371
10472
|
const window2 = await resolveFinalFrameExtractionWindow2(
|
|
10372
10473
|
readFrom,
|
|
@@ -10386,7 +10487,7 @@ async function appendVideoAudioFromProbe(input) {
|
|
|
10386
10487
|
}
|
|
10387
10488
|
|
|
10388
10489
|
// src/services/render/videoLayerPassthroughPlan.ts
|
|
10389
|
-
import { existsSync as
|
|
10490
|
+
import { existsSync as existsSync14 } from "node:fs";
|
|
10390
10491
|
import {
|
|
10391
10492
|
buildVideoLayerInput,
|
|
10392
10493
|
isHttpUrl as isHttpUrl3,
|
|
@@ -10454,7 +10555,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
10454
10555
|
const { video } = q;
|
|
10455
10556
|
if (isHttpUrl3(video.src)) return { reason: "remote_source" };
|
|
10456
10557
|
const path = resolveProjectRelativeSrc4(video.src, input.projectDir, input.compiledDir);
|
|
10457
|
-
if (!
|
|
10558
|
+
if (!existsSync14(path)) return { reason: "source_missing" };
|
|
10458
10559
|
const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
|
|
10459
10560
|
if ("reason" in layout) return layout;
|
|
10460
10561
|
const layer = await buildVideoLayerInput(
|
|
@@ -10469,7 +10570,7 @@ async function planVideoLayerPassthrough(input) {
|
|
|
10469
10570
|
}
|
|
10470
10571
|
|
|
10471
10572
|
// src/services/render/stages/audioStage.ts
|
|
10472
|
-
import { existsSync as
|
|
10573
|
+
import { existsSync as existsSync16 } from "node:fs";
|
|
10473
10574
|
import { join as join24 } from "node:path";
|
|
10474
10575
|
import {
|
|
10475
10576
|
MIXED_AUDIO_FILENAME,
|
|
@@ -10480,7 +10581,7 @@ import {
|
|
|
10480
10581
|
} from "@hyperframes/engine";
|
|
10481
10582
|
|
|
10482
10583
|
// src/services/render/audioDeliveryLimit.ts
|
|
10483
|
-
import { existsSync as
|
|
10584
|
+
import { existsSync as existsSync15 } from "node:fs";
|
|
10484
10585
|
import { dirname as dirname10, join as join23 } from "node:path";
|
|
10485
10586
|
import {
|
|
10486
10587
|
applyAudioFxChain,
|
|
@@ -10989,7 +11090,7 @@ async function limitDeliveryPeaks(input, deps = {
|
|
|
10989
11090
|
applyChain: applyAudioFxChain,
|
|
10990
11091
|
encode: encodeAac2,
|
|
10991
11092
|
rename: renameWithRetry6,
|
|
10992
|
-
sourceExists:
|
|
11093
|
+
sourceExists: existsSync15
|
|
10993
11094
|
}) {
|
|
10994
11095
|
const { audioPath, sourcePath, signal, timeoutMs } = input;
|
|
10995
11096
|
if (!deps.sourceExists(sourcePath)) return { success: true };
|
|
@@ -11084,7 +11185,7 @@ async function runAudioStageScoped(input) {
|
|
|
11084
11185
|
);
|
|
11085
11186
|
audioLoweredDb = guard.loweredDb;
|
|
11086
11187
|
input.log?.info("[audio] phases", { ...result.audioPhaseMs, guard: Date.now() - guardStart });
|
|
11087
|
-
if (input.keepDeliverySource && !guard.sourceStale &&
|
|
11188
|
+
if (input.keepDeliverySource && !guard.sourceStale && existsSync16(pcmSourcePath)) {
|
|
11088
11189
|
deliverySourcePath = pcmSourcePath;
|
|
11089
11190
|
}
|
|
11090
11191
|
}
|
|
@@ -11212,7 +11313,7 @@ async function mixAudioForDelivery(input, duration, pcmSourcePath) {
|
|
|
11212
11313
|
}
|
|
11213
11314
|
|
|
11214
11315
|
// src/services/render/stages/captureStage.ts
|
|
11215
|
-
import { existsSync as
|
|
11316
|
+
import { existsSync as existsSync17, readdirSync as readdirSync4, statfsSync as statfsSync2 } from "node:fs";
|
|
11216
11317
|
import { join as join25 } from "node:path";
|
|
11217
11318
|
import {
|
|
11218
11319
|
classifyCaptureFailure as classifyCaptureFailure2,
|
|
@@ -11283,7 +11384,7 @@ function diskCaptureShortfallError(needBytes, freeBytes, framesDir, basis, remed
|
|
|
11283
11384
|
}
|
|
11284
11385
|
function measureCaptureFrameBytes(workDir, framesDir) {
|
|
11285
11386
|
let total = sampleDirectoryBytes(framesDir);
|
|
11286
|
-
if (!
|
|
11387
|
+
if (!existsSync17(workDir)) return total;
|
|
11287
11388
|
for (const attempt of readdirSync4(workDir)) {
|
|
11288
11389
|
if (/^retry-\d+-batch-\d+-worker-\d+$/.test(attempt)) {
|
|
11289
11390
|
total += sampleDirectoryBytes(join25(workDir, attempt));
|
|
@@ -11465,7 +11566,7 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
|
|
|
11465
11566
|
captureBeyondViewport = session.options.captureBeyondViewport;
|
|
11466
11567
|
try {
|
|
11467
11568
|
if (probeSession) {
|
|
11468
|
-
prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
|
|
11569
|
+
await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
|
|
11469
11570
|
probeSession = null;
|
|
11470
11571
|
}
|
|
11471
11572
|
await ensureSessionReady(session, {
|
|
@@ -11590,7 +11691,7 @@ async function captureSessionFrames(session, { input, rangeStart, rangeEnd, resu
|
|
|
11590
11691
|
}
|
|
11591
11692
|
|
|
11592
11693
|
// src/services/render/stages/captureHdrStage.ts
|
|
11593
|
-
import { existsSync as
|
|
11694
|
+
import { existsSync as existsSync19, mkdirSync as mkdirSync10 } from "node:fs";
|
|
11594
11695
|
import { join as join29 } from "node:path";
|
|
11595
11696
|
import {
|
|
11596
11697
|
closeCaptureSession as closeCaptureSession7,
|
|
@@ -11836,7 +11937,7 @@ import { Worker } from "node:worker_threads";
|
|
|
11836
11937
|
import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
|
|
11837
11938
|
import { dirname as dirname11, join as join27 } from "node:path";
|
|
11838
11939
|
import { createRequire } from "node:module";
|
|
11839
|
-
import { existsSync as
|
|
11940
|
+
import { existsSync as existsSync18 } from "node:fs";
|
|
11840
11941
|
import { cpus as cpus2 } from "node:os";
|
|
11841
11942
|
function resolveWorkerEntry(explicit) {
|
|
11842
11943
|
if (explicit && explicit.length > 0) {
|
|
@@ -11849,7 +11950,7 @@ function resolveWorkerEntry(explicit) {
|
|
|
11849
11950
|
}
|
|
11850
11951
|
const moduleDir = dirname11(fileURLToPath3(import.meta.url));
|
|
11851
11952
|
const jsPath = join27(moduleDir, "shaderTransitionWorker.js");
|
|
11852
|
-
if (
|
|
11953
|
+
if (existsSync18(jsPath)) return { path: jsPath, isTs: false };
|
|
11853
11954
|
const tsPath = join27(moduleDir, "shaderTransitionWorker.ts");
|
|
11854
11955
|
return { path: tsPath, isTs: true };
|
|
11855
11956
|
}
|
|
@@ -12410,7 +12511,7 @@ async function runCaptureHdrStage(input) {
|
|
|
12410
12511
|
}
|
|
12411
12512
|
const debugDumpEnabled = process.env.KEEP_TEMP === "1";
|
|
12412
12513
|
const debugDumpDir = debugDumpEnabled ? join29(framesDir, "debug-composite") : null;
|
|
12413
|
-
if (debugDumpDir && !
|
|
12514
|
+
if (debugDumpDir && !existsSync19(debugDumpDir)) {
|
|
12414
12515
|
mkdirSync10(debugDumpDir, { recursive: true });
|
|
12415
12516
|
}
|
|
12416
12517
|
const compositeTransfer = resolveCompositeTransfer(hasHdrContent, effectiveHdr);
|
|
@@ -12567,7 +12668,7 @@ async function runCaptureHdrStage(input) {
|
|
|
12567
12668
|
// src/services/render/stages/encodeStage.ts
|
|
12568
12669
|
import {
|
|
12569
12670
|
copyFileSync as copyFileSync4,
|
|
12570
|
-
existsSync as
|
|
12671
|
+
existsSync as existsSync20,
|
|
12571
12672
|
mkdirSync as mkdirSync11,
|
|
12572
12673
|
readdirSync as readdirSync5,
|
|
12573
12674
|
readFileSync as readFileSync9,
|
|
@@ -12701,7 +12802,7 @@ async function encodeGifFromDir(framesDir, framePattern, outputPath, input) {
|
|
|
12701
12802
|
const failure = await reencodeWithClearedWholeFrames(argsInput, run, startTime);
|
|
12702
12803
|
if (failure) return failure;
|
|
12703
12804
|
}
|
|
12704
|
-
const fileSize =
|
|
12805
|
+
const fileSize = existsSync20(outputPath) ? statSync8(outputPath).size : 0;
|
|
12705
12806
|
return {
|
|
12706
12807
|
success: true,
|
|
12707
12808
|
outputPath,
|
|
@@ -12862,7 +12963,7 @@ async function runEncodeStage(input) {
|
|
|
12862
12963
|
const stage5Start = Date.now();
|
|
12863
12964
|
if (isPngSequence) {
|
|
12864
12965
|
const encoded = startEncodeProgress(job, "Writing PNG sequence", onProgress);
|
|
12865
|
-
if (!
|
|
12966
|
+
if (!existsSync20(outputPath)) mkdirSync11(outputPath, { recursive: true });
|
|
12866
12967
|
const captured = readdirSync5(framesDir).filter((name) => name.endsWith(".png")).sort();
|
|
12867
12968
|
if (captured.length === 0) {
|
|
12868
12969
|
throw new Error(
|
|
@@ -12873,7 +12974,7 @@ async function runEncodeStage(input) {
|
|
|
12873
12974
|
const dst = join30(outputPath, formatExportFrameName(i, "png"));
|
|
12874
12975
|
copyFileSync4(join30(framesDir, name), dst);
|
|
12875
12976
|
});
|
|
12876
|
-
if (hasAudio && audioOutputPath &&
|
|
12977
|
+
if (hasAudio && audioOutputPath && existsSync20(audioOutputPath)) {
|
|
12877
12978
|
copyFileSync4(audioOutputPath, join30(outputPath, MIXED_AUDIO_FILENAME2));
|
|
12878
12979
|
log.info(
|
|
12879
12980
|
`[Render] png-sequence: ${MIXED_AUDIO_FILENAME2} sidecar written to ${outputPath}/${MIXED_AUDIO_FILENAME2}`
|
|
@@ -13262,7 +13363,7 @@ function findMissingFrameRanges(totalFrames, framesDir, frameExt) {
|
|
|
13262
13363
|
let rangeStart = null;
|
|
13263
13364
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
13264
13365
|
const framePath = join31(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
13265
|
-
const missing = !
|
|
13366
|
+
const missing = !existsSync21(framePath) || statSync9(framePath).size <= 8;
|
|
13266
13367
|
if (missing && rangeStart === null) {
|
|
13267
13368
|
rangeStart = frameIndex;
|
|
13268
13369
|
} else if (!missing && rangeStart !== null) {
|
|
@@ -13352,17 +13453,25 @@ function resetCaptureAttemptProgress(job) {
|
|
|
13352
13453
|
job.framesRendered = 0;
|
|
13353
13454
|
}
|
|
13354
13455
|
var FIRST_FRAME_STALL_MS = 3e5;
|
|
13456
|
+
var FIRST_FRAME_STARTUP_FACTOR = 2;
|
|
13457
|
+
var FIRST_FRAME_STALL_CEILING_MS = 9e5;
|
|
13355
13458
|
var TAIL_STALL_MS = FIRST_FRAME_STALL_MS;
|
|
13356
|
-
function
|
|
13459
|
+
function firstFrameWindowMs(probeStartupMs) {
|
|
13460
|
+
const fromStartup = (probeStartupMs ?? 0) * FIRST_FRAME_STARTUP_FACTOR;
|
|
13461
|
+
if (!Number.isFinite(fromStartup)) return FIRST_FRAME_STALL_MS;
|
|
13462
|
+
return Math.max(FIRST_FRAME_STALL_MS, Math.min(FIRST_FRAME_STALL_CEILING_MS, fromStartup));
|
|
13463
|
+
}
|
|
13464
|
+
function frameStallRule(job, totalFrames, probeStartupMs) {
|
|
13357
13465
|
const noProgressMs = resolveCaptureStallTimeoutMs();
|
|
13358
13466
|
return {
|
|
13359
13467
|
progress: () => job.framesRendered ?? 0,
|
|
13360
13468
|
noProgressMs,
|
|
13361
|
-
firstProgressMs: Math.max(
|
|
13469
|
+
firstProgressMs: Math.max(firstFrameWindowMs(probeStartupMs), noProgressMs),
|
|
13362
13470
|
complete: () => (job.framesRendered ?? 0) >= totalFrames,
|
|
13363
13471
|
tailMs: Math.max(TAIL_STALL_MS, noProgressMs),
|
|
13364
13472
|
detail: () => describeWorkerPhases(job),
|
|
13365
|
-
attemptOpened: () => forgetWorkerPhases(job)
|
|
13473
|
+
attemptOpened: () => forgetWorkerPhases(job),
|
|
13474
|
+
activity: () => staticDedupActivity(job)
|
|
13366
13475
|
};
|
|
13367
13476
|
}
|
|
13368
13477
|
function isRecoverableParallelCaptureError(error) {
|
|
@@ -13387,7 +13496,7 @@ function countCapturedFrames(totalFrames, framesDir, frameExt) {
|
|
|
13387
13496
|
let captured = 0;
|
|
13388
13497
|
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex++) {
|
|
13389
13498
|
const framePath = join31(framesDir, formatCaptureFrameName(frameIndex, frameExt));
|
|
13390
|
-
if (
|
|
13499
|
+
if (existsSync21(framePath)) captured++;
|
|
13391
13500
|
}
|
|
13392
13501
|
return captured;
|
|
13393
13502
|
}
|
|
@@ -14050,9 +14159,10 @@ function resolveRenderDebugDir() {
|
|
|
14050
14159
|
async function executeRenderJob(job, projectDir, outputPath, progressSink, abortSignal, assertRenderActive) {
|
|
14051
14160
|
validateHlsRenderConfig(job.config);
|
|
14052
14161
|
validateDeliveryEncoderConfig(job.config);
|
|
14162
|
+
validateChromaSubsamplingConfig(job.config);
|
|
14053
14163
|
const debugDir = resolveRenderDebugDir();
|
|
14054
14164
|
const outputDir = dirname13(outputPath);
|
|
14055
|
-
if (!
|
|
14165
|
+
if (!existsSync21(outputDir)) mkdirSync12(outputDir, { recursive: true });
|
|
14056
14166
|
const workDir = job.config.debug ? join31(debugDir, job.id) : createRenderWorkDir(resolveRenderWorkDirPrefix(outputPath, job.id), outputDir);
|
|
14057
14167
|
const pipelineStart = Date.now();
|
|
14058
14168
|
const baseLog = job.config.logger ?? defaultLogger;
|
|
@@ -14194,7 +14304,7 @@ async function executeRenderPipeline(input) {
|
|
|
14194
14304
|
job.startedAt = /* @__PURE__ */ new Date();
|
|
14195
14305
|
assertNotAborted();
|
|
14196
14306
|
assertConfiguredFfmpegBinariesExist();
|
|
14197
|
-
if (!
|
|
14307
|
+
if (!existsSync21(workDir)) mkdirSync12(workDir, { recursive: true });
|
|
14198
14308
|
if (job.config.debug) {
|
|
14199
14309
|
log.info("[Render] Debug artifacts enabled", { workDir, logPath });
|
|
14200
14310
|
}
|
|
@@ -14224,7 +14334,7 @@ async function executeRenderPipeline(input) {
|
|
|
14224
14334
|
});
|
|
14225
14335
|
const entryFile = job.config.entryFile || "index.html";
|
|
14226
14336
|
const htmlPath = join31(projectDir, entryFile);
|
|
14227
|
-
if (!
|
|
14337
|
+
if (!existsSync21(htmlPath)) {
|
|
14228
14338
|
throw new Error(`Entry file not found: ${htmlPath}`);
|
|
14229
14339
|
}
|
|
14230
14340
|
assertNotAborted();
|
|
@@ -14316,6 +14426,7 @@ async function executeRenderPipeline(input) {
|
|
|
14316
14426
|
(result) => Object.assign(job, result)
|
|
14317
14427
|
);
|
|
14318
14428
|
const subTimelineWaitMemo = {};
|
|
14429
|
+
const staticDedupMemo = {};
|
|
14319
14430
|
const probeResult = await observeRenderStage(
|
|
14320
14431
|
observability,
|
|
14321
14432
|
"browser_probe",
|
|
@@ -14336,6 +14447,7 @@ async function executeRenderPipeline(input) {
|
|
|
14336
14447
|
needsAlpha,
|
|
14337
14448
|
deviceScaleFactor,
|
|
14338
14449
|
subTimelineWaitMemo,
|
|
14450
|
+
staticDedupMemo,
|
|
14339
14451
|
recordReferenceBackground
|
|
14340
14452
|
}),
|
|
14341
14453
|
// Browser probe is pre-capture; report `browser calibrating` so a
|
|
@@ -14568,7 +14680,7 @@ async function executeRenderPipeline(input) {
|
|
|
14568
14680
|
throw new Error("File server failed to initialize before frame capture");
|
|
14569
14681
|
}
|
|
14570
14682
|
const framesDir = join31(workDir, "captured-frames");
|
|
14571
|
-
if (!
|
|
14683
|
+
if (!existsSync21(framesDir)) mkdirSync12(framesDir, { recursive: true });
|
|
14572
14684
|
updateJobStatus(job, "rendering", "Checking browser GPU", 25, onProgress, {
|
|
14573
14685
|
code: "start_browsers"
|
|
14574
14686
|
});
|
|
@@ -14587,18 +14699,28 @@ async function executeRenderPipeline(input) {
|
|
|
14587
14699
|
forceScreenshot: captureForceScreenshot
|
|
14588
14700
|
});
|
|
14589
14701
|
const videoCaptureBeyondViewport = resolveVideoCaptureBeyondViewport(composition.videos.length);
|
|
14590
|
-
const
|
|
14591
|
-
|
|
14592
|
-
|
|
14593
|
-
|
|
14702
|
+
const captureSurface = resolveCaptureSurface(
|
|
14703
|
+
{
|
|
14704
|
+
needsAlpha,
|
|
14705
|
+
motionBlur: job.config.motionBlur,
|
|
14706
|
+
chromaSubsampling: job.config.chromaSubsampling
|
|
14707
|
+
},
|
|
14708
|
+
job.config.quality
|
|
14709
|
+
);
|
|
14710
|
+
if (job.config.chromaSubsampling === "444") {
|
|
14711
|
+
log.info("[Render] Capture: png (chromaSubsampling 444, lossless)");
|
|
14712
|
+
}
|
|
14594
14713
|
const captureOptions = {
|
|
14595
14714
|
width,
|
|
14596
14715
|
height,
|
|
14597
14716
|
fps: job.config.fps,
|
|
14598
|
-
|
|
14599
|
-
|
|
14600
|
-
|
|
14601
|
-
|
|
14717
|
+
...captureSurface,
|
|
14718
|
+
...videoLayer ? {
|
|
14719
|
+
format: "png",
|
|
14720
|
+
quality: void 0,
|
|
14721
|
+
transparent: true,
|
|
14722
|
+
hiddenElementIds: [videoLayer.videoId]
|
|
14723
|
+
} : {},
|
|
14602
14724
|
variables: job.config.variables,
|
|
14603
14725
|
deviceScaleFactor,
|
|
14604
14726
|
motionBlur: job.config.motionBlur,
|
|
@@ -14617,6 +14739,9 @@ async function executeRenderPipeline(input) {
|
|
|
14617
14739
|
videoMetadataHints,
|
|
14618
14740
|
skipReadinessVideoIds: videoReadinessSkipIds,
|
|
14619
14741
|
subTimelineWaitMemo,
|
|
14742
|
+
staticDedupMemo,
|
|
14743
|
+
compositionHash,
|
|
14744
|
+
onStaticDedupActivity: () => noteStaticDedupActivity(job),
|
|
14620
14745
|
// Probe-resolved duration: drawElement self-verification derives its
|
|
14621
14746
|
// sample frame indices from this so they land inside the drained range.
|
|
14622
14747
|
compositionDurationSeconds: job.duration,
|
|
@@ -14705,6 +14830,7 @@ async function executeRenderPipeline(input) {
|
|
|
14705
14830
|
);
|
|
14706
14831
|
const nativeHdrIds = /* @__PURE__ */ new Set([...nativeHdrVideoIds, ...nativeHdrImageIds]);
|
|
14707
14832
|
const hasHdrContent = Boolean(effectiveHdr && nativeHdrIds.size > 0);
|
|
14833
|
+
assertChromaSubsamplingSdr(job.config, hasHdrContent);
|
|
14708
14834
|
if (hasHdrContent) assertOutputScaleSupported(deviceScaleFactor, "hdr_layered");
|
|
14709
14835
|
routePageMotionBlur = pageMotionBlurForRoute({ hasHdrContent, useLayeredComposite: false });
|
|
14710
14836
|
const deSingleMinFrames = resolveDeSingleMinFrames(process.env);
|
|
@@ -15287,7 +15413,9 @@ async function executeRenderPipeline(input) {
|
|
|
15287
15413
|
usePageSideCompositing: capturePlan.usePageSideCompositing,
|
|
15288
15414
|
hasHdrContent: capturePlan.hasHdrContent,
|
|
15289
15415
|
hasShaderTransitions: compiled.hasShaderTransitions,
|
|
15290
|
-
isPngSequence
|
|
15416
|
+
isPngSequence,
|
|
15417
|
+
captureImageFormat: captureOptions.format ?? "jpeg",
|
|
15418
|
+
chromaSubsampling: job.config.chromaSubsampling ?? "420"
|
|
15291
15419
|
});
|
|
15292
15420
|
const encoderHdr = hasHdrContent ? effectiveHdr : void 0;
|
|
15293
15421
|
const presetFormat = outputFormat === "webm" || outputFormat === "mov" ? outputFormat : "mp4";
|
|
@@ -15295,7 +15423,8 @@ async function executeRenderPipeline(input) {
|
|
|
15295
15423
|
job.config.quality,
|
|
15296
15424
|
presetFormat,
|
|
15297
15425
|
encoderHdr,
|
|
15298
|
-
job.config.proresProfile
|
|
15426
|
+
job.config.proresProfile,
|
|
15427
|
+
job.config.chromaSubsampling
|
|
15299
15428
|
);
|
|
15300
15429
|
if (job.config.crf != null && job.config.videoBitrate) {
|
|
15301
15430
|
log.warn(
|
|
@@ -15377,7 +15506,7 @@ async function executeRenderPipeline(input) {
|
|
|
15377
15506
|
onProgress
|
|
15378
15507
|
});
|
|
15379
15508
|
},
|
|
15380
|
-
{ stall: frameStallRule(job, totalFrames) }
|
|
15509
|
+
{ stall: frameStallRule(job, totalFrames, perfStages.browserProbeMs) }
|
|
15381
15510
|
);
|
|
15382
15511
|
lastBrowserConsole = hdrRes.lastBrowserConsole;
|
|
15383
15512
|
layeredCaptureWarnings.push(...hdrRes.warnings);
|
|
@@ -15829,7 +15958,7 @@ async function executeRenderPipeline(input) {
|
|
|
15829
15958
|
interleaveFrames: overlap !== null,
|
|
15830
15959
|
openAttempt
|
|
15831
15960
|
}),
|
|
15832
|
-
{ stall: frameStallRule(job, totalFrames) }
|
|
15961
|
+
{ stall: frameStallRule(job, totalFrames, perfStages.browserProbeMs) }
|
|
15833
15962
|
);
|
|
15834
15963
|
let captureRes;
|
|
15835
15964
|
try {
|
|
@@ -15959,7 +16088,7 @@ async function executeRenderPipeline(input) {
|
|
|
15959
16088
|
})
|
|
15960
16089
|
);
|
|
15961
16090
|
const totalElapsed = Date.now() - pipelineStart;
|
|
15962
|
-
const tmpPeakBytes =
|
|
16091
|
+
const tmpPeakBytes = existsSync21(workDir) ? sampleDirectoryBytes(workDir) : 0;
|
|
15963
16092
|
recordTransientRetryObservability();
|
|
15964
16093
|
observability.checkpoint("pipeline", "artifact validated", { totalElapsedMs: totalElapsed });
|
|
15965
16094
|
const observabilitySummary = observability.summary({
|
|
@@ -16040,7 +16169,7 @@ async function executeRenderPipeline(input) {
|
|
|
16040
16169
|
}
|
|
16041
16170
|
}
|
|
16042
16171
|
if (job.config.debug) {
|
|
16043
|
-
if (!isPngSequence && !isHls &&
|
|
16172
|
+
if (!isPngSequence && !isHls && existsSync21(stagedOutputPath)) {
|
|
16044
16173
|
const debugOutput = join31(workDir, `output${videoExt}`);
|
|
16045
16174
|
copyFileSync5(stagedOutputPath, debugOutput);
|
|
16046
16175
|
}
|
|
@@ -16152,7 +16281,7 @@ async function executeRenderPipeline(input) {
|
|
|
16152
16281
|
|
|
16153
16282
|
// src/services/hyperframeLint.ts
|
|
16154
16283
|
import {
|
|
16155
|
-
existsSync as
|
|
16284
|
+
existsSync as existsSync22,
|
|
16156
16285
|
readFileSync as readFileSync10,
|
|
16157
16286
|
statSync as statSync10,
|
|
16158
16287
|
openSync as openSync5,
|
|
@@ -16206,7 +16335,7 @@ function readEntryHtml(filePath) {
|
|
|
16206
16335
|
}
|
|
16207
16336
|
function readProjectEntryFile(projectDir, preferredEntryFile) {
|
|
16208
16337
|
const absProjectDir = resolve9(projectDir);
|
|
16209
|
-
if (!
|
|
16338
|
+
if (!existsSync22(absProjectDir) || !statSync10(absProjectDir).isDirectory()) {
|
|
16210
16339
|
return { error: `Project directory not found: ${absProjectDir}` };
|
|
16211
16340
|
}
|
|
16212
16341
|
const entryCandidates = [preferredEntryFile, "index.html", "src/index.html"].filter(
|
|
@@ -16275,7 +16404,7 @@ async function runHyperframeLint(prepared) {
|
|
|
16275
16404
|
import { Worker as Worker2 } from "node:worker_threads";
|
|
16276
16405
|
import { fileURLToPath as fileURLToPath5 } from "node:url";
|
|
16277
16406
|
import { dirname as dirname14, join as join33 } from "node:path";
|
|
16278
|
-
import { existsSync as
|
|
16407
|
+
import { existsSync as existsSync23 } from "node:fs";
|
|
16279
16408
|
var DEFAULT_HEALTH_PORT = 9848;
|
|
16280
16409
|
async function startHealthWorker(options = {}) {
|
|
16281
16410
|
const log = options.logger ?? defaultLogger2();
|
|
@@ -16352,7 +16481,7 @@ function resolveWorkerEntry2() {
|
|
|
16352
16481
|
const here = dirname14(fileURLToPath5(import.meta.url));
|
|
16353
16482
|
const candidates = [join33(here, "healthWorkerThread.js"), join33(here, "healthWorkerThread.ts")];
|
|
16354
16483
|
for (const candidate of candidates) {
|
|
16355
|
-
if (
|
|
16484
|
+
if (existsSync23(candidate)) return candidate;
|
|
16356
16485
|
}
|
|
16357
16486
|
return void 0;
|
|
16358
16487
|
}
|
|
@@ -16392,7 +16521,7 @@ import {
|
|
|
16392
16521
|
createReferenceBackgroundRecorder as createReferenceBackgroundRecorder2
|
|
16393
16522
|
} from "@hyperframes/engine";
|
|
16394
16523
|
import { audioFailureDiagnostics as audioFailureDiagnostics3 } from "@hyperframes/engine";
|
|
16395
|
-
import { extname as extname4, isAbsolute as isAbsolute4, join as
|
|
16524
|
+
import { extname as extname4, isAbsolute as isAbsolute4, join as join35, relative as relative4, sep as sep4 } from "node:path";
|
|
16396
16525
|
import {
|
|
16397
16526
|
fpsToNumber as fpsToNumber9,
|
|
16398
16527
|
HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
|
|
@@ -16418,11 +16547,15 @@ import {
|
|
|
16418
16547
|
// src/services/distributed/chunkFrames.ts
|
|
16419
16548
|
import {
|
|
16420
16549
|
compositionRequiresWebGpu as compositionRequiresWebGpu3,
|
|
16421
|
-
createVideoFrameInjector as createVideoFrameInjector3
|
|
16550
|
+
createVideoFrameInjector as createVideoFrameInjector3,
|
|
16551
|
+
mediaIdPathSegment as mediaIdPathSegment3
|
|
16422
16552
|
} from "@hyperframes/engine";
|
|
16423
16553
|
|
|
16424
16554
|
// src/services/distributed/shared.ts
|
|
16425
16555
|
import { execFile as execFileCallback } from "node:child_process";
|
|
16556
|
+
import { dirname as dirname15, join as join34 } from "node:path";
|
|
16557
|
+
import { existsSync as existsSync24, readFileSync as readFileSync11 } from "node:fs";
|
|
16558
|
+
import { fileURLToPath as fileURLToPath6 } from "node:url";
|
|
16426
16559
|
import { promisify as promisify2 } from "node:util";
|
|
16427
16560
|
import {
|
|
16428
16561
|
getFfmpegBinary,
|
|
@@ -16430,6 +16563,30 @@ import {
|
|
|
16430
16563
|
} from "@hyperframes/engine";
|
|
16431
16564
|
var PLAN_AUDIO_RELATIVE_PATH = MIXED_AUDIO_FILENAME3;
|
|
16432
16565
|
var execFile = promisify2(execFileCallback);
|
|
16566
|
+
var cachedProducerVersion = null;
|
|
16567
|
+
function readProducerVersion() {
|
|
16568
|
+
if (cachedProducerVersion !== null) return cachedProducerVersion;
|
|
16569
|
+
const startDir = dirname15(fileURLToPath6(import.meta.url));
|
|
16570
|
+
let current = startDir;
|
|
16571
|
+
for (let i = 0; i < 10; i++) {
|
|
16572
|
+
const candidate = join34(current, "package.json");
|
|
16573
|
+
if (existsSync24(candidate)) {
|
|
16574
|
+
try {
|
|
16575
|
+
const pkg = JSON.parse(readFileSync11(candidate, "utf-8"));
|
|
16576
|
+
if (pkg.name === "@hyperframes/producer" && typeof pkg.version === "string") {
|
|
16577
|
+
cachedProducerVersion = pkg.version;
|
|
16578
|
+
return pkg.version;
|
|
16579
|
+
}
|
|
16580
|
+
} catch {
|
|
16581
|
+
}
|
|
16582
|
+
}
|
|
16583
|
+
const parent = dirname15(current);
|
|
16584
|
+
if (parent === current) break;
|
|
16585
|
+
current = parent;
|
|
16586
|
+
}
|
|
16587
|
+
cachedProducerVersion = "0.0.0-unknown";
|
|
16588
|
+
return cachedProducerVersion;
|
|
16589
|
+
}
|
|
16433
16590
|
|
|
16434
16591
|
// src/services/distributed/chunkWeights.ts
|
|
16435
16592
|
import { resolveFrameFormat } from "@hyperframes/engine";
|
|
@@ -16510,9 +16667,9 @@ var PLAN_ROOT_CATEGORY = {
|
|
|
16510
16667
|
var PLAN_DIR_SIZE_LIMIT_BYTES = 2 * 1024 * 1024 * 1024;
|
|
16511
16668
|
var FREEZE_OWNED_PLAN_FILES = [
|
|
16512
16669
|
"plan.json",
|
|
16513
|
-
|
|
16514
|
-
|
|
16515
|
-
|
|
16670
|
+
join35("meta", "composition.json"),
|
|
16671
|
+
join35("meta", "encoder.json"),
|
|
16672
|
+
join35("meta", "chunks.json")
|
|
16516
16673
|
];
|
|
16517
16674
|
|
|
16518
16675
|
// src/services/distributed/renderConfigValidation.ts
|
|
@@ -16672,6 +16829,7 @@ function assertRequestOptionScalars(options) {
|
|
|
16672
16829
|
assertOptionalEnum(options, "proresProfile", PRORES_PROFILE_NAMES2);
|
|
16673
16830
|
assertOptionalEnum(options, "strictness", ["strict", "best-effort"]);
|
|
16674
16831
|
assertOptionalEnum(options, "hdrMode", ["auto", "force-hdr", "force-sdr"]);
|
|
16832
|
+
assertOptionalEnum(options, "chromaSubsampling", ["420", "444"]);
|
|
16675
16833
|
assertOptionalEnum(options, "pageMotionBlur", ["off"]);
|
|
16676
16834
|
if (options.videoFrameFormat !== void 0 && !isVideoFrameFormat2(options.videoFrameFormat)) {
|
|
16677
16835
|
throw new Error("Render request videoFrameFormat is invalid");
|
|
@@ -16832,7 +16990,15 @@ function parseRenderOptions(body) {
|
|
|
16832
16990
|
const format = parseServerFormat(body.format);
|
|
16833
16991
|
const outputDynamicRange = parseServerOutputDynamicRange(body.outputDynamicRange) ?? fromRenderHdrMode(parseLegacyServerHdrMode(body.hdrMode));
|
|
16834
16992
|
const encoder = parseEncoderOptions(body, format ?? "mp4");
|
|
16835
|
-
const {
|
|
16993
|
+
const {
|
|
16994
|
+
crf,
|
|
16995
|
+
videoBitrate,
|
|
16996
|
+
videoFrameFormat,
|
|
16997
|
+
keyframeIntervalSeconds,
|
|
16998
|
+
maxBitrate,
|
|
16999
|
+
bufferSize,
|
|
17000
|
+
chromaSubsampling
|
|
17001
|
+
} = encoder.ok ? encoder.options : {};
|
|
16836
17002
|
const { variables, outputResolution, outputResolutionAspectAgnostic } = parseRenderOverrides(body);
|
|
16837
17003
|
return {
|
|
16838
17004
|
outputPath,
|
|
@@ -16845,6 +17011,7 @@ function parseRenderOptions(body) {
|
|
|
16845
17011
|
keyframeIntervalSeconds,
|
|
16846
17012
|
maxBitrate,
|
|
16847
17013
|
bufferSize,
|
|
17014
|
+
chromaSubsampling,
|
|
16848
17015
|
useGpu,
|
|
16849
17016
|
debug,
|
|
16850
17017
|
forceScreenshot,
|
|
@@ -16884,6 +17051,7 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
16884
17051
|
keyframeIntervalSeconds: input.keyframeIntervalSeconds,
|
|
16885
17052
|
maxBitrate: input.maxBitrate,
|
|
16886
17053
|
bufferSize: input.bufferSize,
|
|
17054
|
+
chromaSubsampling: input.chromaSubsampling,
|
|
16887
17055
|
useGpu: input.useGpu,
|
|
16888
17056
|
debug: input.debug,
|
|
16889
17057
|
strictness: input.strictness,
|
|
@@ -16901,16 +17069,29 @@ function buildRenderJobConfig(input, outputPath, log) {
|
|
|
16901
17069
|
function resolvePreparedRenderOutput(prepared, rendersDir, log) {
|
|
16902
17070
|
const { input, cleanupProjectDir } = prepared;
|
|
16903
17071
|
const absoluteOutputPath = resolveOutputPath(input.projectDir, input.outputPath, rendersDir, log);
|
|
16904
|
-
const outputDir =
|
|
17072
|
+
const outputDir = dirname16(absoluteOutputPath);
|
|
16905
17073
|
if (!existsSync25(outputDir)) mkdirSync13(outputDir, { recursive: true });
|
|
16906
17074
|
return { input, cleanupProjectDir, absoluteOutputPath };
|
|
16907
17075
|
}
|
|
17076
|
+
function prepareRenderJob(prepared, rendersDir, log) {
|
|
17077
|
+
try {
|
|
17078
|
+
const output = resolvePreparedRenderOutput(prepared, rendersDir, log);
|
|
17079
|
+
const job = createRenderJob(buildRenderJobConfig(output.input, output.absoluteOutputPath, log));
|
|
17080
|
+
return { ...output, job };
|
|
17081
|
+
} catch (error) {
|
|
17082
|
+
cleanupTempDir(prepared.cleanupProjectDir, log);
|
|
17083
|
+
return { error: error instanceof Error ? error.message : String(error) };
|
|
17084
|
+
}
|
|
17085
|
+
}
|
|
16908
17086
|
function validateRenderOverrides(body) {
|
|
16909
17087
|
const encoder = parseEncoderOptions(body, parseServerFormat(body.format) ?? "mp4");
|
|
16910
17088
|
if (!encoder.ok) return encoder.error;
|
|
16911
17089
|
if (body.maxRenderMs !== void 0 && (typeof body.maxRenderMs !== "number" || !Number.isInteger(body.maxRenderMs) || body.maxRenderMs < 0)) {
|
|
16912
17090
|
return "maxRenderMs must be a non-negative integer number of milliseconds";
|
|
16913
17091
|
}
|
|
17092
|
+
if (typeof body.workers === "number" && (!Number.isInteger(body.workers) || body.workers < 1)) {
|
|
17093
|
+
return "workers must be a positive integer";
|
|
17094
|
+
}
|
|
16914
17095
|
if (body.variables !== void 0 && !isPlainObject2(body.variables)) {
|
|
16915
17096
|
return 'variables must be a JSON object keyed by variable id (e.g. {"title":"Hello"})';
|
|
16916
17097
|
}
|
|
@@ -16925,6 +17106,9 @@ function validateRenderOverrides(body) {
|
|
|
16925
17106
|
if (outputDynamicRange !== void 0 && legacyHdrMode !== void 0 && outputDynamicRange !== fromRenderHdrMode(legacyHdrMode)) {
|
|
16926
17107
|
return "outputDynamicRange and legacy hdrMode must describe the same output policy";
|
|
16927
17108
|
}
|
|
17109
|
+
if (body.chromaSubsampling === "444" && outputDynamicRange === "hdr") {
|
|
17110
|
+
return 'chromaSubsampling "444" is SDR only, not outputDynamicRange "hdr"';
|
|
17111
|
+
}
|
|
16928
17112
|
return validateOutputResolutionOverride(body);
|
|
16929
17113
|
}
|
|
16930
17114
|
function validateOutputResolutionOverride(body) {
|
|
@@ -16968,8 +17152,8 @@ async function resolveInlineRenderHtml(body) {
|
|
|
16968
17152
|
}
|
|
16969
17153
|
function materializeInlineProject(html, options) {
|
|
16970
17154
|
const tempRoot = process.env.PRODUCER_TMP_PROJECT_DIR || tmpdir3();
|
|
16971
|
-
const tempProjectDir = mkdtempSync(
|
|
16972
|
-
writeFileSync8(
|
|
17155
|
+
const tempProjectDir = mkdtempSync(join36(tempRoot, "producer-project-"));
|
|
17156
|
+
writeFileSync8(join36(tempProjectDir, "index.html"), html, "utf-8");
|
|
16973
17157
|
return {
|
|
16974
17158
|
prepared: {
|
|
16975
17159
|
input: { projectDir: tempProjectDir, ...options },
|
|
@@ -17188,11 +17372,11 @@ function createRenderHandlers(options = {}) {
|
|
|
17188
17372
|
if ("error" in preparedResult) {
|
|
17189
17373
|
return c.json({ success: false, requestId, error: preparedResult.error }, 400);
|
|
17190
17374
|
}
|
|
17191
|
-
const
|
|
17192
|
-
|
|
17193
|
-
|
|
17194
|
-
|
|
17195
|
-
|
|
17375
|
+
const preparedJob = prepareRenderJob(preparedResult.prepared, rendersDir, log);
|
|
17376
|
+
if ("error" in preparedJob) {
|
|
17377
|
+
return c.json({ success: false, requestId, error: preparedJob.error }, 400);
|
|
17378
|
+
}
|
|
17379
|
+
const { job, input, cleanupProjectDir, absoluteOutputPath } = preparedJob;
|
|
17196
17380
|
const release = await renderSemaphore.acquire();
|
|
17197
17381
|
log.info("render started", {
|
|
17198
17382
|
requestId,
|
|
@@ -17200,7 +17384,6 @@ function createRenderHandlers(options = {}) {
|
|
|
17200
17384
|
fps: input.fps,
|
|
17201
17385
|
quality: input.quality
|
|
17202
17386
|
});
|
|
17203
|
-
const job = createRenderJob(buildRenderJobConfig(input, absoluteOutputPath, log));
|
|
17204
17387
|
try {
|
|
17205
17388
|
await executeRenderJob(
|
|
17206
17389
|
job,
|
|
@@ -17268,13 +17451,20 @@ function createRenderHandlers(options = {}) {
|
|
|
17268
17451
|
const t0 = Date.now();
|
|
17269
17452
|
const prepared = await prepareSseRenderRequest(c, stream, requestId);
|
|
17270
17453
|
if (!prepared) return;
|
|
17271
|
-
const
|
|
17272
|
-
|
|
17273
|
-
|
|
17274
|
-
|
|
17275
|
-
|
|
17454
|
+
const preparedJob = prepareRenderJob(prepared, rendersDir, log);
|
|
17455
|
+
if ("error" in preparedJob) {
|
|
17456
|
+
await stream.writeSSE({
|
|
17457
|
+
data: JSON.stringify({
|
|
17458
|
+
type: "error",
|
|
17459
|
+
requestId,
|
|
17460
|
+
error: preparedJob.error,
|
|
17461
|
+
stage: "validation"
|
|
17462
|
+
})
|
|
17463
|
+
});
|
|
17464
|
+
return;
|
|
17465
|
+
}
|
|
17466
|
+
const { job, input, cleanupProjectDir, absoluteOutputPath } = preparedJob;
|
|
17276
17467
|
log.info("render-stream started", { requestId, projectDir: input.projectDir });
|
|
17277
|
-
const job = createRenderJob(buildRenderJobConfig(input, absoluteOutputPath, log));
|
|
17278
17468
|
const abortController = new AbortController();
|
|
17279
17469
|
const onRequestAbort = () => abortController.abort(new RenderCancelledError("request_aborted"));
|
|
17280
17470
|
c.req.raw.signal.addEventListener("abort", onRequestAbort, { once: true });
|
|
@@ -17318,7 +17508,8 @@ function createRenderHandlers(options = {}) {
|
|
|
17318
17508
|
videoDurationSeconds: job.duration ?? null,
|
|
17319
17509
|
outcome: job.outcome ?? "completed",
|
|
17320
17510
|
warnings: job.warnings,
|
|
17321
|
-
perf: job.perfSummary ?? null
|
|
17511
|
+
perf: job.perfSummary ?? null,
|
|
17512
|
+
producerVersion: readProducerVersion()
|
|
17322
17513
|
})
|
|
17323
17514
|
});
|
|
17324
17515
|
} catch (error) {
|
|
@@ -17363,9 +17554,26 @@ function createRenderHandlers(options = {}) {
|
|
|
17363
17554
|
});
|
|
17364
17555
|
return { render, renderStream, lint, health, outputs, queue };
|
|
17365
17556
|
}
|
|
17557
|
+
function isCrossOriginBrowserRequest(c) {
|
|
17558
|
+
const fetchSite = c.req.header("sec-fetch-site");
|
|
17559
|
+
if (fetchSite) return fetchSite !== "same-origin" && fetchSite !== "none";
|
|
17560
|
+
const origin = c.req.header("origin");
|
|
17561
|
+
if (!origin) return false;
|
|
17562
|
+
try {
|
|
17563
|
+
return new URL(origin).host !== c.req.header("host");
|
|
17564
|
+
} catch {
|
|
17565
|
+
return true;
|
|
17566
|
+
}
|
|
17567
|
+
}
|
|
17366
17568
|
function createProducerApp(options = {}) {
|
|
17367
17569
|
const app = new Hono2();
|
|
17368
17570
|
const handlers = createRenderHandlers(options);
|
|
17571
|
+
app.post("*", async (c, next) => {
|
|
17572
|
+
if (isCrossOriginBrowserRequest(c)) {
|
|
17573
|
+
return c.json({ success: false, error: "Cross-origin requests are not allowed" }, 403);
|
|
17574
|
+
}
|
|
17575
|
+
await next();
|
|
17576
|
+
});
|
|
17369
17577
|
app.get("/health", handlers.health);
|
|
17370
17578
|
app.post("/render", handlers.render);
|
|
17371
17579
|
app.post("/render/stream", handlers.renderStream);
|