node-av 1.3.0 → 2.0.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 (45) hide show
  1. package/README.md +37 -38
  2. package/dist/api/bitstream-filter.d.ts +2 -2
  3. package/dist/api/bitstream-filter.js +2 -2
  4. package/dist/api/decoder.d.ts +131 -120
  5. package/dist/api/decoder.js +191 -203
  6. package/dist/api/decoder.js.map +1 -1
  7. package/dist/api/encoder.d.ts +135 -77
  8. package/dist/api/encoder.js +235 -192
  9. package/dist/api/encoder.js.map +1 -1
  10. package/dist/api/filter-presets.d.ts +408 -1534
  11. package/dist/api/filter-presets.js +1005 -2058
  12. package/dist/api/filter-presets.js.map +1 -1
  13. package/dist/api/filter.d.ts +160 -165
  14. package/dist/api/filter.js +294 -374
  15. package/dist/api/filter.js.map +1 -1
  16. package/dist/api/hardware.d.ts +8 -31
  17. package/dist/api/hardware.js +19 -70
  18. package/dist/api/hardware.js.map +1 -1
  19. package/dist/api/index.d.ts +1 -1
  20. package/dist/api/index.js +1 -1
  21. package/dist/api/index.js.map +1 -1
  22. package/dist/api/media-input.d.ts +1 -1
  23. package/dist/api/media-input.js +3 -8
  24. package/dist/api/media-input.js.map +1 -1
  25. package/dist/api/media-output.d.ts +35 -128
  26. package/dist/api/media-output.js +136 -208
  27. package/dist/api/media-output.js.map +1 -1
  28. package/dist/api/pipeline.d.ts +17 -17
  29. package/dist/api/pipeline.js +19 -42
  30. package/dist/api/pipeline.js.map +1 -1
  31. package/dist/api/types.d.ts +17 -57
  32. package/dist/lib/dictionary.d.ts +2 -2
  33. package/dist/lib/dictionary.js +2 -2
  34. package/dist/lib/dictionary.js.map +1 -1
  35. package/dist/lib/filter-context.d.ts +19 -2
  36. package/dist/lib/filter-context.js +15 -0
  37. package/dist/lib/filter-context.js.map +1 -1
  38. package/dist/lib/format-context.d.ts +18 -18
  39. package/dist/lib/format-context.js +20 -20
  40. package/dist/lib/format-context.js.map +1 -1
  41. package/dist/lib/frame.d.ts +43 -1
  42. package/dist/lib/frame.js +53 -0
  43. package/dist/lib/frame.js.map +1 -1
  44. package/package.json +17 -17
  45. package/release_notes.md +0 -29
@@ -1,4 +1,5 @@
1
- import type { AVHWDeviceType, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
1
+ import type { AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
2
+ import type { HardwareContext } from './hardware.js';
2
3
  /**
3
4
  * Hardware filter capabilities for different platforms.
4
5
  * Maps hardware types to their supported filter operations.
@@ -13,7 +14,7 @@ import type { AVHWDeviceType, AVPixelFormat, AVSampleFormat } from '../constants
13
14
  * - Vulkan: Cross-platform with growing filter support
14
15
  * - OpenCL: Cross-platform compute-based filtering
15
16
  */
16
- export interface HardwareFilterSupport {
17
+ export interface FilterSupport {
17
18
  scale: boolean;
18
19
  overlay: boolean;
19
20
  transpose: boolean;
@@ -29,134 +30,307 @@ export interface HardwareFilterSupport {
29
30
  stack: boolean;
30
31
  }
31
32
  /**
32
- * Base class for filter preset implementations.
33
- * Provides common filter building methods that can be overridden by hardware-specific implementations.
34
- *
35
- * This class defines the standard filter operations available in FFmpeg,
36
- * with each method returning a filter string that can be used in a filter graph.
37
- * Hardware-specific implementations may override these methods to use optimized
38
- * hardware filters instead of software implementations.
33
+ * Filter preset builder for composing filter chains.
34
+ * Supports both software and hardware-accelerated filters.
35
+ * Automatically selects appropriate filter implementations based on hardware context.
36
+ * Uses fluent interface pattern for chaining multiple filters.
39
37
  *
40
38
  * @example
41
39
  * ```typescript
42
- * class CustomPresets extends FilterPresetBase {
43
- * override scale(width: number, height: number): string | null {
44
- * return `custom_scale=${width}:${height}`;
45
- * }
46
- * }
40
+ * // Software filter chain
41
+ * const filter = FilterPreset.chain()
42
+ * .scale(1920, 1080)
43
+ * .fps(30)
44
+ * .fade('in', 0, 2)
45
+ * .build();
46
+ *
47
+ * // Hardware-accelerated filter chain
48
+ * const hw = HardwareContext.auto();
49
+ * const hwFilter = FilterPreset.chain(hw)
50
+ * .scale(1920, 1080)
51
+ * .blur('gaussian', 5)
52
+ * .build();
47
53
  * ```
48
54
  */
49
- export declare abstract class FilterPresetBase {
55
+ export declare class FilterPreset {
56
+ private hardware?;
57
+ private filters;
58
+ private support;
59
+ private constructor();
60
+ /**
61
+ * Checks if a filter is hardware-accelerated.
62
+ *
63
+ * @param filterName - Name of the filter to check
64
+ * @returns True if the filter uses hardware acceleration
65
+ *
66
+ * @example
67
+ * ```typescript
68
+ * if (FilterPreset.isHardwareFilter('scale_cuda')) {
69
+ * console.log('Hardware accelerated scaling');
70
+ * }
71
+ * ```
72
+ */
73
+ static isHardwareFilter(filterName: string): boolean;
74
+ /**
75
+ * Creates a new filter chain builder.
76
+ *
77
+ * @param hardware - Optional hardware context for hardware-accelerated filters
78
+ * @returns A new FilterPreset instance for chaining
79
+ *
80
+ * @example
81
+ * ```typescript
82
+ * // Software filter chain
83
+ * const filter = FilterPreset.chain()
84
+ * .scale(1280, 720)
85
+ * .fps(30)
86
+ * .build();
87
+ * ```
88
+ *
89
+ * @example
90
+ * ```typescript
91
+ * // Hardware filter chain
92
+ * const hw = HardwareContext.auto();
93
+ * const filter = FilterPreset.chain(hw)
94
+ * .scale(1280, 720)
95
+ * .deinterlace()
96
+ * .build();
97
+ * ```
98
+ */
99
+ static chain(hardware?: HardwareContext | null): FilterPreset;
100
+ /**
101
+ * Adds a custom filter string to the chain.
102
+ *
103
+ * @param filter - Custom filter string
104
+ * @returns This instance for chaining
105
+ *
106
+ * @example
107
+ * ```typescript
108
+ * chain.custom('myfilter=param1:param2')
109
+ * ```
110
+ */
111
+ custom(filter: string): this;
112
+ /**
113
+ * Builds the final filter string.
114
+ *
115
+ * @param separator - Separator between filters (default: ',')
116
+ * @returns Combined filter string
117
+ *
118
+ * @example
119
+ * ```typescript
120
+ * const filterString = chain.build() // "scale=1920:1080,fps=30"
121
+ * ```
122
+ */
123
+ build(separator?: string): string;
50
124
  /**
51
- * Creates a scale filter string.
125
+ * Returns the filters as an array.
126
+ *
127
+ * @returns Array of filter strings
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * const filters = chain.toArray() // ["scale=1920:1080", "fps=30"]
132
+ * ```
133
+ */
134
+ toArray(): string[];
135
+ /**
136
+ * Adds a scale filter to the chain.
137
+ * Automatically selects hardware-specific scaler if hardware context is set.
52
138
  *
53
139
  * @param width - Target width in pixels
54
140
  * @param height - Target height in pixels
55
- * @param options - Additional scaling options (e.g., flags for algorithm)
56
- * @returns Filter string or null if not supported
141
+ * @param options - Additional scaling options (e.g., flags for algorithm, npp for CUDA)
142
+ * @returns This instance for chaining
57
143
  *
58
144
  * @example
59
145
  * ```typescript
60
- * presets.scale(1920, 1080) // Scale to Full HD
61
- * presets.scale(640, 480, { flags: 'lanczos' }) // With specific algorithm
146
+ * chain.scale(1920, 1080) // Scale to Full HD
147
+ * chain.scale(640, 480, { flags: 'lanczos' }) // With specific algorithm
148
+ * chain.scale(1920, 1080, { npp: true }) // Use NPP for CUDA
62
149
  * ```
63
150
  *
64
151
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#scale | FFmpeg scale filter}
65
152
  */
66
- scale(width: number, height: number, options?: Record<string, any>): string | null;
153
+ scale(width: number, height: number, options?: Record<string, any>): FilterPreset;
67
154
  /**
68
- * Creates a crop filter string.
155
+ * Adds a crop filter to the chain.
69
156
  *
70
157
  * @param width - Width of the cropped area
71
158
  * @param height - Height of the cropped area
72
159
  * @param x - X coordinate of top-left corner (default: 0)
73
160
  * @param y - Y coordinate of top-left corner (default: 0)
74
- * @returns Filter string or null if not supported
161
+ * @returns This instance for chaining
75
162
  *
76
163
  * @example
77
164
  * ```typescript
78
- * presets.crop(640, 480, 100, 100) // Crop 640x480 area starting at (100,100)
79
- * presets.crop(1280, 720) // Crop from top-left corner
165
+ * chain.crop(640, 480, 100, 100) // Crop 640x480 area starting at (100,100)
166
+ * chain.crop(1280, 720) // Crop from top-left corner
80
167
  * ```
81
168
  *
82
169
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#crop | FFmpeg crop filter}
83
170
  */
84
- crop(width: number, height: number, x?: number, y?: number): string | null;
171
+ crop(width: number, height: number, x?: number, y?: number): FilterPreset;
172
+ /**
173
+ * Adds a blur filter to the chain (hardware-specific).
174
+ * Only available for hardware presets that support blur
175
+ *
176
+ * @param type - Blur type (default: 'avg')
177
+ * @param radius - Blur radius (optional)
178
+ *
179
+ * @returns This instance for chaining
180
+ *
181
+ * @example
182
+ * ```typescript
183
+ * const chain = FilterPresets.chain()
184
+ * .blur('gaussian', 5)
185
+ * .build();
186
+ * ```
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * const chain = FilterPresets.chain()
191
+ * .blur('box')
192
+ * .build();
193
+ * ```
194
+ */
195
+ blur(type?: 'avg' | 'gaussian' | 'box', radius?: number): FilterPreset;
196
+ /**
197
+ * Adds a sharpen filter to the chain (hardware-specific).
198
+ * Only available for hardware presets that support sharpening
199
+ *
200
+ * @param amount - Sharpen amount (optional)
201
+ *
202
+ * @returns This instance for chaining
203
+ *
204
+ * @example
205
+ * ```typescript
206
+ * const chain = FilterPresets.chain()
207
+ * .sharpen(1.5)
208
+ * .build();
209
+ * ```
210
+ *
211
+ * @example
212
+ * ```typescript
213
+ * const chain = FilterPresets.chain()
214
+ * .sharpen()
215
+ * .build();
216
+ * ```
217
+ */
218
+ sharpen(amount?: number): FilterPreset;
85
219
  /**
86
- * Creates an FPS filter string to change frame rate.
220
+ * Adds an FPS filter to change frame rate.
87
221
  *
88
222
  * @param fps - Target frames per second
89
- * @returns Filter string or null if not supported
223
+ * @returns This instance for chaining
90
224
  *
91
225
  * @example
92
226
  * ```typescript
93
- * presets.fps(30) // Convert to 30 FPS
94
- * presets.fps(23.976) // Film frame rate
227
+ * chain.fps(30) // Convert to 30 FPS
228
+ * chain.fps(23.976) // Film frame rate
95
229
  * ```
96
230
  *
97
231
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#fps | FFmpeg fps filter}
98
232
  */
99
- fps(fps: number): string | null;
233
+ fps(fps: number): FilterPreset;
100
234
  /**
101
- * Creates a format filter string to convert pixel format.
235
+ * Adds a format filter to convert pixel format.
102
236
  *
103
- * @param pixelFormat - Target pixel format(s) - can be string, AVPixelFormat enum, or array
104
- * @returns Filter string or null if not supported
237
+ * @param pixelFormat - Target pixel format(s) - AVPixelFormat enum, or array
238
+ * @returns This instance for chaining
105
239
  *
106
240
  * @example
107
241
  * ```typescript
108
242
  * // Single format
109
- * presets.format('yuv420p');
110
- * presets.format(AV_PIX_FMT_YUV420P);
243
+ * chain.format(AV_PIX_FMT_YUV420P);
111
244
  *
112
- * // Multiple formats (creates a chain)
113
- * presets.format(['yuv420p', 'rgb24']);
245
+ * // Multiple formats (tries formats in order)
246
+ * chain.format([AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24]);
114
247
  * ```
115
248
  *
116
249
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#format | FFmpeg format filter}
117
250
  */
118
- format(pixelFormat: string | AVPixelFormat | (string | AVPixelFormat)[]): string | null;
251
+ format(pixelFormat: AVPixelFormat | AVPixelFormat[]): FilterPreset;
119
252
  /**
120
- * Creates a rotate filter string.
253
+ * Adds a rotate filter to the chain.
121
254
  *
122
255
  * @param angle - Rotation angle in degrees
123
- * @returns Filter string or null if not supported
256
+ * @returns This instance for chaining
124
257
  *
125
258
  * @example
126
259
  * ```typescript
127
- * presets.rotate(90) // Rotate 90 degrees clockwise
128
- * presets.rotate(-45) // Rotate 45 degrees counter-clockwise
260
+ * chain.rotate(90) // Rotate 90 degrees clockwise
261
+ * chain.rotate(-45) // Rotate 45 degrees counter-clockwise
129
262
  * ```
130
263
  *
131
264
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#rotate | FFmpeg rotate filter}
132
265
  */
133
- rotate(angle: number): string | null;
266
+ rotate(angle: number): FilterPreset;
134
267
  /**
135
- * Creates a horizontal flip filter string.
268
+ * Adds a flip filter to the chain (hardware-specific).
269
+ * Falls back to hflip/vflip if hardware flip not available
136
270
  *
137
- * @returns Filter string or null if not supported
271
+ * @param direction - Flip direction ('h' or 'v')
272
+ *
273
+ * @returns This instance for chaining
138
274
  *
139
275
  * @example
140
276
  * ```typescript
141
- * presets.hflip() // Mirror horizontally
277
+ * const chain = FilterPresets.chain()
278
+ * .flip('h')
279
+ * .build();
142
280
  * ```
143
281
  *
144
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hflip | FFmpeg hflip filter}
282
+ * @example
283
+ * ```typescript
284
+ * const chain = FilterPresets.chain()
285
+ * .flip('v')
286
+ * .build();
287
+ * ```
145
288
  */
146
- hflip(): string | null;
289
+ flip(direction: 'h' | 'v'): FilterPreset;
147
290
  /**
148
- * Creates a vertical flip filter string.
291
+ * Adds a stack filter to the chain (hardware-specific).
292
+ * Only available for hardware presets that support stacking
149
293
  *
150
- * @returns Filter string or null if not supported
294
+ * @param type - Stack type ('h' for horizontal, 'v' for vertical, 'x' for grid)
295
+ * @param inputs - Number of inputs (default: 2)
296
+ *
297
+ * @returns This instance for chaining
298
+ *
299
+ * @example
300
+ * ```typescript
301
+ * const chain = FilterPresets.chain()
302
+ * .stack('h', 2)
303
+ * .build();
304
+ * ```
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * const chain = FilterPresets.chain()
309
+ * .stack('x', 4)
310
+ * .build();
311
+ * ```
312
+ */
313
+ stack(type: 'h' | 'v' | 'x', inputs?: number): FilterPreset;
314
+ /**
315
+ * Creates a tonemap filter.
316
+ * Used for HDR to SDR conversion with hardware acceleration.
317
+ *
318
+ * @param alg - Tonemapping algorithm (e.g., 'hable', 'reinhard', 'mobius', etc.)
319
+ * @param options - Tonemapping options
320
+ *
321
+ * @returns Hardware tonemap filter string or null if not supported
151
322
  *
152
323
  * @example
153
324
  * ```typescript
154
- * presets.vflip() // Flip upside down
325
+ * const filter = hwPresets.tonemap();
155
326
  * ```
156
327
  *
157
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#vflip | FFmpeg vflip filter}
328
+ * @example
329
+ * ```typescript
330
+ * const filter = hwPresets.tonemap({ tonemap: 'hable', desat: '0' });
331
+ * ```
158
332
  */
159
- vflip(): string | null;
333
+ tonemap(alg: string, options: Record<string, string | number>): FilterPreset;
160
334
  /**
161
335
  * Creates a fade filter string for video.
162
336
  *
@@ -173,7 +347,7 @@ export declare abstract class FilterPresetBase {
173
347
  *
174
348
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#fade | FFmpeg fade filter}
175
349
  */
176
- fade(type: 'in' | 'out', start: number, duration: number): string | null;
350
+ fade(type: 'in' | 'out', start: number, duration: number): FilterPreset;
177
351
  /**
178
352
  * Creates an overlay filter string to composite two video streams.
179
353
  *
@@ -193,7 +367,7 @@ export declare abstract class FilterPresetBase {
193
367
  *
194
368
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#overlay | FFmpeg overlay filter}
195
369
  */
196
- overlay(x?: number, y?: number, options?: Record<string, string>): string | null;
370
+ overlay(x?: number, y?: number, options?: Record<string, string>): FilterPreset;
197
371
  /**
198
372
  * Creates a volume filter string for audio.
199
373
  *
@@ -208,7 +382,7 @@ export declare abstract class FilterPresetBase {
208
382
  *
209
383
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#volume | FFmpeg volume filter}
210
384
  */
211
- volume(factor: number): string | null;
385
+ volume(factor: number): FilterPreset;
212
386
  /**
213
387
  * Creates an audio format filter string.
214
388
  *
@@ -231,78 +405,93 @@ export declare abstract class FilterPresetBase {
231
405
  *
232
406
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aformat | FFmpeg aformat filter}
233
407
  */
234
- aformat(sampleFormat: string | AVSampleFormat, sampleRate?: number, channelLayout?: string): string | null;
408
+ aformat(sampleFormat: AVSampleFormat | AVSampleFormat[], sampleRate?: number, channelLayout?: string): FilterPreset;
235
409
  /**
236
- * Creates an asetnsamples filter string to set the number of samples per frame.
410
+ * Adds an asetnsamples filter to set the number of samples per frame.
237
411
  * This is crucial for encoders like Opus that require specific frame sizes.
238
412
  *
239
413
  * @param samples - Number of samples per frame
240
414
  * @param padding - Whether to pad or drop samples (default: true)
241
- * @returns Filter string or null if not supported
415
+ * @returns This instance for chaining
242
416
  *
243
417
  * @example
244
418
  * ```typescript
245
419
  * // For Opus encoder (requires 960 samples)
246
- * presets.asetnsamples(960);
420
+ * chain.asetnsamples(960);
247
421
  *
248
422
  * // Drop samples instead of padding
249
- * presets.asetnsamples(1024, false);
423
+ * chain.asetnsamples(1024, false);
250
424
  * ```
251
425
  *
252
426
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#asetnsamples | FFmpeg asetnsamples filter}
253
427
  */
254
- asetnsamples(samples: number, padding?: boolean): string | null;
428
+ asetnsamples(samples: number, padding?: boolean): FilterPreset;
429
+ /**
430
+ * Adds an aresample filter to change audio sample rate.
431
+ *
432
+ * @param rate - Target sample rate in Hz
433
+ * @returns This instance for chaining
434
+ *
435
+ * @example
436
+ * ```typescript
437
+ * chain.aresample(44100) // Convert to 44.1 kHz
438
+ * chain.aresample(48000) // Convert to 48 kHz
439
+ * ```
440
+ *
441
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aresample | FFmpeg aresample filter}
442
+ */
443
+ aresample(rate: number): FilterPreset;
255
444
  /**
256
- * Creates an atempo filter string to change audio playback speed.
445
+ * Adds an atempo filter to change audio playback speed.
257
446
  * Factor must be between 0.5 and 2.0. For larger changes, chain multiple atempo filters.
258
447
  *
259
448
  * @param factor - Tempo factor (0.5 = half speed, 2.0 = double speed)
260
- * @returns Filter string or null if not supported
449
+ * @returns This instance for chaining
261
450
  *
262
451
  * @example
263
452
  * ```typescript
264
- * presets.atempo(1.5) // 1.5x speed
265
- * presets.atempo(0.8) // Slow down to 80% speed
453
+ * chain.atempo(1.5) // 1.5x speed
454
+ * chain.atempo(0.8) // Slow down to 80% speed
266
455
  * ```
267
456
  *
268
457
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#atempo | FFmpeg atempo filter}
269
458
  */
270
- atempo(factor: number): string | null;
459
+ atempo(factor: number): FilterPreset;
271
460
  /**
272
- * Creates an audio fade filter string.
461
+ * Adds an audio fade filter.
273
462
  *
274
463
  * @param type - Fade type ('in' or 'out')
275
464
  * @param start - Start time in seconds
276
465
  * @param duration - Fade duration in seconds
277
- * @returns Filter string or null if not supported
466
+ * @returns This instance for chaining
278
467
  *
279
468
  * @example
280
469
  * ```typescript
281
- * presets.afade('in', 0, 3) // 3-second audio fade in
282
- * presets.afade('out', 20, 2) // 2-second fade out at 20s
470
+ * chain.afade('in', 0, 3) // 3-second audio fade in
471
+ * chain.afade('out', 20, 2) // 2-second fade out at 20s
283
472
  * ```
284
473
  *
285
474
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#afade | FFmpeg afade filter}
286
475
  */
287
- afade(type: 'in' | 'out', start: number, duration: number): string | null;
476
+ afade(type: 'in' | 'out', start: number, duration: number): FilterPreset;
288
477
  /**
289
- * Creates an amix filter string to mix multiple audio streams.
478
+ * Adds an amix filter to mix multiple audio streams.
290
479
  *
291
480
  * @param inputs - Number of input streams to mix (default: 2)
292
481
  * @param duration - How to determine output duration (default: 'longest')
293
- * @returns Filter string or null if not supported
482
+ * @returns This instance for chaining
294
483
  *
295
484
  * @example
296
485
  * ```typescript
297
- * presets.amix(3, 'longest') // Mix 3 audio streams
298
- * presets.amix(2, 'first') // Mix 2 streams, use first's duration
486
+ * chain.amix(3, 'longest') // Mix 3 audio streams
487
+ * chain.amix(2, 'first') // Mix 2 streams, use first's duration
299
488
  * ```
300
489
  *
301
490
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#amix | FFmpeg amix filter}
302
491
  */
303
- amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): string | null;
492
+ amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): FilterPreset;
304
493
  /**
305
- * Creates a pad filter string to add padding to video.
494
+ * Adds a pad filter to add padding to video.
306
495
  * Essential for aspect ratio adjustments and letterboxing.
307
496
  *
308
497
  * @param width - Output width (can use expressions like 'iw+100')
@@ -310,38 +499,38 @@ export declare abstract class FilterPresetBase {
310
499
  * @param x - X position of input video (default: '(ow-iw)/2' for center)
311
500
  * @param y - Y position of input video (default: '(oh-ih)/2' for center)
312
501
  * @param color - Padding color (default: 'black')
313
- * @returns Filter string or null if not supported
502
+ * @returns This instance for chaining
314
503
  *
315
504
  * @example
316
505
  * ```typescript
317
506
  * // Add black bars for 16:9 aspect ratio
318
- * presets.pad('iw', 'iw*9/16');
507
+ * chain.pad('iw', 'iw*9/16');
319
508
  *
320
509
  * // Add 50px padding on all sides
321
- * presets.pad('iw+100', 'ih+100');
510
+ * chain.pad('iw+100', 'ih+100');
322
511
  * ```
323
512
  *
324
513
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#pad | FFmpeg pad filter}
325
514
  */
326
- pad(width: string | number, height: string | number, x?: string, y?: string, color?: string): string | null;
515
+ pad(width: string | number, height: string | number, x?: string, y?: string, color?: string): FilterPreset;
327
516
  /**
328
- * Creates a trim filter string to cut a portion of the stream.
517
+ * Adds a trim filter to cut a portion of the stream.
329
518
  * Crucial for cutting segments from media.
330
519
  *
331
520
  * @param start - Start time in seconds
332
521
  * @param end - End time in seconds (optional)
333
522
  * @param duration - Duration in seconds (optional, alternative to end)
334
- * @returns Filter string or null if not supported
523
+ * @returns This instance for chaining
335
524
  *
336
525
  * @example
337
526
  * ```typescript
338
- * presets.trim(10, 30) // Extract from 10s to 30s
339
- * presets.trim(5, undefined, 10) // Extract 10s starting at 5s
527
+ * chain.trim(10, 30) // Extract from 10s to 30s
528
+ * chain.trim(5, undefined, 10) // Extract 10s starting at 5s
340
529
  * ```
341
530
  *
342
531
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#trim | FFmpeg trim filter}
343
532
  */
344
- trim(start: number, end?: number, duration?: number): string | null;
533
+ trim(start: number, end?: number, duration?: number): FilterPreset;
345
534
  /**
346
535
  * Creates a setpts filter string to change presentation timestamps.
347
536
  * Essential for speed changes and timestamp manipulation.
@@ -363,7 +552,7 @@ export declare abstract class FilterPresetBase {
363
552
  *
364
553
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#setpts | FFmpeg setpts filter}
365
554
  */
366
- setpts(expression: string): string | null;
555
+ setpts(expression: string): FilterPreset;
367
556
  /**
368
557
  * Creates an asetpts filter string for audio timestamp manipulation.
369
558
  *
@@ -377,7 +566,7 @@ export declare abstract class FilterPresetBase {
377
566
  *
378
567
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#asetpts | FFmpeg asetpts filter}
379
568
  */
380
- asetpts(expression: string): string | null;
569
+ asetpts(expression: string): FilterPreset;
381
570
  /**
382
571
  * Creates a transpose filter string for rotation/flipping.
383
572
  * More efficient than rotate for 90-degree rotations.
@@ -393,7 +582,7 @@ export declare abstract class FilterPresetBase {
393
582
  *
394
583
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#transpose | FFmpeg transpose filter}
395
584
  */
396
- transpose(mode: number | 'clock' | 'cclock' | 'clock_flip' | 'cclock_flip'): string | null;
585
+ transpose(mode: number | 'clock' | 'cclock' | 'clock_flip' | 'cclock_flip'): FilterPreset;
397
586
  /**
398
587
  * Creates a setsar filter string to set sample aspect ratio.
399
588
  * Important for correcting aspect ratio issues.
@@ -409,7 +598,7 @@ export declare abstract class FilterPresetBase {
409
598
  *
410
599
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#setsar | FFmpeg setsar/setdar filter}
411
600
  */
412
- setsar(ratio: string | number): string | null;
601
+ setsar(ratio: string | number): FilterPreset;
413
602
  /**
414
603
  * Creates a setdar filter string to set display aspect ratio.
415
604
  *
@@ -424,29 +613,30 @@ export declare abstract class FilterPresetBase {
424
613
  *
425
614
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#setsar | FFmpeg setsar/setdar filter}
426
615
  */
427
- setdar(ratio: string | number): string | null;
616
+ setdar(ratio: string | number): FilterPreset;
428
617
  /**
429
- * Creates an apad filter string to add audio padding.
618
+ * Adds an apad filter to add audio padding.
430
619
  * Useful for ensuring minimum audio duration.
431
620
  *
432
621
  * @param wholeDuration - Minimum duration in seconds (optional)
433
622
  * @param padDuration - Amount of padding to add in seconds (optional)
434
- * @returns Filter string or null if not supported
623
+ * @returns This instance for chaining
435
624
  *
436
625
  * @example
437
626
  * ```typescript
438
- * presets.apad(30) // Ensure at least 30 seconds total
439
- * presets.apad(undefined, 5) // Add 5 seconds of padding
627
+ * chain.apad(30) // Ensure at least 30 seconds total
628
+ * chain.apad(undefined, 5) // Add 5 seconds of padding
440
629
  * ```
441
630
  *
442
631
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#apad | FFmpeg apad filter}
443
632
  */
444
- apad(wholeDuration?: number, padDuration?: number): string | null;
633
+ apad(wholeDuration?: number, padDuration?: number): FilterPreset;
445
634
  /**
446
635
  * Creates a deinterlace filter string.
447
636
  * Essential for processing interlaced content.
448
637
  *
449
638
  * @param mode - Deinterlace mode (default: 'yadif')
639
+ * @param options - Additional options for the filter
450
640
  * @returns Filter string or null if not supported
451
641
  *
452
642
  * @example
@@ -457,7 +647,7 @@ export declare abstract class FilterPresetBase {
457
647
  *
458
648
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#yadif | FFmpeg yadif filter}
459
649
  */
460
- deinterlace(mode?: 'yadif' | 'bwdif' | 'w3fdif'): string | null;
650
+ deinterlace(mode?: 'yadif' | 'bwdif' | 'w3fdif', options?: Record<string, any>): FilterPreset;
461
651
  /**
462
652
  * Creates a select filter string to select specific frames.
463
653
  * Powerful for extracting keyframes, specific frame types, etc.
@@ -473,7 +663,7 @@ export declare abstract class FilterPresetBase {
473
663
  *
474
664
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#select | FFmpeg select filter}
475
665
  */
476
- select(expression: string): string | null;
666
+ select(expression: string): FilterPreset;
477
667
  /**
478
668
  * Creates an aselect filter string for audio selection.
479
669
  *
@@ -487,7 +677,7 @@ export declare abstract class FilterPresetBase {
487
677
  *
488
678
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aselect | FFmpeg aselect filter}
489
679
  */
490
- aselect(expression: string): string | null;
680
+ aselect(expression: string): FilterPreset;
491
681
  /**
492
682
  * Creates a concat filter string to concatenate multiple inputs.
493
683
  * Essential for joining multiple video/audio segments.
@@ -505,7 +695,7 @@ export declare abstract class FilterPresetBase {
505
695
  *
506
696
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#concat | FFmpeg concat filter}
507
697
  */
508
- concat(n: number, v?: number, a?: number): string | null;
698
+ concat(n: number, v?: number, a?: number): FilterPreset;
509
699
  /**
510
700
  * Creates an amerge filter string to merge multiple audio streams into one.
511
701
  * Different from amix - this creates multi-channel output.
@@ -521,7 +711,7 @@ export declare abstract class FilterPresetBase {
521
711
  *
522
712
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#amerge | FFmpeg amerge filter}
523
713
  */
524
- amerge(inputs?: number): string | null;
714
+ amerge(inputs?: number): FilterPreset;
525
715
  /**
526
716
  * Creates a channelmap filter string to remap audio channels.
527
717
  * Critical for audio channel manipulation.
@@ -537,7 +727,7 @@ export declare abstract class FilterPresetBase {
537
727
  *
538
728
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#channelmap | FFmpeg channelmap filter}
539
729
  */
540
- channelmap(map: string): string | null;
730
+ channelmap(map: string): FilterPreset;
541
731
  /**
542
732
  * Creates a channelsplit filter string to split audio channels.
543
733
  *
@@ -552,7 +742,7 @@ export declare abstract class FilterPresetBase {
552
742
  *
553
743
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#channelsplit | FFmpeg channelsplit filter}
554
744
  */
555
- channelsplit(channelLayout?: string): string | null;
745
+ channelsplit(channelLayout?: string): FilterPreset;
556
746
  /**
557
747
  * Creates a loudnorm filter string for loudness normalization.
558
748
  * Essential for broadcast compliance and consistent audio levels.
@@ -570,7 +760,7 @@ export declare abstract class FilterPresetBase {
570
760
  *
571
761
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#loudnorm | FFmpeg loudnorm filter}
572
762
  */
573
- loudnorm(I?: number, TP?: number, LRA?: number): string | null;
763
+ loudnorm(I?: number, TP?: number, LRA?: number): FilterPreset;
574
764
  /**
575
765
  * Creates a compand filter string for audio compression/expansion.
576
766
  * Important for dynamic range control.
@@ -588,1577 +778,261 @@ export declare abstract class FilterPresetBase {
588
778
  *
589
779
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#compand | FFmpeg compand filter}
590
780
  */
591
- compand(attacks: string, decays: string, points: string, gain?: number): string | null;
592
- }
593
- /**
594
- * Filter chain builder for composing multiple filters.
595
- * Allows fluent API for building complex filter graphs by chaining filter operations.
596
- *
597
- * @example
598
- * ```typescript
599
- * const chain = new FilterChain()
600
- * .add('scale=1920:1080')
601
- * .add('fps=30')
602
- * .custom('rotate=45*PI/180')
603
- * .build();
604
- * // Result: "scale=1920:1080,fps=30,rotate=45*PI/180"
605
- * ```
606
- */
607
- export declare class FilterChain {
608
- private filters;
781
+ compand(attacks: string, decays: string, points: string, gain?: number): FilterPreset;
609
782
  /**
610
- * Adds a filter to the chain.
783
+ * Adds a drawtext filter to overlay text on video.
611
784
  *
612
- * @param filter - Filter string to add (ignored if null/undefined)
785
+ * @param text - Text to display
786
+ * @param options - Text rendering options
613
787
  * @returns This instance for chaining
614
788
  *
615
789
  * @example
616
790
  * ```typescript
617
- * chain.add('scale=1920:1080')
791
+ * chain.drawtext('Hello World', { x: 10, y: 10, fontsize: 24 })
792
+ * chain.drawtext('Timestamp', {
793
+ * x: 10,
794
+ * y: 10,
795
+ * fontsize: 24,
796
+ * fontcolor: 'white',
797
+ * fontfile: '/path/to/font.ttf'
798
+ * })
618
799
  * ```
800
+ *
801
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#drawtext | FFmpeg drawtext filter}
619
802
  */
620
- add(filter: string | null | undefined): this;
803
+ drawtext(text: string, options: Record<string, any>): FilterPreset;
621
804
  /**
622
- * Adds a custom filter string to the chain.
805
+ * Adds a split filter to duplicate a video stream.
623
806
  *
624
- * @param filter - Custom filter string
807
+ * @param outputs - Number of output streams (default: 2)
625
808
  * @returns This instance for chaining
626
809
  *
627
810
  * @example
628
811
  * ```typescript
629
- * chain.custom('myfilter=param1:param2')
812
+ * chain.split() // Split into 2 outputs
813
+ * chain.split(3) // Split into 3 outputs
630
814
  * ```
815
+ *
816
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#split | FFmpeg split filter}
631
817
  */
632
- custom(filter: string): this;
818
+ split(outputs?: number): FilterPreset;
633
819
  /**
634
- * Builds the final filter string.
820
+ * Adds an asplit filter to duplicate an audio stream.
635
821
  *
636
- * @param separator - Separator between filters (default: ',')
637
- * @returns Combined filter string
822
+ * @param outputs - Number of output streams (default: 2)
823
+ * @returns This instance for chaining
638
824
  *
639
825
  * @example
640
826
  * ```typescript
641
- * const filterString = chain.build() // "scale=1920:1080,fps=30"
827
+ * chain.asplit() // Split into 2 outputs
828
+ * chain.asplit(3) // Split into 3 outputs
642
829
  * ```
830
+ *
831
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#asplit | FFmpeg asplit filter}
643
832
  */
644
- build(separator?: string): string;
833
+ asplit(outputs?: number): FilterPreset;
645
834
  /**
646
- * Returns the filters as an array.
835
+ * Adds an adelay filter to delay audio by specified milliseconds.
647
836
  *
648
- * @returns Array of filter strings
837
+ * @param delays - Delay in milliseconds (single value or array for multiple channels)
838
+ * @returns This instance for chaining
649
839
  *
650
840
  * @example
651
841
  * ```typescript
652
- * const filters = chain.toArray() // ["scale=1920:1080", "fps=30"]
842
+ * chain.adelay(100) // Delay all channels by 100ms
843
+ * chain.adelay([100, 200]) // Delay first channel by 100ms, second by 200ms
653
844
  * ```
845
+ *
846
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#adelay | FFmpeg adelay filter}
654
847
  */
655
- toArray(): string[];
656
- }
657
- /**
658
- * Base chain builder with common filter methods.
659
- * Provides a fluent API for building filter chains using preset methods.
660
- *
661
- * @template T The preset type this builder uses
662
- *
663
- * @example
664
- * ```typescript
665
- * const chain = new ChainBuilderBase(presets)
666
- * .scale(1920, 1080)
667
- * .fps(30)
668
- * .fade('in', 0, 2)
669
- * .build();
670
- * ```
671
- */
672
- export declare abstract class ChainBuilderBase<T extends FilterPresetBase> extends FilterChain {
673
- protected readonly presets: T;
674
- /**
675
- * @param presets - The filter presets to use
676
- * @internal
677
- */
678
- constructor(presets: T);
848
+ adelay(delays: number | number[]): FilterPreset;
679
849
  /**
680
- * Adds a scale filter to the chain.
681
- *
682
- * @param width - Target width
683
- * @param height - Target height
684
- * @param options - Additional scaling options
850
+ * Adds an aecho filter for audio echo effect.
685
851
  *
852
+ * @param in_gain - Input gain (0-1)
853
+ * @param out_gain - Output gain (0-1)
854
+ * @param delays - Delay in milliseconds
855
+ * @param decays - Decay factor (0-1)
686
856
  * @returns This instance for chaining
687
857
  *
688
858
  * @example
689
859
  * ```typescript
690
- * const chain = FilterPresets.chain()
691
- * .scale(1920, 1080)
692
- * .build();
860
+ * chain.aecho(0.8, 0.9, 1000, 0.3) // Echo with 1 second delay
693
861
  * ```
694
862
  *
695
- * @example
696
- * ```typescript
697
- * const chain = FilterPresets.chain()
698
- * .scale(1280, 720, { flags: 'lanczos' })
699
- * .build();
700
- * ```
701
- *
702
- * @see {@link FilterPresetBase.scale}
703
- */
704
- scale(width: number, height: number, options?: Record<string, any>): this;
705
- /**
706
- * Adds a crop filter to the chain.
707
- *
708
- * @param width - Crop width
709
- * @param height - Crop height
710
- * @param x - X position (default: 0)
711
- * @param y - Y position (default: 0)
712
- *
713
- * @returns This instance for chaining
714
- *
715
- * @example
716
- * ```typescript
717
- * const chain = FilterPresets.chain()
718
- * .crop(640, 480)
719
- * .build();
720
- * ```
721
- *
722
- * @example
723
- * ```typescript
724
- * const chain = FilterPresets.chain()
725
- * .crop(1920, 1080, 100, 50)
726
- * .build();
727
- * ```
728
- *
729
- * @see {@link FilterPresetBase.crop}
863
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aecho | FFmpeg aecho filter}
730
864
  */
731
- crop(width: number, height: number, x?: number, y?: number): this;
865
+ aecho(in_gain: number, out_gain: number, delays: number, decays: number): FilterPreset;
732
866
  /**
733
- * Adds an FPS filter to the chain.
734
- *
735
- * @param fps - Target frame rate
867
+ * Adds a highpass filter to remove low frequencies.
736
868
  *
869
+ * @param frequency - Cutoff frequency in Hz
870
+ * @param options - Additional filter options
737
871
  * @returns This instance for chaining
738
872
  *
739
873
  * @example
740
874
  * ```typescript
741
- * const chain = FilterPresets.chain()
742
- * .fps(30)
743
- * .build();
744
- * ```
745
- *
746
- * @example
747
- * ```typescript
748
- * const chain = FilterPresets.chain()
749
- * .fps(23.976)
750
- * .build();
875
+ * chain.highpass(200) // Remove frequencies below 200Hz
876
+ * chain.highpass(200, { width_type: 'q', width: 1 })
751
877
  * ```
752
878
  *
753
- * @see {@link FilterPresetBase.fps}
879
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#highpass | FFmpeg highpass filter}
754
880
  */
755
- fps(fps: number): this;
881
+ highpass(frequency: number, options?: Record<string, any>): FilterPreset;
756
882
  /**
757
- * Adds a format filter to the chain.
758
- *
759
- * @param pixelFormat - Target pixel format(s)
883
+ * Adds a lowpass filter to remove high frequencies.
760
884
  *
885
+ * @param frequency - Cutoff frequency in Hz
886
+ * @param options - Additional filter options
761
887
  * @returns This instance for chaining
762
888
  *
763
889
  * @example
764
890
  * ```typescript
765
- * const chain = FilterPresets.chain()
766
- * .format('yuv420p')
767
- * .build();
768
- * ```
769
- *
770
- * @example
771
- * ```typescript
772
- * const chain = FilterPresets.chain()
773
- * .format(AV_PIX_FMT_RGB24)
774
- * .build();
891
+ * chain.lowpass(5000) // Remove frequencies above 5000Hz
775
892
  * ```
776
893
  *
777
- * @see {@link FilterPresetBase.format}
894
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#lowpass | FFmpeg lowpass filter}
778
895
  */
779
- format(pixelFormat: string | AVPixelFormat | (string | AVPixelFormat)[]): this;
896
+ lowpass(frequency: number, options?: Record<string, any>): FilterPreset;
780
897
  /**
781
- * Adds a rotate filter to the chain.
782
- *
783
- * @param angle - Rotation angle in degrees
898
+ * Adds a bandpass filter to keep only a frequency band.
784
899
  *
900
+ * @param frequency - Center frequency in Hz
901
+ * @param options - Additional filter options
785
902
  * @returns This instance for chaining
786
903
  *
787
904
  * @example
788
905
  * ```typescript
789
- * const chain = FilterPresets.chain()
790
- * .rotate(45)
791
- * .build();
792
- * ```
793
- *
794
- * @example
795
- * ```typescript
796
- * const chain = FilterPresets.chain()
797
- * .rotate(-90)
798
- * .build();
906
+ * chain.bandpass(1000) // Keep frequencies around 1000Hz
799
907
  * ```
800
908
  *
801
- * @see {@link FilterPresetBase.rotate}
909
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#bandpass | FFmpeg bandpass filter}
802
910
  */
803
- rotate(angle: number): this;
911
+ bandpass(frequency: number, options?: Record<string, any>): FilterPreset;
804
912
  /**
805
- * Adds a horizontal flip filter to the chain.
913
+ * Adds an equalizer filter for frequency band adjustment.
806
914
  *
915
+ * @param frequency - Center frequency in Hz
916
+ * @param width - Band width
917
+ * @param gain - Gain in dB
918
+ * @param width_type - Width type (optional)
807
919
  * @returns This instance for chaining
808
920
  *
809
921
  * @example
810
922
  * ```typescript
811
- * const chain = FilterPresets.chain()
812
- * .hflip()
813
- * .build();
923
+ * chain.equalizer(1000, 2, 5) // Boost 1000Hz by 5dB
924
+ * chain.equalizer(1000, 2, 5, 'q') // Use Q factor for width
814
925
  * ```
815
926
  *
816
- * @see {@link FilterPresetBase.hflip}
927
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#equalizer | FFmpeg equalizer filter}
817
928
  */
818
- hflip(): this;
929
+ equalizer(frequency: number, width: number, gain: number, width_type?: string): FilterPreset;
819
930
  /**
820
- * Adds a vertical flip filter to the chain.
931
+ * Adds a compressor filter for dynamic range compression.
821
932
  *
933
+ * @param options - Compressor parameters
822
934
  * @returns This instance for chaining
823
935
  *
824
936
  * @example
825
937
  * ```typescript
826
- * const chain = FilterPresets.chain()
827
- * .vflip()
828
- * .build();
938
+ * chain.compressor() // Default compression
939
+ * chain.compressor({
940
+ * threshold: 0.5,
941
+ * ratio: 4,
942
+ * attack: 5,
943
+ * release: 50
944
+ * })
829
945
  * ```
830
946
  *
831
- * @see {@link FilterPresetBase.vflip}
947
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#acompressor | FFmpeg acompressor filter}
832
948
  */
833
- vflip(): this;
949
+ compressor(options?: Record<string, any>): FilterPreset;
834
950
  /**
835
- * Adds a fade filter to the chain.
951
+ * Adds an atrim filter to trim audio.
836
952
  *
837
- * @param type - Fade type ('in' or 'out')
838
953
  * @param start - Start time in seconds
839
- * @param duration - Fade duration in seconds
840
- *
841
- * @returns This instance for chaining
842
- *
843
- * @example
844
- * ```typescript
845
- * const chain = FilterPresets.chain()
846
- * .fade('in', 0, 2)
847
- * .build();
848
- * ```
849
- *
850
- * @example
851
- * ```typescript
852
- * const chain = FilterPresets.chain()
853
- * .fade('out', 10, 1.5)
854
- * .build();
855
- * ```
856
- *
857
- * @see {@link FilterPresetBase.fade}
858
- */
859
- fade(type: 'in' | 'out', start: number, duration: number): this;
860
- /**
861
- * Adds an overlay filter to the chain.
862
- *
863
- * @param x - X position (default: 0)
864
- * @param y - Y position (default: 0)
865
- * @param options - Additional overlay options
866
- *
867
- * @returns This instance for chaining
868
- *
869
- * @example
870
- * ```typescript
871
- * const chain = FilterPresets.chain()
872
- * .overlay(100, 50)
873
- * .build();
874
- * ```
875
- *
876
- * @example
877
- * ```typescript
878
- * const chain = FilterPresets.chain()
879
- * .overlay(10, 10, { enable: 'between(t,5,10)' })
880
- * .build();
881
- * ```
882
- *
883
- * @see {@link FilterPresetBase.overlay}
884
- */
885
- overlay(x?: number, y?: number, options?: Record<string, string>): this;
886
- /**
887
- * Adds a volume filter to the chain.
888
- *
889
- * @param factor - Volume factor
890
- *
891
- * @returns This instance for chaining
892
- *
893
- * @example
894
- * ```typescript
895
- * const chain = FilterPresets.chain()
896
- * .volume(0.5)
897
- * .build();
898
- * ```
899
- *
900
- * @example
901
- * ```typescript
902
- * const chain = FilterPresets.chain()
903
- * .volume(2.0)
904
- * .build();
905
- * ```
906
- *
907
- * @see {@link FilterPresetBase.volume}
908
- */
909
- volume(factor: number): this;
910
- /**
911
- * Adds an audio format filter to the chain.
912
- *
913
- * @param sampleFormat - Target sample format
914
- * @param sampleRate - Target sample rate (optional)
915
- * @param channelLayout - Target channel layout (optional)
916
- *
917
- * @returns This instance for chaining
918
- *
919
- * @example
920
- * ```typescript
921
- * const chain = FilterPresets.chain()
922
- * .aformat(AV_SAMPLE_FMT_FLT, 48000, 'stereo')
923
- * .build();
924
- * ```
925
- *
926
- * @example
927
- * ```typescript
928
- * const chain = FilterPresets.chain()
929
- * .aformat('s16', 44100)
930
- * .build();
931
- * ```
932
- *
933
- * @see {@link FilterPresetBase.aformat}
934
- */
935
- aformat(sampleFormat: string | AVSampleFormat, sampleRate?: number, channelLayout?: string): this;
936
- /**
937
- * Adds an asetnsamples filter to the chain.
938
- *
939
- * @param samples - Number of samples per frame
940
- * @param padding - Whether to pad or drop samples (default: true)
941
- *
954
+ * @param end - End time in seconds (optional)
955
+ * @param duration - Duration in seconds (optional)
942
956
  * @returns This instance for chaining
943
957
  *
944
958
  * @example
945
959
  * ```typescript
946
- * const chain = FilterPresets.chain()
947
- * .asetnsamples(960)
948
- * .build();
949
- * ```
950
- *
951
- * @example
952
- * ```typescript
953
- * const chain = FilterPresets.chain()
954
- * .asetnsamples(1024, false)
955
- * .build();
960
+ * chain.atrim(10, 20) // Extract audio from 10s to 20s
956
961
  * ```
957
962
  *
958
- * @see {@link FilterPresetBase.asetnsamples}
963
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#atrim | FFmpeg atrim filter}
959
964
  */
960
- asetnsamples(samples: number, padding?: boolean): this;
965
+ atrim(start: number, end?: number, duration?: number): FilterPreset;
961
966
  /**
962
- * Adds an atempo filter to the chain.
963
- *
964
- * @param factor - Tempo factor (0.5 to 2.0)
967
+ * Adds a hwupload filter to upload frames to hardware.
965
968
  *
966
969
  * @returns This instance for chaining
967
970
  *
968
971
  * @example
969
972
  * ```typescript
970
973
  * const chain = FilterPresets.chain()
971
- * .atempo(1.5)
972
- * .build();
973
- * ```
974
- *
975
- * @example
976
- * ```typescript
977
- * const chain = FilterPresets.chain()
978
- * .atempo(0.8)
974
+ * .hwupload()
975
+ * .scale(1920, 1080)
979
976
  * .build();
980
977
  * ```
981
- *
982
- * @see {@link FilterPresetBase.atempo}
983
978
  */
984
- atempo(factor: number): this;
979
+ hwupload(): FilterPreset;
985
980
  /**
986
- * Adds an audio fade filter to the chain.
987
- *
988
- * @param type - Fade type ('in' or 'out')
989
- * @param start - Start time in seconds
990
- * @param duration - Fade duration in seconds
981
+ * Adds a hwdownload filter to download frames from hardware.
991
982
  *
992
983
  * @returns This instance for chaining
993
984
  *
994
985
  * @example
995
986
  * ```typescript
996
987
  * const chain = FilterPresets.chain()
997
- * .afade('in', 0, 3)
998
- * .build();
999
- * ```
1000
- *
1001
- * @example
1002
- * ```typescript
1003
- * const chain = FilterPresets.chain()
1004
- * .afade('out', 25, 2)
988
+ * .scale(1920, 1080)
989
+ * .hwdownload()
1005
990
  * .build();
1006
991
  * ```
1007
- *
1008
- * @see {@link FilterPresetBase.afade}
1009
992
  */
1010
- afade(type: 'in' | 'out', start: number, duration: number): this;
993
+ hwdownload(): FilterPreset;
1011
994
  /**
1012
- * Adds an amix filter to the chain.
995
+ * Adds a hwmap filter to map frames between hardware devices.
1013
996
  *
1014
- * @param inputs - Number of inputs (default: 2)
1015
- * @param duration - Duration mode (default: 'longest')
997
+ * @param derive - Device to derive from (optional)
1016
998
  *
1017
999
  * @returns This instance for chaining
1018
1000
  *
1019
1001
  * @example
1020
1002
  * ```typescript
1021
1003
  * const chain = FilterPresets.chain()
1022
- * .amix(3, 'longest')
1004
+ * .hwmap('cuda')
1023
1005
  * .build();
1024
1006
  * ```
1025
1007
  *
1026
1008
  * @example
1027
1009
  * ```typescript
1028
1010
  * const chain = FilterPresets.chain()
1029
- * .amix(2, 'first')
1011
+ * .hwmap()
1030
1012
  * .build();
1031
1013
  * ```
1032
- *
1033
- * @see {@link FilterPresetBase.amix}
1034
- */
1035
- amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): this;
1036
- /**
1037
- * Adds a pad filter to the chain.
1038
- *
1039
- * @param width - Target width
1040
- * @param height - Target height
1041
- * @param x - X position of input
1042
- * @param y - Y position of input
1043
- * @param color - Padding color
1044
- *
1045
- * @returns This instance for chaining
1046
- *
1047
- * @example
1048
- * ```typescript
1049
- * chain.pad('iw*2', 'ih*2') // Double the canvas size
1050
- * ```
1051
- *
1052
- * @see {@link FilterPresetBase.pad}
1053
- */
1054
- pad(width: string | number, height: string | number, x?: string, y?: string, color?: string): this;
1055
- /**
1056
- * Adds a trim filter to the chain.
1057
- *
1058
- * @param start - Start time in seconds
1059
- * @param end - End time in seconds
1060
- * @param duration - Duration in seconds
1061
- *
1062
- * @returns This instance for chaining
1063
- *
1064
- * @example
1065
- * ```typescript
1066
- * chain.trim(10, 20) // Extract 10 seconds from t=10 to t=20
1067
- * ```
1068
- *
1069
- * @see {@link FilterPresetBase.trim}
1070
- */
1071
- trim(start: number, end?: number, duration?: number): this;
1072
- /**
1073
- * Adds a setpts filter to the chain.
1074
- *
1075
- * @param expression - PTS expression
1076
- *
1077
- * @returns This instance for chaining
1078
- *
1079
- * @example
1080
- * ```typescript
1081
- * chain.setpts('PTS/2') // Double playback speed
1082
- * ```
1083
- *
1084
- * @see {@link FilterPresetBase.setpts}
1085
- */
1086
- setpts(expression: string): this;
1087
- /**
1088
- * Adds an asetpts filter to the chain.
1089
- *
1090
- * @param expression - PTS expression
1091
- *
1092
- * @returns This instance for chaining
1093
- *
1094
- * @example
1095
- * ```typescript
1096
- * chain.asetpts('PTS-STARTPTS') // Reset audio timestamps
1097
- * ```
1098
- *
1099
- * @see {@link FilterPresetBase.asetpts}
1100
- */
1101
- asetpts(expression: string): this;
1102
- /**
1103
- * Adds a setsar filter to the chain.
1104
- *
1105
- * @param ratio - Sample aspect ratio
1106
- *
1107
- * @returns This instance for chaining
1108
- *
1109
- * @example
1110
- * ```typescript
1111
- * chain.setsar('1:1') // Square pixels
1112
- * ```
1113
- *
1114
- * @see {@link FilterPresetBase.setsar}
1115
- */
1116
- setsar(ratio: string | number): this;
1117
- /**
1118
- * Adds a setdar filter to the chain.
1119
- *
1120
- * @param ratio - Display aspect ratio
1121
- *
1122
- * @returns This instance for chaining
1123
- *
1124
- * @example
1125
- * ```typescript
1126
- * chain.setdar('16:9') // Set widescreen aspect
1127
- * ```
1128
- *
1129
- * @see {@link FilterPresetBase.setdar}
1130
1014
  */
1131
- setdar(ratio: string | number): this;
1015
+ hwmap(derive?: string): FilterPreset;
1132
1016
  /**
1133
- * Adds an apad filter to the chain.
1134
- *
1135
- * @param wholeDuration - Minimum total duration
1136
- * @param padDuration - Padding duration to add
1017
+ * Adds a filter to the chain.
1137
1018
  *
1019
+ * @param filter - Filter string to add (ignored if null/undefined)
1138
1020
  * @returns This instance for chaining
1139
1021
  *
1140
1022
  * @example
1141
1023
  * ```typescript
1142
- * chain.apad(10) // Ensure at least 10 seconds of audio
1024
+ * chain.add('scale=1920:1080')
1143
1025
  * ```
1144
1026
  *
1145
- * @see {@link FilterPresetBase.apad}
1027
+ * @internal
1146
1028
  */
1147
- apad(wholeDuration?: number, padDuration?: number): this;
1029
+ private add;
1148
1030
  /**
1149
- * Adds a select filter to the chain.
1150
- *
1151
- * @param expression - Selection expression
1152
- *
1153
- * @returns This instance for chaining
1031
+ * Determines filter support for the hardware type.
1154
1032
  *
1155
- * @example
1156
- * ```typescript
1157
- * chain.select('eq(pict_type,I)') // Select only I-frames
1158
- * ```
1033
+ * @returns Hardware filter support configuration
1159
1034
  *
1160
- * @see {@link FilterPresetBase.select}
1161
- */
1162
- select(expression: string): this;
1163
- /**
1164
- * Adds an aselect filter to the chain.
1165
- *
1166
- * @param expression - Selection expression
1167
- *
1168
- * @returns This instance for chaining
1169
- *
1170
- * @example
1171
- * ```typescript
1172
- * chain.aselect('between(t,10,20)') // Select audio between 10-20s
1173
- * ```
1174
- *
1175
- * @see {@link FilterPresetBase.aselect}
1176
- */
1177
- aselect(expression: string): this;
1178
- /**
1179
- * Adds a concat filter to the chain.
1180
- *
1181
- * @param n - Number of input segments
1182
- * @param v - Number of video streams
1183
- * @param a - Number of audio streams
1184
- *
1185
- * @returns This instance for chaining
1186
- *
1187
- * @example
1188
- * ```typescript
1189
- * chain.concat(3, 1, 1) // Concatenate 3 segments with video and audio
1190
- * ```
1191
- *
1192
- * @see {@link FilterPresetBase.concat}
1193
- */
1194
- concat(n: number, v?: number, a?: number): this;
1195
- /**
1196
- * Adds an amerge filter to the chain.
1197
- *
1198
- * @param inputs - Number of input streams
1199
- *
1200
- * @returns This instance for chaining
1201
- *
1202
- * @example
1203
- * ```typescript
1204
- * chain.amerge(2) // Merge 2 audio streams
1205
- * ```
1206
- *
1207
- * @see {@link FilterPresetBase.amerge}
1208
- */
1209
- amerge(inputs?: number): this;
1210
- /**
1211
- * Adds a channelmap filter to the chain.
1212
- *
1213
- * @param map - Channel mapping string
1214
- *
1215
- * @returns This instance for chaining
1216
- *
1217
- * @example
1218
- * ```typescript
1219
- * chain.channelmap('FL-FR|FR-FL') // Swap stereo channels
1220
- * ```
1221
- *
1222
- * @see {@link FilterPresetBase.channelmap}
1223
- */
1224
- channelmap(map: string): this;
1225
- /**
1226
- * Adds a channelsplit filter to the chain.
1227
- *
1228
- * @param channelLayout - Channel layout to split
1229
- *
1230
- * @returns This instance for chaining
1231
- *
1232
- * @example
1233
- * ```typescript
1234
- * chain.channelsplit('stereo') // Split stereo into two mono streams
1235
- * ```
1236
- *
1237
- * @see {@link FilterPresetBase.channelsplit}
1238
- */
1239
- channelsplit(channelLayout?: string): this;
1240
- /**
1241
- * Adds a loudnorm filter to the chain.
1242
- *
1243
- * @param I - Integrated loudness target (LUFS)
1244
- * @param TP - True peak (dBTP)
1245
- * @param LRA - Loudness range (LU)
1246
- *
1247
- * @returns This instance for chaining
1248
- *
1249
- * @example
1250
- * ```typescript
1251
- * chain.loudnorm(-16, -1.5, 11) // Streaming loudness standard
1252
- * ```
1253
- *
1254
- * @see {@link FilterPresetBase.loudnorm}
1255
- */
1256
- loudnorm(I?: number, TP?: number, LRA?: number): this;
1257
- /**
1258
- * Adds a compand filter to the chain.
1259
- *
1260
- * @param attacks - Attack times
1261
- * @param decays - Decay times
1262
- * @param points - Transfer function points
1263
- * @param gain - Output gain
1264
- *
1265
- * @returns This instance for chaining
1266
- *
1267
- * @example
1268
- * ```typescript
1269
- * chain.compand('0.3|0.3', '1|1', '-90/-60|-60/-40|-40/-30|-20/-20', 6)
1270
- * ```
1271
- *
1272
- * @see {@link FilterPresetBase.compand}
1273
- */
1274
- compand(attacks: string, decays: string, points: string, gain?: number): this;
1275
- /**
1276
- * Adds a transpose filter to the chain (hardware-specific).
1277
- * Only available for hardware presets that support transpose
1278
- *
1279
- * @param mode - Transpose mode (number or string)
1280
- *
1281
- * @returns This instance for chaining
1282
- *
1283
- * @example
1284
- * ```typescript
1285
- * const chain = FilterPresets.chain()
1286
- * .transpose('clock')
1287
- * .build();
1288
- * ```
1289
- *
1290
- * @example
1291
- * ```typescript
1292
- * const chain = FilterPresets.chain()
1293
- * .transpose('cclock_flip')
1294
- * .build();
1295
- * ```
1296
- */
1297
- transpose(mode?: number | 'clock' | 'cclock' | 'clock_flip' | 'cclock_flip'): this;
1298
- /**
1299
- * Adds a tonemap filter to the chain (hardware-specific).
1300
- * Only available for hardware presets that support tonemapping
1301
- *
1302
- * @param options - Tonemapping options
1303
- *
1304
- * @returns This instance for chaining
1305
- *
1306
- * @example
1307
- * ```typescript
1308
- * const chain = FilterPresets.chain()
1309
- * .tonemap()
1310
- * .build();
1311
- * ```
1312
- *
1313
- * @example
1314
- * ```typescript
1315
- * const chain = FilterPresets.chain()
1316
- * .tonemap({ tonemap: 'hable', desat: '0' })
1317
- * .build();
1318
- * ```
1319
- */
1320
- tonemap(options?: Record<string, string>): this;
1321
- /**
1322
- * Adds a deinterlace filter to the chain (hardware-specific).
1323
- * Only available for hardware presets that support deinterlacing
1324
- *
1325
- * @param mode - Deinterlace mode (optional)
1326
- *
1327
- * @returns This instance for chaining
1328
- *
1329
- * @example
1330
- * ```typescript
1331
- * const chain = FilterPresets.chain()
1332
- * .deinterlace()
1333
- * .build();
1334
- * ```
1335
- *
1336
- * @example
1337
- * ```typescript
1338
- * const chain = FilterPresets.chain()
1339
- * .deinterlace('yadif')
1340
- * .build();
1341
- * ```
1342
- */
1343
- deinterlace(mode?: string): this;
1344
- /**
1345
- * Adds a flip filter to the chain (hardware-specific).
1346
- * Falls back to hflip/vflip if hardware flip not available
1347
- *
1348
- * @param direction - Flip direction ('h' or 'v')
1349
- *
1350
- * @returns This instance for chaining
1351
- *
1352
- * @example
1353
- * ```typescript
1354
- * const chain = FilterPresets.chain()
1355
- * .flip('h')
1356
- * .build();
1357
- * ```
1358
- *
1359
- * @example
1360
- * ```typescript
1361
- * const chain = FilterPresets.chain()
1362
- * .flip('v')
1363
- * .build();
1364
- * ```
1365
- */
1366
- flip(direction: 'h' | 'v'): this;
1367
- /**
1368
- * Adds a blur filter to the chain (hardware-specific).
1369
- * Only available for hardware presets that support blur
1370
- *
1371
- * @param type - Blur type (default: 'avg')
1372
- * @param radius - Blur radius (optional)
1373
- *
1374
- * @returns This instance for chaining
1375
- *
1376
- * @example
1377
- * ```typescript
1378
- * const chain = FilterPresets.chain()
1379
- * .blur('gaussian', 5)
1380
- * .build();
1381
- * ```
1382
- *
1383
- * @example
1384
- * ```typescript
1385
- * const chain = FilterPresets.chain()
1386
- * .blur('box')
1387
- * .build();
1388
- * ```
1389
- */
1390
- blur(type?: 'avg' | 'gaussian' | 'box', radius?: number): this;
1391
- /**
1392
- * Adds a sharpen filter to the chain (hardware-specific).
1393
- * Only available for hardware presets that support sharpening
1394
- *
1395
- * @param amount - Sharpen amount (optional)
1396
- *
1397
- * @returns This instance for chaining
1398
- *
1399
- * @example
1400
- * ```typescript
1401
- * const chain = FilterPresets.chain()
1402
- * .sharpen(1.5)
1403
- * .build();
1404
- * ```
1405
- *
1406
- * @example
1407
- * ```typescript
1408
- * const chain = FilterPresets.chain()
1409
- * .sharpen()
1410
- * .build();
1411
- * ```
1412
- */
1413
- sharpen(amount?: number): this;
1414
- /**
1415
- * Adds a stack filter to the chain (hardware-specific).
1416
- * Only available for hardware presets that support stacking
1417
- *
1418
- * @param type - Stack type ('h' for horizontal, 'v' for vertical, 'x' for grid)
1419
- * @param inputs - Number of inputs (default: 2)
1420
- *
1421
- * @returns This instance for chaining
1422
- *
1423
- * @example
1424
- * ```typescript
1425
- * const chain = FilterPresets.chain()
1426
- * .stack('h', 2)
1427
- * .build();
1428
- * ```
1429
- *
1430
- * @example
1431
- * ```typescript
1432
- * const chain = FilterPresets.chain()
1433
- * .stack('x', 4)
1434
- * .build();
1435
- * ```
1436
- */
1437
- stack(type: 'h' | 'v' | 'x', inputs?: number): this;
1438
- /**
1439
- * Adds a hwupload filter to upload frames to hardware.
1440
- *
1441
- * @returns This instance for chaining
1442
- *
1443
- * @example
1444
- * ```typescript
1445
- * const chain = FilterPresets.chain()
1446
- * .hwupload()
1447
- * .scale(1920, 1080)
1448
- * .build();
1449
- * ```
1450
- */
1451
- hwupload(): this;
1452
- /**
1453
- * Adds a hwdownload filter to download frames from hardware.
1454
- *
1455
- * @returns This instance for chaining
1456
- *
1457
- * @example
1458
- * ```typescript
1459
- * const chain = FilterPresets.chain()
1460
- * .scale(1920, 1080)
1461
- * .hwdownload()
1462
- * .build();
1463
- * ```
1464
- */
1465
- hwdownload(): this;
1466
- /**
1467
- * Adds a hwmap filter to map frames between hardware devices.
1468
- *
1469
- * @param derive - Device to derive from (optional)
1470
- *
1471
- * @returns This instance for chaining
1472
- *
1473
- * @example
1474
- * ```typescript
1475
- * const chain = FilterPresets.chain()
1476
- * .hwmap('cuda')
1477
- * .build();
1478
- * ```
1479
- *
1480
- * @example
1481
- * ```typescript
1482
- * const chain = FilterPresets.chain()
1483
- * .hwmap()
1484
- * .build();
1485
- * ```
1486
- */
1487
- hwmap(derive?: string): this;
1488
- }
1489
- /**
1490
- * Fluent filter chain builder with preset methods.
1491
- * Provides a convenient API for building filter chains using standard presets.
1492
- *
1493
- * @example
1494
- * ```typescript
1495
- * const filter = FilterPresets.chain()
1496
- * .scale(1920, 1080)
1497
- * .fps(30)
1498
- * .fade('in', 0, 2)
1499
- * .format('yuv420p')
1500
- * .build();
1501
- * ```
1502
- */
1503
- export declare class FilterChainBuilder extends ChainBuilderBase<FilterPresets> {
1504
- }
1505
- /**
1506
- * Standard filter presets for software filtering.
1507
- * Provides static methods for creating common filter strings and
1508
- * a chain builder for composing complex filter graphs.
1509
- *
1510
- * @example
1511
- * ```typescript
1512
- * // Static methods for individual filters
1513
- * const scaleFilter = FilterPresets.scale(1920, 1080);
1514
- * const fpsFilter = FilterPresets.fps(30);
1515
- *
1516
- * // Chain builder for complex graphs
1517
- * const chain = FilterPresets.chain()
1518
- * .scale(1920, 1080)
1519
- * .fps(30)
1520
- * .fade('in', 0, 2)
1521
- * .build();
1522
- * ```
1523
- */
1524
- export declare class FilterPresets extends FilterPresetBase {
1525
- private static instance;
1526
- /**
1527
- * Creates a new filter chain builder.
1528
- *
1529
- * @returns A new FilterChainBuilder instance
1530
- *
1531
- * @example
1532
- * ```typescript
1533
- * const filter = FilterPresets.chain()
1534
- * .scale(1280, 720)
1535
- * .fps(30)
1536
- * .build();
1537
- * ```
1538
- */
1539
- static chain(): FilterChainBuilder;
1540
- /**
1541
- * Creates a scale filter string.
1542
- *
1543
- * @param width - Target width
1544
- * @param height - Target height
1545
- * @param flags - Scaling algorithm flags (optional)
1546
- *
1547
- * @returns Scale filter string
1548
- *
1549
- * @example
1550
- * ```typescript
1551
- * const filter = FilterPresets.scale(1920, 1080);
1552
- * ```
1553
- *
1554
- * @example
1555
- * ```typescript
1556
- * const filter = FilterPresets.scale(1280, 720, 'lanczos');
1557
- * ```
1558
- */
1559
- static scale(width: number, height: number, flags?: string): string;
1560
- /**
1561
- * Creates a crop filter string.
1562
- *
1563
- * @param width - Crop width
1564
- * @param height - Crop height
1565
- * @param x - X position (default: 0)
1566
- * @param y - Y position (default: 0)
1567
- *
1568
- * @returns Crop filter string
1569
- *
1570
- * @example
1571
- * ```typescript
1572
- * const filter = FilterPresets.crop(640, 480);
1573
- * ```
1574
- *
1575
- * @example
1576
- * ```typescript
1577
- * const filter = FilterPresets.crop(1920, 1080, 100, 50);
1578
- * ```
1579
- */
1580
- static crop(width: number, height: number, x?: number, y?: number): string;
1581
- /**
1582
- * Creates an FPS filter string.
1583
- *
1584
- * @param fps - Target frame rate
1585
- *
1586
- * @returns FPS filter string
1587
- *
1588
- * @example
1589
- * ```typescript
1590
- * const filter = FilterPresets.fps(30);
1591
- * ```
1592
- *
1593
- * @example
1594
- * ```typescript
1595
- * const filter = FilterPresets.fps(23.976);
1596
- * ```
1597
- */
1598
- static fps(fps: number): string;
1599
- /**
1600
- * Creates a format filter string.
1601
- *
1602
- * @param pixelFormat - Target pixel format(s)
1603
- *
1604
- * @returns Format filter string
1605
- *
1606
- * @example
1607
- * ```typescript
1608
- * const filter = FilterPresets.format('yuv420p');
1609
- * ```
1610
- *
1611
- * @example
1612
- * ```typescript
1613
- * const filter = FilterPresets.format(AV_PIX_FMT_RGB24);
1614
- * ```
1615
- */
1616
- static format(pixelFormat: string | AVPixelFormat | (string | AVPixelFormat)[]): string;
1617
- /**
1618
- * Creates a rotate filter string.
1619
- *
1620
- * @param angle - Rotation angle in degrees
1621
- *
1622
- * @returns Rotate filter string
1623
- *
1624
- * @example
1625
- * ```typescript
1626
- * const filter = FilterPresets.rotate(45);
1627
- * ```
1628
- *
1629
- * @example
1630
- * ```typescript
1631
- * const filter = FilterPresets.rotate(-90);
1632
- * ```
1633
- */
1634
- static rotate(angle: number): string;
1635
- /**
1636
- * Creates a horizontal flip filter string.
1637
- *
1638
- * @returns Horizontal flip filter string
1639
- *
1640
- * @example
1641
- * ```typescript
1642
- * const filter = FilterPresets.hflip();
1643
- * ```
1644
- */
1645
- static hflip(): string;
1646
- /**
1647
- * Creates a vertical flip filter string.
1648
- *
1649
- * @returns Vertical flip filter string
1650
- *
1651
- * @example
1652
- * ```typescript
1653
- * const filter = FilterPresets.vflip();
1654
- * ```
1655
- */
1656
- static vflip(): string;
1657
- /**
1658
- * Creates a fade filter string.
1659
- *
1660
- * @param type - Fade type ('in' or 'out')
1661
- * @param start - Start time in seconds
1662
- * @param duration - Fade duration in seconds
1663
- *
1664
- * @returns Fade filter string
1665
- *
1666
- * @example
1667
- * ```typescript
1668
- * const filter = FilterPresets.fade('in', 0, 2);
1669
- * ```
1670
- *
1671
- * @example
1672
- * ```typescript
1673
- * const filter = FilterPresets.fade('out', 10, 1.5);
1674
- * ```
1675
- */
1676
- static fade(type: 'in' | 'out', start: number, duration: number): string;
1677
- /**
1678
- * Creates an overlay filter string.
1679
- *
1680
- * @param x - X position (default: 0)
1681
- * @param y - Y position (default: 0)
1682
- *
1683
- * @returns Overlay filter string
1684
- *
1685
- * @example
1686
- * ```typescript
1687
- * const filter = FilterPresets.overlay(100, 50);
1688
- * ```
1689
- *
1690
- * @example
1691
- * ```typescript
1692
- * const filter = FilterPresets.overlay();
1693
- * ```
1694
- */
1695
- static overlay(x?: number, y?: number): string;
1696
- /**
1697
- * Creates a volume filter string.
1698
- *
1699
- * @param factor - Volume multiplication factor
1700
- *
1701
- * @returns Volume filter string
1702
- *
1703
- * @example
1704
- * ```typescript
1705
- * const filter = FilterPresets.volume(0.5);
1706
- * ```
1707
- *
1708
- * @example
1709
- * ```typescript
1710
- * const filter = FilterPresets.volume(2.0);
1711
- * ```
1712
- */
1713
- static volume(factor: number): string;
1714
- /**
1715
- * Creates an audio format filter string.
1716
- *
1717
- * @param sampleFormat - Target sample format
1718
- * @param sampleRate - Target sample rate (optional)
1719
- * @param channelLayout - Target channel layout (optional)
1720
- *
1721
- * @returns Audio format filter string
1722
- *
1723
- * @example
1724
- * ```typescript
1725
- * const filter = FilterPresets.aformat(AV_SAMPLE_FMT_FLT, 48000, 'stereo');
1726
- * ```
1727
- *
1728
- * @example
1729
- * ```typescript
1730
- * const filter = FilterPresets.aformat('s16', 44100);
1731
- * ```
1732
- */
1733
- static aformat(sampleFormat: string | AVSampleFormat, sampleRate?: number, channelLayout?: string): string;
1734
- /**
1735
- * Creates an asetnsamples filter string.
1736
- *
1737
- * @param samples - Number of samples per frame
1738
- * @param padding - Whether to pad or drop samples (default: true)
1739
- *
1740
- * @returns Asetnsamples filter string
1741
- *
1742
- * @example
1743
- * ```typescript
1744
- * const filter = FilterPresets.asetnsamples(960);
1745
- * ```
1746
- *
1747
- * @example
1748
- * ```typescript
1749
- * const filter = FilterPresets.asetnsamples(1024, false);
1750
- * ```
1751
- */
1752
- static asetnsamples(samples: number, padding?: boolean): string;
1753
- /**
1754
- * Creates an atempo filter string.
1755
- *
1756
- * @param factor - Tempo factor (0.5 to 2.0)
1757
- *
1758
- * @returns Atempo filter string
1759
- *
1760
- * @example
1761
- * ```typescript
1762
- * const filter = FilterPresets.atempo(1.5);
1763
- * ```
1764
- *
1765
- * @example
1766
- * ```typescript
1767
- * const filter = FilterPresets.atempo(0.8);
1768
- * ```
1769
- */
1770
- static atempo(factor: number): string;
1771
- /**
1772
- * Creates an audio fade filter string.
1773
- *
1774
- * @param type - Fade type ('in' or 'out')
1775
- * @param start - Start time in seconds
1776
- * @param duration - Fade duration in seconds
1777
- *
1778
- * @returns Audio fade filter string
1779
- *
1780
- * @example
1781
- * ```typescript
1782
- * const filter = FilterPresets.afade('in', 0, 3);
1783
- * ```
1784
- *
1785
- * @example
1786
- * ```typescript
1787
- * const filter = FilterPresets.afade('out', 25, 2);
1788
- * ```
1789
- */
1790
- static afade(type: 'in' | 'out', start: number, duration: number): string;
1791
- /**
1792
- * Creates an amix filter string.
1793
- *
1794
- * @param inputs - Number of inputs (default: 2)
1795
- * @param duration - Duration mode (default: 'longest')
1796
- *
1797
- * @returns Amix filter string
1798
- *
1799
- * @example
1800
- * ```typescript
1801
- * const filter = FilterPresets.amix(3, 'longest');
1802
- * ```
1803
- *
1804
- * @example
1805
- * ```typescript
1806
- * const filter = FilterPresets.amix(2, 'first');
1807
- * ```
1808
- */
1809
- static amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): string;
1810
- }
1811
- /**
1812
- * Hardware-accelerated filter presets.
1813
- * Provides optimized filter implementations for specific hardware types,
1814
- * with automatic fallback when operations aren't supported.
1815
- *
1816
- * @example
1817
- * ```typescript
1818
- * // Create hardware presets for CUDA
1819
- * const hw = new HardwareFilterPresets(AV_HWDEVICE_TYPE_CUDA);
1820
- *
1821
- * // Check capabilities
1822
- * if (hw.support.scale) {
1823
- * const scaleFilter = hw.scale(1920, 1080);
1824
- * }
1825
- *
1826
- * // Use chain builder
1827
- * const chain = hw.chain()
1828
- * .hwupload()
1829
- * .scale(1920, 1080)
1830
- * .tonemap()
1831
- * .hwdownload()
1832
- * .build();
1833
- * ```
1834
- */
1835
- export declare class HardwareFilterPresets extends FilterPresetBase {
1836
- private readonly deviceType;
1837
- private readonly deviceTypeName;
1838
- readonly support: HardwareFilterSupport;
1839
- /**
1840
- * @param deviceType - Hardware device type enum
1841
- * @param deviceTypeName - Optional hardware device type name (e.g., 'cuda', 'vaapi')
1842
- */
1843
- constructor(deviceType: AVHWDeviceType, deviceTypeName?: string);
1844
- /**
1845
- * Checks if a filter is hardware-accelerated.
1846
- *
1847
- * @param filterName - Name of the filter to check
1848
- * @returns True if the filter uses hardware acceleration
1849
- *
1850
- * @example
1851
- * ```typescript
1852
- * if (HardwareFilterPresets.isHardwareFilter('scale_cuda')) {
1853
- * console.log('Hardware accelerated scaling');
1854
- * }
1855
- * ```
1856
- */
1857
- static isHardwareFilter(filterName: string): boolean;
1858
- /**
1859
- * Creates a hardware filter chain builder.
1860
- *
1861
- * @returns A new HardwareFilterChainBuilder instance
1862
- *
1863
- * @example
1864
- * ```typescript
1865
- * const filter = hw.chain()
1866
- * .hwupload()
1867
- * .scale(1920, 1080)
1868
- * .hwdownload()
1869
- * .build();
1870
- * ```
1871
- */
1872
- chain(): HardwareFilterChainBuilder;
1873
- /**
1874
- * Creates a hardware-accelerated scale filter.
1875
- *
1876
- * Different hardware types use different scale filters:
1877
- * - CUDA: scale_cuda or scale_npp (with npp option)
1878
- * - VAAPI: scale_vaapi
1879
- * - QSV: scale_qsv
1880
- * - VideoToolbox: scale_vt
1881
- * - RKMPP: scale_rkrga
1882
- *
1883
- * @param width - Target width
1884
- * @param height - Target height
1885
- * @param options - Hardware-specific scaling options
1886
- *
1887
- * @returns Hardware scale filter string or null if not supported
1888
- *
1889
- * @example
1890
- * ```typescript
1891
- * const filter = hwPresets.scale(1920, 1080);
1892
- * ```
1893
- *
1894
- * @example
1895
- * ```typescript
1896
- * const filter = hwPresets.scale(1280, 720, { npp: true });
1897
- * ```
1898
- *
1899
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#scale_005fcuda | FFmpeg scale_cuda filter}
1900
- */
1901
- scale(width: number, height: number, options?: Record<string, any>): string | null;
1902
- /**
1903
- * Creates a hardware-accelerated overlay filter.
1904
- *
1905
- * @param x - X position (default: 0)
1906
- * @param y - Y position (default: 0)
1907
- * @param options - Hardware-specific overlay options
1908
- *
1909
- * @returns Hardware overlay filter string or null if not supported
1910
- *
1911
- * @example
1912
- * ```typescript
1913
- * const filter = hwPresets.overlay(100, 50);
1914
- * ```
1915
- *
1916
- * @example
1917
- * ```typescript
1918
- * const filter = hwPresets.overlay(0, 0, { eof_action: 'pass' });
1919
- * ```
1920
- *
1921
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#overlay_005fcuda | FFmpeg overlay_cuda filter}
1922
- */
1923
- overlay(x?: number, y?: number, options?: Record<string, string>): string | null;
1924
- /**
1925
- * Creates a hardware-accelerated transpose filter.
1926
- *
1927
- * Direction values:
1928
- * - 0: 90 degrees counter-clockwise and vertical flip
1929
- * - 1 / 'clock': 90 degrees clockwise
1930
- * - 2 / 'cclock': 90 degrees counter-clockwise
1931
- * - 3 / 'clock_flip': 90 degrees clockwise and vertical flip
1932
- *
1933
- * @param mode - Transpose mode (number or string)
1934
- *
1935
- * @returns Hardware transpose filter string or null if not supported
1936
- *
1937
- * @example
1938
- * ```typescript
1939
- * const filter = hwPresets.transpose('clock');
1940
- * ```
1941
- *
1942
- * @example
1943
- * ```typescript
1944
- * const filter = hwPresets.transpose(2);
1945
- * ```
1946
- */
1947
- transpose(mode: number | 'clock' | 'cclock' | 'clock_flip' | 'cclock_flip'): string | null;
1948
- /**
1949
- * Creates a hardware-accelerated tonemap filter.
1950
- * Used for HDR to SDR conversion with hardware acceleration.
1951
- *
1952
- * @param options - Tonemapping options (algorithm, parameters)
1953
- *
1954
- * @returns Hardware tonemap filter string or null if not supported
1955
- *
1956
- * @example
1957
- * ```typescript
1958
- * const filter = hwPresets.tonemap();
1959
- * ```
1960
- *
1961
- * @example
1962
- * ```typescript
1963
- * const filter = hwPresets.tonemap({ tonemap: 'hable', desat: '0' });
1964
- * ```
1965
- */
1966
- tonemap(options?: Record<string, string>): string | null;
1967
- /**
1968
- * Creates a hardware-accelerated deinterlace filter.
1969
- *
1970
- * Different hardware types use different deinterlacers:
1971
- * - CUDA: yadif_cuda
1972
- * - VAAPI: deinterlace_vaapi
1973
- * - QSV: deinterlace_qsv
1974
- * - Vulkan: bwdif_vulkan
1975
- * - VideoToolbox: yadif_videotoolbox
1976
- *
1977
- * @param mode - Deinterlacing mode (optional)
1978
- *
1979
- * @returns Hardware deinterlace filter string or null if not supported
1980
- *
1981
- * @example
1982
- * ```typescript
1983
- * const filter = hwPresets.deinterlace();
1984
- * ```
1985
- *
1986
- * @example
1987
- * ```typescript
1988
- * const filter = hwPresets.deinterlace('send_field');
1989
- * ```
1990
- */
1991
- deinterlace(mode?: string): string | null;
1992
- /**
1993
- * Creates a hardware-accelerated flip filter.
1994
- * Currently only Vulkan supports hardware flip filters.
1995
- *
1996
- * @param direction - Flip direction ('h' for horizontal, 'v' for vertical)
1997
- *
1998
- * @returns Hardware flip filter string or null if not supported
1999
- *
2000
- * @example
2001
- * ```typescript
2002
- * const filter = hwPresets.flip('h');
2003
- * ```
2004
- *
2005
- * @example
2006
- * ```typescript
2007
- * const filter = hwPresets.flip('v');
2008
- * ```
2009
- */
2010
- flip(direction: 'h' | 'v'): string | null;
2011
- /**
2012
- * Creates a hardware-accelerated blur filter.
2013
- *
2014
- * Different hardware types support different blur filters:
2015
- * - CUDA: bilateral_cuda
2016
- * - Vulkan: avgblur_vulkan, gblur_vulkan
2017
- * - OpenCL: avgblur_opencl, boxblur_opencl
2018
- *
2019
- * @param type - Blur type ('avg', 'gaussian', or 'box', default: 'avg')
2020
- * @param radius - Blur radius (optional)
2021
- *
2022
- * @returns Hardware blur filter string or null if not supported
2023
- *
2024
- * @example
2025
- * ```typescript
2026
- * const filter = hwPresets.blur('gaussian', 5);
2027
- * ```
2028
- *
2029
- * @example
2030
- * ```typescript
2031
- * const filter = hwPresets.blur('avg');
2032
- * ```
2033
- */
2034
- blur(type?: 'avg' | 'gaussian' | 'box', radius?: number): string | null;
2035
- /**
2036
- * Creates a hardware-accelerated sharpen filter.
2037
- *
2038
- * Hardware sharpening support:
2039
- * - VAAPI: sharpness_vaapi
2040
- * - OpenCL: unsharp_opencl
2041
- * - CUDA: sharpen_npp (NPP-based)
2042
- *
2043
- * @param amount - Sharpening amount (optional)
2044
- *
2045
- * @returns Hardware sharpen filter string or null if not supported
2046
- *
2047
- * @example
2048
- * ```typescript
2049
- * const filter = hwPresets.sharpen(1.5);
2050
- * ```
2051
- *
2052
- * @example
2053
- * ```typescript
2054
- * const filter = hwPresets.sharpen();
2055
- * ```
2056
- */
2057
- sharpen(amount?: number): string | null;
2058
- /**
2059
- * Creates a hardware-accelerated stack filter.
2060
- * Only VAAPI and QSV support hardware stacking.
2061
- *
2062
- * @param type - Stack type ('h' for horizontal, 'v' for vertical, 'x' for grid)
2063
- * @param inputs - Number of inputs to stack (default: 2)
2064
- *
2065
- * @returns Hardware stack filter string or null if not supported
2066
- *
2067
- * @example
2068
- * ```typescript
2069
- * const filter = hwPresets.stack('h', 2);
2070
- * ```
2071
- *
2072
- * @example
2073
- * ```typescript
2074
- * const filter = hwPresets.stack('x', 4);
2075
- * ```
2076
- */
2077
- stack(type: 'h' | 'v' | 'x', inputs?: number): string | null;
2078
- /**
2079
- * Creates a hwupload filter to upload frames to hardware memory.
2080
- * CUDA uses hwupload_cuda, others use generic hwupload.
2081
- *
2082
- * @returns Hardware upload filter string
2083
- *
2084
- * @example
2085
- * ```typescript
2086
- * const filter = hwPresets.hwupload();
2087
- * ```
2088
- *
2089
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hwupload | FFmpeg hwupload filter}
2090
- */
2091
- hwupload(): string | null;
2092
- /**
2093
- * Creates a hwdownload filter to download frames from hardware memory.
2094
- *
2095
- * @returns Hardware download filter string
2096
- *
2097
- * @example
2098
- * ```typescript
2099
- * const filter = hwPresets.hwdownload();
2100
- * ```
2101
- *
2102
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hwdownload | FFmpeg hwdownload filter}
2103
- */
2104
- hwdownload(): string | null;
2105
- /**
2106
- * Creates a hwmap filter to map frames between hardware devices.
2107
- *
2108
- * @param derive - Device to derive from (optional)
2109
- *
2110
- * @returns Hardware map filter string
2111
- *
2112
- * @example
2113
- * ```typescript
2114
- * const filter = hwPresets.hwmap('cuda');
2115
- * ```
2116
- *
2117
- * @example
2118
- * ```typescript
2119
- * const filter = hwPresets.hwmap();
2120
- * ```
2121
- *
2122
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hwmap | FFmpeg hwmap filter}
2123
- */
2124
- hwmap(derive?: string): string | null;
2125
- /**
2126
- * Gets the filter capabilities for this hardware type.
2127
- *
2128
- * @returns Object describing which filters are supported
2129
- *
2130
- * @example
2131
- * ```typescript
2132
- * const caps = hw.getCapabilities();
2133
- * if (caps.scale && caps.overlay) {
2134
- * console.log('Hardware supports scaling and overlay');
2135
- * }
2136
- * ```
2137
- */
2138
- getCapabilities(): HardwareFilterSupport;
2139
- /**
2140
- * Determines filter support for the hardware type.
2141
- *
2142
- * @returns Hardware filter support configuration
2143
- *
2144
- * @internal
1035
+ * @internal
2145
1036
  */
2146
1037
  private getSupport;
2147
1038
  }
2148
- /**
2149
- * Hardware filter chain builder with fluent API.
2150
- * Automatically skips unsupported filters (returns null) allowing graceful fallback.
2151
- *
2152
- * @example
2153
- * ```typescript
2154
- * const hw = new HardwareFilterPresets(AV_HWDEVICE_TYPE_CUDA, 'cuda');
2155
- * const chain = hw.chain()
2156
- * .hwupload()
2157
- * .scale(1920, 1080)
2158
- * .tonemap() // Skipped if not supported
2159
- * .hwdownload()
2160
- * .build();
2161
- * ```
2162
- */
2163
- export declare class HardwareFilterChainBuilder extends ChainBuilderBase<HardwareFilterPresets> {
2164
- }