node-av 3.1.2 → 4.0.0

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 (157) hide show
  1. package/README.md +65 -52
  2. package/binding.gyp +4 -0
  3. package/dist/api/audio-frame-buffer.d.ts +201 -0
  4. package/dist/api/audio-frame-buffer.js +275 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +319 -78
  7. package/dist/api/bitstream-filter.js +680 -151
  8. package/dist/api/bitstream-filter.js.map +1 -1
  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_mjpeg.mjpeg +0 -0
  14. package/dist/api/data/test_vp8.ivf +0 -0
  15. package/dist/api/data/test_vp9.ivf +0 -0
  16. package/dist/api/decoder.d.ts +279 -17
  17. package/dist/api/decoder.js +998 -209
  18. package/dist/api/decoder.js.map +1 -1
  19. package/dist/api/{media-input.d.ts → demuxer.d.ts} +294 -44
  20. package/dist/api/demuxer.js +1968 -0
  21. package/dist/api/demuxer.js.map +1 -0
  22. package/dist/api/encoder.d.ts +308 -50
  23. package/dist/api/encoder.js +1133 -111
  24. package/dist/api/encoder.js.map +1 -1
  25. package/dist/api/filter-presets.d.ts +12 -5
  26. package/dist/api/filter-presets.js +21 -7
  27. package/dist/api/filter-presets.js.map +1 -1
  28. package/dist/api/filter.d.ts +406 -40
  29. package/dist/api/filter.js +966 -139
  30. package/dist/api/filter.js.map +1 -1
  31. package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
  32. package/dist/api/fmp4-stream.js +539 -0
  33. package/dist/api/fmp4-stream.js.map +1 -0
  34. package/dist/api/hardware.d.ts +58 -6
  35. package/dist/api/hardware.js +127 -11
  36. package/dist/api/hardware.js.map +1 -1
  37. package/dist/api/index.d.ts +6 -4
  38. package/dist/api/index.js +14 -8
  39. package/dist/api/index.js.map +1 -1
  40. package/dist/api/io-stream.d.ts +3 -3
  41. package/dist/api/io-stream.js +5 -4
  42. package/dist/api/io-stream.js.map +1 -1
  43. package/dist/api/{media-output.d.ts → muxer.d.ts} +274 -60
  44. package/dist/api/muxer.js +1934 -0
  45. package/dist/api/muxer.js.map +1 -0
  46. package/dist/api/pipeline.d.ts +77 -29
  47. package/dist/api/pipeline.js +435 -425
  48. package/dist/api/pipeline.js.map +1 -1
  49. package/dist/api/rtp-stream.d.ts +312 -0
  50. package/dist/api/rtp-stream.js +630 -0
  51. package/dist/api/rtp-stream.js.map +1 -0
  52. package/dist/api/types.d.ts +476 -55
  53. package/dist/api/utilities/async-queue.d.ts +91 -0
  54. package/dist/api/utilities/async-queue.js +162 -0
  55. package/dist/api/utilities/async-queue.js.map +1 -0
  56. package/dist/api/utilities/audio-sample.d.ts +1 -1
  57. package/dist/api/utilities/image.d.ts +1 -1
  58. package/dist/api/utilities/index.d.ts +2 -0
  59. package/dist/api/utilities/index.js +4 -0
  60. package/dist/api/utilities/index.js.map +1 -1
  61. package/dist/api/utilities/media-type.d.ts +1 -1
  62. package/dist/api/utilities/pixel-format.d.ts +1 -1
  63. package/dist/api/utilities/sample-format.d.ts +1 -1
  64. package/dist/api/utilities/scheduler.d.ts +169 -0
  65. package/dist/api/utilities/scheduler.js +136 -0
  66. package/dist/api/utilities/scheduler.js.map +1 -0
  67. package/dist/api/utilities/streaming.d.ts +74 -15
  68. package/dist/api/utilities/streaming.js +170 -12
  69. package/dist/api/utilities/streaming.js.map +1 -1
  70. package/dist/api/utilities/timestamp.d.ts +1 -1
  71. package/dist/api/webrtc-stream.d.ts +288 -0
  72. package/dist/api/webrtc-stream.js +440 -0
  73. package/dist/api/webrtc-stream.js.map +1 -0
  74. package/dist/constants/constants.d.ts +51 -1
  75. package/dist/constants/constants.js +47 -1
  76. package/dist/constants/constants.js.map +1 -1
  77. package/dist/constants/encoders.d.ts +2 -1
  78. package/dist/constants/encoders.js +4 -3
  79. package/dist/constants/encoders.js.map +1 -1
  80. package/dist/constants/hardware.d.ts +26 -0
  81. package/dist/constants/hardware.js +27 -0
  82. package/dist/constants/hardware.js.map +1 -0
  83. package/dist/constants/index.d.ts +1 -0
  84. package/dist/constants/index.js +1 -0
  85. package/dist/constants/index.js.map +1 -1
  86. package/dist/lib/binding.d.ts +19 -8
  87. package/dist/lib/binding.js.map +1 -1
  88. package/dist/lib/codec-context.d.ts +87 -0
  89. package/dist/lib/codec-context.js +125 -4
  90. package/dist/lib/codec-context.js.map +1 -1
  91. package/dist/lib/codec-parameters.d.ts +183 -1
  92. package/dist/lib/codec-parameters.js +209 -0
  93. package/dist/lib/codec-parameters.js.map +1 -1
  94. package/dist/lib/codec-parser.d.ts +23 -0
  95. package/dist/lib/codec-parser.js +25 -0
  96. package/dist/lib/codec-parser.js.map +1 -1
  97. package/dist/lib/codec.d.ts +26 -4
  98. package/dist/lib/codec.js +35 -0
  99. package/dist/lib/codec.js.map +1 -1
  100. package/dist/lib/dictionary.js +1 -0
  101. package/dist/lib/dictionary.js.map +1 -1
  102. package/dist/lib/error.js +1 -1
  103. package/dist/lib/error.js.map +1 -1
  104. package/dist/lib/filter-context.d.ts +52 -11
  105. package/dist/lib/filter-context.js +56 -12
  106. package/dist/lib/filter-context.js.map +1 -1
  107. package/dist/lib/filter-graph.d.ts +9 -0
  108. package/dist/lib/filter-graph.js +13 -0
  109. package/dist/lib/filter-graph.js.map +1 -1
  110. package/dist/lib/filter.d.ts +21 -0
  111. package/dist/lib/filter.js +28 -0
  112. package/dist/lib/filter.js.map +1 -1
  113. package/dist/lib/format-context.d.ts +48 -14
  114. package/dist/lib/format-context.js +76 -7
  115. package/dist/lib/format-context.js.map +1 -1
  116. package/dist/lib/frame.d.ts +168 -0
  117. package/dist/lib/frame.js +212 -0
  118. package/dist/lib/frame.js.map +1 -1
  119. package/dist/lib/hardware-device-context.d.ts +3 -2
  120. package/dist/lib/hardware-device-context.js.map +1 -1
  121. package/dist/lib/index.d.ts +1 -0
  122. package/dist/lib/index.js +2 -0
  123. package/dist/lib/index.js.map +1 -1
  124. package/dist/lib/input-format.d.ts +21 -0
  125. package/dist/lib/input-format.js +42 -2
  126. package/dist/lib/input-format.js.map +1 -1
  127. package/dist/lib/native-types.d.ts +48 -26
  128. package/dist/lib/option.d.ts +25 -13
  129. package/dist/lib/option.js +28 -0
  130. package/dist/lib/option.js.map +1 -1
  131. package/dist/lib/output-format.d.ts +22 -1
  132. package/dist/lib/output-format.js +28 -0
  133. package/dist/lib/output-format.js.map +1 -1
  134. package/dist/lib/packet.d.ts +35 -0
  135. package/dist/lib/packet.js +52 -2
  136. package/dist/lib/packet.js.map +1 -1
  137. package/dist/lib/stream.d.ts +126 -0
  138. package/dist/lib/stream.js +188 -5
  139. package/dist/lib/stream.js.map +1 -1
  140. package/dist/lib/sync-queue.d.ts +179 -0
  141. package/dist/lib/sync-queue.js +197 -0
  142. package/dist/lib/sync-queue.js.map +1 -0
  143. package/dist/lib/types.d.ts +27 -1
  144. package/dist/lib/utilities.d.ts +281 -53
  145. package/dist/lib/utilities.js +298 -55
  146. package/dist/lib/utilities.js.map +1 -1
  147. package/install/check.js +18 -7
  148. package/package.json +20 -19
  149. package/dist/api/fmp4.js +0 -710
  150. package/dist/api/fmp4.js.map +0 -1
  151. package/dist/api/media-input.js +0 -1075
  152. package/dist/api/media-input.js.map +0 -1
  153. package/dist/api/media-output.js +0 -1040
  154. package/dist/api/media-output.js.map +0 -1
  155. package/dist/api/webrtc.d.ts +0 -664
  156. package/dist/api/webrtc.js +0 -1132
  157. package/dist/api/webrtc.js.map +0 -1
@@ -1,5 +1,9 @@
1
- import { Frame } from '../lib/index.js';
2
- import type { AVFilterCmdFlag } from '../constants/constants.js';
1
+ import { Frame } from '../lib/frame.js';
2
+ import { Scheduler } from './utilities/scheduler.js';
3
+ import type { AVColorRange, AVColorSpace, AVFilterCmdFlag, AVPixelFormat, AVSampleFormat } from '../constants/index.js';
4
+ import type { FilterContext } from '../lib/filter-context.js';
5
+ import type { ChannelLayout, IDimension, IRational } from '../lib/types.js';
6
+ import type { Encoder } from './encoder.js';
3
7
  import type { FilterOptions } from './types.js';
4
8
  /**
5
9
  * High-level filter API for audio and video processing.
@@ -44,8 +48,17 @@ export declare class FilterAPI implements Disposable {
44
48
  private options;
45
49
  private buffersrcCtx;
46
50
  private buffersinkCtx;
51
+ private frame;
52
+ private initializePromise;
47
53
  private initialized;
48
54
  private isClosed;
55
+ private calculatedTimeBase;
56
+ private lastFrameProps;
57
+ private inputQueue;
58
+ private outputQueue;
59
+ private workerPromise;
60
+ private nextComponent;
61
+ private pipeToPromise;
49
62
  /**
50
63
  * @param graph - Filter graph instance
51
64
  *
@@ -61,44 +74,46 @@ export declare class FilterAPI implements Disposable {
61
74
  *
62
75
  * Creates and allocates filter graph immediately.
63
76
  * Filter configuration is completed on first frame with frame properties.
77
+ * TimeBase is automatically calculated from first frame based on CFR option.
64
78
  * Hardware frames context is automatically detected from input frames.
65
79
  *
66
80
  * Direct mapping to avfilter_graph_parse_ptr() and avfilter_graph_config().
67
81
  *
68
82
  * @param description - Filter graph description
69
83
  *
70
- * @param options - Filter options including required timeBase
84
+ * @param options - Filter options
71
85
  *
72
86
  * @returns Configured filter instance
73
87
  *
88
+ * @throws {Error} If cfr=true but framerate is not set
89
+ *
74
90
  * @example
75
91
  * ```typescript
76
- * // Simple video filter
77
- * const filter = FilterAPI.create('scale=640:480', {
78
- * timeBase: video.timeBase
79
- * });
92
+ * // Simple video filter (VFR mode, auto timeBase)
93
+ * const filter = FilterAPI.create('scale=640:480');
80
94
  * ```
81
95
  *
82
96
  * @example
83
97
  * ```typescript
84
- * // Complex filter chain
85
- * const filter = FilterAPI.create('crop=640:480:0:0,rotate=PI/4', {
86
- * timeBase: video.timeBase
98
+ * // CFR mode with constant framerate
99
+ * const filter = FilterAPI.create('scale=1920:1080', {
100
+ * cfr: true,
101
+ * framerate: { num: 25, den: 1 }
87
102
  * });
88
103
  * ```
89
104
  *
90
105
  * @example
91
106
  * ```typescript
92
- * // Audio filter
93
- * const filter = FilterAPI.create('volume=0.5,aecho=0.8:0.9:1000:0.3', {
94
- * timeBase: audio.timeBase
107
+ * // Audio filter with resampling
108
+ * const filter = FilterAPI.create('aformat=sample_fmts=s16:sample_rates=44100', {
109
+ * audioResampleOpts: 'async=1'
95
110
  * });
96
111
  * ```
97
112
  *
98
113
  * @see {@link process} For frame processing
99
114
  * @see {@link FilterOptions} For configuration options
100
115
  */
101
- static create(description: string, options: FilterOptions): FilterAPI;
116
+ static create(description: string, options?: FilterOptions): FilterAPI;
102
117
  /**
103
118
  * Check if filter is open.
104
119
  *
@@ -126,6 +141,206 @@ export declare class FilterAPI implements Disposable {
126
141
  * ```
127
142
  */
128
143
  get isFilterInitialized(): boolean;
144
+ /**
145
+ * Get buffersink filter context.
146
+ *
147
+ * Provides access to the buffersink filter context for advanced operations.
148
+ * Returns null if filter is not initialized.
149
+ *
150
+ * @returns Buffersink context or null
151
+ *
152
+ * @example
153
+ * ```typescript
154
+ * const sink = filter.buffersink;
155
+ * if (sink) {
156
+ * const fr = sink.buffersinkGetFrameRate();
157
+ * console.log(`Output frame rate: ${fr.num}/${fr.den}`);
158
+ * }
159
+ * ```
160
+ */
161
+ get buffersink(): FilterContext | null;
162
+ /**
163
+ * Output frame rate from filter graph.
164
+ *
165
+ * Returns the frame rate determined by the filter graph output.
166
+ * Matches FFmpeg CLI's av_buffersink_get_frame_rate() behavior.
167
+ * Returns null if filter is not initialized or frame rate is not set.
168
+ *
169
+ * Direct mapping to av_buffersink_get_frame_rate().
170
+ *
171
+ * @returns Frame rate or null if not available
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * const frameRate = filter.frameRate;
176
+ * if (frameRate) {
177
+ * console.log(`Filter output: ${frameRate.num}/${frameRate.den} fps`);
178
+ * }
179
+ * ```
180
+ *
181
+ * @see {@link timeBase} For output timebase
182
+ */
183
+ get frameRate(): IRational | null;
184
+ /**
185
+ * Output time base from filter graph.
186
+ *
187
+ * Returns the time base of the buffersink output.
188
+ * Matches FFmpeg CLI's av_buffersink_get_time_base() behavior.
189
+ *
190
+ * Direct mapping to av_buffersink_get_time_base().
191
+ *
192
+ * @returns Time base or null if not initialized
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * const timeBase = filter.timeBase;
197
+ * if (timeBase) {
198
+ * console.log(`Filter timebase: ${timeBase.num}/${timeBase.den}`);
199
+ * }
200
+ * ```
201
+ *
202
+ * @see {@link frameRate} For output frame rate
203
+ */
204
+ get timeBase(): IRational | null;
205
+ /**
206
+ * Output format from filter graph.
207
+ *
208
+ * Returns the pixel format (video) or sample format (audio) of the buffersink output.
209
+ * Matches FFmpeg CLI's av_buffersink_get_format() behavior.
210
+ *
211
+ * Direct mapping to av_buffersink_get_format().
212
+ *
213
+ * @returns Pixel format or sample format, or null if not initialized
214
+ *
215
+ * @example
216
+ * ```typescript
217
+ * const format = filter.format;
218
+ * if (format !== null) {
219
+ * console.log(`Filter output format: ${format}`);
220
+ * }
221
+ * ```
222
+ */
223
+ get format(): AVPixelFormat | AVSampleFormat | null;
224
+ /**
225
+ * Output dimensions from filter graph (video only).
226
+ *
227
+ * Returns the width and height of the buffersink output.
228
+ * Matches FFmpeg CLI's av_buffersink_get_w() and av_buffersink_get_h() behavior.
229
+ * Only meaningful for video filters.
230
+ *
231
+ * Direct mapping to av_buffersink_get_w() and av_buffersink_get_h().
232
+ *
233
+ * @returns Dimensions object or null if not initialized
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * const dims = filter.dimensions;
238
+ * if (dims) {
239
+ * console.log(`Filter output: ${dims.width}x${dims.height}`);
240
+ * }
241
+ * ```
242
+ */
243
+ get dimensions(): IDimension | null;
244
+ /**
245
+ * Output sample rate from filter graph (audio only).
246
+ *
247
+ * Returns the sample rate of the buffersink output.
248
+ * Matches FFmpeg CLI's av_buffersink_get_sample_rate() behavior.
249
+ * Only meaningful for audio filters.
250
+ *
251
+ * Direct mapping to av_buffersink_get_sample_rate().
252
+ *
253
+ * @returns Sample rate or null if not initialized
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * const sampleRate = filter.sampleRate;
258
+ * if (sampleRate) {
259
+ * console.log(`Filter output sample rate: ${sampleRate} Hz`);
260
+ * }
261
+ * ```
262
+ */
263
+ get sampleRate(): number | null;
264
+ /**
265
+ * Output channel layout from filter graph (audio only).
266
+ *
267
+ * Returns the channel layout of the buffersink output.
268
+ * Matches FFmpeg CLI's av_buffersink_get_ch_layout() behavior.
269
+ * Only meaningful for audio filters.
270
+ *
271
+ * Direct mapping to av_buffersink_get_ch_layout().
272
+ *
273
+ * @returns Channel layout or null if not initialized
274
+ *
275
+ * @example
276
+ * ```typescript
277
+ * const layout = filter.channelLayout;
278
+ * if (layout) {
279
+ * console.log(`Filter output channels: ${layout.nbChannels}`);
280
+ * }
281
+ * ```
282
+ */
283
+ get channelLayout(): ChannelLayout | null;
284
+ /**
285
+ * Output color space from filter graph (video only).
286
+ *
287
+ * Returns the color space of the buffersink output.
288
+ * Matches FFmpeg CLI's av_buffersink_get_colorspace() behavior.
289
+ * Only meaningful for video filters.
290
+ *
291
+ * Direct mapping to av_buffersink_get_colorspace().
292
+ *
293
+ * @returns Color space or null if not initialized
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * const colorSpace = filter.colorSpace;
298
+ * if (colorSpace !== null) {
299
+ * console.log(`Filter output color space: ${colorSpace}`);
300
+ * }
301
+ * ```
302
+ */
303
+ get colorSpace(): AVColorSpace | null;
304
+ /**
305
+ * Output color range from filter graph (video only).
306
+ *
307
+ * Returns the color range of the buffersink output.
308
+ * Matches FFmpeg CLI's av_buffersink_get_color_range() behavior.
309
+ * Only meaningful for video filters.
310
+ *
311
+ * Direct mapping to av_buffersink_get_color_range().
312
+ *
313
+ * @returns Color range or null if not initialized
314
+ *
315
+ * @example
316
+ * ```typescript
317
+ * const colorRange = filter.colorRange;
318
+ * if (colorRange !== null) {
319
+ * console.log(`Filter output color range: ${colorRange}`);
320
+ * }
321
+ * ```
322
+ */
323
+ get colorRange(): AVColorRange | null;
324
+ /**
325
+ * Output sample aspect ratio from filter graph (video only).
326
+ *
327
+ * Returns the sample aspect ratio of the buffersink output.
328
+ * Matches FFmpeg CLI's av_buffersink_get_sample_aspect_ratio() behavior.
329
+ * Only meaningful for video filters.
330
+ *
331
+ * Direct mapping to av_buffersink_get_sample_aspect_ratio().
332
+ *
333
+ * @returns Sample aspect ratio or null if not initialized
334
+ *
335
+ * @example
336
+ * ```typescript
337
+ * const sar = filter.sampleAspectRatio;
338
+ * if (sar) {
339
+ * console.log(`Filter output SAR: ${sar.num}:${sar.den}`);
340
+ * }
341
+ * ```
342
+ */
343
+ get sampleAspectRatio(): IRational | null;
129
344
  /**
130
345
  * Check if filter is ready for processing.
131
346
  *
@@ -165,6 +380,10 @@ export declare class FilterAPI implements Disposable {
165
380
  * Hardware frames context is automatically detected from frame.
166
381
  * Returns null if filter is closed and frame is null.
167
382
  *
383
+ * **Note**: This method receives only ONE frame per call.
384
+ * A single input frame can produce multiple output frames (e.g., fps filter, deinterlace).
385
+ * To receive all frames from an input, use {@link processAll} or {@link frames} instead.
386
+ *
168
387
  * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
169
388
  *
170
389
  * @param frame - Input frame to process (or null to flush)
@@ -195,8 +414,10 @@ export declare class FilterAPI implements Disposable {
195
414
  * // For buffered frames, use the frames() async generator
196
415
  * ```
197
416
  *
417
+ * @see {@link processAll} For processing multiple output frames
198
418
  * @see {@link frames} For processing frame streams
199
419
  * @see {@link flush} For end-of-stream handling
420
+ * @see {@link processSync} For synchronous version
200
421
  */
201
422
  process(frame: Frame | null): Promise<Frame | null>;
202
423
  /**
@@ -209,6 +430,10 @@ export declare class FilterAPI implements Disposable {
209
430
  * Hardware frames context is automatically detected from frame.
210
431
  * Returns null if filter is closed and frame is null.
211
432
  *
433
+ * **Note**: This method receives only ONE frame per call.
434
+ * A single input frame can produce multiple output frames (e.g., fps filter, deinterlace).
435
+ * To receive all frames from an input, use {@link processAllSync} or {@link framesSync} instead.
436
+ *
212
437
  * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
213
438
  *
214
439
  * @param frame - Input frame to process (or null to flush)
@@ -239,62 +464,99 @@ export declare class FilterAPI implements Disposable {
239
464
  * // For buffered frames, use the framesSync() generator
240
465
  * ```
241
466
  *
467
+ * @see {@link processAllSync} For processing multiple output frames
468
+ * @see {@link framesSync} For processing frame streams
469
+ * @see {@link flushSync} For end-of-stream handling
242
470
  * @see {@link process} For async version
243
471
  */
244
472
  processSync(frame: Frame | null): Frame | null;
245
473
  /**
246
- * Process multiple frames at once.
474
+ * Process a frame through the filter.
247
475
  *
248
- * Processes batch of frames and drains all output.
249
- * Useful for filters that buffer multiple frames.
476
+ * Applies filter operations to input frame and receives all available output frames.
477
+ * Returns array of frames - may be empty if filter needs more input.
478
+ * On first frame, automatically builds filter graph with frame properties.
479
+ * One input frame can produce zero, one, or multiple output frames depending on filter.
480
+ * Hardware frames context is automatically detected from frame.
250
481
  *
251
- * @param frames - Array of input frames
482
+ * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
252
483
  *
253
- * @returns Array of all output frames (empty if filter closed)
484
+ * @param frame - Input frame to process (or null to flush)
254
485
  *
255
- * @throws {Error} If filter not ready
486
+ * @returns Array of filtered frames (empty if buffered or filter closed)
487
+ *
488
+ * @throws {Error} If filter could not be initialized
256
489
  *
257
490
  * @throws {FFmpegError} If processing fails
258
491
  *
259
492
  * @example
260
493
  * ```typescript
261
- * const outputs = await filter.processMultiple([frame1, frame2, frame3]);
262
- * for (const output of outputs) {
263
- * console.log(`Output frame: pts=${output.pts}`);
494
+ * const frames = await filter.processAll(inputFrame);
495
+ * for (const output of frames) {
496
+ * console.log(`Got filtered frame: pts=${output.pts}`);
264
497
  * output.free();
265
498
  * }
266
499
  * ```
267
500
  *
501
+ * @example
502
+ * ```typescript
503
+ * // Process frame - may return multiple frames (e.g. fps filter)
504
+ * const frames = await filter.processAll(frame);
505
+ * for (const output of frames) {
506
+ * yield output;
507
+ * }
508
+ * ```
509
+ *
268
510
  * @see {@link process} For single frame processing
511
+ * @see {@link frames} For processing frame streams
512
+ * @see {@link flush} For end-of-stream handling
513
+ * @see {@link processAllSync} For synchronous version
269
514
  */
270
- processMultiple(frames: Frame[]): Promise<Frame[]>;
515
+ processAll(frame: Frame | null): Promise<Frame[]>;
271
516
  /**
272
- * Process multiple frames at once synchronously.
273
- * Synchronous version of processMultiple.
517
+ * Process a frame through the filter synchronously.
518
+ * Synchronous version of processAll.
519
+ *
520
+ * Applies filter operations to input frame and receives all available output frames.
521
+ * Returns array of frames - may be empty if filter needs more input.
522
+ * On first frame, automatically builds filter graph with frame properties.
523
+ * One input frame can produce zero, one, or multiple output frames depending on filter.
524
+ * Hardware frames context is automatically detected from frame.
274
525
  *
275
- * Processes batch of frames and drains all output.
276
- * Useful for filters that buffer multiple frames.
526
+ * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
277
527
  *
278
- * @param frames - Array of input frames
528
+ * @param frame - Input frame to process (or null to flush)
279
529
  *
280
- * @returns Array of all output frames (empty if filter closed)
530
+ * @returns Array of filtered frames (empty if buffered or filter closed)
281
531
  *
282
- * @throws {Error} If filter not ready
532
+ * @throws {Error} If filter could not be initialized
283
533
  *
284
534
  * @throws {FFmpegError} If processing fails
285
535
  *
286
536
  * @example
287
537
  * ```typescript
288
- * const outputs = filter.processMultipleSync([frame1, frame2, frame3]);
538
+ * const outputs = filter.processAllSync(inputFrame);
289
539
  * for (const output of outputs) {
290
- * console.log(`Output frame: pts=${output.pts}`);
540
+ * console.log(`Got filtered frame: pts=${output.pts}`);
291
541
  * output.free();
292
542
  * }
293
543
  * ```
294
544
  *
295
- * @see {@link processMultiple} For async version
545
+ * @example
546
+ * ```typescript
547
+ * // Process frame - may return multiple frames (e.g. fps filter)
548
+ * const outputs = filter.processAllSync(frame);
549
+ * for (const output of outputs) {
550
+ * yield output;
551
+ * }
552
+ * ```
553
+ *
554
+ * @see {@link processSync} For single frame processing
555
+ * @see {@link framesSync} For processing frame streams
556
+ * @see {@link flushSync} For end-of-stream handling
557
+ * @see {@link process} For async version
296
558
  */
297
- processMultipleSync(frames: Frame[]): Frame[];
559
+ processAllSync(frame: Frame | null): Frame[];
298
560
  /**
299
561
  * Process frame stream through filter.
300
562
  *
@@ -336,9 +598,10 @@ export declare class FilterAPI implements Disposable {
336
598
  * ```
337
599
  *
338
600
  * @see {@link process} For single frame processing
339
- * @see {@link flush} For end-of-stream handling
601
+ * @see {@link Decoder.frames} For frames source
602
+ * @see {@link framesSync} For sync version
340
603
  */
341
- frames(frames: AsyncGenerator<Frame>): AsyncGenerator<Frame>;
604
+ frames(frames: AsyncIterable<Frame | null>): AsyncGenerator<Frame | null>;
342
605
  /**
343
606
  * Process frame stream through filter synchronously.
344
607
  * Synchronous version of frames.
@@ -380,9 +643,11 @@ export declare class FilterAPI implements Disposable {
380
643
  * }
381
644
  * ```
382
645
  *
646
+ * @see {@link processSync} For single frame processing
647
+ * @see {@link Decoder.framesSync} For frames source
383
648
  * @see {@link frames} For async version
384
649
  */
385
- framesSync(frames: Generator<Frame>): Generator<Frame>;
650
+ framesSync(frames: Generator<Frame | null>): Generator<Frame | null>;
386
651
  /**
387
652
  * Flush filter and signal end-of-stream.
388
653
  *
@@ -405,7 +670,8 @@ export declare class FilterAPI implements Disposable {
405
670
  * ```
406
671
  *
407
672
  * @see {@link flushFrames} For async iteration
408
- * @see {@link frames} For complete pipeline
673
+ * @see {@link receive} For getting flushed frames
674
+ * @see {@link flushSync} For synchronous version
409
675
  */
410
676
  flush(): Promise<void>;
411
677
  /**
@@ -430,6 +696,8 @@ export declare class FilterAPI implements Disposable {
430
696
  * }
431
697
  * ```
432
698
  *
699
+ * @see {@link flushFramesSync} For sync iteration
700
+ * @see {@link receiveSync} For getting flushed frames
433
701
  * @see {@link flush} For async version
434
702
  */
435
703
  flushSync(): void;
@@ -452,8 +720,9 @@ export declare class FilterAPI implements Disposable {
452
720
  * }
453
721
  * ```
454
722
  *
723
+ * @see {@link process} For frame processing
455
724
  * @see {@link flush} For manual flush
456
- * @see {@link frames} For complete pipeline
725
+ * @see {@link flushFramesSync} For sync version
457
726
  */
458
727
  flushFrames(): AsyncGenerator<Frame>;
459
728
  /**
@@ -476,6 +745,8 @@ export declare class FilterAPI implements Disposable {
476
745
  * }
477
746
  * ```
478
747
  *
748
+ * @see {@link processSync} For frame processing
749
+ * @see {@link flushSync} For manual flush
479
750
  * @see {@link flushFrames} For async version
480
751
  */
481
752
  flushFramesSync(): Generator<Frame>;
@@ -500,6 +771,10 @@ export declare class FilterAPI implements Disposable {
500
771
  * frame.free();
501
772
  * }
502
773
  * ```
774
+ *
775
+ * @see {@link process} For frame processing
776
+ * @see {@link flush} For flushing filter
777
+ * @see {@link receiveSync} For synchronous version
503
778
  */
504
779
  receive(): Promise<Frame | null>;
505
780
  /**
@@ -525,6 +800,8 @@ export declare class FilterAPI implements Disposable {
525
800
  * }
526
801
  * ```
527
802
  *
803
+ * @see {@link processSync} For frame processing
804
+ * @see {@link flushSync} For flushing filter
528
805
  * @see {@link receive} For async version
529
806
  */
530
807
  receiveSync(): Frame | null;
@@ -591,6 +868,20 @@ export declare class FilterAPI implements Disposable {
591
868
  * @see {@link sendCommand} For immediate commands
592
869
  */
593
870
  queueCommand(target: string, cmd: string, arg: string, ts: number, flags?: AVFilterCmdFlag): void;
871
+ /**
872
+ * Pipe decoded frames to a filter component or encoder.
873
+ *
874
+ * @param target - Filter to receive frames or encoder to encode frames
875
+ *
876
+ * @returns Scheduler for continued chaining
877
+ *
878
+ * @example
879
+ * ```typescript
880
+ * decoder.pipeTo(filter).pipeTo(encoder)
881
+ * ```
882
+ */
883
+ pipeTo(target: FilterAPI): Scheduler<Frame>;
884
+ pipeTo(target: Encoder): Scheduler<Frame>;
594
885
  /**
595
886
  * Free filter resources.
596
887
  *
@@ -605,6 +896,36 @@ export declare class FilterAPI implements Disposable {
605
896
  * @see {@link Symbol.dispose} For automatic cleanup
606
897
  */
607
898
  close(): void;
899
+ /**
900
+ * Worker loop for push-based processing.
901
+ *
902
+ * @internal
903
+ */
904
+ private runWorker;
905
+ /**
906
+ * Send frame to input queue.
907
+ *
908
+ * @param frame - Frame to send
909
+ *
910
+ * @internal
911
+ */
912
+ private sendToQueue;
913
+ /**
914
+ * Receive frame from output queue.
915
+ *
916
+ * @returns Frame from output queue or null if closed
917
+ *
918
+ * @internal
919
+ */
920
+ private receiveFrame;
921
+ /**
922
+ * Flush the entire filter pipeline.
923
+ *
924
+ * Propagates flush through worker, output queue, and next component.
925
+ *
926
+ * @internal
927
+ */
928
+ private flushPipeline;
608
929
  /**
609
930
  * Initialize filter graph from first frame.
610
931
  *
@@ -640,6 +961,51 @@ export declare class FilterAPI implements Disposable {
640
961
  * @see {@link initialize} For async version
641
962
  */
642
963
  private initializeSync;
964
+ /**
965
+ * Check if frame properties changed and handle according to dropOnChange/allowReinit options.
966
+ *
967
+ * Implements FFmpeg's IFILTER_FLAG_DROPCHANGED and IFILTER_FLAG_REINIT logic
968
+ *
969
+ * @param frame - Frame to check
970
+ *
971
+ * @returns true if frame should be processed, false if frame should be dropped
972
+ *
973
+ * @throws {Error} If format changed and allowReinit is false
974
+ *
975
+ * @internal
976
+ */
977
+ private checkFramePropertiesChanged;
978
+ /**
979
+ * Calculate timeBase from frame based on media type and CFR option.
980
+ *
981
+ * Implements FFmpeg's ifilter_parameters_from_frame logic:
982
+ * - Audio: Always { 1, sample_rate }
983
+ * - Video CFR: 1/framerate (inverse of framerate)
984
+ * - Video VFR: Use frame.timeBase
985
+ *
986
+ * @param frame - Input frame
987
+ *
988
+ * @returns Calculated timeBase
989
+ *
990
+ * @internal
991
+ */
992
+ private calculateTimeBase;
993
+ /**
994
+ * Post-process output frame from buffersink.
995
+ *
996
+ * Applies FFmpeg's fg_output_step() behavior:
997
+ * 1. Sets frame.timeBase from buffersink (filters can change timeBase, e.g., aresample)
998
+ * 2. Calculates video frame duration from frame rate if not set
999
+ *
1000
+ * This must be called AFTER buffersinkGetFrame() for every output frame.
1001
+ *
1002
+ * @param frame - Output frame from buffersink
1003
+ *
1004
+ * @throws {Error} If buffersink context not available
1005
+ *
1006
+ * @internal
1007
+ */
1008
+ private postProcessOutputFrame;
643
1009
  /**
644
1010
  * Create buffer source with frame parameters.
645
1011
  *