@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,344 @@
1
+ import { OptionMember } from './option.js';
2
+ import type { AVPixelFormat, SwsFlags } from '../constants/constants.js';
3
+ import type { Frame } from './frame.js';
4
+ import type { NativeSoftwareScaleContext, NativeWrapper } from './native-types.js';
5
+ /**
6
+ * Video scaling and pixel format conversion context.
7
+ *
8
+ * Provides high-quality image scaling and pixel format conversion for video frames.
9
+ * Supports various scaling algorithms from fast bilinear to high-quality Lanczos.
10
+ * Essential for resolution changes, aspect ratio adjustments, and format compatibility
11
+ * in video processing pipelines.
12
+ *
13
+ * Direct mapping to FFmpeg's SwsContext.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { SoftwareScaleContext, Frame, FFmpegError } from 'node-av';
18
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_LANCZOS } from 'node-av/constants';
19
+ *
20
+ * // Create scaler
21
+ * const scaler = new SoftwareScaleContext();
22
+ *
23
+ * // Configure scaling: 1920x1080 YUV420P -> 1280x720 RGB24
24
+ * scaler.getContext(
25
+ * 1920, 1080, AV_PIX_FMT_YUV420P, // Source
26
+ * 1280, 720, AV_PIX_FMT_RGB24, // Destination
27
+ * SWS_LANCZOS // High quality
28
+ * );
29
+ *
30
+ * const ret = scaler.initContext();
31
+ * FFmpegError.throwIfError(ret, 'initContext');
32
+ *
33
+ * // Scale frames
34
+ * const dstFrame = new Frame();
35
+ * dstFrame.width = 1280;
36
+ * dstFrame.height = 720;
37
+ * dstFrame.format = AV_PIX_FMT_RGB24;
38
+ * dstFrame.allocBuffer();
39
+ *
40
+ * const height = await scaler.scaleFrame(dstFrame, srcFrame);
41
+ * console.log(`Scaled to ${height} lines`);
42
+ *
43
+ * // Clean up
44
+ * scaler.freeContext();
45
+ * ```
46
+ *
47
+ * @see [SwsContext](https://ffmpeg.org/doxygen/trunk/structSwsContext.html) - FFmpeg Doxygen
48
+ * @see {@link Frame} For video frame operations
49
+ */
50
+ export declare class SoftwareScaleContext extends OptionMember<NativeSoftwareScaleContext> implements Disposable, NativeWrapper<NativeSoftwareScaleContext> {
51
+ constructor();
52
+ /**
53
+ * Allocate scale context.
54
+ *
55
+ * Allocates memory for the scaler.
56
+ * Must be called before configuration if using options.
57
+ *
58
+ * Direct mapping to sws_alloc_context().
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const scaler = new SoftwareScaleContext();
63
+ * scaler.allocContext();
64
+ * // Now configure with setOption() or getContext()
65
+ * ```
66
+ *
67
+ * @see {@link getContext} For direct configuration
68
+ */
69
+ allocContext(): void;
70
+ /**
71
+ * Configure scaling context.
72
+ *
73
+ * Sets up the scaler with source and destination formats.
74
+ * This is the primary configuration method.
75
+ *
76
+ * Direct mapping to sws_getContext().
77
+ *
78
+ * @param srcW - Source width in pixels
79
+ *
80
+ * @param srcH - Source height in pixels
81
+ *
82
+ * @param srcFormat - Source pixel format
83
+ *
84
+ * @param dstW - Destination width in pixels
85
+ *
86
+ * @param dstH - Destination height in pixels
87
+ *
88
+ * @param dstFormat - Destination pixel format
89
+ *
90
+ * @param flags - Scaling algorithm flags (SWS_*)
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
95
+ * import { SWS_BILINEAR, SWS_BICUBIC, SWS_LANCZOS, SWS_FAST_BILINEAR } from 'node-av/constants';
96
+ *
97
+ * // Fast bilinear (lower quality, faster)
98
+ * scaler.getContext(
99
+ * 1920, 1080, AV_PIX_FMT_YUV420P,
100
+ * 1280, 720, AV_PIX_FMT_RGB24,
101
+ * SWS_FAST_BILINEAR
102
+ * );
103
+ *
104
+ * // High quality Lanczos (higher quality, slower)
105
+ * scaler.getContext(
106
+ * 1920, 1080, AV_PIX_FMT_YUV420P,
107
+ * 3840, 2160, AV_PIX_FMT_YUV420P, // Upscaling
108
+ * SWS_LANCZOS
109
+ * );
110
+ * ```
111
+ *
112
+ * @see {@link initContext} Must be called after configuration
113
+ */
114
+ getContext(srcW: number, srcH: number, srcFormat: AVPixelFormat, dstW: number, dstH: number, dstFormat: AVPixelFormat, flags?: SwsFlags): void;
115
+ /**
116
+ * Initialize scaling context.
117
+ *
118
+ * Initializes the scaler after configuration.
119
+ * Must be called before any scaling operations.
120
+ *
121
+ * Direct mapping to sws_init_context().
122
+ *
123
+ * @returns 0 on success, negative AVERROR on error:
124
+ * - AVERROR_EINVAL: Invalid parameters
125
+ * - AVERROR_ENOMEM: Memory allocation failure
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * import { FFmpegError } from 'node-av';
130
+ *
131
+ * const ret = scaler.initContext();
132
+ * FFmpegError.throwIfError(ret, 'initContext');
133
+ * ```
134
+ *
135
+ * @see {@link getContext} For configuration
136
+ */
137
+ initContext(): number;
138
+ /**
139
+ * Free scaling context.
140
+ *
141
+ * Releases all resources associated with the scaler.
142
+ * The context becomes invalid after calling this.
143
+ *
144
+ * Direct mapping to sws_freeContext().
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * scaler.freeContext();
149
+ * // Scaler is now invalid
150
+ * ```
151
+ *
152
+ * @see {@link Symbol.dispose} For automatic cleanup
153
+ */
154
+ freeContext(): void;
155
+ /**
156
+ * Scale image data.
157
+ *
158
+ * Scales raw image data from source to destination buffers.
159
+ * Low-level interface for custom buffer management.
160
+ *
161
+ * Direct mapping to sws_scale().
162
+ *
163
+ * @param srcSlice - Source data planes (one buffer per plane)
164
+ *
165
+ * @param srcStride - Bytes per line for each plane
166
+ *
167
+ * @param srcSliceY - Starting Y position in source
168
+ *
169
+ * @param srcSliceH - Height of source slice to process
170
+ *
171
+ * @param dst - Destination data planes
172
+ *
173
+ * @param dstStride - Destination bytes per line
174
+ *
175
+ * @returns Output height in pixels, negative AVERROR on error:
176
+ * - AVERROR_EINVAL: Invalid parameters
177
+ *
178
+ * @example
179
+ * ```typescript
180
+ * // Scale YUV420P data
181
+ * const srcPlanes = [yPlane, uPlane, vPlane];
182
+ * const srcStrides = [1920, 960, 960]; // Full HD
183
+ * const dstPlanes = [dstY, dstU, dstV];
184
+ * const dstStrides = [1280, 640, 640]; // 720p
185
+ *
186
+ * const height = await scaler.scale(
187
+ * srcPlanes, srcStrides, 0, 1080,
188
+ * dstPlanes, dstStrides
189
+ * );
190
+ * console.log(`Scaled ${height} lines`);
191
+ * ```
192
+ *
193
+ * @see {@link scaleFrame} For frame-based scaling
194
+ */
195
+ scale(srcSlice: Buffer[], srcStride: number[], srcSliceY: number, srcSliceH: number, dst: Buffer[], dstStride: number[]): Promise<number>;
196
+ /**
197
+ * Scale video synchronously.
198
+ * Synchronous version of scale.
199
+ *
200
+ * Scales raw video data from source to destination format.
201
+ * Can scale a slice or entire image.
202
+ *
203
+ * Direct mapping to sws_scale().
204
+ *
205
+ * @param srcSlice - Array of source buffers (one per plane)
206
+ *
207
+ * @param srcStride - Array of source strides (bytes per row)
208
+ *
209
+ * @param srcSliceY - Y position of slice (0 for full image)
210
+ *
211
+ * @param srcSliceH - Height of slice (full height for entire image)
212
+ *
213
+ * @param dst - Array of destination buffers (one per plane)
214
+ *
215
+ * @param dstStride - Array of destination strides
216
+ *
217
+ * @returns Height of output image, or negative AVERROR:
218
+ * - AVERROR_EINVAL: Invalid parameters
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * import { FFmpegError } from 'node-av';
223
+ *
224
+ * // Scale YUV420P image
225
+ * const srcBufs = [yPlane, uPlane, vPlane];
226
+ * const srcStrides = [srcWidth, srcWidth/2, srcWidth/2];
227
+ * const dstBufs = [dstY, dstU, dstV];
228
+ * const dstStrides = [dstWidth, dstWidth/2, dstWidth/2];
229
+ *
230
+ * const height = scaler.scaleSync(
231
+ * srcBufs, srcStrides,
232
+ * 0, srcHeight, // Full image
233
+ * dstBufs, dstStrides
234
+ * );
235
+ * FFmpegError.throwIfError(height, 'scaleSync');
236
+ * console.log(`Scaled ${height} lines`);
237
+ * ```
238
+ *
239
+ * @see {@link scale} For async version
240
+ */
241
+ scaleSync(srcSlice: Buffer[], srcStride: number[], srcSliceY: number, srcSliceH: number, dst: Buffer[], dstStride: number[]): number;
242
+ /**
243
+ * Scale video frame.
244
+ *
245
+ * Scales an entire video frame to the destination format.
246
+ * Simpler interface than scale() for frame-based processing.
247
+ *
248
+ * Direct mapping to sws_scale_frame().
249
+ *
250
+ * @param dst - Destination frame (must be allocated)
251
+ *
252
+ * @param src - Source frame
253
+ *
254
+ * @returns 0 on success, negative AVERROR on error:
255
+ * - AVERROR_EINVAL: Invalid parameters
256
+ * - AVERROR_ENOMEM: Memory allocation failure
257
+ *
258
+ * @example
259
+ * ```typescript
260
+ * import { Frame, FFmpegError } from 'node-av';
261
+ * import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
262
+ *
263
+ * // Create destination frame
264
+ * const dstFrame = new Frame();
265
+ * dstFrame.width = 1280;
266
+ * dstFrame.height = 720;
267
+ * dstFrame.format = AV_PIX_FMT_RGB24;
268
+ * const ret = dstFrame.allocBuffer();
269
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
270
+ *
271
+ * // Scale frame
272
+ * const ret2 = await scaler.scaleFrame(dstFrame, srcFrame);
273
+ * FFmpegError.throwIfError(ret2, 'scaleFrame');
274
+ *
275
+ * // dstFrame now contains scaled image
276
+ * ```
277
+ *
278
+ * @see {@link scale} For buffer-based scaling
279
+ */
280
+ scaleFrame(dst: Frame, src: Frame): Promise<number>;
281
+ /**
282
+ * Scale video frame synchronously.
283
+ * Synchronous version of scaleFrame.
284
+ *
285
+ * Scales an entire video frame to the destination format.
286
+ * Simpler interface than scaleSync() for frame-based processing.
287
+ *
288
+ * Direct mapping to sws_scale_frame().
289
+ *
290
+ * @param dst - Destination frame (must be allocated)
291
+ *
292
+ * @param src - Source frame
293
+ *
294
+ * @returns 0 on success, negative AVERROR on error:
295
+ * - AVERROR_EINVAL: Invalid parameters
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * import { FFmpegError } from 'node-av';
300
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
301
+ *
302
+ * // Convert YUV to RGB
303
+ * const srcFrame = new Frame();
304
+ * srcFrame.allocBuffer(AV_PIX_FMT_YUV420P, 1920, 1080);
305
+ * // ... fill with YUV data ...
306
+ *
307
+ * const dstFrame = new Frame();
308
+ * dstFrame.allocBuffer(AV_PIX_FMT_RGB24, 1920, 1080);
309
+ *
310
+ * const ret = scaler.scaleFrameSync(dstFrame, srcFrame);
311
+ * FFmpegError.throwIfError(ret, 'scaleFrameSync');
312
+ *
313
+ * // dstFrame now contains scaled image
314
+ * ```
315
+ *
316
+ * @see {@link scaleFrame} For async version
317
+ */
318
+ scaleFrameSync(dst: Frame, src: Frame): number;
319
+ /**
320
+ * Get the underlying native SoftwareScaleContext object.
321
+ *
322
+ * @returns The native SoftwareScaleContext binding object
323
+ *
324
+ * @internal
325
+ */
326
+ getNative(): NativeSoftwareScaleContext;
327
+ /**
328
+ * Dispose of the scaling context.
329
+ *
330
+ * Implements the Disposable interface for automatic cleanup.
331
+ * Equivalent to calling freeContext().
332
+ *
333
+ * @example
334
+ * ```typescript
335
+ * {
336
+ * using scaler = new SoftwareScaleContext();
337
+ * scaler.getContext(...);
338
+ * scaler.initContext();
339
+ * // Use scaler...
340
+ * } // Automatically freed when leaving scope
341
+ * ```
342
+ */
343
+ [Symbol.dispose](): void;
344
+ }
@@ -0,0 +1,366 @@
1
+ import { SWS_BILINEAR } from '../constants/constants.js';
2
+ import { bindings } from './binding.js';
3
+ import { OptionMember } from './option.js';
4
+ /**
5
+ * Video scaling and pixel format conversion context.
6
+ *
7
+ * Provides high-quality image scaling and pixel format conversion for video frames.
8
+ * Supports various scaling algorithms from fast bilinear to high-quality Lanczos.
9
+ * Essential for resolution changes, aspect ratio adjustments, and format compatibility
10
+ * in video processing pipelines.
11
+ *
12
+ * Direct mapping to FFmpeg's SwsContext.
13
+ *
14
+ * @example
15
+ * ```typescript
16
+ * import { SoftwareScaleContext, Frame, FFmpegError } from 'node-av';
17
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_LANCZOS } from 'node-av/constants';
18
+ *
19
+ * // Create scaler
20
+ * const scaler = new SoftwareScaleContext();
21
+ *
22
+ * // Configure scaling: 1920x1080 YUV420P -> 1280x720 RGB24
23
+ * scaler.getContext(
24
+ * 1920, 1080, AV_PIX_FMT_YUV420P, // Source
25
+ * 1280, 720, AV_PIX_FMT_RGB24, // Destination
26
+ * SWS_LANCZOS // High quality
27
+ * );
28
+ *
29
+ * const ret = scaler.initContext();
30
+ * FFmpegError.throwIfError(ret, 'initContext');
31
+ *
32
+ * // Scale frames
33
+ * const dstFrame = new Frame();
34
+ * dstFrame.width = 1280;
35
+ * dstFrame.height = 720;
36
+ * dstFrame.format = AV_PIX_FMT_RGB24;
37
+ * dstFrame.allocBuffer();
38
+ *
39
+ * const height = await scaler.scaleFrame(dstFrame, srcFrame);
40
+ * console.log(`Scaled to ${height} lines`);
41
+ *
42
+ * // Clean up
43
+ * scaler.freeContext();
44
+ * ```
45
+ *
46
+ * @see [SwsContext](https://ffmpeg.org/doxygen/trunk/structSwsContext.html) - FFmpeg Doxygen
47
+ * @see {@link Frame} For video frame operations
48
+ */
49
+ export class SoftwareScaleContext extends OptionMember {
50
+ constructor() {
51
+ super(new bindings.SoftwareScaleContext());
52
+ }
53
+ /**
54
+ * Allocate scale context.
55
+ *
56
+ * Allocates memory for the scaler.
57
+ * Must be called before configuration if using options.
58
+ *
59
+ * Direct mapping to sws_alloc_context().
60
+ *
61
+ * @example
62
+ * ```typescript
63
+ * const scaler = new SoftwareScaleContext();
64
+ * scaler.allocContext();
65
+ * // Now configure with setOption() or getContext()
66
+ * ```
67
+ *
68
+ * @see {@link getContext} For direct configuration
69
+ */
70
+ allocContext() {
71
+ this.native.allocContext();
72
+ }
73
+ /**
74
+ * Configure scaling context.
75
+ *
76
+ * Sets up the scaler with source and destination formats.
77
+ * This is the primary configuration method.
78
+ *
79
+ * Direct mapping to sws_getContext().
80
+ *
81
+ * @param srcW - Source width in pixels
82
+ *
83
+ * @param srcH - Source height in pixels
84
+ *
85
+ * @param srcFormat - Source pixel format
86
+ *
87
+ * @param dstW - Destination width in pixels
88
+ *
89
+ * @param dstH - Destination height in pixels
90
+ *
91
+ * @param dstFormat - Destination pixel format
92
+ *
93
+ * @param flags - Scaling algorithm flags (SWS_*)
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
98
+ * import { SWS_BILINEAR, SWS_BICUBIC, SWS_LANCZOS, SWS_FAST_BILINEAR } from 'node-av/constants';
99
+ *
100
+ * // Fast bilinear (lower quality, faster)
101
+ * scaler.getContext(
102
+ * 1920, 1080, AV_PIX_FMT_YUV420P,
103
+ * 1280, 720, AV_PIX_FMT_RGB24,
104
+ * SWS_FAST_BILINEAR
105
+ * );
106
+ *
107
+ * // High quality Lanczos (higher quality, slower)
108
+ * scaler.getContext(
109
+ * 1920, 1080, AV_PIX_FMT_YUV420P,
110
+ * 3840, 2160, AV_PIX_FMT_YUV420P, // Upscaling
111
+ * SWS_LANCZOS
112
+ * );
113
+ * ```
114
+ *
115
+ * @see {@link initContext} Must be called after configuration
116
+ */
117
+ getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags = SWS_BILINEAR) {
118
+ this.native.getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags);
119
+ }
120
+ /**
121
+ * Initialize scaling context.
122
+ *
123
+ * Initializes the scaler after configuration.
124
+ * Must be called before any scaling operations.
125
+ *
126
+ * Direct mapping to sws_init_context().
127
+ *
128
+ * @returns 0 on success, negative AVERROR on error:
129
+ * - AVERROR_EINVAL: Invalid parameters
130
+ * - AVERROR_ENOMEM: Memory allocation failure
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * import { FFmpegError } from 'node-av';
135
+ *
136
+ * const ret = scaler.initContext();
137
+ * FFmpegError.throwIfError(ret, 'initContext');
138
+ * ```
139
+ *
140
+ * @see {@link getContext} For configuration
141
+ */
142
+ initContext() {
143
+ return this.native.initContext();
144
+ }
145
+ /**
146
+ * Free scaling context.
147
+ *
148
+ * Releases all resources associated with the scaler.
149
+ * The context becomes invalid after calling this.
150
+ *
151
+ * Direct mapping to sws_freeContext().
152
+ *
153
+ * @example
154
+ * ```typescript
155
+ * scaler.freeContext();
156
+ * // Scaler is now invalid
157
+ * ```
158
+ *
159
+ * @see {@link Symbol.dispose} For automatic cleanup
160
+ */
161
+ freeContext() {
162
+ this.native.freeContext();
163
+ }
164
+ /**
165
+ * Scale image data.
166
+ *
167
+ * Scales raw image data from source to destination buffers.
168
+ * Low-level interface for custom buffer management.
169
+ *
170
+ * Direct mapping to sws_scale().
171
+ *
172
+ * @param srcSlice - Source data planes (one buffer per plane)
173
+ *
174
+ * @param srcStride - Bytes per line for each plane
175
+ *
176
+ * @param srcSliceY - Starting Y position in source
177
+ *
178
+ * @param srcSliceH - Height of source slice to process
179
+ *
180
+ * @param dst - Destination data planes
181
+ *
182
+ * @param dstStride - Destination bytes per line
183
+ *
184
+ * @returns Output height in pixels, negative AVERROR on error:
185
+ * - AVERROR_EINVAL: Invalid parameters
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * // Scale YUV420P data
190
+ * const srcPlanes = [yPlane, uPlane, vPlane];
191
+ * const srcStrides = [1920, 960, 960]; // Full HD
192
+ * const dstPlanes = [dstY, dstU, dstV];
193
+ * const dstStrides = [1280, 640, 640]; // 720p
194
+ *
195
+ * const height = await scaler.scale(
196
+ * srcPlanes, srcStrides, 0, 1080,
197
+ * dstPlanes, dstStrides
198
+ * );
199
+ * console.log(`Scaled ${height} lines`);
200
+ * ```
201
+ *
202
+ * @see {@link scaleFrame} For frame-based scaling
203
+ */
204
+ async scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride) {
205
+ return await this.native.scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride);
206
+ }
207
+ /**
208
+ * Scale video synchronously.
209
+ * Synchronous version of scale.
210
+ *
211
+ * Scales raw video data from source to destination format.
212
+ * Can scale a slice or entire image.
213
+ *
214
+ * Direct mapping to sws_scale().
215
+ *
216
+ * @param srcSlice - Array of source buffers (one per plane)
217
+ *
218
+ * @param srcStride - Array of source strides (bytes per row)
219
+ *
220
+ * @param srcSliceY - Y position of slice (0 for full image)
221
+ *
222
+ * @param srcSliceH - Height of slice (full height for entire image)
223
+ *
224
+ * @param dst - Array of destination buffers (one per plane)
225
+ *
226
+ * @param dstStride - Array of destination strides
227
+ *
228
+ * @returns Height of output image, or negative AVERROR:
229
+ * - AVERROR_EINVAL: Invalid parameters
230
+ *
231
+ * @example
232
+ * ```typescript
233
+ * import { FFmpegError } from 'node-av';
234
+ *
235
+ * // Scale YUV420P image
236
+ * const srcBufs = [yPlane, uPlane, vPlane];
237
+ * const srcStrides = [srcWidth, srcWidth/2, srcWidth/2];
238
+ * const dstBufs = [dstY, dstU, dstV];
239
+ * const dstStrides = [dstWidth, dstWidth/2, dstWidth/2];
240
+ *
241
+ * const height = scaler.scaleSync(
242
+ * srcBufs, srcStrides,
243
+ * 0, srcHeight, // Full image
244
+ * dstBufs, dstStrides
245
+ * );
246
+ * FFmpegError.throwIfError(height, 'scaleSync');
247
+ * console.log(`Scaled ${height} lines`);
248
+ * ```
249
+ *
250
+ * @see {@link scale} For async version
251
+ */
252
+ scaleSync(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride) {
253
+ return this.native.scaleSync(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride);
254
+ }
255
+ /**
256
+ * Scale video frame.
257
+ *
258
+ * Scales an entire video frame to the destination format.
259
+ * Simpler interface than scale() for frame-based processing.
260
+ *
261
+ * Direct mapping to sws_scale_frame().
262
+ *
263
+ * @param dst - Destination frame (must be allocated)
264
+ *
265
+ * @param src - Source frame
266
+ *
267
+ * @returns 0 on success, negative AVERROR on error:
268
+ * - AVERROR_EINVAL: Invalid parameters
269
+ * - AVERROR_ENOMEM: Memory allocation failure
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * import { Frame, FFmpegError } from 'node-av';
274
+ * import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
275
+ *
276
+ * // Create destination frame
277
+ * const dstFrame = new Frame();
278
+ * dstFrame.width = 1280;
279
+ * dstFrame.height = 720;
280
+ * dstFrame.format = AV_PIX_FMT_RGB24;
281
+ * const ret = dstFrame.allocBuffer();
282
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
283
+ *
284
+ * // Scale frame
285
+ * const ret2 = await scaler.scaleFrame(dstFrame, srcFrame);
286
+ * FFmpegError.throwIfError(ret2, 'scaleFrame');
287
+ *
288
+ * // dstFrame now contains scaled image
289
+ * ```
290
+ *
291
+ * @see {@link scale} For buffer-based scaling
292
+ */
293
+ async scaleFrame(dst, src) {
294
+ return await this.native.scaleFrame(dst.getNative(), src.getNative());
295
+ }
296
+ /**
297
+ * Scale video frame synchronously.
298
+ * Synchronous version of scaleFrame.
299
+ *
300
+ * Scales an entire video frame to the destination format.
301
+ * Simpler interface than scaleSync() for frame-based processing.
302
+ *
303
+ * Direct mapping to sws_scale_frame().
304
+ *
305
+ * @param dst - Destination frame (must be allocated)
306
+ *
307
+ * @param src - Source frame
308
+ *
309
+ * @returns 0 on success, negative AVERROR on error:
310
+ * - AVERROR_EINVAL: Invalid parameters
311
+ *
312
+ * @example
313
+ * ```typescript
314
+ * import { FFmpegError } from 'node-av';
315
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
316
+ *
317
+ * // Convert YUV to RGB
318
+ * const srcFrame = new Frame();
319
+ * srcFrame.allocBuffer(AV_PIX_FMT_YUV420P, 1920, 1080);
320
+ * // ... fill with YUV data ...
321
+ *
322
+ * const dstFrame = new Frame();
323
+ * dstFrame.allocBuffer(AV_PIX_FMT_RGB24, 1920, 1080);
324
+ *
325
+ * const ret = scaler.scaleFrameSync(dstFrame, srcFrame);
326
+ * FFmpegError.throwIfError(ret, 'scaleFrameSync');
327
+ *
328
+ * // dstFrame now contains scaled image
329
+ * ```
330
+ *
331
+ * @see {@link scaleFrame} For async version
332
+ */
333
+ scaleFrameSync(dst, src) {
334
+ return this.native.scaleFrameSync(dst.getNative(), src.getNative());
335
+ }
336
+ /**
337
+ * Get the underlying native SoftwareScaleContext object.
338
+ *
339
+ * @returns The native SoftwareScaleContext binding object
340
+ *
341
+ * @internal
342
+ */
343
+ getNative() {
344
+ return this.native;
345
+ }
346
+ /**
347
+ * Dispose of the scaling context.
348
+ *
349
+ * Implements the Disposable interface for automatic cleanup.
350
+ * Equivalent to calling freeContext().
351
+ *
352
+ * @example
353
+ * ```typescript
354
+ * {
355
+ * using scaler = new SoftwareScaleContext();
356
+ * scaler.getContext(...);
357
+ * scaler.initContext();
358
+ * // Use scaler...
359
+ * } // Automatically freed when leaving scope
360
+ * ```
361
+ */
362
+ [Symbol.dispose]() {
363
+ this.native[Symbol.dispose]();
364
+ }
365
+ }
366
+ //# sourceMappingURL=software-scale-context.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"software-scale-context.js","sourceRoot":"","sources":["../../src/lib/software-scale-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA4CG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAwC;IAChF;QACE,KAAK,CAAC,IAAI,QAAQ,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC7C,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA2CG;IACH,UAAU,CAAC,IAAY,EAAE,IAAY,EAAE,SAAwB,EAAE,IAAY,EAAE,IAAY,EAAE,SAAwB,EAAE,QAAkB,YAAY;QACnJ,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,WAAW;QACT,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAuCG;IACH,KAAK,CAAC,KAAK,CAAC,QAAkB,EAAE,SAAmB,EAAE,SAAiB,EAAE,SAAiB,EAAE,GAAa,EAAE,SAAmB;QAC3H,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IAC5F,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,SAAS,CAAC,QAAkB,EAAE,SAAmB,EAAE,SAAiB,EAAE,SAAiB,EAAE,GAAa,EAAE,SAAmB;QACzH,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IAC1F,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;IACH,KAAK,CAAC,UAAU,CAAC,GAAU,EAAE,GAAU;QACrC,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;IACxE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAoCG;IACH,cAAc,CAAC,GAAU,EAAE,GAAU;QACnC,OAAO,IAAI,CAAC,MAAM,CAAC,cAAc,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;IACtE,CAAC;IAED;;;;;;OAMG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,CAAC;CACF"}