bare-ffmpeg 1.0.0-3 → 1.0.0-31

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 (51) hide show
  1. package/CMakeLists.txt +10 -3
  2. package/README.md +1811 -0
  3. package/binding.cc +4638 -0
  4. package/cmake/ports/ffmpeg/port.cmake +514 -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 +22 -4
  11. package/lib/audio-fifo.js +47 -0
  12. package/lib/channel-layout.js +35 -0
  13. package/lib/codec-context.js +210 -16
  14. package/lib/codec-parameters.js +242 -8
  15. package/lib/codec.js +19 -1
  16. package/lib/constants.js +245 -9
  17. package/lib/dictionary.js +28 -15
  18. package/lib/errors.js +38 -0
  19. package/lib/filter-context.js +7 -0
  20. package/lib/filter-graph.js +47 -0
  21. package/lib/filter-inout.js +55 -0
  22. package/lib/filter.js +7 -0
  23. package/lib/format-context.js +72 -31
  24. package/lib/frame.js +88 -22
  25. package/lib/image.js +22 -0
  26. package/lib/input-format.js +36 -4
  27. package/lib/io-context.js +36 -6
  28. package/lib/log.js +16 -0
  29. package/lib/output-format.js +33 -2
  30. package/lib/packet.js +153 -12
  31. package/lib/rational.js +49 -1
  32. package/lib/resampler.js +63 -0
  33. package/lib/samples.js +96 -0
  34. package/lib/scaler.js +8 -7
  35. package/lib/stream.js +58 -14
  36. package/package.json +9 -4
  37. package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
  38. package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
  39. package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
  40. package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
  41. package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
  42. package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
  43. package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
  44. package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
  45. package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
  46. package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
  47. package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
  48. package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
  49. package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
  50. package/binding.c +0 -2203
  51. package/lib/reference-counted.js +0 -39
package/README.md CHANGED
@@ -6,6 +6,1817 @@ 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 with support for streaming and custom I/O operations.
14
+
15
+ ```js
16
+ const io = new ffmpeg.IOContext(buffer[, options])
17
+ ```
18
+
19
+ Parameters:
20
+
21
+ - `buffer` (`Buffer` | `number`): The media data buffer or buffer size for streaming
22
+ - `options` (`object`, optional): Configuration options
23
+ - `onread` (`function`): A function for refilling the buffer.
24
+ - `onwrite` (`function`): A function for writing the buffer contents.
25
+ - `onseek` (`function`): A function for seeking to specified byte position.
26
+
27
+ **Returns**: A new `IOContext` instance
28
+
29
+ #### Constructor Options
30
+
31
+ ##### `onread(buffer, requestedLen)`
32
+
33
+ Callback function called when FFmpeg needs to read data. For streaming scenarios where data is not available in a single buffer.
34
+
35
+ Parameters:
36
+
37
+ - `buffer` (`Buffer`): Buffer to fill with data
38
+ - `requestedLen` (`number`): Number of bytes requested
39
+
40
+ **Returns**: `number` - Number of bytes actually read, or 0 for EOF
41
+
42
+ ##### `onwrite(buffer)`
43
+
44
+ Callback function called when FFmpeg needs to write data. For streaming output scenarios.
45
+
46
+ Parameters:
47
+
48
+ - `buffer` (`Buffer`): Buffer containing data to write
49
+
50
+ **Returns**: `number` - Number of bytes written
51
+
52
+ ##### `onseek(offset, whence)`
53
+
54
+ Callback function called when FFmpeg needs to seek within the data source.
55
+
56
+ Parameters:
57
+
58
+ - `offset` (`number`): Offset to seek to
59
+ - `whence` (`number`): Seek mode (see `ffmpeg.constants.seek`)
60
+
61
+ **Returns**: `number` - New position or file size for `AVSEEK_SIZE`
62
+
63
+ #### Examples
64
+
65
+ **Basic usage with buffer:**
66
+
67
+ ```js
68
+ const image = require('./fixtures/image/sample.jpeg', {
69
+ with: { type: 'binary' }
70
+ })
71
+ const io = new ffmpeg.IOContext(image)
72
+ io.destroy()
73
+ ```
74
+
75
+ **Streaming with custom read callback:**
76
+
77
+ ```js
78
+ const io = new ffmpeg.IOContext(4096, {
79
+ onread: (buffer) => {
80
+ const bytesToRead = Math.min(buffer.length, data.length - offset)
81
+ if (bytesToRead === 0) return 0
82
+
83
+ const chunk = data.subarray(offset, offset + bytesToRead)
84
+ buffer.set(chunk)
85
+ offset += bytesToRead
86
+ return bytesToRead
87
+ }
88
+ })
89
+ ```
90
+
91
+ **Streaming with seek support:**
92
+
93
+ ```js
94
+ const io = new ffmpeg.IOContext(4096, {
95
+ onread: (buffer) => {
96
+ // ... read implementation
97
+ },
98
+ onseek: (offset, whence) => {
99
+ switch (whence) {
100
+ case ffmpeg.constants.seek.SIZE:
101
+ return data.length
102
+ case ffmpeg.constants.seek.SET:
103
+ offset = offset
104
+ return offset
105
+ default:
106
+ return -1
107
+ }
108
+ }
109
+ })
110
+ ```
111
+
112
+ #### Methods
113
+
114
+ ##### `IOContext.destroy()`
115
+
116
+ Destroys the `IOContext` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
117
+
118
+ **Returns**: `void`
119
+
120
+ ### `Dictionary`
121
+
122
+ The `Dictionary` API provides functionality to store and retrieve key-value pairs, commonly used for passing options to various FFmpeg components.
123
+
124
+ ```js
125
+ const dict = new ffmpeg.Dictionary()
126
+ ```
127
+
128
+ **Returns**: A new `Dictionary` instance
129
+
130
+ Example:
131
+
132
+ ```js
133
+ const dict = new ffmpeg.Dictionary()
134
+ dict.set('video_codec', 'h264')
135
+ dict.set('audio_codec', 'aac')
136
+ dict.set('bitrate', '1000k')
137
+ ```
138
+
139
+ #### Methods
140
+
141
+ ##### `Dictionary.set(key, value)`
142
+
143
+ Sets a key-value pair in the dictionary. Non-string values are automatically converted to strings.
144
+
145
+ Parameters:
146
+
147
+ - `key` (`string`): The dictionary key
148
+ - `value` (`string` | `number`): The value to store
149
+
150
+ **Returns**: `void`
151
+
152
+ ##### `Dictionary.get(key)`
153
+
154
+ Retrieves a value from the dictionary by key.
155
+
156
+ Parameters:
157
+
158
+ - `key` (`string`): The dictionary key
159
+
160
+ **Returns**: `string` value or `null` if the key doesn't exist
161
+
162
+ ##### `Dictionary.entries()`
163
+
164
+ Retrieves all keys and values.
165
+
166
+ **Returns**: `Array<[string, string]>` value
167
+
168
+ ##### `Dictionary.destroy()`
169
+
170
+ Destroys the `Dictionary` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
171
+
172
+ **Returns**: `void`
173
+
174
+ #### Iteration
175
+
176
+ The `Dictionary` class implements the iterator protocol, allowing you to iterate over all key-value pairs:
177
+
178
+ ```js
179
+ const dict = new ffmpeg.Dictionary()
180
+ dict.set('foo', 'bar')
181
+ dict.set('baz', 'qux')
182
+
183
+ for (const [key, value] of dict) {
184
+ console.log(`${key}: ${value}`)
185
+ }
186
+ ```
187
+
188
+ #### Static methods
189
+
190
+ ##### `Dictionary.from(object)`
191
+
192
+ A helper to create a `Dictionary` instance from an object.
193
+
194
+ ```js
195
+ const dict = ffmpeg.Dictionary.from({
196
+ foo: 'bar',
197
+ baz: 'qux'
198
+ })
199
+ ```
200
+
201
+ **Returns**: A new `Dictionary` instance
202
+
203
+ ### `FormatContext`
204
+
205
+ The `FormatContext` API provides the base functionality for reading and writing media files.
206
+
207
+ > This is the base class that `InputFormatContext` and `OutputFormatContext` extend.
208
+
209
+ #### Properties
210
+
211
+ ##### `FormatContext.io`
212
+
213
+ Gets the IO context associated with this format context.
214
+
215
+ **Returns**: `IOContext` instance or `null`
216
+
217
+ ##### `FormatContext.streams`
218
+
219
+ Gets the array of media streams.
220
+
221
+ **Returns**: Array of `Stream` instances
222
+
223
+ #### Methods
224
+
225
+ ##### `FormatContext.readFrame(packet)`
226
+
227
+ Reads the next frame from the media file into a packet.
228
+
229
+ Parameters:
230
+
231
+ - `packet` (`Packet`): The packet to store the frame data
232
+
233
+ **Returns**: `boolean` indicating if a frame was read
234
+
235
+ ##### `FormatContext.getBestStream(type)`
236
+
237
+ Gets the best stream of the specified media type.
238
+
239
+ Parameters:
240
+
241
+ - `type` (`number`): The media type from `ffmpeg.constants.mediaTypes`
242
+
243
+ **Returns**: `Stream` instance or `null` if not found
244
+
245
+ ##### `FormatContext.destroy()`
246
+
247
+ Destroys the `FormatContext` and frees all associated resources including streams. Automatically called when the object is managed by a `using` declaration.
248
+
249
+ **Returns**: `void`
250
+
251
+ ### `InputFormatContext`
252
+
253
+ The `InputFormatContext` API extends `FormatContext` to provide functionality for reading media files.
254
+
255
+ ```js
256
+ const format = new ffmpeg.InputFormatContext(io, options[, url])
257
+ ```
258
+
259
+ Parameters:
260
+
261
+ - `io` (`IOContext` | `InputFormat`): The IO context or input format. The ownership of `io` is transferred.
262
+ - `options` (`Dictionary`): Format options. Required when using `InputFormat`, ignored when using `IOContext`. The ownership of `options` is transferred.
263
+ - `url` (`string`, optional): Media source URL. Defaults to a platform-specific value
264
+
265
+ **Returns**: A new `InputFormatContext` instance
266
+
267
+ #### Methods
268
+
269
+ ##### `InputFormatContext.inputFormat`
270
+
271
+ Gets the input format associated with this context.
272
+
273
+ **Returns**: `InputFormat` instance or `undefined` if not available
274
+
275
+ ##### `InputFormatContext.destroy()`
276
+
277
+ Destroys the `InputFormatContext` and closes the input format. Automatically called when the object is managed by a `using` declaration.
278
+
279
+ **Returns**: void
280
+
281
+ ### `OutputFormatContext`
282
+
283
+ The `OutputFormatContext` API extends `FormatContext` to provide functionality for writing media files.
284
+
285
+ ```js
286
+ const format = new ffmpeg.OutputFormatContext(formatName, io)
287
+ ```
288
+
289
+ Parameters:
290
+
291
+ - `formatName` (`string`): The output format name (e.g., `'mp4'`, `'avi'`)
292
+ - `io` (`IOContext`): The IO context for writing. The ownership of `io` is transferred.
293
+
294
+ **Returns**: A new `OutputFormatContext` instance
295
+
296
+ #### Methods
297
+
298
+ ##### `OutputFormatContext.createStream(codec)`
299
+
300
+ Creates a new stream in the output format.
301
+
302
+ Parameters:
303
+
304
+ - `codec` (`Codec`): The codec to use for the stream
305
+
306
+ **Returns**: A new `Stream` instance
307
+
308
+ ##### `OutputFormatContext.outputFormat`
309
+
310
+ Gets the output format associated with this context.
311
+
312
+ **Returns**: `OutputFormat` instance or `undefined` if not available
313
+
314
+ ##### `OutputFormatContext.destroy()`
315
+
316
+ Destroys the `OutputFormatContext` and closes the output format. Automatically called when the object is managed by a `using` declaration.
317
+
318
+ **Returns**: `void`
319
+
320
+ ### `Codec`
321
+
322
+ The `Codec` API provides access to FFmpeg codecs for encoding and decoding.
323
+
324
+ #### Static properties
325
+
326
+ ##### `Codec.H264`
327
+
328
+ H.264 video codec.
329
+
330
+ **Returns**: `Codec` instance
331
+
332
+ ##### `Codec.MJPEG`
333
+
334
+ Motion JPEG video codec.
335
+
336
+ **Returns**: `Codec` instance
337
+
338
+ ##### `Codec.AAC`
339
+
340
+ AAC audio codec.
341
+
342
+ **Returns**: `Codec` instance
343
+
344
+ ##### `Codec.AV1`
345
+
346
+ AV1 video codec.
347
+
348
+ **Returns**: `Codec` instance
349
+
350
+ #### Properties
351
+
352
+ ##### `Codec.id`
353
+
354
+ Gets the codec ID.
355
+
356
+ **Returns**: `number`
357
+
358
+ ##### `Codec.encoder`
359
+
360
+ Gets the encoder for this codec.
361
+
362
+ **Returns**: `Encoder` instance
363
+
364
+ ##### `Codec.decoder`
365
+
366
+ Gets the decoder for this codec.
367
+
368
+ **Returns**: `Decoder` instance
369
+
370
+ #### Methods
371
+
372
+ ##### `Codec.for(id)`
373
+
374
+ Gets a codec by ID.
375
+
376
+ Parameters:
377
+
378
+ - `id` (`number`): The codec ID
379
+
380
+ **Returns**: `Codec` instance
381
+
382
+ ### `CodecContext`
383
+
384
+ The `CodecContext` API provides functionality to encode or decode media frames.
385
+
386
+ ```js
387
+ const codecCtx = new ffmpeg.CodecContext(codec)
388
+ ```
389
+
390
+ Parameters:
391
+
392
+ - `codec` (Codec): The codec to use (e.g., `ffmpeg.Codec.H264.encoder`)
393
+
394
+ **Returns**: A new `CodecContext` instance
395
+
396
+ #### Properties
397
+
398
+ ##### `CodecContext.timeBase`
399
+
400
+ Gets or sets the time base for the codec context.
401
+
402
+ **Returns**: `Rational` instance
403
+
404
+ ##### `CodecContext.pixelFormat`
405
+
406
+ Gets or sets the pixel format for video codecs.
407
+
408
+ **Returns**: `number` (pixel format constant)
409
+
410
+ ##### `CodecContext.width`
411
+
412
+ Gets or sets the frame width for video codecs.
413
+
414
+ **Returns**: `number`
415
+
416
+ ##### `CodecContext.height`
417
+
418
+ Gets or sets the frame height for video codecs.
419
+
420
+ **Returns**: `number`
421
+
422
+ ##### `CodecContext.frameSize`
423
+
424
+ Gets the number of samples per channel in an audio frame.
425
+
426
+ **Returns**: `number`
427
+
428
+ ##### `CodecContext.frameNum`
429
+
430
+ When encoding this gets the total number of frames passed to the encoder so far.
431
+
432
+ When decoding this gets the total number of frames returned from the decoder so far.
433
+
434
+ **Returns**: `number`
435
+
436
+ ##### `CodecContext.requestSampleFormat`
437
+
438
+ _Only when decoding_
439
+
440
+ Set to before calling `context.open()` to hint decoder of preferred output format if supported.
441
+
442
+ Always rely on `CodecContext.sampleFormat` for actual decoded format.
443
+
444
+ **Returns**: `number`
445
+
446
+ ##### `CodecContext.getFormat`
447
+
448
+ _Only when decoding_
449
+
450
+ Sets a callback function for pixel format negotiation during decoding. Called when FFmpeg needs to choose between multiple supported formats, typically for hardware acceleration.
451
+
452
+ **Type**: `function` (setter only)
453
+
454
+ **Callback Signature**: `(context: CodecContext, formats: number[]) => number`
455
+
456
+ Parameters:
457
+
458
+ - `context` (`CodecContext`): The codec context instance
459
+ - `formats` (`number[]`): Array of available pixel format constants
460
+
461
+ **Returns**: `number` - The chosen pixel format constant from the provided array
462
+
463
+ Must be set before calling `context.open()`.
464
+
465
+ #### Methods
466
+
467
+ ##### `CodecContext.open([options])`
468
+
469
+ Opens the codec context for encoding/decoding.
470
+
471
+ Parameters:
472
+
473
+ - `options` (`Dictionary`, optional): Codec-specific options
474
+
475
+ **Returns**: `void`
476
+
477
+ ##### `CodecContext.sendFrame(frame)`
478
+
479
+ Sends a frame to the encoder.
480
+
481
+ Parameters:
482
+
483
+ - `frame` (`Frame`): The frame to encode
484
+
485
+ **Returns**: `boolean` indicating if the frame was sent
486
+
487
+ ##### `CodecContext.receiveFrame(frame)`
488
+
489
+ Receives a decoded frame from the decoder.
490
+
491
+ Parameters:
492
+
493
+ - `frame` (`Frame`): The frame to store the decoded data
494
+
495
+ **Returns**: `boolean` indicating if a frame was received
496
+
497
+ ##### `CodecContext.sendPacket(packet)`
498
+
499
+ Sends a packet to the decoder.
500
+
501
+ Parameters:
502
+
503
+ - `packet` (`Packet`): The packet to decode
504
+
505
+ **Returns**: `boolean` indicating if the packet was sent
506
+
507
+ ##### `CodecContext.receivePacket(packet)`
508
+
509
+ Receives an encoded packet from the encoder.
510
+
511
+ Parameters:
512
+
513
+ - `packet` (`Packet`): The packet to store the encoded data
514
+
515
+ **Returns**: `boolean` indicating if a packet was received
516
+
517
+ ##### `CodecContext.getSupportedConfig(config)`
518
+
519
+ Gets the supported values for a codec configuration option.
520
+
521
+ Parameters:
522
+
523
+ - `config` (`number`): The configuration type from `ffmpeg.constants.codecConfig`
524
+
525
+ **Returns**:
526
+
527
+ - For `PIX_FORMAT`, `SAMPLE_FORMAT`, `COLOR_RANGE`, `COLOR_SPACE`: `Int32Array` of supported values (all valid values are included if the codec has no restrictions)
528
+ - For `SAMPLE_RATE`: `Int32Array` of supported sample rates or `null` if the codec accepts any valid sample rate
529
+ - For `FRAME_RATE`: Array of `Rational` instances or `null` if the codec accepts any valid frame rate
530
+ - For `CHANNEL_LAYOUT`: Array of `ChannelLayout` instances or `null` if the codec accepts any valid channel layout
531
+
532
+ **Throws**: Error if the config type is not applicable to this codec (e.g., asking for pixel formats from an audio codec)
533
+
534
+ Examples:
535
+
536
+ ```js
537
+ const codecCtx = new ffmpeg.CodecContext(ffmpeg.Codec.AV1.encoder)
538
+
539
+ const pixelFormats = codecCtx.getSupportedConfig(
540
+ ffmpeg.constants.codecConfig.PIX_FORMAT
541
+ )
542
+ if (pixelFormats) {
543
+ console.log('Supported pixel formats:', pixelFormats)
544
+ }
545
+
546
+ const frameRates = codecCtx.getSupportedConfig(
547
+ ffmpeg.constants.codecConfig.FRAME_RATE
548
+ )
549
+ if (frameRates) {
550
+ frameRates.forEach((rate) => {
551
+ console.log(`${rate.toNumber()} fps`)
552
+ })
553
+ }
554
+
555
+ const layouts = codecCtx.getSupportedConfig(
556
+ ffmpeg.constants.codecConfig.CHANNEL_LAYOUT
557
+ )
558
+ if (layouts) {
559
+ console.log('Supported channel layouts:', layouts)
560
+ }
561
+ ```
562
+
563
+ ##### `CodecContext.getOption(name[, flags])`
564
+
565
+ Gets the value of a codec option.
566
+
567
+ Parameters:
568
+
569
+ - `name` (`string`): The option name (for example, `'threads'` or `'crf'`)
570
+ - `flags` (`number`, optional): Option search flags (default `ffmpeg.constants.optionFlags.SEARCH_CHILDREN`)
571
+
572
+ **Returns**: `string` value or `null` when the option is unset
573
+
574
+ ##### `CodecContext.setOption(name, value[, flags])`
575
+
576
+ Sets a codec option.
577
+
578
+ Parameters:
579
+
580
+ - `name` (`string`): The option name to set
581
+ - `value` (`string`): The option value
582
+ - `flags` (`number`, optional): Option search flags (default `ffmpeg.constants.optionFlags.SEARCH_CHILDREN`)
583
+
584
+ **Returns**: `void`
585
+
586
+ ##### `CodecContext.setOptionDictionary(dictionary[, flags])`
587
+
588
+ Sets options from a `Dictionary`. Ownership of the dictionary is retained by the caller.
589
+
590
+ Parameters:
591
+
592
+ - `dictionary` (`Dictionary`): Dictionary of option key/value pairs
593
+ - `flags` (`number`, optional): Option search flags (default `ffmpeg.constants.optionFlags.SEARCH_CHILDREN`)
594
+
595
+ **Returns**: `void`
596
+
597
+ ##### `CodecContext.setOptionDefaults()`
598
+
599
+ Resets codec options to their defaults.
600
+
601
+ **Returns**: `void`
602
+
603
+ ##### `CodecContext.listOptionNames([flags])`
604
+
605
+ Lists option names available on the codec context.
606
+
607
+ Parameters:
608
+
609
+ - `flags` (`number`, optional): Option search flags (default `ffmpeg.constants.optionFlags.SEARCH_CHILDREN`)
610
+
611
+ **Returns**: `Array<string>` of option names
612
+
613
+ ##### `CodecContext.getOptions([flags])`
614
+
615
+ Collects option values into a plain object.
616
+
617
+ Parameters:
618
+
619
+ - `flags` (`number`, optional): Option search flags (default `ffmpeg.constants.optionFlags.SEARCH_CHILDREN`)
620
+
621
+ **Returns**: `object` mapping option names to string values
622
+
623
+ ##### `CodecContext.copyOptionsFrom(context)`
624
+
625
+ Copies options from another codec context.
626
+
627
+ Parameters:
628
+
629
+ - `context` (`CodecContext`): Source context whose options should be copied
630
+
631
+ **Returns**: `void`
632
+
633
+ Example:
634
+
635
+ ```js
636
+ using source = new ffmpeg.CodecContext(ffmpeg.Codec.AV1.encoder)
637
+ using target = new ffmpeg.CodecContext(ffmpeg.Codec.AV1.encoder)
638
+
639
+ source.setOption('crf', '28')
640
+ source.setOption('threads', '4')
641
+ source.setOptionDictionary(ffmpeg.Dictionary.from({ preset: 'slow' }))
642
+
643
+ target.setOptionDefaults()
644
+ target.copyOptionsFrom(source)
645
+
646
+ console.log(target.getOptions())
647
+ ```
648
+
649
+ ##### `CodecContext.destroy()`
650
+
651
+ Destroys the `CodecContext` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
652
+
653
+ **Returns**: `void`
654
+
655
+ ### `CodecParameters`
656
+
657
+ The `CodecParameters` API provides functionality to access codec parameters from streams.
658
+
659
+ ```js
660
+ const params = stream.codecParameters // Get from stream
661
+ ```
662
+
663
+ #### Properties
664
+
665
+ ##### `CodecParameters.type`
666
+
667
+ General type of the encoded data.
668
+
669
+ **Returns**: `number`
670
+
671
+ ##### `CodecParameters.id`
672
+
673
+ Specific type of the encoded data (the codec used).
674
+
675
+ **Returns**: `number`
676
+
677
+ ##### `CodecParameters.tag`
678
+
679
+ Additional information about the codec (corresponds to the AVI FOURCC).
680
+
681
+ **Returns**: `number`
682
+
683
+ ##### `CodecParameters.bitRate`
684
+
685
+ Gets the bit rate.
686
+
687
+ **Returns**: `number`
688
+
689
+ ##### `CodecParameters.bitsPerCodedSample`
690
+
691
+ Gets the bits per coded sample.
692
+
693
+ **Returns**: `number`
694
+
695
+ ##### `CodecParameters.bitsPerRawSample`
696
+
697
+ Gets the bits per raw sample.
698
+
699
+ **Returns**: `number`
700
+
701
+ ##### `CodecParameters.sampleRate`
702
+
703
+ Gets the sample rate for audio codecs.
704
+
705
+ **Returns**: `number`
706
+
707
+ ##### `CodecParameters.frameRate`
708
+
709
+ Gets the frame rate for video codecs.
710
+
711
+ **Returns**: `Rational`
712
+
713
+ ##### `CodecParameters.extraData`
714
+
715
+ Out-of-band global headers that may be used by some codecs.
716
+
717
+ **Returns**: `Buffer`
718
+
719
+ ##### `CodecParameters.profile`
720
+
721
+ Codec-specific bitstream restrictions that the stream conforms to.
722
+
723
+ **Returns**: `number`
724
+
725
+ ##### `CodecParameters.level`
726
+
727
+ Codec-specific bitstream restrictions that the stream conforms to.
728
+
729
+ **Returns**: `number`
730
+
731
+ ##### `CodecParameters.format`
732
+
733
+ Video: the pixel format, the value corresponds to AVPixelFormat.
734
+ Audio: the sample format, the value corresponds to AVSampleFormat.
735
+
736
+ **Returns**: `number`
737
+
738
+ ##### `CodecParameters.nbChannels`
739
+
740
+ Number of channels in the layout.
741
+
742
+ **Returns**: `number`
743
+
744
+ ##### `CodecParameters.channelLayout`
745
+
746
+ Gets or sets the channel layout, see `ffmpeg.constants.channelLayouts`
747
+
748
+ **Returns**: `ChannelLayout`
749
+
750
+ ##### `CodecParameters.blockAlign`
751
+
752
+ Audio only. The number of bytes per coded audio frame, required by some
753
+ formats.
754
+
755
+ Corresponds to `nBlockAlign` in `WAVEFORMATEX`.
756
+
757
+ **Returns**: `number`
758
+
759
+ ##### `CodecParameters.initalPadding`
760
+
761
+ Audio only. The amount of padding (in samples) inserted by the encoder at the beginning of the audio. I.e. this number of leading decoded samples must be discarded by the caller to get the original audio without leading padding.
762
+
763
+ **Returns**: `number`
764
+
765
+ ##### `CodecParameters.trailingPadding`
766
+
767
+ Audio only. The amount of padding (in samples) appended by the encoder to the end of the audio. I.e. this number of decoded samples must be discarded by the caller from the end of the stream to get the original audio without any trailing padding.
768
+
769
+ ##### `CodecParameters.seekPreroll`
770
+
771
+ Audio only. Number of samples to skip after a discontinuity.
772
+
773
+ **Returns**: `number`
774
+
775
+ ##### `CodecParameters.sampleAspectRatio`
776
+
777
+ Video only. The aspect ratio (width / height) which a single pixel should have when displayed.
778
+
779
+ When the aspect ratio is unknown / undefined, the numerator should be set to 0 (the denominator may have any value).
780
+
781
+ **Returns**: `number`
782
+
783
+ ##### `CodecParameters.videoDelay`
784
+
785
+ Video only. Number of delayed frames.
786
+
787
+ **Returns**: `number`
788
+
789
+ #### Methods
790
+
791
+ ##### `CodecParameters.fromContext(context)`
792
+
793
+ Copies parameters from a codec context.
794
+
795
+ Parameters:
796
+
797
+ - `context` (`CodecContext`): The codec context
798
+
799
+ **Returns**: `void`
800
+
801
+ ##### `CodecParameters.toContext(context)`
802
+
803
+ Copies parameters to a codec context.
804
+
805
+ Parameters:
806
+
807
+ - `context` (`CodecContext`): The codec context
808
+
809
+ **Returns**: `void`
810
+
811
+ ### `InputFormat`
812
+
813
+ The `InputFormat` API provides functionality to specify input format for media sources.
814
+
815
+ ```js
816
+ const format = new ffmpeg.InputFormat([name])
817
+ ```
818
+
819
+ Parameters:
820
+
821
+ - `name` (`string`, optional): The input format name. Defaults to a platform-specific value:
822
+ - `darwin`, `ios`: ``'avfoundation'`
823
+ - `linux`: `'v4l2'`
824
+ - `win32`: `'dshow'`
825
+
826
+ **Returns**: A new `InputFormat` instance
827
+
828
+ #### Properties
829
+
830
+ ##### `InputFormat.extensions`
831
+
832
+ Gets the file extensions associated with this input format.
833
+
834
+ **Returns**: `string` - Comma-separated list of file extensions (e.g., `'mkv,mk3d,mka,mks,webm'`)
835
+
836
+ ##### `InputFormat.mimeType`
837
+
838
+ Gets the MIME type for this input format.
839
+
840
+ **Returns**: `string` - The MIME type (e.g., `'audio/webm,audio/x-matroska,video/webm,video/x-matroska'`)
841
+
842
+ ##### `InputFormat.name`
843
+
844
+ Returns format name
845
+
846
+ **Returns**: `string` - The short-name (e.g., `webm`)
847
+
848
+ #### Example
849
+
850
+ ```js
851
+ const format = new ffmpeg.InputFormat('webm')
852
+ console.log(format.extensions) // 'mkv,mk3d,mka,mks,webm'
853
+ console.log(format.mimeType) // 'audio/webm,audio/x-matroska,video/webm,video/x-matroska'
854
+ ```
855
+
856
+ #### Methods
857
+
858
+ ##### `InputFormat.destroy()`
859
+
860
+ Destroys the `InputFormat` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
861
+
862
+ **Returns**: `void`
863
+
864
+ ### `OutputFormat`
865
+
866
+ The `OutputFormat` API provides functionality to specify output format for media files.
867
+
868
+ ```js
869
+ const format = new ffmpeg.OutputFormat(name)
870
+ ```
871
+
872
+ Parameters:
873
+
874
+ - `name` (`string`): The output format name (e.g., `'mp4'`, `'avi'`, `'mov'`)
875
+
876
+ **Returns**: A new `OutputFormat` instance
877
+
878
+ #### Properties
879
+
880
+ ##### `OutputFormat.extensions`
881
+
882
+ Gets the file extensions associated with this output format.
883
+
884
+ **Returns**: `string` - Comma-separated list of file extensions (e.g., `'webm'`, `'mp4,m4a,m4v'`)
885
+
886
+ ##### `OutputFormat.mimeType`
887
+
888
+ Gets the MIME type for this output format.
889
+
890
+ **Returns**: `string` - The MIME type (e.g., `'video/webm'`, `'video/mp4'`)
891
+
892
+ ##### `OutputFormat.name`
893
+
894
+ Returns format name
895
+
896
+ **Returns**: `string` - The short-name (e.g., `webm`)
897
+
898
+ #### Example
899
+
900
+ ```js
901
+ const format = new ffmpeg.OutputFormat('webm')
902
+ console.log(format.extensions) // 'webm'
903
+ console.log(format.mimeType) // 'video/webm'
904
+ ```
905
+
906
+ #### Methods
907
+
908
+ ##### `OutputFormat.destroy()`
909
+
910
+ Destroys the `OutputFormat` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
911
+
912
+ **Returns**: `void`
913
+
914
+ ### `Frame`
915
+
916
+ This structure describes decoded (raw) audio or video data.
917
+
918
+ ```js
919
+ const frame = new ffmpeg.Frame()
920
+ ```
921
+
922
+ **Returns**: A new `Frame` instance
923
+
924
+ #### Properties
925
+
926
+ ##### `Frame.width`
927
+
928
+ Gets or sets the frame width.
929
+
930
+ **Returns**: `number`
931
+
932
+ ##### `Frame.height`
933
+
934
+ Gets or sets the frame height.
935
+
936
+ **Returns**: `number`
937
+
938
+ ##### `Frame.format`
939
+
940
+ Gets or sets the format of the frame, `-1` if unknown or unset.
941
+
942
+ **Returns**: `number` (sample format constant)
943
+
944
+ ##### `Frame.channelLayout`
945
+
946
+ Gets or sets the channel layout for audio frames.
947
+
948
+ **Returns**: `number` (channel layout constant)
949
+
950
+ ##### `Frame.nbSamples`
951
+
952
+ Gets or sets the number of audio samples.
953
+
954
+ **Returns**: `number`
955
+
956
+ #### Methods
957
+
958
+ ##### `Frame.alloc()`
959
+
960
+ Allocates memory for the frame data.
961
+
962
+ **Returns**: `void`
963
+
964
+ ##### `Frame.destroy()`
965
+
966
+ Destroys the `Frame` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
967
+
968
+ **Returns**: `void`
969
+
970
+ ##### `Frame.copyProperties(otherFrame)`
971
+
972
+ Copies all metadata properties such as timestamps, timebase and width/height for videoframes and
973
+ sampleRate channelLayout for audioFrames.
974
+
975
+ see `av_frame_copy_props()` for details.
976
+
977
+ ```js
978
+ const src = new ffmpeg.Frame()
979
+ const dst = new ffmpeg.Frame()
980
+
981
+ decoder.receiveFrame(src)
982
+ rescaler.convert(src, dst)
983
+
984
+ dst.copyProperties(src) // transfer all meta-data
985
+ ```
986
+
987
+ **Returns**: `void`
988
+
989
+ ### `Packet`
990
+
991
+ 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.
992
+
993
+ ```js
994
+ const packet = new ffmpeg.Packet([buffer])
995
+ ```
996
+
997
+ Parameters:
998
+
999
+ - `buffer` (`Buffer`, optional): Initial packet data
1000
+
1001
+ **Returns**: A new `Packet` instance
1002
+
1003
+ #### Properties
1004
+
1005
+ ##### `Packet.data`
1006
+
1007
+ Gets the packet data buffer.
1008
+
1009
+ **Returns**: `Buffer`
1010
+
1011
+ ##### `Packet.streamIndex`
1012
+
1013
+ Gets the stream index this packet belongs to.
1014
+
1015
+ **Returns**: `number`
1016
+
1017
+ ##### `Packet.isKeyFrame`
1018
+
1019
+ Get or set the key frame flag.
1020
+
1021
+ **Returns**: `boolean`
1022
+
1023
+ ##### `Packet.sideData`
1024
+
1025
+ Gets or sets the side data associated with the packet.
1026
+
1027
+ **Returns**: `Array<SideData>`
1028
+
1029
+ #### Methods
1030
+
1031
+ ##### `Packet.unref()`
1032
+
1033
+ Decrements the reference count and unreferences the packet.
1034
+
1035
+ **Returns**: `void`
1036
+
1037
+ ##### `Packet.destroy()`
1038
+
1039
+ Destroys the `Packet` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
1040
+
1041
+ **Returns**: `void`
1042
+
1043
+ ### `SideData`
1044
+
1045
+ The `SideData` API provides functionality to handle side data associated with packets. Side data contains additional metadata that may be useful for specific codecs or processing.
1046
+
1047
+ ```js
1048
+ const sideData = new ffmpeg.Packet.SideData(handle, options)
1049
+ ```
1050
+
1051
+ Parameters:
1052
+
1053
+ - `handle` (`ArrayBuffer`): Internal side data handle
1054
+ - `options` (`object`, optional): Configuration options
1055
+ - `type` (`number`): The side data type
1056
+ - `data` (`Buffer`): The side data buffer
1057
+
1058
+ **Returns**: A new `SideData` instance
1059
+
1060
+ #### Static Methods
1061
+
1062
+ ##### `SideData.fromData(data, type)`
1063
+
1064
+ Creates a new `SideData` instance from data and type.
1065
+
1066
+ Parameters:
1067
+
1068
+ - `data` (`Buffer`): The side data buffer
1069
+ - `type` (`number`): The side data type constant
1070
+
1071
+ **Returns**: A new `SideData` instance
1072
+
1073
+ #### Properties
1074
+
1075
+ ##### `SideData.type`
1076
+
1077
+ Gets the side data type.
1078
+
1079
+ **Returns**: `number`
1080
+
1081
+ ##### `SideData.name`
1082
+
1083
+ Gets the human-readable name of the side data type.
1084
+
1085
+ **Returns**: `string`
1086
+
1087
+ ##### `SideData.data`
1088
+
1089
+ Gets the side data buffer.
1090
+
1091
+ **Returns**: `Buffer`
1092
+
1093
+ #### Example
1094
+
1095
+ ```js
1096
+ const packet = new ffmpeg.Packet()
1097
+ const sideData = ffmpeg.Packet.SideData.fromData(
1098
+ Buffer.from('metadata'),
1099
+ ffmpeg.constants.packetSideDataType.NEW_EXTRADATA
1100
+ )
1101
+ packet.sideData = [sideData]
1102
+ ```
1103
+
1104
+ ### `Image`
1105
+
1106
+ The `Image` API provides functionality to create and manage image buffers.
1107
+
1108
+ ```js
1109
+ const image = new ffmpeg.Image(pixelFormat, width, height[, align])
1110
+ ```
1111
+
1112
+ Parameters:
1113
+
1114
+ - `pixelFormat` (`number` | `string`): The pixel format
1115
+ - `width` (`number`): The image width in pixels
1116
+ - `height` (`number`): The image height in pixels
1117
+ - `align` (`number`, optional): Memory alignment. Defaults to 1
1118
+
1119
+ **Returns**: A new `Image` instance
1120
+
1121
+ #### Properties
1122
+
1123
+ ##### `Image.pixelFormat`
1124
+
1125
+ Gets the pixel format.
1126
+
1127
+ **Returns**: `number`
1128
+
1129
+ ##### `Image.width`
1130
+
1131
+ Gets the image width.
1132
+
1133
+ **Returns**: `number`
1134
+
1135
+ ##### `Image.height`
1136
+
1137
+ Gets the image height.
1138
+
1139
+ **Returns**: `number`
1140
+
1141
+ ##### `Image.align`
1142
+
1143
+ Gets the memory alignment.
1144
+
1145
+ **Returns**: `number`
1146
+
1147
+ ##### `Image.data`
1148
+
1149
+ Gets the image data buffer.
1150
+
1151
+ **Returns**: `Buffer`
1152
+
1153
+ #### Methods
1154
+
1155
+ ##### `Image.fill(frame)`
1156
+
1157
+ Fills a frame with the image data.
1158
+
1159
+ Parameters:
1160
+
1161
+ - `frame` (`Frame`): The frame to fill
1162
+
1163
+ **Returns**: void
1164
+
1165
+ ##### `Image.read(frame)`
1166
+
1167
+ Reads image data from a frame into the image buffer.
1168
+
1169
+ Parameters:
1170
+
1171
+ - `frame` (`Frame`): The frame to read from
1172
+
1173
+ **Returns**: `void`
1174
+
1175
+ ##### `Image.lineSize([plane])`
1176
+
1177
+ Gets the line size for a specific plane.
1178
+
1179
+ Parameters:
1180
+
1181
+ - `plane` (`number`, optional): Plane index. Defaults to 0
1182
+
1183
+ **Returns**: `number`
1184
+
1185
+ #### Static methods
1186
+
1187
+ ##### `Image.lineSize(pixelFormat, width[, plane])`
1188
+
1189
+ Static method to get line size for a pixel format.
1190
+
1191
+ Parameters:
1192
+
1193
+ - `pixelFormat` (`number` | `string`): The pixel format
1194
+ - `width` (`number`): The image width
1195
+ - `plane` (`number`, optional): Plane index. Defaults to 0
1196
+
1197
+ **Returns**: `number`
1198
+
1199
+ ### `Rational`
1200
+
1201
+ The `Rational` API provides functionality to represent rational numbers (fractions).
1202
+
1203
+ ```js
1204
+ const rational = new ffmpeg.Rational(numerator, denominator)
1205
+ ```
1206
+
1207
+ Parameters:
1208
+
1209
+ - `numerator` (`number`): The numerator
1210
+ - `denominator` (`number`): The denominator
1211
+
1212
+ **Returns**: A new `Rational` instance
1213
+
1214
+ #### Properties
1215
+
1216
+ ##### `Rational.numerator`
1217
+
1218
+ Gets the numerator.
1219
+
1220
+ **Returns**: `number`
1221
+
1222
+ ##### `Rational.denominator`
1223
+
1224
+ Gets the denominator.
1225
+
1226
+ **Returns**: `number`
1227
+
1228
+ ##### `Rational.valid`
1229
+
1230
+ Returns if true if rational describes a non-zero & non-negative quantity.
1231
+
1232
+ **Returns**: `number`
1233
+
1234
+ ##### `Rational.uninitialized`
1235
+
1236
+ Returns if true when is not set.
1237
+
1238
+ **Returns**: `number`
1239
+
1240
+ ##### `Rational.toNumber()`
1241
+
1242
+ see `av_q2d()`
1243
+
1244
+ **Returns**: `number`
1245
+
1246
+ ##### `static Rational.from(number)`
1247
+
1248
+ see `av_d2q()`
1249
+
1250
+ **Returns**: `Rational`
1251
+
1252
+ ##### `Rational.rescaleQ(number, timebaseA, timebaseB)`
1253
+
1254
+ see `av_rescale_q()`
1255
+
1256
+ **Returns**: `number`
1257
+
1258
+ ### `Stream`
1259
+
1260
+ The `Stream` API provides functionality to access media stream information and create decoders/encoders.
1261
+
1262
+ ```js
1263
+ const stream = new ffmpeg.Stream(handle)
1264
+ ```
1265
+
1266
+ Parameters:
1267
+
1268
+ - `handle` (`ArrayBuffer`): Internal stream handle
1269
+
1270
+ **Returns**: A new `Stream` instance
1271
+
1272
+ > Streams are typically obtained from format contexts: `const stream = format.streams[0]`
1273
+
1274
+ #### Properties
1275
+
1276
+ ##### `Stream.id`
1277
+
1278
+ Gets or sets the stream ID.
1279
+
1280
+ **Returns**: `number`
1281
+
1282
+ ##### `Stream.index`
1283
+
1284
+ Gets the stream index.
1285
+
1286
+ **Returns**: `number`
1287
+
1288
+ ##### `Stream.codec`
1289
+
1290
+ Gets the codec for this stream.
1291
+
1292
+ **Returns**: `Codec` instance
1293
+
1294
+ ##### `Stream.codecParameters`
1295
+
1296
+ Gets the codec parameters for this stream.
1297
+
1298
+ **Returns**: `CodecParameters` instance
1299
+
1300
+ ##### `Stream.timeBase`
1301
+
1302
+ Gets or sets the time base for the stream.
1303
+
1304
+ **Returns**: `Rational` instance
1305
+
1306
+ ##### `Stream.avgFramerate`
1307
+
1308
+ Gets or sets the average framerate for video streams.
1309
+
1310
+ **Returns**: `Rational` instance
1311
+
1312
+ Example:
1313
+
1314
+ ```js
1315
+ const fps = stream.avgFramerate.toNumber()
1316
+ ```
1317
+
1318
+ ##### `Stream.duration`
1319
+
1320
+ Gets or sets the duration of the stream in time base units.
1321
+
1322
+ **Returns**: `number` - Duration in time base units, or `0` if unknown
1323
+
1324
+ #### Methods
1325
+
1326
+ ##### `Stream.decoder()`
1327
+
1328
+ Creates a decoder for this stream.
1329
+
1330
+ **Returns**: `CodecContext` instance
1331
+
1332
+ ##### `Stream.encoder()`
1333
+
1334
+ Creates an encoder for this stream.
1335
+
1336
+ **Returns**: `CodecContext` instance
1337
+
1338
+ ### `Resampler`
1339
+
1340
+ The `Resampler` API provides functionality to convert audio between different sample rates, channel layouts, and sample formats.
1341
+
1342
+ ```js
1343
+ const resampler = new ffmpeg.Resampler(
1344
+ inputSampleRate,
1345
+ inputChannelLayout,
1346
+ inputSampleFormat,
1347
+ outputSampleRate,
1348
+ outputChannelLayout,
1349
+ outputSampleFormat
1350
+ )
1351
+ ```
1352
+
1353
+ Parameters:
1354
+
1355
+ - `inputSampleRate` (`number`): Input sample rate in Hz
1356
+ - `inputChannelLayout` (`number`): Input channel layout constant
1357
+ - `inputSampleFormat` (`number`): Input sample format constant
1358
+ - `outputSampleRate` (`number`): Output sample rate in Hz
1359
+ - `outputChannelLayout` (`number`): Output channel layout constant
1360
+ - `outputSampleFormat` (`number`): Output sample format constant
1361
+
1362
+ **Returns**: A new `Resampler` instance
1363
+
1364
+ #### Properties
1365
+
1366
+ ##### `Resampler.inputSampleRate`
1367
+
1368
+ Gets the input sample rate.
1369
+
1370
+ **Returns**: `number`
1371
+
1372
+ ##### `Resampler.outputSampleRate`
1373
+
1374
+ Gets the output sample rate.
1375
+
1376
+ **Returns**: `number`
1377
+
1378
+ ##### `Resampler.delay`
1379
+
1380
+ Gets the resampler delay in samples.
1381
+
1382
+ **Returns**: `number`
1383
+
1384
+ #### Methods
1385
+
1386
+ ##### `Resampler.convert(inputFrame, outputFrame)`
1387
+
1388
+ Converts audio data from input frame to output frame.
1389
+
1390
+ Parameters:
1391
+
1392
+ - `inputFrame` (`Frame`): The input audio frame
1393
+ - `outputFrame` (`Frame`): The output audio frame
1394
+
1395
+ **Returns**: `number` of samples converted
1396
+
1397
+ ##### `Resampler.flush(outputFrame)`
1398
+
1399
+ Flushes any remaining samples in the resampler.
1400
+
1401
+ Parameters:
1402
+
1403
+ - `outputFrame` (`Frame`): The output audio frame
1404
+
1405
+ **Returns**: `number` of samples flushed
1406
+
1407
+ ##### `Resampler.destroy()`
1408
+
1409
+ Destroys the `Resampler` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
1410
+
1411
+ **Returns**: `void`
1412
+
1413
+ ### `Scaler`
1414
+
1415
+ The `Scaler` API provides functionality to scale and convert video frames between different pixel formats and resolutions.
1416
+
1417
+ ```js
1418
+ const scaler = new ffmpeg.Scaler(
1419
+ sourcePixelFormat,
1420
+ sourceWidth,
1421
+ sourceHeight,
1422
+ targetPixelFormat,
1423
+ targetWidth,
1424
+ targetHeight
1425
+ )
1426
+ ```
1427
+
1428
+ Parameters:
1429
+
1430
+ - `sourcePixelFormat` (`number` | `string`): Source pixel format
1431
+ - `sourceWidth` (`number`): Source width in pixels
1432
+ - `sourceHeight` (`number`): Source height in pixels
1433
+ - `targetPixelFormat` (`number` | `string`): Target pixel format
1434
+ - `targetWidth` (`number`): Target width in pixels
1435
+ - `targetHeight` (`number`): Target height in pixels
1436
+
1437
+ **Returns**: A new `Scaler` instance
1438
+
1439
+ #### Methods
1440
+
1441
+ ##### `Scaler.scale(source, target)`
1442
+
1443
+ Scales a source frame to a target frame.
1444
+
1445
+ Parameters:
1446
+
1447
+ - `source` (`Frame`): The source frame
1448
+ - `target` (`Frame`): The target frame
1449
+
1450
+ **Returns**: `boolean` indicating success
1451
+
1452
+ ##### `Scaler.scale(source, y, height, target)`
1453
+
1454
+ Scales a portion of a source frame to a target frame.
1455
+
1456
+ Parameters:
1457
+
1458
+ - `source` (`Frame`): The source frame
1459
+ - `y` (`number`): Starting Y coordinate
1460
+ - `height` (`number`): Height to scale
1461
+ - `target` (`Frame`): The target frame
1462
+
1463
+ **Returns**: `boolean` indicating success
1464
+
1465
+ ##### `Scaler.destroy()`
1466
+
1467
+ Destroys the `Scaler` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
1468
+
1469
+ **Returns**: `void`
1470
+
1471
+ ### `Filter`
1472
+
1473
+ The `Filter` API provides access to FFmpeg filters by name.
1474
+
1475
+ ```js
1476
+ const filter = new ffmpeg.Filter(name)
1477
+ ```
1478
+
1479
+ Parameters:
1480
+
1481
+ - `name` (`string`): The filter name (e.g., `'scale'`, `'buffer'`, `'overlay'`)
1482
+
1483
+ **Returns**: A new `Filter` instance
1484
+
1485
+ #### Example
1486
+
1487
+ ```js
1488
+ const filter = new ffmpeg.Filter('buffer')
1489
+ ```
1490
+
1491
+ ### `FilterGraph`
1492
+
1493
+ The `FilterGraph` API provides functionality to create and manage complex filter chains for audio and video processing.
1494
+
1495
+ ```js
1496
+ const graph = new ffmpeg.FilterGraph()
1497
+ ```
1498
+
1499
+ **Returns**: A new `FilterGraph` instance
1500
+
1501
+ #### Methods
1502
+
1503
+ ##### `FilterGraph.createFilter(context, filter, name, args)`
1504
+
1505
+ Creates a filter within the filter graph with the specified parameters.
1506
+
1507
+ Parameters:
1508
+
1509
+ - `context` (`FilterContext`): The filter context to associate with this filter
1510
+ - `filter` (`Filter`): The filter to create (e.g., `new ffmpeg.Filter('buffer')`)
1511
+ - `name` (`string`): A unique name for this filter instance
1512
+ - `args` (`object` | `undefined`): Filter-specific arguments
1513
+ - `width` (`number`): Video width in pixels
1514
+ - `height` (`number`): Video height in pixels
1515
+ - `pixelFormat` (`number`): Pixel format constant
1516
+ - `timeBase` (`Rational`): Time base for the filter
1517
+ - `aspectRatio` (`Rational`): Pixel aspect ratio
1518
+
1519
+ **Returns**: `void`
1520
+
1521
+ ```js
1522
+ using graph = new ffmpeg.FilterGraph()
1523
+ const context = new ffmpeg.FilterContext()
1524
+ const filter = new ffmpeg.Filter('buffer')
1525
+
1526
+ graph.createFilter(context, filter, 'in', {
1527
+ width: 1920,
1528
+ height: 1080,
1529
+ pixelFormat: ffmpeg.constants.pixelFormats.RGB24,
1530
+ timeBase: new ffmpeg.Rational(1, 30),
1531
+ aspectRatio: new ffmpeg.Rational(1, 1)
1532
+ })
1533
+ ```
1534
+
1535
+ ##### `FilterGraph.parse(filterDescription, inputs, outputs)`
1536
+
1537
+ Parses a filter description string and applies it to the filter graph.
1538
+
1539
+ Parameters:
1540
+
1541
+ - `filterDescription` (`string`): The filter description (e.g., `'negate'`, `'scale=640:480'`)
1542
+ - `inputs` (`FilterInOut`): Input filter endpoints
1543
+ - `outputs` (`FilterInOut`): Output filter endpoints
1544
+
1545
+ **Returns**: `void`
1546
+
1547
+ ##### `FilterGraph.configure()`
1548
+
1549
+ Configures the filter graph and validates all connections.
1550
+
1551
+ **Returns**: `void`
1552
+
1553
+ ##### `FilterGraph.destroy()`
1554
+
1555
+ Destroys the `FilterGraph` and frees all associated resources including any created filters. Automatically called when the object is managed by a `using` declaration.
1556
+
1557
+ **Returns**: `void`
1558
+
1559
+ ### `AudioFIFO`
1560
+
1561
+ The `AudioFIFO` API provides a first in first out buffer for audio samples. This is useful for buffering audio data between different processing stages.
1562
+
1563
+ ```js
1564
+ const fifo = new ffmpeg.AudioFIFO(sampleFormat, channels, nbSamples)
1565
+ ```
1566
+
1567
+ Parameters:
1568
+
1569
+ - `sampleFormat` (`number` | `string`): The audio sample format
1570
+ - `channels` (`number`): Number of audio channels
1571
+ - `nbSamples` (`number`): Initial buffer size in samples
1572
+
1573
+ **Returns**: A new `AudioFIFO` instance
1574
+
1575
+ Example:
1576
+
1577
+ ```js
1578
+ const fifo = new ffmpeg.AudioFIFO(ffmpeg.constants.sampleFormats.S16, 2, 1024)
1579
+ ```
1580
+
1581
+ #### Properties
1582
+
1583
+ ##### `AudioFIFO.size`
1584
+
1585
+ Gets the number of samples currently in the FIFO.
1586
+
1587
+ **Returns**: `number`
1588
+
1589
+ ##### `AudioFIFO.space`
1590
+
1591
+ Gets the number of samples that can be written to the FIFO.
1592
+
1593
+ **Returns**: `number`
1594
+
1595
+ #### Methods
1596
+
1597
+ ##### `AudioFIFO.write(frame)`
1598
+
1599
+ Writes samples from a frame to the FIFO. The FIFO will automatically grow if needed.
1600
+
1601
+ Parameters:
1602
+
1603
+ - `frame` (`Frame`): The audio frame containing samples to write
1604
+
1605
+ **Returns**: `number` of samples written
1606
+
1607
+ ##### `AudioFIFO.read(frame, nbSamples)`
1608
+
1609
+ Reads samples from the FIFO into a frame.
1610
+
1611
+ Parameters:
1612
+
1613
+ - `frame` (`Frame`): The frame to read samples into
1614
+ - `nbSamples` (`number`): Number of samples to read
1615
+
1616
+ **Returns**: `number` of samples actually read
1617
+
1618
+ ##### `AudioFIFO.peek(frame, nbSamples)`
1619
+
1620
+ Reads samples from the FIFO without removing them.
1621
+
1622
+ Parameters:
1623
+
1624
+ - `frame` (`Frame`): The frame to read samples into
1625
+ - `nbSamples` (`number`): Number of samples to peek
1626
+
1627
+ **Returns**: `number` of samples peeked
1628
+
1629
+ ##### `AudioFIFO.drain(nbSamples)`
1630
+
1631
+ Removes samples from the FIFO without reading them.
1632
+
1633
+ Parameters:
1634
+
1635
+ - `nbSamples` (`number`): Number of samples to drain
1636
+
1637
+ **Returns**: `void`
1638
+
1639
+ ##### `AudioFIFO.reset()`
1640
+
1641
+ Resets the FIFO to empty state.
1642
+
1643
+ **Returns**: `void`
1644
+
1645
+ ##### `AudioFIFO.destroy()`
1646
+
1647
+ Destroys the `AudioFIFO` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
1648
+
1649
+ **Returns**: `void`
1650
+
1651
+ ### `FilterInOut`
1652
+
1653
+ The `FilterInOut` API provides functionality to represent input and output pads for FFmpeg filter graphs.
1654
+
1655
+ ```js
1656
+ const filterInOut = new ffmpeg.FilterInOut()
1657
+ ```
1658
+
1659
+ **Returns**: A new `FilterInOut` instance
1660
+
1661
+ > **Note**: FilterInOut objects form a linked list structure in FFmpeg. When destroying a FilterInOut that has a `next` reference, the entire chain is automatically freed. Only destroy the head of the chain to avoid double-free errors.
1662
+
1663
+ #### Properties
1664
+
1665
+ ##### `FilterInOut.name`
1666
+
1667
+ Gets or sets the name identifier for this input/output pad.
1668
+
1669
+ **Returns**: `string` or `undefined` if not set
1670
+
1671
+ ```js
1672
+ const filterInOut = new ffmpeg.FilterInOut()
1673
+ filterInOut.name = 'input'
1674
+ console.log(filterInOut.name) // 'input'
1675
+ ```
1676
+
1677
+ ##### `FilterInOut.padIdx`
1678
+
1679
+ Gets or sets the pad index within the filter context.
1680
+
1681
+ **Returns**: `number`
1682
+
1683
+ ```js
1684
+ filterInOut.padIdx = 0
1685
+ console.log(filterInOut.padIdx) // 0
1686
+ ```
1687
+
1688
+ ##### `FilterInOut.filterContext`
1689
+
1690
+ Gets or sets the filter context associated with this input/output pad.
1691
+
1692
+ **Returns**: `FilterContext` instance or `null` if not set
1693
+
1694
+ > **Note**: FilterContext must be created through FilterGraph operations before it can be used effectively.
1695
+
1696
+ ##### `FilterInOut.next`
1697
+
1698
+ Gets or sets the next FilterInOut in the linked list chain.
1699
+
1700
+ **Returns**: `FilterInOut` instance or `null` if this is the last in the chain
1701
+
1702
+ ```js
1703
+ const input = new ffmpeg.FilterInOut()
1704
+ const output = new ffmpeg.FilterInOut()
1705
+ output.name = 'output'
1706
+
1707
+ input.next = output
1708
+ console.log(input.next.name) // 'output'
1709
+ ```
1710
+
1711
+ #### Methods
1712
+
1713
+ ##### `FilterInOut.destroy()`
1714
+
1715
+ Destroys the `FilterInOut` and frees all associated resources. **Important**: This automatically frees the entire linked list chain via FFmpeg's `avfilter_inout_free()`.
1716
+
1717
+ **Returns**: `void`
1718
+
1719
+ ```js
1720
+ const head = new ffmpeg.FilterInOut()
1721
+ const next = new ffmpeg.FilterInOut()
1722
+ head.next = next
1723
+
1724
+ // Only destroy the head - 'next' is automatically freed
1725
+ head.destroy()
1726
+ // DO NOT call next.destroy() - causes double-free error
1727
+ ```
1728
+
1729
+ ### Constants and Utilities
1730
+
1731
+ The `constants` module provides utility functions for working with FFmpeg format constants and conversions.
1732
+
1733
+ #### Methods
1734
+
1735
+ ##### `ffmpeg.constants.toPixelFormat(format)`
1736
+
1737
+ Converts a pixel format string or number to its corresponding constant value.
1738
+
1739
+ Parameters:
1740
+
1741
+ - `format` (`string` | `number`): The pixel format name (e.g., `'RGB24'`, `'YUV420P'`) or constant value
1742
+
1743
+ **Returns**: `number` - The pixel format constant
1744
+
1745
+ **Throws**: Error if the format is unknown or invalid type
1746
+
1747
+ ```js
1748
+ const format = ffmpeg.constants.toPixelFormat('RGB24')
1749
+ console.log(format) // Outputs the RGB24 constant value
1750
+ ```
1751
+
1752
+ ##### `ffmpeg.constants.toSampleFormat(format)`
1753
+
1754
+ Converts a sample format string or number to its corresponding constant value.
1755
+
1756
+ Parameters:
1757
+
1758
+ - `format` (`string` | `number`): The sample format name (e.g., `'S16'`, `'FLTP'`) or constant value
1759
+
1760
+ **Returns**: `number` - The sample format constant
1761
+
1762
+ **Throws**: Error if the format is unknown or invalid type
1763
+
1764
+ ```js
1765
+ const format = ffmpeg.constants.toSampleFormat('S16')
1766
+ console.log(format) // Outputs the S16 constant value
1767
+ ```
1768
+
1769
+ ##### `ffmpeg.constants.toChannelLayout(layout)`
1770
+
1771
+ Converts a channel layout string or number to its corresponding constant value.
1772
+
1773
+ Parameters:
1774
+
1775
+ - `layout` (`string` | `number`): The channel layout name (e.g., `'STEREO'`, `'5.1'`) or constant value
1776
+
1777
+ **Returns**: `number` - The channel layout constant
1778
+
1779
+ **Throws**: Error if the layout is unknown or invalid type
1780
+
1781
+ ```js
1782
+ const layout = ffmpeg.constants.toChannelLayout('STEREO')
1783
+ console.log(layout) // Outputs the STEREO constant value
1784
+ ```
1785
+
1786
+ ##### `ffmpeg.constants.getSampleFormatName(sampleFormat)`
1787
+
1788
+ Gets the human-readable name of a sample format from its constant value.
1789
+
1790
+ Parameters:
1791
+
1792
+ - `sampleFormat` (`number`): The sample format constant
1793
+
1794
+ **Returns**: `string` - The sample format name
1795
+
1796
+ ```js
1797
+ const name = ffmpeg.constants.getSampleFormatName(
1798
+ ffmpeg.constants.sampleFormats.S16
1799
+ )
1800
+ console.log(name) // 's16'
1801
+ ```
1802
+
1803
+ ##### `ffmpeg.constants.getPixelFormatName(pixelFormat)`
1804
+
1805
+ Gets the human-readable name of a pixel format from its constant value.
1806
+
1807
+ Parameters:
1808
+
1809
+ - `pixelFormat` (`number`): The pixel format constant
1810
+
1811
+ **Returns**: `string` - The pixel format name
1812
+
1813
+ ```js
1814
+ const name = ffmpeg.constants.getPixelFormatName(
1815
+ ffmpeg.constants.pixelFormats.RGB24
1816
+ )
1817
+ console.log(name) // 'rgb24'
1818
+ ```
1819
+
9
1820
  ## License
10
1821
 
11
1822
  Apache-2.0