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
@@ -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.
71
- *
72
- * The AVFilter that this context is an instance of.
65
+ * Filter descriptor.
73
66
  *
74
- * Direct mapping to AVFilterContext->filter
67
+ * Reference to the filter type this context instantiates.
75
68
  *
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.
88
+ * Total number of input connections this filter can accept.
98
89
  *
99
- * Direct mapping to AVFilterContext->nb_inputs
100
- *
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';
172
- *
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');
161
+ * import { FFmpegError } from 'node-av';
178
162
  *
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,144 +340,268 @@ 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());
377
+ }
378
+ /**
379
+ * Get time base from buffer sink.
380
+ *
381
+ * Returns the time base of frames from a buffer sink filter.
382
+ * Only valid for buffer sink filters.
383
+ *
384
+ * Direct mapping to av_buffersink_get_time_base().
385
+ *
386
+ * @returns Time base as Rational
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * const timeBase = bufferSink.buffersinkGetTimeBase();
391
+ * console.log(`Time base: ${timeBase.num}/${timeBase.den}`);
392
+ * ```
393
+ */
394
+ buffersinkGetTimeBase() {
395
+ const tb = this.native.buffersinkGetTimeBase();
396
+ return new Rational(tb.num, tb.den);
372
397
  }
373
398
  /**
374
- * Set the frame size for a buffersink filter.
399
+ * Get pixel/sample format from buffer sink.
375
400
  *
376
- * Direct mapping to av_buffersink_set_frame_size()
401
+ * Returns the format of frames from a buffer sink filter.
402
+ * Only valid for buffer sink filters.
377
403
  *
378
- * For audio encoders that require a specific frame size.
404
+ * Direct mapping to av_buffersink_get_format().
379
405
  *
380
- * @param frameSize - The frame size to set
406
+ * @returns Pixel format for video, sample format for audio
381
407
  *
382
408
  * @example
383
409
  * ```typescript
384
- * if (encCtx.frameSize > 0) {
385
- * buffersinkCtx.buffersinkSetFrameSize(encCtx.frameSize);
410
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
411
+ *
412
+ * const format = bufferSink.buffersinkGetFormat();
413
+ * if (format === AV_PIX_FMT_YUV420P) {
414
+ * console.log('Output is YUV420P');
386
415
  * }
387
416
  * ```
388
417
  */
389
- // buffersinkSetFrameSize(frameSize: number): void {
390
- // this.native.buffersinkSetFrameSize(frameSize);
391
- // }
418
+ buffersinkGetFormat() {
419
+ return this.native.buffersinkGetFormat();
420
+ }
392
421
  /**
393
- * Get the time base from a buffersink filter.
422
+ * Get frame width from buffer sink.
394
423
  *
395
- * Direct mapping to av_buffersink_get_time_base()
424
+ * Returns the width of video frames from a buffer sink filter.
425
+ * Only valid for video buffer sink filters.
396
426
  *
397
- * Returns the time base of the buffersink filter.
427
+ * Direct mapping to av_buffersink_get_w().
398
428
  *
399
- * @returns The time base as a Rational
429
+ * @returns Frame width in pixels
400
430
  *
401
431
  * @example
402
432
  * ```typescript
403
- * const timeBase = buffersinkCtx.buffersinkGetTimeBase();
404
- * console.log(`Time base: ${timeBase.num}/${timeBase.den}`);
433
+ * const width = bufferSink.buffersinkGetWidth();
434
+ * console.log(`Output width: ${width}px`);
405
435
  * ```
406
436
  */
407
- buffersinkGetTimeBase() {
408
- const tb = this.native.buffersinkGetTimeBase();
409
- return new Rational(tb.num, tb.den);
437
+ buffersinkGetWidth() {
438
+ return this.native.buffersinkGetWidth();
439
+ }
440
+ /**
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.
445
+ *
446
+ * Direct mapping to av_buffersink_get_h().
447
+ *
448
+ * @returns Frame height in pixels
449
+ *
450
+ * @example
451
+ * ```typescript
452
+ * const height = bufferSink.buffersinkGetHeight();
453
+ * console.log(`Output height: ${height}px`);
454
+ * ```
455
+ */
456
+ buffersinkGetHeight() {
457
+ return this.native.buffersinkGetHeight();
458
+ }
459
+ /**
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.
464
+ *
465
+ * Direct mapping to av_buffersink_get_sample_aspect_ratio().
466
+ *
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
+ * ```
474
+ */
475
+ buffersinkGetSampleAspectRatio() {
476
+ const sar = this.native.buffersinkGetSampleAspectRatio();
477
+ return new Rational(sar.num, sar.den);
478
+ }
479
+ /**
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.
484
+ *
485
+ * Direct mapping to av_buffersink_get_frame_rate().
486
+ *
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
+ * ```
494
+ */
495
+ buffersinkGetFrameRate() {
496
+ const fr = this.native.buffersinkGetFrameRate();
497
+ return new Rational(fr.num, fr.den);
498
+ }
499
+ /**
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.
504
+ *
505
+ * Direct mapping to av_buffersink_get_sample_rate().
506
+ *
507
+ * @returns Sample rate in Hz
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * const sampleRate = bufferSink.buffersinkGetSampleRate();
512
+ * console.log(`Sample rate: ${sampleRate} Hz`);
513
+ * ```
514
+ */
515
+ buffersinkGetSampleRate() {
516
+ return this.native.buffersinkGetSampleRate();
517
+ }
518
+ /**
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.
523
+ *
524
+ * Direct mapping to av_buffersink_get_channel_layout().
525
+ *
526
+ * @returns Channel layout configuration
527
+ *
528
+ * @example
529
+ * ```typescript
530
+ * const layout = bufferSink.buffersinkGetChannelLayout();
531
+ * console.log(`Channels: ${layout.nbChannels}`);
532
+ * ```
533
+ */
534
+ buffersinkGetChannelLayout() {
535
+ return this.native.buffersinkGetChannelLayout();
410
536
  }
411
537
  /**
412
538
  * Free the filter context.
413
539
  *
414
- * 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().
415
544
  *
416
545
  * @example
417
546
  * ```typescript
418
- * filterCtx.free();
419
- * // filterCtx is now invalid and should not be used
547
+ * context.free();
548
+ * // Context is now invalid
420
549
  * ```
550
+ *
551
+ * @see {@link Symbol.dispose} For automatic cleanup
421
552
  */
422
553
  free() {
423
554
  this.native.free();
424
555
  }
425
556
  /**
426
- * Check if this is a source filter context.
557
+ * Check if filter is a source.
427
558
  *
428
- * Source filters have no inputs and generate data.
559
+ * Source filters generate frames without input.
429
560
  *
430
- * @returns true if the filter has no input pads, false otherwise
561
+ * @returns True if filter has no inputs
431
562
  *
432
563
  * @example
433
564
  * ```typescript
434
- * if (filterCtx.isSource()) {
565
+ * if (context.isSource()) {
435
566
  * console.log('This is a source filter');
436
567
  * }
437
568
  * ```
569
+ *
570
+ * @see {@link isSink} To check for sink filters
438
571
  */
439
572
  isSource() {
440
573
  return this.nbInputs === 0;
441
574
  }
442
575
  /**
443
- * Check if this is a sink filter context.
576
+ * Check if filter is a sink.
444
577
  *
445
- * Sink filters have no outputs and consume data.
578
+ * Sink filters consume frames without output.
446
579
  *
447
- * @returns true if the filter has no output pads, false otherwise
580
+ * @returns True if filter has no outputs
448
581
  *
449
582
  * @example
450
583
  * ```typescript
451
- * if (filterCtx.isSink()) {
584
+ * if (context.isSink()) {
452
585
  * console.log('This is a sink filter');
453
586
  * }
454
587
  * ```
588
+ *
589
+ * @see {@link isSource} To check for source filters
455
590
  */
456
591
  isSink() {
457
592
  return this.nbOutputs === 0;
458
593
  }
459
594
  /**
460
- * Check if the filter is ready for processing.
595
+ * Check if filter is ready.
461
596
  *
462
- * Filters must be initialized before they can process data.
597
+ * Indicates whether the filter is ready for processing.
463
598
  *
464
- * @returns true if the filter has been properly initialized, false otherwise
599
+ * @returns True if filter is ready
465
600
  *
466
601
  * @example
467
602
  * ```typescript
468
- * filterCtx.initStr('1280:720');
469
- * if (filterCtx.isReady()) {
470
- * console.log('Filter is ready for processing');
603
+ * if (context.isReady()) {
604
+ * // Filter is ready for processing
471
605
  * }
472
606
  * ```
473
607
  */
@@ -475,10 +609,11 @@ export class FilterContext extends OptionMember {
475
609
  return this.ready !== 0;
476
610
  }
477
611
  /**
478
- * Get the native FFmpeg AVFilterContext pointer.
612
+ * Get the underlying native FilterContext object.
613
+ *
614
+ * @returns The native FilterContext binding object
479
615
  *
480
- * @internal For use by other wrapper classes
481
- * @returns The underlying native filter context object
616
+ * @internal
482
617
  */
483
618
  getNative() {
484
619
  return this.native;
@@ -492,9 +627,9 @@ export class FilterContext extends OptionMember {
492
627
  * @example
493
628
  * ```typescript
494
629
  * {
495
- * using filterCtx = filterGraph.createFilter(filter, 'my_filter');
496
- * filterCtx.initStr('args');
497
- * // ... use filter context
630
+ * using context = graph.createFilter(filter, 'test');
631
+ * context.initStr('640:480');
632
+ * // Use context...
498
633
  * } // Automatically freed when leaving scope
499
634
  * ```
500
635
  */