node-av 1.1.0 → 1.2.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 +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -59
- package/CHANGELOG.md +0 -8
|
@@ -4,569 +4,485 @@ import type { Frame } from './frame.js';
|
|
|
4
4
|
import type { NativeSoftwareResampleContext, NativeWrapper } from './native-types.js';
|
|
5
5
|
import type { ChannelLayout } from './types.js';
|
|
6
6
|
/**
|
|
7
|
-
*
|
|
7
|
+
* Audio resampling and format conversion context.
|
|
8
8
|
*
|
|
9
|
-
* Provides
|
|
10
|
-
*
|
|
11
|
-
*
|
|
9
|
+
* Provides comprehensive audio format conversion including sample rate conversion,
|
|
10
|
+
* channel layout remapping, and sample format conversion. Essential for audio
|
|
11
|
+
* processing pipelines where format compatibility is required between components.
|
|
12
|
+
* Supports high-quality resampling algorithms with configurable parameters.
|
|
12
13
|
*
|
|
13
14
|
* Direct mapping to FFmpeg's SwrContext.
|
|
14
15
|
*
|
|
15
16
|
* @example
|
|
16
17
|
* ```typescript
|
|
17
|
-
* import { SoftwareResampleContext, FFmpegError } from 'node-av';
|
|
18
|
-
* import {
|
|
18
|
+
* import { SoftwareResampleContext, Frame, FFmpegError } from 'node-av';
|
|
19
|
+
* import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
19
20
|
*
|
|
20
|
-
* // Create
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
* 48000
|
|
21
|
+
* // Create resampler
|
|
22
|
+
* const resampler = new SoftwareResampleContext();
|
|
23
|
+
*
|
|
24
|
+
* // Configure format conversion
|
|
25
|
+
* const outLayout = { nbChannels: 2, order: 1, u: { mask: 3n } }; // Stereo
|
|
26
|
+
* const inLayout = { nbChannels: 1, order: 1, u: { mask: 1n } }; // Mono
|
|
27
|
+
*
|
|
28
|
+
* const ret = resampler.allocSetOpts2(
|
|
29
|
+
* outLayout, AV_SAMPLE_FMT_S16, 48000, // Output: Stereo, 16-bit, 48kHz
|
|
30
|
+
* inLayout, AV_SAMPLE_FMT_FLTP, 44100 // Input: Mono, float, 44.1kHz
|
|
29
31
|
* );
|
|
30
32
|
* FFmpegError.throwIfError(ret, 'allocSetOpts2');
|
|
31
33
|
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
34
|
+
* const ret2 = resampler.init();
|
|
35
|
+
* FFmpegError.throwIfError(ret2, 'init');
|
|
36
|
+
*
|
|
37
|
+
* // Convert audio frame
|
|
38
|
+
* const outFrame = new Frame();
|
|
39
|
+
* outFrame.nbSamples = 1024;
|
|
40
|
+
* outFrame.format = AV_SAMPLE_FMT_S16;
|
|
41
|
+
* outFrame.channelLayout = outLayout;
|
|
42
|
+
* outFrame.sampleRate = 48000;
|
|
43
|
+
* outFrame.allocBuffer();
|
|
35
44
|
*
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
* FFmpegError.throwIfError(samplesOut, 'convert');
|
|
45
|
+
* const ret3 = resampler.convertFrame(outFrame, inFrame);
|
|
46
|
+
* FFmpegError.throwIfError(ret3, 'convertFrame');
|
|
39
47
|
*
|
|
40
|
-
* //
|
|
41
|
-
*
|
|
48
|
+
* // Get conversion delay
|
|
49
|
+
* const delay = resampler.getDelay(48000n);
|
|
50
|
+
* console.log(`Resampler delay: ${delay} samples`);
|
|
51
|
+
*
|
|
52
|
+
* // Clean up
|
|
53
|
+
* resampler.free();
|
|
42
54
|
* ```
|
|
55
|
+
*
|
|
56
|
+
* @see [SwrContext](https://ffmpeg.org/doxygen/trunk/structSwrContext.html) - FFmpeg Doxygen
|
|
57
|
+
* @see {@link Frame} For audio frame operations
|
|
43
58
|
*/
|
|
44
59
|
export declare class SoftwareResampleContext extends OptionMember<NativeSoftwareResampleContext> implements Disposable, NativeWrapper<NativeSoftwareResampleContext> {
|
|
45
|
-
/**
|
|
46
|
-
* Create a new software resample context.
|
|
47
|
-
*
|
|
48
|
-
* The context is uninitialized - you must call alloc() or allocSetOpts2() before use.
|
|
49
|
-
* No FFmpeg resources are allocated until initialization.
|
|
50
|
-
*
|
|
51
|
-
* Direct wrapper around SwrContext.
|
|
52
|
-
*
|
|
53
|
-
* @example
|
|
54
|
-
* ```typescript
|
|
55
|
-
* import { SoftwareResampleContext, FFmpegError } from 'node-av';
|
|
56
|
-
* import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
57
|
-
*
|
|
58
|
-
* const swr = new SoftwareResampleContext();
|
|
59
|
-
* const ret = swr.allocSetOpts2(
|
|
60
|
-
* { order: 0, nbChannels: 2, mask: 0x3 },
|
|
61
|
-
* AV_SAMPLE_FMT_S16,
|
|
62
|
-
* 44100,
|
|
63
|
-
* { order: 0, nbChannels: 6, mask: 0x3f },
|
|
64
|
-
* AV_SAMPLE_FMT_FLTP,
|
|
65
|
-
* 48000
|
|
66
|
-
* );
|
|
67
|
-
* FFmpegError.throwIfError(ret, 'allocSetOpts2');
|
|
68
|
-
* const initRet = swr.init();
|
|
69
|
-
* FFmpegError.throwIfError(initRet, 'init');
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
60
|
constructor();
|
|
73
61
|
/**
|
|
74
|
-
* Allocate
|
|
62
|
+
* Allocate resample context.
|
|
75
63
|
*
|
|
76
|
-
* Allocates
|
|
77
|
-
*
|
|
64
|
+
* Allocates memory for the resampler.
|
|
65
|
+
* Must be called before configuration.
|
|
78
66
|
*
|
|
79
|
-
* Direct mapping to swr_alloc()
|
|
80
|
-
*
|
|
81
|
-
* @throws {Error} Memory allocation failure (ENOMEM)
|
|
67
|
+
* Direct mapping to swr_alloc().
|
|
82
68
|
*
|
|
83
69
|
* @example
|
|
84
70
|
* ```typescript
|
|
85
|
-
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* swr.alloc();
|
|
89
|
-
* // Set options via AVOptions API
|
|
90
|
-
* const ret = swr.init();
|
|
91
|
-
* FFmpegError.throwIfError(ret, 'init');
|
|
71
|
+
* const resampler = new SoftwareResampleContext();
|
|
72
|
+
* resampler.alloc();
|
|
73
|
+
* // Now configure with setOption() or allocSetOpts2()
|
|
92
74
|
* ```
|
|
93
75
|
*
|
|
94
|
-
* @see {@link allocSetOpts2} For
|
|
95
|
-
* @see {@link init} To initialize after configuration
|
|
76
|
+
* @see {@link allocSetOpts2} For combined allocation and configuration
|
|
96
77
|
*/
|
|
97
78
|
alloc(): void;
|
|
98
79
|
/**
|
|
99
|
-
* Allocate
|
|
80
|
+
* Allocate and configure resampler.
|
|
100
81
|
*
|
|
101
|
-
*
|
|
102
|
-
*
|
|
82
|
+
* Combined allocation and configuration of the resampler with
|
|
83
|
+
* input and output format specifications.
|
|
103
84
|
*
|
|
104
|
-
* Direct mapping to swr_alloc_set_opts2()
|
|
85
|
+
* Direct mapping to swr_alloc_set_opts2().
|
|
105
86
|
*
|
|
106
87
|
* @param outChLayout - Output channel layout
|
|
107
88
|
* @param outSampleFmt - Output sample format
|
|
108
|
-
* @param outSampleRate - Output sample rate
|
|
89
|
+
* @param outSampleRate - Output sample rate in Hz
|
|
109
90
|
* @param inChLayout - Input channel layout
|
|
110
91
|
* @param inSampleFmt - Input sample format
|
|
111
|
-
* @param inSampleRate - Input sample rate
|
|
112
|
-
*
|
|
92
|
+
* @param inSampleRate - Input sample rate in Hz
|
|
113
93
|
* @returns 0 on success, negative AVERROR on error:
|
|
114
|
-
* -
|
|
115
|
-
* -
|
|
116
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
94
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
95
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
117
96
|
*
|
|
118
97
|
* @example
|
|
119
98
|
* ```typescript
|
|
120
|
-
* import {
|
|
121
|
-
* import {
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
99
|
+
* import { FFmpegError } from 'node-av';
|
|
100
|
+
* import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
101
|
+
*
|
|
102
|
+
* // Stereo layout
|
|
103
|
+
* const stereo = { nbChannels: 2, order: 1, u: { mask: 3n } };
|
|
104
|
+
* // 5.1 layout
|
|
105
|
+
* const surround = { nbChannels: 6, order: 1, u: { mask: 63n } };
|
|
106
|
+
*
|
|
107
|
+
* // Convert 5.1 float to stereo 16-bit
|
|
108
|
+
* const ret = resampler.allocSetOpts2(
|
|
109
|
+
* stereo, AV_SAMPLE_FMT_S16, 48000,
|
|
110
|
+
* surround, AV_SAMPLE_FMT_FLTP, 48000
|
|
130
111
|
* );
|
|
131
112
|
* FFmpegError.throwIfError(ret, 'allocSetOpts2');
|
|
132
113
|
* ```
|
|
133
114
|
*
|
|
134
|
-
* @see {@link init}
|
|
115
|
+
* @see {@link init} Must be called after configuration
|
|
135
116
|
*/
|
|
136
117
|
allocSetOpts2(outChLayout: ChannelLayout, outSampleFmt: AVSampleFormat, outSampleRate: number, inChLayout: ChannelLayout, inSampleFmt: AVSampleFormat, inSampleRate: number): number;
|
|
137
118
|
/**
|
|
138
|
-
* Initialize
|
|
119
|
+
* Initialize resampler.
|
|
139
120
|
*
|
|
140
|
-
*
|
|
141
|
-
* Must be called
|
|
121
|
+
* Initializes the resampler after configuration.
|
|
122
|
+
* Must be called before any conversion operations.
|
|
142
123
|
*
|
|
143
|
-
* Direct mapping to swr_init()
|
|
124
|
+
* Direct mapping to swr_init().
|
|
144
125
|
*
|
|
145
126
|
* @returns 0 on success, negative AVERROR on error:
|
|
146
|
-
* -
|
|
147
|
-
* -
|
|
148
|
-
* - <0: Other errors
|
|
127
|
+
* - AVERROR_EINVAL: Invalid configuration
|
|
128
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
149
129
|
*
|
|
150
130
|
* @example
|
|
151
131
|
* ```typescript
|
|
152
132
|
* import { FFmpegError } from 'node-av';
|
|
153
133
|
*
|
|
154
|
-
* const ret =
|
|
134
|
+
* const ret = resampler.init();
|
|
155
135
|
* FFmpegError.throwIfError(ret, 'init');
|
|
156
136
|
* ```
|
|
157
137
|
*
|
|
158
138
|
* @see {@link allocSetOpts2} For configuration
|
|
159
|
-
* @see {@link
|
|
139
|
+
* @see {@link isInitialized} To check initialization status
|
|
160
140
|
*/
|
|
161
141
|
init(): number;
|
|
162
142
|
/**
|
|
163
|
-
* Free
|
|
143
|
+
* Free resampler context.
|
|
164
144
|
*
|
|
165
|
-
*
|
|
145
|
+
* Releases all resources associated with the resampler.
|
|
146
|
+
* The context becomes invalid after calling this.
|
|
147
|
+
*
|
|
148
|
+
* Direct mapping to swr_free().
|
|
166
149
|
*
|
|
167
150
|
* @example
|
|
168
151
|
* ```typescript
|
|
169
|
-
*
|
|
170
|
-
* //
|
|
152
|
+
* resampler.free();
|
|
153
|
+
* // Resampler is now invalid
|
|
171
154
|
* ```
|
|
155
|
+
*
|
|
156
|
+
* @see {@link close} For closing without freeing
|
|
157
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
172
158
|
*/
|
|
173
159
|
free(): void;
|
|
174
160
|
/**
|
|
175
|
-
*
|
|
161
|
+
* Close resampler context.
|
|
176
162
|
*
|
|
177
|
-
*
|
|
163
|
+
* Closes the resampler but keeps the context allocated.
|
|
164
|
+
* Can be reconfigured and reinitialized after closing.
|
|
178
165
|
*
|
|
179
|
-
*
|
|
180
|
-
* swr_init() can also be used without swr_close().
|
|
181
|
-
* This function is mainly provided for simplifying the usecase
|
|
182
|
-
* where one tries to support libavresample and libswresample.
|
|
166
|
+
* Direct mapping to swr_close().
|
|
183
167
|
*
|
|
184
168
|
* @example
|
|
185
169
|
* ```typescript
|
|
186
|
-
*
|
|
187
|
-
* //
|
|
188
|
-
* // Can be reinitialized with swr.init()
|
|
170
|
+
* resampler.close();
|
|
171
|
+
* // Can now reconfigure and reinit
|
|
189
172
|
* ```
|
|
173
|
+
*
|
|
174
|
+
* @see {@link free} For complete deallocation
|
|
190
175
|
*/
|
|
191
176
|
close(): void;
|
|
192
177
|
/**
|
|
193
|
-
* Convert audio.
|
|
194
|
-
*
|
|
195
|
-
* Converts audio between different formats, sample rates, and channel layouts.
|
|
196
|
-
* Handles buffering internally when output space is insufficient.
|
|
178
|
+
* Convert audio samples.
|
|
197
179
|
*
|
|
198
|
-
*
|
|
180
|
+
* Converts audio samples from input format to output format.
|
|
181
|
+
* Handles resampling, channel remapping, and format conversion.
|
|
199
182
|
*
|
|
200
|
-
*
|
|
201
|
-
* @param outCount - Amount of space available for output in samples per channel
|
|
202
|
-
* @param inBuffer - Input buffers, only the first one need be set in case of packed audio
|
|
203
|
-
* @param inCount - Number of input samples available in one channel
|
|
183
|
+
* Direct mapping to swr_convert().
|
|
204
184
|
*
|
|
205
|
-
* @
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
185
|
+
* @param outBuffer - Output sample buffers (one per channel for planar)
|
|
186
|
+
* @param outCount - Maximum output samples per channel
|
|
187
|
+
* @param inBuffer - Input sample buffers (one per channel for planar)
|
|
188
|
+
* @param inCount - Input samples per channel
|
|
189
|
+
* @returns Number of output samples per channel, negative AVERROR on error:
|
|
190
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
191
|
+
* - AVERROR_INPUT_CHANGED: Input format changed
|
|
209
192
|
*
|
|
210
193
|
* @example
|
|
211
194
|
* ```typescript
|
|
212
195
|
* import { FFmpegError } from 'node-av';
|
|
213
196
|
*
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
218
|
-
*
|
|
197
|
+
* // Convert audio buffers
|
|
198
|
+
* const outBuffers = [Buffer.alloc(4096), Buffer.alloc(4096)]; // Stereo
|
|
199
|
+
* const inBuffers = [inputBuffer]; // Mono
|
|
200
|
+
*
|
|
201
|
+
* const samples = await resampler.convert(
|
|
202
|
+
* outBuffers, 1024,
|
|
203
|
+
* inBuffers, inputSamples
|
|
219
204
|
* );
|
|
220
|
-
*
|
|
221
|
-
*
|
|
205
|
+
*
|
|
206
|
+
* if (samples < 0) {
|
|
207
|
+
* FFmpegError.throwIfError(samples, 'convert');
|
|
208
|
+
* }
|
|
209
|
+
* console.log(`Converted ${samples} samples`);
|
|
222
210
|
* ```
|
|
223
211
|
*
|
|
224
|
-
* @see {@link getOutSamples} To calculate required output space
|
|
225
212
|
* @see {@link convertFrame} For frame-based conversion
|
|
226
|
-
*
|
|
227
|
-
* @note If more input is provided than output space, then the input will be buffered.
|
|
228
|
-
* You can avoid this buffering by using swr_get_out_samples() to retrieve an
|
|
229
|
-
* upper bound on the required number of output samples for the given number of
|
|
230
|
-
* input samples. Conversion will run directly without copying whenever possible.
|
|
231
213
|
*/
|
|
232
214
|
convert(outBuffer: Buffer[] | null, outCount: number, inBuffer: Buffer[] | null, inCount: number): Promise<number>;
|
|
233
215
|
/**
|
|
234
|
-
* Convert
|
|
235
|
-
*
|
|
236
|
-
* Frame-based audio conversion with automatic buffer management.
|
|
237
|
-
* Handles format, sample rate, and channel layout conversion.
|
|
216
|
+
* Convert audio frame.
|
|
238
217
|
*
|
|
239
|
-
*
|
|
218
|
+
* Converts an entire audio frame to the output format.
|
|
219
|
+
* Simpler interface than convert() for frame-based processing.
|
|
240
220
|
*
|
|
241
|
-
*
|
|
242
|
-
* @param inFrame - Input AVFrame (can be null for draining)
|
|
221
|
+
* Direct mapping to swr_convert_frame().
|
|
243
222
|
*
|
|
223
|
+
* @param outFrame - Output frame (null to drain)
|
|
224
|
+
* @param inFrame - Input frame (null to flush)
|
|
244
225
|
* @returns 0 on success, negative AVERROR on error:
|
|
245
|
-
* -
|
|
246
|
-
* -
|
|
247
|
-
* -
|
|
248
|
-
* - <0: Other errors
|
|
226
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
227
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
228
|
+
* - AVERROR_INPUT_CHANGED: Input format changed
|
|
249
229
|
*
|
|
250
230
|
* @example
|
|
251
231
|
* ```typescript
|
|
252
232
|
* import { Frame, FFmpegError } from 'node-av';
|
|
253
233
|
*
|
|
254
|
-
*
|
|
234
|
+
* // Convert frame
|
|
235
|
+
* const outFrame = new Frame();
|
|
236
|
+
* const ret = resampler.convertFrame(outFrame, inFrame);
|
|
255
237
|
* FFmpegError.throwIfError(ret, 'convertFrame');
|
|
256
238
|
*
|
|
257
|
-
* //
|
|
258
|
-
* const
|
|
259
|
-
*
|
|
239
|
+
* // Drain remaining samples
|
|
240
|
+
* const drainFrame = new Frame();
|
|
241
|
+
* const ret2 = resampler.convertFrame(drainFrame, null);
|
|
242
|
+
* if (ret2 === 0) {
|
|
243
|
+
* // Got drained samples
|
|
244
|
+
* }
|
|
260
245
|
* ```
|
|
261
246
|
*
|
|
262
247
|
* @see {@link convert} For buffer-based conversion
|
|
263
|
-
* @see {@link
|
|
264
|
-
*
|
|
265
|
-
* @note Input and output AVFrames must have channel_layout, sample_rate and format set.
|
|
266
|
-
* If the output AVFrame does not have the data pointers allocated the nb_samples
|
|
267
|
-
* field will be set and av_frame_get_buffer() is called to allocate the frame.
|
|
248
|
+
* @see {@link configFrame} To configure from frame
|
|
268
249
|
*/
|
|
269
250
|
convertFrame(outFrame: Frame | null, inFrame: Frame | null): number;
|
|
270
251
|
/**
|
|
271
|
-
* Configure
|
|
272
|
-
*
|
|
273
|
-
* Automatically configures the resample context from frame parameters.
|
|
274
|
-
* Resets the context even on failure and calls close() internally if open.
|
|
252
|
+
* Configure resampler from frames.
|
|
275
253
|
*
|
|
276
|
-
*
|
|
254
|
+
* Configures the resampler using format information from frames.
|
|
255
|
+
* Alternative to allocSetOpts2() for frame-based setup.
|
|
277
256
|
*
|
|
278
|
-
*
|
|
279
|
-
* @param inFrame - Input AVFrame (provides input parameters)
|
|
257
|
+
* Direct mapping to swr_config_frame().
|
|
280
258
|
*
|
|
259
|
+
* @param outFrame - Frame with output format
|
|
260
|
+
* @param inFrame - Frame with input format
|
|
281
261
|
* @returns 0 on success, negative AVERROR on error:
|
|
282
|
-
* -
|
|
283
|
-
* - AVERROR(EINVAL): Invalid frame parameters
|
|
284
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
285
|
-
* - <0: Other errors
|
|
262
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
286
263
|
*
|
|
287
264
|
* @example
|
|
288
265
|
* ```typescript
|
|
289
266
|
* import { FFmpegError } from 'node-av';
|
|
290
267
|
*
|
|
291
|
-
*
|
|
268
|
+
* // Configure from frames
|
|
269
|
+
* const ret = resampler.configFrame(outFrame, inFrame);
|
|
292
270
|
* FFmpegError.throwIfError(ret, 'configFrame');
|
|
293
|
-
*
|
|
294
|
-
*
|
|
271
|
+
*
|
|
272
|
+
* const ret2 = resampler.init();
|
|
273
|
+
* FFmpegError.throwIfError(ret2, 'init');
|
|
295
274
|
* ```
|
|
296
275
|
*
|
|
297
|
-
* @see {@link
|
|
276
|
+
* @see {@link allocSetOpts2} For manual configuration
|
|
298
277
|
*/
|
|
299
278
|
configFrame(outFrame: Frame | null, inFrame: Frame | null): number;
|
|
300
279
|
/**
|
|
301
|
-
* Check
|
|
280
|
+
* Check if initialized.
|
|
302
281
|
*
|
|
303
|
-
*
|
|
282
|
+
* Returns whether the resampler has been initialized.
|
|
304
283
|
*
|
|
305
|
-
* Direct mapping to swr_is_initialized()
|
|
284
|
+
* Direct mapping to swr_is_initialized().
|
|
306
285
|
*
|
|
307
286
|
* @returns True if initialized, false otherwise
|
|
308
287
|
*
|
|
309
288
|
* @example
|
|
310
289
|
* ```typescript
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
* if (swr.isInitialized()) {
|
|
314
|
-
* // Context is ready for conversion
|
|
315
|
-
* const ret = await swr.convert(outBuf, outCount, inBuf, inCount);
|
|
316
|
-
* FFmpegError.throwIfError(ret, 'convert');
|
|
290
|
+
* if (!resampler.isInitialized()) {
|
|
291
|
+
* resampler.init();
|
|
317
292
|
* }
|
|
318
293
|
* ```
|
|
294
|
+
*
|
|
295
|
+
* @see {@link init} To initialize
|
|
319
296
|
*/
|
|
320
297
|
isInitialized(): boolean;
|
|
321
298
|
/**
|
|
322
|
-
*
|
|
323
|
-
*
|
|
324
|
-
* Returns the total buffering delay in the resample context.
|
|
325
|
-
* Accounts for both buffered data and sample rate conversion delays.
|
|
299
|
+
* Get resampler delay.
|
|
326
300
|
*
|
|
327
|
-
*
|
|
301
|
+
* Returns the number of samples currently buffered in the resampler.
|
|
302
|
+
* These samples will be output when flushing or with new input.
|
|
328
303
|
*
|
|
329
|
-
*
|
|
330
|
-
* - 1: delay in seconds
|
|
331
|
-
* - 1000: delay in milliseconds
|
|
332
|
-
* - input sample rate: delay in input samples
|
|
333
|
-
* - output sample rate: delay in output samples
|
|
334
|
-
* - LCM of rates: exact rounding-free delay
|
|
304
|
+
* Direct mapping to swr_get_delay().
|
|
335
305
|
*
|
|
336
|
-
* @
|
|
306
|
+
* @param base - Time base for the returned delay
|
|
307
|
+
* @returns Delay in samples at the given base rate
|
|
337
308
|
*
|
|
338
309
|
* @example
|
|
339
310
|
* ```typescript
|
|
340
|
-
* // Get delay in
|
|
341
|
-
* const
|
|
342
|
-
* console.log(
|
|
311
|
+
* // Get delay in output sample rate
|
|
312
|
+
* const delay = resampler.getDelay(48000n);
|
|
313
|
+
* console.log(`${delay} samples buffered`);
|
|
343
314
|
*
|
|
344
|
-
* // Get delay in
|
|
345
|
-
* const
|
|
346
|
-
* console.log(
|
|
315
|
+
* // Get delay in microseconds
|
|
316
|
+
* const delayUs = resampler.getDelay(1000000n);
|
|
317
|
+
* console.log(`${delayUs} microseconds delay`);
|
|
347
318
|
* ```
|
|
348
|
-
*
|
|
349
|
-
* @see {@link getOutSamples} To calculate output buffer size
|
|
350
319
|
*/
|
|
351
320
|
getDelay(base: bigint): bigint;
|
|
352
321
|
/**
|
|
353
|
-
*
|
|
322
|
+
* Calculate output sample count.
|
|
354
323
|
*
|
|
355
|
-
* Calculates
|
|
356
|
-
*
|
|
324
|
+
* Calculates how many output samples will be produced
|
|
325
|
+
* for a given number of input samples.
|
|
357
326
|
*
|
|
358
|
-
* Direct mapping to swr_get_out_samples()
|
|
327
|
+
* Direct mapping to swr_get_out_samples().
|
|
359
328
|
*
|
|
360
329
|
* @param inSamples - Number of input samples
|
|
361
|
-
*
|
|
362
|
-
* @returns Upper bound on output samples or negative AVERROR:
|
|
363
|
-
* - >=0: Upper bound on the number of samples that the next swr_convert will output
|
|
364
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
365
|
-
* - <0: Other errors
|
|
330
|
+
* @returns Number of output samples
|
|
366
331
|
*
|
|
367
332
|
* @example
|
|
368
333
|
* ```typescript
|
|
369
|
-
*
|
|
370
|
-
*
|
|
371
|
-
* const outSamples = swr.getOutSamples(inSamples);
|
|
372
|
-
* FFmpegError.throwIfError(outSamples, 'getOutSamples');
|
|
373
|
-
* // Allocate output buffer for outSamples samples
|
|
374
|
-
* const bufferSize = outSamples * bytesPerSample * channels;
|
|
334
|
+
* const outSamples = resampler.getOutSamples(1024);
|
|
335
|
+
* console.log(`1024 input samples -> ${outSamples} output samples`);
|
|
375
336
|
* ```
|
|
376
|
-
*
|
|
377
|
-
* @see {@link convert} For actual conversion
|
|
378
|
-
*
|
|
379
|
-
* @note This depends on the internal state, and anything changing the internal state
|
|
380
|
-
* (like further swr_convert() calls) may change the number of samples returned.
|
|
381
337
|
*/
|
|
382
338
|
getOutSamples(inSamples: number): number;
|
|
383
339
|
/**
|
|
384
|
-
*
|
|
340
|
+
* Calculate next PTS.
|
|
385
341
|
*
|
|
386
|
-
*
|
|
387
|
-
* Timestamps are in 1/(in_sample_rate * out_sample_rate) units.
|
|
342
|
+
* Calculates the presentation timestamp for the next output sample.
|
|
388
343
|
*
|
|
389
|
-
* Direct mapping to swr_next_pts()
|
|
344
|
+
* Direct mapping to swr_next_pts().
|
|
390
345
|
*
|
|
391
|
-
* @param pts -
|
|
392
|
-
*
|
|
393
|
-
* @returns The output timestamp for the next output sample
|
|
346
|
+
* @param pts - Current presentation timestamp
|
|
347
|
+
* @returns Next presentation timestamp
|
|
394
348
|
*
|
|
395
349
|
* @example
|
|
396
350
|
* ```typescript
|
|
397
|
-
*
|
|
398
|
-
*
|
|
351
|
+
* let pts = 0n;
|
|
352
|
+
* pts = resampler.nextPts(pts);
|
|
353
|
+
* console.log(`Next PTS: ${pts}`);
|
|
399
354
|
* ```
|
|
400
|
-
*
|
|
401
|
-
* @see {@link setCompensation} For timestamp compensation
|
|
402
355
|
*/
|
|
403
356
|
nextPts(pts: bigint): bigint;
|
|
404
357
|
/**
|
|
405
|
-
*
|
|
358
|
+
* Set compensation.
|
|
406
359
|
*
|
|
407
|
-
* Adjusts resampling to compensate for
|
|
408
|
-
*
|
|
360
|
+
* Adjusts the resampling rate to compensate for clock drift.
|
|
361
|
+
* Used for audio/video synchronization.
|
|
409
362
|
*
|
|
410
|
-
* Direct mapping to swr_set_compensation()
|
|
411
|
-
*
|
|
412
|
-
* @param sampleDelta - Delta in PTS per sample
|
|
413
|
-
* @param compensationDistance - Number of samples to compensate for
|
|
363
|
+
* Direct mapping to swr_set_compensation().
|
|
414
364
|
*
|
|
365
|
+
* @param sampleDelta - Sample difference to compensate
|
|
366
|
+
* @param compensationDistance - Distance over which to compensate
|
|
415
367
|
* @returns 0 on success, negative AVERROR on error:
|
|
416
|
-
* -
|
|
417
|
-
* - AVERROR(EINVAL): Invalid parameters (NULL context, negative distance, etc.)
|
|
418
|
-
* - AVERROR(ENOSYS): Compensation unsupported by resampler
|
|
419
|
-
* - <0: Other errors
|
|
368
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
420
369
|
*
|
|
421
370
|
* @example
|
|
422
371
|
* ```typescript
|
|
423
372
|
* import { FFmpegError } from 'node-av';
|
|
424
373
|
*
|
|
425
|
-
*
|
|
374
|
+
* // Compensate 10 samples over 1000 samples
|
|
375
|
+
* const ret = resampler.setCompensation(10, 1000);
|
|
426
376
|
* FFmpegError.throwIfError(ret, 'setCompensation');
|
|
427
377
|
* ```
|
|
428
|
-
*
|
|
429
|
-
* @see {@link nextPts} For automatic compensation
|
|
430
378
|
*/
|
|
431
379
|
setCompensation(sampleDelta: number, compensationDistance: number): number;
|
|
432
380
|
/**
|
|
433
|
-
* Set
|
|
381
|
+
* Set channel mapping.
|
|
434
382
|
*
|
|
435
|
-
*
|
|
436
|
-
* Use -1 to mute a channel.
|
|
383
|
+
* Sets custom channel mapping for remixing.
|
|
437
384
|
*
|
|
438
|
-
* Direct mapping to swr_set_channel_mapping()
|
|
385
|
+
* Direct mapping to swr_set_channel_mapping().
|
|
439
386
|
*
|
|
440
|
-
* @param channelMap -
|
|
441
|
-
*
|
|
442
|
-
* @returns 0 on success, negative AVERROR on error:
|
|
443
|
-
* - 0: Success
|
|
444
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
445
|
-
* - <0: Other errors
|
|
387
|
+
* @param channelMap - Array mapping input to output channels
|
|
388
|
+
* @returns 0 on success, negative AVERROR on error
|
|
446
389
|
*
|
|
447
390
|
* @example
|
|
448
391
|
* ```typescript
|
|
449
|
-
*
|
|
450
|
-
*
|
|
451
|
-
* // Map channels: 0->0, 1->1, mute channel 2
|
|
452
|
-
* const ret = swr.setChannelMapping([0, 1, -1]);
|
|
392
|
+
* // Map stereo to reverse stereo (swap L/R)
|
|
393
|
+
* const ret = resampler.setChannelMapping([1, 0]);
|
|
453
394
|
* FFmpegError.throwIfError(ret, 'setChannelMapping');
|
|
454
395
|
* ```
|
|
455
|
-
*
|
|
456
|
-
* @see {@link setMatrix} For custom mixing matrix
|
|
457
396
|
*/
|
|
458
397
|
setChannelMapping(channelMap: number[]): number;
|
|
459
398
|
/**
|
|
460
|
-
* Set
|
|
399
|
+
* Set mixing matrix.
|
|
461
400
|
*
|
|
462
|
-
* Sets custom
|
|
463
|
-
* matrix[i + stride * o] is the weight of input channel i in output channel o.
|
|
401
|
+
* Sets a custom mixing matrix for channel remapping.
|
|
464
402
|
*
|
|
465
|
-
* Direct mapping to swr_set_matrix()
|
|
403
|
+
* Direct mapping to swr_set_matrix().
|
|
466
404
|
*
|
|
467
|
-
* @param matrix -
|
|
468
|
-
* @param stride -
|
|
469
|
-
*
|
|
470
|
-
* @returns 0 on success, negative AVERROR on error:
|
|
471
|
-
* - 0: Success
|
|
472
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
473
|
-
* - <0: Other errors
|
|
405
|
+
* @param matrix - Mixing matrix coefficients
|
|
406
|
+
* @param stride - Matrix row stride
|
|
407
|
+
* @returns 0 on success, negative AVERROR on error
|
|
474
408
|
*
|
|
475
409
|
* @example
|
|
476
410
|
* ```typescript
|
|
477
|
-
*
|
|
478
|
-
*
|
|
479
|
-
* //
|
|
480
|
-
*
|
|
481
|
-
*
|
|
411
|
+
* // Custom downmix matrix
|
|
412
|
+
* const matrix = [
|
|
413
|
+
* 1.0, 0.0, // Left channel
|
|
414
|
+
* 0.0, 1.0, // Right channel
|
|
415
|
+
* ];
|
|
416
|
+
* const ret = resampler.setMatrix(matrix, 2);
|
|
482
417
|
* FFmpegError.throwIfError(ret, 'setMatrix');
|
|
483
418
|
* ```
|
|
484
|
-
*
|
|
485
|
-
* @see {@link setChannelMapping} For channel remapping
|
|
486
419
|
*/
|
|
487
420
|
setMatrix(matrix: number[], stride: number): number;
|
|
488
421
|
/**
|
|
489
|
-
*
|
|
422
|
+
* Drop output samples.
|
|
490
423
|
*
|
|
491
|
-
*
|
|
492
|
-
*
|
|
493
|
-
*
|
|
494
|
-
* Direct mapping to swr_drop_output()
|
|
424
|
+
* Drops the specified number of output samples.
|
|
425
|
+
* Used for synchronization adjustments.
|
|
495
426
|
*
|
|
496
|
-
*
|
|
427
|
+
* Direct mapping to swr_drop_output().
|
|
497
428
|
*
|
|
498
|
-
* @
|
|
499
|
-
*
|
|
500
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
501
|
-
* - <0: Other errors
|
|
429
|
+
* @param count - Number of samples to drop
|
|
430
|
+
* @returns 0 on success, negative AVERROR on error
|
|
502
431
|
*
|
|
503
432
|
* @example
|
|
504
433
|
* ```typescript
|
|
505
|
-
*
|
|
506
|
-
*
|
|
507
|
-
*
|
|
508
|
-
*
|
|
434
|
+
* // Drop 100 output samples
|
|
435
|
+
* const ret = resampler.dropOutput(100);
|
|
436
|
+
* if (ret >= 0) {
|
|
437
|
+
* console.log(`Dropped ${ret} samples`);
|
|
438
|
+
* }
|
|
509
439
|
* ```
|
|
510
|
-
*
|
|
511
|
-
* @see {@link injectSilence} For adding silence
|
|
512
|
-
* @see {@link nextPts} For automatic compensation
|
|
513
440
|
*/
|
|
514
441
|
dropOutput(count: number): number;
|
|
515
442
|
/**
|
|
516
|
-
*
|
|
443
|
+
* Inject silence.
|
|
517
444
|
*
|
|
518
|
-
*
|
|
519
|
-
*
|
|
445
|
+
* Injects silent samples into the output.
|
|
446
|
+
* Used for padding or synchronization.
|
|
520
447
|
*
|
|
521
|
-
* Direct mapping to swr_inject_silence()
|
|
448
|
+
* Direct mapping to swr_inject_silence().
|
|
522
449
|
*
|
|
523
|
-
* @param count - Number of samples to
|
|
524
|
-
*
|
|
525
|
-
* @returns 0 on success, negative AVERROR on error:
|
|
526
|
-
* - 0: Success
|
|
527
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
528
|
-
* - <0: Other errors
|
|
450
|
+
* @param count - Number of silent samples to inject
|
|
451
|
+
* @returns 0 on success, negative AVERROR on error
|
|
529
452
|
*
|
|
530
453
|
* @example
|
|
531
454
|
* ```typescript
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
*
|
|
535
|
-
*
|
|
455
|
+
* // Inject 100 silent samples
|
|
456
|
+
* const ret = resampler.injectSilence(100);
|
|
457
|
+
* if (ret >= 0) {
|
|
458
|
+
* console.log(`Injected ${ret} silent samples`);
|
|
459
|
+
* }
|
|
536
460
|
* ```
|
|
537
|
-
*
|
|
538
|
-
* @see {@link dropOutput} For dropping samples
|
|
539
|
-
* @see {@link nextPts} For automatic compensation
|
|
540
461
|
*/
|
|
541
462
|
injectSilence(count: number): number;
|
|
542
463
|
/**
|
|
543
|
-
* Get the native
|
|
464
|
+
* Get the underlying native SoftwareResampleContext object.
|
|
465
|
+
*
|
|
466
|
+
* @returns The native SoftwareResampleContext binding object
|
|
544
467
|
*
|
|
545
|
-
* @internal
|
|
546
|
-
* @returns The underlying native resample context object
|
|
468
|
+
* @internal
|
|
547
469
|
*/
|
|
548
470
|
getNative(): NativeSoftwareResampleContext;
|
|
549
471
|
/**
|
|
550
|
-
* Dispose of the
|
|
472
|
+
* Dispose of the resampler context.
|
|
551
473
|
*
|
|
552
474
|
* Implements the Disposable interface for automatic cleanup.
|
|
553
475
|
* Equivalent to calling free().
|
|
554
476
|
*
|
|
555
477
|
* @example
|
|
556
478
|
* ```typescript
|
|
557
|
-
* import { SoftwareResampleContext, FFmpegError } from 'node-av';
|
|
558
|
-
*
|
|
559
479
|
* {
|
|
560
|
-
* using
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
*
|
|
564
|
-
* FFmpegError.throwIfError(initRet, 'init');
|
|
565
|
-
* // ... use context
|
|
480
|
+
* using resampler = new SoftwareResampleContext();
|
|
481
|
+
* resampler.allocSetOpts2(...);
|
|
482
|
+
* resampler.init();
|
|
483
|
+
* // Use resampler...
|
|
566
484
|
* } // Automatically freed when leaving scope
|
|
567
485
|
* ```
|
|
568
|
-
*
|
|
569
|
-
* @see {@link free} For manual cleanup
|
|
570
486
|
*/
|
|
571
487
|
[Symbol.dispose](): void;
|
|
572
488
|
}
|