@hyperframes/producer 0.9.39 → 0.9.40

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -31,7 +31,7 @@ import {
31
31
  import { HF_AUDIO_GROUP_TAG } from "@hyperframes/core/audio-groups";
32
32
  import { HTML_BODY_CSS_HEIGHT_FIRST_RE, HTML_BODY_CSS_WIDTH_FIRST_RE } from "@hyperframes/parsers";
33
33
  import {
34
- extractMediaMetadata as extractMediaMetadata4,
34
+ extractMediaMetadata as extractMediaMetadata5,
35
35
  resolveConfig as resolveConfig2,
36
36
  closeCaptureSession as closeCaptureSession8,
37
37
  createCaptureSession as createCaptureSession8,
@@ -2145,8 +2145,9 @@ import {
2145
2145
  import { CaptureFailure, classifyCaptureFailure } from "@hyperframes/engine";
2146
2146
 
2147
2147
  // src/services/render/perfSummary.ts
2148
- import { arch, cpus, platform, totalmem } from "node:os";
2148
+ import { arch, platform, totalmem } from "node:os";
2149
2149
  import { fpsToNumber as fpsToNumber2 } from "@hyperframes/core";
2150
+ import { hostCpuCount } from "@hyperframes/engine";
2150
2151
 
2151
2152
  // src/services/render/hdrPerf.ts
2152
2153
  function createHdrPerfCollector() {
@@ -2493,7 +2494,7 @@ function buildRenderPerfSummary(input) {
2493
2494
  host: {
2494
2495
  platform: platform(),
2495
2496
  arch: arch(),
2496
- cpuCount: cpus().length,
2497
+ cpuCount: hostCpuCount(),
2497
2498
  totalMemMb: Math.round(totalmem() / (1024 * 1024)),
2498
2499
  nodeVersion: process.version,
2499
2500
  gpuDisabled: input.gpuDisabled
@@ -5558,7 +5559,12 @@ async function extractAllDeferredFrames(extracted, input) {
5558
5559
  video.videoId,
5559
5560
  range.startTime,
5560
5561
  range.durationSeconds,
5561
- { fps: input.fps, outputDir: dirname5(video.outputDir), format: range.format },
5562
+ {
5563
+ fps: input.fps,
5564
+ outputDir: dirname5(video.outputDir),
5565
+ format: range.format,
5566
+ shownBox: input.shownBoxes?.get(video.videoId)
5567
+ },
5562
5568
  input.signal,
5563
5569
  input.cfg
5564
5570
  ),
@@ -5583,6 +5589,74 @@ async function extractAllDeferredFrames(extracted, input) {
5583
5589
  }
5584
5590
  }
5585
5591
 
5592
+ // src/services/render/videoShownBoxes.ts
5593
+ import {
5594
+ extractMediaMetadata as extractMediaMetadata3,
5595
+ measureVideoShownBoxRanges,
5596
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc2
5597
+ } from "@hyperframes/engine";
5598
+ var SHOWN_BOX_STRIDE_S = 0.25;
5599
+ var MOVING_BOX_HEADROOM = 1.1;
5600
+ async function oversizedVideos(videos, projectDir, compiledDir, canvas) {
5601
+ const sized = await Promise.all(
5602
+ videos.map(async (video) => {
5603
+ if (/^https?:\/\//i.test(video.src)) return false;
5604
+ try {
5605
+ const path = resolveProjectRelativeSrc2(video.src, projectDir, compiledDir);
5606
+ const { width, height } = await extractMediaMetadata3(path);
5607
+ return width > canvas.width || height > canvas.height;
5608
+ } catch {
5609
+ return false;
5610
+ }
5611
+ })
5612
+ );
5613
+ return videos.filter((_, index) => sized[index]);
5614
+ }
5615
+ function shownBoxTimes(videos, fps) {
5616
+ const frame = fps.den / fps.num;
5617
+ const times = /* @__PURE__ */ new Set();
5618
+ for (const { start, end } of videos) {
5619
+ const last = Math.max(start, end - frame);
5620
+ for (let t = start; t < last; t += SHOWN_BOX_STRIDE_S) times.add(t);
5621
+ times.add(last);
5622
+ }
5623
+ return [...times].sort((a, b) => a - b);
5624
+ }
5625
+ async function measureLocalShownBoxes(page, videos, fps, log) {
5626
+ const times = shownBoxTimes(videos, fps);
5627
+ const startedAt = Date.now();
5628
+ try {
5629
+ const ranges = await measureVideoShownBoxRanges(
5630
+ page,
5631
+ videos.map((video) => video.id),
5632
+ times
5633
+ );
5634
+ await page.evaluate(
5635
+ () => window.__hf?.seek?.(0)
5636
+ );
5637
+ const boxes2 = /* @__PURE__ */ new Map();
5638
+ for (const [id, { largest, smallest }] of ranges) {
5639
+ const moves = largest.width !== smallest.width || largest.height !== smallest.height;
5640
+ const grow = moves ? MOVING_BOX_HEADROOM : 1;
5641
+ boxes2.set(id, { width: largest.width * grow, height: largest.height * grow });
5642
+ }
5643
+ log.info("[Render] Measured the boxes videos are shown at", {
5644
+ videos: videos.length,
5645
+ boxed: boxes2.size,
5646
+ seeks: times.length,
5647
+ elapsedMs: Date.now() - startedAt
5648
+ });
5649
+ return boxes2;
5650
+ } catch (error) {
5651
+ log.warn("[Render] Could not measure the boxes videos are shown at; extracting at full size", {
5652
+ error: error instanceof Error ? error.message : String(error),
5653
+ seeks: times.length,
5654
+ elapsedMs: Date.now() - startedAt
5655
+ });
5656
+ return void 0;
5657
+ }
5658
+ }
5659
+
5586
5660
  // src/services/render/segmentVideoFrames.ts
5587
5661
  import { mkdirSync as mkdirSync5, rmSync as rmSync8 } from "node:fs";
5588
5662
  import { join as join12 } from "node:path";
@@ -5607,6 +5681,7 @@ function createSegmentVideoFrames(input) {
5607
5681
  cfg: input.cfg,
5608
5682
  signal: input.abortSignal,
5609
5683
  sourceOf,
5684
+ shownBoxes: input.shownBoxes,
5610
5685
  onMissingFrame: (video, index) => new Error(
5611
5686
  `[Render] video ${JSON.stringify(video.videoId)} has no frame ${index}; it was expected to have ${video.totalFrames} frames.`
5612
5687
  )
@@ -7320,7 +7395,7 @@ import {
7320
7395
  isNotMediaPayload,
7321
7396
  NotMediaPayloadError,
7322
7397
  probeMediaProfile,
7323
- resolveProjectRelativeSrc as resolveProjectRelativeSrc2
7398
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc3
7324
7399
  } from "@hyperframes/engine";
7325
7400
  var ASSET_MEDIA_TYPE_MISMATCH = "ASSET_MEDIA_TYPE_MISMATCH";
7326
7401
  var AssetMediaTypeMismatchError = class extends Error {
@@ -7367,7 +7442,7 @@ function dropMediaOutsideProject(input) {
7367
7442
  const roots = [projectDir, compiledDir, join18(workDir, "downloads")];
7368
7443
  const staysInside = ({ id, src }) => {
7369
7444
  if (!src || isRemoteOrInlineSource(src)) return true;
7370
- const path = resolveProjectRelativeSrc2(src, projectDir, compiledDir);
7445
+ const path = resolveProjectRelativeSrc3(src, projectDir, compiledDir);
7371
7446
  if (roots.some((root) => !escapesAssetRoot(path, root))) return true;
7372
7447
  log.warn(`[Render] Media "${id}" source is missing: it is outside the project folder`, { src });
7373
7448
  return false;
@@ -7397,7 +7472,7 @@ async function preflightCompositionAssetMediaTypes(input) {
7397
7472
  const byPath = /* @__PURE__ */ new Map();
7398
7473
  for (const reference of references) {
7399
7474
  if (!reference.src || isRemoteOrInlineSource(reference.src)) continue;
7400
- const resolvedPath = resolveProjectRelativeSrc2(
7475
+ const resolvedPath = resolveProjectRelativeSrc3(
7401
7476
  reference.src,
7402
7477
  input.projectDir,
7403
7478
  input.compiledDir
@@ -9605,7 +9680,7 @@ async function runProbeStage(input) {
9605
9680
  );
9606
9681
  const hasVariableMedia = hasVariableBoundMedia(compiled.html, job.config.variables);
9607
9682
  const hasInsertedMedia = hasRuntimeMediaChanges(compiled.html);
9608
- const needsBrowser = cfg.videoLayerPassthrough || probeRequiresBrowser({
9683
+ const needsBrowser = cfg.videoLayerPassthrough || input.measuresShownBoxes === true || probeRequiresBrowser({
9609
9684
  durationSeconds: composition.duration,
9610
9685
  unresolvedCompositionCount: compiled.unresolvedCompositions.length,
9611
9686
  hasAutoStart,
@@ -9624,6 +9699,7 @@ async function runProbeStage(input) {
9624
9699
  if (hasScriptedAudio) reasons.push("scripted audio volume");
9625
9700
  if (hasInsertedMedia) reasons.push("runtime-created or source-mutated media");
9626
9701
  if (hasVariableMedia) reasons.push("variable-bound media source(s)");
9702
+ if (input.measuresShownBoxes) reasons.push("video(s) larger than the canvas");
9627
9703
  log.info("Launching browser for composition probe...", {
9628
9704
  reasons
9629
9705
  });
@@ -10157,7 +10233,7 @@ import {
10157
10233
  createFrameLookupTable as createFrameLookupTable3,
10158
10234
  detectTransfer,
10159
10235
  extractAllVideoFrames,
10160
- extractMediaMetadata as extractMediaMetadata3,
10236
+ extractMediaMetadata as extractMediaMetadata4,
10161
10237
  gradingKeepsSdr as gradingKeepsSdr2,
10162
10238
  isVideoPastTimelineEnd,
10163
10239
  isHdrColorSpace as isHdrColorSpace2,
@@ -10165,7 +10241,7 @@ import {
10165
10241
  resolveFinalFrameExtractionWindow as resolveFinalFrameExtractionWindow2,
10166
10242
  resolveVideoExtractionWindow as resolveVideoExtractionWindow2,
10167
10243
  isHttpUrl as isHttpUrl2,
10168
- resolveProjectRelativeSrc as resolveProjectRelativeSrc3,
10244
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc4,
10169
10245
  runVideoExtractionWithRetry as runVideoExtractionWithRetry2,
10170
10246
  safeVideoExtractionSourceIdentity,
10171
10247
  videoAudioId as videoAudioId2
@@ -10381,7 +10457,7 @@ function applyVideoExtractionFailurePolicy(result, policy, log) {
10381
10457
  }
10382
10458
  async function probeColorSpaceSafely(path, log) {
10383
10459
  try {
10384
- const meta = await extractMediaMetadata3(path);
10460
+ const meta = await extractMediaMetadata4(path);
10385
10461
  return meta.colorSpace;
10386
10462
  } catch (error) {
10387
10463
  log?.warn("HDR color-space probe failed; treating source as SDR", {
@@ -10403,6 +10479,7 @@ async function runExtractVideosStage(input) {
10403
10479
  assertNotAborted,
10404
10480
  materializeSymlinks,
10405
10481
  deferRangeExtraction,
10482
+ shownBoxes,
10406
10483
  urlByAbsentLocalPath,
10407
10484
  skipFrameExtractionIds = []
10408
10485
  } = input;
@@ -10424,10 +10501,10 @@ async function runExtractVideosStage(input) {
10424
10501
  log?.info("Probing video color spaces...", { videoCount: composition.videos.length });
10425
10502
  const probeFailures = await Promise.all(
10426
10503
  composition.videos.map(async (v) => {
10427
- const videoPath = resolveProjectRelativeSrc3(v.src, projectDir, compiledDir);
10504
+ const videoPath = resolveProjectRelativeSrc4(v.src, projectDir, compiledDir);
10428
10505
  if (!existsSync13(videoPath)) return null;
10429
10506
  try {
10430
- const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata3(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata3(videoPath), {
10507
+ const attempted = extractionPolicy.maxTransientRetries === 0 ? { result: await extractMediaMetadata4(videoPath), retries: 0 } : await runVideoExtractionWithRetry2(() => extractMediaMetadata4(videoPath), {
10431
10508
  signal: abortSignal,
10432
10509
  maxTransientRetries: extractionPolicy.maxTransientRetries,
10433
10510
  onRetry: () => {
@@ -10462,7 +10539,7 @@ async function runExtractVideosStage(input) {
10462
10539
  if (probesHdr && composition.images.length > 0) {
10463
10540
  const probed = await Promise.all(
10464
10541
  composition.images.map(async (img) => {
10465
- const imgPath = resolveProjectRelativeSrc3(img.src, projectDir, compiledDir);
10542
+ const imgPath = resolveProjectRelativeSrc4(img.src, projectDir, compiledDir);
10466
10543
  if (!existsSync13(imgPath)) return null;
10467
10544
  const colorSpace = await probeColorSpaceSafely(imgPath, log);
10468
10545
  if (isHdrColorSpace2(colorSpace)) {
@@ -10504,6 +10581,7 @@ async function runExtractVideosStage(input) {
10504
10581
  maxTransientRetries: extractionPolicy.maxTransientRetries,
10505
10582
  collectProbeFailures: extractionPolicy.failureMode === "enforce",
10506
10583
  deferRangeExtraction,
10584
+ shownBoxes,
10507
10585
  contentKeyedDirs: [join22(compiledDir, REMOTE_MEDIA_SUBDIR)],
10508
10586
  urlByAbsentLocalPath,
10509
10587
  onProgress: ({ planned = 0, done = 0 }) => {
@@ -10581,10 +10659,10 @@ async function appendVideoAudioFromProbe(input) {
10581
10659
  );
10582
10660
  const probed = await Promise.all(
10583
10661
  videos.map(async (video) => {
10584
- const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc3(video.src, projectDir, compiledDir);
10662
+ const path = isHttpUrl2(video.src) ? video.src : resolveProjectRelativeSrc4(video.src, projectDir, compiledDir);
10585
10663
  const readFrom = urlByAbsentLocalPath?.get(path) ?? path;
10586
10664
  if (!isHttpUrl2(readFrom) && !existsSync13(readFrom)) return null;
10587
- const metadata = await extractMediaMetadata3(readFrom);
10665
+ const metadata = await extractMediaMetadata4(readFrom);
10588
10666
  const window2 = await resolveFinalFrameExtractionWindow2(
10589
10667
  readFrom,
10590
10668
  video,
@@ -10608,7 +10686,7 @@ import {
10608
10686
  buildVideoLayerInput,
10609
10687
  isHttpUrl as isHttpUrl3,
10610
10688
  qualifyVideoLayer,
10611
- resolveProjectRelativeSrc as resolveProjectRelativeSrc4
10689
+ resolveProjectRelativeSrc as resolveProjectRelativeSrc5
10612
10690
  } from "@hyperframes/engine";
10613
10691
  var SAMPLES = 9;
10614
10692
  function inspectVideoLayout(id, w, h, time) {
@@ -10670,7 +10748,7 @@ async function planVideoLayerPassthrough(input) {
10670
10748
  if (!q.qualifies) return { reason: q.reason };
10671
10749
  const { video } = q;
10672
10750
  if (isHttpUrl3(video.src)) return { reason: "remote_source" };
10673
- const path = resolveProjectRelativeSrc4(video.src, input.projectDir, input.compiledDir);
10751
+ const path = resolveProjectRelativeSrc5(video.src, input.projectDir, input.compiledDir);
10674
10752
  if (!existsSync14(path)) return { reason: "source_missing" };
10675
10753
  const layout = await probeVideoLayout(input.page, video.id, input.canvas, input.duration);
10676
10754
  if ("reason" in layout) return layout;
@@ -12053,8 +12131,8 @@ import { Worker } from "node:worker_threads";
12053
12131
  import { fileURLToPath as fileURLToPath3, pathToFileURL } from "node:url";
12054
12132
  import { dirname as dirname11, join as join28 } from "node:path";
12055
12133
  import { createRequire } from "node:module";
12134
+ import { usableCpuCount } from "@hyperframes/engine";
12056
12135
  import { existsSync as existsSync18 } from "node:fs";
12057
- import { cpus as cpus2 } from "node:os";
12058
12136
  function resolveWorkerEntry(explicit) {
12059
12137
  if (explicit && explicit.length > 0) {
12060
12138
  return { path: explicit, isTs: explicit.endsWith(".ts") };
@@ -12086,7 +12164,7 @@ function buildExecArgv(entryIsTs) {
12086
12164
  return inherited;
12087
12165
  }
12088
12166
  async function createShaderTransitionWorkerPool(opts) {
12089
- const cpuCount = Math.max(1, cpus2().length);
12167
+ const cpuCount = Math.max(1, usableCpuCount());
12090
12168
  const size = Math.max(1, Math.min(opts.size, cpuCount));
12091
12169
  const log = opts.log ?? {};
12092
12170
  const { path: entry, isTs: entryIsTs } = resolveWorkerEntry(opts.workerEntryPath);
@@ -14543,6 +14621,12 @@ async function executeRenderPipeline(input) {
14543
14621
  );
14544
14622
  const subTimelineWaitMemo = {};
14545
14623
  const staticDedupMemo = {};
14624
+ const largerThanCanvas = await oversizedVideos(
14625
+ composition.videos,
14626
+ projectDir,
14627
+ join32(workDir, "compiled"),
14628
+ { width: outputWidth, height: outputHeight }
14629
+ );
14546
14630
  const probeResult = await observeRenderStage(
14547
14631
  observability,
14548
14632
  "browser_probe",
@@ -14550,6 +14634,7 @@ async function executeRenderPipeline(input) {
14550
14634
  () => runProbeStage({
14551
14635
  projectDir,
14552
14636
  workDir,
14637
+ measuresShownBoxes: largerThanCanvas.length > 0,
14553
14638
  job,
14554
14639
  cfg,
14555
14640
  forceScreenshot: captureForceScreenshot,
@@ -14575,6 +14660,7 @@ async function executeRenderPipeline(input) {
14575
14660
  compositionHash = computeCompositionObservabilityHash(compiled.html);
14576
14661
  fileServer = probeResult.fileServer;
14577
14662
  probeSession = probeResult.probeSession;
14663
+ const shownBoxes = largerThanCanvas.length > 0 && probeSession?.isInitialized ? await measureLocalShownBoxes(probeSession.page, largerThanCanvas, job.config.fps, log) : void 0;
14578
14664
  job.strictVariablesChecked = probeResult.strictVariablesChecked;
14579
14665
  lastBrowserConsole = probeResult.lastBrowserConsole;
14580
14666
  let resolvedCaptureBeyondViewport = probeSession?.options.captureBeyondViewport;
@@ -14680,6 +14766,7 @@ async function executeRenderPipeline(input) {
14680
14766
  // Local staging can use links; distributed plan() alone requires real copies.
14681
14767
  materializeSymlinks: false,
14682
14768
  deferRangeExtraction: windowVideoFrames ? true : void 0,
14769
+ shownBoxes,
14683
14770
  onProgress
14684
14771
  })
14685
14772
  );
@@ -14909,7 +14996,8 @@ async function executeRenderPipeline(input) {
14909
14996
  rootDir: workDir,
14910
14997
  cfg,
14911
14998
  injectorOptions: frameCacheOptions(cfg, workerCount),
14912
- abortSignal: executionSignal
14999
+ abortSignal: executionSignal,
15000
+ shownBoxes
14913
15001
  }),
14914
15002
  workDir,
14915
15003
  (bytes) => updateCaptureObservability({ videoFrameWindowPeakBytes: bytes })
@@ -14931,6 +15019,7 @@ async function executeRenderPipeline(input) {
14931
15019
  () => extractAllDeferredFrames(extracted, {
14932
15020
  fps: job.config.fps,
14933
15021
  cfg,
15022
+ shownBoxes,
14934
15023
  signal: executionSignal,
14935
15024
  maxTransientRetries: resolveVideoExtractionPolicy().maxTransientRetries,
14936
15025
  onProgress: (done, total) => reportExtractProgress(job, done, total, onProgress)
@@ -15673,7 +15762,7 @@ async function executeRenderPipeline(input) {
15673
15762
  completedSegments = await validateCompletedSegments(
15674
15763
  existing,
15675
15764
  segmentPlanHash,
15676
- (path) => probeSegmentFrameCount(path, extractMediaMetadata4)
15765
+ (path) => probeSegmentFrameCount(path, extractMediaMetadata5)
15677
15766
  );
15678
15767
  log.info(`[Render] resuming: ${completedSegments.size} segments complete`, {
15679
15768
  segmentDir
@@ -19073,7 +19162,6 @@ async function plan(projectDir, config, planDir, options = {}) {
19073
19162
  // src/services/distributed/renderChunk.ts
19074
19163
  import { randomBytes } from "node:crypto";
19075
19164
  import { existsSync as existsSync29, mkdirSync as mkdirSync19, readFileSync as readFileSync14, readdirSync as readdirSync11, rmSync as rmSync17, writeFileSync as writeFileSync13 } from "node:fs";
19076
- import { cpus as cpus3 } from "node:os";
19077
19165
  import { join as join45 } from "node:path";
19078
19166
  import {
19079
19167
  assertSwiftShader,
@@ -19089,7 +19177,8 @@ import {
19089
19177
  measureVideoShownBoxes,
19090
19178
  probeBeginFrameLiveness as probeBeginFrameLiveness2,
19091
19179
  readWebGlVendorInfoFromCanvas,
19092
- resolveConfig as resolveConfig4
19180
+ resolveConfig as resolveConfig4,
19181
+ usableCpuCount as usableCpuCount2
19093
19182
  } from "@hyperframes/engine";
19094
19183
 
19095
19184
  // src/services/distributed/planV2.ts
@@ -20515,7 +20604,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
20515
20604
  const captureSession = session;
20516
20605
  session = null;
20517
20606
  verifyStarted = Date.now();
20518
- overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, cpus3().length) ? encodeWhileCapturing(encodeInput, framesInChunk) : null;
20607
+ overlap.current = canEncodeWhileCapturing(encodeInput, chunkWorkerCount, usableCpuCount2()) ? encodeWhileCapturing(encodeInput, framesInChunk) : null;
20519
20608
  await observeRenderStage(
20520
20609
  new RenderObservabilityRecorder({ pipelineStartMs: start, log }),
20521
20610
  "capture_chunk",