node-av-lgpl 0.0.0 → 7.1.0-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 (311) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +711 -0
  3. package/dist/api/audio-frame-buffer.d.ts +636 -0
  4. package/dist/api/audio-frame-buffer.js +1027 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +938 -0
  7. package/dist/api/bitstream-filter.js +1427 -0
  8. package/dist/api/bitstream-filter.js.map +1 -0
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_h264.h264 +0 -0
  14. package/dist/api/data/test_hevc.h265 +0 -0
  15. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  16. package/dist/api/data/test_vp8.ivf +0 -0
  17. package/dist/api/data/test_vp9.ivf +0 -0
  18. package/dist/api/decoder.d.ts +1413 -0
  19. package/dist/api/decoder.js +2367 -0
  20. package/dist/api/decoder.js.map +1 -0
  21. package/dist/api/demuxer.d.ts +1295 -0
  22. package/dist/api/demuxer.js +2344 -0
  23. package/dist/api/demuxer.js.map +1 -0
  24. package/dist/api/device.d.ts +589 -0
  25. package/dist/api/device.js +964 -0
  26. package/dist/api/device.js.map +1 -0
  27. package/dist/api/encoder-pool.d.ts +262 -0
  28. package/dist/api/encoder-pool.js +397 -0
  29. package/dist/api/encoder-pool.js.map +1 -0
  30. package/dist/api/encoder.d.ts +1509 -0
  31. package/dist/api/encoder.js +2619 -0
  32. package/dist/api/encoder.js.map +1 -0
  33. package/dist/api/filter-complex.d.ts +828 -0
  34. package/dist/api/filter-complex.js +1661 -0
  35. package/dist/api/filter-complex.js.map +1 -0
  36. package/dist/api/filter-presets.d.ts +800 -0
  37. package/dist/api/filter-presets.js +1554 -0
  38. package/dist/api/filter-presets.js.map +1 -0
  39. package/dist/api/filter.d.ts +1339 -0
  40. package/dist/api/filter.js +2075 -0
  41. package/dist/api/filter.js.map +1 -0
  42. package/dist/api/fmp4-stream.d.ts +797 -0
  43. package/dist/api/fmp4-stream.js +1428 -0
  44. package/dist/api/fmp4-stream.js.map +1 -0
  45. package/dist/api/hardware.d.ts +677 -0
  46. package/dist/api/hardware.js +1300 -0
  47. package/dist/api/hardware.js.map +1 -0
  48. package/dist/api/index.d.ts +21 -0
  49. package/dist/api/index.js +38 -0
  50. package/dist/api/index.js.map +1 -0
  51. package/dist/api/io-stream.d.ts +308 -0
  52. package/dist/api/io-stream.js +358 -0
  53. package/dist/api/io-stream.js.map +1 -0
  54. package/dist/api/muxer.d.ts +1311 -0
  55. package/dist/api/muxer.js +2672 -0
  56. package/dist/api/muxer.js.map +1 -0
  57. package/dist/api/pipeline.d.ts +801 -0
  58. package/dist/api/pipeline.js +1344 -0
  59. package/dist/api/pipeline.js.map +1 -0
  60. package/dist/api/probe.d.ts +128 -0
  61. package/dist/api/probe.js +227 -0
  62. package/dist/api/probe.js.map +1 -0
  63. package/dist/api/rtp-stream.d.ts +497 -0
  64. package/dist/api/rtp-stream.js +1131 -0
  65. package/dist/api/rtp-stream.js.map +1 -0
  66. package/dist/api/scaler.d.ts +561 -0
  67. package/dist/api/scaler.js +918 -0
  68. package/dist/api/scaler.js.map +1 -0
  69. package/dist/api/types.d.ts +17 -0
  70. package/dist/api/types.js +2 -0
  71. package/dist/api/types.js.map +1 -0
  72. package/dist/api/utilities/async-queue.d.ts +149 -0
  73. package/dist/api/utilities/async-queue.js +254 -0
  74. package/dist/api/utilities/async-queue.js.map +1 -0
  75. package/dist/api/utilities/audio-sample.d.ts +117 -0
  76. package/dist/api/utilities/audio-sample.js +112 -0
  77. package/dist/api/utilities/audio-sample.js.map +1 -0
  78. package/dist/api/utilities/audio-transcode.d.ts +20 -0
  79. package/dist/api/utilities/audio-transcode.js +27 -0
  80. package/dist/api/utilities/audio-transcode.js.map +1 -0
  81. package/dist/api/utilities/channel-layout.d.ts +76 -0
  82. package/dist/api/utilities/channel-layout.js +80 -0
  83. package/dist/api/utilities/channel-layout.js.map +1 -0
  84. package/dist/api/utilities/codec-format.d.ts +87 -0
  85. package/dist/api/utilities/codec-format.js +117 -0
  86. package/dist/api/utilities/codec-format.js.map +1 -0
  87. package/dist/api/utilities/context-options.d.ts +25 -0
  88. package/dist/api/utilities/context-options.js +23 -0
  89. package/dist/api/utilities/context-options.js.map +1 -0
  90. package/dist/api/utilities/electron-shared-texture.d.ts +368 -0
  91. package/dist/api/utilities/electron-shared-texture.js +540 -0
  92. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  93. package/dist/api/utilities/image.d.ts +207 -0
  94. package/dist/api/utilities/image.js +213 -0
  95. package/dist/api/utilities/image.js.map +1 -0
  96. package/dist/api/utilities/index.d.ts +14 -0
  97. package/dist/api/utilities/index.js +27 -0
  98. package/dist/api/utilities/index.js.map +1 -0
  99. package/dist/api/utilities/live-decoding.d.ts +15 -0
  100. package/dist/api/utilities/live-decoding.js +32 -0
  101. package/dist/api/utilities/live-decoding.js.map +1 -0
  102. package/dist/api/utilities/media-type.d.ts +49 -0
  103. package/dist/api/utilities/media-type.js +53 -0
  104. package/dist/api/utilities/media-type.js.map +1 -0
  105. package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
  106. package/dist/api/utilities/packet-age-watchdog.js +594 -0
  107. package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
  108. package/dist/api/utilities/pixel-format.d.ts +89 -0
  109. package/dist/api/utilities/pixel-format.js +97 -0
  110. package/dist/api/utilities/pixel-format.js.map +1 -0
  111. package/dist/api/utilities/sample-format.d.ts +129 -0
  112. package/dist/api/utilities/sample-format.js +141 -0
  113. package/dist/api/utilities/sample-format.js.map +1 -0
  114. package/dist/api/utilities/scale-size.d.ts +51 -0
  115. package/dist/api/utilities/scale-size.js +55 -0
  116. package/dist/api/utilities/scale-size.js.map +1 -0
  117. package/dist/api/utilities/scheduler.d.ts +138 -0
  118. package/dist/api/utilities/scheduler.js +98 -0
  119. package/dist/api/utilities/scheduler.js.map +1 -0
  120. package/dist/api/utilities/streaming.d.ts +186 -0
  121. package/dist/api/utilities/streaming.js +309 -0
  122. package/dist/api/utilities/streaming.js.map +1 -0
  123. package/dist/api/utilities/timestamp.d.ts +193 -0
  124. package/dist/api/utilities/timestamp.js +206 -0
  125. package/dist/api/utilities/timestamp.js.map +1 -0
  126. package/dist/api/utilities/video-transcode.d.ts +218 -0
  127. package/dist/api/utilities/video-transcode.js +624 -0
  128. package/dist/api/utilities/video-transcode.js.map +1 -0
  129. package/dist/api/utilities/whisper-model.d.ts +330 -0
  130. package/dist/api/utilities/whisper-model.js +587 -0
  131. package/dist/api/utilities/whisper-model.js.map +1 -0
  132. package/dist/api/utils.d.ts +19 -0
  133. package/dist/api/utils.js +39 -0
  134. package/dist/api/utils.js.map +1 -0
  135. package/dist/api/webrtc-stream.d.ts +294 -0
  136. package/dist/api/webrtc-stream.js +546 -0
  137. package/dist/api/webrtc-stream.js.map +1 -0
  138. package/dist/api/whisper.d.ts +326 -0
  139. package/dist/api/whisper.js +402 -0
  140. package/dist/api/whisper.js.map +1 -0
  141. package/dist/constants/bsf-options.d.ts +364 -0
  142. package/dist/constants/bsf-options.js +7 -0
  143. package/dist/constants/bsf-options.js.map +1 -0
  144. package/dist/constants/channel-layouts.d.ts +53 -0
  145. package/dist/constants/channel-layouts.js +57 -0
  146. package/dist/constants/channel-layouts.js.map +1 -0
  147. package/dist/constants/constants.d.ts +2435 -0
  148. package/dist/constants/constants.js +1989 -0
  149. package/dist/constants/constants.js.map +1 -0
  150. package/dist/constants/decoders.d.ts +651 -0
  151. package/dist/constants/decoders.js +641 -0
  152. package/dist/constants/decoders.js.map +1 -0
  153. package/dist/constants/encoders.d.ts +314 -0
  154. package/dist/constants/encoders.js +309 -0
  155. package/dist/constants/encoders.js.map +1 -0
  156. package/dist/constants/filter-options.d.ts +12099 -0
  157. package/dist/constants/filter-options.js +7 -0
  158. package/dist/constants/filter-options.js.map +1 -0
  159. package/dist/constants/format-options.d.ts +4319 -0
  160. package/dist/constants/format-options.js +7 -0
  161. package/dist/constants/format-options.js.map +1 -0
  162. package/dist/constants/formats.d.ts +18 -0
  163. package/dist/constants/formats.js +7 -0
  164. package/dist/constants/formats.js.map +1 -0
  165. package/dist/constants/hardware.d.ts +26 -0
  166. package/dist/constants/hardware.js +27 -0
  167. package/dist/constants/hardware.js.map +1 -0
  168. package/dist/constants/index.d.ts +10 -0
  169. package/dist/constants/index.js +6 -0
  170. package/dist/constants/index.js.map +1 -0
  171. package/dist/constants/options.d.ts +6217 -0
  172. package/dist/constants/options.js +7 -0
  173. package/dist/constants/options.js.map +1 -0
  174. package/dist/ffmpeg/index.d.ts +101 -0
  175. package/dist/ffmpeg/index.js +161 -0
  176. package/dist/ffmpeg/index.js.map +1 -0
  177. package/dist/ffmpeg/version.d.ts +6 -0
  178. package/dist/ffmpeg/version.js +7 -0
  179. package/dist/ffmpeg/version.js.map +1 -0
  180. package/dist/index.d.ts +4 -0
  181. package/dist/index.js +9 -0
  182. package/dist/index.js.map +1 -0
  183. package/dist/lib/audio-fifo.d.ts +399 -0
  184. package/dist/lib/audio-fifo.js +431 -0
  185. package/dist/lib/audio-fifo.js.map +1 -0
  186. package/dist/lib/binding.d.ts +242 -0
  187. package/dist/lib/binding.js +102 -0
  188. package/dist/lib/binding.js.map +1 -0
  189. package/dist/lib/bitstream-filter-context.d.ts +381 -0
  190. package/dist/lib/bitstream-filter-context.js +443 -0
  191. package/dist/lib/bitstream-filter-context.js.map +1 -0
  192. package/dist/lib/bitstream-filter.d.ts +140 -0
  193. package/dist/lib/bitstream-filter.js +154 -0
  194. package/dist/lib/bitstream-filter.js.map +1 -0
  195. package/dist/lib/codec-context.d.ts +1069 -0
  196. package/dist/lib/codec-context.js +1336 -0
  197. package/dist/lib/codec-context.js.map +1 -0
  198. package/dist/lib/codec-parameters.d.ts +664 -0
  199. package/dist/lib/codec-parameters.js +813 -0
  200. package/dist/lib/codec-parameters.js.map +1 -0
  201. package/dist/lib/codec-parser.d.ts +201 -0
  202. package/dist/lib/codec-parser.js +213 -0
  203. package/dist/lib/codec-parser.js.map +1 -0
  204. package/dist/lib/codec.d.ts +617 -0
  205. package/dist/lib/codec.js +746 -0
  206. package/dist/lib/codec.js.map +1 -0
  207. package/dist/lib/device.d.ts +294 -0
  208. package/dist/lib/device.js +326 -0
  209. package/dist/lib/device.js.map +1 -0
  210. package/dist/lib/dictionary.d.ts +333 -0
  211. package/dist/lib/dictionary.js +372 -0
  212. package/dist/lib/dictionary.js.map +1 -0
  213. package/dist/lib/error.d.ts +311 -0
  214. package/dist/lib/error.js +395 -0
  215. package/dist/lib/error.js.map +1 -0
  216. package/dist/lib/fifo.d.ts +416 -0
  217. package/dist/lib/fifo.js +453 -0
  218. package/dist/lib/fifo.js.map +1 -0
  219. package/dist/lib/filter-context.d.ts +714 -0
  220. package/dist/lib/filter-context.js +783 -0
  221. package/dist/lib/filter-context.js.map +1 -0
  222. package/dist/lib/filter-graph-segment.d.ts +161 -0
  223. package/dist/lib/filter-graph-segment.js +172 -0
  224. package/dist/lib/filter-graph-segment.js.map +1 -0
  225. package/dist/lib/filter-graph.d.ts +641 -0
  226. package/dist/lib/filter-graph.js +704 -0
  227. package/dist/lib/filter-graph.js.map +1 -0
  228. package/dist/lib/filter-inout.d.ts +202 -0
  229. package/dist/lib/filter-inout.js +261 -0
  230. package/dist/lib/filter-inout.js.map +1 -0
  231. package/dist/lib/filter.d.ts +243 -0
  232. package/dist/lib/filter.js +272 -0
  233. package/dist/lib/filter.js.map +1 -0
  234. package/dist/lib/format-context.d.ts +1335 -0
  235. package/dist/lib/format-context.js +1455 -0
  236. package/dist/lib/format-context.js.map +1 -0
  237. package/dist/lib/frame-utils.d.ts +116 -0
  238. package/dist/lib/frame-utils.js +98 -0
  239. package/dist/lib/frame-utils.js.map +1 -0
  240. package/dist/lib/frame.d.ts +1315 -0
  241. package/dist/lib/frame.js +1535 -0
  242. package/dist/lib/frame.js.map +1 -0
  243. package/dist/lib/hardware-device-context.d.ts +362 -0
  244. package/dist/lib/hardware-device-context.js +383 -0
  245. package/dist/lib/hardware-device-context.js.map +1 -0
  246. package/dist/lib/hardware-frames-context.d.ts +418 -0
  247. package/dist/lib/hardware-frames-context.js +471 -0
  248. package/dist/lib/hardware-frames-context.js.map +1 -0
  249. package/dist/lib/index.d.ts +35 -0
  250. package/dist/lib/index.js +60 -0
  251. package/dist/lib/index.js.map +1 -0
  252. package/dist/lib/input-format.d.ts +249 -0
  253. package/dist/lib/input-format.js +306 -0
  254. package/dist/lib/input-format.js.map +1 -0
  255. package/dist/lib/io-context.d.ts +698 -0
  256. package/dist/lib/io-context.js +771 -0
  257. package/dist/lib/io-context.js.map +1 -0
  258. package/dist/lib/log.d.ts +174 -0
  259. package/dist/lib/log.js +184 -0
  260. package/dist/lib/log.js.map +1 -0
  261. package/dist/lib/native-types.d.ts +1024 -0
  262. package/dist/lib/native-types.js +2 -0
  263. package/dist/lib/native-types.js.map +1 -0
  264. package/dist/lib/option.d.ts +953 -0
  265. package/dist/lib/option.js +1607 -0
  266. package/dist/lib/option.js.map +1 -0
  267. package/dist/lib/output-format.d.ts +222 -0
  268. package/dist/lib/output-format.js +259 -0
  269. package/dist/lib/output-format.js.map +1 -0
  270. package/dist/lib/packet.d.ts +521 -0
  271. package/dist/lib/packet.js +613 -0
  272. package/dist/lib/packet.js.map +1 -0
  273. package/dist/lib/rational.d.ts +251 -0
  274. package/dist/lib/rational.js +278 -0
  275. package/dist/lib/rational.js.map +1 -0
  276. package/dist/lib/software-resample-context.d.ts +552 -0
  277. package/dist/lib/software-resample-context.js +592 -0
  278. package/dist/lib/software-resample-context.js.map +1 -0
  279. package/dist/lib/software-scale-context.d.ts +344 -0
  280. package/dist/lib/software-scale-context.js +366 -0
  281. package/dist/lib/software-scale-context.js.map +1 -0
  282. package/dist/lib/stream.d.ts +383 -0
  283. package/dist/lib/stream.js +524 -0
  284. package/dist/lib/stream.js.map +1 -0
  285. package/dist/lib/sync-queue.d.ts +179 -0
  286. package/dist/lib/sync-queue.js +197 -0
  287. package/dist/lib/sync-queue.js.map +1 -0
  288. package/dist/lib/types.d.ts +34 -0
  289. package/dist/lib/types.js +2 -0
  290. package/dist/lib/types.js.map +1 -0
  291. package/dist/lib/utilities.d.ts +1198 -0
  292. package/dist/lib/utilities.js +1302 -0
  293. package/dist/lib/utilities.js.map +1 -0
  294. package/dist/utils/electron.d.ts +49 -0
  295. package/dist/utils/electron.js +63 -0
  296. package/dist/utils/electron.js.map +1 -0
  297. package/dist/utils/index.d.ts +6 -0
  298. package/dist/utils/index.js +7 -0
  299. package/dist/utils/index.js.map +1 -0
  300. package/dist/utils/libc.d.ts +11 -0
  301. package/dist/utils/libc.js +35 -0
  302. package/dist/utils/libc.js.map +1 -0
  303. package/dist/utils/variant.d.ts +26 -0
  304. package/dist/utils/variant.js +31 -0
  305. package/dist/utils/variant.js.map +1 -0
  306. package/dist/webrtc/index.d.ts +4 -0
  307. package/dist/webrtc/index.js +7 -0
  308. package/dist/webrtc/index.js.map +1 -0
  309. package/install/check.js +124 -0
  310. package/install/ffmpeg.js +66 -0
  311. package/package.json +165 -3
@@ -0,0 +1,636 @@
1
+ import { Frame } from '../lib/frame.js';
2
+ import type { AVSampleFormat } from '../constants/index.js';
3
+ import type { ChannelLayout } from '../lib/types.js';
4
+ /**
5
+ * Options for {@link AudioFrameBuffer.create}.
6
+ */
7
+ export interface AudioFrameBufferOptions {
8
+ /**
9
+ * Where the timestamps of the output frames come from.
10
+ *
11
+ * With `'input'` the output keeps the timing of the pushed frames, as described
12
+ * for {@link AudioFrameBuffer}. With `'samples'` input timestamps are ignored and
13
+ * the output is counted from 0 by its samples, in the time base of the pushed
14
+ * frames; use it for input whose timestamps are unusable.
15
+ *
16
+ * @default 'input'
17
+ */
18
+ timestamps?: 'input' | 'samples';
19
+ /**
20
+ * Largest gap in seconds that is filled with silence.
21
+ *
22
+ * A larger gap restarts the output timeline at the new timestamp, so it shows up
23
+ * as a timestamp jump instead. Real-time outputs such as RTP are better served by
24
+ * `0`: a filled gap is only written once the input resumes and then goes out as a
25
+ * burst of late packets, while receivers handle a timestamp gap like packet loss.
26
+ * Gaps of up to one output frame are filled either way, because a restart pads the
27
+ * current output frame with silence to its end. The silence is generated while
28
+ * pulling and takes no memory, but a long fill comes out in one go once the input
29
+ * resumes.
30
+ *
31
+ * @default 1
32
+ */
33
+ maxGapFill?: number;
34
+ }
35
+ /**
36
+ * Check the options of an audio frame buffer.
37
+ *
38
+ * @param options - Options to check
39
+ *
40
+ * @throws {RangeError} If an option is out of range
41
+ *
42
+ * @internal
43
+ */
44
+ export declare function assertAudioFrameBufferOptions(options: AudioFrameBufferOptions): void;
45
+ /**
46
+ * Audio frame buffering utility for encoders with fixed frame size requirements.
47
+ *
48
+ * Many audio encoders (Opus, AAC, MP3, etc.) require frames with a specific number
49
+ * of samples (frame_size). This class buffers incoming frames and outputs frames
50
+ * with exactly the required size.
51
+ *
52
+ * Output frames keep the input timing: each carries the timestamp of its first
53
+ * sample, in the time base of the pushed frames, and counts on by samples while the
54
+ * input is continuous. Deviations of up to 20 ms count as continuous, and larger ones
55
+ * only once they persist over 0.2 s of input, so jitter and single frames with a wrong
56
+ * timestamp leave the audio untouched. A persistent gap of up to a second is then
57
+ * filled with silence and an overlap of up to a second is dropped, which keeps the
58
+ * audio contiguous and in sync; a larger jump restarts the timeline at the new
59
+ * timestamp on the next frame boundary. Frames without a timestamp or time base
60
+ * continue the previous one.
61
+ *
62
+ * Uses FFmpeg's AVAudioFifo internally for efficient sample buffering.
63
+ *
64
+ * @example
65
+ * ```typescript
66
+ * import { AudioFrameBuffer } from 'node-av/api';
67
+ *
68
+ * // Create buffer for 480-sample frames (e.g., Opus at 24kHz)
69
+ * using buffer = AudioFrameBuffer.create(480, AV_SAMPLE_FMT_FLT, 48000, 'mono', 1);
70
+ *
71
+ * // Push variable-sized frames from filter
72
+ * for await (const frame of filterOutput) {
73
+ * await buffer.push(frame);
74
+ *
75
+ * // Pull fixed-size frames for encoder
76
+ * let outputFrame;
77
+ * while ((outputFrame = await buffer.pull()) !== null) {
78
+ * await encoder.encode(outputFrame);
79
+ * outputFrame.free();
80
+ * }
81
+ * }
82
+ *
83
+ * // Flush remaining samples (final partial frame is padded with silence)
84
+ * let outputFrame;
85
+ * while ((outputFrame = await buffer.pull()) !== null) {
86
+ * await encoder.encode(outputFrame);
87
+ * outputFrame.free();
88
+ * }
89
+ * const tail = await buffer.pullPartial();
90
+ * if (tail) {
91
+ * await encoder.encode(tail);
92
+ * tail.free();
93
+ * }
94
+ * ```
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * // Real-time output: input gaps become timestamp jumps instead of silence
99
+ * using buffer = AudioFrameBuffer.create(960, AV_SAMPLE_FMT_FLT, 48000, 'mono', 1, { maxGapFill: 0 });
100
+ * ```
101
+ */
102
+ export declare class AudioFrameBuffer implements Disposable {
103
+ private fifo;
104
+ private frame;
105
+ private frameSize;
106
+ private channels;
107
+ private sampleStride;
108
+ private staging;
109
+ private stagingPlanes;
110
+ private silenceValue;
111
+ private sampleTimeBase;
112
+ private timeBase;
113
+ private countsInSamples;
114
+ private followInput;
115
+ private tolerance;
116
+ private confirmSamples;
117
+ private maxFill;
118
+ private maxTrim;
119
+ private headIndex;
120
+ private tailIndex;
121
+ private segments;
122
+ private silence;
123
+ private timed;
124
+ private trimPending;
125
+ private deviation;
126
+ /**
127
+ * @param fifo - Underlying AudioFifo instance
128
+ *
129
+ * @param frameSize - Number of samples per output frame
130
+ *
131
+ * @param sampleFormat - Audio sample format
132
+ *
133
+ * @param sampleRate - Sample rate in Hz
134
+ *
135
+ * @param channelLayout - Channel layout
136
+ *
137
+ * @param options - Timing options
138
+ *
139
+ * @internal
140
+ */
141
+ private constructor();
142
+ /**
143
+ * Create an audio frame buffer.
144
+ *
145
+ * @param frameSize - Required frame size in samples
146
+ *
147
+ * @param sampleFormat - Audio sample format
148
+ *
149
+ * @param sampleRate - Sample rate in Hz
150
+ *
151
+ * @param channelLayout - Channel layout (e.g., 'mono', 'stereo')
152
+ *
153
+ * @param channels - Number of audio channels
154
+ *
155
+ * @param options - Timing options
156
+ *
157
+ * @returns Configured audio frame buffer
158
+ *
159
+ * @throws {RangeError} If an option is out of range
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * // For Opus encoder at 48kHz with 20ms frames
164
+ * const buffer = AudioFrameBuffer.create(960, AV_SAMPLE_FMT_FLT, 48000, 'mono', 1);
165
+ * ```
166
+ */
167
+ static create(frameSize: number, sampleFormat: AVSampleFormat, sampleRate: number, channelLayout: ChannelLayout, channels: number, options?: AudioFrameBufferOptions): AudioFrameBuffer;
168
+ /**
169
+ * Get number of samples currently in buffer.
170
+ *
171
+ * Includes silence inserted for gaps in the input.
172
+ *
173
+ * @returns Number of buffered samples
174
+ *
175
+ * @example
176
+ * ```typescript
177
+ * console.log(`Buffer contains ${buffer.size} samples`);
178
+ * ```
179
+ */
180
+ get size(): number;
181
+ /**
182
+ * Check if a complete frame is available.
183
+ *
184
+ * Returns true if the buffer holds at least frameSize samples.
185
+ *
186
+ * @returns True if a full frame can be pulled
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * while (buffer.hasFrame()) {
191
+ * const frame = buffer.pull();
192
+ * // Process frame...
193
+ * }
194
+ * ```
195
+ */
196
+ hasFrame(): boolean;
197
+ /**
198
+ * Push an audio frame into the buffer asynchronously.
199
+ *
200
+ * The frame's samples are added to the internal FIFO.
201
+ * Call hasFrame() and pull() to retrieve fixed-size output frames.
202
+ *
203
+ * The first frame with a valid time base fixes the time base of the output frames.
204
+ * When the frame timestamps deviate from the buffered samples by more than 20 ms
205
+ * over at least 0.2 s of input (and 3 frames), a gap is filled with silence (up to
206
+ * `maxGapFill`) and an overlap of up to 1 s is dropped from the input; a larger jump
207
+ * restarts the timeline at the new timestamp after padding the current output frame
208
+ * with silence. The frames that arrive until then still continue the previous
209
+ * timeline. Each such correction is a short dropout or cut in the audio: input whose
210
+ * timestamps drift against its sample count, such as a capture device stamped from
211
+ * the system clock, gets one per 20 ms of drift, which keeps it within about 20 ms
212
+ * of its timestamps.
213
+ *
214
+ * @param frame - Audio frame to buffer
215
+ *
216
+ * @throws {Error} If the frame is not an audio frame
217
+ *
218
+ * @throws {FFmpegError} If the samples cannot be written to the FIFO
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * await buffer.push(filterFrame);
223
+ * ```
224
+ *
225
+ * @see {@link pushSync} For synchronous version
226
+ */
227
+ push(frame: Frame): Promise<void>;
228
+ /**
229
+ * Push an audio frame into the buffer synchronously.
230
+ * Synchronous version of push.
231
+ *
232
+ * The frame's samples are added to the internal FIFO.
233
+ * Call hasFrame() and pullSync() to retrieve fixed-size output frames.
234
+ * Timestamps are handled as in push().
235
+ *
236
+ * @param frame - Audio frame to buffer
237
+ *
238
+ * @throws {Error} If the frame is not an audio frame
239
+ *
240
+ * @throws {FFmpegError} If the samples cannot be written to the FIFO
241
+ *
242
+ * @example
243
+ * ```typescript
244
+ * buffer.pushSync(filterFrame);
245
+ * ```
246
+ *
247
+ * @see {@link push} For async version
248
+ */
249
+ pushSync(frame: Frame): void;
250
+ /**
251
+ * Pull a fixed-size audio frame from the buffer asynchronously.
252
+ *
253
+ * Reads exactly frameSize samples from the FIFO and returns a cloned Frame
254
+ * stamped with the timestamp of its first sample.
255
+ * Returns null if not enough samples are available.
256
+ * Reuses internal frame buffer for efficiency (like Decoder does).
257
+ *
258
+ * @returns Audio frame with exactly frameSize samples, or null if insufficient samples
259
+ *
260
+ * @throws {FFmpegError} If the FIFO cannot be read or the frame cannot be filled
261
+ *
262
+ * @throws {Error} If frame cloning fails (out of memory)
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * using frame = await buffer.pull();
267
+ * if (frame) {
268
+ * await encoder.encode(frame);
269
+ * }
270
+ * ```
271
+ *
272
+ * @see {@link pullSync} For synchronous version
273
+ */
274
+ pull(): Promise<Frame | null>;
275
+ /**
276
+ * Pull a fixed-size audio frame from the buffer synchronously.
277
+ * Synchronous version of pull.
278
+ *
279
+ * Reads exactly frameSize samples from the FIFO and returns a cloned Frame
280
+ * stamped with the timestamp of its first sample.
281
+ * Returns null if not enough samples are available.
282
+ * Reuses internal frame buffer for efficiency (like Decoder does).
283
+ *
284
+ * @returns Audio frame with exactly frameSize samples, or null if insufficient samples
285
+ *
286
+ * @throws {FFmpegError} If the FIFO cannot be read or the frame cannot be filled
287
+ *
288
+ * @throws {Error} If frame cloning fails (out of memory)
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * using frame = buffer.pullSync();
293
+ * if (frame) {
294
+ * encoder.encodeSync(frame);
295
+ * }
296
+ * ```
297
+ *
298
+ * @see {@link pull} For async version
299
+ */
300
+ pullSync(): Frame | null;
301
+ /**
302
+ * Pull the final partial frame from the buffer asynchronously.
303
+ *
304
+ * Reads the remaining samples (fewer than frameSize) and pads the tail with
305
+ * silence so the returned frame still carries exactly frameSize samples.
306
+ * Intended for end-of-stream flushing only - without it the tail (up to
307
+ * frameSize - 1 samples) would be dropped. Returns null if the buffer is
308
+ * empty, or while a complete frame is still available (drain those with
309
+ * pull() first). The padding counts as audio, so frames pushed afterwards are
310
+ * timed after it.
311
+ *
312
+ * @returns Silence-padded audio frame with frameSize samples, or null if nothing to drain
313
+ *
314
+ * @throws {FFmpegError} If the FIFO cannot be read or the frame cannot be filled
315
+ *
316
+ * @throws {Error} If frame cloning fails (out of memory)
317
+ *
318
+ * @example
319
+ * ```typescript
320
+ * // At end of stream, after pull() has returned null
321
+ * using tail = await buffer.pullPartial();
322
+ * if (tail) {
323
+ * await encoder.encode(tail);
324
+ * }
325
+ * ```
326
+ *
327
+ * @see {@link pullPartialSync} For synchronous version
328
+ * @see {@link pull} For pulling complete frames
329
+ */
330
+ pullPartial(): Promise<Frame | null>;
331
+ /**
332
+ * Pull the final partial frame from the buffer synchronously.
333
+ * Synchronous version of pullPartial.
334
+ *
335
+ * Reads the remaining samples (fewer than frameSize) and pads the tail with
336
+ * silence so the returned frame still carries exactly frameSize samples.
337
+ * Intended for end-of-stream flushing only. Returns null if the buffer is
338
+ * empty, or while a complete frame is still available.
339
+ *
340
+ * @returns Silence-padded audio frame with frameSize samples, or null if nothing to drain
341
+ *
342
+ * @throws {FFmpegError} If the FIFO cannot be read or the frame cannot be filled
343
+ *
344
+ * @throws {Error} If frame cloning fails (out of memory)
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * // At end of stream, after pullSync() has returned null
349
+ * using tail = buffer.pullPartialSync();
350
+ * if (tail) {
351
+ * encoder.encodeSync(tail);
352
+ * }
353
+ * ```
354
+ *
355
+ * @see {@link pullPartial} For async version
356
+ * @see {@link pullSync} For pulling complete frames
357
+ */
358
+ pullPartialSync(): Frame | null;
359
+ /**
360
+ * Reset the buffer, discarding all buffered samples.
361
+ *
362
+ * The next pushed frame starts a new timeline, and its time base becomes
363
+ * the output time base.
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * buffer.reset();
368
+ * ```
369
+ */
370
+ reset(): void;
371
+ /**
372
+ * Decide how a pushed frame continues the buffered samples.
373
+ *
374
+ * The only place that moves the write position: it records the silence before the
375
+ * frame and accounts for the samples the caller then writes, so the position always
376
+ * runs ahead of the buffered samples by exactly the writes still in flight.
377
+ *
378
+ * @param frame - Audio frame about to be written
379
+ *
380
+ * @param nbSamples - Number of samples in the frame
381
+ *
382
+ * @returns Samples to drop from the head of the frame
383
+ *
384
+ * @internal
385
+ */
386
+ private planPush;
387
+ /**
388
+ * Append silence at the write position.
389
+ *
390
+ * Silence only exists as a run of sample indices and is generated while pulling, so
391
+ * a long gap costs neither a buffer of its size nor a FIFO grown to hold it (an
392
+ * AVAudioFifo never shrinks again).
393
+ *
394
+ * @param samples - Number of silent samples
395
+ *
396
+ * @internal
397
+ */
398
+ private addSilence;
399
+ /**
400
+ * Anchor the timeline at the first frame that carries a timestamp.
401
+ *
402
+ * @param pts - Timestamp of the frame in the output time base
403
+ *
404
+ * @returns Silence to write before the frame
405
+ *
406
+ * @internal
407
+ */
408
+ private anchorInput;
409
+ /**
410
+ * Compare a frame's timestamp with the buffered samples and compensate a persistent deviation.
411
+ *
412
+ * Within the tolerance the frame counts on by samples. A larger deviation is only
413
+ * acted on once it has lasted over enough input in the same direction: jitter and
414
+ * frames with a wrong timestamp come and go, while gaps, overlaps and clock steps
415
+ * persist. The correction is the median deviation of that run, so jitter on top of
416
+ * a real step does not leak into it.
417
+ *
418
+ * @param pts - Timestamp of the frame in the output time base
419
+ *
420
+ * @param nbSamples - Number of samples in the frame
421
+ *
422
+ * @returns Silence to write before the frame
423
+ *
424
+ * @internal
425
+ */
426
+ private trackInput;
427
+ /**
428
+ * Apply a confirmed deviation to the timeline.
429
+ *
430
+ * A gap is filled with silence and an overlap is dropped from the input, which keeps
431
+ * the output contiguous and on its frame grid. Beyond their limits the timeline
432
+ * restarts at the frame's timestamp instead.
433
+ *
434
+ * @param offset - Deviation of the frame in the output time base
435
+ *
436
+ * @param expected - Timestamp the frame would have without the deviation
437
+ *
438
+ * @returns Silence to write before the frame
439
+ *
440
+ * @internal
441
+ */
442
+ private compensate;
443
+ /**
444
+ * Start a new segment at the next output frame boundary.
445
+ *
446
+ * Every output frame then lies within one segment, so its timestamp stays well
447
+ * defined; the current partial frame is padded with silence to get there.
448
+ *
449
+ * @param pts - Timestamp of the frame about to be written
450
+ *
451
+ * @returns Silence to write before the frame
452
+ *
453
+ * @internal
454
+ */
455
+ private restart;
456
+ /**
457
+ * Fix the output time base from the first pushed frame.
458
+ *
459
+ * Frames without a valid time base leave the output counting samples (1/sample_rate).
460
+ *
461
+ * @param frame - First pushed frame
462
+ *
463
+ * @returns Output time base
464
+ *
465
+ * @internal
466
+ */
467
+ private lockTimeBase;
468
+ /**
469
+ * Read a frame's timestamp in the output time base.
470
+ *
471
+ * @param frame - Pushed frame
472
+ *
473
+ * @returns Timestamp, or AV_NOPTS_VALUE if the frame has no timestamp or time base
474
+ *
475
+ * @internal
476
+ */
477
+ private inputPts;
478
+ /**
479
+ * Timestamp of the next sample to pull.
480
+ *
481
+ * Drops segments the head has reached the end of first, so the head lies in the first one.
482
+ *
483
+ * @returns Timestamp in the output time base
484
+ *
485
+ * @internal
486
+ */
487
+ private headPts;
488
+ /**
489
+ * Timestamp right after the last buffered sample.
490
+ *
491
+ * @returns Timestamp in the output time base
492
+ *
493
+ * @internal
494
+ */
495
+ private tailPts;
496
+ /**
497
+ * Treat the silence padding of a partial frame as written audio.
498
+ *
499
+ * @internal
500
+ */
501
+ private advanceTailToHead;
502
+ /**
503
+ * Realign the write position with the FIFO after a failed write.
504
+ *
505
+ * @internal
506
+ */
507
+ private resyncTail;
508
+ /**
509
+ * Number of samples that can be pulled: buffered samples plus the silence between them.
510
+ *
511
+ * Stops at the first silence run that lies behind a write still in flight.
512
+ *
513
+ * @returns Number of samples available from the read position
514
+ *
515
+ * @internal
516
+ */
517
+ private available;
518
+ /**
519
+ * Split the next samples to pull into FIFO reads and silence.
520
+ *
521
+ * @param count - Number of samples to pull
522
+ *
523
+ * @returns Parts in pull order
524
+ *
525
+ * @internal
526
+ */
527
+ private readRuns;
528
+ /**
529
+ * Read the next samples into the head of the staging buffer.
530
+ *
531
+ * @param count - Number of samples to read
532
+ *
533
+ * @throws {FFmpegError} If the FIFO cannot be read
534
+ *
535
+ * @internal
536
+ */
537
+ private readStaging;
538
+ /**
539
+ * Read the next samples into the head of the staging buffer synchronously.
540
+ * Synchronous version of readStaging.
541
+ *
542
+ * @param count - Number of samples to read
543
+ *
544
+ * @throws {FFmpegError} If the FIFO cannot be read
545
+ *
546
+ * @internal
547
+ */
548
+ private readStagingSync;
549
+ /**
550
+ * Staging planes starting at a sample offset.
551
+ *
552
+ * @param offset - First sample to write to
553
+ *
554
+ * @returns Plane buffers for a FIFO read
555
+ *
556
+ * @internal
557
+ */
558
+ private stagingAt;
559
+ /**
560
+ * Convert a sample count to output time base ticks.
561
+ *
562
+ * @param samples - Number of samples
563
+ *
564
+ * @returns Duration in the output time base
565
+ *
566
+ * @internal
567
+ */
568
+ private ticks;
569
+ /**
570
+ * Convert output time base ticks to a sample count.
571
+ *
572
+ * @param ticks - Duration in the output time base
573
+ *
574
+ * @returns Number of samples (rounded)
575
+ *
576
+ * @internal
577
+ */
578
+ private samples;
579
+ /**
580
+ * Plane buffers of a pushed frame, starting at a sample offset.
581
+ *
582
+ * @param frame - Pushed frame
583
+ *
584
+ * @param skip - Samples to leave out at the head
585
+ *
586
+ * @returns Plane buffers to write to the FIFO
587
+ *
588
+ * @internal
589
+ */
590
+ private inputPlanes;
591
+ /**
592
+ * Stamp the reusable frame, advance the read position by one frame and hand out a clone.
593
+ *
594
+ * @param pts - Timestamp of the frame's first sample
595
+ *
596
+ * @returns Cloned output frame
597
+ *
598
+ * @throws {Error} If frame cloning fails (out of memory)
599
+ *
600
+ * @internal
601
+ */
602
+ private emitFrame;
603
+ /**
604
+ * Fill the staged sample range [fromSample, toSample) with silence.
605
+ *
606
+ * Planar frames carry one channel per plane; packed frames interleave all
607
+ * channels in plane 0.
608
+ *
609
+ * @param fromSample - First sample index to silence
610
+ *
611
+ * @param toSample - Sample index after the last one to silence
612
+ *
613
+ * @internal
614
+ */
615
+ private fillSilence;
616
+ /**
617
+ * Copy the staged samples into the reusable frame.
618
+ *
619
+ * A frame pulled earlier may still share the frame's buffer, so the buffer is
620
+ * made writable first instead of overwriting the samples under that frame.
621
+ *
622
+ * @throws {FFmpegError} If the frame buffer cannot be made writable or filled
623
+ *
624
+ * @internal
625
+ */
626
+ private commitStaging;
627
+ /**
628
+ * Free the buffer and all resources.
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * buffer.free();
633
+ * ```
634
+ */
635
+ [Symbol.dispose](): void;
636
+ }