node-av 1.1.0 → 1.2.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 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- 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 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.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.js +5 -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 +264 -281
- package/dist/lib/codec.js +268 -285
- 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 +2 -1
- package/dist/lib/index.js +2 -2
- 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 +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- 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 +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -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
|
|
@@ -113,7 +126,7 @@ import { HardwareContext } from 'node-av/api';
|
|
|
113
126
|
import { FF_ENCODER_H264_VIDEOTOOLBOX } from 'node-av/constants';
|
|
114
127
|
|
|
115
128
|
// Automatically detect best available hardware
|
|
116
|
-
const hw =
|
|
129
|
+
const hw = HardwareContext.auto();
|
|
117
130
|
if (hw) {
|
|
118
131
|
console.log(`Using hardware: ${hw.deviceTypeName}`);
|
|
119
132
|
|
|
@@ -135,8 +148,8 @@ if (hw) {
|
|
|
135
148
|
import { AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_VAAPI } from 'node-av/constants';
|
|
136
149
|
|
|
137
150
|
// Use specific hardware type
|
|
138
|
-
const cuda =
|
|
139
|
-
const vaapi =
|
|
151
|
+
const cuda = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
|
|
152
|
+
const vaapi = HardwareContext.create(AV_HWDEVICE_TYPE_VAAPI, '/dev/dri/renderD128');
|
|
140
153
|
```
|
|
141
154
|
|
|
142
155
|
## Imports and Tree Shaking
|
|
@@ -243,50 +256,50 @@ NodeAV provides direct bindings to FFmpeg's C APIs, which work with raw memory p
|
|
|
243
256
|
|
|
244
257
|
| Example | FFmpeg | Low-Level API | High-Level API |
|
|
245
258
|
|---------|--------|---------------|----------------|
|
|
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) | |
|
|
259
|
+
| `api-encode-decode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-encode-decode.ts) |
|
|
260
|
+
| `api-frame-extract` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-frame-extract.ts) |
|
|
261
|
+
| `api-hw-decode-sw-encode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-decode-sw-encode.ts) |
|
|
262
|
+
| `api-hw-raw` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-raw.ts) |
|
|
263
|
+
| `api-hw-rtsp-custom-io` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-rtsp-custom-io.ts) |
|
|
264
|
+
| `api-hw-rtsp` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-rtsp.ts) |
|
|
265
|
+
| `api-hw-transcode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-hw-transcode.ts) |
|
|
266
|
+
| `api-muxing` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-muxing.ts) |
|
|
267
|
+
| `api-pipeline-hw-rtsp` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-pipeline-hw-rtsp.ts) |
|
|
268
|
+
| `api-pipeline-raw-muxing` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-pipeline-raw-muxing.ts) |
|
|
269
|
+
| `api-stream-input` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-stream-input.ts) |
|
|
270
|
+
| `api-sw-decode-hw-encode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-sw-decode-hw-encode.ts) |
|
|
271
|
+
| `api-sw-transcode` | | | [✓](https://github.com/seydx/av/tree/main/examples/api-sw-transcode.ts) |
|
|
272
|
+
| `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) | |
|
|
273
|
+
| `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) | |
|
|
274
|
+
| `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) | |
|
|
275
|
+
| `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) | |
|
|
276
|
+
| `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) | |
|
|
277
|
+
| `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) | |
|
|
278
|
+
| `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) | |
|
|
279
|
+
| `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) | |
|
|
280
|
+
| `ffprobe-metadata` | | [✓](https://github.com/seydx/av/tree/main/examples/ffprobe-metadata.ts) | |
|
|
281
|
+
| `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) | |
|
|
282
|
+
| `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) | |
|
|
283
|
+
| `hw-encode` | | [✓](https://github.com/seydx/av/tree/main/examples/hw-encode.ts) | |
|
|
284
|
+
| `hw-transcode` | | [✓](https://github.com/seydx/av/tree/main/examples/hw-transcode.ts) | |
|
|
272
285
|
| `qsv-decode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/qsv_decode.c) | | |
|
|
273
286
|
| `qsv-transcode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/qsv_transcode.c) | | |
|
|
274
287
|
| `vaapi-encode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_encode.c) | | |
|
|
275
288
|
| `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) | |
|
|
289
|
+
| `mux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/mux.c) | [✓](https://github.com/seydx/av/tree/main/examples/mux.ts) | |
|
|
290
|
+
| `remux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/remux.c) | [✓](https://github.com/seydx/av/tree/main/examples/remux.ts) | |
|
|
291
|
+
| `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) | |
|
|
292
|
+
| `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) | |
|
|
293
|
+
| `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) | |
|
|
294
|
+
| `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) | |
|
|
295
|
+
| `transcode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/transcode.c) | [✓](https://github.com/seydx/av/tree/main/examples/transcode.ts) | |
|
|
283
296
|
|
|
284
297
|
|
|
285
298
|
## Prebuilt Binaries
|
|
286
299
|
|
|
287
300
|
Prebuilt binaries are available for macOS, Linux, and Windows (x64/arm64). The package will automatically build from source if needed.
|
|
288
301
|
|
|
289
|
-
For detailed installation instructions, build requirements, and troubleshooting, see the **[Installation Guide](INSTALLATION.md)**.
|
|
302
|
+
For detailed installation instructions, build requirements, and troubleshooting, see the **[Installation Guide](https://github.com/seydx/av/tree/main/INSTALLATION.md)**.
|
|
290
303
|
|
|
291
304
|
## License
|
|
292
305
|
|
|
@@ -296,7 +309,7 @@ This project is licensed under the MIT License. See the LICENSE file for details
|
|
|
296
309
|
|
|
297
310
|
## Contributing
|
|
298
311
|
|
|
299
|
-
Contributions are welcome! Please read [CONTRIBUTION.md](CONTRIBUTION.md) for development setup, code standards, and contribution guidelines before submitting pull requests.
|
|
312
|
+
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
313
|
|
|
301
314
|
## Support
|
|
302
315
|
|
|
@@ -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,260 @@ 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.
|
|
72
55
|
*
|
|
73
|
-
*
|
|
74
|
-
* and
|
|
56
|
+
* Initializes filter with stream codec parameters.
|
|
57
|
+
* Configures time base and prepares for packet processing.
|
|
75
58
|
*
|
|
76
|
-
*
|
|
77
|
-
* @param stream - Stream to filter
|
|
59
|
+
* Direct mapping to av_bsf_get_by_name() and av_bsf_alloc().
|
|
78
60
|
*
|
|
79
|
-
* @
|
|
61
|
+
* @param filterName - Name of the bitstream filter
|
|
62
|
+
* @param stream - Stream to apply filter to
|
|
63
|
+
* @returns Configured bitstream filter
|
|
80
64
|
*
|
|
81
|
-
* @throws {Error} If filter
|
|
65
|
+
* @throws {Error} If filter not found or initialization fails
|
|
66
|
+
* @throws {FFmpegError} If allocation or initialization fails
|
|
82
67
|
*
|
|
83
68
|
* @example
|
|
84
69
|
* ```typescript
|
|
85
|
-
*
|
|
86
|
-
* const
|
|
87
|
-
* const bsf = await BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
70
|
+
* // H.264 MP4 to Annex B conversion
|
|
71
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', videoStream);
|
|
88
72
|
* ```
|
|
89
|
-
*/
|
|
90
|
-
static create(filterName: string, stream: Stream): Promise<BitStreamFilterAPI>;
|
|
91
|
-
/**
|
|
92
|
-
* Get the filter name.
|
|
93
73
|
*
|
|
94
|
-
* @
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* // AAC ADTS to ASC conversion
|
|
77
|
+
* const filter = BitStreamFilterAPI.create('aac_adtstoasc', audioStream);
|
|
78
|
+
* ```
|
|
79
|
+
*
|
|
80
|
+
* @example
|
|
81
|
+
* ```typescript
|
|
82
|
+
* // Remove metadata
|
|
83
|
+
* const filter = BitStreamFilterAPI.create('filter_units', stream);
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @see {@link BitStreamFilter.getByName} For filter discovery
|
|
95
87
|
*/
|
|
96
|
-
|
|
88
|
+
static create(filterName: string, stream: Stream): BitStreamFilterAPI;
|
|
97
89
|
/**
|
|
98
|
-
* Get
|
|
90
|
+
* Get filter name.
|
|
99
91
|
*
|
|
100
|
-
* @
|
|
92
|
+
* @example
|
|
93
|
+
* ```typescript
|
|
94
|
+
* console.log(`Using filter: ${filter.name}`);
|
|
95
|
+
* ```
|
|
101
96
|
*/
|
|
102
|
-
get
|
|
97
|
+
get name(): string;
|
|
103
98
|
/**
|
|
104
99
|
* Get output codec parameters.
|
|
105
100
|
*
|
|
106
|
-
*
|
|
107
|
-
*
|
|
101
|
+
* Parameters after filter processing.
|
|
102
|
+
* May differ from input parameters.
|
|
108
103
|
*
|
|
109
|
-
* @
|
|
104
|
+
* @example
|
|
105
|
+
* ```typescript
|
|
106
|
+
* const outputParams = filter.outputCodecParameters;
|
|
107
|
+
* console.log(`Output codec: ${outputParams?.codecId}`);
|
|
108
|
+
* ```
|
|
110
109
|
*/
|
|
111
110
|
get outputCodecParameters(): import("../lib/codec-parameters.js").CodecParameters | null;
|
|
112
111
|
/**
|
|
113
112
|
* Get output time base.
|
|
114
113
|
*
|
|
115
|
-
*
|
|
114
|
+
* Time base after filter processing.
|
|
116
115
|
*
|
|
117
|
-
* @
|
|
116
|
+
* @example
|
|
117
|
+
* ```typescript
|
|
118
|
+
* const tb = filter.outputTimeBase;
|
|
119
|
+
* console.log(`Output timebase: ${tb?.num}/${tb?.den}`);
|
|
120
|
+
* ```
|
|
118
121
|
*/
|
|
119
122
|
get outputTimeBase(): import("../lib/rational.js").Rational | null;
|
|
120
123
|
/**
|
|
121
|
-
* Process a
|
|
124
|
+
* Process a packet through the filter.
|
|
122
125
|
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
126
|
+
* Applies bitstream filter to packet.
|
|
127
|
+
* May produce zero, one, or multiple output packets.
|
|
128
|
+
* Pass null to signal end-of-stream.
|
|
125
129
|
*
|
|
126
|
-
*
|
|
130
|
+
* Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
|
|
127
131
|
*
|
|
128
|
-
* @
|
|
132
|
+
* @param packet - Packet to filter or null for EOF
|
|
133
|
+
* @returns Array of filtered packets
|
|
134
|
+
*
|
|
135
|
+
* @throws {Error} If filter is disposed
|
|
136
|
+
* @throws {FFmpegError} If filtering fails
|
|
129
137
|
*
|
|
130
138
|
* @example
|
|
131
139
|
* ```typescript
|
|
132
|
-
* const
|
|
133
|
-
* const
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* console.log(`Filtered packet: size=${packet.size}`);
|
|
137
|
-
* await output.writePacket(packet);
|
|
140
|
+
* const outputPackets = await filter.process(inputPacket);
|
|
141
|
+
* for (const packet of outputPackets) {
|
|
142
|
+
* console.log(`Filtered packet: pts=${packet.pts}`);
|
|
143
|
+
* packet.free();
|
|
138
144
|
* }
|
|
139
145
|
* ```
|
|
146
|
+
*
|
|
147
|
+
* @example
|
|
148
|
+
* ```typescript
|
|
149
|
+
* // Flush filter
|
|
150
|
+
* const remaining = await filter.process(null);
|
|
151
|
+
* ```
|
|
152
|
+
*
|
|
153
|
+
* @see {@link flush} For explicit flushing
|
|
154
|
+
* @see {@link packets} For stream processing
|
|
140
155
|
*/
|
|
141
156
|
process(packet: Packet | null): Promise<Packet[]>;
|
|
142
157
|
/**
|
|
143
|
-
* Process
|
|
144
|
-
*
|
|
145
|
-
* Async generator that processes packets lazily and yields filtered results.
|
|
146
|
-
* Automatically handles EOF and cleanup.
|
|
158
|
+
* Process packet stream through filter.
|
|
147
159
|
*
|
|
148
|
-
*
|
|
160
|
+
* High-level async generator for filtering packet streams.
|
|
161
|
+
* Automatically handles flushing at end of stream.
|
|
162
|
+
* Yields filtered packets ready for output.
|
|
149
163
|
*
|
|
164
|
+
* @param packets - Async iterable of packets
|
|
150
165
|
* @yields Filtered packets
|
|
166
|
+
* @throws {Error} If filter is disposed
|
|
167
|
+
* @throws {FFmpegError} If filtering fails
|
|
151
168
|
*
|
|
152
169
|
* @example
|
|
153
170
|
* ```typescript
|
|
154
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
157
|
-
*
|
|
158
|
-
* for await (const packet of media.packets()) {
|
|
159
|
-
* if (packet.streamIndex === stream.index) {
|
|
160
|
-
* yield packet;
|
|
161
|
-
* }
|
|
162
|
-
* }
|
|
171
|
+
* // Filter entire stream
|
|
172
|
+
* for await (const packet of filter.packets(input.packets())) {
|
|
173
|
+
* await output.writePacket(packet);
|
|
174
|
+
* packet.free();
|
|
163
175
|
* }
|
|
176
|
+
* ```
|
|
164
177
|
*
|
|
165
|
-
*
|
|
166
|
-
*
|
|
178
|
+
* @example
|
|
179
|
+
* ```typescript
|
|
180
|
+
* // Chain with decoder
|
|
181
|
+
* const decoder = await Decoder.create(stream);
|
|
182
|
+
* const filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
183
|
+
*
|
|
184
|
+
* for await (const frame of decoder.frames(filter.packets(input.packets()))) {
|
|
185
|
+
* // Process frames
|
|
186
|
+
* frame.free();
|
|
167
187
|
* }
|
|
168
188
|
* ```
|
|
189
|
+
*
|
|
190
|
+
* @see {@link process} For single packet filtering
|
|
191
|
+
* @see {@link flush} For end-of-stream handling
|
|
169
192
|
*/
|
|
170
193
|
packets(packets: AsyncIterable<Packet>): AsyncGenerator<Packet>;
|
|
171
194
|
/**
|
|
172
|
-
* Flush
|
|
195
|
+
* Flush filter and get remaining packets.
|
|
196
|
+
*
|
|
197
|
+
* Signals end-of-stream and retrieves buffered packets.
|
|
198
|
+
* Also resets internal filter state.
|
|
173
199
|
*
|
|
174
|
-
*
|
|
175
|
-
* Should be called when all input packets have been processed.
|
|
200
|
+
* Direct mapping to av_bsf_flush().
|
|
176
201
|
*
|
|
177
|
-
* @returns Array of remaining packets
|
|
202
|
+
* @returns Array of remaining packets
|
|
203
|
+
*
|
|
204
|
+
* @throws {Error} If filter is disposed
|
|
178
205
|
*
|
|
179
206
|
* @example
|
|
180
207
|
* ```typescript
|
|
181
|
-
*
|
|
182
|
-
* const remaining = await bsf.flush();
|
|
208
|
+
* const remaining = await filter.flush();
|
|
183
209
|
* for (const packet of remaining) {
|
|
184
210
|
* await output.writePacket(packet);
|
|
211
|
+
* packet.free();
|
|
185
212
|
* }
|
|
186
213
|
* ```
|
|
214
|
+
*
|
|
215
|
+
* @see {@link flushPackets} For async iteration
|
|
216
|
+
* @see {@link reset} For state reset only
|
|
187
217
|
*/
|
|
188
218
|
flush(): Promise<Packet[]>;
|
|
189
219
|
/**
|
|
190
|
-
* Flush
|
|
220
|
+
* Flush filter as async generator.
|
|
191
221
|
*
|
|
192
|
-
*
|
|
193
|
-
*
|
|
222
|
+
* Convenient async iteration over remaining packets.
|
|
223
|
+
* Combines flush and iteration.
|
|
194
224
|
*
|
|
195
|
-
* @yields Remaining packets
|
|
225
|
+
* @yields Remaining packets
|
|
226
|
+
* @throws {Error} If filter is disposed
|
|
196
227
|
*
|
|
197
228
|
* @example
|
|
198
229
|
* ```typescript
|
|
199
|
-
*
|
|
200
|
-
* for await (const packet of bsf.flushPackets()) {
|
|
230
|
+
* for await (const packet of filter.flushPackets()) {
|
|
201
231
|
* await output.writePacket(packet);
|
|
202
|
-
*
|
|
232
|
+
* packet.free();
|
|
203
233
|
* }
|
|
204
234
|
* ```
|
|
235
|
+
*
|
|
236
|
+
* @see {@link flush} For array return
|
|
205
237
|
*/
|
|
206
238
|
flushPackets(): AsyncGenerator<Packet>;
|
|
207
239
|
/**
|
|
208
|
-
* Get
|
|
209
|
-
*
|
|
240
|
+
* Get associated stream.
|
|
241
|
+
*
|
|
242
|
+
* Returns the stream this filter was created for.
|
|
243
|
+
*
|
|
244
|
+
* @returns Associated stream
|
|
245
|
+
*
|
|
246
|
+
* @example
|
|
247
|
+
* ```typescript
|
|
248
|
+
* const stream = filter.getStream();
|
|
249
|
+
* console.log(`Filtering stream ${stream.index}`);
|
|
250
|
+
* ```
|
|
210
251
|
*/
|
|
211
252
|
getStream(): Stream;
|
|
212
253
|
/**
|
|
213
|
-
* Reset
|
|
254
|
+
* Reset filter state.
|
|
214
255
|
*
|
|
215
|
-
* Clears internal buffers and resets
|
|
216
|
-
*
|
|
256
|
+
* Clears internal buffers and resets filter.
|
|
257
|
+
* Does not dispose resources.
|
|
258
|
+
*
|
|
259
|
+
* Direct mapping to av_bsf_flush().
|
|
260
|
+
*
|
|
261
|
+
* @throws {Error} If filter is disposed
|
|
217
262
|
*
|
|
218
263
|
* @example
|
|
219
264
|
* ```typescript
|
|
220
|
-
* //
|
|
221
|
-
*
|
|
222
|
-
* bsf.reset(); // Clear filter state
|
|
223
|
-
* // Continue processing from new position
|
|
265
|
+
* // Reset for new segment
|
|
266
|
+
* filter.reset();
|
|
224
267
|
* ```
|
|
268
|
+
*
|
|
269
|
+
* @see {@link flush} For reset with packet retrieval
|
|
225
270
|
*/
|
|
226
271
|
reset(): void;
|
|
227
272
|
/**
|
|
228
|
-
* Dispose of
|
|
273
|
+
* Dispose of filter and free resources.
|
|
229
274
|
*
|
|
230
|
-
*
|
|
231
|
-
*
|
|
275
|
+
* Releases filter context and marks as disposed.
|
|
276
|
+
* Safe to call multiple times.
|
|
232
277
|
*
|
|
233
278
|
* @example
|
|
234
279
|
* ```typescript
|
|
235
|
-
*
|
|
236
|
-
* using bsf = await BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
237
|
-
* // ... use filter
|
|
238
|
-
* } // Automatically disposed when leaving scope
|
|
280
|
+
* filter.dispose();
|
|
239
281
|
* ```
|
|
282
|
+
*
|
|
283
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
240
284
|
*/
|
|
241
285
|
dispose(): void;
|
|
242
286
|
/**
|
|
243
|
-
*
|
|
287
|
+
* Dispose of filter.
|
|
288
|
+
*
|
|
289
|
+
* Implements Disposable interface for automatic cleanup.
|
|
290
|
+
* Equivalent to calling dispose().
|
|
291
|
+
*
|
|
292
|
+
* @example
|
|
293
|
+
* ```typescript
|
|
294
|
+
* {
|
|
295
|
+
* using filter = BitStreamFilterAPI.create('h264_mp4toannexb', stream);
|
|
296
|
+
* // Use filter...
|
|
297
|
+
* } // Automatically disposed
|
|
298
|
+
* ```
|
|
299
|
+
*
|
|
300
|
+
* @see {@link dispose} For manual cleanup
|
|
244
301
|
*/
|
|
245
302
|
[Symbol.dispose](): void;
|
|
246
303
|
}
|