node-av 1.0.3 → 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.
Files changed (162) hide show
  1. package/README.md +56 -41
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +182 -126
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +286 -130
  6. package/dist/api/decoder.js +321 -159
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +254 -158
  9. package/dist/api/encoder.js +326 -298
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +912 -0
  12. package/dist/api/filter-presets.js +1407 -0
  13. package/dist/api/filter-presets.js.map +1 -0
  14. package/dist/api/filter.d.ts +280 -284
  15. package/dist/api/filter.js +435 -509
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +226 -159
  18. package/dist/api/hardware.js +405 -287
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -2
  21. package/dist/api/index.js +1 -0
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +45 -47
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +244 -141
  27. package/dist/api/media-input.js +207 -104
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +212 -129
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +22 -182
  36. package/dist/api/utilities/audio-sample.d.ts +1 -1
  37. package/dist/api/utilities/image.d.ts +1 -1
  38. package/dist/api/utilities/media-type.d.ts +1 -1
  39. package/dist/api/utilities/pixel-format.d.ts +1 -1
  40. package/dist/api/utilities/sample-format.d.ts +1 -1
  41. package/dist/api/utilities/timestamp.d.ts +1 -1
  42. package/dist/api/utils.d.ts +1 -2
  43. package/dist/api/utils.js +9 -0
  44. package/dist/api/utils.js.map +1 -1
  45. package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
  46. package/dist/constants/channel-layouts.js.map +1 -0
  47. package/dist/{lib → constants}/constants.d.ts +19 -4
  48. package/dist/{lib → constants}/constants.js +15 -1
  49. package/dist/constants/constants.js.map +1 -0
  50. package/dist/constants/decoders.d.ts +609 -0
  51. package/dist/constants/decoders.js +617 -0
  52. package/dist/constants/decoders.js.map +1 -0
  53. package/dist/constants/encoders.d.ts +285 -0
  54. package/dist/constants/encoders.js +298 -0
  55. package/dist/constants/encoders.js.map +1 -0
  56. package/dist/constants/index.d.ts +4 -0
  57. package/dist/constants/index.js +5 -0
  58. package/dist/constants/index.js.map +1 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +2 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/audio-fifo.d.ts +128 -171
  63. package/dist/lib/audio-fifo.js +130 -173
  64. package/dist/lib/audio-fifo.js.map +1 -1
  65. package/dist/lib/binding.d.ts +7 -5
  66. package/dist/lib/binding.js +5 -0
  67. package/dist/lib/binding.js.map +1 -1
  68. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  69. package/dist/lib/bitstream-filter-context.js +139 -188
  70. package/dist/lib/bitstream-filter-context.js.map +1 -1
  71. package/dist/lib/bitstream-filter.d.ts +69 -55
  72. package/dist/lib/bitstream-filter.js +68 -54
  73. package/dist/lib/bitstream-filter.js.map +1 -1
  74. package/dist/lib/codec-context.d.ts +317 -381
  75. package/dist/lib/codec-context.js +316 -381
  76. package/dist/lib/codec-context.js.map +1 -1
  77. package/dist/lib/codec-parameters.d.ts +161 -171
  78. package/dist/lib/codec-parameters.js +162 -172
  79. package/dist/lib/codec-parameters.js.map +1 -1
  80. package/dist/lib/codec-parser.d.ts +92 -105
  81. package/dist/lib/codec-parser.js +92 -103
  82. package/dist/lib/codec-parser.js.map +1 -1
  83. package/dist/lib/codec.d.ts +328 -217
  84. package/dist/lib/codec.js +392 -218
  85. package/dist/lib/codec.js.map +1 -1
  86. package/dist/lib/dictionary.d.ts +150 -204
  87. package/dist/lib/dictionary.js +159 -213
  88. package/dist/lib/dictionary.js.map +1 -1
  89. package/dist/lib/error.d.ts +97 -131
  90. package/dist/lib/error.js +98 -128
  91. package/dist/lib/error.js.map +1 -1
  92. package/dist/lib/filter-context.d.ts +317 -194
  93. package/dist/lib/filter-context.js +335 -200
  94. package/dist/lib/filter-context.js.map +1 -1
  95. package/dist/lib/filter-graph.d.ts +252 -293
  96. package/dist/lib/filter-graph.js +253 -294
  97. package/dist/lib/filter-graph.js.map +1 -1
  98. package/dist/lib/filter-inout.d.ts +87 -95
  99. package/dist/lib/filter-inout.js +87 -95
  100. package/dist/lib/filter-inout.js.map +1 -1
  101. package/dist/lib/filter.d.ts +93 -111
  102. package/dist/lib/filter.js +94 -112
  103. package/dist/lib/filter.js.map +1 -1
  104. package/dist/lib/format-context.d.ts +321 -429
  105. package/dist/lib/format-context.js +314 -386
  106. package/dist/lib/format-context.js.map +1 -1
  107. package/dist/lib/frame.d.ts +263 -406
  108. package/dist/lib/frame.js +263 -408
  109. package/dist/lib/frame.js.map +1 -1
  110. package/dist/lib/hardware-device-context.d.ts +150 -204
  111. package/dist/lib/hardware-device-context.js +149 -203
  112. package/dist/lib/hardware-device-context.js.map +1 -1
  113. package/dist/lib/hardware-frames-context.d.ts +171 -181
  114. package/dist/lib/hardware-frames-context.js +171 -181
  115. package/dist/lib/hardware-frames-context.js.map +1 -1
  116. package/dist/lib/index.d.ts +2 -3
  117. package/dist/lib/index.js +2 -5
  118. package/dist/lib/index.js.map +1 -1
  119. package/dist/lib/input-format.d.ts +90 -118
  120. package/dist/lib/input-format.js +89 -117
  121. package/dist/lib/input-format.js.map +1 -1
  122. package/dist/lib/io-context.d.ts +210 -242
  123. package/dist/lib/io-context.js +221 -253
  124. package/dist/lib/io-context.js.map +1 -1
  125. package/dist/lib/log.d.ts +86 -120
  126. package/dist/lib/log.js +85 -122
  127. package/dist/lib/log.js.map +1 -1
  128. package/dist/lib/native-types.d.ts +127 -112
  129. package/dist/lib/native-types.js +9 -0
  130. package/dist/lib/native-types.js.map +1 -1
  131. package/dist/lib/option.d.ts +285 -242
  132. package/dist/lib/option.js +310 -250
  133. package/dist/lib/option.js.map +1 -1
  134. package/dist/lib/output-format.d.ts +78 -102
  135. package/dist/lib/output-format.js +77 -101
  136. package/dist/lib/output-format.js.map +1 -1
  137. package/dist/lib/packet.d.ts +173 -241
  138. package/dist/lib/packet.js +172 -241
  139. package/dist/lib/packet.js.map +1 -1
  140. package/dist/lib/rational.d.ts +0 -2
  141. package/dist/lib/rational.js +0 -2
  142. package/dist/lib/rational.js.map +1 -1
  143. package/dist/lib/software-resample-context.d.ts +242 -326
  144. package/dist/lib/software-resample-context.js +242 -326
  145. package/dist/lib/software-resample-context.js.map +1 -1
  146. package/dist/lib/software-scale-context.d.ts +130 -174
  147. package/dist/lib/software-scale-context.js +132 -176
  148. package/dist/lib/software-scale-context.js.map +1 -1
  149. package/dist/lib/stream.d.ts +88 -198
  150. package/dist/lib/stream.js +87 -197
  151. package/dist/lib/stream.js.map +1 -1
  152. package/dist/lib/types.d.ts +1 -1
  153. package/dist/lib/utilities.d.ts +372 -181
  154. package/dist/lib/utilities.js +373 -182
  155. package/dist/lib/utilities.js.map +1 -1
  156. package/install/check.js +0 -1
  157. package/package.json +32 -24
  158. package/release_notes.md +43 -13
  159. package/CHANGELOG.md +0 -8
  160. package/dist/lib/channel-layouts.js.map +0 -1
  161. package/dist/lib/constants.js.map +0 -1
  162. /package/dist/{lib → constants}/channel-layouts.js +0 -0
@@ -1,572 +1,488 @@
1
1
  import { OptionMember } from './option.js';
2
- import type { AVSampleFormat } from './constants.js';
2
+ import type { AVSampleFormat } from '../constants/constants.js';
3
3
  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
- * Software audio resampling context.
7
+ * Audio resampling and format conversion context.
8
8
  *
9
- * Provides high-quality audio resampling, format conversion, and channel mixing.
10
- * Supports sample rate conversion, channel layout remapping, and sample format conversion.
11
- * Uses the libswresample library for efficient audio processing.
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 { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
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 and configure resample context
21
- * const swr = new SoftwareResampleContext();
22
- * const ret = swr.allocSetOpts2(
23
- * { order: 0, nbChannels: 2, mask: 0x3 }, // stereo out
24
- * AV_SAMPLE_FMT_S16,
25
- * 44100,
26
- * { order: 0, nbChannels: 6, mask: 0x3f }, // 5.1 in
27
- * AV_SAMPLE_FMT_FLTP,
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
- * // Initialize
33
- * const initRet = swr.init();
34
- * FFmpegError.throwIfError(initRet, 'init');
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
- * // Convert audio
37
- * const samplesOut = await swr.convert(outBuffers, outSamples, inBuffers, inSamples);
38
- * FFmpegError.throwIfError(samplesOut, 'convert');
45
+ * const ret3 = resampler.convertFrame(outFrame, inFrame);
46
+ * FFmpegError.throwIfError(ret3, 'convertFrame');
39
47
  *
40
- * // Cleanup
41
- * swr.free();
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 SwrContext.
62
+ * Allocate resample context.
75
63
  *
76
- * Allocates an uninitialized resample context.
77
- * Options must be set through the AVOptions API before calling init().
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
- * import { SoftwareResampleContext, FFmpegError } from 'node-av';
86
- *
87
- * const swr = new SoftwareResampleContext();
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 one-step configuration
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 SwrContext if needed and set/reset common parameters.
80
+ * Allocate and configure resampler.
100
81
  *
101
- * One-step allocation and configuration of the resample context.
102
- * Automatically allocates the context if not already allocated.
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 (frequency in Hz)
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 (frequency in Hz)
112
- *
92
+ * @param inSampleRate - Input sample rate in Hz
113
93
  * @returns 0 on success, negative AVERROR on error:
114
- * - 0: Success
115
- * - AVERROR(EINVAL): Invalid parameters
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 { SoftwareResampleContext, FFmpegError } from 'node-av';
121
- * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
122
- *
123
- * const ret = swr.allocSetOpts2(
124
- * { order: 0, nbChannels: 2, mask: 0x3 }, // stereo
125
- * AV_SAMPLE_FMT_S16,
126
- * 44100,
127
- * { order: 0, nbChannels: 6, mask: 0x3f }, // 5.1
128
- * AV_SAMPLE_FMT_FLTP,
129
- * 48000
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} To initialize after configuration
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 context after user parameters have been set.
119
+ * Initialize resampler.
139
120
  *
140
- * Completes initialization of the resample context.
141
- * Must be called after configuration and before conversion.
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
- * - 0: Success
147
- * - AVERROR(EINVAL): Invalid parameters
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 = swr.init();
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 convert} For audio conversion
139
+ * @see {@link isInitialized} To check initialization status
160
140
  */
161
141
  init(): number;
162
142
  /**
163
- * Free the given SwrContext and set the pointer to NULL.
143
+ * Free resampler context.
164
144
  *
165
- * Direct mapping to swr_free()
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
- * swr.free();
170
- * // swr is now invalid and should not be used
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
- * Closes the context so that swr_is_initialized() returns 0.
161
+ * Close resampler context.
176
162
  *
177
- * Direct mapping to swr_close()
163
+ * Closes the resampler but keeps the context allocated.
164
+ * Can be reconfigured and reinitialized after closing.
178
165
  *
179
- * The context can be brought back to life by running swr_init(),
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
- * swr.close();
187
- * // Context is now closed but not freed
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
- * Direct mapping to swr_convert()
180
+ * Converts audio samples from input format to output format.
181
+ * Handles resampling, channel remapping, and format conversion.
199
182
  *
200
- * @param outBuffer - Output buffers, only the first one need be set in case of packed audio
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
- * @returns Number of samples output per channel, negative AVERROR on error:
206
- * - >=0: Number of samples output per channel
207
- * - AVERROR(EINVAL): Invalid parameters
208
- * - <0: Other errors
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
- * const samplesOut = await swr.convert(
215
- * outBuffers,
216
- * outSamples,
217
- * inBuffers,
218
- * inSamples
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
- * FFmpegError.throwIfError(samplesOut, 'convert');
221
- * console.log(`Converted ${samplesOut} samples per channel`);
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 the samples in the input AVFrame and write them to the output AVFrame.
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
- * Direct mapping to swr_convert_frame()
218
+ * Converts an entire audio frame to the output format.
219
+ * Simpler interface than convert() for frame-based processing.
240
220
  *
241
- * @param outFrame - Output AVFrame (can be null for flushing)
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
- * - 0: Success
246
- * - AVERROR(EINVAL): Invalid frame parameters
247
- * - AVERROR(EAGAIN): Need more input or output
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
- * const ret = swr.convertFrame(outFrame, inFrame);
234
+ * // Convert frame
235
+ * const outFrame = new Frame();
236
+ * const ret = resampler.convertFrame(outFrame, inFrame);
255
237
  * FFmpegError.throwIfError(ret, 'convertFrame');
256
238
  *
257
- * // Flush remaining samples
258
- * const flushRet = swr.convertFrame(outFrame, null);
259
- * FFmpegError.throwIfError(flushRet, 'flush');
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 getDelay} To check buffered samples
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 or reconfigure the SwrContext using the information provided by the AVFrames.
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
- * Direct mapping to swr_config_frame()
254
+ * Configures the resampler using format information from frames.
255
+ * Alternative to allocSetOpts2() for frame-based setup.
277
256
  *
278
- * @param outFrame - Output AVFrame (provides output parameters)
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
- * - 0: Success
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
- * const ret = swr.configFrame(outFrame, inFrame);
268
+ * // Configure from frames
269
+ * const ret = resampler.configFrame(outFrame, inFrame);
292
270
  * FFmpegError.throwIfError(ret, 'configFrame');
293
- * const initRet = swr.init();
294
- * FFmpegError.throwIfError(initRet, 'init');
271
+ *
272
+ * const ret2 = resampler.init();
273
+ * FFmpegError.throwIfError(ret2, 'init');
295
274
  * ```
296
275
  *
297
- * @see {@link init} Must be called after configuration
276
+ * @see {@link allocSetOpts2} For manual configuration
298
277
  */
299
278
  configFrame(outFrame: Frame | null, inFrame: Frame | null): number;
300
279
  /**
301
- * Check whether an swr context has been initialized or not.
280
+ * Check if initialized.
302
281
  *
303
- * Checks if the context is ready for audio conversion.
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
- * import { FFmpegError } from 'node-av';
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
- * Gets the delay the next input sample will experience relative to the next output sample.
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
- * Direct mapping to swr_get_delay()
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
- * @param base - Timebase in which the returned delay will be:
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
- * @returns The delay in 1 / base units
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 milliseconds
341
- * const delayMs = swr.getDelay(1000n);
342
- * console.log(`Buffered: ${delayMs}ms`);
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 output samples
345
- * const delaySamples = swr.getDelay(BigInt(outputSampleRate));
346
- * console.log(`Buffered: ${delaySamples} samples`);
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
- * Find an upper bound on the number of samples that the next swr_convert will output.
322
+ * Calculate output sample count.
354
323
  *
355
- * Calculates maximum output samples for given input samples.
356
- * Accounts for buffered data and sample rate conversion.
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
- * import { FFmpegError } from 'node-av';
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
- * Convert the next timestamp from input to output.
340
+ * Calculate next PTS.
385
341
  *
386
- * Converts timestamps accounting for sample rate conversion.
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 - Timestamp for the next input sample, INT64_MIN if unknown
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
- * const outPts = swr.nextPts(inPts);
398
- * outFrame.pts = outPts;
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
- * Activate resampling compensation ("soft" compensation).
358
+ * Set compensation.
406
359
  *
407
- * Adjusts resampling to compensate for timestamp drift.
408
- * Automatically called by nextPts() when needed.
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
- * - 0: Success
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
- * const ret = swr.setCompensation(delta, distance);
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 a customized input channel mapping.
381
+ * Set channel mapping.
434
382
  *
435
- * Remaps input channels to output channels.
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 - Customized input channel mapping (array of channel indexes, -1 for a muted channel)
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
- * import { FFmpegError } from 'node-av';
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 a customized remix matrix.
399
+ * Set mixing matrix.
461
400
  *
462
- * Sets custom coefficients for channel mixing.
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 - Remix coefficients
468
- * @param stride - Offset between lines of the matrix
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
- * import { FFmpegError } from 'node-av';
478
- *
479
- * // Set custom mix matrix for stereo to mono
480
- * const matrix = [0.5, 0.5]; // Mix both channels equally
481
- * const ret = swr.setMatrix(matrix, 1);
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
- * Drops the specified number of output samples.
422
+ * Drop output samples.
490
423
  *
491
- * Discards output samples for "hard" timestamp compensation.
492
- * Automatically called by nextPts() when needed.
493
- *
494
- * Direct mapping to swr_drop_output()
424
+ * Drops the specified number of output samples.
425
+ * Used for synchronization adjustments.
495
426
  *
496
- * @param count - Number of samples to be dropped
427
+ * Direct mapping to swr_drop_output().
497
428
  *
498
- * @returns 0 on success, negative AVERROR on error:
499
- * - 0: Success
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
- * import { FFmpegError } from 'node-av';
506
- *
507
- * const ret = swr.dropOutput(100);
508
- * FFmpegError.throwIfError(ret, 'dropOutput');
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
- * Injects the specified number of silence samples.
443
+ * Inject silence.
517
444
  *
518
- * Inserts silent samples for "hard" timestamp compensation.
519
- * Automatically called by nextPts() when needed.
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 be injected
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
- * import { FFmpegError } from 'node-av';
533
- *
534
- * const ret = swr.injectSilence(100);
535
- * FFmpegError.throwIfError(ret, 'injectSilence');
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 FFmpeg SwrContext pointer.
464
+ * Get the underlying native SoftwareResampleContext object.
465
+ *
466
+ * @returns The native SoftwareResampleContext binding object
544
467
  *
545
- * @internal For use by other wrapper classes
546
- * @returns The underlying native resample context object
468
+ * @internal
547
469
  */
548
470
  getNative(): NativeSoftwareResampleContext;
549
471
  /**
550
- * Dispose of the resample context.
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 swr = new SoftwareResampleContext();
561
- * const ret = swr.allocSetOpts2(...);
562
- * FFmpegError.throwIfError(ret, 'allocSetOpts2');
563
- * const initRet = swr.init();
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
  }