node-av 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +377 -0
  4. package/binding.gyp +78 -0
  5. package/dist/api/bitstream-filter.d.ts +246 -0
  6. package/dist/api/bitstream-filter.js +369 -0
  7. package/dist/api/bitstream-filter.js.map +1 -0
  8. package/dist/api/decoder.d.ts +257 -0
  9. package/dist/api/decoder.js +424 -0
  10. package/dist/api/decoder.js.map +1 -0
  11. package/dist/api/encoder.d.ts +298 -0
  12. package/dist/api/encoder.js +574 -0
  13. package/dist/api/encoder.js.map +1 -0
  14. package/dist/api/filter.d.ts +457 -0
  15. package/dist/api/filter.js +876 -0
  16. package/dist/api/filter.js.map +1 -0
  17. package/dist/api/hardware.d.ts +318 -0
  18. package/dist/api/hardware.js +558 -0
  19. package/dist/api/hardware.js.map +1 -0
  20. package/dist/api/index.d.ts +12 -0
  21. package/dist/api/index.js +20 -0
  22. package/dist/api/index.js.map +1 -0
  23. package/dist/api/io-stream.d.ts +109 -0
  24. package/dist/api/io-stream.js +124 -0
  25. package/dist/api/io-stream.js.map +1 -0
  26. package/dist/api/media-input.d.ts +295 -0
  27. package/dist/api/media-input.js +456 -0
  28. package/dist/api/media-input.js.map +1 -0
  29. package/dist/api/media-output.d.ts +274 -0
  30. package/dist/api/media-output.js +486 -0
  31. package/dist/api/media-output.js.map +1 -0
  32. package/dist/api/pipeline.d.ts +117 -0
  33. package/dist/api/pipeline.js +836 -0
  34. package/dist/api/pipeline.js.map +1 -0
  35. package/dist/api/types.d.ts +440 -0
  36. package/dist/api/types.js +2 -0
  37. package/dist/api/types.js.map +1 -0
  38. package/dist/api/utilities/audio-sample.d.ts +115 -0
  39. package/dist/api/utilities/audio-sample.js +110 -0
  40. package/dist/api/utilities/audio-sample.js.map +1 -0
  41. package/dist/api/utilities/channel-layout.d.ts +83 -0
  42. package/dist/api/utilities/channel-layout.js +87 -0
  43. package/dist/api/utilities/channel-layout.js.map +1 -0
  44. package/dist/api/utilities/image.d.ts +177 -0
  45. package/dist/api/utilities/image.js +183 -0
  46. package/dist/api/utilities/image.js.map +1 -0
  47. package/dist/api/utilities/index.d.ts +8 -0
  48. package/dist/api/utilities/index.js +17 -0
  49. package/dist/api/utilities/index.js.map +1 -0
  50. package/dist/api/utilities/media-type.d.ts +56 -0
  51. package/dist/api/utilities/media-type.js +60 -0
  52. package/dist/api/utilities/media-type.js.map +1 -0
  53. package/dist/api/utilities/pixel-format.d.ts +94 -0
  54. package/dist/api/utilities/pixel-format.js +102 -0
  55. package/dist/api/utilities/pixel-format.js.map +1 -0
  56. package/dist/api/utilities/sample-format.d.ts +132 -0
  57. package/dist/api/utilities/sample-format.js +144 -0
  58. package/dist/api/utilities/sample-format.js.map +1 -0
  59. package/dist/api/utilities/streaming.d.ts +104 -0
  60. package/dist/api/utilities/streaming.js +137 -0
  61. package/dist/api/utilities/streaming.js.map +1 -0
  62. package/dist/api/utilities/timestamp.d.ts +187 -0
  63. package/dist/api/utilities/timestamp.js +200 -0
  64. package/dist/api/utilities/timestamp.js.map +1 -0
  65. package/dist/api/utils.d.ts +61 -0
  66. package/dist/api/utils.js +330 -0
  67. package/dist/api/utils.js.map +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +5 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lib/audio-fifo.d.ts +339 -0
  72. package/dist/lib/audio-fifo.js +365 -0
  73. package/dist/lib/audio-fifo.js.map +1 -0
  74. package/dist/lib/binding.d.ts +192 -0
  75. package/dist/lib/binding.js +70 -0
  76. package/dist/lib/binding.js.map +1 -0
  77. package/dist/lib/bitstream-filter-context.d.ts +345 -0
  78. package/dist/lib/bitstream-filter-context.js +407 -0
  79. package/dist/lib/bitstream-filter-context.js.map +1 -0
  80. package/dist/lib/bitstream-filter.d.ts +124 -0
  81. package/dist/lib/bitstream-filter.js +138 -0
  82. package/dist/lib/bitstream-filter.js.map +1 -0
  83. package/dist/lib/channel-layouts.d.ts +51 -0
  84. package/dist/lib/channel-layouts.js +55 -0
  85. package/dist/lib/channel-layouts.js.map +1 -0
  86. package/dist/lib/codec-context.d.ts +763 -0
  87. package/dist/lib/codec-context.js +974 -0
  88. package/dist/lib/codec-context.js.map +1 -0
  89. package/dist/lib/codec-parameters.d.ts +362 -0
  90. package/dist/lib/codec-parameters.js +460 -0
  91. package/dist/lib/codec-parameters.js.map +1 -0
  92. package/dist/lib/codec-parser.d.ts +185 -0
  93. package/dist/lib/codec-parser.js +193 -0
  94. package/dist/lib/codec-parser.js.map +1 -0
  95. package/dist/lib/codec.d.ts +432 -0
  96. package/dist/lib/codec.js +492 -0
  97. package/dist/lib/codec.js.map +1 -0
  98. package/dist/lib/constants.d.ts +2037 -0
  99. package/dist/lib/constants.js +1659 -0
  100. package/dist/lib/constants.js.map +1 -0
  101. package/dist/lib/dictionary.d.ts +371 -0
  102. package/dist/lib/dictionary.js +406 -0
  103. package/dist/lib/dictionary.js.map +1 -0
  104. package/dist/lib/error.d.ts +216 -0
  105. package/dist/lib/error.js +254 -0
  106. package/dist/lib/error.js.map +1 -0
  107. package/dist/lib/filter-context.d.ts +445 -0
  108. package/dist/lib/filter-context.js +505 -0
  109. package/dist/lib/filter-context.js.map +1 -0
  110. package/dist/lib/filter-graph.d.ts +556 -0
  111. package/dist/lib/filter-graph.js +608 -0
  112. package/dist/lib/filter-graph.js.map +1 -0
  113. package/dist/lib/filter-inout.d.ts +205 -0
  114. package/dist/lib/filter-inout.js +264 -0
  115. package/dist/lib/filter-inout.js.map +1 -0
  116. package/dist/lib/filter.d.ts +231 -0
  117. package/dist/lib/filter.js +260 -0
  118. package/dist/lib/filter.js.map +1 -0
  119. package/dist/lib/format-context.d.ts +798 -0
  120. package/dist/lib/format-context.js +845 -0
  121. package/dist/lib/format-context.js.map +1 -0
  122. package/dist/lib/frame.d.ts +784 -0
  123. package/dist/lib/frame.js +933 -0
  124. package/dist/lib/frame.js.map +1 -0
  125. package/dist/lib/hardware-device-context.d.ts +407 -0
  126. package/dist/lib/hardware-device-context.js +429 -0
  127. package/dist/lib/hardware-device-context.js.map +1 -0
  128. package/dist/lib/hardware-frames-context.d.ts +374 -0
  129. package/dist/lib/hardware-frames-context.js +430 -0
  130. package/dist/lib/hardware-frames-context.js.map +1 -0
  131. package/dist/lib/index.d.ts +31 -0
  132. package/dist/lib/index.js +54 -0
  133. package/dist/lib/index.js.map +1 -0
  134. package/dist/lib/input-format.d.ts +216 -0
  135. package/dist/lib/input-format.js +246 -0
  136. package/dist/lib/input-format.js.map +1 -0
  137. package/dist/lib/io-context.d.ts +495 -0
  138. package/dist/lib/io-context.js +550 -0
  139. package/dist/lib/io-context.js.map +1 -0
  140. package/dist/lib/log.d.ts +201 -0
  141. package/dist/lib/log.js +219 -0
  142. package/dist/lib/log.js.map +1 -0
  143. package/dist/lib/native-types.d.ts +719 -0
  144. package/dist/lib/native-types.js +2 -0
  145. package/dist/lib/native-types.js.map +1 -0
  146. package/dist/lib/option.d.ts +589 -0
  147. package/dist/lib/option.js +853 -0
  148. package/dist/lib/option.js.map +1 -0
  149. package/dist/lib/output-format.d.ts +179 -0
  150. package/dist/lib/output-format.js +205 -0
  151. package/dist/lib/output-format.js.map +1 -0
  152. package/dist/lib/packet.d.ts +487 -0
  153. package/dist/lib/packet.js +558 -0
  154. package/dist/lib/packet.js.map +1 -0
  155. package/dist/lib/rational.d.ts +210 -0
  156. package/dist/lib/rational.js +233 -0
  157. package/dist/lib/rational.js.map +1 -0
  158. package/dist/lib/software-resample-context.d.ts +572 -0
  159. package/dist/lib/software-resample-context.js +610 -0
  160. package/dist/lib/software-resample-context.js.map +1 -0
  161. package/dist/lib/software-scale-context.d.ts +290 -0
  162. package/dist/lib/software-scale-context.js +308 -0
  163. package/dist/lib/software-scale-context.js.map +1 -0
  164. package/dist/lib/stream.d.ts +322 -0
  165. package/dist/lib/stream.js +408 -0
  166. package/dist/lib/stream.js.map +1 -0
  167. package/dist/lib/types.d.ts +59 -0
  168. package/dist/lib/types.js +8 -0
  169. package/dist/lib/types.js.map +1 -0
  170. package/dist/lib/utilities.d.ts +346 -0
  171. package/dist/lib/utilities.js +424 -0
  172. package/dist/lib/utilities.js.map +1 -0
  173. package/install/check.js +113 -0
  174. package/install/ffmpeg.js +163 -0
  175. package/package.json +107 -0
@@ -0,0 +1,572 @@
1
+ import { OptionMember } from './option.js';
2
+ import type { AVSampleFormat } from './constants.js';
3
+ import type { Frame } from './frame.js';
4
+ import type { NativeSoftwareResampleContext, NativeWrapper } from './native-types.js';
5
+ import type { ChannelLayout } from './types.js';
6
+ /**
7
+ * Software audio resampling context.
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.
12
+ *
13
+ * Direct mapping to FFmpeg's SwrContext.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
18
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
19
+ *
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
29
+ * );
30
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
31
+ *
32
+ * // Initialize
33
+ * const initRet = swr.init();
34
+ * FFmpegError.throwIfError(initRet, 'init');
35
+ *
36
+ * // Convert audio
37
+ * const samplesOut = await swr.convert(outBuffers, outSamples, inBuffers, inSamples);
38
+ * FFmpegError.throwIfError(samplesOut, 'convert');
39
+ *
40
+ * // Cleanup
41
+ * swr.free();
42
+ * ```
43
+ */
44
+ 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
+ constructor();
73
+ /**
74
+ * Allocate SwrContext.
75
+ *
76
+ * Allocates an uninitialized resample context.
77
+ * Options must be set through the AVOptions API before calling init().
78
+ *
79
+ * Direct mapping to swr_alloc()
80
+ *
81
+ * @throws {Error} Memory allocation failure (ENOMEM)
82
+ *
83
+ * @example
84
+ * ```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');
92
+ * ```
93
+ *
94
+ * @see {@link allocSetOpts2} For one-step configuration
95
+ * @see {@link init} To initialize after configuration
96
+ */
97
+ alloc(): void;
98
+ /**
99
+ * Allocate SwrContext if needed and set/reset common parameters.
100
+ *
101
+ * One-step allocation and configuration of the resample context.
102
+ * Automatically allocates the context if not already allocated.
103
+ *
104
+ * Direct mapping to swr_alloc_set_opts2()
105
+ *
106
+ * @param outChLayout - Output channel layout
107
+ * @param outSampleFmt - Output sample format
108
+ * @param outSampleRate - Output sample rate (frequency in Hz)
109
+ * @param inChLayout - Input channel layout
110
+ * @param inSampleFmt - Input sample format
111
+ * @param inSampleRate - Input sample rate (frequency in Hz)
112
+ *
113
+ * @returns 0 on success, negative AVERROR on error:
114
+ * - 0: Success
115
+ * - AVERROR(EINVAL): Invalid parameters
116
+ * - AVERROR(ENOMEM): Memory allocation failure
117
+ *
118
+ * @example
119
+ * ```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
130
+ * );
131
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
132
+ * ```
133
+ *
134
+ * @see {@link init} To initialize after configuration
135
+ */
136
+ allocSetOpts2(outChLayout: ChannelLayout, outSampleFmt: AVSampleFormat, outSampleRate: number, inChLayout: ChannelLayout, inSampleFmt: AVSampleFormat, inSampleRate: number): number;
137
+ /**
138
+ * Initialize context after user parameters have been set.
139
+ *
140
+ * Completes initialization of the resample context.
141
+ * Must be called after configuration and before conversion.
142
+ *
143
+ * Direct mapping to swr_init()
144
+ *
145
+ * @returns 0 on success, negative AVERROR on error:
146
+ * - 0: Success
147
+ * - AVERROR(EINVAL): Invalid parameters
148
+ * - <0: Other errors
149
+ *
150
+ * @example
151
+ * ```typescript
152
+ * import { FFmpegError } from 'node-av';
153
+ *
154
+ * const ret = swr.init();
155
+ * FFmpegError.throwIfError(ret, 'init');
156
+ * ```
157
+ *
158
+ * @see {@link allocSetOpts2} For configuration
159
+ * @see {@link convert} For audio conversion
160
+ */
161
+ init(): number;
162
+ /**
163
+ * Free the given SwrContext and set the pointer to NULL.
164
+ *
165
+ * Direct mapping to swr_free()
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * swr.free();
170
+ * // swr is now invalid and should not be used
171
+ * ```
172
+ */
173
+ free(): void;
174
+ /**
175
+ * Closes the context so that swr_is_initialized() returns 0.
176
+ *
177
+ * Direct mapping to swr_close()
178
+ *
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.
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * swr.close();
187
+ * // Context is now closed but not freed
188
+ * // Can be reinitialized with swr.init()
189
+ * ```
190
+ */
191
+ close(): void;
192
+ /**
193
+ * Convert audio.
194
+ *
195
+ * Converts audio between different formats, sample rates, and channel layouts.
196
+ * Handles buffering internally when output space is insufficient.
197
+ *
198
+ * Direct mapping to swr_convert()
199
+ *
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
204
+ *
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
209
+ *
210
+ * @example
211
+ * ```typescript
212
+ * import { FFmpegError } from 'node-av';
213
+ *
214
+ * const samplesOut = await swr.convert(
215
+ * outBuffers,
216
+ * outSamples,
217
+ * inBuffers,
218
+ * inSamples
219
+ * );
220
+ * FFmpegError.throwIfError(samplesOut, 'convert');
221
+ * console.log(`Converted ${samplesOut} samples per channel`);
222
+ * ```
223
+ *
224
+ * @see {@link getOutSamples} To calculate required output space
225
+ * @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
+ */
232
+ convert(outBuffer: Buffer[] | null, outCount: number, inBuffer: Buffer[] | null, inCount: number): Promise<number>;
233
+ /**
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.
238
+ *
239
+ * Direct mapping to swr_convert_frame()
240
+ *
241
+ * @param outFrame - Output AVFrame (can be null for flushing)
242
+ * @param inFrame - Input AVFrame (can be null for draining)
243
+ *
244
+ * @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
249
+ *
250
+ * @example
251
+ * ```typescript
252
+ * import { Frame, FFmpegError } from 'node-av';
253
+ *
254
+ * const ret = swr.convertFrame(outFrame, inFrame);
255
+ * FFmpegError.throwIfError(ret, 'convertFrame');
256
+ *
257
+ * // Flush remaining samples
258
+ * const flushRet = swr.convertFrame(outFrame, null);
259
+ * FFmpegError.throwIfError(flushRet, 'flush');
260
+ * ```
261
+ *
262
+ * @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.
268
+ */
269
+ convertFrame(outFrame: Frame | null, inFrame: Frame | null): number;
270
+ /**
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.
275
+ *
276
+ * Direct mapping to swr_config_frame()
277
+ *
278
+ * @param outFrame - Output AVFrame (provides output parameters)
279
+ * @param inFrame - Input AVFrame (provides input parameters)
280
+ *
281
+ * @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
286
+ *
287
+ * @example
288
+ * ```typescript
289
+ * import { FFmpegError } from 'node-av';
290
+ *
291
+ * const ret = swr.configFrame(outFrame, inFrame);
292
+ * FFmpegError.throwIfError(ret, 'configFrame');
293
+ * const initRet = swr.init();
294
+ * FFmpegError.throwIfError(initRet, 'init');
295
+ * ```
296
+ *
297
+ * @see {@link init} Must be called after configuration
298
+ */
299
+ configFrame(outFrame: Frame | null, inFrame: Frame | null): number;
300
+ /**
301
+ * Check whether an swr context has been initialized or not.
302
+ *
303
+ * Checks if the context is ready for audio conversion.
304
+ *
305
+ * Direct mapping to swr_is_initialized()
306
+ *
307
+ * @returns True if initialized, false otherwise
308
+ *
309
+ * @example
310
+ * ```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');
317
+ * }
318
+ * ```
319
+ */
320
+ isInitialized(): boolean;
321
+ /**
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.
326
+ *
327
+ * Direct mapping to swr_get_delay()
328
+ *
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
335
+ *
336
+ * @returns The delay in 1 / base units
337
+ *
338
+ * @example
339
+ * ```typescript
340
+ * // Get delay in milliseconds
341
+ * const delayMs = swr.getDelay(1000n);
342
+ * console.log(`Buffered: ${delayMs}ms`);
343
+ *
344
+ * // Get delay in output samples
345
+ * const delaySamples = swr.getDelay(BigInt(outputSampleRate));
346
+ * console.log(`Buffered: ${delaySamples} samples`);
347
+ * ```
348
+ *
349
+ * @see {@link getOutSamples} To calculate output buffer size
350
+ */
351
+ getDelay(base: bigint): bigint;
352
+ /**
353
+ * Find an upper bound on the number of samples that the next swr_convert will output.
354
+ *
355
+ * Calculates maximum output samples for given input samples.
356
+ * Accounts for buffered data and sample rate conversion.
357
+ *
358
+ * Direct mapping to swr_get_out_samples()
359
+ *
360
+ * @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
366
+ *
367
+ * @example
368
+ * ```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;
375
+ * ```
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
+ */
382
+ getOutSamples(inSamples: number): number;
383
+ /**
384
+ * Convert the next timestamp from input to output.
385
+ *
386
+ * Converts timestamps accounting for sample rate conversion.
387
+ * Timestamps are in 1/(in_sample_rate * out_sample_rate) units.
388
+ *
389
+ * Direct mapping to swr_next_pts()
390
+ *
391
+ * @param pts - Timestamp for the next input sample, INT64_MIN if unknown
392
+ *
393
+ * @returns The output timestamp for the next output sample
394
+ *
395
+ * @example
396
+ * ```typescript
397
+ * const outPts = swr.nextPts(inPts);
398
+ * outFrame.pts = outPts;
399
+ * ```
400
+ *
401
+ * @see {@link setCompensation} For timestamp compensation
402
+ */
403
+ nextPts(pts: bigint): bigint;
404
+ /**
405
+ * Activate resampling compensation ("soft" compensation).
406
+ *
407
+ * Adjusts resampling to compensate for timestamp drift.
408
+ * Automatically called by nextPts() when needed.
409
+ *
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
414
+ *
415
+ * @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
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * import { FFmpegError } from 'node-av';
424
+ *
425
+ * const ret = swr.setCompensation(delta, distance);
426
+ * FFmpegError.throwIfError(ret, 'setCompensation');
427
+ * ```
428
+ *
429
+ * @see {@link nextPts} For automatic compensation
430
+ */
431
+ setCompensation(sampleDelta: number, compensationDistance: number): number;
432
+ /**
433
+ * Set a customized input channel mapping.
434
+ *
435
+ * Remaps input channels to output channels.
436
+ * Use -1 to mute a channel.
437
+ *
438
+ * Direct mapping to swr_set_channel_mapping()
439
+ *
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
446
+ *
447
+ * @example
448
+ * ```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]);
453
+ * FFmpegError.throwIfError(ret, 'setChannelMapping');
454
+ * ```
455
+ *
456
+ * @see {@link setMatrix} For custom mixing matrix
457
+ */
458
+ setChannelMapping(channelMap: number[]): number;
459
+ /**
460
+ * Set a customized remix matrix.
461
+ *
462
+ * Sets custom coefficients for channel mixing.
463
+ * matrix[i + stride * o] is the weight of input channel i in output channel o.
464
+ *
465
+ * Direct mapping to swr_set_matrix()
466
+ *
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
474
+ *
475
+ * @example
476
+ * ```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);
482
+ * FFmpegError.throwIfError(ret, 'setMatrix');
483
+ * ```
484
+ *
485
+ * @see {@link setChannelMapping} For channel remapping
486
+ */
487
+ setMatrix(matrix: number[], stride: number): number;
488
+ /**
489
+ * Drops the specified number of output samples.
490
+ *
491
+ * Discards output samples for "hard" timestamp compensation.
492
+ * Automatically called by nextPts() when needed.
493
+ *
494
+ * Direct mapping to swr_drop_output()
495
+ *
496
+ * @param count - Number of samples to be dropped
497
+ *
498
+ * @returns 0 on success, negative AVERROR on error:
499
+ * - 0: Success
500
+ * - AVERROR(EINVAL): Invalid parameters
501
+ * - <0: Other errors
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * import { FFmpegError } from 'node-av';
506
+ *
507
+ * const ret = swr.dropOutput(100);
508
+ * FFmpegError.throwIfError(ret, 'dropOutput');
509
+ * ```
510
+ *
511
+ * @see {@link injectSilence} For adding silence
512
+ * @see {@link nextPts} For automatic compensation
513
+ */
514
+ dropOutput(count: number): number;
515
+ /**
516
+ * Injects the specified number of silence samples.
517
+ *
518
+ * Inserts silent samples for "hard" timestamp compensation.
519
+ * Automatically called by nextPts() when needed.
520
+ *
521
+ * Direct mapping to swr_inject_silence()
522
+ *
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
529
+ *
530
+ * @example
531
+ * ```typescript
532
+ * import { FFmpegError } from 'node-av';
533
+ *
534
+ * const ret = swr.injectSilence(100);
535
+ * FFmpegError.throwIfError(ret, 'injectSilence');
536
+ * ```
537
+ *
538
+ * @see {@link dropOutput} For dropping samples
539
+ * @see {@link nextPts} For automatic compensation
540
+ */
541
+ injectSilence(count: number): number;
542
+ /**
543
+ * Get the native FFmpeg SwrContext pointer.
544
+ *
545
+ * @internal For use by other wrapper classes
546
+ * @returns The underlying native resample context object
547
+ */
548
+ getNative(): NativeSoftwareResampleContext;
549
+ /**
550
+ * Dispose of the resample context.
551
+ *
552
+ * Implements the Disposable interface for automatic cleanup.
553
+ * Equivalent to calling free().
554
+ *
555
+ * @example
556
+ * ```typescript
557
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
558
+ *
559
+ * {
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
566
+ * } // Automatically freed when leaving scope
567
+ * ```
568
+ *
569
+ * @see {@link free} For manual cleanup
570
+ */
571
+ [Symbol.dispose](): void;
572
+ }