@hyperframes/producer 0.9.97 → 0.9.99

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
@@ -368,6 +368,7 @@ import { randomUUID as randomUUID3 } from "crypto";
368
368
  import { fileURLToPath as fileURLToPath5 } from "url";
369
369
 
370
370
  // src/services/fileServer.ts
371
+ import { referencedFontResponse } from "@hyperframes/share/referencedFont.mjs";
371
372
  import { Hono } from "hono";
372
373
  import { serve } from "@hono/node-server";
373
374
  import {
@@ -1202,6 +1203,8 @@ function createFileServer(options) {
1202
1203
  if (file) break;
1203
1204
  }
1204
1205
  if (!file) {
1206
+ const font = await referencedFontResponse(projectDir, new URL(c.req.url), c.req.raw.method);
1207
+ if (font) return font;
1205
1208
  if (!/favicon\.ico$/i.test(requestPath)) {
1206
1209
  console.warn(`[FileServer] 404 Not Found: ${terminalText2(boundedPageText(requestPath))}`);
1207
1210
  }
@@ -4685,6 +4688,15 @@ var OPENING_CAPTURE_SESSION = {
4685
4688
  captureMode: "screenshot",
4686
4689
  captureStep: "opening the capture session"
4687
4690
  };
4691
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
4692
+ try {
4693
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
4694
+ } catch (error) {
4695
+ void opening.then(closeCaptureSession).catch(() => {
4696
+ });
4697
+ throw error;
4698
+ }
4699
+ }
4688
4700
  var OPENING_RISK_SESSION = {
4689
4701
  captureMode: "screenshot",
4690
4702
  captureStep: "opening the screenshot session for effect frames"
@@ -4702,20 +4714,44 @@ var SequentialCaptureStallError = class extends Error {
4702
4714
  };
4703
4715
  function raceAgainstStall(promise, deadlineMs, input, signal) {
4704
4716
  return new Promise((resolve15, reject) => {
4705
- const clock = createStallClock();
4706
- const trip = () => reject(
4707
- signal?.aborted ? new Error(
4708
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4709
- ) : new SequentialCaptureStallError(
4710
- input.session,
4711
- input.stallTimeoutMs,
4712
- input.frameIndex,
4713
- input.totalFrames
4714
- )
4717
+ const abortError3 = () => new Error(
4718
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4715
4719
  );
4720
+ if (signal?.aborted) {
4721
+ promise.catch(() => {
4722
+ });
4723
+ reject(abortError3());
4724
+ return;
4725
+ }
4726
+ const clock = createStallClock();
4727
+ let settled = false;
4728
+ let timer;
4729
+ const cleanup = () => {
4730
+ clearTimeout(timer);
4731
+ signal?.removeEventListener("abort", onAbort);
4732
+ };
4733
+ const onAbort = () => {
4734
+ if (settled) return;
4735
+ settled = true;
4736
+ cleanup();
4737
+ reject(abortError3());
4738
+ };
4739
+ const trip = () => {
4740
+ if (settled) return;
4741
+ settled = true;
4742
+ cleanup();
4743
+ reject(
4744
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
4745
+ input.session,
4746
+ input.stallTimeoutMs,
4747
+ input.frameIndex,
4748
+ input.totalFrames
4749
+ )
4750
+ );
4751
+ };
4752
+ signal?.addEventListener("abort", onAbort, { once: true });
4716
4753
  const deadline = Math.max(0, deadlineMs);
4717
4754
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
4718
- let timer;
4719
4755
  const look = () => {
4720
4756
  const idle = clock.idle(wait);
4721
4757
  if (idle >= deadline) return trip();
@@ -4725,11 +4761,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
4725
4761
  timer = setTimeout(look, wait);
4726
4762
  promise.then(
4727
4763
  (value) => {
4728
- clearTimeout(timer);
4764
+ if (settled) return;
4765
+ settled = true;
4766
+ cleanup();
4729
4767
  resolve15(value);
4730
4768
  },
4731
4769
  (error) => {
4732
- clearTimeout(timer);
4770
+ if (settled) return;
4771
+ settled = true;
4772
+ cleanup();
4733
4773
  reject(error);
4734
4774
  }
4735
4775
  );
@@ -5228,20 +5268,14 @@ async function runCaptureStreamingStage(input) {
5228
5268
  abortSignal
5229
5269
  });
5230
5270
  const openSession = async () => {
5231
- const opening = createCaptureSession(
5232
- fileServer.url,
5233
- framesDir,
5234
- buildCaptureOptions(),
5235
- videoInjector,
5236
- captureCfg
5271
+ assertNotAborted();
5272
+ return openCaptureSessionWithinBudget(
5273
+ withinInitBudget,
5274
+ createCaptureSession(fileServer.url, framesDir, buildCaptureOptions(), videoInjector, {
5275
+ ...captureCfg,
5276
+ signal: abortSignal
5277
+ })
5237
5278
  );
5238
- try {
5239
- return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
5240
- } catch (error) {
5241
- void opening.then(closeCaptureSession, () => {
5242
- });
5243
- throw error;
5244
- }
5245
5279
  };
5246
5280
  const session = probeSession ?? await openSession();
5247
5281
  captureBeyondViewport = session.options.captureBeyondViewport;
@@ -5261,7 +5295,8 @@ async function runCaptureStreamingStage(input) {
5261
5295
  ...captureCfg,
5262
5296
  useDrawElement: false,
5263
5297
  staticFrameDedup: false,
5264
- enableBrowserPool: false
5298
+ enableBrowserPool: false,
5299
+ signal: abortSignal
5265
5300
  }
5266
5301
  );
5267
5302
  if (attemptClosed) {
@@ -5424,17 +5459,23 @@ async function captureSegmentFrames(ctx, segment, encoder) {
5424
5459
  for (let i = segment.startFrame; i < segment.endFrame; i++) {
5425
5460
  ctx.assertNotAborted();
5426
5461
  const time = i * ctx.job.config.fps.den / ctx.job.config.fps.num;
5427
- const { buffer } = await raceAgainstStall(
5428
- ctx.captureFrame(ctx.session, i, time),
5429
- ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5430
- {
5431
- session: ctx.session,
5432
- frameIndex: i,
5433
- totalFrames: ctx.totalFrames,
5434
- stallTimeoutMs: ctx.stallTimeoutMs
5435
- },
5436
- ctx.abortSignal
5437
- );
5462
+ let buffer;
5463
+ try {
5464
+ ({ buffer } = await raceAgainstStall(
5465
+ ctx.captureFrame(ctx.session, i, time),
5466
+ ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5467
+ {
5468
+ session: ctx.session,
5469
+ frameIndex: i,
5470
+ totalFrames: ctx.totalFrames,
5471
+ stallTimeoutMs: ctx.stallTimeoutMs
5472
+ },
5473
+ ctx.abortSignal
5474
+ ));
5475
+ } catch (error) {
5476
+ if (ctx.abortSignal?.aborted) ctx.assertNotAborted();
5477
+ throw error;
5478
+ }
5438
5479
  await verifyDrawElementSample(ctx.session, i, buffer, {
5439
5480
  log: ctx.log,
5440
5481
  verifyMinDb: ctx.verifyMinDb
@@ -6468,7 +6509,7 @@ function segmentFramesDir(rootDir, index) {
6468
6509
  }
6469
6510
  function createSegmentVideoFrames(input) {
6470
6511
  const extractFrames = input.extractFrames ?? extractDeferredFrames;
6471
- const sourceOf = input.sourceOf ?? ((video) => video.srcPath);
6512
+ const sourceOf2 = input.sourceOf ?? ((video) => video.srcPath);
6472
6513
  const fullyExtracted = input.extracted.filter((video) => !video.deferredRange);
6473
6514
  const tableFor = async (frames, dir) => {
6474
6515
  const sliced = await extractFrames({
@@ -6479,7 +6520,7 @@ function createSegmentVideoFrames(input) {
6479
6520
  outputRoot: dir,
6480
6521
  cfg: input.cfg,
6481
6522
  signal: input.abortSignal,
6482
- sourceOf,
6523
+ sourceOf: sourceOf2,
6483
6524
  shownBoxes: input.shownBoxes,
6484
6525
  onMissingFrame: (video, index) => new Error(
6485
6526
  `[Render] video ${JSON.stringify(video.videoId)} has no frame ${index}; it was expected to have ${video.totalFrames} frames.`
@@ -7148,6 +7189,15 @@ import {
7148
7189
  } from "@hyperframes/engine";
7149
7190
  var SHORT_CLIP_ONE_FRAME_TOLERANCE_MIN_EXPECTED_FRAMES = 14;
7150
7191
  var SHORT_CLIP_ONE_FRAME_TOLERANCE_MAX_EXPECTED_FRAMES = 20;
7192
+ var s3 = (seconds) => seconds.toFixed(3);
7193
+ function sourceWords(report) {
7194
+ const s = report.source;
7195
+ if (!s) return "";
7196
+ const vfr = s.isVFR ? ", variable frame rate" : "";
7197
+ const lead = s.leadSeconds > 0 ? `, video from ${s3(s.leadSeconds)} s` : "";
7198
+ const speed = s.rate === "ramp" ? "on a speed ramp" : `at ${s.rate}x`;
7199
+ return `; source ${s.codec}, ${s.fps} fps${vfr}, plays to ${s3(s.playsTo)} s${lead}; clip ${s3(report.clipStart)}-${s3(report.clipEnd)} s reads source ${s3(s.readsFrom)}-${s3(s.readsTo)} s ${speed}`;
7200
+ }
7151
7201
  var VideoFrameCoverageError = class extends Error {
7152
7202
  // Read structurally by isVideoFrameCoverageError and cross-module callers.
7153
7203
  hyperframesVideoFrameCoverageError = true;
@@ -7194,6 +7244,19 @@ function expectedFramesForVideo(video, entry, fps) {
7194
7244
  const sourceFrames = expectedFramesForClip(0, sourceDuration, fps, rounding);
7195
7245
  return Math.min(slotFrames, sourceFrames);
7196
7246
  }
7247
+ function sourceOf(video, entry) {
7248
+ const rate = normalizeRateSpec(video.playbackRate);
7249
+ return {
7250
+ codec: entry.metadata.videoCodec,
7251
+ fps: entry.metadata.fps,
7252
+ isVFR: entry.metadata.isVFR,
7253
+ playsTo: resolvePlayableVideoDuration(entry.metadata),
7254
+ leadSeconds: entry.metadata.videoStreamLeadSeconds ?? 0,
7255
+ readsFrom: video.mediaStart,
7256
+ readsTo: video.mediaStart + sourceTimeAt(rate, Math.max(0, video.end - video.start)),
7257
+ rate: typeof rate === "number" ? rate : "ramp"
7258
+ };
7259
+ }
7197
7260
  function computeVideoFrameCoverage(videos, extracted, fps) {
7198
7261
  const byId = /* @__PURE__ */ new Map();
7199
7262
  for (const entry of extracted) byId.set(entry.videoId, entry);
@@ -7209,7 +7272,8 @@ function computeVideoFrameCoverage(videos, extracted, fps) {
7209
7272
  clipEnd: video.end,
7210
7273
  expectedFrames,
7211
7274
  capturedFrames,
7212
- ratio
7275
+ ratio,
7276
+ ...entry && { source: sourceOf(video, entry) }
7213
7277
  });
7214
7278
  }
7215
7279
  return reports;
@@ -7226,7 +7290,7 @@ function assertVideoFrameCoverage(reports, threshold) {
7226
7290
  const thresholdPct = (threshold * 100).toFixed(1);
7227
7291
  const suffix = sorted.length > 1 ? ` (+${sorted.length - 1} more clip(s) below threshold)` : "";
7228
7292
  throw new VideoFrameCoverageError(
7229
- `Video "${worst.videoId}" captured ${worst.capturedFrames} of expected ${worst.expectedFrames} frames (coverage ${pct}%, threshold ${thresholdPct}%). check/snapshot may pass while the encoded MP4 renders this clip blank, so the render is aborted to prevent shipping a wrong MP4.${suffix} Set HF_VIDEO_COVERAGE_THRESHOLD=0 to disable this gate.`,
7293
+ `Video "${worst.videoId}" captured ${worst.capturedFrames} of expected ${worst.expectedFrames} frames (coverage ${pct}%, threshold ${thresholdPct}%${sourceWords(worst)}). check/snapshot may pass while the encoded MP4 renders this clip blank, so the render is aborted to prevent shipping a wrong MP4.${suffix} Set HF_VIDEO_COVERAGE_THRESHOLD=0 to disable this gate.`,
7230
7294
  { threshold, worst, failedReports: sorted }
7231
7295
  );
7232
7296
  }
@@ -13523,25 +13587,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
13523
13587
  assertNotAborted();
13524
13588
  attempt?.throwIfAborted();
13525
13589
  };
13590
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
13591
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
13526
13592
  const videoInjector = createRenderVideoFrameInjector();
13527
- const session = probeSession ?? await createCaptureSession5(
13528
- fileServer.url,
13593
+ const session = probeSession ?? await openSequentialDiskSession({
13594
+ assertAttemptActive,
13595
+ initBudget,
13596
+ fileServerUrl: fileServer.url,
13529
13597
  framesDir,
13530
13598
  captureOptions,
13531
13599
  videoInjector,
13532
- captureCfg
13533
- );
13600
+ captureCfg,
13601
+ attemptSignal
13602
+ });
13534
13603
  captureBeyondViewport = session.options.captureBeyondViewport;
13535
13604
  try {
13536
13605
  if (probeSession) {
13537
13606
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
13538
13607
  probeSession = null;
13539
13608
  }
13540
- await ensureSessionReady(session, {
13541
- frameIndex: resumeFrom,
13542
- totalFrames,
13543
- abortSignal: input.abortSignal
13544
- });
13609
+ await ensureSessionReady(session, initBudget);
13545
13610
  assertAttemptActive();
13546
13611
  lastBrowserConsole = session.browserConsoleBuffer;
13547
13612
  await captureSessionFrames(session, {
@@ -13593,9 +13658,26 @@ function planTransientResume(error, ctx) {
13593
13658
  if (!firstMissing) return null;
13594
13659
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
13595
13660
  }
13661
+ function combineAbortSignals(first, second) {
13662
+ if (first && second) return AbortSignal.any([first, second]);
13663
+ return second ?? first;
13664
+ }
13665
+ async function openSequentialDiskSession(args) {
13666
+ args.assertAttemptActive();
13667
+ return openCaptureSessionWithinBudget(
13668
+ createSessionInitBudget(args.initBudget),
13669
+ createCaptureSession5(
13670
+ args.fileServerUrl,
13671
+ args.framesDir,
13672
+ args.captureOptions,
13673
+ args.videoInjector,
13674
+ { ...args.captureCfg, signal: args.attemptSignal }
13675
+ )
13676
+ );
13677
+ }
13596
13678
  async function ensureSessionReady(session, budget) {
13597
13679
  if (!session.isInitialized) {
13598
- await initializeSession5(session);
13680
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
13599
13681
  return;
13600
13682
  }
13601
13683
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
@@ -14397,12 +14479,17 @@ async function runCaptureHdrStage(input) {
14397
14479
  projectDir,
14398
14480
  compiledDir
14399
14481
  });
14400
- const domSession = await createCaptureSession7(
14401
- fileServer.url,
14402
- framesDir,
14403
- buildCaptureOptions(),
14404
- createRenderVideoFrameInjector(),
14405
- hdrCfg
14482
+ assertNotAborted();
14483
+ const withinInitBudget = createSessionInitBudget({ frameIndex: 0, totalFrames, abortSignal });
14484
+ const domSession = await openCaptureSessionWithinBudget(
14485
+ withinInitBudget,
14486
+ createCaptureSession7(
14487
+ fileServer.url,
14488
+ framesDir,
14489
+ buildCaptureOptions(),
14490
+ createRenderVideoFrameInjector(),
14491
+ { ...hdrCfg, signal: abortSignal }
14492
+ )
14406
14493
  );
14407
14494
  let hdrEncoder = null;
14408
14495
  let hdrEncoderClosed = false;
@@ -14411,7 +14498,7 @@ async function runCaptureHdrStage(input) {
14411
14498
  let releaseHdrImageReservation = null;
14412
14499
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
14413
14500
  try {
14414
- await initializeSession7(domSession);
14501
+ await withinInitBudget(initializeSession7(domSession), domSession);
14415
14502
  assertNotAborted();
14416
14503
  lastBrowserConsole = domSession.browserConsoleBuffer;
14417
14504
  await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
@@ -16367,6 +16454,9 @@ async function executeRenderPipeline(input) {
16367
16454
  memSampler = createMemorySampler();
16368
16455
  const assertNotAborted = () => {
16369
16456
  execution.assertActive(() => new RenderCancelledError("render_cancelled"));
16457
+ if (executionSignal.aborted) {
16458
+ throw tooSlowError ?? audioFailure ?? new RenderCancelledError("render_cancelled");
16459
+ }
16370
16460
  };
16371
16461
  job.startedAt = /* @__PURE__ */ new Date();
16372
16462
  assertNotAborted();