@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.
@@ -410,6 +410,7 @@ import { randomUUID as randomUUID3 } from "crypto";
410
410
  import { fileURLToPath as fileURLToPath5 } from "url";
411
411
 
412
412
  // src/services/fileServer.ts
413
+ import { referencedFontResponse } from "@hyperframes/share/referencedFont.mjs";
413
414
  import { Hono } from "hono";
414
415
  import { serve } from "@hono/node-server";
415
416
  import {
@@ -1244,6 +1245,8 @@ function createFileServer(options) {
1244
1245
  if (file) break;
1245
1246
  }
1246
1247
  if (!file) {
1248
+ const font = await referencedFontResponse(projectDir, new URL(c.req.url), c.req.raw.method);
1249
+ if (font) return font;
1247
1250
  if (!/favicon\.ico$/i.test(requestPath)) {
1248
1251
  console.warn(`[FileServer] 404 Not Found: ${terminalText2(boundedPageText(requestPath))}`);
1249
1252
  }
@@ -4723,6 +4726,15 @@ var OPENING_CAPTURE_SESSION = {
4723
4726
  captureMode: "screenshot",
4724
4727
  captureStep: "opening the capture session"
4725
4728
  };
4729
+ async function openCaptureSessionWithinBudget(withinInitBudget, opening) {
4730
+ try {
4731
+ return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
4732
+ } catch (error) {
4733
+ void opening.then(closeCaptureSession).catch(() => {
4734
+ });
4735
+ throw error;
4736
+ }
4737
+ }
4726
4738
  var OPENING_RISK_SESSION = {
4727
4739
  captureMode: "screenshot",
4728
4740
  captureStep: "opening the screenshot session for effect frames"
@@ -4740,20 +4752,44 @@ var SequentialCaptureStallError = class extends Error {
4740
4752
  };
4741
4753
  function raceAgainstStall(promise, deadlineMs, input, signal) {
4742
4754
  return new Promise((resolve13, reject) => {
4743
- const clock = createStallClock();
4744
- const trip = () => reject(
4745
- signal?.aborted ? new Error(
4746
- `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4747
- ) : new SequentialCaptureStallError(
4748
- input.session,
4749
- input.stallTimeoutMs,
4750
- input.frameIndex,
4751
- input.totalFrames
4752
- )
4755
+ const abortError3 = () => new Error(
4756
+ `[Render] Sequential ${captureModeLabel(input.session.captureMode)} capture aborted while a capture call was in flight (frame ${input.frameIndex}/${input.totalFrames}).`
4753
4757
  );
4758
+ if (signal?.aborted) {
4759
+ promise.catch(() => {
4760
+ });
4761
+ reject(abortError3());
4762
+ return;
4763
+ }
4764
+ const clock = createStallClock();
4765
+ let settled = false;
4766
+ let timer;
4767
+ const cleanup = () => {
4768
+ clearTimeout(timer);
4769
+ signal?.removeEventListener("abort", onAbort);
4770
+ };
4771
+ const onAbort = () => {
4772
+ if (settled) return;
4773
+ settled = true;
4774
+ cleanup();
4775
+ reject(abortError3());
4776
+ };
4777
+ const trip = () => {
4778
+ if (settled) return;
4779
+ settled = true;
4780
+ cleanup();
4781
+ reject(
4782
+ signal?.aborted ? abortError3() : new SequentialCaptureStallError(
4783
+ input.session,
4784
+ input.stallTimeoutMs,
4785
+ input.frameIndex,
4786
+ input.totalFrames
4787
+ )
4788
+ );
4789
+ };
4790
+ signal?.addEventListener("abort", onAbort, { once: true });
4754
4791
  const deadline = Math.max(0, deadlineMs);
4755
4792
  let wait = Math.min(deadline, DE_STALL_POLL_MS);
4756
- let timer;
4757
4793
  const look = () => {
4758
4794
  const idle = clock.idle(wait);
4759
4795
  if (idle >= deadline) return trip();
@@ -4763,11 +4799,15 @@ function raceAgainstStall(promise, deadlineMs, input, signal) {
4763
4799
  timer = setTimeout(look, wait);
4764
4800
  promise.then(
4765
4801
  (value) => {
4766
- clearTimeout(timer);
4802
+ if (settled) return;
4803
+ settled = true;
4804
+ cleanup();
4767
4805
  resolve13(value);
4768
4806
  },
4769
4807
  (error) => {
4770
- clearTimeout(timer);
4808
+ if (settled) return;
4809
+ settled = true;
4810
+ cleanup();
4771
4811
  reject(error);
4772
4812
  }
4773
4813
  );
@@ -5266,20 +5306,14 @@ async function runCaptureStreamingStage(input) {
5266
5306
  abortSignal
5267
5307
  });
5268
5308
  const openSession = async () => {
5269
- const opening = createCaptureSession(
5270
- fileServer.url,
5271
- framesDir,
5272
- buildCaptureOptions(),
5273
- videoInjector,
5274
- captureCfg
5309
+ assertNotAborted();
5310
+ return openCaptureSessionWithinBudget(
5311
+ withinInitBudget,
5312
+ createCaptureSession(fileServer.url, framesDir, buildCaptureOptions(), videoInjector, {
5313
+ ...captureCfg,
5314
+ signal: abortSignal
5315
+ })
5275
5316
  );
5276
- try {
5277
- return await withinInitBudget(opening, OPENING_CAPTURE_SESSION);
5278
- } catch (error) {
5279
- void opening.then(closeCaptureSession, () => {
5280
- });
5281
- throw error;
5282
- }
5283
5317
  };
5284
5318
  const session = probeSession ?? await openSession();
5285
5319
  captureBeyondViewport = session.options.captureBeyondViewport;
@@ -5299,7 +5333,8 @@ async function runCaptureStreamingStage(input) {
5299
5333
  ...captureCfg,
5300
5334
  useDrawElement: false,
5301
5335
  staticFrameDedup: false,
5302
- enableBrowserPool: false
5336
+ enableBrowserPool: false,
5337
+ signal: abortSignal
5303
5338
  }
5304
5339
  );
5305
5340
  if (attemptClosed) {
@@ -5462,17 +5497,23 @@ async function captureSegmentFrames(ctx, segment, encoder) {
5462
5497
  for (let i = segment.startFrame; i < segment.endFrame; i++) {
5463
5498
  ctx.assertNotAborted();
5464
5499
  const time = i * ctx.job.config.fps.den / ctx.job.config.fps.num;
5465
- const { buffer } = await raceAgainstStall(
5466
- ctx.captureFrame(ctx.session, i, time),
5467
- ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5468
- {
5469
- session: ctx.session,
5470
- frameIndex: i,
5471
- totalFrames: ctx.totalFrames,
5472
- stallTimeoutMs: ctx.stallTimeoutMs
5473
- },
5474
- ctx.abortSignal
5475
- );
5500
+ let buffer;
5501
+ try {
5502
+ ({ buffer } = await raceAgainstStall(
5503
+ ctx.captureFrame(ctx.session, i, time),
5504
+ ctx.stallTimeoutMs - (Date.now() - lastProgressAt),
5505
+ {
5506
+ session: ctx.session,
5507
+ frameIndex: i,
5508
+ totalFrames: ctx.totalFrames,
5509
+ stallTimeoutMs: ctx.stallTimeoutMs
5510
+ },
5511
+ ctx.abortSignal
5512
+ ));
5513
+ } catch (error) {
5514
+ if (ctx.abortSignal?.aborted) ctx.assertNotAborted();
5515
+ throw error;
5516
+ }
5476
5517
  await verifyDrawElementSample(ctx.session, i, buffer, {
5477
5518
  log: ctx.log,
5478
5519
  verifyMinDb: ctx.verifyMinDb
@@ -6506,7 +6547,7 @@ function segmentFramesDir(rootDir, index) {
6506
6547
  }
6507
6548
  function createSegmentVideoFrames(input) {
6508
6549
  const extractFrames = input.extractFrames ?? extractDeferredFrames;
6509
- const sourceOf = input.sourceOf ?? ((video) => video.srcPath);
6550
+ const sourceOf2 = input.sourceOf ?? ((video) => video.srcPath);
6510
6551
  const fullyExtracted = input.extracted.filter((video) => !video.deferredRange);
6511
6552
  const tableFor = async (frames, dir) => {
6512
6553
  const sliced = await extractFrames({
@@ -6517,7 +6558,7 @@ function createSegmentVideoFrames(input) {
6517
6558
  outputRoot: dir,
6518
6559
  cfg: input.cfg,
6519
6560
  signal: input.abortSignal,
6520
- sourceOf,
6561
+ sourceOf: sourceOf2,
6521
6562
  shownBoxes: input.shownBoxes,
6522
6563
  onMissingFrame: (video, index) => new Error(
6523
6564
  `[Render] video ${JSON.stringify(video.videoId)} has no frame ${index}; it was expected to have ${video.totalFrames} frames.`
@@ -7186,6 +7227,15 @@ import {
7186
7227
  } from "@hyperframes/engine";
7187
7228
  var SHORT_CLIP_ONE_FRAME_TOLERANCE_MIN_EXPECTED_FRAMES = 14;
7188
7229
  var SHORT_CLIP_ONE_FRAME_TOLERANCE_MAX_EXPECTED_FRAMES = 20;
7230
+ var s3 = (seconds) => seconds.toFixed(3);
7231
+ function sourceWords(report) {
7232
+ const s = report.source;
7233
+ if (!s) return "";
7234
+ const vfr = s.isVFR ? ", variable frame rate" : "";
7235
+ const lead = s.leadSeconds > 0 ? `, video from ${s3(s.leadSeconds)} s` : "";
7236
+ const speed = s.rate === "ramp" ? "on a speed ramp" : `at ${s.rate}x`;
7237
+ 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}`;
7238
+ }
7189
7239
  var VideoFrameCoverageError = class extends Error {
7190
7240
  // Read structurally by isVideoFrameCoverageError and cross-module callers.
7191
7241
  hyperframesVideoFrameCoverageError = true;
@@ -7232,6 +7282,19 @@ function expectedFramesForVideo(video, entry, fps) {
7232
7282
  const sourceFrames = expectedFramesForClip(0, sourceDuration, fps, rounding);
7233
7283
  return Math.min(slotFrames, sourceFrames);
7234
7284
  }
7285
+ function sourceOf(video, entry) {
7286
+ const rate = normalizeRateSpec(video.playbackRate);
7287
+ return {
7288
+ codec: entry.metadata.videoCodec,
7289
+ fps: entry.metadata.fps,
7290
+ isVFR: entry.metadata.isVFR,
7291
+ playsTo: resolvePlayableVideoDuration(entry.metadata),
7292
+ leadSeconds: entry.metadata.videoStreamLeadSeconds ?? 0,
7293
+ readsFrom: video.mediaStart,
7294
+ readsTo: video.mediaStart + sourceTimeAt(rate, Math.max(0, video.end - video.start)),
7295
+ rate: typeof rate === "number" ? rate : "ramp"
7296
+ };
7297
+ }
7235
7298
  function computeVideoFrameCoverage(videos, extracted, fps) {
7236
7299
  const byId = /* @__PURE__ */ new Map();
7237
7300
  for (const entry of extracted) byId.set(entry.videoId, entry);
@@ -7247,7 +7310,8 @@ function computeVideoFrameCoverage(videos, extracted, fps) {
7247
7310
  clipEnd: video.end,
7248
7311
  expectedFrames,
7249
7312
  capturedFrames,
7250
- ratio
7313
+ ratio,
7314
+ ...entry && { source: sourceOf(video, entry) }
7251
7315
  });
7252
7316
  }
7253
7317
  return reports;
@@ -7264,7 +7328,7 @@ function assertVideoFrameCoverage(reports, threshold) {
7264
7328
  const thresholdPct = (threshold * 100).toFixed(1);
7265
7329
  const suffix = sorted.length > 1 ? ` (+${sorted.length - 1} more clip(s) below threshold)` : "";
7266
7330
  throw new VideoFrameCoverageError(
7267
- `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.`,
7331
+ `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.`,
7268
7332
  { threshold, worst, failedReports: sorted }
7269
7333
  );
7270
7334
  }
@@ -13505,25 +13569,26 @@ async function runSequentialDiskCapture(input, captureOptions, captureCfg, check
13505
13569
  assertNotAborted();
13506
13570
  attempt?.throwIfAborted();
13507
13571
  };
13572
+ const attemptSignal = combineAbortSignals(abortSignal, attempt);
13573
+ const initBudget = { frameIndex: resumeFrom, totalFrames, abortSignal: attemptSignal };
13508
13574
  const videoInjector = createRenderVideoFrameInjector();
13509
- const session = probeSession ?? await createCaptureSession5(
13510
- fileServer.url,
13575
+ const session = probeSession ?? await openSequentialDiskSession({
13576
+ assertAttemptActive,
13577
+ initBudget,
13578
+ fileServerUrl: fileServer.url,
13511
13579
  framesDir,
13512
13580
  captureOptions,
13513
13581
  videoInjector,
13514
- captureCfg
13515
- );
13582
+ captureCfg,
13583
+ attemptSignal
13584
+ });
13516
13585
  captureBeyondViewport = session.options.captureBeyondViewport;
13517
13586
  try {
13518
13587
  if (probeSession) {
13519
13588
  await prepareCaptureSessionForReuse3(session, framesDir, videoInjector);
13520
13589
  probeSession = null;
13521
13590
  }
13522
- await ensureSessionReady(session, {
13523
- frameIndex: resumeFrom,
13524
- totalFrames,
13525
- abortSignal: input.abortSignal
13526
- });
13591
+ await ensureSessionReady(session, initBudget);
13527
13592
  assertAttemptActive();
13528
13593
  lastBrowserConsole = session.browserConsoleBuffer;
13529
13594
  await captureSessionFrames(session, {
@@ -13575,9 +13640,26 @@ function planTransientResume(error, ctx) {
13575
13640
  if (!firstMissing) return null;
13576
13641
  return isTransientCaptureRetryEligible(failure.kind, missing, ctx.retriesUsed) ? firstMissing.startFrame : null;
13577
13642
  }
13643
+ function combineAbortSignals(first, second) {
13644
+ if (first && second) return AbortSignal.any([first, second]);
13645
+ return second ?? first;
13646
+ }
13647
+ async function openSequentialDiskSession(args) {
13648
+ args.assertAttemptActive();
13649
+ return openCaptureSessionWithinBudget(
13650
+ createSessionInitBudget(args.initBudget),
13651
+ createCaptureSession5(
13652
+ args.fileServerUrl,
13653
+ args.framesDir,
13654
+ args.captureOptions,
13655
+ args.videoInjector,
13656
+ { ...args.captureCfg, signal: args.attemptSignal }
13657
+ )
13658
+ );
13659
+ }
13578
13660
  async function ensureSessionReady(session, budget) {
13579
13661
  if (!session.isInitialized) {
13580
- await initializeSession5(session);
13662
+ await createSessionInitBudget(budget)(initializeSession5(session), session);
13581
13663
  return;
13582
13664
  }
13583
13665
  if (process.env.PRODUCER_EXPERIMENTAL_FAST_CAPTURE === "true") {
@@ -14379,12 +14461,17 @@ async function runCaptureHdrStage(input) {
14379
14461
  projectDir,
14380
14462
  compiledDir
14381
14463
  });
14382
- const domSession = await createCaptureSession7(
14383
- fileServer.url,
14384
- framesDir,
14385
- buildCaptureOptions(),
14386
- createRenderVideoFrameInjector(),
14387
- hdrCfg
14464
+ assertNotAborted();
14465
+ const withinInitBudget = createSessionInitBudget({ frameIndex: 0, totalFrames, abortSignal });
14466
+ const domSession = await openCaptureSessionWithinBudget(
14467
+ withinInitBudget,
14468
+ createCaptureSession7(
14469
+ fileServer.url,
14470
+ framesDir,
14471
+ buildCaptureOptions(),
14472
+ createRenderVideoFrameInjector(),
14473
+ { ...hdrCfg, signal: abortSignal }
14474
+ )
14388
14475
  );
14389
14476
  let hdrEncoder = null;
14390
14477
  let hdrEncoderClosed = false;
@@ -14393,7 +14480,7 @@ async function runCaptureHdrStage(input) {
14393
14480
  let releaseHdrImageReservation = null;
14394
14481
  const hdrVideoFrameSources = /* @__PURE__ */ new Map();
14395
14482
  try {
14396
- await initializeSession7(domSession);
14483
+ await withinInitBudget(initializeSession7(domSession), domSession);
14397
14484
  assertNotAborted();
14398
14485
  lastBrowserConsole = domSession.browserConsoleBuffer;
14399
14486
  await initTransparentBackground2(domSession.page, { clearCompositionRoot: true });
@@ -16349,6 +16436,9 @@ async function executeRenderPipeline(input) {
16349
16436
  memSampler = createMemorySampler();
16350
16437
  const assertNotAborted = () => {
16351
16438
  execution.assertActive(() => new RenderCancelledError("render_cancelled"));
16439
+ if (executionSignal.aborted) {
16440
+ throw tooSlowError ?? audioFailure ?? new RenderCancelledError("render_cancelled");
16441
+ }
16352
16442
  };
16353
16443
  job.startedAt = /* @__PURE__ */ new Date();
16354
16444
  assertNotAborted();
@@ -49,6 +49,7 @@ export type StalledSession = {
49
49
  captureStep?: string;
50
50
  };
51
51
  export declare const OPENING_CAPTURE_SESSION: StalledSession;
52
+ export declare function openCaptureSessionWithinBudget(withinInitBudget: ReturnType<typeof createSessionInitBudget>, opening: Promise<CaptureSession>): Promise<CaptureSession>;
52
53
  export declare function raceAgainstStall<T>(promise: Promise<T>, deadlineMs: number, input: {
53
54
  session: StalledSession;
54
55
  frameIndex: number;
@@ -53,6 +53,21 @@ export interface VideoFrameCoverageReport {
53
53
  capturedFrames: number;
54
54
  /** `capturedFrames / expectedFrames`; `1` when `expectedFrames === 0` (nothing to cover). */
55
55
  ratio: number;
56
+ /** What the clip reads, when it was probed: the failure's message names it. */
57
+ source?: {
58
+ codec: string;
59
+ fps: number;
60
+ isVFR: boolean;
61
+ /** Where the video's last frame ends on the media timeline: the end the gate's expected frames stop at. */
62
+ playsTo: number;
63
+ /** Media time before the video's first frame, when the stream starts late. */
64
+ leadSeconds: number;
65
+ /** The span of source the clip's window reads, through its speed or ramp. */
66
+ readsFrom: number;
67
+ readsTo: number;
68
+ /** A number, or "ramp" when the speed changes over the clip. */
69
+ rate: number | "ramp";
70
+ };
56
71
  }
57
72
  /**
58
73
  * Discriminant-based error so callers cross-module (producer server,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/producer",
3
- "version": "0.9.97",
3
+ "version": "0.9.99",
4
4
  "description": "HTML-to-video rendering engine using Chrome's BeginFrame API",
5
5
  "repository": {
6
6
  "type": "git",
@@ -35,11 +35,12 @@
35
35
  "postcss": "^8.4.0",
36
36
  "puppeteer": "~25.13.0",
37
37
  "puppeteer-core": "^25.13.0",
38
- "@hyperframes/engine": "0.9.97",
39
- "@hyperframes/parsers": "0.9.97",
40
- "@hyperframes/core": "0.9.97",
41
- "@hyperframes/studio-server": "0.9.97",
42
- "@hyperframes/lint": "0.9.97"
38
+ "@hyperframes/core": "0.9.99",
39
+ "@hyperframes/parsers": "0.9.99",
40
+ "@hyperframes/lint": "0.9.99",
41
+ "@hyperframes/share": "0.9.99",
42
+ "@hyperframes/studio-server": "0.9.99",
43
+ "@hyperframes/engine": "0.9.99"
43
44
  },
44
45
  "devDependencies": {
45
46
  "@types/node": "^25.0.10",
@@ -48,7 +49,7 @@
48
49
  "tsx": "^4.21.0",
49
50
  "typescript": "^5.7.2",
50
51
  "vitest": "^4.1.12",
51
- "@hyperframes/aws-lambda": "0.9.97"
52
+ "@hyperframes/aws-lambda": "0.9.99"
52
53
  },
53
54
  "engines": {
54
55
  "node": ">=22"