@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,789 @@
1
+ import { Filter } from './filter.js';
2
+ import { HardwareDeviceContext } from './hardware-device-context.js';
3
+ import { OptionMember } from './option.js';
4
+ import { Rational } from './rational.js';
5
+ /**
6
+ * Filter instance in a filter graph.
7
+ *
8
+ * Represents an instantiated filter within a filter graph. Each context contains
9
+ * a specific filter configuration with its parameters, connections to other filters,
10
+ * and input/output pads. Supports both software and hardware filtering operations.
11
+ * Essential for building complex filter chains for audio/video processing.
12
+ *
13
+ * Direct mapping to FFmpeg's AVFilterContext.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { FilterContext, FilterGraph, Filter, FFmpegError } from 'node-av';
18
+ *
19
+ * // Create filter context in a graph
20
+ * const graph = new FilterGraph();
21
+ * const filter = Filter.getByName('scale');
22
+ * const context = graph.createFilter(filter, 'scaler');
23
+ *
24
+ * // Initialize with parameters
25
+ * const ret = context.initStr('640:480');
26
+ * FFmpegError.throwIfError(ret, 'initStr');
27
+ *
28
+ * // Link filters together
29
+ * const ret2 = source.link(0, context, 0);
30
+ * FFmpegError.throwIfError(ret2, 'link');
31
+ *
32
+ * // For buffer source/sink
33
+ * const ret3 = await bufferSrc.buffersrcAddFrame(frame);
34
+ * FFmpegError.throwIfError(ret3, 'buffersrcAddFrame');
35
+ * ```
36
+ *
37
+ * @see [AVFilterContext](https://ffmpeg.org/doxygen/trunk/structAVFilterContext.html) - FFmpeg Doxygen
38
+ * @see {@link FilterGraph} For managing filter graphs
39
+ * @see {@link Filter} For filter descriptors
40
+ */
41
+ export class FilterContext extends OptionMember {
42
+ _hwDeviceCtx; // Cache for hardware device context wrapper
43
+ /**
44
+ * @param native - The native filter context instance
45
+ *
46
+ * @internal
47
+ */
48
+ constructor(native) {
49
+ super(native);
50
+ }
51
+ /**
52
+ * Filter instance name.
53
+ *
54
+ * User-assigned name for this filter instance in the graph.
55
+ * Used for identification and debugging.
56
+ *
57
+ * Direct mapping to AVFilterContext->name.
58
+ */
59
+ get name() {
60
+ return this.native.name;
61
+ }
62
+ set name(value) {
63
+ this.native.name = value;
64
+ }
65
+ /**
66
+ * Filter descriptor.
67
+ *
68
+ * Reference to the filter type this context instantiates.
69
+ *
70
+ * Direct mapping to AVFilterContext->filter.
71
+ */
72
+ get filter() {
73
+ const native = this.native.filter;
74
+ return native ? new Filter(native) : null;
75
+ }
76
+ /**
77
+ * Parent filter graph.
78
+ *
79
+ * Reference to the graph containing this filter context.
80
+ *
81
+ * Direct mapping to AVFilterContext->graph.
82
+ */
83
+ get graph() {
84
+ return this.native.graph;
85
+ }
86
+ /**
87
+ * Number of input pads.
88
+ *
89
+ * Total number of input connections this filter can accept.
90
+ *
91
+ * Direct mapping to AVFilterContext->nb_inputs.
92
+ */
93
+ get nbInputs() {
94
+ return this.native.nbInputs;
95
+ }
96
+ /**
97
+ * Number of output pads.
98
+ *
99
+ * Total number of output connections this filter can provide.
100
+ *
101
+ * Direct mapping to AVFilterContext->nb_outputs.
102
+ */
103
+ get nbOutputs() {
104
+ return this.native.nbOutputs;
105
+ }
106
+ /**
107
+ * Hardware device context.
108
+ *
109
+ * Hardware acceleration context for GPU-based filtering.
110
+ * Set to enable hardware-accelerated filter operations.
111
+ *
112
+ * Direct mapping to AVFilterContext->hw_device_ctx.
113
+ */
114
+ get hwDeviceCtx() {
115
+ const native = this.native.hwDeviceCtx;
116
+ if (!native) {
117
+ // Clear cache if native is null
118
+ this._hwDeviceCtx = undefined;
119
+ return null;
120
+ }
121
+ // Return cached wrapper if available and still valid
122
+ if (this._hwDeviceCtx && this._hwDeviceCtx.native === native) {
123
+ return this._hwDeviceCtx;
124
+ }
125
+ // Create and cache new wrapper
126
+ const device = Object.create(HardwareDeviceContext.prototype);
127
+ device.native = native;
128
+ this._hwDeviceCtx = device;
129
+ return device;
130
+ }
131
+ set hwDeviceCtx(value) {
132
+ this.native.hwDeviceCtx = value?.getNative() ?? null;
133
+ // Clear cache when setting new value
134
+ this._hwDeviceCtx = undefined;
135
+ }
136
+ /**
137
+ * Number of extra hardware frames to allocate.
138
+ *
139
+ * Specifies additional hardware frame buffers for filters that need them.
140
+ * Useful for deinterlacing or other filters requiring frame buffering.
141
+ *
142
+ * Direct mapping to AVFilterContext->extra_hw_frames.
143
+ */
144
+ get extraHWFrames() {
145
+ return this.native.extraHWFrames;
146
+ }
147
+ set extraHWFrames(value) {
148
+ this.native.extraHWFrames = value;
149
+ }
150
+ /**
151
+ * Initialize filter with dictionary options.
152
+ *
153
+ * Configures the filter with key-value option pairs.
154
+ * Must be called after creation and before processing.
155
+ *
156
+ * Direct mapping to avfilter_init_dict().
157
+ *
158
+ * @param options - Dictionary of filter options
159
+ *
160
+ * @returns 0 on success, negative AVERROR on error:
161
+ * - AVERROR_EINVAL: Invalid parameters
162
+ * - AVERROR_ENOMEM: Memory allocation failure
163
+ *
164
+ * @example
165
+ * ```typescript
166
+ * import { FFmpegError } from 'node-av';
167
+ *
168
+ * const options = { width: '1920', height: '1080' };
169
+ * const ret = context.init(options);
170
+ * FFmpegError.throwIfError(ret, 'init');
171
+ * ```
172
+ *
173
+ * @see {@link initStr} For string-based initialization
174
+ */
175
+ init(options = null) {
176
+ return this.native.init(options ?? null);
177
+ }
178
+ /**
179
+ * Initialize filter with string arguments.
180
+ *
181
+ * Configures the filter using a string representation of parameters.
182
+ * Format depends on the specific filter.
183
+ *
184
+ * Direct mapping to avfilter_init_str().
185
+ *
186
+ * @param args - Filter arguments string
187
+ *
188
+ * @returns 0 on success, negative AVERROR on error:
189
+ * - AVERROR_EINVAL: Invalid arguments
190
+ * - AVERROR_ENOMEM: Memory allocation failure
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * import { FFmpegError } from 'node-av';
195
+ *
196
+ * // Scale filter with width:height
197
+ * const ret = scaleContext.initStr('1920:1080');
198
+ * FFmpegError.throwIfError(ret, 'initStr');
199
+ *
200
+ * // Crop filter with width:height:x:y
201
+ * const ret2 = cropContext.initStr('640:480:100:50');
202
+ * FFmpegError.throwIfError(ret2, 'initStr');
203
+ * ```
204
+ *
205
+ * @see {@link init} For dictionary-based initialization
206
+ */
207
+ initStr(args = null) {
208
+ return this.native.initStr(args ?? null);
209
+ }
210
+ /**
211
+ * Link this filter's output to another filter's input.
212
+ *
213
+ * Creates a connection between two filters in the graph.
214
+ * Data flows from this filter's output pad to the destination's input pad.
215
+ *
216
+ * Direct mapping to avfilter_link().
217
+ *
218
+ * @param srcPad - Output pad index of this filter
219
+ *
220
+ * @param dst - Destination filter context
221
+ *
222
+ * @param dstPad - Input pad index of destination filter
223
+ *
224
+ * @returns 0 on success, negative AVERROR on error:
225
+ * - AVERROR_EINVAL: Invalid pad indices or incompatible formats
226
+ * - AVERROR_ENOMEM: Memory allocation failure
227
+ *
228
+ * @example
229
+ * ```typescript
230
+ * import { FFmpegError } from 'node-av';
231
+ *
232
+ * // Link source output 0 to scale input 0
233
+ * const ret = source.link(0, scale, 0);
234
+ * FFmpegError.throwIfError(ret, 'link');
235
+ *
236
+ * // Link scale output 0 to sink input 0
237
+ * const ret2 = scale.link(0, sink, 0);
238
+ * FFmpegError.throwIfError(ret2, 'link');
239
+ * ```
240
+ *
241
+ * @see {@link unlink} To disconnect filters
242
+ */
243
+ link(srcPad, dst, dstPad) {
244
+ return this.native.link(srcPad, dst.native, dstPad);
245
+ }
246
+ /**
247
+ * Unlink a filter pad.
248
+ *
249
+ * Disconnects a pad from its linked filter.
250
+ * Used to reconfigure filter connections.
251
+ *
252
+ * Direct mapping to avfilter_link_free().
253
+ *
254
+ * @param pad - Pad index to unlink
255
+ *
256
+ * @example
257
+ * ```typescript
258
+ * // Disconnect output pad 0
259
+ * context.unlink(0);
260
+ * ```
261
+ *
262
+ * @see {@link link} To connect filters
263
+ */
264
+ unlink(pad) {
265
+ this.native.unlink(pad);
266
+ }
267
+ /**
268
+ * Add a frame to a buffer source filter.
269
+ *
270
+ * Sends a frame into the filter graph through a buffer source.
271
+ * Only valid for buffer source filters. Send null to signal EOF.
272
+ *
273
+ * Direct mapping to av_buffersrc_add_frame_flags().
274
+ *
275
+ * @param frame - Frame to send, or null for EOF
276
+ *
277
+ * @param flags - Optional buffersrc flags (defaults to AV_BUFFERSRC_FLAG_NONE = 0)
278
+ *
279
+ * @returns 0 on success, negative AVERROR on error:
280
+ * - AVERROR_EAGAIN: Filter needs more output consumption
281
+ * - AVERROR_EOF: Filter has been closed
282
+ * - AVERROR_EINVAL: Not a buffer source filter
283
+ * - AVERROR_ENOMEM: Memory allocation failure
284
+ *
285
+ * @example
286
+ * ```typescript
287
+ * import { FFmpegError } from 'node-av';
288
+ * import { AVERROR_EAGAIN, AV_BUFFERSRC_FLAG_PUSH } from 'node-av/constants';
289
+ *
290
+ * // Send frame to filter graph with PUSH flag (immediate processing)
291
+ * const ret = await bufferSrc.buffersrcAddFrame(frame, AV_BUFFERSRC_FLAG_PUSH);
292
+ * if (ret === AVERROR_EAGAIN) {
293
+ * // Need to consume output first
294
+ * } else {
295
+ * FFmpegError.throwIfError(ret, 'buffersrcAddFrame');
296
+ * }
297
+ *
298
+ * // Signal EOF
299
+ * await bufferSrc.buffersrcAddFrame(null);
300
+ * ```
301
+ *
302
+ * @see {@link buffersinkGetFrame} To retrieve filtered frames
303
+ */
304
+ async buffersrcAddFrame(frame, flags) {
305
+ return await this.native.buffersrcAddFrame(frame ? frame.getNative() : null, flags);
306
+ }
307
+ /**
308
+ * Add frame to buffer source filter synchronously.
309
+ * Synchronous version of buffersrcAddFrame.
310
+ *
311
+ * Sends a frame to a buffer source filter for processing.
312
+ * Only valid for buffer source filters (buffer, abuffer).
313
+ *
314
+ * Direct mapping to av_buffersrc_add_frame_flags().
315
+ *
316
+ * @param frame - Frame to send (null to mark EOF)
317
+ *
318
+ * @param flags - Optional buffersrc flags (defaults to AV_BUFFERSRC_FLAG_NONE = 0)
319
+ *
320
+ * @returns 0 on success, negative AVERROR on error:
321
+ * - AVERROR_EAGAIN: Need to retrieve output first
322
+ * - AVERROR_EOF: Graph has finished processing
323
+ * - AVERROR_EINVAL: Invalid parameters
324
+ * - AVERROR(ENOMEM): Memory allocation failure
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * import { FFmpegError } from 'node-av';
329
+ * import { AVERROR_EAGAIN, AV_BUFFERSRC_FLAG_PUSH } from 'node-av/constants';
330
+ *
331
+ * // Send frame to filter with PUSH flag (immediate processing)
332
+ * const ret = bufferSrc.buffersrcAddFrameSync(frame, AV_BUFFERSRC_FLAG_PUSH);
333
+ * if (ret === AVERROR_EAGAIN) {
334
+ * // Need to get output frames first
335
+ * const filtered = new Frame();
336
+ * bufferSink.buffersinkGetFrameSync(filtered);
337
+ * } else {
338
+ * FFmpegError.throwIfError(ret, 'buffersrcAddFrameSync');
339
+ * }
340
+ *
341
+ * // Mark end of stream
342
+ * bufferSrc.buffersrcAddFrameSync(null);
343
+ * ```
344
+ *
345
+ * @see {@link buffersrcAddFrame} For async version
346
+ */
347
+ buffersrcAddFrameSync(frame, flags) {
348
+ return this.native.buffersrcAddFrameSync(frame ? frame.getNative() : null, flags);
349
+ }
350
+ /**
351
+ * Set parameters for a buffer source filter.
352
+ *
353
+ * Configures the format and properties of frames that will be sent
354
+ * to the buffer source. Must be called before sending frames.
355
+ *
356
+ * Direct mapping to av_buffersrc_parameters_set().
357
+ *
358
+ * @param params - Source parameters
359
+ *
360
+ * @param params.width - Video frame width
361
+ *
362
+ * @param params.height - Video frame height
363
+ *
364
+ * @param params.format - Pixel or sample format
365
+ *
366
+ * @param params.timeBase - Time base for timestamps
367
+ *
368
+ * @param params.frameRate - Video frame rate
369
+ *
370
+ * @param params.sampleAspectRatio - Pixel aspect ratio
371
+ *
372
+ * @param params.hwFramesCtx - Hardware frames context
373
+ *
374
+ * @param params.sampleRate - Audio sample rate
375
+ *
376
+ * @param params.channelLayout - Audio channel layout
377
+ *
378
+ * @param params.colorRange - Color range for video
379
+ *
380
+ * @param params.colorSpace - Color space for video
381
+ *
382
+ * @param params.alphaMode - Alpha channel mode
383
+ *
384
+ * @returns 0 on success, negative AVERROR on error:
385
+ * - AVERROR_EINVAL: Invalid parameters
386
+ * - AVERROR_ENOMEM: Memory allocation failure
387
+ *
388
+ * @example
389
+ * ```typescript
390
+ * import { FFmpegError, Rational } from 'node-av';
391
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
392
+ *
393
+ * // Configure video buffer source
394
+ * const ret = bufferSrc.buffersrcParametersSet({
395
+ * width: 1920,
396
+ * height: 1080,
397
+ * format: AV_PIX_FMT_YUV420P,
398
+ * timeBase: { num: 1, den: 25 },
399
+ * frameRate: { num: 25, den: 1 }
400
+ * });
401
+ * FFmpegError.throwIfError(ret, 'buffersrcParametersSet');
402
+ *
403
+ * @example
404
+ * ```typescript
405
+ * import { FFmpegError } from 'node-av';
406
+ * import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
407
+ *
408
+ * // Configure audio buffer source
409
+ * const ret = bufferSrc.buffersrcParametersSet({
410
+ * format: AV_SAMPLE_FMT_FLTP,
411
+ * sampleRate: 44100,
412
+ * channelLayout: AV_CHANNEL_LAYOUT_STEREO
413
+ * });
414
+ * FFmpegError.throwIfError(ret, 'buffersrcParametersSet');
415
+ * ```
416
+ */
417
+ buffersrcParametersSet(params) {
418
+ const nativeParams = { ...params };
419
+ if (params.hwFramesCtx) {
420
+ nativeParams.hwFramesCtx = params.hwFramesCtx.getNative();
421
+ }
422
+ return this.native.buffersrcParametersSet(nativeParams);
423
+ }
424
+ /**
425
+ * Get a frame from a buffer sink filter.
426
+ *
427
+ * Retrieves a filtered frame from the filter graph through a buffer sink.
428
+ * Only valid for buffer sink filters.
429
+ *
430
+ * Direct mapping to av_buffersink_get_frame().
431
+ *
432
+ * @param frame - Frame to receive filtered data
433
+ *
434
+ * @returns 0 on success, negative AVERROR on error:
435
+ * - AVERROR_EAGAIN: No frame available yet
436
+ * - AVERROR_EOF: No more frames will be produced
437
+ * - AVERROR_EINVAL: Not a buffer sink filter
438
+ *
439
+ * @example
440
+ * ```typescript
441
+ * import { FFmpegError, Frame } from 'node-av';
442
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
443
+ *
444
+ * const frame = new Frame();
445
+ * frame.alloc();
446
+ *
447
+ * const ret = await bufferSink.buffersinkGetFrame(frame);
448
+ * if (ret === AVERROR_EAGAIN) {
449
+ * // No frame available yet
450
+ * } else if (ret === AVERROR_EOF) {
451
+ * // End of stream
452
+ * } else {
453
+ * FFmpegError.throwIfError(ret, 'buffersinkGetFrame');
454
+ * // Process filtered frame
455
+ * }
456
+ * ```
457
+ *
458
+ * @see {@link buffersrcAddFrame} To send frames for filtering
459
+ */
460
+ async buffersinkGetFrame(frame) {
461
+ return await this.native.buffersinkGetFrame(frame.getNative());
462
+ }
463
+ /**
464
+ * Get frame from buffer sink filter synchronously.
465
+ * Synchronous version of buffersinkGetFrame.
466
+ *
467
+ * Retrieves a filtered frame from a buffer sink filter.
468
+ * Only valid for buffer sink filters (buffersink, abuffersink).
469
+ *
470
+ * Direct mapping to av_buffersink_get_frame().
471
+ *
472
+ * @param frame - Frame to receive filtered data
473
+ *
474
+ * @returns 0 on success, negative AVERROR on error:
475
+ * - AVERROR_EAGAIN: Need more input
476
+ * - AVERROR_EOF: No more frames available
477
+ * - AVERROR_EINVAL: Invalid parameters
478
+ *
479
+ * @example
480
+ * ```typescript
481
+ * import { Frame, FFmpegError } from 'node-av';
482
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
483
+ *
484
+ * // Get filtered frame
485
+ * const filtered = new Frame();
486
+ * const ret = bufferSink.buffersinkGetFrameSync(filtered);
487
+ *
488
+ * if (ret === 0) {
489
+ * // Process filtered frame
490
+ * console.log(`Got filtered frame with ${filtered.nbSamples} samples`);
491
+ * filtered.unref();
492
+ * } else if (ret === AVERROR_EAGAIN) {
493
+ * // Need more input frames
494
+ * } else if (ret === AVERROR_EOF) {
495
+ * // No more frames
496
+ * } else {
497
+ * FFmpegError.throwIfError(ret, 'buffersinkGetFrameSync');
498
+ * }
499
+ * ```
500
+ *
501
+ * @see {@link buffersinkGetFrame} For async version
502
+ */
503
+ buffersinkGetFrameSync(frame) {
504
+ return this.native.buffersinkGetFrameSync(frame.getNative());
505
+ }
506
+ /**
507
+ * Get time base from buffer sink.
508
+ *
509
+ * Returns the time base of frames from a buffer sink filter.
510
+ * Only valid for buffer sink filters.
511
+ *
512
+ * Direct mapping to av_buffersink_get_time_base().
513
+ *
514
+ * @returns Time base as Rational
515
+ *
516
+ * @example
517
+ * ```typescript
518
+ * const timeBase = bufferSink.buffersinkGetTimeBase();
519
+ * console.log(`Time base: ${timeBase.num}/${timeBase.den}`);
520
+ * ```
521
+ */
522
+ buffersinkGetTimeBase() {
523
+ const tb = this.native.buffersinkGetTimeBase();
524
+ return new Rational(tb.num, tb.den);
525
+ }
526
+ /**
527
+ * Get pixel/sample format from buffer sink.
528
+ *
529
+ * Returns the format of frames from a buffer sink filter.
530
+ * Only valid for buffer sink filters.
531
+ *
532
+ * Direct mapping to av_buffersink_get_format().
533
+ *
534
+ * @returns Pixel format for video, sample format for audio
535
+ *
536
+ * @example
537
+ * ```typescript
538
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
539
+ *
540
+ * const format = bufferSink.buffersinkGetFormat();
541
+ * if (format === AV_PIX_FMT_YUV420P) {
542
+ * console.log('Output is YUV420P');
543
+ * }
544
+ * ```
545
+ */
546
+ buffersinkGetFormat() {
547
+ return this.native.buffersinkGetFormat();
548
+ }
549
+ /**
550
+ * Get frame width from buffer sink.
551
+ *
552
+ * Returns the width of video frames from a buffer sink filter.
553
+ * Only valid for video buffer sink filters.
554
+ *
555
+ * Direct mapping to av_buffersink_get_w().
556
+ *
557
+ * @returns Frame width in pixels
558
+ *
559
+ * @example
560
+ * ```typescript
561
+ * const width = bufferSink.buffersinkGetWidth();
562
+ * console.log(`Output width: ${width}px`);
563
+ * ```
564
+ */
565
+ buffersinkGetWidth() {
566
+ return this.native.buffersinkGetWidth();
567
+ }
568
+ /**
569
+ * Get frame height from buffer sink.
570
+ *
571
+ * Returns the height of video frames from a buffer sink filter.
572
+ * Only valid for video buffer sink filters.
573
+ *
574
+ * Direct mapping to av_buffersink_get_h().
575
+ *
576
+ * @returns Frame height in pixels
577
+ *
578
+ * @example
579
+ * ```typescript
580
+ * const height = bufferSink.buffersinkGetHeight();
581
+ * console.log(`Output height: ${height}px`);
582
+ * ```
583
+ */
584
+ buffersinkGetHeight() {
585
+ return this.native.buffersinkGetHeight();
586
+ }
587
+ /**
588
+ * Get sample aspect ratio from buffer sink.
589
+ *
590
+ * Returns the pixel aspect ratio of video frames from a buffer sink filter.
591
+ * Only valid for video buffer sink filters.
592
+ *
593
+ * Direct mapping to av_buffersink_get_sample_aspect_ratio().
594
+ *
595
+ * @returns Sample aspect ratio as Rational
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * const sar = bufferSink.buffersinkGetSampleAspectRatio();
600
+ * console.log(`SAR: ${sar.num}:${sar.den}`);
601
+ * ```
602
+ */
603
+ buffersinkGetSampleAspectRatio() {
604
+ const sar = this.native.buffersinkGetSampleAspectRatio();
605
+ return new Rational(sar.num, sar.den);
606
+ }
607
+ /**
608
+ * Get frame rate from buffer sink.
609
+ *
610
+ * Returns the frame rate of video from a buffer sink filter.
611
+ * Only valid for video buffer sink filters.
612
+ *
613
+ * Direct mapping to av_buffersink_get_frame_rate().
614
+ *
615
+ * @returns Frame rate as Rational
616
+ *
617
+ * @example
618
+ * ```typescript
619
+ * const frameRate = bufferSink.buffersinkGetFrameRate();
620
+ * console.log(`Frame rate: ${frameRate.num}/${frameRate.den} fps`);
621
+ * ```
622
+ */
623
+ buffersinkGetFrameRate() {
624
+ const fr = this.native.buffersinkGetFrameRate();
625
+ return new Rational(fr.num, fr.den);
626
+ }
627
+ /**
628
+ * Get sample rate from buffer sink.
629
+ *
630
+ * Returns the sample rate of audio from a buffer sink filter.
631
+ * Only valid for audio buffer sink filters.
632
+ *
633
+ * Direct mapping to av_buffersink_get_sample_rate().
634
+ *
635
+ * @returns Sample rate in Hz
636
+ *
637
+ * @example
638
+ * ```typescript
639
+ * const sampleRate = bufferSink.buffersinkGetSampleRate();
640
+ * console.log(`Sample rate: ${sampleRate} Hz`);
641
+ * ```
642
+ */
643
+ buffersinkGetSampleRate() {
644
+ return this.native.buffersinkGetSampleRate();
645
+ }
646
+ /**
647
+ * Get channel layout from buffer sink.
648
+ *
649
+ * Returns the channel layout of audio from a buffer sink filter.
650
+ * Only valid for audio buffer sink filters.
651
+ *
652
+ * Direct mapping to av_buffersink_get_channel_layout().
653
+ *
654
+ * @returns Channel layout configuration
655
+ *
656
+ * @example
657
+ * ```typescript
658
+ * const layout = bufferSink.buffersinkGetChannelLayout();
659
+ * console.log(`Channels: ${layout.nbChannels}`);
660
+ * ```
661
+ */
662
+ buffersinkGetChannelLayout() {
663
+ return this.native.buffersinkGetChannelLayout();
664
+ }
665
+ /**
666
+ * Get color space from buffer sink.
667
+ *
668
+ * Returns the color space of video from a buffer sink filter.
669
+ * Only valid for video buffer sink filters.
670
+ *
671
+ * Direct mapping to av_buffersink_get_colorspace().
672
+ *
673
+ * @returns Color space
674
+ *
675
+ * @example
676
+ * ```typescript
677
+ * const colorSpace = bufferSink.buffersinkGetColorspace();
678
+ * console.log(`Color space: ${colorSpace}`);
679
+ * ```
680
+ */
681
+ buffersinkGetColorspace() {
682
+ return this.native.buffersinkGetColorspace();
683
+ }
684
+ /**
685
+ * Get color range from buffer sink.
686
+ *
687
+ * Returns the color range of video from a buffer sink filter.
688
+ * Only valid for video buffer sink filters.
689
+ *
690
+ * Direct mapping to av_buffersink_get_color_range().
691
+ *
692
+ * @returns Color range
693
+ *
694
+ * @example
695
+ * ```typescript
696
+ * const colorRange = bufferSink.buffersinkGetColorRange();
697
+ * console.log(`Color range: ${colorRange}`);
698
+ * ```
699
+ */
700
+ buffersinkGetColorRange() {
701
+ return this.native.buffersinkGetColorRange();
702
+ }
703
+ /**
704
+ * Free the filter context.
705
+ *
706
+ * Releases all resources associated with the filter context.
707
+ * The context becomes invalid after calling this.
708
+ *
709
+ * Direct mapping to avfilter_free().
710
+ *
711
+ * @example
712
+ * ```typescript
713
+ * context.free();
714
+ * // Context is now invalid
715
+ * ```
716
+ *
717
+ * @see {@link Symbol.dispose} For automatic cleanup
718
+ */
719
+ free() {
720
+ this.native.free();
721
+ }
722
+ /**
723
+ * Check if filter is a source.
724
+ *
725
+ * Source filters generate frames without input.
726
+ *
727
+ * @returns True if filter has no inputs
728
+ *
729
+ * @example
730
+ * ```typescript
731
+ * if (context.isSource()) {
732
+ * console.log('This is a source filter');
733
+ * }
734
+ * ```
735
+ *
736
+ * @see {@link isSink} To check for sink filters
737
+ */
738
+ isSource() {
739
+ return this.nbInputs === 0;
740
+ }
741
+ /**
742
+ * Check if filter is a sink.
743
+ *
744
+ * Sink filters consume frames without output.
745
+ *
746
+ * @returns True if filter has no outputs
747
+ *
748
+ * @example
749
+ * ```typescript
750
+ * if (context.isSink()) {
751
+ * console.log('This is a sink filter');
752
+ * }
753
+ * ```
754
+ *
755
+ * @see {@link isSource} To check for source filters
756
+ */
757
+ isSink() {
758
+ return this.nbOutputs === 0;
759
+ }
760
+ /**
761
+ * Get the underlying native FilterContext object.
762
+ *
763
+ * @returns The native FilterContext binding object
764
+ *
765
+ * @internal
766
+ */
767
+ getNative() {
768
+ return this.native;
769
+ }
770
+ /**
771
+ * Dispose of the filter context.
772
+ *
773
+ * Implements the Disposable interface for automatic cleanup.
774
+ * Equivalent to calling free().
775
+ *
776
+ * @example
777
+ * ```typescript
778
+ * {
779
+ * using context = graph.createFilter(filter, 'test');
780
+ * context.initStr('640:480');
781
+ * // Use context...
782
+ * } // Automatically freed when leaving scope
783
+ * ```
784
+ */
785
+ [Symbol.dispose]() {
786
+ this.native[Symbol.dispose]();
787
+ }
788
+ }
789
+ //# sourceMappingURL=filter-context.js.map