node-av 1.1.0 → 1.3.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.
- package/README.md +51 -59
- package/dist/api/bitstream-filter.d.ts +183 -123
- package/dist/api/bitstream-filter.js +185 -127
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +282 -130
- package/dist/api/decoder.js +290 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +249 -160
- package/dist/api/encoder.js +276 -207
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +1944 -96
- package/dist/api/filter-presets.js +2059 -105
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +264 -200
- package/dist/api/filter.js +269 -231
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +246 -117
- package/dist/api/hardware.js +440 -217
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -55
- package/dist/api/io-stream.js +43 -40
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -139
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +208 -126
- package/dist/api/media-output.js +212 -126
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +361 -38
- package/dist/api/pipeline.js +255 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +26 -187
- package/dist/api/utilities/audio-sample.d.ts +0 -8
- package/dist/api/utilities/audio-sample.js +0 -8
- package/dist/api/utilities/audio-sample.js.map +1 -1
- package/dist/api/utilities/channel-layout.d.ts +0 -8
- package/dist/api/utilities/channel-layout.js +0 -8
- package/dist/api/utilities/channel-layout.js.map +1 -1
- package/dist/api/utilities/image.d.ts +0 -8
- package/dist/api/utilities/image.js +0 -8
- package/dist/api/utilities/image.js.map +1 -1
- package/dist/api/utilities/index.d.ts +3 -3
- package/dist/api/utilities/index.js +3 -3
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -9
- package/dist/api/utilities/media-type.js +1 -9
- package/dist/api/utilities/media-type.js.map +1 -1
- package/dist/api/utilities/pixel-format.d.ts +1 -9
- package/dist/api/utilities/pixel-format.js +1 -9
- package/dist/api/utilities/pixel-format.js.map +1 -1
- package/dist/api/utilities/sample-format.d.ts +1 -9
- package/dist/api/utilities/sample-format.js +1 -9
- package/dist/api/utilities/sample-format.js.map +1 -1
- package/dist/api/utilities/streaming.d.ts +0 -8
- package/dist/api/utilities/streaming.js +0 -8
- package/dist/api/utilities/streaming.js.map +1 -1
- package/dist/api/utilities/timestamp.d.ts +0 -8
- package/dist/api/utilities/timestamp.js +0 -8
- package/dist/api/utilities/timestamp.js.map +1 -1
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +11 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/constants/constants.d.ts +1 -1
- package/dist/constants/constants.js +2 -0
- package/dist/constants/constants.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.d.ts +1 -0
- package/dist/lib/binding.js +7 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +266 -283
- package/dist/lib/codec.js +270 -287
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +3 -2
- package/dist/lib/index.js +3 -3
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +118 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +437 -218
- package/dist/lib/option.js +462 -226
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +435 -181
- package/dist/lib/utilities.js +438 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/install/ffmpeg.js +0 -11
- package/package.json +25 -18
- package/release_notes.md +24 -59
- package/CHANGELOG.md +0 -8
package/README.md
CHANGED
|
@@ -1,7 +1,20 @@
|
|
|
1
|
+
<p align="center">
|
|
2
|
+
<img src="https://github.com/seydx/av/blob/main/docs/logo.png?raw=true" width="250px">
|
|
3
|
+
</p>
|
|
4
|
+
|
|
1
5
|
# NodeAV
|
|
2
6
|
|
|
7
|
+
[](https://www.npmjs.com/package/node-av)
|
|
8
|
+
[](https://www.npmjs.com/package/node-av)
|
|
9
|
+
[](https://opensource.org/licenses/MIT)
|
|
10
|
+
[](https://www.typescriptlang.org/)
|
|
11
|
+
[](https://ffmpeg.org)
|
|
12
|
+
[](https://github.com/seydx/av/tree/main/INSTALLATION.md)
|
|
13
|
+
|
|
3
14
|
Native Node.js bindings for FFmpeg with full TypeScript support. Provides direct access to FFmpeg's C APIs through N-API. Includes both raw FFmpeg bindings for full control and higher-level abstractions. Automatic resource management via Disposable pattern, hardware acceleration support and prebuilt binaries for Windows, Linux, and macOS.
|
|
4
15
|
|
|
16
|
+
📚 **[Documentation](https://seydx.github.io/av)**
|
|
17
|
+
|
|
5
18
|
## Installation
|
|
6
19
|
|
|
7
20
|
```bash
|
|
@@ -79,29 +92,8 @@ const encoder = await Encoder.create(FF_ENCODER_LIBX264, decoder.getOutputStream
|
|
|
79
92
|
|
|
80
93
|
const control = pipeline(input, decoder, encoder, output);
|
|
81
94
|
await control.completion;
|
|
82
|
-
|
|
83
|
-
// The pipeline automatically handles:
|
|
84
|
-
// - Flow control between components
|
|
85
|
-
// - Resource management and cleanup
|
|
86
|
-
// - Error propagation
|
|
87
|
-
// - Backpressure handling
|
|
88
95
|
```
|
|
89
96
|
|
|
90
|
-
## More Examples
|
|
91
|
-
|
|
92
|
-
The `examples/` directory contains comprehensive examples for all API levels:
|
|
93
|
-
|
|
94
|
-
**High-Level API** (`api-*.ts`)
|
|
95
|
-
- Hardware acceleration, muxing, streaming, custom I/O, and more
|
|
96
|
-
|
|
97
|
-
**Low-Level API** (direct FFmpeg bindings)
|
|
98
|
-
- Ported FFmpeg C examples showing fine-grained control
|
|
99
|
-
|
|
100
|
-
**Pipeline API** (`api-pipeline-*.ts`)
|
|
101
|
-
- Complex workflows with automatic flow control
|
|
102
|
-
|
|
103
|
-
See the [Examples Table](#examples) for a complete list.
|
|
104
|
-
|
|
105
97
|
## Hardware Acceleration
|
|
106
98
|
|
|
107
99
|
The library supports all hardware acceleration methods available in FFmpeg. The specific hardware types available depend on your FFmpeg build and system configuration.
|
|
@@ -113,7 +105,7 @@ import { HardwareContext } from 'node-av/api';
|
|
|
113
105
|
import { FF_ENCODER_H264_VIDEOTOOLBOX } from 'node-av/constants';
|
|
114
106
|
|
|
115
107
|
// Automatically detect best available hardware
|
|
116
|
-
const hw =
|
|
108
|
+
const hw = HardwareContext.auto();
|
|
117
109
|
if (hw) {
|
|
118
110
|
console.log(`Using hardware: ${hw.deviceTypeName}`);
|
|
119
111
|
|
|
@@ -135,8 +127,8 @@ if (hw) {
|
|
|
135
127
|
import { AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_VAAPI } from 'node-av/constants';
|
|
136
128
|
|
|
137
129
|
// Use specific hardware type
|
|
138
|
-
const cuda =
|
|
139
|
-
const vaapi =
|
|
130
|
+
const cuda = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
|
|
131
|
+
const vaapi = HardwareContext.create(AV_HWDEVICE_TYPE_VAAPI, '/dev/dri/renderD128');
|
|
140
132
|
```
|
|
141
133
|
|
|
142
134
|
## Imports and Tree Shaking
|
|
@@ -243,50 +235,50 @@ NodeAV provides direct bindings to FFmpeg's C APIs, which work with raw memory p
|
|
|
243
235
|
|
|
244
236
|
| Example | FFmpeg | Low-Level API | High-Level API |
|
|
245
237
|
|---------|--------|---------------|----------------|
|
|
246
|
-
| `api-encode-decode` | | | [✓](examples/api-encode-decode.ts) |
|
|
247
|
-
| `api-frame-extract` | | | [✓](examples/api-frame-extract.ts) |
|
|
248
|
-
| `api-hw-decode-sw-encode` | | | [✓](examples/api-hw-decode-sw-encode.ts) |
|
|
249
|
-
| `api-hw-raw` | | | [✓](examples/api-hw-raw.ts) |
|
|
250
|
-
| `api-hw-rtsp-custom-io` | | | [✓](examples/api-hw-rtsp-custom-io.ts) |
|
|
251
|
-
| `api-hw-rtsp` | | | [✓](examples/api-hw-rtsp.ts) |
|
|
252
|
-
| `api-hw-transcode` | | | [✓](examples/api-hw-transcode.ts) |
|
|
253
|
-
| `api-muxing` | | | [✓](examples/api-muxing.ts) |
|
|
254
|
-
| `api-pipeline-hw-rtsp` | | | [✓](examples/api-pipeline-hw-rtsp.ts) |
|
|
255
|
-
| `api-pipeline-raw-muxing` | | | [✓](examples/api-pipeline-raw-muxing.ts) |
|
|
256
|
-
| `api-stream-input` | | | [✓](examples/api-stream-input.ts) |
|
|
257
|
-
| `api-sw-decode-hw-encode` | | | [✓](examples/api-sw-decode-hw-encode.ts) |
|
|
258
|
-
| `api-sw-transcode` | | | [✓](examples/api-sw-transcode.ts) |
|
|
259
|
-
| `avio-read-callback` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/avio_read_callback.c) | [✓](examples/avio-read-callback.ts) | |
|
|
260
|
-
| `decode-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_audio.c) | [✓](examples/decode-audio.ts) | |
|
|
261
|
-
| `decode-filter-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_filter_audio.c) | [✓](examples/decode-filter-audio.ts) | |
|
|
262
|
-
| `decode-filter-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_filter_video.c) | [✓](examples/decode-filter-video.ts) | |
|
|
263
|
-
| `decode-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_video.c) | [✓](examples/decode-video.ts) | |
|
|
264
|
-
| `demux-decode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/demux_decode.c) | [✓](examples/demux-decode.ts) | |
|
|
265
|
-
| `encode-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/encode_audio.c) | [✓](examples/encode-audio.ts) | |
|
|
266
|
-
| `encode-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/encode_video.c) | [✓](examples/encode-video.ts) | |
|
|
267
|
-
| `ffprobe-metadata` | | [✓](examples/ffprobe-metadata.ts) | |
|
|
268
|
-
| `filter-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/filter_audio.c) | [✓](examples/filter-audio.ts) | |
|
|
269
|
-
| `hw-decode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/hw_decode.c) | [✓](examples/hw-decode.ts) | |
|
|
270
|
-
| `hw-encode` | | [✓](examples/hw-encode.ts) | |
|
|
271
|
-
| `hw-transcode` | | [✓](examples/hw-transcode.ts) | |
|
|
238
|
+
| `api-encode-decode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-encode-decode.ts) |
|
|
239
|
+
| `api-frame-extract` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-frame-extract.ts) |
|
|
240
|
+
| `api-hw-decode-sw-encode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-decode-sw-encode.ts) |
|
|
241
|
+
| `api-hw-raw` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-raw.ts) |
|
|
242
|
+
| `api-hw-rtsp-custom-io` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-rtsp-custom-io.ts) |
|
|
243
|
+
| `api-hw-rtsp` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-rtsp.ts) |
|
|
244
|
+
| `api-hw-transcode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-transcode.ts) |
|
|
245
|
+
| `api-muxing` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-muxing.ts) |
|
|
246
|
+
| `api-pipeline-hw-rtsp` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-pipeline-hw-rtsp.ts) |
|
|
247
|
+
| `api-pipeline-raw-muxing` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-pipeline-raw-muxing.ts) |
|
|
248
|
+
| `api-stream-input` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-stream-input.ts) |
|
|
249
|
+
| `api-sw-decode-hw-encode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-sw-decode-hw-encode.ts) |
|
|
250
|
+
| `api-sw-transcode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-sw-transcode.ts) |
|
|
251
|
+
| `avio-read-callback` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/avio_read_callback.c) | [✓](https://github.com/seydx/av/tree/main/examples/avio-read-callback.ts) | |
|
|
252
|
+
| `decode-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_audio.c) | [✓](https://github.com/seydx/av/tree/main/examples/decode-audio.ts) | |
|
|
253
|
+
| `decode-filter-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_filter_audio.c) | [✓](https://github.com/seydx/av/tree/main/examples/decode-filter-audio.ts) | |
|
|
254
|
+
| `decode-filter-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_filter_video.c) | [✓](https://github.com/seydx/av/tree/main/examples/decode-filter-video.ts) | |
|
|
255
|
+
| `decode-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_video.c) | [✓](https://github.com/seydx/av/tree/main/examples/decode-video.ts) | |
|
|
256
|
+
| `demux-decode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/demux_decode.c) | [✓](https://github.com/seydx/av/tree/main/examples/demux-decode.ts) | |
|
|
257
|
+
| `encode-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/encode_audio.c) | [✓](https://github.com/seydx/av/tree/main/examples/encode-audio.ts) | |
|
|
258
|
+
| `encode-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/encode_video.c) | [✓](https://github.com/seydx/av/tree/main/examples/encode-video.ts) | |
|
|
259
|
+
| `ffprobe-metadata` | | [✓](https://github.com/seydx/av/tree/main/examples/ffprobe-metadata.ts) | |
|
|
260
|
+
| `filter-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/filter_audio.c) | [✓](https://github.com/seydx/av/tree/main/examples/filter-audio.ts) | |
|
|
261
|
+
| `hw-decode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/hw_decode.c) | [✓](https://github.com/seydx/av/tree/main/examples/hw-decode.ts) | |
|
|
262
|
+
| `hw-encode` | | [✓](https://github.com/seydx/av/tree/main/examples/hw-encode.ts) | |
|
|
263
|
+
| `hw-transcode` | | [✓](https://github.com/seydx/av/tree/main/examples/hw-transcode.ts) | |
|
|
272
264
|
| `qsv-decode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/qsv_decode.c) | | |
|
|
273
265
|
| `qsv-transcode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/qsv_transcode.c) | | |
|
|
274
266
|
| `vaapi-encode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_encode.c) | | |
|
|
275
267
|
| `vaapi-transcode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_transcode.c) | | |
|
|
276
|
-
| `mux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/mux.c) | [✓](examples/mux.ts) | |
|
|
277
|
-
| `remux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/remux.c) | [✓](examples/remux.ts) | |
|
|
278
|
-
| `resample-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/resample_audio.c) | [✓](examples/resample-audio.ts) | |
|
|
279
|
-
| `scale-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/scale_video.c) | [✓](examples/scale-video.ts) | |
|
|
280
|
-
| `show-metadata` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/show_metadata.c) | [✓](examples/show-metadata.ts) | |
|
|
281
|
-
| `transcode-aac` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/transcode_aac.c) | [✓](examples/transcode-aac.ts) | |
|
|
282
|
-
| `transcode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/transcode.c) | [✓](examples/transcode.ts) | |
|
|
268
|
+
| `mux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/mux.c) | [✓](https://github.com/seydx/av/tree/main/examples/mux.ts) | |
|
|
269
|
+
| `remux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/remux.c) | [✓](https://github.com/seydx/av/tree/main/examples/remux.ts) | |
|
|
270
|
+
| `resample-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/resample_audio.c) | [✓](https://github.com/seydx/av/tree/main/examples/resample-audio.ts) | |
|
|
271
|
+
| `scale-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/scale_video.c) | [✓](https://github.com/seydx/av/tree/main/examples/scale-video.ts) | |
|
|
272
|
+
| `show-metadata` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/show_metadata.c) | [✓](https://github.com/seydx/av/tree/main/examples/show-metadata.ts) | |
|
|
273
|
+
| `transcode-aac` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/transcode_aac.c) | [✓](https://github.com/seydx/av/tree/main/examples/transcode-aac.ts) | |
|
|
274
|
+
| `transcode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/transcode.c) | [✓](https://github.com/seydx/av/tree/main/examples/transcode.ts) | |
|
|
283
275
|
|
|
284
276
|
|
|
285
277
|
## Prebuilt Binaries
|
|
286
278
|
|
|
287
279
|
Prebuilt binaries are available for macOS, Linux, and Windows (x64/arm64). The package will automatically build from source if needed.
|
|
288
280
|
|
|
289
|
-
For detailed installation instructions, build requirements, and troubleshooting, see the **[Installation Guide](INSTALLATION.md)**.
|
|
281
|
+
For detailed installation instructions, build requirements, and troubleshooting, see the **[Installation Guide](https://github.com/seydx/av/tree/main/INSTALLATION.md)**.
|
|
290
282
|
|
|
291
283
|
## License
|
|
292
284
|
|
|
@@ -296,7 +288,7 @@ This project is licensed under the MIT License. See the LICENSE file for details
|
|
|
296
288
|
|
|
297
289
|
## Contributing
|
|
298
290
|
|
|
299
|
-
Contributions are welcome! Please read [CONTRIBUTION.md](CONTRIBUTION.md) for development setup, code standards, and contribution guidelines before submitting pull requests.
|
|
291
|
+
Contributions are welcome! Please read [CONTRIBUTION.md](https://github.com/seydx/av/tree/main/CONTRIBUTION.md) for development setup, code standards, and contribution guidelines before submitting pull requests.
|
|
300
292
|
|
|
301
293
|
## Support
|
|
302
294
|
|
|
@@ -1,58 +1,42 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* BitStreamFilterAPI - High-level wrapper for bitstream filtering
|
|
3
|
-
*
|
|
4
|
-
* Simplifies FFmpeg's bitstream filter API with automatic initialization,
|
|
5
|
-
* parameter configuration, and packet processing.
|
|
6
|
-
*
|
|
7
|
-
* Handles filter context lifecycle, packet buffering, and flushing.
|
|
8
|
-
* Useful for format conversion, metadata extraction, and stream modifications.
|
|
9
|
-
*
|
|
10
|
-
* @module api/bitstream-filter
|
|
11
|
-
*/
|
|
12
1
|
import { Packet } from '../lib/index.js';
|
|
13
2
|
import type { Stream } from '../lib/index.js';
|
|
14
3
|
/**
|
|
15
4
|
* High-level bitstream filter for packet processing.
|
|
16
5
|
*
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
*
|
|
20
|
-
*
|
|
21
|
-
* Supports packet-by-packet and stream processing modes.
|
|
6
|
+
* Provides simplified interface for applying bitstream filters to packets.
|
|
7
|
+
* Handles filter initialization, packet processing, and memory management.
|
|
8
|
+
* Supports filters like h264_mp4toannexb, hevc_mp4toannexb, aac_adtstoasc.
|
|
9
|
+
* Essential for format conversion and stream compatibility in transcoding pipelines.
|
|
22
10
|
*
|
|
23
11
|
* @example
|
|
24
12
|
* ```typescript
|
|
25
|
-
*
|
|
26
|
-
* const media = await MediaInput.open('video.mp4');
|
|
27
|
-
* const stream = media.video();
|
|
28
|
-
* const bsf = await BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
13
|
+
* import { BitStreamFilterAPI } from 'node-av/api';
|
|
29
14
|
*
|
|
30
|
-
* //
|
|
31
|
-
*
|
|
32
|
-
* if (packet.streamIndex === stream.index) {
|
|
33
|
-
* const filtered = await bsf.process(packet);
|
|
34
|
-
* for (const outPacket of filtered) {
|
|
35
|
-
* // Write to output or process further
|
|
36
|
-
* await output.writePacket(outPacket);
|
|
37
|
-
* }
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
15
|
+
* // Create H.264 Annex B converter
|
|
16
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
40
17
|
*
|
|
41
|
-
* //
|
|
42
|
-
* const
|
|
43
|
-
*
|
|
18
|
+
* // Process packet
|
|
19
|
+
* const outputPackets = await filter.process(inputPacket);
|
|
20
|
+
* for (const packet of outputPackets) {
|
|
21
|
+
* await output.writePacket(packet);
|
|
22
|
+
* packet.free();
|
|
23
|
+
* }
|
|
44
24
|
* ```
|
|
45
25
|
*
|
|
46
26
|
* @example
|
|
47
27
|
* ```typescript
|
|
48
28
|
* // Process packet stream
|
|
49
|
-
* const
|
|
29
|
+
* const filter = BitStreamFilterAPI.create('hevc_mp4toannexb', videoStream);
|
|
50
30
|
*
|
|
51
|
-
* for await (const
|
|
52
|
-
*
|
|
53
|
-
*
|
|
31
|
+
* for await (const packet of filter.packets(input.packets())) {
|
|
32
|
+
* await output.writePacket(packet);
|
|
33
|
+
* packet.free();
|
|
54
34
|
* }
|
|
55
35
|
* ```
|
|
36
|
+
*
|
|
37
|
+
* @see {@link BitStreamFilter} For available filters
|
|
38
|
+
* @see {@link BitStreamFilterContext} For low-level API
|
|
39
|
+
* @see {@link MediaOutput} For writing filtered packets
|
|
56
40
|
*/
|
|
57
41
|
export declare class BitStreamFilterAPI implements Disposable {
|
|
58
42
|
private ctx;
|
|
@@ -60,187 +44,263 @@ export declare class BitStreamFilterAPI implements Disposable {
|
|
|
60
44
|
private stream;
|
|
61
45
|
private isDisposed;
|
|
62
46
|
/**
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* @param
|
|
66
|
-
* @
|
|
67
|
-
* @param stream - The stream this filter is for
|
|
47
|
+
* @param filter - Bitstream filter instance
|
|
48
|
+
* @param ctx - Filter context
|
|
49
|
+
* @param stream - Associated stream
|
|
50
|
+
* @internal
|
|
68
51
|
*/
|
|
69
52
|
private constructor();
|
|
70
53
|
/**
|
|
71
|
-
* Create a bitstream filter for a
|
|
54
|
+
* Create a bitstream filter for a stream.
|
|
55
|
+
*
|
|
56
|
+
* Initializes filter with stream codec parameters.
|
|
57
|
+
* Configures time base and prepares for packet processing.
|
|
72
58
|
*
|
|
73
|
-
*
|
|
74
|
-
* and initialization.
|
|
59
|
+
* Direct mapping to av_bsf_get_by_name() and av_bsf_alloc().
|
|
75
60
|
*
|
|
76
|
-
* @param filterName - Name of the bitstream filter
|
|
77
|
-
* @param stream - Stream to filter
|
|
61
|
+
* @param filterName - Name of the bitstream filter
|
|
62
|
+
* @param stream - Stream to apply filter to
|
|
63
|
+
* @returns Configured bitstream filter
|
|
78
64
|
*
|
|
79
|
-
* @
|
|
65
|
+
* @throws {Error} If filter not found or initialization fails
|
|
80
66
|
*
|
|
81
|
-
* @throws {
|
|
67
|
+
* @throws {FFmpegError} If allocation or initialization fails
|
|
82
68
|
*
|
|
83
69
|
* @example
|
|
84
70
|
* ```typescript
|
|
85
|
-
*
|
|
86
|
-
* const
|
|
87
|
-
*
|
|
71
|
+
* // H.264 MP4 to Annex B conversion
|
|
72
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', videoStream);
|
|
73
|
+
* ```
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```typescript
|
|
77
|
+
* // AAC ADTS to ASC conversion
|
|
78
|
+
* const filter = BitStreamFilterAPI.create('aac_adtstoasc', audioStream);
|
|
79
|
+
* ```
|
|
80
|
+
*
|
|
81
|
+
* @example
|
|
82
|
+
* ```typescript
|
|
83
|
+
* // Remove metadata
|
|
84
|
+
* const filter = BitStreamFilterAPI.create('filter_units', stream);
|
|
88
85
|
* ```
|
|
89
|
-
*/
|
|
90
|
-
static create(filterName: string, stream: Stream): Promise<BitStreamFilterAPI>;
|
|
91
|
-
/**
|
|
92
|
-
* Get the filter name.
|
|
93
86
|
*
|
|
94
|
-
* @
|
|
87
|
+
* @see {@link BitStreamFilter.getByName} For filter discovery
|
|
95
88
|
*/
|
|
96
|
-
|
|
89
|
+
static create(filterName: string, stream: Stream): BitStreamFilterAPI;
|
|
97
90
|
/**
|
|
98
|
-
* Get
|
|
91
|
+
* Get filter name.
|
|
99
92
|
*
|
|
100
|
-
* @
|
|
93
|
+
* @example
|
|
94
|
+
* ```typescript
|
|
95
|
+
* console.log(`Using filter: ${filter.name}`);
|
|
96
|
+
* ```
|
|
101
97
|
*/
|
|
102
|
-
get
|
|
98
|
+
get name(): string;
|
|
103
99
|
/**
|
|
104
100
|
* Get output codec parameters.
|
|
105
101
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
102
|
+
* Parameters after filter processing.
|
|
103
|
+
* May differ from input parameters.
|
|
108
104
|
*
|
|
109
|
-
* @
|
|
105
|
+
* @example
|
|
106
|
+
* ```typescript
|
|
107
|
+
* const outputParams = filter.outputCodecParameters;
|
|
108
|
+
* console.log(`Output codec: ${outputParams?.codecId}`);
|
|
109
|
+
* ```
|
|
110
110
|
*/
|
|
111
111
|
get outputCodecParameters(): import("../lib/codec-parameters.js").CodecParameters | null;
|
|
112
112
|
/**
|
|
113
113
|
* Get output time base.
|
|
114
114
|
*
|
|
115
|
-
*
|
|
115
|
+
* Time base after filter processing.
|
|
116
116
|
*
|
|
117
|
-
* @
|
|
117
|
+
* @example
|
|
118
|
+
* ```typescript
|
|
119
|
+
* const tb = filter.outputTimeBase;
|
|
120
|
+
* console.log(`Output timebase: ${tb?.num}/${tb?.den}`);
|
|
121
|
+
* ```
|
|
118
122
|
*/
|
|
119
123
|
get outputTimeBase(): import("../lib/rational.js").Rational | null;
|
|
120
124
|
/**
|
|
121
|
-
* Process a
|
|
125
|
+
* Process a packet through the filter.
|
|
122
126
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
127
|
+
* Applies bitstream filter to packet.
|
|
128
|
+
* May produce zero, one, or multiple output packets.
|
|
129
|
+
* Pass null to signal end-of-stream.
|
|
125
130
|
*
|
|
126
|
-
*
|
|
131
|
+
* Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
|
|
127
132
|
*
|
|
128
|
-
* @
|
|
133
|
+
* @param packet - Packet to filter or null for EOF
|
|
134
|
+
* @returns Array of filtered packets
|
|
135
|
+
*
|
|
136
|
+
* @throws {Error} If filter is disposed
|
|
137
|
+
*
|
|
138
|
+
* @throws {FFmpegError} If filtering fails
|
|
129
139
|
*
|
|
130
140
|
* @example
|
|
131
141
|
* ```typescript
|
|
132
|
-
* const
|
|
133
|
-
* const
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* console.log(`Filtered packet: size=${packet.size}`);
|
|
137
|
-
* await output.writePacket(packet);
|
|
142
|
+
* const outputPackets = await filter.process(inputPacket);
|
|
143
|
+
* for (const packet of outputPackets) {
|
|
144
|
+
* console.log(`Filtered packet: pts=${packet.pts}`);
|
|
145
|
+
* packet.free();
|
|
138
146
|
* }
|
|
139
147
|
* ```
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* // Flush filter
|
|
152
|
+
* const remaining = await filter.process(null);
|
|
153
|
+
* ```
|
|
154
|
+
*
|
|
155
|
+
* @see {@link flush} For explicit flushing
|
|
156
|
+
* @see {@link packets} For stream processing
|
|
140
157
|
*/
|
|
141
158
|
process(packet: Packet | null): Promise<Packet[]>;
|
|
142
159
|
/**
|
|
143
|
-
* Process
|
|
160
|
+
* Process packet stream through filter.
|
|
144
161
|
*
|
|
145
|
-
*
|
|
146
|
-
* Automatically handles
|
|
147
|
-
*
|
|
148
|
-
* @param packets - Async iterable of packets to filter
|
|
162
|
+
* High-level async generator for filtering packet streams.
|
|
163
|
+
* Automatically handles flushing at end of stream.
|
|
164
|
+
* Yields filtered packets ready for output.
|
|
149
165
|
*
|
|
166
|
+
* @param packets - Async iterable of packets
|
|
150
167
|
* @yields Filtered packets
|
|
168
|
+
* @throws {Error} If filter is disposed
|
|
169
|
+
*
|
|
170
|
+
* @throws {FFmpegError} If filtering fails
|
|
151
171
|
*
|
|
152
172
|
* @example
|
|
153
173
|
* ```typescript
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* for await (const packet of media.packets()) {
|
|
159
|
-
* if (packet.streamIndex === stream.index) {
|
|
160
|
-
* yield packet;
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
174
|
+
* // Filter entire stream
|
|
175
|
+
* for await (const packet of filter.packets(input.packets())) {
|
|
176
|
+
* await output.writePacket(packet);
|
|
177
|
+
* packet.free();
|
|
163
178
|
* }
|
|
179
|
+
* ```
|
|
164
180
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
181
|
+
* @example
|
|
182
|
+
* ```typescript
|
|
183
|
+
* // Chain with decoder
|
|
184
|
+
* const decoder = await Decoder.create(stream);
|
|
185
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
186
|
+
*
|
|
187
|
+
* for await (const frame of decoder.frames(filter.packets(input.packets()))) {
|
|
188
|
+
* // Process frames
|
|
189
|
+
* frame.free();
|
|
167
190
|
* }
|
|
168
191
|
* ```
|
|
192
|
+
*
|
|
193
|
+
* @see {@link process} For single packet filtering
|
|
194
|
+
* @see {@link flush} For end-of-stream handling
|
|
169
195
|
*/
|
|
170
196
|
packets(packets: AsyncIterable<Packet>): AsyncGenerator<Packet>;
|
|
171
197
|
/**
|
|
172
|
-
* Flush
|
|
198
|
+
* Flush filter and get remaining packets.
|
|
173
199
|
*
|
|
174
|
-
*
|
|
175
|
-
*
|
|
200
|
+
* Signals end-of-stream and retrieves buffered packets.
|
|
201
|
+
* Also resets internal filter state.
|
|
176
202
|
*
|
|
177
|
-
*
|
|
203
|
+
* Direct mapping to av_bsf_flush().
|
|
204
|
+
*
|
|
205
|
+
* @returns Array of remaining packets
|
|
206
|
+
*
|
|
207
|
+
* @throws {Error} If filter is disposed
|
|
178
208
|
*
|
|
179
209
|
* @example
|
|
180
210
|
* ```typescript
|
|
181
|
-
*
|
|
182
|
-
* const remaining = await bsf.flush();
|
|
211
|
+
* const remaining = await filter.flush();
|
|
183
212
|
* for (const packet of remaining) {
|
|
184
213
|
* await output.writePacket(packet);
|
|
214
|
+
* packet.free();
|
|
185
215
|
* }
|
|
186
216
|
* ```
|
|
217
|
+
*
|
|
218
|
+
* @see {@link flushPackets} For async iteration
|
|
219
|
+
* @see {@link reset} For state reset only
|
|
187
220
|
*/
|
|
188
221
|
flush(): Promise<Packet[]>;
|
|
189
222
|
/**
|
|
190
|
-
* Flush
|
|
223
|
+
* Flush filter as async generator.
|
|
191
224
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
225
|
+
* Convenient async iteration over remaining packets.
|
|
226
|
+
* Combines flush and iteration.
|
|
194
227
|
*
|
|
195
|
-
* @yields Remaining packets
|
|
228
|
+
* @yields Remaining packets
|
|
229
|
+
* @throws {Error} If filter is disposed
|
|
196
230
|
*
|
|
197
231
|
* @example
|
|
198
232
|
* ```typescript
|
|
199
|
-
*
|
|
200
|
-
* for await (const packet of bsf.flushPackets()) {
|
|
233
|
+
* for await (const packet of filter.flushPackets()) {
|
|
201
234
|
* await output.writePacket(packet);
|
|
202
|
-
*
|
|
235
|
+
* packet.free();
|
|
203
236
|
* }
|
|
204
237
|
* ```
|
|
238
|
+
*
|
|
239
|
+
* @see {@link flush} For array return
|
|
205
240
|
*/
|
|
206
241
|
flushPackets(): AsyncGenerator<Packet>;
|
|
207
242
|
/**
|
|
208
|
-
* Get
|
|
209
|
-
*
|
|
243
|
+
* Get associated stream.
|
|
244
|
+
*
|
|
245
|
+
* Returns the stream this filter was created for.
|
|
246
|
+
*
|
|
247
|
+
* @returns Associated stream
|
|
248
|
+
*
|
|
249
|
+
* @example
|
|
250
|
+
* ```typescript
|
|
251
|
+
* const stream = filter.getStream();
|
|
252
|
+
* console.log(`Filtering stream ${stream.index}`);
|
|
253
|
+
* ```
|
|
210
254
|
*/
|
|
211
255
|
getStream(): Stream;
|
|
212
256
|
/**
|
|
213
|
-
* Reset
|
|
257
|
+
* Reset filter state.
|
|
258
|
+
*
|
|
259
|
+
* Clears internal buffers and resets filter.
|
|
260
|
+
* Does not dispose resources.
|
|
214
261
|
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
262
|
+
* Direct mapping to av_bsf_flush().
|
|
263
|
+
*
|
|
264
|
+
* @throws {Error} If filter is disposed
|
|
217
265
|
*
|
|
218
266
|
* @example
|
|
219
267
|
* ```typescript
|
|
220
|
-
* //
|
|
221
|
-
*
|
|
222
|
-
* bsf.reset(); // Clear filter state
|
|
223
|
-
* // Continue processing from new position
|
|
268
|
+
* // Reset for new segment
|
|
269
|
+
* filter.reset();
|
|
224
270
|
* ```
|
|
271
|
+
*
|
|
272
|
+
* @see {@link flush} For reset with packet retrieval
|
|
225
273
|
*/
|
|
226
274
|
reset(): void;
|
|
227
275
|
/**
|
|
228
|
-
* Dispose of
|
|
276
|
+
* Dispose of filter and free resources.
|
|
229
277
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
278
|
+
* Releases filter context and marks as disposed.
|
|
279
|
+
* Safe to call multiple times.
|
|
232
280
|
*
|
|
233
281
|
* @example
|
|
234
282
|
* ```typescript
|
|
235
|
-
*
|
|
236
|
-
* using bsf = await BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
237
|
-
* // ... use filter
|
|
238
|
-
* } // Automatically disposed when leaving scope
|
|
283
|
+
* filter.dispose();
|
|
239
284
|
* ```
|
|
285
|
+
*
|
|
286
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
240
287
|
*/
|
|
241
288
|
dispose(): void;
|
|
242
289
|
/**
|
|
243
|
-
*
|
|
290
|
+
* Dispose of filter.
|
|
291
|
+
*
|
|
292
|
+
* Implements Disposable interface for automatic cleanup.
|
|
293
|
+
* Equivalent to calling dispose().
|
|
294
|
+
*
|
|
295
|
+
* @example
|
|
296
|
+
* ```typescript
|
|
297
|
+
* {
|
|
298
|
+
* using filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
299
|
+
* // Use filter...
|
|
300
|
+
* } // Automatically disposed
|
|
301
|
+
* ```
|
|
302
|
+
*
|
|
303
|
+
* @see {@link dispose} For manual cleanup
|
|
244
304
|
*/
|
|
245
305
|
[Symbol.dispose](): void;
|
|
246
306
|
}
|