node-av 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -3
  21. package/dist/api/index.js +1 -1
  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 +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  27. package/dist/api/media-input.js +205 -103
  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 +210 -128
  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 +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. package/CHANGELOG.md +0 -8
@@ -3,52 +3,46 @@ import { HardwareDeviceContext } from './hardware-device-context.js';
3
3
  import { OptionMember } from './option.js';
4
4
  import { Rational } from './rational.js';
5
5
  /**
6
- * Filter context for media processing.
6
+ * Filter instance in a filter graph.
7
7
  *
8
- * Represents an instance of a filter in a filter graph.
9
- * Manages filter configuration, parameters, and connections.
10
- * Must be created through FilterGraph.createFilter() and properly initialized before use.
8
+ * Represents an instantiated filter within a filter graph. Each context contains
9
+ * a specific filter configuration with its parameters, connections to other filters,
10
+ * and input/output pads. Supports both software and hardware filtering operations.
11
+ * Essential for building complex filter chains for audio/video processing.
11
12
  *
12
13
  * Direct mapping to FFmpeg's AVFilterContext.
13
14
  *
14
15
  * @example
15
16
  * ```typescript
16
- * import { FilterGraph, Filter, FFmpegError } from 'node-av';
17
+ * import { FilterContext, FilterGraph, Filter, FFmpegError } from 'node-av';
17
18
  *
18
- * // Create filter context through FilterGraph
19
- * const filterGraph = new FilterGraph();
20
- * filterGraph.alloc();
19
+ * // Create filter context in a graph
20
+ * const graph = new FilterGraph();
21
+ * const filter = Filter.getByName('scale');
22
+ * const context = graph.createFilter(filter, 'scaler');
21
23
  *
22
- * const bufferFilter = Filter.getByName('buffer');
23
- * const bufferCtx = filterGraph.createFilter(bufferFilter, 'in');
24
- * const initRet = bufferCtx.initStr('video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25:pixel_aspect=1/1');
25
- * FFmpegError.throwIfError(initRet, 'initStr buffer');
24
+ * // Initialize with parameters
25
+ * const ret = context.initStr('640:480');
26
+ * FFmpegError.throwIfError(ret, 'initStr');
26
27
  *
27
- * // Link filters
28
- * const scaleFilter = Filter.getByName('scale');
29
- * const scaleCtx = filterGraph.createFilter(scaleFilter, 'scale');
30
- * const scaleRet = scaleCtx.initStr('1280:720');
31
- * FFmpegError.throwIfError(scaleRet, 'initStr scale');
28
+ * // Link filters together
29
+ * const ret2 = source.link(0, context, 0);
30
+ * FFmpegError.throwIfError(ret2, 'link');
32
31
  *
33
- * const linkRet = bufferCtx.link(0, scaleCtx, 0);
34
- * FFmpegError.throwIfError(linkRet, 'link');
35
- *
36
- * // Configure and use the graph
37
- * const configRet = filterGraph.config();
38
- * FFmpegError.throwIfError(configRet, 'config');
32
+ * // For buffer source/sink
33
+ * const ret3 = await bufferSrc.buffersrcAddFrame(frame);
34
+ * FFmpegError.throwIfError(ret3, 'buffersrcAddFrame');
39
35
  * ```
36
+ *
37
+ * @see [AVFilterContext](https://ffmpeg.org/doxygen/trunk/structAVFilterContext.html) - FFmpeg Doxygen
38
+ * @see {@link FilterGraph} For managing filter graphs
39
+ * @see {@link Filter} For filter descriptors
40
40
  */
41
41
  export class FilterContext extends OptionMember {
42
42
  _hwDeviceCtx; // Cache for hardware device context wrapper
43
43
  /**
44
- * Constructor is internal - use FilterGraph.createFilter().
45
- *
46
- * FilterContexts are created and managed by FilterGraph.
47
- * Do not instantiate directly.
48
- *
44
+ * @param native - The native filter context instance
49
45
  * @internal
50
- *
51
- * @param native - Native AVFilterContext to wrap
52
46
  */
53
47
  constructor(native) {
54
48
  super(native);
@@ -56,9 +50,10 @@ export class FilterContext extends OptionMember {
56
50
  /**
57
51
  * Filter instance name.
58
52
  *
59
- * The unique name of this filter instance in the graph.
53
+ * User-assigned name for this filter instance in the graph.
54
+ * Used for identification and debugging.
60
55
  *
61
- * Direct mapping to AVFilterContext->name
56
+ * Direct mapping to AVFilterContext->name.
62
57
  */
63
58
  get name() {
64
59
  return this.native.name;
@@ -67,26 +62,22 @@ export class FilterContext extends OptionMember {
67
62
  this.native.name = value;
68
63
  }
69
64
  /**
70
- * The filter definition.
65
+ * Filter descriptor.
71
66
  *
72
- * The AVFilter that this context is an instance of.
67
+ * Reference to the filter type this context instantiates.
73
68
  *
74
- * Direct mapping to AVFilterContext->filter
75
- *
76
- * @readonly
69
+ * Direct mapping to AVFilterContext->filter.
77
70
  */
78
71
  get filter() {
79
72
  const native = this.native.filter;
80
73
  return native ? new Filter(native) : null;
81
74
  }
82
75
  /**
83
- * The parent filter graph.
84
- *
85
- * The filter graph that contains this filter context.
76
+ * Parent filter graph.
86
77
  *
87
- * Direct mapping to AVFilterContext->graph
78
+ * Reference to the graph containing this filter context.
88
79
  *
89
- * @readonly
80
+ * Direct mapping to AVFilterContext->graph.
90
81
  */
91
82
  get graph() {
92
83
  return this.native.graph;
@@ -94,11 +85,9 @@ export class FilterContext extends OptionMember {
94
85
  /**
95
86
  * Number of input pads.
96
87
  *
97
- * The number of input connections this filter can accept.
98
- *
99
- * Direct mapping to AVFilterContext->nb_inputs
88
+ * Total number of input connections this filter can accept.
100
89
  *
101
- * @readonly
90
+ * Direct mapping to AVFilterContext->nb_inputs.
102
91
  */
103
92
  get nbInputs() {
104
93
  return this.native.nbInputs;
@@ -106,30 +95,31 @@ export class FilterContext extends OptionMember {
106
95
  /**
107
96
  * Number of output pads.
108
97
  *
109
- * Direct mapping to AVFilterContext->nb_outputs
98
+ * Total number of output connections this filter can provide.
110
99
  *
111
- * The number of output connections this filter can provide.
100
+ * Direct mapping to AVFilterContext->nb_outputs.
112
101
  */
113
102
  get nbOutputs() {
114
103
  return this.native.nbOutputs;
115
104
  }
116
105
  /**
117
- * Filter readiness status.
106
+ * Filter readiness state.
118
107
  *
119
- * Direct mapping to AVFilterContext->ready
108
+ * Indicates if the filter is ready for processing.
109
+ * Non-zero when ready.
120
110
  *
121
- * Non-zero when the filter has been properly initialized.
111
+ * Direct mapping to AVFilterContext->ready.
122
112
  */
123
113
  get ready() {
124
114
  return this.native.ready;
125
115
  }
126
116
  /**
127
- * Get or set the hardware device context.
117
+ * Hardware device context.
128
118
  *
129
- * Direct mapping to AVFilterContext->hw_device_ctx
119
+ * Hardware acceleration context for GPU-based filtering.
120
+ * Set to enable hardware-accelerated filter operations.
130
121
  *
131
- * Used for hardware-accelerated filters that need device context.
132
- * Must be set before filter initialization for hardware filters.
122
+ * Direct mapping to AVFilterContext->hw_device_ctx.
133
123
  */
134
124
  get hwDeviceCtx() {
135
125
  const native = this.native.hwDeviceCtx;
@@ -154,65 +144,59 @@ export class FilterContext extends OptionMember {
154
144
  this._hwDeviceCtx = undefined;
155
145
  }
156
146
  /**
157
- * Initialize the filter with options.
147
+ * Initialize filter with dictionary options.
158
148
  *
159
- * Direct mapping to avfilter_init_dict()
149
+ * Configures the filter with key-value option pairs.
150
+ * Must be called after creation and before processing.
160
151
  *
161
- * @param options - Optional dictionary of filter options
152
+ * Direct mapping to avfilter_init_dict().
162
153
  *
154
+ * @param options - Dictionary of filter options
163
155
  * @returns 0 on success, negative AVERROR on error:
164
- * - 0: Success
165
- * - AVERROR(EINVAL): Invalid options
166
- * - AVERROR(ENOMEM): Memory allocation failure
167
- * - <0: Other filter-specific errors
156
+ * - AVERROR_EINVAL: Invalid parameters
157
+ * - AVERROR_ENOMEM: Memory allocation failure
168
158
  *
169
159
  * @example
170
160
  * ```typescript
171
- * import { Dictionary, FilterContext, FFmpegError } from 'node-av';
161
+ * import { FFmpegError } from 'node-av';
172
162
  *
173
- * const options = new Dictionary();
174
- * const ret1 = options.set('width', '1280', 0);
175
- * FFmpegError.throwIfError(ret1, 'set width');
176
- * const ret2 = options.set('height', '720', 0);
177
- * FFmpegError.throwIfError(ret2, 'set height');
178
- *
179
- * const initRet = filterCtx.init(options.getNative());
180
- * FFmpegError.throwIfError(initRet, 'init');
181
- * options.free();
163
+ * const options = { width: '1920', height: '1080' };
164
+ * const ret = context.init(options);
165
+ * FFmpegError.throwIfError(ret, 'init');
182
166
  * ```
183
167
  *
184
- * @see initStr() - Alternative initialization with string arguments
168
+ * @see {@link initStr} For string-based initialization
185
169
  */
186
170
  init(options = null) {
187
171
  return this.native.init(options ?? null);
188
172
  }
189
173
  /**
190
- * Initialize the filter with a string argument.
174
+ * Initialize filter with string arguments.
191
175
  *
192
- * Direct mapping to avfilter_init_str()
176
+ * Configures the filter using a string representation of parameters.
177
+ * Format depends on the specific filter.
193
178
  *
194
- * @param args - Filter arguments string (format is filter-specific)
179
+ * Direct mapping to avfilter_init_str().
195
180
  *
181
+ * @param args - Filter arguments string
196
182
  * @returns 0 on success, negative AVERROR on error:
197
- * - 0: Success
198
- * - AVERROR(EINVAL): Invalid arguments
199
- * - AVERROR(ENOMEM): Memory allocation failure
200
- * - <0: Other filter-specific errors
183
+ * - AVERROR_EINVAL: Invalid arguments
184
+ * - AVERROR_ENOMEM: Memory allocation failure
201
185
  *
202
186
  * @example
203
187
  * ```typescript
204
- * import { FilterContext, FFmpegError } from 'node-av';
188
+ * import { FFmpegError } from 'node-av';
205
189
  *
206
- * // Initialize scale filter
207
- * const scaleRet = scaleCtx.initStr('1280:720');
208
- * FFmpegError.throwIfError(scaleRet, 'initStr scale');
190
+ * // Scale filter with width:height
191
+ * const ret = scaleContext.initStr('1920:1080');
192
+ * FFmpegError.throwIfError(ret, 'initStr');
209
193
  *
210
- * // Initialize buffer source
211
- * const bufferRet = bufferCtx.initStr('video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25');
212
- * FFmpegError.throwIfError(bufferRet, 'initStr buffer');
194
+ * // Crop filter with width:height:x:y
195
+ * const ret2 = cropContext.initStr('640:480:100:50');
196
+ * FFmpegError.throwIfError(ret2, 'initStr');
213
197
  * ```
214
198
  *
215
- * @see init() - Alternative initialization with dictionary
199
+ * @see {@link init} For dictionary-based initialization
216
200
  */
217
201
  initStr(args = null) {
218
202
  return this.native.initStr(args ?? null);
@@ -220,30 +204,32 @@ export class FilterContext extends OptionMember {
220
204
  /**
221
205
  * Link this filter's output to another filter's input.
222
206
  *
223
- * Direct mapping to avfilter_link()
207
+ * Creates a connection between two filters in the graph.
208
+ * Data flows from this filter's output pad to the destination's input pad.
224
209
  *
225
- * @param srcPad - Output pad index on this filter
226
- * @param dst - Destination filter context
227
- * @param dstPad - Input pad index on destination filter
210
+ * Direct mapping to avfilter_link().
228
211
  *
212
+ * @param srcPad - Output pad index of this filter
213
+ * @param dst - Destination filter context
214
+ * @param dstPad - Input pad index of destination filter
229
215
  * @returns 0 on success, negative AVERROR on error:
230
- * - 0: Success
231
- * - AVERROR(EINVAL): Invalid pad indices or incompatible formats
232
- * - AVERROR(ENOMEM): Memory allocation failure
233
- * - <0: Other linking errors
216
+ * - AVERROR_EINVAL: Invalid pad indices or incompatible formats
217
+ * - AVERROR_ENOMEM: Memory allocation failure
234
218
  *
235
219
  * @example
236
220
  * ```typescript
237
- * import { FilterContext, FFmpegError } from 'node-av';
221
+ * import { FFmpegError } from 'node-av';
238
222
  *
239
- * // Link buffer source to scale filter
240
- * const linkRet1 = bufferCtx.link(0, scaleCtx, 0);
241
- * FFmpegError.throwIfError(linkRet1, 'link buffer to scale');
223
+ * // Link source output 0 to scale input 0
224
+ * const ret = source.link(0, scale, 0);
225
+ * FFmpegError.throwIfError(ret, 'link');
242
226
  *
243
- * // Link scale to sink
244
- * const linkRet2 = scaleCtx.link(0, sinkCtx, 0);
245
- * FFmpegError.throwIfError(linkRet2, 'link scale to sink');
227
+ * // Link scale output 0 to sink input 0
228
+ * const ret2 = scale.link(0, sink, 0);
229
+ * FFmpegError.throwIfError(ret2, 'link');
246
230
  * ```
231
+ *
232
+ * @see {@link unlink} To disconnect filters
247
233
  */
248
234
  link(srcPad, dst, dstPad) {
249
235
  return this.native.link(srcPad, dst.native, dstPad);
@@ -251,16 +237,20 @@ export class FilterContext extends OptionMember {
251
237
  /**
252
238
  * Unlink a filter pad.
253
239
  *
254
- * Removes the connection from the specified input pad.
255
- * Note: avfilter_link_free is deprecated, we set pointer to nullptr instead.
240
+ * Disconnects a pad from its linked filter.
241
+ * Used to reconfigure filter connections.
242
+ *
243
+ * Direct mapping to avfilter_link_free().
256
244
  *
257
- * @param pad - Input pad index to unlink
245
+ * @param pad - Pad index to unlink
258
246
  *
259
247
  * @example
260
248
  * ```typescript
261
- * // Unlink the first input pad
262
- * filterCtx.unlink(0);
249
+ * // Disconnect output pad 0
250
+ * context.unlink(0);
263
251
  * ```
252
+ *
253
+ * @see {@link link} To connect filters
264
254
  */
265
255
  unlink(pad) {
266
256
  this.native.unlink(pad);
@@ -268,54 +258,74 @@ export class FilterContext extends OptionMember {
268
258
  /**
269
259
  * Add a frame to a buffer source filter.
270
260
  *
271
- * Direct mapping to av_buffersrc_add_frame()
272
- *
273
- * This function is specific to buffer source filters and is used
274
- * to feed frames into the filter graph.
261
+ * Sends a frame into the filter graph through a buffer source.
262
+ * Only valid for buffer source filters. Send null to signal EOF.
275
263
  *
276
- * @param frame - The frame to add (can be null to signal EOF)
264
+ * Direct mapping to av_buffersrc_add_frame().
277
265
  *
266
+ * @param frame - Frame to send, or null for EOF
278
267
  * @returns 0 on success, negative AVERROR on error:
279
- * - 0: Success
280
- * - AVERROR(EAGAIN): The buffer is full, try again later
281
- * - AVERROR(EINVAL): Invalid parameters
282
- * - AVERROR_EOF: The filter has been closed
268
+ * - AVERROR_EAGAIN: Filter needs more output consumption
269
+ * - AVERROR_EOF: Filter has been closed
270
+ * - AVERROR_EINVAL: Not a buffer source filter
271
+ * - AVERROR_ENOMEM: Memory allocation failure
283
272
  *
284
273
  * @example
285
274
  * ```typescript
286
- * import { Frame, FilterContext, FFmpegError } from 'node-av';
287
- *
288
- * // Feed a frame to the buffer source
289
- * const addRet = srcCtx.buffersrcAddFrame(frame);
290
- * FFmpegError.throwIfError(addRet, 'buffersrcAddFrame');
275
+ * import { FFmpegError } from 'node-av';
276
+ * import { AVERROR_EAGAIN } from 'node-av/constants';
277
+ *
278
+ * // Send frame to filter graph
279
+ * const ret = await bufferSrc.buffersrcAddFrame(frame);
280
+ * if (ret === AVERROR_EAGAIN) {
281
+ * // Need to consume output first
282
+ * } else {
283
+ * FFmpegError.throwIfError(ret, 'buffersrcAddFrame');
284
+ * }
291
285
  *
292
- * // Signal end of stream
293
- * const eofRet = srcCtx.buffersrcAddFrame(null);
294
- * FFmpegError.throwIfError(eofRet, 'buffersrcAddFrame EOF');
286
+ * // Signal EOF
287
+ * await bufferSrc.buffersrcAddFrame(null);
295
288
  * ```
289
+ *
290
+ * @see {@link buffersinkGetFrame} To retrieve filtered frames
296
291
  */
297
292
  async buffersrcAddFrame(frame) {
298
- return this.native.buffersrcAddFrame(frame ? frame.getNative() : null);
293
+ return await this.native.buffersrcAddFrame(frame ? frame.getNative() : null);
299
294
  }
300
295
  /**
301
296
  * Set parameters for a buffer source filter.
302
297
  *
303
- * Direct mapping to av_buffersrc_parameters_set()
304
- *
305
- * This function configures a buffer source filter with specific parameters,
306
- * including hardware frames context for hardware-accelerated filtering.
307
- *
308
- * @param params - Parameters for the buffer source
309
- * @returns 0 on success, negative error code on failure
298
+ * Configures the format and properties of frames that will be sent
299
+ * to the buffer source. Must be called before sending frames.
300
+ *
301
+ * Direct mapping to av_buffersrc_parameters_set().
302
+ *
303
+ * @param params - Source parameters
304
+ * @param params.width - Video frame width
305
+ * @param params.height - Video frame height
306
+ * @param params.format - Pixel or sample format
307
+ * @param params.timeBase - Time base for timestamps
308
+ * @param params.frameRate - Video frame rate
309
+ * @param params.sampleAspectRatio - Pixel aspect ratio
310
+ * @param params.hwFramesCtx - Hardware frames context
311
+ * @param params.sampleRate - Audio sample rate
312
+ * @param params.channelLayout - Audio channel layout
313
+ * @returns 0 on success, negative AVERROR on error:
314
+ * - AVERROR_EINVAL: Invalid parameters
315
+ * - AVERROR_ENOMEM: Memory allocation failure
310
316
  *
311
317
  * @example
312
318
  * ```typescript
313
- * const ret = srcCtx.buffersrcParametersSet({
319
+ * import { FFmpegError, Rational } from 'node-av';
320
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
321
+ *
322
+ * // Configure video buffer source
323
+ * const ret = bufferSrc.buffersrcParametersSet({
314
324
  * width: 1920,
315
325
  * height: 1080,
316
326
  * format: AV_PIX_FMT_YUV420P,
317
- * timeBase: { num: 1, den: 30 },
318
- * hwFramesCtx: hardware.framesContext
327
+ * timeBase: { num: 1, den: 25 },
328
+ * frameRate: { num: 25, den: 1 }
319
329
  * });
320
330
  * FFmpegError.throwIfError(ret, 'buffersrcParametersSet');
321
331
  * ```
@@ -330,77 +340,54 @@ export class FilterContext extends OptionMember {
330
340
  /**
331
341
  * Get a frame from a buffer sink filter.
332
342
  *
333
- * Direct mapping to av_buffersink_get_frame()
334
- *
335
- * This function is specific to buffer sink filters and is used
336
- * to retrieve filtered frames from the filter graph.
343
+ * Retrieves a filtered frame from the filter graph through a buffer sink.
344
+ * Only valid for buffer sink filters.
337
345
  *
338
- * @param frame - The frame to receive the filtered data
346
+ * Direct mapping to av_buffersink_get_frame().
339
347
  *
348
+ * @param frame - Frame to receive filtered data
340
349
  * @returns 0 on success, negative AVERROR on error:
341
- * - 0: Success, frame contains valid data
342
- * - AVERROR(EAGAIN): No frame available, need more input
343
- * - AVERROR_EOF: End of stream reached
344
- * - AVERROR(EINVAL): Invalid parameters
350
+ * - AVERROR_EAGAIN: No frame available yet
351
+ * - AVERROR_EOF: No more frames will be produced
352
+ * - AVERROR_EINVAL: Not a buffer sink filter
345
353
  *
346
354
  * @example
347
355
  * ```typescript
348
- * import { Frame, FilterContext, FFmpegError } from 'node-av';
356
+ * import { FFmpegError, Frame } from 'node-av';
349
357
  * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
350
358
  *
351
- * // Get filtered frames
352
359
  * const frame = new Frame();
353
360
  * frame.alloc();
354
361
  *
355
- * let ret = sinkCtx.buffersinkGetFrame(frame);
356
- * while (ret >= 0) {
357
- * // Process the filtered frame
358
- * processFrame(frame);
359
- * frame.unref();
360
- *
361
- * // Try to get another frame
362
- * ret = sinkCtx.buffersinkGetFrame(frame);
363
- * }
364
- *
365
- * if (!FFmpegError.is(ret, AVERROR_EAGAIN) && !FFmpegError.is(ret, AVERROR_EOF)) {
362
+ * const ret = await bufferSink.buffersinkGetFrame(frame);
363
+ * if (ret === AVERROR_EAGAIN) {
364
+ * // No frame available yet
365
+ * } else if (ret === AVERROR_EOF) {
366
+ * // End of stream
367
+ * } else {
366
368
  * FFmpegError.throwIfError(ret, 'buffersinkGetFrame');
369
+ * // Process filtered frame
367
370
  * }
368
371
  * ```
372
+ *
373
+ * @see {@link buffersrcAddFrame} To send frames for filtering
369
374
  */
370
375
  async buffersinkGetFrame(frame) {
371
- return this.native.buffersinkGetFrame(frame.getNative());
376
+ return await this.native.buffersinkGetFrame(frame.getNative());
372
377
  }
373
378
  /**
374
- * Set the frame size for a buffersink filter.
375
- *
376
- * Direct mapping to av_buffersink_set_frame_size()
377
- *
378
- * For audio encoders that require a specific frame size.
379
- *
380
- * @param frameSize - The frame size to set
381
- *
382
- * @example
383
- * ```typescript
384
- * if (encCtx.frameSize > 0) {
385
- * buffersinkCtx.buffersinkSetFrameSize(encCtx.frameSize);
386
- * }
387
- * ```
388
- */
389
- // buffersinkSetFrameSize(frameSize: number): void {
390
- // this.native.buffersinkSetFrameSize(frameSize);
391
- // }
392
- /**
393
- * Get the time base from a buffersink filter.
379
+ * Get time base from buffer sink.
394
380
  *
395
- * Direct mapping to av_buffersink_get_time_base()
381
+ * Returns the time base of frames from a buffer sink filter.
382
+ * Only valid for buffer sink filters.
396
383
  *
397
- * Returns the time base of the buffersink filter.
384
+ * Direct mapping to av_buffersink_get_time_base().
398
385
  *
399
- * @returns The time base as a Rational
386
+ * @returns Time base as Rational
400
387
  *
401
388
  * @example
402
389
  * ```typescript
403
- * const timeBase = buffersinkCtx.buffersinkGetTimeBase();
390
+ * const timeBase = bufferSink.buffersinkGetTimeBase();
404
391
  * console.log(`Time base: ${timeBase.num}/${timeBase.den}`);
405
392
  * ```
406
393
  */
@@ -409,73 +396,140 @@ export class FilterContext extends OptionMember {
409
396
  return new Rational(tb.num, tb.den);
410
397
  }
411
398
  /**
412
- * Get the pixel/sample format from a buffersink filter.
399
+ * Get pixel/sample format from buffer sink.
400
+ *
401
+ * Returns the format of frames from a buffer sink filter.
402
+ * Only valid for buffer sink filters.
403
+ *
404
+ * Direct mapping to av_buffersink_get_format().
405
+ *
406
+ * @returns Pixel format for video, sample format for audio
413
407
  *
414
- * Direct mapping to av_buffersink_get_format()
408
+ * @example
409
+ * ```typescript
410
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
415
411
  *
416
- * @returns The format (pixel format for video, sample format for audio)
412
+ * const format = bufferSink.buffersinkGetFormat();
413
+ * if (format === AV_PIX_FMT_YUV420P) {
414
+ * console.log('Output is YUV420P');
415
+ * }
416
+ * ```
417
417
  */
418
418
  buffersinkGetFormat() {
419
419
  return this.native.buffersinkGetFormat();
420
420
  }
421
421
  /**
422
- * Get the width from a video buffersink filter.
422
+ * Get frame width from buffer sink.
423
+ *
424
+ * Returns the width of video frames from a buffer sink filter.
425
+ * Only valid for video buffer sink filters.
423
426
  *
424
- * Direct mapping to av_buffersink_get_w()
427
+ * Direct mapping to av_buffersink_get_w().
425
428
  *
426
- * @returns The video width in pixels
429
+ * @returns Frame width in pixels
430
+ *
431
+ * @example
432
+ * ```typescript
433
+ * const width = bufferSink.buffersinkGetWidth();
434
+ * console.log(`Output width: ${width}px`);
435
+ * ```
427
436
  */
428
437
  buffersinkGetWidth() {
429
438
  return this.native.buffersinkGetWidth();
430
439
  }
431
440
  /**
432
- * Get the height from a video buffersink filter.
441
+ * Get frame height from buffer sink.
442
+ *
443
+ * Returns the height of video frames from a buffer sink filter.
444
+ * Only valid for video buffer sink filters.
433
445
  *
434
- * Direct mapping to av_buffersink_get_h()
446
+ * Direct mapping to av_buffersink_get_h().
435
447
  *
436
- * @returns The video height in pixels
448
+ * @returns Frame height in pixels
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * const height = bufferSink.buffersinkGetHeight();
453
+ * console.log(`Output height: ${height}px`);
454
+ * ```
437
455
  */
438
456
  buffersinkGetHeight() {
439
457
  return this.native.buffersinkGetHeight();
440
458
  }
441
459
  /**
442
- * Get the sample aspect ratio from a video buffersink filter.
460
+ * Get sample aspect ratio from buffer sink.
461
+ *
462
+ * Returns the pixel aspect ratio of video frames from a buffer sink filter.
463
+ * Only valid for video buffer sink filters.
443
464
  *
444
- * Direct mapping to av_buffersink_get_sample_aspect_ratio()
465
+ * Direct mapping to av_buffersink_get_sample_aspect_ratio().
445
466
  *
446
- * @returns The sample aspect ratio as a Rational
467
+ * @returns Sample aspect ratio as Rational
468
+ *
469
+ * @example
470
+ * ```typescript
471
+ * const sar = bufferSink.buffersinkGetSampleAspectRatio();
472
+ * console.log(`SAR: ${sar.num}:${sar.den}`);
473
+ * ```
447
474
  */
448
475
  buffersinkGetSampleAspectRatio() {
449
476
  const sar = this.native.buffersinkGetSampleAspectRatio();
450
477
  return new Rational(sar.num, sar.den);
451
478
  }
452
479
  /**
453
- * Get the frame rate from a video buffersink filter.
480
+ * Get frame rate from buffer sink.
481
+ *
482
+ * Returns the frame rate of video from a buffer sink filter.
483
+ * Only valid for video buffer sink filters.
454
484
  *
455
- * Direct mapping to av_buffersink_get_frame_rate()
485
+ * Direct mapping to av_buffersink_get_frame_rate().
456
486
  *
457
- * @returns The frame rate as a Rational
487
+ * @returns Frame rate as Rational
488
+ *
489
+ * @example
490
+ * ```typescript
491
+ * const frameRate = bufferSink.buffersinkGetFrameRate();
492
+ * console.log(`Frame rate: ${frameRate.num}/${frameRate.den} fps`);
493
+ * ```
458
494
  */
459
495
  buffersinkGetFrameRate() {
460
496
  const fr = this.native.buffersinkGetFrameRate();
461
497
  return new Rational(fr.num, fr.den);
462
498
  }
463
499
  /**
464
- * Get the sample rate from an audio buffersink filter.
500
+ * Get sample rate from buffer sink.
501
+ *
502
+ * Returns the sample rate of audio from a buffer sink filter.
503
+ * Only valid for audio buffer sink filters.
465
504
  *
466
- * Direct mapping to av_buffersink_get_sample_rate()
505
+ * Direct mapping to av_buffersink_get_sample_rate().
467
506
  *
468
- * @returns The audio sample rate in Hz
507
+ * @returns Sample rate in Hz
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * const sampleRate = bufferSink.buffersinkGetSampleRate();
512
+ * console.log(`Sample rate: ${sampleRate} Hz`);
513
+ * ```
469
514
  */
470
515
  buffersinkGetSampleRate() {
471
516
  return this.native.buffersinkGetSampleRate();
472
517
  }
473
518
  /**
474
- * Get the channel layout from an audio buffersink filter.
519
+ * Get channel layout from buffer sink.
520
+ *
521
+ * Returns the channel layout of audio from a buffer sink filter.
522
+ * Only valid for audio buffer sink filters.
475
523
  *
476
- * Direct mapping to av_buffersink_get_ch_layout()
524
+ * Direct mapping to av_buffersink_get_channel_layout().
477
525
  *
478
- * @returns The channel layout object with order, nbChannels, and mask
526
+ * @returns Channel layout configuration
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * const layout = bufferSink.buffersinkGetChannelLayout();
531
+ * console.log(`Channels: ${layout.nbChannels}`);
532
+ * ```
479
533
  */
480
534
  buffersinkGetChannelLayout() {
481
535
  return this.native.buffersinkGetChannelLayout();
@@ -483,63 +537,71 @@ export class FilterContext extends OptionMember {
483
537
  /**
484
538
  * Free the filter context.
485
539
  *
486
- * Direct mapping to avfilter_free()
540
+ * Releases all resources associated with the filter context.
541
+ * The context becomes invalid after calling this.
542
+ *
543
+ * Direct mapping to avfilter_free().
487
544
  *
488
545
  * @example
489
546
  * ```typescript
490
- * filterCtx.free();
491
- * // filterCtx is now invalid and should not be used
547
+ * context.free();
548
+ * // Context is now invalid
492
549
  * ```
550
+ *
551
+ * @see {@link Symbol.dispose} For automatic cleanup
493
552
  */
494
553
  free() {
495
554
  this.native.free();
496
555
  }
497
556
  /**
498
- * Check if this is a source filter context.
557
+ * Check if filter is a source.
499
558
  *
500
- * Source filters have no inputs and generate data.
559
+ * Source filters generate frames without input.
501
560
  *
502
- * @returns true if the filter has no input pads, false otherwise
561
+ * @returns True if filter has no inputs
503
562
  *
504
563
  * @example
505
564
  * ```typescript
506
- * if (filterCtx.isSource()) {
565
+ * if (context.isSource()) {
507
566
  * console.log('This is a source filter');
508
567
  * }
509
568
  * ```
569
+ *
570
+ * @see {@link isSink} To check for sink filters
510
571
  */
511
572
  isSource() {
512
573
  return this.nbInputs === 0;
513
574
  }
514
575
  /**
515
- * Check if this is a sink filter context.
576
+ * Check if filter is a sink.
516
577
  *
517
- * Sink filters have no outputs and consume data.
578
+ * Sink filters consume frames without output.
518
579
  *
519
- * @returns true if the filter has no output pads, false otherwise
580
+ * @returns True if filter has no outputs
520
581
  *
521
582
  * @example
522
583
  * ```typescript
523
- * if (filterCtx.isSink()) {
584
+ * if (context.isSink()) {
524
585
  * console.log('This is a sink filter');
525
586
  * }
526
587
  * ```
588
+ *
589
+ * @see {@link isSource} To check for source filters
527
590
  */
528
591
  isSink() {
529
592
  return this.nbOutputs === 0;
530
593
  }
531
594
  /**
532
- * Check if the filter is ready for processing.
595
+ * Check if filter is ready.
533
596
  *
534
- * Filters must be initialized before they can process data.
597
+ * Indicates whether the filter is ready for processing.
535
598
  *
536
- * @returns true if the filter has been properly initialized, false otherwise
599
+ * @returns True if filter is ready
537
600
  *
538
601
  * @example
539
602
  * ```typescript
540
- * filterCtx.initStr('1280:720');
541
- * if (filterCtx.isReady()) {
542
- * console.log('Filter is ready for processing');
603
+ * if (context.isReady()) {
604
+ * // Filter is ready for processing
543
605
  * }
544
606
  * ```
545
607
  */
@@ -547,10 +609,11 @@ export class FilterContext extends OptionMember {
547
609
  return this.ready !== 0;
548
610
  }
549
611
  /**
550
- * Get the native FFmpeg AVFilterContext pointer.
612
+ * Get the underlying native FilterContext object.
551
613
  *
552
- * @internal For use by other wrapper classes
553
- * @returns The underlying native filter context object
614
+ * @returns The native FilterContext binding object
615
+ *
616
+ * @internal
554
617
  */
555
618
  getNative() {
556
619
  return this.native;
@@ -564,9 +627,9 @@ export class FilterContext extends OptionMember {
564
627
  * @example
565
628
  * ```typescript
566
629
  * {
567
- * using filterCtx = filterGraph.createFilter(filter, 'my_filter');
568
- * filterCtx.initStr('args');
569
- * // ... use filter context
630
+ * using context = graph.createFilter(filter, 'test');
631
+ * context.initStr('640:480');
632
+ * // Use context...
570
633
  * } // Automatically freed when leaving scope
571
634
  * ```
572
635
  */