@hyperframes/producer 0.9.106 → 0.10.0

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
 
@@ -365,6 +365,7 @@ import {
365
365
  getDrawElementVerificationDetails,
366
366
  augmentProtocolTimeoutError,
367
367
  augmentPageNavigationTimeoutError,
368
+ createCacheLease,
368
369
  displaySize
369
370
  } from "@hyperframes/engine";
370
371
  import {
@@ -399,11 +400,8 @@ import { promisify } from "node:util";
399
400
  import { Readable } from "node:stream";
400
401
  import { join as join2, extname, resolve as resolve2, sep as sep2 } from "node:path";
401
402
  import { injectScriptsAtHeadStart, injectScriptsIntoHtml } from "@hyperframes/core/compiler";
402
- import { injectTagsAtHeadStart } from "@hyperframes/core/compiler/html-document";
403
- import {
404
- PREVIEW_FOR_ANOTHER_SITE_META,
405
- serviceWorkerScriptFetch
406
- } from "@hyperframes/core/studio-preview-mark";
403
+ import { markForAnotherSite } from "@hyperframes/core/compiler/html-document";
404
+ import { serviceWorkerScriptFetch } from "@hyperframes/core/studio-preview-mark";
407
405
  import { fpsToNumber, terminalText as terminalText2 } from "@hyperframes/core";
408
406
  import { isPrivateFileUnder as isPrivateFileUnder2, isStudioPrivatePath as isStudioPrivatePath2 } from "@hyperframes/core/safe-path";
409
407
  import { stripSdrPngColourTags } from "@hyperframes/core/compiler/png-colour-tags";
@@ -1006,7 +1004,6 @@ var HF_BRIDGE_SCRIPT = `(function() {
1006
1004
  if (bridge()) __realClearInterval(iv);
1007
1005
  }, 50);
1008
1006
  })();`;
1009
- var OFFER_NO_FRAMING_SITE_AN_EDITING_PORT = `<meta name="${PREVIEW_FOR_ANOTHER_SITE_META}">`;
1010
1007
  var RENDER_CAPTURE_MODE_SHIM = "globalThis.__HF_RENDER_CAPTURE_MODE = true;";
1011
1008
  function closeFileServerSafely(fileServer, label, log = defaultLogger) {
1012
1009
  try {
@@ -1105,7 +1102,7 @@ function createFileServer(options) {
1105
1102
  html = injectScriptsAtHeadStart(html, preHeadScripts);
1106
1103
  }
1107
1104
  html = isIndex ? injectScriptsIntoHtml(html, headScripts, bodyScripts, stripEmbeddedRuntime) : html;
1108
- html = injectTagsAtHeadStart(html, OFFER_NO_FRAMING_SITE_AN_EDITING_PORT);
1105
+ html = markForAnotherSite(html);
1109
1106
  return c.text(html, 200, { "Content-Type": contentType });
1110
1107
  }
1111
1108
  if (ext === ".png") {
@@ -1598,6 +1595,7 @@ import {
1598
1595
  } from "@hyperframes/engine";
1599
1596
 
1600
1597
  // src/services/render/renderDirOwner.ts
1598
+ import { ownerRecordState, processOwnerRecord } from "@hyperframes/engine";
1601
1599
  import { RENDER_TEMP_DIR } from "@hyperframes/core/project-folders";
1602
1600
  import { createStagingDir, toWin32LongPath } from "@hyperframes/core/atomic-file";
1603
1601
 
@@ -7649,7 +7647,8 @@ async function runExtractVideosStage(input) {
7649
7647
  shownBoxes,
7650
7648
  urlByAbsentLocalPath,
7651
7649
  audioDownloadDir,
7652
- skipFrameExtractionIds = []
7650
+ skipFrameExtractionIds = [],
7651
+ cacheLease
7653
7652
  } = input;
7654
7653
  const stage2Start = Date.now();
7655
7654
  const assetRoots = job.config.allowOutsideProjectAssets ? void 0 : mediaAssetRoots(projectDir, compiledDir);
@@ -7769,6 +7768,7 @@ async function runExtractVideosStage(input) {
7769
7768
  contentKeyedDirs: [join14(compiledDir, REMOTE_MEDIA_SUBDIR)],
7770
7769
  urlByAbsentLocalPath,
7771
7770
  assetRoots,
7771
+ cacheLease,
7772
7772
  onProgress: ({ planned = 0, done = 0 }) => {
7773
7773
  framesPlanned += planned;
7774
7774
  framesDone += done;
@@ -8823,6 +8823,8 @@ async function runCaptureStage(input) {
8823
8823
  pageErrorLines: workerPageErrors,
8824
8824
  openAttempt: input.openAttempt,
8825
8825
  verifyFirstSession: input.verifyFirstSession,
8826
+ prepareSession: input.prepareSession,
8827
+ onSessionUnprepared: input.onSessionUnprepared,
8826
8828
  onProgress: (progress) => {
8827
8829
  if (progress.latestWorkerPhase) {
8828
8830
  if (progress.capturedFrames === 0) reportWorkerStartup(job, progress, onProgress);
@@ -9736,7 +9738,11 @@ async function executeDiskCaptureWithAdaptiveRetry(options) {
9736
9738
  } : void 0,
9737
9739
  void 0,
9738
9740
  options.cfg,
9739
- { verifyFirstSession: options.verifyFirstSession }
9741
+ {
9742
+ verifyFirstSession: options.verifyFirstSession,
9743
+ prepareSession: options.prepareSession,
9744
+ onSessionUnprepared: options.onSessionUnprepared
9745
+ }
9740
9746
  );
9741
9747
  pushWorkerDedupPerfs(workerResults, options.dedupPerfs);
9742
9748
  if (options.pageErrorLines) pushWorkerPageErrors(workerResults, options.pageErrorLines);
@@ -12119,7 +12125,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
12119
12125
  const composition = compileResult.composition;
12120
12126
  const { deviceScaleFactor } = compileResult;
12121
12127
  let forceScreenshot = compileResult.forceScreenshot;
12122
- if (cfg.lowMemoryMode) forceScreenshot = true;
12128
+ if (cfg.lowMemoryMode || deviceScaleFactor !== 1) forceScreenshot = true;
12123
12129
  const { width, height } = composition;
12124
12130
  if (config.rejectOnSystemFonts !== false) {
12125
12131
  validateNoSystemFonts(compiled.html);
@@ -13801,6 +13807,8 @@ import {
13801
13807
  getEncoderPreset as getEncoderPreset6,
13802
13808
  initializeSession as initializeSession10,
13803
13809
  measureVideoShownBoxes,
13810
+ measureVideoShownBoxPart,
13811
+ mergeVideoShownBoxParts,
13804
13812
  probeBeginFrameLiveness as probeBeginFrameLiveness2,
13805
13813
  readWebGlVendorInfoFromCanvas,
13806
13814
  resolveConfig as resolveConfig5,
@@ -13920,6 +13928,35 @@ async function beginFrameSessionNeedsScreenshotFallback(session, probe = probeBe
13920
13928
  );
13921
13929
  return !await probe(session.page, timeoutMs, probeTick, session.beginFrameIntervalMs);
13922
13930
  }
13931
+ function createSharedBoxMeasure(onDone) {
13932
+ const started = Date.now();
13933
+ let done = false;
13934
+ let workerCount = 0;
13935
+ const shares = /* @__PURE__ */ new Map();
13936
+ return {
13937
+ settled: () => done,
13938
+ fullSize: () => {
13939
+ if (done) return;
13940
+ done = true;
13941
+ onDone(void 0);
13942
+ },
13943
+ add: (worker, part, cost) => {
13944
+ if (done) return;
13945
+ if (worker.workerCount !== workerCount) shares.clear();
13946
+ workerCount = worker.workerCount;
13947
+ shares.set(worker.workerId, { part, ...cost });
13948
+ if (shares.size < workerCount) return;
13949
+ done = true;
13950
+ const all = [...shares.values()];
13951
+ onDone(mergeVideoShownBoxParts(all.map((share) => share.part)), {
13952
+ workers: workerCount,
13953
+ frames: all.reduce((sum2, share) => sum2 + share.frames, 0),
13954
+ durationMs: Date.now() - started,
13955
+ slowestShareMs: Math.max(...all.map((share) => share.durationMs))
13956
+ });
13957
+ }
13958
+ };
13959
+ }
13923
13960
  function hashChunkOutput(outputPath, kind) {
13924
13961
  if (kind === "file") return sha256Hex(readFileSync12(outputPath));
13925
13962
  const entries = readdirSync9(outputPath).filter((name) => /\.(png|jpg|jpeg)$/i.test(name)).sort();
@@ -14125,14 +14162,26 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14125
14162
  });
14126
14163
  boxesReady.catch(() => {
14127
14164
  });
14165
+ const shownVideoIds = [...shownFrames.keys()];
14166
+ const chunkFrameTimes = chunkFrameNumbers.map(
14167
+ (frame) => frame * chunkFps.den / chunkFps.num
14168
+ );
14128
14169
  const measureBoxes = async (page) => {
14129
- shownBoxes = await measureVideoShownBoxes(
14130
- page,
14131
- [...shownFrames.keys()],
14132
- chunkFrameNumbers.map((frame) => frame * chunkFps.den / chunkFps.num)
14133
- );
14170
+ shownBoxes = await measureVideoShownBoxes(page, shownVideoIds, chunkFrameTimes);
14134
14171
  boxesMeasured();
14135
14172
  };
14173
+ const sharedBoxes = createSharedBoxMeasure((boxes2, pass) => {
14174
+ shownBoxes = boxes2;
14175
+ boxesMeasured();
14176
+ if (pass) log.info("[renderChunk] video boxes measured", { chunkIndex, ...pass });
14177
+ });
14178
+ const measureShare = async (session2, worker) => {
14179
+ if (sharedBoxes.settled()) return;
14180
+ const started = Date.now();
14181
+ const times = chunkFrameTimes.filter((_, i) => i % worker.workerCount === worker.workerId);
14182
+ const part = await measureVideoShownBoxPart(session2.page, shownVideoIds, times);
14183
+ sharedBoxes.add(worker, part, { frames: times.length, durationMs: Date.now() - started });
14184
+ };
14136
14185
  if (chunkWorkerCount === 1) {
14137
14186
  const bootStarted = Date.now();
14138
14187
  session = await createVerifiedDistributedCaptureSession(
@@ -14174,14 +14223,13 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14174
14223
  );
14175
14224
  sessionBootMs += Date.now() - screenshotBootStarted;
14176
14225
  }
14177
- } else if (!verifyInWorker) {
14178
- boxesMeasured();
14226
+ } else if (!verifyInWorker || shownVideoIds.length === 0) {
14227
+ sharedBoxes.fullSize();
14179
14228
  }
14180
14229
  let verification;
14181
14230
  const verifyFirstWorker = (first) => verification ??= (async () => {
14182
14231
  sessionBootMs = Date.now() - verifyStarted;
14183
14232
  try {
14184
- await measureBoxes(first.page);
14185
14233
  const selectedScreenshot = first.launchCaptureMode === "screenshot";
14186
14234
  if (selectedScreenshot || await beginFrameSessionNeedsScreenshotFallback(first)) {
14187
14235
  forceScreenshotForChunk = true;
@@ -14366,7 +14414,9 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14366
14414
  onFrameLanded: (frame) => overlap.current?.onFrameLanded(frame),
14367
14415
  interleaveFrames: interleavesCapture(overlap.current !== null, options),
14368
14416
  openAttempt,
14369
- verifyFirstSession: forceScreenshot || !verifyInWorker ? void 0 : verifyFirstWorker
14417
+ verifyFirstSession: forceScreenshot || !verifyInWorker ? void 0 : verifyFirstWorker,
14418
+ prepareSession: forceScreenshot || !verifyInWorker ? void 0 : measureShare,
14419
+ onSessionUnprepared: () => sharedBoxes.fullSize()
14370
14420
  }),
14371
14421
  { stall: frameStallRule(job, framesInChunk, void 0) }
14372
14422
  ).catch(async (captureError) => {
@@ -14378,7 +14428,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
14378
14428
  },
14379
14429
  resetForScreenshotRetry: () => {
14380
14430
  rmSync12(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
14381
- boxesMeasured();
14431
+ sharedBoxes.fullSize();
14382
14432
  mkdirSync15(framesDir, { recursive: true });
14383
14433
  capturePerfs.length = 0;
14384
14434
  captureAttempts.length = 0;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "380fcd392d15e1bfcdcc4d990cef42657bc58071aad326a92d379fe0af52a663",
4
+ "sha256": "82bb6f5b055041dbe4a42d8eae51c8d405236b4ae160e7c43bf13c2b6ea431af",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"