@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,820 @@
1
+ import { Packet } from '../lib/packet.js';
2
+ import { Muxer } from './muxer.js';
3
+ import { Scheduler, SchedulerControl } from './utilities/scheduler.js';
4
+ import type { Stream } from '../lib/stream.js';
5
+ /**
6
+ * Options for bitstream filter creation.
7
+ */
8
+ export interface BitstreamFilterOptions {
9
+ /**
10
+ * Filter-specific options.
11
+ *
12
+ * Key-value pairs of FFmpeg bitstream filter options.
13
+ * These are passed directly to the filter via av_opt_set().
14
+ * Available options depend on the specific filter being used.
15
+ */
16
+ options?: Record<string, string | number | boolean | bigint | undefined | null>;
17
+ /**
18
+ * AbortSignal for cancellation.
19
+ *
20
+ * When aborted, async generators stop yielding and async methods throw AbortError.
21
+ */
22
+ signal?: AbortSignal;
23
+ }
24
+ /**
25
+ * High-level bitstream filter for packet processing.
26
+ *
27
+ * Provides simplified interface for applying bitstream filters to packets.
28
+ * Handles filter initialization, packet processing, and memory management.
29
+ * Supports both synchronous packet-by-packet filtering and async iteration over packets.
30
+ * Supports filters like h264_mp4toannexb, hevc_mp4toannexb, aac_adtstoasc.
31
+ * Essential for format conversion and stream compatibility in transcoding pipelines.
32
+ *
33
+ * @example
34
+ * ```typescript
35
+ * import { BitStreamFilterAPI } from 'node-av/api';
36
+ *
37
+ * // Create H.264 Annex B converter
38
+ * const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
39
+ *
40
+ * // Filter packet
41
+ * const outputPackets = await filter.filterAll(inputPacket);
42
+ * for (const packet of outputPackets) {
43
+ * await output.writePacket(packet);
44
+ * packet.free();
45
+ * }
46
+ * ```
47
+ *
48
+ * @example
49
+ * ```typescript
50
+ * // Filter packet stream
51
+ * const filter = BitStreamFilterAPI.create('hevc_mp4toannexb', videoStream);
52
+ *
53
+ * for await (const packet of filter.packets(input.packets())) {
54
+ * await output.writePacket(packet);
55
+ * packet.free();
56
+ * }
57
+ * ```
58
+ *
59
+ * @see {@link BitStreamFilter} For available filters
60
+ * @see {@link BitStreamFilterContext} For low-level API
61
+ * @see {@link Muxer} For writing filtered packets
62
+ */
63
+ export declare class BitStreamFilterAPI implements Disposable {
64
+ private ctx;
65
+ private bsf;
66
+ private stream;
67
+ private packet;
68
+ private isClosed;
69
+ private inputQueue;
70
+ private outputQueue;
71
+ private workerPromise;
72
+ private nextComponent;
73
+ private pipeToPromise;
74
+ private signal?;
75
+ /**
76
+ * @param bsf - Bitstream filter
77
+ *
78
+ * @param ctx - Filter context
79
+ *
80
+ * @param stream - Associated stream
81
+ *
82
+ * @internal
83
+ */
84
+ private constructor();
85
+ /**
86
+ * Create a bitstream filter for a stream.
87
+ *
88
+ * Initializes filter with stream codec parameters.
89
+ * Configures time base and prepares for packet processing.
90
+ *
91
+ * Direct mapping to av_bsf_get_by_name() and av_bsf_alloc().
92
+ *
93
+ * @param filterName - Name of the bitstream filter
94
+ *
95
+ * @param stream - Stream to apply filter to
96
+ *
97
+ * @param filterOptions - Optional filter-specific options
98
+ *
99
+ * @returns Configured bitstream filter
100
+ *
101
+ * @throws {Error} If initialization fails
102
+ *
103
+ * @throws {FFmpegError} If allocation or initialization fails
104
+ *
105
+ * @example
106
+ * ```typescript
107
+ * // H.264 MP4 to Annex B conversion
108
+ * const filter = BitStreamFilterAPI.create('h264_mp4toannexb', videoStream);
109
+ * ```
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * // AAC ADTS to ASC conversion
114
+ * const filter = BitStreamFilterAPI.create('aac_adtstoasc', audioStream);
115
+ * ```
116
+ *
117
+ * @example
118
+ * ```typescript
119
+ * // Remove AUDs from H.264 stream
120
+ * const filter = BitStreamFilterAPI.create('h264_metadata', stream, {
121
+ * options: { aud: 'remove' }
122
+ * });
123
+ * ```
124
+ *
125
+ * @example
126
+ * ```typescript
127
+ * // Set H.264 level
128
+ * const filter = BitStreamFilterAPI.create('h264_metadata', stream, {
129
+ * options: { level: 51 }
130
+ * });
131
+ * ```
132
+ *
133
+ * @see {@link BitStreamFilter.getByName} For filter discovery
134
+ * @see {@link BitstreamFilterOptions} For available options
135
+ */
136
+ static create(filterName: string, stream: Stream, filterOptions?: BitstreamFilterOptions): BitStreamFilterAPI;
137
+ /**
138
+ * Get filter name.
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * console.log(`Using filter: ${filter.name}`);
143
+ * ```
144
+ */
145
+ get name(): string;
146
+ /**
147
+ * Get output codec parameters.
148
+ *
149
+ * Parameters after filter processing.
150
+ * May differ from input parameters.
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const outputParams = filter.outputCodecParameters;
155
+ * console.log(`Output codec: ${outputParams?.codecId}`);
156
+ * ```
157
+ */
158
+ get outputCodecParameters(): import("../index.js").CodecParameters | null;
159
+ /**
160
+ * Get output time base.
161
+ *
162
+ * Time base after filter processing.
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * const tb = filter.outputTimeBase;
167
+ * console.log(`Output timebase: ${tb?.num}/${tb?.den}`);
168
+ * ```
169
+ */
170
+ get outputTimeBase(): import("../index.js").Rational | null;
171
+ /**
172
+ * Check if filter is open.
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * if (filter.isBitstreamFilterOpen) {
177
+ * const packet = await filter.process(frame);
178
+ * }
179
+ * ```
180
+ */
181
+ get isBitstreamFilterOpen(): boolean;
182
+ /**
183
+ * Send a packet to the filter.
184
+ *
185
+ * Sends a packet to the filter for processing.
186
+ * Does not return filtered packets - use {@link receive} to retrieve packets.
187
+ * A single packet can produce zero, one, or multiple packets depending on filter.
188
+ *
189
+ * **Important**: This method only SENDS the packet to the filter.
190
+ * You must call {@link receive} separately (potentially multiple times) to get filtered packets.
191
+ *
192
+ * Direct mapping to av_bsf_send_packet().
193
+ *
194
+ * @param packet - Packet to send to filter, or null to flush
195
+ *
196
+ * @throws {FFmpegError} If sending fails
197
+ *
198
+ * @example
199
+ * ```typescript
200
+ * // Send packet and receive filtered packets
201
+ * await filter.filter(inputPacket);
202
+ *
203
+ * // Receive all available filtered packets
204
+ * while (true) {
205
+ * const outPacket = await filter.receive();
206
+ * if (!outPacket) break;
207
+ * console.log(`Filtered packet with PTS: ${outPacket.pts}`);
208
+ * await output.writePacket(outPacket);
209
+ * outPacket.free();
210
+ * }
211
+ * ```
212
+ *
213
+ * @example
214
+ * ```typescript
215
+ * for await (const packet of input.packets()) {
216
+ * // packet is null at end of stream - automatically flushes filter
217
+ * await filter.filter(packet);
218
+ *
219
+ * // Receive available filtered packets
220
+ * let outPacket;
221
+ * while ((outPacket = await filter.receive())) {
222
+ * await output.writePacket(outPacket);
223
+ * outPacket.free();
224
+ * }
225
+ * }
226
+ * ```
227
+ *
228
+ * @see {@link receive} For receiving filtered packets
229
+ * @see {@link filterAll} For combined send+receive operation
230
+ * @see {@link packets} For automatic packet iteration
231
+ * @see {@link flush} For end-of-stream handling
232
+ * @see {@link filterSync} For synchronous version
233
+ */
234
+ filter(packet: Packet | null): Promise<void>;
235
+ /**
236
+ * Send a packet to the filter synchronously.
237
+ * Synchronous version of filter.
238
+ *
239
+ * Sends a packet to the filter for processing.
240
+ * Does not return filtered packets - use {@link receiveSync} to retrieve packets.
241
+ * A single packet can produce zero, one, or multiple packets depending on filter.
242
+ *
243
+ * **Important**: This method only SENDS the packet to the filter.
244
+ * You must call {@link receiveSync} separately (potentially multiple times) to get filtered packets.
245
+ *
246
+ * Direct mapping to av_bsf_send_packet().
247
+ *
248
+ * @param packet - Packet to send to filter, or null to flush
249
+ *
250
+ * @throws {FFmpegError} If sending fails
251
+ *
252
+ * @example
253
+ * ```typescript
254
+ * // Send packet and receive filtered packets
255
+ * filter.filterSync(inputPacket);
256
+ *
257
+ * // Receive all available filtered packets
258
+ * while (true) {
259
+ * const outPacket = filter.receiveSync();
260
+ * if (!outPacket) break;
261
+ * console.log(`Filtered packet with PTS: ${outPacket.pts}`);
262
+ * output.writePacketSync(outPacket);
263
+ * outPacket.free();
264
+ * }
265
+ * ```
266
+ *
267
+ * @example
268
+ * ```typescript
269
+ * for (const packet of packets) {
270
+ * // packet is null at end of stream - automatically flushes filter
271
+ * filter.filterSync(packet);
272
+ *
273
+ * // Receive available filtered packets
274
+ * let outPacket;
275
+ * while ((outPacket = filter.receiveSync())) {
276
+ * output.writePacketSync(outPacket);
277
+ * outPacket.free();
278
+ * }
279
+ * }
280
+ * ```
281
+ *
282
+ * @see {@link receiveSync} For receiving filtered packets
283
+ * @see {@link filterAllSync} For combined send+receive operation
284
+ * @see {@link packetsSync} For automatic packet iteration
285
+ * @see {@link flushSync} For end-of-stream handling
286
+ * @see {@link filter} For async version
287
+ */
288
+ filterSync(packet: Packet | null): void;
289
+ /**
290
+ * Filter a packet to packets.
291
+ *
292
+ * Sends a packet to the filter and receives all available filtered packets.
293
+ * Returns array of packets - may be empty if filter needs more data.
294
+ * One packet can produce zero, one, or multiple packets depending on filter.
295
+ *
296
+ * Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
297
+ *
298
+ * @param packet - Packet to filter, or null to flush
299
+ *
300
+ * @returns Array of filtered packets (empty if more data needed or filter is closed)
301
+ *
302
+ * @throws {FFmpegError} If filtering fails
303
+ *
304
+ * @example
305
+ * ```typescript
306
+ * const outputPackets = await filter.filterAll(inputPacket);
307
+ * for (const packet of outputPackets) {
308
+ * console.log(`Filtered packet: pts=${packet.pts}`);
309
+ * await output.writePacket(packet);
310
+ * packet.free();
311
+ * }
312
+ * ```
313
+ *
314
+ * @example
315
+ * ```typescript
316
+ * // Flush remaining packets at end of stream
317
+ * const remaining = await filter.filterAll(null);
318
+ * for (const packet of remaining) {
319
+ * await output.writePacket(packet);
320
+ * packet.free();
321
+ * }
322
+ * ```
323
+ *
324
+ * @see {@link filter} For single packet filtering
325
+ * @see {@link packets} For stream processing
326
+ * @see {@link flush} For end-of-stream handling
327
+ * @see {@link filterAllSync} For synchronous version
328
+ */
329
+ filterAll(packet: Packet | null): Promise<Packet[]>;
330
+ /**
331
+ * Filter a packet to packets synchronously.
332
+ * Synchronous version of filterAll.
333
+ *
334
+ * Sends a packet to the filter and receives all available filtered packets.
335
+ * Returns array of packets - may be empty if filter needs more data.
336
+ * One packet can produce zero, one, or multiple packets depending on filter.
337
+ *
338
+ * Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
339
+ *
340
+ * @param packet - Packet to filter, or null to flush
341
+ *
342
+ * @returns Array of filtered packets (empty if more data needed or filter is closed)
343
+ *
344
+ * @throws {FFmpegError} If filtering fails
345
+ *
346
+ * @example
347
+ * ```typescript
348
+ * const outputPackets = filter.filterAllSync(inputPacket);
349
+ * for (const packet of outputPackets) {
350
+ * console.log(`Filtered packet: pts=${packet.pts}`);
351
+ * output.writePacketSync(packet);
352
+ * packet.free();
353
+ * }
354
+ * ```
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * // Flush remaining packets at end of stream
359
+ * const remaining = filter.filterAllSync(null);
360
+ * for (const packet of remaining) {
361
+ * output.writePacketSync(packet);
362
+ * packet.free();
363
+ * }
364
+ * ```
365
+ *
366
+ * @see {@link filterSync} For single packet filtering
367
+ * @see {@link packetsSync} For stream processing
368
+ * @see {@link flushSync} For end-of-stream handling
369
+ * @see {@link filterAll} For async version
370
+ */
371
+ filterAllSync(packet: Packet | null): Packet[];
372
+ /**
373
+ * Filter packet stream to filtered packet stream.
374
+ *
375
+ * High-level async generator for complete filtering pipeline.
376
+ * Filter is only flushed when EOF (null) signal is explicitly received.
377
+ * Primary interface for stream-based filtering.
378
+ *
379
+ * **EOF Handling:**
380
+ * - Send null to flush filter and get remaining buffered packets
381
+ * - Generator yields null after flushing when null is received
382
+ * - No automatic flushing - filter stays open until EOF or close()
383
+ *
384
+ * @param packets - Async iterable of packets, single packet, or null to flush
385
+ *
386
+ * @yields {Packet | null} Filtered packets, followed by null when explicitly flushed
387
+ *
388
+ * @throws {FFmpegError} If filtering fails
389
+ *
390
+ * @example
391
+ * ```typescript
392
+ * // Stream of packets with automatic EOF propagation
393
+ * for await (const packet of filter.packets(input.packets())) {
394
+ * if (packet === null) {
395
+ * console.log('Filter flushed');
396
+ * break;
397
+ * }
398
+ * await output.writePacket(packet);
399
+ * packet.free(); // Must free output packets
400
+ * }
401
+ * ```
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * // Single packet - no automatic flush
406
+ * for await (const packet of filter.packets(singlePacket)) {
407
+ * await output.writePacket(packet);
408
+ * packet.free();
409
+ * }
410
+ * // Filter remains open, buffered packets not flushed
411
+ * ```
412
+ *
413
+ * @example
414
+ * ```typescript
415
+ * // Explicit flush with EOF
416
+ * for await (const packet of filter.packets(null)) {
417
+ * if (packet === null) {
418
+ * console.log('All buffered packets flushed');
419
+ * break;
420
+ * }
421
+ * console.log('Buffered packet:', packet.pts);
422
+ * await output.writePacket(packet);
423
+ * packet.free();
424
+ * }
425
+ * ```
426
+ *
427
+ * @see {@link filter} For single packet filtering
428
+ * @see {@link Demuxer.packets} For packet source
429
+ * @see {@link packetsSync} For sync version
430
+ */
431
+ packets(packets: AsyncIterable<Packet | null> | Packet | null): AsyncGenerator<Packet | null>;
432
+ /**
433
+ * Filter packet stream to filtered packet stream synchronously.
434
+ * Synchronous version of packets.
435
+ *
436
+ * High-level sync generator for complete filtering pipeline.
437
+ * Filter is only flushed when EOF (null) signal is explicitly received.
438
+ * Primary interface for stream-based filtering.
439
+ *
440
+ * **EOF Handling:**
441
+ * - Send null to flush filter and get remaining buffered packets
442
+ * - Generator yields null after flushing when null is received
443
+ * - No automatic flushing - filter stays open until EOF or close()
444
+ *
445
+ * @param packets - Iterable of packets, single packet, or null to flush
446
+ *
447
+ * @yields {Packet | null} Filtered packets, followed by null when explicitly flushed
448
+ *
449
+ * @throws {FFmpegError} If filtering fails
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * // Stream of packets with automatic EOF propagation
454
+ * for (const packet of filter.packetsSync(inputPackets)) {
455
+ * if (packet === null) {
456
+ * console.log('Filter flushed');
457
+ * break;
458
+ * }
459
+ * output.writePacketSync(packet);
460
+ * packet.free(); // Must free output packets
461
+ * }
462
+ * ```
463
+ *
464
+ * @example
465
+ * ```typescript
466
+ * // Single packet - no automatic flush
467
+ * for (const packet of filter.packetsSync(singlePacket)) {
468
+ * output.writePacketSync(packet);
469
+ * packet.free();
470
+ * }
471
+ * // Filter remains open, buffered packets not flushed
472
+ * ```
473
+ *
474
+ * @example
475
+ * ```typescript
476
+ * // Explicit flush with EOF
477
+ * for (const packet of filter.packetsSync(null)) {
478
+ * if (packet === null) {
479
+ * console.log('All buffered packets flushed');
480
+ * break;
481
+ * }
482
+ * console.log('Buffered packet:', packet.pts);
483
+ * output.writePacketSync(packet);
484
+ * packet.free();
485
+ * }
486
+ * ```
487
+ *
488
+ * @see {@link filterSync} For single packet filtering
489
+ * @see {@link packets} For async version
490
+ */
491
+ packetsSync(packets: Iterable<Packet | null> | Packet | null): Generator<Packet | null>;
492
+ /**
493
+ * Flush filter and signal end-of-stream.
494
+ *
495
+ * Sends null packet to filter to signal end-of-stream.
496
+ * Does nothing if filter is closed.
497
+ * Must call receive() or flushPackets() to get remaining buffered packets.
498
+ *
499
+ * Direct mapping to av_bsf_send_packet(NULL) and av_bsf_flush().
500
+ *
501
+ * @throws {FFmpegError} If flush fails
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * // Signal end of stream
506
+ * await filter.flush();
507
+ *
508
+ * // Then get remaining packets
509
+ * let packet;
510
+ * while ((packet = await filter.receive()) !== null) {
511
+ * console.log('Got buffered packet');
512
+ * await output.writePacket(packet);
513
+ * packet.free();
514
+ * }
515
+ * ```
516
+ *
517
+ * @see {@link flushPackets} For async iteration
518
+ * @see {@link receive} For getting buffered packets
519
+ * @see {@link reset} For state reset only
520
+ * @see {@link flushSync} For synchronous version
521
+ */
522
+ flush(): Promise<void>;
523
+ /**
524
+ * Flush filter and signal end-of-stream synchronously.
525
+ * Synchronous version of flush.
526
+ *
527
+ * Sends null packet to filter to signal end-of-stream.
528
+ * Does nothing if filter is closed.
529
+ * Must call receiveSync() or flushPacketsSync() to get remaining buffered packets.
530
+ *
531
+ * Direct mapping to av_bsf_send_packet(NULL) and av_bsf_flush().
532
+ *
533
+ * @throws {FFmpegError} If flush fails
534
+ *
535
+ * @example
536
+ * ```typescript
537
+ * // Signal end of stream
538
+ * filter.flushSync();
539
+ *
540
+ * // Then get remaining packets
541
+ * let packet;
542
+ * while ((packet = filter.receiveSync()) !== null) {
543
+ * console.log('Got buffered packet');
544
+ * output.writePacketSync(packet);
545
+ * packet.free();
546
+ * }
547
+ * ```
548
+ *
549
+ * @see {@link flushPacketsSync} For sync iteration
550
+ * @see {@link receiveSync} For getting buffered packets
551
+ * @see {@link reset} For state reset only
552
+ * @see {@link flush} For async version
553
+ */
554
+ flushSync(): void;
555
+ /**
556
+ * Receive packet from filter.
557
+ *
558
+ * Gets filtered packets from the filter's internal buffer.
559
+ * Handles packet allocation and error checking.
560
+ * Returns null if filter is closed or no packets available.
561
+ * Call repeatedly until null to drain all buffered packets.
562
+ *
563
+ * Direct mapping to av_bsf_receive_packet().
564
+ *
565
+ * @returns Cloned packet or null if no packets available
566
+ *
567
+ * @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
568
+ *
569
+ * @throws {Error} If packet cloning fails (out of memory)
570
+ *
571
+ * @example
572
+ * ```typescript
573
+ * const packet = await filter.receive();
574
+ * if (packet) {
575
+ * console.log('Got filtered packet');
576
+ * await output.writePacket(packet);
577
+ * packet.free();
578
+ * }
579
+ * ```
580
+ *
581
+ * @example
582
+ * ```typescript
583
+ * // Drain all buffered packets
584
+ * let packet;
585
+ * while ((packet = await filter.receive()) !== null) {
586
+ * console.log(`Packet PTS: ${packet.pts}`);
587
+ * await output.writePacket(packet);
588
+ * packet.free();
589
+ * }
590
+ * ```
591
+ *
592
+ * @see {@link filter} For filtering packets
593
+ * @see {@link flush} For signaling end-of-stream
594
+ * @see {@link receiveSync} For synchronous version
595
+ */
596
+ receive(): Promise<Packet | null>;
597
+ /**
598
+ * Receive packet from filter synchronously.
599
+ * Synchronous version of receive.
600
+ *
601
+ * Gets filtered packets from the filter's internal buffer.
602
+ * Handles packet allocation and error checking.
603
+ * Returns null if filter is closed or no packets available.
604
+ * Call repeatedly until null to drain all buffered packets.
605
+ *
606
+ * Direct mapping to av_bsf_receive_packet().
607
+ *
608
+ * @returns Cloned packet or null if no packets available
609
+ *
610
+ * @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
611
+ *
612
+ * @throws {Error} If packet cloning fails (out of memory)
613
+ *
614
+ * @example
615
+ * ```typescript
616
+ * const packet = filter.receiveSync();
617
+ * if (packet) {
618
+ * console.log('Got filtered packet');
619
+ * output.writePacketSync(packet);
620
+ * packet.free();
621
+ * }
622
+ * ```
623
+ *
624
+ * @example
625
+ * ```typescript
626
+ * // Drain all buffered packets
627
+ * let packet;
628
+ * while ((packet = filter.receiveSync()) !== null) {
629
+ * console.log(`Packet PTS: ${packet.pts}`);
630
+ * output.writePacketSync(packet);
631
+ * packet.free();
632
+ * }
633
+ * ```
634
+ *
635
+ * @see {@link filterSync} For filtering packets
636
+ * @see {@link flushSync} For signaling end-of-stream
637
+ * @see {@link receive} For async version
638
+ */
639
+ receiveSync(): Packet | null;
640
+ /**
641
+ * Flush all buffered packets as async generator.
642
+ *
643
+ * Convenient async iteration over remaining packets.
644
+ * Automatically sends flush signal and retrieves buffered packets.
645
+ * Useful for end-of-stream processing.
646
+ *
647
+ * @yields {Packet} Buffered packets
648
+ *
649
+ * @example
650
+ * ```typescript
651
+ * // Flush at end of filtering
652
+ * for await (const packet of filter.flushPackets()) {
653
+ * console.log('Processing buffered packet');
654
+ * await output.writePacket(packet);
655
+ * packet.free();
656
+ * }
657
+ * ```
658
+ *
659
+ * @see {@link filter} For filtering packets
660
+ * @see {@link flush} For signaling end-of-stream
661
+ * @see {@link flushPacketsSync} For synchronous version
662
+ */
663
+ flushPackets(): AsyncGenerator<Packet>;
664
+ /**
665
+ * Flush all buffered packets as generator synchronously.
666
+ * Synchronous version of flushPackets.
667
+ *
668
+ * Convenient sync iteration over remaining packets.
669
+ * Automatically retrieves buffered packets after flush.
670
+ * Useful for end-of-stream processing.
671
+ *
672
+ * @yields {Packet} Buffered packets
673
+ *
674
+ * @example
675
+ * ```typescript
676
+ * // Flush at end of filtering
677
+ * for (const packet of filter.flushPacketsSync()) {
678
+ * console.log('Processing buffered packet');
679
+ * output.writePacketSync(packet);
680
+ * packet.free();
681
+ * }
682
+ * ```
683
+ *
684
+ * @see {@link filterSync} For filtering packets
685
+ * @see {@link flushSync} For signaling end-of-stream
686
+ * @see {@link flushPackets} For async version
687
+ */
688
+ flushPacketsSync(): Generator<Packet>;
689
+ /**
690
+ * Get associated stream.
691
+ *
692
+ * Returns the stream this filter was created for.
693
+ *
694
+ * @returns Associated stream
695
+ *
696
+ * @example
697
+ * ```typescript
698
+ * const stream = filter.getStream();
699
+ * console.log(`Filtering stream ${stream.index}`);
700
+ * ```
701
+ */
702
+ getStream(): Stream;
703
+ /**
704
+ * Reset filter state.
705
+ *
706
+ * Clears internal buffers and resets filter.
707
+ * Does not dispose resources.
708
+ *
709
+ * Direct mapping to av_bsf_flush().
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * // Reset for new segment
714
+ * filter.reset();
715
+ * ```
716
+ *
717
+ * @see {@link flush} For reset with packet retrieval
718
+ */
719
+ reset(): void;
720
+ /**
721
+ * Close filter and free resources.
722
+ *
723
+ * Releases filter context and marks as closed.
724
+ * Safe to call multiple times.
725
+ *
726
+ * @example
727
+ * ```typescript
728
+ * filter.close();
729
+ * ```
730
+ *
731
+ * @see {@link Symbol.dispose} For automatic cleanup
732
+ */
733
+ close(): void;
734
+ /**
735
+ * Dispose of filter.
736
+ *
737
+ * Implements Disposable interface for automatic cleanup.
738
+ * Equivalent to calling dispose().
739
+ *
740
+ * @example
741
+ * ```typescript
742
+ * {
743
+ * using filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
744
+ * // Use filter...
745
+ * } // Automatically disposed
746
+ * ```
747
+ *
748
+ * @see {@link close} For manual cleanup
749
+ */
750
+ [Symbol.dispose](): void;
751
+ /**
752
+ * Send packet to input queue or flush the pipeline.
753
+ *
754
+ * When packet is provided, queues it for filtering.
755
+ * When null is provided, triggers flush sequence:
756
+ * - Closes input queue
757
+ * - Waits for worker completion
758
+ * - Closes output queue (no buffering, bitstream filters are stateless)
759
+ * - Waits for pipeTo task completion
760
+ * - Propagates flush to next component (if any)
761
+ *
762
+ * Used by scheduler system for pipeline control.
763
+ *
764
+ * @param packet - Packet to send, or null to flush
765
+ *
766
+ * @internal
767
+ */
768
+ sendToQueue(packet: Packet | null): Promise<void>;
769
+ /**
770
+ * Receive packet from output queue.
771
+ *
772
+ * @returns Packet from queue or null if closed
773
+ *
774
+ * @internal
775
+ */
776
+ receiveFromQueue(): Promise<Packet | null>;
777
+ /**
778
+ * Worker loop for push-based processing.
779
+ *
780
+ * @internal
781
+ */
782
+ private runWorker;
783
+ /**
784
+ * Pipe output to another bitstream filter.
785
+ *
786
+ * Starts background worker for packet processing.
787
+ * Packets flow through: input → this filter → target filter.
788
+ *
789
+ * @param target - Target bitstream filter
790
+ *
791
+ * @returns Scheduler for continued chaining
792
+ *
793
+ * @example
794
+ * ```typescript
795
+ * const filter1 = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
796
+ * const filter2 = BitStreamFilterAPI.create('dump_extra', stream);
797
+ * filter1.pipeTo(filter2).pipeTo(output, 0);
798
+ * ```
799
+ */
800
+ pipeTo(target: BitStreamFilterAPI): Scheduler<Packet>;
801
+ /**
802
+ * Pipe output to muxer.
803
+ *
804
+ * Terminal stage - writes filtered packets to output file.
805
+ *
806
+ * @param output - Muxer to write to
807
+ *
808
+ * @param streamIndex - Stream index in output
809
+ *
810
+ * @returns Control interface for pipeline
811
+ *
812
+ * @example
813
+ * ```typescript
814
+ * const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
815
+ * const control = filter.pipeTo(output, 0);
816
+ * await control.send(packet);
817
+ * ```
818
+ */
819
+ pipeTo(output: Muxer, streamIndex: number): SchedulerControl<Packet>;
820
+ }