bare-ffmpeg 1.0.0-26 → 1.0.0-28
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.
- package/README.md +289 -0
- package/binding.cc +563 -34
- package/index.js +8 -0
- package/lib/codec-context.js +48 -0
- package/lib/codec-parameters.js +6 -2
- package/lib/constants.js +9 -0
- package/lib/filter-context.js +7 -0
- package/lib/filter-graph.js +54 -0
- package/lib/filter-inout.js +55 -0
- package/lib/filter.js +7 -0
- package/lib/frame.js +4 -0
- package/lib/input-format.js +8 -0
- package/lib/output-format.js +8 -0
- package/lib/packet.js +6 -1
- package/lib/rational.js +15 -3
- package/lib/samples.js +40 -25
- package/lib/stream.js +11 -0
- package/package.json +4 -2
- package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
package/README.md
CHANGED
|
@@ -407,6 +407,20 @@ Gets or sets the frame height for video codecs.
|
|
|
407
407
|
|
|
408
408
|
**Returns**: `number`
|
|
409
409
|
|
|
410
|
+
##### `CodecContext.frameSize`
|
|
411
|
+
|
|
412
|
+
Gets the number of samples per channel in an audio frame.
|
|
413
|
+
|
|
414
|
+
**Returns**: `number`
|
|
415
|
+
|
|
416
|
+
##### `CodecContext.frameNum`
|
|
417
|
+
|
|
418
|
+
When encoding this gets the total number of frames passed to the encoder so far.
|
|
419
|
+
|
|
420
|
+
When decoding this gets the total number of frames returned from the decoder so far.
|
|
421
|
+
|
|
422
|
+
**Returns**: `number`
|
|
423
|
+
|
|
410
424
|
#### Methods
|
|
411
425
|
|
|
412
426
|
##### `CodecContext.open([options])`
|
|
@@ -459,6 +473,52 @@ Parameters:
|
|
|
459
473
|
|
|
460
474
|
**Returns**: `boolean` indicating if a packet was received
|
|
461
475
|
|
|
476
|
+
##### `CodecContext.getSupportedConfig(config)`
|
|
477
|
+
|
|
478
|
+
Gets the supported values for a codec configuration option.
|
|
479
|
+
|
|
480
|
+
Parameters:
|
|
481
|
+
|
|
482
|
+
- `config` (`number`): The configuration type from `ffmpeg.constants.codecConfig`
|
|
483
|
+
|
|
484
|
+
**Returns**:
|
|
485
|
+
|
|
486
|
+
- For `PIX_FORMAT`, `SAMPLE_FORMAT`, `COLOR_RANGE`, `COLOR_SPACE`: `Int32Array` of supported values (all valid values are included if the codec has no restrictions)
|
|
487
|
+
- For `SAMPLE_RATE`: `Int32Array` of supported sample rates or `null` if the codec accepts any valid sample rate
|
|
488
|
+
- For `FRAME_RATE`: Array of `Rational` instances or `null` if the codec accepts any valid frame rate
|
|
489
|
+
- For `CHANNEL_LAYOUT`: Array of `ChannelLayout` instances or `null` if the codec accepts any valid channel layout
|
|
490
|
+
|
|
491
|
+
**Throws**: Error if the config type is not applicable to this codec (e.g., asking for pixel formats from an audio codec)
|
|
492
|
+
|
|
493
|
+
Examples:
|
|
494
|
+
|
|
495
|
+
```js
|
|
496
|
+
const codecCtx = new ffmpeg.CodecContext(ffmpeg.Codec.AV1.encoder)
|
|
497
|
+
|
|
498
|
+
const pixelFormats = codecCtx.getSupportedConfig(
|
|
499
|
+
ffmpeg.constants.codecConfig.PIX_FORMAT
|
|
500
|
+
)
|
|
501
|
+
if (pixelFormats) {
|
|
502
|
+
console.log('Supported pixel formats:', pixelFormats)
|
|
503
|
+
}
|
|
504
|
+
|
|
505
|
+
const frameRates = codecCtx.getSupportedConfig(
|
|
506
|
+
ffmpeg.constants.codecConfig.FRAME_RATE
|
|
507
|
+
)
|
|
508
|
+
if (frameRates) {
|
|
509
|
+
frameRates.forEach((rate) => {
|
|
510
|
+
console.log(`${rate.toNumber()} fps`)
|
|
511
|
+
})
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
const layouts = codecCtx.getSupportedConfig(
|
|
515
|
+
ffmpeg.constants.codecConfig.CHANNEL_LAYOUT
|
|
516
|
+
)
|
|
517
|
+
if (layouts) {
|
|
518
|
+
console.log('Supported channel layouts:', layouts)
|
|
519
|
+
}
|
|
520
|
+
```
|
|
521
|
+
|
|
462
522
|
##### `CodecContext.destroy()`
|
|
463
523
|
|
|
464
524
|
Destroys the `CodecContext` and frees all associated resources. Automatically called when the object is managed by a `using` declaration.
|
|
@@ -638,6 +698,28 @@ Parameters:
|
|
|
638
698
|
|
|
639
699
|
**Returns**: A new `InputFormat` instance
|
|
640
700
|
|
|
701
|
+
#### Properties
|
|
702
|
+
|
|
703
|
+
##### `InputFormat.extensions`
|
|
704
|
+
|
|
705
|
+
Gets the file extensions associated with this input format.
|
|
706
|
+
|
|
707
|
+
**Returns**: `string` - Comma-separated list of file extensions (e.g., `'mkv,mk3d,mka,mks,webm'`)
|
|
708
|
+
|
|
709
|
+
##### `InputFormat.mimeType`
|
|
710
|
+
|
|
711
|
+
Gets the MIME type for this input format.
|
|
712
|
+
|
|
713
|
+
**Returns**: `string` - The MIME type (e.g., `'audio/webm,audio/x-matroska,video/webm,video/x-matroska'`)
|
|
714
|
+
|
|
715
|
+
#### Example
|
|
716
|
+
|
|
717
|
+
```js
|
|
718
|
+
const format = new ffmpeg.InputFormat('webm')
|
|
719
|
+
console.log(format.extensions) // 'mkv,mk3d,mka,mks,webm'
|
|
720
|
+
console.log(format.mimeType) // 'audio/webm,audio/x-matroska,video/webm,video/x-matroska'
|
|
721
|
+
```
|
|
722
|
+
|
|
641
723
|
#### Methods
|
|
642
724
|
|
|
643
725
|
##### `InputFormat.destroy()`
|
|
@@ -660,6 +742,28 @@ Parameters:
|
|
|
660
742
|
|
|
661
743
|
**Returns**: A new `OutputFormat` instance
|
|
662
744
|
|
|
745
|
+
#### Properties
|
|
746
|
+
|
|
747
|
+
##### `OutputFormat.extensions`
|
|
748
|
+
|
|
749
|
+
Gets the file extensions associated with this output format.
|
|
750
|
+
|
|
751
|
+
**Returns**: `string` - Comma-separated list of file extensions (e.g., `'webm'`, `'mp4,m4a,m4v'`)
|
|
752
|
+
|
|
753
|
+
##### `OutputFormat.mimeType`
|
|
754
|
+
|
|
755
|
+
Gets the MIME type for this output format.
|
|
756
|
+
|
|
757
|
+
**Returns**: `string` - The MIME type (e.g., `'video/webm'`, `'video/mp4'`)
|
|
758
|
+
|
|
759
|
+
#### Example
|
|
760
|
+
|
|
761
|
+
```js
|
|
762
|
+
const format = new ffmpeg.OutputFormat('webm')
|
|
763
|
+
console.log(format.extensions) // 'webm'
|
|
764
|
+
console.log(format.mimeType) // 'video/webm'
|
|
765
|
+
```
|
|
766
|
+
|
|
663
767
|
#### Methods
|
|
664
768
|
|
|
665
769
|
##### `OutputFormat.destroy()`
|
|
@@ -724,6 +828,25 @@ Destroys the `Frame` and frees all associated resources. Automatically called wh
|
|
|
724
828
|
|
|
725
829
|
**Returns**: `void`
|
|
726
830
|
|
|
831
|
+
##### `Frame.copyProperties(otherFrame)`
|
|
832
|
+
|
|
833
|
+
Copies all metadata properties such as timestamps, timebase and width/height for videoframes and
|
|
834
|
+
sampleRate channelLayout for audioFrames.
|
|
835
|
+
|
|
836
|
+
see `av_frame_copy_props()` for details.
|
|
837
|
+
|
|
838
|
+
```js
|
|
839
|
+
const src = new ffmpeg.Frame()
|
|
840
|
+
const dst = new ffmpeg.Frame()
|
|
841
|
+
|
|
842
|
+
decoder.receiveFrame(src)
|
|
843
|
+
rescaler.convert(src, dst)
|
|
844
|
+
|
|
845
|
+
dst.copyProperties(src) // transfer all meta-data
|
|
846
|
+
```
|
|
847
|
+
|
|
848
|
+
**Returns**: `void`
|
|
849
|
+
|
|
727
850
|
### `Packet`
|
|
728
851
|
|
|
729
852
|
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.
|
|
@@ -1200,6 +1323,94 @@ Destroys the `Scaler` and frees all associated resources. Automatically called w
|
|
|
1200
1323
|
|
|
1201
1324
|
**Returns**: `void`
|
|
1202
1325
|
|
|
1326
|
+
### `Filter`
|
|
1327
|
+
|
|
1328
|
+
The `Filter` API provides access to FFmpeg filters by name.
|
|
1329
|
+
|
|
1330
|
+
```js
|
|
1331
|
+
const filter = new ffmpeg.Filter(name)
|
|
1332
|
+
```
|
|
1333
|
+
|
|
1334
|
+
Parameters:
|
|
1335
|
+
|
|
1336
|
+
- `name` (`string`): The filter name (e.g., `'scale'`, `'buffer'`, `'overlay'`)
|
|
1337
|
+
|
|
1338
|
+
**Returns**: A new `Filter` instance
|
|
1339
|
+
|
|
1340
|
+
#### Example
|
|
1341
|
+
|
|
1342
|
+
```js
|
|
1343
|
+
const filter = new ffmpeg.Filter('buffer')
|
|
1344
|
+
```
|
|
1345
|
+
|
|
1346
|
+
### `FilterGraph`
|
|
1347
|
+
|
|
1348
|
+
The `FilterGraph` API provides functionality to create and manage complex filter chains for audio and video processing.
|
|
1349
|
+
|
|
1350
|
+
```js
|
|
1351
|
+
const graph = new ffmpeg.FilterGraph()
|
|
1352
|
+
```
|
|
1353
|
+
|
|
1354
|
+
**Returns**: A new `FilterGraph` instance
|
|
1355
|
+
|
|
1356
|
+
#### Methods
|
|
1357
|
+
|
|
1358
|
+
##### `FilterGraph.createFilter(context, filter, name, args)`
|
|
1359
|
+
|
|
1360
|
+
Creates a filter within the filter graph with the specified parameters.
|
|
1361
|
+
|
|
1362
|
+
Parameters:
|
|
1363
|
+
|
|
1364
|
+
- `context` (`FilterContext`): The filter context to associate with this filter
|
|
1365
|
+
- `filter` (`Filter`): The filter to create (e.g., `new ffmpeg.Filter('buffer')`)
|
|
1366
|
+
- `name` (`string`): A unique name for this filter instance
|
|
1367
|
+
- `args` (`object` | `undefined`): Filter-specific arguments
|
|
1368
|
+
- `width` (`number`): Video width in pixels
|
|
1369
|
+
- `height` (`number`): Video height in pixels
|
|
1370
|
+
- `pixelFormat` (`number`): Pixel format constant
|
|
1371
|
+
- `timeBase` (`Rational`): Time base for the filter
|
|
1372
|
+
- `aspectRatio` (`Rational`): Pixel aspect ratio
|
|
1373
|
+
|
|
1374
|
+
**Returns**: `void`
|
|
1375
|
+
|
|
1376
|
+
```js
|
|
1377
|
+
using graph = new ffmpeg.FilterGraph()
|
|
1378
|
+
const context = new ffmpeg.FilterContext()
|
|
1379
|
+
const filter = new ffmpeg.Filter('buffer')
|
|
1380
|
+
|
|
1381
|
+
graph.createFilter(context, filter, 'in', {
|
|
1382
|
+
width: 1920,
|
|
1383
|
+
height: 1080,
|
|
1384
|
+
pixelFormat: ffmpeg.constants.pixelFormats.RGB24,
|
|
1385
|
+
timeBase: new ffmpeg.Rational(1, 30),
|
|
1386
|
+
aspectRatio: new ffmpeg.Rational(1, 1)
|
|
1387
|
+
})
|
|
1388
|
+
```
|
|
1389
|
+
|
|
1390
|
+
##### `FilterGraph.parse(filterDescription, inputs, outputs)`
|
|
1391
|
+
|
|
1392
|
+
Parses a filter description string and applies it to the filter graph.
|
|
1393
|
+
|
|
1394
|
+
Parameters:
|
|
1395
|
+
|
|
1396
|
+
- `filterDescription` (`string`): The filter description (e.g., `'negate'`, `'scale=640:480'`)
|
|
1397
|
+
- `inputs` (`FilterInOut`): Input filter endpoints
|
|
1398
|
+
- `outputs` (`FilterInOut`): Output filter endpoints
|
|
1399
|
+
|
|
1400
|
+
**Returns**: `void`
|
|
1401
|
+
|
|
1402
|
+
##### `FilterGraph.configure()`
|
|
1403
|
+
|
|
1404
|
+
Configures the filter graph and validates all connections.
|
|
1405
|
+
|
|
1406
|
+
**Returns**: `void`
|
|
1407
|
+
|
|
1408
|
+
##### `FilterGraph.destroy()`
|
|
1409
|
+
|
|
1410
|
+
Destroys the `FilterGraph` and frees all associated resources including any created filters. Automatically called when the object is managed by a `using` declaration.
|
|
1411
|
+
|
|
1412
|
+
**Returns**: `void`
|
|
1413
|
+
|
|
1203
1414
|
### `AudioFIFO`
|
|
1204
1415
|
|
|
1205
1416
|
The `AudioFIFO` API provides a first in first out buffer for audio samples. This is useful for buffering audio data between different processing stages.
|
|
@@ -1292,6 +1503,84 @@ Destroys the `AudioFIFO` and frees all associated resources. Automatically calle
|
|
|
1292
1503
|
|
|
1293
1504
|
**Returns**: `void`
|
|
1294
1505
|
|
|
1506
|
+
### `FilterInOut`
|
|
1507
|
+
|
|
1508
|
+
The `FilterInOut` API provides functionality to represent input and output pads for FFmpeg filter graphs.
|
|
1509
|
+
|
|
1510
|
+
```js
|
|
1511
|
+
const filterInOut = new ffmpeg.FilterInOut()
|
|
1512
|
+
```
|
|
1513
|
+
|
|
1514
|
+
**Returns**: A new `FilterInOut` instance
|
|
1515
|
+
|
|
1516
|
+
> **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.
|
|
1517
|
+
|
|
1518
|
+
#### Properties
|
|
1519
|
+
|
|
1520
|
+
##### `FilterInOut.name`
|
|
1521
|
+
|
|
1522
|
+
Gets or sets the name identifier for this input/output pad.
|
|
1523
|
+
|
|
1524
|
+
**Returns**: `string` or `undefined` if not set
|
|
1525
|
+
|
|
1526
|
+
```js
|
|
1527
|
+
const filterInOut = new ffmpeg.FilterInOut()
|
|
1528
|
+
filterInOut.name = 'input'
|
|
1529
|
+
console.log(filterInOut.name) // 'input'
|
|
1530
|
+
```
|
|
1531
|
+
|
|
1532
|
+
##### `FilterInOut.padIdx`
|
|
1533
|
+
|
|
1534
|
+
Gets or sets the pad index within the filter context.
|
|
1535
|
+
|
|
1536
|
+
**Returns**: `number`
|
|
1537
|
+
|
|
1538
|
+
```js
|
|
1539
|
+
filterInOut.padIdx = 0
|
|
1540
|
+
console.log(filterInOut.padIdx) // 0
|
|
1541
|
+
```
|
|
1542
|
+
|
|
1543
|
+
##### `FilterInOut.filterContext`
|
|
1544
|
+
|
|
1545
|
+
Gets or sets the filter context associated with this input/output pad.
|
|
1546
|
+
|
|
1547
|
+
**Returns**: `FilterContext` instance or `null` if not set
|
|
1548
|
+
|
|
1549
|
+
> **Note**: FilterContext must be created through FilterGraph operations before it can be used effectively.
|
|
1550
|
+
|
|
1551
|
+
##### `FilterInOut.next`
|
|
1552
|
+
|
|
1553
|
+
Gets or sets the next FilterInOut in the linked list chain.
|
|
1554
|
+
|
|
1555
|
+
**Returns**: `FilterInOut` instance or `null` if this is the last in the chain
|
|
1556
|
+
|
|
1557
|
+
```js
|
|
1558
|
+
const input = new ffmpeg.FilterInOut()
|
|
1559
|
+
const output = new ffmpeg.FilterInOut()
|
|
1560
|
+
output.name = 'output'
|
|
1561
|
+
|
|
1562
|
+
input.next = output
|
|
1563
|
+
console.log(input.next.name) // 'output'
|
|
1564
|
+
```
|
|
1565
|
+
|
|
1566
|
+
#### Methods
|
|
1567
|
+
|
|
1568
|
+
##### `FilterInOut.destroy()`
|
|
1569
|
+
|
|
1570
|
+
Destroys the `FilterInOut` and frees all associated resources. **Important**: This automatically frees the entire linked list chain via FFmpeg's `avfilter_inout_free()`.
|
|
1571
|
+
|
|
1572
|
+
**Returns**: `void`
|
|
1573
|
+
|
|
1574
|
+
```js
|
|
1575
|
+
const head = new ffmpeg.FilterInOut()
|
|
1576
|
+
const next = new ffmpeg.FilterInOut()
|
|
1577
|
+
head.next = next
|
|
1578
|
+
|
|
1579
|
+
// Only destroy the head - 'next' is automatically freed
|
|
1580
|
+
head.destroy()
|
|
1581
|
+
// DO NOT call next.destroy() - causes double-free error
|
|
1582
|
+
```
|
|
1583
|
+
|
|
1295
1584
|
## License
|
|
1296
1585
|
|
|
1297
1586
|
Apache-2.0
|