node-av 2.0.0 → 2.1.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 (123) hide show
  1. package/README.md +10 -2
  2. package/binding.gyp +12 -0
  3. package/dist/api/bitstream-filter.d.ts +132 -0
  4. package/dist/api/bitstream-filter.js +198 -0
  5. package/dist/api/bitstream-filter.js.map +1 -1
  6. package/dist/api/decoder.d.ts +145 -0
  7. package/dist/api/decoder.js +225 -0
  8. package/dist/api/decoder.js.map +1 -1
  9. package/dist/api/encoder.d.ts +206 -0
  10. package/dist/api/encoder.js +315 -0
  11. package/dist/api/encoder.js.map +1 -1
  12. package/dist/api/filter-presets.d.ts +92 -0
  13. package/dist/api/filter-presets.js +92 -0
  14. package/dist/api/filter-presets.js.map +1 -1
  15. package/dist/api/filter.d.ts +225 -0
  16. package/dist/api/filter.js +363 -0
  17. package/dist/api/filter.js.map +1 -1
  18. package/dist/api/hardware.d.ts +17 -0
  19. package/dist/api/hardware.js +17 -0
  20. package/dist/api/hardware.js.map +1 -1
  21. package/dist/api/io-stream.d.ts +6 -0
  22. package/dist/api/io-stream.js +2 -0
  23. package/dist/api/io-stream.js.map +1 -1
  24. package/dist/api/media-input.d.ts +207 -1
  25. package/dist/api/media-input.js +353 -0
  26. package/dist/api/media-input.js.map +1 -1
  27. package/dist/api/media-output.d.ts +132 -1
  28. package/dist/api/media-output.js +339 -0
  29. package/dist/api/media-output.js.map +1 -1
  30. package/dist/api/pipeline.d.ts +65 -0
  31. package/dist/api/pipeline.js +61 -0
  32. package/dist/api/pipeline.js.map +1 -1
  33. package/dist/api/types.d.ts +7 -0
  34. package/dist/api/utils.js +2 -0
  35. package/dist/api/utils.js.map +1 -1
  36. package/dist/lib/audio-fifo.d.ts +103 -0
  37. package/dist/lib/audio-fifo.js +109 -0
  38. package/dist/lib/audio-fifo.js.map +1 -1
  39. package/dist/lib/binding.d.ts +1 -0
  40. package/dist/lib/binding.js.map +1 -1
  41. package/dist/lib/bitstream-filter-context.d.ts +79 -0
  42. package/dist/lib/bitstream-filter-context.js +83 -0
  43. package/dist/lib/bitstream-filter-context.js.map +1 -1
  44. package/dist/lib/bitstream-filter.d.ts +2 -0
  45. package/dist/lib/bitstream-filter.js +2 -0
  46. package/dist/lib/bitstream-filter.js.map +1 -1
  47. package/dist/lib/codec-context.d.ts +168 -0
  48. package/dist/lib/codec-context.js +178 -0
  49. package/dist/lib/codec-context.js.map +1 -1
  50. package/dist/lib/codec-parameters.d.ts +3 -0
  51. package/dist/lib/codec-parameters.js +3 -0
  52. package/dist/lib/codec-parameters.js.map +1 -1
  53. package/dist/lib/codec-parser.d.ts +6 -0
  54. package/dist/lib/codec-parser.js +6 -0
  55. package/dist/lib/codec-parser.js.map +1 -1
  56. package/dist/lib/codec.d.ts +12 -0
  57. package/dist/lib/codec.js +12 -0
  58. package/dist/lib/codec.js.map +1 -1
  59. package/dist/lib/dictionary.d.ts +16 -0
  60. package/dist/lib/dictionary.js +16 -0
  61. package/dist/lib/dictionary.js.map +1 -1
  62. package/dist/lib/error.d.ts +8 -0
  63. package/dist/lib/error.js +9 -0
  64. package/dist/lib/error.js.map +1 -1
  65. package/dist/lib/filter-context.d.ts +100 -0
  66. package/dist/lib/filter-context.js +104 -0
  67. package/dist/lib/filter-context.js.map +1 -1
  68. package/dist/lib/filter-graph.d.ts +80 -0
  69. package/dist/lib/filter-graph.js +84 -0
  70. package/dist/lib/filter-graph.js.map +1 -1
  71. package/dist/lib/filter-inout.d.ts +1 -0
  72. package/dist/lib/filter-inout.js +1 -0
  73. package/dist/lib/filter-inout.js.map +1 -1
  74. package/dist/lib/filter.d.ts +2 -0
  75. package/dist/lib/filter.js +2 -0
  76. package/dist/lib/filter.js.map +1 -1
  77. package/dist/lib/format-context.d.ts +338 -2
  78. package/dist/lib/format-context.js +355 -3
  79. package/dist/lib/format-context.js.map +1 -1
  80. package/dist/lib/frame.d.ts +41 -0
  81. package/dist/lib/frame.js +43 -0
  82. package/dist/lib/frame.js.map +1 -1
  83. package/dist/lib/hardware-device-context.d.ts +8 -0
  84. package/dist/lib/hardware-device-context.js +8 -0
  85. package/dist/lib/hardware-device-context.js.map +1 -1
  86. package/dist/lib/hardware-frames-context.d.ts +55 -0
  87. package/dist/lib/hardware-frames-context.js +57 -0
  88. package/dist/lib/hardware-frames-context.js.map +1 -1
  89. package/dist/lib/input-format.d.ts +43 -3
  90. package/dist/lib/input-format.js +48 -0
  91. package/dist/lib/input-format.js.map +1 -1
  92. package/dist/lib/io-context.d.ts +212 -0
  93. package/dist/lib/io-context.js +228 -0
  94. package/dist/lib/io-context.js.map +1 -1
  95. package/dist/lib/log.d.ts +2 -0
  96. package/dist/lib/log.js +2 -0
  97. package/dist/lib/log.js.map +1 -1
  98. package/dist/lib/native-types.d.ts +39 -1
  99. package/dist/lib/option.d.ts +90 -0
  100. package/dist/lib/option.js +97 -0
  101. package/dist/lib/option.js.map +1 -1
  102. package/dist/lib/output-format.d.ts +4 -0
  103. package/dist/lib/output-format.js +4 -0
  104. package/dist/lib/output-format.js.map +1 -1
  105. package/dist/lib/packet.d.ts +7 -0
  106. package/dist/lib/packet.js +7 -0
  107. package/dist/lib/packet.js.map +1 -1
  108. package/dist/lib/rational.d.ts +1 -0
  109. package/dist/lib/rational.js +1 -0
  110. package/dist/lib/rational.js.map +1 -1
  111. package/dist/lib/software-resample-context.d.ts +64 -0
  112. package/dist/lib/software-resample-context.js +66 -0
  113. package/dist/lib/software-resample-context.js.map +1 -1
  114. package/dist/lib/software-scale-context.d.ts +98 -0
  115. package/dist/lib/software-scale-context.js +102 -0
  116. package/dist/lib/software-scale-context.js.map +1 -1
  117. package/dist/lib/stream.d.ts +1 -0
  118. package/dist/lib/stream.js +1 -0
  119. package/dist/lib/stream.js.map +1 -1
  120. package/dist/lib/utilities.d.ts +60 -0
  121. package/dist/lib/utilities.js +60 -0
  122. package/dist/lib/utilities.js.map +1 -1
  123. package/package.json +13 -13
@@ -48,8 +48,11 @@ export declare class FilterAPI implements Disposable {
48
48
  private isClosed;
49
49
  /**
50
50
  * @param graph - Filter graph instance
51
+ *
51
52
  * @param description - Filter description string
53
+ *
52
54
  * @param options - Filter options
55
+ *
53
56
  * @internal
54
57
  */
55
58
  private constructor();
@@ -63,7 +66,9 @@ export declare class FilterAPI implements Disposable {
63
66
  * Direct mapping to avfilter_graph_parse_ptr() and avfilter_graph_config().
64
67
  *
65
68
  * @param description - Filter graph description
69
+ *
66
70
  * @param options - Filter options including required timeBase
71
+ *
67
72
  * @returns Configured filter instance
68
73
  *
69
74
  * @throws {Error} If filter creation or configuration fails
@@ -167,6 +172,7 @@ export declare class FilterAPI implements Disposable {
167
172
  * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
168
173
  *
169
174
  * @param frame - Input frame to process (or null to flush)
175
+ *
170
176
  * @returns Filtered frame or null if buffered
171
177
  *
172
178
  * @throws {Error} If filter is closed with non-null frame
@@ -197,6 +203,49 @@ export declare class FilterAPI implements Disposable {
197
203
  * @see {@link flush} For end-of-stream handling
198
204
  */
199
205
  process(frame: Frame | null): Promise<Frame | null>;
206
+ /**
207
+ * Process a frame through the filter synchronously.
208
+ * Synchronous version of process.
209
+ *
210
+ * Applies filter operations to input frame.
211
+ * On first frame, automatically builds filter graph with frame properties.
212
+ * May buffer frames internally before producing output.
213
+ * Hardware frames context is automatically detected from frame.
214
+ * Returns null if filter is closed and frame is null.
215
+ *
216
+ * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
217
+ *
218
+ * @param frame - Input frame to process (or null to flush)
219
+ *
220
+ * @returns Filtered frame or null if buffered
221
+ *
222
+ * @throws {Error} If filter is closed with non-null frame
223
+ *
224
+ * @throws {FFmpegError} If processing fails
225
+ *
226
+ * @example
227
+ * ```typescript
228
+ * const output = filter.processSync(inputFrame);
229
+ * if (output) {
230
+ * console.log(`Got filtered frame: pts=${output.pts}`);
231
+ * output.free();
232
+ * }
233
+ * ```
234
+ *
235
+ * @example
236
+ * ```typescript
237
+ * // Process frame - may buffer internally
238
+ * const output = filter.processSync(frame);
239
+ * if (output) {
240
+ * // Got output immediately
241
+ * yield output;
242
+ * }
243
+ * // For buffered frames, use the framesSync() generator
244
+ * ```
245
+ *
246
+ * @see {@link process} For async version
247
+ */
248
+ processSync(frame: Frame | null): Frame | null;
200
249
  /**
201
250
  * Process multiple frames at once.
202
251
  *
@@ -204,6 +253,7 @@ export declare class FilterAPI implements Disposable {
204
253
  * Useful for filters that buffer multiple frames.
205
254
  *
206
255
  * @param frames - Array of input frames
256
+ *
207
257
  * @returns Array of all output frames
208
258
  *
209
259
  * @throws {Error} If filter not ready
@@ -222,6 +272,33 @@ export declare class FilterAPI implements Disposable {
222
272
  * @see {@link process} For single frame processing
223
273
  */
224
274
  processMultiple(frames: Frame[]): Promise<Frame[]>;
275
+ /**
276
+ * Process multiple frames at once synchronously.
277
+ * Synchronous version of processMultiple.
278
+ *
279
+ * Processes batch of frames and drains all output.
280
+ * Useful for filters that buffer multiple frames.
281
+ *
282
+ * @param frames - Array of input frames
283
+ *
284
+ * @returns Array of all output frames
285
+ *
286
+ * @throws {Error} If filter not ready
287
+ *
288
+ * @throws {FFmpegError} If processing fails
289
+ *
290
+ * @example
291
+ * ```typescript
292
+ * const outputs = filter.processMultipleSync([frame1, frame2, frame3]);
293
+ * for (const output of outputs) {
294
+ * console.log(`Output frame: pts=${output.pts}`);
295
+ * output.free();
296
+ * }
297
+ * ```
298
+ *
299
+ * @see {@link processMultiple} For async version
300
+ */
301
+ processMultipleSync(frames: Frame[]): Frame[];
225
302
  /**
226
303
  * Process frame stream through filter.
227
304
  *
@@ -230,7 +307,9 @@ export declare class FilterAPI implements Disposable {
230
307
  * Frees input frames after processing.
231
308
  *
232
309
  * @param frames - Async generator of input frames
310
+ *
233
311
  * @yields {Frame} Filtered frames
312
+ *
234
313
  * @throws {Error} If filter not ready
235
314
  *
236
315
  * @throws {FFmpegError} If processing fails
@@ -264,6 +343,50 @@ export declare class FilterAPI implements Disposable {
264
343
  * @see {@link flush} For end-of-stream handling
265
344
  */
266
345
  frames(frames: AsyncGenerator<Frame>): AsyncGenerator<Frame>;
346
+ /**
347
+ * Process frame stream through filter synchronously.
348
+ * Synchronous version of frames.
349
+ *
350
+ * High-level sync generator for filtering frame streams.
351
+ * Automatically handles buffering and flushing.
352
+ * Frees input frames after processing.
353
+ *
354
+ * @param frames - Generator of input frames
355
+ *
356
+ * @yields {Frame} Filtered frames
357
+ *
358
+ * @throws {Error} If filter not ready
359
+ *
360
+ * @throws {FFmpegError} If processing fails
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * // Filter decoded frames
365
+ * for (const frame of filter.framesSync(decoder.framesSync(packets))) {
366
+ * encoder.encodeSync(frame);
367
+ * frame.free();
368
+ * }
369
+ * ```
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * // Chain filters
374
+ * const filter1 = await FilterAPI.create('scale=640:480', {
375
+ * timeBase: video.timeBase
376
+ * });
377
+ * const filter2 = await FilterAPI.create('rotate=PI/4', {
378
+ * timeBase: video.timeBase
379
+ * });
380
+ *
381
+ * for (const frame of filter2.framesSync(filter1.framesSync(input))) {
382
+ * // Process filtered frames
383
+ * frame.free();
384
+ * }
385
+ * ```
386
+ *
387
+ * @see {@link frames} For async version
388
+ */
389
+ framesSync(frames: Generator<Frame>): Generator<Frame>;
267
390
  /**
268
391
  * Flush filter and signal end-of-stream.
269
392
  *
@@ -289,6 +412,31 @@ export declare class FilterAPI implements Disposable {
289
412
  * @see {@link frames} For complete pipeline
290
413
  */
291
414
  flush(): Promise<void>;
415
+ /**
416
+ * Flush filter and signal end-of-stream synchronously.
417
+ * Synchronous version of flush.
418
+ *
419
+ * Sends null frame to flush buffered data.
420
+ * Must call receiveSync() to get flushed frames.
421
+ * Does nothing if filter is closed or was never initialized.
422
+ *
423
+ * Direct mapping to av_buffersrc_add_frame(NULL).
424
+ *
425
+ * @throws {FFmpegError} If flush fails
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * filter.flushSync();
430
+ * // Get remaining frames
431
+ * let frame;
432
+ * while ((frame = filter.receiveSync()) !== null) {
433
+ * frame.free();
434
+ * }
435
+ * ```
436
+ *
437
+ * @see {@link flush} For async version
438
+ */
439
+ flushSync(): void;
292
440
  /**
293
441
  * Flush filter and yield remaining frames.
294
442
  *
@@ -312,6 +460,29 @@ export declare class FilterAPI implements Disposable {
312
460
  * @see {@link frames} For complete pipeline
313
461
  */
314
462
  flushFrames(): AsyncGenerator<Frame>;
463
+ /**
464
+ * Flush filter and yield remaining frames synchronously.
465
+ * Synchronous version of flushFrames.
466
+ *
467
+ * Convenient sync generator for flushing.
468
+ * Combines flush and receive operations.
469
+ * Returns immediately if filter is closed or was never initialized.
470
+ *
471
+ * @yields {Frame} Remaining frames from filter
472
+ *
473
+ * @throws {FFmpegError} If flush fails
474
+ *
475
+ * @example
476
+ * ```typescript
477
+ * for (const frame of filter.flushFramesSync()) {
478
+ * console.log(`Flushed frame: pts=${frame.pts}`);
479
+ * frame.free();
480
+ * }
481
+ * ```
482
+ *
483
+ * @see {@link flushFrames} For async version
484
+ */
485
+ flushFramesSync(): Generator<Frame>;
315
486
  /**
316
487
  * Receive buffered frame from filter.
317
488
  *
@@ -335,6 +506,32 @@ export declare class FilterAPI implements Disposable {
335
506
  * ```
336
507
  */
337
508
  receive(): Promise<Frame | null>;
509
+ /**
510
+ * Receive buffered frame from filter synchronously.
511
+ * Synchronous version of receive.
512
+ *
513
+ * Drains frames buffered by the filter.
514
+ * Call repeatedly until null to get all buffered frames.
515
+ * Returns null if filter is closed, not initialized, or no frames available.
516
+ *
517
+ * Direct mapping to av_buffersink_get_frame().
518
+ *
519
+ * @returns Buffered frame or null if none available
520
+ *
521
+ * @throws {FFmpegError} If receiving fails
522
+ *
523
+ * @example
524
+ * ```typescript
525
+ * let frame;
526
+ * while ((frame = filter.receiveSync()) !== null) {
527
+ * console.log(`Received frame: pts=${frame.pts}`);
528
+ * frame.free();
529
+ * }
530
+ * ```
531
+ *
532
+ * @see {@link receive} For async version
533
+ */
534
+ receiveSync(): Frame | null;
338
535
  /**
339
536
  * Send command to filter.
340
537
  *
@@ -344,9 +541,13 @@ export declare class FilterAPI implements Disposable {
344
541
  * Direct mapping to avfilter_graph_send_command().
345
542
  *
346
543
  * @param target - Target filter name
544
+ *
347
545
  * @param cmd - Command name
546
+ *
348
547
  * @param arg - Command argument
548
+ *
349
549
  * @param flags - Command flags
550
+ *
350
551
  * @returns Response string from filter
351
552
  *
352
553
  * @throws {Error} If filter not ready
@@ -372,10 +573,15 @@ export declare class FilterAPI implements Disposable {
372
573
  * Direct mapping to avfilter_graph_queue_command().
373
574
  *
374
575
  * @param target - Target filter name
576
+ *
375
577
  * @param cmd - Command name
578
+ *
376
579
  * @param arg - Command argument
580
+ *
377
581
  * @param ts - Timestamp for execution
582
+ *
378
583
  * @param flags - Command flags
584
+ *
379
585
  * @throws {Error} If filter not ready
380
586
  *
381
587
  * @throws {FFmpegError} If queue fails
@@ -419,6 +625,25 @@ export declare class FilterAPI implements Disposable {
419
625
  * @internal
420
626
  */
421
627
  private initialize;
628
+ /**
629
+ * Initialize filter graph from first frame synchronously.
630
+ * Synchronous version of initialize.
631
+ *
632
+ * Creates and configures filter graph components.
633
+ * Sets buffer source parameters from frame properties.
634
+ * Automatically configures hardware frames context if present.
635
+ *
636
+ * @param frame - First frame to process, provides format and hw context
637
+ *
638
+ * @throws {Error} If initialization fails
639
+ *
640
+ * @throws {FFmpegError} If configuration fails
641
+ *
642
+ * @internal
643
+ *
644
+ * @see {@link initialize} For async version
645
+ */
646
+ private initializeSync;
422
647
  /**
423
648
  * Create buffer source with frame parameters.
424
649
  *