node-av 1.2.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 (99) hide show
  1. package/README.md +37 -59
  2. package/dist/api/bitstream-filter.d.ts +5 -2
  3. package/dist/api/bitstream-filter.js +7 -4
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +135 -119
  6. package/dist/api/decoder.js +195 -202
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +141 -78
  9. package/dist/api/encoder.js +241 -193
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +699 -573
  12. package/dist/api/filter-presets.js +1157 -840
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +180 -157
  15. package/dist/api/filter.js +314 -366
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +28 -29
  18. package/dist/api/hardware.js +80 -74
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +1 -1
  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 +6 -0
  24. package/dist/api/io-stream.js +6 -0
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +2 -1
  27. package/dist/api/media-input.js +3 -8
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +37 -126
  30. package/dist/api/media-output.js +138 -206
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +193 -0
  33. package/dist/api/pipeline.js +36 -42
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +22 -57
  36. package/dist/api/utilities/audio-sample.d.ts +0 -8
  37. package/dist/api/utilities/audio-sample.js +0 -8
  38. package/dist/api/utilities/audio-sample.js.map +1 -1
  39. package/dist/api/utilities/channel-layout.d.ts +0 -8
  40. package/dist/api/utilities/channel-layout.js +0 -8
  41. package/dist/api/utilities/channel-layout.js.map +1 -1
  42. package/dist/api/utilities/image.d.ts +0 -8
  43. package/dist/api/utilities/image.js +0 -8
  44. package/dist/api/utilities/image.js.map +1 -1
  45. package/dist/api/utilities/index.d.ts +3 -3
  46. package/dist/api/utilities/index.js +3 -3
  47. package/dist/api/utilities/index.js.map +1 -1
  48. package/dist/api/utilities/media-type.d.ts +1 -9
  49. package/dist/api/utilities/media-type.js +1 -9
  50. package/dist/api/utilities/media-type.js.map +1 -1
  51. package/dist/api/utilities/pixel-format.d.ts +1 -9
  52. package/dist/api/utilities/pixel-format.js +1 -9
  53. package/dist/api/utilities/pixel-format.js.map +1 -1
  54. package/dist/api/utilities/sample-format.d.ts +1 -9
  55. package/dist/api/utilities/sample-format.js +1 -9
  56. package/dist/api/utilities/sample-format.js.map +1 -1
  57. package/dist/api/utilities/streaming.d.ts +0 -8
  58. package/dist/api/utilities/streaming.js +0 -8
  59. package/dist/api/utilities/streaming.js.map +1 -1
  60. package/dist/api/utilities/timestamp.d.ts +0 -8
  61. package/dist/api/utilities/timestamp.js +0 -8
  62. package/dist/api/utilities/timestamp.js.map +1 -1
  63. package/dist/api/utils.js +2 -0
  64. package/dist/api/utils.js.map +1 -1
  65. package/dist/constants/constants.d.ts +1 -1
  66. package/dist/constants/constants.js +2 -0
  67. package/dist/constants/constants.js.map +1 -1
  68. package/dist/lib/binding.d.ts +1 -0
  69. package/dist/lib/binding.js +2 -0
  70. package/dist/lib/binding.js.map +1 -1
  71. package/dist/lib/codec.d.ts +4 -4
  72. package/dist/lib/codec.js +4 -4
  73. package/dist/lib/dictionary.d.ts +2 -2
  74. package/dist/lib/dictionary.js +2 -2
  75. package/dist/lib/dictionary.js.map +1 -1
  76. package/dist/lib/error.d.ts +1 -1
  77. package/dist/lib/error.js +1 -1
  78. package/dist/lib/filter-context.d.ts +19 -2
  79. package/dist/lib/filter-context.js +15 -0
  80. package/dist/lib/filter-context.js.map +1 -1
  81. package/dist/lib/format-context.d.ts +18 -18
  82. package/dist/lib/format-context.js +20 -20
  83. package/dist/lib/format-context.js.map +1 -1
  84. package/dist/lib/frame.d.ts +43 -1
  85. package/dist/lib/frame.js +53 -0
  86. package/dist/lib/frame.js.map +1 -1
  87. package/dist/lib/index.d.ts +1 -1
  88. package/dist/lib/index.js +1 -1
  89. package/dist/lib/index.js.map +1 -1
  90. package/dist/lib/native-types.d.ts +1 -0
  91. package/dist/lib/option.d.ts +176 -0
  92. package/dist/lib/option.js +176 -0
  93. package/dist/lib/option.js.map +1 -1
  94. package/dist/lib/utilities.d.ts +64 -1
  95. package/dist/lib/utilities.js +65 -0
  96. package/dist/lib/utilities.js.map +1 -1
  97. package/install/ffmpeg.js +0 -11
  98. package/package.json +16 -18
  99. package/release_notes.md +0 -48
@@ -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,100 +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
143
+ *
144
+ * @example
145
+ * ```typescript
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
149
+ * ```
57
150
  *
58
151
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#scale | FFmpeg scale filter}
59
152
  */
60
- scale(width: number, height: number, options?: Record<string, any>): string | null;
153
+ scale(width: number, height: number, options?: Record<string, any>): FilterPreset;
61
154
  /**
62
- * Creates a crop filter string.
155
+ * Adds a crop filter to the chain.
63
156
  *
64
157
  * @param width - Width of the cropped area
65
158
  * @param height - Height of the cropped area
66
159
  * @param x - X coordinate of top-left corner (default: 0)
67
160
  * @param y - Y coordinate of top-left corner (default: 0)
68
- * @returns Filter string or null if not supported
161
+ * @returns This instance for chaining
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * chain.crop(640, 480, 100, 100) // Crop 640x480 area starting at (100,100)
166
+ * chain.crop(1280, 720) // Crop from top-left corner
167
+ * ```
69
168
  *
70
169
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#crop | FFmpeg crop filter}
71
170
  */
72
- 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;
73
196
  /**
74
- * Creates an FPS filter string to change frame rate.
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;
219
+ /**
220
+ * Adds an FPS filter to change frame rate.
75
221
  *
76
222
  * @param fps - Target frames per second
77
- * @returns Filter string or null if not supported
223
+ * @returns This instance for chaining
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * chain.fps(30) // Convert to 30 FPS
228
+ * chain.fps(23.976) // Film frame rate
229
+ * ```
78
230
  *
79
231
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#fps | FFmpeg fps filter}
80
232
  */
81
- fps(fps: number): string | null;
233
+ fps(fps: number): FilterPreset;
82
234
  /**
83
- * Creates a format filter string to convert pixel format.
235
+ * Adds a format filter to convert pixel format.
84
236
  *
85
- * @param pixelFormat - Target pixel format(s) - can be string, AVPixelFormat enum, or array
86
- * @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
87
239
  *
88
240
  * @example
89
241
  * ```typescript
90
242
  * // Single format
91
- * presets.format('yuv420p');
92
- * presets.format(AV_PIX_FMT_YUV420P);
243
+ * chain.format(AV_PIX_FMT_YUV420P);
93
244
  *
94
- * // Multiple formats (creates a chain)
95
- * presets.format(['yuv420p', 'rgb24']);
245
+ * // Multiple formats (tries formats in order)
246
+ * chain.format([AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24]);
96
247
  * ```
97
248
  *
98
249
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#format | FFmpeg format filter}
99
250
  */
100
- format(pixelFormat: string | AVPixelFormat | (string | AVPixelFormat)[]): string | null;
251
+ format(pixelFormat: AVPixelFormat | AVPixelFormat[]): FilterPreset;
101
252
  /**
102
- * Creates a rotate filter string.
253
+ * Adds a rotate filter to the chain.
103
254
  *
104
255
  * @param angle - Rotation angle in degrees
105
- * @returns Filter string or null if not supported
256
+ * @returns This instance for chaining
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * chain.rotate(90) // Rotate 90 degrees clockwise
261
+ * chain.rotate(-45) // Rotate 45 degrees counter-clockwise
262
+ * ```
106
263
  *
107
264
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#rotate | FFmpeg rotate filter}
108
265
  */
109
- rotate(angle: number): string | null;
266
+ rotate(angle: number): FilterPreset;
110
267
  /**
111
- * 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
112
270
  *
113
- * @returns Filter string or null if not supported
271
+ * @param direction - Flip direction ('h' or 'v')
272
+ *
273
+ * @returns This instance for chaining
114
274
  *
115
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hflip | FFmpeg hflip filter}
275
+ * @example
276
+ * ```typescript
277
+ * const chain = FilterPresets.chain()
278
+ * .flip('h')
279
+ * .build();
280
+ * ```
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const chain = FilterPresets.chain()
285
+ * .flip('v')
286
+ * .build();
287
+ * ```
116
288
  */
117
- hflip(): string | null;
289
+ flip(direction: 'h' | 'v'): FilterPreset;
118
290
  /**
119
- * 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
120
293
  *
121
- * @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.
122
317
  *
123
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#vflip | FFmpeg vflip filter}
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
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * const filter = hwPresets.tonemap();
326
+ * ```
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const filter = hwPresets.tonemap({ tonemap: 'hable', desat: '0' });
331
+ * ```
124
332
  */
125
- vflip(): string | null;
333
+ tonemap(alg: string, options: Record<string, string | number>): FilterPreset;
126
334
  /**
127
335
  * Creates a fade filter string for video.
128
336
  *
@@ -131,9 +339,15 @@ export declare abstract class FilterPresetBase {
131
339
  * @param duration - Fade duration in seconds
132
340
  * @returns Filter string or null if not supported
133
341
  *
342
+ * @example
343
+ * ```typescript
344
+ * presets.fade('in', 0, 2) // 2-second fade in from start
345
+ * presets.fade('out', 10, 1) // 1-second fade out at 10 seconds
346
+ * ```
347
+ *
134
348
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#fade | FFmpeg fade filter}
135
349
  */
136
- fade(type: 'in' | 'out', start: number, duration: number): string | null;
350
+ fade(type: 'in' | 'out', start: number, duration: number): FilterPreset;
137
351
  /**
138
352
  * Creates an overlay filter string to composite two video streams.
139
353
  *
@@ -153,16 +367,22 @@ export declare abstract class FilterPresetBase {
153
367
  *
154
368
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#overlay | FFmpeg overlay filter}
155
369
  */
156
- overlay(x?: number, y?: number, options?: Record<string, string>): string | null;
370
+ overlay(x?: number, y?: number, options?: Record<string, string>): FilterPreset;
157
371
  /**
158
372
  * Creates a volume filter string for audio.
159
373
  *
160
374
  * @param factor - Volume multiplication factor (1.0 = unchanged, 2.0 = double)
161
375
  * @returns Filter string or null if not supported
162
376
  *
377
+ * @example
378
+ * ```typescript
379
+ * presets.volume(0.5) // Reduce volume by 50%
380
+ * presets.volume(1.5) // Increase volume by 50%
381
+ * ```
382
+ *
163
383
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#volume | FFmpeg volume filter}
164
384
  */
165
- volume(factor: number): string | null;
385
+ volume(factor: number): FilterPreset;
166
386
  /**
167
387
  * Creates an audio format filter string.
168
388
  *
@@ -185,705 +405,628 @@ export declare abstract class FilterPresetBase {
185
405
  *
186
406
  * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aformat | FFmpeg aformat filter}
187
407
  */
188
- aformat(sampleFormat: string | AVSampleFormat, sampleRate?: number, channelLayout?: string): string | null;
189
- /**
190
- * Creates an atempo filter string to change audio playback speed.
191
- * Factor must be between 0.5 and 2.0. For larger changes, chain multiple atempo filters.
192
- *
193
- * @param factor - Tempo factor (0.5 = half speed, 2.0 = double speed)
194
- * @returns Filter string or null if not supported
195
- *
196
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#atempo | FFmpeg atempo filter}
197
- */
198
- atempo(factor: number): string | null;
199
- /**
200
- * Creates an audio fade filter string.
201
- *
202
- * @param type - Fade type ('in' or 'out')
203
- * @param start - Start time in seconds
204
- * @param duration - Fade duration in seconds
205
- * @returns Filter string or null if not supported
206
- *
207
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#afade | FFmpeg afade filter}
208
- */
209
- afade(type: 'in' | 'out', start: number, duration: number): string | null;
210
- /**
211
- * Creates an amix filter string to mix multiple audio streams.
212
- *
213
- * @param inputs - Number of input streams to mix (default: 2)
214
- * @param duration - How to determine output duration (default: 'longest')
215
- * @returns Filter string or null if not supported
216
- *
217
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#amix | FFmpeg amix filter}
218
- */
219
- amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): string | null;
220
- }
221
- /**
222
- * Filter chain builder for composing multiple filters.
223
- * Allows fluent API for building complex filter graphs by chaining filter operations.
224
- *
225
- * @example
226
- * ```typescript
227
- * const chain = new FilterChain()
228
- * .add('scale=1920:1080')
229
- * .add('fps=30')
230
- * .custom('rotate=45*PI/180')
231
- * .build();
232
- * // Result: "scale=1920:1080,fps=30,rotate=45*PI/180"
233
- * ```
234
- */
235
- export declare class FilterChain {
236
- private filters;
237
- /**
238
- * Adds a filter to the chain.
239
- *
240
- * @param filter - Filter string to add (ignored if null/undefined)
241
- * @returns This instance for chaining
242
- */
243
- add(filter: string | null | undefined): this;
244
- /**
245
- * Adds a custom filter string to the chain.
246
- *
247
- * @param filter - Custom filter string
248
- * @returns This instance for chaining
249
- */
250
- custom(filter: string): this;
251
- /**
252
- * Builds the final filter string.
253
- *
254
- * @param separator - Separator between filters (default: ',')
255
- * @returns Combined filter string
256
- */
257
- build(separator?: string): string;
258
- /**
259
- * Returns the filters as an array.
260
- *
261
- * @returns Array of filter strings
262
- */
263
- toArray(): string[];
264
- }
265
- /**
266
- * Base chain builder with common filter methods.
267
- * Provides a fluent API for building filter chains using preset methods.
268
- *
269
- * @template T The preset type this builder uses
270
- *
271
- * @example
272
- * ```typescript
273
- * const chain = new ChainBuilderBase(presets)
274
- * .scale(1920, 1080)
275
- * .fps(30)
276
- * .fade('in', 0, 2)
277
- * .build();
278
- * ```
279
- */
280
- export declare abstract class ChainBuilderBase<T extends FilterPresetBase> extends FilterChain {
281
- protected readonly presets: T;
282
- /**
283
- * @param presets - The filter presets to use
284
- * @internal
285
- */
286
- constructor(presets: T);
287
- /**
288
- * Adds a scale filter to the chain.
289
- *
290
- * @param width - Target width
291
- * @param height - Target height
292
- * @param options - Additional scaling options
293
- * @returns This instance for chaining
294
- *
295
- * @see {@link FilterPresetBase.scale}
296
- */
297
- scale(width: number, height: number, options?: Record<string, any>): this;
408
+ aformat(sampleFormat: AVSampleFormat | AVSampleFormat[], sampleRate?: number, channelLayout?: string): FilterPreset;
298
409
  /**
299
- * Adds a crop filter to the chain.
410
+ * Adds an asetnsamples filter to set the number of samples per frame.
411
+ * This is crucial for encoders like Opus that require specific frame sizes.
300
412
  *
301
- * @param width - Crop width
302
- * @param height - Crop height
303
- * @param x - X position (default: 0)
304
- * @param y - Y position (default: 0)
413
+ * @param samples - Number of samples per frame
414
+ * @param padding - Whether to pad or drop samples (default: true)
305
415
  * @returns This instance for chaining
306
416
  *
307
- * @see {@link FilterPresetBase.crop}
308
- */
309
- crop(width: number, height: number, x?: number, y?: number): this;
310
- /**
311
- * Adds an FPS filter to the chain.
417
+ * @example
418
+ * ```typescript
419
+ * // For Opus encoder (requires 960 samples)
420
+ * chain.asetnsamples(960);
312
421
  *
313
- * @param fps - Target frame rate
314
- * @returns This instance for chaining
422
+ * // Drop samples instead of padding
423
+ * chain.asetnsamples(1024, false);
424
+ * ```
315
425
  *
316
- * @see {@link FilterPresetBase.fps}
426
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#asetnsamples | FFmpeg asetnsamples filter}
317
427
  */
318
- fps(fps: number): this;
428
+ asetnsamples(samples: number, padding?: boolean): FilterPreset;
319
429
  /**
320
- * Adds a format filter to the chain.
430
+ * Adds an aresample filter to change audio sample rate.
321
431
  *
322
- * @param pixelFormat - Target pixel format(s)
432
+ * @param rate - Target sample rate in Hz
323
433
  * @returns This instance for chaining
324
434
  *
325
- * @see {@link FilterPresetBase.format}
326
- */
327
- format(pixelFormat: string | AVPixelFormat | (string | AVPixelFormat)[]): this;
328
- /**
329
- * Adds a rotate filter to the chain.
330
- *
331
- * @param angle - Rotation angle in degrees
332
- * @returns This instance for chaining
435
+ * @example
436
+ * ```typescript
437
+ * chain.aresample(44100) // Convert to 44.1 kHz
438
+ * chain.aresample(48000) // Convert to 48 kHz
439
+ * ```
333
440
  *
334
- * @see {@link FilterPresetBase.rotate}
441
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aresample | FFmpeg aresample filter}
335
442
  */
336
- rotate(angle: number): this;
443
+ aresample(rate: number): FilterPreset;
337
444
  /**
338
- * Adds a horizontal flip filter to the chain.
445
+ * Adds an atempo filter to change audio playback speed.
446
+ * Factor must be between 0.5 and 2.0. For larger changes, chain multiple atempo filters.
339
447
  *
448
+ * @param factor - Tempo factor (0.5 = half speed, 2.0 = double speed)
340
449
  * @returns This instance for chaining
341
450
  *
342
- * @see {@link FilterPresetBase.hflip}
343
- */
344
- hflip(): this;
345
- /**
346
- * Adds a vertical flip filter to the chain.
347
- *
348
- * @returns This instance for chaining
451
+ * @example
452
+ * ```typescript
453
+ * chain.atempo(1.5) // 1.5x speed
454
+ * chain.atempo(0.8) // Slow down to 80% speed
455
+ * ```
349
456
  *
350
- * @see {@link FilterPresetBase.vflip}
457
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#atempo | FFmpeg atempo filter}
351
458
  */
352
- vflip(): this;
459
+ atempo(factor: number): FilterPreset;
353
460
  /**
354
- * Adds a fade filter to the chain.
461
+ * Adds an audio fade filter.
355
462
  *
356
463
  * @param type - Fade type ('in' or 'out')
357
464
  * @param start - Start time in seconds
358
465
  * @param duration - Fade duration in seconds
359
466
  * @returns This instance for chaining
360
467
  *
361
- * @see {@link FilterPresetBase.fade}
362
- */
363
- fade(type: 'in' | 'out', start: number, duration: number): this;
364
- /**
365
- * Adds an overlay filter to the chain.
366
- *
367
- * @param x - X position (default: 0)
368
- * @param y - Y position (default: 0)
369
- * @param options - Additional overlay options
370
- * @returns This instance for chaining
468
+ * @example
469
+ * ```typescript
470
+ * chain.afade('in', 0, 3) // 3-second audio fade in
471
+ * chain.afade('out', 20, 2) // 2-second fade out at 20s
472
+ * ```
371
473
  *
372
- * @see {@link FilterPresetBase.overlay}
474
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#afade | FFmpeg afade filter}
373
475
  */
374
- overlay(x?: number, y?: number, options?: Record<string, string>): this;
476
+ afade(type: 'in' | 'out', start: number, duration: number): FilterPreset;
375
477
  /**
376
- * Adds a volume filter to the chain.
478
+ * Adds an amix filter to mix multiple audio streams.
377
479
  *
378
- * @param factor - Volume factor
480
+ * @param inputs - Number of input streams to mix (default: 2)
481
+ * @param duration - How to determine output duration (default: 'longest')
379
482
  * @returns This instance for chaining
380
483
  *
381
- * @see {@link FilterPresetBase.volume}
484
+ * @example
485
+ * ```typescript
486
+ * chain.amix(3, 'longest') // Mix 3 audio streams
487
+ * chain.amix(2, 'first') // Mix 2 streams, use first's duration
488
+ * ```
489
+ *
490
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#amix | FFmpeg amix filter}
382
491
  */
383
- volume(factor: number): this;
492
+ amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): FilterPreset;
384
493
  /**
385
- * Adds an audio format filter to the chain.
494
+ * Adds a pad filter to add padding to video.
495
+ * Essential for aspect ratio adjustments and letterboxing.
386
496
  *
387
- * @param sampleFormat - Target sample format
388
- * @param sampleRate - Target sample rate (optional)
389
- * @param channelLayout - Target channel layout (optional)
497
+ * @param width - Output width (can use expressions like 'iw+100')
498
+ * @param height - Output height (can use expressions like 'ih+100')
499
+ * @param x - X position of input video (default: '(ow-iw)/2' for center)
500
+ * @param y - Y position of input video (default: '(oh-ih)/2' for center)
501
+ * @param color - Padding color (default: 'black')
390
502
  * @returns This instance for chaining
391
503
  *
392
- * @see {@link FilterPresetBase.aformat}
393
- */
394
- aformat(sampleFormat: string | AVSampleFormat, sampleRate?: number, channelLayout?: string): this;
395
- /**
396
- * Adds an atempo filter to the chain.
504
+ * @example
505
+ * ```typescript
506
+ * // Add black bars for 16:9 aspect ratio
507
+ * chain.pad('iw', 'iw*9/16');
397
508
  *
398
- * @param factor - Tempo factor (0.5 to 2.0)
399
- * @returns This instance for chaining
509
+ * // Add 50px padding on all sides
510
+ * chain.pad('iw+100', 'ih+100');
511
+ * ```
400
512
  *
401
- * @see {@link FilterPresetBase.atempo}
513
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#pad | FFmpeg pad filter}
402
514
  */
403
- atempo(factor: number): this;
515
+ pad(width: string | number, height: string | number, x?: string, y?: string, color?: string): FilterPreset;
404
516
  /**
405
- * Adds an audio fade filter to the chain.
517
+ * Adds a trim filter to cut a portion of the stream.
518
+ * Crucial for cutting segments from media.
406
519
  *
407
- * @param type - Fade type ('in' or 'out')
408
520
  * @param start - Start time in seconds
409
- * @param duration - Fade duration in seconds
521
+ * @param end - End time in seconds (optional)
522
+ * @param duration - Duration in seconds (optional, alternative to end)
410
523
  * @returns This instance for chaining
411
524
  *
412
- * @see {@link FilterPresetBase.afade}
525
+ * @example
526
+ * ```typescript
527
+ * chain.trim(10, 30) // Extract from 10s to 30s
528
+ * chain.trim(5, undefined, 10) // Extract 10s starting at 5s
529
+ * ```
530
+ *
531
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#trim | FFmpeg trim filter}
413
532
  */
414
- afade(type: 'in' | 'out', start: number, duration: number): this;
533
+ trim(start: number, end?: number, duration?: number): FilterPreset;
415
534
  /**
416
- * Adds an amix filter to the chain.
535
+ * Creates a setpts filter string to change presentation timestamps.
536
+ * Essential for speed changes and timestamp manipulation.
417
537
  *
418
- * @param inputs - Number of inputs (default: 2)
419
- * @param duration - Duration mode (default: 'longest')
420
- * @returns This instance for chaining
538
+ * @param expression - PTS expression (e.g., 'PTS*2' for half speed, 'PTS/2' for double speed)
539
+ * @returns Filter string or null if not supported
421
540
  *
422
- * @see {@link FilterPresetBase.amix}
423
- */
424
- amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): this;
425
- /**
426
- * Adds a transpose filter to the chain (hardware-specific).
427
- * Only available for hardware presets that support transpose
541
+ * @example
542
+ * ```typescript
543
+ * // Double speed
544
+ * presets.setpts('PTS/2');
428
545
  *
429
- * @param dir - Transpose direction (default: 0)
430
- * @returns This instance for chaining
546
+ * // Half speed
547
+ * presets.setpts('PTS*2');
548
+ *
549
+ * // Reset timestamps
550
+ * presets.setpts('PTS-STARTPTS');
551
+ * ```
431
552
  *
553
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#setpts | FFmpeg setpts filter}
432
554
  */
433
- transpose(dir?: number): this;
555
+ setpts(expression: string): FilterPreset;
434
556
  /**
435
- * Adds a tonemap filter to the chain (hardware-specific).
436
- * Only available for hardware presets that support tonemapping
557
+ * Creates an asetpts filter string for audio timestamp manipulation.
437
558
  *
438
- * @param options - Tonemapping options
439
- * @returns This instance for chaining
559
+ * @param expression - PTS expression
560
+ * @returns Filter string or null if not supported
561
+ *
562
+ * @example
563
+ * ```typescript
564
+ * presets.asetpts('PTS-STARTPTS') // Reset timestamps to start from 0
565
+ * ```
440
566
  *
567
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#asetpts | FFmpeg asetpts filter}
441
568
  */
442
- tonemap(options?: Record<string, string>): this;
569
+ asetpts(expression: string): FilterPreset;
443
570
  /**
444
- * Adds a deinterlace filter to the chain (hardware-specific).
445
- * Only available for hardware presets that support deinterlacing
571
+ * Creates a transpose filter string for rotation/flipping.
572
+ * More efficient than rotate for 90-degree rotations.
446
573
  *
447
- * @param mode - Deinterlace mode (optional)
448
- * @returns This instance for chaining
574
+ * @param mode - Transpose mode (0-3, or named constants)
575
+ * @returns Filter string or null if not supported
576
+ *
577
+ * @example
578
+ * ```typescript
579
+ * presets.transpose(1) // Rotate 90 degrees clockwise
580
+ * presets.transpose('cclock') // Rotate 90 degrees counter-clockwise
581
+ * ```
449
582
  *
583
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#transpose | FFmpeg transpose filter}
450
584
  */
451
- deinterlace(mode?: string): this;
585
+ transpose(mode: number | 'clock' | 'cclock' | 'clock_flip' | 'cclock_flip'): FilterPreset;
452
586
  /**
453
- * Adds a flip filter to the chain (hardware-specific).
454
- * Falls back to hflip/vflip if hardware flip not available
587
+ * Creates a setsar filter string to set sample aspect ratio.
588
+ * Important for correcting aspect ratio issues.
455
589
  *
456
- * @param direction - Flip direction ('h' or 'v')
457
- * @returns This instance for chaining
590
+ * @param ratio - Aspect ratio (e.g., '1:1', '16:9', or number)
591
+ * @returns Filter string or null if not supported
592
+ *
593
+ * @example
594
+ * ```typescript
595
+ * presets.setsar('1:1') // Square pixels
596
+ * presets.setsar(1.333) // 4:3 aspect ratio
597
+ * ```
458
598
  *
599
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#setsar | FFmpeg setsar/setdar filter}
459
600
  */
460
- flip(direction: 'h' | 'v'): this;
601
+ setsar(ratio: string | number): FilterPreset;
461
602
  /**
462
- * Adds a blur filter to the chain (hardware-specific).
463
- * Only available for hardware presets that support blur
603
+ * Creates a setdar filter string to set display aspect ratio.
464
604
  *
465
- * @param type - Blur type (default: 'avg')
466
- * @param radius - Blur radius (optional)
467
- * @returns This instance for chaining
605
+ * @param ratio - Aspect ratio (e.g., '16:9', '4:3')
606
+ * @returns Filter string or null if not supported
607
+ *
608
+ * @example
609
+ * ```typescript
610
+ * presets.setdar('16:9') // Widescreen
611
+ * presets.setdar('4:3') // Traditional TV aspect
612
+ * ```
468
613
  *
614
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#setsar | FFmpeg setsar/setdar filter}
469
615
  */
470
- blur(type?: 'avg' | 'gaussian' | 'box', radius?: number): this;
616
+ setdar(ratio: string | number): FilterPreset;
471
617
  /**
472
- * Adds a sharpen filter to the chain (hardware-specific).
473
- * Only available for hardware presets that support sharpening
618
+ * Adds an apad filter to add audio padding.
619
+ * Useful for ensuring minimum audio duration.
474
620
  *
475
- * @param amount - Sharpen amount (optional)
621
+ * @param wholeDuration - Minimum duration in seconds (optional)
622
+ * @param padDuration - Amount of padding to add in seconds (optional)
476
623
  * @returns This instance for chaining
477
624
  *
625
+ * @example
626
+ * ```typescript
627
+ * chain.apad(30) // Ensure at least 30 seconds total
628
+ * chain.apad(undefined, 5) // Add 5 seconds of padding
629
+ * ```
630
+ *
631
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#apad | FFmpeg apad filter}
478
632
  */
479
- sharpen(amount?: number): this;
633
+ apad(wholeDuration?: number, padDuration?: number): FilterPreset;
480
634
  /**
481
- * Adds a stack filter to the chain (hardware-specific).
482
- * Only available for hardware presets that support stacking
635
+ * Creates a deinterlace filter string.
636
+ * Essential for processing interlaced content.
483
637
  *
484
- * @param type - Stack type ('h' for horizontal, 'v' for vertical, 'x' for grid)
485
- * @param inputs - Number of inputs (default: 2)
486
- * @returns This instance for chaining
638
+ * @param mode - Deinterlace mode (default: 'yadif')
639
+ * @param options - Additional options for the filter
640
+ * @returns Filter string or null if not supported
487
641
  *
488
- */
489
- stack(type: 'h' | 'v' | 'x', inputs?: number): this;
490
- /**
491
- * Adds a hwupload filter to upload frames to hardware.
642
+ * @example
643
+ * ```typescript
644
+ * presets.deinterlace('yadif') // Standard deinterlacing
645
+ * presets.deinterlace('bwdif') // Bob Weaver deinterlacing
646
+ * ```
492
647
  *
493
- * @returns This instance for chaining
648
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#yadif | FFmpeg yadif filter}
494
649
  */
495
- hwupload(): this;
650
+ deinterlace(mode?: 'yadif' | 'bwdif' | 'w3fdif', options?: Record<string, any>): FilterPreset;
496
651
  /**
497
- * Adds a hwdownload filter to download frames from hardware.
652
+ * Creates a select filter string to select specific frames.
653
+ * Powerful for extracting keyframes, specific frame types, etc.
498
654
  *
499
- * @returns This instance for chaining
500
- */
501
- hwdownload(): this;
502
- /**
503
- * Adds a hwmap filter to map frames between hardware devices.
655
+ * @param expression - Selection expression
656
+ * @returns Filter string or null if not supported
504
657
  *
505
- * @param derive - Device to derive from (optional)
506
- * @returns This instance for chaining
658
+ * @example
659
+ * ```typescript
660
+ * presets.select('eq(pict_type,I)') // Select only keyframes
661
+ * presets.select('not(mod(n,10))') // Select every 10th frame
662
+ * ```
663
+ *
664
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#select | FFmpeg select filter}
507
665
  */
508
- hwmap(derive?: string): this;
509
- }
510
- /**
511
- * Fluent filter chain builder with preset methods.
512
- * Provides a convenient API for building filter chains using standard presets.
513
- *
514
- * @example
515
- * ```typescript
516
- * const filter = FilterPresets.chain()
517
- * .scale(1920, 1080)
518
- * .fps(30)
519
- * .fade('in', 0, 2)
520
- * .format('yuv420p')
521
- * .build();
522
- * ```
523
- */
524
- export declare class FilterChainBuilder extends ChainBuilderBase<FilterPresets> {
525
- }
526
- /**
527
- * Standard filter presets for software filtering.
528
- * Provides static methods for creating common filter strings and
529
- * a chain builder for composing complex filter graphs.
530
- *
531
- * @example
532
- * ```typescript
533
- * // Static methods for individual filters
534
- * const scaleFilter = FilterPresets.scale(1920, 1080);
535
- * const fpsFilter = FilterPresets.fps(30);
536
- *
537
- * // Chain builder for complex graphs
538
- * const chain = FilterPresets.chain()
539
- * .scale(1920, 1080)
540
- * .fps(30)
541
- * .fade('in', 0, 2)
542
- * .build();
543
- * ```
544
- */
545
- export declare class FilterPresets extends FilterPresetBase {
546
- private static instance;
666
+ select(expression: string): FilterPreset;
547
667
  /**
548
- * Creates a new filter chain builder.
668
+ * Creates an aselect filter string for audio selection.
549
669
  *
550
- * @returns A new FilterChainBuilder instance
670
+ * @param expression - Selection expression
671
+ * @returns Filter string or null if not supported
551
672
  *
552
673
  * @example
553
674
  * ```typescript
554
- * const filter = FilterPresets.chain()
555
- * .scale(1280, 720)
556
- * .fps(30)
557
- * .build();
675
+ * presets.aselect('between(t,10,20)') // Select audio between 10-20 seconds
558
676
  * ```
559
- */
560
- static chain(): FilterChainBuilder;
561
- /**
562
- * Creates a scale filter string.
563
677
  *
564
- * @param width - Target width
565
- * @param height - Target height
566
- * @param flags - Scaling algorithm flags (optional)
567
- * @returns Scale filter string
678
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aselect | FFmpeg aselect filter}
568
679
  */
569
- static scale(width: number, height: number, flags?: string): string;
680
+ aselect(expression: string): FilterPreset;
570
681
  /**
571
- * Creates a crop filter string.
682
+ * Creates a concat filter string to concatenate multiple inputs.
683
+ * Essential for joining multiple video/audio segments.
572
684
  *
573
- * @param width - Crop width
574
- * @param height - Crop height
575
- * @param x - X position (default: 0)
576
- * @param y - Y position (default: 0)
577
- * @returns Crop filter string
578
- */
579
- static crop(width: number, height: number, x?: number, y?: number): string;
580
- /**
581
- * Creates an FPS filter string.
685
+ * @param n - Number of input segments
686
+ * @param v - Number of output video streams (0 or 1)
687
+ * @param a - Number of output audio streams (0 or 1)
688
+ * @returns Filter string or null if not supported
582
689
  *
583
- * @param fps - Target frame rate
584
- * @returns FPS filter string
585
- */
586
- static fps(fps: number): string;
587
- /**
588
- * Creates a format filter string.
690
+ * @example
691
+ * ```typescript
692
+ * presets.concat(3, 1, 1) // Join 3 segments with video and audio
693
+ * presets.concat(2, 1, 0) // Join 2 video-only segments
694
+ * ```
589
695
  *
590
- * @param pixelFormat - Target pixel format(s)
591
- * @returns Format filter string
696
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#concat | FFmpeg concat filter}
592
697
  */
593
- static format(pixelFormat: string | AVPixelFormat | (string | AVPixelFormat)[]): string;
698
+ concat(n: number, v?: number, a?: number): FilterPreset;
594
699
  /**
595
- * Creates a rotate filter string.
700
+ * Creates an amerge filter string to merge multiple audio streams into one.
701
+ * Different from amix - this creates multi-channel output.
596
702
  *
597
- * @param angle - Rotation angle in degrees
598
- * @returns Rotate filter string
599
- */
600
- static rotate(angle: number): string;
601
- /**
602
- * Creates a horizontal flip filter string.
703
+ * @param inputs - Number of input streams
704
+ * @returns Filter string or null if not supported
603
705
  *
604
- * @returns Horizontal flip filter string
605
- */
606
- static hflip(): string;
607
- /**
608
- * Creates a vertical flip filter string.
706
+ * @example
707
+ * ```typescript
708
+ * presets.amerge(2) // Merge 2 mono streams to stereo
709
+ * presets.amerge(6) // Merge 6 channels for 5.1 surround
710
+ * ```
609
711
  *
610
- * @returns Vertical flip filter string
712
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#amerge | FFmpeg amerge filter}
611
713
  */
612
- static vflip(): string;
714
+ amerge(inputs?: number): FilterPreset;
613
715
  /**
614
- * Creates a fade filter string.
716
+ * Creates a channelmap filter string to remap audio channels.
717
+ * Critical for audio channel manipulation.
615
718
  *
616
- * @param type - Fade type ('in' or 'out')
617
- * @param start - Start time in seconds
618
- * @param duration - Fade duration in seconds
619
- * @returns Fade filter string
620
- */
621
- static fade(type: 'in' | 'out', start: number, duration: number): string;
622
- /**
623
- * Creates an overlay filter string.
719
+ * @param map - Channel mapping (e.g., '0-0|1-1' or 'FL-FR|FR-FL' to swap stereo)
720
+ * @returns Filter string or null if not supported
624
721
  *
625
- * @param x - X position (default: 0)
626
- * @param y - Y position (default: 0)
627
- * @returns Overlay filter string
628
- */
629
- static overlay(x?: number, y?: number): string;
630
- /**
631
- * Creates a volume filter string.
722
+ * @example
723
+ * ```typescript
724
+ * presets.channelmap('FL-FR|FR-FL') // Swap left and right channels
725
+ * presets.channelmap('0-0|0-1') // Duplicate mono to stereo
726
+ * ```
632
727
  *
633
- * @param factor - Volume multiplication factor
634
- * @returns Volume filter string
728
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#channelmap | FFmpeg channelmap filter}
635
729
  */
636
- static volume(factor: number): string;
730
+ channelmap(map: string): FilterPreset;
637
731
  /**
638
- * Creates an audio format filter string.
732
+ * Creates a channelsplit filter string to split audio channels.
639
733
  *
640
- * @param sampleFormat - Target sample format
641
- * @param sampleRate - Target sample rate (optional)
642
- * @param channelLayout - Target channel layout (optional)
643
- * @returns Audio format filter string
644
- */
645
- static aformat(sampleFormat: string | AVSampleFormat, sampleRate?: number, channelLayout?: string): string;
646
- /**
647
- * Creates an atempo filter string.
734
+ * @param channelLayout - Channel layout to split (optional)
735
+ * @returns Filter string or null if not supported
648
736
  *
649
- * @param factor - Tempo factor (0.5 to 2.0)
650
- * @returns Atempo filter string
651
- */
652
- static atempo(factor: number): string;
653
- /**
654
- * Creates an audio fade filter string.
737
+ * @example
738
+ * ```typescript
739
+ * presets.channelsplit('stereo') // Split stereo to 2 mono
740
+ * presets.channelsplit('5.1') // Split 5.1 to individual channels
741
+ * ```
655
742
  *
656
- * @param type - Fade type ('in' or 'out')
657
- * @param start - Start time in seconds
658
- * @param duration - Fade duration in seconds
659
- * @returns Audio fade filter string
743
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#channelsplit | FFmpeg channelsplit filter}
660
744
  */
661
- static afade(type: 'in' | 'out', start: number, duration: number): string;
745
+ channelsplit(channelLayout?: string): FilterPreset;
662
746
  /**
663
- * Creates an amix filter string.
747
+ * Creates a loudnorm filter string for loudness normalization.
748
+ * Essential for broadcast compliance and consistent audio levels.
664
749
  *
665
- * @param inputs - Number of inputs (default: 2)
666
- * @param duration - Duration mode (default: 'longest')
667
- * @returns Amix filter string
750
+ * @param I - Integrated loudness target (default: -24 LUFS)
751
+ * @param TP - True peak (default: -2 dBTP)
752
+ * @param LRA - Loudness range (default: 7 LU)
753
+ * @returns Filter string or null if not supported
754
+ *
755
+ * @example
756
+ * ```typescript
757
+ * presets.loudnorm(-23, -1, 7) // EBU R128 broadcast standard
758
+ * presets.loudnorm(-16, -1.5, 11) // Streaming platforms standard
759
+ * ```
760
+ *
761
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#loudnorm | FFmpeg loudnorm filter}
668
762
  */
669
- static amix(inputs?: number, duration?: 'first' | 'longest' | 'shortest'): string;
670
- }
671
- /**
672
- * Hardware-accelerated filter presets.
673
- * Provides optimized filter implementations for specific hardware types,
674
- * with automatic fallback when operations aren't supported.
675
- *
676
- * @example
677
- * ```typescript
678
- * // Create hardware presets for CUDA
679
- * const hw = new HardwareFilterPresets(AV_HWDEVICE_TYPE_CUDA, 'cuda');
680
- *
681
- * // Check capabilities
682
- * if (hw.support.scale) {
683
- * const scaleFilter = hw.scale(1920, 1080);
684
- * }
685
- *
686
- * // Use chain builder
687
- * const chain = hw.chain()
688
- * .hwupload()
689
- * .scale(1920, 1080)
690
- * .tonemap()
691
- * .hwdownload()
692
- * .build();
693
- * ```
694
- */
695
- export declare class HardwareFilterPresets extends FilterPresetBase {
696
- private readonly deviceType;
697
- private readonly deviceTypeName;
698
- readonly support: HardwareFilterSupport;
763
+ loudnorm(I?: number, TP?: number, LRA?: number): FilterPreset;
699
764
  /**
700
- * @param deviceType - Hardware device type enum
701
- * @param deviceTypeName - Hardware device type name (e.g., 'cuda', 'vaapi')
765
+ * Creates a compand filter string for audio compression/expansion.
766
+ * Important for dynamic range control.
767
+ *
768
+ * @param attacks - Attack times
769
+ * @param decays - Decay times
770
+ * @param points - Transfer function points
771
+ * @param gain - Output gain
772
+ * @returns Filter string or null if not supported
773
+ *
774
+ * @example
775
+ * ```typescript
776
+ * presets.compand('0.3|0.3', '1|1', '-90/-60|-60/-40|-40/-30|-20/-20', 6)
777
+ * ```
778
+ *
779
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#compand | FFmpeg compand filter}
702
780
  */
703
- constructor(deviceType: AVHWDeviceType, deviceTypeName: string);
781
+ compand(attacks: string, decays: string, points: string, gain?: number): FilterPreset;
704
782
  /**
705
- * Checks if a filter is hardware-accelerated.
783
+ * Adds a drawtext filter to overlay text on video.
706
784
  *
707
- * @param filterName - Name of the filter to check
708
- * @returns True if the filter uses hardware acceleration
785
+ * @param text - Text to display
786
+ * @param options - Text rendering options
787
+ * @returns This instance for chaining
709
788
  *
710
789
  * @example
711
790
  * ```typescript
712
- * if (HardwareFilterPresets.isHardwareFilter('scale_cuda')) {
713
- * console.log('Hardware accelerated scaling');
714
- * }
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
+ * })
715
799
  * ```
800
+ *
801
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#drawtext | FFmpeg drawtext filter}
716
802
  */
717
- static isHardwareFilter(filterName: string): boolean;
803
+ drawtext(text: string, options: Record<string, any>): FilterPreset;
718
804
  /**
719
- * Creates a hardware filter chain builder.
805
+ * Adds a split filter to duplicate a video stream.
720
806
  *
721
- * @returns A new HardwareFilterChainBuilder instance
807
+ * @param outputs - Number of output streams (default: 2)
808
+ * @returns This instance for chaining
722
809
  *
723
810
  * @example
724
811
  * ```typescript
725
- * const filter = hw.chain()
726
- * .hwupload()
727
- * .scale(1920, 1080)
728
- * .hwdownload()
729
- * .build();
812
+ * chain.split() // Split into 2 outputs
813
+ * chain.split(3) // Split into 3 outputs
730
814
  * ```
815
+ *
816
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#split | FFmpeg split filter}
731
817
  */
732
- chain(): HardwareFilterChainBuilder;
818
+ split(outputs?: number): FilterPreset;
733
819
  /**
734
- * Creates a hardware-accelerated scale filter.
735
- *
736
- * Different hardware types use different scale filters:
737
- * - CUDA: scale_cuda or scale_npp (with npp option)
738
- * - VAAPI: scale_vaapi
739
- * - QSV: scale_qsv
740
- * - VideoToolbox: scale_vt
741
- * - RKMPP: scale_rkrga
820
+ * Adds an asplit filter to duplicate an audio stream.
742
821
  *
743
- * @param width - Target width
744
- * @param height - Target height
745
- * @param options - Hardware-specific scaling options
746
- * @returns Hardware scale filter string or null if not supported
822
+ * @param outputs - Number of output streams (default: 2)
823
+ * @returns This instance for chaining
747
824
  *
825
+ * @example
826
+ * ```typescript
827
+ * chain.asplit() // Split into 2 outputs
828
+ * chain.asplit(3) // Split into 3 outputs
829
+ * ```
748
830
  *
749
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#scale_005fcuda | FFmpeg scale_cuda filter}
831
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#asplit | FFmpeg asplit filter}
750
832
  */
751
- scale(width: number, height: number, options?: Record<string, any>): string | null;
833
+ asplit(outputs?: number): FilterPreset;
752
834
  /**
753
- * Creates a hardware-accelerated overlay filter.
835
+ * Adds an adelay filter to delay audio by specified milliseconds.
754
836
  *
755
- * @param x - X position (default: 0)
756
- * @param y - Y position (default: 0)
757
- * @param options - Hardware-specific overlay options
758
- * @returns Hardware overlay filter string or null if not supported
837
+ * @param delays - Delay in milliseconds (single value or array for multiple channels)
838
+ * @returns This instance for chaining
839
+ *
840
+ * @example
841
+ * ```typescript
842
+ * chain.adelay(100) // Delay all channels by 100ms
843
+ * chain.adelay([100, 200]) // Delay first channel by 100ms, second by 200ms
844
+ * ```
759
845
  *
760
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#overlay_005fcuda | FFmpeg overlay_cuda filter}
846
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#adelay | FFmpeg adelay filter}
761
847
  */
762
- overlay(x?: number, y?: number, options?: Record<string, string>): string | null;
848
+ adelay(delays: number | number[]): FilterPreset;
763
849
  /**
764
- * Creates a hardware-accelerated transpose filter.
850
+ * Adds an aecho filter for audio echo effect.
765
851
  *
766
- * Direction values:
767
- * - 0: 90 degrees counter-clockwise and vertical flip
768
- * - 1: 90 degrees clockwise
769
- * - 2: 90 degrees counter-clockwise
770
- * - 3: 90 degrees clockwise and vertical flip
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)
856
+ * @returns This instance for chaining
771
857
  *
772
- * @param dir - Transpose direction (default: 0)
773
- * @returns Hardware transpose filter string or null if not supported
858
+ * @example
859
+ * ```typescript
860
+ * chain.aecho(0.8, 0.9, 1000, 0.3) // Echo with 1 second delay
861
+ * ```
774
862
  *
863
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#aecho | FFmpeg aecho filter}
775
864
  */
776
- transpose(dir?: number): string | null;
865
+ aecho(in_gain: number, out_gain: number, delays: number, decays: number): FilterPreset;
777
866
  /**
778
- * Creates a hardware-accelerated tonemap filter.
779
- * Used for HDR to SDR conversion with hardware acceleration.
867
+ * Adds a highpass filter to remove low frequencies.
780
868
  *
781
- * @param options - Tonemapping options (algorithm, parameters)
782
- * @returns Hardware tonemap filter string or null if not supported
869
+ * @param frequency - Cutoff frequency in Hz
870
+ * @param options - Additional filter options
871
+ * @returns This instance for chaining
783
872
  *
873
+ * @example
874
+ * ```typescript
875
+ * chain.highpass(200) // Remove frequencies below 200Hz
876
+ * chain.highpass(200, { width_type: 'q', width: 1 })
877
+ * ```
878
+ *
879
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#highpass | FFmpeg highpass filter}
784
880
  */
785
- tonemap(options?: Record<string, string>): string | null;
881
+ highpass(frequency: number, options?: Record<string, any>): FilterPreset;
786
882
  /**
787
- * Creates a hardware-accelerated deinterlace filter.
883
+ * Adds a lowpass filter to remove high frequencies.
788
884
  *
789
- * Different hardware types use different deinterlacers:
790
- * - CUDA: yadif_cuda
791
- * - VAAPI: deinterlace_vaapi
792
- * - QSV: deinterlace_qsv
793
- * - Vulkan: bwdif_vulkan
794
- * - VideoToolbox: yadif_videotoolbox
885
+ * @param frequency - Cutoff frequency in Hz
886
+ * @param options - Additional filter options
887
+ * @returns This instance for chaining
795
888
  *
796
- * @param mode - Deinterlacing mode (optional)
797
- * @returns Hardware deinterlace filter string or null if not supported
889
+ * @example
890
+ * ```typescript
891
+ * chain.lowpass(5000) // Remove frequencies above 5000Hz
892
+ * ```
798
893
  *
894
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#lowpass | FFmpeg lowpass filter}
799
895
  */
800
- deinterlace(mode?: string): string | null;
896
+ lowpass(frequency: number, options?: Record<string, any>): FilterPreset;
801
897
  /**
802
- * Creates a hardware-accelerated flip filter.
803
- * Currently only Vulkan supports hardware flip filters.
898
+ * Adds a bandpass filter to keep only a frequency band.
804
899
  *
805
- * @param direction - Flip direction ('h' for horizontal, 'v' for vertical)
806
- * @returns Hardware flip filter string or null if not supported
900
+ * @param frequency - Center frequency in Hz
901
+ * @param options - Additional filter options
902
+ * @returns This instance for chaining
903
+ *
904
+ * @example
905
+ * ```typescript
906
+ * chain.bandpass(1000) // Keep frequencies around 1000Hz
907
+ * ```
807
908
  *
909
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#bandpass | FFmpeg bandpass filter}
808
910
  */
809
- flip(direction: 'h' | 'v'): string | null;
911
+ bandpass(frequency: number, options?: Record<string, any>): FilterPreset;
810
912
  /**
811
- * Creates a hardware-accelerated blur filter.
913
+ * Adds an equalizer filter for frequency band adjustment.
812
914
  *
813
- * Different hardware types support different blur filters:
814
- * - CUDA: bilateral_cuda
815
- * - Vulkan: avgblur_vulkan, gblur_vulkan
816
- * - OpenCL: avgblur_opencl, boxblur_opencl
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)
919
+ * @returns This instance for chaining
817
920
  *
818
- * @param type - Blur type ('avg', 'gaussian', or 'box', default: 'avg')
819
- * @param radius - Blur radius (optional)
820
- * @returns Hardware blur filter string or null if not supported
921
+ * @example
922
+ * ```typescript
923
+ * chain.equalizer(1000, 2, 5) // Boost 1000Hz by 5dB
924
+ * chain.equalizer(1000, 2, 5, 'q') // Use Q factor for width
925
+ * ```
821
926
  *
927
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#equalizer | FFmpeg equalizer filter}
822
928
  */
823
- blur(type?: 'avg' | 'gaussian' | 'box', radius?: number): string | null;
929
+ equalizer(frequency: number, width: number, gain: number, width_type?: string): FilterPreset;
824
930
  /**
825
- * Creates a hardware-accelerated sharpen filter.
931
+ * Adds a compressor filter for dynamic range compression.
826
932
  *
827
- * Hardware sharpening support:
828
- * - VAAPI: sharpness_vaapi
829
- * - OpenCL: unsharp_opencl
830
- * - CUDA: sharpen_npp (NPP-based)
933
+ * @param options - Compressor parameters
934
+ * @returns This instance for chaining
831
935
  *
832
- * @param amount - Sharpening amount (optional)
833
- * @returns Hardware sharpen filter string or null if not supported
936
+ * @example
937
+ * ```typescript
938
+ * chain.compressor() // Default compression
939
+ * chain.compressor({
940
+ * threshold: 0.5,
941
+ * ratio: 4,
942
+ * attack: 5,
943
+ * release: 50
944
+ * })
945
+ * ```
834
946
  *
947
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#acompressor | FFmpeg acompressor filter}
835
948
  */
836
- sharpen(amount?: number): string | null;
949
+ compressor(options?: Record<string, any>): FilterPreset;
837
950
  /**
838
- * Creates a hardware-accelerated stack filter.
839
- * Only VAAPI and QSV support hardware stacking.
951
+ * Adds an atrim filter to trim audio.
840
952
  *
841
- * @param type - Stack type ('h' for horizontal, 'v' for vertical, 'x' for grid)
842
- * @param inputs - Number of inputs to stack (default: 2)
843
- * @returns Hardware stack filter string or null if not supported
953
+ * @param start - Start time in seconds
954
+ * @param end - End time in seconds (optional)
955
+ * @param duration - Duration in seconds (optional)
956
+ * @returns This instance for chaining
957
+ *
958
+ * @example
959
+ * ```typescript
960
+ * chain.atrim(10, 20) // Extract audio from 10s to 20s
961
+ * ```
844
962
  *
963
+ * @see {@link https://ffmpeg.org/ffmpeg-filters.html#atrim | FFmpeg atrim filter}
845
964
  */
846
- stack(type: 'h' | 'v' | 'x', inputs?: number): string | null;
965
+ atrim(start: number, end?: number, duration?: number): FilterPreset;
847
966
  /**
848
- * Creates a hwupload filter to upload frames to hardware memory.
849
- * CUDA uses hwupload_cuda, others use generic hwupload.
967
+ * Adds a hwupload filter to upload frames to hardware.
850
968
  *
851
- * @returns Hardware upload filter string
969
+ * @returns This instance for chaining
852
970
  *
853
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hwupload | FFmpeg hwupload filter}
971
+ * @example
972
+ * ```typescript
973
+ * const chain = FilterPresets.chain()
974
+ * .hwupload()
975
+ * .scale(1920, 1080)
976
+ * .build();
977
+ * ```
854
978
  */
855
- hwupload(): string | null;
979
+ hwupload(): FilterPreset;
856
980
  /**
857
- * Creates a hwdownload filter to download frames from hardware memory.
981
+ * Adds a hwdownload filter to download frames from hardware.
858
982
  *
859
- * @returns Hardware download filter string
983
+ * @returns This instance for chaining
860
984
  *
861
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hwdownload | FFmpeg hwdownload filter}
985
+ * @example
986
+ * ```typescript
987
+ * const chain = FilterPresets.chain()
988
+ * .scale(1920, 1080)
989
+ * .hwdownload()
990
+ * .build();
991
+ * ```
862
992
  */
863
- hwdownload(): string | null;
993
+ hwdownload(): FilterPreset;
864
994
  /**
865
- * Creates a hwmap filter to map frames between hardware devices.
995
+ * Adds a hwmap filter to map frames between hardware devices.
866
996
  *
867
997
  * @param derive - Device to derive from (optional)
868
- * @returns Hardware map filter string
869
998
  *
870
- * @see {@link https://ffmpeg.org/ffmpeg-filters.html#hwmap | FFmpeg hwmap filter}
999
+ * @returns This instance for chaining
1000
+ *
1001
+ * @example
1002
+ * ```typescript
1003
+ * const chain = FilterPresets.chain()
1004
+ * .hwmap('cuda')
1005
+ * .build();
1006
+ * ```
1007
+ *
1008
+ * @example
1009
+ * ```typescript
1010
+ * const chain = FilterPresets.chain()
1011
+ * .hwmap()
1012
+ * .build();
1013
+ * ```
871
1014
  */
872
- hwmap(derive?: string): string | null;
1015
+ hwmap(derive?: string): FilterPreset;
873
1016
  /**
874
- * Gets the filter capabilities for this hardware type.
1017
+ * Adds a filter to the chain.
875
1018
  *
876
- * @returns Object describing which filters are supported
1019
+ * @param filter - Filter string to add (ignored if null/undefined)
1020
+ * @returns This instance for chaining
877
1021
  *
878
1022
  * @example
879
1023
  * ```typescript
880
- * const caps = hw.getCapabilities();
881
- * if (caps.scale && caps.overlay) {
882
- * console.log('Hardware supports scaling and overlay');
883
- * }
1024
+ * chain.add('scale=1920:1080')
884
1025
  * ```
1026
+ *
1027
+ * @internal
885
1028
  */
886
- getCapabilities(): HardwareFilterSupport;
1029
+ private add;
887
1030
  /**
888
1031
  * Determines filter support for the hardware type.
889
1032
  *
@@ -893,20 +1036,3 @@ export declare class HardwareFilterPresets extends FilterPresetBase {
893
1036
  */
894
1037
  private getSupport;
895
1038
  }
896
- /**
897
- * Hardware filter chain builder with fluent API.
898
- * Automatically skips unsupported filters (returns null) allowing graceful fallback.
899
- *
900
- * @example
901
- * ```typescript
902
- * const hw = new HardwareFilterPresets(AV_HWDEVICE_TYPE_CUDA, 'cuda');
903
- * const chain = hw.chain()
904
- * .hwupload()
905
- * .scale(1920, 1080)
906
- * .tonemap() // Skipped if not supported
907
- * .hwdownload()
908
- * .build();
909
- * ```
910
- */
911
- export declare class HardwareFilterChainBuilder extends ChainBuilderBase<HardwareFilterPresets> {
912
- }