@torrent-tv/proxy 2.45.0 → 2.46.0

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/CHANGELOG.md CHANGED
@@ -1,3 +1,9 @@
1
+ ## 2.46.0
2
+
3
+ - **New**: The cost of DECODING is measured per codec family, not once on H.264. A video that has to be re-encoded is by definition one the browser could not play — HEVC, 10-bit — so the one model the host had was fitted on the codec it is least often asked about, and those decode dearer per pixel on the same box. There are now sets for HEVC 8-bit and HEVC Main 10 beside the H.264 one (`assets/calibration/`, four clips each: two sizes at two bitrates, the smallest grid that keeps the axes independent and still leaves a spare), the source's own codec and bit depth choose the constants, and a family with no set of its own is priced as H.264 — said in the log rather than left to be inferred. Measured on a desktop 2026-08-20, the same 1080p picture at ~5.8 Mbit/s: 7.7x as 8-bit HEVC against 6.3x as 10-bit, which is why ten bits is its own family and not a multiplier. AV1 has no set yet; the release survey of 2026-07-10 found it rare where HEVC was 18 %.
4
+ - **New**: The video's bit depth is read from the probe (`parseFfmpegBitDepth`), and it travels with the source's pixel and bit rates because it decides which measurement of this host applies.
5
+ - **Chore**: When the H.264 clips do not fit, the line now says which families did. Measured on a fast desktop the same day, the H.264 readings stopped being ordered — 1080p at 9.35 Mbit/s costing 0.0307 s/s against 720p at 9.94 costing 0.0472, which is not a thing a decoder does — so a failure there is a measurement problem and not a missing file, and the two have to be tellable apart.
6
+
1
7
  ## 2.45.0
2
8
 
3
9
  - **Fix**: A run is cut where the PLAYER was told the cuts are. There are two boundary tables — the live one, corrected as produced segments reveal where the file's cuts truly are, and the one the playlist text was written from — and a player places every fragment by the text it holds, which never changes. The cut list handed to ffmpeg came from the live table, so every correction moved the run away from the timeline the player is reading: measured 2026-08-20 on `Minions.and.Monsters.1080p.mkv`, 119 of 125 produced segments arrived a uniform 2.002 s before the times their playlist named, against the 0.5 s hls.js bridges, and a fragment that does not land is fetched again — on 2026-08-17 two of them 1908 times each. A seek is resolved on the same table for the same reason: the time being resolved came out of that playlist. The corrections keep their purpose, which is to describe the FILE — a variant created later inherits the corrected table and publishes it, so its own playlist and its own cuts agree from the start — but they may no longer move the cuts of a session already being read.
@@ -58,6 +58,43 @@ ffmpeg's own output rather than from this table. Two rules hold, though:
58
58
  - **the axes stay independent** — every size at both bitrates. Dropping one cell
59
59
  reintroduces the collinearity that produced the zeros above.
60
60
 
61
- Codecs other than H.264 (HEVC, AV1, 10-bit) decode dearer per pixel, and the
62
- model fitted here does not describe them. Covering them means a set per codec
63
- family and constants chosen by the source's own codec roadmap item 3(b).
61
+ ## One set per codec family
62
+
63
+ A video that has to be RE-ENCODED is by definition one the browser could not
64
+ play, which is to say HEVC, 10-bit or AV1 — so the model was fitted on the one
65
+ codec it is least often asked about. There is now a set per family, and the
66
+ source's own codec chooses the constants.
67
+
68
+ | file | codec | resolution | bitrate |
69
+ |---|---|---|---|
70
+ | `cal-hevc-1080-hi.mp4` | HEVC Main, 8-bit | 1920×1080 | 5.78 Mbit/s |
71
+ | `cal-hevc-1080-lo.mp4` | HEVC Main, 8-bit | 1920×1080 | 0.52 Mbit/s |
72
+ | `cal-hevc-480-hi.mp4` | HEVC Main, 8-bit | 854×480 | 7.76 Mbit/s |
73
+ | `cal-hevc-480-lo.mp4` | HEVC Main, 8-bit | 854×480 | 0.74 Mbit/s |
74
+ | `cal-hevc10-1080-hi.mp4` | HEVC Main 10 | 1920×1080 | 5.82 Mbit/s |
75
+ | `cal-hevc10-1080-lo.mp4` | HEVC Main 10 | 1920×1080 | 0.52 Mbit/s |
76
+ | `cal-hevc10-480-hi.mp4` | HEVC Main 10 | 854×480 | 6.95 Mbit/s |
77
+ | `cal-hevc10-480-lo.mp4` | HEVC Main 10 | 854×480 | 0.68 Mbit/s |
78
+
79
+ Four per family, not six: two sizes at two bitrates is the smallest grid that
80
+ keeps the axes independent and still leaves one spare measurement, and every
81
+ clip costs the startup about two seconds. They are one second long rather than
82
+ two — the benchmark loops the clip and measures a slope over about a second of
83
+ decoding, so length beyond that buys nothing and only makes the package larger.
84
+
85
+ They were cut from `cal-h264-1080-hi.mp4` rather than from the 4K master, which
86
+ is not in this repository. Re-encoding an already-compressed picture softens its
87
+ grain slightly; what is being measured is the cost of decoding the new
88
+ bitstream, and the grain that survives is the same material in every set, which
89
+ is what makes the families comparable to each other.
90
+
91
+ 10-bit is its own family rather than a multiplier on the 8-bit one. Wider
92
+ samples mean wider arithmetic, and how much that costs is a property of the
93
+ machine — which is the thing being measured. Measured on a desktop 2026-08-20,
94
+ 1080p at ~5.8 Mbit/s: 7.7x as 8-bit HEVC and 6.3x as 10-bit, so it is a real
95
+ difference and not a rounding.
96
+
97
+ AV1 has no set yet. The release survey of 2026-07-10 found it rare where HEVC
98
+ was 18 %, so it is priced as H.264 until it is worth the startup seconds — and
99
+ the log says which families were measured and which are falling back, rather
100
+ than leaving it to be inferred.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@torrent-tv/proxy",
3
- "version": "2.45.0",
3
+ "version": "2.46.0",
4
4
  "description": "Torrent proxy client that exposes webseed-like HTTP stream endpoint.",
5
5
  "license": "GPL-3.0-or-later",
6
6
  "publishConfig": {
@@ -315,17 +315,49 @@ function invert(matrix) {
315
315
  return work.map((row) => row.slice(size));
316
316
  }
317
317
 
318
+ /**
319
+ * Which measured family prices a source of this codec and depth.
320
+ *
321
+ * The families are the ones there are clips for. Anything else is priced as
322
+ * H.264 — not because it decodes like H.264, but because that is the only
323
+ * measurement of this host there is, and saying so in one place beats each
324
+ * caller inventing its own fallback.
325
+ *
326
+ * 10-bit is its own family rather than a multiplier on the 8-bit one: the
327
+ * samples are wider, the arithmetic is wider, and how much that costs is a
328
+ * property of the machine, which is what is being measured.
329
+ *
330
+ * @param {{ codec?: string | null, bitDepth?: number | null }} source
331
+ * @returns {string}
332
+ */
333
+ export function decodeFamilyOf(source) {
334
+ const codec = typeof source?.codec === "string" ? source.codec.trim().toLowerCase() : "";
335
+ const depth = Number(source?.bitDepth);
336
+ const tenBit = Number.isFinite(depth) && depth >= 10;
337
+ if (codec === "hevc" || codec === "h265" || codec === "x265") {
338
+ return tenBit ? "hevc10" : "hevc";
339
+ }
340
+ return "h264";
341
+ }
342
+
318
343
  /**
319
344
  * What a model prices one source at.
320
345
  *
321
- * @param {DecodeCostModel} model
322
- * @param {{ megapixelsPerSecond: number, megabitsPerSecond: number }} source
346
+ * The model may carry a set of per-family fits (`families`) alongside the H.264
347
+ * terms it also spreads at the top level, which is what a caller that knows
348
+ * nothing about codecs still reads. When the source names a codec and that
349
+ * family was measured, its own constants are used.
350
+ *
351
+ * @param {DecodeCostModel & { families?: Record<string, DecodeCostModel> }} model
352
+ * @param {{ megapixelsPerSecond: number, megabitsPerSecond: number, codec?: string | null, bitDepth?: number | null }} source
323
353
  * @returns {number} Seconds of work per second of content.
324
354
  */
325
355
  export function decodeCostOf(model, source) {
356
+ const family = decodeFamilyOf(source);
357
+ const terms = model?.families?.[family] ?? model;
326
358
  return (
327
- model.pixelTerm * source.megapixelsPerSecond +
328
- model.bitrateTerm * source.megabitsPerSecond +
329
- model.constantTerm
359
+ terms.pixelTerm * source.megapixelsPerSecond +
360
+ terms.bitrateTerm * source.megabitsPerSecond +
361
+ terms.constantTerm
330
362
  );
331
363
  }
@@ -165,3 +165,48 @@ export function parseFfmpegHdr(stderrText) {
165
165
  // the reliable HDR signal.
166
166
  return /\b(smpte2084|arib-std-b67|arib_std_b67)\b/i.test(videoLine[0]);
167
167
  }
168
+
169
+ /**
170
+ * How many bits per sample the video carries, from the pixel format ffmpeg
171
+ * prints on its `Video:` line.
172
+ *
173
+ * This is a decode-cost input, not a colour one: a 10-bit stream holds wider
174
+ * samples and is decoded with wider arithmetic, and how much that costs is a
175
+ * property of the machine. It is therefore its own calibration family rather
176
+ * than a multiplier on the 8-bit one.
177
+ *
178
+ * ffmpeg names the depth in the format itself — `yuv420p10le`, `yuv420p12le`,
179
+ * `p010le` — and omits it at 8 bits (`yuv420p`, `nv12`). An unreadable line
180
+ * gives null, and the caller then prices the source as 8-bit, which is what
181
+ * every source was priced as before this existed.
182
+ *
183
+ * @param {string} stderrText
184
+ * @returns {number | null}
185
+ */
186
+ export function parseFfmpegBitDepth(stderrText) {
187
+ if (typeof stderrText !== "string" || stderrText.length === 0) {
188
+ return null;
189
+ }
190
+ const videoLine = stderrText.match(/Video:[^\n]*/i);
191
+ if (!videoLine) {
192
+ return null;
193
+ }
194
+ // The pixel format is the token after the codec and its tag, and the depth
195
+ // rides on its name. `p010`/`p016` are the two that state it without a `p`
196
+ // separator, and they are 10 and 16 bits.
197
+ const named = videoLine[0].match(/\byuv[a-z0-9]*?p(\d{1,2})(?:le|be)\b/i);
198
+ if (named) {
199
+ const depth = Number(named[1]);
200
+ return Number.isFinite(depth) && depth >= 8 ? depth : null;
201
+ }
202
+ if (/\bp010(?:le|be)?\b/i.test(videoLine[0])) {
203
+ return 10;
204
+ }
205
+ if (/\bp016(?:le|be)?\b/i.test(videoLine[0])) {
206
+ return 16;
207
+ }
208
+ if (/\byuv[a-z0-9]*p\b|\bnv12\b|\bnv21\b|\bgbrp\b/i.test(videoLine[0])) {
209
+ return 8;
210
+ }
211
+ return null;
212
+ }
@@ -180,8 +180,13 @@ export function variantHeightsFor(sourceHeight) {
180
180
  * Returns null when the probe did not report enough — the budget then prices
181
181
  * the encoder alone rather than inventing a figure.
182
182
  *
183
- * @param {{ width: number | null, height: number | null, fps: number | null, bitrateKbps: number | null }} mediaInfo
184
- * @returns {{ megapixelsPerSecond: number, megabitsPerSecond: number } | null}
183
+ * The codec and bit depth travel with the rates because they decide WHICH
184
+ * measurement of this host applies: the model is fitted per codec family, and a
185
+ * video that has to be re-encoded is by definition one the browser could not
186
+ * play — HEVC, 10-bit — which is exactly where H.264 constants are wrong.
187
+ *
188
+ * @param {{ width: number | null, height: number | null, fps: number | null, bitrateKbps: number | null, codec?: string | null, bitDepth?: number | null }} mediaInfo
189
+ * @returns {{ megapixelsPerSecond: number, megabitsPerSecond: number, codec: string, bitDepth: number | null } | null}
185
190
  */
186
191
  export function sourceDecodeCharacteristics(mediaInfo) {
187
192
  const width = Number(mediaInfo?.width);
@@ -191,9 +196,12 @@ export function sourceDecodeCharacteristics(mediaInfo) {
191
196
  if (!(width > 0) || !(height > 0) || !(fps > 0) || !(kbps > 0)) {
192
197
  return null;
193
198
  }
199
+ const depth = Number(mediaInfo?.bitDepth);
194
200
  return {
195
201
  megapixelsPerSecond: (width * height * fps) / 1e6,
196
- megabitsPerSecond: kbps / 1000
202
+ megabitsPerSecond: kbps / 1000,
203
+ codec: typeof mediaInfo?.codec === "string" ? mediaInfo.codec : "",
204
+ bitDepth: Number.isFinite(depth) && depth > 0 ? depth : null
197
205
  };
198
206
  }
199
207
 
@@ -683,14 +683,41 @@ export async function detectTonemapSupport({ ffmpegBin, logger }) {
683
683
  // optimistic. Six points leave three spare, so the fit has a residual, and a
684
684
  // term the data does not determine can be refused instead of published as a
685
685
  // zero that looks measured. See `assets/calibration/NOTICE.md`.
686
- const CALIBRATION_CLIPS = [
687
- "cal-h264-1080-hi.mp4",
688
- "cal-h264-1080-lo.mp4",
689
- "cal-h264-720-hi.mp4",
690
- "cal-h264-720-lo.mp4",
691
- "cal-h264-480-hi.mp4",
692
- "cal-h264-480-lo.mp4"
693
- ];
686
+ //
687
+ // One set PER CODEC FAMILY, because a family is what the model describes. The
688
+ // fit used to be H.264 only, while a video that has to be RE-ENCODED is by
689
+ // definition one the browser could not play — which is to say HEVC, 10-bit or
690
+ // AV1 — and those decode dearer per pixel on the same box. Pricing them with
691
+ // H.264 constants is the one case the model is always asked about and was never
692
+ // measured on.
693
+ //
694
+ // A family that has no set of its own is priced with H.264's, which is what
695
+ // happened to every family before this; the line says so rather than implying
696
+ // it. AV1 has no set yet: the survey of 2026-07-10 found it rare where HEVC was
697
+ // 18 % of releases, so it waits for the same treatment.
698
+ const CALIBRATION_SETS = {
699
+ h264: [
700
+ "cal-h264-1080-hi.mp4",
701
+ "cal-h264-1080-lo.mp4",
702
+ "cal-h264-720-hi.mp4",
703
+ "cal-h264-720-lo.mp4",
704
+ "cal-h264-480-hi.mp4",
705
+ "cal-h264-480-lo.mp4"
706
+ ],
707
+ hevc: [
708
+ "cal-hevc-1080-hi.mp4",
709
+ "cal-hevc-1080-lo.mp4",
710
+ "cal-hevc-480-hi.mp4",
711
+ "cal-hevc-480-lo.mp4"
712
+ ],
713
+ hevc10: [
714
+ "cal-hevc10-1080-hi.mp4",
715
+ "cal-hevc10-1080-lo.mp4",
716
+ "cal-hevc10-480-hi.mp4",
717
+ "cal-hevc10-480-lo.mp4"
718
+ ]
719
+ };
720
+ const CALIBRATION_CLIPS = CALIBRATION_SETS.h264;
694
721
  const CALIBRATION_DIR = path.join(path.dirname(fileURLToPath(import.meta.url)), "..", "assets", "calibration");
695
722
  // How wide the measured window must be before the slope is trusted, and how
696
723
  // long to wait for it at most. A second of decoding is thousands of frames on a
@@ -833,13 +860,54 @@ export async function benchmarkContention({ ffmpegBin, logger, clipsDir = CALIBR
833
860
 
834
861
  export async function benchmarkDecodeCost({ ffmpegBin, logger, clipsDir = CALIBRATION_DIR }) {
835
862
  const log = logger ?? { info: () => {}, warn: () => {} };
863
+ const startedAllAt = Date.now();
864
+ /** @type {Record<string, { pixelTerm: number, bitrateTerm: number, constantTerm: number }>} */
865
+ const families = {};
866
+ for (const [family, clips] of Object.entries(CALIBRATION_SETS)) {
867
+ const fitted = await fitOneFamily({ ffmpegBin, log, clipsDir, family, clips });
868
+ if (fitted) {
869
+ families[family] = fitted;
870
+ }
871
+ }
872
+ if (!families.h264) {
873
+ // H.264 is the family every other one falls back to, so without it there is
874
+ // no model at all rather than a partial one. Which families DID fit is said
875
+ // anyway: on a fast host the H.264 clips decode at 20-80x and the readings
876
+ // stop being ordered — measured 2026-08-20 on a desktop, 1080p at 9.35
877
+ // Mbit/s costing 0.0307 s/s against 720p at 9.94 costing 0.0472, which is
878
+ // not a thing a decoder does — so a failure here is a measurement problem
879
+ // and not a missing file, and the line has to let those be told apart.
880
+ log.warn(
881
+ "hwaccel: decode cost unknown — the H.264 clips did not fit" +
882
+ (Object.keys(families).length > 0
883
+ ? `, though ${Object.keys(families).join(" and ")} did`
884
+ : "")
885
+ );
886
+ return null;
887
+ }
888
+ const missing = Object.keys(CALIBRATION_SETS).filter((family) => !families[family]);
889
+ log.info(
890
+ `hwaccel: decode cost measured for ${Object.keys(families).join(", ")}` +
891
+ (missing.length > 0 ? `; ${missing.join(" and ")} priced as H.264` : "") +
892
+ ` (in ${((Date.now() - startedAllAt) / 1000).toFixed(1)}s)`
893
+ );
894
+ return { families, ...families.h264 };
895
+ }
896
+
897
+ /**
898
+ * Fit one codec family's decode cost from its own clips.
899
+ *
900
+ * @param {{ ffmpegBin: string, log: { info: Function, warn: Function }, clipsDir: string, family: string, clips: string[] }} params
901
+ * @returns {Promise<{ pixelTerm: number, bitrateTerm: number, constantTerm: number } | null>}
902
+ */
903
+ async function fitOneFamily({ ffmpegBin, log, clipsDir, family, clips }) {
836
904
  const startedAllAt = Date.now();
837
905
  /** @type {Array<{ megapixelsPerSecond: number, megabitsPerSecond: number, costSecondsPerSecond: number }>} */
838
906
  const samples = [];
839
- for (const clip of CALIBRATION_CLIPS) {
907
+ for (const clip of clips) {
840
908
  const measured = await measureDecodeSlope(ffmpegBin, path.join(clipsDir, clip));
841
909
  if (!measured) {
842
- log.warn(`hwaccel: decode benchmark "${clip}" failed or said nothing; decode cost unknown`);
910
+ log.warn(`hwaccel: decode benchmark "${clip}" failed or said nothing; ${family} not measured`);
843
911
  return null;
844
912
  }
845
913
  const cost = 1 / measured.speed;
@@ -856,11 +924,11 @@ export async function benchmarkDecodeCost({ ffmpegBin, logger, clipsDir = CALIBR
856
924
  }
857
925
  const fitted = fitDecodeCost(samples);
858
926
  if (!fitted) {
859
- log.warn("hwaccel: decode cost could not be fitted to these measurements; decode cost unknown");
927
+ log.warn(`hwaccel: ${family} decode cost could not be fitted to these measurements`);
860
928
  return null;
861
929
  }
862
930
  log.info(
863
- `hwaccel: decode cost = ${fitted.pixelTerm.toFixed(6)} × Mpx/s + ${fitted.bitrateTerm.toFixed(6)} × Mbit/s ` +
931
+ `hwaccel: ${family} decode cost = ${fitted.pixelTerm.toFixed(6)} × Mpx/s + ${fitted.bitrateTerm.toFixed(6)} × Mbit/s ` +
864
932
  `+ ${fitted.constantTerm.toFixed(4)} s/s (${fitted.shape} from ${fitted.samples} clips, ` +
865
933
  `typical disagreement ${fitted.residualRms.toFixed(4)} s/s` +
866
934
  // Named rather than implied: a zero in the line above means "not
@@ -13,6 +13,7 @@ import {
13
13
  parseFfmpegDurationSeconds,
14
14
  parseFfmpegStartTimeSeconds,
15
15
  parseFfmpegVideoDimensions,
16
+ parseFfmpegBitDepth,
16
17
  parseFfmpegBitrateKbps,
17
18
  parseFfmpegVideoFps,
18
19
  parseFfmpegHdr
@@ -534,6 +535,11 @@ export function createPlaybackPlanner({
534
535
  height: videoHeight,
535
536
  fps: parseFfmpegVideoFps(probe.stderr),
536
537
  bitrateKbps: parseFfmpegBitrateKbps(probe.stderr),
538
+ // Which family of the decode measurement prices this source. A video
539
+ // that has to be re-encoded is one the browser could not play, so it
540
+ // is usually NOT H.264, and H.264 constants are wrong for it.
541
+ codec: videoCodec,
542
+ bitDepth: parseFfmpegBitDepth(probe.stderr),
537
543
  // Which file this is, so the offer can be answered from what an
538
544
  // encoder has already learned about THIS source rather than from the
539
545
  // startup clips — the same correction a live session applies.
@@ -569,7 +575,8 @@ export function createPlaybackPlanner({
569
575
  bitrateKbps: parseFfmpegBitrateKbps(probe.stderr),
570
576
  fps: parseFfmpegVideoFps(probe.stderr),
571
577
  startTime: parseFfmpegStartTimeSeconds(probe.stderr),
572
- isHdr: parseFfmpegHdr(probe.stderr)
578
+ isHdr: parseFfmpegHdr(probe.stderr),
579
+ bitDepth: parseFfmpegBitDepth(probe.stderr)
573
580
  });
574
581
  // Warm the file-body start for the transcode session that follows.
575
582
  // Fire-and-forget: never delays the plan response.
@@ -17,6 +17,7 @@ import assert from "node:assert/strict";
17
17
  import { createRequire } from "node:module";
18
18
  import { spawn } from "node:child_process";
19
19
  import { mkdtemp, rm } from "node:fs/promises";
20
+ import { decodeCostOf, decodeFamilyOf } from "../services/decode-cost-fit.js";
20
21
  import os from "node:os";
21
22
  import path from "node:path";
22
23
  import {
@@ -282,8 +283,22 @@ test("a banner with no bitrate reads as no bitrate, not as zero", () => {
282
283
  test("the source's decode figures come off the probe, or not at all", () => {
283
284
  assert.deepEqual(sourceDecodeCharacteristics({ width: 1920, height: 1080, fps: 24, bitrateKbps: 8000 }), {
284
285
  megapixelsPerSecond: (1920 * 1080 * 24) / 1e6,
285
- megabitsPerSecond: 8
286
+ megabitsPerSecond: 8,
287
+ // Which measurement of this host applies. Absent on the probe means absent
288
+ // here — the caller then prices the source as H.264 8-bit, which is what
289
+ // every source was priced as before the model was fitted per family.
290
+ codec: "",
291
+ bitDepth: null
286
292
  });
293
+ assert.deepEqual(
294
+ sourceDecodeCharacteristics({ width: 1920, height: 1080, fps: 24, bitrateKbps: 8000, codec: "hevc", bitDepth: 10 }),
295
+ {
296
+ megapixelsPerSecond: (1920 * 1080 * 24) / 1e6,
297
+ megabitsPerSecond: 8,
298
+ codec: "hevc",
299
+ bitDepth: 10
300
+ }
301
+ );
287
302
  assert.equal(sourceDecodeCharacteristics({ width: 1920, height: 1080, fps: 24, bitrateKbps: null }), null);
288
303
  assert.equal(sourceDecodeCharacteristics(null), null);
289
304
  });
@@ -391,3 +406,52 @@ test("the OFFER drops the rungs the host cannot hold, and the master keeps addre
391
406
  "the copied height costs no encoder and stays; nothing re-encoded survives that supply"
392
407
  );
393
408
  });
409
+
410
+ test("a source is priced by its own codec family when that family was measured", () => {
411
+ // A model as the startup benchmark now returns it: H.264 terms at the top
412
+ // level, for a caller that knows nothing about codecs, and the measured
413
+ // families beside them.
414
+ const model = {
415
+ pixelTerm: 0.006, bitrateTerm: 0.012, constantTerm: 0,
416
+ families: {
417
+ h264: { pixelTerm: 0.006, bitrateTerm: 0.012, constantTerm: 0 },
418
+ hevc: { pixelTerm: 0.011, bitrateTerm: 0.020, constantTerm: 0 },
419
+ hevc10: { pixelTerm: 0.017, bitrateTerm: 0.026, constantTerm: 0 }
420
+ }
421
+ };
422
+ const rates = { megapixelsPerSecond: 50, megabitsPerSecond: 9 };
423
+ const asH264 = decodeCostOf(model, { ...rates, codec: "h264", bitDepth: 8 });
424
+ const asHevc = decodeCostOf(model, { ...rates, codec: "hevc", bitDepth: 8 });
425
+ const asHevc10 = decodeCostOf(model, { ...rates, codec: "hevc", bitDepth: 10 });
426
+ assert.equal(Number(asH264.toFixed(4)), 0.408);
427
+ assert.equal(Number(asHevc.toFixed(4)), 0.73);
428
+ assert.equal(Number(asHevc10.toFixed(4)), 1.084);
429
+ // The whole point: the same file costs more as HEVC than as H.264, and more
430
+ // again at ten bits. A single fit could not say that.
431
+ assert.ok(asHevc > asH264 && asHevc10 > asHevc);
432
+ });
433
+
434
+ test("a family with no clips is priced as H.264, and a model with no families still works", () => {
435
+ const withFamilies = {
436
+ pixelTerm: 0.006, bitrateTerm: 0.012, constantTerm: 0,
437
+ families: { h264: { pixelTerm: 0.006, bitrateTerm: 0.012, constantTerm: 0 } }
438
+ };
439
+ const rates = { megapixelsPerSecond: 50, megabitsPerSecond: 9 };
440
+ // AV1 has no set of its own yet.
441
+ assert.equal(
442
+ decodeCostOf(withFamilies, { ...rates, codec: "av1", bitDepth: 8 }),
443
+ decodeCostOf(withFamilies, { ...rates, codec: "h264", bitDepth: 8 })
444
+ );
445
+ // And a flat model — every model before this release — is unchanged.
446
+ const flat = { pixelTerm: 0.006, bitrateTerm: 0.012, constantTerm: 0 };
447
+ assert.equal(decodeCostOf(flat, { ...rates, codec: "hevc", bitDepth: 10 }), 0.408);
448
+ });
449
+
450
+ test("the family is chosen by codec and depth, and unknown names fall to H.264", () => {
451
+ assert.equal(decodeFamilyOf({ codec: "hevc", bitDepth: 8 }), "hevc");
452
+ assert.equal(decodeFamilyOf({ codec: "HEVC", bitDepth: 10 }), "hevc10");
453
+ assert.equal(decodeFamilyOf({ codec: "h265", bitDepth: 12 }), "hevc10");
454
+ assert.equal(decodeFamilyOf({ codec: "h264", bitDepth: 10 }), "h264");
455
+ assert.equal(decodeFamilyOf({ codec: "vc1", bitDepth: null }), "h264");
456
+ assert.equal(decodeFamilyOf({}), "h264");
457
+ });