node-av 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +56 -41
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +182 -126
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +286 -130
  6. package/dist/api/decoder.js +321 -159
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +254 -158
  9. package/dist/api/encoder.js +326 -298
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +912 -0
  12. package/dist/api/filter-presets.js +1407 -0
  13. package/dist/api/filter-presets.js.map +1 -0
  14. package/dist/api/filter.d.ts +280 -284
  15. package/dist/api/filter.js +435 -509
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +226 -159
  18. package/dist/api/hardware.js +405 -287
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -2
  21. package/dist/api/index.js +1 -0
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +45 -47
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +244 -141
  27. package/dist/api/media-input.js +207 -104
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +212 -129
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +22 -182
  36. package/dist/api/utilities/audio-sample.d.ts +1 -1
  37. package/dist/api/utilities/image.d.ts +1 -1
  38. package/dist/api/utilities/media-type.d.ts +1 -1
  39. package/dist/api/utilities/pixel-format.d.ts +1 -1
  40. package/dist/api/utilities/sample-format.d.ts +1 -1
  41. package/dist/api/utilities/timestamp.d.ts +1 -1
  42. package/dist/api/utils.d.ts +1 -2
  43. package/dist/api/utils.js +9 -0
  44. package/dist/api/utils.js.map +1 -1
  45. package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
  46. package/dist/constants/channel-layouts.js.map +1 -0
  47. package/dist/{lib → constants}/constants.d.ts +19 -4
  48. package/dist/{lib → constants}/constants.js +15 -1
  49. package/dist/constants/constants.js.map +1 -0
  50. package/dist/constants/decoders.d.ts +609 -0
  51. package/dist/constants/decoders.js +617 -0
  52. package/dist/constants/decoders.js.map +1 -0
  53. package/dist/constants/encoders.d.ts +285 -0
  54. package/dist/constants/encoders.js +298 -0
  55. package/dist/constants/encoders.js.map +1 -0
  56. package/dist/constants/index.d.ts +4 -0
  57. package/dist/constants/index.js +5 -0
  58. package/dist/constants/index.js.map +1 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +2 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/audio-fifo.d.ts +128 -171
  63. package/dist/lib/audio-fifo.js +130 -173
  64. package/dist/lib/audio-fifo.js.map +1 -1
  65. package/dist/lib/binding.d.ts +7 -5
  66. package/dist/lib/binding.js +5 -0
  67. package/dist/lib/binding.js.map +1 -1
  68. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  69. package/dist/lib/bitstream-filter-context.js +139 -188
  70. package/dist/lib/bitstream-filter-context.js.map +1 -1
  71. package/dist/lib/bitstream-filter.d.ts +69 -55
  72. package/dist/lib/bitstream-filter.js +68 -54
  73. package/dist/lib/bitstream-filter.js.map +1 -1
  74. package/dist/lib/codec-context.d.ts +317 -381
  75. package/dist/lib/codec-context.js +316 -381
  76. package/dist/lib/codec-context.js.map +1 -1
  77. package/dist/lib/codec-parameters.d.ts +161 -171
  78. package/dist/lib/codec-parameters.js +162 -172
  79. package/dist/lib/codec-parameters.js.map +1 -1
  80. package/dist/lib/codec-parser.d.ts +92 -105
  81. package/dist/lib/codec-parser.js +92 -103
  82. package/dist/lib/codec-parser.js.map +1 -1
  83. package/dist/lib/codec.d.ts +328 -217
  84. package/dist/lib/codec.js +392 -218
  85. package/dist/lib/codec.js.map +1 -1
  86. package/dist/lib/dictionary.d.ts +150 -204
  87. package/dist/lib/dictionary.js +159 -213
  88. package/dist/lib/dictionary.js.map +1 -1
  89. package/dist/lib/error.d.ts +97 -131
  90. package/dist/lib/error.js +98 -128
  91. package/dist/lib/error.js.map +1 -1
  92. package/dist/lib/filter-context.d.ts +317 -194
  93. package/dist/lib/filter-context.js +335 -200
  94. package/dist/lib/filter-context.js.map +1 -1
  95. package/dist/lib/filter-graph.d.ts +252 -293
  96. package/dist/lib/filter-graph.js +253 -294
  97. package/dist/lib/filter-graph.js.map +1 -1
  98. package/dist/lib/filter-inout.d.ts +87 -95
  99. package/dist/lib/filter-inout.js +87 -95
  100. package/dist/lib/filter-inout.js.map +1 -1
  101. package/dist/lib/filter.d.ts +93 -111
  102. package/dist/lib/filter.js +94 -112
  103. package/dist/lib/filter.js.map +1 -1
  104. package/dist/lib/format-context.d.ts +321 -429
  105. package/dist/lib/format-context.js +314 -386
  106. package/dist/lib/format-context.js.map +1 -1
  107. package/dist/lib/frame.d.ts +263 -406
  108. package/dist/lib/frame.js +263 -408
  109. package/dist/lib/frame.js.map +1 -1
  110. package/dist/lib/hardware-device-context.d.ts +150 -204
  111. package/dist/lib/hardware-device-context.js +149 -203
  112. package/dist/lib/hardware-device-context.js.map +1 -1
  113. package/dist/lib/hardware-frames-context.d.ts +171 -181
  114. package/dist/lib/hardware-frames-context.js +171 -181
  115. package/dist/lib/hardware-frames-context.js.map +1 -1
  116. package/dist/lib/index.d.ts +2 -3
  117. package/dist/lib/index.js +2 -5
  118. package/dist/lib/index.js.map +1 -1
  119. package/dist/lib/input-format.d.ts +90 -118
  120. package/dist/lib/input-format.js +89 -117
  121. package/dist/lib/input-format.js.map +1 -1
  122. package/dist/lib/io-context.d.ts +210 -242
  123. package/dist/lib/io-context.js +221 -253
  124. package/dist/lib/io-context.js.map +1 -1
  125. package/dist/lib/log.d.ts +86 -120
  126. package/dist/lib/log.js +85 -122
  127. package/dist/lib/log.js.map +1 -1
  128. package/dist/lib/native-types.d.ts +127 -112
  129. package/dist/lib/native-types.js +9 -0
  130. package/dist/lib/native-types.js.map +1 -1
  131. package/dist/lib/option.d.ts +285 -242
  132. package/dist/lib/option.js +310 -250
  133. package/dist/lib/option.js.map +1 -1
  134. package/dist/lib/output-format.d.ts +78 -102
  135. package/dist/lib/output-format.js +77 -101
  136. package/dist/lib/output-format.js.map +1 -1
  137. package/dist/lib/packet.d.ts +173 -241
  138. package/dist/lib/packet.js +172 -241
  139. package/dist/lib/packet.js.map +1 -1
  140. package/dist/lib/rational.d.ts +0 -2
  141. package/dist/lib/rational.js +0 -2
  142. package/dist/lib/rational.js.map +1 -1
  143. package/dist/lib/software-resample-context.d.ts +242 -326
  144. package/dist/lib/software-resample-context.js +242 -326
  145. package/dist/lib/software-resample-context.js.map +1 -1
  146. package/dist/lib/software-scale-context.d.ts +130 -174
  147. package/dist/lib/software-scale-context.js +132 -176
  148. package/dist/lib/software-scale-context.js.map +1 -1
  149. package/dist/lib/stream.d.ts +88 -198
  150. package/dist/lib/stream.js +87 -197
  151. package/dist/lib/stream.js.map +1 -1
  152. package/dist/lib/types.d.ts +1 -1
  153. package/dist/lib/utilities.d.ts +372 -181
  154. package/dist/lib/utilities.js +373 -182
  155. package/dist/lib/utilities.js.map +1 -1
  156. package/install/check.js +0 -1
  157. package/package.json +32 -24
  158. package/release_notes.md +43 -13
  159. package/CHANGELOG.md +0 -8
  160. package/dist/lib/channel-layouts.js.map +0 -1
  161. package/dist/lib/constants.js.map +0 -1
  162. /package/dist/{lib → constants}/channel-layouts.js +0 -0
@@ -1,305 +1,261 @@
1
+ import { SWS_BILINEAR } from '../constants/constants.js';
1
2
  import { bindings } from './binding.js';
2
- import { SWS_BILINEAR } from './constants.js';
3
3
  import { OptionMember } from './option.js';
4
4
  /**
5
- * Software video scaling context.
5
+ * Video scaling and pixel format conversion context.
6
6
  *
7
- * Provides high-quality video scaling, format conversion, and color space conversion.
7
+ * Provides high-quality image scaling and pixel format conversion for video frames.
8
8
  * Supports various scaling algorithms from fast bilinear to high-quality Lanczos.
9
- * Uses the libswscale library for efficient video processing.
9
+ * Essential for resolution changes, aspect ratio adjustments, and format compatibility
10
+ * in video processing pipelines.
10
11
  *
11
12
  * Direct mapping to FFmpeg's SwsContext.
12
13
  *
13
14
  * @example
14
15
  * ```typescript
15
16
  * import { SoftwareScaleContext, Frame, FFmpegError } from 'node-av';
16
- * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
17
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_LANCZOS } from 'node-av/constants';
17
18
  *
18
- * // Create and configure scale context
19
- * const sws = new SoftwareScaleContext();
20
- * sws.getContext(
21
- * 1920, 1080, AV_PIX_FMT_YUV420P,
22
- * 1280, 720, AV_PIX_FMT_RGB24,
23
- * SWS_BILINEAR
24
- * );
19
+ * // Create scaler
20
+ * const scaler = new SoftwareScaleContext();
25
21
  *
26
- * // Scale frame data
27
- * const ret = await sws.scale(
28
- * srcSlice, srcStride, 0, srcHeight,
29
- * dst, dstStride
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
30
27
  * );
31
28
  *
32
- * // Or scale Frame objects directly
33
- * const scaleRet = await sws.scaleFrame(dstFrame, srcFrame);
34
- * FFmpegError.throwIfError(scaleRet, 'scaleFrame');
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`);
35
41
  *
36
- * // Cleanup
37
- * sws.freeContext();
42
+ * // Clean up
43
+ * scaler.freeContext();
38
44
  * ```
45
+ *
46
+ * @see [SwsContext](https://ffmpeg.org/doxygen/trunk/structSwsContext.html) - FFmpeg Doxygen
47
+ * @see {@link Frame} For video frame operations
39
48
  */
40
49
  export class SoftwareScaleContext extends OptionMember {
41
- /**
42
- * Create a new software scale context.
43
- *
44
- * The context is uninitialized - you must call allocContext() or getContext() before use.
45
- * No FFmpeg resources are allocated until initialization.
46
- *
47
- * Direct wrapper around SwsContext.
48
- *
49
- * @example
50
- * ```typescript
51
- * import { SoftwareScaleContext } from 'node-av';
52
- * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
53
- *
54
- * const sws = new SoftwareScaleContext();
55
- * sws.getContext(
56
- * 1920, 1080, AV_PIX_FMT_YUV420P,
57
- * 1280, 720, AV_PIX_FMT_RGB24,
58
- * SWS_BILINEAR
59
- * );
60
- * ```
61
- */
62
50
  constructor() {
63
51
  super(new bindings.SoftwareScaleContext());
64
52
  }
65
53
  /**
66
- * Allocate an empty SwsContext.
54
+ * Allocate scale context.
67
55
  *
68
- * Allocates an uninitialized scale context.
69
- * Options must be set through the AVOptions API before calling initContext().
56
+ * Allocates memory for the scaler.
57
+ * Must be called before configuration if using options.
70
58
  *
71
- * Direct mapping to sws_alloc_context()
72
- *
73
- * @throws {Error} Memory allocation failure (ENOMEM)
59
+ * Direct mapping to sws_alloc_context().
74
60
  *
75
61
  * @example
76
62
  * ```typescript
77
- * import { SoftwareScaleContext, FFmpegError } from 'node-av';
78
- *
79
- * const sws = new SoftwareScaleContext();
80
- * sws.allocContext();
81
- * // Set options via AVOptions API
82
- * const ret = sws.initContext();
83
- * FFmpegError.throwIfError(ret, 'initContext');
63
+ * const scaler = new SoftwareScaleContext();
64
+ * scaler.allocContext();
65
+ * // Now configure with setOption() or getContext()
84
66
  * ```
85
67
  *
86
- * @see {@link getContext} For one-step allocation and configuration
87
- * @see {@link initContext} To initialize after configuration
68
+ * @see {@link getContext} For direct configuration
88
69
  */
89
70
  allocContext() {
90
71
  this.native.allocContext();
91
72
  }
92
73
  /**
93
- * Allocate and return an SwsContext.
94
- *
95
- * One-step allocation and configuration of the scale context.
96
- * Sets up everything needed for scaling operations.
97
- *
98
- * Direct mapping to sws_getContext()
99
- *
100
- * @param srcW - The width of the source image
101
- * @param srcH - The height of the source image
102
- * @param srcFormat - The source image format
103
- * @param dstW - The width of the destination image
104
- * @param dstH - The height of the destination image
105
- * @param dstFormat - The destination image format
106
- * @param flags - Specify which algorithm and options to use for rescaling:
107
- * - SWS_FAST_BILINEAR: Fast bilinear
108
- * - SWS_BILINEAR: Bilinear
109
- * - SWS_BICUBIC: Bicubic
110
- * - SWS_X: Experimental
111
- * - SWS_POINT: Nearest neighbor
112
- * - SWS_AREA: Area averaging
113
- * - SWS_BICUBLIN: Luma bicubic, chroma bilinear
114
- * - SWS_GAUSS: Gaussian
115
- * - SWS_SINC: Sinc
116
- * - SWS_LANCZOS: Lanczos
117
- * - SWS_SPLINE: Natural bicubic spline
118
- *
119
- * @throws {Error} Memory allocation failure (ENOMEM)
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
+ * @param srcH - Source height in pixels
83
+ * @param srcFormat - Source pixel format
84
+ * @param dstW - Destination width in pixels
85
+ * @param dstH - Destination height in pixels
86
+ * @param dstFormat - Destination pixel format
87
+ * @param flags - Scaling algorithm flags (SWS_*)
120
88
  *
121
89
  * @example
122
90
  * ```typescript
123
- * import { SoftwareScaleContext } from 'node-av';
124
- * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
91
+ * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24 } from 'node-av/constants';
92
+ * import { SWS_BILINEAR, SWS_BICUBIC, SWS_LANCZOS, SWS_FAST_BILINEAR } from 'node-av/constants';
125
93
  *
126
- * // Scale from 1080p YUV to 720p RGB
127
- * sws.getContext(
94
+ * // Fast bilinear (lower quality, faster)
95
+ * scaler.getContext(
128
96
  * 1920, 1080, AV_PIX_FMT_YUV420P,
129
97
  * 1280, 720, AV_PIX_FMT_RGB24,
130
- * SWS_BILINEAR
98
+ * SWS_FAST_BILINEAR
99
+ * );
100
+ *
101
+ * // High quality Lanczos (higher quality, slower)
102
+ * scaler.getContext(
103
+ * 1920, 1080, AV_PIX_FMT_YUV420P,
104
+ * 3840, 2160, AV_PIX_FMT_YUV420P, // Upscaling
105
+ * SWS_LANCZOS
131
106
  * );
132
107
  * ```
133
108
  *
134
- * @see {@link scale} To scale image data
135
- * @see {@link scaleFrame} To scale Frame objects
109
+ * @see {@link initContext} Must be called after configuration
136
110
  */
137
111
  getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags = SWS_BILINEAR) {
138
112
  this.native.getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags);
139
113
  }
140
114
  /**
141
- * Initialize the swscaler context sws_context.
115
+ * Initialize scaling context.
142
116
  *
143
- * Completes initialization of the scale context.
144
- * Must be called after allocContext() and configuration.
117
+ * Initializes the scaler after configuration.
118
+ * Must be called before any scaling operations.
145
119
  *
146
- * Direct mapping to sws_init_context()
120
+ * Direct mapping to sws_init_context().
147
121
  *
148
122
  * @returns 0 on success, negative AVERROR on error:
149
- * - 0: Success
150
- * - AVERROR(EINVAL): Invalid parameters
151
- * - AVERROR(ENOMEM): Memory allocation failure
152
- * - <0: Other errors
123
+ * - AVERROR_EINVAL: Invalid parameters
124
+ * - AVERROR_ENOMEM: Memory allocation failure
153
125
  *
154
126
  * @example
155
127
  * ```typescript
156
128
  * import { FFmpegError } from 'node-av';
157
129
  *
158
- * const ret = sws.initContext();
130
+ * const ret = scaler.initContext();
159
131
  * FFmpegError.throwIfError(ret, 'initContext');
160
132
  * ```
161
133
  *
162
- * @see {@link allocContext} For allocation
163
- * @see {@link getContext} For one-step setup
134
+ * @see {@link getContext} For configuration
164
135
  */
165
136
  initContext() {
166
137
  return this.native.initContext();
167
138
  }
168
139
  /**
169
- * Free the swscaler context swsContext.
140
+ * Free scaling context.
170
141
  *
171
- * Releases all resources associated with the scale context.
172
- * Safe to call on NULL context.
142
+ * Releases all resources associated with the scaler.
143
+ * The context becomes invalid after calling this.
173
144
  *
174
- * Direct mapping to sws_freeContext()
145
+ * Direct mapping to sws_freeContext().
175
146
  *
176
147
  * @example
177
148
  * ```typescript
178
- * sws.freeContext();
179
- * // sws is now invalid and should not be used
149
+ * scaler.freeContext();
150
+ * // Scaler is now invalid
180
151
  * ```
152
+ *
153
+ * @see {@link Symbol.dispose} For automatic cleanup
181
154
  */
182
155
  freeContext() {
183
156
  this.native.freeContext();
184
157
  }
185
158
  /**
186
- * Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst.
187
- *
188
- * Scales image data from source to destination.
189
- * Processes image in slices for efficient memory usage.
159
+ * Scale image data.
190
160
  *
191
- * Direct mapping to sws_scale()
161
+ * Scales raw image data from source to destination buffers.
162
+ * Low-level interface for custom buffer management.
192
163
  *
193
- * @param srcSlice - The array containing the pointers to the planes of the source slice
194
- * @param srcStride - The array containing the strides for each plane of the source image
195
- * @param srcSliceY - The position in the source image of the slice to process (first row number)
196
- * @param srcSliceH - The height of the source slice (number of rows)
197
- * @param dst - The array containing the pointers to the planes of the destination image
198
- * @param dstStride - The array containing the strides for each plane of the destination image
164
+ * Direct mapping to sws_scale().
199
165
  *
200
- * @returns Promise resolving to the height of the output slice
166
+ * @param srcSlice - Source data planes (one buffer per plane)
167
+ * @param srcStride - Bytes per line for each plane
168
+ * @param srcSliceY - Starting Y position in source
169
+ * @param srcSliceH - Height of source slice to process
170
+ * @param dst - Destination data planes
171
+ * @param dstStride - Destination bytes per line
172
+ * @returns Output height in pixels, negative AVERROR on error:
173
+ * - AVERROR_EINVAL: Invalid parameters
201
174
  *
202
175
  * @example
203
176
  * ```typescript
204
- * const outputHeight = await sws.scale(
205
- * srcData,
206
- * srcLinesize,
207
- * 0,
208
- * srcHeight,
209
- * dstData,
210
- * dstLinesize
177
+ * // Scale YUV420P data
178
+ * const srcPlanes = [yPlane, uPlane, vPlane];
179
+ * const srcStrides = [1920, 960, 960]; // Full HD
180
+ * const dstPlanes = [dstY, dstU, dstV];
181
+ * const dstStrides = [1280, 640, 640]; // 720p
182
+ *
183
+ * const height = await scaler.scale(
184
+ * srcPlanes, srcStrides, 0, 1080,
185
+ * dstPlanes, dstStrides
211
186
  * );
212
- * console.log(`Scaled ${outputHeight} rows`);
187
+ * console.log(`Scaled ${height} lines`);
213
188
  * ```
214
189
  *
215
- * @see {@link scaleFrame} For Frame-based scaling
216
- *
217
- * @note Slices must be provided in sequential order (top-bottom or bottom-top).
218
- * Non-sequential order results in undefined behavior.
190
+ * @see {@link scaleFrame} For frame-based scaling
219
191
  */
220
192
  async scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride) {
221
- return this.native.scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride);
193
+ return await this.native.scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride);
222
194
  }
223
195
  /**
224
- * Scale source data from src and write the output to dst.
225
- *
226
- * Frame-based scaling with automatic configuration.
227
- * Dynamically adapts to frame properties without reallocation.
196
+ * Scale video frame.
228
197
  *
229
- * Direct mapping to sws_scale_frame()
198
+ * Scales an entire video frame to the destination format.
199
+ * Simpler interface than scale() for frame-based processing.
230
200
  *
231
- * @param dst - The destination frame (buffers can be pre-allocated or allocated by scaler)
232
- * @param src - The source frame
201
+ * Direct mapping to sws_scale_frame().
233
202
  *
234
- * @returns The height of the output slice on success, negative AVERROR on error:
235
- * - >0: Output height (success)
236
- * - AVERROR(EINVAL): Invalid parameters
237
- * - AVERROR(ENOMEM): Memory allocation failure
238
- * - <0: Other errors
203
+ * @param dst - Destination frame (must be allocated)
204
+ * @param src - Source frame
205
+ * @returns 0 on success, negative AVERROR on error:
206
+ * - AVERROR_EINVAL: Invalid parameters
207
+ * - AVERROR_ENOMEM: Memory allocation failure
239
208
  *
240
209
  * @example
241
210
  * ```typescript
242
211
  * import { Frame, FFmpegError } from 'node-av';
243
212
  * import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
244
213
  *
245
- * const srcFrame = new Frame();
246
- * srcFrame.alloc();
247
- * // ... fill srcFrame with data ...
248
- *
214
+ * // Create destination frame
249
215
  * const dstFrame = new Frame();
250
- * dstFrame.alloc();
251
216
  * dstFrame.width = 1280;
252
217
  * dstFrame.height = 720;
253
218
  * dstFrame.format = AV_PIX_FMT_RGB24;
254
- * const bufRet = dstFrame.getBuffer();
255
- * FFmpegError.throwIfError(bufRet, 'getBuffer');
219
+ * const ret = dstFrame.allocBuffer();
220
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
221
+ *
222
+ * // Scale frame
223
+ * const ret2 = await scaler.scaleFrame(dstFrame, srcFrame);
224
+ * FFmpegError.throwIfError(ret2, 'scaleFrame');
256
225
  *
257
- * const ret = await sws.scaleFrame(dstFrame, srcFrame);
258
- * FFmpegError.throwIfError(ret, 'scaleFrame');
259
- * console.log(`Scaled to height: ${ret}`);
226
+ * // dstFrame now contains scaled image
260
227
  * ```
261
228
  *
262
229
  * @see {@link scale} For buffer-based scaling
263
- *
264
- * @note This function can be used directly on an allocated context without
265
- * calling sws_init_context(). Such usage is fully dynamic and does not
266
- * require reallocation if frame properties change.
267
230
  */
268
231
  async scaleFrame(dst, src) {
269
- return this.native.scaleFrame(dst.getNative(), src.getNative());
232
+ return await this.native.scaleFrame(dst.getNative(), src.getNative());
270
233
  }
271
234
  /**
272
- * Get the native FFmpeg SwsContext pointer.
235
+ * Get the underlying native SoftwareScaleContext object.
236
+ *
237
+ * @returns The native SoftwareScaleContext binding object
273
238
  *
274
- * @internal For use by other wrapper classes
275
- * @returns The underlying native scale context object
239
+ * @internal
276
240
  */
277
241
  getNative() {
278
242
  return this.native;
279
243
  }
280
244
  /**
281
- * Dispose of the scale context.
245
+ * Dispose of the scaling context.
282
246
  *
283
247
  * Implements the Disposable interface for automatic cleanup.
284
248
  * Equivalent to calling freeContext().
285
249
  *
286
250
  * @example
287
251
  * ```typescript
288
- * import { SoftwareScaleContext } from 'node-av';
289
- * import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
290
- *
291
252
  * {
292
- * using sws = new SoftwareScaleContext();
293
- * sws.getContext(
294
- * 1920, 1080, AV_PIX_FMT_YUV420P,
295
- * 1280, 720, AV_PIX_FMT_RGB24,
296
- * SWS_BILINEAR
297
- * );
298
- * // ... use context
253
+ * using scaler = new SoftwareScaleContext();
254
+ * scaler.getContext(...);
255
+ * scaler.initContext();
256
+ * // Use scaler...
299
257
  * } // Automatically freed when leaving scope
300
258
  * ```
301
- *
302
- * @see {@link freeContext} For manual cleanup
303
259
  */
304
260
  [Symbol.dispose]() {
305
261
  this.native[Symbol.dispose]();
@@ -1 +1 @@
1
- {"version":3,"file":"software-scale-context.js","sourceRoot":"","sources":["../../src/lib/software-scale-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAC9C,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,oBAAqB,SAAQ,YAAwC;IAChF;;;;;;;;;;;;;;;;;;;;OAoBG;IACH;QACE,KAAK,CAAC,IAAI,QAAQ,CAAC,oBAAoB,EAAE,CAAC,CAAC;IAC7C,CAA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