bare-ffmpeg 1.0.0-9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (58) hide show
  1. package/CMakeLists.txt +32 -10
  2. package/README.md +65 -769
  3. package/binding.cc +5372 -0
  4. package/cmake/ports/ffmpeg/port.cmake +513 -0
  5. package/cmake/ports/libdrm/port.cmake +32 -0
  6. package/cmake/ports/libva/port.cmake +53 -0
  7. package/cmake/ports/opus/patches/01-windows-clang.patch +52 -0
  8. package/cmake/ports/opus/port.cmake +42 -0
  9. package/cmake/ports/svt-av1/port.cmake +42 -0
  10. package/cmake/ports/x264/patches/01-windows-clang.patch +33 -0
  11. package/cmake/ports/x264/port.cmake +162 -0
  12. package/index.js +28 -9
  13. package/lib/audio-fifo.js +47 -0
  14. package/lib/channel-layout.js +35 -0
  15. package/lib/codec-context.js +185 -7
  16. package/lib/codec-parameters.js +252 -4
  17. package/lib/codec.js +16 -0
  18. package/lib/constants.js +339 -12
  19. package/lib/dictionary.js +20 -0
  20. package/lib/errors.js +26 -0
  21. package/lib/filter-context.js +7 -0
  22. package/lib/filter-graph.js +42 -0
  23. package/lib/filter-inout.js +52 -0
  24. package/lib/filter.js +7 -0
  25. package/lib/format-context.js +42 -23
  26. package/lib/frame.js +81 -12
  27. package/lib/hw-device-context.js +31 -0
  28. package/lib/hw-frames-constraints.js +54 -0
  29. package/lib/hw-frames-context.js +92 -0
  30. package/lib/image.js +14 -3
  31. package/lib/input-format.js +36 -2
  32. package/lib/io-context.js +29 -4
  33. package/lib/log.js +16 -0
  34. package/lib/output-format.js +33 -2
  35. package/lib/packet.js +143 -1
  36. package/lib/rational.js +46 -1
  37. package/lib/resampler.js +23 -17
  38. package/lib/samples.js +85 -0
  39. package/lib/scaler.js +3 -9
  40. package/lib/stream.js +51 -14
  41. package/package.json +9 -5
  42. package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
  43. package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
  44. package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
  45. package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
  46. package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
  47. package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
  48. package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
  49. package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
  50. package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
  51. package/prebuilds/linux-arm64/bare-ffmpeg/libva-drm.so.2 +0 -0
  52. package/prebuilds/linux-arm64/bare-ffmpeg/libva.so.2 +0 -0
  53. package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
  54. package/prebuilds/linux-x64/bare-ffmpeg/libva-drm.so.2 +0 -0
  55. package/prebuilds/linux-x64/bare-ffmpeg/libva.so.2 +0 -0
  56. package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
  57. package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
  58. package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
package/README.md CHANGED
@@ -2,818 +2,114 @@
2
2
 
3
3
  Low-level FFmpeg bindings for Bare.
4
4
 
5
- ```
6
- npm i bare-ffmpeg
7
- ```
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`
5
+ ## Installation
181
6
 
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
7
  ```
315
-
316
- #### Properties
317
-
318
- ##### `CodecParameters.bitRate`
319
-
320
- Gets the bit rate.
321
-
322
- **Returns**: `number`
323
-
324
- ##### `CodecParameters.bitsPerCodedSample`
325
-
326
- Gets the bits per coded sample.
327
-
328
- **Returns**: `number`
329
-
330
- ##### `CodecParameters.bitsPerRawSample`
331
-
332
- Gets the bits per raw sample.
333
-
334
- **Returns**: `number`
335
-
336
- ##### `CodecParameters.sampleRate`
337
-
338
- Gets the sample rate for audio codecs.
339
-
340
- **Returns**: `number`
341
-
342
- #### Methods
343
-
344
- ##### `CodecParameters.fromContext(context)`
345
-
346
- Copies parameters from a codec context.
347
-
348
- Parameters:
349
-
350
- - `context` (`CodecContext`): The codec context
351
-
352
- **Returns**: `void`
353
-
354
- ##### `CodecParameters.toContext(context)`
355
-
356
- Copies parameters to a codec context.
357
-
358
- Parameters:
359
-
360
- - `context` (`CodecContext`): The codec context
361
-
362
- **Returns**: `void`
363
-
364
- ##### `CodecParameters.destroy()`
365
-
366
- Destroys the `CodecParameters` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
367
-
368
- **Returns**: `void`
369
-
370
- ### `InputFormat`
371
-
372
- The `InputFormat` API provides functionality to specify input format for media sources.
373
-
374
- ```js
375
- const format = new ffmpeg.InputFormat([name])
8
+ npm i bare-ffmpeg
376
9
  ```
377
10
 
378
- Parameters:
379
-
380
- - `name` (`string`, optional): The input format name. Defaults to a platform-specific value:
381
- - `darwin`, `ios`: ``'avfoundation'`
382
- - `linux`: `'v4l2'`
383
- - `win32`: `'dshow'`
11
+ ## API Documentation
384
12
 
385
- **Returns**: A new `InputFormat` instance
13
+ Complete API documentation for all components is available in the `/docs` directory:
386
14
 
387
- #### Methods
15
+ ### Core Components
388
16
 
389
- ##### `InputFormat.destroy()`
17
+ - [IOContext](docs/io-context.md) - Input/output context for media files with streaming support
18
+ - [Dictionary](docs/dictionary.md) - Key-value pairs for FFmpeg options
390
19
 
391
- Destroys the `InputFormat` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
20
+ ### Codecs & Streams
392
21
 
393
- **Returns**: `void`
22
+ - [Codec](docs/codec.md) - Access to FFmpeg codecs
23
+ - [CodecContext](docs/codec-context.md) - Encoding/decoding functionality
24
+ - [CodecParameters](docs/codec-parameters.md) - Codec parameter configuration
25
+ - [Stream](docs/stream.md) - Media stream information and operations
394
26
 
395
- ### `OutputFormat`
27
+ ### Formats
396
28
 
397
- The `OutputFormat` API provides functionality to specify output format for media files.
29
+ - [InputFormat](docs/input-format.md) - Input format specification
30
+ - [OutputFormat](docs/output-format.md) - Output format specification
31
+ - [FormatContext](docs/format-context.md) - Base class for media file handling
32
+ - [InputFormatContext](docs/input-format-context.md) - Reading media files
33
+ - [OutputFormatContext](docs/output-format-context.md) - Writing media files
398
34
 
399
- ```js
400
- const format = new ffmpeg.OutputFormat(name)
401
- ```
35
+ ### Data Structures
402
36
 
403
- Parameters:
37
+ - [Frame](docs/frame.md) - Decoded audio/video data
38
+ - [Packet](docs/packet.md) - Encoded audio/video data
39
+ - [SideData](docs/side-data.md) - Packet side data and metadata
40
+ - [Image](docs/image.md) - Raw pixel data management
41
+ - [Rational](docs/rational.md) - Rational number (fraction) representation
404
42
 
405
- - `name` (`string`): The output format name (e.g., `'mp4'`, `'avi'`, `'mov'`)
43
+ ### Processing
406
44
 
407
- **Returns**: A new `OutputFormat` instance
45
+ - [Scaler](docs/scaler.md) - Video scaling and pixel format conversion
46
+ - [Resampler](docs/resampler.md) - Audio resampling and format conversion
47
+ - [Filter](docs/filter.md) - FFmpeg filter access
48
+ - [FilterGraph](docs/filter-graph.md) - Filter chain management
49
+ - [FilterContext](docs/filter-context.md) - Filter instance representation
50
+ - [FilterInOut](docs/filter-in-out.md) - Filter input/output pads
51
+ - [AudioFIFO](docs/audio-fifo.md) - Audio sample buffering
408
52
 
409
- #### Methods
53
+ ### Hardware Acceleration
410
54
 
411
- ##### `OutputFormat.destroy()`
55
+ - [HWDeviceContext](docs/hw-device-context.md) - Hardware device context for acceleration
56
+ - [HWFramesContext](docs/hw-frames-context.md) - Hardware frame pool management
57
+ - [HWFramesConstraints](docs/hw-frames-constraints.md) - Hardware capability information
412
58
 
413
- Destroys the `OutputFormat` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
59
+ ### Utilities
414
60
 
415
- **Returns**: `void`
61
+ - [Constants](docs/constants.md) - FFmpeg constants and utility functions
416
62
 
417
- ### `Frame`
63
+ ## Building
418
64
 
419
- This structure describes decoded (raw) audio or video data.
65
+ <https://github.com/holepunchto/bare-make> is used for compiling the native bindings in [`binding.cc`](binding.cc). Start by installing the tool globally:
420
66
 
421
- ```js
422
- const frame = new ffmpeg.Frame()
67
+ ```console
68
+ npm i -g bare-make
423
69
  ```
424
70
 
425
- **Returns**: A new `Frame` instance
426
-
427
- #### Properties
428
-
429
- ##### `Frame.width`
430
-
431
- Gets or sets the frame width.
432
-
433
- **Returns**: `number`
434
-
435
- ##### `Frame.height`
436
-
437
- Gets or sets the frame height.
438
-
439
- **Returns**: `number`
440
-
441
- ##### `Frame.pixelFormat`
442
-
443
- Gets or sets the pixel format.
444
-
445
- **Returns**: `number` (pixel format constant)
71
+ Next, generate the build system for compiling the bindings, optionally setting the `--debug` flag to enable debug symbols and assertions:
446
72
 
447
- ##### `Frame.format`
448
-
449
- Gets or sets the sample format for audio frames.
450
-
451
- **Returns**: `number` (sample format constant)
452
-
453
- ##### `Frame.channelLayout`
454
-
455
- Gets or sets the channel layout for audio frames.
456
-
457
- **Returns**: `number` (channel layout constant)
458
-
459
- ##### `Frame.nbSamples`
460
-
461
- Gets or sets the number of audio samples.
462
-
463
- **Returns**: `number`
464
-
465
- #### Methods
466
-
467
- ##### `Frame.alloc()`
468
-
469
- Allocates memory for the frame data.
470
-
471
- **Returns**: `void`
472
-
473
- ##### `Frame.destroy()`
474
-
475
- Destroys the `Frame` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
476
-
477
- **Returns**: `void`
478
-
479
- ### `Packet`
480
-
481
- 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.
482
-
483
- ```js
484
- const packet = new ffmpeg.Packet([buffer])
73
+ ```console
74
+ bare-make generate [--debug]
485
75
  ```
486
76
 
487
- Parameters:
488
-
489
- - `buffer` (`Buffer`, optional): Initial packet data
490
-
491
- **Returns**: A new `Packet` instance
492
-
493
- #### Properties
77
+ This only has to be run once per repository checkout. When updating `bare-make` or your compiler toolchain it might also be necessary to regenerate the build system. To do so, run the command again with the `--no-cache` flag set to disregard the existing build system cache:
494
78
 
495
- ##### `Packet.data`
496
-
497
- Gets the packet data buffer.
498
-
499
- **Returns**: `Buffer`
500
-
501
- ##### `Packet.streamIndex`
502
-
503
- Gets the stream index this packet belongs to.
504
-
505
- **Returns**: `number`
506
-
507
- #### Methods
508
-
509
- ##### `Packet.unref()`
510
-
511
- Decrements the reference count and unreferences the packet.
512
-
513
- **Returns**: `void`
514
-
515
- ##### `Packet.destroy()`
516
-
517
- Destroys the `Packet` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
518
-
519
- **Returns**: `void`
520
-
521
- ### `Image`
522
-
523
- The `Image` API provides functionality to create and manage image buffers.
524
-
525
- ```js
526
- const image = new ffmpeg.Image(pixelFormat, width, height[, align])
79
+ ```console
80
+ bare-make generate [--debug] --no-cache
527
81
  ```
528
82
 
529
- Parameters:
530
-
531
- - `pixelFormat` (`number` | `string`): The pixel format
532
- - `width` (`number`): The image width in pixels
533
- - `height` (`number`): The image height in pixels
534
- - `align` (`number`, optional): Memory alignment. Defaults to 1
535
-
536
- **Returns**: A new `Image` instance
537
-
538
- #### Properties
539
-
540
- ##### `Image.pixelFormat`
541
-
542
- Gets the pixel format.
543
-
544
- **Returns**: `number`
545
-
546
- ##### `Image.width`
547
-
548
- Gets the image width.
549
-
550
- **Returns**: `number`
551
-
552
- ##### `Image.height`
553
-
554
- Gets the image height.
555
-
556
- **Returns**: `number`
557
-
558
- ##### `Image.align`
559
-
560
- Gets the memory alignment.
561
-
562
- **Returns**: `number`
563
-
564
- ##### `Image.data`
565
-
566
- Gets the image data buffer.
567
-
568
- **Returns**: `Buffer`
569
-
570
- #### Methods
571
-
572
- ##### `Image.fill(frame)`
573
-
574
- Fills a frame with the image data.
575
-
576
- Parameters:
577
-
578
- - `frame` (`Frame`): The frame to fill
579
-
580
- **Returns**: void
581
-
582
- ##### `Image.lineSize([plane])`
583
-
584
- Gets the line size for a specific plane.
585
-
586
- Parameters:
587
-
588
- - `plane` (`number`, optional): Plane index. Defaults to 0
83
+ With a build system generated, the bindings can be compiled:
589
84
 
590
- **Returns**: `number`
591
-
592
- #### Static methods
593
-
594
- ##### `Image.lineSize(pixelFormat, width[, plane])`
595
-
596
- Static method to get line size for a pixel format.
597
-
598
- Parameters:
599
-
600
- - `pixelFormat` (`number` | `string`): The pixel format
601
- - `width` (`number`): The image width
602
- - `plane` (`number`, optional): Plane index. Defaults to 0
603
-
604
- **Returns**: `number`
605
-
606
- ### `Rational`
607
-
608
- The `Rational` API provides functionality to represent rational numbers (fractions).
609
-
610
- ```js
611
- const rational = new ffmpeg.Rational(numerator, denominator)
85
+ ```console
86
+ bare-make build
612
87
  ```
613
88
 
614
- Parameters:
615
-
616
- - `numerator` (`number`): The numerator
617
- - `denominator` (`number`): The denominator
618
-
619
- **Returns**: A new `Rational` instance
89
+ This will compile the bindings and output the resulting shared library module to the `build/` directory. To install it into the `prebuilds/` directory where the Bare addon resolution algorithm expects to find it, do:
620
90
 
621
- #### Properties
622
-
623
- ##### `Rational.numerator`
624
-
625
- Gets the numerator.
626
-
627
- **Returns**: `number`
628
-
629
- ##### `Rational.denominator`
630
-
631
- Gets the denominator.
632
-
633
- **Returns**: `number`
634
-
635
- ### `Stream`
636
-
637
- The `Stream` API provides functionality to access media stream information and create decoders/encoders.
638
-
639
- ```js
640
- const stream = new ffmpeg.Stream(handle)
91
+ ```console
92
+ bare-make install
641
93
  ```
642
94
 
643
- Parameters:
644
-
645
- - `handle` (`ArrayBuffer`): Internal stream handle
646
-
647
- **Returns**: A new `Stream` instance
95
+ To make iteration faster during development, the shared library module can also be linked into the `prebuilds/` directory rather than copied. To do so, set the `--link` flag:
648
96
 
649
- > Streams are typically obtained from format contexts: `const stream = format.streams[0]`
650
-
651
- #### Properties
652
-
653
- ##### `Stream.codecParameters`
654
-
655
- Gets the codec parameters for this stream.
656
-
657
- **Returns**: `CodecParameters` instance
658
-
659
- ##### `Stream.codec`
660
-
661
- Gets the codec for this stream
662
-
663
- **Returns**: `Codec` instance
664
-
665
- #### Methods
666
-
667
- ##### `Stream.decoder()`
668
-
669
- Creates and opens a decoder for this stream.
670
-
671
- **Returns**: `CodecContext` instance
672
-
673
- ##### `Stream.encoder()`
674
-
675
- Creates and opens an encoder for this stream.
676
-
677
- **Returns**: `CodecContext` instance
678
-
679
- ##### `Stream.destroy()`
680
-
681
- Destroys the `Stream` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
682
-
683
- **Returns**: `void`
684
-
685
- ### `Resampler`
686
-
687
- The `Resampler` API provides functionality to convert audio between different sample rates, channel layouts, and sample formats.
688
-
689
- ```js
690
- const resampler = new ffmpeg.Resampler(
691
- inputSampleRate,
692
- inputChannelLayout,
693
- inputSampleFormat,
694
- outputSampleRate,
695
- outputChannelLayout,
696
- outputSampleFormat
697
- )
97
+ ```console
98
+ bare-make install --link
698
99
  ```
699
100
 
700
- Parameters:
701
-
702
- - `inputSampleRate` (`number`): Input sample rate in Hz
703
- - `inputChannelLayout` (`number`): Input channel layout constant
704
- - `inputSampleFormat` (`number`): Input sample format constant
705
- - `outputSampleRate` (`number`): Output sample rate in Hz
706
- - `outputChannelLayout` (`number`): Output channel layout constant
707
- - `outputSampleFormat` (`number`): Output sample format constant
708
-
709
- **Returns**: A new `Resampler` instance
710
-
711
- #### Properties
712
-
713
- ##### `Resampler.inputSampleRate`
714
-
715
- Gets the input sample rate.
716
-
717
- **Returns**: `number`
718
-
719
- ##### `Resampler.outputSampleRate`
720
-
721
- Gets the output sample rate.
722
-
723
- **Returns**: `number`
724
-
725
- ##### `Resampler.delay`
726
-
727
- Gets the resampler delay in samples.
728
-
729
- **Returns**: `number`
730
-
731
- #### Methods
732
-
733
- ##### `Resampler.convert(inputFrame, outputFrame)`
734
-
735
- Converts audio data from input frame to output frame.
736
-
737
- Parameters:
738
-
739
- - `inputFrame` (`Frame`): The input audio frame
740
- - `outputFrame` (`Frame`): The output audio frame
741
-
742
- **Returns**: `number` of samples converted
743
-
744
- ##### `Resampler.flush(outputFrame)`
745
-
746
- Flushes any remaining samples in the resampler.
747
-
748
- Parameters:
749
-
750
- - `outputFrame` (`Frame`): The output audio frame
751
-
752
- **Returns**: `number` of samples flushed
753
-
754
- ##### `Resampler.destroy()`
755
-
756
- Destroys the `Resampler` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
757
-
758
- **Returns**: `void`
759
-
760
- ### `Scaler`
761
-
762
- The `Scaler` API provides functionality to scale and convert video frames between different pixel formats and resolutions.
763
-
764
- ```js
765
- const scaler = new ffmpeg.Scaler(
766
- sourcePixelFormat,
767
- sourceWidth,
768
- sourceHeight,
769
- targetPixelFormat,
770
- targetWidth,
771
- targetHeight
772
- )
773
- ```
774
-
775
- Parameters:
776
-
777
- - `sourcePixelFormat` (`number` | `string`): Source pixel format
778
- - `sourceWidth` (`number`): Source width in pixels
779
- - `sourceHeight` (`number`): Source height in pixels
780
- - `targetPixelFormat` (`number` | `string`): Target pixel format
781
- - `targetWidth` (`number`): Target width in pixels
782
- - `targetHeight` (`number`): Target height in pixels
783
-
784
- **Returns**: A new `Scaler` instance
785
-
786
- #### Methods
787
-
788
- ##### `Scaler.scale(source, target)`
789
-
790
- Scales a source frame to a target frame.
791
-
792
- Parameters:
793
-
794
- - `source` (`Frame`): The source frame
795
- - `target` (`Frame`): The target frame
796
-
797
- **Returns**: `boolean` indicating success
798
-
799
- ##### `Scaler.scale(source, y, height, target)`
800
-
801
- Scales a portion of a source frame to a target frame.
802
-
803
- Parameters:
804
-
805
- - `source` (`Frame`): The source frame
806
- - `y` (`number`): Starting Y coordinate
807
- - `height` (`number`): Height to scale
808
- - `target` (`Frame`): The target frame
101
+ Prior to publishing the module, make sure that no links exist within the `prebuilds/` directory as these will not be included in the resulting package archive.
809
102
 
810
- **Returns**: `boolean` indicating success
103
+ ### Options
811
104
 
812
- ##### `Scaler.destroy()`
105
+ A few compile options can be configured to customize the addon. Compile options may be set by passing the `--define option=value` flag to the `bare-make generate` command when generating the build system.
813
106
 
814
- Destroys the `Scaler` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
107
+ > [!WARNING]
108
+ > The compile options are not covered by semantic versioning and are subject to change without warning.
815
109
 
816
- **Returns**: `void`
110
+ | Option | Default | Description |
111
+ | :----------------------- | :------ | :--------------------------------------- |
112
+ | `BARE_FFMPEG_ENABLE_GPL` | `OFF` | Enable GPL-licensed features (e.g, x264) |
817
113
 
818
114
  ## License
819
115