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.
Files changed (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -3
  21. package/dist/api/index.js +1 -1
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  27. package/dist/api/media-input.js +205 -103
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +210 -128
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. 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
- * Frame for uncompressed audio/video data.
5
+ * Container for uncompressed audio/video data.
6
6
  *
7
- * Contains raw audio samples or video pixels after decoding or before encoding.
8
- * Provides full control over allocation, configuration and lifecycle.
9
- * Supports both planar and packed data layouts for audio and video.
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, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
17
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
17
18
  *
18
- * // Create and allocate frame - full control
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 videoRet = frame.getBuffer(); // Allocate buffers
27
- * FFmpegError.throwIfError(videoRet, 'getBuffer');
27
+ * const ret = frame.allocBuffer();
28
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
28
29
  *
29
- * // Configure audio frame
30
- * const audioFrame = new Frame();
31
- * audioFrame.alloc();
32
- * audioFrame.format = AV_SAMPLE_FMT_FLTP;
33
- * audioFrame.sampleRate = 48000;
34
- * audioFrame.nbSamples = 1024;
35
- * audioFrame.channelLayout = { nbChannels: 2, order: 0, mask: 3n };
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(); // Clear data but keep frame allocated
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
- * Format of the frame.
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
- * Must be set before calling getBuffer() or allocBuffer().
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 the video frame in pixels.
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 the video frame in pixels.
107
- *
108
- * Direct mapping to AVFrame->height
75
+ * Height of video frame in pixels.
109
76
  *
110
- * For video: MUST be set before calling getBuffer() or allocBuffer().
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 (per channel) described by this frame.
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 in time_base units.
135
- *
136
- * Time when frame should be shown to user.
97
+ * Presentation timestamp.
137
98
  *
138
- * Direct mapping to AVFrame->pts
99
+ * Time when the frame should be presented.
100
+ * In time base units. AV_NOPTS_VALUE if unknown.
139
101
  *
140
- * Can be AV_NOPTS_VALUE if unknown.
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 copied from the AVPacket that triggered returning this frame.
111
+ * DTS from the packet that produced this frame.
150
112
  *
151
- * If frame threading isn't used, this is also the presentation time
152
- * calculated from only AVPacket.dts values without pts values.
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
- * Direct mapping to AVFrame->best_effort_timestamp (computed value)
127
+ * Frame timestamp estimated using various heuristics.
128
+ * In time base units.
166
129
  *
167
- * Attempts to provide the most accurate timestamp for the frame.
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 pts/dts timestamps.
139
+ * Time base for timestamps.
178
140
  *
179
- * Direct mapping to AVFrame->time_base
141
+ * Defines the unit of the timestamps (seconds per tick).
180
142
  *
181
- * This is the fundamental unit of time (in seconds) in terms
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
- * Direct mapping to AVFrame->key_frame
155
+ * 1 if keyframe, 0 otherwise.
195
156
  *
196
- * 1 -> keyframe, 0 -> not a keyframe.
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
- * Direct mapping to AVFrame->pict_type
168
+ * Type of frame (I, P, B, etc.).
211
169
  *
212
- * AV_PICTURE_TYPE_I for intra frames, AV_PICTURE_TYPE_P for predicted frames,
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 for the video frame.
179
+ * Sample aspect ratio.
225
180
  *
226
- * Direct mapping to AVFrame->sample_aspect_ratio
181
+ * Pixel width/height ratio. 0/1 if unknown.
227
182
  *
228
- * 0/1 if unknown/unspecified.
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
- * Sample rate of the audio data.
193
+ * Audio sample rate.
241
194
  *
242
- * Direct mapping to AVFrame->sample_rate
195
+ * Number of samples per second.
243
196
  *
244
- * In samples per second.
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
- * Channel layout of the audio data.
206
+ * Audio channel layout.
256
207
  *
257
- * Direct mapping to AVFrame->ch_layout
208
+ * Describes the channel configuration.
258
209
  *
259
- * Describes the number and order of audio channels.
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 size (stride) for each plane.
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
- * For audio, only linesize[0] may be set. For planar audio, each channel
288
- * plane must be the same size.
229
+ * Number of bytes per line for each data plane.
289
230
  *
290
- * For video the linesizes should be multiples of the CPUs alignment preference,
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
- * MPEG vs JPEG YUV color range.
237
+ * Color range.
299
238
  *
300
- * Direct mapping to AVFrame->color_range
239
+ * MPEG (limited) or JPEG (full) range.
301
240
  *
302
- * AVCOL_RANGE_MPEG (limited/tv/16-235), AVCOL_RANGE_JPEG (full/pc/0-255)
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
- * Chromaticity coordinates of the source primaries.
250
+ * Color primaries.
314
251
  *
315
- * Direct mapping to AVFrame->color_primaries
252
+ * Chromaticity coordinates of the source primaries.
316
253
  *
317
- * AVCOL_PRI_BT709, AVCOL_PRI_BT2020, etc.
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 Transfer Characteristic.
263
+ * Color transfer characteristic.
329
264
  *
330
- * Direct mapping to AVFrame->color_trc
265
+ * Transfer function (gamma).
331
266
  *
332
- * AVCOL_TRC_BT709, AVCOL_TRC_SMPTE2084 (PQ), AVCOL_TRC_ARIB_STD_B67 (HLG), etc.
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 colorspace type.
276
+ * YUV color space.
344
277
  *
345
- * Direct mapping to AVFrame->colorspace
278
+ * Color space type for YUV content.
346
279
  *
347
- * AVCOL_SPC_BT709, AVCOL_SPC_BT2020_NCL, etc.
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
- * Location of chroma samples.
289
+ * Chroma sample location.
359
290
  *
360
- * Direct mapping to AVFrame->chroma_location
291
+ * Position of chroma samples.
361
292
  *
362
- * AVCHROMA_LOC_LEFT (MPEG-1/2/4, H.264 default), AVCHROMA_LOC_CENTER (MPEG-2), etc.
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
- * Pointers to the data planes/channels.
302
+ * Raw frame data planes.
374
303
  *
375
- * Direct mapping to AVFrame->data
304
+ * Array of buffers containing the frame data.
305
+ * One buffer per plane (e.g., Y, U, V for YUV420P).
376
306
  *
377
- * For video, this is an array of pointers to picture planes.
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
- * Pointers to the data planes/channels for frames with more than 8 channels.
313
+ * Extended data planes.
389
314
  *
390
- * Direct mapping to AVFrame->extended_data
315
+ * For audio with >8 channels or planar audio.
316
+ * Points to data planes beyond the first 8.
391
317
  *
392
- * For audio, if the number of channels is greater than 8, this must be used
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 the frame data is writable.
401
- *
402
- * Direct mapping to av_frame_is_writable()
324
+ * Check if frame data is writable.
403
325
  *
404
- * A frame is writable if all its underlying buffers are writable and there's
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
- * Direct mapping to AVFrame->hw_frames_ctx
334
+ * Reference to hardware frames context for GPU frames.
335
+ * Null for software frames.
416
336
  *
417
- * For hwaccel-format frames, this should be a reference to the
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 an AVFrame and set its fields to default values.
361
+ * Allocate a new frame.
443
362
  *
444
- * Allocates the AVFrame structure and initializes all fields to default values.
445
- * This only allocates the frame structure itself, not the data buffers.
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} Memory allocation failure (ENOMEM)
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 allocated
458
- * // Still need to allocate data buffers with getBuffer()
374
+ * // Frame structure is now ready
459
375
  * ```
460
376
  *
461
- * @see {@link getBuffer} To allocate data buffers
462
- * @see {@link free} To free the frame
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 and any dynamically allocated objects in it.
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
- * Direct mapping to av_frame_free()
386
+ * Deallocates the frame and its data. The frame becomes invalid after this.
474
387
  *
475
- * @note
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
- * // frame is now invalid and should not be used
393
+ * // Frame is now invalid
484
394
  * ```
485
395
  *
486
- * @see {@link unref} To clear data but keep frame allocated
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
- * Set up a new reference to the data described by the source frame.
402
+ * Create a reference to another frame.
493
403
  *
494
- * Creates a reference to the source frame's data buffers.
495
- * Both frames will share the same data through reference counting.
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
- * - 0: Success (frame now references src data)
504
- * - AVERROR(ENOMEM): Memory allocation failure
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 { Frame, FFmpegError } from 'node-av';
416
+ * import { FFmpegError } from 'node-av';
511
417
  *
512
- * const ret = frame.ref(sourceFrame);
513
- * FFmpegError.throwIfError(ret, 'frame.ref');
514
- * // frame now references the same data as sourceFrame
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 references
518
- * @see {@link clone} To create a new frame with same data
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 all the buffers referenced by frame and reset the frame fields.
432
+ * Unreference the frame.
525
433
  *
526
- * Clears all data from the frame but keeps the frame structure allocated.
527
- * The frame can be reused for the next decode/encode operation.
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 now empty but still allocated
537
- * // Can be reused for next decode/encode
442
+ * // Frame data is freed, structure can be reused
538
443
  * ```
539
444
  *
540
- * @see {@link free} To completely free the frame
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
- * Create a new frame that references the same data as this frame.
452
+ * Clone the frame.
547
453
  *
548
- * Creates a new frame and sets it up as a reference to this frame's data.
549
- * This is a shortcut for av_frame_alloc() + av_frame_ref().
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 referencing the same data, or null on error:
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
- * import { Frame } from 'node-av';
560
- *
561
- * const clonedFrame = frame.clone();
562
- * if (!clonedFrame) {
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 into existing frame
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
- * Allocate new buffer(s) for audio or video data.
484
+ * Get required buffer size for the frame.
584
485
  *
585
- * Allocates data buffers for the frame based on its parameters.
586
- * Frame parameters must be set before calling this function.
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 - Required buffer size alignment. 0 for automatic.
591
- *
592
- * @returns 0 on success, negative AVERROR on error:
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 { Frame, FFmpegError, AV_PIX_FMT_YUV420P } from 'node-av';
497
+ * import { FFmpegError } from 'node-av';
601
498
  *
602
- * // Video frame
603
- * frame.format = AV_PIX_FMT_YUV420P;
604
- * frame.width = 1920;
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} Convenience wrapper with default alignment
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 buffer(s) for frame according to its parameters.
510
+ * Allocate data buffers for the frame.
624
511
  *
625
- * Convenience wrapper for getBuffer() with default alignment.
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() with align=0
515
+ * Direct mapping to av_frame_get_buffer().
629
516
  *
630
517
  * @returns 0 on success, negative AVERROR on error:
631
- * - 0: Success (buffers allocated)
632
- * - AVERROR(EINVAL): Invalid frame parameters
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 { Frame, FFmpegError } from 'node-av';
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} With custom alignment
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 that the frame data is writable.
539
+ * Ensure frame data is writable.
652
540
  *
653
- * Makes a private copy of the frame data if it's currently shared.
654
- * Does nothing if frame is already writable.
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
- * - 0: Success (frame is now writable)
660
- * - AVERROR(ENOMEM): Memory allocation failure
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 { Frame, FFmpegError } from 'node-av';
552
+ * import { FFmpegError } from 'node-av';
667
553
  *
668
- * if (!frame.isWritable) {
669
- * const ret = frame.makeWritable();
670
- * FFmpegError.throwIfError(ret, 'makeWritable');
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 only "metadata" fields from src to this frame.
564
+ * Copy frame properties without copying data.
682
565
  *
683
- * Copies all frame properties except the actual data buffers.
684
- * This includes timestamps, format, dimensions, side data, etc.
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
- * @returns >=0 on success, negative AVERROR on error:
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 { Frame, FFmpegError } from 'node-av';
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 (but not data)
581
+ * // dstFrame now has same properties as srcFrame
702
582
  * ```
703
583
  *
704
- * @see {@link copy} To copy data as well
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 the frame data from src to this frame.
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
- * Direct mapping to av_frame_copy()
592
+ * Copies both data and metadata from source frame.
593
+ * Destination must have allocated buffers of correct size.
716
594
  *
717
- * @param src - Source frame to copy data from
595
+ * Direct mapping to av_frame_copy().
718
596
  *
719
- * @returns >=0 on success, negative AVERROR on error:
720
- * - >=0: Success (data copied)
721
- * - AVERROR(EINVAL): Frames have different parameters (format, size, etc.)
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 { Frame, FFmpegError } from 'node-av';
603
+ * import { FFmpegError } from 'node-av';
727
604
  *
728
- * // Destination must be allocated with same parameters
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
- * const allocRet = dstFrame.allocBuffer();
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 metadata only
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 a buffer.
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
- * For video frames, the buffer should contain raw pixel data in the frame's pixel format.
753
- * For audio frames, the buffer should contain raw audio samples in the frame's sample format.
624
+ * Copies data from buffer into frame data planes.
625
+ * Frame must have allocated buffers.
754
626
  *
755
- * @param buffer - Buffer containing raw frame data
756
- * @returns 0 on success, negative AVERROR on failure
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
- * // Video frame from raw YUV420p data
761
- * const frame = new Frame();
762
- * frame.alloc();
763
- * frame.format = AV_PIX_FMT_YUV420P;
764
- * frame.width = 1920;
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 to or from hardware surfaces.
644
+ * Transfer data between hardware and software frames.
784
645
  *
785
- * Transfers frame data between hardware (GPU) and software (CPU) memory.
786
- * Can be used for both upload and download operations.
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 (currently unused, should be set to zero)
792
- *
793
- * @returns Promise resolving to 0 on success, negative AVERROR on error:
794
- * - 0: Success (data transferred)
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 { Frame, FFmpegError } from 'node-av';
659
+ * import { FFmpegError } from 'node-av';
803
660
  *
804
- * // Transfer from hardware to software frame
661
+ * // Download from GPU to CPU
805
662
  * const swFrame = new Frame();
806
663
  * swFrame.alloc();
807
- * const ret = await hwFrame.hwframeTransferData(swFrame, 0);
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} Check if frame is hardware frame
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
- * A frame is considered a hardware frame if it has a hw_frames_ctx set.
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 this is a hardware frame, false otherwise
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 hwframeTransferData} To transfer between CPU and GPU
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
- * A frame is considered a software frame if it doesn't have hw_frames_ctx
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 this is a software frame, false otherwise
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 CPU memory');
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 frames
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 from the frame.
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 - The type of side data to retrieve
873
- * @returns Buffer containing the side data, or null if not found
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 { Frame } from 'node-av';
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
- * // Check for closed captions
881
- * const ccData = frame.getSideData(AV_FRAME_DATA_A53_CC);
882
- * if (ccData) {
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 for the frame.
742
+ * Allocate new side data.
892
743
  *
893
- * Allocates a new side data buffer of the specified size.
894
- * Returns a Buffer that references the allocated memory.
895
- * Direct mapping to av_frame_new_side_data()
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 hdrBuffer = frame.newSideData(
759
+ * // Allocate and write HDR metadata
760
+ * const hdrData = frame.newSideData(
909
761
  * AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
910
- * 24 // Size of mastering display metadata structure
762
+ * 40
911
763
  * );
912
- * // Write HDR metadata to the buffer
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 the frame.
774
+ * Remove side data from frame.
775
+ *
776
+ * Removes specific type of side data.
920
777
  *
921
- * Removes and frees the specified type of side data from the frame.
922
- * Direct mapping to av_frame_remove_side_data()
778
+ * Direct mapping to av_frame_remove_side_data().
923
779
  *
924
- * @param type - The type of side data to remove
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 FFmpeg AVFrame pointer.
797
+ * Get the underlying native Frame object.
798
+ *
799
+ * @returns The native Frame binding object
940
800
  *
941
- * @internal For use by other wrapper classes
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
- * // ... use frame
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]();