@revizly/node-av 5.2.2-beta.1

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 (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,441 @@
1
+ import { bindings } from './binding.js';
2
+ import { BitStreamFilter } from './bitstream-filter.js';
3
+ import { CodecParameters } from './codec-parameters.js';
4
+ import { OptionMember } from './option.js';
5
+ import { Rational } from './rational.js';
6
+ /**
7
+ * Bitstream filter context for processing compressed video/audio streams.
8
+ *
9
+ * Applies bitstream filters to modify or analyze compressed packets without
10
+ * full decoding/encoding. Common uses include format conversion (e.g., H.264 MP4 to Annex B),
11
+ * metadata extraction, parameter set manipulation, and packet splitting/merging.
12
+ * Essential for stream compatibility between different containers and decoders.
13
+ *
14
+ * Direct mapping to FFmpeg's AVBSFContext.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { BitStreamFilterContext, BitStreamFilter, Packet, FFmpegError } from 'node-av';
19
+ *
20
+ * // Create and initialize H.264 stream format converter
21
+ * const ctx = new BitStreamFilterContext();
22
+ * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
23
+ * if (!filter) {
24
+ * throw new Error('H.264 filter not available');
25
+ * }
26
+ *
27
+ * let ret = ctx.alloc(filter);
28
+ * FFmpegError.throwIfError(ret, 'alloc');
29
+ *
30
+ * ret = ctx.init();
31
+ * FFmpegError.throwIfError(ret, 'init');
32
+ *
33
+ * // Process packets
34
+ * const inputPacket = new Packet();
35
+ * const outputPacket = new Packet();
36
+ *
37
+ * ret = await ctx.sendPacket(inputPacket);
38
+ * FFmpegError.throwIfError(ret, 'sendPacket');
39
+ *
40
+ * ret = await ctx.receivePacket(outputPacket);
41
+ * if (ret >= 0) {
42
+ * // Process filtered packet
43
+ * }
44
+ *
45
+ * // Cleanup
46
+ * ctx.free();
47
+ * ```
48
+ *
49
+ * @see {@link BitStreamFilter} For available filter types
50
+ * @see {@link Packet} For packet manipulation
51
+ */
52
+ export class BitStreamFilterContext extends OptionMember {
53
+ _filter; // Cache for filter wrapper
54
+ constructor() {
55
+ super(new bindings.BitStreamFilterContext());
56
+ }
57
+ /**
58
+ * Check if the context has been initialized.
59
+ *
60
+ * Returns true if init() has been successfully called.
61
+ * The context must be initialized before sending/receiving packets.
62
+ */
63
+ get isInitialized() {
64
+ return this.native.isInitialized();
65
+ }
66
+ /**
67
+ * Input codec parameters.
68
+ *
69
+ * Parameters describing the input stream format.
70
+ * These are automatically configured from the input packets in most cases.
71
+ *
72
+ * Direct mapping to AVBSFContext->par_in.
73
+ */
74
+ get inputCodecParameters() {
75
+ const nativeParams = this.native.inputCodecParameters;
76
+ if (!nativeParams) {
77
+ return null;
78
+ }
79
+ // Wrap it in our TypeScript class
80
+ const wrapper = Object.create(CodecParameters.prototype);
81
+ wrapper.native = nativeParams;
82
+ return wrapper;
83
+ }
84
+ /**
85
+ * Output codec parameters.
86
+ *
87
+ * Parameters describing the output stream format after filtering.
88
+ * These reflect any changes made by the bitstream filter.
89
+ *
90
+ * Direct mapping to AVBSFContext->par_out.
91
+ */
92
+ get outputCodecParameters() {
93
+ const nativeParams = this.native.outputCodecParameters;
94
+ if (!nativeParams) {
95
+ return null;
96
+ }
97
+ // Wrap it in our TypeScript class
98
+ const wrapper = Object.create(CodecParameters.prototype);
99
+ wrapper.native = nativeParams;
100
+ return wrapper;
101
+ }
102
+ /**
103
+ * Input time base.
104
+ *
105
+ * Time base of the input packets (timestamps per second).
106
+ * Must be set before init() for proper timestamp handling.
107
+ *
108
+ * Direct mapping to AVBSFContext->time_base_in.
109
+ */
110
+ get inputTimeBase() {
111
+ const tb = this.native.inputTimeBase;
112
+ return new Rational(tb.num, tb.den);
113
+ }
114
+ set inputTimeBase(value) {
115
+ this.native.inputTimeBase = { num: value.num, den: value.den };
116
+ }
117
+ /**
118
+ * Output time base.
119
+ *
120
+ * Time base of the output packets after filtering.
121
+ * May differ from input if the filter modifies timing.
122
+ *
123
+ * Direct mapping to AVBSFContext->time_base_out.
124
+ */
125
+ get outputTimeBase() {
126
+ const tb = this.native.outputTimeBase;
127
+ if (!tb)
128
+ return null;
129
+ return new Rational(tb.num, tb.den);
130
+ }
131
+ /**
132
+ * The bitstream filter being used.
133
+ *
134
+ * Reference to the filter descriptor allocated to this context.
135
+ *
136
+ * Direct mapping to AVBSFContext->filter.
137
+ */
138
+ get filter() {
139
+ if (!this._filter) {
140
+ const native = this.native.filter;
141
+ if (!native) {
142
+ return null;
143
+ }
144
+ this._filter = new BitStreamFilter(native);
145
+ }
146
+ return this._filter;
147
+ }
148
+ /**
149
+ * Allocate a bitstream filter context.
150
+ *
151
+ * Allocates and configures the context for the specified filter.
152
+ * Must be called before init().
153
+ *
154
+ * Direct mapping to av_bsf_alloc().
155
+ *
156
+ * @param filter - The bitstream filter to use
157
+ *
158
+ * @returns 0 on success, negative AVERROR on error:
159
+ * - AVERROR_ENOMEM: Memory allocation failure
160
+ * - AVERROR_EINVAL: Invalid filter
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * import { FFmpegError } from 'node-av';
165
+ *
166
+ * const filter = BitStreamFilter.getByName('h264_mp4toannexb');
167
+ * if (!filter) {
168
+ * throw new Error('Filter not found');
169
+ * }
170
+ *
171
+ * const ret = ctx.alloc(filter);
172
+ * FFmpegError.throwIfError(ret, 'alloc');
173
+ * ```
174
+ *
175
+ * @see {@link init} To initialize after allocation
176
+ * @see {@link BitStreamFilter.getByName} To get filter by name
177
+ */
178
+ alloc(filter) {
179
+ return this.native.alloc(filter.getNative());
180
+ }
181
+ /**
182
+ * Initialize the bitstream filter context.
183
+ *
184
+ * Initializes the filter with the configured parameters.
185
+ * Must be called after alloc() and before processing packets.
186
+ *
187
+ * Direct mapping to av_bsf_init().
188
+ *
189
+ * @returns 0 on success, negative AVERROR on error:
190
+ * - AVERROR_EINVAL: Invalid parameters
191
+ * - AVERROR_ENOMEM: Memory allocation failure
192
+ *
193
+ * @example
194
+ * ```typescript
195
+ * import { FFmpegError } from 'node-av';
196
+ *
197
+ * // Allocate and initialize
198
+ * const ret1 = ctx.alloc(filter);
199
+ * FFmpegError.throwIfError(ret1, 'alloc');
200
+ *
201
+ * // Set parameters if needed
202
+ * ctx.inputTimeBase = new Rational(1, 25);
203
+ *
204
+ * const ret2 = ctx.init();
205
+ * FFmpegError.throwIfError(ret2, 'init');
206
+ * ```
207
+ *
208
+ * @see {@link alloc} Must be called first
209
+ * @see {@link isInitialized} To check initialization status
210
+ */
211
+ init() {
212
+ return this.native.init();
213
+ }
214
+ /**
215
+ * Free the bitstream filter context.
216
+ *
217
+ * Releases all resources associated with the context.
218
+ * The context becomes invalid after calling this.
219
+ *
220
+ * Direct mapping to av_bsf_free().
221
+ *
222
+ * @example
223
+ * ```typescript
224
+ * ctx.free();
225
+ * // Context is now invalid
226
+ * ```
227
+ *
228
+ * @see {@link Symbol.dispose} For automatic cleanup
229
+ * @see {@link alloc} To allocate
230
+ */
231
+ free() {
232
+ this.native.free();
233
+ this._filter = undefined;
234
+ }
235
+ /**
236
+ * Flush the bitstream filter.
237
+ *
238
+ * Resets the internal state and discards any buffered data.
239
+ * Useful when seeking or switching streams.
240
+ *
241
+ * Direct mapping to av_bsf_flush().
242
+ *
243
+ * @example
244
+ * ```typescript
245
+ * // Flush when seeking
246
+ * ctx.flush();
247
+ * // Now ready to process packets from new position
248
+ * ```
249
+ */
250
+ flush() {
251
+ this.native.flush();
252
+ }
253
+ /**
254
+ * Send a packet to the bitstream filter.
255
+ *
256
+ * Submits a packet for filtering. The filter may buffer the packet
257
+ * internally and require multiple calls to receivePacket() to retrieve
258
+ * all output. Send null to signal end of stream.
259
+ *
260
+ * Direct mapping to av_bsf_send_packet().
261
+ *
262
+ * @param packet - Packet to filter, or null to signal EOF
263
+ *
264
+ * @returns 0 on success, negative AVERROR on error:
265
+ * - AVERROR_EAGAIN: Filter needs output to be consumed first
266
+ * - AVERROR_EOF: Filter has been flushed
267
+ * - AVERROR_EINVAL: Invalid parameters
268
+ * - AVERROR_ENOMEM: Memory allocation failure
269
+ *
270
+ * @example
271
+ * ```typescript
272
+ * import { FFmpegError } from 'node-av';
273
+ * import { AVERROR_EAGAIN } from 'node-av';
274
+ *
275
+ * const ret = await ctx.sendPacket(inputPacket);
276
+ * if (ret === AVERROR_EAGAIN) {
277
+ * // Need to receive packets first
278
+ * const ret2 = await ctx.receivePacket(outputPacket);
279
+ * FFmpegError.throwIfError(ret2, 'receivePacket');
280
+ * } else {
281
+ * FFmpegError.throwIfError(ret, 'sendPacket');
282
+ * }
283
+ *
284
+ * // Send EOF
285
+ * await ctx.sendPacket(null);
286
+ * ```
287
+ *
288
+ * @see {@link receivePacket} To retrieve filtered packets
289
+ */
290
+ async sendPacket(packet) {
291
+ return await this.native.sendPacket(packet ? packet.getNative() : null);
292
+ }
293
+ /**
294
+ * Send a packet to the bitstream filter synchronously.
295
+ * Synchronous version of sendPacket.
296
+ *
297
+ * Submits a packet for filtering. The filter may buffer packets
298
+ * internally and produce output with different timing.
299
+ *
300
+ * Direct mapping to av_bsf_send_packet().
301
+ *
302
+ * @param packet - Packet to filter (null to drain)
303
+ *
304
+ * @returns 0 on success, negative AVERROR on error:
305
+ * - AVERROR_EAGAIN: Need to receive packets first
306
+ * - AVERROR_EOF: Filter has been flushed
307
+ * - AVERROR_EINVAL: Invalid state
308
+ * - AVERROR(ENOMEM): Memory allocation failure
309
+ *
310
+ * @example
311
+ * ```typescript
312
+ * import { FFmpegError } from 'node-av';
313
+ * import { AVERROR_EAGAIN } from 'node-av/constants';
314
+ *
315
+ * // Send packet to filter
316
+ * const ret = ctx.sendPacketSync(inputPacket);
317
+ * if (ret === AVERROR_EAGAIN) {
318
+ * // Need to receive output first
319
+ * const outputPacket = new Packet();
320
+ * ctx.receivePacketSync(outputPacket);
321
+ * } else {
322
+ * FFmpegError.throwIfError(ret, 'sendPacketSync');
323
+ * }
324
+ *
325
+ * // Drain filter
326
+ * ctx.sendPacketSync(null);
327
+ * ```
328
+ *
329
+ * @see {@link sendPacket} For async version
330
+ */
331
+ sendPacketSync(packet) {
332
+ return this.native.sendPacketSync(packet ? packet.getNative() : null);
333
+ }
334
+ /**
335
+ * Receive a filtered packet from the bitstream filter.
336
+ *
337
+ * Retrieves a packet that has been processed by the filter.
338
+ * May need to be called multiple times after each sendPacket().
339
+ *
340
+ * Direct mapping to av_bsf_receive_packet().
341
+ *
342
+ * @param packet - Packet to receive filtered data into
343
+ *
344
+ * @returns 0 on success, negative AVERROR on error:
345
+ * - AVERROR_EAGAIN: Need more input
346
+ * - AVERROR_EOF: No more packets available
347
+ * - AVERROR_EINVAL: Invalid parameters
348
+ *
349
+ * @example
350
+ * ```typescript
351
+ * import { FFmpegError } from 'node-av';
352
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
353
+ *
354
+ * // Receive all available packets
355
+ * while (true) {
356
+ * const ret = await ctx.receivePacket(outputPacket);
357
+ * if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
358
+ * break;
359
+ * }
360
+ * FFmpegError.throwIfError(ret, 'receivePacket');
361
+ *
362
+ * // Process filtered packet
363
+ * console.log(`Filtered packet size: ${outputPacket.size}`);
364
+ * }
365
+ * ```
366
+ *
367
+ * @see {@link sendPacket} To submit packets for filtering
368
+ */
369
+ async receivePacket(packet) {
370
+ return await this.native.receivePacket(packet.getNative());
371
+ }
372
+ /**
373
+ * Receive a filtered packet from the bitstream filter synchronously.
374
+ * Synchronous version of receivePacket.
375
+ *
376
+ * Retrieves a packet that has been processed by the filter.
377
+ * May need to be called multiple times after each sendPacketSync().
378
+ *
379
+ * Direct mapping to av_bsf_receive_packet().
380
+ *
381
+ * @param packet - Packet to receive filtered data into
382
+ *
383
+ * @returns 0 on success, negative AVERROR on error:
384
+ * - AVERROR_EAGAIN: Need more input
385
+ * - AVERROR_EOF: No more packets available
386
+ *
387
+ * @example
388
+ * ```typescript
389
+ * import { FFmpegError } from 'node-av';
390
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
391
+ *
392
+ * // Receive filtered packets
393
+ * const outputPacket = new Packet();
394
+ * let ret;
395
+ * while ((ret = ctx.receivePacketSync(outputPacket)) >= 0) {
396
+ * // Process filtered packet
397
+ * console.log(`Filtered packet size: ${outputPacket.size}`);
398
+ * outputPacket.unref();
399
+ * }
400
+ *
401
+ * if (ret !== AVERROR_EAGAIN && ret !== AVERROR_EOF) {
402
+ * FFmpegError.throwIfError(ret, 'receivePacketSync');
403
+ * }
404
+ * ```
405
+ *
406
+ * @see {@link receivePacket} For async version
407
+ */
408
+ receivePacketSync(packet) {
409
+ return this.native.receivePacketSync(packet.getNative());
410
+ }
411
+ /**
412
+ * Get the underlying native BitStreamFilterContext object.
413
+ *
414
+ * @returns The native BitStreamFilterContext binding object
415
+ *
416
+ * @internal
417
+ */
418
+ getNative() {
419
+ return this.native;
420
+ }
421
+ /**
422
+ * Dispose of the bitstream filter context.
423
+ *
424
+ * Implements the Disposable interface for automatic cleanup.
425
+ * Equivalent to calling free().
426
+ *
427
+ * @example
428
+ * ```typescript
429
+ * {
430
+ * using ctx = new BitStreamFilterContext();
431
+ * ctx.alloc(filter);
432
+ * ctx.init();
433
+ * // Use context...
434
+ * } // Automatically freed when leaving scope
435
+ * ```
436
+ */
437
+ [Symbol.dispose]() {
438
+ this.native[Symbol.dispose]();
439
+ }
440
+ }
441
+ //# sourceMappingURL=bitstream-filter-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"bitstream-filter-context.js","sourceRoot":"","sources":["../../src/lib/bitstream-filter-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,eAAe,EAAE,MAAM,uBAAuB,CAAC;AACxD,OAAO,EAAE,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} from './native-types.js';
3
+ /**
4
+ * Bitstream filter descriptor.
5
+ *
6
+ * Provides access to bitstream filter properties and codec compatibility information.
7
+ * Bitstream filters are used to modify or analyze compressed bitstreams without
8
+ * full decoding/encoding. Common uses include H.264/HEVC parameter set extraction,
9
+ * VP9 superframe splitting, and adding/removing codec-specific headers.
10
+ *
11
+ * Direct mapping to FFmpeg's AVBitStreamFilter.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { BitStreamFilter } from 'node-av';
16
+ *
17
+ * // Get a specific bitstream filter
18
+ * const h264Filter = BitStreamFilter.getByName('h264_mp4toannexb');
19
+ * if (h264Filter) {
20
+ * console.log(`Filter: ${h264Filter.name}`);
21
+ * console.log(`Supported codecs: ${h264Filter.codecIds}`);
22
+ * }
23
+ *
24
+ * // List all available bitstream filters
25
+ * const filters = BitStreamFilter.iterate();
26
+ * for (const filter of filters) {
27
+ * console.log(`- ${filter.name}`);
28
+ * }
29
+ * ```
30
+ *
31
+ * @see [AVBitStreamFilter](https://ffmpeg.org/doxygen/trunk/structAVBitStreamFilter.html) - FFmpeg Doxygen
32
+ */
33
+ export declare class BitStreamFilter implements NativeWrapper<NativeBitStreamFilter> {
34
+ private native;
35
+ /**
36
+ * @param native The native bitstream filter instance
37
+ *
38
+ * @internal
39
+ */
40
+ constructor(native: NativeBitStreamFilter);
41
+ /**
42
+ * Get a bitstream filter by name.
43
+ *
44
+ * Retrieves a specific bitstream filter descriptor by its name.
45
+ * Common filter names include 'h264_mp4toannexb', 'hevc_mp4toannexb',
46
+ * 'extract_extradata', 'vp9_superframe', etc.
47
+ *
48
+ * Direct mapping to av_bsf_get_by_name().
49
+ *
50
+ * @param name - Name of the bitstream filter
51
+ *
52
+ * @returns BitStreamFilter instance if found, null otherwise
53
+ *
54
+ * @example
55
+ * ```typescript
56
+ * // Get H.264 stream format converter
57
+ * const h264Filter = BitStreamFilter.getByName('h264_mp4toannexb');
58
+ * if (!h264Filter) {
59
+ * throw new Error('H.264 bitstream filter not available');
60
+ * }
61
+ *
62
+ * // Get HEVC metadata extractor
63
+ * const hevcFilter = BitStreamFilter.getByName('hevc_metadata');
64
+ * ```
65
+ *
66
+ * @see {@link iterate} To list all available filters
67
+ * @see {@link BitStreamFilterContext.alloc} To use the filter
68
+ */
69
+ static getByName(name: string): BitStreamFilter | null;
70
+ /**
71
+ * Iterate over all available bitstream filters.
72
+ *
73
+ * Returns an array of all registered bitstream filters in FFmpeg.
74
+ * Useful for discovering available filters or building filter lists.
75
+ *
76
+ * Direct mapping to av_bsf_iterate().
77
+ *
78
+ * @returns Array of all available bitstream filters
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * import { BitStreamFilter } from 'node-av';
83
+ * import { AV_CODEC_ID_H264 } from 'node-av/constants';
84
+ *
85
+ * // List all available filters
86
+ * const filters = BitStreamFilter.iterate();
87
+ * console.log(`Found ${filters.length} bitstream filters`);
88
+ *
89
+ * // Find filters that support H.264
90
+ * const h264Filters = filters.filter(f =>
91
+ * f.codecIds?.includes(AV_CODEC_ID_H264)
92
+ * );
93
+ * console.log('H.264 compatible filters:');
94
+ * for (const filter of h264Filters) {
95
+ * console.log(`- ${filter.name}`);
96
+ * }
97
+ * ```
98
+ *
99
+ * @see {@link getByName} To get a specific filter
100
+ */
101
+ static iterate(): BitStreamFilter[];
102
+ /**
103
+ * Name of the bitstream filter.
104
+ *
105
+ * Human-readable name identifying the filter (e.g., 'h264_mp4toannexb').
106
+ *
107
+ * Direct mapping to AVBitStreamFilter->name.
108
+ */
109
+ get name(): string | null;
110
+ /**
111
+ * List of supported codec IDs.
112
+ *
113
+ * Array of codec IDs that this filter can process.
114
+ * If null, the filter supports all codecs.
115
+ *
116
+ * Direct mapping to AVBitStreamFilter->codec_ids.
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * import { AV_CODEC_ID_H264, AV_CODEC_ID_HEVC } from 'node-av/constants';
121
+ *
122
+ * const filter = BitStreamFilter.getByName('extract_extradata');
123
+ * if (filter?.codecIds) {
124
+ * const supportsH264 = filter.codecIds.includes(AV_CODEC_ID_H264);
125
+ * const supportsHEVC = filter.codecIds.includes(AV_CODEC_ID_HEVC);
126
+ * console.log(`H.264 support: ${supportsH264}`);
127
+ * console.log(`HEVC support: ${supportsHEVC}`);
128
+ * }
129
+ * ```
130
+ */
131
+ get codecIds(): AVCodecID[] | null;
132
+ /**
133
+ * Get the underlying native BitStreamFilter object.
134
+ *
135
+ * @returns The native BitStreamFilter binding object
136
+ *
137
+ * @internal
138
+ */
139
+ getNative(): NativeBitStreamFilter;
140
+ }