@revizly/node-av 5.2.2-beta.1

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 (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,1234 @@
1
+ import { Frame } from '../lib/frame.js';
2
+ import { Scheduler } from './utilities/scheduler.js';
3
+ import type { AVColorRange, AVColorSpace, AVFilterCmdFlag, AVPixelFormat, AVSampleFormat, EOFSignal } from '../constants/index.js';
4
+ import type { FilterContext } from '../lib/filter-context.js';
5
+ import type { ChannelLayout, IDimension, IRational } from '../lib/types.js';
6
+ import type { Encoder } from './encoder.js';
7
+ import type { HardwareContext } from './hardware.js';
8
+ /**
9
+ * Options for creating a filter instance.
10
+ */
11
+ export interface FilterOptions {
12
+ /**
13
+ * Number of threads for parallel processing.
14
+ *
15
+ * Controls the number of threads used for filter processing.
16
+ * Set to 0 to auto-detect based on CPU cores.
17
+ *
18
+ * @default 0 (auto-detect)
19
+ */
20
+ threads?: number;
21
+ /**
22
+ * Software scaler options for video filters.
23
+ *
24
+ * Options passed to libswscale when scaling video within filters.
25
+ * Maps to AVFilterGraph->scale_sws_opts.
26
+ */
27
+ scaleSwsOpts?: string;
28
+ /**
29
+ * Audio resampler options for audio filters.
30
+ *
31
+ * Options passed to libswresample when resampling audio within filters.
32
+ * Maps to AVFilterGraph->aresample_swr_opts.
33
+ */
34
+ audioResampleOpts?: string;
35
+ /**
36
+ * Hardware acceleration context.
37
+ *
38
+ * Pass a HardwareContext instance to enable hardware-accelerated filtering.
39
+ * Set to null to disable hardware acceleration.
40
+ */
41
+ hardware?: HardwareContext | null;
42
+ /**
43
+ * Number of extra hardware frames to allocate.
44
+ *
45
+ * Useful for hardware filters requiring additional frame buffering.
46
+ * Some hardware filters need extra frames for look-ahead or reference.
47
+ */
48
+ extraHWFrames?: number;
49
+ /**
50
+ * Force constant framerate mode (CFR).
51
+ *
52
+ * When true, timeBase is automatically set to 1/framerate (like FFmpeg CLI -fps_mode cfr).
53
+ * When false (default), timeBase is taken from frame.timeBase (VFR mode).
54
+ *
55
+ * Maps to FFmpeg's IFILTER_FLAG_CFR.
56
+ * Requires `framerate` to be set when enabled.
57
+ *
58
+ * @default false (VFR mode)
59
+ */
60
+ cfr?: boolean;
61
+ /**
62
+ * Framerate for CFR mode or as hint for buffer source.
63
+ *
64
+ * Required when `cfr=true` to calculate timeBase = 1/framerate.
65
+ * Also passed to AVBufferSrcParameters->frame_rate.
66
+ *
67
+ * Maps to FFmpeg's InputFilterOptions->framerate.
68
+ */
69
+ framerate?: IRational;
70
+ /**
71
+ * Drop frames on format/parameter changes instead of reinitializing filtergraph.
72
+ *
73
+ * When true, frames with changed properties (resolution, format, etc.) are dropped
74
+ * instead of triggering filtergraph reinitialization. Useful for live streams
75
+ * with unstable properties.
76
+ *
77
+ * Maps to FFmpeg's IFILTER_FLAG_DROPCHANGED.
78
+ *
79
+ * @default false
80
+ */
81
+ dropOnChange?: boolean;
82
+ /**
83
+ * Allow filtergraph reinitialization when frame parameters change.
84
+ *
85
+ * When false, parameter changes (resolution, format) will cause errors
86
+ * instead of reinitializing the filtergraph.
87
+ * When true (default), filtergraph is reinitialized on parameter changes.
88
+ *
89
+ * Maps to FFmpeg's IFILTER_FLAG_REINIT.
90
+ *
91
+ * @default true
92
+ */
93
+ allowReinit?: boolean;
94
+ /**
95
+ * AbortSignal for cancellation.
96
+ *
97
+ * When aborted, async generators stop yielding and async methods throw AbortError.
98
+ */
99
+ signal?: AbortSignal;
100
+ }
101
+ /**
102
+ * High-level filter API for audio and video processing.
103
+ *
104
+ * Provides simplified interface for applying FFmpeg filters to frames.
105
+ * Handles filter graph construction, frame buffering, and command control.
106
+ * Supports both software and hardware-accelerated filtering operations.
107
+ * Essential component for effects, transformations, and format conversions.
108
+ *
109
+ * @example
110
+ * ```typescript
111
+ * import { FilterAPI } from 'node-av/api';
112
+ *
113
+ * // Create video filter - initializes on first frame
114
+ * const filter = FilterAPI.create('scale=1280:720', {
115
+ * timeBase: video.timeBase,
116
+ * });
117
+ *
118
+ * // Process frame - first frame configures filter graph
119
+ * const output = await filter.process(inputFrame);
120
+ * if (output) {
121
+ * console.log(`Filtered frame: ${output.width}x${output.height}`);
122
+ * output.free();
123
+ * }
124
+ * ```
125
+ *
126
+ * @example
127
+ * ```typescript
128
+ * // Hardware-accelerated filtering - hw context detected from frame
129
+ * const filter = FilterAPI.create('hwupload,scale_cuda=1920:1080,hwdownload', {
130
+ * timeBase: video.timeBase,
131
+ * });
132
+ * // Hardware frames context will be automatically detected from first frame
133
+ * ```
134
+ *
135
+ * @see {@link FilterGraph} For low-level filter graph API
136
+ * @see {@link Frame} For frame operations
137
+ */
138
+ export declare class FilterAPI implements Disposable {
139
+ private graph;
140
+ private description;
141
+ private options;
142
+ private buffersrcCtx;
143
+ private buffersinkCtx;
144
+ private frame;
145
+ private initializePromise;
146
+ private initialized;
147
+ private isClosed;
148
+ private calculatedTimeBase;
149
+ private lastFrameProps;
150
+ private inputQueue;
151
+ private outputQueue;
152
+ private workerPromise;
153
+ private nextComponent;
154
+ private signal?;
155
+ private pipeToPromise;
156
+ /**
157
+ * @param graph - Filter graph instance
158
+ *
159
+ * @param description - Filter description string
160
+ *
161
+ * @param options - Filter options
162
+ *
163
+ * @internal
164
+ */
165
+ private constructor();
166
+ /**
167
+ * Create a filter with specified description and configuration.
168
+ *
169
+ * Direct mapping to avfilter_graph_parse_ptr() and avfilter_graph_config().
170
+ *
171
+ * @param description - Filter graph description
172
+ *
173
+ * @param options - Filter options
174
+ *
175
+ * @returns Configured filter instance
176
+ *
177
+ * @throws {Error} If cfr=true but framerate is not set
178
+ *
179
+ * @example
180
+ * ```typescript
181
+ * // Simple video filter (VFR mode, auto timeBase)
182
+ * const filter = FilterAPI.create('scale=640:480');
183
+ * ```
184
+ *
185
+ * @example
186
+ * ```typescript
187
+ * // CFR mode with constant framerate
188
+ * const filter = FilterAPI.create('scale=1920:1080', {
189
+ * cfr: true,
190
+ * framerate: { num: 25, den: 1 }
191
+ * });
192
+ * ```
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * // Audio filter with resampling
197
+ * const filter = FilterAPI.create('aformat=sample_fmts=s16:sample_rates=44100', {
198
+ * audioResampleOpts: 'async=1'
199
+ * });
200
+ * ```
201
+ *
202
+ * @see {@link process} For frame processing
203
+ * @see {@link FilterOptions} For configuration options
204
+ */
205
+ static create(description: string, options?: FilterOptions): FilterAPI;
206
+ /**
207
+ * Check if filter is open.
208
+ *
209
+ * @example
210
+ * ```typescript
211
+ * if (filter.isFilterOpen) {
212
+ * const output = await filter.process(frame);
213
+ * }
214
+ * ```
215
+ */
216
+ get isFilterOpen(): boolean;
217
+ /**
218
+ * Check if filter has been initialized.
219
+ *
220
+ * Returns true after first frame has been processed and filter graph configured.
221
+ * Useful for checking if filter has received frame properties.
222
+ *
223
+ * @returns true if filter graph has been built from first frame
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * if (!filter.isFilterInitialized) {
228
+ * console.log('Filter will initialize on first frame');
229
+ * }
230
+ * ```
231
+ */
232
+ get isFilterInitialized(): boolean;
233
+ /**
234
+ * Get buffersink filter context.
235
+ *
236
+ * Provides access to the buffersink filter context for advanced operations.
237
+ * Returns null if filter is not initialized.
238
+ *
239
+ * @returns Buffersink context or null
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * const sink = filter.buffersink;
244
+ * if (sink) {
245
+ * const fr = sink.buffersinkGetFrameRate();
246
+ * console.log(`Output frame rate: ${fr.num}/${fr.den}`);
247
+ * }
248
+ * ```
249
+ */
250
+ get buffersink(): FilterContext | null;
251
+ /**
252
+ * Output frame rate from filter graph.
253
+ *
254
+ * Returns the frame rate determined by the filter graph output.
255
+ * Returns null if filter is not initialized or frame rate is not set.
256
+ *
257
+ * Direct mapping to av_buffersink_get_frame_rate().
258
+ *
259
+ * @returns Frame rate or null if not available
260
+ *
261
+ * @example
262
+ * ```typescript
263
+ * const frameRate = filter.frameRate;
264
+ * if (frameRate) {
265
+ * console.log(`Filter output: ${frameRate.num}/${frameRate.den} fps`);
266
+ * }
267
+ * ```
268
+ *
269
+ * @see {@link timeBase} For output timebase
270
+ */
271
+ get frameRate(): IRational | null;
272
+ /**
273
+ * Output time base from filter graph.
274
+ *
275
+ * Returns the time base of the buffersink output.
276
+ * Matches FFmpeg CLI's av_buffersink_get_time_base() behavior.
277
+ *
278
+ * Direct mapping to av_buffersink_get_time_base().
279
+ *
280
+ * @returns Time base or null if not initialized
281
+ *
282
+ * @example
283
+ * ```typescript
284
+ * const timeBase = filter.timeBase;
285
+ * if (timeBase) {
286
+ * console.log(`Filter timebase: ${timeBase.num}/${timeBase.den}`);
287
+ * }
288
+ * ```
289
+ *
290
+ * @see {@link frameRate} For output frame rate
291
+ */
292
+ get timeBase(): IRational | null;
293
+ /**
294
+ * Output format from filter graph.
295
+ *
296
+ * Returns the pixel format (video) or sample format (audio) of the buffersink output.
297
+ * Matches FFmpeg CLI's av_buffersink_get_format() behavior.
298
+ *
299
+ * Direct mapping to av_buffersink_get_format().
300
+ *
301
+ * @returns Pixel format or sample format, or null if not initialized
302
+ *
303
+ * @example
304
+ * ```typescript
305
+ * const format = filter.format;
306
+ * if (format !== null) {
307
+ * console.log(`Filter output format: ${format}`);
308
+ * }
309
+ * ```
310
+ */
311
+ get format(): AVPixelFormat | AVSampleFormat | null;
312
+ /**
313
+ * Output dimensions from filter graph (video only).
314
+ *
315
+ * Returns the width and height of the buffersink output.
316
+ * Matches FFmpeg CLI's av_buffersink_get_w() and av_buffersink_get_h() behavior.
317
+ * Only meaningful for video filters.
318
+ *
319
+ * Direct mapping to av_buffersink_get_w() and av_buffersink_get_h().
320
+ *
321
+ * @returns Dimensions object or null if not initialized
322
+ *
323
+ * @example
324
+ * ```typescript
325
+ * const dims = filter.dimensions;
326
+ * if (dims) {
327
+ * console.log(`Filter output: ${dims.width}x${dims.height}`);
328
+ * }
329
+ * ```
330
+ */
331
+ get dimensions(): IDimension | null;
332
+ /**
333
+ * Output sample rate from filter graph (audio only).
334
+ *
335
+ * Returns the sample rate of the buffersink output.
336
+ * Matches FFmpeg CLI's av_buffersink_get_sample_rate() behavior.
337
+ * Only meaningful for audio filters.
338
+ *
339
+ * Direct mapping to av_buffersink_get_sample_rate().
340
+ *
341
+ * @returns Sample rate or null if not initialized
342
+ *
343
+ * @example
344
+ * ```typescript
345
+ * const sampleRate = filter.sampleRate;
346
+ * if (sampleRate) {
347
+ * console.log(`Filter output sample rate: ${sampleRate} Hz`);
348
+ * }
349
+ * ```
350
+ */
351
+ get sampleRate(): number | null;
352
+ /**
353
+ * Output channel layout from filter graph (audio only).
354
+ *
355
+ * Returns the channel layout of the buffersink output.
356
+ * Matches FFmpeg CLI's av_buffersink_get_ch_layout() behavior.
357
+ * Only meaningful for audio filters.
358
+ *
359
+ * Direct mapping to av_buffersink_get_ch_layout().
360
+ *
361
+ * @returns Channel layout or null if not initialized
362
+ *
363
+ * @example
364
+ * ```typescript
365
+ * const layout = filter.channelLayout;
366
+ * if (layout) {
367
+ * console.log(`Filter output channels: ${layout.nbChannels}`);
368
+ * }
369
+ * ```
370
+ */
371
+ get channelLayout(): ChannelLayout | null;
372
+ /**
373
+ * Output color space from filter graph (video only).
374
+ *
375
+ * Returns the color space of the buffersink output.
376
+ * Matches FFmpeg CLI's av_buffersink_get_colorspace() behavior.
377
+ * Only meaningful for video filters.
378
+ *
379
+ * Direct mapping to av_buffersink_get_colorspace().
380
+ *
381
+ * @returns Color space or null if not initialized
382
+ *
383
+ * @example
384
+ * ```typescript
385
+ * const colorSpace = filter.colorSpace;
386
+ * if (colorSpace !== null) {
387
+ * console.log(`Filter output color space: ${colorSpace}`);
388
+ * }
389
+ * ```
390
+ */
391
+ get colorSpace(): AVColorSpace | null;
392
+ /**
393
+ * Output color range from filter graph (video only).
394
+ *
395
+ * Returns the color range of the buffersink output.
396
+ * Matches FFmpeg CLI's av_buffersink_get_color_range() behavior.
397
+ * Only meaningful for video filters.
398
+ *
399
+ * Direct mapping to av_buffersink_get_color_range().
400
+ *
401
+ * @returns Color range or null if not initialized
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * const colorRange = filter.colorRange;
406
+ * if (colorRange !== null) {
407
+ * console.log(`Filter output color range: ${colorRange}`);
408
+ * }
409
+ * ```
410
+ */
411
+ get colorRange(): AVColorRange | null;
412
+ /**
413
+ * Output sample aspect ratio from filter graph (video only).
414
+ *
415
+ * Returns the sample aspect ratio of the buffersink output.
416
+ * Matches FFmpeg CLI's av_buffersink_get_sample_aspect_ratio() behavior.
417
+ * Only meaningful for video filters.
418
+ *
419
+ * Direct mapping to av_buffersink_get_sample_aspect_ratio().
420
+ *
421
+ * @returns Sample aspect ratio or null if not initialized
422
+ *
423
+ * @example
424
+ * ```typescript
425
+ * const sar = filter.sampleAspectRatio;
426
+ * if (sar) {
427
+ * console.log(`Filter output SAR: ${sar.num}:${sar.den}`);
428
+ * }
429
+ * ```
430
+ */
431
+ get sampleAspectRatio(): IRational | null;
432
+ /**
433
+ * Check if filter is ready for processing.
434
+ *
435
+ * @returns true if initialized and ready
436
+ *
437
+ * @example
438
+ * ```typescript
439
+ * if (filter.isReady()) {
440
+ * const output = await filter.process(frame);
441
+ * }
442
+ * ```
443
+ */
444
+ isReady(): boolean;
445
+ /**
446
+ * Get filter graph description.
447
+ *
448
+ * Returns human-readable graph structure.
449
+ * Useful for debugging filter chains.
450
+ *
451
+ * Direct mapping to avfilter_graph_dump().
452
+ *
453
+ * @returns Graph description or null if closed
454
+ *
455
+ * @example
456
+ * ```typescript
457
+ * const description = filter.getGraphDescription();
458
+ * console.log('Filter graph:', description);
459
+ * ```
460
+ */
461
+ getGraphDescription(): string | null;
462
+ /**
463
+ * Send a frame to the filter.
464
+ *
465
+ * Sends a frame to the filter for processing.
466
+ * Does not return filtered frames - use {@link receive} to retrieve frames.
467
+ * On first frame, automatically builds filter graph with frame properties.
468
+ * A single input frame can produce zero, one, or multiple output frames.
469
+ *
470
+ * **Important**: This method only SENDS the frame to the filter.
471
+ * You must call {@link receive} separately (potentially multiple times) to get filtered frames.
472
+ *
473
+ * Direct mapping to av_buffersrc_add_frame().
474
+ *
475
+ * @param frame - Input frame to send to filter, or null to flush
476
+ *
477
+ * @throws {Error} If filter could not be initialized
478
+ *
479
+ * @throws {FFmpegError} If sending frame fails
480
+ *
481
+ * @example
482
+ * ```typescript
483
+ * // Send frame and receive filtered frames
484
+ * await filter.process(inputFrame);
485
+ *
486
+ * // Receive all available filtered frames
487
+ * while (true) {
488
+ * const output = await filter.receive();
489
+ * if (!output) break;
490
+ * console.log(`Got filtered frame: pts=${output.pts}`);
491
+ * output.free();
492
+ * }
493
+ * ```
494
+ *
495
+ * @example
496
+ * ```typescript
497
+ * for await (const frame of decoder.frames(input.packets())) {
498
+ * // Send frame
499
+ * await filter.process(frame);
500
+ *
501
+ * // Receive available filtered frames
502
+ * let output;
503
+ * while ((output = await filter.receive())) {
504
+ * await encoder.encode(output);
505
+ * output.free();
506
+ * }
507
+ * frame.free();
508
+ * }
509
+ * ```
510
+ *
511
+ * @see {@link receive} For receiving filtered frames
512
+ * @see {@link processAll} For combined send+receive operation
513
+ * @see {@link frames} For processing frame streams
514
+ * @see {@link flush} For end-of-stream handling
515
+ * @see {@link processSync} For synchronous version
516
+ */
517
+ process(frame: Frame | null): Promise<void>;
518
+ /**
519
+ * Send a frame to the filter synchronously.
520
+ * Synchronous version of process.
521
+ *
522
+ * Sends a frame to the filter for processing.
523
+ * Does not return filtered frames - use {@link receiveSync} to retrieve frames.
524
+ * On first frame, automatically builds filter graph with frame properties.
525
+ * A single input frame can produce zero, one, or multiple output frames.
526
+ *
527
+ * **Important**: This method only SENDS the frame to the filter.
528
+ * You must call {@link receiveSync} separately (potentially multiple times) to get filtered frames.
529
+ *
530
+ * Direct mapping to av_buffersrc_add_frame().
531
+ *
532
+ * @param frame - Input frame to send to filter, or null to flush
533
+ *
534
+ * @throws {Error} If filter could not be initialized
535
+ *
536
+ * @throws {FFmpegError} If sending frame fails
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * // Send frame and receive filtered frames
541
+ * filter.processSync(inputFrame);
542
+ *
543
+ * // Receive all available filtered frames
544
+ * let output;
545
+ * while ((output = filter.receiveSync())) {
546
+ * console.log(`Got filtered frame: pts=${output.pts}`);
547
+ * output.free();
548
+ * }
549
+ * ```
550
+ *
551
+ * @see {@link receiveSync} For receiving filtered frames
552
+ * @see {@link processAllSync} For combined send+receive operation
553
+ * @see {@link framesSync} For processing frame streams
554
+ * @see {@link flushSync} For end-of-stream handling
555
+ * @see {@link process} For async version
556
+ */
557
+ processSync(frame: Frame | null): void;
558
+ /**
559
+ * Process a frame through the filter.
560
+ *
561
+ * Applies filter operations to input frame and receives all available output frames.
562
+ * Returns array of frames - may be empty if filter needs more input.
563
+ * On first frame, automatically builds filter graph with frame properties.
564
+ * One input frame can produce zero, one, or multiple output frames depending on filter.
565
+ * Hardware frames context is automatically detected from frame.
566
+ *
567
+ * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
568
+ *
569
+ * @param frame - Input frame to process
570
+ *
571
+ * @returns Array of filtered frames (empty if buffered or filter closed)
572
+ *
573
+ * @throws {Error} If filter could not be initialized
574
+ *
575
+ * @throws {FFmpegError} If processing fails
576
+ *
577
+ * @example
578
+ * ```typescript
579
+ * const frames = await filter.processAll(inputFrame);
580
+ * for (const output of frames) {
581
+ * console.log(`Got filtered frame: pts=${output.pts}`);
582
+ * output.free();
583
+ * }
584
+ * ```
585
+ *
586
+ * @example
587
+ * ```typescript
588
+ * // Process frame - may return multiple frames (e.g. fps filter)
589
+ * const frames = await filter.processAll(frame);
590
+ * for (const output of frames) {
591
+ * yield output;
592
+ * }
593
+ * ```
594
+ *
595
+ * @see {@link process} For single frame processing
596
+ * @see {@link frames} For processing frame streams
597
+ * @see {@link flush} For end-of-stream handling
598
+ * @see {@link processAllSync} For synchronous version
599
+ */
600
+ processAll(frame: Frame | null): Promise<Frame[]>;
601
+ /**
602
+ * Process a frame through the filter synchronously.
603
+ * Synchronous version of processAll.
604
+ *
605
+ * Applies filter operations to input frame and receives all available output frames.
606
+ * Returns array of frames - may be empty if filter needs more input.
607
+ * On first frame, automatically builds filter graph with frame properties.
608
+ * One input frame can produce zero, one, or multiple output frames depending on filter.
609
+ * Hardware frames context is automatically detected from frame.
610
+ *
611
+ * Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
612
+ *
613
+ * @param frame - Input frame to process
614
+ *
615
+ * @returns Array of filtered frames (empty if buffered or filter closed)
616
+ *
617
+ * @throws {Error} If filter could not be initialized
618
+ *
619
+ * @throws {FFmpegError} If processing fails
620
+ *
621
+ * @example
622
+ * ```typescript
623
+ * const outputs = filter.processAllSync(inputFrame);
624
+ * for (const output of outputs) {
625
+ * console.log(`Got filtered frame: pts=${output.pts}`);
626
+ * output.free();
627
+ * }
628
+ * ```
629
+ *
630
+ * @example
631
+ * ```typescript
632
+ * // Process frame - may return multiple frames (e.g. fps filter)
633
+ * const outputs = filter.processAllSync(frame);
634
+ * for (const output of outputs) {
635
+ * yield output;
636
+ * }
637
+ * ```
638
+ *
639
+ * @see {@link processSync} For single frame processing
640
+ * @see {@link framesSync} For processing frame streams
641
+ * @see {@link flushSync} For end-of-stream handling
642
+ * @see {@link process} For async version
643
+ */
644
+ processAllSync(frame: Frame): Frame[];
645
+ /**
646
+ * Process frame stream through filter.
647
+ *
648
+ * High-level async generator for filtering frame streams.
649
+ * Filter is only flushed when EOF (null) signal is explicitly received.
650
+ * Primary interface for stream-based filtering.
651
+ *
652
+ * **EOF Handling:**
653
+ * - Send null to flush filter and get remaining buffered frames
654
+ * - Generator yields null after flushing when null is received
655
+ * - No automatic flushing - filter stays open until EOF or close()
656
+ *
657
+ * @param frames - Async iterable of frames, single frame, or null to flush
658
+ *
659
+ * @yields {Frame | null} Filtered frames, followed by null when explicitly flushed
660
+ *
661
+ * @throws {Error} If filter not ready
662
+ *
663
+ * @throws {FFmpegError} If processing fails
664
+ *
665
+ * @example
666
+ * ```typescript
667
+ * // Stream of frames with automatic EOF propagation
668
+ * for await (const frame of filter.frames(decoder.frames(packets))) {
669
+ * if (frame === null) {
670
+ * console.log('Filter flushed');
671
+ * break;
672
+ * }
673
+ * await encoder.encode(frame);
674
+ * frame.free();
675
+ * }
676
+ * ```
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * // Single frame - no automatic flush
681
+ * for await (const frame of filter.frames(singleFrame)) {
682
+ * await encoder.encode(frame);
683
+ * frame.free();
684
+ * }
685
+ * // Filter remains open, buffered frames not flushed
686
+ * ```
687
+ *
688
+ * @example
689
+ * ```typescript
690
+ * // Explicit flush with EOF
691
+ * for await (const frame of filter.frames(null)) {
692
+ * if (frame === null) {
693
+ * console.log('All buffered frames flushed');
694
+ * break;
695
+ * }
696
+ * console.log('Buffered frame:', frame.pts);
697
+ * frame.free();
698
+ * }
699
+ * ```
700
+ *
701
+ * @see {@link process} For single frame processing
702
+ * @see {@link Decoder.frames} For frames source
703
+ * @see {@link framesSync} For sync version
704
+ */
705
+ frames(frames: AsyncIterable<Frame | null> | Frame | null): AsyncGenerator<Frame | null>;
706
+ /**
707
+ * Process frame stream through filter synchronously.
708
+ * Synchronous version of frames.
709
+ *
710
+ * High-level sync generator for filtering frame streams.
711
+ * Filter is only flushed when EOF (null) signal is explicitly received.
712
+ * Primary interface for stream-based filtering.
713
+ *
714
+ * **EOF Handling:**
715
+ * - Send null to flush filter and get remaining buffered frames
716
+ * - Generator yields null after flushing when null is received
717
+ * - No automatic flushing - filter stays open until EOF or close()
718
+ *
719
+ * @param frames - Iterable of frames, single frame, or null to flush
720
+ *
721
+ * @yields {Frame | null} Filtered frames, followed by null when explicitly flushed
722
+ *
723
+ * @throws {Error} If filter not ready
724
+ *
725
+ * @throws {FFmpegError} If processing fails
726
+ *
727
+ * @example
728
+ * ```typescript
729
+ * // Stream of frames with automatic EOF propagation
730
+ * for (const frame of filter.framesSync(decoder.framesSync(packets))) {
731
+ * if (frame === null) {
732
+ * console.log('Filter flushed');
733
+ * break;
734
+ * }
735
+ * encoder.encodeSync(frame);
736
+ * frame.free();
737
+ * }
738
+ * ```
739
+ *
740
+ * @example
741
+ * ```typescript
742
+ * // Single frame - no automatic flush
743
+ * for (const frame of filter.framesSync(singleFrame)) {
744
+ * encoder.encodeSync(frame);
745
+ * frame.free();
746
+ * }
747
+ * // Filter remains open, buffered frames not flushed
748
+ * ```
749
+ *
750
+ * @example
751
+ * ```typescript
752
+ * // Explicit flush with EOF
753
+ * for (const frame of filter.framesSync(null)) {
754
+ * if (frame === null) {
755
+ * console.log('All buffered frames flushed');
756
+ * break;
757
+ * }
758
+ * console.log('Buffered frame:', frame.pts);
759
+ * frame.free();
760
+ * }
761
+ * ```
762
+ *
763
+ * @see {@link processSync} For single frame processing
764
+ * @see {@link Decoder.framesSync} For frames source
765
+ * @see {@link frames} For async version
766
+ */
767
+ framesSync(frames: Iterable<Frame | null> | Frame | null): Generator<Frame | null>;
768
+ /**
769
+ * Flush filter and signal end-of-stream.
770
+ *
771
+ * Sends null frame to flush buffered data.
772
+ * Must call receive() to get flushed frames.
773
+ * Does nothing if filter is closed or was never initialized.
774
+ *
775
+ * Direct mapping to av_buffersrc_add_frame(NULL).
776
+ *
777
+ * @throws {FFmpegError} If flush fails
778
+ *
779
+ * @example
780
+ * ```typescript
781
+ * await filter.flush();
782
+ * // Get remaining frames
783
+ * let frame;
784
+ * while ((frame = await filter.receive()) !== null) {
785
+ * frame.free();
786
+ * }
787
+ * ```
788
+ *
789
+ * @see {@link flushFrames} For async iteration
790
+ * @see {@link receive} For getting flushed frames
791
+ * @see {@link flushSync} For synchronous version
792
+ */
793
+ flush(): Promise<void>;
794
+ /**
795
+ * Flush filter and signal end-of-stream synchronously.
796
+ * Synchronous version of flush.
797
+ *
798
+ * Sends null frame to flush buffered data.
799
+ * Must call receiveSync() to get flushed frames.
800
+ * Does nothing if filter is closed or was never initialized.
801
+ *
802
+ * Direct mapping to av_buffersrc_add_frame(NULL).
803
+ *
804
+ * @throws {FFmpegError} If flush fails
805
+ *
806
+ * @example
807
+ * ```typescript
808
+ * filter.flushSync();
809
+ * // Get remaining frames
810
+ * let frame;
811
+ * while ((frame = filter.receiveSync()) !== null) {
812
+ * frame.free();
813
+ * }
814
+ * ```
815
+ *
816
+ * @see {@link flushFramesSync} For sync iteration
817
+ * @see {@link receiveSync} For getting flushed frames
818
+ * @see {@link flush} For async version
819
+ */
820
+ flushSync(): void;
821
+ /**
822
+ * Flush filter and yield remaining frames.
823
+ *
824
+ * Convenient async generator for flushing.
825
+ * Combines flush and receive operations.
826
+ * Returns immediately if filter is closed or was never initialized.
827
+ *
828
+ * @yields {Frame} Remaining frames from filter
829
+ *
830
+ * @throws {FFmpegError} If flush fails
831
+ *
832
+ * @example
833
+ * ```typescript
834
+ * for await (const frame of filter.flushFrames()) {
835
+ * console.log(`Flushed frame: pts=${frame.pts}`);
836
+ * frame.free();
837
+ * }
838
+ * ```
839
+ *
840
+ * @see {@link process} For frame processing
841
+ * @see {@link flush} For manual flush
842
+ * @see {@link flushFramesSync} For sync version
843
+ */
844
+ flushFrames(): AsyncGenerator<Frame>;
845
+ /**
846
+ * Flush filter and yield remaining frames synchronously.
847
+ * Synchronous version of flushFrames.
848
+ *
849
+ * Convenient sync generator for flushing.
850
+ * Combines flush and receive operations.
851
+ * Returns immediately if filter is closed or was never initialized.
852
+ *
853
+ * @yields {Frame} Remaining frames from filter
854
+ *
855
+ * @throws {FFmpegError} If flush fails
856
+ *
857
+ * @example
858
+ * ```typescript
859
+ * for (const frame of filter.flushFramesSync()) {
860
+ * console.log(`Flushed frame: pts=${frame.pts}`);
861
+ * frame.free();
862
+ * }
863
+ * ```
864
+ *
865
+ * @see {@link processSync} For frame processing
866
+ * @see {@link flushSync} For manual flush
867
+ * @see {@link flushFrames} For async version
868
+ */
869
+ flushFramesSync(): Generator<Frame>;
870
+ /**
871
+ * Receive buffered frame from filter.
872
+ *
873
+ * Drains frames buffered by the filter.
874
+ * Call repeatedly until null or EOF to get all buffered frames.
875
+ * Implements FFmpeg's send/receive pattern.
876
+ *
877
+ * **Return Values:**
878
+ * - `Frame` - Successfully received frame (AVERROR >= 0)
879
+ * - `null` - Need more input data (AVERROR_EAGAIN), or filter not initialized
880
+ * - `undefined` - End of stream reached (AVERROR_EOF), or filter is closed
881
+ *
882
+ * Direct mapping to av_buffersink_get_frame().
883
+ *
884
+ * @returns Buffered frame, null if need more data, or undefined if stream ended
885
+ *
886
+ * @throws {FFmpegError} If receiving fails
887
+ *
888
+ * @throws {Error} If frame cloning fails (out of memory)
889
+ *
890
+ * @example
891
+ * ```typescript
892
+ * // Process all buffered frames
893
+ * while (true) {
894
+ * const frame = await filter.receive();
895
+ * if (!frame) break; // Stop on EAGAIN or EOF
896
+ * console.log(`Received frame: pts=${frame.pts}`);
897
+ * frame.free();
898
+ * }
899
+ * ```
900
+ *
901
+ * @example
902
+ * ```typescript
903
+ * // Handle each return value explicitly
904
+ * const frame = await filter.receive();
905
+ * if (frame === EOF) {
906
+ * console.log('Filter stream ended');
907
+ * } else if (frame === null) {
908
+ * console.log('Need more input data');
909
+ * } else {
910
+ * console.log(`Got frame: pts=${frame.pts}`);
911
+ * frame.free();
912
+ * }
913
+ * ```
914
+ *
915
+ * @see {@link process} For frame processing
916
+ * @see {@link flush} For flushing filter
917
+ * @see {@link receiveSync} For synchronous version
918
+ * @see {@link EOF} For end-of-stream signal
919
+ */
920
+ receive(): Promise<Frame | EOFSignal | null>;
921
+ /**
922
+ * Receive buffered frame from filter synchronously.
923
+ * Synchronous version of receive.
924
+ *
925
+ * Drains frames buffered by the filter.
926
+ * Call repeatedly until null or EOF to get all buffered frames.
927
+ * Implements FFmpeg's send/receive pattern.
928
+ *
929
+ * **Return Values:**
930
+ * - `Frame` - Successfully received frame (AVERROR >= 0)
931
+ * - `null` - Need more input data (AVERROR_EAGAIN), or filter not initialized
932
+ * - `undefined` - End of stream reached (AVERROR_EOF), or filter is closed
933
+ *
934
+ * Direct mapping to av_buffersink_get_frame().
935
+ *
936
+ * @returns Buffered frame, null if need more data, or undefined if stream ended
937
+ *
938
+ * @throws {FFmpegError} If receiving fails
939
+ *
940
+ * @throws {Error} If frame cloning fails (out of memory)
941
+ *
942
+ * @example
943
+ * ```typescript
944
+ * // Process all buffered frames
945
+ * while (true) {
946
+ * const frame = filter.receiveSync();
947
+ * if (!frame) break; // Stop on EAGAIN or EOF
948
+ * console.log(`Received frame: pts=${frame.pts}`);
949
+ * frame.free();
950
+ * }
951
+ * ```
952
+ *
953
+ * @example
954
+ * ```typescript
955
+ * // Handle each return value explicitly
956
+ * const frame = filter.receiveSync();
957
+ * if (frame === EOF) {
958
+ * console.log('Filter stream ended');
959
+ * } else if (frame === null) {
960
+ * console.log('Need more input data');
961
+ * } else {
962
+ * console.log(`Got frame: pts=${frame.pts}`);
963
+ * frame.free();
964
+ * }
965
+ * ```
966
+ *
967
+ * @see {@link processSync} For frame processing
968
+ * @see {@link flushSync} For flushing filter
969
+ * @see {@link receive} For async version
970
+ * @see {@link EOF} For end-of-stream signal
971
+ */
972
+ receiveSync(): Frame | EOFSignal | null;
973
+ /**
974
+ * Send command to filter.
975
+ *
976
+ * Sends runtime command to specific filter in graph.
977
+ * Allows dynamic parameter adjustment.
978
+ *
979
+ * Direct mapping to avfilter_graph_send_command().
980
+ *
981
+ * @param target - Target filter name
982
+ *
983
+ * @param cmd - Command name
984
+ *
985
+ * @param arg - Command argument
986
+ *
987
+ * @param flags - Command flags
988
+ *
989
+ * @returns Response string from filter
990
+ *
991
+ * @throws {Error} If filter not ready
992
+ *
993
+ * @throws {FFmpegError} If command fails
994
+ *
995
+ * @example
996
+ * ```typescript
997
+ * // Change volume at runtime
998
+ * const response = filter.sendCommand('volume', 'volume', '0.5');
999
+ * console.log(`Volume changed: ${response}`);
1000
+ * ```
1001
+ *
1002
+ * @see {@link queueCommand} For delayed commands
1003
+ */
1004
+ sendCommand(target: string, cmd: string, arg: string, flags?: AVFilterCmdFlag): string;
1005
+ /**
1006
+ * Queue command for later execution.
1007
+ *
1008
+ * Schedules command to execute at specific timestamp.
1009
+ * Useful for synchronized parameter changes.
1010
+ *
1011
+ * Direct mapping to avfilter_graph_queue_command().
1012
+ *
1013
+ * @param target - Target filter name
1014
+ *
1015
+ * @param cmd - Command name
1016
+ *
1017
+ * @param arg - Command argument
1018
+ *
1019
+ * @param ts - Timestamp for execution
1020
+ *
1021
+ * @param flags - Command flags
1022
+ *
1023
+ * @throws {Error} If filter not ready
1024
+ *
1025
+ * @throws {FFmpegError} If queue fails
1026
+ *
1027
+ * @example
1028
+ * ```typescript
1029
+ * // Queue volume change at 10 seconds
1030
+ * filter.queueCommand('volume', 'volume', '0.8', 10.0);
1031
+ * ```
1032
+ *
1033
+ * @see {@link sendCommand} For immediate commands
1034
+ */
1035
+ queueCommand(target: string, cmd: string, arg: string, ts: number, flags?: AVFilterCmdFlag): void;
1036
+ /**
1037
+ * Pipe decoded frames to a filter component or encoder.
1038
+ *
1039
+ * @param target - Filter to receive frames or encoder to encode frames
1040
+ *
1041
+ * @returns Scheduler for continued chaining
1042
+ *
1043
+ * @example
1044
+ * ```typescript
1045
+ * decoder.pipeTo(filter).pipeTo(encoder)
1046
+ * ```
1047
+ */
1048
+ pipeTo(target: FilterAPI): Scheduler<Frame>;
1049
+ pipeTo(target: Encoder): Scheduler<Frame>;
1050
+ /**
1051
+ * Free filter resources.
1052
+ *
1053
+ * Releases filter graph and contexts.
1054
+ * Safe to call multiple times.
1055
+ *
1056
+ * @example
1057
+ * ```typescript
1058
+ * filter.close();
1059
+ * ```
1060
+ *
1061
+ * @see {@link Symbol.dispose} For automatic cleanup
1062
+ */
1063
+ close(): void;
1064
+ /**
1065
+ * Worker loop for push-based processing.
1066
+ *
1067
+ * @internal
1068
+ */
1069
+ private runWorker;
1070
+ /**
1071
+ * Send frame to input queue or flush the pipeline.
1072
+ *
1073
+ * When frame is provided, queues it for filtering.
1074
+ * When null is provided, triggers flush sequence:
1075
+ * - Closes input queue
1076
+ * - Waits for worker completion
1077
+ * - Flushes filter and sends remaining frames to output queue
1078
+ * - Closes output queue
1079
+ * - Waits for pipeTo task completion
1080
+ * - Propagates flush to next component (if any)
1081
+ *
1082
+ * Used by scheduler system for pipeline control.
1083
+ *
1084
+ * @param frame - Frame to send, or null to flush
1085
+ *
1086
+ * @internal
1087
+ */
1088
+ private sendToQueue;
1089
+ /**
1090
+ * Receive frame from output queue.
1091
+ *
1092
+ * @returns Frame from output queue or null if closed
1093
+ *
1094
+ * @internal
1095
+ */
1096
+ private receiveFrame;
1097
+ /**
1098
+ * Initialize filter graph from first frame.
1099
+ *
1100
+ * Creates and configures filter graph components.
1101
+ * Sets buffer source parameters from frame properties.
1102
+ * Automatically configures hardware frames context if present.
1103
+ *
1104
+ * @param frame - First frame to process, provides format and hw context
1105
+ *
1106
+ * @throws {Error} If initialization fails
1107
+ *
1108
+ * @throws {FFmpegError} If configuration fails
1109
+ *
1110
+ * @internal
1111
+ */
1112
+ private initialize;
1113
+ /**
1114
+ * Initialize filter graph from first frame synchronously.
1115
+ * Synchronous version of initialize.
1116
+ *
1117
+ * Creates and configures filter graph components.
1118
+ * Sets buffer source parameters from frame properties.
1119
+ * Automatically configures hardware frames context if present.
1120
+ *
1121
+ * @param frame - First frame to process, provides format and hw context
1122
+ *
1123
+ * @throws {Error} If initialization fails
1124
+ *
1125
+ * @throws {FFmpegError} If configuration fails
1126
+ *
1127
+ * @internal
1128
+ *
1129
+ * @see {@link initialize} For async version
1130
+ */
1131
+ private initializeSync;
1132
+ /**
1133
+ * Check if frame properties changed and handle according to dropOnChange/allowReinit options.
1134
+ *
1135
+ * Implements FFmpeg's IFILTER_FLAG_DROPCHANGED and IFILTER_FLAG_REINIT logic
1136
+ *
1137
+ * @param frame - Frame to check
1138
+ *
1139
+ * @returns true if frame should be processed, false if frame should be dropped
1140
+ *
1141
+ * @throws {Error} If format changed and allowReinit is false
1142
+ *
1143
+ * @internal
1144
+ */
1145
+ private checkFramePropertiesChanged;
1146
+ /**
1147
+ * Calculate timeBase from frame based on media type and CFR option.
1148
+ *
1149
+ * Implements FFmpeg's ifilter_parameters_from_frame logic:
1150
+ * - Audio: Always { 1, sample_rate }
1151
+ * - Video CFR: 1/framerate (inverse of framerate)
1152
+ * - Video VFR: Use frame.timeBase
1153
+ *
1154
+ * @param frame - Input frame
1155
+ *
1156
+ * @returns Calculated timeBase
1157
+ *
1158
+ * @internal
1159
+ */
1160
+ private calculateTimeBase;
1161
+ /**
1162
+ * Post-process output frame from buffersink.
1163
+ *
1164
+ * Applies FFmpeg's fg_output_step() behavior:
1165
+ * 1. Sets frame.timeBase from buffersink (filters can change timeBase, e.g., aresample)
1166
+ * 2. Calculates video frame duration from frame rate if not set
1167
+ *
1168
+ * This must be called AFTER buffersinkGetFrame() for every output frame.
1169
+ *
1170
+ * @param frame - Output frame from buffersink
1171
+ *
1172
+ * @throws {Error} If buffersink context not available
1173
+ *
1174
+ * @internal
1175
+ */
1176
+ private postProcessOutputFrame;
1177
+ /**
1178
+ * Create buffer source with frame parameters.
1179
+ *
1180
+ * Configures buffer source with frame properties including hardware context.
1181
+ * Automatically detects video/audio and sets appropriate parameters.
1182
+ *
1183
+ * @param frame - Frame providing format, dimensions, and hw_frames_ctx
1184
+ *
1185
+ * @throws {Error} If creation fails
1186
+ *
1187
+ * @throws {FFmpegError} If configuration fails
1188
+ *
1189
+ * @internal
1190
+ */
1191
+ private createBufferSource;
1192
+ /**
1193
+ * Create buffer sink.
1194
+ *
1195
+ * @param frame - Frame
1196
+ *
1197
+ * @throws {Error} If creation fails
1198
+ *
1199
+ * @internal
1200
+ */
1201
+ private createBufferSink;
1202
+ /**
1203
+ * Parse filter description and build graph.
1204
+ *
1205
+ * Uses the Segment API to parse filters, which allows setting hw_device_ctx
1206
+ * before filter initialization when needed. Works for both hardware and software filters.
1207
+ *
1208
+ * @param frame - First frame to process, provides hw_frames_ctx if any
1209
+ *
1210
+ * @throws {Error} If parsing fails
1211
+ *
1212
+ * @throws {FFmpegError} If graph construction fails
1213
+ *
1214
+ * @internal
1215
+ */
1216
+ private parseFilterDescription;
1217
+ /**
1218
+ * Dispose of filter.
1219
+ *
1220
+ * Implements Disposable interface for automatic cleanup.
1221
+ * Equivalent to calling close().
1222
+ *
1223
+ * @example
1224
+ * ```typescript
1225
+ * {
1226
+ * using filter = FilterAPI.create('scale=640:480', { ... });
1227
+ * // Use filter...
1228
+ * } // Automatically freed
1229
+ * ```
1230
+ *
1231
+ * @see {@link close} For manual cleanup
1232
+ */
1233
+ [Symbol.dispose](): void;
1234
+ }