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
@@ -1,68 +1,43 @@
1
- /**
2
- * Filter - High-level wrapper for media filtering
3
- *
4
- * Implements FFmpeg CLI's filter graph behavior with proper hardware context handling.
5
- * Uses lazy initialization for hardware inputs: graph is built when first frame arrives
6
- * with hw_frames_ctx. For software inputs, initializes immediately.
7
- *
8
- * Handles filter graph creation, frame processing, and format conversion.
9
- * Supports complex filter chains and hardware-accelerated filters.
10
- *
11
- * @module api/filter
12
- */
13
1
  import { Frame } from '../lib/index.js';
14
2
  import type { AVFilterCmdFlag, AVMediaType } from '../constants/constants.js';
15
3
  import type { FilterOptions, StreamInfo } from './types.js';
16
4
  /**
17
- * High-level filter API for media processing.
5
+ * High-level filter API for audio and video processing.
18
6
  *
19
- * Provides a simplified interface for FFmpeg's filter system.
20
- * Supports both simple filter chains and complex filter graphs.
21
- * Handles automatic format negotiation and buffer management.
22
- *
23
- * The filter graph uses lazy initialization for hardware inputs - it's built when
24
- * the first frame arrives with hw_frames_ctx. This matches FFmpeg CLI behavior
25
- * for proper hardware context propagation.
7
+ * Provides simplified interface for applying FFmpeg filters to frames.
8
+ * Handles filter graph construction, frame buffering, and command control.
9
+ * Supports both software and hardware-accelerated filtering operations.
10
+ * Essential component for effects, transformations, and format conversions.
26
11
  *
27
12
  * @example
28
13
  * ```typescript
29
- * import { FilterAPI, Frame } from '@seydx/av/api';
30
- *
31
- * // Simple video filter from a stream
32
- * const videoStream = media.video();
33
- * const filter = await FilterAPI.create('scale=1280:720,format=yuv420p', videoStream);
14
+ * import { FilterAPI } from 'node-av/api';
34
15
  *
35
- * // Process frames
36
- * const outputFrame = await filter.process(inputFrame);
37
- * ```
16
+ * // Create video filter
17
+ * const filter = await FilterAPI.create('scale=1280:720', videoInfo);
38
18
  *
39
- * @example
40
- * ```typescript
41
- * // Hardware acceleration (decoder -> hw filter -> encoder)
42
- * const hw = await HardwareContext.auto();
43
- * const decoder = await Decoder.create(stream, { hardware: hw });
44
- * const filter = await FilterAPI.create('scale_vt=640:480', decoder.getOutputStreamInfo(), {
45
- * hardware: hw
46
- * });
19
+ * // Process frame
20
+ * const output = await filter.process(inputFrame);
21
+ * if (output) {
22
+ * console.log(`Filtered frame: ${output.width}x${output.height}`);
23
+ * output.free();
24
+ * }
47
25
  * ```
48
26
  *
49
27
  * @example
50
28
  * ```typescript
51
- * // Software decode -> hardware encode pipeline with hwupload
52
- * const decoder = await Decoder.create(stream);
53
- * const hw = await HardwareContext.auto();
54
- * const filter = await FilterAPI.create('format=nv12,hwupload', decoder.getOutputStreamInfo(), {
55
- * hardware: hw // Required for hwupload to create hw_frames_ctx
56
- * });
29
+ * // Hardware-accelerated filtering
30
+ * const hw = HardwareContext.auto();
31
+ * const filter = await FilterAPI.create(
32
+ * 'hwupload,scale_cuda=1920:1080,hwdownload',
33
+ * videoInfo,
34
+ * { hardware: hw }
35
+ * );
57
36
  * ```
58
37
  *
59
- * @example
60
- * ```typescript
61
- * // Hardware decode -> software encode pipeline with hwdownload
62
- * const hw = await HardwareContext.auto();
63
- * const decoder = await Decoder.create(stream, { hardware: hw });
64
- * const filter = await FilterAPI.create('hwdownload,format=yuv420p', decoder.getOutputStreamInfo());
65
- * ```
38
+ * @see {@link FilterGraph} For low-level filter graph API
39
+ * @see {@link HardwareContext} For hardware acceleration
40
+ * @see {@link Frame} For frame operations
66
41
  */
67
42
  export declare class FilterAPI implements Disposable {
68
43
  private graph;
@@ -75,343 +50,404 @@ export declare class FilterAPI implements Disposable {
75
50
  private description;
76
51
  private options;
77
52
  /**
78
- * Create a new Filter instance.
79
- *
80
- * @param config - Stream information from input stream
81
- * @param description - Filter graph description
82
- * @param options - Filter options including hardware context
53
+ * @param config - Stream configuration
54
+ * @param description - Filter description string
55
+ * @param options - Filter options
83
56
  * @internal
84
57
  */
85
58
  private constructor();
86
59
  /**
87
- * Create a filter from a filter description string.
60
+ * Create a filter with specified description and configuration.
88
61
  *
89
- * Accepts either a Stream (from MediaInput/Decoder) or StreamInfo (for raw data).
90
- * Automatically sets up buffer source and sink filters.
62
+ * Constructs filter graph from description string.
63
+ * Configures input/output buffers and threading.
64
+ * For video filters, uses lazy initialization to detect hardware frames.
91
65
  *
92
- * For hardware input formats: Uses lazy initialization, waits for first frame
93
- * with hw_frames_ctx before configuring the filter graph.
94
- * For software formats: Initializes immediately.
66
+ * Direct mapping to avfilter_graph_parse_ptr() and avfilter_graph_config().
95
67
  *
96
- * Hardware context handling:
97
- * - hwupload: Requires hardware context, creates its own hw_frames_ctx
98
- * - hwdownload: Uses hw_frames_ctx propagated from previous filters
99
- * - Other HW filters: Use propagated hw_frames_ctx or hwupload's output
100
- *
101
- * @param description - Filter graph description (e.g., "scale=1280:720" or complex chains)
102
- * @param input - Stream or StreamInfo describing the input
103
- * @param options - Optional filter options including hardware context
104
- *
105
- * @returns Promise resolving to configured Filter instance
68
+ * @param description - Filter graph description
69
+ * @param input - Input stream configuration
70
+ * @param options - Filter options
71
+ * @returns Configured filter instance
106
72
  *
107
- * @throws {FFmpegError} If filter creation or configuration fails
108
- * @throws {Error} If hardware filter requires hardware context but none provided
73
+ * @throws {Error} If filter creation or configuration fails
74
+ * @throws {FFmpegError} If graph parsing or config fails
109
75
  *
110
76
  * @example
111
77
  * ```typescript
112
- * // Simple filter
113
- * const filter = await FilterAPI.create('scale=640:480', videoStream);
78
+ * // Simple video filter
79
+ * const filter = await FilterAPI.create('scale=640:480', videoInfo);
80
+ * ```
114
81
  *
115
- * // Complex filter chain with hardware
116
- * const hw = await HardwareContext.auto();
117
- * const decoder = await Decoder.create(stream, { hardware: hw });
82
+ * @example
83
+ * ```typescript
84
+ * // Complex filter chain
118
85
  * const filter = await FilterAPI.create(
119
- * 'scale_vt=640:480,hwdownload,format=yuv420p',
120
- * decoder.getOutputStreamInfo(),
121
- * { hardware: hw }
86
+ * 'crop=640:480:0:0,rotate=PI/4',
87
+ * videoInfo
122
88
  * );
89
+ * ```
123
90
  *
124
- * // From StreamInfo (for raw data)
125
- * const filter = await FilterAPI.create('scale=640:480', {
126
- * type: 'video',
127
- * width: 1920,
128
- * height: 1080,
129
- * pixelFormat: AV_PIX_FMT_YUV420P,
130
- * timeBase: { num: 1, den: 30 }
131
- * });
91
+ * @example
92
+ * ```typescript
93
+ * // Audio filter
94
+ * const filter = await FilterAPI.create(
95
+ * 'volume=0.5,aecho=0.8:0.9:1000:0.3',
96
+ * audioInfo
97
+ * );
132
98
  * ```
99
+ *
100
+ * @see {@link process} For frame processing
101
+ * @see {@link FilterOptions} For configuration options
133
102
  */
134
103
  static create(description: string, input: StreamInfo, options?: FilterOptions): Promise<FilterAPI>;
135
104
  /**
136
- * Process a single frame through the filter.
137
- *
138
- * Sends a frame through the filter graph and returns the filtered result.
139
- * May return null if the filter needs more input frames.
105
+ * Process a frame through the filter.
140
106
  *
141
- * On first frame with hw_frames_ctx, initializes the filter graph (lazy initialization).
142
- * Subsequent frames are processed normally. FFmpeg automatically propagates
143
- * hw_frames_ctx through the filter chain.
107
+ * Applies filter operations to input frame.
108
+ * May buffer frames internally before producing output.
109
+ * For video, performs lazy initialization on first frame.
144
110
  *
145
- * @param frame - Input frame to filter
111
+ * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
146
112
  *
147
- * @returns Promise resolving to filtered frame or null if more input needed
113
+ * @param frame - Input frame to process
114
+ * @returns Filtered frame or null if buffered
148
115
  *
116
+ * @throws {Error} If filter not ready
149
117
  * @throws {FFmpegError} If processing fails
150
- * @throws {Error} If filter not initialized or hardware frame required but not provided
151
118
  *
152
119
  * @example
153
120
  * ```typescript
154
- * const outputFrame = await filter.process(inputFrame);
155
- * if (outputFrame) {
156
- * // Process the filtered frame
121
+ * const output = await filter.process(inputFrame);
122
+ * if (output) {
123
+ * console.log(`Got filtered frame: pts=${output.pts}`);
124
+ * output.free();
125
+ * }
126
+ * ```
127
+ *
128
+ * @example
129
+ * ```typescript
130
+ * // Process and drain
131
+ * const output = await filter.process(frame);
132
+ * if (output) yield output;
133
+ *
134
+ * // Drain buffered frames
135
+ * let buffered;
136
+ * while ((buffered = await filter.receive()) !== null) {
137
+ * yield buffered;
157
138
  * }
158
139
  * ```
140
+ *
141
+ * @see {@link receive} For draining buffered frames
142
+ * @see {@link frames} For stream processing
159
143
  */
160
144
  process(frame: Frame): Promise<Frame | null>;
161
145
  /**
162
- * Process multiple frames through the filter.
146
+ * Process multiple frames at once.
163
147
  *
164
- * Batch processing for better performance.
165
- * Returns all available output frames.
148
+ * Processes batch of frames and drains all output.
149
+ * Useful for filters that buffer multiple frames.
166
150
  *
167
151
  * @param frames - Array of input frames
152
+ * @returns Array of all output frames
168
153
  *
169
- * @returns Promise resolving to array of filtered frames
170
- *
154
+ * @throws {Error} If filter not ready
171
155
  * @throws {FFmpegError} If processing fails
172
156
  *
173
157
  * @example
174
158
  * ```typescript
175
- * const outputFrames = await filter.processMultiple(inputFrames);
159
+ * const outputs = await filter.processMultiple([frame1, frame2, frame3]);
160
+ * for (const output of outputs) {
161
+ * console.log(`Output frame: pts=${output.pts}`);
162
+ * output.free();
163
+ * }
176
164
  * ```
165
+ *
166
+ * @see {@link process} For single frame processing
177
167
  */
178
168
  processMultiple(frames: Frame[]): Promise<Frame[]>;
179
169
  /**
180
- * Receive a filtered frame without sending input.
170
+ * Receive buffered frame from filter.
171
+ *
172
+ * Drains frames buffered by the filter.
173
+ * Call repeatedly until null to get all buffered frames.
181
174
  *
182
- * Used to drain buffered frames from the filter.
183
- * Returns null when no more frames are available.
175
+ * Direct mapping to av_buffersink_get_frame().
184
176
  *
185
- * @returns Promise resolving to filtered frame or null
177
+ * @returns Buffered frame or null if none available
186
178
  *
187
- * @throws {FFmpegError} If receiving fails
179
+ * @throws {Error} If filter not ready
180
+ * @throws {FFmpegError} If receive fails
188
181
  *
189
182
  * @example
190
183
  * ```typescript
191
- * // Drain all buffered frames
192
- * while (true) {
193
- * const frame = await filter.receive();
194
- * if (!frame) break;
195
- * // Process frame
184
+ * // Drain buffered frames
185
+ * let frame;
186
+ * while ((frame = await filter.receive()) !== null) {
187
+ * console.log(`Buffered frame: pts=${frame.pts}`);
188
+ * frame.free();
196
189
  * }
197
190
  * ```
191
+ *
192
+ * @see {@link process} For input processing
193
+ * @see {@link flush} For end-of-stream
198
194
  */
199
195
  receive(): Promise<Frame | null>;
200
196
  /**
201
- * Flush the filter by sending null frame.
197
+ * Flush filter and signal end-of-stream.
202
198
  *
203
- * Signals end of stream to the filter.
204
- * Use receive() to get any remaining frames.
199
+ * Sends null frame to flush buffered data.
200
+ * Must call receive() to get flushed frames.
205
201
  *
206
- * @returns Promise resolving when flush is complete
202
+ * Direct mapping to av_buffersrc_add_frame(NULL).
207
203
  *
204
+ * @throws {Error} If filter not ready
208
205
  * @throws {FFmpegError} If flush fails
209
206
  *
210
207
  * @example
211
208
  * ```typescript
212
209
  * await filter.flush();
213
210
  * // Get remaining frames
214
- * while (true) {
215
- * const frame = await filter.receive();
216
- * if (!frame) break;
217
- * // Process final frames
211
+ * let frame;
212
+ * while ((frame = await filter.receive()) !== null) {
213
+ * frame.free();
218
214
  * }
219
215
  * ```
216
+ *
217
+ * @see {@link flushFrames} For async iteration
218
+ * @see {@link receive} For draining frames
220
219
  */
221
220
  flush(): Promise<void>;
222
221
  /**
223
- * Flush filter and yield all remaining frames as a generator.
222
+ * Flush filter and yield remaining frames.
224
223
  *
225
- * More convenient than calling flush() + receive() in a loop.
226
- * Automatically sends flush signal and yields all buffered frames.
224
+ * Convenient async generator for flushing.
225
+ * Combines flush and receive operations.
227
226
  *
228
- * @returns Async generator of remaining frames
229
- *
230
- * @throws {Error} If filter is not initialized
227
+ * @yields Remaining frames from filter
228
+ * @throws {Error} If filter not ready
229
+ * @throws {FFmpegError} If flush fails
231
230
  *
232
231
  * @example
233
232
  * ```typescript
234
- * // Process all remaining frames with generator
235
233
  * for await (const frame of filter.flushFrames()) {
236
- * // Process final frame
237
- * using _ = frame; // Auto cleanup
234
+ * console.log(`Flushed frame: pts=${frame.pts}`);
235
+ * frame.free();
238
236
  * }
239
237
  * ```
238
+ *
239
+ * @see {@link flush} For manual flush
240
+ * @see {@link frames} For complete pipeline
240
241
  */
241
242
  flushFrames(): AsyncGenerator<Frame>;
242
243
  /**
243
- * Process frames as an async generator.
244
+ * Process frame stream through filter.
244
245
  *
245
- * Provides a convenient iterator interface for filtering.
246
- * Automatically handles buffering and draining.
247
- * Input frames are automatically freed after processing.
246
+ * High-level async generator for filtering frame streams.
247
+ * Automatically handles buffering and flushing.
248
+ * Frees input frames after processing.
248
249
  *
249
- * IMPORTANT: The yielded frames MUST be freed by the caller!
250
- * Input frames are automatically freed after processing.
251
- *
252
- * @param frames - Async generator of input frames (will be freed automatically)
250
+ * @param frames - Async generator of input frames
251
+ * @yields Filtered frames
252
+ * @throws {Error} If filter not ready
253
+ * @throws {FFmpegError} If processing fails
253
254
  *
254
- * @returns Async generator of filtered frames (ownership transferred to caller)
255
+ * @example
256
+ * ```typescript
257
+ * // Filter decoded frames
258
+ * for await (const frame of filter.frames(decoder.frames(packets))) {
259
+ * await encoder.encode(frame);
260
+ * frame.free();
261
+ * }
262
+ * ```
255
263
  *
256
264
  * @example
257
265
  * ```typescript
258
- * for await (const filtered of filter.frames(decoder.frames())) {
259
- * // Process filtered frame
260
- * using _ = filtered; // Auto cleanup with using statement
266
+ * // Chain filters
267
+ * const filter1 = await FilterAPI.create('scale=640:480', info);
268
+ * const filter2 = await FilterAPI.create('rotate=PI/4', info);
269
+ *
270
+ * for await (const frame of filter2.frames(filter1.frames(input))) {
271
+ * // Process filtered frames
272
+ * frame.free();
261
273
  * }
262
274
  * ```
275
+ *
276
+ * @see {@link process} For single frame processing
277
+ * @see {@link flush} For end-of-stream handling
263
278
  */
264
279
  frames(frames: AsyncGenerator<Frame>): AsyncGenerator<Frame>;
265
280
  /**
266
- * Send a command to a filter in the graph.
281
+ * Send command to filter.
282
+ *
283
+ * Sends runtime command to specific filter in graph.
284
+ * Allows dynamic parameter adjustment.
267
285
  *
268
- * Allows runtime modification of filter parameters without recreating the graph.
269
- * Not all filters support commands - check filter documentation.
286
+ * Direct mapping to avfilter_graph_send_command().
270
287
  *
271
- * @param target - Filter name or "all" to send to all filters
272
- * @param cmd - Command name (e.g., "volume", "hue", "brightness")
273
- * @param arg - Command argument value
274
- * @param flags - Optional command flags
288
+ * @param target - Target filter name
289
+ * @param cmd - Command name
290
+ * @param arg - Command argument
291
+ * @param flags - Command flags
292
+ * @returns Response string from filter
275
293
  *
276
- * @returns Command response
294
+ * @throws {Error} If filter not ready
295
+ * @throws {FFmpegError} If command fails
277
296
  *
278
297
  * @example
279
298
  * ```typescript
280
- * // Change volume dynamically
299
+ * // Change volume at runtime
281
300
  * const response = filter.sendCommand('volume', 'volume', '0.5');
282
- * if (response) {
283
- * console.log('Volume changed successfully');
284
- * }
301
+ * console.log(`Volume changed: ${response}`);
285
302
  * ```
286
303
  *
287
- * @example
288
- * ```typescript
289
- * // Enable/disable all filters at runtime
290
- * filter.sendCommand('all', 'enable', 'expr=gte(t,10)');
291
- * ```
304
+ * @see {@link queueCommand} For delayed commands
292
305
  */
293
306
  sendCommand(target: string, cmd: string, arg: string, flags?: AVFilterCmdFlag): string;
294
307
  /**
295
- * Queue a command to be executed at a specific time.
308
+ * Queue command for later execution.
309
+ *
310
+ * Schedules command to execute at specific timestamp.
311
+ * Useful for synchronized parameter changes.
296
312
  *
297
- * Commands are executed when processing frames with matching timestamps.
298
- * Useful for scripted filter changes synchronized with media playback.
313
+ * Direct mapping to avfilter_graph_queue_command().
299
314
  *
300
- * @param target - Filter name or "all" to send to all filters
301
- * @param cmd - Command name (e.g., "volume", "hue", "brightness")
302
- * @param arg - Command argument value
303
- * @param ts - Timestamp when command should execute (in seconds)
304
- * @param flags - Optional command flags
315
+ * @param target - Target filter name
316
+ * @param cmd - Command name
317
+ * @param arg - Command argument
318
+ * @param ts - Timestamp for execution
319
+ * @param flags - Command flags
320
+ * @throws {Error} If filter not ready
321
+ * @throws {FFmpegError} If queue fails
305
322
  *
306
323
  * @example
307
324
  * ```typescript
308
- * // Schedule volume changes at specific times
309
- * filter.queueCommand('volume', 'volume', '0.5', 5.0); // At 5 seconds
310
- * filter.queueCommand('volume', 'volume', '0.8', 10.0); // At 10 seconds
311
- * filter.queueCommand('volume', 'volume', '0.2', 15.0); // At 15 seconds
325
+ * // Queue volume change at 10 seconds
326
+ * filter.queueCommand('volume', 'volume', '0.8', 10.0);
312
327
  * ```
328
+ *
329
+ * @see {@link sendCommand} For immediate commands
313
330
  */
314
331
  queueCommand(target: string, cmd: string, arg: string, ts: number, flags?: AVFilterCmdFlag): void;
315
332
  /**
316
- * Get the filter graph description.
333
+ * Get filter graph description.
317
334
  *
318
- * Returns a string representation of the filter graph in DOT format.
319
- * Useful for debugging and visualization.
335
+ * Returns human-readable graph structure.
336
+ * Useful for debugging filter chains.
337
+ *
338
+ * Direct mapping to avfilter_graph_dump().
320
339
  *
321
340
  * @returns Graph description or null if not initialized
322
341
  *
323
342
  * @example
324
343
  * ```typescript
325
344
  * const description = filter.getGraphDescription();
326
- * console.log(description);
345
+ * console.log('Filter graph:', description);
327
346
  * ```
328
347
  */
329
348
  getGraphDescription(): string | null;
330
349
  /**
331
- * Check if the filter is initialized and ready.
350
+ * Check if filter is ready for processing.
351
+ *
352
+ * @returns true if initialized and ready
332
353
  *
333
- * @returns true if the filter is ready for processing
354
+ * @example
355
+ * ```typescript
356
+ * if (filter.isReady()) {
357
+ * const output = await filter.process(frame);
358
+ * }
359
+ * ```
334
360
  */
335
361
  isReady(): boolean;
336
362
  /**
337
- * Get the media type of this filter.
363
+ * Get media type of filter.
364
+ *
365
+ * @returns AVMEDIA_TYPE_VIDEO or AVMEDIA_TYPE_AUDIO
338
366
  *
339
- * @returns The media type (video or audio)
367
+ * @example
368
+ * ```typescript
369
+ * if (filter.getMediaType() === AVMEDIA_TYPE_VIDEO) {
370
+ * console.log('Video filter');
371
+ * }
372
+ * ```
340
373
  */
341
374
  getMediaType(): AVMediaType;
342
375
  /**
343
- * Free all filter resources.
376
+ * Free filter resources.
344
377
  *
345
- * Releases the filter graph and all associated filters.
346
- * The filter instance cannot be used after calling this.
378
+ * Releases filter graph and contexts.
379
+ * Safe to call multiple times.
347
380
  *
348
381
  * @example
349
382
  * ```typescript
350
383
  * filter.free();
351
- * // filter is now invalid
352
384
  * ```
385
+ *
386
+ * @see {@link Symbol.dispose} For automatic cleanup
353
387
  */
354
388
  free(): void;
355
389
  /**
356
- * Initialize the filter graph.
390
+ * Initialize filter graph.
357
391
  *
358
- * Sets up buffer source, buffer sink, and parses the filter description.
359
- * Configures the graph for processing.
392
+ * Creates and configures filter graph components.
393
+ * For video, may use hardware frames context from first frame.
360
394
  *
361
- * For hardware inputs: Uses hw_frames_ctx from first frame
362
- * For software inputs: Initializes without hw_frames_ctx
363
- *
364
- * @internal
395
+ * @param firstFrame - First frame for hardware detection (video only)
396
+ * @throws {Error} If initialization fails
397
+ * @throws {FFmpegError} If configuration fails
365
398
  */
366
399
  private initialize;
367
400
  /**
368
401
  * Create buffer source with hardware frames context.
369
402
  *
370
- * @internal
403
+ * @param frame - Frame with hw_frames_ctx
404
+ * @throws {Error} If creation fails
405
+ * @throws {FFmpegError} If configuration fails
371
406
  */
372
407
  private createBufferSourceWithHwFrames;
373
408
  /**
374
- * Create and configure the buffer source filter without hw_frames_ctx.
409
+ * Create standard buffer source.
375
410
  *
376
- * @internal
411
+ * @throws {Error} If creation fails
377
412
  */
378
413
  private createBufferSource;
379
414
  /**
380
- * Create and configure the buffer sink filter.
415
+ * Create buffer sink.
381
416
  *
382
- * @internal
417
+ * @throws {Error} If creation fails
383
418
  */
384
419
  private createBufferSink;
385
420
  /**
386
- * Parse and connect the filter description.
421
+ * Parse filter description and build graph.
387
422
  *
388
- * @internal
423
+ * @param description - Filter description string
424
+ * @throws {Error} If parsing fails
425
+ * @throws {FFmpegError} If graph construction fails
389
426
  */
390
427
  private parseFilterDescription;
391
428
  /**
392
- * Check if hardware context is required for the filter chain.
393
- *
394
- * Validates that hardware context is provided when needed:
395
- * - hwupload: Always requires hardware context
396
- * - Hardware filters (AVFILTER_FLAG_HWDEVICE): Recommend hardware context
397
- * - hwdownload: Warns if input is not hardware format
429
+ * Check hardware requirements for filters.
398
430
  *
399
- * @internal
431
+ * @param description - Filter description
432
+ * @param options - Filter options
433
+ * @throws {Error} If hardware requirements not met
400
434
  */
401
435
  private checkHardwareRequirements;
402
436
  /**
403
- * Dispose of the filter.
437
+ * Dispose of filter.
404
438
  *
405
- * Implements the Disposable interface for automatic cleanup.
439
+ * Implements Disposable interface for automatic cleanup.
406
440
  * Equivalent to calling free().
407
441
  *
408
442
  * @example
409
443
  * ```typescript
410
444
  * {
411
- * using filter = await Filter.create('scale=1280:720', config);
412
- * // ... use filter
413
- * } // Automatically freed when leaving scope
445
+ * using filter = await FilterAPI.create('scale=640:480', info);
446
+ * // Use filter...
447
+ * } // Automatically freed
414
448
  * ```
449
+ *
450
+ * @see {@link free} For manual cleanup
415
451
  */
416
452
  [Symbol.dispose](): void;
417
453
  }