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,610 @@
1
+ import { bindings } from './binding.js';
2
+ import { OptionMember } from './option.js';
3
+ /**
4
+ * Software audio resampling context.
5
+ *
6
+ * Provides high-quality audio resampling, format conversion, and channel mixing.
7
+ * Supports sample rate conversion, channel layout remapping, and sample format conversion.
8
+ * Uses the libswresample library for efficient audio processing.
9
+ *
10
+ * Direct mapping to FFmpeg's SwrContext.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
15
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
16
+ *
17
+ * // Create and configure resample context
18
+ * const swr = new SoftwareResampleContext();
19
+ * const ret = swr.allocSetOpts2(
20
+ * { order: 0, nbChannels: 2, mask: 0x3 }, // stereo out
21
+ * AV_SAMPLE_FMT_S16,
22
+ * 44100,
23
+ * { order: 0, nbChannels: 6, mask: 0x3f }, // 5.1 in
24
+ * AV_SAMPLE_FMT_FLTP,
25
+ * 48000
26
+ * );
27
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
28
+ *
29
+ * // Initialize
30
+ * const initRet = swr.init();
31
+ * FFmpegError.throwIfError(initRet, 'init');
32
+ *
33
+ * // Convert audio
34
+ * const samplesOut = await swr.convert(outBuffers, outSamples, inBuffers, inSamples);
35
+ * FFmpegError.throwIfError(samplesOut, 'convert');
36
+ *
37
+ * // Cleanup
38
+ * swr.free();
39
+ * ```
40
+ */
41
+ export class SoftwareResampleContext extends OptionMember {
42
+ /**
43
+ * Create a new software resample context.
44
+ *
45
+ * The context is uninitialized - you must call alloc() or allocSetOpts2() before use.
46
+ * No FFmpeg resources are allocated until initialization.
47
+ *
48
+ * Direct wrapper around SwrContext.
49
+ *
50
+ * @example
51
+ * ```typescript
52
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
53
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
54
+ *
55
+ * const swr = new SoftwareResampleContext();
56
+ * const ret = swr.allocSetOpts2(
57
+ * { order: 0, nbChannels: 2, mask: 0x3 },
58
+ * AV_SAMPLE_FMT_S16,
59
+ * 44100,
60
+ * { order: 0, nbChannels: 6, mask: 0x3f },
61
+ * AV_SAMPLE_FMT_FLTP,
62
+ * 48000
63
+ * );
64
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
65
+ * const initRet = swr.init();
66
+ * FFmpegError.throwIfError(initRet, 'init');
67
+ * ```
68
+ */
69
+ constructor() {
70
+ super(new bindings.SoftwareResampleContext());
71
+ }
72
+ /**
73
+ * Allocate SwrContext.
74
+ *
75
+ * Allocates an uninitialized resample context.
76
+ * Options must be set through the AVOptions API before calling init().
77
+ *
78
+ * Direct mapping to swr_alloc()
79
+ *
80
+ * @throws {Error} Memory allocation failure (ENOMEM)
81
+ *
82
+ * @example
83
+ * ```typescript
84
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
85
+ *
86
+ * const swr = new SoftwareResampleContext();
87
+ * swr.alloc();
88
+ * // Set options via AVOptions API
89
+ * const ret = swr.init();
90
+ * FFmpegError.throwIfError(ret, 'init');
91
+ * ```
92
+ *
93
+ * @see {@link allocSetOpts2} For one-step configuration
94
+ * @see {@link init} To initialize after configuration
95
+ */
96
+ alloc() {
97
+ this.native.alloc();
98
+ }
99
+ /**
100
+ * Allocate SwrContext if needed and set/reset common parameters.
101
+ *
102
+ * One-step allocation and configuration of the resample context.
103
+ * Automatically allocates the context if not already allocated.
104
+ *
105
+ * Direct mapping to swr_alloc_set_opts2()
106
+ *
107
+ * @param outChLayout - Output channel layout
108
+ * @param outSampleFmt - Output sample format
109
+ * @param outSampleRate - Output sample rate (frequency in Hz)
110
+ * @param inChLayout - Input channel layout
111
+ * @param inSampleFmt - Input sample format
112
+ * @param inSampleRate - Input sample rate (frequency in Hz)
113
+ *
114
+ * @returns 0 on success, negative AVERROR on error:
115
+ * - 0: Success
116
+ * - AVERROR(EINVAL): Invalid parameters
117
+ * - AVERROR(ENOMEM): Memory allocation failure
118
+ *
119
+ * @example
120
+ * ```typescript
121
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
122
+ * import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
123
+ *
124
+ * const ret = swr.allocSetOpts2(
125
+ * { order: 0, nbChannels: 2, mask: 0x3 }, // stereo
126
+ * AV_SAMPLE_FMT_S16,
127
+ * 44100,
128
+ * { order: 0, nbChannels: 6, mask: 0x3f }, // 5.1
129
+ * AV_SAMPLE_FMT_FLTP,
130
+ * 48000
131
+ * );
132
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
133
+ * ```
134
+ *
135
+ * @see {@link init} To initialize after configuration
136
+ */
137
+ allocSetOpts2(outChLayout, outSampleFmt, outSampleRate, inChLayout, inSampleFmt, inSampleRate) {
138
+ return this.native.allocSetOpts2(outChLayout, outSampleFmt, outSampleRate, inChLayout, inSampleFmt, inSampleRate);
139
+ }
140
+ /**
141
+ * Initialize context after user parameters have been set.
142
+ *
143
+ * Completes initialization of the resample context.
144
+ * Must be called after configuration and before conversion.
145
+ *
146
+ * Direct mapping to swr_init()
147
+ *
148
+ * @returns 0 on success, negative AVERROR on error:
149
+ * - 0: Success
150
+ * - AVERROR(EINVAL): Invalid parameters
151
+ * - <0: Other errors
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * import { FFmpegError } from 'node-av';
156
+ *
157
+ * const ret = swr.init();
158
+ * FFmpegError.throwIfError(ret, 'init');
159
+ * ```
160
+ *
161
+ * @see {@link allocSetOpts2} For configuration
162
+ * @see {@link convert} For audio conversion
163
+ */
164
+ init() {
165
+ return this.native.init();
166
+ }
167
+ /**
168
+ * Free the given SwrContext and set the pointer to NULL.
169
+ *
170
+ * Direct mapping to swr_free()
171
+ *
172
+ * @example
173
+ * ```typescript
174
+ * swr.free();
175
+ * // swr is now invalid and should not be used
176
+ * ```
177
+ */
178
+ free() {
179
+ this.native.free();
180
+ }
181
+ /**
182
+ * Closes the context so that swr_is_initialized() returns 0.
183
+ *
184
+ * Direct mapping to swr_close()
185
+ *
186
+ * The context can be brought back to life by running swr_init(),
187
+ * swr_init() can also be used without swr_close().
188
+ * This function is mainly provided for simplifying the usecase
189
+ * where one tries to support libavresample and libswresample.
190
+ *
191
+ * @example
192
+ * ```typescript
193
+ * swr.close();
194
+ * // Context is now closed but not freed
195
+ * // Can be reinitialized with swr.init()
196
+ * ```
197
+ */
198
+ close() {
199
+ this.native.close();
200
+ }
201
+ /**
202
+ * Convert audio.
203
+ *
204
+ * Converts audio between different formats, sample rates, and channel layouts.
205
+ * Handles buffering internally when output space is insufficient.
206
+ *
207
+ * Direct mapping to swr_convert()
208
+ *
209
+ * @param outBuffer - Output buffers, only the first one need be set in case of packed audio
210
+ * @param outCount - Amount of space available for output in samples per channel
211
+ * @param inBuffer - Input buffers, only the first one need be set in case of packed audio
212
+ * @param inCount - Number of input samples available in one channel
213
+ *
214
+ * @returns Number of samples output per channel, negative AVERROR on error:
215
+ * - >=0: Number of samples output per channel
216
+ * - AVERROR(EINVAL): Invalid parameters
217
+ * - <0: Other errors
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * import { FFmpegError } from 'node-av';
222
+ *
223
+ * const samplesOut = await swr.convert(
224
+ * outBuffers,
225
+ * outSamples,
226
+ * inBuffers,
227
+ * inSamples
228
+ * );
229
+ * FFmpegError.throwIfError(samplesOut, 'convert');
230
+ * console.log(`Converted ${samplesOut} samples per channel`);
231
+ * ```
232
+ *
233
+ * @see {@link getOutSamples} To calculate required output space
234
+ * @see {@link convertFrame} For frame-based conversion
235
+ *
236
+ * @note If more input is provided than output space, then the input will be buffered.
237
+ * You can avoid this buffering by using swr_get_out_samples() to retrieve an
238
+ * upper bound on the required number of output samples for the given number of
239
+ * input samples. Conversion will run directly without copying whenever possible.
240
+ */
241
+ async convert(outBuffer, outCount, inBuffer, inCount) {
242
+ return this.native.convert(outBuffer, outCount, inBuffer, inCount);
243
+ }
244
+ /**
245
+ * Convert the samples in the input AVFrame and write them to the output AVFrame.
246
+ *
247
+ * Frame-based audio conversion with automatic buffer management.
248
+ * Handles format, sample rate, and channel layout conversion.
249
+ *
250
+ * Direct mapping to swr_convert_frame()
251
+ *
252
+ * @param outFrame - Output AVFrame (can be null for flushing)
253
+ * @param inFrame - Input AVFrame (can be null for draining)
254
+ *
255
+ * @returns 0 on success, negative AVERROR on error:
256
+ * - 0: Success
257
+ * - AVERROR(EINVAL): Invalid frame parameters
258
+ * - AVERROR(EAGAIN): Need more input or output
259
+ * - <0: Other errors
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * import { Frame, FFmpegError } from 'node-av';
264
+ *
265
+ * const ret = swr.convertFrame(outFrame, inFrame);
266
+ * FFmpegError.throwIfError(ret, 'convertFrame');
267
+ *
268
+ * // Flush remaining samples
269
+ * const flushRet = swr.convertFrame(outFrame, null);
270
+ * FFmpegError.throwIfError(flushRet, 'flush');
271
+ * ```
272
+ *
273
+ * @see {@link convert} For buffer-based conversion
274
+ * @see {@link getDelay} To check buffered samples
275
+ *
276
+ * @note Input and output AVFrames must have channel_layout, sample_rate and format set.
277
+ * If the output AVFrame does not have the data pointers allocated the nb_samples
278
+ * field will be set and av_frame_get_buffer() is called to allocate the frame.
279
+ */
280
+ convertFrame(outFrame, inFrame) {
281
+ return this.native.convertFrame(outFrame?.getNative() ?? null, inFrame?.getNative() ?? null);
282
+ }
283
+ /**
284
+ * Configure or reconfigure the SwrContext using the information provided by the AVFrames.
285
+ *
286
+ * Automatically configures the resample context from frame parameters.
287
+ * Resets the context even on failure and calls close() internally if open.
288
+ *
289
+ * Direct mapping to swr_config_frame()
290
+ *
291
+ * @param outFrame - Output AVFrame (provides output parameters)
292
+ * @param inFrame - Input AVFrame (provides input parameters)
293
+ *
294
+ * @returns 0 on success, negative AVERROR on error:
295
+ * - 0: Success
296
+ * - AVERROR(EINVAL): Invalid frame parameters
297
+ * - AVERROR(ENOMEM): Memory allocation failure
298
+ * - <0: Other errors
299
+ *
300
+ * @example
301
+ * ```typescript
302
+ * import { FFmpegError } from 'node-av';
303
+ *
304
+ * const ret = swr.configFrame(outFrame, inFrame);
305
+ * FFmpegError.throwIfError(ret, 'configFrame');
306
+ * const initRet = swr.init();
307
+ * FFmpegError.throwIfError(initRet, 'init');
308
+ * ```
309
+ *
310
+ * @see {@link init} Must be called after configuration
311
+ */
312
+ configFrame(outFrame, inFrame) {
313
+ return this.native.configFrame(outFrame?.getNative() ?? null, inFrame?.getNative() ?? null);
314
+ }
315
+ /**
316
+ * Check whether an swr context has been initialized or not.
317
+ *
318
+ * Checks if the context is ready for audio conversion.
319
+ *
320
+ * Direct mapping to swr_is_initialized()
321
+ *
322
+ * @returns True if initialized, false otherwise
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * import { FFmpegError } from 'node-av';
327
+ *
328
+ * if (swr.isInitialized()) {
329
+ * // Context is ready for conversion
330
+ * const ret = await swr.convert(outBuf, outCount, inBuf, inCount);
331
+ * FFmpegError.throwIfError(ret, 'convert');
332
+ * }
333
+ * ```
334
+ */
335
+ isInitialized() {
336
+ return this.native.isInitialized();
337
+ }
338
+ /**
339
+ * Gets the delay the next input sample will experience relative to the next output sample.
340
+ *
341
+ * Returns the total buffering delay in the resample context.
342
+ * Accounts for both buffered data and sample rate conversion delays.
343
+ *
344
+ * Direct mapping to swr_get_delay()
345
+ *
346
+ * @param base - Timebase in which the returned delay will be:
347
+ * - 1: delay in seconds
348
+ * - 1000: delay in milliseconds
349
+ * - input sample rate: delay in input samples
350
+ * - output sample rate: delay in output samples
351
+ * - LCM of rates: exact rounding-free delay
352
+ *
353
+ * @returns The delay in 1 / base units
354
+ *
355
+ * @example
356
+ * ```typescript
357
+ * // Get delay in milliseconds
358
+ * const delayMs = swr.getDelay(1000n);
359
+ * console.log(`Buffered: ${delayMs}ms`);
360
+ *
361
+ * // Get delay in output samples
362
+ * const delaySamples = swr.getDelay(BigInt(outputSampleRate));
363
+ * console.log(`Buffered: ${delaySamples} samples`);
364
+ * ```
365
+ *
366
+ * @see {@link getOutSamples} To calculate output buffer size
367
+ */
368
+ getDelay(base) {
369
+ return this.native.getDelay(base);
370
+ }
371
+ /**
372
+ * Find an upper bound on the number of samples that the next swr_convert will output.
373
+ *
374
+ * Calculates maximum output samples for given input samples.
375
+ * Accounts for buffered data and sample rate conversion.
376
+ *
377
+ * Direct mapping to swr_get_out_samples()
378
+ *
379
+ * @param inSamples - Number of input samples
380
+ *
381
+ * @returns Upper bound on output samples or negative AVERROR:
382
+ * - >=0: Upper bound on the number of samples that the next swr_convert will output
383
+ * - AVERROR(EINVAL): Invalid parameters
384
+ * - <0: Other errors
385
+ *
386
+ * @example
387
+ * ```typescript
388
+ * import { FFmpegError } from 'node-av';
389
+ *
390
+ * const outSamples = swr.getOutSamples(inSamples);
391
+ * FFmpegError.throwIfError(outSamples, 'getOutSamples');
392
+ * // Allocate output buffer for outSamples samples
393
+ * const bufferSize = outSamples * bytesPerSample * channels;
394
+ * ```
395
+ *
396
+ * @see {@link convert} For actual conversion
397
+ *
398
+ * @note This depends on the internal state, and anything changing the internal state
399
+ * (like further swr_convert() calls) may change the number of samples returned.
400
+ */
401
+ getOutSamples(inSamples) {
402
+ return this.native.getOutSamples(inSamples);
403
+ }
404
+ /**
405
+ * Convert the next timestamp from input to output.
406
+ *
407
+ * Converts timestamps accounting for sample rate conversion.
408
+ * Timestamps are in 1/(in_sample_rate * out_sample_rate) units.
409
+ *
410
+ * Direct mapping to swr_next_pts()
411
+ *
412
+ * @param pts - Timestamp for the next input sample, INT64_MIN if unknown
413
+ *
414
+ * @returns The output timestamp for the next output sample
415
+ *
416
+ * @example
417
+ * ```typescript
418
+ * const outPts = swr.nextPts(inPts);
419
+ * outFrame.pts = outPts;
420
+ * ```
421
+ *
422
+ * @see {@link setCompensation} For timestamp compensation
423
+ */
424
+ nextPts(pts) {
425
+ return this.native.nextPts(pts);
426
+ }
427
+ /**
428
+ * Activate resampling compensation ("soft" compensation).
429
+ *
430
+ * Adjusts resampling to compensate for timestamp drift.
431
+ * Automatically called by nextPts() when needed.
432
+ *
433
+ * Direct mapping to swr_set_compensation()
434
+ *
435
+ * @param sampleDelta - Delta in PTS per sample
436
+ * @param compensationDistance - Number of samples to compensate for
437
+ *
438
+ * @returns 0 on success, negative AVERROR on error:
439
+ * - 0: Success
440
+ * - AVERROR(EINVAL): Invalid parameters (NULL context, negative distance, etc.)
441
+ * - AVERROR(ENOSYS): Compensation unsupported by resampler
442
+ * - <0: Other errors
443
+ *
444
+ * @example
445
+ * ```typescript
446
+ * import { FFmpegError } from 'node-av';
447
+ *
448
+ * const ret = swr.setCompensation(delta, distance);
449
+ * FFmpegError.throwIfError(ret, 'setCompensation');
450
+ * ```
451
+ *
452
+ * @see {@link nextPts} For automatic compensation
453
+ */
454
+ setCompensation(sampleDelta, compensationDistance) {
455
+ return this.native.setCompensation(sampleDelta, compensationDistance);
456
+ }
457
+ /**
458
+ * Set a customized input channel mapping.
459
+ *
460
+ * Remaps input channels to output channels.
461
+ * Use -1 to mute a channel.
462
+ *
463
+ * Direct mapping to swr_set_channel_mapping()
464
+ *
465
+ * @param channelMap - Customized input channel mapping (array of channel indexes, -1 for a muted channel)
466
+ *
467
+ * @returns 0 on success, negative AVERROR on error:
468
+ * - 0: Success
469
+ * - AVERROR(EINVAL): Invalid parameters
470
+ * - <0: Other errors
471
+ *
472
+ * @example
473
+ * ```typescript
474
+ * import { FFmpegError } from 'node-av';
475
+ *
476
+ * // Map channels: 0->0, 1->1, mute channel 2
477
+ * const ret = swr.setChannelMapping([0, 1, -1]);
478
+ * FFmpegError.throwIfError(ret, 'setChannelMapping');
479
+ * ```
480
+ *
481
+ * @see {@link setMatrix} For custom mixing matrix
482
+ */
483
+ setChannelMapping(channelMap) {
484
+ return this.native.setChannelMapping(channelMap);
485
+ }
486
+ /**
487
+ * Set a customized remix matrix.
488
+ *
489
+ * Sets custom coefficients for channel mixing.
490
+ * matrix[i + stride * o] is the weight of input channel i in output channel o.
491
+ *
492
+ * Direct mapping to swr_set_matrix()
493
+ *
494
+ * @param matrix - Remix coefficients
495
+ * @param stride - Offset between lines of the matrix
496
+ *
497
+ * @returns 0 on success, negative AVERROR on error:
498
+ * - 0: Success
499
+ * - AVERROR(EINVAL): Invalid parameters
500
+ * - <0: Other errors
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * import { FFmpegError } from 'node-av';
505
+ *
506
+ * // Set custom mix matrix for stereo to mono
507
+ * const matrix = [0.5, 0.5]; // Mix both channels equally
508
+ * const ret = swr.setMatrix(matrix, 1);
509
+ * FFmpegError.throwIfError(ret, 'setMatrix');
510
+ * ```
511
+ *
512
+ * @see {@link setChannelMapping} For channel remapping
513
+ */
514
+ setMatrix(matrix, stride) {
515
+ return this.native.setMatrix(matrix, stride);
516
+ }
517
+ /**
518
+ * Drops the specified number of output samples.
519
+ *
520
+ * Discards output samples for "hard" timestamp compensation.
521
+ * Automatically called by nextPts() when needed.
522
+ *
523
+ * Direct mapping to swr_drop_output()
524
+ *
525
+ * @param count - Number of samples to be dropped
526
+ *
527
+ * @returns 0 on success, negative AVERROR on error:
528
+ * - 0: Success
529
+ * - AVERROR(EINVAL): Invalid parameters
530
+ * - <0: Other errors
531
+ *
532
+ * @example
533
+ * ```typescript
534
+ * import { FFmpegError } from 'node-av';
535
+ *
536
+ * const ret = swr.dropOutput(100);
537
+ * FFmpegError.throwIfError(ret, 'dropOutput');
538
+ * ```
539
+ *
540
+ * @see {@link injectSilence} For adding silence
541
+ * @see {@link nextPts} For automatic compensation
542
+ */
543
+ dropOutput(count) {
544
+ return this.native.dropOutput(count);
545
+ }
546
+ /**
547
+ * Injects the specified number of silence samples.
548
+ *
549
+ * Inserts silent samples for "hard" timestamp compensation.
550
+ * Automatically called by nextPts() when needed.
551
+ *
552
+ * Direct mapping to swr_inject_silence()
553
+ *
554
+ * @param count - Number of samples to be injected
555
+ *
556
+ * @returns 0 on success, negative AVERROR on error:
557
+ * - 0: Success
558
+ * - AVERROR(EINVAL): Invalid parameters
559
+ * - <0: Other errors
560
+ *
561
+ * @example
562
+ * ```typescript
563
+ * import { FFmpegError } from 'node-av';
564
+ *
565
+ * const ret = swr.injectSilence(100);
566
+ * FFmpegError.throwIfError(ret, 'injectSilence');
567
+ * ```
568
+ *
569
+ * @see {@link dropOutput} For dropping samples
570
+ * @see {@link nextPts} For automatic compensation
571
+ */
572
+ injectSilence(count) {
573
+ return this.native.injectSilence(count);
574
+ }
575
+ /**
576
+ * Get the native FFmpeg SwrContext pointer.
577
+ *
578
+ * @internal For use by other wrapper classes
579
+ * @returns The underlying native resample context object
580
+ */
581
+ getNative() {
582
+ return this.native;
583
+ }
584
+ /**
585
+ * Dispose of the resample context.
586
+ *
587
+ * Implements the Disposable interface for automatic cleanup.
588
+ * Equivalent to calling free().
589
+ *
590
+ * @example
591
+ * ```typescript
592
+ * import { SoftwareResampleContext, FFmpegError } from 'node-av';
593
+ *
594
+ * {
595
+ * using swr = new SoftwareResampleContext();
596
+ * const ret = swr.allocSetOpts2(...);
597
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
598
+ * const initRet = swr.init();
599
+ * FFmpegError.throwIfError(initRet, 'init');
600
+ * // ... use context
601
+ * } // Automatically freed when leaving scope
602
+ * ```
603
+ *
604
+ * @see {@link free} For manual cleanup
605
+ */
606
+ [Symbol.dispose]() {
607
+ this.native[Symbol.dispose]();
608
+ }
609
+ }
610
+ //# sourceMappingURL=software-resample-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"software-resample-context.js","sourceRoot":"","sources":["../../src/lib/software-resample-context.ts"],"names":[],"mappings":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