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
@@ -2,103 +2,79 @@ import { bindings } from './binding.js';
2
2
  import { FilterContext } from './filter-context.js';
3
3
  import { OptionMember } from './option.js';
4
4
  /**
5
- * Filter graph for media processing.
5
+ * Filter graph for audio/video processing pipelines.
6
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.
7
+ * Manages a collection of interconnected filters forming a processing pipeline.
8
+ * Filters are connected through their input/output pads to create complex
9
+ * audio/video transformations. Supports both simple linear chains and complex
10
+ * graphs with multiple inputs/outputs. Essential for effects, format conversions,
11
+ * scaling, and other media processing operations.
10
12
  *
11
13
  * Direct mapping to FFmpeg's AVFilterGraph.
12
14
  *
13
15
  * @example
14
16
  * ```typescript
15
- * import { FilterGraph, Filter, FilterContext, FFmpegError } from 'node-av';
17
+ * import { FilterGraph, Filter, FilterInOut, FFmpegError } from 'node-av';
16
18
  *
17
- * // Create and configure a simple filter graph
19
+ * // Create and configure filter graph
18
20
  * const graph = new FilterGraph();
19
21
  * graph.alloc();
20
22
  *
21
- * // Create buffer source
22
- * const bufferFilter = Filter.getByName('buffer');
23
- * if (!bufferFilter) throw new Error('Buffer filter not found');
23
+ * // Create filters
24
24
  * const bufferSrc = graph.createFilter(
25
- * bufferFilter,
26
- * 'in',
27
- * 'video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25'
25
+ * Filter.getByName('buffer')!,
26
+ * 'src',
27
+ * 'video_size=1920x1080:pix_fmt=yuv420p'
28
28
  * );
29
- * if (!bufferSrc) throw new Error('Failed to create buffer source');
30
29
  *
31
- * // Create scale filter
32
- * const scaleFilter = Filter.getByName('scale');
33
- * if (!scaleFilter) throw new Error('Scale filter not found');
34
30
  * const scale = graph.createFilter(
35
- * scaleFilter,
31
+ * Filter.getByName('scale')!,
36
32
  * 'scale',
37
- * '1280:720'
33
+ * '640:480'
38
34
  * );
39
- * if (!scale) throw new Error('Failed to create scale filter');
40
35
  *
41
- * // Create buffer sink
42
- * const sinkFilter = Filter.getByName('buffersink');
43
- * if (!sinkFilter) throw new Error('Buffersink filter not found');
44
36
  * const bufferSink = graph.createFilter(
45
- * sinkFilter,
46
- * 'out'
37
+ * Filter.getByName('buffersink')!,
38
+ * 'sink'
47
39
  * );
48
- * if (!bufferSink) throw new Error('Failed to create buffer sink');
49
40
  *
50
41
  * // Link filters
51
- * const linkRet1 = bufferSrc.link(0, scale, 0);
52
- * FFmpegError.throwIfError(linkRet1, 'link buffer to scale');
42
+ * bufferSrc.link(0, scale, 0);
43
+ * scale.link(0, bufferSink, 0);
53
44
  *
54
- * const linkRet2 = scale.link(0, bufferSink, 0);
55
- * FFmpegError.throwIfError(linkRet2, 'link scale to sink');
45
+ * // Configure graph
46
+ * const ret = await graph.config();
47
+ * FFmpegError.throwIfError(ret, 'config');
56
48
  *
57
- * // Configure the graph
58
- * const configRet = graph.config();
59
- * FFmpegError.throwIfError(configRet, 'config');
60
- *
61
- * // Clean up
62
- * graph.free();
49
+ * // Parse filter string
50
+ * const ret2 = graph.parse2('[in]scale=640:480[out]');
51
+ * FFmpegError.throwIfError(ret2, 'parse2');
63
52
  * ```
53
+ *
54
+ * @see [AVFilterGraph](https://ffmpeg.org/doxygen/trunk/structAVFilterGraph.html) - FFmpeg Doxygen
55
+ * @see {@link FilterContext} For filter instances
56
+ * @see {@link Filter} For filter descriptors
64
57
  */
65
58
  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
59
  constructor() {
84
60
  super(new bindings.FilterGraph());
85
61
  }
86
62
  /**
87
63
  * Number of filters in the graph.
88
64
  *
89
- * Direct mapping to AVFilterGraph->nb_filters
65
+ * Total count of filter contexts in this graph.
90
66
  *
91
- * The total count of filters currently in the graph.
67
+ * Direct mapping to AVFilterGraph->nb_filters.
92
68
  */
93
69
  get nbFilters() {
94
70
  return this.native.nbFilters;
95
71
  }
96
72
  /**
97
- * Array of all filters in the graph.
98
- *
99
- * Direct mapping to AVFilterGraph->filters
73
+ * Array of filters in the graph.
100
74
  *
101
75
  * All filter contexts currently in the graph.
76
+ *
77
+ * Direct mapping to AVFilterGraph->filters.
102
78
  */
103
79
  get filters() {
104
80
  const natives = this.native.filters;
@@ -107,11 +83,12 @@ export class FilterGraph extends OptionMember {
107
83
  return natives.map((native) => new FilterContext(native));
108
84
  }
109
85
  /**
110
- * Thread type for graph processing.
86
+ * Threading type for graph execution.
111
87
  *
112
- * Direct mapping to AVFilterGraph->thread_type
88
+ * Controls how filters are executed in parallel.
89
+ * Use AVFILTER_THREAD_SLICE for slice-based threading.
113
90
  *
114
- * Controls threading behavior of the graph (0 = disabled, AVFILTER_THREAD_SLICE = slice threading).
91
+ * Direct mapping to AVFilterGraph->thread_type.
115
92
  */
116
93
  get threadType() {
117
94
  return this.native.threadType;
@@ -120,11 +97,12 @@ export class FilterGraph extends OptionMember {
120
97
  this.native.threadType = value;
121
98
  }
122
99
  /**
123
- * Number of threads for graph processing.
100
+ * Number of threads for parallel processing.
124
101
  *
125
- * Direct mapping to AVFilterGraph->nb_threads
102
+ * Number of threads used for filter execution.
103
+ * 0 means automatic detection.
126
104
  *
127
- * 0 means automatic detection based on CPU cores.
105
+ * Direct mapping to AVFilterGraph->nb_threads.
128
106
  */
129
107
  get nbThreads() {
130
108
  return this.native.nbThreads;
@@ -133,11 +111,11 @@ export class FilterGraph extends OptionMember {
133
111
  this.native.nbThreads = value;
134
112
  }
135
113
  /**
136
- * Software scaler options.
114
+ * Swscale options for scale filter.
137
115
  *
138
- * Direct mapping to AVFilterGraph->scale_sws_opts
116
+ * Options string passed to swscale for scaling operations.
139
117
  *
140
- * Options string passed to the software scaler (e.g., "flags=bicubic").
118
+ * Direct mapping to AVFilterGraph->scale_sws_opts.
141
119
  */
142
120
  get scaleSwsOpts() {
143
121
  return this.native.scaleSwsOpts;
@@ -146,25 +124,24 @@ export class FilterGraph extends OptionMember {
146
124
  this.native.scaleSwsOpts = value;
147
125
  }
148
126
  /**
149
- * Allocate the filter graph.
127
+ * Allocate a filter graph.
150
128
  *
151
- * Allocates the graph structure and initializes it.
152
- * Must be called before adding filters to the graph.
129
+ * Allocates memory for the filter graph structure.
130
+ * Must be called before using the graph.
153
131
  *
154
- * Direct mapping to avfilter_graph_alloc()
132
+ * Direct mapping to avfilter_graph_alloc().
155
133
  *
156
- * @throws {Error} Memory allocation failure (ENOMEM)
134
+ * @throws {Error} If allocation fails (ENOMEM)
157
135
  *
158
136
  * @example
159
137
  * ```typescript
160
- * import { FilterGraph } from 'node-av';
161
- *
162
138
  * const graph = new FilterGraph();
163
139
  * graph.alloc();
164
- * // Graph is now allocated and ready
140
+ * // Graph is now ready for filter creation
165
141
  * ```
166
142
  *
167
- * @see {@link free} To free the graph
143
+ * @see {@link free} To deallocate
144
+ * @see {@link config} To configure after building
168
145
  */
169
146
  alloc() {
170
147
  this.native.alloc();
@@ -172,90 +149,88 @@ export class FilterGraph extends OptionMember {
172
149
  /**
173
150
  * Free the filter graph.
174
151
  *
175
- * Releases all resources associated with the graph.
176
- * All filters in the graph are also freed.
152
+ * Releases all resources associated with the graph,
153
+ * including all contained filters.
177
154
  *
178
- * Direct mapping to avfilter_graph_free()
155
+ * Direct mapping to avfilter_graph_free().
179
156
  *
180
157
  * @example
181
158
  * ```typescript
182
159
  * graph.free();
183
- * // graph is now invalid and should not be used
160
+ * // Graph is now invalid
184
161
  * ```
162
+ *
163
+ * @see {@link alloc} To allocate
164
+ * @see {@link Symbol.dispose} For automatic cleanup
185
165
  */
186
166
  free() {
187
167
  this.native.free();
188
168
  }
189
169
  /**
190
- * Create a filter instance in the graph.
170
+ * Create and initialize a filter in the graph.
191
171
  *
192
- * Direct mapping to avfilter_graph_create_filter()
172
+ * Creates a new filter context, adds it to the graph,
173
+ * and initializes it with the provided arguments.
193
174
  *
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)
175
+ * Direct mapping to avfilter_graph_create_filter().
197
176
  *
198
- * @returns The created filter context or null on failure
177
+ * @param filter - Filter descriptor to instantiate
178
+ * @param name - Name for this filter instance
179
+ * @param args - Initialization arguments (filter-specific)
180
+ * @returns Created filter context, or null on failure
199
181
  *
200
182
  * @example
201
183
  * ```typescript
202
184
  * // 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
185
+ * const scale = graph.createFilter(
186
+ * Filter.getByName('scale')!,
187
+ * 'scaler',
188
+ * '640:480' // width:height
208
189
  * );
209
190
  *
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'
191
+ * // Create a buffer source
192
+ * const src = graph.createFilter(
193
+ * Filter.getByName('buffer')!,
194
+ * 'source',
195
+ * 'video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25'
216
196
  * );
217
197
  * ```
198
+ *
199
+ * @see {@link allocFilter} To allocate without initializing
200
+ * @see {@link getFilter} To retrieve by name
218
201
  */
219
202
  createFilter(filter, name, args = null) {
220
203
  const native = this.native.createFilter(filter.getNative(), name, args ?? null);
221
204
  return native ? new FilterContext(native) : null;
222
205
  }
223
206
  /**
224
- * Allocate a filter instance in the graph without initializing it.
207
+ * Allocate a filter in the graph.
225
208
  *
226
- * Direct mapping to avfilter_graph_alloc_filter()
209
+ * Creates a new filter context and adds it to the graph,
210
+ * but does not initialize it. Call init() on the context afterwards.
227
211
  *
228
- * This method allocates the filter but does not initialize it.
229
- * You must call filter.init() or filter.initStr() afterwards.
212
+ * Direct mapping to avfilter_graph_alloc_filter().
230
213
  *
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
214
+ * @param filter - Filter descriptor to instantiate
215
+ * @param name - Name for this filter instance
216
+ * @returns Allocated filter context, or null on failure
235
217
  *
236
218
  * @example
237
219
  * ```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');
220
+ * import { FFmpegError } from 'node-av';
221
+ *
222
+ * const filter = graph.allocFilter(
223
+ * Filter.getByName('scale')!,
224
+ * 'scaler'
225
+ * );
226
+ * if (filter) {
227
+ * // Initialize separately
228
+ * const ret = filter.initStr('640:480');
229
+ * FFmpegError.throwIfError(ret, 'initStr');
230
+ * }
255
231
  * ```
256
232
  *
257
- * @note This provides an alternative workflow to createFilter,
258
- * allowing options to be set before initialization.
233
+ * @see {@link createFilter} To allocate and initialize
259
234
  */
260
235
  allocFilter(filter, name) {
261
236
  const native = this.native.allocFilter(filter.getNative(), name);
@@ -264,19 +239,23 @@ export class FilterGraph extends OptionMember {
264
239
  /**
265
240
  * Get a filter by name from the graph.
266
241
  *
267
- * Direct mapping to avfilter_graph_get_filter()
242
+ * Retrieves an existing filter context by its instance name.
268
243
  *
269
- * @param name - The filter instance name
244
+ * Direct mapping to avfilter_graph_get_filter().
270
245
  *
271
- * @returns The filter context or null if not found
246
+ * @param name - Name of the filter instance
247
+ * @returns Filter context if found, null otherwise
272
248
  *
273
249
  * @example
274
250
  * ```typescript
275
- * const scaleCtx = graph.getFilter('my_scale');
276
- * if (scaleCtx) {
277
- * console.log('Found scale filter');
251
+ * // Find a previously created filter
252
+ * const scaler = graph.getFilter('scaler');
253
+ * if (scaler) {
254
+ * console.log('Found scaler filter');
278
255
  * }
279
256
  * ```
257
+ *
258
+ * @see {@link createFilter} To create new filters
280
259
  */
281
260
  getFilter(name) {
282
261
  const native = this.native.getFilter(name);
@@ -285,164 +264,150 @@ export class FilterGraph extends OptionMember {
285
264
  /**
286
265
  * Configure the filter graph.
287
266
  *
288
- * Direct mapping to avfilter_graph_config()
267
+ * Validates and finalizes the graph configuration.
268
+ * Must be called after all filters are created and linked.
269
+ *
270
+ * Direct mapping to avfilter_graph_config().
289
271
  *
290
272
  * @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
273
+ * - AVERROR_EINVAL: Invalid graph configuration
274
+ * - AVERROR_ENOMEM: Memory allocation failure
295
275
  *
296
276
  * @example
297
277
  * ```typescript
298
- * import { FilterGraph, FFmpegError } from 'node-av';
278
+ * import { FFmpegError } from 'node-av';
299
279
  *
300
- * // After creating and linking all filters
301
- * const ret = graph.config();
280
+ * // Build graph...
281
+ * // Link filters...
282
+ *
283
+ * // Configure the complete graph
284
+ * const ret = await graph.config();
302
285
  * FFmpegError.throwIfError(ret, 'config');
303
286
  * // Graph is now ready for processing
304
287
  * ```
305
288
  *
306
- * @note Must be called after all filters are added and connected.
289
+ * @see {@link validate} To check configuration
307
290
  */
308
291
  async config() {
309
- return this.native.config();
292
+ return await this.native.config();
310
293
  }
311
294
  /**
312
- * Parse a filtergraph description.
295
+ * Parse a filter graph description.
313
296
  *
314
- * Direct mapping to avfilter_graph_parse()
297
+ * Parses a textual representation of a filter graph and adds
298
+ * filters to this graph. Handles labeled inputs and outputs.
315
299
  *
316
- * @param filters - Filtergraph description string
317
- * @param inputs - Input pad list
318
- * @param outputs - Output pad list
300
+ * Direct mapping to avfilter_graph_parse().
319
301
  *
302
+ * @param filters - Filter graph description string
303
+ * @param inputs - Linked list of graph inputs
304
+ * @param outputs - Linked list of graph outputs
320
305
  * @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
306
+ * - AVERROR_EINVAL: Parse error
307
+ * - AVERROR_ENOMEM: Memory allocation failure
325
308
  *
326
309
  * @example
327
310
  * ```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);
311
+ * import { FFmpegError, FilterInOut } from 'node-av';
312
+ *
313
+ * const inputs = FilterInOut.createList([
314
+ * { name: 'in', filterCtx: bufferSrc, padIdx: 0 }
315
+ * ]);
316
+ * const outputs = FilterInOut.createList([
317
+ * { name: 'out', filterCtx: bufferSink, padIdx: 0 }
318
+ * ]);
319
+ *
320
+ * const ret = graph.parse(
321
+ * '[in]scale=640:480,format=yuv420p[out]',
322
+ * inputs,
323
+ * outputs
324
+ * );
343
325
  * FFmpegError.throwIfError(ret, 'parse');
344
326
  * ```
327
+ *
328
+ * @see {@link parse2} For simpler syntax
329
+ * @see {@link parsePtr} For alternative parsing
345
330
  */
346
331
  parse(filters, inputs, outputs) {
347
332
  return this.native.parse(filters, inputs ? inputs.getNative() : null, outputs ? outputs.getNative() : null);
348
333
  }
349
334
  /**
350
- * Parse a filtergraph description (simplified).
335
+ * Parse a filter graph description (simplified).
351
336
  *
352
- * Direct mapping to avfilter_graph_parse2()
337
+ * Parses a textual filter description with automatic input/output handling.
338
+ * Simpler than parse() but less flexible.
353
339
  *
354
- * @param filters - Filtergraph description string
340
+ * Direct mapping to avfilter_graph_parse2().
355
341
  *
342
+ * @param filters - Filter graph description string
356
343
  * @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
344
+ * - AVERROR_EINVAL: Parse error
345
+ * - AVERROR_ENOMEM: Memory allocation failure
361
346
  *
362
347
  * @example
363
348
  * ```typescript
364
- * import { FilterGraph, FFmpegError } from 'node-av';
349
+ * import { FFmpegError } from 'node-av';
365
350
  *
366
351
  * // Parse a simple filter chain
367
- * const ret = graph.parse2('scale=1280:720,format=yuv420p');
352
+ * const ret = graph.parse2(
353
+ * 'scale=640:480,format=yuv420p'
354
+ * );
368
355
  * FFmpegError.throwIfError(ret, 'parse2');
369
356
  * ```
370
357
  *
371
- * @note Automatically handles inputs and outputs.
358
+ * @see {@link parse} For labeled inputs/outputs
372
359
  */
373
360
  parse2(filters) {
374
361
  return this.native.parse2(filters);
375
362
  }
376
363
  /**
377
- * Parse a filtergraph description (pointer version).
364
+ * Parse a filter graph description with pointer.
378
365
  *
379
- * Direct mapping to avfilter_graph_parse_ptr()
366
+ * Alternative parsing method with different parameter handling.
380
367
  *
381
- * @param filters - Filtergraph description string
382
- * @param inputs - Optional input pad list (FilterInOut)
383
- * @param outputs - Optional output pad list (FilterInOut)
368
+ * Direct mapping to avfilter_graph_parse_ptr().
384
369
  *
370
+ * @param filters - Filter graph description string
371
+ * @param inputs - Optional linked list of inputs
372
+ * @param outputs - Optional linked list of outputs
385
373
  * @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
374
+ * - AVERROR_EINVAL: Parse error
375
+ * - AVERROR_ENOMEM: Memory allocation failure
390
376
  *
391
377
  * @example
392
378
  * ```typescript
393
- * import { FilterGraph, FFmpegError } from 'node-av';
379
+ * import { FFmpegError } from 'node-av';
394
380
  *
395
- * // Parse a complex filter graph
396
381
  * const ret = graph.parsePtr(
397
- * '[0:v] scale=1280:720 [scaled]; [scaled] split [out1][out2]'
382
+ * '[in]scale=w=640:h=480[out]'
398
383
  * );
399
384
  * FFmpegError.throwIfError(ret, 'parsePtr');
400
385
  * ```
401
386
  *
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.
387
+ * @see {@link parse} For standard parsing
388
+ * @see {@link parse2} For simplified parsing
422
389
  */
423
390
  parsePtr(filters, inputs, outputs) {
424
391
  return this.native.parsePtr(filters, inputs ? inputs.getNative() : null, outputs ? outputs.getNative() : null);
425
392
  }
426
393
  /**
427
- * Validate the filter graph.
394
+ * Validate the filter graph configuration.
428
395
  *
429
- * Direct mapping to avfilter_graph_validate()
396
+ * Checks if the graph is valid and properly configured.
397
+ * Does not finalize the graph like config() does.
430
398
  *
431
399
  * @returns 0 on success, negative AVERROR on error:
432
- * - 0: Valid graph structure
433
- * - AVERROR(EINVAL): Invalid graph structure
434
- * - <0: Other validation errors
400
+ * - AVERROR_EINVAL: Invalid configuration
435
401
  *
436
402
  * @example
437
403
  * ```typescript
438
- * // Validate before configuring
404
+ * import { FFmpegError } from 'node-av';
405
+ *
439
406
  * const ret = graph.validate();
440
- * if (ret < 0) {
441
- * console.error('Graph validation failed');
442
- * }
407
+ * FFmpegError.throwIfError(ret, 'validate');
443
408
  * ```
444
409
  *
445
- * @note Checks that the graph structure is valid without configuring it.
410
+ * @see {@link config} To configure and finalize
446
411
  */
447
412
  validate() {
448
413
  return this.native.validate();
@@ -450,138 +415,132 @@ export class FilterGraph extends OptionMember {
450
415
  /**
451
416
  * Request a frame from the oldest sink.
452
417
  *
453
- * Direct mapping to avfilter_graph_request_oldest()
418
+ * Requests that a frame be output from the oldest sink in the graph.
419
+ * Used to drive the filter graph processing.
420
+ *
421
+ * Direct mapping to avfilter_graph_request_oldest().
454
422
  *
455
423
  * @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
424
+ * - AVERROR_EOF: End of stream reached
425
+ * - AVERROR_EAGAIN: Need more input
460
426
  *
461
427
  * @example
462
428
  * ```typescript
463
- * import { FilterGraph, FFmpegError } from 'node-av';
429
+ * import { FFmpegError } from 'node-av';
464
430
  * import { AVERROR_EOF, AVERROR_EAGAIN } from 'node-av/constants';
465
431
  *
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
432
+ * const ret = await graph.requestOldest();
433
+ * if (ret === AVERROR_EOF) {
434
+ * // No more frames
435
+ * } else if (ret === AVERROR_EAGAIN) {
436
+ * // Need to provide more input
437
+ * } else {
438
+ * FFmpegError.throwIfError(ret, 'requestOldest');
476
439
  * }
477
440
  * ```
478
- *
479
- * @note Triggers processing in the graph to produce output.
480
441
  */
481
442
  async requestOldest() {
482
- return this.native.requestOldest();
443
+ return await this.native.requestOldest();
483
444
  }
484
445
  /**
485
- * Get the graph structure as a string.
446
+ * Dump the filter graph to a string.
486
447
  *
487
- * Returns a string representation of the filter graph in DOT format.
488
- * Uses avfilter_graph_dump() internally.
448
+ * Returns a textual representation of the graph structure.
449
+ * Useful for debugging and visualization.
489
450
  *
490
- * @returns String representation of the filter graph or null if not allocated
451
+ * Direct mapping to avfilter_graph_dump().
452
+ *
453
+ * @returns Graph description string, or null on failure
491
454
  *
492
455
  * @example
493
456
  * ```typescript
494
- * const graphDescription = graph.dump();
495
- * console.log('Filter graph:', graphDescription);
457
+ * const graphStr = graph.dump();
458
+ * if (graphStr) {
459
+ * console.log('Graph structure:');
460
+ * console.log(graphStr);
461
+ * }
496
462
  * ```
497
463
  */
498
464
  dump() {
499
465
  return this.native.dump();
500
466
  }
501
467
  /**
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)
468
+ * Send a command to filters in the graph.
512
469
  *
513
- * @returns Error code (negative) or response object { response: string | null }
470
+ * Sends a command to one or more filters for immediate execution.
471
+ * Target can be a specific filter name or "all" for all filters.
514
472
  *
515
- * @example
516
- * ```typescript
517
- * import { FilterGraph, FFmpegError, AVFILTER_CMD_FLAG_ONE } from 'node-av';
473
+ * Direct mapping to avfilter_graph_send_command().
518
474
  *
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
- * ```
475
+ * @param target - Filter name or "all"
476
+ * @param cmd - Command to send
477
+ * @param arg - Command argument
478
+ * @param flags - Command flags
479
+ * @returns Error code or response object
527
480
  *
528
481
  * @example
529
482
  * ```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
483
  * // Send command to specific filter
534
- * const result = graph.sendCommand('scale', 'width', '1920');
484
+ * const result = graph.sendCommand(
485
+ * 'volume',
486
+ * 'volume',
487
+ * '0.5'
488
+ * );
489
+ *
490
+ * // Send to all filters
491
+ * const result2 = graph.sendCommand(
492
+ * 'all',
493
+ * 'enable',
494
+ * 'timeline'
495
+ * );
535
496
  * ```
536
497
  *
537
- * @note Not all filters support commands. Check filter documentation.
498
+ * @see {@link queueCommand} For delayed execution
538
499
  */
539
500
  sendCommand(target, cmd, arg, flags) {
540
501
  return this.native.sendCommand(target, cmd, arg, flags);
541
502
  }
542
503
  /**
543
- * Queue a command to be executed at a specific time.
504
+ * Queue a command for delayed execution.
544
505
  *
545
- * Direct mapping to avfilter_graph_queue_command()
506
+ * Schedules a command to be executed at a specific timestamp.
507
+ * The command is executed when the filter processes a frame with that timestamp.
546
508
  *
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)
509
+ * Direct mapping to avfilter_graph_queue_command().
554
510
  *
511
+ * @param target - Filter name or "all"
512
+ * @param cmd - Command to queue
513
+ * @param arg - Command argument
514
+ * @param ts - Timestamp for execution
515
+ * @param flags - Command flags
555
516
  * @returns 0 on success, negative AVERROR on error
556
517
  *
557
518
  * @example
558
519
  * ```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);
520
+ * import { FFmpegError } from 'node-av';
521
+ *
522
+ * // Queue volume change at 5 seconds
523
+ * const ret = graph.queueCommand(
524
+ * 'volume',
525
+ * 'volume',
526
+ * '0.2',
527
+ * 5000000, // microseconds
528
+ * 0
529
+ * );
563
530
  * FFmpegError.throwIfError(ret, 'queueCommand');
564
531
  * ```
565
532
  *
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.
533
+ * @see {@link sendCommand} For immediate execution
576
534
  */
577
535
  queueCommand(target, cmd, arg, ts, flags) {
578
536
  return this.native.queueCommand(target, cmd, arg, ts, flags);
579
537
  }
580
538
  /**
581
- * Get the native FFmpeg AVFilterGraph pointer.
539
+ * Get the underlying native FilterGraph object.
540
+ *
541
+ * @returns The native FilterGraph binding object
582
542
  *
583
- * @internal For use by other wrapper classes
584
- * @returns The underlying native filter graph object
543
+ * @internal
585
544
  */
586
545
  getNative() {
587
546
  return this.native;
@@ -597,7 +556,7 @@ export class FilterGraph extends OptionMember {
597
556
  * {
598
557
  * using graph = new FilterGraph();
599
558
  * graph.alloc();
600
- * // ... use graph
559
+ * // Build and use graph...
601
560
  * } // Automatically freed when leaving scope
602
561
  * ```
603
562
  */