bare-ffmpeg 1.0.0-25 → 1.0.0-27
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 +299 -0
- package/binding.cc +730 -32
- package/index.js +8 -0
- package/lib/codec-context.js +63 -1
- package/lib/codec-parameters.js +14 -2
- package/lib/constants.js +57 -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/packet.js +65 -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.
|
|
@@ -752,6 +812,18 @@ Gets the stream index this packet belongs to.
|
|
|
752
812
|
|
|
753
813
|
**Returns**: `number`
|
|
754
814
|
|
|
815
|
+
##### `Packet.isKeyFrame`
|
|
816
|
+
|
|
817
|
+
Get or set the key frame flag.
|
|
818
|
+
|
|
819
|
+
**Returns**: `boolean`
|
|
820
|
+
|
|
821
|
+
##### `Packet.sideData`
|
|
822
|
+
|
|
823
|
+
Gets or sets the side data associated with the packet.
|
|
824
|
+
|
|
825
|
+
**Returns**: `Array<SideData>`
|
|
826
|
+
|
|
755
827
|
#### Methods
|
|
756
828
|
|
|
757
829
|
##### `Packet.unref()`
|
|
@@ -766,6 +838,67 @@ Destroys the `Packet` and frees all associated resources. Automatically called w
|
|
|
766
838
|
|
|
767
839
|
**Returns**: `void`
|
|
768
840
|
|
|
841
|
+
### `SideData`
|
|
842
|
+
|
|
843
|
+
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.
|
|
844
|
+
|
|
845
|
+
```js
|
|
846
|
+
const sideData = new ffmpeg.Packet.SideData(handle, options)
|
|
847
|
+
```
|
|
848
|
+
|
|
849
|
+
Parameters:
|
|
850
|
+
|
|
851
|
+
- `handle` (`ArrayBuffer`): Internal side data handle
|
|
852
|
+
- `options` (`object`, optional): Configuration options
|
|
853
|
+
- `type` (`number`): The side data type
|
|
854
|
+
- `data` (`Buffer`): The side data buffer
|
|
855
|
+
|
|
856
|
+
**Returns**: A new `SideData` instance
|
|
857
|
+
|
|
858
|
+
#### Static Methods
|
|
859
|
+
|
|
860
|
+
##### `SideData.fromData(data, type)`
|
|
861
|
+
|
|
862
|
+
Creates a new `SideData` instance from data and type.
|
|
863
|
+
|
|
864
|
+
Parameters:
|
|
865
|
+
|
|
866
|
+
- `data` (`Buffer`): The side data buffer
|
|
867
|
+
- `type` (`number`): The side data type constant
|
|
868
|
+
|
|
869
|
+
**Returns**: A new `SideData` instance
|
|
870
|
+
|
|
871
|
+
#### Properties
|
|
872
|
+
|
|
873
|
+
##### `SideData.type`
|
|
874
|
+
|
|
875
|
+
Gets the side data type.
|
|
876
|
+
|
|
877
|
+
**Returns**: `number`
|
|
878
|
+
|
|
879
|
+
##### `SideData.name`
|
|
880
|
+
|
|
881
|
+
Gets the human-readable name of the side data type.
|
|
882
|
+
|
|
883
|
+
**Returns**: `string`
|
|
884
|
+
|
|
885
|
+
##### `SideData.data`
|
|
886
|
+
|
|
887
|
+
Gets the side data buffer.
|
|
888
|
+
|
|
889
|
+
**Returns**: `Buffer`
|
|
890
|
+
|
|
891
|
+
#### Example
|
|
892
|
+
|
|
893
|
+
```js
|
|
894
|
+
const packet = new ffmpeg.Packet()
|
|
895
|
+
const sideData = ffmpeg.Packet.SideData.fromData(
|
|
896
|
+
Buffer.from('metadata'),
|
|
897
|
+
ffmpeg.constants.packetSideDataType.NEW_EXTRADATA
|
|
898
|
+
)
|
|
899
|
+
packet.sideData = [sideData]
|
|
900
|
+
```
|
|
901
|
+
|
|
769
902
|
### `Image`
|
|
770
903
|
|
|
771
904
|
The `Image` API provides functionality to create and manage image buffers.
|
|
@@ -1127,6 +1260,94 @@ Destroys the `Scaler` and frees all associated resources. Automatically called w
|
|
|
1127
1260
|
|
|
1128
1261
|
**Returns**: `void`
|
|
1129
1262
|
|
|
1263
|
+
### `Filter`
|
|
1264
|
+
|
|
1265
|
+
The `Filter` API provides access to FFmpeg filters by name.
|
|
1266
|
+
|
|
1267
|
+
```js
|
|
1268
|
+
const filter = new ffmpeg.Filter(name)
|
|
1269
|
+
```
|
|
1270
|
+
|
|
1271
|
+
Parameters:
|
|
1272
|
+
|
|
1273
|
+
- `name` (`string`): The filter name (e.g., `'scale'`, `'buffer'`, `'overlay'`)
|
|
1274
|
+
|
|
1275
|
+
**Returns**: A new `Filter` instance
|
|
1276
|
+
|
|
1277
|
+
#### Example
|
|
1278
|
+
|
|
1279
|
+
```js
|
|
1280
|
+
const filter = new ffmpeg.Filter('buffer')
|
|
1281
|
+
```
|
|
1282
|
+
|
|
1283
|
+
### `FilterGraph`
|
|
1284
|
+
|
|
1285
|
+
The `FilterGraph` API provides functionality to create and manage complex filter chains for audio and video processing.
|
|
1286
|
+
|
|
1287
|
+
```js
|
|
1288
|
+
const graph = new ffmpeg.FilterGraph()
|
|
1289
|
+
```
|
|
1290
|
+
|
|
1291
|
+
**Returns**: A new `FilterGraph` instance
|
|
1292
|
+
|
|
1293
|
+
#### Methods
|
|
1294
|
+
|
|
1295
|
+
##### `FilterGraph.createFilter(context, filter, name, args)`
|
|
1296
|
+
|
|
1297
|
+
Creates a filter within the filter graph with the specified parameters.
|
|
1298
|
+
|
|
1299
|
+
Parameters:
|
|
1300
|
+
|
|
1301
|
+
- `context` (`FilterContext`): The filter context to associate with this filter
|
|
1302
|
+
- `filter` (`Filter`): The filter to create (e.g., `new ffmpeg.Filter('buffer')`)
|
|
1303
|
+
- `name` (`string`): A unique name for this filter instance
|
|
1304
|
+
- `args` (`object` | `undefined`): Filter-specific arguments
|
|
1305
|
+
- `width` (`number`): Video width in pixels
|
|
1306
|
+
- `height` (`number`): Video height in pixels
|
|
1307
|
+
- `pixelFormat` (`number`): Pixel format constant
|
|
1308
|
+
- `timeBase` (`Rational`): Time base for the filter
|
|
1309
|
+
- `aspectRatio` (`Rational`): Pixel aspect ratio
|
|
1310
|
+
|
|
1311
|
+
**Returns**: `void`
|
|
1312
|
+
|
|
1313
|
+
```js
|
|
1314
|
+
using graph = new ffmpeg.FilterGraph()
|
|
1315
|
+
const context = new ffmpeg.FilterContext()
|
|
1316
|
+
const filter = new ffmpeg.Filter('buffer')
|
|
1317
|
+
|
|
1318
|
+
graph.createFilter(context, filter, 'in', {
|
|
1319
|
+
width: 1920,
|
|
1320
|
+
height: 1080,
|
|
1321
|
+
pixelFormat: ffmpeg.constants.pixelFormats.RGB24,
|
|
1322
|
+
timeBase: new ffmpeg.Rational(1, 30),
|
|
1323
|
+
aspectRatio: new ffmpeg.Rational(1, 1)
|
|
1324
|
+
})
|
|
1325
|
+
```
|
|
1326
|
+
|
|
1327
|
+
##### `FilterGraph.parse(filterDescription, inputs, outputs)`
|
|
1328
|
+
|
|
1329
|
+
Parses a filter description string and applies it to the filter graph.
|
|
1330
|
+
|
|
1331
|
+
Parameters:
|
|
1332
|
+
|
|
1333
|
+
- `filterDescription` (`string`): The filter description (e.g., `'negate'`, `'scale=640:480'`)
|
|
1334
|
+
- `inputs` (`FilterInOut`): Input filter endpoints
|
|
1335
|
+
- `outputs` (`FilterInOut`): Output filter endpoints
|
|
1336
|
+
|
|
1337
|
+
**Returns**: `void`
|
|
1338
|
+
|
|
1339
|
+
##### `FilterGraph.configure()`
|
|
1340
|
+
|
|
1341
|
+
Configures the filter graph and validates all connections.
|
|
1342
|
+
|
|
1343
|
+
**Returns**: `void`
|
|
1344
|
+
|
|
1345
|
+
##### `FilterGraph.destroy()`
|
|
1346
|
+
|
|
1347
|
+
Destroys the `FilterGraph` and frees all associated resources including any created filters. Automatically called when the object is managed by a `using` declaration.
|
|
1348
|
+
|
|
1349
|
+
**Returns**: `void`
|
|
1350
|
+
|
|
1130
1351
|
### `AudioFIFO`
|
|
1131
1352
|
|
|
1132
1353
|
The `AudioFIFO` API provides a first in first out buffer for audio samples. This is useful for buffering audio data between different processing stages.
|
|
@@ -1219,6 +1440,84 @@ Destroys the `AudioFIFO` and frees all associated resources. Automatically calle
|
|
|
1219
1440
|
|
|
1220
1441
|
**Returns**: `void`
|
|
1221
1442
|
|
|
1443
|
+
### `FilterInOut`
|
|
1444
|
+
|
|
1445
|
+
The `FilterInOut` API provides functionality to represent input and output pads for FFmpeg filter graphs.
|
|
1446
|
+
|
|
1447
|
+
```js
|
|
1448
|
+
const filterInOut = new ffmpeg.FilterInOut()
|
|
1449
|
+
```
|
|
1450
|
+
|
|
1451
|
+
**Returns**: A new `FilterInOut` instance
|
|
1452
|
+
|
|
1453
|
+
> **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.
|
|
1454
|
+
|
|
1455
|
+
#### Properties
|
|
1456
|
+
|
|
1457
|
+
##### `FilterInOut.name`
|
|
1458
|
+
|
|
1459
|
+
Gets or sets the name identifier for this input/output pad.
|
|
1460
|
+
|
|
1461
|
+
**Returns**: `string` or `undefined` if not set
|
|
1462
|
+
|
|
1463
|
+
```js
|
|
1464
|
+
const filterInOut = new ffmpeg.FilterInOut()
|
|
1465
|
+
filterInOut.name = 'input'
|
|
1466
|
+
console.log(filterInOut.name) // 'input'
|
|
1467
|
+
```
|
|
1468
|
+
|
|
1469
|
+
##### `FilterInOut.padIdx`
|
|
1470
|
+
|
|
1471
|
+
Gets or sets the pad index within the filter context.
|
|
1472
|
+
|
|
1473
|
+
**Returns**: `number`
|
|
1474
|
+
|
|
1475
|
+
```js
|
|
1476
|
+
filterInOut.padIdx = 0
|
|
1477
|
+
console.log(filterInOut.padIdx) // 0
|
|
1478
|
+
```
|
|
1479
|
+
|
|
1480
|
+
##### `FilterInOut.filterContext`
|
|
1481
|
+
|
|
1482
|
+
Gets or sets the filter context associated with this input/output pad.
|
|
1483
|
+
|
|
1484
|
+
**Returns**: `FilterContext` instance or `null` if not set
|
|
1485
|
+
|
|
1486
|
+
> **Note**: FilterContext must be created through FilterGraph operations before it can be used effectively.
|
|
1487
|
+
|
|
1488
|
+
##### `FilterInOut.next`
|
|
1489
|
+
|
|
1490
|
+
Gets or sets the next FilterInOut in the linked list chain.
|
|
1491
|
+
|
|
1492
|
+
**Returns**: `FilterInOut` instance or `null` if this is the last in the chain
|
|
1493
|
+
|
|
1494
|
+
```js
|
|
1495
|
+
const input = new ffmpeg.FilterInOut()
|
|
1496
|
+
const output = new ffmpeg.FilterInOut()
|
|
1497
|
+
output.name = 'output'
|
|
1498
|
+
|
|
1499
|
+
input.next = output
|
|
1500
|
+
console.log(input.next.name) // 'output'
|
|
1501
|
+
```
|
|
1502
|
+
|
|
1503
|
+
#### Methods
|
|
1504
|
+
|
|
1505
|
+
##### `FilterInOut.destroy()`
|
|
1506
|
+
|
|
1507
|
+
Destroys the `FilterInOut` and frees all associated resources. **Important**: This automatically frees the entire linked list chain via FFmpeg's `avfilter_inout_free()`.
|
|
1508
|
+
|
|
1509
|
+
**Returns**: `void`
|
|
1510
|
+
|
|
1511
|
+
```js
|
|
1512
|
+
const head = new ffmpeg.FilterInOut()
|
|
1513
|
+
const next = new ffmpeg.FilterInOut()
|
|
1514
|
+
head.next = next
|
|
1515
|
+
|
|
1516
|
+
// Only destroy the head - 'next' is automatically freed
|
|
1517
|
+
head.destroy()
|
|
1518
|
+
// DO NOT call next.destroy() - causes double-free error
|
|
1519
|
+
```
|
|
1520
|
+
|
|
1222
1521
|
## License
|
|
1223
1522
|
|
|
1224
1523
|
Apache-2.0
|