node-av 0.0.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 (175) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +377 -0
  4. package/binding.gyp +78 -0
  5. package/dist/api/bitstream-filter.d.ts +246 -0
  6. package/dist/api/bitstream-filter.js +369 -0
  7. package/dist/api/bitstream-filter.js.map +1 -0
  8. package/dist/api/decoder.d.ts +257 -0
  9. package/dist/api/decoder.js +424 -0
  10. package/dist/api/decoder.js.map +1 -0
  11. package/dist/api/encoder.d.ts +298 -0
  12. package/dist/api/encoder.js +574 -0
  13. package/dist/api/encoder.js.map +1 -0
  14. package/dist/api/filter.d.ts +457 -0
  15. package/dist/api/filter.js +876 -0
  16. package/dist/api/filter.js.map +1 -0
  17. package/dist/api/hardware.d.ts +318 -0
  18. package/dist/api/hardware.js +558 -0
  19. package/dist/api/hardware.js.map +1 -0
  20. package/dist/api/index.d.ts +12 -0
  21. package/dist/api/index.js +20 -0
  22. package/dist/api/index.js.map +1 -0
  23. package/dist/api/io-stream.d.ts +109 -0
  24. package/dist/api/io-stream.js +124 -0
  25. package/dist/api/io-stream.js.map +1 -0
  26. package/dist/api/media-input.d.ts +295 -0
  27. package/dist/api/media-input.js +456 -0
  28. package/dist/api/media-input.js.map +1 -0
  29. package/dist/api/media-output.d.ts +274 -0
  30. package/dist/api/media-output.js +486 -0
  31. package/dist/api/media-output.js.map +1 -0
  32. package/dist/api/pipeline.d.ts +117 -0
  33. package/dist/api/pipeline.js +836 -0
  34. package/dist/api/pipeline.js.map +1 -0
  35. package/dist/api/types.d.ts +440 -0
  36. package/dist/api/types.js +2 -0
  37. package/dist/api/types.js.map +1 -0
  38. package/dist/api/utilities/audio-sample.d.ts +115 -0
  39. package/dist/api/utilities/audio-sample.js +110 -0
  40. package/dist/api/utilities/audio-sample.js.map +1 -0
  41. package/dist/api/utilities/channel-layout.d.ts +83 -0
  42. package/dist/api/utilities/channel-layout.js +87 -0
  43. package/dist/api/utilities/channel-layout.js.map +1 -0
  44. package/dist/api/utilities/image.d.ts +177 -0
  45. package/dist/api/utilities/image.js +183 -0
  46. package/dist/api/utilities/image.js.map +1 -0
  47. package/dist/api/utilities/index.d.ts +8 -0
  48. package/dist/api/utilities/index.js +17 -0
  49. package/dist/api/utilities/index.js.map +1 -0
  50. package/dist/api/utilities/media-type.d.ts +56 -0
  51. package/dist/api/utilities/media-type.js +60 -0
  52. package/dist/api/utilities/media-type.js.map +1 -0
  53. package/dist/api/utilities/pixel-format.d.ts +94 -0
  54. package/dist/api/utilities/pixel-format.js +102 -0
  55. package/dist/api/utilities/pixel-format.js.map +1 -0
  56. package/dist/api/utilities/sample-format.d.ts +132 -0
  57. package/dist/api/utilities/sample-format.js +144 -0
  58. package/dist/api/utilities/sample-format.js.map +1 -0
  59. package/dist/api/utilities/streaming.d.ts +104 -0
  60. package/dist/api/utilities/streaming.js +137 -0
  61. package/dist/api/utilities/streaming.js.map +1 -0
  62. package/dist/api/utilities/timestamp.d.ts +187 -0
  63. package/dist/api/utilities/timestamp.js +200 -0
  64. package/dist/api/utilities/timestamp.js.map +1 -0
  65. package/dist/api/utils.d.ts +61 -0
  66. package/dist/api/utils.js +330 -0
  67. package/dist/api/utils.js.map +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +5 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lib/audio-fifo.d.ts +339 -0
  72. package/dist/lib/audio-fifo.js +365 -0
  73. package/dist/lib/audio-fifo.js.map +1 -0
  74. package/dist/lib/binding.d.ts +192 -0
  75. package/dist/lib/binding.js +70 -0
  76. package/dist/lib/binding.js.map +1 -0
  77. package/dist/lib/bitstream-filter-context.d.ts +345 -0
  78. package/dist/lib/bitstream-filter-context.js +407 -0
  79. package/dist/lib/bitstream-filter-context.js.map +1 -0
  80. package/dist/lib/bitstream-filter.d.ts +124 -0
  81. package/dist/lib/bitstream-filter.js +138 -0
  82. package/dist/lib/bitstream-filter.js.map +1 -0
  83. package/dist/lib/channel-layouts.d.ts +51 -0
  84. package/dist/lib/channel-layouts.js +55 -0
  85. package/dist/lib/channel-layouts.js.map +1 -0
  86. package/dist/lib/codec-context.d.ts +763 -0
  87. package/dist/lib/codec-context.js +974 -0
  88. package/dist/lib/codec-context.js.map +1 -0
  89. package/dist/lib/codec-parameters.d.ts +362 -0
  90. package/dist/lib/codec-parameters.js +460 -0
  91. package/dist/lib/codec-parameters.js.map +1 -0
  92. package/dist/lib/codec-parser.d.ts +185 -0
  93. package/dist/lib/codec-parser.js +193 -0
  94. package/dist/lib/codec-parser.js.map +1 -0
  95. package/dist/lib/codec.d.ts +432 -0
  96. package/dist/lib/codec.js +492 -0
  97. package/dist/lib/codec.js.map +1 -0
  98. package/dist/lib/constants.d.ts +2037 -0
  99. package/dist/lib/constants.js +1659 -0
  100. package/dist/lib/constants.js.map +1 -0
  101. package/dist/lib/dictionary.d.ts +371 -0
  102. package/dist/lib/dictionary.js +406 -0
  103. package/dist/lib/dictionary.js.map +1 -0
  104. package/dist/lib/error.d.ts +216 -0
  105. package/dist/lib/error.js +254 -0
  106. package/dist/lib/error.js.map +1 -0
  107. package/dist/lib/filter-context.d.ts +445 -0
  108. package/dist/lib/filter-context.js +505 -0
  109. package/dist/lib/filter-context.js.map +1 -0
  110. package/dist/lib/filter-graph.d.ts +556 -0
  111. package/dist/lib/filter-graph.js +608 -0
  112. package/dist/lib/filter-graph.js.map +1 -0
  113. package/dist/lib/filter-inout.d.ts +205 -0
  114. package/dist/lib/filter-inout.js +264 -0
  115. package/dist/lib/filter-inout.js.map +1 -0
  116. package/dist/lib/filter.d.ts +231 -0
  117. package/dist/lib/filter.js +260 -0
  118. package/dist/lib/filter.js.map +1 -0
  119. package/dist/lib/format-context.d.ts +798 -0
  120. package/dist/lib/format-context.js +845 -0
  121. package/dist/lib/format-context.js.map +1 -0
  122. package/dist/lib/frame.d.ts +784 -0
  123. package/dist/lib/frame.js +933 -0
  124. package/dist/lib/frame.js.map +1 -0
  125. package/dist/lib/hardware-device-context.d.ts +407 -0
  126. package/dist/lib/hardware-device-context.js +429 -0
  127. package/dist/lib/hardware-device-context.js.map +1 -0
  128. package/dist/lib/hardware-frames-context.d.ts +374 -0
  129. package/dist/lib/hardware-frames-context.js +430 -0
  130. package/dist/lib/hardware-frames-context.js.map +1 -0
  131. package/dist/lib/index.d.ts +31 -0
  132. package/dist/lib/index.js +54 -0
  133. package/dist/lib/index.js.map +1 -0
  134. package/dist/lib/input-format.d.ts +216 -0
  135. package/dist/lib/input-format.js +246 -0
  136. package/dist/lib/input-format.js.map +1 -0
  137. package/dist/lib/io-context.d.ts +495 -0
  138. package/dist/lib/io-context.js +550 -0
  139. package/dist/lib/io-context.js.map +1 -0
  140. package/dist/lib/log.d.ts +201 -0
  141. package/dist/lib/log.js +219 -0
  142. package/dist/lib/log.js.map +1 -0
  143. package/dist/lib/native-types.d.ts +719 -0
  144. package/dist/lib/native-types.js +2 -0
  145. package/dist/lib/native-types.js.map +1 -0
  146. package/dist/lib/option.d.ts +589 -0
  147. package/dist/lib/option.js +853 -0
  148. package/dist/lib/option.js.map +1 -0
  149. package/dist/lib/output-format.d.ts +179 -0
  150. package/dist/lib/output-format.js +205 -0
  151. package/dist/lib/output-format.js.map +1 -0
  152. package/dist/lib/packet.d.ts +487 -0
  153. package/dist/lib/packet.js +558 -0
  154. package/dist/lib/packet.js.map +1 -0
  155. package/dist/lib/rational.d.ts +210 -0
  156. package/dist/lib/rational.js +233 -0
  157. package/dist/lib/rational.js.map +1 -0
  158. package/dist/lib/software-resample-context.d.ts +572 -0
  159. package/dist/lib/software-resample-context.js +610 -0
  160. package/dist/lib/software-resample-context.js.map +1 -0
  161. package/dist/lib/software-scale-context.d.ts +290 -0
  162. package/dist/lib/software-scale-context.js +308 -0
  163. package/dist/lib/software-scale-context.js.map +1 -0
  164. package/dist/lib/stream.d.ts +322 -0
  165. package/dist/lib/stream.js +408 -0
  166. package/dist/lib/stream.js.map +1 -0
  167. package/dist/lib/types.d.ts +59 -0
  168. package/dist/lib/types.js +8 -0
  169. package/dist/lib/types.js.map +1 -0
  170. package/dist/lib/utilities.d.ts +346 -0
  171. package/dist/lib/utilities.js +424 -0
  172. package/dist/lib/utilities.js.map +1 -0
  173. package/install/check.js +113 -0
  174. package/install/ffmpeg.js +163 -0
  175. package/package.json +107 -0
@@ -0,0 +1,608 @@
1
+ import { bindings } from './binding.js';
2
+ import { FilterContext } from './filter-context.js';
3
+ import { OptionMember } from './option.js';
4
+ /**
5
+ * Filter graph for media processing.
6
+ *
7
+ * Container for filters and their connections in a processing pipeline.
8
+ * Manages the entire filtering system from sources to sinks.
9
+ * Supports complex filter chains with multiple inputs and outputs.
10
+ *
11
+ * Direct mapping to FFmpeg's AVFilterGraph.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { FilterGraph, Filter, FilterContext, FFmpegError } from 'node-av';
16
+ *
17
+ * // Create and configure a simple filter graph
18
+ * const graph = new FilterGraph();
19
+ * graph.alloc();
20
+ *
21
+ * // Create buffer source
22
+ * const bufferFilter = Filter.getByName('buffer');
23
+ * if (!bufferFilter) throw new Error('Buffer filter not found');
24
+ * const bufferSrc = graph.createFilter(
25
+ * bufferFilter,
26
+ * 'in',
27
+ * 'video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25'
28
+ * );
29
+ * if (!bufferSrc) throw new Error('Failed to create buffer source');
30
+ *
31
+ * // Create scale filter
32
+ * const scaleFilter = Filter.getByName('scale');
33
+ * if (!scaleFilter) throw new Error('Scale filter not found');
34
+ * const scale = graph.createFilter(
35
+ * scaleFilter,
36
+ * 'scale',
37
+ * '1280:720'
38
+ * );
39
+ * if (!scale) throw new Error('Failed to create scale filter');
40
+ *
41
+ * // Create buffer sink
42
+ * const sinkFilter = Filter.getByName('buffersink');
43
+ * if (!sinkFilter) throw new Error('Buffersink filter not found');
44
+ * const bufferSink = graph.createFilter(
45
+ * sinkFilter,
46
+ * 'out'
47
+ * );
48
+ * if (!bufferSink) throw new Error('Failed to create buffer sink');
49
+ *
50
+ * // Link filters
51
+ * const linkRet1 = bufferSrc.link(0, scale, 0);
52
+ * FFmpegError.throwIfError(linkRet1, 'link buffer to scale');
53
+ *
54
+ * const linkRet2 = scale.link(0, bufferSink, 0);
55
+ * FFmpegError.throwIfError(linkRet2, 'link scale to sink');
56
+ *
57
+ * // Configure the graph
58
+ * const configRet = graph.config();
59
+ * FFmpegError.throwIfError(configRet, 'config');
60
+ *
61
+ * // Clean up
62
+ * graph.free();
63
+ * ```
64
+ */
65
+ export class FilterGraph extends OptionMember {
66
+ /**
67
+ * Create a new FilterGraph instance.
68
+ *
69
+ * The graph is uninitialized - you must call alloc() before use.
70
+ * No FFmpeg resources are allocated until alloc() is called.
71
+ *
72
+ * Direct wrapper around AVFilterGraph.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import { FilterGraph } from 'node-av';
77
+ *
78
+ * const graph = new FilterGraph();
79
+ * graph.alloc();
80
+ * // Graph is now ready for use
81
+ * ```
82
+ */
83
+ constructor() {
84
+ super(new bindings.FilterGraph());
85
+ }
86
+ /**
87
+ * Number of filters in the graph.
88
+ *
89
+ * Direct mapping to AVFilterGraph->nb_filters
90
+ *
91
+ * The total count of filters currently in the graph.
92
+ */
93
+ get nbFilters() {
94
+ return this.native.nbFilters;
95
+ }
96
+ /**
97
+ * Array of all filters in the graph.
98
+ *
99
+ * Direct mapping to AVFilterGraph->filters
100
+ *
101
+ * All filter contexts currently in the graph.
102
+ */
103
+ get filters() {
104
+ const natives = this.native.filters;
105
+ if (!natives)
106
+ return null;
107
+ return natives.map((native) => new FilterContext(native));
108
+ }
109
+ /**
110
+ * Thread type for graph processing.
111
+ *
112
+ * Direct mapping to AVFilterGraph->thread_type
113
+ *
114
+ * Controls threading behavior of the graph (0 = disabled, AVFILTER_THREAD_SLICE = slice threading).
115
+ */
116
+ get threadType() {
117
+ return this.native.threadType;
118
+ }
119
+ set threadType(value) {
120
+ this.native.threadType = value;
121
+ }
122
+ /**
123
+ * Number of threads for graph processing.
124
+ *
125
+ * Direct mapping to AVFilterGraph->nb_threads
126
+ *
127
+ * 0 means automatic detection based on CPU cores.
128
+ */
129
+ get nbThreads() {
130
+ return this.native.nbThreads;
131
+ }
132
+ set nbThreads(value) {
133
+ this.native.nbThreads = value;
134
+ }
135
+ /**
136
+ * Software scaler options.
137
+ *
138
+ * Direct mapping to AVFilterGraph->scale_sws_opts
139
+ *
140
+ * Options string passed to the software scaler (e.g., "flags=bicubic").
141
+ */
142
+ get scaleSwsOpts() {
143
+ return this.native.scaleSwsOpts;
144
+ }
145
+ set scaleSwsOpts(value) {
146
+ this.native.scaleSwsOpts = value;
147
+ }
148
+ /**
149
+ * Allocate the filter graph.
150
+ *
151
+ * Allocates the graph structure and initializes it.
152
+ * Must be called before adding filters to the graph.
153
+ *
154
+ * Direct mapping to avfilter_graph_alloc()
155
+ *
156
+ * @throws {Error} Memory allocation failure (ENOMEM)
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * import { FilterGraph } from 'node-av';
161
+ *
162
+ * const graph = new FilterGraph();
163
+ * graph.alloc();
164
+ * // Graph is now allocated and ready
165
+ * ```
166
+ *
167
+ * @see {@link free} To free the graph
168
+ */
169
+ alloc() {
170
+ this.native.alloc();
171
+ }
172
+ /**
173
+ * Free the filter graph.
174
+ *
175
+ * Releases all resources associated with the graph.
176
+ * All filters in the graph are also freed.
177
+ *
178
+ * Direct mapping to avfilter_graph_free()
179
+ *
180
+ * @example
181
+ * ```typescript
182
+ * graph.free();
183
+ * // graph is now invalid and should not be used
184
+ * ```
185
+ */
186
+ free() {
187
+ this.native.free();
188
+ }
189
+ /**
190
+ * Create a filter instance in the graph.
191
+ *
192
+ * Direct mapping to avfilter_graph_create_filter()
193
+ *
194
+ * @param filter - The filter definition
195
+ * @param name - Name for this filter instance (must be unique in the graph)
196
+ * @param args - Optional initialization arguments (filter-specific format)
197
+ *
198
+ * @returns The created filter context or null on failure
199
+ *
200
+ * @example
201
+ * ```typescript
202
+ * // Create a scale filter
203
+ * const scaleFilter = Filter.getByName('scale');
204
+ * const scaleCtx = graph.createFilter(
205
+ * scaleFilter!,
206
+ * 'my_scale',
207
+ * '1280:720' // width:height
208
+ * );
209
+ *
210
+ * // Create a buffer source for video
211
+ * const bufferFilter = Filter.getByName('buffer');
212
+ * const bufferCtx = graph.createFilter(
213
+ * bufferFilter!,
214
+ * 'video_in',
215
+ * 'video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25:pixel_aspect=1/1'
216
+ * );
217
+ * ```
218
+ */
219
+ createFilter(filter, name, args = null) {
220
+ const native = this.native.createFilter(filter.getNative(), name, args ?? null);
221
+ return native ? new FilterContext(native) : null;
222
+ }
223
+ /**
224
+ * Allocate a filter instance in the graph without initializing it.
225
+ *
226
+ * Direct mapping to avfilter_graph_alloc_filter()
227
+ *
228
+ * This method allocates the filter but does not initialize it.
229
+ * You must call filter.init() or filter.initStr() afterwards.
230
+ *
231
+ * @param filter - The filter definition
232
+ * @param name - Name for this filter instance (must be unique in the graph)
233
+ *
234
+ * @returns The allocated filter context or null on failure
235
+ *
236
+ * @example
237
+ * ```typescript
238
+ * import { FilterGraph, Filter, FFmpegError } from 'node-av';
239
+ *
240
+ * // Allocate a filter without initializing
241
+ * const scaleFilter = Filter.getByName('scale');
242
+ * if (!scaleFilter) throw new Error('Scale filter not found');
243
+ * const scaleCtx = graph.allocFilter(scaleFilter, 'my_scale');
244
+ * if (!scaleCtx) throw new Error('Failed to allocate filter');
245
+ *
246
+ * // Set options using setOpt
247
+ * const ret1 = scaleCtx.setOpt('width', '1280');
248
+ * FFmpegError.throwIfError(ret1, 'setOpt width');
249
+ * const ret2 = scaleCtx.setOpt('height', '720');
250
+ * FFmpegError.throwIfError(ret2, 'setOpt height');
251
+ *
252
+ * // Initialize the filter
253
+ * const initRet = scaleCtx.init();
254
+ * FFmpegError.throwIfError(initRet, 'init');
255
+ * ```
256
+ *
257
+ * @note This provides an alternative workflow to createFilter,
258
+ * allowing options to be set before initialization.
259
+ */
260
+ allocFilter(filter, name) {
261
+ const native = this.native.allocFilter(filter.getNative(), name);
262
+ return native ? new FilterContext(native) : null;
263
+ }
264
+ /**
265
+ * Get a filter by name from the graph.
266
+ *
267
+ * Direct mapping to avfilter_graph_get_filter()
268
+ *
269
+ * @param name - The filter instance name
270
+ *
271
+ * @returns The filter context or null if not found
272
+ *
273
+ * @example
274
+ * ```typescript
275
+ * const scaleCtx = graph.getFilter('my_scale');
276
+ * if (scaleCtx) {
277
+ * console.log('Found scale filter');
278
+ * }
279
+ * ```
280
+ */
281
+ getFilter(name) {
282
+ const native = this.native.getFilter(name);
283
+ return native ? new FilterContext(native) : null;
284
+ }
285
+ /**
286
+ * Configure the filter graph.
287
+ *
288
+ * Direct mapping to avfilter_graph_config()
289
+ *
290
+ * @returns 0 on success, negative AVERROR on error:
291
+ * - 0: Success
292
+ * - AVERROR(EINVAL): Invalid graph configuration
293
+ * - AVERROR(ENOMEM): Memory allocation failure
294
+ * - <0: Other configuration errors
295
+ *
296
+ * @example
297
+ * ```typescript
298
+ * import { FilterGraph, FFmpegError } from 'node-av';
299
+ *
300
+ * // After creating and linking all filters
301
+ * const ret = graph.config();
302
+ * FFmpegError.throwIfError(ret, 'config');
303
+ * // Graph is now ready for processing
304
+ * ```
305
+ *
306
+ * @note Must be called after all filters are added and connected.
307
+ */
308
+ async config() {
309
+ return this.native.config();
310
+ }
311
+ /**
312
+ * Parse a filtergraph description.
313
+ *
314
+ * Direct mapping to avfilter_graph_parse()
315
+ *
316
+ * @param filters - Filtergraph description string
317
+ * @param inputs - Input pad list
318
+ * @param outputs - Output pad list
319
+ *
320
+ * @returns 0 on success, negative AVERROR on error:
321
+ * - 0: Success
322
+ * - AVERROR(EINVAL): Invalid filtergraph syntax
323
+ * - AVERROR(ENOMEM): Memory allocation failure
324
+ * - <0: Other parsing errors
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * import { FilterGraph, FilterInOut, FFmpegError } from 'node-av';
329
+ *
330
+ * const inputs = new FilterInOut();
331
+ * inputs.alloc();
332
+ * inputs.name = 'in';
333
+ * inputs.filterCtx = bufferSrcCtx;
334
+ * inputs.padIdx = 0;
335
+ *
336
+ * const outputs = new FilterInOut();
337
+ * outputs.alloc();
338
+ * outputs.name = 'out';
339
+ * outputs.filterCtx = bufferSinkCtx;
340
+ * outputs.padIdx = 0;
341
+ *
342
+ * const ret = graph.parse('[in] scale=1280:720 [out]', inputs, outputs);
343
+ * FFmpegError.throwIfError(ret, 'parse');
344
+ * ```
345
+ */
346
+ parse(filters, inputs, outputs) {
347
+ return this.native.parse(filters, inputs ? inputs.getNative() : null, outputs ? outputs.getNative() : null);
348
+ }
349
+ /**
350
+ * Parse a filtergraph description (simplified).
351
+ *
352
+ * Direct mapping to avfilter_graph_parse2()
353
+ *
354
+ * @param filters - Filtergraph description string
355
+ *
356
+ * @returns 0 on success, negative AVERROR on error:
357
+ * - 0: Success
358
+ * - AVERROR(EINVAL): Invalid filtergraph syntax
359
+ * - AVERROR(ENOMEM): Memory allocation failure
360
+ * - <0: Other parsing errors
361
+ *
362
+ * @example
363
+ * ```typescript
364
+ * import { FilterGraph, FFmpegError } from 'node-av';
365
+ *
366
+ * // Parse a simple filter chain
367
+ * const ret = graph.parse2('scale=1280:720,format=yuv420p');
368
+ * FFmpegError.throwIfError(ret, 'parse2');
369
+ * ```
370
+ *
371
+ * @note Automatically handles inputs and outputs.
372
+ */
373
+ parse2(filters) {
374
+ return this.native.parse2(filters);
375
+ }
376
+ /**
377
+ * Parse a filtergraph description (pointer version).
378
+ *
379
+ * Direct mapping to avfilter_graph_parse_ptr()
380
+ *
381
+ * @param filters - Filtergraph description string
382
+ * @param inputs - Optional input pad list (FilterInOut)
383
+ * @param outputs - Optional output pad list (FilterInOut)
384
+ *
385
+ * @returns 0 on success, negative AVERROR on error:
386
+ * - 0: Success
387
+ * - AVERROR(EINVAL): Invalid filtergraph syntax
388
+ * - AVERROR(ENOMEM): Memory allocation failure
389
+ * - <0: Other parsing errors
390
+ *
391
+ * @example
392
+ * ```typescript
393
+ * import { FilterGraph, FFmpegError } from 'node-av';
394
+ *
395
+ * // Parse a complex filter graph
396
+ * const ret = graph.parsePtr(
397
+ * '[0:v] scale=1280:720 [scaled]; [scaled] split [out1][out2]'
398
+ * );
399
+ * FFmpegError.throwIfError(ret, 'parsePtr');
400
+ * ```
401
+ *
402
+ * @example
403
+ * ```typescript
404
+ * import { FilterGraph, FilterInOut, FFmpegError } from 'node-av';
405
+ *
406
+ * // Parse with explicit inputs/outputs
407
+ * const inputs = new FilterInOut();
408
+ * inputs.name = 'in';
409
+ * inputs.filterCtx = buffersrcCtx;
410
+ * inputs.padIdx = 0;
411
+ *
412
+ * const outputs = new FilterInOut();
413
+ * outputs.name = 'out';
414
+ * outputs.filterCtx = buffersinkCtx;
415
+ * outputs.padIdx = 0;
416
+ *
417
+ * const ret = graph.parsePtr(filtersDescr, inputs, outputs);
418
+ * FFmpegError.throwIfError(ret, 'parsePtr');
419
+ * ```
420
+ *
421
+ * @note Similar to parse2 but with different internal handling.
422
+ */
423
+ parsePtr(filters, inputs, outputs) {
424
+ return this.native.parsePtr(filters, inputs ? inputs.getNative() : null, outputs ? outputs.getNative() : null);
425
+ }
426
+ /**
427
+ * Validate the filter graph.
428
+ *
429
+ * Direct mapping to avfilter_graph_validate()
430
+ *
431
+ * @returns 0 on success, negative AVERROR on error:
432
+ * - 0: Valid graph structure
433
+ * - AVERROR(EINVAL): Invalid graph structure
434
+ * - <0: Other validation errors
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * // Validate before configuring
439
+ * const ret = graph.validate();
440
+ * if (ret < 0) {
441
+ * console.error('Graph validation failed');
442
+ * }
443
+ * ```
444
+ *
445
+ * @note Checks that the graph structure is valid without configuring it.
446
+ */
447
+ validate() {
448
+ return this.native.validate();
449
+ }
450
+ /**
451
+ * Request a frame from the oldest sink.
452
+ *
453
+ * Direct mapping to avfilter_graph_request_oldest()
454
+ *
455
+ * @returns 0 on success, negative AVERROR on error:
456
+ * - 0: Success
457
+ * - AVERROR_EOF: No more frames available
458
+ * - AVERROR(EAGAIN): Need more input data
459
+ * - <0: Other processing errors
460
+ *
461
+ * @example
462
+ * ```typescript
463
+ * import { FilterGraph, FFmpegError } from 'node-av';
464
+ * import { AVERROR_EOF, AVERROR_EAGAIN } from 'node-av/constants';
465
+ *
466
+ * // Pull frames from the graph
467
+ * while (true) {
468
+ * const ret = await graph.requestOldest();
469
+ * if (FFmpegError.is(ret, AVERROR_EOF)) {
470
+ * break; // No more frames
471
+ * }
472
+ * if (ret < 0 && !FFmpegError.is(ret, AVERROR_EAGAIN)) {
473
+ * FFmpegError.throwIfError(ret, 'requestOldest');
474
+ * }
475
+ * // Process output from sinks
476
+ * }
477
+ * ```
478
+ *
479
+ * @note Triggers processing in the graph to produce output.
480
+ */
481
+ async requestOldest() {
482
+ return this.native.requestOldest();
483
+ }
484
+ /**
485
+ * Get the graph structure as a string.
486
+ *
487
+ * Returns a string representation of the filter graph in DOT format.
488
+ * Uses avfilter_graph_dump() internally.
489
+ *
490
+ * @returns String representation of the filter graph or null if not allocated
491
+ *
492
+ * @example
493
+ * ```typescript
494
+ * const graphDescription = graph.dump();
495
+ * console.log('Filter graph:', graphDescription);
496
+ * ```
497
+ */
498
+ dump() {
499
+ return this.native.dump();
500
+ }
501
+ /**
502
+ * Send a command to one or more filters in the graph.
503
+ *
504
+ * Direct mapping to avfilter_graph_send_command()
505
+ *
506
+ * @param target - Filter name or "all" to send to all filters
507
+ * @param cmd - Command name (e.g., "volume", "hue", "rate")
508
+ * @param arg - Command argument (e.g., "0.5", "2.0")
509
+ * @param flags - Command flags (AVFilterCmdFlag, default: 0)
510
+ * - AVFILTER_CMD_FLAG_ONE: Stop once a filter understood the command
511
+ * - AVFILTER_CMD_FLAG_FAST: Only execute if fast (hardware acceleration)
512
+ *
513
+ * @returns Error code (negative) or response object { response: string | null }
514
+ *
515
+ * @example
516
+ * ```typescript
517
+ * import { FilterGraph, FFmpegError, AVFILTER_CMD_FLAG_ONE } from 'node-av';
518
+ *
519
+ * // Send volume change command to audio filter
520
+ * const result = graph.sendCommand('volume', 'volume', '0.5');
521
+ * if (typeof result === 'number') {
522
+ * console.error('Command failed:', FFmpegError.strerror(result));
523
+ * } else {
524
+ * console.log('Response:', result.response);
525
+ * }
526
+ * ```
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * // Send command to all filters, stop at first one that handles it
531
+ * const result = graph.sendCommand('all', 'enable', 'expr=gte(t,10)', AVFILTER_CMD_FLAG_ONE);
532
+ *
533
+ * // Send command to specific filter
534
+ * const result = graph.sendCommand('scale', 'width', '1920');
535
+ * ```
536
+ *
537
+ * @note Not all filters support commands. Check filter documentation.
538
+ */
539
+ sendCommand(target, cmd, arg, flags) {
540
+ return this.native.sendCommand(target, cmd, arg, flags);
541
+ }
542
+ /**
543
+ * Queue a command to be executed at a specific time.
544
+ *
545
+ * Direct mapping to avfilter_graph_queue_command()
546
+ *
547
+ * @param target - Filter name or "all" to send to all filters
548
+ * @param cmd - Command name (e.g., "volume", "hue", "rate")
549
+ * @param arg - Command argument (e.g., "0.5", "2.0")
550
+ * @param ts - Timestamp when the command should be executed
551
+ * @param flags - Command flags (AVFilterCmdFlag, default: 0)
552
+ * - AVFILTER_CMD_FLAG_ONE: Stop once a filter understood the command
553
+ * - AVFILTER_CMD_FLAG_FAST: Only execute if fast (hardware acceleration)
554
+ *
555
+ * @returns 0 on success, negative AVERROR on error
556
+ *
557
+ * @example
558
+ * ```typescript
559
+ * import { FilterGraph, FFmpegError, AVFILTER_CMD_FLAG_ONE } from 'node-av';
560
+ *
561
+ * // Queue volume change at 10 seconds
562
+ * const ret = graph.queueCommand('volume', 'volume', '0.2', 10.0);
563
+ * FFmpegError.throwIfError(ret, 'queueCommand');
564
+ * ```
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * // Queue multiple commands at different times
569
+ * graph.queueCommand('volume', 'volume', '0.5', 5.0);
570
+ * graph.queueCommand('volume', 'volume', '1.0', 10.0);
571
+ * graph.queueCommand('volume', 'volume', '0.2', 15.0);
572
+ * ```
573
+ *
574
+ * @note Commands are executed when processing frames with matching timestamps.
575
+ * @note Not all filters support queued commands.
576
+ */
577
+ queueCommand(target, cmd, arg, ts, flags) {
578
+ return this.native.queueCommand(target, cmd, arg, ts, flags);
579
+ }
580
+ /**
581
+ * Get the native FFmpeg AVFilterGraph pointer.
582
+ *
583
+ * @internal For use by other wrapper classes
584
+ * @returns The underlying native filter graph object
585
+ */
586
+ getNative() {
587
+ return this.native;
588
+ }
589
+ /**
590
+ * Dispose of the filter graph.
591
+ *
592
+ * Implements the Disposable interface for automatic cleanup.
593
+ * Equivalent to calling free().
594
+ *
595
+ * @example
596
+ * ```typescript
597
+ * {
598
+ * using graph = new FilterGraph();
599
+ * graph.alloc();
600
+ * // ... use graph
601
+ * } // Automatically freed when leaving scope
602
+ * ```
603
+ */
604
+ [Symbol.dispose]() {
605
+ this.native[Symbol.dispose]();
606
+ }
607
+ }
608
+ //# sourceMappingURL=filter-graph.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"filter-graph.js","sourceRoot":"","sources":["../../src/lib/filter-graph.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAC;AACpD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAO3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4DG;AACH,MAAM,OAAO,WAAY,SAAQ,YAA+B;IAC9D;;;;;;;;;;;;;;;;OAgBG;IACH;QACE,KAAK,CAAC,IAAI,QAAQ,CAAC,WAAW,EAAE,CAAC,CAAC;IACpC,CAAC;IAED;;;;;;OAMG;IACH,IAAI,SAAS;QACX,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC;IAC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