node-av 1.1.0 → 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.
- package/README.md +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -59
- package/CHANGELOG.md +0 -8
|
@@ -2,304 +2,260 @@ import { SWS_BILINEAR } from '../constants/constants.js';
|
|
|
2
2
|
import { bindings } from './binding.js';
|
|
3
3
|
import { OptionMember } from './option.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Video scaling and pixel format conversion context.
|
|
6
6
|
*
|
|
7
|
-
* Provides high-quality
|
|
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
|
-
*
|
|
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,
|
|
17
|
+
* import { AV_PIX_FMT_YUV420P, AV_PIX_FMT_RGB24, SWS_LANCZOS } from 'node-av/constants';
|
|
17
18
|
*
|
|
18
|
-
* // Create
|
|
19
|
-
* const
|
|
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
|
-
* //
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
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
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
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
|
-
* //
|
|
37
|
-
*
|
|
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
|
|
54
|
+
* Allocate scale context.
|
|
67
55
|
*
|
|
68
|
-
* Allocates
|
|
69
|
-
*
|
|
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
|
-
*
|
|
78
|
-
*
|
|
79
|
-
*
|
|
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
|
|
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
|
-
*
|
|
94
|
-
*
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
* Direct mapping to sws_getContext()
|
|
99
|
-
*
|
|
100
|
-
* @param srcW -
|
|
101
|
-
* @param srcH -
|
|
102
|
-
* @param srcFormat -
|
|
103
|
-
* @param dstW -
|
|
104
|
-
* @param dstH -
|
|
105
|
-
* @param dstFormat -
|
|
106
|
-
* @param flags -
|
|
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 {
|
|
124
|
-
* import {
|
|
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
|
-
* //
|
|
127
|
-
*
|
|
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
|
-
*
|
|
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
|
|
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
|
|
115
|
+
* Initialize scaling context.
|
|
142
116
|
*
|
|
143
|
-
*
|
|
144
|
-
* Must be called
|
|
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
|
-
* -
|
|
150
|
-
* -
|
|
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 =
|
|
130
|
+
* const ret = scaler.initContext();
|
|
159
131
|
* FFmpegError.throwIfError(ret, 'initContext');
|
|
160
132
|
* ```
|
|
161
133
|
*
|
|
162
|
-
* @see {@link
|
|
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
|
|
140
|
+
* Free scaling context.
|
|
170
141
|
*
|
|
171
|
-
* Releases all resources associated with the
|
|
172
|
-
*
|
|
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
|
-
*
|
|
179
|
-
* //
|
|
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
|
|
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
|
-
*
|
|
161
|
+
* Scales raw image data from source to destination buffers.
|
|
162
|
+
* Low-level interface for custom buffer management.
|
|
192
163
|
*
|
|
193
|
-
*
|
|
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
|
-
* @
|
|
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
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
207
|
-
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
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 ${
|
|
187
|
+
* console.log(`Scaled ${height} lines`);
|
|
213
188
|
* ```
|
|
214
189
|
*
|
|
215
|
-
* @see {@link scaleFrame} For
|
|
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
|
|
225
|
-
*
|
|
226
|
-
* Frame-based scaling with automatic configuration.
|
|
227
|
-
* Dynamically adapts to frame properties without reallocation.
|
|
196
|
+
* Scale video frame.
|
|
228
197
|
*
|
|
229
|
-
*
|
|
198
|
+
* Scales an entire video frame to the destination format.
|
|
199
|
+
* Simpler interface than scale() for frame-based processing.
|
|
230
200
|
*
|
|
231
|
-
*
|
|
232
|
-
* @param src - The source frame
|
|
201
|
+
* Direct mapping to sws_scale_frame().
|
|
233
202
|
*
|
|
234
|
-
* @
|
|
235
|
-
*
|
|
236
|
-
*
|
|
237
|
-
* -
|
|
238
|
-
* -
|
|
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
|
-
*
|
|
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
|
|
255
|
-
* FFmpegError.throwIfError(
|
|
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
|
-
*
|
|
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
|
|
235
|
+
* Get the underlying native SoftwareScaleContext object.
|
|
236
|
+
*
|
|
237
|
+
* @returns The native SoftwareScaleContext binding object
|
|
273
238
|
*
|
|
274
|
-
* @internal
|
|
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
|
|
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
|
|
293
|
-
*
|
|
294
|
-
*
|
|
295
|
-
*
|
|
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,YAAY,EAAE,MAAM,2BAA2B,CAAC;AACzD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAM3C
|
|
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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAqCG;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;;;;;;;;;;;;;;;;;;;;;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAiCG;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;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;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;;;;;;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"}
|