webcodecs-node 0.5.2 → 0.7.1
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 +279 -0
- package/dist/backends/types.d.ts +2 -0
- package/dist/backends/types.d.ts.map +1 -1
- package/dist/backends/types.js.map +1 -1
- package/dist/canvas/canvas-utils.d.ts +115 -0
- package/dist/canvas/canvas-utils.d.ts.map +1 -0
- package/dist/canvas/canvas-utils.js +169 -0
- package/dist/canvas/canvas-utils.js.map +1 -0
- package/dist/canvas/frame-loop.d.ts +113 -0
- package/dist/canvas/frame-loop.d.ts.map +1 -0
- package/dist/canvas/frame-loop.js +291 -0
- package/dist/canvas/frame-loop.js.map +1 -0
- package/dist/canvas/gpu-context.d.ts +61 -0
- package/dist/canvas/gpu-context.d.ts.map +1 -0
- package/dist/canvas/gpu-context.js +134 -0
- package/dist/canvas/gpu-context.js.map +1 -0
- package/dist/canvas/index.d.ts +22 -0
- package/dist/canvas/index.d.ts.map +1 -0
- package/dist/canvas/index.js +25 -0
- package/dist/canvas/index.js.map +1 -0
- package/dist/canvas/types.d.ts +101 -0
- package/dist/canvas/types.d.ts.map +1 -0
- package/dist/canvas/types.js +7 -0
- package/dist/canvas/types.js.map +1 -0
- package/dist/codec-utils/formats.d.ts.map +1 -1
- package/dist/codec-utils/formats.js +31 -0
- package/dist/codec-utils/formats.js.map +1 -1
- package/dist/config/ffmpeg-quality.d.ts +14 -0
- package/dist/config/ffmpeg-quality.d.ts.map +1 -0
- package/dist/config/ffmpeg-quality.js +41 -0
- package/dist/config/ffmpeg-quality.js.map +1 -0
- package/dist/containers/Muxer.d.ts.map +1 -1
- package/dist/containers/Muxer.js +4 -1
- package/dist/containers/Muxer.js.map +1 -1
- package/dist/core/AudioData.d.ts +2 -1
- package/dist/core/AudioData.d.ts.map +1 -1
- package/dist/core/AudioData.js.map +1 -1
- package/dist/core/VideoFrame.d.ts +2 -2
- package/dist/core/VideoFrame.d.ts.map +1 -1
- package/dist/core/VideoFrame.js +58 -48
- package/dist/core/VideoFrame.js.map +1 -1
- package/dist/decoders/AudioDecoder.d.ts +1 -0
- package/dist/decoders/AudioDecoder.d.ts.map +1 -1
- package/dist/decoders/AudioDecoder.js +39 -17
- package/dist/decoders/AudioDecoder.js.map +1 -1
- package/dist/decoders/ImageDecoder.d.ts +1 -0
- package/dist/decoders/ImageDecoder.d.ts.map +1 -1
- package/dist/decoders/ImageDecoder.js +40 -3
- package/dist/decoders/ImageDecoder.js.map +1 -1
- package/dist/decoders/VideoDecoder.d.ts +12 -0
- package/dist/decoders/VideoDecoder.d.ts.map +1 -1
- package/dist/decoders/VideoDecoder.js +56 -13
- package/dist/decoders/VideoDecoder.js.map +1 -1
- package/dist/demos/demo-1080p-transcode.js +8 -2
- package/dist/demos/demo-1080p-transcode.js.map +1 -1
- package/dist/demos/demo-audio-visualizer.d.ts +11 -0
- package/dist/demos/demo-audio-visualizer.d.ts.map +1 -0
- package/dist/demos/demo-audio-visualizer.js +281 -0
- package/dist/demos/demo-audio-visualizer.js.map +1 -0
- package/dist/demos/demo-dvd-logo.d.ts +8 -0
- package/dist/demos/demo-dvd-logo.d.ts.map +1 -0
- package/dist/demos/demo-dvd-logo.js +196 -0
- package/dist/demos/demo-dvd-logo.js.map +1 -0
- package/dist/demos/demo-four-corners.js +9 -0
- package/dist/demos/demo-four-corners.js.map +1 -1
- package/dist/demos/demo-streaming.js +6 -0
- package/dist/demos/demo-streaming.js.map +1 -1
- package/dist/demos/demo-webcodecs.js +1 -0
- package/dist/demos/demo-webcodecs.js.map +1 -1
- package/dist/encoders/AudioEncoder.d.ts +3 -0
- package/dist/encoders/AudioEncoder.d.ts.map +1 -1
- package/dist/encoders/AudioEncoder.js +70 -28
- package/dist/encoders/AudioEncoder.js.map +1 -1
- package/dist/encoders/ImageEncoder.d.ts +80 -0
- package/dist/encoders/ImageEncoder.d.ts.map +1 -0
- package/dist/encoders/ImageEncoder.js +156 -0
- package/dist/encoders/ImageEncoder.js.map +1 -0
- package/dist/encoders/VideoEncoder.d.ts +11 -0
- package/dist/encoders/VideoEncoder.d.ts.map +1 -1
- package/dist/encoders/VideoEncoder.js +58 -7
- package/dist/encoders/VideoEncoder.js.map +1 -1
- package/dist/encoders/index.d.ts +1 -0
- package/dist/encoders/index.d.ts.map +1 -1
- package/dist/encoders/index.js +1 -0
- package/dist/encoders/index.js.map +1 -1
- package/dist/formats/color-space.d.ts +94 -1
- package/dist/formats/color-space.d.ts.map +1 -1
- package/dist/formats/color-space.js +51 -1
- package/dist/formats/color-space.js.map +1 -1
- package/dist/formats/pixel-formats.d.ts +17 -1
- package/dist/formats/pixel-formats.d.ts.map +1 -1
- package/dist/formats/pixel-formats.js +74 -4
- package/dist/formats/pixel-formats.js.map +1 -1
- package/dist/hardware/detection.d.ts.map +1 -1
- package/dist/hardware/detection.js +5 -2
- package/dist/hardware/detection.js.map +1 -1
- package/dist/hardware/encoder-args.d.ts.map +1 -1
- package/dist/hardware/encoder-args.js +6 -6
- package/dist/hardware/encoder-args.js.map +1 -1
- package/dist/index.d.ts +11 -3
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +8 -2
- package/dist/index.js.map +1 -1
- package/dist/node-av/NodeAvAudioDecoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvAudioDecoder.js +3 -0
- package/dist/node-av/NodeAvAudioDecoder.js.map +1 -1
- package/dist/node-av/NodeAvAudioEncoder.d.ts +5 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvAudioEncoder.js +102 -9
- package/dist/node-av/NodeAvAudioEncoder.js.map +1 -1
- package/dist/node-av/NodeAvVideoEncoder.d.ts +2 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts.map +1 -1
- package/dist/node-av/NodeAvVideoEncoder.js +44 -6
- package/dist/node-av/NodeAvVideoEncoder.js.map +1 -1
- package/dist/node-av/WebPImageDecoder.d.ts +54 -0
- package/dist/node-av/WebPImageDecoder.d.ts.map +1 -0
- package/dist/node-av/WebPImageDecoder.js +176 -0
- package/dist/node-av/WebPImageDecoder.js.map +1 -0
- package/dist/polyfills/OffscreenCanvas.d.ts +141 -7
- package/dist/polyfills/OffscreenCanvas.d.ts.map +1 -1
- package/dist/polyfills/OffscreenCanvas.js +217 -17
- package/dist/polyfills/OffscreenCanvas.js.map +1 -1
- package/dist/types/index.d.ts +1 -0
- package/dist/types/index.d.ts.map +1 -1
- package/dist/types/index.js +2 -0
- package/dist/types/index.js.map +1 -1
- package/dist/types/native-frame.d.ts +74 -0
- package/dist/types/native-frame.d.ts.map +1 -0
- package/dist/types/native-frame.js +32 -0
- package/dist/types/native-frame.js.map +1 -0
- package/dist/utils/codec-validation.d.ts +33 -0
- package/dist/utils/codec-validation.d.ts.map +1 -0
- package/dist/utils/codec-validation.js +247 -0
- package/dist/utils/codec-validation.js.map +1 -0
- package/dist/utils/index.d.ts +1 -1
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +1 -1
- package/dist/utils/index.js.map +1 -1
- package/dist/utils/type-guards.d.ts +29 -1
- package/dist/utils/type-guards.d.ts.map +1 -1
- package/dist/utils/type-guards.js +47 -2
- package/dist/utils/type-guards.js.map +1 -1
- package/docs/api.md +155 -0
- package/docs/configuration.md +27 -0
- package/examples/README.md +28 -1
- package/examples/canvas-encoding.ts +222 -0
- package/examples/offscreen-canvas.ts +230 -0
- package/package.json +9 -3
|
@@ -0,0 +1,247 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Codec string validation according to WebCodecs specification
|
|
3
|
+
*
|
|
4
|
+
* The WebCodecs spec requires strict validation of codec strings:
|
|
5
|
+
* - Case-sensitive matching
|
|
6
|
+
* - Fully qualified codec strings (no ambiguous "vp9", must be "vp09.xx.xx.xx")
|
|
7
|
+
* - Valid profile/level parameters
|
|
8
|
+
*
|
|
9
|
+
* @see https://www.w3.org/TR/webcodecs-codec-registry/
|
|
10
|
+
*/
|
|
11
|
+
/**
|
|
12
|
+
* Validate a video codec string according to WebCodecs spec
|
|
13
|
+
*
|
|
14
|
+
* Returns { valid: true, supported: true } for valid, supported codecs
|
|
15
|
+
* Returns { valid: true, supported: false } for valid but unsupported codecs
|
|
16
|
+
* Returns { valid: false, supported: false } for invalid codec strings
|
|
17
|
+
*/
|
|
18
|
+
export function validateVideoCodec(codec) {
|
|
19
|
+
// Check for whitespace (invalid)
|
|
20
|
+
if (codec !== codec.trim()) {
|
|
21
|
+
return { valid: true, supported: false, error: 'Codec string contains whitespace' };
|
|
22
|
+
}
|
|
23
|
+
// Check for MIME type format (invalid for WebCodecs)
|
|
24
|
+
if (codec.includes('/') || codec.includes(';')) {
|
|
25
|
+
return { valid: true, supported: false, error: 'MIME type format not accepted' };
|
|
26
|
+
}
|
|
27
|
+
// AVC/H.264: avc1.PPCCLL or avc3.PPCCLL
|
|
28
|
+
if (codec.startsWith('avc1.') || codec.startsWith('avc3.')) {
|
|
29
|
+
return validateAvcCodec(codec);
|
|
30
|
+
}
|
|
31
|
+
// HEVC/H.265: hvc1.P.T.Lxx or hev1.P.T.Lxx
|
|
32
|
+
if (codec.startsWith('hvc1.') || codec.startsWith('hev1.')) {
|
|
33
|
+
return validateHevcCodec(codec);
|
|
34
|
+
}
|
|
35
|
+
// VP8: exactly "vp8"
|
|
36
|
+
if (codec === 'vp8') {
|
|
37
|
+
return { valid: true, supported: true };
|
|
38
|
+
}
|
|
39
|
+
// VP8 with wrong casing
|
|
40
|
+
if (codec.toLowerCase() === 'vp8' && codec !== 'vp8') {
|
|
41
|
+
return { valid: true, supported: false, error: 'VP8 codec must be lowercase "vp8"' };
|
|
42
|
+
}
|
|
43
|
+
// VP9: fully qualified vp09.PP.LL.DD or simple "vp9"
|
|
44
|
+
if (codec.startsWith('vp09.')) {
|
|
45
|
+
return validateVp9Codec(codec);
|
|
46
|
+
}
|
|
47
|
+
// Simple "vp9" - accepted for FFmpeg compatibility (though spec prefers vp09.xx.xx.xx)
|
|
48
|
+
if (codec === 'vp9') {
|
|
49
|
+
return { valid: true, supported: true };
|
|
50
|
+
}
|
|
51
|
+
// VP9 with wrong casing
|
|
52
|
+
if (codec.toLowerCase() === 'vp9' && codec !== 'vp9') {
|
|
53
|
+
return { valid: true, supported: false, error: 'VP9 codec must be lowercase "vp9"' };
|
|
54
|
+
}
|
|
55
|
+
// AV1: av01.P.LLT.DD
|
|
56
|
+
if (codec.startsWith('av01.')) {
|
|
57
|
+
return validateAv1Codec(codec);
|
|
58
|
+
}
|
|
59
|
+
// Ambiguous "av1" without profile is not accepted
|
|
60
|
+
if (codec === 'av1' || codec.toLowerCase() === 'av1') {
|
|
61
|
+
return { valid: true, supported: false, error: 'Ambiguous AV1 codec, use av01.P.LLT.DD format' };
|
|
62
|
+
}
|
|
63
|
+
// Unknown codec
|
|
64
|
+
return { valid: true, supported: false, error: `Unrecognized codec: ${codec}` };
|
|
65
|
+
}
|
|
66
|
+
/**
|
|
67
|
+
* Validate AVC/H.264 codec string
|
|
68
|
+
* Format: avc1.PPCCLL or avc3.PPCCLL
|
|
69
|
+
* PP = Profile (hex), CC = Constraints (hex), LL = Level (hex)
|
|
70
|
+
*/
|
|
71
|
+
function validateAvcCodec(codec) {
|
|
72
|
+
// avc1.XXXXXX or avc3.XXXXXX (6 hex digits)
|
|
73
|
+
const match = codec.match(/^(avc[13])\.([0-9A-Fa-f]{6})$/);
|
|
74
|
+
if (!match) {
|
|
75
|
+
return { valid: true, supported: false, error: 'Invalid AVC codec format' };
|
|
76
|
+
}
|
|
77
|
+
const [, prefix, params] = match;
|
|
78
|
+
// Check case sensitivity of prefix
|
|
79
|
+
if (prefix !== prefix.toLowerCase()) {
|
|
80
|
+
return { valid: true, supported: false, error: 'AVC codec prefix must be lowercase' };
|
|
81
|
+
}
|
|
82
|
+
// Parse profile, constraints, level
|
|
83
|
+
const profile = parseInt(params.substring(0, 2), 16);
|
|
84
|
+
const constraints = parseInt(params.substring(2, 4), 16);
|
|
85
|
+
const level = parseInt(params.substring(4, 6), 16);
|
|
86
|
+
// Valid profiles: 66 (Baseline), 77 (Main), 88 (Extended), 100 (High), etc.
|
|
87
|
+
const validProfiles = [66, 77, 88, 100, 110, 122, 244, 44, 83, 86, 118, 128, 138, 139, 134];
|
|
88
|
+
if (!validProfiles.includes(profile)) {
|
|
89
|
+
// Future/unknown profile - mark as unsupported
|
|
90
|
+
return { valid: true, supported: false, error: `Unknown AVC profile: ${profile}` };
|
|
91
|
+
}
|
|
92
|
+
// Valid levels: 10, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52, 60, 61, 62
|
|
93
|
+
const validLevels = [10, 11, 12, 13, 20, 21, 22, 30, 31, 32, 40, 41, 42, 50, 51, 52, 60, 61, 62];
|
|
94
|
+
if (!validLevels.includes(level)) {
|
|
95
|
+
// Note: level 29 (0x1D) is not a valid H.264 level
|
|
96
|
+
return { valid: true, supported: false, error: `Unknown AVC level: ${level}` };
|
|
97
|
+
}
|
|
98
|
+
return { valid: true, supported: true };
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Validate HEVC/H.265 codec string
|
|
102
|
+
* Format: hvc1.P.C.Lxx[.XX] or hev1.P.C.Lxx[.XX]
|
|
103
|
+
* Where P = profile, C = compatibility, Lxx = level, XX = optional constraints
|
|
104
|
+
* Example: hev1.1.6.L93.B0
|
|
105
|
+
*/
|
|
106
|
+
function validateHevcCodec(codec) {
|
|
107
|
+
// HEVC codec format: prefix.profile.compatibility.level[.constraints]
|
|
108
|
+
// Examples: hev1.1.6.L93.B0, hvc1.1.6.L120, hev1.2.4.L153.90
|
|
109
|
+
const match = codec.match(/^(hvc1|hev1)\.(\d+)\.([0-9A-Fa-f]+)\.L(\d+)(?:\.([A-Za-z0-9]+))?$/);
|
|
110
|
+
if (!match) {
|
|
111
|
+
return { valid: true, supported: false, error: 'Invalid HEVC codec format' };
|
|
112
|
+
}
|
|
113
|
+
const [, prefix, profileStr, , levelStr] = match;
|
|
114
|
+
// Check case sensitivity of prefix
|
|
115
|
+
if (prefix !== prefix.toLowerCase()) {
|
|
116
|
+
return { valid: true, supported: false, error: 'HEVC codec prefix must be lowercase' };
|
|
117
|
+
}
|
|
118
|
+
const profile = parseInt(profileStr, 10);
|
|
119
|
+
const level = parseInt(levelStr, 10);
|
|
120
|
+
// Valid HEVC profiles: 1 (Main), 2 (Main 10), 3 (Main Still Picture), etc.
|
|
121
|
+
if (profile < 1 || profile > 11) {
|
|
122
|
+
return { valid: true, supported: false, error: `Unknown HEVC profile: ${profile}` };
|
|
123
|
+
}
|
|
124
|
+
// Valid HEVC levels (level * 30): 30, 60, 63, 90, 93, 120, 123, 150, 153, 156, 180, 183, 186
|
|
125
|
+
const validLevels = [30, 60, 63, 90, 93, 120, 123, 150, 153, 156, 180, 183, 186];
|
|
126
|
+
if (!validLevels.includes(level)) {
|
|
127
|
+
return { valid: true, supported: false, error: `Unknown HEVC level: ${level}` };
|
|
128
|
+
}
|
|
129
|
+
return { valid: true, supported: true };
|
|
130
|
+
}
|
|
131
|
+
/**
|
|
132
|
+
* Validate VP9 codec string
|
|
133
|
+
* Format: vp09.PP.LL.DD
|
|
134
|
+
* PP = Profile (00-03), LL = Level (10-62), DD = Bit depth (08, 10, 12)
|
|
135
|
+
*/
|
|
136
|
+
function validateVp9Codec(codec) {
|
|
137
|
+
const match = codec.match(/^vp09\.(\d{2})\.(\d{2})\.(\d{2})$/);
|
|
138
|
+
if (!match) {
|
|
139
|
+
return { valid: true, supported: false, error: 'Invalid VP9 codec format, expected vp09.PP.LL.DD' };
|
|
140
|
+
}
|
|
141
|
+
const [, profileStr, levelStr, bitDepthStr] = match;
|
|
142
|
+
const profile = parseInt(profileStr, 10);
|
|
143
|
+
const level = parseInt(levelStr, 10);
|
|
144
|
+
const bitDepth = parseInt(bitDepthStr, 10);
|
|
145
|
+
// Valid profiles: 0, 1, 2, 3
|
|
146
|
+
if (profile < 0 || profile > 3) {
|
|
147
|
+
return { valid: true, supported: false, error: `Unknown VP9 profile: ${profile}` };
|
|
148
|
+
}
|
|
149
|
+
// Valid levels: 10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 52, 60, 61, 62
|
|
150
|
+
const validLevels = [10, 11, 20, 21, 30, 31, 40, 41, 50, 51, 52, 60, 61, 62];
|
|
151
|
+
if (!validLevels.includes(level)) {
|
|
152
|
+
return { valid: true, supported: false, error: `Unknown VP9 level: ${level}` };
|
|
153
|
+
}
|
|
154
|
+
// Valid bit depths: 8, 10, 12
|
|
155
|
+
if (bitDepth !== 8 && bitDepth !== 10 && bitDepth !== 12) {
|
|
156
|
+
return { valid: true, supported: false, error: `Unknown VP9 bit depth: ${bitDepth}` };
|
|
157
|
+
}
|
|
158
|
+
return { valid: true, supported: true };
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Validate AV1 codec string
|
|
162
|
+
* Format: av01.P.LLT.DD
|
|
163
|
+
* P = Profile (0=Main, 1=High, 2=Professional)
|
|
164
|
+
* LL = Level (00-23)
|
|
165
|
+
* T = Tier (M=Main, H=High)
|
|
166
|
+
* DD = Bit depth (08, 10, 12)
|
|
167
|
+
*/
|
|
168
|
+
function validateAv1Codec(codec) {
|
|
169
|
+
const match = codec.match(/^av01\.(\d)\.(\d{2})([MH])\.(\d{2})$/);
|
|
170
|
+
if (!match) {
|
|
171
|
+
return { valid: true, supported: false, error: 'Invalid AV1 codec format, expected av01.P.LLT.DD' };
|
|
172
|
+
}
|
|
173
|
+
const [, profileStr, levelStr, tier, bitDepthStr] = match;
|
|
174
|
+
const profile = parseInt(profileStr, 10);
|
|
175
|
+
const level = parseInt(levelStr, 10);
|
|
176
|
+
const bitDepth = parseInt(bitDepthStr, 10);
|
|
177
|
+
// Valid profiles: 0 (Main), 1 (High), 2 (Professional)
|
|
178
|
+
if (profile < 0 || profile > 2) {
|
|
179
|
+
return { valid: true, supported: false, error: `Unknown AV1 profile: ${profile}` };
|
|
180
|
+
}
|
|
181
|
+
// Valid levels: 0-23 (0=2.0, 1=2.1, ..., 23=7.3)
|
|
182
|
+
if (level < 0 || level > 23) {
|
|
183
|
+
return { valid: true, supported: false, error: `Unknown AV1 level: ${level}` };
|
|
184
|
+
}
|
|
185
|
+
// Valid bit depths: 8, 10, 12
|
|
186
|
+
if (bitDepth !== 8 && bitDepth !== 10 && bitDepth !== 12) {
|
|
187
|
+
return { valid: true, supported: false, error: `Unknown AV1 bit depth: ${bitDepth}` };
|
|
188
|
+
}
|
|
189
|
+
return { valid: true, supported: true };
|
|
190
|
+
}
|
|
191
|
+
/**
|
|
192
|
+
* Check if a codec config is valid (should throw TypeError if invalid)
|
|
193
|
+
* This checks for missing/empty required fields
|
|
194
|
+
*/
|
|
195
|
+
export function validateVideoDecoderConfig(config) {
|
|
196
|
+
if (!config || typeof config !== 'object') {
|
|
197
|
+
throw new TypeError('config must be an object');
|
|
198
|
+
}
|
|
199
|
+
const cfg = config;
|
|
200
|
+
if (cfg.codec === undefined || cfg.codec === null) {
|
|
201
|
+
throw new TypeError('codec is required');
|
|
202
|
+
}
|
|
203
|
+
if (typeof cfg.codec !== 'string' || cfg.codec === '') {
|
|
204
|
+
throw new TypeError('codec must be a non-empty string');
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
/**
|
|
208
|
+
* Check if an encoder config is valid (should throw TypeError if invalid)
|
|
209
|
+
*/
|
|
210
|
+
export function validateVideoEncoderConfig(config) {
|
|
211
|
+
if (!config || typeof config !== 'object') {
|
|
212
|
+
throw new TypeError('config must be an object');
|
|
213
|
+
}
|
|
214
|
+
const cfg = config;
|
|
215
|
+
if (cfg.codec === undefined || cfg.codec === null) {
|
|
216
|
+
throw new TypeError('codec is required');
|
|
217
|
+
}
|
|
218
|
+
if (typeof cfg.codec !== 'string' || cfg.codec === '') {
|
|
219
|
+
throw new TypeError('codec must be a non-empty string');
|
|
220
|
+
}
|
|
221
|
+
if (cfg.width === undefined || cfg.width === null) {
|
|
222
|
+
throw new TypeError('width is required');
|
|
223
|
+
}
|
|
224
|
+
if (typeof cfg.width !== 'number' || cfg.width <= 0 || !Number.isFinite(cfg.width)) {
|
|
225
|
+
throw new TypeError('width must be a positive number');
|
|
226
|
+
}
|
|
227
|
+
if (cfg.height === undefined || cfg.height === null) {
|
|
228
|
+
throw new TypeError('height is required');
|
|
229
|
+
}
|
|
230
|
+
if (typeof cfg.height !== 'number' || cfg.height <= 0 || !Number.isFinite(cfg.height)) {
|
|
231
|
+
throw new TypeError('height must be a positive number');
|
|
232
|
+
}
|
|
233
|
+
// Optional field validations
|
|
234
|
+
if (cfg.displayWidth !== undefined && (typeof cfg.displayWidth !== 'number' || cfg.displayWidth <= 0)) {
|
|
235
|
+
throw new TypeError('displayWidth must be a positive number');
|
|
236
|
+
}
|
|
237
|
+
if (cfg.displayHeight !== undefined && (typeof cfg.displayHeight !== 'number' || cfg.displayHeight <= 0)) {
|
|
238
|
+
throw new TypeError('displayHeight must be a positive number');
|
|
239
|
+
}
|
|
240
|
+
if (cfg.bitrate !== undefined && (typeof cfg.bitrate !== 'number' || cfg.bitrate <= 0)) {
|
|
241
|
+
throw new TypeError('bitrate must be a positive number');
|
|
242
|
+
}
|
|
243
|
+
if (cfg.framerate !== undefined && (typeof cfg.framerate !== 'number' || cfg.framerate <= 0)) {
|
|
244
|
+
throw new TypeError('framerate must be a positive number');
|
|
245
|
+
}
|
|
246
|
+
}
|
|
247
|
+
//# sourceMappingURL=codec-validation.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-validation.js","sourceRoot":"","sources":["../../src/utils/codec-validation.ts"],"names":[],"mappings":"AAAA;;;;;;;;;GASG;AAQH;;;;;;GAMG;AACH,MAAM,UAAU,kBAAkB,CAAC,KAAa;IAC9C,iCAAiC;IACjC,IAAI,KAAK,KAAK,KAAK,CAAC,IAAI,EAAE,EAAE,CAAC;QAC3B,OAAO,EAAE,KAAK,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,EAAE,KAAK,EAAE,kCAAkC,EAAE,CAAC;IACtF,CAAC;IAED,qDAAqD;IACrD,I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,CAAC,EAAE,CAAC;QACtG,MAAM,IAAI,SAAS,CAAC,wCAAwC,CAAC,CAAC;IAChE,CAAC;IAED,IAAI,GAAG,CAAC,aAAa,KAAK,SAAS,IAAI,CAAC,OAAO,GAAG,CAAC,aAAa,KAAK,QAAQ,IAAI,GAAG,CAAC,aAAa,IAAI,CAAC,CAAC,EAAE,CAAC;QACzG,MAAM,IAAI,SAAS,CAAC,yCAAyC,CAAC,CAAC;IACjE,CAAC;IAED,IAAI,GAAG,CAAC,OAAO,KAAK,SAAS,IAAI,CAAC,OAAO,GAAG,CAAC,OAAO,KAAK,QAAQ,IAAI,GAAG,CAAC,OAAO,IAAI,CAAC,CAAC,EAAE,CAAC;QACvF,MAAM,IAAI,SAAS,CAAC,mCAAmC,CAAC,CAAC;IAC3D,CAAC;IAED,IAAI,GAAG,CAAC,SAAS,KAAK,SAAS,IAAI,CAAC,OAAO,GAAG,CAAC,SAAS,KAAK,QAAQ,IAAI,GAAG,CAAC,SAAS,IAAI,CAAC,CAAC,EAAE,CAAC;QAC7F,MAAM,IAAI,SAAS,CAAC,qCAAqC,CAAC,CAAC;IAC7D,CAAC;AACH,CAAC"}
|
package/dist/utils/index.d.ts
CHANGED
|
@@ -4,7 +4,7 @@
|
|
|
4
4
|
export { toUint8Array, copyToUint8Array, concatUint8Arrays, isReadableStream, readStreamToUint8Array, } from './buffer.js';
|
|
5
5
|
export { validatePositiveInteger, validateNonNegativeInteger, validateFiniteNumber, validateRequired, validateNonEmptyString, validateConfigured, validateNotClosed, } from './validation.js';
|
|
6
6
|
export { Logger, createLogger, setDebugMode, isDebugMode, type LogLevel, type LogEntry, } from './logger.js';
|
|
7
|
-
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, type ImageDataLike, type CanvasLike, type VideoFrameLike, } from './type-guards.js';
|
|
7
|
+
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, isSkiaCanvas, extractCanvasPixels, type ImageDataLike, type CanvasLike, type VideoFrameLike, type SkiaCanvasLike, } from './type-guards.js';
|
|
8
8
|
export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvcParameterSetsFromAnnexB, buildAvcDecoderConfig, convertAnnexBToAvcc, type AvcConfig, } from './avc.js';
|
|
9
9
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, type HvccConfig, } from './hevc.js';
|
|
10
10
|
export { parseAudioSpecificConfig, wrapAacFrameWithAdts, buildAudioSpecificConfig, stripAdtsHeader, type AacConfig, } from './aac.js';
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAGzB,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,EACX,KAAK,QAAQ,EACb,KAAK,QAAQ,GACd,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,KAAK,aAAa,EAClB,KAAK,UAAU,EACf,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,EACnB,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,EACnB,KAAK,UAAU,GAChB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,EACf,KAAK,SAAS,GACf,MAAM,UAAU,CAAC;AAGlB,OAAO,EACL,oBAAoB,EACpB,KAAK,aAAa,EAClB,KAAK,oBAAoB,GAC1B,MAAM,mBAAmB,CAAC;AAG3B,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,EACf,KAAK,WAAW,EAChB,KAAK,cAAc,EACnB,KAAK,cAAc,GACpB,MAAM,kBAAkB,CAAC;AAG1B,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAGtB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAGH,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,uBAAuB,EACvB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,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,EAChB,KAAK,kBAAkB,GACxB,MAAM,aAAa,CAAC;AAGrB,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,EACtB,KAAK,kBAAkB,GACxB,MAAM,oBAAoB,CAAC;AAG5B,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,EACb,KAAK,gBAAgB,EACrB,KAAK,eAAe,GACrB,MAAM,kBAAkB,CAAC"}
|
package/dist/utils/index.js
CHANGED
|
@@ -8,7 +8,7 @@ export { validatePositiveInteger, validateNonNegativeInteger, validateFiniteNumb
|
|
|
8
8
|
// Logger
|
|
9
9
|
export { Logger, createLogger, setDebugMode, isDebugMode, } from './logger.js';
|
|
10
10
|
// Type guards
|
|
11
|
-
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, } from './type-guards.js';
|
|
11
|
+
export { isImageDataLike, isCanvasLike, isVideoFrameLike, isCanvasImageSource, isSkiaCanvas, extractCanvasPixels, } from './type-guards.js';
|
|
12
12
|
// Codec helpers
|
|
13
13
|
export { parseAvcDecoderConfig, convertAvccToAnnexB, splitAnnexBNals, extractAvcParameterSetsFromAnnexB, buildAvcDecoderConfig, convertAnnexBToAvcc, } from './avc.js';
|
|
14
14
|
export { parseHvccDecoderConfig, convertHvccToAnnexB, splitHevcAnnexBNals, extractHevcParameterSetsFromAnnexB, buildHvccDecoderConfig, convertAnnexBToHvcc, } from './hevc.js';
|
package/dist/utils/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,
|
|
1
|
+
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/utils/index.ts"],"names":[],"mappings":"AAAA;;GAEG;AAEH,mBAAmB;AACnB,OAAO,EACL,YAAY,EACZ,gBAAgB,EAChB,iBAAiB,EACjB,gBAAgB,EAChB,sBAAsB,GACvB,MAAM,aAAa,CAAC;AAErB,uBAAuB;AACvB,OAAO,EACL,uBAAuB,EACvB,0BAA0B,EAC1B,oBAAoB,EACpB,gBAAgB,EAChB,sBAAsB,EACtB,kBAAkB,EAClB,iBAAiB,GAClB,MAAM,iBAAiB,CAAC;AAEzB,SAAS;AACT,OAAO,EACL,MAAM,EACN,YAAY,EACZ,YAAY,EACZ,WAAW,GAGZ,MAAM,aAAa,CAAC;AAErB,cAAc;AACd,OAAO,EACL,eAAe,EACf,YAAY,EACZ,gBAAgB,EAChB,mBAAmB,EACnB,YAAY,EACZ,mBAAmB,GAKpB,MAAM,kBAAkB,CAAC;AAE1B,gBAAgB;AAChB,OAAO,EACL,qBAAqB,EACrB,mBAAmB,EACnB,eAAe,EACf,iCAAiC,EACjC,qBAAqB,EACrB,mBAAmB,GAEpB,MAAM,UAAU,CAAC;AAElB,OAAO,EACL,sBAAsB,EACtB,mBAAmB,EACnB,mBAAmB,EACnB,kCAAkC,EAClC,sBAAsB,EACtB,mBAAmB,GAEpB,MAAM,WAAW,CAAC;AAEnB,OAAO,EACL,wBAAwB,EACxB,oBAAoB,EACpB,wBAAwB,EACxB,eAAe,GAEhB,MAAM,UAAU,CAAC;AAElB,sBAAsB;AACtB,OAAO,EACL,oBAAoB,GAGrB,MAAM,mBAAmB,CAAC;AAE3B,0BAA0B;AAC1B,OAAO,EACL,YAAY,EACZ,UAAU,EACV,iBAAiB,EACjB,iBAAiB,EACjB,YAAY,EACZ,YAAY,EACZ,eAAe,GAIhB,MAAM,kBAAkB,CAAC;AAE1B,oBAAoB;AACpB,OAAO,EACL,WAAW,EACX,oBAAoB,EACpB,4BAA4B,EAC5B,gBAAgB,GACjB,MAAM,cAAc,CAAC;AAEtB,kBAAkB;AAClB,OAAO,EACL,oBAAoB,EACpB,iBAAiB,EACjB,iBAAiB,EACjB,SAAS,EACT,aAAa,EACb,UAAU,EACV,kBAAkB,EAClB,YAAY,EACZ,oBAAoB,EACpB,gBAAgB,GAEjB,MAAM,aAAa,CAAC;AAErB,2BAA2B;AAC3B,OAAO,EACL,mBAAmB,EACnB,eAAe,EACf,gBAAgB,EAChB,mBAAmB,EACnB,sBAAsB,EACtB,sBAAsB,GAEvB,MAAM,oBAAoB,CAAC;AAE5B,4CAA4C;AAC5C,OAAO,EACL,UAAU,EACV,aAAa,EACb,cAAc,EACd,iBAAiB,EACjB,aAAa,EACb,aAAa,GAGd,MAAM,kBAAkB,CAAC"}
|
|
@@ -18,6 +18,21 @@ export interface CanvasLike {
|
|
|
18
18
|
getContext: (type: string, options?: unknown) => unknown;
|
|
19
19
|
_getImageData?: () => Uint8ClampedArray;
|
|
20
20
|
}
|
|
21
|
+
/**
|
|
22
|
+
* Interface for skia-canvas Canvas objects
|
|
23
|
+
*/
|
|
24
|
+
export interface SkiaCanvasLike {
|
|
25
|
+
width: number;
|
|
26
|
+
height: number;
|
|
27
|
+
gpu: boolean;
|
|
28
|
+
engine: {
|
|
29
|
+
renderer: string;
|
|
30
|
+
api?: string;
|
|
31
|
+
};
|
|
32
|
+
getContext: (type: '2d') => any;
|
|
33
|
+
toBuffer: (format: string, options?: unknown) => Promise<Buffer>;
|
|
34
|
+
toBufferSync: (format: string, options?: unknown) => Buffer;
|
|
35
|
+
}
|
|
21
36
|
/**
|
|
22
37
|
* Interface for VideoFrame-like objects (including our polyfill)
|
|
23
38
|
*/
|
|
@@ -45,10 +60,15 @@ export interface VideoFrameLike {
|
|
|
45
60
|
* Check if object is ImageData-like (has data, width, height)
|
|
46
61
|
*/
|
|
47
62
|
export declare function isImageDataLike(obj: unknown): obj is ImageDataLike;
|
|
63
|
+
/**
|
|
64
|
+
* Check if object is a skia-canvas Canvas
|
|
65
|
+
*/
|
|
66
|
+
export declare function isSkiaCanvas(obj: unknown): obj is SkiaCanvasLike;
|
|
48
67
|
/**
|
|
49
68
|
* Check if object is a canvas-like object with getContext
|
|
69
|
+
* Includes both standard canvas and skia-canvas
|
|
50
70
|
*/
|
|
51
|
-
export declare function isCanvasLike(obj: unknown): obj is CanvasLike;
|
|
71
|
+
export declare function isCanvasLike(obj: unknown): obj is CanvasLike | SkiaCanvasLike;
|
|
52
72
|
/**
|
|
53
73
|
* Check if object is a VideoFrame-like object
|
|
54
74
|
*/
|
|
@@ -57,4 +77,12 @@ export declare function isVideoFrameLike(obj: unknown): obj is VideoFrameLike;
|
|
|
57
77
|
* Check if an object is a CanvasImageSource-like object
|
|
58
78
|
*/
|
|
59
79
|
export declare function isCanvasImageSource(obj: unknown): boolean;
|
|
80
|
+
/**
|
|
81
|
+
* Extract raw pixel data from any canvas-like object
|
|
82
|
+
* Returns RGBA Uint8Array
|
|
83
|
+
*
|
|
84
|
+
* @param canvas - Any canvas-like object (skia-canvas, polyfill, or standard)
|
|
85
|
+
* @returns Raw RGBA pixel data as Uint8Array
|
|
86
|
+
*/
|
|
87
|
+
export declare function extractCanvasPixels(canvas: CanvasLike | SkiaCanvasLike): Uint8Array;
|
|
60
88
|
//# sourceMappingURL=type-guards.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guards.d.ts","sourceRoot":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|
16
|
+
* Check if object is a skia-canvas Canvas
|
|
17
|
+
*/
|
|
18
|
+
export function isSkiaCanvas(obj) {
|
|
19
|
+
if (!obj || typeof obj !== 'object')
|
|
20
|
+
return false;
|
|
21
|
+
const o = obj;
|
|
22
|
+
return (typeof o.width === 'number' &&
|
|
23
|
+
typeof o.height === 'number' &&
|
|
24
|
+
typeof o.gpu === 'boolean' &&
|
|
25
|
+
typeof o.getContext === 'function' &&
|
|
26
|
+
typeof o.toBuffer === 'function' &&
|
|
27
|
+
typeof o.toBufferSync === 'function' &&
|
|
28
|
+
typeof o.engine === 'object');
|
|
29
|
+
}
|
|
15
30
|
/**
|
|
16
31
|
* Check if object is a canvas-like object with getContext
|
|
32
|
+
* Includes both standard canvas and skia-canvas
|
|
17
33
|
*/
|
|
18
34
|
export function isCanvasLike(obj) {
|
|
19
35
|
if (!obj || typeof obj !== 'object')
|
|
20
36
|
return false;
|
|
21
37
|
const o = obj;
|
|
22
|
-
|
|
38
|
+
// Standard canvas check
|
|
39
|
+
const isStandardCanvas = typeof o.width === 'number' &&
|
|
23
40
|
typeof o.height === 'number' &&
|
|
24
|
-
typeof o.getContext === 'function'
|
|
41
|
+
typeof o.getContext === 'function';
|
|
42
|
+
return isStandardCanvas;
|
|
25
43
|
}
|
|
26
44
|
/**
|
|
27
45
|
* Check if object is a VideoFrame-like object
|
|
@@ -46,4 +64,31 @@ export function isCanvasImageSource(obj) {
|
|
|
46
64
|
(typeof o.codedWidth === 'number' && typeof o.codedHeight === 'number') ||
|
|
47
65
|
isImageDataLike(obj));
|
|
48
66
|
}
|
|
67
|
+
/**
|
|
68
|
+
* Extract raw pixel data from any canvas-like object
|
|
69
|
+
* Returns RGBA Uint8Array
|
|
70
|
+
*
|
|
71
|
+
* @param canvas - Any canvas-like object (skia-canvas, polyfill, or standard)
|
|
72
|
+
* @returns Raw RGBA pixel data as Uint8Array
|
|
73
|
+
*/
|
|
74
|
+
export function extractCanvasPixels(canvas) {
|
|
75
|
+
// Try skia-canvas method first (most efficient)
|
|
76
|
+
if ('toBufferSync' in canvas && typeof canvas.toBufferSync === 'function') {
|
|
77
|
+
const buffer = canvas.toBufferSync('raw', { colorType: 'rgba' });
|
|
78
|
+
return new Uint8Array(buffer.buffer, buffer.byteOffset, buffer.byteLength);
|
|
79
|
+
}
|
|
80
|
+
// Try polyfill method
|
|
81
|
+
if ('_getImageData' in canvas && typeof canvas._getImageData === 'function') {
|
|
82
|
+
const data = canvas._getImageData();
|
|
83
|
+
return new Uint8Array(data.buffer, data.byteOffset, data.byteLength);
|
|
84
|
+
}
|
|
85
|
+
// Standard canvas 2D context
|
|
86
|
+
const ctx = canvas.getContext('2d');
|
|
87
|
+
if (ctx && typeof ctx.getImageData === 'function') {
|
|
88
|
+
const imageData = ctx.getImageData(0, 0, canvas.width, canvas.height);
|
|
89
|
+
return new Uint8Array(imageData.data.buffer, imageData.data.byteOffset, imageData.data.byteLength);
|
|
90
|
+
}
|
|
91
|
+
// Fallback: empty buffer
|
|
92
|
+
return new Uint8Array(canvas.width * canvas.height * 4);
|
|
93
|
+
}
|
|
49
94
|
//# sourceMappingURL=type-guards.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;
|
|
1
|
+
{"version":3,"file":"type-guards.js","sourceRoot":"","sources":["../../src/utils/type-guards.ts"],"names":[],"mappings":"AAAA;;GAEG;AAyDH;;GAEG;AACH,MAAM,UAAU,eAAe,CAAC,GAAY;IAC1C,IAAI,CAAC,GAAG,IAAI,OAAO,GAAG,KAAK,QAAQ;QAAE,OAAO,KAAK,CAAC;IAClD,MAAM,CAAC,GAAG,GAA8B,CAAC;IACzC,OAAO,CACL,CAAC,CAAC,CAAC,IAAI,YAAY,iBAAiB,IAAI,CAAC,CAAC,IAAI,YAAY,UAAU,CAAC;QACrE,OAAO,CAAC,CAAC,KAAK,KAAK,QAAQ;QAC3B,OA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,IAAI,CAAQ,CAAC;IAC3C,IAAI,GAAG,IAAI,OAAO,GAAG,CAAC,YAAY,KAAK,UAAU,EAAE,CAAC;QAClD,MAAM,SAAS,GAAG,GAAG,CAAC,YAAY,CAAC,CAAC,EAAE,CAAC,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAAC,MAAM,CAAC,CAAC;QACtE,OAAO,IAAI,UAAU,CACnB,SAAS,CAAC,IAAI,CAAC,MAAM,EACrB,SAAS,CAAC,IAAI,CAAC,UAAU,EACzB,SAAS,CAAC,IAAI,CAAC,UAAU,CAC1B,CAAC;IACJ,CAAC;IAED,yBAAyB;IACzB,OAAO,IAAI,UAAU,CAAC,MAAM,CAAC,KAAK,GAAG,MAAM,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC;AAC1D,CAAC"}
|
package/docs/api.md
CHANGED
|
@@ -9,7 +9,9 @@ This document provides detailed API documentation for webcodecs-node.
|
|
|
9
9
|
- [AudioEncoder](#audioencoder)
|
|
10
10
|
- [AudioDecoder](#audiodecoder)
|
|
11
11
|
- [ImageDecoder](#imagedecoder)
|
|
12
|
+
- [ImageEncoder](#imageencoder)
|
|
12
13
|
- [VideoFrame](#videoframe)
|
|
14
|
+
- [VideoColorSpace](#videocolorspace)
|
|
13
15
|
- [AudioData](#audiodata)
|
|
14
16
|
- [EncodedVideoChunk](#encodedvideochunk)
|
|
15
17
|
- [EncodedAudioChunk](#encodedaudiochunk)
|
|
@@ -64,6 +66,7 @@ Configure the encoder. Must be called before encoding.
|
|
|
64
66
|
| `alpha` | 'discard' \| 'keep' | No | Alpha channel handling |
|
|
65
67
|
| `latencyMode` | 'quality' \| 'realtime' | No | Latency vs quality tradeoff |
|
|
66
68
|
| `hardwareAcceleration` | 'no-preference' \| 'prefer-hardware' \| 'prefer-software' | No | Hardware acceleration preference |
|
|
69
|
+
| `maxQueueSize` | number | No | Max pending frames before QuotaExceededError. Auto-calculated from resolution if not set (~300MB target memory). |
|
|
67
70
|
|
|
68
71
|
#### `encode(frame: VideoFrame, options?: VideoEncoderEncodeOptions): void`
|
|
69
72
|
|
|
@@ -122,6 +125,7 @@ Check if a configuration is supported.
|
|
|
122
125
|
| `codedWidth` | number | No | Coded frame width |
|
|
123
126
|
| `codedHeight` | number | No | Coded frame height |
|
|
124
127
|
| `description` | BufferSource | No | Codec-specific data (e.g., SPS/PPS for H.264) |
|
|
128
|
+
| `maxQueueSize` | number | No | Max pending chunks before QuotaExceededError. Auto-calculated from resolution if dimensions provided (~300MB target memory). |
|
|
125
129
|
|
|
126
130
|
#### `decode(chunk: EncodedVideoChunk): void`
|
|
127
131
|
|
|
@@ -289,6 +293,63 @@ Close the decoder.
|
|
|
289
293
|
|
|
290
294
|
---
|
|
291
295
|
|
|
296
|
+
## ImageEncoder
|
|
297
|
+
|
|
298
|
+
Encodes VideoFrames to image formats (PNG, JPEG, WebP). This is a utility class (not part of WebCodecs spec) that mirrors ImageDecoder.
|
|
299
|
+
|
|
300
|
+
### Static Methods
|
|
301
|
+
|
|
302
|
+
#### `isTypeSupported(type: string): boolean`
|
|
303
|
+
|
|
304
|
+
Check if an output format is supported.
|
|
305
|
+
|
|
306
|
+
```typescript
|
|
307
|
+
ImageEncoder.isTypeSupported('image/webp'); // true
|
|
308
|
+
ImageEncoder.isTypeSupported('image/gif'); // false
|
|
309
|
+
```
|
|
310
|
+
|
|
311
|
+
#### `encode(frame: VideoFrame, options?: ImageEncoderOptions): Promise<ImageEncoderResult>`
|
|
312
|
+
|
|
313
|
+
Encode a VideoFrame to an image format asynchronously.
|
|
314
|
+
|
|
315
|
+
```typescript
|
|
316
|
+
const result = await ImageEncoder.encode(frame, {
|
|
317
|
+
type: 'image/jpeg',
|
|
318
|
+
quality: 0.85,
|
|
319
|
+
});
|
|
320
|
+
fs.writeFileSync('output.jpg', Buffer.from(result.data));
|
|
321
|
+
```
|
|
322
|
+
|
|
323
|
+
#### `encodeSync(frame: VideoFrame, options?: ImageEncoderOptions): ImageEncoderResult`
|
|
324
|
+
|
|
325
|
+
Encode a VideoFrame synchronously.
|
|
326
|
+
|
|
327
|
+
```typescript
|
|
328
|
+
const result = ImageEncoder.encodeSync(frame, { type: 'image/png' });
|
|
329
|
+
```
|
|
330
|
+
|
|
331
|
+
#### `encodeBatch(frames: VideoFrame[], options?: ImageEncoderOptions): Promise<ImageEncoderResult[]>`
|
|
332
|
+
|
|
333
|
+
Encode multiple frames in parallel.
|
|
334
|
+
|
|
335
|
+
```typescript
|
|
336
|
+
const results = await ImageEncoder.encodeBatch(frames, { type: 'image/webp' });
|
|
337
|
+
```
|
|
338
|
+
|
|
339
|
+
### Types
|
|
340
|
+
|
|
341
|
+
**ImageEncoderOptions:**
|
|
342
|
+
| Property | Type | Default | Description |
|
|
343
|
+
|----------|------|---------|-------------|
|
|
344
|
+
| `type` | `'image/png' \| 'image/jpeg' \| 'image/webp'` | `'image/png'` | Output format |
|
|
345
|
+
| `quality` | number | 0.92 (JPEG), 0.8 (WebP) | Quality for lossy formats (0-1) |
|
|
346
|
+
|
|
347
|
+
**ImageEncoderResult:**
|
|
348
|
+
- `data: ArrayBuffer` - Encoded image data
|
|
349
|
+
- `type: string` - MIME type of the encoded image
|
|
350
|
+
|
|
351
|
+
---
|
|
352
|
+
|
|
292
353
|
## VideoFrame
|
|
293
354
|
|
|
294
355
|
Represents a single video frame with raw pixel data.
|
|
@@ -311,6 +372,8 @@ new VideoFrame(data: BufferSource, init: VideoFrameBufferInit)
|
|
|
311
372
|
| `displayHeight` | number | No | Display height |
|
|
312
373
|
|
|
313
374
|
**Supported VideoPixelFormat values:**
|
|
375
|
+
|
|
376
|
+
*8-bit formats:*
|
|
314
377
|
- `'I420'` - YUV 4:2:0 planar
|
|
315
378
|
- `'I420A'` - YUV 4:2:0 planar with alpha
|
|
316
379
|
- `'I422'` - YUV 4:2:2 planar
|
|
@@ -321,6 +384,12 @@ new VideoFrame(data: BufferSource, init: VideoFrameBufferInit)
|
|
|
321
384
|
- `'BGRA'` - 8-bit BGRA
|
|
322
385
|
- `'BGRX'` - 8-bit BGR (alpha ignored)
|
|
323
386
|
|
|
387
|
+
*10-bit formats (HDR):*
|
|
388
|
+
- `'I420P10'` - YUV 4:2:0 planar, 10-bit (16-bit container)
|
|
389
|
+
- `'I422P10'` - YUV 4:2:2 planar, 10-bit (16-bit container)
|
|
390
|
+
- `'I444P10'` - YUV 4:4:4 planar, 10-bit (16-bit container)
|
|
391
|
+
- `'P010'` - YUV 4:2:0 semi-planar, 10-bit (16-bit container)
|
|
392
|
+
|
|
324
393
|
### Instance Methods
|
|
325
394
|
|
|
326
395
|
#### `allocationSize(options?: VideoFrameCopyToOptions): number`
|
|
@@ -348,6 +417,92 @@ Release frame resources. Always call this when done.
|
|
|
348
417
|
- `displayHeight: number`
|
|
349
418
|
- `timestamp: number`
|
|
350
419
|
- `duration: number | null`
|
|
420
|
+
- `colorSpace: VideoColorSpace` - Color space information
|
|
421
|
+
|
|
422
|
+
---
|
|
423
|
+
|
|
424
|
+
## VideoColorSpace
|
|
425
|
+
|
|
426
|
+
Describes the color space of a video frame, including HDR metadata.
|
|
427
|
+
|
|
428
|
+
### Constructor
|
|
429
|
+
|
|
430
|
+
```typescript
|
|
431
|
+
new VideoColorSpace(init?: VideoColorSpaceInit)
|
|
432
|
+
```
|
|
433
|
+
|
|
434
|
+
**VideoColorSpaceInit:**
|
|
435
|
+
| Property | Type | Default | Description |
|
|
436
|
+
|----------|------|---------|-------------|
|
|
437
|
+
| `primaries` | string | null | Color primaries ('bt709', 'bt2020', 'smpte432') |
|
|
438
|
+
| `transfer` | string | null | Transfer function ('bt709', 'pq', 'hlg', 'srgb') |
|
|
439
|
+
| `matrix` | string | null | Matrix coefficients ('bt709', 'bt2020-ncl') |
|
|
440
|
+
| `fullRange` | boolean | null | Full vs limited range |
|
|
441
|
+
| `hdrMetadata` | HdrMetadata | null | HDR mastering metadata |
|
|
442
|
+
|
|
443
|
+
### Properties
|
|
444
|
+
|
|
445
|
+
- `primaries: string | null` - Color primaries
|
|
446
|
+
- `transfer: string | null` - Transfer function
|
|
447
|
+
- `matrix: string | null` - Matrix coefficients
|
|
448
|
+
- `fullRange: boolean | null` - Full range flag
|
|
449
|
+
- `hdrMetadata: HdrMetadata | null` - HDR metadata (if present)
|
|
450
|
+
- `isHdr: boolean` - True if PQ or HLG transfer
|
|
451
|
+
- `hasHdrMetadata: boolean` - True if HDR metadata is set
|
|
452
|
+
|
|
453
|
+
### Instance Methods
|
|
454
|
+
|
|
455
|
+
#### `toJSON(): VideoColorSpaceInit`
|
|
456
|
+
|
|
457
|
+
Serialize to JSON-compatible object.
|
|
458
|
+
|
|
459
|
+
### HDR Metadata Types
|
|
460
|
+
|
|
461
|
+
**HdrMetadata:**
|
|
462
|
+
```typescript
|
|
463
|
+
interface HdrMetadata {
|
|
464
|
+
smpteSt2086?: SmpteSt2086Metadata; // Mastering display metadata
|
|
465
|
+
contentLightLevel?: ContentLightLevelInfo; // Content light levels
|
|
466
|
+
}
|
|
467
|
+
```
|
|
468
|
+
|
|
469
|
+
**SmpteSt2086Metadata (Mastering Display):**
|
|
470
|
+
| Property | Type | Description |
|
|
471
|
+
|----------|------|-------------|
|
|
472
|
+
| `primaryRChromaticityX/Y` | number | Red primary chromaticity |
|
|
473
|
+
| `primaryGChromaticityX/Y` | number | Green primary chromaticity |
|
|
474
|
+
| `primaryBChromaticityX/Y` | number | Blue primary chromaticity |
|
|
475
|
+
| `whitePointChromaticityX/Y` | number | White point chromaticity |
|
|
476
|
+
| `maxLuminance` | number | Maximum luminance (nits) |
|
|
477
|
+
| `minLuminance` | number | Minimum luminance (nits) |
|
|
478
|
+
|
|
479
|
+
**ContentLightLevelInfo:**
|
|
480
|
+
| Property | Type | Description |
|
|
481
|
+
|----------|------|-------------|
|
|
482
|
+
| `maxCLL` | number | Maximum Content Light Level (nits) |
|
|
483
|
+
| `maxFALL` | number | Maximum Frame Average Light Level (nits) |
|
|
484
|
+
|
|
485
|
+
### Helper Functions
|
|
486
|
+
|
|
487
|
+
#### `createHdr10MasteringMetadata(maxLuminance, minLuminance?): SmpteSt2086Metadata`
|
|
488
|
+
|
|
489
|
+
Create HDR10 mastering metadata with BT.2020 primaries.
|
|
490
|
+
|
|
491
|
+
```typescript
|
|
492
|
+
const metadata = createHdr10MasteringMetadata(1000, 0.0001);
|
|
493
|
+
```
|
|
494
|
+
|
|
495
|
+
#### `createContentLightLevel(maxCLL, maxFALL): ContentLightLevelInfo`
|
|
496
|
+
|
|
497
|
+
Create content light level info.
|
|
498
|
+
|
|
499
|
+
```typescript
|
|
500
|
+
const cll = createContentLightLevel(800, 400);
|
|
501
|
+
```
|
|
502
|
+
|
|
503
|
+
#### `HDR10_DISPLAY_PRIMARIES`
|
|
504
|
+
|
|
505
|
+
Constant with standard BT.2020 display primaries.
|
|
351
506
|
|
|
352
507
|
---
|
|
353
508
|
|