node-av 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (175) hide show
  1. package/CHANGELOG.md +8 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +377 -0
  4. package/binding.gyp +78 -0
  5. package/dist/api/bitstream-filter.d.ts +246 -0
  6. package/dist/api/bitstream-filter.js +369 -0
  7. package/dist/api/bitstream-filter.js.map +1 -0
  8. package/dist/api/decoder.d.ts +257 -0
  9. package/dist/api/decoder.js +424 -0
  10. package/dist/api/decoder.js.map +1 -0
  11. package/dist/api/encoder.d.ts +298 -0
  12. package/dist/api/encoder.js +574 -0
  13. package/dist/api/encoder.js.map +1 -0
  14. package/dist/api/filter.d.ts +457 -0
  15. package/dist/api/filter.js +876 -0
  16. package/dist/api/filter.js.map +1 -0
  17. package/dist/api/hardware.d.ts +318 -0
  18. package/dist/api/hardware.js +558 -0
  19. package/dist/api/hardware.js.map +1 -0
  20. package/dist/api/index.d.ts +12 -0
  21. package/dist/api/index.js +20 -0
  22. package/dist/api/index.js.map +1 -0
  23. package/dist/api/io-stream.d.ts +109 -0
  24. package/dist/api/io-stream.js +124 -0
  25. package/dist/api/io-stream.js.map +1 -0
  26. package/dist/api/media-input.d.ts +295 -0
  27. package/dist/api/media-input.js +456 -0
  28. package/dist/api/media-input.js.map +1 -0
  29. package/dist/api/media-output.d.ts +274 -0
  30. package/dist/api/media-output.js +486 -0
  31. package/dist/api/media-output.js.map +1 -0
  32. package/dist/api/pipeline.d.ts +117 -0
  33. package/dist/api/pipeline.js +836 -0
  34. package/dist/api/pipeline.js.map +1 -0
  35. package/dist/api/types.d.ts +440 -0
  36. package/dist/api/types.js +2 -0
  37. package/dist/api/types.js.map +1 -0
  38. package/dist/api/utilities/audio-sample.d.ts +115 -0
  39. package/dist/api/utilities/audio-sample.js +110 -0
  40. package/dist/api/utilities/audio-sample.js.map +1 -0
  41. package/dist/api/utilities/channel-layout.d.ts +83 -0
  42. package/dist/api/utilities/channel-layout.js +87 -0
  43. package/dist/api/utilities/channel-layout.js.map +1 -0
  44. package/dist/api/utilities/image.d.ts +177 -0
  45. package/dist/api/utilities/image.js +183 -0
  46. package/dist/api/utilities/image.js.map +1 -0
  47. package/dist/api/utilities/index.d.ts +8 -0
  48. package/dist/api/utilities/index.js +17 -0
  49. package/dist/api/utilities/index.js.map +1 -0
  50. package/dist/api/utilities/media-type.d.ts +56 -0
  51. package/dist/api/utilities/media-type.js +60 -0
  52. package/dist/api/utilities/media-type.js.map +1 -0
  53. package/dist/api/utilities/pixel-format.d.ts +94 -0
  54. package/dist/api/utilities/pixel-format.js +102 -0
  55. package/dist/api/utilities/pixel-format.js.map +1 -0
  56. package/dist/api/utilities/sample-format.d.ts +132 -0
  57. package/dist/api/utilities/sample-format.js +144 -0
  58. package/dist/api/utilities/sample-format.js.map +1 -0
  59. package/dist/api/utilities/streaming.d.ts +104 -0
  60. package/dist/api/utilities/streaming.js +137 -0
  61. package/dist/api/utilities/streaming.js.map +1 -0
  62. package/dist/api/utilities/timestamp.d.ts +187 -0
  63. package/dist/api/utilities/timestamp.js +200 -0
  64. package/dist/api/utilities/timestamp.js.map +1 -0
  65. package/dist/api/utils.d.ts +61 -0
  66. package/dist/api/utils.js +330 -0
  67. package/dist/api/utils.js.map +1 -0
  68. package/dist/index.d.ts +2 -0
  69. package/dist/index.js +5 -0
  70. package/dist/index.js.map +1 -0
  71. package/dist/lib/audio-fifo.d.ts +339 -0
  72. package/dist/lib/audio-fifo.js +365 -0
  73. package/dist/lib/audio-fifo.js.map +1 -0
  74. package/dist/lib/binding.d.ts +192 -0
  75. package/dist/lib/binding.js +70 -0
  76. package/dist/lib/binding.js.map +1 -0
  77. package/dist/lib/bitstream-filter-context.d.ts +345 -0
  78. package/dist/lib/bitstream-filter-context.js +407 -0
  79. package/dist/lib/bitstream-filter-context.js.map +1 -0
  80. package/dist/lib/bitstream-filter.d.ts +124 -0
  81. package/dist/lib/bitstream-filter.js +138 -0
  82. package/dist/lib/bitstream-filter.js.map +1 -0
  83. package/dist/lib/channel-layouts.d.ts +51 -0
  84. package/dist/lib/channel-layouts.js +55 -0
  85. package/dist/lib/channel-layouts.js.map +1 -0
  86. package/dist/lib/codec-context.d.ts +763 -0
  87. package/dist/lib/codec-context.js +974 -0
  88. package/dist/lib/codec-context.js.map +1 -0
  89. package/dist/lib/codec-parameters.d.ts +362 -0
  90. package/dist/lib/codec-parameters.js +460 -0
  91. package/dist/lib/codec-parameters.js.map +1 -0
  92. package/dist/lib/codec-parser.d.ts +185 -0
  93. package/dist/lib/codec-parser.js +193 -0
  94. package/dist/lib/codec-parser.js.map +1 -0
  95. package/dist/lib/codec.d.ts +432 -0
  96. package/dist/lib/codec.js +492 -0
  97. package/dist/lib/codec.js.map +1 -0
  98. package/dist/lib/constants.d.ts +2037 -0
  99. package/dist/lib/constants.js +1659 -0
  100. package/dist/lib/constants.js.map +1 -0
  101. package/dist/lib/dictionary.d.ts +371 -0
  102. package/dist/lib/dictionary.js +406 -0
  103. package/dist/lib/dictionary.js.map +1 -0
  104. package/dist/lib/error.d.ts +216 -0
  105. package/dist/lib/error.js +254 -0
  106. package/dist/lib/error.js.map +1 -0
  107. package/dist/lib/filter-context.d.ts +445 -0
  108. package/dist/lib/filter-context.js +505 -0
  109. package/dist/lib/filter-context.js.map +1 -0
  110. package/dist/lib/filter-graph.d.ts +556 -0
  111. package/dist/lib/filter-graph.js +608 -0
  112. package/dist/lib/filter-graph.js.map +1 -0
  113. package/dist/lib/filter-inout.d.ts +205 -0
  114. package/dist/lib/filter-inout.js +264 -0
  115. package/dist/lib/filter-inout.js.map +1 -0
  116. package/dist/lib/filter.d.ts +231 -0
  117. package/dist/lib/filter.js +260 -0
  118. package/dist/lib/filter.js.map +1 -0
  119. package/dist/lib/format-context.d.ts +798 -0
  120. package/dist/lib/format-context.js +845 -0
  121. package/dist/lib/format-context.js.map +1 -0
  122. package/dist/lib/frame.d.ts +784 -0
  123. package/dist/lib/frame.js +933 -0
  124. package/dist/lib/frame.js.map +1 -0
  125. package/dist/lib/hardware-device-context.d.ts +407 -0
  126. package/dist/lib/hardware-device-context.js +429 -0
  127. package/dist/lib/hardware-device-context.js.map +1 -0
  128. package/dist/lib/hardware-frames-context.d.ts +374 -0
  129. package/dist/lib/hardware-frames-context.js +430 -0
  130. package/dist/lib/hardware-frames-context.js.map +1 -0
  131. package/dist/lib/index.d.ts +31 -0
  132. package/dist/lib/index.js +54 -0
  133. package/dist/lib/index.js.map +1 -0
  134. package/dist/lib/input-format.d.ts +216 -0
  135. package/dist/lib/input-format.js +246 -0
  136. package/dist/lib/input-format.js.map +1 -0
  137. package/dist/lib/io-context.d.ts +495 -0
  138. package/dist/lib/io-context.js +550 -0
  139. package/dist/lib/io-context.js.map +1 -0
  140. package/dist/lib/log.d.ts +201 -0
  141. package/dist/lib/log.js +219 -0
  142. package/dist/lib/log.js.map +1 -0
  143. package/dist/lib/native-types.d.ts +719 -0
  144. package/dist/lib/native-types.js +2 -0
  145. package/dist/lib/native-types.js.map +1 -0
  146. package/dist/lib/option.d.ts +589 -0
  147. package/dist/lib/option.js +853 -0
  148. package/dist/lib/option.js.map +1 -0
  149. package/dist/lib/output-format.d.ts +179 -0
  150. package/dist/lib/output-format.js +205 -0
  151. package/dist/lib/output-format.js.map +1 -0
  152. package/dist/lib/packet.d.ts +487 -0
  153. package/dist/lib/packet.js +558 -0
  154. package/dist/lib/packet.js.map +1 -0
  155. package/dist/lib/rational.d.ts +210 -0
  156. package/dist/lib/rational.js +233 -0
  157. package/dist/lib/rational.js.map +1 -0
  158. package/dist/lib/software-resample-context.d.ts +572 -0
  159. package/dist/lib/software-resample-context.js +610 -0
  160. package/dist/lib/software-resample-context.js.map +1 -0
  161. package/dist/lib/software-scale-context.d.ts +290 -0
  162. package/dist/lib/software-scale-context.js +308 -0
  163. package/dist/lib/software-scale-context.js.map +1 -0
  164. package/dist/lib/stream.d.ts +322 -0
  165. package/dist/lib/stream.js +408 -0
  166. package/dist/lib/stream.js.map +1 -0
  167. package/dist/lib/types.d.ts +59 -0
  168. package/dist/lib/types.js +8 -0
  169. package/dist/lib/types.js.map +1 -0
  170. package/dist/lib/utilities.d.ts +346 -0
  171. package/dist/lib/utilities.js +424 -0
  172. package/dist/lib/utilities.js.map +1 -0
  173. package/install/check.js +113 -0
  174. package/install/ffmpeg.js +163 -0
  175. package/package.json +107 -0
@@ -0,0 +1,784 @@
1
+ import { HardwareFramesContext } from './hardware-frames-context.js';
2
+ import { Rational } from './rational.js';
3
+ import type { AVChromaLocation, AVColorPrimaries, AVColorRange, AVColorSpace, AVColorTransferCharacteristic, AVFrameSideDataType, AVPictureType, AVPixelFormat, AVSampleFormat } from './constants.js';
4
+ import type { NativeFrame, NativeWrapper } from './native-types.js';
5
+ import type { ChannelLayout } from './types.js';
6
+ /**
7
+ * Frame for uncompressed audio/video data.
8
+ *
9
+ * Contains raw audio samples or video pixels after decoding or before encoding.
10
+ * Provides full control over allocation, configuration and lifecycle.
11
+ * Supports both planar and packed data layouts for audio and video.
12
+ *
13
+ * Direct mapping to FFmpeg's AVFrame.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Frame, FFmpegError } from 'node-av';
18
+ * import { AV_PIX_FMT_YUV420P, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
19
+ *
20
+ * // Create and allocate frame - full control
21
+ * const frame = new Frame();
22
+ * frame.alloc();
23
+ *
24
+ * // Configure video frame
25
+ * frame.format = AV_PIX_FMT_YUV420P;
26
+ * frame.width = 1920;
27
+ * frame.height = 1080;
28
+ * const videoRet = frame.getBuffer(); // Allocate buffers
29
+ * FFmpegError.throwIfError(videoRet, 'getBuffer');
30
+ *
31
+ * // Configure audio frame
32
+ * const audioFrame = new Frame();
33
+ * audioFrame.alloc();
34
+ * audioFrame.format = AV_SAMPLE_FMT_FLTP;
35
+ * audioFrame.sampleRate = 48000;
36
+ * audioFrame.nbSamples = 1024;
37
+ * audioFrame.channelLayout = { nbChannels: 2, order: 0, mask: 3n };
38
+ * const audioRet = audioFrame.getBuffer(); // Allocate buffers
39
+ * FFmpegError.throwIfError(audioRet, 'getBuffer');
40
+ *
41
+ * // Receive decoded data
42
+ * const ret = await codecContext.receiveFrame(frame);
43
+ * FFmpegError.throwIfError(ret, 'receiveFrame');
44
+ * console.log(`Frame PTS: ${frame.pts}`);
45
+ *
46
+ * // Cleanup
47
+ * frame.unref(); // Clear data but keep frame allocated
48
+ * frame.free(); // Free frame completely
49
+ * ```
50
+ *
51
+ * @see {@link CodecContext} For encoding/decoding frames
52
+ * @see {@link FilterContext} For filtering frames
53
+ */
54
+ export declare class Frame implements Disposable, NativeWrapper<NativeFrame> {
55
+ private native;
56
+ private _hwFramesCtx?;
57
+ /**
58
+ * Create a new frame.
59
+ *
60
+ * The frame is uninitialized - you must call alloc() before use.
61
+ * No FFmpeg resources are allocated until alloc() is called.
62
+ *
63
+ * Direct wrapper around AVFrame.
64
+ *
65
+ * @example
66
+ * ```typescript
67
+ * import { Frame } from 'node-av';
68
+ *
69
+ * const frame = new Frame();
70
+ * frame.alloc();
71
+ * // Frame is now ready for use
72
+ * ```
73
+ */
74
+ constructor();
75
+ /**
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
82
+ *
83
+ * Must be set before calling getBuffer() or allocBuffer().
84
+ */
85
+ get format(): AVPixelFormat | AVSampleFormat;
86
+ set format(value: AVPixelFormat | AVSampleFormat);
87
+ /**
88
+ * Width of the video frame in pixels.
89
+ *
90
+ * Direct mapping to AVFrame->width
91
+ *
92
+ * For video: MUST be set before calling getBuffer() or allocBuffer().
93
+ * For audio: unused (0).
94
+ */
95
+ get width(): number;
96
+ set width(value: number);
97
+ /**
98
+ * Height of the video frame in pixels.
99
+ *
100
+ * Direct mapping to AVFrame->height
101
+ *
102
+ * For video: MUST be set before calling getBuffer() or allocBuffer().
103
+ * For audio: unused (0).
104
+ */
105
+ get height(): number;
106
+ set height(value: number);
107
+ /**
108
+ * Number of audio samples (per channel) described by this frame.
109
+ *
110
+ * Direct mapping to AVFrame->nb_samples
111
+ *
112
+ * For audio: MUST be set before calling getBuffer() or allocBuffer().
113
+ * For video: unused (0).
114
+ */
115
+ get nbSamples(): number;
116
+ set nbSamples(value: number);
117
+ /**
118
+ * Presentation timestamp in time_base units.
119
+ *
120
+ * Time when frame should be shown to user.
121
+ *
122
+ * Direct mapping to AVFrame->pts
123
+ *
124
+ * Can be AV_NOPTS_VALUE if unknown.
125
+ */
126
+ get pts(): bigint;
127
+ set pts(value: bigint);
128
+ /**
129
+ * DTS copied from the AVPacket that triggered returning this frame.
130
+ *
131
+ * If frame threading isn't used, this is also the presentation time
132
+ * calculated from only AVPacket.dts values without pts values.
133
+ *
134
+ * Direct mapping to AVFrame->pkt_dts
135
+ */
136
+ get pktDts(): bigint;
137
+ set pktDts(value: bigint);
138
+ /**
139
+ * Best effort timestamp.
140
+ *
141
+ * Direct mapping to AVFrame->best_effort_timestamp (computed value)
142
+ *
143
+ * Attempts to provide the most accurate timestamp for the frame.
144
+ * Uses pts if available, otherwise falls back to pkt_dts.
145
+ */
146
+ get bestEffortTimestamp(): bigint;
147
+ set bestEffortTimestamp(value: bigint);
148
+ /**
149
+ * Time base for pts/dts timestamps.
150
+ *
151
+ * Direct mapping to AVFrame->time_base
152
+ *
153
+ * This is the fundamental unit of time (in seconds) in terms
154
+ * of which frame timestamps are represented.
155
+ */
156
+ get timeBase(): Rational;
157
+ set timeBase(value: Rational);
158
+ /**
159
+ * Whether this frame is a keyframe.
160
+ *
161
+ * Direct mapping to AVFrame->key_frame
162
+ *
163
+ * 1 -> keyframe, 0 -> not a keyframe.
164
+ * It is set to 1 for all frames in intra-only codecs.
165
+ * - encoding: Set by libavcodec.
166
+ * - decoding: Set by libavcodec.
167
+ */
168
+ get keyFrame(): number;
169
+ set keyFrame(value: number);
170
+ /**
171
+ * Picture type of the frame.
172
+ *
173
+ * Direct mapping to AVFrame->pict_type
174
+ *
175
+ * AV_PICTURE_TYPE_I for intra frames, AV_PICTURE_TYPE_P for predicted frames,
176
+ * AV_PICTURE_TYPE_B for bi-directionally predicted frames, etc.
177
+ * - encoding: Set by libavcodec. for coded_picture (and set by user for input).
178
+ * - decoding: Set by libavcodec.
179
+ */
180
+ get pictType(): AVPictureType;
181
+ set pictType(value: AVPictureType);
182
+ /**
183
+ * Sample aspect ratio for the video frame.
184
+ *
185
+ * Direct mapping to AVFrame->sample_aspect_ratio
186
+ *
187
+ * 0/1 if unknown/unspecified.
188
+ * This is the aspect ratio of a single pixel (width/height).
189
+ * For anamorphic video, this differs from the display aspect ratio.
190
+ */
191
+ get sampleAspectRatio(): Rational;
192
+ set sampleAspectRatio(value: Rational);
193
+ /**
194
+ * Sample rate of the audio data.
195
+ *
196
+ * Direct mapping to AVFrame->sample_rate
197
+ *
198
+ * In samples per second.
199
+ * - encoding: MUST be set by user.
200
+ * - decoding: MAY be set by libavcodec.
201
+ */
202
+ get sampleRate(): number;
203
+ set sampleRate(value: number);
204
+ /**
205
+ * Channel layout of the audio data.
206
+ *
207
+ * Direct mapping to AVFrame->ch_layout
208
+ *
209
+ * Describes the number and order of audio channels.
210
+ * Must be set before calling getBuffer() for audio frames.
211
+ */
212
+ get channelLayout(): ChannelLayout;
213
+ set channelLayout(value: ChannelLayout);
214
+ /**
215
+ * Number of audio channels.
216
+ *
217
+ * Direct mapping to AVFrame->channels
218
+ *
219
+ * Derived from channel layout.
220
+ * @readonly
221
+ */
222
+ get channels(): number;
223
+ /**
224
+ * Line size (stride) for each plane.
225
+ *
226
+ * Direct mapping to AVFrame->linesize
227
+ *
228
+ * For video, the size in bytes of each picture line.
229
+ * For audio, the size in bytes of each plane.
230
+ *
231
+ * For audio, only linesize[0] may be set. For planar audio, each channel
232
+ * plane must be the same size.
233
+ *
234
+ * For video the linesizes should be multiples of the CPUs alignment preference,
235
+ * this is 16 or 32 for modern desktop CPUs.
236
+ * @readonly
237
+ */
238
+ get linesize(): number[];
239
+ /**
240
+ * MPEG vs JPEG YUV color range.
241
+ *
242
+ * Direct mapping to AVFrame->color_range
243
+ *
244
+ * AVCOL_RANGE_MPEG (limited/tv/16-235), AVCOL_RANGE_JPEG (full/pc/0-255)
245
+ * - encoding: Set by user
246
+ * - decoding: Set by libavcodec
247
+ */
248
+ get colorRange(): AVColorRange;
249
+ set colorRange(value: AVColorRange);
250
+ /**
251
+ * Chromaticity coordinates of the source primaries.
252
+ *
253
+ * Direct mapping to AVFrame->color_primaries
254
+ *
255
+ * AVCOL_PRI_BT709, AVCOL_PRI_BT2020, etc.
256
+ * - encoding: Set by user
257
+ * - decoding: Set by libavcodec
258
+ */
259
+ get colorPrimaries(): AVColorPrimaries;
260
+ set colorPrimaries(value: AVColorPrimaries);
261
+ /**
262
+ * Color Transfer Characteristic.
263
+ *
264
+ * Direct mapping to AVFrame->color_trc
265
+ *
266
+ * AVCOL_TRC_BT709, AVCOL_TRC_SMPTE2084 (PQ), AVCOL_TRC_ARIB_STD_B67 (HLG), etc.
267
+ * - encoding: Set by user
268
+ * - decoding: Set by libavcodec
269
+ */
270
+ get colorTrc(): AVColorTransferCharacteristic;
271
+ set colorTrc(value: AVColorTransferCharacteristic);
272
+ /**
273
+ * YUV colorspace type.
274
+ *
275
+ * Direct mapping to AVFrame->colorspace
276
+ *
277
+ * AVCOL_SPC_BT709, AVCOL_SPC_BT2020_NCL, etc.
278
+ * - encoding: Set by user
279
+ * - decoding: Set by libavcodec
280
+ */
281
+ get colorSpace(): AVColorSpace;
282
+ set colorSpace(value: AVColorSpace);
283
+ /**
284
+ * Location of chroma samples.
285
+ *
286
+ * Direct mapping to AVFrame->chroma_location
287
+ *
288
+ * AVCHROMA_LOC_LEFT (MPEG-1/2/4, H.264 default), AVCHROMA_LOC_CENTER (MPEG-2), etc.
289
+ * - encoding: Set by user
290
+ * - decoding: Set by libavcodec
291
+ */
292
+ get chromaLocation(): AVChromaLocation;
293
+ set chromaLocation(value: AVChromaLocation);
294
+ /**
295
+ * Pointers to the data planes/channels.
296
+ *
297
+ * Direct mapping to AVFrame->data
298
+ *
299
+ * For video, this is an array of pointers to picture planes.
300
+ * For packed audio, this is a single pointer to all audio data.
301
+ * For planar audio, each channel has a separate data pointer.
302
+ *
303
+ * AVFrame.data pointers must point to the first element of an AVFrame.buf array.
304
+ * @readonly
305
+ */
306
+ get data(): Buffer[] | null;
307
+ /**
308
+ * Pointers to the data planes/channels for frames with more than 8 channels.
309
+ *
310
+ * Direct mapping to AVFrame->extended_data
311
+ *
312
+ * For audio, if the number of channels is greater than 8, this must be used
313
+ * to access channels beyond the first 8. Otherwise, data[] should be used.
314
+ * @readonly
315
+ */
316
+ get extendedData(): Buffer[] | null;
317
+ /**
318
+ * Check if the frame data is writable.
319
+ *
320
+ * Direct mapping to av_frame_is_writable()
321
+ *
322
+ * A frame is writable if all its underlying buffers are writable and there's
323
+ * only one reference to each buffer. Use makeWritable() to ensure writability.
324
+ * @readonly
325
+ */
326
+ get isWritable(): boolean;
327
+ /**
328
+ * Hardware frames context.
329
+ *
330
+ * Direct mapping to AVFrame->hw_frames_ctx
331
+ *
332
+ * For hwaccel-format frames, this should be a reference to the
333
+ * AVHWFramesContext describing the frame.
334
+ */
335
+ get hwFramesCtx(): HardwareFramesContext | null;
336
+ set hwFramesCtx(value: HardwareFramesContext | null);
337
+ /**
338
+ * Allocate an AVFrame and set its fields to default values.
339
+ *
340
+ * Allocates the AVFrame structure and initializes all fields to default values.
341
+ * This only allocates the frame structure itself, not the data buffers.
342
+ *
343
+ * Direct mapping to av_frame_alloc()
344
+ *
345
+ * @throws {Error} Memory allocation failure (ENOMEM)
346
+ *
347
+ * @example
348
+ * ```typescript
349
+ * import { Frame } from 'node-av';
350
+ *
351
+ * const frame = new Frame();
352
+ * frame.alloc();
353
+ * // Frame structure is now allocated
354
+ * // Still need to allocate data buffers with getBuffer()
355
+ * ```
356
+ *
357
+ * @see {@link getBuffer} To allocate data buffers
358
+ * @see {@link free} To free the frame
359
+ */
360
+ alloc(): void;
361
+ /**
362
+ * Free the frame and any dynamically allocated objects in it.
363
+ *
364
+ * Frees the frame structure and all associated data buffers.
365
+ * If the frame is reference counted, it will be unreferenced first.
366
+ *
367
+ * Direct mapping to av_frame_free()
368
+ *
369
+ * @note
370
+ * Calling this multiple times is safe, because we check the freed state
371
+ *
372
+ * @example
373
+ * ```typescript
374
+ * import { Frame } from 'node-av';
375
+ *
376
+ * frame.free();
377
+ * // frame is now invalid and should not be used
378
+ * ```
379
+ *
380
+ * @see {@link unref} To clear data but keep frame allocated
381
+ */
382
+ free(): void;
383
+ /**
384
+ * Set up a new reference to the data described by the source frame.
385
+ *
386
+ * Creates a reference to the source frame's data buffers.
387
+ * Both frames will share the same data through reference counting.
388
+ * This function does not copy side data.
389
+ *
390
+ * Direct mapping to av_frame_ref()
391
+ *
392
+ * @param src - Source frame to reference
393
+ *
394
+ * @returns 0 on success, negative AVERROR on error:
395
+ * - 0: Success (frame now references src data)
396
+ * - AVERROR(ENOMEM): Memory allocation failure
397
+ * - AVERROR(EINVAL): Invalid parameters (null frame)
398
+ * - <0: Other errors
399
+ *
400
+ * @example
401
+ * ```typescript
402
+ * import { Frame, FFmpegError } from 'node-av';
403
+ *
404
+ * const ret = frame.ref(sourceFrame);
405
+ * FFmpegError.throwIfError(ret, 'frame.ref');
406
+ * // frame now references the same data as sourceFrame
407
+ * ```
408
+ *
409
+ * @see {@link unref} To remove references
410
+ * @see {@link clone} To create a new frame with same data
411
+ */
412
+ ref(src: Frame): number;
413
+ /**
414
+ * Unreference all the buffers referenced by frame and reset the frame fields.
415
+ *
416
+ * Clears all data from the frame but keeps the frame structure allocated.
417
+ * The frame can be reused for the next decode/encode operation.
418
+ *
419
+ * Direct mapping to av_frame_unref()
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * import { Frame } from 'node-av';
424
+ *
425
+ * frame.unref();
426
+ * // Frame is now empty but still allocated
427
+ * // Can be reused for next decode/encode
428
+ * ```
429
+ *
430
+ * @see {@link free} To completely free the frame
431
+ */
432
+ unref(): void;
433
+ /**
434
+ * Create a new frame that references the same data as this frame.
435
+ *
436
+ * Creates a new frame and sets it up as a reference to this frame's data.
437
+ * This is a shortcut for av_frame_alloc() + av_frame_ref().
438
+ *
439
+ * Direct mapping to av_frame_clone()
440
+ *
441
+ * @returns New frame referencing the same data, or null on error:
442
+ * - Frame object: Success (new frame references this frame's data)
443
+ * - null: Memory allocation failure (ENOMEM)
444
+ *
445
+ * @example
446
+ * ```typescript
447
+ * import { Frame } from 'node-av';
448
+ *
449
+ * const clonedFrame = frame.clone();
450
+ * if (!clonedFrame) {
451
+ * throw new Error('Failed to clone frame: Out of memory');
452
+ * }
453
+ * // clonedFrame references the same data as frame
454
+ * // Both frames must be freed independently
455
+ * ```
456
+ *
457
+ * @see {@link ref} To reference into existing frame
458
+ */
459
+ clone(): Frame | null;
460
+ /**
461
+ * Allocate new buffer(s) for audio or video data.
462
+ *
463
+ * Allocates data buffers for the frame based on its parameters.
464
+ * Frame parameters must be set before calling this function.
465
+ *
466
+ * Direct mapping to av_frame_get_buffer()
467
+ *
468
+ * @param align - Required buffer size alignment. 0 for automatic.
469
+ *
470
+ * @returns 0 on success, negative AVERROR on error:
471
+ * - 0: Success (buffers allocated)
472
+ * - AVERROR(EINVAL): Invalid frame parameters (format/size not set)
473
+ * - AVERROR(ENOMEM): Memory allocation failure
474
+ * - <0: Other errors
475
+ *
476
+ * @example
477
+ * ```typescript
478
+ * import { Frame, FFmpegError, AV_PIX_FMT_YUV420P } from 'node-av';
479
+ *
480
+ * // Video frame
481
+ * frame.format = AV_PIX_FMT_YUV420P;
482
+ * frame.width = 1920;
483
+ * frame.height = 1080;
484
+ * const ret = frame.getBuffer(0);
485
+ * FFmpegError.throwIfError(ret, 'getBuffer');
486
+ * // Frame data buffers are now allocated
487
+ * ```
488
+ *
489
+ * @see {@link allocBuffer} Convenience wrapper with default alignment
490
+ * @see {@link makeWritable} Ensure buffer is writable
491
+ *
492
+ * Required fields before calling:
493
+ * - format (pixel format for video, sample format for audio)
494
+ * - width and height for video
495
+ * - nb_samples and channel_layout for audio
496
+ */
497
+ getBuffer(align?: number): number;
498
+ /**
499
+ * Allocate buffer(s) for frame according to its parameters.
500
+ *
501
+ * Convenience wrapper for getBuffer() with default alignment.
502
+ * Frame parameters must be set before calling.
503
+ *
504
+ * Direct mapping to av_frame_get_buffer() with align=0
505
+ *
506
+ * @returns 0 on success, negative AVERROR on error:
507
+ * - 0: Success (buffers allocated)
508
+ * - AVERROR(EINVAL): Invalid frame parameters
509
+ * - AVERROR(ENOMEM): Memory allocation failure
510
+ * - <0: Other errors
511
+ *
512
+ * @example
513
+ * ```typescript
514
+ * import { Frame, FFmpegError } from 'node-av';
515
+ *
516
+ * const ret = frame.allocBuffer();
517
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
518
+ * // Frame data buffers are now allocated
519
+ * ```
520
+ *
521
+ * @see {@link getBuffer} With custom alignment
522
+ */
523
+ allocBuffer(): number;
524
+ /**
525
+ * Ensure that the frame data is writable.
526
+ *
527
+ * Makes a private copy of the frame data if it's currently shared.
528
+ * Does nothing if frame is already writable.
529
+ *
530
+ * Direct mapping to av_frame_make_writable()
531
+ *
532
+ * @returns 0 on success, negative AVERROR on error:
533
+ * - 0: Success (frame is now writable)
534
+ * - AVERROR(ENOMEM): Memory allocation failure
535
+ * - AVERROR(EINVAL): Invalid parameters
536
+ * - <0: Other errors
537
+ *
538
+ * @example
539
+ * ```typescript
540
+ * import { Frame, FFmpegError } from 'node-av';
541
+ *
542
+ * if (!frame.isWritable) {
543
+ * const ret = frame.makeWritable();
544
+ * FFmpegError.throwIfError(ret, 'makeWritable');
545
+ * }
546
+ * // Frame data can now be modified safely
547
+ * ```
548
+ *
549
+ * @see {@link isWritable} Check if writable
550
+ */
551
+ makeWritable(): number;
552
+ /**
553
+ * Copy only "metadata" fields from src to this frame.
554
+ *
555
+ * Copies all frame properties except the actual data buffers.
556
+ * This includes timestamps, format, dimensions, side data, etc.
557
+ *
558
+ * Direct mapping to av_frame_copy_props()
559
+ *
560
+ * @param src - Source frame to copy properties from
561
+ *
562
+ * @returns >=0 on success, negative AVERROR on error:
563
+ * - >=0: Success (properties copied)
564
+ * - AVERROR(ENOMEM): Memory allocation failure
565
+ * - <0: Other errors
566
+ *
567
+ * @example
568
+ * ```typescript
569
+ * import { Frame, FFmpegError } from 'node-av';
570
+ *
571
+ * const ret = dstFrame.copyProps(srcFrame);
572
+ * FFmpegError.throwIfError(ret, 'copyProps');
573
+ * // dstFrame now has same properties as srcFrame (but not data)
574
+ * ```
575
+ *
576
+ * @see {@link copy} To copy data as well
577
+ */
578
+ copyProps(src: Frame): number;
579
+ /**
580
+ * Copy the frame data from src to this frame.
581
+ *
582
+ * Copies the actual data buffers from source to destination.
583
+ * Destination must be pre-allocated with same parameters.
584
+ *
585
+ * Direct mapping to av_frame_copy()
586
+ *
587
+ * @param src - Source frame to copy data from
588
+ *
589
+ * @returns >=0 on success, negative AVERROR on error:
590
+ * - >=0: Success (data copied)
591
+ * - AVERROR(EINVAL): Frames have different parameters (format, size, etc.)
592
+ * - <0: Other errors
593
+ *
594
+ * @example
595
+ * ```typescript
596
+ * import { Frame, FFmpegError } from 'node-av';
597
+ *
598
+ * // Destination must be allocated with same parameters
599
+ * dstFrame.format = srcFrame.format;
600
+ * dstFrame.width = srcFrame.width;
601
+ * dstFrame.height = srcFrame.height;
602
+ * const allocRet = dstFrame.allocBuffer();
603
+ * FFmpegError.throwIfError(allocRet, 'allocBuffer');
604
+ *
605
+ * const ret = dstFrame.copy(srcFrame);
606
+ * FFmpegError.throwIfError(ret, 'copy');
607
+ * // Data has been copied to dstFrame
608
+ * ```
609
+ *
610
+ * @see {@link copyProps} To copy metadata only
611
+ */
612
+ copy(src: Frame): number;
613
+ /**
614
+ * Transfer data to or from hardware surfaces.
615
+ *
616
+ * Transfers frame data between hardware (GPU) and software (CPU) memory.
617
+ * Can be used for both upload and download operations.
618
+ *
619
+ * Direct mapping to av_hwframe_transfer_data()
620
+ *
621
+ * @param dst - Destination frame
622
+ * @param flags - Transfer flags (currently unused, should be set to zero)
623
+ *
624
+ * @returns Promise resolving to 0 on success, negative AVERROR on error:
625
+ * - 0: Success (data transferred)
626
+ * - AVERROR(ENOSYS): Operation not supported
627
+ * - AVERROR(EINVAL): Invalid parameters
628
+ * - AVERROR(ENOMEM): Memory allocation failure
629
+ * - <0: Other hardware-specific errors
630
+ *
631
+ * @example
632
+ * ```typescript
633
+ * import { Frame, FFmpegError } from 'node-av';
634
+ *
635
+ * // Transfer from hardware to software frame
636
+ * const swFrame = new Frame();
637
+ * swFrame.alloc();
638
+ * const ret = await hwFrame.hwframeTransferData(swFrame, 0);
639
+ * FFmpegError.throwIfError(ret, 'hwframeTransferData');
640
+ * // Data is now in CPU memory
641
+ * ```
642
+ *
643
+ * @see {@link isHwFrame} Check if frame is hardware frame
644
+ */
645
+ hwframeTransferData(dst: Frame, flags?: number): Promise<number>;
646
+ /**
647
+ * Check if this is a hardware frame.
648
+ *
649
+ * A frame is considered a hardware frame if it has a hw_frames_ctx set.
650
+ *
651
+ * Direct check of AVFrame->hw_frames_ctx
652
+ *
653
+ * @returns True if this is a hardware frame, false otherwise
654
+ *
655
+ * @example
656
+ * ```typescript
657
+ * import { Frame } from 'node-av';
658
+ *
659
+ * if (frame.isHwFrame()) {
660
+ * console.log('Frame is in GPU memory');
661
+ * } else {
662
+ * console.log('Frame is in CPU memory');
663
+ * }
664
+ * ```
665
+ *
666
+ * @see {@link hwframeTransferData} To transfer between CPU and GPU
667
+ */
668
+ isHwFrame(): boolean;
669
+ /**
670
+ * Check if this is a software frame.
671
+ *
672
+ * A frame is considered a software frame if it doesn't have hw_frames_ctx
673
+ * but has actual data pointers.
674
+ *
675
+ * Direct check of AVFrame->data[0] && !AVFrame->hw_frames_ctx
676
+ *
677
+ * @returns True if this is a software frame, false otherwise
678
+ *
679
+ * @example
680
+ * ```typescript
681
+ * import { Frame } from 'node-av';
682
+ *
683
+ * if (frame.isSwFrame()) {
684
+ * console.log('Frame is in CPU memory');
685
+ * // Safe to access frame.data
686
+ * }
687
+ * ```
688
+ *
689
+ * @see {@link isHwFrame} To check for hardware frames
690
+ */
691
+ isSwFrame(): boolean;
692
+ /**
693
+ * Get side data from the frame.
694
+ *
695
+ * Direct mapping to av_frame_get_side_data()
696
+ *
697
+ * @param type - The type of side data to retrieve
698
+ * @returns Buffer containing the side data, or null if not found
699
+ *
700
+ * @example
701
+ * ```typescript
702
+ * import { Frame } from 'node-av';
703
+ * import { AV_FRAME_DATA_A53_CC } from 'node-av/constants';
704
+ *
705
+ * // Check for closed captions
706
+ * const ccData = frame.getSideData(AV_FRAME_DATA_A53_CC);
707
+ * if (ccData) {
708
+ * console.log('Found closed caption data:', ccData.length, 'bytes');
709
+ * }
710
+ * ```
711
+ */
712
+ getSideData(type: AVFrameSideDataType): Buffer | null;
713
+ /**
714
+ * Allocate new side data for the frame.
715
+ *
716
+ * Allocates a new side data buffer of the specified size.
717
+ * Returns a Buffer that references the allocated memory.
718
+ * Direct mapping to av_frame_new_side_data()
719
+ *
720
+ * @param type - The type of side data to allocate
721
+ * @param size - Size of the side data buffer to allocate
722
+ * @returns Buffer referencing the allocated side data
723
+ * @throws {Error} If allocation fails
724
+ *
725
+ * @example
726
+ * ```typescript
727
+ * import { Frame } from 'node-av';
728
+ * import { AV_FRAME_DATA_MASTERING_DISPLAY_METADATA } from 'node-av/constants';
729
+ *
730
+ * // Allocate HDR metadata
731
+ * const hdrBuffer = frame.newSideData(
732
+ * AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
733
+ * 24 // Size of mastering display metadata structure
734
+ * );
735
+ * // Write HDR metadata to the buffer
736
+ * ```
737
+ */
738
+ newSideData(type: AVFrameSideDataType, size: number): Buffer;
739
+ /**
740
+ * Remove side data from the frame.
741
+ *
742
+ * Removes and frees the specified type of side data from the frame.
743
+ * Direct mapping to av_frame_remove_side_data()
744
+ *
745
+ * @param type - The type of side data to remove
746
+ *
747
+ * @example
748
+ * ```typescript
749
+ * import { Frame } from 'node-av';
750
+ * import { AV_FRAME_DATA_MOTION_VECTORS } from 'node-av/constants';
751
+ *
752
+ * // Remove motion vectors data
753
+ * frame.removeSideData(AV_FRAME_DATA_MOTION_VECTORS);
754
+ * ```
755
+ */
756
+ removeSideData(type: AVFrameSideDataType): void;
757
+ /**
758
+ * Get the native FFmpeg AVFrame pointer.
759
+ *
760
+ * @internal For use by other wrapper classes
761
+ * @returns The underlying native frame object
762
+ */
763
+ getNative(): NativeFrame;
764
+ /**
765
+ * Dispose of the frame.
766
+ *
767
+ * Implements the Disposable interface for automatic cleanup.
768
+ * Equivalent to calling free().
769
+ *
770
+ * @example
771
+ * ```typescript
772
+ * import { Frame } from 'node-av';
773
+ *
774
+ * {
775
+ * using frame = new Frame();
776
+ * frame.alloc();
777
+ * // ... use frame
778
+ * } // Automatically freed when leaving scope
779
+ * ```
780
+ *
781
+ * @see {@link free} For manual cleanup
782
+ */
783
+ [Symbol.dispose](): void;
784
+ }