webcodecs-node 0.2.2 → 0.3.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 +4 -0
- package/dist/__tests__/AudioDecoder.test.js +3 -3
- package/dist/__tests__/AudioDecoder.test.js.map +1 -1
- package/dist/__tests__/ImageDecoder.wpt.test.d.ts +8 -0
- package/dist/__tests__/ImageDecoder.wpt.test.d.ts.map +1 -0
- package/dist/__tests__/ImageDecoder.wpt.test.js +135 -0
- package/dist/__tests__/ImageDecoder.wpt.test.js.map +1 -0
- package/dist/__tests__/NodeAvDecoder.test.d.ts +2 -0
- package/dist/__tests__/NodeAvDecoder.test.d.ts.map +1 -0
- package/dist/__tests__/NodeAvDecoder.test.js +199 -0
- package/dist/__tests__/NodeAvDecoder.test.js.map +1 -0
- package/dist/__tests__/NodeAvEncoder.test.d.ts +2 -0
- package/dist/__tests__/NodeAvEncoder.test.d.ts.map +1 -0
- package/dist/__tests__/NodeAvEncoder.test.js +176 -0
- package/dist/__tests__/NodeAvEncoder.test.js.map +1 -0
- package/dist/__tests__/VideoFrame.test.js.map +1 -1
- package/dist/backends/index.d.ts +3 -0
- package/dist/backends/index.d.ts.map +1 -0
- package/dist/backends/index.js +2 -0
- package/dist/backends/index.js.map +1 -0
- package/dist/backends/types.d.ts +165 -0
- package/dist/backends/types.d.ts.map +1 -0
- package/dist/backends/types.js +25 -0
- package/dist/backends/types.js.map +1 -0
- package/dist/core/AudioData.d.ts +1 -1
- package/dist/core/AudioData.d.ts.map +1 -1
- package/dist/core/AudioData.js +13 -9
- package/dist/core/AudioData.js.map +1 -1
- package/dist/core/VideoFrame.d.ts +25 -10
- package/dist/core/VideoFrame.d.ts.map +1 -1
- package/dist/core/VideoFrame.js +115 -65
- package/dist/core/VideoFrame.js.map +1 -1
- package/dist/decoders/AudioDecoder.d.ts +6 -12
- package/dist/decoders/AudioDecoder.d.ts.map +1 -1
- package/dist/decoders/AudioDecoder.js +57 -147
- 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 +59 -0
- package/dist/decoders/ImageDecoder.js.map +1 -1
- package/dist/decoders/VideoDecoder.d.ts +6 -13
- package/dist/decoders/VideoDecoder.d.ts.map +1 -1
- package/dist/decoders/VideoDecoder.js +49 -130
- package/dist/decoders/VideoDecoder.js.map +1 -1
- package/dist/demos/demo-conversion.js +2 -2
- package/dist/demos/demo-conversion.js.map +1 -1
- package/dist/demos/demo-four-corners.d.ts +6 -0
- package/dist/demos/demo-four-corners.d.ts.map +1 -0
- package/dist/demos/demo-four-corners.js +218 -0
- package/dist/demos/demo-four-corners.js.map +1 -0
- package/dist/demos/demo-samples.js +228 -64
- package/dist/demos/demo-samples.js.map +1 -1
- package/dist/encoders/AudioEncoder.d.ts +6 -13
- package/dist/encoders/AudioEncoder.d.ts.map +1 -1
- package/dist/encoders/AudioEncoder.js +81 -213
- package/dist/encoders/AudioEncoder.js.map +1 -1
- package/dist/encoders/VideoEncoder.d.ts +5 -14
- package/dist/encoders/VideoEncoder.d.ts.map +1 -1
- package/dist/encoders/VideoEncoder.js +39 -159
- package/dist/encoders/VideoEncoder.js.map +1 -1
- package/dist/formats/conversions/frame-converter.d.ts +17 -0
- package/dist/formats/conversions/frame-converter.d.ts.map +1 -1
- package/dist/formats/conversions/frame-converter.js +127 -0
- package/dist/formats/conversions/frame-converter.js.map +1 -1
- package/dist/formats/conversions/index.d.ts +1 -0
- package/dist/formats/conversions/index.d.ts.map +1 -1
- package/dist/formats/conversions/index.js +2 -0
- package/dist/formats/conversions/index.js.map +1 -1
- package/dist/hardware/detection.d.ts +1 -1
- package/dist/hardware/detection.d.ts.map +1 -1
- package/dist/hardware/detection.js +54 -27
- package/dist/hardware/detection.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts +2 -16
- package/dist/mediabunny/FFmpegAudioDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioDecoder.js +59 -184
- package/dist/mediabunny/FFmpegAudioDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts +4 -38
- package/dist/mediabunny/FFmpegAudioEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegAudioEncoder.js +64 -328
- package/dist/mediabunny/FFmpegAudioEncoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts +2 -36
- package/dist/mediabunny/FFmpegVideoDecoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoDecoder.js +37 -278
- package/dist/mediabunny/FFmpegVideoDecoder.js.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts +6 -35
- package/dist/mediabunny/FFmpegVideoEncoder.d.ts.map +1 -1
- package/dist/mediabunny/FFmpegVideoEncoder.js +46 -334
- package/dist/mediabunny/FFmpegVideoEncoder.js.map +1 -1
- package/dist/node-av/HardwarePipeline.d.ts +36 -0
- package/dist/node-av/HardwarePipeline.d.ts.map +1 -0
- package/dist/node-av/HardwarePipeline.js +243 -0
- package/dist/node-av/HardwarePipeline.js.map +1 -0
- package/dist/node-av/NodeAvAudioDecoder.d.ts +46 -0
- package/dist/node-av/NodeAvAudioDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvAudioDecoder.js +343 -0
- package/dist/node-av/NodeAvAudioDecoder.js.map +1 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts +44 -0
- package/dist/node-av/NodeAvAudioEncoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvAudioEncoder.js +385 -0
- package/dist/node-av/NodeAvAudioEncoder.js.map +1 -0
- package/dist/node-av/NodeAvImageDecoder.d.ts +95 -0
- package/dist/node-av/NodeAvImageDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvImageDecoder.js +287 -0
- package/dist/node-av/NodeAvImageDecoder.js.map +1 -0
- package/dist/node-av/NodeAvVideoDecoder.d.ts +43 -0
- package/dist/node-av/NodeAvVideoDecoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvVideoDecoder.js +361 -0
- package/dist/node-av/NodeAvVideoDecoder.js.map +1 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts +44 -0
- package/dist/node-av/NodeAvVideoEncoder.d.ts.map +1 -0
- package/dist/node-av/NodeAvVideoEncoder.js +397 -0
- package/dist/node-av/NodeAvVideoEncoder.js.map +1 -0
- package/dist/utils/event-target.d.ts +42 -0
- package/dist/utils/event-target.d.ts.map +1 -0
- package/dist/utils/event-target.js +96 -0
- package/dist/utils/event-target.js.map +1 -0
- package/dist/utils/index.d.ts +1 -0
- package/dist/utils/index.d.ts.map +1 -1
- package/dist/utils/index.js +2 -0
- package/dist/utils/index.js.map +1 -1
- package/package.json +14 -6
|
@@ -0,0 +1,243 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* HardwarePipeline - Intelligent filter chain selection for hardware video processing
|
|
3
|
+
*
|
|
4
|
+
* Automatically detects hardware capabilities and builds optimal filter chains
|
|
5
|
+
* for format conversion, preferring GPU-side operations when possible.
|
|
6
|
+
*/
|
|
7
|
+
import { FilterAPI } from 'node-av/api';
|
|
8
|
+
import { createLogger } from '../utils/logger.js';
|
|
9
|
+
const logger = createLogger('HardwarePipeline');
|
|
10
|
+
/**
|
|
11
|
+
* Known capabilities for each hardware type
|
|
12
|
+
* These are the theoretical capabilities - actual support depends on driver version
|
|
13
|
+
*/
|
|
14
|
+
const HARDWARE_CAPABILITIES = {
|
|
15
|
+
cuda: {
|
|
16
|
+
scaleFilter: 'scale_cuda',
|
|
17
|
+
gpuOutputFormats: ['nv12', 'yuv420p', 'p010le', 'yuv444p', 'bgra', 'rgba'],
|
|
18
|
+
supportsRgbOutput: true,
|
|
19
|
+
},
|
|
20
|
+
vaapi: {
|
|
21
|
+
scaleFilter: 'scale_vaapi',
|
|
22
|
+
gpuOutputFormats: ['nv12', 'p010'],
|
|
23
|
+
supportsRgbOutput: false,
|
|
24
|
+
},
|
|
25
|
+
qsv: {
|
|
26
|
+
scaleFilter: 'vpp_qsv', // vpp_qsv is more capable than scale_qsv
|
|
27
|
+
gpuOutputFormats: ['nv12', 'p010', 'bgra'], // bgra on some drivers
|
|
28
|
+
supportsRgbOutput: false, // Conservative - driver dependent
|
|
29
|
+
},
|
|
30
|
+
videotoolbox: {
|
|
31
|
+
scaleFilter: 'scale_vt',
|
|
32
|
+
gpuOutputFormats: ['nv12', 'p010', 'bgra'],
|
|
33
|
+
supportsRgbOutput: true,
|
|
34
|
+
},
|
|
35
|
+
drm: {
|
|
36
|
+
scaleFilter: '', // No GPU scale filter for DRM
|
|
37
|
+
gpuOutputFormats: ['nv12'],
|
|
38
|
+
supportsRgbOutput: false,
|
|
39
|
+
},
|
|
40
|
+
v4l2m2m: {
|
|
41
|
+
scaleFilter: '', // No GPU scale filter for V4L2
|
|
42
|
+
gpuOutputFormats: ['nv12', 'yuv420p'],
|
|
43
|
+
supportsRgbOutput: false,
|
|
44
|
+
},
|
|
45
|
+
software: {
|
|
46
|
+
scaleFilter: '',
|
|
47
|
+
gpuOutputFormats: [],
|
|
48
|
+
supportsRgbOutput: false,
|
|
49
|
+
},
|
|
50
|
+
};
|
|
51
|
+
/**
|
|
52
|
+
* Cache for probed filter chains
|
|
53
|
+
* Maps: hardwareType -> outputFormat -> working filter chain (or null if none work)
|
|
54
|
+
*/
|
|
55
|
+
const filterChainCache = new Map();
|
|
56
|
+
/**
|
|
57
|
+
* Test if a filter chain works by trying to create it
|
|
58
|
+
* Note: This only tests creation, not actual processing. Some filters may create
|
|
59
|
+
* successfully but fail during processing (e.g., vpp_qsv with missing MFX loader).
|
|
60
|
+
*/
|
|
61
|
+
function probeFilterChain(filterDescription, hardware) {
|
|
62
|
+
try {
|
|
63
|
+
const filter = FilterAPI.create(filterDescription, {
|
|
64
|
+
hardware: hardware ?? undefined,
|
|
65
|
+
});
|
|
66
|
+
filter.close();
|
|
67
|
+
return true;
|
|
68
|
+
}
|
|
69
|
+
catch {
|
|
70
|
+
return false;
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
/**
|
|
74
|
+
* Mark a filter chain as failed (discovered during actual processing)
|
|
75
|
+
*/
|
|
76
|
+
export function markFilterChainFailed(hwType, outputFormat, isHardwareFrame) {
|
|
77
|
+
const cacheKey = isHardwareFrame ? outputFormat : `sw_${outputFormat}`;
|
|
78
|
+
let hwCache = filterChainCache.get(hwType);
|
|
79
|
+
if (!hwCache) {
|
|
80
|
+
hwCache = new Map();
|
|
81
|
+
filterChainCache.set(hwType, hwCache);
|
|
82
|
+
}
|
|
83
|
+
// Mark current chain as failed by setting to null
|
|
84
|
+
hwCache.set(cacheKey, null);
|
|
85
|
+
// Also mark it in failed chains set
|
|
86
|
+
failedFilterChains.add(`${hwType}:${cacheKey}`);
|
|
87
|
+
}
|
|
88
|
+
/**
|
|
89
|
+
* Set of filter chains that failed during actual processing
|
|
90
|
+
*/
|
|
91
|
+
const failedFilterChains = new Set();
|
|
92
|
+
/**
|
|
93
|
+
* Check if a specific chain has been marked as failed
|
|
94
|
+
*/
|
|
95
|
+
function isChainFailed(hwType, outputFormat, isHardwareFrame) {
|
|
96
|
+
const cacheKey = isHardwareFrame ? outputFormat : `sw_${outputFormat}`;
|
|
97
|
+
return failedFilterChains.has(`${hwType}:${cacheKey}`);
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Get cached filter chain or null if not cached
|
|
101
|
+
*/
|
|
102
|
+
function getCachedFilterChain(hwType, outputFormat) {
|
|
103
|
+
const hwCache = filterChainCache.get(hwType);
|
|
104
|
+
if (!hwCache)
|
|
105
|
+
return undefined;
|
|
106
|
+
return hwCache.get(outputFormat);
|
|
107
|
+
}
|
|
108
|
+
/**
|
|
109
|
+
* Cache a filter chain result
|
|
110
|
+
*/
|
|
111
|
+
function cacheFilterChain(hwType, outputFormat, chain) {
|
|
112
|
+
let hwCache = filterChainCache.get(hwType);
|
|
113
|
+
if (!hwCache) {
|
|
114
|
+
hwCache = new Map();
|
|
115
|
+
filterChainCache.set(hwType, hwCache);
|
|
116
|
+
}
|
|
117
|
+
hwCache.set(outputFormat, chain);
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Build candidate filter chains in order of preference (best first)
|
|
121
|
+
*/
|
|
122
|
+
function buildCandidateChains(hwType, outputFormat, isHardwareFrame) {
|
|
123
|
+
const candidates = [];
|
|
124
|
+
const caps = HARDWARE_CAPABILITIES[hwType];
|
|
125
|
+
if (!isHardwareFrame) {
|
|
126
|
+
// Software frame - just format conversion
|
|
127
|
+
candidates.push(`format=${outputFormat}`);
|
|
128
|
+
return candidates;
|
|
129
|
+
}
|
|
130
|
+
// Hardware frame - try various strategies
|
|
131
|
+
// Strategy 1: GPU-side conversion if supported (best - no CPU conversion)
|
|
132
|
+
if (caps.scaleFilter && caps.gpuOutputFormats.includes(outputFormat)) {
|
|
133
|
+
// Full GPU: scale on GPU to target format, then download
|
|
134
|
+
candidates.push(`${caps.scaleFilter}=format=${outputFormat},hwdownload,format=${outputFormat}`);
|
|
135
|
+
}
|
|
136
|
+
// Strategy 2: GPU conversion to intermediate, then CPU conversion
|
|
137
|
+
// Try bgra/nv12 as intermediates since they're widely supported
|
|
138
|
+
if (caps.scaleFilter) {
|
|
139
|
+
for (const intermediate of ['bgra', 'nv12']) {
|
|
140
|
+
if (caps.gpuOutputFormats.includes(intermediate) && intermediate !== outputFormat) {
|
|
141
|
+
candidates.push(`${caps.scaleFilter}=format=${intermediate},hwdownload,format=${intermediate},format=${outputFormat}`);
|
|
142
|
+
}
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
// Strategy 3: Simple hwdownload then CPU conversion (most compatible)
|
|
146
|
+
candidates.push(`hwdownload,format=nv12,format=${outputFormat}`);
|
|
147
|
+
// Strategy 4: hwdownload with auto format detection
|
|
148
|
+
candidates.push(`hwdownload,format=${outputFormat}`);
|
|
149
|
+
return candidates;
|
|
150
|
+
}
|
|
151
|
+
/**
|
|
152
|
+
* Track which chain index we're on for each hw/format combo (for fallback iteration)
|
|
153
|
+
*/
|
|
154
|
+
const chainIndexMap = new Map();
|
|
155
|
+
/**
|
|
156
|
+
* Select the best filter chain for the given hardware and output format.
|
|
157
|
+
* Uses probing to verify the chain works on this specific hardware/driver.
|
|
158
|
+
* If a chain fails during actual processing, call getNextFilterChain() to try the next one.
|
|
159
|
+
*/
|
|
160
|
+
export function selectBestFilterChain(hardware, outputFormat, isHardwareFrame) {
|
|
161
|
+
const hwType = hardware?.deviceTypeName ?? 'software';
|
|
162
|
+
const cacheKey = `${hwType}:${isHardwareFrame ? outputFormat : `sw_${outputFormat}`}`;
|
|
163
|
+
// Build candidates in preference order
|
|
164
|
+
const candidates = buildCandidateChains(hwType, outputFormat, isHardwareFrame);
|
|
165
|
+
// Get current index (which chain we're trying)
|
|
166
|
+
const currentIndex = chainIndexMap.get(cacheKey) ?? 0;
|
|
167
|
+
// If we've exhausted all candidates, use the most compatible fallback
|
|
168
|
+
if (currentIndex >= candidates.length) {
|
|
169
|
+
const fallback = `hwdownload,format=nv12,format=${outputFormat}`;
|
|
170
|
+
logger.debug(`All chains exhausted for ${hwType}/${outputFormat}, using final fallback`);
|
|
171
|
+
return fallback;
|
|
172
|
+
}
|
|
173
|
+
const chain = candidates[currentIndex];
|
|
174
|
+
logger.debug(`Trying chain ${currentIndex + 1}/${candidates.length} for ${hwType}/${outputFormat}: ${chain}`);
|
|
175
|
+
return chain;
|
|
176
|
+
}
|
|
177
|
+
/**
|
|
178
|
+
* Move to the next filter chain after the current one failed.
|
|
179
|
+
* Returns the next chain to try, or null if all chains have been exhausted.
|
|
180
|
+
*/
|
|
181
|
+
export function getNextFilterChain(hardware, outputFormat, isHardwareFrame) {
|
|
182
|
+
const hwType = hardware?.deviceTypeName ?? 'software';
|
|
183
|
+
const cacheKey = `${hwType}:${isHardwareFrame ? outputFormat : `sw_${outputFormat}`}`;
|
|
184
|
+
// Increment the chain index
|
|
185
|
+
const currentIndex = (chainIndexMap.get(cacheKey) ?? 0) + 1;
|
|
186
|
+
chainIndexMap.set(cacheKey, currentIndex);
|
|
187
|
+
// Build candidates
|
|
188
|
+
const candidates = buildCandidateChains(hwType, outputFormat, isHardwareFrame);
|
|
189
|
+
if (currentIndex >= candidates.length) {
|
|
190
|
+
logger.debug(`All ${candidates.length} chains failed for ${hwType}/${outputFormat}`);
|
|
191
|
+
return null;
|
|
192
|
+
}
|
|
193
|
+
const chain = candidates[currentIndex];
|
|
194
|
+
logger.debug(`Falling back to chain ${currentIndex + 1}/${candidates.length}: ${chain}`);
|
|
195
|
+
return chain;
|
|
196
|
+
}
|
|
197
|
+
/**
|
|
198
|
+
* Get human-readable description of the selected pipeline
|
|
199
|
+
*/
|
|
200
|
+
export function describePipeline(filterChain, hwType) {
|
|
201
|
+
const parts = [];
|
|
202
|
+
if (filterChain.includes('scale_cuda')) {
|
|
203
|
+
parts.push('CUDA GPU scaling');
|
|
204
|
+
}
|
|
205
|
+
else if (filterChain.includes('scale_vaapi')) {
|
|
206
|
+
parts.push('VAAPI GPU scaling');
|
|
207
|
+
}
|
|
208
|
+
else if (filterChain.includes('vpp_qsv')) {
|
|
209
|
+
parts.push('QSV GPU processing');
|
|
210
|
+
}
|
|
211
|
+
else if (filterChain.includes('scale_vt')) {
|
|
212
|
+
parts.push('VideoToolbox GPU scaling');
|
|
213
|
+
}
|
|
214
|
+
if (filterChain.includes('hwdownload')) {
|
|
215
|
+
parts.push('GPU→CPU transfer');
|
|
216
|
+
}
|
|
217
|
+
const formatMatches = filterChain.match(/format=(\w+)/g);
|
|
218
|
+
if (formatMatches && formatMatches.length > 0) {
|
|
219
|
+
const lastFormat = formatMatches[formatMatches.length - 1].replace('format=', '');
|
|
220
|
+
parts.push(`output: ${lastFormat}`);
|
|
221
|
+
}
|
|
222
|
+
return parts.join(' → ') || filterChain;
|
|
223
|
+
}
|
|
224
|
+
/**
|
|
225
|
+
* Clear the filter chain cache (useful for testing or after hardware changes)
|
|
226
|
+
*/
|
|
227
|
+
export function clearPipelineCache() {
|
|
228
|
+
filterChainCache.clear();
|
|
229
|
+
}
|
|
230
|
+
/**
|
|
231
|
+
* Get current cache status for debugging
|
|
232
|
+
*/
|
|
233
|
+
export function getPipelineCacheStatus() {
|
|
234
|
+
const result = {};
|
|
235
|
+
for (const [hwType, formats] of filterChainCache) {
|
|
236
|
+
result[hwType] = {};
|
|
237
|
+
for (const [format, chain] of formats) {
|
|
238
|
+
result[hwType][format] = chain;
|
|
239
|
+
}
|
|
240
|
+
}
|
|
241
|
+
return result;
|
|
242
|
+
}
|
|
243
|
+
//# sourceMappingURL=HardwarePipeline.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"HardwarePipeline.js","sourceRoot":"","sources":["../../src/node-av/HardwarePipeline.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AAEzD,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAElD,MAAM,MAAM,GAAG,YAAY,CAAC,kBAAkB,CAAC,CAAC;AAgBhD;;;GAGG;AACH,MAAM,qBAAqB,GAAqD;IAC9E,IAAI,EAAE;QACJ,WAAW,EAAE,YAAY;QACzB,gBAAgB,EAAE,CAAC,MAAM,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,EAAE,MAAM,CAAC;QAC1E,iBAAiB,EAAE,IAAI;KACxB;IACD,KAAK,EAAE;QACL,WAAW,EAAE,aAAa;QAC1B,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,CAAC;QAClC,iBAAiB,EAAE,KAAK;KACzB;IACD,GAAG,EAAE;QACH,WAAW,EAAE,SAAS,EAAG,yCAAyC;QAClE,gBAAgB,EAAE,CAAC,MAAM,EAAE,MAAM,EAAE,MAAM,CAAC,EAAG,uBAAuB;QACpE,iBAAiB,EAAE,KAAK,EAAG,kCAAkC;KAC9D;IACD,YAAY,EAAE;QACZ,WA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C;IAED,MAAM,aAAa,GAAG,WAAW,CAAC,KAAK,CAAC,eAAe,CAAC,CAAC;IACzD,IAAI,aAAa,IAAI,aAAa,CAAC,MAAM,GAAG,CAAC,EAAE,CAAC;QAC9C,MAAM,UAAU,GAAG,aAAa,CAAC,aAAa,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,OAAO,CAAC,SAAS,EAAE,EAAE,CAAC,CAAC;QAClF,KAAK,CAAC,IAAI,CAAC,WAAW,UAAU,EAAE,CAAC,CAAC;IACtC,CAAC;IAED,OAAO,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC,IAAI,WAAW,CAAC;AAC1C,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,kBAAkB;IAChC,gBAAgB,CAAC,KAAK,EAAE,CAAC;AAC3B,CAAC;AAED;;GAEG;AACH,MAAM,UAAU,sBAAsB;IACpC,MAAM,MAAM,GAAkD,EAAE,CAAC;IACjE,KAAK,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,IAAI,gBAAgB,EAAE,CAAC;QACjD,MAAM,CAAC,MAAM,CAAC,GAAG,EAAE,CAAC;QACpB,KAAK,MAAM,CAAC,MAAM,EAAE,KAAK,CAAC,IAAI,OAAO,EAAE,CAAC;YACtC,MAAM,CAAC,MAAM,CAAC,CAAC,MAAM,CAAC,GAAG,KAAK,CAAC;QACjC,CAAC;IACH,CAAC;IACD,OAAO,MAAM,CAAC;AAChB,CAAC"}
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeAvAudioDecoder - Audio decoder using node-av native bindings
|
|
3
|
+
*
|
|
4
|
+
* Implements the AudioDecoderBackend interface for decoding audio streams
|
|
5
|
+
* using FFmpeg's libav* libraries via node-av.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import type { AudioDecoderBackend, AudioDecoderBackendConfig } from '../backends/types.js';
|
|
9
|
+
/**
|
|
10
|
+
* NodeAV-backed audio decoder implementing AudioDecoderBackend interface
|
|
11
|
+
*/
|
|
12
|
+
export declare class NodeAvAudioDecoder extends EventEmitter implements AudioDecoderBackend {
|
|
13
|
+
private decoder;
|
|
14
|
+
private formatContext;
|
|
15
|
+
private stream;
|
|
16
|
+
private filter;
|
|
17
|
+
private config;
|
|
18
|
+
private queue;
|
|
19
|
+
private processing;
|
|
20
|
+
private processingPromise;
|
|
21
|
+
private shuttingDown;
|
|
22
|
+
private packetIndex;
|
|
23
|
+
private frameIndex;
|
|
24
|
+
private packetTimeBase;
|
|
25
|
+
private outputSampleFormat;
|
|
26
|
+
private filterDescription;
|
|
27
|
+
private aacConfig;
|
|
28
|
+
private outputFormat;
|
|
29
|
+
get isHealthy(): boolean;
|
|
30
|
+
startDecoder(config: AudioDecoderBackendConfig): void;
|
|
31
|
+
write(data: Buffer | Uint8Array): boolean;
|
|
32
|
+
end(): void;
|
|
33
|
+
kill(): void;
|
|
34
|
+
shutdown(): Promise<void>;
|
|
35
|
+
private processQueue;
|
|
36
|
+
private ensureDecoder;
|
|
37
|
+
private parseOutputFormat;
|
|
38
|
+
private decodeBuffer;
|
|
39
|
+
private drainFrames;
|
|
40
|
+
private toOutputBuffer;
|
|
41
|
+
private parseAacDescription;
|
|
42
|
+
private getChannelLayout;
|
|
43
|
+
private finish;
|
|
44
|
+
private cleanup;
|
|
45
|
+
}
|
|
46
|
+
//# sourceMappingURL=NodeAvAudioDecoder.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeAvAudioDecoder.d.ts","sourceRoot":"","sources":["../../src/node-av/NodeAvAudioDecoder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AA8BtC,OAAO,KAAK,EACV,mBAAmB,EACnB,yBAAyB,EAE1B,MAAM,sBAAsB,CAAC;AAW9B;;GAEG;AACH,qBAAa,kBAAmB,SAAQ,YAAa,YAAW,mBAAmB;IACjF,OAAO,CAAC,OAAO,CAAwB;IACvC,OAAO,CAAC,aAAa,CAA8B;IACnD,OAAO,CAAC,MAAM,CAAuB;IACrC,OAAO,CAAC,MAAM,CAA0B;IACxC,OAAO,CAAC,MAAM,CAA0C;IACxD,OAAO,CAAC,KAAK,CAAgB;IAC7B,OAAO,CAAC,UAAU,CAAS;IAC3B,OAAO,CAAC,iBAAiB,CAA8B;IACvD,OAAO,CAAC,YAAY,CAAS;IAC7B,OAAO,CAAC,WAAW,CAAK;IACxB,OAAO,CAAC,UAAU,CAAK;IACvB,OAAO,CAAC,cAAc,CAAkD;IACxE,OAAO,CAAC,kBAAkB,CAAqC;IAC/D,OAAO,CAAC,iBAAiB,CAAuB;IAChD,OAAO,CAAC,SAAS,CAA0B;IAC3C,OAAO,CAAC,YAAY,CAA4B;IAEhD,IAAI,SAAS,IAAI,OAAO,CAEvB;IAED,YAAY,CAAC,MAAM,EAAE,yBAAyB,GAAG,IAAI;IAQrD,KAAK,CAAC,IAAI,EAAE,MAAM,GAAG,UAAU,GAAG,OAAO;IAgBzC,GAAG,IAAI,IAAI;IAMX,IAAI,IAAI,IAAI;IAMN,QAAQ,IAAI,OAAO,CAAC,IAAI,CAAC;YAIjB,YAAY;YAyBZ,aAAa;IAyC3B,OAAO,CAAC,iBAAiB;YAKX,YAAY;YAqBZ,WAAW;YAwBX,cAAc;IAiC5B,OAAO,CAAC,mBAAmB;IAwC3B,OAAO,CAAC,gBAAgB;YAiBV,MAAM;IAmBpB,OAAO,CAAC,OAAO;CAShB"}
|
|
@@ -0,0 +1,343 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NodeAvAudioDecoder - Audio decoder using node-av native bindings
|
|
3
|
+
*
|
|
4
|
+
* Implements the AudioDecoderBackend interface for decoding audio streams
|
|
5
|
+
* using FFmpeg's libav* libraries via node-av.
|
|
6
|
+
*/
|
|
7
|
+
import { EventEmitter } from 'events';
|
|
8
|
+
import { Decoder, FilterAPI } from 'node-av/api';
|
|
9
|
+
import { FormatContext, Packet, Rational } from 'node-av/lib';
|
|
10
|
+
import { AVMEDIA_TYPE_AUDIO, AV_SAMPLE_FMT_FLT, AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S16P, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_S32P, AV_SAMPLE_FMT_U8, AV_SAMPLE_FMT_U8P, AV_CODEC_ID_AAC, AV_CODEC_ID_OPUS, AV_CODEC_ID_MP3, AV_CODEC_ID_FLAC, AV_CODEC_ID_VORBIS, AV_CODEC_ID_PCM_S16LE, AV_CODEC_ID_PCM_F32LE, AV_CHANNEL_ORDER_NATIVE, AV_CH_LAYOUT_MONO, AV_CH_LAYOUT_STEREO, AV_CH_LAYOUT_5POINT1, AV_CH_LAYOUT_7POINT1, } from 'node-av/constants';
|
|
11
|
+
import { wrapAacFrameWithAdts } from '../utils/aac.js';
|
|
12
|
+
import { createLogger } from '../utils/logger.js';
|
|
13
|
+
const logger = createLogger('NodeAvAudioDecoder');
|
|
14
|
+
/** Default sample rate for audio decoding */
|
|
15
|
+
const DEFAULT_SAMPLE_RATE = 48000;
|
|
16
|
+
/**
|
|
17
|
+
* NodeAV-backed audio decoder implementing AudioDecoderBackend interface
|
|
18
|
+
*/
|
|
19
|
+
export class NodeAvAudioDecoder extends EventEmitter {
|
|
20
|
+
decoder = null;
|
|
21
|
+
formatContext = null;
|
|
22
|
+
stream = null;
|
|
23
|
+
filter = null;
|
|
24
|
+
config = null;
|
|
25
|
+
queue = [];
|
|
26
|
+
processing = false;
|
|
27
|
+
processingPromise = null;
|
|
28
|
+
shuttingDown = false;
|
|
29
|
+
packetIndex = 0;
|
|
30
|
+
frameIndex = 0;
|
|
31
|
+
packetTimeBase = new Rational(1, DEFAULT_SAMPLE_RATE);
|
|
32
|
+
outputSampleFormat = AV_SAMPLE_FMT_FLT;
|
|
33
|
+
filterDescription = null;
|
|
34
|
+
aacConfig = null;
|
|
35
|
+
outputFormat = 'f32';
|
|
36
|
+
get isHealthy() {
|
|
37
|
+
return !this.shuttingDown;
|
|
38
|
+
}
|
|
39
|
+
startDecoder(config) {
|
|
40
|
+
this.config = { ...config };
|
|
41
|
+
this.packetTimeBase = new Rational(1, config.sampleRate);
|
|
42
|
+
this.outputFormat = this.parseOutputFormat(config);
|
|
43
|
+
this.outputSampleFormat = mapSampleFormat(this.outputFormat);
|
|
44
|
+
this.aacConfig = this.parseAacDescription(config);
|
|
45
|
+
}
|
|
46
|
+
write(data) {
|
|
47
|
+
if (!this.config || this.shuttingDown) {
|
|
48
|
+
return false;
|
|
49
|
+
}
|
|
50
|
+
// If we have AAC config, wrap raw AAC frames with ADTS headers
|
|
51
|
+
let dataToWrite = Buffer.from(data);
|
|
52
|
+
if (this.aacConfig) {
|
|
53
|
+
dataToWrite = Buffer.from(wrapAacFrameWithAdts(new Uint8Array(data), this.aacConfig));
|
|
54
|
+
}
|
|
55
|
+
this.queue.push(dataToWrite);
|
|
56
|
+
void this.processQueue();
|
|
57
|
+
return true;
|
|
58
|
+
}
|
|
59
|
+
end() {
|
|
60
|
+
if (this.shuttingDown)
|
|
61
|
+
return;
|
|
62
|
+
this.shuttingDown = true;
|
|
63
|
+
void this.finish().catch((err) => this.emit('error', err));
|
|
64
|
+
}
|
|
65
|
+
kill() {
|
|
66
|
+
this.shuttingDown = true;
|
|
67
|
+
this.cleanup();
|
|
68
|
+
this.emit('close', null);
|
|
69
|
+
}
|
|
70
|
+
async shutdown() {
|
|
71
|
+
this.end();
|
|
72
|
+
}
|
|
73
|
+
async processQueue() {
|
|
74
|
+
if (this.processingPromise) {
|
|
75
|
+
return this.processingPromise;
|
|
76
|
+
}
|
|
77
|
+
this.processingPromise = (async () => {
|
|
78
|
+
if (this.processing)
|
|
79
|
+
return;
|
|
80
|
+
this.processing = true;
|
|
81
|
+
try {
|
|
82
|
+
while (this.queue.length > 0) {
|
|
83
|
+
const data = this.queue.shift();
|
|
84
|
+
await this.decodeBuffer(data);
|
|
85
|
+
}
|
|
86
|
+
}
|
|
87
|
+
catch (err) {
|
|
88
|
+
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
89
|
+
}
|
|
90
|
+
finally {
|
|
91
|
+
this.processing = false;
|
|
92
|
+
this.processingPromise = null;
|
|
93
|
+
}
|
|
94
|
+
})();
|
|
95
|
+
return this.processingPromise;
|
|
96
|
+
}
|
|
97
|
+
async ensureDecoder() {
|
|
98
|
+
if (this.decoder || !this.config) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
const codecId = mapCodecId(this.config.codec);
|
|
102
|
+
if (!codecId) {
|
|
103
|
+
throw new Error(`Unsupported audio codec: ${this.config.codec}`);
|
|
104
|
+
}
|
|
105
|
+
this.formatContext = new FormatContext();
|
|
106
|
+
this.formatContext.allocContext();
|
|
107
|
+
this.stream = this.formatContext.newStream();
|
|
108
|
+
this.stream.timeBase = this.packetTimeBase;
|
|
109
|
+
const params = this.stream.codecpar;
|
|
110
|
+
params.codecType = AVMEDIA_TYPE_AUDIO;
|
|
111
|
+
params.codecId = codecId;
|
|
112
|
+
params.sampleRate = this.config.sampleRate;
|
|
113
|
+
params.channelLayout = this.getChannelLayout(this.config.numberOfChannels);
|
|
114
|
+
params.channels = this.config.numberOfChannels;
|
|
115
|
+
// Set extradata if we have description (e.g., AudioSpecificConfig for AAC)
|
|
116
|
+
if (this.config.description && !this.aacConfig) {
|
|
117
|
+
const desc = this.config.description;
|
|
118
|
+
let bytes;
|
|
119
|
+
if (desc instanceof ArrayBuffer) {
|
|
120
|
+
bytes = new Uint8Array(desc);
|
|
121
|
+
}
|
|
122
|
+
else {
|
|
123
|
+
bytes = new Uint8Array(desc.buffer, desc.byteOffset, desc.byteLength);
|
|
124
|
+
}
|
|
125
|
+
params.extradata = Buffer.from(bytes);
|
|
126
|
+
}
|
|
127
|
+
this.decoder = await Decoder.create(this.stream, {
|
|
128
|
+
exitOnError: true,
|
|
129
|
+
});
|
|
130
|
+
logger.info(`Created decoder for codec: ${this.config.codec}`);
|
|
131
|
+
}
|
|
132
|
+
parseOutputFormat(config) {
|
|
133
|
+
// Default to f32 if not specified
|
|
134
|
+
return 'f32';
|
|
135
|
+
}
|
|
136
|
+
async decodeBuffer(buffer) {
|
|
137
|
+
await this.ensureDecoder();
|
|
138
|
+
if (!this.decoder || !this.stream) {
|
|
139
|
+
throw new Error('Decoder not initialized');
|
|
140
|
+
}
|
|
141
|
+
const packet = new Packet();
|
|
142
|
+
packet.alloc();
|
|
143
|
+
packet.streamIndex = this.stream.index;
|
|
144
|
+
packet.pts = BigInt(this.packetIndex);
|
|
145
|
+
packet.dts = BigInt(this.packetIndex);
|
|
146
|
+
packet.timeBase = this.packetTimeBase;
|
|
147
|
+
packet.data = buffer;
|
|
148
|
+
packet.duration = 1n;
|
|
149
|
+
await this.decoder.decode(packet);
|
|
150
|
+
packet.unref();
|
|
151
|
+
await this.drainFrames();
|
|
152
|
+
this.packetIndex++;
|
|
153
|
+
}
|
|
154
|
+
async drainFrames() {
|
|
155
|
+
if (!this.decoder)
|
|
156
|
+
return;
|
|
157
|
+
let frame = await this.decoder.receive();
|
|
158
|
+
while (frame) {
|
|
159
|
+
const nbSamples = frame.nbSamples;
|
|
160
|
+
if (nbSamples > 0) {
|
|
161
|
+
const converted = await this.toOutputBuffer(frame);
|
|
162
|
+
frame.unref();
|
|
163
|
+
if (converted) {
|
|
164
|
+
this.emit('frame', {
|
|
165
|
+
data: converted,
|
|
166
|
+
numberOfFrames: nbSamples,
|
|
167
|
+
timestamp: this.frameIndex,
|
|
168
|
+
});
|
|
169
|
+
this.frameIndex += nbSamples;
|
|
170
|
+
}
|
|
171
|
+
}
|
|
172
|
+
else {
|
|
173
|
+
frame.unref();
|
|
174
|
+
}
|
|
175
|
+
frame = await this.decoder.receive();
|
|
176
|
+
}
|
|
177
|
+
}
|
|
178
|
+
async toOutputBuffer(frame) {
|
|
179
|
+
const outputFormatName = sampleFormatToFFmpegName(this.outputSampleFormat);
|
|
180
|
+
const frameFormat = frame.format;
|
|
181
|
+
// If frame already matches requested format, just export
|
|
182
|
+
if (frameFormat === this.outputSampleFormat) {
|
|
183
|
+
return frame.toBuffer();
|
|
184
|
+
}
|
|
185
|
+
// Need to convert using filter
|
|
186
|
+
const description = `aformat=sample_fmts=${outputFormatName}`;
|
|
187
|
+
if (!this.filter || this.filterDescription !== description) {
|
|
188
|
+
this.filter?.close();
|
|
189
|
+
this.filter = FilterAPI.create(description, {});
|
|
190
|
+
this.filterDescription = description;
|
|
191
|
+
}
|
|
192
|
+
await this.filter.process(frame);
|
|
193
|
+
let filtered = await this.filter.receive();
|
|
194
|
+
while (filtered === null) {
|
|
195
|
+
filtered = await this.filter.receive();
|
|
196
|
+
}
|
|
197
|
+
if (!filtered) {
|
|
198
|
+
return null;
|
|
199
|
+
}
|
|
200
|
+
const buffer = filtered.toBuffer();
|
|
201
|
+
filtered.unref();
|
|
202
|
+
return buffer;
|
|
203
|
+
}
|
|
204
|
+
parseAacDescription(config) {
|
|
205
|
+
const codecBase = config.codec.split('.')[0].toLowerCase();
|
|
206
|
+
const isAac = codecBase === 'mp4a' || codecBase === 'aac';
|
|
207
|
+
if (!isAac || !config.description) {
|
|
208
|
+
return null;
|
|
209
|
+
}
|
|
210
|
+
// Parse AudioSpecificConfig to get profile and sampling frequency index
|
|
211
|
+
let bytes;
|
|
212
|
+
if (config.description instanceof ArrayBuffer) {
|
|
213
|
+
bytes = new Uint8Array(config.description);
|
|
214
|
+
}
|
|
215
|
+
else {
|
|
216
|
+
bytes = new Uint8Array(config.description.buffer, config.description.byteOffset, config.description.byteLength);
|
|
217
|
+
}
|
|
218
|
+
if (bytes.length < 2) {
|
|
219
|
+
return null;
|
|
220
|
+
}
|
|
221
|
+
// Parse AudioSpecificConfig (ISO 14496-3)
|
|
222
|
+
// First 5 bits: audioObjectType
|
|
223
|
+
// Next 4 bits: samplingFrequencyIndex
|
|
224
|
+
// Next 4 bits: channelConfiguration
|
|
225
|
+
const audioObjectType = (bytes[0] >> 3) & 0x1f;
|
|
226
|
+
const samplingFrequencyIndex = ((bytes[0] & 0x07) << 1) | ((bytes[1] >> 7) & 0x01);
|
|
227
|
+
const channelConfiguration = (bytes[1] >> 3) & 0x0f;
|
|
228
|
+
return {
|
|
229
|
+
audioObjectType,
|
|
230
|
+
samplingFrequencyIndex,
|
|
231
|
+
samplingRate: config.sampleRate,
|
|
232
|
+
channelConfiguration,
|
|
233
|
+
};
|
|
234
|
+
}
|
|
235
|
+
getChannelLayout(numChannels) {
|
|
236
|
+
// Standard channel layouts as ChannelLayout objects
|
|
237
|
+
// Order 1 = AV_CHANNEL_ORDER_NATIVE (required for FFmpeg)
|
|
238
|
+
switch (numChannels) {
|
|
239
|
+
case 1:
|
|
240
|
+
return { nbChannels: 1, order: AV_CHANNEL_ORDER_NATIVE, mask: AV_CH_LAYOUT_MONO };
|
|
241
|
+
case 2:
|
|
242
|
+
return { nbChannels: 2, order: AV_CHANNEL_ORDER_NATIVE, mask: AV_CH_LAYOUT_STEREO };
|
|
243
|
+
case 6:
|
|
244
|
+
return { nbChannels: 6, order: AV_CHANNEL_ORDER_NATIVE, mask: AV_CH_LAYOUT_5POINT1 };
|
|
245
|
+
case 8:
|
|
246
|
+
return { nbChannels: 8, order: AV_CHANNEL_ORDER_NATIVE, mask: AV_CH_LAYOUT_7POINT1 };
|
|
247
|
+
default:
|
|
248
|
+
return { nbChannels: numChannels, order: AV_CHANNEL_ORDER_NATIVE, mask: BigInt((1 << numChannels) - 1) };
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
async finish() {
|
|
252
|
+
await this.processQueue();
|
|
253
|
+
if (this.processingPromise) {
|
|
254
|
+
await this.processingPromise;
|
|
255
|
+
}
|
|
256
|
+
if (this.decoder) {
|
|
257
|
+
try {
|
|
258
|
+
await this.decoder.flush();
|
|
259
|
+
await this.drainFrames();
|
|
260
|
+
}
|
|
261
|
+
catch (err) {
|
|
262
|
+
this.emit('error', err instanceof Error ? err : new Error(String(err)));
|
|
263
|
+
}
|
|
264
|
+
}
|
|
265
|
+
this.emit('close', 0);
|
|
266
|
+
this.cleanup();
|
|
267
|
+
}
|
|
268
|
+
cleanup() {
|
|
269
|
+
this.filter?.close();
|
|
270
|
+
this.filter = null;
|
|
271
|
+
this.decoder?.close();
|
|
272
|
+
this.decoder = null;
|
|
273
|
+
this.formatContext = null;
|
|
274
|
+
this.stream = null;
|
|
275
|
+
this.queue = [];
|
|
276
|
+
}
|
|
277
|
+
}
|
|
278
|
+
function mapCodecId(codec) {
|
|
279
|
+
const codecBase = codec.split('.')[0].toLowerCase();
|
|
280
|
+
switch (codecBase) {
|
|
281
|
+
case 'mp4a':
|
|
282
|
+
case 'aac':
|
|
283
|
+
return AV_CODEC_ID_AAC;
|
|
284
|
+
case 'opus':
|
|
285
|
+
return AV_CODEC_ID_OPUS;
|
|
286
|
+
case 'mp3':
|
|
287
|
+
return AV_CODEC_ID_MP3;
|
|
288
|
+
case 'flac':
|
|
289
|
+
return AV_CODEC_ID_FLAC;
|
|
290
|
+
case 'vorbis':
|
|
291
|
+
return AV_CODEC_ID_VORBIS;
|
|
292
|
+
case 'pcm-s16':
|
|
293
|
+
return AV_CODEC_ID_PCM_S16LE;
|
|
294
|
+
case 'pcm-f32':
|
|
295
|
+
return AV_CODEC_ID_PCM_F32LE;
|
|
296
|
+
default:
|
|
297
|
+
return null;
|
|
298
|
+
}
|
|
299
|
+
}
|
|
300
|
+
function mapSampleFormat(format) {
|
|
301
|
+
switch (format) {
|
|
302
|
+
case 'u8':
|
|
303
|
+
return AV_SAMPLE_FMT_U8;
|
|
304
|
+
case 'u8-planar':
|
|
305
|
+
return AV_SAMPLE_FMT_U8P;
|
|
306
|
+
case 's16':
|
|
307
|
+
return AV_SAMPLE_FMT_S16;
|
|
308
|
+
case 's16-planar':
|
|
309
|
+
return AV_SAMPLE_FMT_S16P;
|
|
310
|
+
case 's32':
|
|
311
|
+
return AV_SAMPLE_FMT_S32;
|
|
312
|
+
case 's32-planar':
|
|
313
|
+
return AV_SAMPLE_FMT_S32P;
|
|
314
|
+
case 'f32':
|
|
315
|
+
return AV_SAMPLE_FMT_FLT;
|
|
316
|
+
case 'f32-planar':
|
|
317
|
+
return AV_SAMPLE_FMT_FLTP;
|
|
318
|
+
default:
|
|
319
|
+
return AV_SAMPLE_FMT_FLT;
|
|
320
|
+
}
|
|
321
|
+
}
|
|
322
|
+
function sampleFormatToFFmpegName(fmt) {
|
|
323
|
+
switch (fmt) {
|
|
324
|
+
case AV_SAMPLE_FMT_U8:
|
|
325
|
+
return 'u8';
|
|
326
|
+
case AV_SAMPLE_FMT_U8P:
|
|
327
|
+
return 'u8p';
|
|
328
|
+
case AV_SAMPLE_FMT_S16:
|
|
329
|
+
return 's16';
|
|
330
|
+
case AV_SAMPLE_FMT_S16P:
|
|
331
|
+
return 's16p';
|
|
332
|
+
case AV_SAMPLE_FMT_S32:
|
|
333
|
+
return 's32';
|
|
334
|
+
case AV_SAMPLE_FMT_S32P:
|
|
335
|
+
return 's32p';
|
|
336
|
+
case AV_SAMPLE_FMT_FLTP:
|
|
337
|
+
return 'fltp';
|
|
338
|
+
case AV_SAMPLE_FMT_FLT:
|
|
339
|
+
default:
|
|
340
|
+
return 'flt';
|
|
341
|
+
}
|
|
342
|
+
}
|
|
343
|
+
//# sourceMappingURL=NodeAvAudioDecoder.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"NodeAvAudioDecoder.js","sourceRoot":"","sources":["../../src/node-av/NodeAvAudioDecoder.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,YAAY,EAAE,MAAM,QAAQ,CAAC;AAEtC,OAAO,EAAE,OAAO,EAAE,SAAS,EAAE,MAAM,aAAa,CAAC;AACjD,OAAO,EAAE,aAAa,EAAE,MAAM,EAAU,QAAQ,EAAE,MAAM,aAAa,CAAC;AACtE,OAAO,EACL,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EACjB,kBAAkB,EAClB,iBAAiB,EAC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