@hyperframes/producer 0.9.107 → 0.10.1

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 CHANGED
@@ -8,7 +8,7 @@ Full HTML-to-video rendering pipeline: capture frames with Chrome's BeginFrame A
8
8
  npm install @hyperframes/producer
9
9
  ```
10
10
 
11
- **Requirements:** Node.js >= 22, FFmpeg, and the pinned `chrome-headless-shell`: run `npx hyperframes browser ensure` once, or name a browser in `PRODUCER_HEADLESS_SHELL_PATH`. A cached browser is used only when its files match the pinned build. HDR capture needs a full Chrome named in `HYPERFRAMES_BROWSER_PATH`.
11
+ **Requirements:** Node.js >= 22.19, FFmpeg, and the pinned `chrome-headless-shell`: run `npx hyperframes browser ensure` once, or name a browser in `PRODUCER_HEADLESS_SHELL_PATH`. A cached browser is used only when its files match the pinned build. HDR capture needs a full Chrome named in `HYPERFRAMES_BROWSER_PATH`.
12
12
 
13
13
  ## Usage
14
14
 
@@ -400,11 +400,8 @@ import { promisify } from "node:util";
400
400
  import { Readable } from "node:stream";
401
401
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
402
402
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
403
- import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
404
- import {
405
- PREVIEW_FOR_ANOTHER_SITE_META,
406
- serviceWorkerScriptFetch
407
- } from "@hyperframes/core/studio-preview-mark";
403
+ import { markForAnotherSite } from "@hyperframes/core/compiler/html-document";
404
+ import { serviceWorkerScriptFetch } from "@hyperframes/core/studio-preview-mark";
408
405
  import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
409
406
  import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
410
407
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -1007,7 +1004,6 @@ var HF_BRIDGE_SCRIPT = `(function() {
1007
1004
  if (bridge()) __realClearInterval(iv);
1008
1005
  }, 50);
1009
1006
  })();`;
1010
- var OFFER_NO_FRAMING_SITE_AN_EDITING_PORT = `<meta name="${PREVIEW_FOR_ANOTHER_SITE_META}">`;
1011
1007
  var RENDER_CAPTURE_MODE_SHIM = "globalThis.__HF_RENDER_CAPTURE_MODE = true;";
1012
1008
  function closeFileServerSafely(fileServer, label, log = defaultLogger) {
1013
1009
  try {
@@ -1106,7 +1102,7 @@ function createFileServer(options) {
1106
1102
  html = injectScriptsAtHeadStart(html, preHeadScripts);
1107
1103
  }
1108
1104
  html = isIndex ? injectScriptsIntoHtml(html, headScripts, bodyScripts, stripEmbeddedRuntime) : html;
1109
- html = injectTagsAtHeadStart(html, OFFER_NO_FRAMING_SITE_AN_EDITING_PORT);
1105
+ html = markForAnotherSite(html);
1110
1106
  return c.text(html, 200, { "Content-Type": contentType });
1111
1107
  }
1112
1108
  if (ext === ".png") {
@@ -8827,6 +8823,8 @@ async function runCaptureStage(input) {
8827
8823
  pageErrorLines: workerPageErrors,
8828
8824
  openAttempt: input.openAttempt,
8829
8825
  verifyFirstSession: input.verifyFirstSession,
8826
+ prepareSession: input.prepareSession,
8827
+ onSessionUnprepared: input.onSessionUnprepared,
8830
8828
  onProgress: (progress) => {
8831
8829
  if (progress.latestWorkerPhase) {
8832
8830
  if (progress.capturedFrames === 0) reportWorkerStartup(job, progress, onProgress);
@@ -9740,7 +9738,11 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
9740
9738
  } : void 0,
9741
9739
  void 0,
9742
9740
  options.cfg,
9743
- { verifyFirstSession: options.verifyFirstSession }
9741
+ {
9742
+ verifyFirstSession: options.verifyFirstSession,
9743
+ prepareSession: options.prepareSession,
9744
+ onSessionUnprepared: options.onSessionUnprepared
9745
+ }
9744
9746
  );
9745
9747
  pushWorkerDedupPerfs(workerResults, options.dedupPerfs);
9746
9748
  if (options.pageErrorLines) pushWorkerPageErrors(workerResults, options.pageErrorLines);
@@ -12123,7 +12125,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
12123
12125
  const composition = compileResult.composition;
12124
12126
  const { deviceScaleFactor } = compileResult;
12125
12127
  let forceScreenshot = compileResult.forceScreenshot;
12126
- if (cfg.lowMemoryMode) forceScreenshot = true;
12128
+ if (cfg.lowMemoryMode || deviceScaleFactor !== 1) forceScreenshot = true;
12127
12129
  const { width, height } = composition;
12128
12130
  if (config.rejectOnSystemFonts !== false) {
12129
12131
  validateNoSystemFonts(compiled.html);
@@ -13796,8 +13798,8 @@ import { join as join34 } from "node:path";
13796
13798
  import {
13797
13799
  assertSwiftShader,
13798
13800
  BROWSER_GPU_NOT_SOFTWARE as BROWSER_GPU_NOT_SOFTWARE4,
13799
- calculateOptimalWorkers as calculateOptimalWorkers2,
13800
13801
  classifyCaptureFailure as classifyCaptureFailure4,
13802
+ computeWorkerSizing as computeWorkerSizing2,
13801
13803
  closeCaptureSession as closeCaptureSession11,
13802
13804
  createCaptureSession as createCaptureSession11,
13803
13805
  createFrameLookupTable as createFrameLookupTable6,
@@ -13805,6 +13807,8 @@ import {
13805
13807
  getEncoderPreset as getEncoderPreset6,
13806
13808
  initializeSession as initializeSession10,
13807
13809
  measureVideoShownBoxes,
13810
+ measureVideoShownBoxPart,
13811
+ mergeVideoShownBoxParts,
13808
13812
  probeBeginFrameLiveness as probeBeginFrameLiveness2,
13809
13813
  readWebGlVendorInfoFromCanvas,
13810
13814
  resolveConfig as resolveConfig5,
@@ -13831,6 +13835,23 @@ function resolveChunkCaptureWorkers(framesInChunk, machineSized, maxCaptureWorke
13831
13835
  const byFrames = Math.floor(framesInChunk / MIN_FRAMES_PER_CHUNK_BROWSER);
13832
13836
  return Math.max(machineSized, Math.floor(Math.min(maxCaptureWorkers, byFrames)));
13833
13837
  }
13838
+ function chunkCaptureSizingLog(input) {
13839
+ const { machineSizing } = input;
13840
+ return {
13841
+ chunkIndex: input.chunkIndex,
13842
+ frames: input.framesEncoded,
13843
+ workers: input.workers,
13844
+ machineSizedWorkers: machineSizing.workers,
13845
+ boundBy: machineSizing.boundBy,
13846
+ cpuBasedWorkers: machineSizing.cpuBasedWorkers,
13847
+ memoryBasedWorkers: machineSizing.memoryBasedWorkers,
13848
+ frameBasedWorkers: machineSizing.frameBasedWorkers,
13849
+ maxCaptureWorkers: input.maxCaptureWorkers ?? null,
13850
+ captureMode: input.captureMode,
13851
+ captureStageMs: input.captureStageMs,
13852
+ captureMsPerFrame: input.framesEncoded > 0 ? Math.round(input.captureStageMs / input.framesEncoded * 10) / 10 : null
13853
+ };
13854
+ }
13834
13855
  function resolveChunkFrameRange(slice, chunkIndex, frameRange) {
13835
13856
  if (frameRange === void 0) return { startFrame: slice.startFrame, endFrame: slice.endFrame };
13836
13857
  const { startFrame, endFrame } = frameRange;
@@ -13924,6 +13945,35 @@ async function beginFrameSessionNeedsScreenshotFallback(session, probe = probeBe
13924
13945
  );
13925
13946
  return !await probe(session.page, timeoutMs, probeTick, session.beginFrameIntervalMs);
13926
13947
  }
13948
+ function createSharedBoxMeasure(onDone) {
13949
+ const started = Date.now();
13950
+ let done = false;
13951
+ let workerCount = 0;
13952
+ const shares = /* @__PURE__ */ new Map();
13953
+ return {
13954
+ settled: () => done,
13955
+ fullSize: () => {
13956
+ if (done) return;
13957
+ done = true;
13958
+ onDone(void 0);
13959
+ },
13960
+ add: (worker, part, cost) => {
13961
+ if (done) return;
13962
+ if (worker.workerCount !== workerCount) shares.clear();
13963
+ workerCount = worker.workerCount;
13964
+ shares.set(worker.workerId, { part, ...cost });
13965
+ if (shares.size < workerCount) return;
13966
+ done = true;
13967
+ const all = [...shares.values()];
13968
+ onDone(mergeVideoShownBoxParts(all.map((share) => share.part)), {
13969
+ workers: workerCount,
13970
+ frames: all.reduce((sum2, share) => sum2 + share.frames, 0),
13971
+ durationMs: Date.now() - started,
13972
+ slowestShareMs: Math.max(...all.map((share) => share.durationMs))
13973
+ });
13974
+ }
13975
+ };
13976
+ }
13927
13977
  function hashChunkOutput(outputPath, kind) {
13928
13978
  if (kind === "file") return sha256Hex(readFileSync12(outputPath));
13929
13979
  const entries = readdirSync9(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
@@ -14100,9 +14150,10 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14100
14150
  });
14101
14151
  captureOptions.onStaticDedupActivity = () => noteCaptureActivity(job);
14102
14152
  const captureFrames = effectiveChunkFrames(framesInChunk, slice.captureCost);
14153
+ const machineSizing = computeWorkerSizing2(captureFrames, void 0, cfg);
14103
14154
  const chunkWorkerCount = resolveChunkCaptureWorkers(
14104
14155
  captureFrames,
14105
- calculateOptimalWorkers2(captureFrames, void 0, cfg),
14156
+ machineSizing.workers,
14106
14157
  options?.maxCaptureWorkers
14107
14158
  );
14108
14159
  let session = null;
@@ -14129,13 +14180,25 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14129
14180
  });
14130
14181
  boxesReady.catch(() => {
14131
14182
  });
14183
+ const shownVideoIds = [...shownFrames.keys()];
14184
+ const chunkFrameTimes = chunkFrameNumbers.map(
14185
+ (frame) => frame * chunkFps.den / chunkFps.num
14186
+ );
14132
14187
  const measureBoxes = async (page) => {
14133
- shownBoxes = await measureVideoShownBoxes(
14134
- page,
14135
- [...shownFrames.keys()],
14136
- chunkFrameNumbers.map((frame) => frame * chunkFps.den / chunkFps.num)
14137
- );
14188
+ shownBoxes = await measureVideoShownBoxes(page, shownVideoIds, chunkFrameTimes);
14189
+ boxesMeasured();
14190
+ };
14191
+ const sharedBoxes = createSharedBoxMeasure((boxes2, pass) => {
14192
+ shownBoxes = boxes2;
14138
14193
  boxesMeasured();
14194
+ if (pass) log.info("[renderChunk] video boxes measured", { chunkIndex, ...pass });
14195
+ });
14196
+ const measureShare = async (session2, worker) => {
14197
+ if (sharedBoxes.settled()) return;
14198
+ const started = Date.now();
14199
+ const times = chunkFrameTimes.filter((_, i) => i % worker.workerCount === worker.workerId);
14200
+ const part = await measureVideoShownBoxPart(session2.page, shownVideoIds, times);
14201
+ sharedBoxes.add(worker, part, { frames: times.length, durationMs: Date.now() - started });
14139
14202
  };
14140
14203
  if (chunkWorkerCount === 1) {
14141
14204
  const bootStarted = Date.now();
@@ -14178,14 +14241,13 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14178
14241
  );
14179
14242
  sessionBootMs += Date.now() - screenshotBootStarted;
14180
14243
  }
14181
- } else if (!verifyInWorker) {
14182
- boxesMeasured();
14244
+ } else if (!verifyInWorker || shownVideoIds.length === 0) {
14245
+ sharedBoxes.fullSize();
14183
14246
  }
14184
14247
  let verification;
14185
14248
  const verifyFirstWorker = (first) => verification ??= (async () => {
14186
14249
  sessionBootMs = Date.now() - verifyStarted;
14187
14250
  try {
14188
- await measureBoxes(first.page);
14189
14251
  const selectedScreenshot = first.launchCaptureMode === "screenshot";
14190
14252
  if (selectedScreenshot || await beginFrameSessionNeedsScreenshotFallback(first)) {
14191
14253
  forceScreenshotForChunk = true;
@@ -14370,7 +14432,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14370
14432
  onFrameLanded: (frame) => overlap.current?.onFrameLanded(frame),
14371
14433
  interleaveFrames: interleavesCapture(overlap.current !== null, options),
14372
14434
  openAttempt,
14373
- verifyFirstSession: forceScreenshot || !verifyInWorker ? void 0 : verifyFirstWorker
14435
+ verifyFirstSession: forceScreenshot || !verifyInWorker ? void 0 : verifyFirstWorker,
14436
+ prepareSession: forceScreenshot || !verifyInWorker ? void 0 : measureShare,
14437
+ onSessionUnprepared: () => sharedBoxes.fullSize()
14374
14438
  }),
14375
14439
  { stall: frameStallRule(job, framesInChunk, void 0) }
14376
14440
  ).catch(async (captureError) => {
@@ -14382,7 +14446,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14382
14446
  },
14383
14447
  resetForScreenshotRetry: () => {
14384
14448
  rmSync12(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
14385
- boxesMeasured();
14449
+ sharedBoxes.fullSize();
14386
14450
  mkdirSync15(framesDir, { recursive: true });
14387
14451
  capturePerfs.length = 0;
14388
14452
  captureAttempts.length = 0;
@@ -14477,6 +14541,18 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14477
14541
  };
14478
14542
  writeFileSync12(perfPath, `${JSON.stringify(perfPayload, null, 2)}
14479
14543
  `, "utf-8");
14544
+ log.info(
14545
+ "[renderChunk] capture sizing",
14546
+ chunkCaptureSizingLog({
14547
+ chunkIndex,
14548
+ framesEncoded,
14549
+ workers: chunkWorkerCount,
14550
+ machineSizing,
14551
+ maxCaptureWorkers: options?.maxCaptureWorkers,
14552
+ captureMode,
14553
+ captureStageMs
14554
+ })
14555
+ );
14480
14556
  try {
14481
14557
  rmSync12(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
14482
14558
  rmSync12(videoFramesDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "82bb6f5b055041dbe4a42d8eae51c8d405236b4ae160e7c43bf13c2b6ea431af",
4
+ "sha256": "88ad63322ffd638d062d5e3854d1a9937439aa8614c715234ac2a5290e84cd14",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"