@revizly/node-av 5.2.2-beta.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 (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,552 @@
1
+ import { OptionMember } from './option.js';
2
+ import type { AVSampleFormat } from '../constants/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
+ * Audio resampling and format conversion context.
8
+ *
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.
13
+ *
14
+ * Direct mapping to FFmpeg's SwrContext.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { SoftwareResampleContext, Frame, FFmpegError } from 'node-av';
19
+ * import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
20
+ *
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
31
+ * );
32
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
33
+ *
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();
44
+ *
45
+ * const ret3 = resampler.convertFrame(outFrame, inFrame);
46
+ * FFmpegError.throwIfError(ret3, 'convertFrame');
47
+ *
48
+ * // Get conversion delay
49
+ * const delay = resampler.getDelay(48000n);
50
+ * console.log(`Resampler delay: ${delay} samples`);
51
+ *
52
+ * // Clean up
53
+ * resampler.free();
54
+ * ```
55
+ *
56
+ * @see [SwrContext](https://ffmpeg.org/doxygen/trunk/structSwrContext.html) - FFmpeg Doxygen
57
+ * @see {@link Frame} For audio frame operations
58
+ */
59
+ export declare class SoftwareResampleContext extends OptionMember<NativeSoftwareResampleContext> implements Disposable, NativeWrapper<NativeSoftwareResampleContext> {
60
+ constructor();
61
+ /**
62
+ * Allocate resample context.
63
+ *
64
+ * Allocates memory for the resampler.
65
+ * Must be called before configuration.
66
+ *
67
+ * Direct mapping to swr_alloc().
68
+ *
69
+ * @example
70
+ * ```typescript
71
+ * const resampler = new SoftwareResampleContext();
72
+ * resampler.alloc();
73
+ * // Now configure with setOption() or allocSetOpts2()
74
+ * ```
75
+ *
76
+ * @see {@link allocSetOpts2} For combined allocation and configuration
77
+ */
78
+ alloc(): void;
79
+ /**
80
+ * Allocate and configure resampler.
81
+ *
82
+ * Combined allocation and configuration of the resampler with
83
+ * input and output format specifications.
84
+ *
85
+ * Direct mapping to swr_alloc_set_opts2().
86
+ *
87
+ * @param outChLayout - Output channel layout
88
+ *
89
+ * @param outSampleFmt - Output sample format
90
+ *
91
+ * @param outSampleRate - Output sample rate in Hz
92
+ *
93
+ * @param inChLayout - Input channel layout
94
+ *
95
+ * @param inSampleFmt - Input sample format
96
+ *
97
+ * @param inSampleRate - Input sample rate in Hz
98
+ *
99
+ * @returns 0 on success, negative AVERROR on error:
100
+ * - AVERROR_EINVAL: Invalid parameters
101
+ * - AVERROR_ENOMEM: Memory allocation failure
102
+ *
103
+ * @example
104
+ * ```typescript
105
+ * import { FFmpegError } from 'node-av';
106
+ * import { AV_SAMPLE_FMT_FLTP, AV_SAMPLE_FMT_S16 } from 'node-av/constants';
107
+ *
108
+ * // Stereo layout
109
+ * const stereo = { nbChannels: 2, order: 1, u: { mask: 3n } };
110
+ * // 5.1 layout
111
+ * const surround = { nbChannels: 6, order: 1, u: { mask: 63n } };
112
+ *
113
+ * // Convert 5.1 float to stereo 16-bit
114
+ * const ret = resampler.allocSetOpts2(
115
+ * stereo, AV_SAMPLE_FMT_S16, 48000,
116
+ * surround, AV_SAMPLE_FMT_FLTP, 48000
117
+ * );
118
+ * FFmpegError.throwIfError(ret, 'allocSetOpts2');
119
+ * ```
120
+ *
121
+ * @see {@link init} Must be called after configuration
122
+ */
123
+ allocSetOpts2(outChLayout: ChannelLayout, outSampleFmt: AVSampleFormat, outSampleRate: number, inChLayout: ChannelLayout, inSampleFmt: AVSampleFormat, inSampleRate: number): number;
124
+ /**
125
+ * Initialize resampler.
126
+ *
127
+ * Initializes the resampler after configuration.
128
+ * Must be called before any conversion operations.
129
+ *
130
+ * Direct mapping to swr_init().
131
+ *
132
+ * @returns 0 on success, negative AVERROR on error:
133
+ * - AVERROR_EINVAL: Invalid configuration
134
+ * - AVERROR_ENOMEM: Memory allocation failure
135
+ *
136
+ * @example
137
+ * ```typescript
138
+ * import { FFmpegError } from 'node-av';
139
+ *
140
+ * const ret = resampler.init();
141
+ * FFmpegError.throwIfError(ret, 'init');
142
+ * ```
143
+ *
144
+ * @see {@link allocSetOpts2} For configuration
145
+ * @see {@link isInitialized} To check initialization status
146
+ */
147
+ init(): number;
148
+ /**
149
+ * Free resampler context.
150
+ *
151
+ * Releases all resources associated with the resampler.
152
+ * The context becomes invalid after calling this.
153
+ *
154
+ * Direct mapping to swr_free().
155
+ *
156
+ * @example
157
+ * ```typescript
158
+ * resampler.free();
159
+ * // Resampler is now invalid
160
+ * ```
161
+ *
162
+ * @see {@link close} For closing without freeing
163
+ * @see {@link Symbol.dispose} For automatic cleanup
164
+ */
165
+ free(): void;
166
+ /**
167
+ * Close resampler context.
168
+ *
169
+ * Closes the resampler but keeps the context allocated.
170
+ * Can be reconfigured and reinitialized after closing.
171
+ *
172
+ * Direct mapping to swr_close().
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * resampler.close();
177
+ * // Can now reconfigure and reinit
178
+ * ```
179
+ *
180
+ * @see {@link free} For complete deallocation
181
+ */
182
+ close(): void;
183
+ /**
184
+ * Convert audio samples.
185
+ *
186
+ * Converts audio samples from input format to output format.
187
+ * Handles resampling, channel remapping, and format conversion.
188
+ *
189
+ * Direct mapping to swr_convert().
190
+ *
191
+ * @param outBuffer - Output sample buffers (one per channel for planar)
192
+ *
193
+ * @param outCount - Maximum output samples per channel
194
+ *
195
+ * @param inBuffer - Input sample buffers (one per channel for planar)
196
+ *
197
+ * @param inCount - Input samples per channel
198
+ *
199
+ * @returns Number of output samples per channel, negative AVERROR on error:
200
+ * - AVERROR_EINVAL: Invalid parameters
201
+ * - AVERROR_INPUT_CHANGED: Input format changed
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * import { FFmpegError } from 'node-av';
206
+ *
207
+ * // Convert audio buffers
208
+ * const outBuffers = [Buffer.alloc(4096), Buffer.alloc(4096)]; // Stereo
209
+ * const inBuffers = [inputBuffer]; // Mono
210
+ *
211
+ * const samples = await resampler.convert(
212
+ * outBuffers, 1024,
213
+ * inBuffers, inputSamples
214
+ * );
215
+ *
216
+ * if (samples < 0) {
217
+ * FFmpegError.throwIfError(samples, 'convert');
218
+ * }
219
+ * console.log(`Converted ${samples} samples`);
220
+ * ```
221
+ *
222
+ * @see {@link convertFrame} For frame-based conversion
223
+ */
224
+ convert(outBuffer: Buffer[] | null, outCount: number, inBuffer: Buffer[] | null, inCount: number): Promise<number>;
225
+ /**
226
+ * Convert audio samples synchronously.
227
+ * Synchronous version of convert.
228
+ *
229
+ * Converts audio between formats, sample rates, and channel layouts.
230
+ * Can handle format conversion, resampling, and channel mixing.
231
+ *
232
+ * Direct mapping to swr_convert().
233
+ *
234
+ * @param outBuffer - Output buffer array (one per channel, null to get delay)
235
+ *
236
+ * @param outCount - Number of output samples space per channel
237
+ *
238
+ * @param inBuffer - Input buffer array (one per channel, null to flush)
239
+ *
240
+ * @param inCount - Number of input samples per channel
241
+ *
242
+ * @returns Number of samples output per channel, or negative AVERROR:
243
+ * - AVERROR_EINVAL: Invalid parameters
244
+ * - AVERROR_ENOMEM: Memory allocation failure
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * import { FFmpegError } from 'node-av';
249
+ *
250
+ * // Convert stereo float to mono s16
251
+ * const inBuffers = [leftChannel, rightChannel];
252
+ * const outBuffers = [monoOutput];
253
+ *
254
+ * const samples = resampler.convertSync(
255
+ * outBuffers, 1024, // Output: 1024 samples max
256
+ * inBuffers, 1024 // Input: 1024 samples
257
+ * );
258
+ * FFmpegError.throwIfError(samples, 'convertSync');
259
+ * console.log(`Converted ${samples} samples`);
260
+ * ```
261
+ *
262
+ * @see {@link convert} For async version
263
+ */
264
+ convertSync(outBuffer: Buffer[] | null, outCount: number, inBuffer: Buffer[] | null, inCount: number): number;
265
+ /**
266
+ * Convert audio frame.
267
+ *
268
+ * Converts an entire audio frame to the output format.
269
+ * Simpler interface than convert() for frame-based processing.
270
+ *
271
+ * Direct mapping to swr_convert_frame().
272
+ *
273
+ * @param outFrame - Output frame (null to drain)
274
+ *
275
+ * @param inFrame - Input frame (null to flush)
276
+ *
277
+ * @returns 0 on success, negative AVERROR on error:
278
+ * - AVERROR_EINVAL: Invalid parameters
279
+ * - AVERROR_ENOMEM: Memory allocation failure
280
+ * - AVERROR_INPUT_CHANGED: Input format changed
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * import { Frame, FFmpegError } from 'node-av';
285
+ *
286
+ * // Convert frame
287
+ * const outFrame = new Frame();
288
+ * const ret = resampler.convertFrame(outFrame, inFrame);
289
+ * FFmpegError.throwIfError(ret, 'convertFrame');
290
+ *
291
+ * // Drain remaining samples
292
+ * const drainFrame = new Frame();
293
+ * const ret2 = resampler.convertFrame(drainFrame, null);
294
+ * if (ret2 === 0) {
295
+ * // Got drained samples
296
+ * }
297
+ * ```
298
+ *
299
+ * @see {@link convert} For buffer-based conversion
300
+ * @see {@link configFrame} To configure from frame
301
+ */
302
+ convertFrame(outFrame: Frame | null, inFrame: Frame | null): number;
303
+ /**
304
+ * Configure resampler from frames.
305
+ *
306
+ * Configures the resampler using format information from frames.
307
+ * Alternative to allocSetOpts2() for frame-based setup.
308
+ *
309
+ * Direct mapping to swr_config_frame().
310
+ *
311
+ * @param outFrame - Frame with output format
312
+ *
313
+ * @param inFrame - Frame with input format
314
+ *
315
+ * @returns 0 on success, negative AVERROR on error:
316
+ * - AVERROR_EINVAL: Invalid parameters
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * import { FFmpegError } from 'node-av';
321
+ *
322
+ * // Configure from frames
323
+ * const ret = resampler.configFrame(outFrame, inFrame);
324
+ * FFmpegError.throwIfError(ret, 'configFrame');
325
+ *
326
+ * const ret2 = resampler.init();
327
+ * FFmpegError.throwIfError(ret2, 'init');
328
+ * ```
329
+ *
330
+ * @see {@link allocSetOpts2} For manual configuration
331
+ */
332
+ configFrame(outFrame: Frame | null, inFrame: Frame | null): number;
333
+ /**
334
+ * Check if initialized.
335
+ *
336
+ * Returns whether the resampler has been initialized.
337
+ *
338
+ * Direct mapping to swr_is_initialized().
339
+ *
340
+ * @returns True if initialized, false otherwise
341
+ *
342
+ * @example
343
+ * ```typescript
344
+ * if (!resampler.isInitialized()) {
345
+ * resampler.init();
346
+ * }
347
+ * ```
348
+ *
349
+ * @see {@link init} To initialize
350
+ */
351
+ isInitialized(): boolean;
352
+ /**
353
+ * Get resampler delay.
354
+ *
355
+ * Returns the number of samples currently buffered in the resampler.
356
+ * These samples will be output when flushing or with new input.
357
+ *
358
+ * Direct mapping to swr_get_delay().
359
+ *
360
+ * @param base - Time base for the returned delay
361
+ *
362
+ * @returns Delay in samples at the given base rate
363
+ *
364
+ * @example
365
+ * ```typescript
366
+ * // Get delay in output sample rate
367
+ * const delay = resampler.getDelay(48000n);
368
+ * console.log(`${delay} samples buffered`);
369
+ *
370
+ * // Get delay in microseconds
371
+ * const delayUs = resampler.getDelay(1000000n);
372
+ * console.log(`${delayUs} microseconds delay`);
373
+ * ```
374
+ */
375
+ getDelay(base: bigint): bigint;
376
+ /**
377
+ * Calculate output sample count.
378
+ *
379
+ * Calculates how many output samples will be produced
380
+ * for a given number of input samples.
381
+ *
382
+ * Direct mapping to swr_get_out_samples().
383
+ *
384
+ * @param inSamples - Number of input samples
385
+ *
386
+ * @returns Number of output samples
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * const outSamples = resampler.getOutSamples(1024);
391
+ * console.log(`1024 input samples -> ${outSamples} output samples`);
392
+ * ```
393
+ */
394
+ getOutSamples(inSamples: number): number;
395
+ /**
396
+ * Calculate next PTS.
397
+ *
398
+ * Calculates the presentation timestamp for the next output sample.
399
+ *
400
+ * Direct mapping to swr_next_pts().
401
+ *
402
+ * @param pts - Current presentation timestamp
403
+ *
404
+ * @returns Next presentation timestamp
405
+ *
406
+ * @example
407
+ * ```typescript
408
+ * let pts = 0n;
409
+ * pts = resampler.nextPts(pts);
410
+ * console.log(`Next PTS: ${pts}`);
411
+ * ```
412
+ */
413
+ nextPts(pts: bigint): bigint;
414
+ /**
415
+ * Set compensation.
416
+ *
417
+ * Adjusts the resampling rate to compensate for clock drift.
418
+ * Used for audio/video synchronization.
419
+ *
420
+ * Direct mapping to swr_set_compensation().
421
+ *
422
+ * @param sampleDelta - Sample difference to compensate
423
+ *
424
+ * @param compensationDistance - Distance over which to compensate
425
+ *
426
+ * @returns 0 on success, negative AVERROR on error:
427
+ * - AVERROR_EINVAL: Invalid parameters
428
+ *
429
+ * @example
430
+ * ```typescript
431
+ * import { FFmpegError } from 'node-av';
432
+ *
433
+ * // Compensate 10 samples over 1000 samples
434
+ * const ret = resampler.setCompensation(10, 1000);
435
+ * FFmpegError.throwIfError(ret, 'setCompensation');
436
+ * ```
437
+ */
438
+ setCompensation(sampleDelta: number, compensationDistance: number): number;
439
+ /**
440
+ * Set channel mapping.
441
+ *
442
+ * Sets custom channel mapping for remixing.
443
+ *
444
+ * Direct mapping to swr_set_channel_mapping().
445
+ *
446
+ * @param channelMap - Array mapping input to output channels
447
+ *
448
+ * @returns 0 on success, negative AVERROR on error
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * // Map stereo to reverse stereo (swap L/R)
453
+ * const ret = resampler.setChannelMapping([1, 0]);
454
+ * FFmpegError.throwIfError(ret, 'setChannelMapping');
455
+ * ```
456
+ */
457
+ setChannelMapping(channelMap: number[]): number;
458
+ /**
459
+ * Set mixing matrix.
460
+ *
461
+ * Sets a custom mixing matrix for channel remapping.
462
+ *
463
+ * Direct mapping to swr_set_matrix().
464
+ *
465
+ * @param matrix - Mixing matrix coefficients
466
+ *
467
+ * @param stride - Matrix row stride
468
+ *
469
+ * @returns 0 on success, negative AVERROR on error
470
+ *
471
+ * @example
472
+ * ```typescript
473
+ * // Custom downmix matrix
474
+ * const matrix = [
475
+ * 1.0, 0.0, // Left channel
476
+ * 0.0, 1.0, // Right channel
477
+ * ];
478
+ * const ret = resampler.setMatrix(matrix, 2);
479
+ * FFmpegError.throwIfError(ret, 'setMatrix');
480
+ * ```
481
+ */
482
+ setMatrix(matrix: number[], stride: number): number;
483
+ /**
484
+ * Drop output samples.
485
+ *
486
+ * Drops the specified number of output samples.
487
+ * Used for synchronization adjustments.
488
+ *
489
+ * Direct mapping to swr_drop_output().
490
+ *
491
+ * @param count - Number of samples to drop
492
+ *
493
+ * @returns 0 on success, negative AVERROR on error
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * // Drop 100 output samples
498
+ * const ret = resampler.dropOutput(100);
499
+ * if (ret >= 0) {
500
+ * console.log(`Dropped ${ret} samples`);
501
+ * }
502
+ * ```
503
+ */
504
+ dropOutput(count: number): number;
505
+ /**
506
+ * Inject silence.
507
+ *
508
+ * Injects silent samples into the output.
509
+ * Used for padding or synchronization.
510
+ *
511
+ * Direct mapping to swr_inject_silence().
512
+ *
513
+ * @param count - Number of silent samples to inject
514
+ *
515
+ * @returns 0 on success, negative AVERROR on error
516
+ *
517
+ * @example
518
+ * ```typescript
519
+ * // Inject 100 silent samples
520
+ * const ret = resampler.injectSilence(100);
521
+ * if (ret >= 0) {
522
+ * console.log(`Injected ${ret} silent samples`);
523
+ * }
524
+ * ```
525
+ */
526
+ injectSilence(count: number): number;
527
+ /**
528
+ * Get the underlying native SoftwareResampleContext object.
529
+ *
530
+ * @returns The native SoftwareResampleContext binding object
531
+ *
532
+ * @internal
533
+ */
534
+ getNative(): NativeSoftwareResampleContext;
535
+ /**
536
+ * Dispose of the resampler context.
537
+ *
538
+ * Implements the Disposable interface for automatic cleanup.
539
+ * Equivalent to calling free().
540
+ *
541
+ * @example
542
+ * ```typescript
543
+ * {
544
+ * using resampler = new SoftwareResampleContext();
545
+ * resampler.allocSetOpts2(...);
546
+ * resampler.init();
547
+ * // Use resampler...
548
+ * } // Automatically freed when leaving scope
549
+ * ```
550
+ */
551
+ [Symbol.dispose](): void;
552
+ }