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/chroma-siting.d.ts
CHANGED
|
@@ -1,71 +1,54 @@
|
|
|
1
1
|
/**
|
|
2
|
-
*
|
|
3
|
-
*
|
|
4
|
-
*
|
|
5
|
-
* conversion must place chroma where the encoder did, or every chroma edge lands half a sample
|
|
6
|
-
* off. `unspecified` is converted as centered.
|
|
2
|
+
* Position of subsampled chroma relative to luma. WebCodecs does not report it, so the demuxer
|
|
3
|
+
* supplies it; a wrong siting shifts chroma edges by half a sample. `unspecified` converts as
|
|
4
|
+
* centered.
|
|
7
5
|
*/
|
|
8
6
|
export type ChromaSiting = "left" | "center" | "top-left" | "unspecified";
|
|
9
7
|
/**
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
* H.264, HEVC, and MPEG-4 Part 2 default 4:2:0 chroma to the left (H.273
|
|
13
|
-
* chroma sample location type 0), as FFmpeg reports them natively. Other
|
|
14
|
-
* codecs stay unspecified, which the engine reads as centered, again as
|
|
15
|
-
* natively.
|
|
8
|
+
* Default chroma siting for a codec. H.264, HEVC and MPEG-4 Part 2 default to `left` (H.273 type
|
|
9
|
+
* 0); other codecs are `unspecified`.
|
|
16
10
|
*/
|
|
17
11
|
export declare function chromaSitingForCodec(codec: string | null | undefined): ChromaSiting;
|
|
18
12
|
/**
|
|
19
|
-
*
|
|
20
|
-
* frames it decodes.
|
|
13
|
+
* Chroma siting a stream signals, matching the native host's reading of FFmpeg's decoder.
|
|
21
14
|
*
|
|
22
|
-
* H.264
|
|
23
|
-
* (`
|
|
24
|
-
*
|
|
25
|
-
* `description` (`avcC`, `hvcC`, `av1C`) or, when it has none (Annex B
|
|
26
|
-
* streams, AV1 in MP4), from the stream's first packet. With neither, or for
|
|
27
|
-
* another codec, the codec's default ({@link chromaSitingForCodec}).
|
|
15
|
+
* Read from the H.264/HEVC SPS VUI or the AV1 sequence header, found in the configuration's
|
|
16
|
+
* `description` (`avcC`, `hvcC`, `av1C`) or else in the first packet. Falls back to
|
|
17
|
+
* {@link chromaSitingForCodec}.
|
|
28
18
|
*
|
|
29
|
-
*
|
|
30
|
-
*
|
|
31
|
-
* 5) is `left`, as H.264 infers it without one (E.2.1) and the native host
|
|
32
|
-
* reads what FFmpeg leaves unspecified. An H.264 or HEVC type from 3 to 5 is
|
|
33
|
-
* `unspecified`, as are AV1's unknown position and HEVC that is not 4:2:0.
|
|
19
|
+
* An H.264 stream with no VUI or a reserved type (above 5) is `left`, as H.264 infers (E.2.1).
|
|
20
|
+
* H.264 or HEVC types 3 to 5, AV1's unknown position, and non-4:2:0 HEVC are `unspecified`.
|
|
34
21
|
*/
|
|
35
22
|
export declare function chromaSitingForStream(codec: string | null | undefined, description?: AllowSharedBufferSource | null, firstPacket?: AllowSharedBufferSource | null): ChromaSiting;
|
|
36
|
-
/**
|
|
23
|
+
/** Sample (pixel) aspect ratio: width over height of one sample. */
|
|
37
24
|
export interface SampleAspect {
|
|
38
25
|
readonly num: number;
|
|
39
26
|
readonly den: number;
|
|
40
27
|
}
|
|
41
28
|
/**
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* `undefined` when the stream signals none (no VUI, `aspect_ratio_idc` 0, a reserved index, or a
|
|
46
|
-
* zero term), for another codec, or when the parameter set does not parse: as FFmpeg's decoder
|
|
47
|
-
* reports it, which a native probe falls back to when the container declares no ratio
|
|
48
|
-
* (`av_guess_sample_aspect_ratio`).
|
|
29
|
+
* Sample aspect ratio from an H.264 or HEVC SPS VUI, read from `description` or else the first
|
|
30
|
+
* packet. `undefined` when none is signalled, for other codecs, or when the SPS does not parse,
|
|
31
|
+
* matching FFmpeg's decoder (which a native probe uses when the container declares no ratio).
|
|
49
32
|
*/
|
|
50
33
|
export declare function sampleAspectForStream(codec: string | null | undefined, description?: AllowSharedBufferSource | null, firstPacket?: AllowSharedBufferSource | null): SampleAspect | undefined;
|
|
51
34
|
/**
|
|
52
|
-
*
|
|
53
|
-
*
|
|
35
|
+
* Chroma siting from one H.264 SPS NAL unit (including its one-byte header), as FFmpeg's parser
|
|
36
|
+
* derives `vui.chroma_location`. An unspecified location reads as `left`, as H.264 infers.
|
|
54
37
|
*
|
|
55
|
-
*
|
|
38
|
+
* @throws RangeError When the SPS ends early.
|
|
56
39
|
*/
|
|
57
40
|
export declare function h264SpsSiting(nal: Uint8Array): ChromaSiting;
|
|
58
41
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
42
|
+
* Chroma siting from one HEVC SPS NAL unit (including its two-byte header), as FFmpeg's decoder
|
|
43
|
+
* sets `avctx->chroma_sample_location`.
|
|
61
44
|
*
|
|
62
|
-
*
|
|
45
|
+
* @throws RangeError When the SPS ends early.
|
|
63
46
|
*/
|
|
64
47
|
export declare function hevcSpsSiting(nal: Uint8Array): ChromaSiting;
|
|
65
48
|
/**
|
|
66
|
-
*
|
|
67
|
-
*
|
|
49
|
+
* Chroma siting from an AV1 sequence header OBU payload, as FFmpeg's AV1 decoders set
|
|
50
|
+
* `avctx->chroma_sample_location`.
|
|
68
51
|
*
|
|
69
|
-
*
|
|
52
|
+
* @throws RangeError When the header ends early.
|
|
70
53
|
*/
|
|
71
54
|
export declare function av1SequenceHeaderSiting(payload: Uint8Array): ChromaSiting;
|
package/dist/chroma-siting.js
CHANGED
|
@@ -1,12 +1,8 @@
|
|
|
1
|
-
// Reads chroma siting and sample
|
|
2
|
-
// decodes
|
|
1
|
+
// Reads chroma siting and sample aspect from parameter sets as FFmpeg does, so browser and native
|
|
2
|
+
// decodes agree.
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
* H.264, HEVC, and MPEG-4 Part 2 default 4:2:0 chroma to the left (H.273
|
|
7
|
-
* chroma sample location type 0), as FFmpeg reports them natively. Other
|
|
8
|
-
* codecs stay unspecified, which the engine reads as centered, again as
|
|
9
|
-
* natively.
|
|
4
|
+
* Default chroma siting for a codec. H.264, HEVC and MPEG-4 Part 2 default to `left` (H.273 type
|
|
5
|
+
* 0); other codecs are `unspecified`.
|
|
10
6
|
*/
|
|
11
7
|
export function chromaSitingForCodec(codec) {
|
|
12
8
|
switch (codecFamily(codec)) {
|
|
@@ -19,21 +15,14 @@ export function chromaSitingForCodec(codec) {
|
|
|
19
15
|
}
|
|
20
16
|
}
|
|
21
17
|
/**
|
|
22
|
-
*
|
|
23
|
-
* frames it decodes.
|
|
18
|
+
* Chroma siting a stream signals, matching the native host's reading of FFmpeg's decoder.
|
|
24
19
|
*
|
|
25
|
-
* H.264
|
|
26
|
-
* (`
|
|
27
|
-
*
|
|
28
|
-
* `description` (`avcC`, `hvcC`, `av1C`) or, when it has none (Annex B
|
|
29
|
-
* streams, AV1 in MP4), from the stream's first packet. With neither, or for
|
|
30
|
-
* another codec, the codec's default ({@link chromaSitingForCodec}).
|
|
20
|
+
* Read from the H.264/HEVC SPS VUI or the AV1 sequence header, found in the configuration's
|
|
21
|
+
* `description` (`avcC`, `hvcC`, `av1C`) or else in the first packet. Falls back to
|
|
22
|
+
* {@link chromaSitingForCodec}.
|
|
31
23
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* 5) is `left`, as H.264 infers it without one (E.2.1) and the native host
|
|
35
|
-
* reads what FFmpeg leaves unspecified. An H.264 or HEVC type from 3 to 5 is
|
|
36
|
-
* `unspecified`, as are AV1's unknown position and HEVC that is not 4:2:0.
|
|
24
|
+
* An H.264 stream with no VUI or a reserved type (above 5) is `left`, as H.264 infers (E.2.1).
|
|
25
|
+
* H.264 or HEVC types 3 to 5, AV1's unknown position, and non-4:2:0 HEVC are `unspecified`.
|
|
37
26
|
*/
|
|
38
27
|
export function chromaSitingForStream(codec, description, firstPacket) {
|
|
39
28
|
const family = codecFamily(codec);
|
|
@@ -51,20 +40,16 @@ export function chromaSitingForStream(codec, description, firstPacket) {
|
|
|
51
40
|
}
|
|
52
41
|
}
|
|
53
42
|
catch {
|
|
54
|
-
//
|
|
43
|
+
// Decoders ignore a truncated or malformed parameter set too.
|
|
55
44
|
return undefined;
|
|
56
45
|
}
|
|
57
46
|
})();
|
|
58
47
|
return signalled ?? chromaSitingForCodec(codec);
|
|
59
48
|
}
|
|
60
49
|
/**
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
* `undefined` when the stream signals none (no VUI, `aspect_ratio_idc` 0, a reserved index, or a
|
|
65
|
-
* zero term), for another codec, or when the parameter set does not parse: as FFmpeg's decoder
|
|
66
|
-
* reports it, which a native probe falls back to when the container declares no ratio
|
|
67
|
-
* (`av_guess_sample_aspect_ratio`).
|
|
50
|
+
* Sample aspect ratio from an H.264 or HEVC SPS VUI, read from `description` or else the first
|
|
51
|
+
* packet. `undefined` when none is signalled, for other codecs, or when the SPS does not parse,
|
|
52
|
+
* matching FFmpeg's decoder (which a native probe uses when the container declares no ratio).
|
|
68
53
|
*/
|
|
69
54
|
export function sampleAspectForStream(codec, description, firstPacket) {
|
|
70
55
|
try {
|
|
@@ -108,10 +93,7 @@ function bytesOf(source) {
|
|
|
108
93
|
}
|
|
109
94
|
return new Uint8Array(source);
|
|
110
95
|
}
|
|
111
|
-
/**
|
|
112
|
-
* FFmpeg's `AVChromaLocation` for an H.273 chroma sample location type, using the engine's names
|
|
113
|
-
* for the ones it samples.
|
|
114
|
-
*/
|
|
96
|
+
/** Maps an H.273 chroma sample location type as FFmpeg's `AVChromaLocation` does. */
|
|
115
97
|
function sitingOfLocationType(type) {
|
|
116
98
|
switch (type) {
|
|
117
99
|
case 0:
|
|
@@ -121,12 +103,11 @@ function sitingOfLocationType(type) {
|
|
|
121
103
|
case 2:
|
|
122
104
|
return "top-left";
|
|
123
105
|
default:
|
|
124
|
-
//
|
|
125
|
-
// reserved.
|
|
106
|
+
// Types 3 to 5 sample as centered natively; above 5 is reserved.
|
|
126
107
|
return "unspecified";
|
|
127
108
|
}
|
|
128
109
|
}
|
|
129
|
-
/**
|
|
110
|
+
/** First H.264 SPS NAL unit, from the `avcC` record or else the first packet. */
|
|
130
111
|
function avcSps(description, firstPacket) {
|
|
131
112
|
return (avcConfigurationSps(bytesOf(description)) ??
|
|
132
113
|
packetNalUnits(bytesOf(firstPacket)).find((unit) => unit.length > 0 && (unit[0] & 0x1f) === 7));
|
|
@@ -135,7 +116,6 @@ function avcSiting(description, firstPacket) {
|
|
|
135
116
|
const sps = avcSps(description, firstPacket);
|
|
136
117
|
return sps === undefined ? undefined : h264SpsSiting(sps);
|
|
137
118
|
}
|
|
138
|
-
/** The first SPS NAL unit of an `avcC` record. */
|
|
139
119
|
function avcConfigurationSps(record) {
|
|
140
120
|
if (record === undefined || record.length < 8 || record[0] !== 1) {
|
|
141
121
|
return undefined;
|
|
@@ -148,22 +128,19 @@ function avcConfigurationSps(record) {
|
|
|
148
128
|
? record.subarray(8, 8 + length)
|
|
149
129
|
: undefined;
|
|
150
130
|
}
|
|
151
|
-
/**
|
|
152
|
-
* The profiles whose SPS carries `chroma_format_idc` and the fields after it, as FFmpeg lists them.
|
|
153
|
-
*/
|
|
131
|
+
/** Profiles whose SPS carries `chroma_format_idc` and following fields (FFmpeg's list). */
|
|
154
132
|
const H264_HIGH_PROFILES = new Set([
|
|
155
133
|
100, 110, 122, 244, 44, 83, 86, 118, 128, 138, 144,
|
|
156
134
|
]);
|
|
157
135
|
/**
|
|
158
|
-
*
|
|
159
|
-
*
|
|
136
|
+
* Chroma siting from one H.264 SPS NAL unit (including its one-byte header), as FFmpeg's parser
|
|
137
|
+
* derives `vui.chroma_location`. An unspecified location reads as `left`, as H.264 infers.
|
|
160
138
|
*
|
|
161
|
-
*
|
|
139
|
+
* @throws RangeError When the SPS ends early.
|
|
162
140
|
*/
|
|
163
141
|
export function h264SpsSiting(nal) {
|
|
164
142
|
return h264Sps(nal).siting;
|
|
165
143
|
}
|
|
166
|
-
/** What one H.264 SPS NAL unit says of its chroma siting and its sample aspect ratio. */
|
|
167
144
|
function h264Sps(nal) {
|
|
168
145
|
const bits = new BitReader(unescape(nal.subarray(1)));
|
|
169
146
|
const profile = bits.bits(8);
|
|
@@ -212,8 +189,7 @@ function h264Sps(nal) {
|
|
|
212
189
|
bits.ue();
|
|
213
190
|
bits.ue();
|
|
214
191
|
}
|
|
215
|
-
//
|
|
216
|
-
// H.264 infers type 0.
|
|
192
|
+
// Without VUI, H.264 infers type 0.
|
|
217
193
|
if (!bits.flag())
|
|
218
194
|
return { siting: "left", aspect: undefined };
|
|
219
195
|
return commonVui(bits, "left");
|
|
@@ -227,10 +203,7 @@ function skipH264ScalingList(bits, size) {
|
|
|
227
203
|
last = next === 0 ? last : next;
|
|
228
204
|
}
|
|
229
205
|
}
|
|
230
|
-
/**
|
|
231
|
-
* The sample aspect ratios of `aspect_ratio_idc` 1 to 16 (H.264 table E-1, HEVC table E.1), as
|
|
232
|
-
* FFmpeg's `ff_h2645_pixel_aspect` lists them.
|
|
233
|
-
*/
|
|
206
|
+
/** Sample aspect ratios for `aspect_ratio_idc` 1 to 16 (H.264 table E-1, HEVC table E.1). */
|
|
234
207
|
const PIXEL_ASPECT = [
|
|
235
208
|
[1, 1],
|
|
236
209
|
[12, 11],
|
|
@@ -250,8 +223,8 @@ const PIXEL_ASPECT = [
|
|
|
250
223
|
[2, 1],
|
|
251
224
|
];
|
|
252
225
|
/**
|
|
253
|
-
* `ff_h2645_decode_common_vui_params` up to the chroma location
|
|
254
|
-
*
|
|
226
|
+
* Mirrors `ff_h2645_decode_common_vui_params` up to the chroma location. Siting defaults to
|
|
227
|
+
* `left`; a reserved type (above 5) maps to `reserved`.
|
|
255
228
|
*/
|
|
256
229
|
function commonVui(bits, reserved = "unspecified") {
|
|
257
230
|
let aspect;
|
|
@@ -280,7 +253,7 @@ function commonVui(bits, reserved = "unspecified") {
|
|
|
280
253
|
aspect,
|
|
281
254
|
};
|
|
282
255
|
}
|
|
283
|
-
/**
|
|
256
|
+
/** First HEVC SPS NAL unit, from the `hvcC` record or else the first packet. */
|
|
284
257
|
function hevcSps(description, firstPacket) {
|
|
285
258
|
return (hevcConfigurationSps(bytesOf(description)) ??
|
|
286
259
|
packetNalUnits(bytesOf(firstPacket)).find((unit) => unit.length > 1 && ((unit[0] >> 1) & 0x3f) === 33));
|
|
@@ -289,7 +262,6 @@ function hevcSiting(description, firstPacket) {
|
|
|
289
262
|
const sps = hevcSps(description, firstPacket);
|
|
290
263
|
return sps === undefined ? undefined : hevcSpsSiting(sps);
|
|
291
264
|
}
|
|
292
|
-
/** The first SPS NAL unit of an `hvcC` record. */
|
|
293
265
|
function hevcConfigurationSps(record) {
|
|
294
266
|
if (record === undefined || record.length < 23 || record[0] !== 1) {
|
|
295
267
|
return undefined;
|
|
@@ -317,15 +289,14 @@ function hevcConfigurationSps(record) {
|
|
|
317
289
|
return undefined;
|
|
318
290
|
}
|
|
319
291
|
/**
|
|
320
|
-
*
|
|
321
|
-
*
|
|
292
|
+
* Chroma siting from one HEVC SPS NAL unit (including its two-byte header), as FFmpeg's decoder
|
|
293
|
+
* sets `avctx->chroma_sample_location`.
|
|
322
294
|
*
|
|
323
|
-
*
|
|
295
|
+
* @throws RangeError When the SPS ends early.
|
|
324
296
|
*/
|
|
325
297
|
export function hevcSpsSiting(nal) {
|
|
326
298
|
return hevcSpsFacts(nal).siting;
|
|
327
299
|
}
|
|
328
|
-
/** What one HEVC SPS NAL unit says of its chroma siting and its sample aspect ratio. */
|
|
329
300
|
function hevcSpsFacts(nal) {
|
|
330
301
|
const bits = new BitReader(unescape(nal.subarray(2)));
|
|
331
302
|
bits.skip(4); // sps_video_parameter_set_id
|
|
@@ -379,7 +350,7 @@ function hevcSpsFacts(nal) {
|
|
|
379
350
|
bits.skip(pocLsbBits + 1);
|
|
380
351
|
}
|
|
381
352
|
bits.skip(2); // sps_temporal_mvp_enabled_flag, strong_intra_smoothing_enabled_flag
|
|
382
|
-
// FFmpeg reports a location only for 4:2:0; without VUI
|
|
353
|
+
// FFmpeg reports a location only for 4:2:0; without VUI it reads as left.
|
|
383
354
|
const vui = bits.flag() ? commonVui(bits) : undefined;
|
|
384
355
|
return {
|
|
385
356
|
siting: chromaFormat !== 1 ? "unspecified" : (vui?.siting ?? "left"),
|
|
@@ -419,10 +390,7 @@ function skipHevcScalingListData(bits) {
|
|
|
419
390
|
}
|
|
420
391
|
}
|
|
421
392
|
}
|
|
422
|
-
/**
|
|
423
|
-
* Reads `count` `st_ref_pic_set`s. Each may be predicted from the one before, so their delta POCs
|
|
424
|
-
* are kept.
|
|
425
|
-
*/
|
|
393
|
+
/** Skips `count` `st_ref_pic_set`s, tracking delta POCs because each may predict the next. */
|
|
426
394
|
function skipShortTermRefPicSets(bits, count) {
|
|
427
395
|
const sets = [];
|
|
428
396
|
for (let index = 0; index < count; index += 1) {
|
|
@@ -487,15 +455,14 @@ function skipShortTermRefPicSets(bits, count) {
|
|
|
487
455
|
}
|
|
488
456
|
}
|
|
489
457
|
function av1Siting(description, firstPacket) {
|
|
490
|
-
// `av1C`
|
|
491
|
-
// header.
|
|
458
|
+
// `av1C` has four bytes of fields, then configuration OBUs that may hold the sequence header.
|
|
492
459
|
const record = bytesOf(description);
|
|
493
460
|
const header = (record !== undefined && record.length > 4 && (record[0] & 0x7f) === 1
|
|
494
461
|
? sequenceHeaderObu(record.subarray(4))
|
|
495
462
|
: undefined) ?? sequenceHeaderObu(bytesOf(firstPacket));
|
|
496
463
|
return header === undefined ? undefined : av1SequenceHeaderSiting(header);
|
|
497
464
|
}
|
|
498
|
-
/**
|
|
465
|
+
/** Payload of the first sequence header OBU in a low-overhead bitstream. */
|
|
499
466
|
function sequenceHeaderObu(data) {
|
|
500
467
|
if (data === undefined)
|
|
501
468
|
return undefined;
|
|
@@ -527,10 +494,10 @@ function sequenceHeaderObu(data) {
|
|
|
527
494
|
return undefined;
|
|
528
495
|
}
|
|
529
496
|
/**
|
|
530
|
-
*
|
|
531
|
-
*
|
|
497
|
+
* Chroma siting from an AV1 sequence header OBU payload, as FFmpeg's AV1 decoders set
|
|
498
|
+
* `avctx->chroma_sample_location`.
|
|
532
499
|
*
|
|
533
|
-
*
|
|
500
|
+
* @throws RangeError When the header ends early.
|
|
534
501
|
*/
|
|
535
502
|
export function av1SequenceHeaderSiting(payload) {
|
|
536
503
|
const bits = new BitReader(payload);
|
|
@@ -630,7 +597,7 @@ export function av1SequenceHeaderSiting(payload) {
|
|
|
630
597
|
return "unspecified";
|
|
631
598
|
}
|
|
632
599
|
}
|
|
633
|
-
/**
|
|
600
|
+
/** Splits a packet into NAL units, Annex B or four-byte length-prefixed. */
|
|
634
601
|
function packetNalUnits(packet) {
|
|
635
602
|
if (packet === undefined || packet.length < 4)
|
|
636
603
|
return [];
|
|
@@ -669,7 +636,7 @@ function packetNalUnits(packet) {
|
|
|
669
636
|
}
|
|
670
637
|
return units;
|
|
671
638
|
}
|
|
672
|
-
/**
|
|
639
|
+
/** Removes emulation prevention bytes from a NAL unit payload. */
|
|
673
640
|
function unescape(payload) {
|
|
674
641
|
const output = new Uint8Array(payload.length);
|
|
675
642
|
let length = 0;
|
package/dist/containers.d.ts
CHANGED
|
@@ -1,49 +1,39 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Export containers
|
|
2
|
+
* Export containers and the codecs each offers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `tests/cases/export-container-corpus.json`. A container offers only the codecs its mainstream
|
|
8
|
-
* players decode in it, which is narrower than what mediabunny writes: QuickTime does not play
|
|
9
|
-
* VP9, AV1 or Opus in a MOV.
|
|
4
|
+
* Mirrors the engine's `alpha2_media::Container` policy so requests can be validated before an
|
|
5
|
+
* encoder or host starts. A container offers only what mainstream players decode in it, which is
|
|
6
|
+
* narrower than what mediabunny can write (QuickTime does not play VP9, AV1 or Opus in MOV).
|
|
10
7
|
*/
|
|
11
8
|
import { type BrowserVideoCodec, type EngineVideoCodec } from "./rate-control.js";
|
|
12
|
-
/** The containers an export can be written in. */
|
|
13
9
|
export type ExportContainer = "mp4" | "mov" | "mkv" | "webm";
|
|
14
|
-
/** The audio codecs an export can carry. */
|
|
15
10
|
export type ExportAudioCodec = "aac" | "opus";
|
|
16
11
|
/** One container's policy. */
|
|
17
12
|
export interface ContainerPolicy {
|
|
18
13
|
readonly id: ExportContainer;
|
|
19
|
-
/** Lowercase
|
|
14
|
+
/** Lowercase extensions without the dot; the first is used for exported files. */
|
|
20
15
|
readonly extensions: readonly string[];
|
|
21
16
|
readonly mimeType: string;
|
|
22
|
-
/**
|
|
17
|
+
/** Video codecs in the engine's spelling, default first. */
|
|
23
18
|
readonly video: readonly EngineVideoCodec[];
|
|
24
|
-
/**
|
|
19
|
+
/** Audio codecs, default first; also the browser's fallback order. */
|
|
25
20
|
readonly audio: readonly ExportAudioCodec[];
|
|
26
21
|
}
|
|
27
|
-
/** Every container's policy, in the engine's order. */
|
|
28
22
|
export declare const EXPORT_CONTAINERS: readonly ContainerPolicy[];
|
|
29
23
|
/** Why an export format request cannot be resolved. */
|
|
30
|
-
export type ExportFormatErrorReason = "unknown" | "unknown-extension" | "extension-mismatch" | "video-codec-not-offered" | "audio-codec-not-offered";
|
|
31
|
-
/**
|
|
24
|
+
export type ExportFormatErrorReason = "unknown" | "unknown-extension" | "extension-mismatch" | "video-codec-not-offered" | "audio-codec-not-offered" | "alpha-unsupported" | "alpha-unsupported-in-container" | "bit-depth-unsupported";
|
|
25
|
+
/** Thrown when a container or codec request is not allowed. */
|
|
32
26
|
export declare class ExportFormatError extends RangeError {
|
|
33
27
|
readonly reason: ExportFormatErrorReason;
|
|
34
28
|
constructor(reason: ExportFormatErrorReason, message: string);
|
|
35
29
|
}
|
|
36
|
-
/**
|
|
37
|
-
* The policy of a container.
|
|
38
|
-
*
|
|
39
|
-
* @throws ExportFormatError When `container` is not one of {@link EXPORT_CONTAINERS}.
|
|
40
|
-
*/
|
|
30
|
+
/** @throws ExportFormatError When `container` is not one of {@link EXPORT_CONTAINERS}. */
|
|
41
31
|
export declare function containerPolicy(container: string): ContainerPolicy;
|
|
42
|
-
/**
|
|
32
|
+
/** Looks up a container by extension (without the dot), case-insensitively. */
|
|
43
33
|
export declare function containerFromExtension(extension: string): ExportContainer | undefined;
|
|
44
|
-
/**
|
|
34
|
+
/** Default browser video codec for `container`. */
|
|
45
35
|
export declare function defaultVideoCodec(container: ExportContainer): BrowserVideoCodec;
|
|
46
|
-
/**
|
|
36
|
+
/** Audio codecs `container` offers, in browser fallback order. */
|
|
47
37
|
export declare function offeredAudioCodecs(container: ExportContainer): readonly ExportAudioCodec[];
|
|
48
38
|
/** A resolved export format, in the engine's codec spelling. */
|
|
49
39
|
export interface EngineExportFormat {
|
|
@@ -52,13 +42,12 @@ export interface EngineExportFormat {
|
|
|
52
42
|
readonly audioCodec: ExportAudioCodec;
|
|
53
43
|
}
|
|
54
44
|
/**
|
|
55
|
-
* Resolves an export's container and codecs
|
|
56
|
-
*
|
|
45
|
+
* Resolves an export's container and codecs in the engine's codec spelling (`h264`), matching the
|
|
46
|
+
* engine's `resolve_export_format`.
|
|
57
47
|
*
|
|
58
|
-
* -
|
|
59
|
-
*
|
|
60
|
-
* - A
|
|
61
|
-
* - An absent codec is the container's default, and a named one must be one it offers.
|
|
48
|
+
* - The container comes from `container`, else from `extension`, else MP4.
|
|
49
|
+
* - A given container and extension must agree.
|
|
50
|
+
* - A missing codec takes the container's default; a given one must be offered.
|
|
62
51
|
*
|
|
63
52
|
* @throws ExportFormatError When the request breaks one of these rules.
|
|
64
53
|
*/
|
|
@@ -76,7 +65,7 @@ export interface ExportFormat {
|
|
|
76
65
|
readonly audioCodec: ExportAudioCodec;
|
|
77
66
|
}
|
|
78
67
|
/**
|
|
79
|
-
* {@link resolveEngineExportFormat} in the browser's codec spelling (`avc`)
|
|
68
|
+
* {@link resolveEngineExportFormat} in the browser's codec spelling (`avc`).
|
|
80
69
|
*
|
|
81
70
|
* @throws ExportFormatError When the request breaks one of its rules.
|
|
82
71
|
*/
|
|
@@ -87,3 +76,25 @@ export declare function resolveExportFormat(request: {
|
|
|
87
76
|
readonly videoCodec?: BrowserVideoCodec;
|
|
88
77
|
readonly audioCodec?: ExportAudioCodec;
|
|
89
78
|
}): ExportFormat;
|
|
79
|
+
/** Output pixel layout, matching the engine's `PixelLayout`. */
|
|
80
|
+
export interface PixelLayout {
|
|
81
|
+
readonly chroma: "420" | "422" | "444";
|
|
82
|
+
readonly bitDepth: 8 | 10;
|
|
83
|
+
readonly alpha: boolean;
|
|
84
|
+
/** `FFmpeg` pixel format name, such as `yuv420p` or `yuva444p10le`. */
|
|
85
|
+
readonly format: string;
|
|
86
|
+
}
|
|
87
|
+
/**
|
|
88
|
+
* Resolves the pixel layout for `codec` in `container`, matching the engine's `resolve_pixels`.
|
|
89
|
+
* `bitDepth` defaults to 10 for ProRes and 8 otherwise.
|
|
90
|
+
*
|
|
91
|
+
* H.264 and MPEG-4 Part 2 write 8-bit 4:2:0. HEVC and AV1 also allow 10-bit. VP9 allows 10-bit, or
|
|
92
|
+
* 8-bit alpha outside MP4. ProRes is 10-bit 4:2:2 (422 HQ), or 4:4:4 with alpha (4444). The
|
|
93
|
+
* container must offer the codec ({@link resolveEngineExportFormat} checks that).
|
|
94
|
+
*
|
|
95
|
+
* @throws ExportFormatError When the codec cannot be written with this depth and alpha.
|
|
96
|
+
*/
|
|
97
|
+
export declare function resolvePixels(codec: EngineVideoCodec, container: ExportContainer, request?: {
|
|
98
|
+
readonly bitDepth?: number;
|
|
99
|
+
readonly alpha?: boolean;
|
|
100
|
+
}): PixelLayout;
|
package/dist/containers.js
CHANGED
|
@@ -1,15 +1,11 @@
|
|
|
1
1
|
/**
|
|
2
|
-
* Export containers
|
|
2
|
+
* Export containers and the codecs each offers.
|
|
3
3
|
*
|
|
4
|
-
*
|
|
5
|
-
*
|
|
6
|
-
*
|
|
7
|
-
* `tests/cases/export-container-corpus.json`. A container offers only the codecs its mainstream
|
|
8
|
-
* players decode in it, which is narrower than what mediabunny writes: QuickTime does not play
|
|
9
|
-
* VP9, AV1 or Opus in a MOV.
|
|
4
|
+
* Mirrors the engine's `alpha2_media::Container` policy so requests can be validated before an
|
|
5
|
+
* encoder or host starts. A container offers only what mainstream players decode in it, which is
|
|
6
|
+
* narrower than what mediabunny can write (QuickTime does not play VP9, AV1 or Opus in MOV).
|
|
10
7
|
*/
|
|
11
8
|
import { engineVideoCodec, } from "./rate-control.js";
|
|
12
|
-
/** Every container's policy, in the engine's order. */
|
|
13
9
|
export const EXPORT_CONTAINERS = [
|
|
14
10
|
{
|
|
15
11
|
id: "mp4",
|
|
@@ -22,7 +18,7 @@ export const EXPORT_CONTAINERS = [
|
|
|
22
18
|
id: "mov",
|
|
23
19
|
extensions: ["mov"],
|
|
24
20
|
mimeType: "video/quicktime",
|
|
25
|
-
video: ["h264", "hevc", "mpeg4-part2"],
|
|
21
|
+
video: ["h264", "hevc", "mpeg4-part2", "prores"],
|
|
26
22
|
audio: ["aac"],
|
|
27
23
|
},
|
|
28
24
|
{
|
|
@@ -40,7 +36,7 @@ export const EXPORT_CONTAINERS = [
|
|
|
40
36
|
audio: ["opus"],
|
|
41
37
|
},
|
|
42
38
|
];
|
|
43
|
-
/**
|
|
39
|
+
/** Thrown when a container or codec request is not allowed. */
|
|
44
40
|
export class ExportFormatError extends RangeError {
|
|
45
41
|
reason;
|
|
46
42
|
constructor(reason, message) {
|
|
@@ -49,39 +45,34 @@ export class ExportFormatError extends RangeError {
|
|
|
49
45
|
this.reason = reason;
|
|
50
46
|
}
|
|
51
47
|
}
|
|
52
|
-
/**
|
|
53
|
-
* The policy of a container.
|
|
54
|
-
*
|
|
55
|
-
* @throws ExportFormatError When `container` is not one of {@link EXPORT_CONTAINERS}.
|
|
56
|
-
*/
|
|
48
|
+
/** @throws ExportFormatError When `container` is not one of {@link EXPORT_CONTAINERS}. */
|
|
57
49
|
export function containerPolicy(container) {
|
|
58
50
|
const policy = EXPORT_CONTAINERS.find((entry) => entry.id === container);
|
|
59
51
|
if (policy === undefined)
|
|
60
52
|
throw new ExportFormatError("unknown", `unknown container "${container}"; expected one of ${EXPORT_CONTAINERS.map((entry) => entry.id).join(", ")}`);
|
|
61
53
|
return policy;
|
|
62
54
|
}
|
|
63
|
-
/**
|
|
55
|
+
/** Looks up a container by extension (without the dot), case-insensitively. */
|
|
64
56
|
export function containerFromExtension(extension) {
|
|
65
57
|
const lower = extension.toLowerCase();
|
|
66
58
|
return EXPORT_CONTAINERS.find((entry) => entry.extensions.includes(lower))
|
|
67
59
|
?.id;
|
|
68
60
|
}
|
|
69
|
-
/**
|
|
61
|
+
/** Default browser video codec for `container`. */
|
|
70
62
|
export function defaultVideoCodec(container) {
|
|
71
63
|
return browserVideoCodec(containerPolicy(container).video[0]);
|
|
72
64
|
}
|
|
73
|
-
/**
|
|
65
|
+
/** Audio codecs `container` offers, in browser fallback order. */
|
|
74
66
|
export function offeredAudioCodecs(container) {
|
|
75
67
|
return containerPolicy(container).audio;
|
|
76
68
|
}
|
|
77
69
|
/**
|
|
78
|
-
* Resolves an export's container and codecs
|
|
79
|
-
*
|
|
70
|
+
* Resolves an export's container and codecs in the engine's codec spelling (`h264`), matching the
|
|
71
|
+
* engine's `resolve_export_format`.
|
|
80
72
|
*
|
|
81
|
-
* -
|
|
82
|
-
*
|
|
83
|
-
* - A
|
|
84
|
-
* - An absent codec is the container's default, and a named one must be one it offers.
|
|
73
|
+
* - The container comes from `container`, else from `extension`, else MP4.
|
|
74
|
+
* - A given container and extension must agree.
|
|
75
|
+
* - A missing codec takes the container's default; a given one must be offered.
|
|
85
76
|
*
|
|
86
77
|
* @throws ExportFormatError When the request breaks one of these rules.
|
|
87
78
|
*/
|
|
@@ -100,7 +91,7 @@ export function resolveEngineExportFormat(request) {
|
|
|
100
91
|
};
|
|
101
92
|
}
|
|
102
93
|
/**
|
|
103
|
-
* {@link resolveEngineExportFormat} in the browser's codec spelling (`avc`)
|
|
94
|
+
* {@link resolveEngineExportFormat} in the browser's codec spelling (`avc`).
|
|
104
95
|
*
|
|
105
96
|
* @throws ExportFormatError When the request breaks one of its rules.
|
|
106
97
|
*/
|
|
@@ -144,7 +135,48 @@ function dotted(extensions) {
|
|
|
144
135
|
function browserVideoCodec(codec) {
|
|
145
136
|
if (codec === "h264")
|
|
146
137
|
return "avc";
|
|
147
|
-
if (codec === "mpeg4-part2")
|
|
148
|
-
throw new ExportFormatError("video-codec-not-offered",
|
|
138
|
+
if (codec === "mpeg4-part2" || codec === "prores")
|
|
139
|
+
throw new ExportFormatError("video-codec-not-offered", `the browser has no ${codec} encoder`);
|
|
149
140
|
return codec;
|
|
150
141
|
}
|
|
142
|
+
/**
|
|
143
|
+
* Resolves the pixel layout for `codec` in `container`, matching the engine's `resolve_pixels`.
|
|
144
|
+
* `bitDepth` defaults to 10 for ProRes and 8 otherwise.
|
|
145
|
+
*
|
|
146
|
+
* H.264 and MPEG-4 Part 2 write 8-bit 4:2:0. HEVC and AV1 also allow 10-bit. VP9 allows 10-bit, or
|
|
147
|
+
* 8-bit alpha outside MP4. ProRes is 10-bit 4:2:2 (422 HQ), or 4:4:4 with alpha (4444). The
|
|
148
|
+
* container must offer the codec ({@link resolveEngineExportFormat} checks that).
|
|
149
|
+
*
|
|
150
|
+
* @throws ExportFormatError When the codec cannot be written with this depth and alpha.
|
|
151
|
+
*/
|
|
152
|
+
export function resolvePixels(codec, container, request = {}) {
|
|
153
|
+
const bitDepth = request.bitDepth ?? (codec === "prores" ? 10 : 8);
|
|
154
|
+
if (bitDepth !== 8 && bitDepth !== 10)
|
|
155
|
+
throw new ExportFormatError("bit-depth-unsupported", `bitDepth: ${bitDepth} is not 8 or 10`);
|
|
156
|
+
const alpha = request.alpha === true;
|
|
157
|
+
const refuseDepth = () => new ExportFormatError("bit-depth-unsupported", `video codec ${codec} cannot be written at ${bitDepth} bits${alpha ? " with alpha" : ""}`);
|
|
158
|
+
let chroma = "420";
|
|
159
|
+
if (codec === "prores") {
|
|
160
|
+
if (bitDepth === 8)
|
|
161
|
+
throw refuseDepth();
|
|
162
|
+
chroma = alpha ? "444" : "422";
|
|
163
|
+
}
|
|
164
|
+
else if (codec === "vp9") {
|
|
165
|
+
if (alpha && container === "mp4")
|
|
166
|
+
throw new ExportFormatError("alpha-unsupported-in-container", `${container} cannot carry vp9 alpha; use webm or mkv`);
|
|
167
|
+
if (alpha && bitDepth === 10)
|
|
168
|
+
throw refuseDepth();
|
|
169
|
+
}
|
|
170
|
+
else {
|
|
171
|
+
if (alpha)
|
|
172
|
+
throw new ExportFormatError("alpha-unsupported", `video codec ${codec} cannot keep alpha; use vp9 (webm, mkv) or prores (mov)`);
|
|
173
|
+
if (bitDepth === 10 && codec !== "hevc" && codec !== "av1")
|
|
174
|
+
throw refuseDepth();
|
|
175
|
+
}
|
|
176
|
+
return {
|
|
177
|
+
chroma,
|
|
178
|
+
bitDepth,
|
|
179
|
+
alpha,
|
|
180
|
+
format: `yuv${alpha ? "a" : ""}${chroma}p${bitDepth === 10 ? "10le" : ""}`,
|
|
181
|
+
};
|
|
182
|
+
}
|