@hyperframes/producer 0.9.69 → 0.9.71

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.
@@ -19,14 +19,14 @@ import {
19
19
  fpsToNumber as fpsToNumber9,
20
20
  HF_COLOR_GRADING_ATTR as HF_COLOR_GRADING_ATTR2
21
21
  } from "@hyperframes/core";
22
- import { isSafePath as isSafePath2 } from "@hyperframes/core/safe-path";
22
+ import { isSafePath as isSafePath3 } from "@hyperframes/core/safe-path";
23
23
  import {
24
24
  getEncoderPreset as getEncoderPreset4,
25
25
  keyframeIntervalToGopSize as keyframeIntervalToGopSize3,
26
26
  normalizeVp9CpuUsed,
27
27
  resolveConfig as resolveConfig3,
28
28
  declareContentAddressedUrl,
29
- renameWithRetry as renameWithRetry8,
29
+ renameWithRetry as renameWithRetry7,
30
30
  declareProbeFactsUrl
31
31
  } from "@hyperframes/engine";
32
32
 
@@ -1753,8 +1753,15 @@ var BYTES_PER_MIB = 1024 * 1024;
1753
1753
  var DEFAULT_HDR_WINDOW_BYTES = 512 * BYTES_PER_MIB;
1754
1754
 
1755
1755
  // src/services/render/segmentManifest.ts
1756
+ import {
1757
+ assertPrivateCachePath,
1758
+ ensurePrivateCacheDir,
1759
+ hyperframesCacheDir
1760
+ } from "@hyperframes/core/cache-dir";
1761
+ import { isSafePath as isSafePath2, realpath } from "@hyperframes/core/safe-path";
1762
+ import { isPathInside as isPathInside3 } from "@hyperframes/parsers/asset-paths";
1756
1763
  import { previewToken } from "@hyperframes/core/preview-proof";
1757
- import { renameWithRetry as renameWithRetry2 } from "@hyperframes/engine";
1764
+ import { replaceFileAtomically } from "@hyperframes/core/atomic-file";
1758
1765
 
1759
1766
  // src/services/render/stages/captureStreamingStage.ts
1760
1767
  import {
@@ -2458,7 +2465,7 @@ import { statSync as statSync3 } from "node:fs";
2458
2465
  var MAX_COMPOSITION_HTML_BYTES = 16 * 1024 * 1024;
2459
2466
  var COMPOSITION_TOO_LARGE = "COMPOSITION_TOO_LARGE";
2460
2467
  var megabytes = (bytes) => `${(bytes / (1024 * 1024)).toFixed(1)} MB`;
2461
- var MAX_EXPANDED_COMPOSITION_BYTES = 2 * MAX_COMPOSITION_HTML_BYTES;
2468
+ var MAX_EXPANDED_COMPOSITION_BYTES = 4 * MAX_COMPOSITION_HTML_BYTES;
2462
2469
  var MAX_COMPOSITION_MOUNTS = 1e4;
2463
2470
  var CompositionTooLargeError = class extends Error {
2464
2471
  constructor(message, publicMetadata) {
@@ -2607,6 +2614,7 @@ import {
2607
2614
  isJavaScriptType,
2608
2615
  prepareFlattenedInnerRoot,
2609
2616
  emitRootCompositionVariableStyles,
2617
+ dropAuthoredSvgReferenceAliases,
2610
2618
  readDeclaredDefaults,
2611
2619
  parseHostVariableValues,
2612
2620
  boundMediaSrc,
@@ -2834,7 +2842,7 @@ import {
2834
2842
  DEFAULT_VP9_CPU_USED,
2835
2843
  isPrivateUnderAssetRoots,
2836
2844
  runFfmpeg as runFfmpeg2,
2837
- renameWithRetry as renameWithRetry3,
2845
+ renameWithRetry as renameWithRetry2,
2838
2846
  urlInputArgs as urlInputArgs2
2839
2847
  } from "@hyperframes/engine";
2840
2848
  import { namesAnotherNetworkRoot } from "@hyperframes/parsers/asset-resolution";
@@ -3019,7 +3027,7 @@ async function ensurePreparedWebm(input) {
3019
3027
  throw new Error("Animated GIF transcode produced an empty output");
3020
3028
  }
3021
3029
  if (!isUsableFile(input.cachePath)) {
3022
- renameWithRetry3(tmpPath, input.cachePath);
3030
+ renameWithRetry2(tmpPath, input.cachePath);
3023
3031
  } else {
3024
3032
  rmSync2(tmpPath, { force: true });
3025
3033
  }
@@ -3155,7 +3163,7 @@ import {
3155
3163
  } from "node:fs";
3156
3164
  import { dirname as dirname5, join as join7, resolve as resolve5 } from "node:path";
3157
3165
  import { parseHTML as parseHTML4 } from "linkedom";
3158
- import { renameWithRetry as renameWithRetry4, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
3166
+ import { renameWithRetry as renameWithRetry3, runFfmpeg as runFfmpeg3, runFfprobe, urlInputArgs as urlInputArgs3 } from "@hyperframes/engine";
3159
3167
 
3160
3168
  // src/services/heifRotation.ts
3161
3169
  function* boxes(buf, start, end) {
@@ -3414,7 +3422,7 @@ async function ensurePreparedJpeg(source, cachePath, outputPath, options) {
3414
3422
  timeoutMs: options.timeoutMs
3415
3423
  });
3416
3424
  if (!isUsableFile2(tmpPath)) throw new Error("conversion produced an empty file");
3417
- renameWithRetry4(tmpPath, cachePath);
3425
+ renameWithRetry3(tmpPath, cachePath);
3418
3426
  } catch (error) {
3419
3427
  const reason = error instanceof Error ? error.message : String(error);
3420
3428
  throw TOOL_FAILURE_RE.test(reason) ? new HeifToolUnavailableError(source.label, reason) : new HeifImageConversionError(source.label, reason);
@@ -4230,13 +4238,14 @@ function inlineSubCompositions(html, subCompositions, projectDir, variableOverri
4230
4238
  const body = document2.querySelector("body");
4231
4239
  const hosts = Array.from(document2.querySelectorAll("[data-composition-src]"));
4232
4240
  if (!hosts.length) {
4241
+ const dropped = dropAuthoredSvgReferenceAliases(document2);
4233
4242
  const emitted = emitRootCompositionVariableStyles(
4234
4243
  document2,
4235
4244
  {},
4236
4245
  variableOverrides,
4237
4246
  { chargeBytes: (bytes) => budget.chargeGenerated("composition variables", bytes) }
4238
4247
  );
4239
- return { html: emitted ? document2.toString() : html, variablesByComp: {} };
4248
+ return { html: emitted || dropped ? document2.toString() : html, variablesByComp: {} };
4240
4249
  }
4241
4250
  const readOnce = /* @__PURE__ */ new Map();
4242
4251
  const readMountHtml = (srcPath) => {
@@ -4428,18 +4437,31 @@ function operatorGsapMirror() {
4428
4437
  return void 0;
4429
4438
  }
4430
4439
  }
4431
- async function downloadScript(src, mirror) {
4440
+ async function downloadScript(src, mirror, signal) {
4432
4441
  if (mirror && new URL(src).href.startsWith(mirror)) {
4433
- const response = await fetch(src, { redirect: "error", signal: AbortSignal.timeout(15e3) });
4442
+ const response = await fetch(src, {
4443
+ redirect: "error",
4444
+ signal: AbortSignal.any([AbortSignal.timeout(15e3), signal])
4445
+ });
4434
4446
  if (!response.ok) throw new Error(`HTTP ${response.status} for ${src}`);
4435
4447
  const bytes = new Uint8Array(await response.arrayBuffer());
4436
4448
  if (bytes.byteLength > MAX_SCRIPT_BYTES) throw new Error(`Script over 16 MiB: ${src}`);
4437
4449
  return bytes;
4438
4450
  }
4439
- return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3 });
4451
+ return fetchPublicHttpsBytes(src, { maxBytes: MAX_SCRIPT_BYTES, timeoutMs: 15e3, signal });
4440
4452
  }
4441
4453
  var MAX_CONCURRENT_SCRIPT_FETCHES = 4;
4442
- async function inlineExternalScripts(html, budget = new CompositionExpansionBudget()) {
4454
+ var MAX_REMOTE_FETCHES = 32;
4455
+ var REMOTE_FETCH_DEADLINE_MS = 6e4;
4456
+ var fetchSignalOf = (signal) => typeof signal === "function" ? signal() : signal;
4457
+ function assertRemoteFetchCount(kind, count) {
4458
+ if (count > MAX_REMOTE_FETCHES) {
4459
+ throw new Error(
4460
+ `The composition links ${count} remote ${kind}; at most ${MAX_REMOTE_FETCHES} are downloaded at compile time`
4461
+ );
4462
+ }
4463
+ }
4464
+ async function inlineExternalScripts(html, budget = new CompositionExpansionBudget(), signal) {
4443
4465
  const fullHtml = ensureFullDocument(html);
4444
4466
  const wrappedFragment = fullHtml !== html;
4445
4467
  const { document: document2 } = parseHTML5(fullHtml);
@@ -4452,9 +4474,19 @@ async function inlineExternalScripts(html, budget = new CompositionExpansionBudg
4452
4474
  }
4453
4475
  }
4454
4476
  if (externalScripts.length === 0) return html;
4477
+ const bundled = /* @__PURE__ */ new Map();
4478
+ const local = externalScripts.map(({ el, src }) => {
4479
+ if (!bundled.has(src)) bundled.set(src, bundledScript(src));
4480
+ const bytes = bundled.get(src);
4481
+ return bytes && matchesScriptIntegrity(bytes, el.getAttribute("integrity") || "") ? bytes : null;
4482
+ });
4483
+ const remote = new Set(externalScripts.filter((_, i) => !local[i]).map(({ src }) => src));
4484
+ assertRemoteFetchCount("scripts", remote.size);
4455
4485
  const mirror = operatorGsapMirror();
4456
4486
  const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
4457
4487
  const stop = new AbortController();
4488
+ const shared = remote.size > 0 ? fetchSignalOf(signal) : void 0;
4489
+ const fetchSignal = shared ? AbortSignal.any([stop.signal, shared]) : stop.signal;
4458
4490
  const fail = (error) => {
4459
4491
  stop.abort(error);
4460
4492
  throw error;
@@ -4471,21 +4503,21 @@ async function inlineExternalScripts(html, budget = new CompositionExpansionBudg
4471
4503
  let bytes = fetches.get(src);
4472
4504
  if (!bytes) {
4473
4505
  bytes = limit(async () => {
4474
- if (stop.signal.aborted) throw stop.signal.reason;
4475
- const downloaded = await downloadScript(src, mirror);
4506
+ fetchSignal.throwIfAborted();
4507
+ const downloaded = await downloadScript(src, mirror, fetchSignal);
4476
4508
  charge(downloaded.byteLength);
4477
4509
  return downloaded;
4478
- }, stop.signal);
4510
+ }, fetchSignal);
4479
4511
  fetches.set(src, bytes);
4480
4512
  }
4481
4513
  return bytes;
4482
4514
  };
4483
4515
  const placed = /* @__PURE__ */ new Set();
4484
4516
  const downloads = await Promise.allSettled(
4485
- externalScripts.map(async ({ el, src }) => {
4517
+ externalScripts.map(async ({ el, src }, i) => {
4486
4518
  const integrity = el.getAttribute("integrity") || "";
4487
- let bytes = bundledScript(src);
4488
- if (bytes && matchesScriptIntegrity(bytes, integrity)) {
4519
+ let bytes = local[i];
4520
+ if (bytes) {
4489
4521
  charge(bytes.byteLength);
4490
4522
  } else {
4491
4523
  bytes = await fetchOnce(src);
@@ -4682,12 +4714,13 @@ function isGoogleFontsUrl(href) {
4682
4714
  }
4683
4715
  }
4684
4716
  var MAX_STYLESHEET_BYTES = 2 * 1024 * 1024;
4685
- async function fetchExternalStylesheetCss(href) {
4717
+ async function fetchExternalStylesheetCss(href, signal) {
4686
4718
  const identity = safeDownloadUrlIdentity(href);
4687
4719
  try {
4688
4720
  return await fetchPublicHttpsText(href, {
4689
4721
  maxBytes: MAX_STYLESHEET_BYTES,
4690
- timeoutMs: 15e3
4722
+ timeoutMs: 15e3,
4723
+ signal
4691
4724
  });
4692
4725
  } catch (err) {
4693
4726
  defaultLogger.warn("[Compiler] External stylesheet fetch failed, preserving link tag.", {
@@ -4727,36 +4760,42 @@ function remoteFontStylesheetHref(tag) {
4727
4760
  if (!href || !/^https?:\/\//i.test(href) || isGoogleFontsUrl(href)) return void 0;
4728
4761
  return href;
4729
4762
  }
4730
- async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget()) {
4763
+ async function inlineExternalFontStylesheets(html, budget = new CompositionExpansionBudget(), signal) {
4731
4764
  const hrefs = /* @__PURE__ */ new Set();
4732
4765
  for (const { parts } of stylesheetLinkMatches(html)) {
4733
4766
  const href = remoteFontStylesheetHref(parts[0]);
4734
4767
  if (href) hrefs.add(href);
4735
4768
  }
4736
4769
  if (hrefs.size === 0) return html;
4737
- const MAX_CONCURRENT_STYLESHEET_FETCHES = 4;
4770
+ assertRemoteFetchCount("stylesheets", hrefs.size);
4771
+ const limit = createConcurrencyLimit(MAX_CONCURRENT_SCRIPT_FETCHES);
4772
+ const stop = new AbortController();
4773
+ const shared = fetchSignalOf(signal);
4774
+ const fetchSignal = shared ? AbortSignal.any([stop.signal, shared]) : stop.signal;
4738
4775
  const inlineByHref = /* @__PURE__ */ new Map();
4739
- const unique = [...hrefs];
4740
- for (let i = 0; i < unique.length; i += MAX_CONCURRENT_STYLESHEET_FETCHES) {
4741
- const batch = unique.slice(i, i + MAX_CONCURRENT_STYLESHEET_FETCHES);
4742
- const sheets = await Promise.all(batch.map(fetchExternalStylesheetCss));
4743
- batch.forEach((href, index) => {
4744
- const css = sheets[index];
4745
- const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
4746
- if (fontFaceBlocks.length === 0) return;
4747
- const inlineStyle = `<style>/* Inlined external font stylesheet */
4776
+ const inlineSheet = async (href) => {
4777
+ const css = await fetchExternalStylesheetCss(href, fetchSignal);
4778
+ const fontFaceBlocks = css ? extractFontFaceBlocks(css) : [];
4779
+ if (fontFaceBlocks.length === 0) return;
4780
+ const inlineStyle = `<style>/* Inlined external font stylesheet */
4748
4781
  ${fontFaceBlocks.join("\n")}
4749
4782
  </style>`;
4783
+ try {
4750
4784
  budget.chargeGenerated(REMOTE_STYLESHEETS, inlineStyle.length);
4751
- inlineByHref.set(href, inlineStyle);
4752
- const identity = safeDownloadUrlIdentity(href);
4753
- defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
4754
- count: fontFaceBlocks.length,
4755
- urlFingerprint: identity.urlFingerprint,
4756
- host: identity.host
4757
- });
4785
+ } catch (error) {
4786
+ stop.abort(error);
4787
+ throw error;
4788
+ }
4789
+ inlineByHref.set(href, inlineStyle);
4790
+ const identity = safeDownloadUrlIdentity(href);
4791
+ defaultLogger.debug("[Compiler] Inlined external @font-face rule(s)", {
4792
+ count: fontFaceBlocks.length,
4793
+ urlFingerprint: identity.urlFingerprint,
4794
+ host: identity.host
4758
4795
  });
4759
- }
4796
+ };
4797
+ await Promise.allSettled([...hrefs].map((href) => limit(() => inlineSheet(href), fetchSignal)));
4798
+ if (stop.signal.aborted) throw stop.signal.reason;
4760
4799
  const placed = /* @__PURE__ */ new Set();
4761
4800
  return replaceMatches(html, stylesheetLinkMatches(html), (tag) => {
4762
4801
  const href = remoteFontStylesheetHref(tag);
@@ -5066,10 +5105,17 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
5066
5105
  const hasShaderTransitions = detectShaderTransitionUsage(sanitizedHtml);
5067
5106
  const usesThreeDTransforms = detectThreeDTransformUsage(sanitizedHtml);
5068
5107
  const hasAncestorBackgroundImage = detectAncestorBackgroundImage(sanitizedHtml);
5108
+ let deadline;
5109
+ const remoteFetches = () => deadline ??= AbortSignal.any([
5110
+ AbortSignal.timeout(REMOTE_FETCH_DEADLINE_MS),
5111
+ ...options.abortSignal ? [options.abortSignal] : []
5112
+ ]);
5069
5113
  const fontSheetHtml = await inlineExternalFontStylesheets(
5070
5114
  promoteCssImportsToLinkTags(sanitizedHtml),
5071
- budget
5115
+ budget,
5116
+ remoteFetches
5072
5117
  );
5118
+ options.abortSignal?.throwIfAborted();
5073
5119
  const normalizedFontHtml = normalizeSystemFontPrimaryFamilies(
5074
5120
  injectTextRenderingRule(coalesceHeadStylesAndBodyScripts(fontSheetHtml))
5075
5121
  );
@@ -5080,7 +5126,8 @@ async function compileForRender(projectDir, htmlPath, downloadDir, options = {})
5080
5126
  projectFontFamilies: projectStylesheetFontFamilies(fontSheetHtml, projectDir),
5081
5127
  abortSignal: options.abortSignal
5082
5128
  });
5083
- const assembledHtml = await inlineExternalScripts(coalescedHtml, budget);
5129
+ const assembledHtml = await inlineExternalScripts(coalescedHtml, budget, remoteFetches);
5130
+ options.abortSignal?.throwIfAborted();
5084
5131
  const htmlWithPositionScript = htmlHasStudioPositionEdits(assembledHtml) ? insertBeforeCloseTag(
5085
5132
  assembledHtml,
5086
5133
  "body",
@@ -7154,10 +7201,11 @@ import {
7154
7201
  applyAudioFxChain,
7155
7202
  describeFfmpegFailure as describeFfmpegFailure3,
7156
7203
  encodeAac as encodeAac2,
7157
- renameWithRetry as renameWithRetry6
7204
+ renameWithRetry as renameWithRetry5
7158
7205
  } from "@hyperframes/engine";
7159
7206
 
7160
7207
  // src/services/render/audioPadTrim.ts
7208
+ import { localContainerInputArgs } from "@hyperframes/parsers/ff-binaries";
7161
7209
  import { spawn } from "node:child_process";
7162
7210
  import { dirname as dirname8, join as join13 } from "node:path";
7163
7211
  import {
@@ -7168,7 +7216,7 @@ import {
7168
7216
  getFfprobeBinary,
7169
7217
  ManagedChildProcess,
7170
7218
  removeScratch,
7171
- renameWithRetry as renameWithRetry5,
7219
+ renameWithRetry as renameWithRetry4,
7172
7220
  runFfmpeg as runFfmpeg5,
7173
7221
  trackChildProcess,
7174
7222
  withPublicOnlyProxy
@@ -7309,10 +7357,10 @@ function sanitizeProbeFailure(reason, paths) {
7309
7357
  }
7310
7358
  async function padOrTrimAudioToVideoFrameCount(input) {
7311
7359
  const probeVideo = input.probeVideoFrameInfo ?? ((videoPath) => defaultProbeVideoFrameInfo(videoPath, input.signal));
7312
- const probeAudio = input.probeAudioInfo ?? defaultProbeAudioInfo;
7360
+ const probeAudio = input.probeAudioInfo ?? ((path, signal) => defaultProbeAudioInfo(path, signal, input.audioContainer));
7313
7361
  const timeoutMs = input.timeoutMs ?? DEFAULT_CONFIG.ffmpegProcessTimeout;
7314
7362
  const runner = input.runFfmpeg ?? ((args) => defaultRunFfmpeg(args, timeoutMs, input.signal));
7315
- const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath);
7363
+ const encode = input.encodeAac ?? defaultAacEncoder(timeoutMs, input.signal, input.sourcePath, input.audioContainer);
7316
7364
  const probeTruePeak = input.probeAudioTruePeakDbfs ?? (input.runFfmpeg || input.encodeAac ? void 0 : (audioPath, signal) => measureTruePeakDbfs(audioPath, { timeoutMs, signal }));
7317
7365
  const [videoResult, audioResult] = await Promise.allSettled([
7318
7366
  probeVideo(input.videoPath),
@@ -7360,7 +7408,7 @@ async function padOrTrimAudioToVideoFrameCount(input) {
7360
7408
  );
7361
7409
  try {
7362
7410
  for (const step of plan.steps) {
7363
- const ffmpegResult = step.kind === "copy" ? await runner(step.args) : await encode(
7411
+ const ffmpegResult = step.kind === "copy" ? await runner([...localContainerInputArgs(input.audioContainer), ...step.args]) : await encode(
7364
7412
  input.sourcePath ?? input.audioPath,
7365
7413
  input.outputPath,
7366
7414
  targetDurationSeconds,
@@ -7444,7 +7492,7 @@ async function cutSource(input, scratchDir, attenuationDb) {
7444
7492
  try {
7445
7493
  const result = await input.rewriteSource(input.sourcePath, cutPath, gainFilter(attenuationDb));
7446
7494
  if (!result.success) throw new Error(result.error);
7447
- renameWithRetry5(cutPath, input.sourcePath, { copyFallback: true });
7495
+ renameWithRetry4(cutPath, input.sourcePath, { copyFallback: true });
7448
7496
  return true;
7449
7497
  } catch {
7450
7498
  removeScratch(input.sourcePath);
@@ -7471,7 +7519,7 @@ async function enforceAacTruePeak(input) {
7471
7519
  if (truePeakDbfs <= AAC_DELIVERY_TRUE_PEAK_DBFS) {
7472
7520
  if (measuredPath !== correctedPath) return { success: true };
7473
7521
  const sourceCut = await cutSource(input, scratchDir, attenuationDb);
7474
- renameWithRetry5(correctedPath, input.audioPath, { copyFallback: true });
7522
+ renameWithRetry4(correctedPath, input.audioPath, { copyFallback: true });
7475
7523
  const loweredDb = Number((-attenuationDb).toFixed(2));
7476
7524
  return sourceCut ? { success: true, loweredDb } : { success: true, loweredDb, sourceStale: true };
7477
7525
  }
@@ -7526,7 +7574,8 @@ function failResult(outputPath, target, source, error) {
7526
7574
  error
7527
7575
  };
7528
7576
  }
7529
- async function defaultProbeVideoFrameInfo(videoPath, signal) {
7577
+ async function defaultProbeVideoFrameInfo(videoPath, signal, container) {
7578
+ const inputArgs = localContainerInputArgs(container);
7530
7579
  const fastInfo = await runFfprobeJson(
7531
7580
  [
7532
7581
  "-v",
@@ -7537,6 +7586,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
7537
7586
  "stream=nb_frames,r_frame_rate",
7538
7587
  "-of",
7539
7588
  "json",
7589
+ ...inputArgs,
7540
7590
  "--",
7541
7591
  videoPath
7542
7592
  ],
@@ -7558,6 +7608,7 @@ async function defaultProbeVideoFrameInfo(videoPath, signal) {
7558
7608
  "stream=nb_read_packets,r_frame_rate",
7559
7609
  "-of",
7560
7610
  "json",
7611
+ ...inputArgs,
7561
7612
  "--",
7562
7613
  videoPath
7563
7614
  ],
@@ -7580,8 +7631,8 @@ function parseFrameRate(rate) {
7580
7631
  }
7581
7632
  return { fpsNum, fpsDen };
7582
7633
  }
7583
- async function defaultProbeAudioInfo(audioPath, signal) {
7584
- const metadata = await extractAudioMetadata3(audioPath, { signal });
7634
+ async function defaultProbeAudioInfo(audioPath, signal, inputContainer) {
7635
+ const metadata = await extractAudioMetadata3(audioPath, { signal, inputContainer });
7585
7636
  return {
7586
7637
  durationSeconds: metadata.durationSeconds,
7587
7638
  sampleRate: metadata.sampleRate,
@@ -7592,9 +7643,9 @@ async function defaultProbeAudioInfo(audioPath, signal) {
7592
7643
  async function defaultRunFfmpeg(args, timeoutMs, signal) {
7593
7644
  return toStepResult(await runFfmpeg5(args, { signal, timeout: timeoutMs }), timeoutMs);
7594
7645
  }
7595
- function defaultAacEncoder(timeoutMs, signal, pcmSourcePath) {
7646
+ function defaultAacEncoder(timeoutMs, signal, pcmSourcePath, inputContainer) {
7596
7647
  return async (inputPath, outputPath, durationSeconds, filter) => {
7597
- const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1 };
7648
+ const options = pcmSourcePath ? { signal, timeout: timeoutMs, filter } : { signal, timeout: timeoutMs, filter, segments: 1, inputContainer };
7598
7649
  return toStepResult(
7599
7650
  await encodeAac(pcmSourcePath ?? inputPath, outputPath, durationSeconds, options),
7600
7651
  timeoutMs
@@ -7667,7 +7718,7 @@ async function limitDeliveryPeaks(input, deps = {
7667
7718
  measure: measureTruePeakDbfs,
7668
7719
  applyChain: applyAudioFxChain,
7669
7720
  encode: encodeAac2,
7670
- rename: renameWithRetry6,
7721
+ rename: renameWithRetry5,
7671
7722
  sourceExists: existsSync10
7672
7723
  }) {
7673
7724
  const { audioPath, sourcePath, signal, timeoutMs } = input;
@@ -10128,7 +10179,7 @@ import { appendRenderProvenanceArgs, describeFfmpegFailure as describeFfmpegFail
10128
10179
  // src/services/distributed/mp4Stitch.ts
10129
10180
  import { createReadStream as createReadStream4, createWriteStream, mkdirSync as mkdirSync8, rmSync as rmSync6 } from "node:fs";
10130
10181
  import { open } from "node:fs/promises";
10131
- import { renameWithRetry as renameWithRetry7 } from "@hyperframes/engine";
10182
+ import { renameWithRetry as renameWithRetry6 } from "@hyperframes/engine";
10132
10183
  import { basename as basename5, dirname as dirname13, join as join24 } from "node:path";
10133
10184
  import { finished, pipeline } from "node:stream/promises";
10134
10185
  import { createStagingDir as createStagingDir4 } from "@hyperframes/core/atomic-file";
@@ -10502,7 +10553,7 @@ async function writeStitchedMp4(chunkPaths, outputPath, audioPath) {
10502
10553
  for (const [i, path] of sourcePaths.entries()) await copyPayload(path, layouts[i], i, out);
10503
10554
  out.end();
10504
10555
  await finished(out);
10505
- renameWithRetry7(join24(workDir, "out.mp4"), outputPath);
10556
+ renameWithRetry6(join24(workDir, "out.mp4"), outputPath);
10506
10557
  } finally {
10507
10558
  out.destroy();
10508
10559
  rmSync6(workDir, { recursive: true, force: true });
@@ -11266,7 +11317,7 @@ async function compilePlanComposition(projectDir, config, planDir, options) {
11266
11317
  const warn = (line) => log.warn(`[Plan] ${line}`);
11267
11318
  const policy = { includeScripts: job.config.includeOutsideScripts };
11268
11319
  if (refusesOutsideLink(projectDir, src, warn, policy)) return false;
11269
- } else if (!isSafePath2(projectDir, src)) return false;
11320
+ } else if (!isSafePath3(projectDir, src)) return false;
11270
11321
  const firstSegment = rel.split(sep4, 1)[0];
11271
11322
  return firstSegment === void 0 || !PLAN_PROJECT_DIR_SKIP_SEGMENTS.has(firstSegment);
11272
11323
  }
@@ -11486,12 +11537,12 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
11486
11537
  const videoSourcesDir = join27(planDir, "video-sources");
11487
11538
  rmSync7(videoSourcesDir, { recursive: true, force: true });
11488
11539
  if (existsSync19(stagedVideoFrames)) {
11489
- renameWithRetry8(stagedVideoFrames, videoFramesDst);
11540
+ renameWithRetry7(stagedVideoFrames, videoFramesDst);
11490
11541
  } else {
11491
11542
  mkdirSync10(videoFramesDst, { recursive: true });
11492
11543
  }
11493
11544
  if (existsSync19(finalCompiledDir)) rmSync7(finalCompiledDir, { recursive: true, force: true });
11494
- renameWithRetry8(compiledDir, finalCompiledDir);
11545
+ renameWithRetry7(compiledDir, finalCompiledDir);
11495
11546
  const shipVideoSource = createVideoSourceShipper({
11496
11547
  planDir,
11497
11548
  projectDir,
@@ -11612,7 +11663,7 @@ async function buildLocalExecutionPlan(projectDir, config, executionPlanDir, opt
11612
11663
  }
11613
11664
  const planAudioPath = join27(planDir, PLAN_AUDIO_RELATIVE_PATH);
11614
11665
  if (audioResult?.hasAudio && existsSync19(audioResult.audioOutputPath)) {
11615
- renameWithRetry8(audioResult.audioOutputPath, planAudioPath);
11666
+ renameWithRetry7(audioResult.audioOutputPath, planAudioPath);
11616
11667
  }
11617
11668
  if (chunksCarryAudio && existsSync19(planAudioPath)) {
11618
11669
  if (options.sliceChunkAudio) {
@@ -11735,7 +11786,7 @@ async function buildPlanAudio(projectDir, config, workRoot, outputPath, options
11735
11786
  applyDistributedAudioWarningPolicy(c.job, mixed.audioError, mixed.audioFailures, c.log);
11736
11787
  }
11737
11788
  if (!mixed.hasAudio || !existsSync19(mixed.audioOutputPath)) return { hasAudio: false };
11738
- renameWithRetry8(mixed.audioOutputPath, outputPath);
11789
+ renameWithRetry7(mixed.audioOutputPath, outputPath);
11739
11790
  return { hasAudio: true };
11740
11791
  } finally {
11741
11792
  rmSync7(c.workDir, { recursive: true, force: true });
@@ -11764,7 +11815,7 @@ import { DISTRIBUTED_FPS, isDistributedFps } from "@hyperframes/core";
11764
11815
  import {
11765
11816
  createFrameLookupTable as createFrameLookupTable5,
11766
11817
  mediaIdPathSegment as mediaIdPathSegment4,
11767
- renameWithRetry as renameWithRetry10
11818
+ renameWithRetry as renameWithRetry9
11768
11819
  } from "@hyperframes/engine";
11769
11820
 
11770
11821
  // src/services/distributed/planV2Publisher.ts
@@ -11777,7 +11828,7 @@ import {
11777
11828
  statSync as statSync8,
11778
11829
  writeFileSync as writeFileSync9
11779
11830
  } from "node:fs";
11780
- import { renameWithRetry as renameWithRetry9 } from "@hyperframes/engine";
11831
+ import { renameWithRetry as renameWithRetry8 } from "@hyperframes/engine";
11781
11832
  import { dirname as dirname14, join as join29 } from "node:path";
11782
11833
 
11783
11834
  // src/services/distributed/planV2Errors.ts
@@ -11862,7 +11913,7 @@ var LocalPlanV2ArtifactPublisher = class {
11862
11913
  if (!cannotHardLink(error)) throw error;
11863
11914
  copyFileSync7(blob.sourcePath, temporaryPath);
11864
11915
  }
11865
- renameWithRetry9(temporaryPath, destinationPath);
11916
+ renameWithRetry8(temporaryPath, destinationPath);
11866
11917
  } finally {
11867
11918
  rmSync8(stagingDir, { recursive: true, force: true });
11868
11919
  }
@@ -11876,7 +11927,7 @@ var LocalPlanV2ArtifactPublisher = class {
11876
11927
  }
11877
11928
  }
11878
11929
  writeFileSync9(join29(this.temporaryDir, "plan.json"), manifestBytes, "utf-8");
11879
- renameWithRetry9(this.temporaryDir, this.destinationDir);
11930
+ renameWithRetry8(this.temporaryDir, this.destinationDir);
11880
11931
  this.#committed = true;
11881
11932
  }
11882
11933
  async abort() {
@@ -12149,7 +12200,7 @@ function writeBlob(sourcePath, destinationPath) {
12149
12200
  const temporaryPath = join30(temporaryDir, "blob");
12150
12201
  try {
12151
12202
  copyFileSync8(sourcePath, temporaryPath);
12152
- renameWithRetry10(temporaryPath, destinationPath);
12203
+ renameWithRetry9(temporaryPath, destinationPath);
12153
12204
  } finally {
12154
12205
  rmSync9(temporaryDir, { recursive: true, force: true });
12155
12206
  }
@@ -12281,7 +12332,7 @@ function createPlanV2FromExecutionPlan(executionPlanDir, planV2Dir) {
12281
12332
  canonicalJsonStringify(publication.manifest),
12282
12333
  "utf-8"
12283
12334
  );
12284
- renameWithRetry10(tempDir, planV2Dir);
12335
+ renameWithRetry9(tempDir, planV2Dir);
12285
12336
  return resultFromManifest(planV2Dir, publication.manifest);
12286
12337
  } catch (error) {
12287
12338
  rmSync9(tempDir, { recursive: true, force: true });
@@ -12569,7 +12620,7 @@ function materializePlanV2Target(planV2Dir, target, destinationDir, options = {}
12569
12620
  }),
12570
12621
  "utf-8"
12571
12622
  );
12572
- renameWithRetry10(tempDir, destinationDir);
12623
+ renameWithRetry9(tempDir, destinationDir);
12573
12624
  } catch (error) {
12574
12625
  rmSync9(tempDir, { recursive: true, force: true });
12575
12626
  throw error;
@@ -12651,12 +12702,13 @@ import {
12651
12702
  readFileSync as readFileSync11,
12652
12703
  readdirSync as readdirSync8,
12653
12704
  rmSync as rmSync10,
12654
- statSync as statSync10,
12655
- writeFileSync as writeFileSync11
12705
+ statSync as statSync10
12656
12706
  } from "node:fs";
12707
+ import { localContainerInputArgs as localContainerInputArgs2 } from "@hyperframes/parsers/ff-binaries";
12657
12708
  import { basename as basename6, dirname as dirname16, join as join31 } from "node:path";
12658
12709
  import {
12659
12710
  appendRateCapArgs as appendRateCapArgs2,
12711
+ writeVideoConcatList,
12660
12712
  appendRenderProvenanceArgs as appendRenderProvenanceArgs2,
12661
12713
  concatListInputArgs,
12662
12714
  describeFfmpegFailure as describeFfmpegFailure5,
@@ -12666,7 +12718,7 @@ import {
12666
12718
  resolveConfig as resolveConfig4,
12667
12719
  runFfmpeg as runFfmpeg8,
12668
12720
  appendSoftwareEncoderThreadsArg,
12669
- renameWithRetry as renameWithRetry11
12721
+ renameWithRetry as renameWithRetry10
12670
12722
  } from "@hyperframes/engine";
12671
12723
  import { fpsToFfmpegArg as fpsToFfmpegArg3 } from "@hyperframes/core";
12672
12724
  import { createStagingDir as createStagingDir7 } from "@hyperframes/core/atomic-file";
@@ -12728,7 +12780,7 @@ async function assemble(planDir, chunkOutputs, audioPath, outputPath, options) {
12728
12780
  const finalPath = join31(workDir, `output.${format}`);
12729
12781
  const audio = audioPath !== null && existsSync22(audioPath) ? audioPath : null;
12730
12782
  await writeJoined(ctx, videoSources, audio, finalPath);
12731
- renameWithRetry11(finalPath, outputPath);
12783
+ renameWithRetry10(finalPath, outputPath);
12732
12784
  log.info("[assemble] stage timings", {
12733
12785
  ...stageMs,
12734
12786
  chunks: chunkPaths.length,
@@ -12784,7 +12836,11 @@ function readAssemblePlan(planDir, chunkPaths) {
12784
12836
  return plan;
12785
12837
  }
12786
12838
  function videoInputArgs(ctx, videoSources) {
12787
- return videoSources.length === 1 ? ["-i", videoSources[0]] : concatDemuxerInput(videoSources, ctx.workDir, ctx.fpsArg);
12839
+ return videoSources.length === 1 ? [
12840
+ ...localContainerInputArgs2(ctx.format === "webm" ? "matroska" : "mov"),
12841
+ "-i",
12842
+ videoSources[0]
12843
+ ] : ["-r", ctx.fpsArg, ...concatListInputArgs(writeVideoConcatList(ctx.workDir, videoSources))];
12788
12844
  }
12789
12845
  function cfrEncodeArgs(inputArgs, encoder, fpsArg) {
12790
12846
  const args = [
@@ -12838,8 +12894,9 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
12838
12894
  "audioMs",
12839
12895
  () => padOrTrimAudioToVideoFrameCount({
12840
12896
  videoPath: videoSources[0],
12841
- probeVideoFrameInfo: () => probeJoinedFrameInfo(videoSources, ctx.fps, ctx.signal),
12897
+ probeVideoFrameInfo: () => probeJoinedFrameInfo(videoSources, ctx),
12842
12898
  audioPath,
12899
+ audioContainer: "mov",
12843
12900
  outputPath: paddedAudioPath,
12844
12901
  signal: ctx.signal,
12845
12902
  timeoutMs: ctx.timeout
@@ -12862,6 +12919,7 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
12862
12919
  ctx.signal,
12863
12920
  {
12864
12921
  audioCodec: "aac",
12922
+ audioContainer: "mov",
12865
12923
  ffmpegProcessTimeout: ctx.timeout,
12866
12924
  videoInputArgs: videoInputArgs(ctx, videoSources)
12867
12925
  },
@@ -12872,21 +12930,16 @@ async function writeJoined(ctx, videoSources, audioPath, finalPath) {
12872
12930
  throw encoderFailureError("[assemble] audio mux failed", muxResult);
12873
12931
  }
12874
12932
  }
12875
- function concatDemuxerInput(chunkPaths, workDir, fpsArg) {
12876
- const listPath = join31(workDir, "concat-list.txt");
12877
- const body = chunkPaths.map((path) => `file '${path.replace(/'/g, "'\\''")}'`).join("\n");
12878
- writeFileSync11(listPath, `${body}
12879
- `, "utf-8");
12880
- return ["-r", fpsArg, ...concatListInputArgs(listPath)];
12881
- }
12882
- async function probeJoinedFrameInfo(videoPaths, fps, signal) {
12933
+ async function probeJoinedFrameInfo(videoPaths, ctx) {
12883
12934
  const infos = await Promise.all(
12884
- videoPaths.map((path) => defaultProbeVideoFrameInfo(path, signal))
12935
+ videoPaths.map(
12936
+ (path) => defaultProbeVideoFrameInfo(path, ctx.signal, ctx.format === "webm" ? "matroska" : "mov")
12937
+ )
12885
12938
  );
12886
12939
  return {
12887
12940
  frameCount: infos.reduce((sum2, info) => sum2 + info.frameCount, 0),
12888
- fpsNum: fps.num,
12889
- fpsDen: fps.den
12941
+ fpsNum: ctx.fps.num,
12942
+ fpsDen: ctx.fps.den
12890
12943
  };
12891
12944
  }
12892
12945
  async function runAssembleFfmpeg(args, step, signal, timeout) {
@@ -12983,7 +13036,7 @@ function mergePngFrameDirs(chunkPaths, outputPath, totalFrames, audioPath, start
12983
13036
 
12984
13037
  // src/services/distributed/renderChunk.ts
12985
13038
  import { randomBytes } from "node:crypto";
12986
- import { existsSync as existsSync23, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync12 } from "node:fs";
13039
+ import { existsSync as existsSync23, mkdirSync as mkdirSync14, readFileSync as readFileSync12, readdirSync as readdirSync9, rmSync as rmSync11, writeFileSync as writeFileSync11 } from "node:fs";
12987
13040
  import { join as join32 } from "node:path";
12988
13041
  import {
12989
13042
  assertSwiftShader,
@@ -13666,7 +13719,7 @@ async function renderChunk(planDir, chunkIndex, outputChunkPath, options) {
13666
13719
  producerVersion: plan.producerVersion,
13667
13720
  ffmpegVersion
13668
13721
  };
13669
- writeFileSync12(perfPath, `${JSON.stringify(perfPayload, null, 2)}
13722
+ writeFileSync11(perfPath, `${JSON.stringify(perfPayload, null, 2)}
13670
13723
  `, "utf-8");
13671
13724
  try {
13672
13725
  rmSync11(workDir, { recursive: true, force: true, maxRetries: 3, retryDelay: 100 });
@@ -14153,7 +14206,7 @@ var isMissing = (result) => result.error?.code === "ENOENT";
14153
14206
  var ffmpegIsMissing = async (signal) => isMissing(await runFfmpeg9(["-version"], { signal }));
14154
14207
 
14155
14208
  // src/services/distributed/probeFacts.ts
14156
- import { writeFileSync as writeFileSync13 } from "node:fs";
14209
+ import { writeFileSync as writeFileSync12 } from "node:fs";
14157
14210
  import { extname as extname6 } from "node:path";
14158
14211
  import { buildProbeFactsText } from "@hyperframes/engine";
14159
14212
  var PROBE_FACTS_EXTENSIONS = /* @__PURE__ */ new Set([".mp4", ".mov", ".m4v", ".webm", ".mkv"]);
@@ -14162,7 +14215,7 @@ function wantsProbeFacts(path) {
14162
14215
  }
14163
14216
  async function buildProbeFacts(inputPath, outputPath, signal) {
14164
14217
  try {
14165
- writeFileSync13(outputPath, await buildProbeFactsText(inputPath, signal));
14218
+ writeFileSync12(outputPath, await buildProbeFactsText(inputPath, signal));
14166
14219
  return "built";
14167
14220
  } catch (error) {
14168
14221
  if (signal?.aborted) throw error;
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": "0.1.0",
3
3
  "buildId": "dev",
4
- "sha256": "b80e7f680f11ef0b2095d559d0709e1f1a606424fd7ea3efc0f778222f183615",
4
+ "sha256": "279f068486724f733989369acb37a7104f934da40f7c305067f51dcef4be881e",
5
5
  "artifacts": {
6
6
  "iife": "hyperframe.runtime.iife.js",
7
7
  "esm": "hyperframe.runtime.mjs"