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
package/dist/lib/frame.js
CHANGED
|
@@ -2,20 +2,21 @@ import { bindings } from './binding.js';
|
|
|
2
2
|
import { HardwareFramesContext } from './hardware-frames-context.js';
|
|
3
3
|
import { Rational } from './rational.js';
|
|
4
4
|
/**
|
|
5
|
-
*
|
|
5
|
+
* Container for uncompressed audio/video data.
|
|
6
6
|
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
9
|
-
*
|
|
7
|
+
* Stores decoded audio samples or video pixels. Each frame contains raw data
|
|
8
|
+
* for a single video frame or a set of audio samples. Includes format information,
|
|
9
|
+
* timing data, and metadata. Supports both software and hardware (GPU) frames.
|
|
10
|
+
* Essential for decoding, encoding, and filter operations.
|
|
10
11
|
*
|
|
11
12
|
* Direct mapping to FFmpeg's AVFrame.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
16
|
* import { Frame, FFmpegError } from 'node-av';
|
|
16
|
-
* import { AV_PIX_FMT_YUV420P
|
|
17
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
17
18
|
*
|
|
18
|
-
* // Create and allocate frame
|
|
19
|
+
* // Create and allocate frame
|
|
19
20
|
* const frame = new Frame();
|
|
20
21
|
* frame.alloc();
|
|
21
22
|
*
|
|
@@ -23,64 +24,35 @@ import { Rational } from './rational.js';
|
|
|
23
24
|
* frame.format = AV_PIX_FMT_YUV420P;
|
|
24
25
|
* frame.width = 1920;
|
|
25
26
|
* frame.height = 1080;
|
|
26
|
-
* const
|
|
27
|
-
* FFmpegError.throwIfError(
|
|
27
|
+
* const ret = frame.allocBuffer();
|
|
28
|
+
* FFmpegError.throwIfError(ret, 'allocBuffer');
|
|
28
29
|
*
|
|
29
|
-
* //
|
|
30
|
-
* const
|
|
31
|
-
*
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
*
|
|
35
|
-
*
|
|
36
|
-
* const audioRet = audioFrame.getBuffer(); // Allocate buffers
|
|
37
|
-
* FFmpegError.throwIfError(audioRet, 'getBuffer');
|
|
38
|
-
*
|
|
39
|
-
* // Receive decoded data
|
|
40
|
-
* const ret = await codecContext.receiveFrame(frame);
|
|
41
|
-
* FFmpegError.throwIfError(ret, 'receiveFrame');
|
|
42
|
-
* console.log(`Frame PTS: ${frame.pts}`);
|
|
30
|
+
* // Receive decoded frame
|
|
31
|
+
* const ret2 = await codecContext.receiveFrame(frame);
|
|
32
|
+
* if (ret2 >= 0) {
|
|
33
|
+
* console.log(`Frame PTS: ${frame.pts}`);
|
|
34
|
+
* console.log(`Frame type: ${frame.pictType}`);
|
|
35
|
+
* console.log(`Keyframe: ${frame.keyFrame}`);
|
|
36
|
+
* }
|
|
43
37
|
*
|
|
44
38
|
* // Cleanup
|
|
45
|
-
* frame.unref();
|
|
46
|
-
* frame.free(); // Free frame completely
|
|
39
|
+
* frame.unref();
|
|
47
40
|
* ```
|
|
48
41
|
*
|
|
42
|
+
* @see [AVFrame](https://ffmpeg.org/doxygen/trunk/structAVFrame.html) - FFmpeg Doxygen
|
|
49
43
|
* @see {@link CodecContext} For encoding/decoding frames
|
|
50
44
|
* @see {@link FilterContext} For filtering frames
|
|
51
45
|
*/
|
|
52
46
|
export class Frame {
|
|
53
47
|
native;
|
|
54
48
|
_hwFramesCtx; // Cache for hardware frames context wrapper
|
|
55
|
-
/**
|
|
56
|
-
* Create a new frame.
|
|
57
|
-
*
|
|
58
|
-
* The frame is uninitialized - you must call alloc() before use.
|
|
59
|
-
* No FFmpeg resources are allocated until alloc() is called.
|
|
60
|
-
*
|
|
61
|
-
* Direct wrapper around AVFrame.
|
|
62
|
-
*
|
|
63
|
-
* @example
|
|
64
|
-
* ```typescript
|
|
65
|
-
* import { Frame } from 'node-av';
|
|
66
|
-
*
|
|
67
|
-
* const frame = new Frame();
|
|
68
|
-
* frame.alloc();
|
|
69
|
-
* // Frame is now ready for use
|
|
70
|
-
* ```
|
|
71
|
-
*/
|
|
72
49
|
constructor() {
|
|
73
50
|
this.native = new bindings.Frame();
|
|
74
51
|
}
|
|
75
52
|
/**
|
|
76
|
-
*
|
|
77
|
-
*
|
|
78
|
-
* For video: AVPixelFormat (-1 if unknown or unset).
|
|
79
|
-
* For audio: AVSampleFormat (-1 if unknown or unset).
|
|
80
|
-
*
|
|
81
|
-
* Direct mapping to AVFrame->format
|
|
53
|
+
* Pixel format for video frames or sample format for audio.
|
|
82
54
|
*
|
|
83
|
-
*
|
|
55
|
+
* Direct mapping to AVFrame->format.
|
|
84
56
|
*/
|
|
85
57
|
get format() {
|
|
86
58
|
return this.native.format;
|
|
@@ -89,12 +61,9 @@ export class Frame {
|
|
|
89
61
|
this.native.format = value;
|
|
90
62
|
}
|
|
91
63
|
/**
|
|
92
|
-
* Width of
|
|
64
|
+
* Width of video frame in pixels.
|
|
93
65
|
*
|
|
94
|
-
* Direct mapping to AVFrame->width
|
|
95
|
-
*
|
|
96
|
-
* For video: MUST be set before calling getBuffer() or allocBuffer().
|
|
97
|
-
* For audio: unused (0).
|
|
66
|
+
* Direct mapping to AVFrame->width.
|
|
98
67
|
*/
|
|
99
68
|
get width() {
|
|
100
69
|
return this.native.width;
|
|
@@ -103,12 +72,9 @@ export class Frame {
|
|
|
103
72
|
this.native.width = value;
|
|
104
73
|
}
|
|
105
74
|
/**
|
|
106
|
-
* Height of
|
|
107
|
-
*
|
|
108
|
-
* Direct mapping to AVFrame->height
|
|
75
|
+
* Height of video frame in pixels.
|
|
109
76
|
*
|
|
110
|
-
*
|
|
111
|
-
* For audio: unused (0).
|
|
77
|
+
* Direct mapping to AVFrame->height.
|
|
112
78
|
*/
|
|
113
79
|
get height() {
|
|
114
80
|
return this.native.height;
|
|
@@ -117,12 +83,9 @@ export class Frame {
|
|
|
117
83
|
this.native.height = value;
|
|
118
84
|
}
|
|
119
85
|
/**
|
|
120
|
-
* Number of audio samples
|
|
86
|
+
* Number of audio samples per channel.
|
|
121
87
|
*
|
|
122
|
-
* Direct mapping to AVFrame->nb_samples
|
|
123
|
-
*
|
|
124
|
-
* For audio: MUST be set before calling getBuffer() or allocBuffer().
|
|
125
|
-
* For video: unused (0).
|
|
88
|
+
* Direct mapping to AVFrame->nb_samples.
|
|
126
89
|
*/
|
|
127
90
|
get nbSamples() {
|
|
128
91
|
return this.native.nbSamples;
|
|
@@ -131,13 +94,12 @@ export class Frame {
|
|
|
131
94
|
this.native.nbSamples = value;
|
|
132
95
|
}
|
|
133
96
|
/**
|
|
134
|
-
* Presentation timestamp
|
|
135
|
-
*
|
|
136
|
-
* Time when frame should be shown to user.
|
|
97
|
+
* Presentation timestamp.
|
|
137
98
|
*
|
|
138
|
-
*
|
|
99
|
+
* Time when the frame should be presented.
|
|
100
|
+
* In time base units. AV_NOPTS_VALUE if unknown.
|
|
139
101
|
*
|
|
140
|
-
*
|
|
102
|
+
* Direct mapping to AVFrame->pts.
|
|
141
103
|
*/
|
|
142
104
|
get pts() {
|
|
143
105
|
return this.native.pts;
|
|
@@ -146,12 +108,12 @@ export class Frame {
|
|
|
146
108
|
this.native.pts = value;
|
|
147
109
|
}
|
|
148
110
|
/**
|
|
149
|
-
* DTS
|
|
111
|
+
* DTS from the packet that produced this frame.
|
|
150
112
|
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
113
|
+
* Copy of packet DTS for reference.
|
|
114
|
+
* In time base units. AV_NOPTS_VALUE if unknown.
|
|
153
115
|
*
|
|
154
|
-
* Direct mapping to AVFrame->pkt_dts
|
|
116
|
+
* Direct mapping to AVFrame->pkt_dts.
|
|
155
117
|
*/
|
|
156
118
|
get pktDts() {
|
|
157
119
|
return this.native.pktDts;
|
|
@@ -162,10 +124,10 @@ export class Frame {
|
|
|
162
124
|
/**
|
|
163
125
|
* Best effort timestamp.
|
|
164
126
|
*
|
|
165
|
-
*
|
|
127
|
+
* Frame timestamp estimated using various heuristics.
|
|
128
|
+
* In time base units.
|
|
166
129
|
*
|
|
167
|
-
*
|
|
168
|
-
* Uses pts if available, otherwise falls back to pkt_dts.
|
|
130
|
+
* Direct mapping to AVFrame->best_effort_timestamp.
|
|
169
131
|
*/
|
|
170
132
|
get bestEffortTimestamp() {
|
|
171
133
|
return this.native.bestEffortTimestamp;
|
|
@@ -174,12 +136,11 @@ export class Frame {
|
|
|
174
136
|
this.native.bestEffortTimestamp = value;
|
|
175
137
|
}
|
|
176
138
|
/**
|
|
177
|
-
* Time base for
|
|
139
|
+
* Time base for timestamps.
|
|
178
140
|
*
|
|
179
|
-
*
|
|
141
|
+
* Defines the unit of the timestamps (seconds per tick).
|
|
180
142
|
*
|
|
181
|
-
*
|
|
182
|
-
* of which frame timestamps are represented.
|
|
143
|
+
* Direct mapping to AVFrame->time_base.
|
|
183
144
|
*/
|
|
184
145
|
get timeBase() {
|
|
185
146
|
const tb = this.native.timeBase;
|
|
@@ -191,12 +152,9 @@ export class Frame {
|
|
|
191
152
|
/**
|
|
192
153
|
* Whether this frame is a keyframe.
|
|
193
154
|
*
|
|
194
|
-
*
|
|
155
|
+
* 1 if keyframe, 0 otherwise.
|
|
195
156
|
*
|
|
196
|
-
*
|
|
197
|
-
* It is set to 1 for all frames in intra-only codecs.
|
|
198
|
-
* - encoding: Set by libavcodec.
|
|
199
|
-
* - decoding: Set by libavcodec.
|
|
157
|
+
* Direct mapping to AVFrame->key_frame.
|
|
200
158
|
*/
|
|
201
159
|
get keyFrame() {
|
|
202
160
|
return this.native.keyFrame;
|
|
@@ -207,12 +165,9 @@ export class Frame {
|
|
|
207
165
|
/**
|
|
208
166
|
* Picture type of the frame.
|
|
209
167
|
*
|
|
210
|
-
*
|
|
168
|
+
* Type of frame (I, P, B, etc.).
|
|
211
169
|
*
|
|
212
|
-
*
|
|
213
|
-
* AV_PICTURE_TYPE_B for bi-directionally predicted frames, etc.
|
|
214
|
-
* - encoding: Set by libavcodec. for coded_picture (and set by user for input).
|
|
215
|
-
* - decoding: Set by libavcodec.
|
|
170
|
+
* Direct mapping to AVFrame->pict_type.
|
|
216
171
|
*/
|
|
217
172
|
get pictType() {
|
|
218
173
|
return this.native.pictType;
|
|
@@ -221,13 +176,11 @@ export class Frame {
|
|
|
221
176
|
this.native.pictType = value;
|
|
222
177
|
}
|
|
223
178
|
/**
|
|
224
|
-
* Sample aspect ratio
|
|
179
|
+
* Sample aspect ratio.
|
|
225
180
|
*
|
|
226
|
-
*
|
|
181
|
+
* Pixel width/height ratio. 0/1 if unknown.
|
|
227
182
|
*
|
|
228
|
-
*
|
|
229
|
-
* This is the aspect ratio of a single pixel (width/height).
|
|
230
|
-
* For anamorphic video, this differs from the display aspect ratio.
|
|
183
|
+
* Direct mapping to AVFrame->sample_aspect_ratio.
|
|
231
184
|
*/
|
|
232
185
|
get sampleAspectRatio() {
|
|
233
186
|
const sar = this.native.sampleAspectRatio;
|
|
@@ -237,13 +190,11 @@ export class Frame {
|
|
|
237
190
|
this.native.sampleAspectRatio = { num: value.num, den: value.den };
|
|
238
191
|
}
|
|
239
192
|
/**
|
|
240
|
-
*
|
|
193
|
+
* Audio sample rate.
|
|
241
194
|
*
|
|
242
|
-
*
|
|
195
|
+
* Number of samples per second.
|
|
243
196
|
*
|
|
244
|
-
*
|
|
245
|
-
* - encoding: MUST be set by user.
|
|
246
|
-
* - decoding: MAY be set by libavcodec.
|
|
197
|
+
* Direct mapping to AVFrame->sample_rate.
|
|
247
198
|
*/
|
|
248
199
|
get sampleRate() {
|
|
249
200
|
return this.native.sampleRate;
|
|
@@ -252,12 +203,11 @@ export class Frame {
|
|
|
252
203
|
this.native.sampleRate = value;
|
|
253
204
|
}
|
|
254
205
|
/**
|
|
255
|
-
*
|
|
206
|
+
* Audio channel layout.
|
|
256
207
|
*
|
|
257
|
-
*
|
|
208
|
+
* Describes the channel configuration.
|
|
258
209
|
*
|
|
259
|
-
*
|
|
260
|
-
* Must be set before calling getBuffer() for audio frames.
|
|
210
|
+
* Direct mapping to AVFrame->ch_layout.
|
|
261
211
|
*/
|
|
262
212
|
get channelLayout() {
|
|
263
213
|
return this.native.channelLayout;
|
|
@@ -268,40 +218,27 @@ export class Frame {
|
|
|
268
218
|
/**
|
|
269
219
|
* Number of audio channels.
|
|
270
220
|
*
|
|
271
|
-
* Direct mapping to AVFrame->channels
|
|
272
|
-
*
|
|
273
221
|
* Derived from channel layout.
|
|
274
|
-
* @readonly
|
|
275
222
|
*/
|
|
276
223
|
get channels() {
|
|
277
224
|
return this.native.channels;
|
|
278
225
|
}
|
|
279
226
|
/**
|
|
280
|
-
* Line
|
|
281
|
-
*
|
|
282
|
-
* Direct mapping to AVFrame->linesize
|
|
283
|
-
*
|
|
284
|
-
* For video, the size in bytes of each picture line.
|
|
285
|
-
* For audio, the size in bytes of each plane.
|
|
227
|
+
* Line sizes for each plane.
|
|
286
228
|
*
|
|
287
|
-
*
|
|
288
|
-
* plane must be the same size.
|
|
229
|
+
* Number of bytes per line for each data plane.
|
|
289
230
|
*
|
|
290
|
-
*
|
|
291
|
-
* this is 16 or 32 for modern desktop CPUs.
|
|
292
|
-
* @readonly
|
|
231
|
+
* Direct mapping to AVFrame->linesize.
|
|
293
232
|
*/
|
|
294
233
|
get linesize() {
|
|
295
234
|
return this.native.linesize;
|
|
296
235
|
}
|
|
297
236
|
/**
|
|
298
|
-
*
|
|
237
|
+
* Color range.
|
|
299
238
|
*
|
|
300
|
-
*
|
|
239
|
+
* MPEG (limited) or JPEG (full) range.
|
|
301
240
|
*
|
|
302
|
-
*
|
|
303
|
-
* - encoding: Set by user
|
|
304
|
-
* - decoding: Set by libavcodec
|
|
241
|
+
* Direct mapping to AVFrame->color_range.
|
|
305
242
|
*/
|
|
306
243
|
get colorRange() {
|
|
307
244
|
return this.native.colorRange;
|
|
@@ -310,13 +247,11 @@ export class Frame {
|
|
|
310
247
|
this.native.colorRange = value;
|
|
311
248
|
}
|
|
312
249
|
/**
|
|
313
|
-
*
|
|
250
|
+
* Color primaries.
|
|
314
251
|
*
|
|
315
|
-
*
|
|
252
|
+
* Chromaticity coordinates of the source primaries.
|
|
316
253
|
*
|
|
317
|
-
*
|
|
318
|
-
* - encoding: Set by user
|
|
319
|
-
* - decoding: Set by libavcodec
|
|
254
|
+
* Direct mapping to AVFrame->color_primaries.
|
|
320
255
|
*/
|
|
321
256
|
get colorPrimaries() {
|
|
322
257
|
return this.native.colorPrimaries;
|
|
@@ -325,13 +260,11 @@ export class Frame {
|
|
|
325
260
|
this.native.colorPrimaries = value;
|
|
326
261
|
}
|
|
327
262
|
/**
|
|
328
|
-
* Color
|
|
263
|
+
* Color transfer characteristic.
|
|
329
264
|
*
|
|
330
|
-
*
|
|
265
|
+
* Transfer function (gamma).
|
|
331
266
|
*
|
|
332
|
-
*
|
|
333
|
-
* - encoding: Set by user
|
|
334
|
-
* - decoding: Set by libavcodec
|
|
267
|
+
* Direct mapping to AVFrame->color_trc.
|
|
335
268
|
*/
|
|
336
269
|
get colorTrc() {
|
|
337
270
|
return this.native.colorTrc;
|
|
@@ -340,13 +273,11 @@ export class Frame {
|
|
|
340
273
|
this.native.colorTrc = value;
|
|
341
274
|
}
|
|
342
275
|
/**
|
|
343
|
-
* YUV
|
|
276
|
+
* YUV color space.
|
|
344
277
|
*
|
|
345
|
-
*
|
|
278
|
+
* Color space type for YUV content.
|
|
346
279
|
*
|
|
347
|
-
*
|
|
348
|
-
* - encoding: Set by user
|
|
349
|
-
* - decoding: Set by libavcodec
|
|
280
|
+
* Direct mapping to AVFrame->colorspace.
|
|
350
281
|
*/
|
|
351
282
|
get colorSpace() {
|
|
352
283
|
return this.native.colorSpace;
|
|
@@ -355,13 +286,11 @@ export class Frame {
|
|
|
355
286
|
this.native.colorSpace = value;
|
|
356
287
|
}
|
|
357
288
|
/**
|
|
358
|
-
*
|
|
289
|
+
* Chroma sample location.
|
|
359
290
|
*
|
|
360
|
-
*
|
|
291
|
+
* Position of chroma samples.
|
|
361
292
|
*
|
|
362
|
-
*
|
|
363
|
-
* - encoding: Set by user
|
|
364
|
-
* - decoding: Set by libavcodec
|
|
293
|
+
* Direct mapping to AVFrame->chroma_location.
|
|
365
294
|
*/
|
|
366
295
|
get chromaLocation() {
|
|
367
296
|
return this.native.chromaLocation;
|
|
@@ -370,52 +299,42 @@ export class Frame {
|
|
|
370
299
|
this.native.chromaLocation = value;
|
|
371
300
|
}
|
|
372
301
|
/**
|
|
373
|
-
*
|
|
302
|
+
* Raw frame data planes.
|
|
374
303
|
*
|
|
375
|
-
*
|
|
304
|
+
* Array of buffers containing the frame data.
|
|
305
|
+
* One buffer per plane (e.g., Y, U, V for YUV420P).
|
|
376
306
|
*
|
|
377
|
-
*
|
|
378
|
-
* For packed audio, this is a single pointer to all audio data.
|
|
379
|
-
* For planar audio, each channel has a separate data pointer.
|
|
380
|
-
*
|
|
381
|
-
* AVFrame.data pointers must point to the first element of an AVFrame.buf array.
|
|
382
|
-
* @readonly
|
|
307
|
+
* Direct mapping to AVFrame->data.
|
|
383
308
|
*/
|
|
384
309
|
get data() {
|
|
385
310
|
return this.native.data;
|
|
386
311
|
}
|
|
387
312
|
/**
|
|
388
|
-
*
|
|
313
|
+
* Extended data planes.
|
|
389
314
|
*
|
|
390
|
-
*
|
|
315
|
+
* For audio with >8 channels or planar audio.
|
|
316
|
+
* Points to data planes beyond the first 8.
|
|
391
317
|
*
|
|
392
|
-
*
|
|
393
|
-
* to access channels beyond the first 8. Otherwise, data[] should be used.
|
|
394
|
-
* @readonly
|
|
318
|
+
* Direct mapping to AVFrame->extended_data.
|
|
395
319
|
*/
|
|
396
320
|
get extendedData() {
|
|
397
321
|
return this.native.extendedData;
|
|
398
322
|
}
|
|
399
323
|
/**
|
|
400
|
-
* Check if
|
|
401
|
-
*
|
|
402
|
-
* Direct mapping to av_frame_is_writable()
|
|
324
|
+
* Check if frame data is writable.
|
|
403
325
|
*
|
|
404
|
-
*
|
|
405
|
-
* only one reference to each buffer. Use makeWritable() to ensure writability.
|
|
406
|
-
* @readonly
|
|
326
|
+
* True if the frame data can be modified.
|
|
407
327
|
*/
|
|
408
328
|
get isWritable() {
|
|
409
329
|
return this.native.isWritable;
|
|
410
330
|
}
|
|
411
|
-
// Hardware Acceleration
|
|
412
331
|
/**
|
|
413
332
|
* Hardware frames context.
|
|
414
333
|
*
|
|
415
|
-
*
|
|
334
|
+
* Reference to hardware frames context for GPU frames.
|
|
335
|
+
* Null for software frames.
|
|
416
336
|
*
|
|
417
|
-
*
|
|
418
|
-
* AVHWFramesContext describing the frame.
|
|
337
|
+
* Direct mapping to AVFrame->hw_frames_ctx.
|
|
419
338
|
*/
|
|
420
339
|
get hwFramesCtx() {
|
|
421
340
|
// Return cached wrapper if we already have one
|
|
@@ -439,134 +358,117 @@ export class Frame {
|
|
|
439
358
|
this._hwFramesCtx = undefined;
|
|
440
359
|
}
|
|
441
360
|
/**
|
|
442
|
-
* Allocate
|
|
361
|
+
* Allocate a new frame.
|
|
443
362
|
*
|
|
444
|
-
* Allocates the
|
|
445
|
-
*
|
|
363
|
+
* Allocates the frame structure. Must be called before using the frame
|
|
364
|
+
* unless it was created by another function (e.g., clone()).
|
|
446
365
|
*
|
|
447
|
-
* Direct mapping to av_frame_alloc()
|
|
366
|
+
* Direct mapping to av_frame_alloc().
|
|
448
367
|
*
|
|
449
|
-
* @throws {Error}
|
|
368
|
+
* @throws {Error} If allocation fails (ENOMEM)
|
|
450
369
|
*
|
|
451
370
|
* @example
|
|
452
371
|
* ```typescript
|
|
453
|
-
* import { Frame } from 'node-av';
|
|
454
|
-
*
|
|
455
372
|
* const frame = new Frame();
|
|
456
373
|
* frame.alloc();
|
|
457
|
-
* // Frame structure is now
|
|
458
|
-
* // Still need to allocate data buffers with getBuffer()
|
|
374
|
+
* // Frame structure is now ready
|
|
459
375
|
* ```
|
|
460
376
|
*
|
|
461
|
-
* @see {@link
|
|
462
|
-
* @see {@link free} To
|
|
377
|
+
* @see {@link allocBuffer} To allocate data buffers
|
|
378
|
+
* @see {@link free} To deallocate the frame
|
|
463
379
|
*/
|
|
464
380
|
alloc() {
|
|
465
381
|
this.native.alloc();
|
|
466
382
|
}
|
|
467
383
|
/**
|
|
468
|
-
* Free the frame
|
|
469
|
-
*
|
|
470
|
-
* Frees the frame structure and all associated data buffers.
|
|
471
|
-
* If the frame is reference counted, it will be unreferenced first.
|
|
384
|
+
* Free the frame.
|
|
472
385
|
*
|
|
473
|
-
*
|
|
386
|
+
* Deallocates the frame and its data. The frame becomes invalid after this.
|
|
474
387
|
*
|
|
475
|
-
*
|
|
476
|
-
* Calling this multiple times is safe, because we check the freed state
|
|
388
|
+
* Direct mapping to av_frame_free().
|
|
477
389
|
*
|
|
478
390
|
* @example
|
|
479
391
|
* ```typescript
|
|
480
|
-
* import { Frame } from 'node-av';
|
|
481
|
-
*
|
|
482
392
|
* frame.free();
|
|
483
|
-
* //
|
|
393
|
+
* // Frame is now invalid
|
|
484
394
|
* ```
|
|
485
395
|
*
|
|
486
|
-
* @see {@link unref} To
|
|
396
|
+
* @see {@link unref} To only free data, keeping structure
|
|
487
397
|
*/
|
|
488
398
|
free() {
|
|
489
399
|
this.native.free();
|
|
490
400
|
}
|
|
491
401
|
/**
|
|
492
|
-
*
|
|
402
|
+
* Create a reference to another frame.
|
|
493
403
|
*
|
|
494
|
-
*
|
|
495
|
-
* Both frames will share the same data
|
|
496
|
-
* This function does not copy side data.
|
|
404
|
+
* Sets up this frame as a reference to the source frame's data.
|
|
405
|
+
* Both frames will share the same data buffers.
|
|
497
406
|
*
|
|
498
|
-
* Direct mapping to av_frame_ref()
|
|
407
|
+
* Direct mapping to av_frame_ref().
|
|
499
408
|
*
|
|
500
409
|
* @param src - Source frame to reference
|
|
501
|
-
*
|
|
502
410
|
* @returns 0 on success, negative AVERROR on error:
|
|
503
|
-
* -
|
|
504
|
-
* -
|
|
505
|
-
* - AVERROR(EINVAL): Invalid parameters (null frame)
|
|
506
|
-
* - <0: Other errors
|
|
411
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
412
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
507
413
|
*
|
|
508
414
|
* @example
|
|
509
415
|
* ```typescript
|
|
510
|
-
* import {
|
|
416
|
+
* import { FFmpegError } from 'node-av';
|
|
511
417
|
*
|
|
512
|
-
* const
|
|
513
|
-
*
|
|
514
|
-
*
|
|
418
|
+
* const frame2 = new Frame();
|
|
419
|
+
* frame2.alloc();
|
|
420
|
+
* const ret = frame2.ref(frame1);
|
|
421
|
+
* FFmpegError.throwIfError(ret, 'ref');
|
|
422
|
+
* // frame2 now references frame1's data
|
|
515
423
|
* ```
|
|
516
424
|
*
|
|
517
|
-
* @see {@link unref} To remove
|
|
518
|
-
* @see {@link clone} To create
|
|
425
|
+
* @see {@link unref} To remove reference
|
|
426
|
+
* @see {@link clone} To create independent copy
|
|
519
427
|
*/
|
|
520
428
|
ref(src) {
|
|
521
429
|
return this.native.ref(src.getNative());
|
|
522
430
|
}
|
|
523
431
|
/**
|
|
524
|
-
* Unreference
|
|
432
|
+
* Unreference the frame.
|
|
525
433
|
*
|
|
526
|
-
*
|
|
527
|
-
* The frame
|
|
434
|
+
* Frees the frame data if this was the last reference.
|
|
435
|
+
* The frame structure remains allocated and can be reused.
|
|
528
436
|
*
|
|
529
|
-
* Direct mapping to av_frame_unref()
|
|
437
|
+
* Direct mapping to av_frame_unref().
|
|
530
438
|
*
|
|
531
439
|
* @example
|
|
532
440
|
* ```typescript
|
|
533
|
-
* import { Frame } from 'node-av';
|
|
534
|
-
*
|
|
535
441
|
* frame.unref();
|
|
536
|
-
* // Frame is
|
|
537
|
-
* // Can be reused for next decode/encode
|
|
442
|
+
* // Frame data is freed, structure can be reused
|
|
538
443
|
* ```
|
|
539
444
|
*
|
|
540
|
-
* @see {@link
|
|
445
|
+
* @see {@link ref} To create reference
|
|
446
|
+
* @see {@link free} To free everything
|
|
541
447
|
*/
|
|
542
448
|
unref() {
|
|
543
449
|
this.native.unref();
|
|
544
450
|
}
|
|
545
451
|
/**
|
|
546
|
-
*
|
|
452
|
+
* Clone the frame.
|
|
547
453
|
*
|
|
548
|
-
* Creates
|
|
549
|
-
*
|
|
454
|
+
* Creates an independent copy of the frame with its own data buffers.
|
|
455
|
+
* The new frame has the same content but can be modified independently.
|
|
550
456
|
*
|
|
551
|
-
* Direct mapping to av_frame_clone()
|
|
457
|
+
* Direct mapping to av_frame_clone().
|
|
552
458
|
*
|
|
553
|
-
* @returns New frame
|
|
554
|
-
* - Frame object: Success (new frame references this frame's data)
|
|
555
|
-
* - null: Memory allocation failure (ENOMEM)
|
|
459
|
+
* @returns New frame instance, or null on allocation failure
|
|
556
460
|
*
|
|
557
461
|
* @example
|
|
558
462
|
* ```typescript
|
|
559
|
-
*
|
|
560
|
-
*
|
|
561
|
-
*
|
|
562
|
-
*
|
|
563
|
-
* throw new Error('Failed to clone frame: Out of memory');
|
|
463
|
+
* const copy = frame.clone();
|
|
464
|
+
* if (copy) {
|
|
465
|
+
* // Modify copy without affecting original
|
|
466
|
+
* copy.pts = frame.pts + 1000n;
|
|
564
467
|
* }
|
|
565
|
-
* // clonedFrame references the same data as frame
|
|
566
|
-
* // Both frames must be freed independently
|
|
567
468
|
* ```
|
|
568
469
|
*
|
|
569
|
-
* @see {@link ref} To reference
|
|
470
|
+
* @see {@link ref} To create reference instead of copy
|
|
471
|
+
* @see {@link copy} To copy into existing frame
|
|
570
472
|
*/
|
|
571
473
|
clone() {
|
|
572
474
|
const cloned = this.native.clone();
|
|
@@ -575,266 +477,216 @@ export class Frame {
|
|
|
575
477
|
}
|
|
576
478
|
// Wrap the native cloned frame
|
|
577
479
|
const frame = Object.create(Frame.prototype);
|
|
578
|
-
// Need to set private property - this is safe since we control the implementation
|
|
579
480
|
frame.native = cloned;
|
|
580
481
|
return frame;
|
|
581
482
|
}
|
|
582
483
|
/**
|
|
583
|
-
*
|
|
484
|
+
* Get required buffer size for the frame.
|
|
584
485
|
*
|
|
585
|
-
*
|
|
586
|
-
*
|
|
486
|
+
* Calculates the required buffer size based on frame parameters.
|
|
487
|
+
* Must set format, width/height (video) or format, nb_samples, channel_layout (audio) first.
|
|
587
488
|
*
|
|
588
|
-
* Direct mapping to av_frame_get_buffer()
|
|
489
|
+
* Direct mapping to av_frame_get_buffer().
|
|
589
490
|
*
|
|
590
|
-
* @param align -
|
|
591
|
-
*
|
|
592
|
-
*
|
|
593
|
-
* - 0: Success (buffers allocated)
|
|
594
|
-
* - AVERROR(EINVAL): Invalid frame parameters (format/size not set)
|
|
595
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
596
|
-
* - <0: Other errors
|
|
491
|
+
* @param align - Buffer size alignment (0 for default)
|
|
492
|
+
* @returns Required buffer size in bytes, or negative AVERROR:
|
|
493
|
+
* - AVERROR_EINVAL: Invalid frame parameters
|
|
597
494
|
*
|
|
598
495
|
* @example
|
|
599
496
|
* ```typescript
|
|
600
|
-
* import {
|
|
497
|
+
* import { FFmpegError } from 'node-av';
|
|
601
498
|
*
|
|
602
|
-
*
|
|
603
|
-
*
|
|
604
|
-
*
|
|
605
|
-
* frame.height = 1080;
|
|
606
|
-
* const ret = frame.getBuffer(0);
|
|
607
|
-
* FFmpegError.throwIfError(ret, 'getBuffer');
|
|
608
|
-
* // Frame data buffers are now allocated
|
|
499
|
+
* const size = frame.getBuffer();
|
|
500
|
+
* FFmpegError.throwIfError(size, 'getBuffer');
|
|
501
|
+
* console.log(`Buffer size: ${size} bytes`);
|
|
609
502
|
* ```
|
|
610
503
|
*
|
|
611
|
-
* @see {@link allocBuffer}
|
|
612
|
-
* @see {@link makeWritable} Ensure buffer is writable
|
|
613
|
-
*
|
|
614
|
-
* Required fields before calling:
|
|
615
|
-
* - format (pixel format for video, sample format for audio)
|
|
616
|
-
* - width and height for video
|
|
617
|
-
* - nb_samples and channel_layout for audio
|
|
504
|
+
* @see {@link allocBuffer} To allocate the buffer
|
|
618
505
|
*/
|
|
619
506
|
getBuffer(align = 0) {
|
|
620
507
|
return this.native.getBuffer(align);
|
|
621
508
|
}
|
|
622
509
|
/**
|
|
623
|
-
* Allocate
|
|
510
|
+
* Allocate data buffers for the frame.
|
|
624
511
|
*
|
|
625
|
-
*
|
|
512
|
+
* Allocates buffers based on frame format and dimensions.
|
|
626
513
|
* Frame parameters must be set before calling.
|
|
627
514
|
*
|
|
628
|
-
* Direct mapping to av_frame_get_buffer()
|
|
515
|
+
* Direct mapping to av_frame_get_buffer().
|
|
629
516
|
*
|
|
630
517
|
* @returns 0 on success, negative AVERROR on error:
|
|
631
|
-
* -
|
|
632
|
-
* -
|
|
633
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
634
|
-
* - <0: Other errors
|
|
518
|
+
* - AVERROR_EINVAL: Invalid frame parameters
|
|
519
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
635
520
|
*
|
|
636
521
|
* @example
|
|
637
522
|
* ```typescript
|
|
638
|
-
* import {
|
|
523
|
+
* import { FFmpegError } from 'node-av';
|
|
524
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
639
525
|
*
|
|
526
|
+
* frame.format = AV_PIX_FMT_YUV420P;
|
|
527
|
+
* frame.width = 1920;
|
|
528
|
+
* frame.height = 1080;
|
|
640
529
|
* const ret = frame.allocBuffer();
|
|
641
530
|
* FFmpegError.throwIfError(ret, 'allocBuffer');
|
|
642
|
-
* // Frame data buffers are now allocated
|
|
643
531
|
* ```
|
|
644
532
|
*
|
|
645
|
-
* @see {@link getBuffer}
|
|
533
|
+
* @see {@link getBuffer} To get required size
|
|
646
534
|
*/
|
|
647
535
|
allocBuffer() {
|
|
648
536
|
return this.native.allocBuffer();
|
|
649
537
|
}
|
|
650
538
|
/**
|
|
651
|
-
* Ensure
|
|
539
|
+
* Ensure frame data is writable.
|
|
652
540
|
*
|
|
653
|
-
*
|
|
654
|
-
*
|
|
541
|
+
* Creates a private copy of the data if it's shared with other frames.
|
|
542
|
+
* Call before modifying frame data to avoid affecting other references.
|
|
655
543
|
*
|
|
656
|
-
* Direct mapping to av_frame_make_writable()
|
|
544
|
+
* Direct mapping to av_frame_make_writable().
|
|
657
545
|
*
|
|
658
546
|
* @returns 0 on success, negative AVERROR on error:
|
|
659
|
-
* -
|
|
660
|
-
* -
|
|
661
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
662
|
-
* - <0: Other errors
|
|
547
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
548
|
+
* - AVERROR_EINVAL: Invalid frame
|
|
663
549
|
*
|
|
664
550
|
* @example
|
|
665
551
|
* ```typescript
|
|
666
|
-
* import {
|
|
552
|
+
* import { FFmpegError } from 'node-av';
|
|
667
553
|
*
|
|
668
|
-
*
|
|
669
|
-
*
|
|
670
|
-
*
|
|
671
|
-
*
|
|
672
|
-
* // Frame data can now be modified safely
|
|
554
|
+
* // Ensure we can safely modify data
|
|
555
|
+
* const ret = frame.makeWritable();
|
|
556
|
+
* FFmpegError.throwIfError(ret, 'makeWritable');
|
|
557
|
+
* // Now safe to modify frame.data
|
|
673
558
|
* ```
|
|
674
|
-
*
|
|
675
|
-
* @see {@link isWritable} Check if writable
|
|
676
559
|
*/
|
|
677
560
|
makeWritable() {
|
|
678
561
|
return this.native.makeWritable();
|
|
679
562
|
}
|
|
680
563
|
/**
|
|
681
|
-
* Copy
|
|
564
|
+
* Copy frame properties without copying data.
|
|
682
565
|
*
|
|
683
|
-
* Copies
|
|
684
|
-
*
|
|
566
|
+
* Copies metadata, timestamps, format info, etc. but not the actual data.
|
|
567
|
+
* Useful for preparing output frames with same properties.
|
|
685
568
|
*
|
|
686
|
-
* Direct mapping to av_frame_copy_props()
|
|
569
|
+
* Direct mapping to av_frame_copy_props().
|
|
687
570
|
*
|
|
688
571
|
* @param src - Source frame to copy properties from
|
|
689
|
-
*
|
|
690
|
-
*
|
|
691
|
-
* - >=0: Success (properties copied)
|
|
692
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
693
|
-
* - <0: Other errors
|
|
572
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
573
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
694
574
|
*
|
|
695
575
|
* @example
|
|
696
576
|
* ```typescript
|
|
697
|
-
* import {
|
|
577
|
+
* import { FFmpegError } from 'node-av';
|
|
698
578
|
*
|
|
699
579
|
* const ret = dstFrame.copyProps(srcFrame);
|
|
700
580
|
* FFmpegError.throwIfError(ret, 'copyProps');
|
|
701
|
-
* // dstFrame now has same properties as srcFrame
|
|
581
|
+
* // dstFrame now has same properties as srcFrame
|
|
702
582
|
* ```
|
|
703
583
|
*
|
|
704
|
-
* @see {@link copy} To copy
|
|
584
|
+
* @see {@link copy} To copy both properties and data
|
|
705
585
|
*/
|
|
706
586
|
copyProps(src) {
|
|
707
587
|
return this.native.copyProps(src.getNative());
|
|
708
588
|
}
|
|
709
589
|
/**
|
|
710
|
-
* Copy
|
|
711
|
-
*
|
|
712
|
-
* Copies the actual data buffers from source to destination.
|
|
713
|
-
* Destination must be pre-allocated with same parameters.
|
|
590
|
+
* Copy frame data and properties.
|
|
714
591
|
*
|
|
715
|
-
*
|
|
592
|
+
* Copies both data and metadata from source frame.
|
|
593
|
+
* Destination must have allocated buffers of correct size.
|
|
716
594
|
*
|
|
717
|
-
*
|
|
595
|
+
* Direct mapping to av_frame_copy().
|
|
718
596
|
*
|
|
719
|
-
* @
|
|
720
|
-
*
|
|
721
|
-
* -
|
|
722
|
-
* - <0: Other errors
|
|
597
|
+
* @param src - Source frame to copy from
|
|
598
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
599
|
+
* - AVERROR_EINVAL: Incompatible frames
|
|
723
600
|
*
|
|
724
601
|
* @example
|
|
725
602
|
* ```typescript
|
|
726
|
-
* import {
|
|
603
|
+
* import { FFmpegError } from 'node-av';
|
|
727
604
|
*
|
|
728
|
-
* //
|
|
605
|
+
* // Allocate destination with same format
|
|
729
606
|
* dstFrame.format = srcFrame.format;
|
|
730
607
|
* dstFrame.width = srcFrame.width;
|
|
731
608
|
* dstFrame.height = srcFrame.height;
|
|
732
|
-
*
|
|
733
|
-
* FFmpegError.throwIfError(allocRet, 'allocBuffer');
|
|
609
|
+
* dstFrame.allocBuffer();
|
|
734
610
|
*
|
|
735
611
|
* const ret = dstFrame.copy(srcFrame);
|
|
736
612
|
* FFmpegError.throwIfError(ret, 'copy');
|
|
737
|
-
* // Data has been copied to dstFrame
|
|
738
613
|
* ```
|
|
739
614
|
*
|
|
740
|
-
* @see {@link copyProps} To copy
|
|
615
|
+
* @see {@link copyProps} To copy only properties
|
|
616
|
+
* @see {@link clone} To create new frame with copy
|
|
741
617
|
*/
|
|
742
618
|
copy(src) {
|
|
743
619
|
return this.native.copy(src.getNative());
|
|
744
620
|
}
|
|
745
621
|
/**
|
|
746
|
-
* Fill frame data from
|
|
747
|
-
*
|
|
748
|
-
* Copies raw frame data from a Buffer into this frame's data planes.
|
|
749
|
-
* The frame must be allocated with the correct format, width/height (for video),
|
|
750
|
-
* or nb_samples (for audio) before calling this method.
|
|
622
|
+
* Fill frame data from buffer.
|
|
751
623
|
*
|
|
752
|
-
*
|
|
753
|
-
*
|
|
624
|
+
* Copies data from buffer into frame data planes.
|
|
625
|
+
* Frame must have allocated buffers.
|
|
754
626
|
*
|
|
755
|
-
* @param buffer -
|
|
756
|
-
* @returns 0 on success, negative AVERROR on
|
|
627
|
+
* @param buffer - Source buffer with frame data
|
|
628
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
629
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
757
630
|
*
|
|
758
631
|
* @example
|
|
759
632
|
* ```typescript
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
*
|
|
764
|
-
*
|
|
765
|
-
* frame.height = 1080;
|
|
766
|
-
* frame.allocBuffer();
|
|
767
|
-
* frame.fromBuffer(rawYuvBuffer);
|
|
768
|
-
*
|
|
769
|
-
* // Audio frame from raw PCM data
|
|
770
|
-
* const audioFrame = new Frame();
|
|
771
|
-
* audioFrame.alloc();
|
|
772
|
-
* audioFrame.format = AV_SAMPLE_FMT_FLTP;
|
|
773
|
-
* audioFrame.nbSamples = 1024;
|
|
774
|
-
* audioFrame.channelLayout = { order: 0, nb_channels: 2, u: { mask: 3n } };
|
|
775
|
-
* audioFrame.allocBuffer();
|
|
776
|
-
* audioFrame.fromBuffer(rawPcmBuffer);
|
|
633
|
+
* import { FFmpegError } from 'node-av';
|
|
634
|
+
*
|
|
635
|
+
* const buffer = Buffer.from(rawVideoData);
|
|
636
|
+
* const ret = frame.fromBuffer(buffer);
|
|
637
|
+
* FFmpegError.throwIfError(ret, 'fromBuffer');
|
|
777
638
|
* ```
|
|
778
639
|
*/
|
|
779
640
|
fromBuffer(buffer) {
|
|
780
641
|
return this.native.fromBuffer(buffer);
|
|
781
642
|
}
|
|
782
643
|
/**
|
|
783
|
-
* Transfer data
|
|
644
|
+
* Transfer data between hardware and software frames.
|
|
784
645
|
*
|
|
785
|
-
*
|
|
786
|
-
*
|
|
646
|
+
* Copies frame data between GPU and system memory.
|
|
647
|
+
* Direction depends on source and destination frame types.
|
|
787
648
|
*
|
|
788
|
-
* Direct mapping to av_hwframe_transfer_data()
|
|
649
|
+
* Direct mapping to av_hwframe_transfer_data().
|
|
789
650
|
*
|
|
790
|
-
* @param dst - Destination frame
|
|
791
|
-
* @param flags - Transfer flags (
|
|
792
|
-
*
|
|
793
|
-
*
|
|
794
|
-
* -
|
|
795
|
-
* - AVERROR(ENOSYS): Operation not supported
|
|
796
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
797
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
798
|
-
* - <0: Other hardware-specific errors
|
|
651
|
+
* @param dst - Destination frame (software or hardware)
|
|
652
|
+
* @param flags - Transfer flags (0 for default)
|
|
653
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
654
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
655
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
799
656
|
*
|
|
800
657
|
* @example
|
|
801
658
|
* ```typescript
|
|
802
|
-
* import {
|
|
659
|
+
* import { FFmpegError } from 'node-av';
|
|
803
660
|
*
|
|
804
|
-
* //
|
|
661
|
+
* // Download from GPU to CPU
|
|
805
662
|
* const swFrame = new Frame();
|
|
806
663
|
* swFrame.alloc();
|
|
807
|
-
* const ret = await hwFrame.hwframeTransferData(swFrame
|
|
664
|
+
* const ret = await hwFrame.hwframeTransferData(swFrame);
|
|
808
665
|
* FFmpegError.throwIfError(ret, 'hwframeTransferData');
|
|
809
|
-
* // Data is now in CPU memory
|
|
810
666
|
* ```
|
|
811
667
|
*
|
|
812
|
-
* @see {@link isHwFrame}
|
|
668
|
+
* @see {@link isHwFrame} To check if frame is hardware
|
|
669
|
+
* @see {@link isSwFrame} To check if frame is software
|
|
813
670
|
*/
|
|
814
671
|
async hwframeTransferData(dst, flags) {
|
|
815
|
-
return this.native.hwframeTransferData(dst.getNative(), flags ?? 0);
|
|
672
|
+
return await this.native.hwframeTransferData(dst.getNative(), flags ?? 0);
|
|
816
673
|
}
|
|
817
674
|
/**
|
|
818
675
|
* Check if this is a hardware frame.
|
|
819
676
|
*
|
|
820
|
-
*
|
|
821
|
-
*
|
|
822
|
-
* Direct check of AVFrame->hw_frames_ctx
|
|
677
|
+
* Returns true if frame data is in GPU memory.
|
|
823
678
|
*
|
|
824
|
-
* @returns True if
|
|
679
|
+
* @returns True if hardware frame, false otherwise
|
|
825
680
|
*
|
|
826
681
|
* @example
|
|
827
682
|
* ```typescript
|
|
828
|
-
* import { Frame } from 'node-av';
|
|
829
|
-
*
|
|
830
683
|
* if (frame.isHwFrame()) {
|
|
831
684
|
* console.log('Frame is in GPU memory');
|
|
832
|
-
* } else {
|
|
833
|
-
* console.log('Frame is in CPU memory');
|
|
834
685
|
* }
|
|
835
686
|
* ```
|
|
836
687
|
*
|
|
837
|
-
* @see {@link
|
|
688
|
+
* @see {@link isSwFrame} To check for software frame
|
|
689
|
+
* @see {@link hwframeTransferData} To transfer between GPU/CPU
|
|
838
690
|
*/
|
|
839
691
|
isHwFrame() {
|
|
840
692
|
return this.native.isHwFrame();
|
|
@@ -842,104 +694,111 @@ export class Frame {
|
|
|
842
694
|
/**
|
|
843
695
|
* Check if this is a software frame.
|
|
844
696
|
*
|
|
845
|
-
*
|
|
846
|
-
* but has actual data pointers.
|
|
847
|
-
*
|
|
848
|
-
* Direct check of AVFrame->data[0] && !AVFrame->hw_frames_ctx
|
|
697
|
+
* Returns true if frame data is in system memory.
|
|
849
698
|
*
|
|
850
|
-
* @returns True if
|
|
699
|
+
* @returns True if software frame, false otherwise
|
|
851
700
|
*
|
|
852
701
|
* @example
|
|
853
702
|
* ```typescript
|
|
854
|
-
* import { Frame } from 'node-av';
|
|
855
|
-
*
|
|
856
703
|
* if (frame.isSwFrame()) {
|
|
857
|
-
* console.log('Frame is in
|
|
858
|
-
* // Safe to access frame.data
|
|
704
|
+
* console.log('Frame is in system memory');
|
|
859
705
|
* }
|
|
860
706
|
* ```
|
|
861
707
|
*
|
|
862
|
-
* @see {@link isHwFrame} To check for hardware
|
|
708
|
+
* @see {@link isHwFrame} To check for hardware frame
|
|
709
|
+
* @see {@link hwframeTransferData} To transfer between GPU/CPU
|
|
863
710
|
*/
|
|
864
711
|
isSwFrame() {
|
|
865
712
|
return this.native.isSwFrame();
|
|
866
713
|
}
|
|
867
714
|
/**
|
|
868
|
-
* Get side data
|
|
715
|
+
* Get frame side data.
|
|
716
|
+
*
|
|
717
|
+
* Retrieves additional data associated with the frame
|
|
718
|
+
* (e.g., motion vectors, film grain, HDR metadata).
|
|
869
719
|
*
|
|
870
|
-
* Direct mapping to av_frame_get_side_data()
|
|
720
|
+
* Direct mapping to av_frame_get_side_data().
|
|
871
721
|
*
|
|
872
|
-
* @param type -
|
|
873
|
-
* @returns
|
|
722
|
+
* @param type - Type of side data to retrieve
|
|
723
|
+
* @returns Side data buffer, or null if not present
|
|
874
724
|
*
|
|
875
725
|
* @example
|
|
876
726
|
* ```typescript
|
|
877
|
-
* import {
|
|
878
|
-
* import { AV_FRAME_DATA_A53_CC } from 'node-av/constants';
|
|
727
|
+
* import { AV_FRAME_DATA_MOTION_VECTORS } from 'node-av/constants';
|
|
879
728
|
*
|
|
880
|
-
*
|
|
881
|
-
*
|
|
882
|
-
*
|
|
883
|
-
* console.log('Found closed caption data:', ccData.length, 'bytes');
|
|
729
|
+
* const motionVectors = frame.getSideData(AV_FRAME_DATA_MOTION_VECTORS);
|
|
730
|
+
* if (motionVectors) {
|
|
731
|
+
* console.log(`Motion data size: ${motionVectors.length} bytes`);
|
|
884
732
|
* }
|
|
885
733
|
* ```
|
|
734
|
+
*
|
|
735
|
+
* @see {@link newSideData} To add side data
|
|
736
|
+
* @see {@link removeSideData} To remove side data
|
|
886
737
|
*/
|
|
887
738
|
getSideData(type) {
|
|
888
739
|
return this.native.getSideData(type);
|
|
889
740
|
}
|
|
890
741
|
/**
|
|
891
|
-
* Allocate new side data
|
|
742
|
+
* Allocate new side data.
|
|
892
743
|
*
|
|
893
|
-
* Allocates
|
|
894
|
-
* Returns
|
|
895
|
-
*
|
|
744
|
+
* Allocates side data buffer attached to the frame.
|
|
745
|
+
* Returns buffer that can be written to directly.
|
|
746
|
+
*
|
|
747
|
+
* Direct mapping to av_frame_new_side_data().
|
|
748
|
+
*
|
|
749
|
+
* @param type - Type of side data
|
|
750
|
+
* @param size - Size in bytes to allocate
|
|
751
|
+
* @returns Allocated buffer for writing
|
|
896
752
|
*
|
|
897
|
-
* @param type - The type of side data to allocate
|
|
898
|
-
* @param size - Size of the side data buffer to allocate
|
|
899
|
-
* @returns Buffer referencing the allocated side data
|
|
900
753
|
* @throws {Error} If allocation fails
|
|
901
754
|
*
|
|
902
755
|
* @example
|
|
903
756
|
* ```typescript
|
|
904
|
-
* import { Frame } from 'node-av';
|
|
905
757
|
* import { AV_FRAME_DATA_MASTERING_DISPLAY_METADATA } from 'node-av/constants';
|
|
906
758
|
*
|
|
907
|
-
* // Allocate HDR metadata
|
|
908
|
-
* const
|
|
759
|
+
* // Allocate and write HDR metadata
|
|
760
|
+
* const hdrData = frame.newSideData(
|
|
909
761
|
* AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
|
|
910
|
-
*
|
|
762
|
+
* 40
|
|
911
763
|
* );
|
|
912
|
-
* // Write
|
|
764
|
+
* // Write metadata to buffer...
|
|
913
765
|
* ```
|
|
766
|
+
*
|
|
767
|
+
* @see {@link getSideData} To retrieve side data
|
|
768
|
+
* @see {@link removeSideData} To remove side data
|
|
914
769
|
*/
|
|
915
770
|
newSideData(type, size) {
|
|
916
771
|
return this.native.newSideData(type, size);
|
|
917
772
|
}
|
|
918
773
|
/**
|
|
919
|
-
* Remove side data from
|
|
774
|
+
* Remove side data from frame.
|
|
775
|
+
*
|
|
776
|
+
* Removes specific type of side data.
|
|
920
777
|
*
|
|
921
|
-
*
|
|
922
|
-
* Direct mapping to av_frame_remove_side_data()
|
|
778
|
+
* Direct mapping to av_frame_remove_side_data().
|
|
923
779
|
*
|
|
924
|
-
* @param type -
|
|
780
|
+
* @param type - Type of side data to remove
|
|
925
781
|
*
|
|
926
782
|
* @example
|
|
927
783
|
* ```typescript
|
|
928
|
-
* import { Frame } from 'node-av';
|
|
929
784
|
* import { AV_FRAME_DATA_MOTION_VECTORS } from 'node-av/constants';
|
|
930
785
|
*
|
|
931
|
-
* // Remove motion vectors data
|
|
932
786
|
* frame.removeSideData(AV_FRAME_DATA_MOTION_VECTORS);
|
|
787
|
+
* // Motion vectors removed
|
|
933
788
|
* ```
|
|
789
|
+
*
|
|
790
|
+
* @see {@link getSideData} To retrieve side data
|
|
791
|
+
* @see {@link newSideData} To add side data
|
|
934
792
|
*/
|
|
935
793
|
removeSideData(type) {
|
|
936
794
|
this.native.removeSideData(type);
|
|
937
795
|
}
|
|
938
796
|
/**
|
|
939
|
-
* Get the native
|
|
797
|
+
* Get the underlying native Frame object.
|
|
798
|
+
*
|
|
799
|
+
* @returns The native Frame binding object
|
|
940
800
|
*
|
|
941
|
-
* @internal
|
|
942
|
-
* @returns The underlying native frame object
|
|
801
|
+
* @internal
|
|
943
802
|
*/
|
|
944
803
|
getNative() {
|
|
945
804
|
return this.native;
|
|
@@ -952,16 +811,12 @@ export class Frame {
|
|
|
952
811
|
*
|
|
953
812
|
* @example
|
|
954
813
|
* ```typescript
|
|
955
|
-
* import { Frame } from 'node-av';
|
|
956
|
-
*
|
|
957
814
|
* {
|
|
958
815
|
* using frame = new Frame();
|
|
959
816
|
* frame.alloc();
|
|
960
|
-
* //
|
|
817
|
+
* // Use frame...
|
|
961
818
|
* } // Automatically freed when leaving scope
|
|
962
819
|
* ```
|
|
963
|
-
*
|
|
964
|
-
* @see {@link free} For manual cleanup
|
|
965
820
|
*/
|
|
966
821
|
[Symbol.dispose]() {
|
|
967
822
|
this.native[Symbol.dispose]();
|