alpha2 0.4.6 → 0.5.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +5 -4
- package/THIRD_PARTY_NOTICES.md +4 -0
- package/dist/abort.d.ts +12 -0
- package/dist/abort.js +48 -0
- package/dist/active-clock.d.ts +35 -0
- package/dist/active-clock.js +99 -0
- package/dist/assets.d.ts +28 -22
- package/dist/assets.js +8 -12
- package/dist/audio-layout.d.ts +52 -74
- package/dist/audio-layout.js +114 -148
- package/dist/audio-timeline.d.ts +89 -117
- package/dist/audio-timeline.js +102 -118
- package/dist/audio-worker.d.ts +12 -21
- package/dist/audio-worker.js +8 -13
- package/dist/audio-worklet-processor.js +45 -58
- package/dist/audio-worklet.d.ts +45 -76
- package/dist/audio-worklet.js +44 -79
- package/dist/audio.d.ts +15 -23
- package/dist/audio.js +9 -13
- package/dist/builder.d.ts +45 -63
- package/dist/builder.js +49 -45
- package/dist/capabilities.d.ts +99 -16
- package/dist/capabilities.js +2 -2
- package/dist/captions.d.ts +45 -22
- package/dist/captions.js +60 -15
- package/dist/chroma-siting.d.ts +24 -41
- package/dist/chroma-siting.js +38 -71
- package/dist/containers.d.ts +41 -30
- package/dist/containers.js +59 -27
- package/dist/decoder-fallback.d.ts +13 -0
- package/dist/decoder-fallback.js +38 -0
- package/dist/decoder-order.d.ts +24 -39
- package/dist/decoder-order.js +28 -42
- package/dist/edit.d.ts +77 -154
- package/dist/edit.js +98 -180
- package/dist/effects.d.ts +108 -177
- package/dist/effects.js +7 -9
- package/dist/export-destination.d.ts +25 -41
- package/dist/export-destination.js +20 -32
- package/dist/export-failure.d.ts +34 -59
- package/dist/export-failure.js +54 -48
- package/dist/export-metrics.d.ts +116 -0
- package/dist/export-metrics.js +74 -0
- package/dist/export-retry.d.ts +46 -29
- package/dist/export-retry.js +86 -51
- package/dist/exporter.d.ts +67 -116
- package/dist/exporter.js +133 -133
- package/dist/extensions.d.ts +69 -115
- package/dist/extensions.js +55 -82
- package/dist/frame-intake.d.ts +92 -0
- package/dist/frame-intake.js +114 -0
- package/dist/frame-supply.d.ts +96 -162
- package/dist/frame-supply.js +181 -171
- package/dist/generated/project-schema.d.ts +701 -485
- package/dist/generated/project-schema.js +55 -2
- package/dist/generated/project-shape.js +261 -16
- package/dist/geometry.d.ts +28 -34
- package/dist/geometry.js +18 -23
- package/dist/gpu-recovery.d.ts +92 -0
- package/dist/gpu-recovery.js +135 -0
- package/dist/hdr-frames.d.ts +82 -67
- package/dist/hdr-frames.js +112 -49
- package/dist/index.d.ts +4 -0
- package/dist/index.js +4 -0
- package/dist/json-text.d.ts +13 -23
- package/dist/json-text.js +10 -20
- package/dist/layout-values.d.ts +14 -22
- package/dist/layout-values.js +18 -21
- package/dist/layout.d.ts +48 -63
- package/dist/layout.js +37 -37
- package/dist/loudness.d.ts +27 -32
- package/dist/loudness.js +19 -23
- package/dist/media.d.ts +85 -237
- package/dist/media.js +133 -287
- package/dist/mediabunny.d.ts +166 -245
- package/dist/mediabunny.js +741 -580
- package/dist/physical-frames.d.ts +5 -17
- package/dist/physical-frames.js +4 -11
- package/dist/player.d.ts +56 -47
- package/dist/player.js +155 -40
- package/dist/presented-frames.d.ts +2 -7
- package/dist/presented-frames.js +3 -8
- package/dist/project.d.ts +73 -117
- package/dist/project.js +384 -445
- package/dist/rate-control.d.ts +9 -23
- package/dist/rate-control.js +7 -18
- package/dist/renderer-choice.d.ts +41 -0
- package/dist/renderer-choice.js +82 -0
- package/dist/repacked-bytes.d.ts +0 -2
- package/dist/repacked-bytes.js +2 -5
- package/dist/robustness.d.ts +25 -37
- package/dist/robustness.js +71 -54
- package/dist/sha256.d.ts +5 -13
- package/dist/sha256.js +9 -24
- package/dist/text.d.ts +97 -71
- package/dist/text.js +33 -70
- package/dist/video-frames.d.ts +7 -25
- package/dist/video-frames.js +12 -29
- package/dist/waveform.d.ts +5 -11
- package/dist/waveform.js +4 -9
- package/dist/worker-error.d.ts +5 -20
- package/dist/worker-error.js +8 -25
- package/dist/worker.d.ts +82 -95
- package/dist/worker.js +235 -143
- package/package.json +26 -2
- package/wasm/alpha2_audio_worklet.wasm +0 -0
- package/wasm/alpha2_extensions.d.ts +26 -47
- package/wasm/alpha2_extensions.js +26 -47
- package/wasm/alpha2_extensions_bg.wasm +0 -0
- package/wasm/alpha2_wasm.d.ts +460 -567
- package/wasm/alpha2_wasm.js +594 -594
- package/wasm/alpha2_wasm_bg.wasm +0 -0
- package/wasm/alpha2_wasm_bg.wasm.d.ts +15 -8
- package/wasm/rust-crate-licenses.md +2 -2
- package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline1.js +1 -0
- package/wasm/snippets/alpha2-wasm-1313375d424845c0/inline2.js +82 -0
- package/wasm/snippets/alpha2-wasm-c62e60c964e88a52/inline2.js +0 -52
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline0.js +0 -0
- /package/wasm/snippets/{alpha2-wasm-c62e60c964e88a52 → alpha2-wasm-1313375d424845c0}/inline3.js +0 -0
package/dist/audio-layout.js
CHANGED
|
@@ -1,6 +1,4 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* `FFmpeg`'s channel names, by channel number (`enum AVChannel`); a number without one is `UNK`.
|
|
3
|
-
*/
|
|
1
|
+
/** `FFmpeg` channel names by `enum AVChannel` number; unnamed numbers are `UNK`. */
|
|
4
2
|
const SPEAKER_BY_CHANNEL = new Map([
|
|
5
3
|
[0, "FL"],
|
|
6
4
|
[1, "FR"],
|
|
@@ -39,7 +37,7 @@ const SPEAKER_BY_CHANNEL = new Map([
|
|
|
39
37
|
[61, "BIL"],
|
|
40
38
|
[62, "BIR"],
|
|
41
39
|
]);
|
|
42
|
-
/**
|
|
40
|
+
/** Valid speaker names: the named `FFmpeg` channels plus `UNK`. */
|
|
43
41
|
export const AUDIO_SPEAKERS = new Set([
|
|
44
42
|
...SPEAKER_BY_CHANNEL.values(),
|
|
45
43
|
"UNK",
|
|
@@ -47,10 +45,7 @@ export const AUDIO_SPEAKERS = new Set([
|
|
|
47
45
|
function speakerOfChannel(channel) {
|
|
48
46
|
return SPEAKER_BY_CHANNEL.get(channel) ?? "UNK";
|
|
49
47
|
}
|
|
50
|
-
/**
|
|
51
|
-
* The speakers of a native-order channel mask, in bit order, as `FFmpeg`'s
|
|
52
|
-
* `av_channel_layout_from_mask` lists them. A set bit with no named channel is `UNK`.
|
|
53
|
-
*/
|
|
48
|
+
/** Speakers of a native-order channel mask in bit order (`av_channel_layout_from_mask`). */
|
|
54
49
|
export function speakersOfMask(mask) {
|
|
55
50
|
const speakers = [];
|
|
56
51
|
for (let bit = 0; bit < 64; bit += 1)
|
|
@@ -58,19 +53,41 @@ export function speakersOfMask(mask) {
|
|
|
58
53
|
speakers.push(speakerOfChannel(bit));
|
|
59
54
|
return speakers;
|
|
60
55
|
}
|
|
61
|
-
const
|
|
56
|
+
const CHANNEL_OF_SPEAKER = new Map([...SPEAKER_BY_CHANNEL].map(([channel, speaker]) => [speaker, channel]));
|
|
62
57
|
/**
|
|
63
|
-
*
|
|
58
|
+
* `speakers` with an LFE inserted in native order, plus its plane index, for decoders that add a
|
|
59
|
+
* silent LFE (a WebCodecs decoder does for E-AC-3 5.0). `null` when there is already an LFE or the
|
|
60
|
+
* list is not native-order named speakers.
|
|
64
61
|
*/
|
|
62
|
+
export function speakersWithLfe(speakers) {
|
|
63
|
+
const channels = speakers.map((speaker) => CHANNEL_OF_SPEAKER.get(speaker));
|
|
64
|
+
const lfe = CHANNEL_OF_SPEAKER.get("LFE");
|
|
65
|
+
if (channels.some((channel, index) => channel === undefined ||
|
|
66
|
+
channel === lfe ||
|
|
67
|
+
(index > 0 && channel <= channels[index - 1])))
|
|
68
|
+
return null;
|
|
69
|
+
const at = channels.findIndex((channel) => channel > lfe);
|
|
70
|
+
const lfePlane = at === -1 ? speakers.length : at;
|
|
71
|
+
return {
|
|
72
|
+
speakers: [
|
|
73
|
+
...speakers.slice(0, lfePlane),
|
|
74
|
+
"LFE",
|
|
75
|
+
...speakers.slice(lfePlane),
|
|
76
|
+
],
|
|
77
|
+
lfePlane,
|
|
78
|
+
};
|
|
79
|
+
}
|
|
80
|
+
const list = (names) => names.split(" ");
|
|
81
|
+
/** `null` when the layout names no speaker, as `SpeakerLayout::declared_or_default` reads it. */
|
|
65
82
|
function declared(speakers) {
|
|
66
83
|
if (speakers === null || speakers.every((speaker) => speaker === "UNK"))
|
|
67
84
|
return null;
|
|
68
85
|
return speakers;
|
|
69
86
|
}
|
|
70
87
|
/**
|
|
71
|
-
*
|
|
72
|
-
* `
|
|
73
|
-
* `
|
|
88
|
+
* Speakers of a `WAVE_FORMAT_EXTENSIBLE` channel mask in a `fmt ` chunk payload, as `FFmpeg`'s RIFF
|
|
89
|
+
* demuxer reads it. `null` for other formats, short payloads, or a mask whose bit count is not
|
|
90
|
+
* `channels`.
|
|
74
91
|
*/
|
|
75
92
|
export function wavSpeakers(fmt, channels) {
|
|
76
93
|
if (fmt.length < 24)
|
|
@@ -109,9 +126,8 @@ const MOV_LABELS = {
|
|
|
109
126
|
LFE1: "LFE",
|
|
110
127
|
};
|
|
111
128
|
/**
|
|
112
|
-
* QuickTime channel layout tags (`
|
|
113
|
-
* `
|
|
114
|
-
* Haptic) is unnamed.
|
|
129
|
+
* QuickTime channel layout tags (`mov_chan.h`) and their channels per `mov_chan.c`. Labels without
|
|
130
|
+
* an `FFmpeg` channel (ambisonics, Csd, HI, VI, Haptic) are unnamed.
|
|
115
131
|
*/
|
|
116
132
|
const MOV_LAYOUT_TAGS = new Map([
|
|
117
133
|
[100, "C"],
|
|
@@ -200,17 +216,16 @@ const MOV_LAYOUT_TAGS = new Map([
|
|
|
200
216
|
[181, "Lc C Rc L R Ls Cs Rs LFE"],
|
|
201
217
|
[182, "C L R Ls Rs LFE Cs"],
|
|
202
218
|
]);
|
|
203
|
-
/**
|
|
219
|
+
/** `mov_get_channel_id`. */
|
|
204
220
|
function movLabelSpeaker(label) {
|
|
205
221
|
if (label >= 1 && label <= 18)
|
|
206
222
|
return speakerOfChannel(label - 1);
|
|
207
223
|
return ({ 35: "WL", 36: "WR", 37: "LFE2", 38: "DL", 39: "DR" }[label] ?? "UNK");
|
|
208
224
|
}
|
|
209
225
|
/**
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
213
|
-
* else, including a truncated payload.
|
|
226
|
+
* Speakers a QuickTime `chan` payload (after version and flags) declares, per `ff_mov_read_chan`:
|
|
227
|
+
* channel descriptions, a bitmap, or a known layout tag, each matching `channels`. `null`
|
|
228
|
+
* otherwise, including for truncated payloads.
|
|
214
229
|
*/
|
|
215
230
|
export function movChanSpeakers(chan, channels) {
|
|
216
231
|
if (chan.length < 12)
|
|
@@ -243,15 +258,12 @@ export function movChanSpeakers(chan, channels) {
|
|
|
243
258
|
return declared(labels.split(" ").map((label) => MOV_LABELS[label] ?? "UNK"));
|
|
244
259
|
}
|
|
245
260
|
const CONTAINERS = new Set(["moov", "trak", "mdia", "minf", "stbl", "wave"]);
|
|
246
|
-
/**
|
|
261
|
+
/** Largest `moov` box read to find a `chan`; larger ones are treated as declaring none. */
|
|
247
262
|
const MAX_MOOV_BYTES = 64 * 1024 * 1024;
|
|
248
263
|
function boxType(bytes, at) {
|
|
249
264
|
return String.fromCharCode(...bytes.subarray(at, at + 4));
|
|
250
265
|
}
|
|
251
|
-
/**
|
|
252
|
-
* The boxes inside `bytes[start, end)`: type, payload start and end. Stops at the first malformed
|
|
253
|
-
* one.
|
|
254
|
-
*/
|
|
266
|
+
/** Iterates the boxes in `bytes[start, end)`, stopping at the first malformed one. */
|
|
255
267
|
function* boxes(bytes, start, end) {
|
|
256
268
|
const view = new DataView(bytes.buffer, bytes.byteOffset, bytes.byteLength);
|
|
257
269
|
let at = start;
|
|
@@ -277,9 +289,8 @@ function* boxes(bytes, start, end) {
|
|
|
277
289
|
}
|
|
278
290
|
}
|
|
279
291
|
/**
|
|
280
|
-
*
|
|
281
|
-
*
|
|
282
|
-
* version and flags; `FFmpeg` ignores any other version).
|
|
292
|
+
* First `chan` or version 0 `chnl` box in a `trak`'s sound sample description, where `FFmpeg` looks
|
|
293
|
+
* for one. Payloads start after version and flags.
|
|
283
294
|
*/
|
|
284
295
|
function findLayoutBox(bytes, start, end) {
|
|
285
296
|
for (const box of boxes(bytes, start, end)) {
|
|
@@ -301,13 +312,12 @@ function findLayoutBox(bytes, start, end) {
|
|
|
301
312
|
return found;
|
|
302
313
|
}
|
|
303
314
|
if (box.type === "stsd") {
|
|
304
|
-
//
|
|
305
|
-
// follow its fixed fields.
|
|
315
|
+
// Skip the full-box header and entry count.
|
|
306
316
|
for (const entry of boxes(bytes, box.payload + 8, box.end)) {
|
|
307
317
|
const view = new DataView(bytes.buffer, bytes.byteOffset);
|
|
308
318
|
const version = view.getUint16(entry.payload + 8);
|
|
309
|
-
// QuickTime sound descriptions grow by 16 (
|
|
310
|
-
//
|
|
319
|
+
// QuickTime sound descriptions grow by 16 (v1) or 36 (v2) bytes; ISO v1 does not, so try
|
|
320
|
+
// both offsets.
|
|
311
321
|
const offsets = version === 2 ? [56] : version === 1 ? [36, 20] : [20];
|
|
312
322
|
for (const offset of offsets) {
|
|
313
323
|
const found = findLayoutBox(bytes, entry.payload + 8 + offset, entry.end);
|
|
@@ -319,7 +329,7 @@ function findLayoutBox(bytes, start, end) {
|
|
|
319
329
|
}
|
|
320
330
|
return null;
|
|
321
331
|
}
|
|
322
|
-
/**
|
|
332
|
+
/** Track ID from a `trak`'s `tkhd`, or `null`. */
|
|
323
333
|
function trackId(bytes, trak) {
|
|
324
334
|
for (const box of boxes(bytes, trak.payload, trak.end)) {
|
|
325
335
|
if (box.type !== "tkhd")
|
|
@@ -330,7 +340,7 @@ function trackId(bytes, trak) {
|
|
|
330
340
|
}
|
|
331
341
|
return null;
|
|
332
342
|
}
|
|
333
|
-
/**
|
|
343
|
+
/** ASCII text of `length` bytes at `offset`, or `null` when the source is shorter. */
|
|
334
344
|
async function readTag(read, offset, length) {
|
|
335
345
|
const bytes = await read(offset, length);
|
|
336
346
|
return bytes.length < length ? null : boxType(bytes, 0).slice(0, length);
|
|
@@ -391,9 +401,9 @@ async function movLayoutBox(read, size, track) {
|
|
|
391
401
|
}
|
|
392
402
|
return null;
|
|
393
403
|
}
|
|
394
|
-
/** ISO/IEC 23001-8 speaker positions (table 8), as `mov_chan.c
|
|
404
|
+
/** ISO/IEC 23001-8 speaker positions (table 8), mapped as in `mov_chan.c`. */
|
|
395
405
|
const ISO_POSITIONS = list("FL FR FC LFE SL SR FLC FRC BL BR BC SDL SDR SSL SSR WL WR TFL TFR TFC TBL TBR TBC TSL TSR TC LFE2 BFL BFR BFC TTL TTR");
|
|
396
|
-
/** ISO/IEC 23001-8 channel configurations, as `mov_chan.c
|
|
406
|
+
/** ISO/IEC 23001-8 channel configurations, laid out as in `mov_chan.c`. */
|
|
397
407
|
const ISO_CONFIGURATIONS = {
|
|
398
408
|
1: "FC",
|
|
399
409
|
2: "FL FR",
|
|
@@ -410,11 +420,9 @@ const ISO_CONFIGURATIONS = {
|
|
|
410
420
|
14: "FC FL FR SL SR LFE TFL TFR",
|
|
411
421
|
};
|
|
412
422
|
/**
|
|
413
|
-
*
|
|
414
|
-
*
|
|
415
|
-
*
|
|
416
|
-
* channels, a configuration `FFmpeg` does not know or of another count, a truncated payload, or
|
|
417
|
-
* one naming no speaker.
|
|
423
|
+
* Speakers an ISO `chnl` payload (after version and flags) declares, per `ff_mov_read_chnl`:
|
|
424
|
+
* explicit positions, or a channel configuration minus omitted channels. `null` for no channels,
|
|
425
|
+
* an unknown or mismatched configuration, a truncated payload, or no named speaker.
|
|
418
426
|
*/
|
|
419
427
|
export function chnlSpeakers(chnl, channels) {
|
|
420
428
|
if (chnl.length < 2 || !(chnl[0] & 1))
|
|
@@ -427,7 +435,7 @@ export function chnlSpeakers(chnl, channels) {
|
|
|
427
435
|
const position = chnl[at];
|
|
428
436
|
if (position === undefined)
|
|
429
437
|
return null;
|
|
430
|
-
//
|
|
438
|
+
// Explicit position: skip azimuth and elevation.
|
|
431
439
|
at += position === 126 ? 4 : 1;
|
|
432
440
|
speakers.push(ISO_POSITIONS[position] ?? "UNK");
|
|
433
441
|
}
|
|
@@ -448,7 +456,6 @@ export function chnlSpeakers(chnl, channels) {
|
|
|
448
456
|
return null;
|
|
449
457
|
return declared(all.filter((_, channel) => !((omitted >> BigInt(channel)) & 1n)));
|
|
450
458
|
}
|
|
451
|
-
/** The channel layout a QuickTime or ISO sample description declares, or `null`. */
|
|
452
459
|
async function movSpeakers(read, size, track, channels) {
|
|
453
460
|
const box = await movLayoutBox(read, size, track);
|
|
454
461
|
if (box === null)
|
|
@@ -457,7 +464,7 @@ async function movSpeakers(read, size, track, channels) {
|
|
|
457
464
|
? movChanSpeakers(box.payload, channels)
|
|
458
465
|
: chnlSpeakers(box.payload, channels);
|
|
459
466
|
}
|
|
460
|
-
/**
|
|
467
|
+
/** Big-endian bit reader; reading past the end throws `RangeError`. */
|
|
461
468
|
class Bits {
|
|
462
469
|
#bit;
|
|
463
470
|
#bytes;
|
|
@@ -496,21 +503,18 @@ class Bits {
|
|
|
496
503
|
return new Bits(this.#bytes, this.#bit);
|
|
497
504
|
}
|
|
498
505
|
}
|
|
499
|
-
/** `
|
|
506
|
+
/** `AV_CH_*` bits by speaker name. */
|
|
500
507
|
const CHANNEL_BIT = new Map([...SPEAKER_BY_CHANNEL].map(([channel, speaker]) => [
|
|
501
508
|
speaker,
|
|
502
509
|
1n << BigInt(channel),
|
|
503
510
|
]));
|
|
504
511
|
const bitsOf = (names) => list(names).reduce((mask, speaker) => mask | CHANNEL_BIT.get(speaker), 0n);
|
|
505
|
-
/**
|
|
506
|
-
* The speakers of a native-order mask of `channels` bits, or `null` for a mask of another count
|
|
507
|
-
* (`FFmpeg` would deliver planes the mask does not name).
|
|
508
|
-
*/
|
|
512
|
+
/** Speakers of a native-order mask, or `null` when its bit count is not `channels`. */
|
|
509
513
|
function maskSpeakers(mask, channels) {
|
|
510
514
|
const speakers = speakersOfMask(mask);
|
|
511
515
|
return speakers.length === channels ? declared(speakers) : null;
|
|
512
516
|
}
|
|
513
|
-
// AAC syntax elements and
|
|
517
|
+
// AAC syntax elements and program config element positions (`aacdec.h`).
|
|
514
518
|
const SCE = 0;
|
|
515
519
|
const CPE = 1;
|
|
516
520
|
const CCE = 2;
|
|
@@ -522,10 +526,7 @@ const LFE = 4;
|
|
|
522
526
|
const CC = 5;
|
|
523
527
|
const AAC_NONE = -1;
|
|
524
528
|
const AAC_UNUSED = 0x200;
|
|
525
|
-
/**
|
|
526
|
-
* The channels `FFmpeg`'s AAC decoder assigns elements at each position, by height layer, then
|
|
527
|
-
* position (front, side, back, LFE): `ff_aac_channel_map`.
|
|
528
|
-
*/
|
|
529
|
+
/** `ff_aac_channel_map`: channels by height layer, then position (front, side, back, LFE). */
|
|
529
530
|
const AAC_CHANNEL_MAP = [
|
|
530
531
|
[
|
|
531
532
|
[2, 6, 7, 0, 1, AAC_NONE],
|
|
@@ -551,10 +552,9 @@ const elements = (spec) => spec.split(" ").map((element) => ({
|
|
|
551
552
|
position: { F: FRONT, S: SIDE, B: BACK, L: LFE }[element[1]],
|
|
552
553
|
}));
|
|
553
554
|
/**
|
|
554
|
-
*
|
|
555
|
-
*
|
|
556
|
-
*
|
|
557
|
-
* encoders write it, rather than the specification's 7.1(wide), unless asked to be strict.
|
|
555
|
+
* `ff_aac_channel_layout_map`: elements of each AAC channel configuration. Configuration 7's
|
|
556
|
+
* second front pair is a back pair, since `FFmpeg` decodes it as 7.1 (as encoders write it) rather
|
|
557
|
+
* than the specification's 7.1(wide).
|
|
558
558
|
*/
|
|
559
559
|
const AAC_CONFIGURATION_ELEMENTS = {
|
|
560
560
|
1: elements("SF"),
|
|
@@ -569,11 +569,11 @@ const AAC_CONFIGURATION_ELEMENTS = {
|
|
|
569
569
|
13: elements("SF CF CF CB CB SB LL LL SF CF CS SS CB SB SF CF"),
|
|
570
570
|
14: elements("SF CF CB LL CF"),
|
|
571
571
|
};
|
|
572
|
-
/**
|
|
572
|
+
/** `ff_mpeg4audio_channels`. */
|
|
573
573
|
const AAC_CONFIGURATION_CHANNELS = [
|
|
574
574
|
0, 1, 2, 3, 4, 5, 6, 8, 0, 0, 0, 7, 8, 24, 8,
|
|
575
575
|
];
|
|
576
|
-
/**
|
|
576
|
+
/** `ff_mpeg4audio_sample_rates`. */
|
|
577
577
|
const AAC_SAMPLE_RATES = [
|
|
578
578
|
96_000, 88_200, 64_000, 48_000, 44_100, 32_000, 24_000, 22_050, 16_000,
|
|
579
579
|
12_000, 11_025, 8_000, 7_350,
|
|
@@ -581,9 +581,9 @@ const AAC_SAMPLE_RATES = [
|
|
|
581
581
|
const AOT_AAC_LC = 2;
|
|
582
582
|
const AOT_SBR = 5;
|
|
583
583
|
const AOT_PS = 29;
|
|
584
|
-
/** Object types whose `GASpecificConfig` `FFmpeg` reads
|
|
584
|
+
/** Object types whose `GASpecificConfig` (including a PCE) `FFmpeg` reads. */
|
|
585
585
|
const AAC_GA_OBJECT_TYPES = new Set([1, 2, 3, 4, 17, 23]);
|
|
586
|
-
/** `count_paired_channels
|
|
586
|
+
/** `count_paired_channels`. */
|
|
587
587
|
function countPairedChannels(map, position, current) {
|
|
588
588
|
let channels = 0;
|
|
589
589
|
let firstCpe = false;
|
|
@@ -611,10 +611,7 @@ function countPairedChannels(map, position, current) {
|
|
|
611
611
|
return -1;
|
|
612
612
|
return channels;
|
|
613
613
|
}
|
|
614
|
-
/**
|
|
615
|
-
* `assign_channels`: the channels of the elements at `position` in `layer`, from `state.current`,
|
|
616
|
-
* added to `state.mask`. `false` where `FFmpeg` gives up on the layout.
|
|
617
|
-
*/
|
|
614
|
+
/** `assign_channels`; returns `false` where `FFmpeg` gives up on the layout. */
|
|
618
615
|
function assignChannels(map, layer, position, state) {
|
|
619
616
|
const channelsOf = AAC_CHANNEL_MAP[layer][position - 1];
|
|
620
617
|
let channels = countPairedChannels(map, position, state.current);
|
|
@@ -662,9 +659,8 @@ function assignChannels(map, layer, position, state) {
|
|
|
662
659
|
return channels === 0;
|
|
663
660
|
}
|
|
664
661
|
/**
|
|
665
|
-
*
|
|
666
|
-
*
|
|
667
|
-
* native order.
|
|
662
|
+
* Channel mask from `sniff_channel_order`, or `0n` when the layout stays unspecified. Planes are
|
|
663
|
+
* delivered in the mask's native order.
|
|
668
664
|
*/
|
|
669
665
|
function aacElementsMask(map, ps) {
|
|
670
666
|
const state = { current: 0, mask: 0n };
|
|
@@ -682,8 +678,8 @@ function aacElementsMask(map, ps) {
|
|
|
682
678
|
return state.mask;
|
|
683
679
|
}
|
|
684
680
|
/**
|
|
685
|
-
*
|
|
686
|
-
*
|
|
681
|
+
* `decode_pce`, starting after the element instance tag; `null` when truncated. `alignment` is the
|
|
682
|
+
* bit the comment's byte alignment counts from.
|
|
687
683
|
*/
|
|
688
684
|
function programConfigElements(bits, alignment) {
|
|
689
685
|
bits.skip(2 + 4); // object type, sampling frequency index
|
|
@@ -732,9 +728,8 @@ function aacObjectType(bits) {
|
|
|
732
728
|
return type === 31 ? 32 + bits.read(6) : type;
|
|
733
729
|
}
|
|
734
730
|
/**
|
|
735
|
-
*
|
|
736
|
-
*
|
|
737
|
-
* channels. `undefined` when `FFmpeg` would not decode the config.
|
|
731
|
+
* Elements an `AudioSpecificConfig` declares (from its channel configuration or PCE), plus whether
|
|
732
|
+
* parametric stereo applies. `undefined` when `FFmpeg` would not decode the config.
|
|
738
733
|
*/
|
|
739
734
|
function aacConfigElements(config) {
|
|
740
735
|
try {
|
|
@@ -763,7 +758,7 @@ function aacConfigElements(config) {
|
|
|
763
758
|
bits.skip(4);
|
|
764
759
|
}
|
|
765
760
|
if (!explicitSbr) {
|
|
766
|
-
//
|
|
761
|
+
// Backward-compatible SBR or PS signalling after the specific config.
|
|
767
762
|
const sync = bits.copy();
|
|
768
763
|
while (sync.left > 15) {
|
|
769
764
|
if (sync.show(11) !== 0x2b7) {
|
|
@@ -828,10 +823,8 @@ function aacConfigElements(config) {
|
|
|
828
823
|
}
|
|
829
824
|
}
|
|
830
825
|
/**
|
|
831
|
-
*
|
|
832
|
-
*
|
|
833
|
-
* `ff_aac_output_configure` does. `null` when `FFmpeg` leaves the layout unspecified;
|
|
834
|
-
* `undefined` when it would not decode the config at all.
|
|
826
|
+
* Speakers of an `AudioSpecificConfig` as `ff_aac_output_configure` orders them. `null` when the
|
|
827
|
+
* layout stays unspecified; `undefined` when `FFmpeg` would not decode the config.
|
|
835
828
|
*/
|
|
836
829
|
export function aacSpeakers(config) {
|
|
837
830
|
const elements = aacConfigElements(config);
|
|
@@ -841,10 +834,9 @@ export function aacSpeakers(config) {
|
|
|
841
834
|
return mask === 0n ? null : speakersOfMask(mask);
|
|
842
835
|
}
|
|
843
836
|
/**
|
|
844
|
-
*
|
|
845
|
-
*
|
|
846
|
-
*
|
|
847
|
-
* configuration or one `FFmpeg` would not decode.
|
|
837
|
+
* PCE output elements as type then position letters: `SF CF CB LL` is a front SCE, a front CPE,
|
|
838
|
+
* a back CPE and an LFE. `null` for a config with a channel configuration or one `FFmpeg` would not
|
|
839
|
+
* decode.
|
|
848
840
|
*/
|
|
849
841
|
export function aacProgramConfigElements(config) {
|
|
850
842
|
const elements = aacConfigElements(config);
|
|
@@ -855,7 +847,7 @@ export function aacProgramConfigElements(config) {
|
|
|
855
847
|
.map((element) => ["S", "C", "", "L"][element.type] + " FSBL"[element.position])
|
|
856
848
|
.join(" ");
|
|
857
849
|
}
|
|
858
|
-
/**
|
|
850
|
+
/** Channels of each AC-3 `acmod`, as `FFmpeg` lays them out. */
|
|
859
851
|
const AC3_MODE_MASKS = [
|
|
860
852
|
"FL FR",
|
|
861
853
|
"FC",
|
|
@@ -866,7 +858,7 @@ const AC3_MODE_MASKS = [
|
|
|
866
858
|
"FL FR SL SR",
|
|
867
859
|
"FL FR FC SL SR",
|
|
868
860
|
].map(bitsOf);
|
|
869
|
-
/**
|
|
861
|
+
/** Channels each E-AC-3 dependent substream channel map bit adds, most significant first. */
|
|
870
862
|
const EAC3_CHANNEL_MAP = [
|
|
871
863
|
"FL",
|
|
872
864
|
"FC",
|
|
@@ -976,9 +968,8 @@ function ac3Header(frame) {
|
|
|
976
968
|
}
|
|
977
969
|
}
|
|
978
970
|
/**
|
|
979
|
-
*
|
|
980
|
-
*
|
|
981
|
-
* `undefined` when the packet does not start with a frame `FFmpeg` decodes.
|
|
971
|
+
* Speakers `FFmpeg`'s AC-3 or E-AC-3 decoder produces for a packet, including channels added by an
|
|
972
|
+
* E-AC-3 dependent frame. `undefined` when the packet does not start with a decodable frame.
|
|
982
973
|
*/
|
|
983
974
|
export function ac3Speakers(packet) {
|
|
984
975
|
const first = ac3Header(packet);
|
|
@@ -997,7 +988,7 @@ export function ac3Speakers(packet) {
|
|
|
997
988
|
}
|
|
998
989
|
return speakersOfMask(mask);
|
|
999
990
|
}
|
|
1000
|
-
/**
|
|
991
|
+
/** Speakers of each DTS core `AMODE` that `FFmpeg` decodes. */
|
|
1001
992
|
const DTS_MODE_MASKS = [
|
|
1002
993
|
"FC",
|
|
1003
994
|
"FL FR",
|
|
@@ -1013,13 +1004,11 @@ const DTS_MODE_MASKS = [
|
|
|
1013
1004
|
const DTS_CORE_SYNC = 0x7ffe8001;
|
|
1014
1005
|
const DTS_CORE_SYNC_LE = 0xfe7f0180;
|
|
1015
1006
|
const DTS_SUBSTREAM_SYNC = 0x64582025;
|
|
1016
|
-
/**
|
|
1007
|
+
/** Core extension types that add channels: XCH and XXCH. */
|
|
1017
1008
|
const DTS_CHANNEL_EXTENSIONS = new Set([0, 6]);
|
|
1018
1009
|
/**
|
|
1019
|
-
*
|
|
1020
|
-
*
|
|
1021
|
-
* (channel extensions, an extension substream, a substream without a core) or is not a 16-bit
|
|
1022
|
-
* core; those layouts are not read.
|
|
1010
|
+
* Speakers of a core-only DTS packet. `null` for anything beyond a 16-bit core (channel extensions,
|
|
1011
|
+
* extension substreams, coreless substreams), whose layouts are not read.
|
|
1023
1012
|
*/
|
|
1024
1013
|
export function dtsSpeakers(packet) {
|
|
1025
1014
|
if (packet.length < 16)
|
|
@@ -1072,10 +1061,7 @@ export function dtsSpeakers(packet) {
|
|
|
1072
1061
|
return null;
|
|
1073
1062
|
}
|
|
1074
1063
|
}
|
|
1075
|
-
/**
|
|
1076
|
-
* `strtol(text, NULL, 0)` as a 64-bit two's-complement value: leading space, a sign, then a hex
|
|
1077
|
-
* (`0x`), octal (`0`) or decimal number, read up to the first character that is not a digit.
|
|
1078
|
-
*/
|
|
1064
|
+
/** C `strtol(text, NULL, 0)` as a 64-bit two's-complement value. */
|
|
1079
1065
|
function strtol(text) {
|
|
1080
1066
|
const match = /^[\t\n\v\f\r ]*([+-]?)(0[xX](?=[0-9a-fA-F])|0?)([0-9a-fA-F]*)/.exec(text);
|
|
1081
1067
|
const [, sign, prefix, rest] = match;
|
|
@@ -1096,9 +1082,8 @@ function strtol(text) {
|
|
|
1096
1082
|
return BigInt.asUintN(64, value);
|
|
1097
1083
|
}
|
|
1098
1084
|
/**
|
|
1099
|
-
*
|
|
1100
|
-
*
|
|
1101
|
-
* a mask `FFmpeg` refuses (zero, or past its first 18 speakers).
|
|
1085
|
+
* Mask from the first `WAVEFORMATEXTENSIBLE_CHANNEL_MASK` comment in a FLAC `VORBIS_COMMENT` block,
|
|
1086
|
+
* or `null` when absent or refused by `FFmpeg` (zero, or beyond its first 18 speakers).
|
|
1102
1087
|
*/
|
|
1103
1088
|
function vorbisCommentMask(block) {
|
|
1104
1089
|
const view = new DataView(block.buffer, block.byteOffset, block.byteLength);
|
|
@@ -1128,10 +1113,7 @@ function vorbisCommentMask(block) {
|
|
|
1128
1113
|
}
|
|
1129
1114
|
return null;
|
|
1130
1115
|
}
|
|
1131
|
-
/**
|
|
1132
|
-
* The first FLAC `VORBIS_COMMENT` block among the metadata blocks from `offset`, read through
|
|
1133
|
-
* `read`, or `null`.
|
|
1134
|
-
*/
|
|
1116
|
+
/** First FLAC `VORBIS_COMMENT` block among the metadata blocks from `offset`, or `null`. */
|
|
1135
1117
|
async function flacVorbisComment(read, offset) {
|
|
1136
1118
|
let at = offset;
|
|
1137
1119
|
for (let block = 0; block < 128; block += 1) {
|
|
@@ -1148,12 +1130,11 @@ async function flacVorbisComment(read, offset) {
|
|
|
1148
1130
|
return null;
|
|
1149
1131
|
}
|
|
1150
1132
|
/**
|
|
1151
|
-
*
|
|
1152
|
-
* `FFmpeg`
|
|
1153
|
-
* block is the stream info (`description`). `FFmpeg`'s MP4 and Ogg demuxers read none.
|
|
1133
|
+
* FLAC channel-mask comment from a FLAC file's metadata or Matroska codec private data
|
|
1134
|
+
* (`description`). `FFmpeg`'s MP4 and Ogg demuxers do not read it.
|
|
1154
1135
|
*/
|
|
1155
1136
|
async function flacMask(read, description) {
|
|
1156
|
-
//
|
|
1137
|
+
// Skip a leading ID3v2 tag, as `FFmpeg` does.
|
|
1157
1138
|
let start = 0;
|
|
1158
1139
|
const id3 = await read(0, 10);
|
|
1159
1140
|
if (id3.length === 10 && boxType(id3, 0).startsWith("ID3"))
|
|
@@ -1178,7 +1159,7 @@ async function flacMask(read, description) {
|
|
|
1178
1159
|
const block = await flacVorbisComment((offset, length) => Promise.resolve(description.subarray(offset, offset + length)), 42);
|
|
1179
1160
|
return block === null ? null : vorbisCommentMask(block);
|
|
1180
1161
|
}
|
|
1181
|
-
/** Vorbis
|
|
1162
|
+
/** Vorbis and Opus mapping family 1 channel orders, as `FFmpeg` reorders them. */
|
|
1182
1163
|
const VORBIS_LAYOUTS = [
|
|
1183
1164
|
"FC",
|
|
1184
1165
|
"FL FR",
|
|
@@ -1200,7 +1181,7 @@ const FLAC_LAYOUTS = [
|
|
|
1200
1181
|
"FL FR FC LFE BC SL SR",
|
|
1201
1182
|
"FL FR FC LFE BL BR SL SR",
|
|
1202
1183
|
];
|
|
1203
|
-
/**
|
|
1184
|
+
/** AAC channel configuration for each ADTS channel count (configurations 1 to 7). */
|
|
1204
1185
|
export const ADTS_CONFIGURATIONS = {
|
|
1205
1186
|
1: 1,
|
|
1206
1187
|
2: 2,
|
|
@@ -1210,10 +1191,7 @@ export const ADTS_CONFIGURATIONS = {
|
|
|
1210
1191
|
6: 6,
|
|
1211
1192
|
8: 7,
|
|
1212
1193
|
};
|
|
1213
|
-
/**
|
|
1214
|
-
* The AAC channel configuration of an `AudioSpecificConfig`. `null` for a truncated config or for
|
|
1215
|
-
* configuration 0, which defers to a program config element.
|
|
1216
|
-
*/
|
|
1194
|
+
/** AAC channel configuration, or `null` when truncated or 0 (defers to a PCE). */
|
|
1217
1195
|
export function aacChannelConfiguration(config) {
|
|
1218
1196
|
try {
|
|
1219
1197
|
const bits = new Bits(config);
|
|
@@ -1227,7 +1205,7 @@ export function aacChannelConfiguration(config) {
|
|
|
1227
1205
|
return null;
|
|
1228
1206
|
}
|
|
1229
1207
|
}
|
|
1230
|
-
/**
|
|
1208
|
+
/** `OpusHead` channel mapping family; 0 without a head. */
|
|
1231
1209
|
export function opusMappingFamily(description) {
|
|
1232
1210
|
return description !== null &&
|
|
1233
1211
|
description.length >= 19 &&
|
|
@@ -1236,15 +1214,14 @@ export function opusMappingFamily(description) {
|
|
|
1236
1214
|
: 0;
|
|
1237
1215
|
}
|
|
1238
1216
|
/**
|
|
1239
|
-
*
|
|
1240
|
-
*
|
|
1217
|
+
* Layout the codec's decoder sets. `undefined` when the container decides, `null` when the decoder
|
|
1218
|
+
* leaves it unspecified.
|
|
1241
1219
|
*/
|
|
1242
1220
|
function decoderLayout(codec, description, channels, packet) {
|
|
1243
1221
|
const fixed = (layouts) => layouts[channels - 1] === undefined ? null : list(layouts[channels - 1]);
|
|
1244
1222
|
switch (codec) {
|
|
1245
1223
|
case "aac": {
|
|
1246
|
-
//
|
|
1247
|
-
// to 7 by their distinct channel counts.
|
|
1224
|
+
// No `AudioSpecificConfig` means ADTS, whose configurations 1 to 7 have distinct counts.
|
|
1248
1225
|
const configuration = ADTS_CONFIGURATIONS[channels];
|
|
1249
1226
|
const config = description ??
|
|
1250
1227
|
(configuration === undefined
|
|
@@ -1280,24 +1257,16 @@ function decoderLayout(codec, description, channels, packet) {
|
|
|
1280
1257
|
return channels <= 2 ? fixed(VORBIS_LAYOUTS) : undefined;
|
|
1281
1258
|
}
|
|
1282
1259
|
/**
|
|
1283
|
-
*
|
|
1284
|
-
*
|
|
1285
|
-
*
|
|
1286
|
-
* head, Vorbis's and FLAC's fixed orders, an AC-3 or E-AC-3 frame's channel mode, LFE and
|
|
1287
|
-
* dependent channel map, a DTS core's channel arrangement, and mono or stereo for any codec.
|
|
1288
|
-
* `null` when the codec says nothing the decoder would read, or the decoder would leave the layout
|
|
1289
|
-
* unspecified.
|
|
1260
|
+
* Speakers a codec's own headers declare, in `FFmpeg`'s decoder plane order. Covers AAC, Opus
|
|
1261
|
+
* mapping families 0 and 1, Vorbis and FLAC fixed orders, AC-3/E-AC-3, DTS cores, and mono or
|
|
1262
|
+
* stereo for any codec. `null` when the decoder would leave the layout unspecified.
|
|
1290
1263
|
*
|
|
1291
|
-
*
|
|
1292
|
-
*
|
|
1293
|
-
* @param description The decoder configuration's description (`AudioSpecificConfig`,
|
|
1294
|
-
* `OpusHead`), when the track has one.
|
|
1295
|
-
* @param packet The track's first packet, which an AC-3, E-AC-3 or DTS decoder reads its layout
|
|
1296
|
-
* from.
|
|
1264
|
+
* Other decoders may deliver another order (Safari's AAC keeps bitstream order);
|
|
1265
|
+
* `decoder-order.ts` measures and corrects for that.
|
|
1297
1266
|
*
|
|
1298
|
-
*
|
|
1299
|
-
*
|
|
1300
|
-
*
|
|
1267
|
+
* @param codec mediabunny's codec name (`aac`, `opus`, `vorbis`, `flac`, `ac3`, `eac3`, `dts`).
|
|
1268
|
+
* @param description The decoder configuration description (`AudioSpecificConfig`, `OpusHead`).
|
|
1269
|
+
* @param packet The first packet, from which AC-3, E-AC-3 and DTS layouts are read.
|
|
1301
1270
|
*/
|
|
1302
1271
|
export function codecSpeakers(codec, description, channels, packet = null) {
|
|
1303
1272
|
const speakers = decoderLayout(codec, description, channels, packet);
|
|
@@ -1308,22 +1277,19 @@ export function codecSpeakers(codec, description, channels, packet = null) {
|
|
|
1308
1277
|
: null;
|
|
1309
1278
|
}
|
|
1310
1279
|
/**
|
|
1311
|
-
*
|
|
1280
|
+
* Speakers the source's primary audio track declares, or `null`.
|
|
1312
1281
|
*
|
|
1313
|
-
*
|
|
1314
|
-
*
|
|
1315
|
-
*
|
|
1316
|
-
* Matroska, a QuickTime `chan` or ISO `chnl` box, and FLAC's own order otherwise. PCM, and any
|
|
1317
|
-
* other codec, is laid out by its container: a WAVE channel mask, a QuickTime `chan` box, an ISO
|
|
1318
|
-
* `chnl` box.
|
|
1282
|
+
* Codecs whose decoder sets a layout use {@link codecSpeakers} regardless of the container. FLAC
|
|
1283
|
+
* takes a matching container layout (channel-mask comment, `chan` or `chnl`), else its own order.
|
|
1284
|
+
* PCM and other codecs use the container's WAVE mask, `chan` or `chnl` box.
|
|
1319
1285
|
*
|
|
1320
1286
|
* @param read Reads the source file's bytes.
|
|
1321
1287
|
* @param size The source file's size in bytes.
|
|
1322
|
-
* @param track
|
|
1323
|
-
*
|
|
1288
|
+
* @param track `id` selects the QuickTime `trak`; without a match, the first track with a layout
|
|
1289
|
+
* box is used.
|
|
1324
1290
|
* @param description The track's decoder configuration description, if any.
|
|
1325
|
-
* @param firstPacket Reads the
|
|
1326
|
-
*
|
|
1291
|
+
* @param firstPacket Reads the first packet, for AC-3, E-AC-3 and DTS; resolves `null` when there
|
|
1292
|
+
* is none.
|
|
1327
1293
|
*
|
|
1328
1294
|
* Rejects only when `read` or `firstPacket` rejects; malformed bytes resolve to `null`.
|
|
1329
1295
|
*/
|