node-av 0.0.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.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,290 @@
|
|
|
1
|
+
import { OptionMember } from './option.js';
|
|
2
|
+
import type { AVPixelFormat, SWSFlag } from './constants.js';
|
|
3
|
+
import type { Frame } from './frame.js';
|
|
4
|
+
import type { NativeSoftwareScaleContext, NativeWrapper } from './native-types.js';
|
|
5
|
+
/**
|
|
6
|
+
* Software video scaling context.
|
|
7
|
+
*
|
|
8
|
+
* Provides high-quality video scaling, format conversion, and color space conversion.
|
|
9
|
+
* Supports various scaling algorithms from fast bilinear to high-quality Lanczos.
|
|
10
|
+
* Uses the libswscale library for efficient video processing.
|
|
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_BILINEAR } from 'node-av/constants';
|
|
18
|
+
*
|
|
19
|
+
* // Create and configure scale context
|
|
20
|
+
* const sws = new SoftwareScaleContext();
|
|
21
|
+
* sws.getContext(
|
|
22
|
+
* 1920, 1080, AV_PIX_FMT_YUV420P,
|
|
23
|
+
* 1280, 720, AV_PIX_FMT_RGB24,
|
|
24
|
+
* SWS_BILINEAR
|
|
25
|
+
* );
|
|
26
|
+
*
|
|
27
|
+
* // Scale frame data
|
|
28
|
+
* const ret = await sws.scale(
|
|
29
|
+
* srcSlice, srcStride, 0, srcHeight,
|
|
30
|
+
* dst, dstStride
|
|
31
|
+
* );
|
|
32
|
+
*
|
|
33
|
+
* // Or scale Frame objects directly
|
|
34
|
+
* const scaleRet = await sws.scaleFrame(dstFrame, srcFrame);
|
|
35
|
+
* FFmpegError.throwIfError(scaleRet, 'scaleFrame');
|
|
36
|
+
*
|
|
37
|
+
* // Cleanup
|
|
38
|
+
* sws.freeContext();
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export declare class SoftwareScaleContext extends OptionMember<NativeSoftwareScaleContext> implements Disposable, NativeWrapper<NativeSoftwareScaleContext> {
|
|
42
|
+
/**
|
|
43
|
+
* Create a new software scale context.
|
|
44
|
+
*
|
|
45
|
+
* The context is uninitialized - you must call allocContext() or getContext() before use.
|
|
46
|
+
* No FFmpeg resources are allocated until initialization.
|
|
47
|
+
*
|
|
48
|
+
* Direct wrapper around SwsContext.
|
|
49
|
+
*
|
|
50
|
+
* @example
|
|
51
|
+
* ```typescript
|
|
52
|
+
* import { SoftwareScaleContext } from 'node-av';
|
|
53
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
|
|
54
|
+
*
|
|
55
|
+
* const sws = new SoftwareScaleContext();
|
|
56
|
+
* sws.getContext(
|
|
57
|
+
* 1920, 1080, AV_PIX_FMT_YUV420P,
|
|
58
|
+
* 1280, 720, AV_PIX_FMT_RGB24,
|
|
59
|
+
* SWS_BILINEAR
|
|
60
|
+
* );
|
|
61
|
+
* ```
|
|
62
|
+
*/
|
|
63
|
+
constructor();
|
|
64
|
+
/**
|
|
65
|
+
* Allocate an empty SwsContext.
|
|
66
|
+
*
|
|
67
|
+
* Allocates an uninitialized scale context.
|
|
68
|
+
* Options must be set through the AVOptions API before calling initContext().
|
|
69
|
+
*
|
|
70
|
+
* Direct mapping to sws_alloc_context()
|
|
71
|
+
*
|
|
72
|
+
* @throws {Error} Memory allocation failure (ENOMEM)
|
|
73
|
+
*
|
|
74
|
+
* @example
|
|
75
|
+
* ```typescript
|
|
76
|
+
* import { SoftwareScaleContext, FFmpegError } from 'node-av';
|
|
77
|
+
*
|
|
78
|
+
* const sws = new SoftwareScaleContext();
|
|
79
|
+
* sws.allocContext();
|
|
80
|
+
* // Set options via AVOptions API
|
|
81
|
+
* const ret = sws.initContext();
|
|
82
|
+
* FFmpegError.throwIfError(ret, 'initContext');
|
|
83
|
+
* ```
|
|
84
|
+
*
|
|
85
|
+
* @see {@link getContext} For one-step allocation and configuration
|
|
86
|
+
* @see {@link initContext} To initialize after configuration
|
|
87
|
+
*/
|
|
88
|
+
allocContext(): void;
|
|
89
|
+
/**
|
|
90
|
+
* Allocate and return an SwsContext.
|
|
91
|
+
*
|
|
92
|
+
* One-step allocation and configuration of the scale context.
|
|
93
|
+
* Sets up everything needed for scaling operations.
|
|
94
|
+
*
|
|
95
|
+
* Direct mapping to sws_getContext()
|
|
96
|
+
*
|
|
97
|
+
* @param srcW - The width of the source image
|
|
98
|
+
* @param srcH - The height of the source image
|
|
99
|
+
* @param srcFormat - The source image format
|
|
100
|
+
* @param dstW - The width of the destination image
|
|
101
|
+
* @param dstH - The height of the destination image
|
|
102
|
+
* @param dstFormat - The destination image format
|
|
103
|
+
* @param flags - Specify which algorithm and options to use for rescaling:
|
|
104
|
+
* - SWS_FAST_BILINEAR: Fast bilinear
|
|
105
|
+
* - SWS_BILINEAR: Bilinear
|
|
106
|
+
* - SWS_BICUBIC: Bicubic
|
|
107
|
+
* - SWS_X: Experimental
|
|
108
|
+
* - SWS_POINT: Nearest neighbor
|
|
109
|
+
* - SWS_AREA: Area averaging
|
|
110
|
+
* - SWS_BICUBLIN: Luma bicubic, chroma bilinear
|
|
111
|
+
* - SWS_GAUSS: Gaussian
|
|
112
|
+
* - SWS_SINC: Sinc
|
|
113
|
+
* - SWS_LANCZOS: Lanczos
|
|
114
|
+
* - SWS_SPLINE: Natural bicubic spline
|
|
115
|
+
*
|
|
116
|
+
* @throws {Error} Memory allocation failure (ENOMEM)
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { SoftwareScaleContext } from 'node-av';
|
|
121
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
|
|
122
|
+
*
|
|
123
|
+
* // Scale from 1080p YUV to 720p RGB
|
|
124
|
+
* sws.getContext(
|
|
125
|
+
* 1920, 1080, AV_PIX_FMT_YUV420P,
|
|
126
|
+
* 1280, 720, AV_PIX_FMT_RGB24,
|
|
127
|
+
* SWS_BILINEAR
|
|
128
|
+
* );
|
|
129
|
+
* ```
|
|
130
|
+
*
|
|
131
|
+
* @see {@link scale} To scale image data
|
|
132
|
+
* @see {@link scaleFrame} To scale Frame objects
|
|
133
|
+
*/
|
|
134
|
+
getContext(srcW: number, srcH: number, srcFormat: AVPixelFormat, dstW: number, dstH: number, dstFormat: AVPixelFormat, flags?: SWSFlag): void;
|
|
135
|
+
/**
|
|
136
|
+
* Initialize the swscaler context sws_context.
|
|
137
|
+
*
|
|
138
|
+
* Completes initialization of the scale context.
|
|
139
|
+
* Must be called after allocContext() and configuration.
|
|
140
|
+
*
|
|
141
|
+
* Direct mapping to sws_init_context()
|
|
142
|
+
*
|
|
143
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
144
|
+
* - 0: Success
|
|
145
|
+
* - AVERROR(EINVAL): Invalid parameters
|
|
146
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
147
|
+
* - <0: Other errors
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { FFmpegError } from 'node-av';
|
|
152
|
+
*
|
|
153
|
+
* const ret = sws.initContext();
|
|
154
|
+
* FFmpegError.throwIfError(ret, 'initContext');
|
|
155
|
+
* ```
|
|
156
|
+
*
|
|
157
|
+
* @see {@link allocContext} For allocation
|
|
158
|
+
* @see {@link getContext} For one-step setup
|
|
159
|
+
*/
|
|
160
|
+
initContext(): number;
|
|
161
|
+
/**
|
|
162
|
+
* Free the swscaler context swsContext.
|
|
163
|
+
*
|
|
164
|
+
* Releases all resources associated with the scale context.
|
|
165
|
+
* Safe to call on NULL context.
|
|
166
|
+
*
|
|
167
|
+
* Direct mapping to sws_freeContext()
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* sws.freeContext();
|
|
172
|
+
* // sws is now invalid and should not be used
|
|
173
|
+
* ```
|
|
174
|
+
*/
|
|
175
|
+
freeContext(): void;
|
|
176
|
+
/**
|
|
177
|
+
* Scale the image slice in srcSlice and put the resulting scaled slice in the image in dst.
|
|
178
|
+
*
|
|
179
|
+
* Scales image data from source to destination.
|
|
180
|
+
* Processes image in slices for efficient memory usage.
|
|
181
|
+
*
|
|
182
|
+
* Direct mapping to sws_scale()
|
|
183
|
+
*
|
|
184
|
+
* @param srcSlice - The array containing the pointers to the planes of the source slice
|
|
185
|
+
* @param srcStride - The array containing the strides for each plane of the source image
|
|
186
|
+
* @param srcSliceY - The position in the source image of the slice to process (first row number)
|
|
187
|
+
* @param srcSliceH - The height of the source slice (number of rows)
|
|
188
|
+
* @param dst - The array containing the pointers to the planes of the destination image
|
|
189
|
+
* @param dstStride - The array containing the strides for each plane of the destination image
|
|
190
|
+
*
|
|
191
|
+
* @returns Promise resolving to the height of the output slice
|
|
192
|
+
*
|
|
193
|
+
* @example
|
|
194
|
+
* ```typescript
|
|
195
|
+
* const outputHeight = await sws.scale(
|
|
196
|
+
* srcData,
|
|
197
|
+
* srcLinesize,
|
|
198
|
+
* 0,
|
|
199
|
+
* srcHeight,
|
|
200
|
+
* dstData,
|
|
201
|
+
* dstLinesize
|
|
202
|
+
* );
|
|
203
|
+
* console.log(`Scaled ${outputHeight} rows`);
|
|
204
|
+
* ```
|
|
205
|
+
*
|
|
206
|
+
* @see {@link scaleFrame} For Frame-based scaling
|
|
207
|
+
*
|
|
208
|
+
* @note Slices must be provided in sequential order (top-bottom or bottom-top).
|
|
209
|
+
* Non-sequential order results in undefined behavior.
|
|
210
|
+
*/
|
|
211
|
+
scale(srcSlice: Buffer[], srcStride: number[], srcSliceY: number, srcSliceH: number, dst: Buffer[], dstStride: number[]): Promise<number>;
|
|
212
|
+
/**
|
|
213
|
+
* Scale source data from src and write the output to dst.
|
|
214
|
+
*
|
|
215
|
+
* Frame-based scaling with automatic configuration.
|
|
216
|
+
* Dynamically adapts to frame properties without reallocation.
|
|
217
|
+
*
|
|
218
|
+
* Direct mapping to sws_scale_frame()
|
|
219
|
+
*
|
|
220
|
+
* @param dst - The destination frame (buffers can be pre-allocated or allocated by scaler)
|
|
221
|
+
* @param src - The source frame
|
|
222
|
+
*
|
|
223
|
+
* @returns The height of the output slice on success, negative AVERROR on error:
|
|
224
|
+
* - >0: Output height (success)
|
|
225
|
+
* - AVERROR(EINVAL): Invalid parameters
|
|
226
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
227
|
+
* - <0: Other errors
|
|
228
|
+
*
|
|
229
|
+
* @example
|
|
230
|
+
* ```typescript
|
|
231
|
+
* import { Frame, FFmpegError } from 'node-av';
|
|
232
|
+
* import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
|
|
233
|
+
*
|
|
234
|
+
* const srcFrame = new Frame();
|
|
235
|
+
* srcFrame.alloc();
|
|
236
|
+
* // ... fill srcFrame with data ...
|
|
237
|
+
*
|
|
238
|
+
* const dstFrame = new Frame();
|
|
239
|
+
* dstFrame.alloc();
|
|
240
|
+
* dstFrame.width = 1280;
|
|
241
|
+
* dstFrame.height = 720;
|
|
242
|
+
* dstFrame.format = AV_PIX_FMT_RGB24;
|
|
243
|
+
* const bufRet = dstFrame.getBuffer();
|
|
244
|
+
* FFmpegError.throwIfError(bufRet, 'getBuffer');
|
|
245
|
+
*
|
|
246
|
+
* const ret = await sws.scaleFrame(dstFrame, srcFrame);
|
|
247
|
+
* FFmpegError.throwIfError(ret, 'scaleFrame');
|
|
248
|
+
* console.log(`Scaled to height: ${ret}`);
|
|
249
|
+
* ```
|
|
250
|
+
*
|
|
251
|
+
* @see {@link scale} For buffer-based scaling
|
|
252
|
+
*
|
|
253
|
+
* @note This function can be used directly on an allocated context without
|
|
254
|
+
* calling sws_init_context(). Such usage is fully dynamic and does not
|
|
255
|
+
* require reallocation if frame properties change.
|
|
256
|
+
*/
|
|
257
|
+
scaleFrame(dst: Frame, src: Frame): Promise<number>;
|
|
258
|
+
/**
|
|
259
|
+
* Get the native FFmpeg SwsContext pointer.
|
|
260
|
+
*
|
|
261
|
+
* @internal For use by other wrapper classes
|
|
262
|
+
* @returns The underlying native scale context object
|
|
263
|
+
*/
|
|
264
|
+
getNative(): NativeSoftwareScaleContext;
|
|
265
|
+
/**
|
|
266
|
+
* Dispose of the scale context.
|
|
267
|
+
*
|
|
268
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
269
|
+
* Equivalent to calling freeContext().
|
|
270
|
+
*
|
|
271
|
+
* @example
|
|
272
|
+
* ```typescript
|
|
273
|
+
* import { SoftwareScaleContext } from 'node-av';
|
|
274
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
|
|
275
|
+
*
|
|
276
|
+
* {
|
|
277
|
+
* using sws = new SoftwareScaleContext();
|
|
278
|
+
* sws.getContext(
|
|
279
|
+
* 1920, 1080, AV_PIX_FMT_YUV420P,
|
|
280
|
+
* 1280, 720, AV_PIX_FMT_RGB24,
|
|
281
|
+
* SWS_BILINEAR
|
|
282
|
+
* );
|
|
283
|
+
* // ... use context
|
|
284
|
+
* } // Automatically freed when leaving scope
|
|
285
|
+
* ```
|
|
286
|
+
*
|
|
287
|
+
* @see {@link freeContext} For manual cleanup
|
|
288
|
+
*/
|
|
289
|
+
[Symbol.dispose](): void;
|
|
290
|
+
}
|
|
@@ -0,0 +1,308 @@
|
|
|
1
|
+
import { bindings } from './binding.js';
|
|
2
|
+
import { SWS_BILINEAR } from './constants.js';
|
|
3
|
+
import { OptionMember } from './option.js';
|
|
4
|
+
/**
|
|
5
|
+
* Software video scaling context.
|
|
6
|
+
*
|
|
7
|
+
* Provides high-quality video scaling, format conversion, and color space conversion.
|
|
8
|
+
* Supports various scaling algorithms from fast bilinear to high-quality Lanczos.
|
|
9
|
+
* Uses the libswscale library for efficient video processing.
|
|
10
|
+
*
|
|
11
|
+
* Direct mapping to FFmpeg's SwsContext.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { SoftwareScaleContext, Frame, FFmpegError } from 'node-av';
|
|
16
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
|
|
17
|
+
*
|
|
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
|
+
* );
|
|
25
|
+
*
|
|
26
|
+
* // Scale frame data
|
|
27
|
+
* const ret = await sws.scale(
|
|
28
|
+
* srcSlice, srcStride, 0, srcHeight,
|
|
29
|
+
* dst, dstStride
|
|
30
|
+
* );
|
|
31
|
+
*
|
|
32
|
+
* // Or scale Frame objects directly
|
|
33
|
+
* const scaleRet = await sws.scaleFrame(dstFrame, srcFrame);
|
|
34
|
+
* FFmpegError.throwIfError(scaleRet, 'scaleFrame');
|
|
35
|
+
*
|
|
36
|
+
* // Cleanup
|
|
37
|
+
* sws.freeContext();
|
|
38
|
+
* ```
|
|
39
|
+
*/
|
|
40
|
+
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
|
+
constructor() {
|
|
63
|
+
super(new bindings.SoftwareScaleContext());
|
|
64
|
+
}
|
|
65
|
+
/**
|
|
66
|
+
* Allocate an empty SwsContext.
|
|
67
|
+
*
|
|
68
|
+
* Allocates an uninitialized scale context.
|
|
69
|
+
* Options must be set through the AVOptions API before calling initContext().
|
|
70
|
+
*
|
|
71
|
+
* Direct mapping to sws_alloc_context()
|
|
72
|
+
*
|
|
73
|
+
* @throws {Error} Memory allocation failure (ENOMEM)
|
|
74
|
+
*
|
|
75
|
+
* @example
|
|
76
|
+
* ```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');
|
|
84
|
+
* ```
|
|
85
|
+
*
|
|
86
|
+
* @see {@link getContext} For one-step allocation and configuration
|
|
87
|
+
* @see {@link initContext} To initialize after configuration
|
|
88
|
+
*/
|
|
89
|
+
allocContext() {
|
|
90
|
+
this.native.allocContext();
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
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)
|
|
120
|
+
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* import { SoftwareScaleContext } from 'node-av';
|
|
124
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_BILINEAR } from 'node-av/constants';
|
|
125
|
+
*
|
|
126
|
+
* // Scale from 1080p YUV to 720p RGB
|
|
127
|
+
* sws.getContext(
|
|
128
|
+
* 1920, 1080, AV_PIX_FMT_YUV420P,
|
|
129
|
+
* 1280, 720, AV_PIX_FMT_RGB24,
|
|
130
|
+
* SWS_BILINEAR
|
|
131
|
+
* );
|
|
132
|
+
* ```
|
|
133
|
+
*
|
|
134
|
+
* @see {@link scale} To scale image data
|
|
135
|
+
* @see {@link scaleFrame} To scale Frame objects
|
|
136
|
+
*/
|
|
137
|
+
getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags = SWS_BILINEAR) {
|
|
138
|
+
this.native.getContext(srcW, srcH, srcFormat, dstW, dstH, dstFormat, flags);
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* Initialize the swscaler context sws_context.
|
|
142
|
+
*
|
|
143
|
+
* Completes initialization of the scale context.
|
|
144
|
+
* Must be called after allocContext() and configuration.
|
|
145
|
+
*
|
|
146
|
+
* Direct mapping to sws_init_context()
|
|
147
|
+
*
|
|
148
|
+
* @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
|
|
153
|
+
*
|
|
154
|
+
* @example
|
|
155
|
+
* ```typescript
|
|
156
|
+
* import { FFmpegError } from 'node-av';
|
|
157
|
+
*
|
|
158
|
+
* const ret = sws.initContext();
|
|
159
|
+
* FFmpegError.throwIfError(ret, 'initContext');
|
|
160
|
+
* ```
|
|
161
|
+
*
|
|
162
|
+
* @see {@link allocContext} For allocation
|
|
163
|
+
* @see {@link getContext} For one-step setup
|
|
164
|
+
*/
|
|
165
|
+
initContext() {
|
|
166
|
+
return this.native.initContext();
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Free the swscaler context swsContext.
|
|
170
|
+
*
|
|
171
|
+
* Releases all resources associated with the scale context.
|
|
172
|
+
* Safe to call on NULL context.
|
|
173
|
+
*
|
|
174
|
+
* Direct mapping to sws_freeContext()
|
|
175
|
+
*
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* sws.freeContext();
|
|
179
|
+
* // sws is now invalid and should not be used
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
freeContext() {
|
|
183
|
+
this.native.freeContext();
|
|
184
|
+
}
|
|
185
|
+
/**
|
|
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.
|
|
190
|
+
*
|
|
191
|
+
* Direct mapping to sws_scale()
|
|
192
|
+
*
|
|
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
|
|
199
|
+
*
|
|
200
|
+
* @returns Promise resolving to the height of the output slice
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* const outputHeight = await sws.scale(
|
|
205
|
+
* srcData,
|
|
206
|
+
* srcLinesize,
|
|
207
|
+
* 0,
|
|
208
|
+
* srcHeight,
|
|
209
|
+
* dstData,
|
|
210
|
+
* dstLinesize
|
|
211
|
+
* );
|
|
212
|
+
* console.log(`Scaled ${outputHeight} rows`);
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
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.
|
|
219
|
+
*/
|
|
220
|
+
async scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride) {
|
|
221
|
+
return this.native.scale(srcSlice, srcStride, srcSliceY, srcSliceH, dst, dstStride);
|
|
222
|
+
}
|
|
223
|
+
/**
|
|
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.
|
|
228
|
+
*
|
|
229
|
+
* Direct mapping to sws_scale_frame()
|
|
230
|
+
*
|
|
231
|
+
* @param dst - The destination frame (buffers can be pre-allocated or allocated by scaler)
|
|
232
|
+
* @param src - The source frame
|
|
233
|
+
*
|
|
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
|
|
239
|
+
*
|
|
240
|
+
* @example
|
|
241
|
+
* ```typescript
|
|
242
|
+
* import { Frame, FFmpegError } from 'node-av';
|
|
243
|
+
* import { AV_PIX_FMT_RGB24 } from 'node-av/constants';
|
|
244
|
+
*
|
|
245
|
+
* const srcFrame = new Frame();
|
|
246
|
+
* srcFrame.alloc();
|
|
247
|
+
* // ... fill srcFrame with data ...
|
|
248
|
+
*
|
|
249
|
+
* const dstFrame = new Frame();
|
|
250
|
+
* dstFrame.alloc();
|
|
251
|
+
* dstFrame.width = 1280;
|
|
252
|
+
* dstFrame.height = 720;
|
|
253
|
+
* dstFrame.format = AV_PIX_FMT_RGB24;
|
|
254
|
+
* const bufRet = dstFrame.getBuffer();
|
|
255
|
+
* FFmpegError.throwIfError(bufRet, 'getBuffer');
|
|
256
|
+
*
|
|
257
|
+
* const ret = await sws.scaleFrame(dstFrame, srcFrame);
|
|
258
|
+
* FFmpegError.throwIfError(ret, 'scaleFrame');
|
|
259
|
+
* console.log(`Scaled to height: ${ret}`);
|
|
260
|
+
* ```
|
|
261
|
+
*
|
|
262
|
+
* @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
|
+
*/
|
|
268
|
+
async scaleFrame(dst, src) {
|
|
269
|
+
return this.native.scaleFrame(dst.getNative(), src.getNative());
|
|
270
|
+
}
|
|
271
|
+
/**
|
|
272
|
+
* Get the native FFmpeg SwsContext pointer.
|
|
273
|
+
*
|
|
274
|
+
* @internal For use by other wrapper classes
|
|
275
|
+
* @returns The underlying native scale context object
|
|
276
|
+
*/
|
|
277
|
+
getNative() {
|
|
278
|
+
return this.native;
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Dispose of the scale context.
|
|
282
|
+
*
|
|
283
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
284
|
+
* Equivalent to calling freeContext().
|
|
285
|
+
*
|
|
286
|
+
* @example
|
|
287
|
+
* ```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
|
+
* {
|
|
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
|
|
299
|
+
* } // Automatically freed when leaving scope
|
|
300
|
+
* ```
|
|
301
|
+
*
|
|
302
|
+
* @see {@link freeContext} For manual cleanup
|
|
303
|
+
*/
|
|
304
|
+
[Symbol.dispose]() {
|
|
305
|
+
this.native[Symbol.dispose]();
|
|
306
|
+
}
|
|
307
|
+
}
|
|
308
|
+
//# 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,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,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,YAAY;QACV,IAAI,CAAC,MAAM,CAAC,YAAY,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,UAAU,CAAC,IAAY,EAAE,IAAY,EAAE,SAAwB,EAAE,IAAY,EAAE,IAAY,EAAE,SAAwB,EAAE,QAAiB,YAAY;QAClJ,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,SAAS,EAAE,KAAK,CAAC,CAAC;IAC9E,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,WAAW;QACT,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;OAaG;IACH,WAAW;QACT,IAAI,CAAC,MAAM,CAAC,WAAW,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,KAAK,CAAC,KAAK,CAAC,QAAkB,EAAE,SAAmB,EAAE,SAAiB,EAAE,SAAiB,EAAE,GAAa,EAAE,SAAmB;QAC3H,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,QAAQ,EAAE,SAAS,EAAE,SAAS,EAAE,SAAS,EAAE,GAAG,EAAE,SAAS,CAAC,CAAC;IACtF,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OA4CG;IACH,KAAK,CAAC,UAAU,CAAC,GAAU,EAAE,GAAU;QACrC,OAAO,IAAI,CAAC,MAAM,CAAC,UAAU,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,GAAG,CAAC,SAAS,EAAE,CAAC,CAAC;IAClE,CAAC;IAED;;;;;OAKG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,CAAC;CACF"}
|