node-av 1.0.3 → 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.
Files changed (162) hide show
  1. package/README.md +56 -41
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +182 -126
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +286 -130
  6. package/dist/api/decoder.js +321 -159
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +254 -158
  9. package/dist/api/encoder.js +326 -298
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +912 -0
  12. package/dist/api/filter-presets.js +1407 -0
  13. package/dist/api/filter-presets.js.map +1 -0
  14. package/dist/api/filter.d.ts +280 -284
  15. package/dist/api/filter.js +435 -509
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +226 -159
  18. package/dist/api/hardware.js +405 -287
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -2
  21. package/dist/api/index.js +1 -0
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +45 -47
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +244 -141
  27. package/dist/api/media-input.js +207 -104
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +212 -129
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +22 -182
  36. package/dist/api/utilities/audio-sample.d.ts +1 -1
  37. package/dist/api/utilities/image.d.ts +1 -1
  38. package/dist/api/utilities/media-type.d.ts +1 -1
  39. package/dist/api/utilities/pixel-format.d.ts +1 -1
  40. package/dist/api/utilities/sample-format.d.ts +1 -1
  41. package/dist/api/utilities/timestamp.d.ts +1 -1
  42. package/dist/api/utils.d.ts +1 -2
  43. package/dist/api/utils.js +9 -0
  44. package/dist/api/utils.js.map +1 -1
  45. package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
  46. package/dist/constants/channel-layouts.js.map +1 -0
  47. package/dist/{lib → constants}/constants.d.ts +19 -4
  48. package/dist/{lib → constants}/constants.js +15 -1
  49. package/dist/constants/constants.js.map +1 -0
  50. package/dist/constants/decoders.d.ts +609 -0
  51. package/dist/constants/decoders.js +617 -0
  52. package/dist/constants/decoders.js.map +1 -0
  53. package/dist/constants/encoders.d.ts +285 -0
  54. package/dist/constants/encoders.js +298 -0
  55. package/dist/constants/encoders.js.map +1 -0
  56. package/dist/constants/index.d.ts +4 -0
  57. package/dist/constants/index.js +5 -0
  58. package/dist/constants/index.js.map +1 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +2 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/audio-fifo.d.ts +128 -171
  63. package/dist/lib/audio-fifo.js +130 -173
  64. package/dist/lib/audio-fifo.js.map +1 -1
  65. package/dist/lib/binding.d.ts +7 -5
  66. package/dist/lib/binding.js +5 -0
  67. package/dist/lib/binding.js.map +1 -1
  68. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  69. package/dist/lib/bitstream-filter-context.js +139 -188
  70. package/dist/lib/bitstream-filter-context.js.map +1 -1
  71. package/dist/lib/bitstream-filter.d.ts +69 -55
  72. package/dist/lib/bitstream-filter.js +68 -54
  73. package/dist/lib/bitstream-filter.js.map +1 -1
  74. package/dist/lib/codec-context.d.ts +317 -381
  75. package/dist/lib/codec-context.js +316 -381
  76. package/dist/lib/codec-context.js.map +1 -1
  77. package/dist/lib/codec-parameters.d.ts +161 -171
  78. package/dist/lib/codec-parameters.js +162 -172
  79. package/dist/lib/codec-parameters.js.map +1 -1
  80. package/dist/lib/codec-parser.d.ts +92 -105
  81. package/dist/lib/codec-parser.js +92 -103
  82. package/dist/lib/codec-parser.js.map +1 -1
  83. package/dist/lib/codec.d.ts +328 -217
  84. package/dist/lib/codec.js +392 -218
  85. package/dist/lib/codec.js.map +1 -1
  86. package/dist/lib/dictionary.d.ts +150 -204
  87. package/dist/lib/dictionary.js +159 -213
  88. package/dist/lib/dictionary.js.map +1 -1
  89. package/dist/lib/error.d.ts +97 -131
  90. package/dist/lib/error.js +98 -128
  91. package/dist/lib/error.js.map +1 -1
  92. package/dist/lib/filter-context.d.ts +317 -194
  93. package/dist/lib/filter-context.js +335 -200
  94. package/dist/lib/filter-context.js.map +1 -1
  95. package/dist/lib/filter-graph.d.ts +252 -293
  96. package/dist/lib/filter-graph.js +253 -294
  97. package/dist/lib/filter-graph.js.map +1 -1
  98. package/dist/lib/filter-inout.d.ts +87 -95
  99. package/dist/lib/filter-inout.js +87 -95
  100. package/dist/lib/filter-inout.js.map +1 -1
  101. package/dist/lib/filter.d.ts +93 -111
  102. package/dist/lib/filter.js +94 -112
  103. package/dist/lib/filter.js.map +1 -1
  104. package/dist/lib/format-context.d.ts +321 -429
  105. package/dist/lib/format-context.js +314 -386
  106. package/dist/lib/format-context.js.map +1 -1
  107. package/dist/lib/frame.d.ts +263 -406
  108. package/dist/lib/frame.js +263 -408
  109. package/dist/lib/frame.js.map +1 -1
  110. package/dist/lib/hardware-device-context.d.ts +150 -204
  111. package/dist/lib/hardware-device-context.js +149 -203
  112. package/dist/lib/hardware-device-context.js.map +1 -1
  113. package/dist/lib/hardware-frames-context.d.ts +171 -181
  114. package/dist/lib/hardware-frames-context.js +171 -181
  115. package/dist/lib/hardware-frames-context.js.map +1 -1
  116. package/dist/lib/index.d.ts +2 -3
  117. package/dist/lib/index.js +2 -5
  118. package/dist/lib/index.js.map +1 -1
  119. package/dist/lib/input-format.d.ts +90 -118
  120. package/dist/lib/input-format.js +89 -117
  121. package/dist/lib/input-format.js.map +1 -1
  122. package/dist/lib/io-context.d.ts +210 -242
  123. package/dist/lib/io-context.js +221 -253
  124. package/dist/lib/io-context.js.map +1 -1
  125. package/dist/lib/log.d.ts +86 -120
  126. package/dist/lib/log.js +85 -122
  127. package/dist/lib/log.js.map +1 -1
  128. package/dist/lib/native-types.d.ts +127 -112
  129. package/dist/lib/native-types.js +9 -0
  130. package/dist/lib/native-types.js.map +1 -1
  131. package/dist/lib/option.d.ts +285 -242
  132. package/dist/lib/option.js +310 -250
  133. package/dist/lib/option.js.map +1 -1
  134. package/dist/lib/output-format.d.ts +78 -102
  135. package/dist/lib/output-format.js +77 -101
  136. package/dist/lib/output-format.js.map +1 -1
  137. package/dist/lib/packet.d.ts +173 -241
  138. package/dist/lib/packet.js +172 -241
  139. package/dist/lib/packet.js.map +1 -1
  140. package/dist/lib/rational.d.ts +0 -2
  141. package/dist/lib/rational.js +0 -2
  142. package/dist/lib/rational.js.map +1 -1
  143. package/dist/lib/software-resample-context.d.ts +242 -326
  144. package/dist/lib/software-resample-context.js +242 -326
  145. package/dist/lib/software-resample-context.js.map +1 -1
  146. package/dist/lib/software-scale-context.d.ts +130 -174
  147. package/dist/lib/software-scale-context.js +132 -176
  148. package/dist/lib/software-scale-context.js.map +1 -1
  149. package/dist/lib/stream.d.ts +88 -198
  150. package/dist/lib/stream.js +87 -197
  151. package/dist/lib/stream.js.map +1 -1
  152. package/dist/lib/types.d.ts +1 -1
  153. package/dist/lib/utilities.d.ts +372 -181
  154. package/dist/lib/utilities.js +373 -182
  155. package/dist/lib/utilities.js.map +1 -1
  156. package/install/check.js +0 -1
  157. package/package.json +32 -24
  158. package/release_notes.md +43 -13
  159. package/CHANGELOG.md +0 -8
  160. package/dist/lib/channel-layouts.js.map +0 -1
  161. package/dist/lib/constants.js.map +0 -1
  162. /package/dist/{lib → constants}/channel-layouts.js +0 -0
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
+ [![npm version](https://img.shields.io/npm/v/node-av.svg)](https://www.npmjs.com/package/node-av)
8
+ [![npm downloads](https://img.shields.io/npm/dm/node-av.svg)](https://www.npmjs.com/package/node-av)
9
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://opensource.org/licenses/MIT)
10
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue.svg)](https://www.typescriptlang.org/)
11
+ [![FFmpeg](https://img.shields.io/badge/FFmpeg-7.1+-green.svg)](https://ffmpeg.org)
12
+ [![Platform](https://img.shields.io/badge/platform-Windows%20%7C%20macOS%20%7C%20Linux-lightgrey.svg)](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
@@ -14,6 +27,7 @@ npm install node-av
14
27
 
15
28
  ```typescript
16
29
  import { Decoder, Encoder, MediaInput, MediaOutput } from 'node-av/api';
30
+ import { FF_ENCODER_LIBX264 } from 'node-av/constants';
17
31
 
18
32
  // Open media
19
33
  await using input = await MediaInput.open('input.mp4');
@@ -24,7 +38,7 @@ const videoStream = input.video();
24
38
 
25
39
  // Create decoder/encoder
26
40
  using decoder = await Decoder.create(videoStream!);
27
- using encoder = await Encoder.create('libx264', videoStream!, {
41
+ using encoder = await Encoder.create(FF_ENCODER_LIBX264, decoder.getOutputStreamInfo(), {
28
42
  bitrate: '2M',
29
43
  gopSize: 60,
30
44
  });
@@ -71,7 +85,7 @@ import { pipeline, MediaInput, MediaOutput, Decoder, Encoder } from 'node-av/api
71
85
  const input = await MediaInput.open('input.mp4');
72
86
  const output = await MediaOutput.open('output.mp4');
73
87
  const decoder = await Decoder.create(input.video());
74
- const encoder = await Encoder.create('libx264', input.video(), {
88
+ const encoder = await Encoder.create(FF_ENCODER_LIBX264, decoder.getOutputStreamInfo(), {
75
89
  bitrate: '2M',
76
90
  gopSize: 60
77
91
  });
@@ -109,9 +123,10 @@ The library supports all hardware acceleration methods available in FFmpeg. The
109
123
 
110
124
  ```typescript
111
125
  import { HardwareContext } from 'node-av/api';
126
+ import { FF_ENCODER_H264_VIDEOTOOLBOX } from 'node-av/constants';
112
127
 
113
128
  // Automatically detect best available hardware
114
- const hw = await HardwareContext.auto();
129
+ const hw = HardwareContext.auto();
115
130
  if (hw) {
116
131
  console.log(`Using hardware: ${hw.deviceTypeName}`);
117
132
 
@@ -121,7 +136,7 @@ if (hw) {
121
136
  });
122
137
 
123
138
  // Use with encoder (use hardware-specific codec)
124
- const encoder = await Encoder.create('h264_videotoolbox', videoStream, {
139
+ const encoder = await Encoder.create(FF_ENCODER_H264_VIDEOTOOLBOX, decoder.getOutputStreamInfo(), {
125
140
  hardware: hw
126
141
  });
127
142
  }
@@ -133,8 +148,8 @@ if (hw) {
133
148
  import { AV_HWDEVICE_TYPE_CUDA, AV_HWDEVICE_TYPE_VAAPI } from 'node-av/constants';
134
149
 
135
150
  // Use specific hardware type
136
- const cuda = await HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
137
- const vaapi = await HardwareContext.create(AV_HWDEVICE_TYPE_VAAPI, '/dev/dri/renderD128');
151
+ const cuda = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
152
+ const vaapi = HardwareContext.create(AV_HWDEVICE_TYPE_VAAPI, '/dev/dri/renderD128');
138
153
  ```
139
154
 
140
155
  ## Imports and Tree Shaking
@@ -241,50 +256,50 @@ NodeAV provides direct bindings to FFmpeg's C APIs, which work with raw memory p
241
256
 
242
257
  | Example | FFmpeg | Low-Level API | High-Level API |
243
258
  |---------|--------|---------------|----------------|
244
- | `api-encode-decode` | | | [✓](examples/api-encode-decode.ts) |
245
- | `api-frame-extract` | | | [✓](examples/api-frame-extract.ts) |
246
- | `api-hw-decode-sw-encode` | | | [✓](examples/api-hw-decode-sw-encode.ts) |
247
- | `api-hw-raw` | | | [✓](examples/api-hw-raw.ts) |
248
- | `api-hw-rtsp-custom-io` | | | [✓](examples/api-hw-rtsp-custom-io.ts) |
249
- | `api-hw-rtsp` | | | [✓](examples/api-hw-rtsp.ts) |
250
- | `api-hw-transcode` | | | [✓](examples/api-hw-transcode.ts) |
251
- | `api-muxing` | | | [✓](examples/api-muxing.ts) |
252
- | `api-pipeline-hw-rtsp` | | | [✓](examples/api-pipeline-hw-rtsp.ts) |
253
- | `api-pipeline-raw-muxing` | | | [✓](examples/api-pipeline-raw-muxing.ts) |
254
- | `api-stream-input` | | | [✓](examples/api-stream-input.ts) |
255
- | `api-sw-decode-hw-encode` | | | [✓](examples/api-sw-decode-hw-encode.ts) |
256
- | `api-sw-transcode` | | | [✓](examples/api-sw-transcode.ts) |
257
- | `avio-read-callback` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/avio_read_callback.c) | [✓](examples/avio-read-callback.ts) | |
258
- | `decode-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_audio.c) | [✓](examples/decode-audio.ts) | |
259
- | `decode-filter-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_filter_audio.c) | [✓](examples/decode-filter-audio.ts) | |
260
- | `decode-filter-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_filter_video.c) | [✓](examples/decode-filter-video.ts) | |
261
- | `decode-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/decode_video.c) | [✓](examples/decode-video.ts) | |
262
- | `demux-decode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/demux_decode.c) | [✓](examples/demux-decode.ts) | |
263
- | `encode-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/encode_audio.c) | [✓](examples/encode-audio.ts) | |
264
- | `encode-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/encode_video.c) | [✓](examples/encode-video.ts) | |
265
- | `ffprobe-metadata` | | [✓](examples/ffprobe-metadata.ts) | |
266
- | `filter-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/filter_audio.c) | [✓](examples/filter-audio.ts) | |
267
- | `hw-decode` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/hw_decode.c) | [✓](examples/hw-decode.ts) | |
268
- | `hw-encode` | | [✓](examples/hw-encode.ts) | |
269
- | `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) | |
270
285
  | `qsv-decode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/qsv_decode.c) | | |
271
286
  | `qsv-transcode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/qsv_transcode.c) | | |
272
287
  | `vaapi-encode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_encode.c) | | |
273
288
  | `vaapi-transcode` | [✓](https://github.com/FFmpeg/FFmpeg/blob/master/doc/examples/vaapi_transcode.c) | | |
274
- | `mux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/mux.c) | [✓](examples/mux.ts) | |
275
- | `remux` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/remux.c) | [✓](examples/remux.ts) | |
276
- | `resample-audio` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/resample_audio.c) | [✓](examples/resample-audio.ts) | |
277
- | `scale-video` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/scale_video.c) | [✓](examples/scale-video.ts) | |
278
- | `show-metadata` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/show_metadata.c) | [✓](examples/show-metadata.ts) | |
279
- | `transcode-aac` | [✓](https://github.com/FFmpeg/FFmpeg/tree/master/doc/examples/transcode_aac.c) | [✓](examples/transcode-aac.ts) | |
280
- | `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) | |
281
296
 
282
297
 
283
298
  ## Prebuilt Binaries
284
299
 
285
300
  Prebuilt binaries are available for macOS, Linux, and Windows (x64/arm64). The package will automatically build from source if needed.
286
301
 
287
- 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)**.
288
303
 
289
304
  ## License
290
305
 
@@ -294,7 +309,7 @@ This project is licensed under the MIT License. See the LICENSE file for details
294
309
 
295
310
  ## Contributing
296
311
 
297
- 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.
298
313
 
299
314
  ## Support
300
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
- * Handles filter initialization, packet processing, and cleanup.
18
- * Designed for simple, efficient packet filtering workflows.
19
- *
20
- * Manages filter context lifecycle and provides automatic cleanup.
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
- * // Create filter for H.264 stream
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
- * // Process packets
31
- * for await (const packet of media.packets()) {
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
- * // Flush and cleanup
42
- * const remaining = await bsf.flush();
43
- * bsf.dispose();
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 bsf = await BitStreamFilterAPI.create('extract_extradata', stream);
29
+ * const filter = BitStreamFilterAPI.create('hevc_mp4toannexb', videoStream);
50
30
  *
51
- * for await (const filtered of bsf.packets(media.packets())) {
52
- * // Filtered packets are automatically processed
53
- * await output.writePacket(filtered);
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
- * Private constructor - use BitStreamFilterAPI.create() instead.
64
- *
65
- * @param filter - The bitstream filter
66
- * @param ctx - Initialized filter context
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 specific stream.
54
+ * Create a bitstream filter for a stream.
72
55
  *
73
- * Factory method that handles filter discovery, context setup,
74
- * and initialization.
56
+ * Initializes filter with stream codec parameters.
57
+ * Configures time base and prepares for packet processing.
75
58
  *
76
- * @param filterName - Name of the bitstream filter (e.g., 'h264_mp4toannexb')
77
- * @param stream - Stream to filter
59
+ * Direct mapping to av_bsf_get_by_name() and av_bsf_alloc().
78
60
  *
79
- * @returns Promise resolving to configured BitStreamFilterAPI
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 unavailable or initialization fails
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
- * const media = await MediaInput.open('video.mp4');
86
- * const stream = media.video();
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
- * @returns The name of the bitstream filter
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
- get name(): string;
88
+ static create(filterName: string, stream: Stream): BitStreamFilterAPI;
97
89
  /**
98
- * Get the associated stream.
90
+ * Get filter name.
99
91
  *
100
- * @returns The stream this filter was created for
92
+ * @example
93
+ * ```typescript
94
+ * console.log(`Using filter: ${filter.name}`);
95
+ * ```
101
96
  */
102
- get streamInfo(): Stream;
97
+ get name(): string;
103
98
  /**
104
99
  * Get output codec parameters.
105
100
  *
106
- * Returns the output codec parameters after filter initialization.
107
- * These may differ from input parameters depending on the filter.
101
+ * Parameters after filter processing.
102
+ * May differ from input parameters.
108
103
  *
109
- * @returns Output codec parameters, or null if not available
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
- * Returns the output time base after filter initialization.
114
+ * Time base after filter processing.
116
115
  *
117
- * @returns Output time base, or null if not available
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 single packet through the filter.
124
+ * Process a packet through the filter.
122
125
  *
123
- * Sends a packet to the filter and retrieves all output packets.
124
- * One input packet may produce zero, one, or multiple output packets.
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
- * @param packet - Packet to filter, or null to signal EOF
130
+ * Direct mapping to av_bsf_send_packet() and av_bsf_receive_packet().
127
131
  *
128
- * @returns Array of filtered packets (may be empty)
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 inputPacket = await media.readPacket();
133
- * const filtered = await bsf.process(inputPacket);
134
- *
135
- * for (const packet of filtered) {
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 a stream of packets through the filter.
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
- * @param packets - Async iterable of packets to filter
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
- * const bsf = await BitStreamFilterAPI.create('h264_mp4toannexb', stream);
155
- *
156
- * // Filter only video packets
157
- * async function* videoPackets() {
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
- * for await (const filtered of bsf.packets(videoPackets())) {
166
- * await output.writePacket(filtered);
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 the filter and retrieve remaining packets.
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
- * Sends EOF to the filter and retrieves any buffered packets.
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 (may be empty)
202
+ * @returns Array of remaining packets
203
+ *
204
+ * @throws {Error} If filter is disposed
178
205
  *
179
206
  * @example
180
207
  * ```typescript
181
- * // After processing all packets
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 the filter and yield remaining packets.
220
+ * Flush filter as async generator.
191
221
  *
192
- * Async generator that sends EOF to the filter and yields any buffered packets.
193
- * Provides a convenient way to process all remaining packets after input is complete.
222
+ * Convenient async iteration over remaining packets.
223
+ * Combines flush and iteration.
194
224
  *
195
- * @yields Remaining packets from the filter
225
+ * @yields Remaining packets
226
+ * @throws {Error} If filter is disposed
196
227
  *
197
228
  * @example
198
229
  * ```typescript
199
- * // Process all remaining packets with generator
200
- * for await (const packet of bsf.flushPackets()) {
230
+ * for await (const packet of filter.flushPackets()) {
201
231
  * await output.writePacket(packet);
202
- * using _ = packet; // Auto cleanup
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 the stream this filter was created for.
209
- * Used for determining stream configuration in pipeline.
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 the filter state.
254
+ * Reset filter state.
214
255
  *
215
- * Clears internal buffers and resets the filter to initial state.
216
- * Useful when seeking or switching between streams.
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
- * // When seeking in the input
221
- * await media.seek(timestamp);
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 the filter resources.
273
+ * Dispose of filter and free resources.
229
274
  *
230
- * Automatically called when using the `using` statement.
231
- * Frees all associated FFmpeg resources.
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
- * Symbol.dispose implementation for using statement.
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
  }