bare-ffmpeg 1.0.0-2 → 1.0.0-20

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 (47) hide show
  1. package/CMakeLists.txt +10 -3
  2. package/README.md +990 -0
  3. package/binding.cc +3150 -0
  4. package/cmake/ports/ffmpeg/port.cmake +513 -0
  5. package/cmake/ports/opus/patches/01-windows-clang.patch +52 -0
  6. package/cmake/ports/opus/port.cmake +42 -0
  7. package/cmake/ports/svt-av1/port.cmake +42 -0
  8. package/cmake/ports/x264/patches/01-windows-clang.patch +33 -0
  9. package/cmake/ports/x264/port.cmake +157 -0
  10. package/index.js +14 -4
  11. package/lib/audio-fifo.js +47 -0
  12. package/lib/channel-layout.js +35 -0
  13. package/lib/codec-context.js +92 -15
  14. package/lib/codec-parameters.js +154 -8
  15. package/lib/codec.js +19 -0
  16. package/lib/constants.js +163 -8
  17. package/lib/dictionary.js +10 -15
  18. package/lib/errors.js +38 -0
  19. package/lib/format-context.js +62 -31
  20. package/lib/frame.js +87 -16
  21. package/lib/image.js +22 -0
  22. package/lib/input-format.js +8 -3
  23. package/lib/io-context.js +29 -6
  24. package/lib/log.js +16 -0
  25. package/lib/output-format.js +4 -0
  26. package/lib/packet.js +88 -13
  27. package/lib/rational.js +35 -1
  28. package/lib/resampler.js +63 -0
  29. package/lib/samples.js +49 -0
  30. package/lib/scaler.js +8 -7
  31. package/lib/stream.js +37 -12
  32. package/package.json +7 -4
  33. package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
  34. package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
  35. package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
  36. package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
  37. package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
  38. package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
  39. package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
  40. package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
  41. package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
  42. package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
  43. package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
  44. package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
  45. package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
  46. package/binding.c +0 -2128
  47. package/lib/reference-counted.js +0 -39
package/README.md CHANGED
@@ -6,6 +6,996 @@ Low-level FFmpeg bindings for Bare.
6
6
  npm i bare-ffmpeg
7
7
  ```
8
8
 
9
+ ## API
10
+
11
+ ### `IOContext`
12
+
13
+ The `IOContext` API provides functionality to create input/output contexts for media files.
14
+
15
+ ```js
16
+ const io = new ffmpeg.IOContext(buffer)
17
+ ```
18
+
19
+ Parameters:
20
+
21
+ - `buffer` (`Buffer`): The media data buffer
22
+
23
+ **Returns**: A new `IOContext` instance
24
+
25
+ Example:
26
+
27
+ ```js
28
+ const image = require('./fixtures/image/sample.jpeg', {
29
+ with: { type: 'binary' }
30
+ })
31
+ const io = new ffmpeg.IOContext(image)
32
+ io.destroy()
33
+ ```
34
+
35
+ #### Methods
36
+
37
+ ##### `IOContext.destroy()`
38
+
39
+ Destroys the `IOContext` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
40
+
41
+ **Returns**: `void`
42
+
43
+ ### `FormatContext`
44
+
45
+ The `FormatContext` API provides the base functionality for reading and writing media files.
46
+
47
+ > This is the base class that `InputFormatContext` and `OutputFormatContext` extend.
48
+
49
+ #### Properties
50
+
51
+ ##### `FormatContext.io`
52
+
53
+ Gets the IO context associated with this format context.
54
+
55
+ **Returns**: `IOContext` instance or `null`
56
+
57
+ ##### `FormatContext.streams`
58
+
59
+ Gets the array of media streams.
60
+
61
+ **Returns**: Array of `Stream` instances
62
+
63
+ #### Methods
64
+
65
+ ##### `FormatContext.readFrame(packet)`
66
+
67
+ Reads the next frame from the media file into a packet.
68
+
69
+ Parameters:
70
+
71
+ - `packet` (`Packet`): The packet to store the frame data
72
+
73
+ **Returns**: `boolean` indicating if a frame was read
74
+
75
+ ##### `FormatContext.getBestStream(type)`
76
+
77
+ Gets the best stream of the specified media type.
78
+
79
+ Parameters:
80
+
81
+ - `type` (`number`): The media type from `ffmpeg.constants.mediaTypes`
82
+
83
+ **Returns**: `Stream` instance or `null` if not found
84
+
85
+ ##### `FormatContext.destroy()`
86
+
87
+ Destroys the `FormatContext` and frees all associated resources including streams. Automatically called when the object is managed by a `using` declaration.
88
+
89
+ **Returns**: `void`
90
+
91
+ ### `InputFormatContext`
92
+
93
+ The `InputFormatContext` API extends `FormatContext` to provide functionality for reading media files.
94
+
95
+ ```js
96
+ const format = new ffmpeg.InputFormatContext(io, options[, url])
97
+ ```
98
+
99
+ Parameters:
100
+
101
+ - `io` (`IOContext` | `InputFormat`): The IO context or input format. The ownership of `io` is transferred.
102
+ - `options` (`Dictionary`): Format options. Required when using `InputFormat`, ignored when using `IOContext`. The ownership of `options` is transferred.
103
+ - `url` (`string`, optional): Media source URL. Defaults to a platform-specific value
104
+
105
+ **Returns**: A new `InputFormatContext` instance
106
+
107
+ #### Methods
108
+
109
+ ##### `InputFormatContext.destroy()`
110
+
111
+ Destroys the `InputFormatContext` and closes the input format. Automatically called when the object is managed by a `using` declaration.
112
+
113
+ **Returns**: void
114
+
115
+ ### `OutputFormatContext`
116
+
117
+ The `OutputFormatContext` API extends `FormatContext` to provide functionality for writing media files.
118
+
119
+ ```js
120
+ const format = new ffmpeg.OutputFormatContext(formatName, io)
121
+ ```
122
+
123
+ Parameters:
124
+
125
+ - `formatName` (`string`): The output format name (e.g., `'mp4'`, `'avi'`)
126
+ - `io` (`IOContext`): The IO context for writing. The ownership of `io` is transferred.
127
+
128
+ **Returns**: A new `OutputFormatContext` instance
129
+
130
+ #### Methods
131
+
132
+ ##### `OutputFormatContext.createStream(codec)`
133
+
134
+ Creates a new stream in the output format.
135
+
136
+ Parameters:
137
+
138
+ - `codec` (`Codec`): The codec to use for the stream
139
+
140
+ **Returns**: A new `Stream` instance
141
+
142
+ ##### `OutputFormatContext.destroy()`
143
+
144
+ Destroys the `OutputFormatContext` and closes the output format. Automatically called when the object is managed by a `using` declaration.
145
+
146
+ **Returns**: `void`
147
+
148
+ ### `Codec`
149
+
150
+ The `Codec` API provides access to FFmpeg codecs for encoding and decoding.
151
+
152
+ #### Static properties
153
+
154
+ ##### `Codec.H264`
155
+
156
+ H.264 video codec.
157
+
158
+ **Returns**: `Codec` instance
159
+
160
+ ##### `Codec.MJPEG`
161
+
162
+ Motion JPEG video codec.
163
+
164
+ **Returns**: `Codec` instance
165
+
166
+ ##### `Codec.AAC`
167
+
168
+ AAC audio codec.
169
+
170
+ **Returns**: `Codec` instance
171
+
172
+ ##### `Codec.AV1`
173
+
174
+ AV1 video codec.
175
+
176
+ **Returns**: `Codec` instance
177
+
178
+ #### Properties
179
+
180
+ ##### `Codec.id`
181
+
182
+ Gets the codec ID.
183
+
184
+ **Returns**: `number`
185
+
186
+ ##### `Codec.encoder`
187
+
188
+ Gets the encoder for this codec.
189
+
190
+ **Returns**: `Encoder` instance
191
+
192
+ ##### `Codec.decoder`
193
+
194
+ Gets the decoder for this codec.
195
+
196
+ **Returns**: `Decoder` instance
197
+
198
+ #### Methods
199
+
200
+ ##### `Codec.for(id)`
201
+
202
+ Gets a codec by ID.
203
+
204
+ Parameters:
205
+
206
+ - `id` (`number`): The codec ID
207
+
208
+ **Returns**: `Codec` instance
209
+
210
+ ### `CodecContext`
211
+
212
+ The `CodecContext` API provides functionality to encode or decode media frames.
213
+
214
+ ```js
215
+ const codecCtx = new ffmpeg.CodecContext(codec)
216
+ ```
217
+
218
+ Parameters:
219
+
220
+ - `codec` (Codec): The codec to use (e.g., `ffmpeg.Codec.H264.encoder`)
221
+
222
+ **Returns**: A new `CodecContext` instance
223
+
224
+ #### Properties
225
+
226
+ ##### `CodecContext.timeBase`
227
+
228
+ Gets or sets the time base for the codec context.
229
+
230
+ **Returns**: `Rational` instance
231
+
232
+ ##### `CodecContext.pixelFormat`
233
+
234
+ Gets or sets the pixel format for video codecs.
235
+
236
+ **Returns**: `number` (pixel format constant)
237
+
238
+ ##### `CodecContext.width`
239
+
240
+ Gets or sets the frame width for video codecs.
241
+
242
+ **Returns**: `number`
243
+
244
+ ##### `CodecContext.height`
245
+
246
+ Gets or sets the frame height for video codecs.
247
+
248
+ **Returns**: `number`
249
+
250
+ #### Methods
251
+
252
+ ##### `CodecContext.open([options])`
253
+
254
+ Opens the codec context for encoding/decoding.
255
+
256
+ Parameters:
257
+
258
+ - `options` (`Dictionary`, optional): Codec-specific options
259
+
260
+ **Returns**: `CodecContext` instance (for chaining)
261
+
262
+ ##### `CodecContext.sendFrame(frame)`
263
+
264
+ Sends a frame to the encoder.
265
+
266
+ Parameters:
267
+
268
+ - `frame` (`Frame`): The frame to encode
269
+
270
+ **Returns**: `boolean` indicating if the frame was sent
271
+
272
+ ##### `CodecContext.receiveFrame(frame)`
273
+
274
+ Receives a decoded frame from the decoder.
275
+
276
+ Parameters:
277
+
278
+ - `frame` (`Frame`): The frame to store the decoded data
279
+
280
+ **Returns**: `boolean` indicating if a frame was received
281
+
282
+ ##### `CodecContext.sendPacket(packet)`
283
+
284
+ Sends a packet to the decoder.
285
+
286
+ Parameters:
287
+
288
+ - `packet` (`Packet`): The packet to decode
289
+
290
+ **Returns**: `boolean` indicating if the packet was sent
291
+
292
+ ##### `CodecContext.receivePacket(packet)`
293
+
294
+ Receives an encoded packet from the encoder.
295
+
296
+ Parameters:
297
+
298
+ - `packet` (`Packet`): The packet to store the encoded data
299
+
300
+ **Returns**: `boolean` indicating if a packet was received
301
+
302
+ ##### `CodecContext.destroy()`
303
+
304
+ Destroys the `CodecContext` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
305
+
306
+ **Returns**: `void`
307
+
308
+ ### `CodecParameters`
309
+
310
+ The `CodecParameters` API provides functionality to access codec parameters from streams.
311
+
312
+ ```js
313
+ const params = stream.codecParameters // Get from stream
314
+ ```
315
+
316
+ #### Properties
317
+
318
+ ##### `CodecParameters.type`
319
+
320
+ General type of the encoded data.
321
+
322
+ **Returns**: `number`
323
+
324
+ ##### `CodecParameters.id`
325
+
326
+ Specific type of the encoded data (the codec used).
327
+
328
+ **Returns**: `number`
329
+
330
+ ##### `CodecParameters.tag`
331
+
332
+ Additional information about the codec (corresponds to the AVI FOURCC).
333
+
334
+ **Returns**: `number`
335
+
336
+ ##### `CodecParameters.bitRate`
337
+
338
+ Gets the bit rate.
339
+
340
+ **Returns**: `number`
341
+
342
+ ##### `CodecParameters.bitsPerCodedSample`
343
+
344
+ Gets the bits per coded sample.
345
+
346
+ **Returns**: `number`
347
+
348
+ ##### `CodecParameters.bitsPerRawSample`
349
+
350
+ Gets the bits per raw sample.
351
+
352
+ **Returns**: `number`
353
+
354
+ ##### `CodecParameters.sampleRate`
355
+
356
+ Gets the sample rate for audio codecs.
357
+
358
+ **Returns**: `number`
359
+
360
+ ##### `CodecParameters.frameRate`
361
+
362
+ Gets the frame rate for video codecs.
363
+
364
+ **Returns**: `Rational`
365
+
366
+ ##### `CodecParameters.extraData`
367
+
368
+ Out-of-band global headers that may be used by some codecs.
369
+
370
+ **Returns**: `Buffer`
371
+
372
+ ##### `CodecParameters.profile`
373
+
374
+ Codec-specific bitstream restrictions that the stream conforms to.
375
+
376
+ **Returns**: `number`
377
+
378
+ ##### `CodecParameters.level`
379
+
380
+ Codec-specific bitstream restrictions that the stream conforms to.
381
+
382
+ **Returns**: `number`
383
+
384
+ ##### `CodecParameters.format`
385
+
386
+ Video: the pixel format, the value corresponds to AVPixelFormat.
387
+ Audio: the sample format, the value corresponds to AVSampleFormat.
388
+
389
+ **Returns**: `number`
390
+
391
+ ##### `CodecParameters.nbChannels`
392
+
393
+ Number of channels in the layout.
394
+
395
+ **Returns**: `number`
396
+
397
+ ##### `CodecParameters.channelLayout`
398
+
399
+ Gets or sets the channel layout, see `ffmpeg.constants.channelLayouts`
400
+
401
+ **Returns**: `ChannelLayout`
402
+
403
+ #### Methods
404
+
405
+ ##### `CodecParameters.fromContext(context)`
406
+
407
+ Copies parameters from a codec context.
408
+
409
+ Parameters:
410
+
411
+ - `context` (`CodecContext`): The codec context
412
+
413
+ **Returns**: `void`
414
+
415
+ ##### `CodecParameters.toContext(context)`
416
+
417
+ Copies parameters to a codec context.
418
+
419
+ Parameters:
420
+
421
+ - `context` (`CodecContext`): The codec context
422
+
423
+ **Returns**: `void`
424
+
425
+ ### `InputFormat`
426
+
427
+ The `InputFormat` API provides functionality to specify input format for media sources.
428
+
429
+ ```js
430
+ const format = new ffmpeg.InputFormat([name])
431
+ ```
432
+
433
+ Parameters:
434
+
435
+ - `name` (`string`, optional): The input format name. Defaults to a platform-specific value:
436
+ - `darwin`, `ios`: ``'avfoundation'`
437
+ - `linux`: `'v4l2'`
438
+ - `win32`: `'dshow'`
439
+
440
+ **Returns**: A new `InputFormat` instance
441
+
442
+ #### Methods
443
+
444
+ ##### `InputFormat.destroy()`
445
+
446
+ Destroys the `InputFormat` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
447
+
448
+ **Returns**: `void`
449
+
450
+ ### `OutputFormat`
451
+
452
+ The `OutputFormat` API provides functionality to specify output format for media files.
453
+
454
+ ```js
455
+ const format = new ffmpeg.OutputFormat(name)
456
+ ```
457
+
458
+ Parameters:
459
+
460
+ - `name` (`string`): The output format name (e.g., `'mp4'`, `'avi'`, `'mov'`)
461
+
462
+ **Returns**: A new `OutputFormat` instance
463
+
464
+ #### Methods
465
+
466
+ ##### `OutputFormat.destroy()`
467
+
468
+ Destroys the `OutputFormat` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
469
+
470
+ **Returns**: `void`
471
+
472
+ ### `Frame`
473
+
474
+ This structure describes decoded (raw) audio or video data.
475
+
476
+ ```js
477
+ const frame = new ffmpeg.Frame()
478
+ ```
479
+
480
+ **Returns**: A new `Frame` instance
481
+
482
+ #### Properties
483
+
484
+ ##### `Frame.width`
485
+
486
+ Gets or sets the frame width.
487
+
488
+ **Returns**: `number`
489
+
490
+ ##### `Frame.height`
491
+
492
+ Gets or sets the frame height.
493
+
494
+ **Returns**: `number`
495
+
496
+ ##### `Frame.pixelFormat`
497
+
498
+ Gets or sets the pixel format.
499
+
500
+ **Returns**: `number` (pixel format constant)
501
+
502
+ ##### `Frame.format`
503
+
504
+ Gets or sets the sample format for audio frames.
505
+
506
+ **Returns**: `number` (sample format constant)
507
+
508
+ ##### `Frame.channelLayout`
509
+
510
+ Gets or sets the channel layout for audio frames.
511
+
512
+ **Returns**: `number` (channel layout constant)
513
+
514
+ ##### `Frame.nbSamples`
515
+
516
+ Gets or sets the number of audio samples.
517
+
518
+ **Returns**: `number`
519
+
520
+ #### Methods
521
+
522
+ ##### `Frame.alloc()`
523
+
524
+ Allocates memory for the frame data.
525
+
526
+ **Returns**: `void`
527
+
528
+ ##### `Frame.destroy()`
529
+
530
+ Destroys the `Frame` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
531
+
532
+ **Returns**: `void`
533
+
534
+ ### `Packet`
535
+
536
+ This structure stores compressed data. It is typically exported by demuxers and then passed as input to decoders, or received as output from encoders and then passed to muxers.
537
+
538
+ ```js
539
+ const packet = new ffmpeg.Packet([buffer])
540
+ ```
541
+
542
+ Parameters:
543
+
544
+ - `buffer` (`Buffer`, optional): Initial packet data
545
+
546
+ **Returns**: A new `Packet` instance
547
+
548
+ #### Properties
549
+
550
+ ##### `Packet.data`
551
+
552
+ Gets the packet data buffer.
553
+
554
+ **Returns**: `Buffer`
555
+
556
+ ##### `Packet.streamIndex`
557
+
558
+ Gets the stream index this packet belongs to.
559
+
560
+ **Returns**: `number`
561
+
562
+ #### Methods
563
+
564
+ ##### `Packet.unref()`
565
+
566
+ Decrements the reference count and unreferences the packet.
567
+
568
+ **Returns**: `void`
569
+
570
+ ##### `Packet.destroy()`
571
+
572
+ Destroys the `Packet` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
573
+
574
+ **Returns**: `void`
575
+
576
+ ### `Image`
577
+
578
+ The `Image` API provides functionality to create and manage image buffers.
579
+
580
+ ```js
581
+ const image = new ffmpeg.Image(pixelFormat, width, height[, align])
582
+ ```
583
+
584
+ Parameters:
585
+
586
+ - `pixelFormat` (`number` | `string`): The pixel format
587
+ - `width` (`number`): The image width in pixels
588
+ - `height` (`number`): The image height in pixels
589
+ - `align` (`number`, optional): Memory alignment. Defaults to 1
590
+
591
+ **Returns**: A new `Image` instance
592
+
593
+ #### Properties
594
+
595
+ ##### `Image.pixelFormat`
596
+
597
+ Gets the pixel format.
598
+
599
+ **Returns**: `number`
600
+
601
+ ##### `Image.width`
602
+
603
+ Gets the image width.
604
+
605
+ **Returns**: `number`
606
+
607
+ ##### `Image.height`
608
+
609
+ Gets the image height.
610
+
611
+ **Returns**: `number`
612
+
613
+ ##### `Image.align`
614
+
615
+ Gets the memory alignment.
616
+
617
+ **Returns**: `number`
618
+
619
+ ##### `Image.data`
620
+
621
+ Gets the image data buffer.
622
+
623
+ **Returns**: `Buffer`
624
+
625
+ #### Methods
626
+
627
+ ##### `Image.fill(frame)`
628
+
629
+ Fills a frame with the image data.
630
+
631
+ Parameters:
632
+
633
+ - `frame` (`Frame`): The frame to fill
634
+
635
+ **Returns**: void
636
+
637
+ ##### `Image.read(frame)`
638
+
639
+ Reads image data from a frame into the image buffer.
640
+
641
+ Parameters:
642
+
643
+ - `frame` (`Frame`): The frame to read from
644
+
645
+ **Returns**: `void`
646
+
647
+ ##### `Image.lineSize([plane])`
648
+
649
+ Gets the line size for a specific plane.
650
+
651
+ Parameters:
652
+
653
+ - `plane` (`number`, optional): Plane index. Defaults to 0
654
+
655
+ **Returns**: `number`
656
+
657
+ #### Static methods
658
+
659
+ ##### `Image.lineSize(pixelFormat, width[, plane])`
660
+
661
+ Static method to get line size for a pixel format.
662
+
663
+ Parameters:
664
+
665
+ - `pixelFormat` (`number` | `string`): The pixel format
666
+ - `width` (`number`): The image width
667
+ - `plane` (`number`, optional): Plane index. Defaults to 0
668
+
669
+ **Returns**: `number`
670
+
671
+ ### `Rational`
672
+
673
+ The `Rational` API provides functionality to represent rational numbers (fractions).
674
+
675
+ ```js
676
+ const rational = new ffmpeg.Rational(numerator, denominator)
677
+ ```
678
+
679
+ Parameters:
680
+
681
+ - `numerator` (`number`): The numerator
682
+ - `denominator` (`number`): The denominator
683
+
684
+ **Returns**: A new `Rational` instance
685
+
686
+ #### Properties
687
+
688
+ ##### `Rational.numerator`
689
+
690
+ Gets the numerator.
691
+
692
+ **Returns**: `number`
693
+
694
+ ##### `Rational.denominator`
695
+
696
+ Gets the denominator.
697
+
698
+ **Returns**: `number`
699
+
700
+ ##### `Rational.valid`
701
+
702
+ Returns if true if rational describes a non-zero & non-negative quantity.
703
+
704
+ **Returns**: `number`
705
+
706
+ ##### `Rational.uninitialized`
707
+
708
+ Returns if true when is not set.
709
+
710
+ **Returns**: `number`
711
+
712
+ ##### `Rational.toNumber()`
713
+
714
+ see `av_q2d()`
715
+
716
+ **Returns**: `number`
717
+
718
+ ##### `static Rational.from(number)`
719
+
720
+ see `av_d2q()`
721
+
722
+ **Returns**: `Rational`
723
+
724
+ ##### `Rational.rescaleQ(number, timebaseA, timebaseB)`
725
+
726
+ see `av_rescale_q()`
727
+
728
+ **Returns**: `number`
729
+
730
+ ### `Stream`
731
+
732
+ The `Stream` API provides functionality to access media stream information and create decoders/encoders.
733
+
734
+ ```js
735
+ const stream = new ffmpeg.Stream(handle)
736
+ ```
737
+
738
+ Parameters:
739
+
740
+ - `handle` (`ArrayBuffer`): Internal stream handle
741
+
742
+ **Returns**: A new `Stream` instance
743
+
744
+ > Streams are typically obtained from format contexts: `const stream = format.streams[0]`
745
+
746
+ #### Properties
747
+
748
+ ##### `Stream.codecParameters`
749
+
750
+ Gets the codec parameters for this stream.
751
+
752
+ **Returns**: `CodecParameters` instance
753
+
754
+ ##### `Stream.codec`
755
+
756
+ Gets the codec for this stream
757
+
758
+ **Returns**: `Codec` instance
759
+
760
+ #### Methods
761
+
762
+ ##### `Stream.decoder()`
763
+
764
+ Creates and opens a decoder for this stream.
765
+
766
+ **Returns**: `CodecContext` instance
767
+
768
+ ##### `Stream.encoder()`
769
+
770
+ Creates and opens an encoder for this stream.
771
+
772
+ **Returns**: `CodecContext` instance
773
+
774
+ ### `Resampler`
775
+
776
+ The `Resampler` API provides functionality to convert audio between different sample rates, channel layouts, and sample formats.
777
+
778
+ ```js
779
+ const resampler = new ffmpeg.Resampler(
780
+ inputSampleRate,
781
+ inputChannelLayout,
782
+ inputSampleFormat,
783
+ outputSampleRate,
784
+ outputChannelLayout,
785
+ outputSampleFormat
786
+ )
787
+ ```
788
+
789
+ Parameters:
790
+
791
+ - `inputSampleRate` (`number`): Input sample rate in Hz
792
+ - `inputChannelLayout` (`number`): Input channel layout constant
793
+ - `inputSampleFormat` (`number`): Input sample format constant
794
+ - `outputSampleRate` (`number`): Output sample rate in Hz
795
+ - `outputChannelLayout` (`number`): Output channel layout constant
796
+ - `outputSampleFormat` (`number`): Output sample format constant
797
+
798
+ **Returns**: A new `Resampler` instance
799
+
800
+ #### Properties
801
+
802
+ ##### `Resampler.inputSampleRate`
803
+
804
+ Gets the input sample rate.
805
+
806
+ **Returns**: `number`
807
+
808
+ ##### `Resampler.outputSampleRate`
809
+
810
+ Gets the output sample rate.
811
+
812
+ **Returns**: `number`
813
+
814
+ ##### `Resampler.delay`
815
+
816
+ Gets the resampler delay in samples.
817
+
818
+ **Returns**: `number`
819
+
820
+ #### Methods
821
+
822
+ ##### `Resampler.convert(inputFrame, outputFrame)`
823
+
824
+ Converts audio data from input frame to output frame.
825
+
826
+ Parameters:
827
+
828
+ - `inputFrame` (`Frame`): The input audio frame
829
+ - `outputFrame` (`Frame`): The output audio frame
830
+
831
+ **Returns**: `number` of samples converted
832
+
833
+ ##### `Resampler.flush(outputFrame)`
834
+
835
+ Flushes any remaining samples in the resampler.
836
+
837
+ Parameters:
838
+
839
+ - `outputFrame` (`Frame`): The output audio frame
840
+
841
+ **Returns**: `number` of samples flushed
842
+
843
+ ##### `Resampler.destroy()`
844
+
845
+ Destroys the `Resampler` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
846
+
847
+ **Returns**: `void`
848
+
849
+ ### `Scaler`
850
+
851
+ The `Scaler` API provides functionality to scale and convert video frames between different pixel formats and resolutions.
852
+
853
+ ```js
854
+ const scaler = new ffmpeg.Scaler(
855
+ sourcePixelFormat,
856
+ sourceWidth,
857
+ sourceHeight,
858
+ targetPixelFormat,
859
+ targetWidth,
860
+ targetHeight
861
+ )
862
+ ```
863
+
864
+ Parameters:
865
+
866
+ - `sourcePixelFormat` (`number` | `string`): Source pixel format
867
+ - `sourceWidth` (`number`): Source width in pixels
868
+ - `sourceHeight` (`number`): Source height in pixels
869
+ - `targetPixelFormat` (`number` | `string`): Target pixel format
870
+ - `targetWidth` (`number`): Target width in pixels
871
+ - `targetHeight` (`number`): Target height in pixels
872
+
873
+ **Returns**: A new `Scaler` instance
874
+
875
+ #### Methods
876
+
877
+ ##### `Scaler.scale(source, target)`
878
+
879
+ Scales a source frame to a target frame.
880
+
881
+ Parameters:
882
+
883
+ - `source` (`Frame`): The source frame
884
+ - `target` (`Frame`): The target frame
885
+
886
+ **Returns**: `boolean` indicating success
887
+
888
+ ##### `Scaler.scale(source, y, height, target)`
889
+
890
+ Scales a portion of a source frame to a target frame.
891
+
892
+ Parameters:
893
+
894
+ - `source` (`Frame`): The source frame
895
+ - `y` (`number`): Starting Y coordinate
896
+ - `height` (`number`): Height to scale
897
+ - `target` (`Frame`): The target frame
898
+
899
+ **Returns**: `boolean` indicating success
900
+
901
+ ##### `Scaler.destroy()`
902
+
903
+ Destroys the `Scaler` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
904
+
905
+ **Returns**: `void`
906
+
907
+ ### `AudioFIFO`
908
+
909
+ The `AudioFIFO` API provides a first in first out buffer for audio samples. This is useful for buffering audio data between different processing stages.
910
+
911
+ ```js
912
+ const fifo = new ffmpeg.AudioFIFO(sampleFormat, channels, nbSamples)
913
+ ```
914
+
915
+ Parameters:
916
+
917
+ - `sampleFormat` (`number` | `string`): The audio sample format
918
+ - `channels` (`number`): Number of audio channels
919
+ - `nbSamples` (`number`): Initial buffer size in samples
920
+
921
+ **Returns**: A new `AudioFIFO` instance
922
+
923
+ Example:
924
+
925
+ ```js
926
+ const fifo = new ffmpeg.AudioFIFO(ffmpeg.constants.sampleFormats.S16, 2, 1024)
927
+ ```
928
+
929
+ #### Properties
930
+
931
+ ##### `AudioFIFO.size`
932
+
933
+ Gets the number of samples currently in the FIFO.
934
+
935
+ **Returns**: `number`
936
+
937
+ ##### `AudioFIFO.space`
938
+
939
+ Gets the number of samples that can be written to the FIFO.
940
+
941
+ **Returns**: `number`
942
+
943
+ #### Methods
944
+
945
+ ##### `AudioFIFO.write(frame)`
946
+
947
+ Writes samples from a frame to the FIFO. The FIFO will automatically grow if needed.
948
+
949
+ Parameters:
950
+
951
+ - `frame` (`Frame`): The audio frame containing samples to write
952
+
953
+ **Returns**: `number` of samples written
954
+
955
+ ##### `AudioFIFO.read(frame, nbSamples)`
956
+
957
+ Reads samples from the FIFO into a frame.
958
+
959
+ Parameters:
960
+
961
+ - `frame` (`Frame`): The frame to read samples into
962
+ - `nbSamples` (`number`): Number of samples to read
963
+
964
+ **Returns**: `number` of samples actually read
965
+
966
+ ##### `AudioFIFO.peek(frame, nbSamples)`
967
+
968
+ Reads samples from the FIFO without removing them.
969
+
970
+ Parameters:
971
+
972
+ - `frame` (`Frame`): The frame to read samples into
973
+ - `nbSamples` (`number`): Number of samples to peek
974
+
975
+ **Returns**: `number` of samples peeked
976
+
977
+ ##### `AudioFIFO.drain(nbSamples)`
978
+
979
+ Removes samples from the FIFO without reading them.
980
+
981
+ Parameters:
982
+
983
+ - `nbSamples` (`number`): Number of samples to drain
984
+
985
+ **Returns**: `void`
986
+
987
+ ##### `AudioFIFO.reset()`
988
+
989
+ Resets the FIFO to empty state.
990
+
991
+ **Returns**: `void`
992
+
993
+ ##### `AudioFIFO.destroy()`
994
+
995
+ Destroys the `AudioFIFO` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
996
+
997
+ **Returns**: `void`
998
+
9
999
  ## License
10
1000
 
11
1001
  Apache-2.0