@hyperframes/studio-server 0.9.0 → 0.9.2

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.
@@ -24,7 +24,7 @@ import {
24
24
  utimesSync,
25
25
  writeFileSync as writeFileSync2
26
26
  } from "fs";
27
- import { availableParallelism, tmpdir, totalmem } from "os";
27
+ import os, { availableParallelism, tmpdir, totalmem } from "os";
28
28
  import { basename as basename3, dirname as dirname3, extname as extname4, isAbsolute, join as join4, relative, resolve, sep } from "path";
29
29
  import { hdrToSdrToneMapFilter } from "@hyperframes/core";
30
30
  import { findFfBinary } from "@hyperframes/parsers/ff-binaries";
@@ -317,6 +317,7 @@ function boundedEnvInteger(name, fallback, min, max) {
317
317
  return Number.isSafeInteger(parsed) && parsed >= min && parsed <= max ? parsed : fallback;
318
318
  }
319
319
  var MAX_CONCURRENT_TRANSCODES = boundedEnvInteger("HYPERFRAMES_PROXY_MAX_CONCURRENCY", 2, 1, 16);
320
+ var BACKGROUND_NICENESS = 19;
320
321
  var MAX_QUEUED_TRANSCODES = boundedEnvInteger("HYPERFRAMES_PROXY_MAX_QUEUE", 8, 0, 256);
321
322
  var STDERR_TAIL_MAX_CHARS = 4e3;
322
323
  var TRANSCODE_STALL_MS = boundedEnvInteger(
@@ -754,7 +755,7 @@ async function buildVideoFilter(ffmpegPath, sourcePath, metadata, keepsAlpha, bo
754
755
  `format=${pixelFormat}`
755
756
  ].join(",") : [evenScale, `format=${pixelFormat}`].join(",");
756
757
  }
757
- async function runFfmpeg(sourcePath, outputPath, chunkPrefix, variant, box, signal, onProgress) {
758
+ async function runFfmpeg(sourcePath, outputPath, chunkPrefix, variant, box, signal, onProgress, isBackground = () => false) {
758
759
  const metadata = await probeMediaMetadata(sourcePath);
759
760
  const ffmpegPath = findFfBinary("ffmpeg", { configuredMustExist: true });
760
761
  if (!ffmpegPath) {
@@ -795,7 +796,8 @@ async function runFfmpeg(sourcePath, outputPath, chunkPrefix, variant, box, sign
795
796
  ],
796
797
  TRANSCODE_STALL_MS,
797
798
  pieceSignal,
798
- onEncoded
799
+ onEncoded,
800
+ isBackground()
799
801
  );
800
802
  const ranges = chunkRanges(totalSeconds);
801
803
  try {
@@ -837,7 +839,14 @@ function concatArgs(listPath, target, variant) {
837
839
  ];
838
840
  }
839
841
  var OUT_TIME = /^out_time_(?:us|ms)=(\d+)$/;
840
- function spawnFfmpeg(ffmpegPath, args, stallMs, signal, onProgress) {
842
+ function lowerPriorityUnlessExited(pid) {
843
+ try {
844
+ os.setPriority(pid, BACKGROUND_NICENESS);
845
+ } catch {
846
+ return;
847
+ }
848
+ }
849
+ function spawnFfmpeg(ffmpegPath, args, stallMs, signal, onProgress, background = false) {
841
850
  return new Promise((resolvePromise, reject) => {
842
851
  signal.throwIfAborted();
843
852
  const proc = spawn(ffmpegPath, args, {
@@ -846,6 +855,7 @@ function spawnFfmpeg(ffmpegPath, args, stallMs, signal, onProgress) {
846
855
  signal,
847
856
  windowsHide: true
848
857
  });
858
+ if (background && proc.pid !== void 0) lowerPriorityUnlessExited(proc.pid);
849
859
  let stalled = false;
850
860
  let timer;
851
861
  const armStall = () => {
@@ -951,7 +961,8 @@ async function transcodeToCache(job, projectDir, absoluteSourcePath, cachePath,
951
961
  variant,
952
962
  box,
953
963
  job.abandoned.signal,
954
- (progress) => reportProgress(job, progress)
964
+ (progress) => reportProgress(job, progress),
965
+ () => job.background && !job.priority
955
966
  );
956
967
  renameSync(tempPath, cachePath);
957
968
  writeCopyIndex(contentIndex, cachePath);
@@ -1004,6 +1015,7 @@ async function resolveProxy(projectDir, absoluteSourcePath, variant = "h264", bo
1004
1015
  const job = {
1005
1016
  cachePath,
1006
1017
  priority: options.priority === true,
1018
+ background: options.background === true,
1007
1019
  callers: 0,
1008
1020
  abandoned: new AbortController(),
1009
1021
  progress: /* @__PURE__ */ new Set()
@@ -1,7 +1,7 @@
1
1
  import {
2
2
  PROXY_PARAMS_VERSION,
3
3
  resolveProxy
4
- } from "./chunk-G4VPDLXC.js";
4
+ } from "./chunk-CEQWOCYI.js";
5
5
  import {
6
6
  createMediaCodecProbeCache,
7
7
  proxyVariantFor,
@@ -4,8 +4,8 @@ import {
4
4
  isAutoProxyEnabled,
5
5
  proxyEtagSalt,
6
6
  resolvePreviewMediaCodecProbeCache
7
- } from "../chunk-JVMMZB22.js";
8
- import "../chunk-G4VPDLXC.js";
7
+ } from "../chunk-PN2VGFAA.js";
8
+ import "../chunk-CEQWOCYI.js";
9
9
  import "../chunk-FUTDRYQK.js";
10
10
  import "../chunk-X73QTST2.js";
11
11
  import "../chunk-QF7MFJJU.js";
@@ -89,6 +89,7 @@ declare function resolveProxies(projectDir: string, sources: ReadonlyArray<{
89
89
  }>, onSettled?: (index: number) => void, onProgress?: (index: number, progress: ProxyProgress) => void, signal?: AbortSignal): Promise<PromiseSettledResult<string>[]>;
90
90
  interface ResolveProxyOptions {
91
91
  priority?: boolean;
92
+ background?: boolean;
92
93
  signal?: AbortSignal;
93
94
  /** Hears how far the shared copy has got, from the first caller's start to the copy's end. */
94
95
  onProgress?: (progress: ProxyProgress) => void;
@@ -20,7 +20,7 @@ import {
20
20
  retryProxyCopy,
21
21
  sourceFolderKind,
22
22
  waitForProxy
23
- } from "../chunk-G4VPDLXC.js";
23
+ } from "../chunk-CEQWOCYI.js";
24
24
  import "../chunk-FUTDRYQK.js";
25
25
  import "../chunk-X73QTST2.js";
26
26
  import "../chunk-QF7MFJJU.js";
package/dist/index.js CHANGED
@@ -86,7 +86,7 @@ import {
86
86
  isAutoProxyEnabled,
87
87
  proxyEtagSalt,
88
88
  resolvePreviewMediaCodecProbeCache
89
- } from "./chunk-JVMMZB22.js";
89
+ } from "./chunk-PN2VGFAA.js";
90
90
  import {
91
91
  CACHE_DIR_NAME,
92
92
  PROXY_PENDING_RETRY_AFTER_SECONDS,
@@ -99,7 +99,7 @@ import {
99
99
  resolveProxy,
100
100
  retryProxyCopy,
101
101
  waitForProxy
102
- } from "./chunk-G4VPDLXC.js";
102
+ } from "./chunk-CEQWOCYI.js";
103
103
  import {
104
104
  PROXY_VARIANT_CONFIG,
105
105
  decideMediaProxyEligibility,
@@ -4635,9 +4635,10 @@ ${etag}`;
4635
4635
  if (c.req.query(PREVIEW_PROXY_RETRY_PARAM) !== void 0) {
4636
4636
  retryProxyCopy(project.dir, file, proxyVariant, proxyBox);
4637
4637
  }
4638
- const priority = c.req.header(PREVIEW_PROXY_PRIORITY_HEADER) === "1";
4638
+ const asked = c.req.header(PREVIEW_PROXY_PRIORITY_HEADER);
4639
+ const urgency = asked === "0" ? { background: true } : { priority: asked === "1" };
4639
4640
  servedPath = await waitForProxy(
4640
- resolveProxy(project.dir, file, proxyVariant, proxyBox, { priority }),
4641
+ resolveProxy(project.dir, file, proxyVariant, proxyBox, urgency),
4641
4642
  0
4642
4643
  );
4643
4644
  } catch (err) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@hyperframes/studio-server",
3
- "version": "0.9.0",
3
+ "version": "0.9.2",
4
4
  "repository": {
5
5
  "type": "git",
6
6
  "url": "https://github.com/heygen-com/hyperframes",
@@ -84,8 +84,8 @@
84
84
  "linkedom": "^0.18.12",
85
85
  "postcss": "^8.5.8",
86
86
  "postcss-selector-parser": "^7.1.2",
87
- "@hyperframes/core": "0.9.0",
88
- "@hyperframes/parsers": "0.9.0"
87
+ "@hyperframes/core": "0.9.2",
88
+ "@hyperframes/parsers": "0.9.2"
89
89
  },
90
90
  "devDependencies": {
91
91
  "@types/node": "^25.0.10",