video-fps-probe 0.4.0-beta.1 → 0.4.0-beta.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.
Files changed (61) hide show
  1. package/CHANGELOG.md +29 -0
  2. package/README.md +8 -6
  3. package/dist/analyze.js +10 -1
  4. package/dist/api/codes.js +2 -0
  5. package/dist/aspect/index.d.ts +13 -0
  6. package/dist/aspect/index.js +180 -0
  7. package/dist/aspect/rational.js +61 -0
  8. package/dist/cjs/aspect/index.d.cts +13 -0
  9. package/dist/cjs/aspect.cjs +1 -0
  10. package/dist/cjs/chunks/boxes-B0T2nt3e.cjs +1 -0
  11. package/dist/cjs/chunks/build-DhETwJLO.cjs +1 -0
  12. package/dist/cjs/chunks/color-xqJHSfhZ.cjs +1 -0
  13. package/dist/cjs/chunks/{compare-D7RVqlqf.cjs → compare-B_HKNwqg.cjs} +1 -1
  14. package/dist/cjs/chunks/config-CSbXzEqr.cjs +1 -0
  15. package/dist/cjs/chunks/{fallback-D9Ak2zFv.cjs → fallback-CyPIR3RM.cjs} +1 -1
  16. package/dist/cjs/chunks/{guards-Dqpjtkdn.cjs → guards-DbQNcAZS.cjs} +1 -1
  17. package/dist/cjs/chunks/isobmff-4RrRf9N-.cjs +1 -0
  18. package/dist/cjs/chunks/matroska-BhgWtuPU.cjs +1 -0
  19. package/dist/cjs/chunks/metadata-ECdzNLkE.cjs +1 -0
  20. package/dist/cjs/chunks/options-B_vLHxHd.cjs +1 -0
  21. package/dist/cjs/chunks/{probe-DDLUfr23.cjs → probe-Cn1DtL-C.cjs} +1 -1
  22. package/dist/cjs/chunks/reader-Dw11ozVU.cjs +1 -0
  23. package/dist/cjs/chunks/runtime-BgAlQQee.cjs +1 -0
  24. package/dist/cjs/chunks/{segments-i-hPN7H3.cjs → segments-B1H6bDz-.cjs} +1 -1
  25. package/dist/cjs/chunks/stats-DW7dVdFa.cjs +1 -0
  26. package/dist/cjs/color/index.d.cts +7 -0
  27. package/dist/cjs/color.cjs +1 -0
  28. package/dist/cjs/core/types.d.cts +46 -1
  29. package/dist/cjs/header/index.d.cts +3 -0
  30. package/dist/cjs/header/limits.d.cts +1 -0
  31. package/dist/cjs/header.cjs +1 -1
  32. package/dist/cjs/index.cjs +1 -1
  33. package/dist/color/codec-string.js +121 -0
  34. package/dist/color/config.js +199 -0
  35. package/dist/color/index.d.ts +7 -0
  36. package/dist/color/index.js +139 -0
  37. package/dist/color/names.js +33 -0
  38. package/dist/color/sps.js +275 -0
  39. package/dist/core/isobmff/build.js +6 -3
  40. package/dist/core/isobmff/config.js +34 -0
  41. package/dist/core/isobmff/header.js +23 -0
  42. package/dist/core/isobmff/moov.js +1 -1
  43. package/dist/core/matroska/header.js +1 -0
  44. package/dist/core/matroska/index.js +4 -2
  45. package/dist/core/options.js +1 -0
  46. package/dist/core/types.d.ts +46 -1
  47. package/dist/header/index.d.ts +3 -0
  48. package/dist/header/index.js +39 -3
  49. package/dist/header/limits.d.ts +1 -0
  50. package/dist/header/limits.js +4 -0
  51. package/dist/header/metadata.js +2 -0
  52. package/dist/standalone/own-isobmff.worker.js +1 -1
  53. package/dist/standalone/own-matroska.worker.js +1 -1
  54. package/dist/standalone/own.worker.js +1 -1
  55. package/package.json +41 -3
  56. package/dist/cjs/chunks/build-CT5g6_bs.cjs +0 -1
  57. package/dist/cjs/chunks/isobmff-B_bb5rS5.cjs +0 -1
  58. package/dist/cjs/chunks/matroska-CLoGzfKA.cjs +0 -1
  59. package/dist/cjs/chunks/reader-DNLR-_tm.cjs +0 -1
  60. package/dist/cjs/chunks/runtime-DtgT0xzU.cjs +0 -1
  61. package/dist/cjs/chunks/stats-D68frkk2.cjs +0 -1
package/CHANGELOG.md CHANGED
@@ -4,6 +4,35 @@ Format: [Keep a Changelog](https://keepachangelog.com/en/1.1.0/). Versions follo
4
4
 
5
5
  ## Unreleased
6
6
 
7
+ ## 0.4.0-beta.2 - 2026-10-31
8
+
9
+ ### Added
10
+
11
+ - `video-fps-probe/color`: `colorOf(track)` and `withColor(result)` read the codec configuration of a video track and give `color`: the range, primaries, transfer and matrix names that ffprobe 8.1.1 prints, where they came from (`sps`, `colr`, `vpcC` or `Colour`), the bit depth, the numeric profile, the RFC 6381 codec string, `hdr` (`'pq'` or `'hlg'`) and the Dolby Vision configuration record. The container wins over the H.264 or HEVC SPS, as in FFmpeg, and the SPS speaks when the container is silent. A value that is not null equals ffprobe on every committed fixture ([color](docs/api.md#color)).
12
+ - `video-fps-probe/aspect`: `aspectOf(track)` and `withAspect(result)` give `sampleAspectRatio`, `displayAspectRatio`, `displayWidth` and `displayHeight`, with the pasp, tkhd matrix, tkhd size and SPS VUI precedence of ffprobe 8.1.1 for MP4 and MOV and the Display and PixelCrop elements for Matroska and WebM. The display size has the rotation applied, for Matroska and WebM the ProjectionPoseRoll that ffprobe reports as the display matrix ([aspect ratio and display size](docs/api.md#aspect-ratio-and-display-size)).
13
+ - `codecConfig: true` keeps the raw codec configuration of each video track in `codecConfig` for both entries, with no read beyond the walk: the TrackEntry of a Matroska or WebM track, the stsd, tkhd and mvhd boxes of an MP4 or MOV track in `analyzeHeader` and the root `analyze`, and in a probe a view of the moov with the index of the trak, `{ family: 'isobmff-moov', moov, trak }`, a family of its own, from which both entries cut the same boxes. The view lies in a copy of the moov that the walk makes only with the option, so a probe posts the bytes of the moov and nothing else. A configuration whose bytes are missing or no longer `Uint8Array` or `DataView` values, as after `JSON.parse`, or that has a buffer transferred to another thread in any member, the view of the moov, a box or the TrackEntry, gives `color` and the aspect fields undefined, as a track without one does.
14
+ - `analyzeHeader` options `codecConfig`, `color` and `aspect`. `color: true` and `aspect: true` apply the two entries from a chunk loaded with `import()` and read no extra byte. Each chunk loads under the deadline and the signal of the call. A chunk never turns a result into an error: one that fails to load or has not loaded by `maxMs` leaves the result as it is with a coded warning, and one that an earlier call loaded, or started to load before it lost to its deadline, is applied even after the deadline, since it reads no byte.
15
+ - The warning codes `codec-config-unavailable`, for the prefix `codec configuration unavailable`, and `metadata-unavailable`, for `color and aspect unavailable`, which `warningCodeOf` gives to an `analyzeHeader` result whose codec configuration or color and aspect step did not run, so an exhaustive switch over `WarningCode` needs the two cases.
16
+ - The new optional result fields `codecConfig`, `color`, `sampleAspectRatio`, `displayAspectRatio`, `displayWidth` and `displayHeight` on `VideoTrackResult`, and the types `CodecConfig`, `ColorInfo`, `ColorSource` and `DolbyVisionConfig`.
17
+ - CommonJS copies of `video-fps-probe/color` and `video-fps-probe/aspect`, so the seven server entries load with `require()` and in Jest with no configuration, and their types name no DOM type.
18
+
19
+ ### Frozen from 0.4.0-beta.2
20
+
21
+ The members of `ColorInfo` and `DolbyVisionConfig`, the `ColorSource` values, the `codecConfig`, `color` and `aspect` options of `analyzeHeader`, the warning codes `codec-config-unavailable` and `metadata-unavailable` with their prefixes and the signatures of `colorOf`, `withColor`, `aspectOf` and `withAspect` join the list of 0.4.0-beta.1. Later releases only add to them. `CodecConfig` is raw bytes for the two entries and may gain members.
22
+
23
+ ### Changed
24
+
25
+ - The installed package may take up to 936 KB unpacked (867 KB in 0.4.0-beta.1), measured at 920 KB, for the two entries, their CommonJS copies and the longer docs.
26
+ - The first MKV or WebM loads 25.76 KB gzip (25.73 KB in 0.4.0-beta.1) for the TrackEntry copy: the Matroska header walk copies every TrackEntry, and the analyzer attaches the copy to the video tracks only with the option. The first MP4 loads 23.13 KB (23.07 KB in 0.4.0-beta.1), 24.91 KB with Vite's default worker format, for the view of the moov that the worker attaches with the option and the copy of the moov it lies in. The 0.4.0 plan gave this step 0.05 KB on the first MP4 path, and the copy takes it to 0.08 KB, measured 0.06 to 0.08 KB over 0.4.0-beta.1, with every first MP4 row inside its budget and the 24.95 KB cap.
27
+ - `video-fps-probe/color` puts 4.93 KB gzip in the entry chunk of an app that imports it, under a budget of 5.0 KB rather than the 4.00 KB the 0.4.0 plan set: the two SPS walkers and the FFmpeg name tables are what make the color result equal to ffprobe, and cutting the boxes out of the moov view of a probe adds 0.25 KB.
28
+ - `video-fps-probe/header` puts 19.81 KB gzip of package code in the entry chunk (19.28 KB in 0.4.0-beta.1). It loads the codec configuration capture and the two entries with `import()`, so an app whose only dynamic import is this one gets Vite's preload helper, 0.75 KB, in its entry chunk too.
29
+ - Still 0 mismatches against ffprobe 8.1.1 on the 168 committed fixtures, now with checks of the color names, bit depth, profile, codec string, Dolby Vision record and both aspect ratios: 4878 checks, with 5 new known deviations where ffprobe takes the color range or matrix from a bitstream the color entry does not read (the AV1 sequence header, ProRes, MPEG-4 Part 2).
30
+
31
+ ### Known limitations
32
+
33
+ - A probe gives an MP4 or MOV track a view of the moov rather than the three boxes, because cutting them in the worker measured 0.25 KB on the first MP4 path, over the 0.08 KB this release allows there. `colorOf` and `aspectOf` read both forms. The view lies in a copy of the moov, so `postMessage` copies the moov and nothing else: the moov box, up to 256 MiB, or the part the walk parsed of a moov whose size runs past the end of the file, up to 16 MiB. Without the copy a probe posted the whole read the moov came from, up to 16 MiB with media data after an mdat. While the walk runs it can hold the moov twice, the read and the copy, up to 512 MiB for a moov at the 256 MiB limit.
34
+ - The color entry does not read the AV1 sequence header, the VP9 frame header, ProRes or HDR10 static metadata (`mdcv`, `clli`, MasteringMetadata), so their values stay null where ffprobe takes them from the decoder. An HLG stream signalled only by an alternative transfer characteristics SEI keeps the `bt2020-10` transfer of its VUI, as the stream keys of ffprobe do. The `rotation` of a Matroska or WebM track stays 0, while `withAspect` applies its ProjectionPoseRoll to the display size.
35
+
7
36
  ## 0.4.0-beta.1 - 2026-10-31
8
37
 
9
38
  ### Added
package/README.md CHANGED
@@ -106,7 +106,9 @@ A server that checks uploads in object storage can read only the header: `analyz
106
106
 
107
107
  `video-fps-probe/url` reads such an object over HTTP Range requests: `analyzeHeader(await openRangeSource(httpRange(presignedUrl)), { limits })`, or `rangeSource(fetcher, { size })` over the client of any object-storage SDK. It needs no SDK and makes one request per read, with no retries, and it checks the status, `Content-Range` and `Content-Length` of every reply before the body is read and caps the body while it streams, so a server that ignores the range or an object whose size changed fails the read as `read-failed` instead of returning wrong bytes. An `If-Match` with the object's ETag, which the caller sends, also catches an overwrite at the same size ([Range source](docs/api.md#range-source)).
108
108
 
109
- CommonJS works on Node 22.12 and newer, the lowest supported version, which load ES modules from `require()`: `const { analyze } = require('video-fps-probe')`, the subpaths included, and a TypeScript project with `"module": "commonjs"` and `moduleResolution` `node10`, such as a NestJS 11 app. The five server entries, `video-fps-probe`, `video-fps-probe/header`, `video-fps-probe/url`, `video-fps-probe/check` and `video-fps-probe/presets`, also ship a minified CommonJS copy with `.d.cts` types for loaders that do not run `require(esm)`, so Jest 30 runs them with no configuration and `jest` as the only dependency, and with `--experimental-vm-modules` on Node 24.9 it loads the ESM build instead. The package tests check all of this from the packed tarball on Node 22.12 and 24. The other entries still need babel-jest in Jest: the tested configuration and a stub for unit tests are in [Jest](docs/api.md#jest).
109
+ The same call can tell an HDR upload from an SDR one and give the display size: `analyzeHeader(source, { color: true, aspect: true })` fills `color` with the range, primaries, transfer and matrix names ffprobe prints, the bit depth, the profile, the RFC 6381 codec string, `hdr` (`'pq'` or `'hlg'`) and the Dolby Vision record, and fills `sampleAspectRatio`, `displayAspectRatio`, `displayWidth` and `displayHeight`, from the boxes of the moov it reads anyway. The container wins over the H.264 or HEVC SPS as in FFmpeg 8.1.1, and the SPS speaks when the container is silent. `video-fps-probe/color` and `video-fps-probe/aspect` do the same for results of `analyzeHeader`, the root `analyze` or a probe with `codecConfig: true` ([Color](docs/api.md#color), [Aspect ratio and display size](docs/api.md#aspect-ratio-and-display-size)).
110
+
111
+ CommonJS works on Node 22.12 and newer, the lowest supported version, which load ES modules from `require()`: `const { analyze } = require('video-fps-probe')`, the subpaths included, and a TypeScript project with `"module": "commonjs"` and `moduleResolution` `node10`, such as a NestJS 11 app. The seven server entries, `video-fps-probe`, `video-fps-probe/header`, `video-fps-probe/url`, `video-fps-probe/color`, `video-fps-probe/aspect`, `video-fps-probe/check` and `video-fps-probe/presets`, also ship a minified CommonJS copy with `.d.cts` types for loaders that do not run `require(esm)`, so Jest 30 runs them with no configuration and `jest` as the only dependency, and with `--experimental-vm-modules` on Node 24.9 it loads the ESM build instead. The package tests check all of this from the packed tarball on Node 22.12 and 24. The other entries still need babel-jest in Jest: the tested configuration and a stub for unit tests are in [Jest](docs/api.md#jest).
110
112
 
111
113
  ## Cancellation, timeouts and failing open
112
114
 
@@ -137,12 +139,12 @@ Rules are JSON, such as `{ fps: { min: 24, max: 60 }, duration: { max: 10 }, vfr
137
139
 
138
140
  <!-- tables:size:start -->
139
141
 
140
- **0.66 KB gzip on the critical path**: the package code in the entry chunk of a Vite 8.3.5 app that imports `video-fps-probe/lazy` (1.40 KB with Vite's preload helper). The rest loads lazily, on the first file:
142
+ **0.67 KB gzip on the critical path**: the package code in the entry chunk of a Vite 8.3.5 app that imports `video-fps-probe/lazy` (1.40 KB with Vite's preload helper). The rest loads lazily, on the first file:
141
143
 
142
144
  | Host Vite config | Critical path | First MP4 | First MKV | All own paths | Worker files |
143
145
  |---|---:|---:|---:|---:|---:|
144
- | `worker: { format: 'es' }` (recommended) | **0.66 KB** | 23.07 KB | 25.73 KB | 49.14 KB | 2 |
145
- | none (Vite's default, 'iife') | **0.66 KB** | 24.85 KB | 27.19 KB | 48.75 KB | 2 |
146
+ | `worker: { format: 'es' }` (recommended) | **0.67 KB** | 23.13 KB | 25.76 KB | 49.23 KB | 2 |
147
+ | none (Vite's default, 'iife') | **0.66 KB** | 24.91 KB | 27.21 KB | 48.85 KB | 2 |
146
148
 
147
149
  Own runs on one worker per container family, picked by the first four bytes of the file, so a first file loads only the worker of its family. An iife worker cannot split, so without the option each own worker is one file with its lazy parts inlined:
148
150
 
@@ -152,7 +154,7 @@ import { defineConfig } from 'vite';
152
154
  export default defineConfig({ worker: { format: 'es' } });
153
155
  ```
154
156
 
155
- Engines cost nothing until imported. Importing a descriptor grows the critical path a little, from 0.66 KB to 0.89 KB with mp4box or mediabunny, 0.76 KB with rVFC and 1.01 KB with all three, and the engine itself loads lazily: mp4box 44.94 KB, mediabunny 54.17 KB, rVFC 2.19 KB. Gzip -9 of production builds from the packed tarball, budgeted in CI. Every configuration is in [docs/benchmarks.md](docs/benchmarks.md#package-size).
157
+ Engines cost nothing until imported. Importing a descriptor grows the critical path a little, from 0.67 KB to 0.89 KB with mp4box or mediabunny, 0.77 KB with rVFC and 1.01 KB with all three, and the engine itself loads lazily: mp4box 44.95 KB, mediabunny 54.16 KB, rVFC 2.19 KB. Gzip -9 of production builds from the packed tarball, budgeted in CI. Every configuration is in [docs/benchmarks.md](docs/benchmarks.md#package-size).
156
158
 
157
159
  `video-fps-probe/react` adds 1.20 KB to the critical path for the provider, `useVideoFps` and its store (React itself not counted), and its first analysis also fetches a 0.43 KB summary module, in parallel with the probe client. `video-fps-probe/check` adds 3.99 KB when imported statically, and nothing lazily. One preset from `video-fps-probe/presets` adds 0.46 KB.
158
160
 
@@ -162,7 +164,7 @@ Engines cost nothing until imported. Importing a descriptor grows the critical p
162
164
 
163
165
  <!-- tables:accuracy-summary:start -->
164
166
 
165
- **0 mismatches against ffprobe 8.1.1** on the 168 committed fixtures: 3318 field checks, 3229 exact, 13 within tolerance (9 of them a definition difference by design: the measured average of a Matroska file that stores no duration for its last frame, which avgFps gives the median interval and ffprobe its own estimate), 2 known deviations with a recorded reason, 74 not applicable. The same comparison runs mp4box.js 2.4.1 and mediabunny 1.62.1 in 5 arms (their idiomatic recipes, mediabunny with a full scan, and this package's tuned adapters) and sorts each difference into wrong, definition differs, unverified, not provided or unsupported container. The [accuracy section](docs/benchmarks.md#accuracy-vs-ffprobe) has the outcomes and where the libraries win.
167
+ **0 mismatches against ffprobe 8.1.1** on the 168 committed fixtures: 4878 field checks, 4675 exact, 13 within tolerance (9 of them a definition difference by design: the measured average of a Matroska file that stores no duration for its last frame, which avgFps gives the median interval and ffprobe its own estimate), 7 known deviations with a recorded reason, 183 not applicable. The same comparison runs mp4box.js 2.4.1 and mediabunny 1.62.1 in 5 arms (their idiomatic recipes, mediabunny with a full scan, and this package's tuned adapters) and sorts each difference into wrong, definition differs, unverified, not provided or unsupported container. The [accuracy section](docs/benchmarks.md#accuracy-vs-ffprobe) has the outcomes and where the libraries win.
166
168
 
167
169
  Of the 168 committed fixtures, 156 are synthetic files made with ffmpeg and 12 are real MediaRecorder recordings from headless Chromium, committed as recorded. Per-engine tables, speed and method: [docs/benchmarks.md](docs/benchmarks.md).
168
170
 
package/dist/analyze.js CHANGED
@@ -1,5 +1,14 @@
1
1
  export async function analyze(input, options = {}) {
2
2
  const { name = typeof File !== 'undefined' && input instanceof File ? input.name : '', engine, ...opts } = options;
3
3
  const module = engine ? await engine.load() : (await import("./worker/runtime.js")).ownEngine;
4
- return module.run(input, name, opts);
4
+ const result = await module.run(input, name, opts);
5
+ if (!result.videoTracks.some((t) => t.codecConfig?.family === 'isobmff-moov'))
6
+ return result;
7
+ try {
8
+ const { isoBoxes } = await import("./core/isobmff/config.js");
9
+ return { ...result, videoTracks: result.videoTracks.map((t) => (t.codecConfig?.family === 'isobmff-moov' ? { ...t, codecConfig: isoBoxes(t.codecConfig.moov, t.codecConfig.trak) } : t)) };
10
+ }
11
+ catch {
12
+ return result;
13
+ }
5
14
  }
package/dist/api/codes.js CHANGED
@@ -49,6 +49,8 @@ const WARNING_PREFIXES = [
49
49
  ['format duration unresolved: ', 'duration-unresolved'],
50
50
  ['fragments ignored: ', 'fragments-ignored'],
51
51
  ['too many top-level boxes', 'structure-limit'],
52
+ ['codec configuration unavailable', 'codec-config-unavailable'],
53
+ ['color and aspect unavailable', 'metadata-unavailable'],
52
54
  ];
53
55
  const TRUNCATED_BOX = /^'(.{4})' at \d+ is truncated/;
54
56
  export function errorCodeOf(result) {
@@ -0,0 +1,13 @@
1
+ import type { FileResult, Rational, VideoTrackResult } from '../core/types.js';
2
+ export type { CodecConfig, Rational } from '../core/types.js';
3
+ export interface AspectInfo {
4
+ sampleAspectRatio: Rational | null;
5
+ displayAspectRatio: Rational | null;
6
+ displayWidth: number | null;
7
+ displayHeight: number | null;
8
+ }
9
+ export type AspectTrack = Pick<VideoTrackResult, 'codecName' | 'width' | 'height' | 'rotation' | 'codecConfig'>;
10
+ export declare function aspectOf(track: AspectTrack): AspectInfo | undefined;
11
+ export declare function withAspect<R extends Pick<FileResult, 'videoTracks'>>(result: R, options?: {
12
+ keepCodecConfig?: boolean;
13
+ }): R;
@@ -0,0 +1,180 @@
1
+ import { boxPayload, elementUint, elements, firstBox, i32, ID_DISPLAY_HEIGHT, ID_DISPLAY_UNIT, ID_DISPLAY_WIDTH, ID_PIXEL_HEIGHT, ID_PIXEL_WIDTH, ID_STEREO_MODE, isoConfig, matroskaConfig, u32, } from "../color/config.js";
2
+ import { avcConfigSps, hevcConfigSps } from "../color/sps.js";
3
+ import { avD2q, avReduce, INT_MAX } from "./rational.js";
4
+ const DAR_MAX = 1048576n;
5
+ const MATRIX_SCALE_LIMIT = 1 << 24;
6
+ const MATRIX_SCALE_TOLERANCE = 0.01;
7
+ const DISPLAY_UNIT_UNKNOWN = 4;
8
+ const WIDTH_TIMES_TWO = new Set([1, 8, 9, 11]);
9
+ const HEIGHT_TIMES_TWO = new Set([2, 3, 6, 7]);
10
+ const ID_PIXEL_CROP_BOTTOM = 0x54aa;
11
+ const ID_PIXEL_CROP_TOP = 0x54bb;
12
+ const ID_PIXEL_CROP_LEFT = 0x54cc;
13
+ const ID_PIXEL_CROP_RIGHT = 0x54dd;
14
+ const ID_PROJECTION = 0x7670;
15
+ const ID_PROJECTION_TYPE = 0x7671;
16
+ const ID_PROJECTION_PRIVATE = 0x7672;
17
+ const ID_PROJECTION_POSE_YAW = 0x7673;
18
+ const ID_PROJECTION_POSE_PITCH = 0x7674;
19
+ const ID_PROJECTION_POSE_ROLL = 0x7675;
20
+ function rational([num, den]) {
21
+ return { num: Number(num), den: Number(den), value: Number(num) / Number(den) };
22
+ }
23
+ const valid = (r) => r !== null && r[0] > 0n && r[1] > 0n;
24
+ function vuiRatio(sps) {
25
+ const sar = sps?.vui?.sar;
26
+ return sar ? avReduce(BigInt(sar[0]), BigInt(sar[1]), INT_MAX) : null;
27
+ }
28
+ function configSps(codec, b, s) {
29
+ return !s ? null : codec === 'h264' ? avcConfigSps(b, s) : codec === 'hevc' ? hevcConfigSps(b, s) : null;
30
+ }
31
+ function matrixOf(box, offset) {
32
+ const p = boxPayload(box);
33
+ if (!box || !p)
34
+ return null;
35
+ const at = p.start + offset(box[p.start]);
36
+ if (at + 36 > p.end)
37
+ return null;
38
+ return Array.from({ length: 9 }, (_, i) => BigInt(i32(box, at + i * 4)));
39
+ }
40
+ function tkhdSizeAt(iso) {
41
+ const tkhd = boxPayload(iso.tkhd);
42
+ const at = iso.tkhd && tkhd ? tkhd.start + (iso.tkhd[tkhd.start] === 1 ? 88 : 76) : -1;
43
+ return tkhd && at + 8 <= tkhd.end ? at : -1;
44
+ }
45
+ function matrixRatio(iso, sizeAt) {
46
+ if (!iso.tkhd || sizeAt < 0 || !u32(iso.tkhd, sizeAt) || !u32(iso.tkhd, sizeAt + 4))
47
+ return null;
48
+ const track = matrixOf(iso.tkhd, (v) => (v === 1 ? 52 : 40));
49
+ if (!track)
50
+ return null;
51
+ const movie = matrixOf(iso.mvhd, (v) => (v === 1 ? 48 : 36)) ?? Array(9).fill(0n);
52
+ const shift = [16n, 16n, 30n];
53
+ const m = [];
54
+ for (let i = 0; i < 3; i++) {
55
+ for (let j = 0; j < 3; j++) {
56
+ let sum = 0n;
57
+ for (let e = 0; e < 3; e++)
58
+ sum += (track[i * 3 + e] * movie[e * 3 + j]) >> shift[e];
59
+ m.push(Number(BigInt.asIntN(32, sum)));
60
+ }
61
+ }
62
+ const identity = m[0] === 65536 && m[4] === 65536 && m[8] === 1 << 30 && !m[1] && !m[2] && !m[3] && !m[5] && !m[6] && !m[7];
63
+ if (identity)
64
+ return null;
65
+ const x = Math.hypot(m[0], m[3]);
66
+ const y = Math.hypot(m[1], m[4]);
67
+ if (!(x > 1 && y > 1 && x < MATRIX_SCALE_LIMIT && y < MATRIX_SCALE_LIMIT && Math.abs(x / y - 1) > MATRIX_SCALE_TOLERANCE))
68
+ return null;
69
+ return avD2q(x / y, INT_MAX);
70
+ }
71
+ function isoRatio(track, iso) {
72
+ const sizeAt = tkhdSizeAt(iso);
73
+ let pasp = null;
74
+ for (const entry of iso.entries) {
75
+ for (const c of entry.children) {
76
+ if (c.type === 'pasp' && c.end - c.start >= 8 && i32(iso.bytes, c.start + 4))
77
+ pasp = [BigInt(i32(iso.bytes, c.start)), BigInt(i32(iso.bytes, c.start + 4))];
78
+ }
79
+ }
80
+ let sar = pasp?.[0] ? avReduce(pasp[0], pasp[1], INT_MAX) : matrixRatio(iso, sizeAt);
81
+ if (!sar?.[0] && iso.tkhd && sizeAt >= 0) {
82
+ const w = BigInt(i32(iso.tkhd, sizeAt) >> 16);
83
+ const h = BigInt(i32(iso.tkhd, sizeAt + 4) >> 16);
84
+ const sw = BigInt(track.width);
85
+ const sh = BigInt(track.height);
86
+ if (w && h && sw && sh && (sw !== w || sh !== h))
87
+ sar = avReduce(sh * w, sw * h, INT_MAX);
88
+ }
89
+ if (valid(sar))
90
+ return sar;
91
+ const entry = iso.entries[0];
92
+ return vuiRatio(configSps(track.codecName, iso.bytes, firstBox(entry, track.codecName === 'h264' ? 'avcC' : 'hvcC')));
93
+ }
94
+ function matroskaCodec(mkv) {
95
+ return mkv.codecId === 'V_MPEG4/ISO/AVC' ? 'h264' : mkv.codecId === 'V_MPEGH/ISO/HEVC' ? 'hevc' : '';
96
+ }
97
+ function matroskaRatio(mkv) {
98
+ const b = mkv.bytes;
99
+ const video = (id) => elementUint(b, mkv.video.get(id));
100
+ const unit = video(ID_DISPLAY_UNIT) ?? 0;
101
+ let sar = null;
102
+ const croppedWidth = (video(ID_PIXEL_WIDTH) ?? 0) - (video(ID_PIXEL_CROP_LEFT) ?? 0) - (video(ID_PIXEL_CROP_RIGHT) ?? 0);
103
+ const croppedHeight = (video(ID_PIXEL_HEIGHT) ?? 0) - (video(ID_PIXEL_CROP_TOP) ?? 0) - (video(ID_PIXEL_CROP_BOTTOM) ?? 0);
104
+ if (unit < DISPLAY_UNIT_UNKNOWN && croppedWidth > 0 && croppedHeight > 0) {
105
+ const dw = video(ID_DISPLAY_WIDTH) ?? (unit === 0 ? croppedWidth : null);
106
+ const dh = video(ID_DISPLAY_HEIGHT) ?? (unit === 0 ? croppedHeight : null);
107
+ const stereo = video(ID_STEREO_MODE) ?? 0;
108
+ if (dw && dh) {
109
+ const wmul = WIDTH_TIMES_TWO.has(stereo) ? 2n : 1n;
110
+ const hmul = HEIGHT_TIMES_TWO.has(stereo) ? 2n : 1n;
111
+ sar = avReduce(BigInt(croppedHeight) * BigInt(dw) * wmul, BigInt(croppedWidth) * BigInt(dh) * hmul, INT_MAX);
112
+ }
113
+ }
114
+ return valid(sar) ? sar : vuiRatio(configSps(matroskaCodec(mkv), b, mkv.codecPrivate));
115
+ }
116
+ function elementFloat(b, span) {
117
+ const n = span ? span.end - span.start : 0;
118
+ if (!span || (n !== 4 && n !== 8))
119
+ return 0;
120
+ const dv = new DataView(b.buffer, b.byteOffset + span.start, n);
121
+ return n === 4 ? dv.getFloat32(0) : dv.getFloat64(0);
122
+ }
123
+ function projectionRotation(mkv) {
124
+ const span = mkv.video.get(ID_PROJECTION);
125
+ if (!span)
126
+ return 0;
127
+ const b = mkv.bytes;
128
+ const projection = new Map();
129
+ for (const e of elements(b, span.start, span.end))
130
+ projection.set(e.id, e);
131
+ const extra = projection.get(ID_PROJECTION_PRIVATE);
132
+ if ((elementUint(b, projection.get(ID_PROJECTION_TYPE)) ?? 0) !== 0 || (extra && extra.end > extra.start && b[extra.start] !== 0))
133
+ return 0;
134
+ const yaw = elementFloat(b, projection.get(ID_PROJECTION_POSE_YAW));
135
+ const roll = elementFloat(b, projection.get(ID_PROJECTION_POSE_ROLL));
136
+ if (elementFloat(b, projection.get(ID_PROJECTION_POSE_PITCH)) !== 0 || (yaw !== 0 && Math.abs(yaw) !== 180) || Number.isNaN(roll))
137
+ return 0;
138
+ const flip = yaw !== 0 ? -1 : 1;
139
+ const radians = (roll * flip * Math.PI) / 180;
140
+ const a = (flip * Math.trunc(Math.cos(radians) * 65536)) / 65536;
141
+ const c = Math.trunc(-Math.sin(radians) * 65536) / 65536;
142
+ const s0 = Math.hypot(a, (flip * Math.trunc(Math.sin(radians) * 65536)) / 65536);
143
+ const s1 = Math.hypot(c, Math.trunc(Math.cos(radians) * 65536) / 65536);
144
+ return s0 && s1 ? Math.trunc(-((Math.atan2(c / s1, a / s0) * 180) / Math.PI)) || 0 : 0;
145
+ }
146
+ export function aspectOf(track) {
147
+ const config = track.codecConfig;
148
+ const iso = config && isoConfig(config);
149
+ const mkv = config && !iso ? matroskaConfig(config) : null;
150
+ if (!iso && !mkv)
151
+ return undefined;
152
+ const sar = iso ? isoRatio(track, iso) : matroskaRatio(mkv);
153
+ const usable = valid(sar) ? sar : null;
154
+ const { width, height } = track;
155
+ if (width <= 0 || height <= 0)
156
+ return { sampleAspectRatio: usable && rational(usable), displayAspectRatio: null, displayWidth: null, displayHeight: null };
157
+ const [num, den] = usable ?? [1n, 1n];
158
+ const storedWidth = Number((2n * BigInt(width) * num + den) / (2n * den));
159
+ const rotation = track.rotation || (mkv ? projectionRotation(mkv) : 0);
160
+ const swap = Math.abs(rotation) % 180 === 90;
161
+ return {
162
+ sampleAspectRatio: usable && rational(usable),
163
+ displayAspectRatio: usable && rational(avReduce(BigInt(width) * num, BigInt(height) * den, DAR_MAX)),
164
+ displayWidth: swap ? height : storedWidth,
165
+ displayHeight: swap ? storedWidth : height,
166
+ };
167
+ }
168
+ export function withAspect(result, options = {}) {
169
+ return {
170
+ ...result,
171
+ videoTracks: result.videoTracks.map((t) => {
172
+ if (!t.codecConfig)
173
+ return t;
174
+ const out = { ...t, ...aspectOf(t) };
175
+ if (!options.keepCodecConfig)
176
+ delete out.codecConfig;
177
+ return out;
178
+ }),
179
+ };
180
+ }
@@ -0,0 +1,61 @@
1
+ export const INT_MAX = 2147483647n;
2
+ const abs = (v) => (v < 0n ? -v : v);
3
+ function gcd(a, b) {
4
+ while (b)
5
+ [a, b] = [b, a % b];
6
+ return a;
7
+ }
8
+ export function avReduce(num, den, max) {
9
+ let a0 = [0n, 1n];
10
+ let a1 = [1n, 0n];
11
+ const negative = num < 0n !== den < 0n;
12
+ const g = gcd(abs(num), abs(den));
13
+ if (g) {
14
+ num = abs(num) / g;
15
+ den = abs(den) / g;
16
+ }
17
+ if (num <= max && den <= max) {
18
+ a1 = [num, den];
19
+ den = 0n;
20
+ }
21
+ while (den) {
22
+ let x = num / den;
23
+ const nextDen = num - den * x;
24
+ const a2n = x * a1[0] + a0[0];
25
+ const a2d = x * a1[1] + a0[1];
26
+ if (a2n > max || a2d > max) {
27
+ if (a1[0])
28
+ x = (max - a0[0]) / a1[0];
29
+ if (a1[1])
30
+ x = x < (max - a0[1]) / a1[1] ? x : (max - a0[1]) / a1[1];
31
+ if (den * (2n * x * a1[1] + a0[1]) > num * a1[1])
32
+ a1 = [x * a1[0] + a0[0], x * a1[1] + a0[1]];
33
+ break;
34
+ }
35
+ a0 = a1;
36
+ a1 = [a2n, a2d];
37
+ num = den;
38
+ den = nextDen;
39
+ }
40
+ return [negative ? -a1[0] : a1[0], a1[1]];
41
+ }
42
+ function binaryExponent(v) {
43
+ if (v === 0)
44
+ return 0;
45
+ let e = Math.floor(Math.log2(v));
46
+ while (2 ** e > v)
47
+ e--;
48
+ while (2 ** (e + 1) <= v)
49
+ e++;
50
+ return e;
51
+ }
52
+ export function avD2q(d, max) {
53
+ if (Number.isNaN(d))
54
+ return [0n, 0n];
55
+ if (Math.abs(d) > Number(INT_MAX) + 3)
56
+ return [d < 0 ? -1n : 1n, 0n];
57
+ const exponent = Math.max(binaryExponent(Math.abs(d)), 0);
58
+ const den = 1n << BigInt(61 - exponent);
59
+ const num = BigInt(Math.floor(d * Number(den) + 0.5));
60
+ return avReduce(num, den, max);
61
+ }
@@ -0,0 +1,13 @@
1
+ import type { FileResult, Rational, VideoTrackResult } from '../core/types.cjs';
2
+ export type { CodecConfig, Rational } from '../core/types.cjs';
3
+ export interface AspectInfo {
4
+ sampleAspectRatio: Rational | null;
5
+ displayAspectRatio: Rational | null;
6
+ displayWidth: number | null;
7
+ displayHeight: number | null;
8
+ }
9
+ export type AspectTrack = Pick<VideoTrackResult, 'codecName' | 'width' | 'height' | 'rotation' | 'codecConfig'>;
10
+ export declare function aspectOf(track: AspectTrack): AspectInfo | undefined;
11
+ export declare function withAspect<R extends Pick<FileResult, 'videoTracks'>>(result: R, options?: {
12
+ keepCodecConfig?: boolean;
13
+ }): R;
@@ -0,0 +1 @@
1
+ Object.defineProperty(exports,Symbol.toStringTag,{value:`Module`});const e=require("./chunks/color-xqJHSfhZ.cjs");exports.aspectOf=e.t,exports.withAspect=e.n;
@@ -0,0 +1 @@
1
+ const e=require("./reader-Dw11ozVU.cjs");var IsoBmffError=class extends Error{constructor(e,t){super(t),this.name=`IsoBmffError`,this.errorCode=e}};function readBoxHeader(t,n,r,i=0){let a=Math.min(t.byteLength,r);if(n+8>a)return null;let o=t.getUint32(n),s=e.n(t,n+4),c=8,l=o;if(o===1){if(n+16>a)return null;let e=t.getBigUint64(n+8);if(e>BigInt(2**53-1))throw new IsoBmffError(`corrupt`,`corrupt file: box '${s}' at ${i+n} has a size above 2^53-1`);l=Number(e),c=16}else o===0&&(l=r-n);if(s===`uuid`&&(c+=16),l<c)throw new IsoBmffError(`corrupt`,`corrupt file: box '${s}' at ${i+n} is smaller than its header`);let u=n+l;return{type:s,start:n,size:l,headerSize:c,end:Math.min(u,r),truncated:u>r}}function*childBoxes(e,t,n,r){let i=t;for(;i+8<=n;){let t;try{t=readBoxHeader(e,i,n)}catch(e){r?.push(e.message.replace(/^corrupt file: /,`ignored invalid child: `));return}if(!t)return;yield t,i=t.start+t.size}}function boxU64(e,t,n,r){let i=e.getBigUint64(t);if(i>BigInt(2**53-1))throw new IsoBmffError(`unsupported`,`unsupported: box '${n}' at ${r} holds a value above 2^53-1`);return Number(i)}function boxI64(e,t,n,r){let i=e.getBigInt64(t);if(i>BigInt(2**53-1)||i<-BigInt(2**53-1))throw new IsoBmffError(`unsupported`,`unsupported: box '${n}' at ${r} holds a value beyond 2^53-1`);return Number(i)}function boundEntries(e,t,n,r,i){let a=Math.max(0,Math.floor(t/n));return e>a?(i.push(`${r} declares ${e} entries but its box holds only ${a}`),a):e}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return childBoxes}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return boxU64}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return boundEntries}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return readBoxHeader}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return boxI64}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return IsoBmffError}});
@@ -0,0 +1 @@
1
+ const e=require("./guards-DbQNcAZS.cjs"),t=require("./reader-Dw11ozVU.cjs"),n=require("./boxes-B0T2nt3e.cjs"),r=require("./rational-Dq5Vza-Q.cjs");let i=null;function videoTags(){if(i)return i;i=new Map;for(let e of`rawvideo:raw yuv22vuyyuvs|v210:v210|mjpeg:jpegmjpaAVDJAVRndmb1|mpeg4:mp4vDIVXXVID3IV2|h263:h263s263H263|dvvideo:dvcpdvc dvppdv5pdv5nAVdvAVd1dvhqdvhpdvh1dvh2dvh3dvh4dvh5dvh6|qtrle:rle |cinepak:cvid|svq1:SVQ1svq1svqi|svq3:SVQ3|vvc:vvc1vvi1|hevc:hev1hvc1dvhe|h264:avc1avc2avc3avc4ai5pai5qai52ai53ai55ai56ai1pai1qai12ai13ai15ai16AVinaivxdva1dvav|evc:evc1|vp8:vp08|vp9:vp09|av1:av01|mpeg1video:m1v m1v1mpegmp1v|mpeg2video:m2v1hdv1hdv2hdv3hdv4hdv5hdv6hdv7hdv8hdv9hdvamx5nmx5pmx4nmx4pmx3nmx3pxd51xd54xd55xd59xd5axd5bxd5cxd5dxd5exd5fxdv1xdv2xdv3xdv4xdv5xdv6xdv7xdv8xdv9xdvaxdvbxdvcxdvdxdvexdvfxdhdxdh2AVmpmp2v|jpeg2000:mjp2|png:png MNG |gif:gif |tiff:tiff|vc1:vc-1|cavs:avs2|avs3:avs3|dirac:drac|dnxhd:AVdnAVdh|prores:apchapcnapcsapcoap4hap4x|prores_raw:aprnaprh|hap:Hap1Hap5HapYHapAHapM|cfhd:CFHD|lcevc:lvc1|apv:apv1`.split(`|`)){let t=e.indexOf(`:`),n=e.slice(0,t);for(let r=t+1;r+4<=e.length;r+=4)i.set(e.slice(r,r+4),n)}return i}const a={32:`mpeg4`,33:`h264`,35:`hevc`,51:`vvc`,96:`mpeg2video`,97:`mpeg2video`,98:`mpeg2video`,99:`mpeg2video`,100:`mpeg2video`,101:`mpeg2video`,106:`mpeg1video`,108:`mjpeg`,109:`png`,110:`jpeg2000`,163:`vc1`,164:`dirac`,177:`vp9`};function isVideoFourcc(e){return videoTags().has(e)}function codecNameFor(e,t=null,n=!1){return t!==null&&a[t]?a[t]:e===`dvh1`&&n?`hevc`:videoTags().get(e)??`unknown`}const o=`no trex: sample defaults taken from tfhd`;function trunRecordSize(e){let t=0;for(let n=256;n<=2048;n<<=1)e&n&&(t+=4);return t}function parseTfhd(e,r,i,a,o,s,c=o+r-8){if(r+8>i)return null;let l=t.r(e,r+1),u=e.getUint32(r+4),d=a.trex.get(u),f=r+8,need=e=>f+e<=i,p=l&131072?o:s;if(l&1){if(!need(8))return null;p=n.i(e,f,`tfhd`,c),f+=8}l&2&&(f+=4);let m=d?d.duration:null;if(l&8){if(!need(4))return null;m=e.getUint32(f),f+=4}let h=d?d.size:0;if(l&16){if(!need(4))return null;h=e.getUint32(f)}return{flags:l,trackId:u,baseDataOffset:p,defaultDuration:m,defaultSize:h,trexMissing:!d}}function parseTrun(e,r,i,a,o,s,c,l){let u=t.r(e,r+1),d=e.getUint32(r+4),f=r+8,p=o;u&1&&(p=a.baseDataOffset+e.getInt32(f),f+=4),u&4&&(f+=4);let m=trunRecordSize(u),h;m>0?h=n.n(d,i-f,m,`trun`,c):(h=d,h>l&&(c.push(`trun count ${d} limited to ${l}`),h=l));let g=m>0&&h<d,_=!!(u&256);if(!_&&a.defaultDuration===null&&h>0)throw new n.t(`corrupt`,`corrupt file: no sample duration for track ${a.trackId}`);let v=a.defaultDuration??0,y=_?new Uint32Array(h):null,b=u&2048?new Int32Array(h):null,x=!!(u&512),S=_?0:v*h,C=p,w=0,T=0;if(m>0)for(let t=0;t<h;t++){if(_){let n=e.getUint32(f);y[t]=n,S+=n,f+=4}let n=a.defaultSize;x&&(n=e.getUint32(f),f+=4),u&1024&&(f+=4),b&&(b[t]=e.getInt32(f),f+=4),C<s&&w++,T===t&&C+n<=s&&T++,C+=n}if(!x){let e=a.defaultSize,t=Math.max(0,s-p);w=e>0?Math.min(h,Math.ceil(t/e)):Math.min(h,t),T=e>0?Math.min(h,Math.floor(t/e)):w,C=p+e*h}return{fragment:{moofIndex:0,baseDts:null,count:h,durations:y,defaultDuration:v,cts:b,durationSum:S,present:w,complete:T,trexMissing:a.trexMissing,overrun:g},dataEnd:C}}function parseMoof(e,t,r,i,a,s){let c=r,l=!1,reject=e=>{a.ffprobeReject||={moof:i,reason:e}},u=new Map;for(let e of a.tracks)u.has(e.id)||u.set(e.id,e);for(let d of n.a(e,t.start+t.headerSize,t.end,a.warnings)){if(d.type!==`traf`)continue;let t=null,f,p=null,m=0;for(let h of n.a(e,d.start+d.headerSize,d.end,a.warnings)){let d=h.start+h.headerSize;if(h.type===`tfhd`){if(t=parseTfhd(e,d,h.end,a,r,c,r+h.start),!t)continue;t.trackId===0?reject(`rejects this file: tfhd with track_ID 0`):t.trexMissing||(l=!0),m=t.baseDataOffset,f=u.get(t.trackId),f||a.warnings.push(`fragment for unknown track ${t.trackId}`)}else if(h.type===`tfdt`&&d+8<=h.end)p=e.getUint8(d)===1&&d+12<=h.end?n.i(e,d+4,`tfdt`,r+h.start):e.getUint32(d+4);else if(h.type===`trun`&&d+8<=h.end){if(l?(!t||t.trexMissing)&&reject(`misreads this file: a traf without trex is read as another track`):reject(`rejects this file: trun without a tfhd that has a trex`),!t||!f)continue;let n=f,{fragment:r,dataEnd:u}=parseTrun(e,d,h.end,t,m,a.fileSize,n.warnings,s);r.moofIndex=i,r.baseDts=p,p=null,m=u,c=u,r.trexMissing&&!n.warnings.includes(o)&&n.warnings.push(o),n.fragments.push(r)}}}}function parseSidx(e,t,r){let i=t.start+t.headerSize,a=i<t.end&&e.getUint8(i)===1;if(i+(a?32:24)>t.end)throw new n.t(`corrupt`,`corrupt file: box 'sidx' at ${r} is truncated`);let o=i+12,s=a?n.i(e,o,`sidx`,r):e.getUint32(o),c=a?n.i(e,o+8,`sidx`,r):e.getUint32(o+4);o+=a?16:8;let l=e.getUint16(o+2);o+=4;let u=r+(t.end-t.start),d=u+c,f=0,p=!1,m=[];for(let n=0;n<l&&o+12<=t.end;n++,o+=12){let t=e.getUint32(o);t&2147483648&&(p=!0);let n=t&2147483647;m.push([d,n]),d+=n,f+=e.getUint32(o+4)}return{start:r,end:u,referenceId:e.getUint32(i+4),timescale:e.getUint32(i+8),earliestPts:s,firstOffset:c,coverageEnd:d,durationSum:f,subsegments:m,hierarchical:p}}const s=2**53-1,c=[65536,0,0,0,65536,0,0,0,1<<30];function newMovie(e){return{fileSize:e,brand:null,compatibleBrands:[],hasFtyp:!1,hasMvhd:!1,timescale:1,duration:0,matrix:Int32Array.from(c),tracks:[],chapterTrackIds:new Set,hasMvex:!1,trex:new Map,moofCount:0,topLevel:[],truncated:!1,ffprobeMoofLimit:1/0,ffprobeReject:null,warnings:[]}}function newTrack(){return{id:0,enabled:!1,handler:``,timescale:0,hasMdhd:!1,mdhdDuration:0,matrix:Int32Array.from(c),sampleEntry:``,originalFormat:null,stsdCount:0,width:0,height:0,esdsObjectType:null,hasHvcc:!1,sttsCounts:new Uint32Array,sttsDeltas:new Uint32Array,cttsCounts:null,cttsOffsets:null,dtsShift:0,sampleCount:null,sampleSize:0,overruns:[],edits:[],fragments:[],warnings:[],dv:null,stss:null,stsz:null,stz2:null,stsc:null,stco:null,co64:null}}function children(e,t,r,i=0){return guard(n.a(e,t.start+t.headerSize+i,t.end,r.warnings),r,t.type)}function*guard(e,t,r){for(let i of e){if(i.truncated){if(t.strict)throw new n.t(`truncated`,`incomplete file: moov is truncated`);t.warnings.push(`'${i.type}' overruns '${r}'`)}yield i}}function payload(e){return e.start+e.headerSize}function readMatrix(e,t){let n=new Int32Array(9);for(let r=0;r<9;r++)n[r]=e.getInt32(t+r*4);return n}function normalizeTimescale(e){return e>0&&e<=2147483647?e:1}function tableRef(e){return{start:payload(e),end:e.end}}function parseStts(e,t,r){let i=payload(t);if(i+8>t.end)return;let a=e.getUint32(i+4),o=n.n(a,t.end-i-8,8,`stts`,r.warnings);o<a&&r.overruns.push(`stts`);let s=new Uint32Array(o),c=new Uint32Array(o),l=!1;for(let t=0;t<o;t++)s[t]=e.getUint32(i+8+t*8),c[t]=e.getUint32(i+12+t*8),c[t]>4294487295&&(l=!0);l&&correctLargeDeltas(s,c,r.warnings),r.sttsCounts=s,r.sttsDeltas=c}function correctLargeDeltas(e,t,n){let r=0n,i=0n;for(let a=0;a<e.length;a++){let o=BigInt(e[a]),s=t[a];if(s>4294487295){n.push(`stts delta ${s} clipped to 1`);let e=s|0;s=1,i+=BigInt(e<0?e:1)*o}else i+=BigInt(s)*o;if(r+=BigInt(s)*o,r>i){let e=(r-i)/(o>0n?o:1n),t=BigInt(s)>e?e:BigInt(s-1>>>0);r-=t*o,s=Number(BigInt(s)-t&4294967295n)}t[a]=s}}function parseCtts(e,t,r){let i=payload(t);if(i+8>t.end)return;let a=e.getUint32(i+4),o=n.n(a,t.end-i-8,8,`ctts`,r.warnings);if(o<a&&r.overruns.push(`ctts`),o===0)return;let s=[],c=[],l=0;for(let t=0;t<o;t++){let n=e.getInt32(i+8+t*8),r=e.getInt32(i+12+t*8);n<=0||(s.push(n),c.push(r),t+2<a&&r<0&&(l=Math.max(l,r===-2147483648?2147483647:-r)))}r.cttsCounts=Uint32Array.from(s),r.cttsOffsets=Int32Array.from(c),r.dtsShift=l}function parseElst(e,t,r,i,a){let o=payload(t);if(o+8>t.end)return;let c=e.getUint8(o),l=c===1?20:12,u=e.getUint32(o+4),d=t.end-o-8,f=u*l===d?u:Math.floor(d/l);if(f!==u&&r.warnings.push(`elst declares ${u} entries but its box holds ${f}`),f===0)return;r.edits.length&&(r.warnings.push(`duplicated elst: the last one is used`),r.edits=[]);let p=i.base+t.start;for(let t=0;t<f;t++){let i=o+8+t*l;if(c===1){let t=n.r(e,i+8,`elst`,p),o=e.getBigInt64(i)===-1n;o&&(r.warnings.push(`unknown elst duration: ${t===-1?`the empty edit is ignored`:`the edit lasts to the end`}`),a.ffprobeReject??={moof:-1,reason:`rejects this file: an elst duration of -1`}),r.edits.push({duration:o?t===-1?0:s:n.i(e,i,`elst`,p),mediaTime:t,rate:e.getInt32(i+16)/65536})}else r.edits.push({duration:e.getUint32(i),mediaTime:e.getInt32(i+4),rate:e.getInt32(i+8)/65536})}}function parseEsds(e,t,n){let r=t+4,descriptor=()=>{if(r+2>n)return null;let t=e.getUint8(r++),i=0;for(let t=0;t<4&&r<n;t++){let t=e.getUint8(r++);if(i=i*128+(t&127),!(t&128))break}return[t,i]},i=descriptor();if(i&&i[0]===3){if(r+3>n)return null;let t=e.getUint8(r+2);r+=3,t&128&&(r+=2),t&64&&r<n&&(r+=1+e.getUint8(r)),t&32&&(r+=2),i=descriptor()}return i&&i[0]===4&&r<n?e.getUint8(r):null}function parseStsd(e,r,i,a){let o=payload(r);if(o+8>r.end||(i.stsdCount=e.getUint32(o+4),i.stsdCount===0))return;let s;try{s=n.o(e,o+8,r.end)}catch(e){i.warnings.push(e.message);return}if(s&&(i.sampleEntry=s.type,!(i.handler===`soun`||s.start+86>s.end))){i.width=e.getUint16(s.start+32),i.height=e.getUint16(s.start+34);for(let r of n.a(e,s.start+86,s.end,a.warnings))if(r.type===`esds`)i.esdsObjectType=parseEsds(e,payload(r),r.end);else if(r.type===`hvcC`)i.hasHvcc=!0;else if(r.type===`sinf`)for(let o of n.a(e,payload(r),r.end,a.warnings))o.type===`frma`&&payload(o)+4<=o.end&&(i.originalFormat=t.n(e,payload(o)))}}function parseStbl(e,t,n,r){for(let i of children(e,t,r)){let t=payload(i);switch(i.type){case`stsd`:parseStsd(e,i,n,r);break;case`stts`:parseStts(e,i,n);break;case`ctts`:parseCtts(e,i,n);break;case`stsz`:case`stz2`:t+12<=i.end&&(n.sampleCount=e.getUint32(t+8),n.sampleSize=i.type===`stsz`?e.getUint32(t+4):0),i.type===`stsz`?n.stsz=tableRef(i):n.stz2=tableRef(i);break;case`stss`:n.stss=tableRef(i),t+8<=i.end&&e.getUint32(t+4)>Math.floor((i.end-t-8)/4)&&n.overruns.push(`stss`);break;case`stsc`:n.stsc=tableRef(i);break;case`stco`:n.stco=tableRef(i);break;case`co64`:n.co64=tableRef(i)}}}function parseMdia(e,n,r,i){for(let a of children(e,n,i)){let n=payload(a);if(a.type===`mdhd`&&n+24<=a.end){let t=e.getUint8(n)===1;if(t&&n+32>a.end)continue;r.hasMdhd=!0;let i=e.getUint32(n+(t?20:12));if(r.timescale=normalizeTimescale(i),r.timescale!==i&&r.warnings.push(`invalid mdhd timescale ${i}, using 1`),t){let t=e.getBigUint64(n+24);r.mdhdDuration=t===18446744073709551615n?0:Number(t)}else{let t=e.getUint32(n+16);r.mdhdDuration=t===4294967295?0:t}}else if(a.type===`hdlr`&&n+12<=a.end)r.handler=t.n(e,n+8);else if(a.type===`minf`)for(let t of children(e,a,i))t.type===`stbl`&&parseStbl(e,t,r,i)}}function parseTrak(e,t,n,r){let i=newTrack();i.dv=e;for(let a of children(e,t,r)){let t=payload(a);if(a.type===`tkhd`&&t+84<=a.end){let n=e.getUint8(t)===1;if(n&&t+96>a.end)continue;i.enabled=(e.getUint8(t+3)&1)==1,i.id=e.getUint32(t+(n?20:12)),i.matrix=readMatrix(e,t+(n?52:40))}else if(a.type===`edts`)for(let t of children(e,a,r))t.type===`elst`&&parseElst(e,t,i,r,n);else if(a.type===`mdia`)parseMdia(e,a,i,r);else if(a.type===`tref`){for(let t of children(e,a,r))if(t.type===`chap`)for(let r=payload(t);r+4<=t.end;r+=4)n.chapterTrackIds.add(e.getUint32(r))}}return i}function parseMoov(e,t,r,i,a=0){let o={strict:i,warnings:r.warnings,base:a};for(let i of children(e,t,o)){let t=payload(i);switch(i.type){case`mvhd`:{if(t+24>i.end)break;let n=e.getUint8(t)===1;if(n&&t+84>i.end)break;r.hasMvhd=!0,r.timescale=normalizeTimescale(e.getUint32(t+(n?20:12))),r.duration=n?Number(e.getBigUint64(t+24)):e.getUint32(t+16),t+(n?84:72)<=i.end&&(r.matrix=readMatrix(e,t+(n?48:36)));break}case`trak`:r.tracks.push(parseTrak(e,i,r,o));break;case`mvex`:r.hasMvex=!0;for(let t of children(e,i,o)){let n=payload(t);t.type===`trex`&&n+24<=t.end&&r.trex.set(e.getUint32(n+4),{duration:e.getUint32(n+12),size:e.getUint32(n+16)})}break;case`cmov`:throw new n.t(`unsupported`,`unsupported: compressed movie header (cmov)`)}}}const l=new Set([`moof`,`styp`,`sidx`,`ssix`,`emsg`,`prft`,`free`,`skip`,`uuid`]);function newPrefetch(){return{windows:[],hints:[],next:0,mfraTried:!1}}function prefetched(e,t,n){for(let[r,i]of e.windows)if(t>=r&&t+n<=r+i.byteLength)return new DataView(i.buffer,i.byteOffset+t-r,n);return null}async function prefetchNext(e,t,n,r){for(;t.next<t.hints.length&&t.hints[t.next]<=n;)t.next++;let i=[];for(let n=t.next;n<t.hints.length&&i.length<8;n++)t.hints[n]<e.size&&i.push([t.hints[n],Math.min(r,e.size-t.hints[n])]);if(t.next+=i.length,!i.length)return;let a=await e.readMany(i,4);t.windows=i.map(([e],t)=>[e,new DataView(a[t].buffer,a[t].byteOffset,a[t].byteLength)]),t.windows.every(([,e])=>startsWithFragmentBox(e))||(t.hints=[],t.next=0)}function startsWithFragmentBox(e){return e.byteLength>=8&&e.getUint32(0)>=8&&l.has(t.n(e,4))}function parseTfraOffsets(e,t,r,i,a=2**53-1){for(let o of n.a(e,t,r)){let t=o.start+o.headerSize;if(o.type!==`tfra`||t+16>o.end)continue;let n=e.getUint8(t)===1,r=e.getUint32(t+8),s=(n?16:8)+(r>>4&3)+(r>>2&3)+(r&3)+3,c=Math.min(e.getUint32(t+12),Math.floor((o.end-t-16)/s));for(let r=0;r<c;r++){let o=t+16+r*s,c=n?e.getBigUint64(o+8):BigInt(e.getUint32(o+4));c>0n&&c<BigInt(a)&&i.add(Number(c))}}}async function mfraMoofOffsets(e){try{return await readMfraOffsets(e)}catch(t){if(e.signal?.aborted||t?.name===`AbortError`)throw t;return[]}}async function readMfraOffsets(e){let r=e.size,i=Math.min(r,65536);if(i<16)return[];let a=await e.view(r-i,i,0);if(t.n(a,i-12)!==`mfro`)return[];let o=a.getUint32(i-4);if(o<24||o>Math.min(r,16777216))return[];let s=o<=i?new DataView(a.buffer,a.byteOffset+i-o,o):await e.view(r-o,o,0),c;try{c=n.o(s,0,o)}catch{return[]}if(!c||c.type!==`mfra`)return[];let l=new Set;return parseTfraOffsets(s,c.headerSize,c.end,l,r),[...l].sort((e,t)=>e-t)}function rescaleRound(e,t,n){if(!(n>0))return 0;let r=BigInt(Math.abs(e))*BigInt(t),i=BigInt(n),a=Number((r+i/2n)/i);return e<0?-a:a}function sampleTotals(e){let t=0,n=0;for(let r=0;r<e.sttsCounts.length;r++)t+=e.sttsCounts[r],n+=e.sttsCounts[r]*e.sttsDeltas[r];let r=0;for(let t of e.fragments)r+=t.count;return{moovSamples:t,moovDuration:n,fragmentSamples:r}}function sumBig(e,t,n){let r=0n,i=0n;if(n){for(let t=0;t<e.sttsCounts.length;t++)r+=BigInt(e.sttsCounts[t]),i+=BigInt(e.sttsCounts[t])*BigInt(e.sttsDeltas[t]);i<=0n&&(r=0n,i=0n)}for(let n of e.fragments)t(n.moofIndex,n.trexMissing)&&(r+=BigInt(n.count),i+=BigInt(n.durationSum));return[r,i]}function rateOf(e,t,n){return t<=0n||n<=0n?null:r.a(BigInt(e)*t,n,r.t)}function averageRates(e,t){let n=e.timescale,visible=(e,n)=>e<t.ffprobeMoofLimit&&!n,[i,a]=sumBig(e,()=>!0,!0),[o,s]=sumBig(e,visible,!0),c=e.overruns.includes(`stts`)||e.fragments.some(e=>e.overrun&&visible(e.moofIndex,e.trexMissing))?null:rateOf(n,o,s);return{avg:rateOf(n,i,a),ffprobe:c?r.o(c):null}}function missingMandatoryAtoms(e){let t=e.dv,declared=e=>t&&e&&e.start+8<=e.end?t.getUint32(e.start+4):0,n=declared(e.co64??e.stco),r=e.sttsCounts.length>0||e.overruns.includes(`stts`),i=e.sampleCount??0;return n>0&&(!r||declared(e.stsc)===0||e.sampleSize===0&&i===0)||i>0&&n===0}function editInfo(e,t,n){let r=0,i=0,a=0,o=null,c=(e.cttsOffsets?.[0]??0)+n.moovDuration;for(let n of e.edits){let l=n.duration===s?Math.max(0,c-n.mediaTime):rescaleRound(n.duration,e.timescale,t);i+=l,n.mediaTime===-1?o||(r+=l):(a++,o||={mediaTime:n.mediaTime,duration:l,rate:n.rate})}return{emptyBefore:r,firstMedia:o,editSum:i,mediaEdits:a}}function trackTiming(e,t,n,r){let i=e.mdhdDuration;n.moovDuration>0&&(i=Math.min(i,n.moovDuration));let a=e.edits.length>0&&n.moovSamples>0;a&&(i=Math.min(i,r.editSum));let o=n.moovDuration,s=null,c=timeOffsetOf(e,t);for(let t of e.fragments)t.baseDts!==null&&(o=t.baseDts),s===null&&t.count>0&&(s=o-c+(t.cts?t.cts[0]:0)),o+=t.durationSum,o>i&&(i=o);let l=completeSidxEnd(e,t);l!==null&&l>i&&(i=l);let u=null;return u=a?r.emptyBefore:n.moovSamples>0?e.cttsOffsets&&e.cttsOffsets.length?e.cttsOffsets[0]:0:s,{durationTs:i,startPts:u}}function completeSidxEnd(e,t){if(t.ffprobeMoofLimit===1/0)return null;let n=0,r=null;for(let i of t.topLevel){if(i.type===`moof`&&++n>t.ffprobeMoofLimit)break;let a=i.sidx;a&&!a.hierarchical&&a.referenceId===e.id&&a.timescale===e.timescale&&(r=a.earliestPts+a.durationSum)}return r}function timeOffsetOf(e,t){let n=0,r=0,i=0;return e.edits.forEach((e,t)=>{t===0&&e.mediaTime===-1?(n=e.duration,i=1):t===i&&e.mediaTime>=0&&(r=e.mediaTime)}),!n&&!r?0:r-rescaleRound(n,e.timescale,t.timescale)}function runsOf(e,t,n){let r=new Float64Array(e.length+1),i=new Float64Array(e.length),a=0,o=0;for(let s=0;s<e.length&&o<n;s++)e[s]<=0||(r[a]=o,i[a]=t[s],o+=Math.min(e[s],n-o),a++);return r[a]=o,{count:a,starts:r,values:i,total:o}}function runFinder(e){let t=e.starts,n=0;return r=>{if(r>=t[n]&&r<t[n+1])return n;let i=0,a=e.count-1;for(;i<a;){let e=Math.ceil((i+a)/2);t[e]<=r?i=e:a=e-1}return n=i,i}}function keyIndex(e,t){let n=e.stss;if(!n||!e.dv)return{all:!0,list:new Float64Array};let r=e.dv,i=n.start+8<=n.end?Math.min(r.getUint32(n.start+4),Math.floor((n.end-n.start-8)/4)):0;if(i===0)return{all:!1,list:Float64Array.of(0)};let a=+(r.getUint32(n.start+8)>0),o=new Float64Array(i),s=0,c=-1;for(let e=0;e<i;e++){let i=r.getUint32(n.start+8+e*4)-a;if(i<=c||i>=t)break;o[s++]=i,c=i}return{all:!1,list:o.subarray(0,s)}}function nextKeyOf(e,t,n){if(n>=t)return-1;if(e.all)return n;let r=e.list,i=0,a=r.length;for(;i<a;){let e=Math.floor((i+a)/2);r[e]<n?i=e+1:a=e}return i<r.length?r[i]:-1}function prevKeyOf(e,t){if(t<0)return-1;if(e.all)return t;let n=e.list,r=0,i=n.length;for(;r<i;){let e=Math.floor((r+i)/2);n[e]<=t?r=e+1:i=e}return r>0?n[r-1]:-1}function keep(e,t,n){let r=n;r<=0||e.len===0&&(e.first=t,e.last=t,e.len=1,r--,r===0)||((e.len>=2&&e.last!==e.first||r>=2&&t!==e.first)&&(e.bad=!0),e.last=t,e.len+=r)}function keepRange(e,t,n,r,i){let a=r,o=Math.min(i,t.total-r),s=0;for(;o>0&&!e.bad;){let r=n(a),i=Math.min(t.starts[r+1]-a,o);keep(e,t.values[r],i),a+=i,o-=i,s++}return s}function keptRate(e,t){return e.bad||e.len===0||!(e.first>0)?null:r.a(t,e.first,r.t)}function ffprobeStage1Rate(e,t,n,i,a){let o=Math.min(n,e.sampleCount??0);if(o<=0||e.sttsCounts.length===0||e.overruns.length>0)return null;let s=e.timescale,c=runsOf(e.sttsCounts,e.sttsDeltas,o),l=runFinder(c),u={len:0,first:0,last:0,bad:!1};if(e.edits.length===0)return keepRange(u,c,l,0,o),keptRate(u,s);if(!e.edits.some(e=>e.mediaTime!==-1))return null;let d=!0;for(let e=1;e<c.count&&d;e++)d=c.values[e]===c.values[0];if(d)return c.values[0]>0?r.a(s,c.values[0],r.t):null;let f=Math.min(i,2e6),p=0,m=!1,spend=e=>(p+=e,p>f&&(m=!0),m),h=new Float64Array(c.count+1);for(let e=0;e<c.count;e++)h[e+1]=h[e]+(c.starts[e+1]-c.starts[e])*c.values[e];let dtsAt=e=>{let t=l(e);return h[t]+(e-c.starts[t])*c.values[t]},durAt=e=>c.values[l(e)],g=!!e.cttsCounts&&e.cttsCounts.length>0,_=g?runsOf(e.cttsCounts,e.cttsOffsets,o):null,v=_?runFinder(_):null,offAt=e=>_&&e<_.total?_.values[v(e)]:0,y=keyIndex(e,o),nextKey=e=>nextKeyOf(y,o,e),prevKey=e=>prevKeyOf(y,e),b=e.dtsShift,firstAtOrAbove=(e,t)=>{let n=0,r=t;for(;n<r;){let t=Math.floor((n+r)/2);dtsAt(t)>=e?r=t:n=t+1}return n},search=(e,t)=>{let n=b>0?e-b:e,r=-1,i=o;for(dtsAt(o-1)-b<n&&(r=o-1);i-r>1;){let e=Math.floor((r+i)/2),t=dtsAt(e)-b;t>=n&&(i=e),t<=n&&(r=e)}let a=t?r:prevKey(r);if(a>0){let e=firstAtOrAbove(dtsAt(a),a);if(e<a){if(t)a=e;else{let t=nextKey(e);t>=0&&t<a&&(a=t)}}}if(g&&a>=0){let e=prevKey(a);for(;e>=0&&!spend(1)&&dtsAt(e)-b+offAt(e)>n;)e=prevKey(e-1);a=e}return a},x=0,S=!1;for(let n of e.edits){let r=n.mediaTime;if(!S&&r===-1)continue;if(S=!0,spend(64))break;let i=rescaleRound(n.duration,e.timescale,t.timescale),a=search(r,!1);if(a<0&&!m&&(a=search(r,!0)),m)break;a<0&&(a=0,x=0),g&&(x=a);let s=-1;if(g){let e=!1;for(let t=nextKey(a);t>=0&&!spend(1);t=nextKey(t+1)){let n=t+1<o?durAt(t):i;if(dtsAt(t)+offAt(t)+n>=i+r){if(e){s=t;break}e=!0}}if(m)break}else{let e=a,t=o;for(;e<t;){let n=Math.floor((e+t)/2);(n+1<o?dtsAt(n+1):dtsAt(o-1)+i)>=i+r?t=n:e=n+1}e<o&&(s=nextKey(e))}let d=s<0?o-a:s-a+1,f=Math.min(d,o-x);if(f>0&&(spend(keepRange(u,c,l,x,f)),x+=f),u.bad)return null;if(m)break}return m?(a?.push(`r_frame_rate not reproduced: edit list walk limit reached`),null):keptRate(u,s)}function cutRuns(e,t,n){let r=[],i=[],a=n;for(let n=0;n<e.length&&a>0;n++){let o=Math.min(e[n],a);o<=0||(r.push(o),i.push(t[n]),a-=o)}return{counts:r,values:i}}function timelineSegments(e,t){let n=[];if(t>0){let r=cutRuns(e.sttsCounts,e.sttsDeltas,t),i=e.cttsCounts&&e.cttsOffsets?cutRuns(e.cttsCounts,e.cttsOffsets,t):null;n.push({durations:{counts:r.counts,deltas:r.values},cts:i?{counts:i.counts,offsets:i.values}:null})}for(let t of e.fragments){let e=t.complete;n.push({baseDts:t.baseDts,durations:t.durations?t.durations.subarray(0,e):{counts:[e],deltas:[t.defaultDuration]},cts:t.cts?t.cts.subarray(0,e):null})}return n}function presentationWindow(e,t,n){let r=t.firstMedia;if(!r)return e.edits.length&&n.push(`edit list has no media edit`),null;t.mediaEdits>1&&n.push(`edit list has ${t.mediaEdits} media edits, only the first is applied`),r.rate!==1&&n.push(`edit rate ${r.rate} is not applied`);let i=e.fragments.length>0||r.duration<=0?r.mediaTime:r.mediaTime+r.duration;return{start:r.mediaTime,end:i}}function moovSamplesInFile(e,t,n){let r=e.dv,i=e.co64??e.stco,a=e.stsz??e.stz2;if(!r||!i||!a||!e.stsc||i.start+8>i.end||e.stsc.start+8>e.stsc.end||a.start+12>a.end)return null;let o=!!e.co64,s=Math.min(r.getUint32(i.start+4),Math.floor((i.end-i.start-8)/(o?8:4))),c=Math.min(r.getUint32(e.stsc.start+4),Math.floor((e.stsc.end-e.stsc.start-8)/12)),l=e.stsz?r.getUint32(a.start+4):0,u=e.stz2?r.getUint8(a.start+7):32,d=Math.min(r.getUint32(a.start+8),n),f=a.end-a.start-12,sizeOf=e=>{if(l)return l;let t=a.start+12;if(u===32)return(e+1)*4<=f?r.getUint32(t+e*4):0;if(u===16)return(e+1)*2<=f?r.getUint16(t+e*2):0;if(u===8)return e<f?r.getUint8(t+e):0;let n=e>>1<f?r.getUint8(t+(e>>1)):0;return e&1?n&15:n>>4},p=0,m=0,h=0,g=0;for(let n=0;n<s&&h<d;n++){for(;g+1<c&&r.getUint32(e.stsc.start+8+(g+1)*12)<=n+1;)g++;let a=c?r.getUint32(e.stsc.start+12+g*12):0,s=o?Number(r.getBigUint64(i.start+8+n*8)):r.getUint32(i.start+8+n*4);for(let e=0;e<a&&h<d;e++,h++){let e=sizeOf(h);s<t&&p++,s+e<=t&&m===h&&m++,s+=e}}return{present:p,complete:m}}function displayRotation(e,t){let n=[16n,16n,30n],r=new Int32Array(9);for(let i=0;i<3;i++)for(let a=0;a<3;a++){let o=0n;for(let r=0;r<3;r++)o+=BigInt(e[i*3+r])*BigInt(t[r*3+a])>>n[r];r[i*3+a]=Number(BigInt.asIntN(32,o))}if(r[0]===65536&&r[4]===65536&&r[8]===1<<30&&!r[1]&&!r[2]&&!r[3]&&!r[5]&&!r[6]&&!r[7])return 0;let i=r[0]/65536,a=r[1]/65536,o=Math.hypot(i,r[3]/65536),s=Math.hypot(a,r[4]/65536);return o===0||s===0?0:Math.trunc(-(Math.atan2(a/s,i/o)*180/Math.PI))||0}const u=16777216,d=65536;function isAbort(e,t){return t.signal?.aborted===!0||e?.name===`AbortError`}function containerOf(e){return e.brand===`qt `||!e.hasFtyp&&e.topLevel.length>0?`mov`:`mp4`}async function readMoov(e,t,r,i){let a=e.size,o=t.start+t.size>a;if(!o&&t.size>268435456)throw new n.t(`too-large`,`unsupported: moov larger than 256 MiB`);let s=o?Math.min(a-t.start,u):t.size,c=await e.view(t.start,s,0),l=i?new DataView(c.buffer.slice(c.byteOffset,c.byteOffset+s)):c,d=n.o(l,0,l.byteLength);if(!d)throw new n.t(`truncated`,`incomplete file: moov is truncated`);parseMoov(l,d,r,o,t.start),o&&r.warnings.push(`moov size exceeds the file; parsed what is there`)}async function walk(e,t,r){let i=e.size,a=0,o=t.readAhead.head,s=!1,c=0,l=!1,u=newPrefetch(),look=async(t,n,r)=>prefetched(u,t,n)??e.view(t,n,r);for(;a+8<=i;){if(e.checkAbort(),++c>4e6){r.warnings.push(`too many top-level boxes`);break}let f=l&&!s&&i-a<=16777216?i-a:o,p=await look(a,Math.min(16,i-a),f),m;try{m=n.o(p,0,i-a,a)}catch(e){if(!s)throw e;r.warnings.push(`ignored trailing data at ${a}: ${e.message}`);break}if(!m)break;let h={...m,start:a,end:Math.min(a+m.size,i)},g=a+m.size,_=m.truncated&&s&&h.type!==`mdat`&&h.type!==`moof`;m.truncated&&(r.truncated=!0,r.warnings.push(_?`ignored trailing data at ${a}: not a box`:`'${h.type}' at ${a} is truncated`));let v={type:h.type,start:a,end:h.end,sidx:null};if(r.topLevel.push(v),_)break;if(h.type===`ftyp`){let t=await e.view(a,Math.min(h.size,1024)),n=h.headerSize;if(n+4<=t.byteLength){r.hasFtyp=!0,r.brand=String.fromCharCode(t.getUint8(n),t.getUint8(n+1),t.getUint8(n+2),t.getUint8(n+3));for(let e=n+8;e+4<=t.byteLength;e+=4)r.compatibleBrands.push(String.fromCharCode(t.getUint8(e),t.getUint8(e+1),t.getUint8(e+2),t.getUint8(e+3)))}}else if(h.type===`moov`)s?r.warnings.push(`ignored a second moov at ${a}`):(r.moov=[a,m.size],await readMoov(e,h,r,t.codecConfig),s=!0);else if(h.type===`moof`){if(!s)throw new n.t(`corrupt`,`corrupt file: movie fragment (moof) before moov`);if(h.size>67108864)throw new n.t(`too-large`,`corrupt file: moof larger than 64 MiB at ${a}`);let c=Math.min(h.size+16,i-a),l=await look(a,c,0),f=n.o(l,0,Math.min(h.size,l.byteLength));f&&parseMoof(l,f,a,r.moofCount,r,t.maxExpandedSamples),r.moofCount++;let p=0;try{let e=n.o(l,h.size,l.byteLength);e&&e.type===`mdat`&&(p=e.size)}catch{p=0}o=p<=d?t.readAhead.fragment:Math.min(65536,Math.max(1024,2*h.size+64)),p>d&&(!u.hints.length&&!u.mfraTried&&(i-a)/(h.size+p)>16&&(u.mfraTried=!0,u.hints=await mfraMoofOffsets(e)),u.next<u.hints.length&&!prefetched(u,a+h.size+p,16)&&await prefetchNext(e,u,a,o)),t.onProgress&&r.moofCount%64==0&&t.onProgress({phase:`fragments`,done:a,total:i})}else if(h.type===`sidx`&&!m.truncated){let e=await look(a,h.size,0),t=n.o(e,0,e.byteLength);t&&(v.sidx=parseSidx(e,t,a)),v.sidx&&v.sidx.subsegments.length>1&&!u.hints.length&&(u.hints=v.sidx.subsegments.map(([e])=>e))}else if(h.type===`mfra`)break;l=h.type===`mdat`,a=g}if(!s)throw new n.t(`no-header`,`incomplete file: no moov`)}async function emulateFfprobeExtent(e,t){let n=e.size,r=new Set(t.tracks.map(e=>e.id)),i=!1,a=!1,o=!1,s=null,c=0;for(let l of t.topLevel){if(l.type===`moof`)c++;else if(l.type===`moov`)i=!0;else if(l.type===`mdat`&&l.end-l.start>8)a=!0;else if(l.type===`sidx`&&i&&l.sidx&&!l.sidx.hierarchical&&r.has(l.sidx.referenceId)){let t=l.sidx.coverageEnd===n;!t&&n>=4&&(s===null&&(s=(await e.view(n-4,4,0)).getUint32(0)),t=l.sidx.coverageEnd===n-s),t&&l.sidx.firstOffset===0&&(o=!0)}if(i&&a&&(o||l.end===n)){t.ffprobeMoofLimit=c;return}}}function layoutOf(e){let t=1/0,n=!1,r=!1;for(let i of e.topLevel)i.type===`mdat`&&(t=Math.min(t,i.start)),n||=i.type===`moof`,r||=!n&&i.type===`sidx`;let i=e.moov,a=i?i[0]:1/0;if(a===t)return null;let o=e.hasMvex?`fragmented`:t<a?`moov-at-end`:`faststart`;return{kind:o,moovOffset:i?a:null,moovSize:i?i[1]:null,sidx:r,emptyMoov:o===`fragmented`&&e.tracks.every(t=>!isVideoTrack(t,e)||!t.sampleCount)}}function isVideoTrack(e,t){return t.chapterTrackIds.has(e.id)?!1:e.handler===`vide`||e.handler!==`soun`&&isVideoFourcc(e.originalFormat??e.sampleEntry)}const f=[`presentedFrames`,`minFps`,`maxFps`,`medianFrameInterval`,`isVfr`,`vfrRatio`,`distinctDeltas`,`duplicateTimestamps`,`nominalFps`,`dominantFps`,`timestampsQuantized`];function buildVideoTrack(t,n,i,a,o){let s=e.l(a.reportedId),c=s.warnings;a.reportedId!==t.id&&c.push(`duplicate track_ID ${t.id}: reported as ${a.reportedId}`),c.push(...t.warnings);let l=t.handler===`auxv`;l&&c.push(`auxiliary video track (handler 'auxv')`);let u=missingMandatoryAtoms(t);u&&c.push(`missing mandatory sample tables: ffprobe ignores the samples and timing of this track`);let d=t.hasMdhd?t.timescale:n.timescale;t.hasMdhd||(c.push(`no mdhd: using the movie timescale`),t.timescale=d),s.fourccOrCodecId=t.sampleEntry,s.codecName=codecNameFor(t.originalFormat??t.sampleEntry,t.esdsObjectType,t.hasHvcc),t.originalFormat&&c.push(`encrypted: ${t.sampleEntry} of ${t.originalFormat}`),t.stsdCount>1&&c.push(`${t.stsdCount} sample descriptions, first used`),s.width=t.width,s.height=t.height,s.rotation=displayRotation(t.matrix,n.matrix),s.enabled=t.enabled,s.timescale=d,i.codecConfig&&(s.codecConfig={family:`isobmff-moov`,moov:t.dv,trak:n.tracks.indexOf(t)});let p=sampleTotals(t),m=n.truncated,h=0;for(let e of t.fragments)h+=e.present;let g=p.moovSamples+p.fragmentSamples,_=p.moovSamples+h;s.frames=_,s.isStill=_<=1,p.moovSamples>0&&t.fragments.length>0&&c.push(`hybrid fragmented file: moov holds ${p.moovSamples} of ${g} samples`),_<g&&c.push(`truncated: ${g-_} of ${g} samples missing`);let v=averageRates(t,n);s.avgFps=v.avg,s.avgFpsFfprobe=a.ffprobeFails?null:v.ffprobe,s.avgFpsFfprobe!==null&&s.avgFpsFfprobe!==r.o(v.avg)&&c.push(`ffprobe reads part of the fragments: avg_frame_rate ${s.avgFpsFfprobe}`),v.ffprobe===null&&!a.ffprobeFails&&g>0&&c.push(`avg_frame_rate of ffprobe is not reproduced: its header values are incomplete or overrun a box`);let y=!o||a.ffprobeFails||u?null:ffprobeStage1Rate(t,n,p.moovSamples,i.maxExpandedSamples,c);s.rFpsFfprobe=y?r.o(y):null;let b=editInfo(t,n.timescale,p);if(!u){let e=trackTiming(t,n,p,b);s.durationSec=e.durationTs/d,s.startSec=e.startPts===null?null:e.startPts/d}let x=p.moovSamples;if(t.sampleCount!==null&&t.sampleCount<x&&(c.push(`stts describes ${x} samples but the sample size table holds ${t.sampleCount}`),x=t.sampleCount),u||!o)return s.presentedFrames=0,finishProvenance(s),{result:s,enabled:t.enabled,auxiliary:l};if(m&&x>0){let e=moovSamplesInFile(t,n.fileSize,p.moovSamples);e&&e.complete<x&&(c.push(`truncated: ${e.complete} of ${x} samples complete`),x=e.complete)}let S=presentationWindow(t,b,c);S&&!t.cttsCounts&&!t.fragments.length&&S.start<=0&&(S.end<=S.start||S.end>=p.moovDuration)&&(S=null);let C=o({segments:timelineSegments(t,x),timescale:d,editWindow:S,maxExpandedSamples:i.maxExpandedSamples});c.push(...C.warnings);for(let e of f)s[e]=C[e];return C.presentedAvgFps&&(s.avgFps=C.presentedAvgFps),s.duplicateTimestamps>0&&c.push(`${s.duplicateTimestamps} duplicate timestamps`),finishProvenance(s),C.presentedAvgFps&&(s.provenance.avgFps=`exact`),{result:s,enabled:t.enabled,auxiliary:l,profile:C.profile}}function finishProvenance(e){let t=e.provenance;for(let e of[`codec`,`dimensions`,`rotation`,`frames`,`avgFps`])t[e]=`header`;e.durationSec!==null&&(t.durationSec=`header`),e.startSec!==null&&(t.startSec=`header`),e.presentedFrames!==null&&(t.presentedFrames=`exact`),e.isVfr!==null&&(t.minFps=`exact`,t.maxFps=`exact`,t.isVfr=`exact`,t.duplicateTimestamps=`exact`,t.medianFrameInterval=`exact`),e.nominalFps&&(t.nominalFps=`exact`),e.dominantFps&&(t.dominantFps=`exact`)}function pickPrimary(e){let t=null,score=e=>(e.result.frames??0)>1?e.auxiliary?.5:e.enabled?2:1:0;for(let n of e)(!t||score(n)>score(t)||score(n)===score(t)&&(n.result.frames??0)>(t.result.frames??0))&&(t=n);return t?t.result.trackId:null}function formatDuration(e,t){let n=2**53-1,r=n,i=n,a=-n,o=-n,s=-n,c=-n;for(let n of e.tracks){if(!n.hasMdhd)continue;let l=t.has(n)||n.handler===`soun`;if(missingMandatoryAtoms(n)){let e=rescaleRound(n.mdhdDuration,1e6,9e4);l?s=Math.max(s,e):c=Math.max(c,e);continue}let u=sampleTotals(n),d=trackTiming(n,e,u,editInfo(n,e.timescale,u)),f=rescaleRound(d.durationTs,1e6,n.timescale);if(d.startPts!==null){let e=rescaleRound(d.startPts,1e6,n.timescale);l?(r=Math.min(r,e),a=Math.max(a,e+f)):(i=Math.min(i,e),o=Math.max(o,e+f))}l?s=Math.max(s,f):c=Math.max(c,f)}return(r===n||r>i&&r-i<1e6)&&(r=i),(a===-n||a<o&&o-a<1e6)&&(a=o),(s===-n||s<c&&c-s<1e6)&&(s=c),r!==n&&a!==-n&&a>=r&&(s=Math.max(s,a-r)),s>0?s/1e6:null}function reportedIds(e){let t=new Map,n=new Set,r=e.reduce((e,t)=>Math.max(e,t.id),0)+1;for(let i of e)n.has(i.id)?t.set(i,r++):(n.add(i.id),t.set(i,i.id));return t}Object.defineProperty(exports,"S",{enumerable:!0,get:function(){return parseSidx}}),Object.defineProperty(exports,"_",{enumerable:!0,get:function(){return sampleTotals}}),Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return containerOf}}),Object.defineProperty(exports,"b",{enumerable:!0,get:function(){return newMovie}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return isAbort}}),Object.defineProperty(exports,"d",{enumerable:!0,get:function(){return pickPrimary}}),Object.defineProperty(exports,"f",{enumerable:!0,get:function(){return readMoov}}),Object.defineProperty(exports,"g",{enumerable:!0,get:function(){return rescaleRound}}),Object.defineProperty(exports,"h",{enumerable:!0,get:function(){return editInfo}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return buildVideoTrack}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return isVideoTrack}}),Object.defineProperty(exports,"m",{enumerable:!0,get:function(){return walk}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return 268435456}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return emulateFfprobeExtent}}),Object.defineProperty(exports,"p",{enumerable:!0,get:function(){return reportedIds}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return u}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return formatDuration}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return 67108864}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return layoutOf}}),Object.defineProperty(exports,"v",{enumerable:!0,get:function(){return trackTiming}}),Object.defineProperty(exports,"x",{enumerable:!0,get:function(){return parseMoof}}),Object.defineProperty(exports,"y",{enumerable:!0,get:function(){return parseTfraOffsets}});
@@ -0,0 +1 @@
1
+ const e=[`apcn`,`apch`,`dvpp`,`dvcp`,`jpeg`];function u16(e,t){return e[t]<<8|e[t+1]}function u32(e,t){return(e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3])>>>0}function i32(e,t){return e[t]<<24|e[t+1]<<16|e[t+2]<<8|e[t+3]}function fourccAt(e,t){return String.fromCharCode(e[t],e[t+1],e[t+2],e[t+3])}function*boxes(e,t,n,r=!1){let i=t;for(;i+8<=n;){let t=u32(e,i),a=fourccAt(e,i+4),o=8;if(t===1){if(i+16>n||!r&&u32(e,i+8)!==0)return;t=u32(e,i+8)*2**32+u32(e,i+12),o=16}else t===0&&(t=n-i);if(r&&a===`uuid`&&(o+=16),t<o||t>2**53-1)return;let s=Math.min(i+t,n);yield{type:a,start:i,end:s,payload:i+o},i+=t}}function sampleEntries(t){let n=[],r=boxes(t,0,t.length).next();if(r.done||r.value.type!==`stsd`)return n;let i=r.value;if(i.payload+8>i.end)return n;let a=u32(t,i.payload+4),o=0,s=``;for(let r of boxes(t,i.payload+8,i.end)){if(o++>=a)break;if(s||=r.type,r.type!==s&&!e.includes(s)&&(s!==`AV1x`||r.type!==`AVup`))continue;let i={type:r.type,children:[]};if(n.push(i),!(r.start+86>r.end))for(let e of boxes(t,r.start+86,r.end)){if(e.type===`sinf`)for(let n of boxes(t,e.payload,e.end))n.type===`frma`&&n.payload+4<=n.end&&(i.type=fourccAt(t,n.payload));i.children.push({type:e.type,start:e.payload,end:e.end})}}return n}const live=e=>ArrayBuffer.isView(e)&&e.buffer.byteLength>0,absentOrLive=e=>e==null||live(e);function lastChild(e,t,n){let r;if(t)for(let i of boxes(e,t.payload,t.end,!0))i.type===n&&(r=i);return r}function moovBoxes(e,t){let n=new Uint8Array(e.buffer,e.byteOffset,e.byteLength),cut=e=>e?n.subarray(e.start,e.end):null,r=boxes(n,0,n.length,!0).next().value,i,a=0;if(r?.type===`moov`){for(let e of boxes(n,r.payload,r.end,!0))if(e.type===`mvhd`)i=e;else if(e.type===`trak`&&a++===t)return{stsd:cut(lastChild(n,lastChild(n,lastChild(n,lastChild(n,e,`mdia`),`minf`),`stbl`),`stsd`)),tkhd:cut(lastChild(n,e,`tkhd`)),mvhd:cut(i)}}return null}function isoConfig(e){let t=e.family===`isobmff`?e:e.family===`isobmff-moov`&&live(e.moov)?moovBoxes(e.moov,e.trak):null;return t&&live(t.stsd)&&absentOrLive(t.tkhd)&&absentOrLive(t.mvhd)?{bytes:t.stsd,entries:sampleEntries(t.stsd),tkhd:t.tkhd,mvhd:t.mvhd}:null}function firstBox(e,t){return e?.children.find(e=>e.type===t)??null}function boxPayload(e){if(!e)return null;let t=boxes(e,0,e.length).next();return t.done?null:{start:t.value.payload,end:t.value.end}}function vint(e,t,n,r){if(t>=n)return null;let i=e[t],a=1;for(;a<=8&&!(i&128>>a-1);)a++;if(a>8||t+a>n)return null;let o=r?i:i&255>>a,s=o===255>>a;for(let n=1;n<a;n++)o=o*256+e[t+n],s&&=e[t+n]===255;return[!r&&s?-1:o,a]}function*elements(e,t,n){let r=t;for(;r<n;){let t=vint(e,r,n,!0);if(!t)return;let i=vint(e,r+t[1],n,!1);if(!i||i[0]<0)return;let a=r+t[1]+i[1],o=Math.min(a+i[0],n);yield{id:t[0],start:a,end:o},r=a+i[0]}}function elementUint(e,t){if(!t||t.end===t.start||t.end-t.start>8)return null;let n=0;for(let r=t.start;r<t.end;r++)n=n*256+e[r];return n}function children(e,t,n=new Map){for(let r of elements(e,t.start,t.end))(r.id!==21936||!n.has(r.id))&&n.set(r.id,r);return n}function codecIdAt(e,t){let n=``;for(let r=t.start;r<t.end&&r<t.start+64&&e[r];r++)n+=String.fromCharCode(e[r]);return n}function matroskaConfig(e){let t=e.family===`matroska`?e.trackEntry:null;if(!live(t))return null;let n={bytes:t,codecId:``,codecPrivate:null,video:new Map,colour:new Map,mappings:[]};for(let e of elements(t,0,t.length))e.id===134?n.codecId=codecIdAt(t,e):e.id===25506?n.codecPrivate=e:e.id===224?children(t,e,n.video):e.id===16868&&n.mappings.push(children(t,e));let r=n.video.get(21936);return r&&(n.colour=children(t,r)),n}const t=new Set([100,110,122,244,44,83,86,118,128,138,139,134,135,144]),n=[0,1,1,1,12,11,10,11,16,11,40,33,24,11,20,11,32,11,80,33,18,11,15,11,64,33,160,99,4,3,3,2,2,1],r=RangeError();function unescapeRbsp(e){let t=new Uint8Array(e.length),n=0,r=0;for(let i of e)r>=2&&i===3?r=0:(t[n++]=i,r=i===0?r+1:0);return t.subarray(0,n)}function bitReader(e,t=0){let n=t*8,r=e.length*8,bit=()=>{check(n<r);let t=e[n>>3]>>7-(n&7)&1;return n++,t},bits=e=>{let t=0;for(let n=0;n<e;n++)t=t*2+bit();return t},skip=e=>{check(n+e<=r),n+=e},ue=(e=4294967294)=>{let t=0;for(;bit()===0;)check(++t<32);let n=2**t-1+bits(t);return check(n<=e),n},se=()=>{let e=ue();return e&1?(e+1)/2:e?-e/2:0};return{bit,bits,skip,ue,se}}function check(e){if(!e)throw r}function readVui(e){let{bit:t,bits:r,skip:i}=e,a={sar:null,fullRange:null,colour:null};if(t()){let e=r(8),t=e===255?[r(16),r(16)]:[n[e*2]??0,n[e*2+1]??0];a.sar=t[0]>0&&t[1]>0?[t[0],t[1]]:null}return t()&&i(1),t()&&(i(3),a.fullRange=t()===1,t()&&(a.colour=[r(8),r(8),r(8)])),a}function skipH264ScalingList(e,t){let{se:n}=e,r=8,i=8;for(let e=0;e<t;e++)i!==0&&(i=(r+n()+256)%256),r=i===0?r:i}function parseH264Sps(e){try{let n=bitReader(unescapeRbsp(e),1),{bit:r,bits:i,skip:a,ue:o,se:s}=n,c=i(8);a(16),o(31);let l=8;if(t.has(c)){let e=o(3);if(e===3&&a(1),l=o(6)+8,check(o(6)+8===l),a(1),r())for(let t=0;t<(e===3?12:8);t++)r()&&skipH264ScalingList(n,t<6?16:64)}o(12);let u=o(2);if(u===0)o(12);else if(u===1){a(1),s(),s();let e=o(255);for(let t=0;t<e;t++)s()}if(o(16),a(1),o(),o(),r()||a(1),a(1),r())for(let e=0;e<4;e++)o();return{bitDepth:l,vui:r()?readVui(n):null}}catch(e){if(e===r)return null;throw e}}function skipProfileTierLevel(e,t){let{bit:n,skip:r}=e;r(88),r(8);let i=[];for(let e=0;e<t;e++)i.push([n(),n()]);t>0&&r(2*(8-t));for(let[e,t]of i)e&&r(88),t&&r(8)}function skipHevcScalingListData(e){let{bit:t,ue:n,se:r}=e;for(let e=0;e<4;e++)for(let i=0;i<6;i+=e===3?3:1)if(t()){let t=Math.min(64,1<<4+(e<<1));if(e>1){let e=r();check(e>=-7&&e<=247)}for(let e=0;e<t;e++)r()}else{let t=n();check(i-t*(e===3?3:1)>=0)}}function skipShortTermRefPicSets(e,t){let{bit:n,skip:r,ue:i}=e,a=[];for(let e=0;e<t;e++)if(e>0&&n()){r(1),i(32767);let t=0;for(let r=0;r<=a[e-1];r++)(n()||n())&&t++;check(t<32),a.push(t)}else{let e=i(15),t=i(15);for(let n=0;n<e+t;n++)i(32767),r(1);a.push(e+t)}}function parseHevcSps(e){try{let t=bitReader(unescapeRbsp(e),2),{bit:n,bits:r,skip:i,ue:a}=t;i(4);let o=r(3);check(o<7),i(1),skipProfileTierLevel(t,o),a(15);let s=a(3);if(s===3&&i(1),a(),a(),n())for(let e=0;e<4;e++)a();let c=a(8)+8,l=a(8)+8;check(s===0||l===c);let u=a(12)+4,d=n();for(let e=d?0:o;e<=o;e++)a(),a(),a();for(let e=0;e<6;e++)a();if(n()&&n()&&skipHevcScalingListData(t),i(2),n()&&(i(8),a(),a(),i(1)),skipShortTermRefPicSets(t,a(64)),n()){let e=a(32);for(let t=0;t<e;t++)i(u+1)}return i(2),{bitDepth:c,vui:n()?readVui(t):null}}catch(e){if(e===r)return null;throw e}}function avcConfigSps(e,t){let n=t.end-t.start>=8&&e[t.start+5]&31?u16(e,t.start+6):-1;return n>=0&&t.start+8+n<=t.end?parseH264Sps(e.subarray(t.start+8,t.start+8+n)):null}function hevcConfigSps(e,t){let n=t.start+23;for(let r=0,i=t.end-t.start>=23?e[t.start+22]:0;r<i&&n+3<=t.end;r++){let r=e[n]&63,i=u16(e,n+1);n+=3;for(let a=0;a<i&&n+2<=t.end;a++){let i=u16(e,n);if(n+2+i>t.end)return null;if(r===33)return parseHevcSps(e.subarray(n+2,n+2+i));n+=2+i}}return null}const i=new Set([66,77,88]),hex2=e=>e.toString(16).padStart(2,`0`),dec2=e=>String(e).padStart(2,`0`);function reverseBits32(e){let t=0;for(let n=0;n<32;n++)t=t*2+(e&1),e>>>=1;return t}function avcFacts(e,t,n){if(t.end-t.start<6)return null;let r=e[t.start+1],a=avcConfigSps(e,t),o=t.start+6;for(let n=0,r=e[t.start+5]&31;n<r&&o+2<=t.end;n++)o+=2+u16(e,o);if(o<t.end)for(let n=0,r=e[o++];n<r&&o+2<=t.end;n++)o+=2+u16(e,o);let s=!i.has(r);return{profile:r,bitDepth:a?.bitDepth??(s?o+4<=t.end?(e[o+1]&7)+8:null:8),codecString:`${n}.${hex2(r)}${hex2(e[t.start+2])}${hex2(e[t.start+3])}`,sps:a}}function hevcFacts(e,t,n){if(t.end-t.start<23)return null;let r=t.start,i=e[r+1]>>6,a=e[r+1]&31,o=u32(e,r+2),s=a;for(let e=1;!s&&e<32;e++)o>>>31-e&1&&(s=e);let c=``;for(let t=5,n=!1;t>=0;t--){let i=e[r+6+t];(i||n)&&(c=`.${i.toString(16)}${c}`,n=!0)}let l=`${n}.${[``,`A`,`B`,`C`][i]}${a}.${reverseBits32(o).toString(16)}.${e[r+1]&32?`H`:`L`}${e[r+12]}${c}`,u=hevcConfigSps(e,t);return{profile:s,bitDepth:u?.bitDepth??(e[r+17]&7)+8,codecString:l,sps:u}}function av1Facts(e,t){if(t.end-t.start<4)return null;let n=e[t.start+1]>>5,r=e[t.start+2],i=r>>6&1,a=n>2?null:i?n===2&&r&32?12:10:8;return{profile:n,bitDepth:a,codecString:a===null?null:`av01.${n}.${dec2(e[t.start+1]&31)}${r&128?`H`:`M`}.${dec2(a)}`,sps:null}}function vp9String(e,t,n){return e===null||t===null||n===null?null:`vp09.${dec2(e)}.${dec2(t)}.${dec2(n)}`}function vpcFacts(e,t){if(t.end-t.start<7)return null;let n=e[t.start+4],r=e[t.start+6]>>4;return{profile:n,bitDepth:r,codecString:vp9String(n,e[t.start+5],r),sps:null}}function vp9PrivateFacts(e,t){let n=new Map;for(let r=t.start;r+2<=t.end;){let i=e[r],a=e[r+1];if(r+2+a>t.end)break;a===1&&!n.has(i)&&n.set(i,e[r+2]),r+=2+a}if(!n.size)return null;let r=n.get(1)??null,i=n.get(3)??null;return{profile:r,bitDepth:i,codecString:vp9String(r,n.get(2)??null,i),sps:null}}function isoConfigFacts(e,t,n){let r=firstBox(n,`avcC`);if(e===`h264`&&r)return avcFacts(t,r,n.type);let i=firstBox(n,`hvcC`);if(e===`hevc`&&i)return hevcFacts(t,i,n.type);let a=firstBox(n,`av1C`);if(e===`av1`&&a)return av1Facts(t,a);let o=firstBox(n,`vpcC`);return e===`vp9`&&o?vpcFacts(t,o):null}function matroskaConfigFacts(e,t,n){return n?e===`V_MPEG4/ISO/AVC`?avcFacts(t,n,`avc1`):e===`V_MPEGH/ISO/HEVC`?hevcFacts(t,n,`hvc1`):e===`V_AV1`?av1Facts(t,n):e===`V_VP9`?vp9PrivateFacts(t,n):null:null}function dolbyVisionString(e,t,n){return`${e}.${dec2(t)}.${dec2(n)}`}const a=`reserved|bt709|unknown|reserved|bt470m|bt470bg|smpte170m|smpte240m|film|bt2020|smpte428|smpte431|smpte432||||||||||ebu3213`.split(`|`),o=`reserved|bt709|unknown|reserved|bt470m|bt470bg|smpte170m|smpte240m|linear|log100|log316|iec61966-2-4|bt1361e|iec61966-2-1|bt2020-10|bt2020-12|smpte2084|smpte428|arib-std-b67`.split(`|`),s=`gbr|bt709|unknown|reserved|fcc|bt470bg|smpte170m|smpte240m|ycgco|bt2020nc|bt2020c|smpte2085|chroma-derived-nc|chroma-derived-c|ictcp|ipt-c2|ycgco-re|ycgco-ro`.split(`|`),c={primaries:{base:a,extended:[`vgamut`]},transfer:{base:o,extended:[`vlog`]},space:{base:s,extended:[]}};function nameOf(e,t){let n=c[e];return(t>=256?n.extended[t-256]:n.base[t])||void 0}function colorName(e,t){return t===null||t===2?null:nameOf(e,t)??null}function namedOrUnspecified(e,t){return nameOf(e,t)===void 0?2:t}const l=[`primaries`,`transfer`,`space`];function namedCodes(e){return l.map((t,n)=>namedOrUnspecified(t,e[n]))}function colorNames(e){return e?l.map((t,n)=>colorName(t,e[n])):[null,null,null]}const u=new Set([`dvh1`,`dvhe`,`dvav`,`dva1`,`dav1`]),d=[`dvcC`,`dvvC`,`dvwC`],f=new Set([1685480259,1685485123]),p=new Set([`h264`,`hevc`]);function dolbyVision(e,t){if(t.end-t.start<4)return null;let n=t.start,r=u16(e,n+2),i=t.end-t.start>=5;return{versionMajor:e[n],versionMinor:e[n+1],profile:r>>9,level:r>>3&63,rpu:!!(r&4),el:!!(r&2),bl:!!(r&1),compatibilityId:i?e[n+4]>>4:0,mdCompression:i?e[n+4]>>2&3:0}}function colrOf(e,t){if(t.end-t.start<10)return null;let n=fourccAt(e,t.start);return n!==`nclx`&&n!==`nclc`?null:{source:`colr`,codes:namedCodes([u16(e,t.start+4),u16(e,t.start+6),u16(e,t.start+8)]),fullRange:n===`nclx`?t.end-t.start>=11&&e[t.start+10]>>7==1:null}}function vpcOf(e,t){if(t.end-t.start<12||e[t.start]!==1)return null;let n=t.start+4;return{source:`vpcC`,codes:namedCodes([e[n+3],e[n+4],e[n+5]]),fullRange:(e[n+2]&1)==1}}function matroskaColour(e,t){if(!t.size)return null;let code=(n,r)=>{let i=elementUint(e,t.get(n))??2;return r.includes(i)?2:i},n=elementUint(e,t.get(21945));return{source:`Colour`,codes:[code(21947,[0,3]),code(21946,[0,3]),code(21937,[3])],fullRange:n===1?!1:n===2||null}}function hdrOf(e){return e===`smpte2084`?`pq`:e===`arib-std-b67`?`hlg`:null}function resolve(e,t,n,r,i){let a=p.has(e)?n?.sps?.vui??null:null,o=t!==null&&t.codes.some(e=>e!==2),s=o?t.codes:a?.colour?namedCodes(a.colour):null,c=o?t.source:a?.colour?`sps`:null,l=t?.fullRange??a?.fullRange??null;l===null&&e===`hevc`&&n?.sps&&(l=!1);let[u,d,f]=colorNames(s);return{range:l===null?null:l?`pc`:`tv`,primaries:u,transfer:d,space:f,source:s?.some(e=>e!==2)?c:null,bitDepth:n?.bitDepth??i,profile:n?.profile??null,codecString:n?.codecString??null,hdr:hdrOf(d),dolbyVision:r}}function isoColor(e,t){let n=isoConfig(t);if(!n)return;let r=n.entries[0];if(!r)return null;let i=n.bytes,a=null,o=null,s=null;for(let e of n.entries)for(let t of e.children){let e=t.type===`colr`?colrOf(i,t):t.type===`vpcC`?vpcOf(i,t):null;e&&(a=e,o=e.fullRange??o),d.includes(t.type)&&(s=dolbyVision(i,t)??s)}let c=isoConfigFacts(e,i,r);return s&&c&&u.has(r.type)&&(c.codecString=dolbyVisionString(r.type,s.profile,s.level)),a||c||s?resolve(e,a&&{...a,fullRange:o},c,s,null):null}function matroskaColor(e,t){let n=matroskaConfig(t);if(!n)return;let r=n.bytes,i=matroskaColour(r,n.colour),a=null;for(let e of n.mappings){let t=e.get(16877);f.has(elementUint(r,e.get(16871))??-1)&&t&&(a=dolbyVision(r,t)??a)}let o=matroskaConfigFacts(n.codecId,r,n.codecPrivate),s=elementUint(r,n.colour.get(21938));return!i&&!o&&!a&&!s?null:resolve(e,i,o,a,s||null)}function colorOf(e){let t=e.codecConfig;if(t)return t.family===`matroska`?matroskaColor(e.codecName,t):isoColor(e.codecName,t)}function withColor(e,t={}){return{...e,videoTracks:e.videoTracks.map(e=>{if(!e.codecConfig)return e;let n={...e,color:colorOf(e)};return t.keepCodecConfig||delete n.codecConfig,n})}}const m=2147483647n,abs=e=>e<0n?-e:e;function gcd(e,t){for(;t;)[e,t]=[t,e%t];return e}function avReduce(e,t,n){let r=[0n,1n],i=[1n,0n],a=e<0n!=t<0n,o=gcd(abs(e),abs(t));for(o&&(e=abs(e)/o,t=abs(t)/o),e<=n&&t<=n&&(i=[e,t],t=0n);t;){let a=e/t,o=e-t*a,s=a*i[0]+r[0],c=a*i[1]+r[1];if(s>n||c>n){i[0]&&(a=(n-r[0])/i[0]),i[1]&&(a=a<(n-r[1])/i[1]?a:(n-r[1])/i[1]),t*(2n*a*i[1]+r[1])>e*i[1]&&(i=[a*i[0]+r[0],a*i[1]+r[1]]);break}r=i,i=[s,c],e=t,t=o}return[a?-i[0]:i[0],i[1]]}function binaryExponent(e){if(e===0)return 0;let t=Math.floor(Math.log2(e));for(;2**t>e;)t--;for(;2**(t+1)<=e;)t++;return t}function avD2q(e,t){if(Number.isNaN(e))return[0n,0n];if(Math.abs(e)>Number(2147483647n)+3)return[e<0?-1n:1n,0n];let n=Math.max(binaryExponent(Math.abs(e)),0),r=1n<<BigInt(61-n);return avReduce(BigInt(Math.floor(e*Number(r)+.5)),r,t)}const h=1<<24,g=new Set([1,8,9,11]),_=new Set([2,3,6,7]);function rational([e,t]){return{num:Number(e),den:Number(t),value:Number(e)/Number(t)}}const valid=e=>e!==null&&e[0]>0n&&e[1]>0n;function vuiRatio(e){let t=e?.vui?.sar;return t?avReduce(BigInt(t[0]),BigInt(t[1]),m):null}function configSps(e,t,n){return n?e===`h264`?avcConfigSps(t,n):e===`hevc`?hevcConfigSps(t,n):null:null}function matrixOf(e,t){let n=boxPayload(e);if(!e||!n)return null;let r=n.start+t(e[n.start]);return r+36>n.end?null:Array.from({length:9},(t,n)=>BigInt(i32(e,r+n*4)))}function tkhdSizeAt(e){let t=boxPayload(e.tkhd),n=e.tkhd&&t?t.start+(e.tkhd[t.start]===1?88:76):-1;return t&&n+8<=t.end?n:-1}function matrixRatio(e,t){if(!e.tkhd||t<0||!u32(e.tkhd,t)||!u32(e.tkhd,t+4))return null;let n=matrixOf(e.tkhd,e=>e===1?52:40);if(!n)return null;let r=matrixOf(e.mvhd,e=>e===1?48:36)??Array(9).fill(0n),i=[16n,16n,30n],a=[];for(let e=0;e<3;e++)for(let t=0;t<3;t++){let o=0n;for(let a=0;a<3;a++)o+=n[e*3+a]*r[a*3+t]>>i[a];a.push(Number(BigInt.asIntN(32,o)))}if(a[0]===65536&&a[4]===65536&&a[8]===1<<30&&!a[1]&&!a[2]&&!a[3]&&!a[5]&&!a[6]&&!a[7])return null;let o=Math.hypot(a[0],a[3]),s=Math.hypot(a[1],a[4]);return o>1&&s>1&&o<h&&s<h&&Math.abs(o/s-1)>.01?avD2q(o/s,m):null}function isoRatio(e,t){let n=tkhdSizeAt(t),r=null;for(let e of t.entries)for(let n of e.children)n.type===`pasp`&&n.end-n.start>=8&&i32(t.bytes,n.start+4)&&(r=[BigInt(i32(t.bytes,n.start)),BigInt(i32(t.bytes,n.start+4))]);let i=r?.[0]?avReduce(r[0],r[1],m):matrixRatio(t,n);if(!i?.[0]&&t.tkhd&&n>=0){let r=BigInt(i32(t.tkhd,n)>>16),a=BigInt(i32(t.tkhd,n+4)>>16),o=BigInt(e.width),s=BigInt(e.height);r&&a&&o&&s&&(o!==r||s!==a)&&(i=avReduce(s*r,o*a,m))}if(valid(i))return i;let a=t.entries[0];return vuiRatio(configSps(e.codecName,t.bytes,firstBox(a,e.codecName===`h264`?`avcC`:`hvcC`)))}function matroskaCodec(e){return e.codecId===`V_MPEG4/ISO/AVC`?`h264`:e.codecId===`V_MPEGH/ISO/HEVC`?`hevc`:``}function matroskaRatio(e){let t=e.bytes,video=n=>elementUint(t,e.video.get(n)),n=video(21682)??0,r=null,i=(video(176)??0)-(video(21708)??0)-(video(21725)??0),a=(video(186)??0)-(video(21691)??0)-(video(21674)??0);if(n<4&&i>0&&a>0){let e=video(21680)??(n===0?i:null),t=video(21690)??(n===0?a:null),o=video(21432)??0;if(e&&t){let n=g.has(o)?2n:1n,s=_.has(o)?2n:1n;r=avReduce(BigInt(a)*BigInt(e)*n,BigInt(i)*BigInt(t)*s,m)}}return valid(r)?r:vuiRatio(configSps(matroskaCodec(e),t,e.codecPrivate))}function elementFloat(e,t){let n=t?t.end-t.start:0;if(!t||n!==4&&n!==8)return 0;let r=new DataView(e.buffer,e.byteOffset+t.start,n);return n===4?r.getFloat32(0):r.getFloat64(0)}function projectionRotation(e){let t=e.video.get(30320);if(!t)return 0;let n=e.bytes,r=new Map;for(let e of elements(n,t.start,t.end))r.set(e.id,e);let i=r.get(30322);if((elementUint(n,r.get(30321))??0)!==0||i&&i.end>i.start&&n[i.start]!==0)return 0;let a=elementFloat(n,r.get(30323)),o=elementFloat(n,r.get(30325));if(elementFloat(n,r.get(30324))!==0||a!==0&&Math.abs(a)!==180||Number.isNaN(o))return 0;let s=a===0?1:-1,c=o*s*Math.PI/180,l=s*Math.trunc(Math.cos(c)*65536)/65536,u=Math.trunc(-Math.sin(c)*65536)/65536,d=Math.hypot(l,s*Math.trunc(Math.sin(c)*65536)/65536),f=Math.hypot(u,Math.trunc(Math.cos(c)*65536)/65536);return d&&f&&Math.trunc(-(Math.atan2(u/f,l/d)*180/Math.PI))||0}function aspectOf(e){let t=e.codecConfig,n=t&&isoConfig(t),r=t&&!n?matroskaConfig(t):null;if(!n&&!r)return;let i=n?isoRatio(e,n):matroskaRatio(r),a=valid(i)?i:null,{width:o,height:s}=e;if(o<=0||s<=0)return{sampleAspectRatio:a&&rational(a),displayAspectRatio:null,displayWidth:null,displayHeight:null};let[c,l]=a??[1n,1n],u=Number((2n*BigInt(o)*c+l)/(2n*l)),d=e.rotation||(r?projectionRotation(r):0),f=Math.abs(d)%180==90;return{sampleAspectRatio:a&&rational(a),displayAspectRatio:a&&rational(avReduce(BigInt(o)*c,BigInt(s)*l,1048576n)),displayWidth:f?s:u,displayHeight:f?u:s}}function withAspect(e,t={}){return{...e,videoTracks:e.videoTracks.map(e=>{if(!e.codecConfig)return e;let n={...e,...aspectOf(e)};return t.keepCodecConfig||delete n.codecConfig,n})}}Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return withColor}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return withAspect}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return colorOf}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return aspectOf}});
@@ -1 +1 @@
1
- const e=require("./guards-Dqpjtkdn.cjs"),t=require("./probe-DDLUfr23.cjs"),n=require("./errors-0oBg1Ai6.cjs"),r=require("./fallback-D9Ak2zFv.cjs");async function compare(i,a,o={}){let s=t.n(a),c=[...new Set(o.engines??i.engines.filter(e=>e!==`rvfc`))],l=c.find(e=>!i.routes.has(e));if(l)throw new n.t(`engine-not-registered`,`engine ${l} is not registered`,{engine:l});let u={...i.defaults},{signal:d,timeoutMs:f,onProgress:p}=o,outcomeOf=async t=>{let o=performance.now();try{let e=await i.run(t,a,s,u,{signal:d,timeoutMs:f,onProgress:p&&(e=>p({...e,engine:t}))});if(e.type===`skipped`)return{status:`skipped`,reason:e.reason};let n=performance.now()-o,c=e.result,l=r.failureOf(c);return l===null?{status:`ok`,result:c,ms:n}:{status:`failed`,result:c,error:l,ms:n}}catch(r){if(e.t(r))throw r;let i=e.n(r)?r:Object.assign(new n.t(`worker-failed`,String(r),{engine:t,cause:r}),{reason:`crash`});return i.code===`unsupported-environment`?{status:`skipped`,reason:`unsupported-environment`}:{status:i.code===`timeout`?`timeout`:`crashed`,error:i}}},m=new Map;for(let e of c){let t=i.routes.get(e),n=t&&`kind`in t?t.kind:e;m.set(n,[...m.get(n)??[],e])}let h=new Map;await Promise.all([...m.values()].map(async e=>{for(let t of e)h.set(t,await outcomeOf(t))}));let g={},_={};for(let e of c){let t=h.get(e);t&&(g[e]=t,`result`in t&&(_[e]=t.result))}let v=t.r(_,o.reference);return{name:s,size:a.size,reference:v.reference,outcomes:g,agreement:v}}exports.compare=compare;
1
+ const e=require("./guards-DbQNcAZS.cjs"),t=require("./probe-Cn1DtL-C.cjs"),n=require("./errors-0oBg1Ai6.cjs"),r=require("./fallback-CyPIR3RM.cjs");async function compare(i,a,o={}){let s=t.n(a),c=[...new Set(o.engines??i.engines.filter(e=>e!==`rvfc`))],l=c.find(e=>!i.routes.has(e));if(l)throw new n.t(`engine-not-registered`,`engine ${l} is not registered`,{engine:l});let u={...i.defaults},{signal:d,timeoutMs:f,onProgress:p}=o,outcomeOf=async t=>{let o=performance.now();try{let e=await i.run(t,a,s,u,{signal:d,timeoutMs:f,onProgress:p&&(e=>p({...e,engine:t}))});if(e.type===`skipped`)return{status:`skipped`,reason:e.reason};let n=performance.now()-o,c=e.result,l=r.failureOf(c);return l===null?{status:`ok`,result:c,ms:n}:{status:`failed`,result:c,error:l,ms:n}}catch(r){if(e.t(r))throw r;let i=e.n(r)?r:Object.assign(new n.t(`worker-failed`,String(r),{engine:t,cause:r}),{reason:`crash`});return i.code===`unsupported-environment`?{status:`skipped`,reason:`unsupported-environment`}:{status:i.code===`timeout`?`timeout`:`crashed`,error:i}}},m=new Map;for(let e of c){let t=i.routes.get(e),n=t&&`kind`in t?t.kind:e;m.set(n,[...m.get(n)??[],e])}let h=new Map;await Promise.all([...m.values()].map(async e=>{for(let t of e)h.set(t,await outcomeOf(t))}));let g={},_={};for(let e of c){let t=h.get(e);t&&(g[e]=t,`result`in t&&(_[e]=t.result))}let v=t.r(_,o.reference);return{name:s,size:a.size,reference:v.reference,outcomes:g,agreement:v}}exports.compare=compare;
@@ -0,0 +1 @@
1
+ const e=require("./boxes-B0T2nt3e.cjs");function copy(e,t){return t?new Uint8Array(e.buffer,e.byteOffset+t.start,t.end-t.start).slice():null}function child(t,n,r){let i;for(let a of e.a(t,n.start+n.headerSize,n.end))a.type===r&&(i=a);return i}function isoBoxes(t,n){let r={family:`isobmff`,stsd:null,tkhd:null,mvhd:null},i=t?e.o(t,0,t.byteLength):null;if(!t||!i||i.type!==`moov`)return r;let a=0;for(let o of e.a(t,i.headerSize,i.end))if(o.type===`mvhd`)r.mvhd=copy(t,o);else if(o.type===`trak`&&a++===n){r.tkhd=copy(t,child(t,o,`tkhd`));let e=child(t,o,`mdia`),n=e&&child(t,e,`minf`),i=n&&child(t,n,`stbl`);r.stsd=copy(t,i&&child(t,i,`stsd`));break}return r}function isoCodecConfig(e,t){return isoBoxes(t.dv,e.tracks.indexOf(t))}exports.isoBoxes=isoBoxes,exports.isoCodecConfig=isoCodecConfig;
@@ -1 +1 @@
1
- const e=require("./guards-Dqpjtkdn.cjs"),t=require("./errors-0oBg1Ai6.cjs"),failureOf=t=>{let n=e.u(t);return t.error??(n?n.avgFps?null:`no frame rate`:`no video track`)},skippedResult=(t,n,r,i)=>({name:r,size:n.size,...e.c(i===`isobmff`?`mp4`:i??`unknown`,i?`unsupported by ${t}`:`not a recognised container`),io:{reads:0,bytesRead:0,ms:0},engine:t}),withAttempts=(e,t)=>t.length>0?{...e,attempts:t.map(({engine:e,error:t})=>({engine:e,error:t}))}:e;async function runChain(n,r,i,a,o,s,c){let l=[],u=null;for(let[d,f]of r.entries()){let p;try{let e=d===0&&c?c:await n(f,i,a,o,s);p=e.type===`result`?e.result:skippedResult(f,i,a,e.family??null)}catch(n){if(e.t(n))throw n;u=e.n(n)?n:Object.assign(new t.t(`worker-failed`,String(n),{engine:f,cause:n}),{reason:`crash`}),l.push({engine:f,error:u.message});continue}let m=failureOf(p);if(m===null||r.length===1)return withAttempts(p,l);l.push({engine:f,error:m,result:p})}for(let e=l.length-1;e>=0;e--){let{result:t}=l[e];if(t)return withAttempts(t,l.slice(0,e).concat(l.slice(e+1)))}throw u}exports.failureOf=failureOf,exports.runChain=runChain;
1
+ const e=require("./guards-DbQNcAZS.cjs"),t=require("./errors-0oBg1Ai6.cjs"),failureOf=t=>{let n=e.u(t);return t.error??(n?n.avgFps?null:`no frame rate`:`no video track`)},skippedResult=(t,n,r,i)=>({name:r,size:n.size,...e.c(i===`isobmff`?`mp4`:i??`unknown`,i?`unsupported by ${t}`:`not a recognised container`),io:{reads:0,bytesRead:0,ms:0},engine:t}),withAttempts=(e,t)=>t.length>0?{...e,attempts:t.map(({engine:e,error:t})=>({engine:e,error:t}))}:e;async function runChain(n,r,i,a,o,s,c){let l=[],u=null;for(let[d,f]of r.entries()){let p;try{let e=d===0&&c?c:await n(f,i,a,o,s);p=e.type===`result`?e.result:skippedResult(f,i,a,e.family??null)}catch(n){if(e.t(n))throw n;u=e.n(n)?n:Object.assign(new t.t(`worker-failed`,String(n),{engine:f,cause:n}),{reason:`crash`}),l.push({engine:f,error:u.message});continue}let m=failureOf(p);if(m===null||r.length===1)return withAttempts(p,l);l.push({engine:f,error:m,result:p})}for(let e=l.length-1;e>=0;e--){let{result:t}=l[e];if(t)return withAttempts(t,l.slice(0,e).concat(l.slice(e+1)))}throw u}exports.failureOf=failureOf,exports.runChain=runChain;
@@ -1 +1 @@
1
- function emptyAnalysis(e,t=null){return{container:e,brand:null,formatDurationSec:null,scan:null,videoTracks:[],audioTrackCount:0,primaryTrackId:null,error:t,warnings:[]}}function emptyTrack(e){return{trackId:e,fourccOrCodecId:``,codecName:``,width:0,height:0,rotation:0,timescale:0,frames:null,presentedFrames:null,durationSec:null,startSec:null,avgFps:null,avgFpsFfprobe:null,rFpsFfprobe:null,nominalFps:null,dominantFps:null,minFps:null,maxFps:null,isVfr:null,vfrRatio:0,distinctDeltas:0,duplicateTimestamps:0,timestampsQuantized:!1,isStill:!1,rateProfile:null,medianFrameInterval:null,provenance:{},warnings:[]}}function primaryTrack(e){return e.primaryTrackId===null?null:e.videoTracks.find(t=>t.trackId===e.primaryTrackId)??null}const e=[[`not a recognised container: empty file`,`empty-file`],[`not a recognised container`,`unrecognised`],[`unsupported: moov larger`,`too-large`],[`corrupt file: moof larger`,`too-large`],[`unsupported:`,`unsupported`],[`incomplete file: moov is truncated`,`truncated`],[`incomplete file: no moov`,`no-header`],[`incomplete header:`,`no-duration`],[`limit reached: maxBytes`,`byte-limit`],[`limit reached: maxReads`,`read-limit`],[`limit reached: maxMs`,`time-limit`],[`limit reached: maxTracks`,`structure-limit`],[`limit reached: maxTopLevelBoxes`,`structure-limit`],[`corrupt file:`,`corrupt`],[`file read failed`,`read-failed`],[`the own `,`unsupported-container`],[`unsupported by `,`unsupported-container`],[`container not read by`,`unsupported-container`],[`invalid EBML header`,`corrupt`],[`no Segment element`,`no-header`],[`no complete TrackEntry in Tracks`,`truncated`],[`no Tracks element found`,`no-header`]],t={"empty-file":`file`,unrecognised:`file`,"unsupported-container":`file`,unsupported:`file`,"too-large":`file`,"no-header":`file`,truncated:`file`,corrupt:`file`,"no-duration":`file`,"engine-failed":`file`,"byte-limit":`limit`,"read-limit":`limit`,"time-limit":`limit`,"structure-limit":`limit`,"read-failed":`io`,"load-failed":`environment`,internal:`internal`},n=[[`invalid mdhd timescale `,`invalid-timescale`],[`invalid timescale `,`invalid-timescale`],[`ignored trailing data at `,`trailing-data`],[`fragment index not read: `,`fragment-index-unread`],[`format duration unresolved: `,`duration-unresolved`],[`fragments ignored: `,`fragments-ignored`],[`too many top-level boxes`,`structure-limit`]],r=/^'(.{4})' at \d+ is truncated/;function errorCodeOf(t){if(t?.errorCode!==void 0)return t.errorCode;let n=t?.error;if(n===null)return null;if(typeof n!=`string`)return`internal`;for(let[t,r]of e)if(n.startsWith(t))return r;return t.engine!==void 0&&t.engine!==`own`?`engine-failed`:`internal`}function errorClass(e){return Object.hasOwn(t,e)?t[e]:`internal`}function warningCodeOf(e){if(typeof e!=`string`)return null;for(let[t,r]of n)if(e.startsWith(t))return r;let t=r.exec(e);return t?t[1]===`mdat`?`truncated-mdat`:`truncated-box`:null}function warningCodesOf(e){let t=new Set,listOf=e=>Array.isArray(e)?e:[];for(let n of[...listOf(e?.warnings),...listOf(e?.videoTracks).flatMap(e=>listOf(e?.warnings))]){let e=warningCodeOf(n);e&&t.add(e)}return[...t]}const field=(e,t)=>typeof e==`object`&&e&&t in e?e[t]:void 0,isProbeError=e=>field(e,`name`)===`ProbeError`&&typeof field(e,`code`)==`string`,probeCode=(e,t,n)=>isProbeError(e)?e.code===t:field(e,`name`)===n;function isAbortError(e){return probeCode(e,`aborted`,`AbortError`)}function isTimeoutError(e){return probeCode(e,`timeout`,`TimeoutError`)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return errorCodeOf}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return emptyAnalysis}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return errorClass}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return emptyTrack}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return isProbeError}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return warningCodeOf}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return isTimeoutError}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return warningCodesOf}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return isAbortError}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return primaryTrack}});
1
+ function emptyAnalysis(e,t=null){return{container:e,brand:null,formatDurationSec:null,scan:null,videoTracks:[],audioTrackCount:0,primaryTrackId:null,error:t,warnings:[]}}function emptyTrack(e){return{trackId:e,fourccOrCodecId:``,codecName:``,width:0,height:0,rotation:0,timescale:0,frames:null,presentedFrames:null,durationSec:null,startSec:null,avgFps:null,avgFpsFfprobe:null,rFpsFfprobe:null,nominalFps:null,dominantFps:null,minFps:null,maxFps:null,isVfr:null,vfrRatio:0,distinctDeltas:0,duplicateTimestamps:0,timestampsQuantized:!1,isStill:!1,rateProfile:null,medianFrameInterval:null,provenance:{},warnings:[]}}function primaryTrack(e){return e.primaryTrackId===null?null:e.videoTracks.find(t=>t.trackId===e.primaryTrackId)??null}const e=[[`not a recognised container: empty file`,`empty-file`],[`not a recognised container`,`unrecognised`],[`unsupported: moov larger`,`too-large`],[`corrupt file: moof larger`,`too-large`],[`unsupported:`,`unsupported`],[`incomplete file: moov is truncated`,`truncated`],[`incomplete file: no moov`,`no-header`],[`incomplete header:`,`no-duration`],[`limit reached: maxBytes`,`byte-limit`],[`limit reached: maxReads`,`read-limit`],[`limit reached: maxMs`,`time-limit`],[`limit reached: maxTracks`,`structure-limit`],[`limit reached: maxTopLevelBoxes`,`structure-limit`],[`corrupt file:`,`corrupt`],[`file read failed`,`read-failed`],[`the own `,`unsupported-container`],[`unsupported by `,`unsupported-container`],[`container not read by`,`unsupported-container`],[`invalid EBML header`,`corrupt`],[`no Segment element`,`no-header`],[`no complete TrackEntry in Tracks`,`truncated`],[`no Tracks element found`,`no-header`]],t={"empty-file":`file`,unrecognised:`file`,"unsupported-container":`file`,unsupported:`file`,"too-large":`file`,"no-header":`file`,truncated:`file`,corrupt:`file`,"no-duration":`file`,"engine-failed":`file`,"byte-limit":`limit`,"read-limit":`limit`,"time-limit":`limit`,"structure-limit":`limit`,"read-failed":`io`,"load-failed":`environment`,internal:`internal`},n=[[`invalid mdhd timescale `,`invalid-timescale`],[`invalid timescale `,`invalid-timescale`],[`ignored trailing data at `,`trailing-data`],[`fragment index not read: `,`fragment-index-unread`],[`format duration unresolved: `,`duration-unresolved`],[`fragments ignored: `,`fragments-ignored`],[`too many top-level boxes`,`structure-limit`],[`codec configuration unavailable`,`codec-config-unavailable`],[`color and aspect unavailable`,`metadata-unavailable`]],r=/^'(.{4})' at \d+ is truncated/;function errorCodeOf(t){if(t?.errorCode!==void 0)return t.errorCode;let n=t?.error;if(n===null)return null;if(typeof n!=`string`)return`internal`;for(let[t,r]of e)if(n.startsWith(t))return r;return t.engine!==void 0&&t.engine!==`own`?`engine-failed`:`internal`}function errorClass(e){return Object.hasOwn(t,e)?t[e]:`internal`}function warningCodeOf(e){if(typeof e!=`string`)return null;for(let[t,r]of n)if(e.startsWith(t))return r;let t=r.exec(e);return t?t[1]===`mdat`?`truncated-mdat`:`truncated-box`:null}function warningCodesOf(e){let t=new Set,listOf=e=>Array.isArray(e)?e:[];for(let n of[...listOf(e?.warnings),...listOf(e?.videoTracks).flatMap(e=>listOf(e?.warnings))]){let e=warningCodeOf(n);e&&t.add(e)}return[...t]}const field=(e,t)=>typeof e==`object`&&e&&t in e?e[t]:void 0,isProbeError=e=>field(e,`name`)===`ProbeError`&&typeof field(e,`code`)==`string`,probeCode=(e,t,n)=>isProbeError(e)?e.code===t:field(e,`name`)===n;function isAbortError(e){return probeCode(e,`aborted`,`AbortError`)}function isTimeoutError(e){return probeCode(e,`timeout`,`TimeoutError`)}Object.defineProperty(exports,"a",{enumerable:!0,get:function(){return errorCodeOf}}),Object.defineProperty(exports,"c",{enumerable:!0,get:function(){return emptyAnalysis}}),Object.defineProperty(exports,"i",{enumerable:!0,get:function(){return errorClass}}),Object.defineProperty(exports,"l",{enumerable:!0,get:function(){return emptyTrack}}),Object.defineProperty(exports,"n",{enumerable:!0,get:function(){return isProbeError}}),Object.defineProperty(exports,"o",{enumerable:!0,get:function(){return warningCodeOf}}),Object.defineProperty(exports,"r",{enumerable:!0,get:function(){return isTimeoutError}}),Object.defineProperty(exports,"s",{enumerable:!0,get:function(){return warningCodesOf}}),Object.defineProperty(exports,"t",{enumerable:!0,get:function(){return isAbortError}}),Object.defineProperty(exports,"u",{enumerable:!0,get:function(){return primaryTrack}});
@@ -0,0 +1 @@
1
+ const e=require("./guards-DbQNcAZS.cjs"),t=require("./reader-Dw11ozVU.cjs"),n=require("./boxes-B0T2nt3e.cjs"),r=require("./build-DhETwJLO.cjs"),i=require("./stats-DW7dVdFa.cjs");async function analyzeIsoBmffDetailed(n,a){let o=r.b(n.size),fail=i=>{if(r.c(i,n))throw i;let a=i instanceof Error?i.message:String(i),s=e.c(r.a(o),i?.errorCode?a:`corrupt file: ${a}`);return s.errorCode=t.i(i),s.layout=r.u(o),s.brand=o.brand,s.warnings=o.warnings,{analysis:s,movie:o}};try{await r.m(n,a,o),await r.o(n,o);let t=e.c(r.a(o));t.brand=o.brand,t.scan=`exact`,t.warnings=o.warnings;let s=o.ffprobeReject,c=s!==null&&s.moof<o.ffprobeMoofLimit;c&&o.warnings.push(`ffprobe 8.1.1 ${s.reason}`);let l=r.p(o.tracks);[...l].some(([e,t])=>e.id!==t)&&o.warnings.push(`duplicate track_ID values`);let u=o.tracks.filter(e=>r.l(e,o)),d=u.map(e=>r.i(e,o,a,{reportedId:l.get(e)??e.id,ffprobeFails:c},i.analyzeTimeline));for(let e of d)e.result.rateProfile=await i.rateProfileOf(e.profile??null);return t.videoTracks=d.map(e=>e.result),t.audioTrackCount=o.tracks.filter(e=>e.handler===`soun`).length,t.primaryTrackId=r.d(d),t.formatDurationSec=r.s(o,new Set(u)),t.layout=r.u(o),{analysis:t,movie:o}}catch(e){return fail(e)}}async function analyzeIsoBmff(e,t){return(await analyzeIsoBmffDetailed(e,t)).analysis}exports.IsoBmffError=n.t,exports.MOOF_HARD_CAP=r.t,exports.MOOV_HARD_CAP=r.n,exports.MOOV_SUSPECT_CAP=r.r,exports.analyzeIsoBmff=analyzeIsoBmff,exports.analyzeIsoBmffDetailed=analyzeIsoBmffDetailed;