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,933 @@
1
+ import { bindings } from './binding.js';
2
+ import { HardwareFramesContext } from './hardware-frames-context.js';
3
+ import { Rational } from './rational.js';
4
+ /**
5
+ * Frame for uncompressed audio/video data.
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.
10
+ *
11
+ * Direct mapping to FFmpeg's AVFrame.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { Frame, FFmpegError } from 'node-av';
16
+ * import { AV_PIX_FMT_YUV420P, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
17
+ *
18
+ * // Create and allocate frame - full control
19
+ * const frame = new Frame();
20
+ * frame.alloc();
21
+ *
22
+ * // Configure video frame
23
+ * frame.format = AV_PIX_FMT_YUV420P;
24
+ * frame.width = 1920;
25
+ * frame.height = 1080;
26
+ * const videoRet = frame.getBuffer(); // Allocate buffers
27
+ * FFmpegError.throwIfError(videoRet, 'getBuffer');
28
+ *
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}`);
43
+ *
44
+ * // Cleanup
45
+ * frame.unref(); // Clear data but keep frame allocated
46
+ * frame.free(); // Free frame completely
47
+ * ```
48
+ *
49
+ * @see {@link CodecContext} For encoding/decoding frames
50
+ * @see {@link FilterContext} For filtering frames
51
+ */
52
+ export class Frame {
53
+ native;
54
+ _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
+ constructor() {
73
+ this.native = new bindings.Frame();
74
+ }
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() {
86
+ return this.native.format;
87
+ }
88
+ set format(value) {
89
+ this.native.format = value;
90
+ }
91
+ /**
92
+ * Width of the video frame in pixels.
93
+ *
94
+ * Direct mapping to AVFrame->width
95
+ *
96
+ * For video: MUST be set before calling getBuffer() or allocBuffer().
97
+ * For audio: unused (0).
98
+ */
99
+ get width() {
100
+ return this.native.width;
101
+ }
102
+ set width(value) {
103
+ this.native.width = value;
104
+ }
105
+ /**
106
+ * Height of the video frame in pixels.
107
+ *
108
+ * Direct mapping to AVFrame->height
109
+ *
110
+ * For video: MUST be set before calling getBuffer() or allocBuffer().
111
+ * For audio: unused (0).
112
+ */
113
+ get height() {
114
+ return this.native.height;
115
+ }
116
+ set height(value) {
117
+ this.native.height = value;
118
+ }
119
+ /**
120
+ * Number of audio samples (per channel) described by this frame.
121
+ *
122
+ * Direct mapping to AVFrame->nb_samples
123
+ *
124
+ * For audio: MUST be set before calling getBuffer() or allocBuffer().
125
+ * For video: unused (0).
126
+ */
127
+ get nbSamples() {
128
+ return this.native.nbSamples;
129
+ }
130
+ set nbSamples(value) {
131
+ this.native.nbSamples = value;
132
+ }
133
+ /**
134
+ * Presentation timestamp in time_base units.
135
+ *
136
+ * Time when frame should be shown to user.
137
+ *
138
+ * Direct mapping to AVFrame->pts
139
+ *
140
+ * Can be AV_NOPTS_VALUE if unknown.
141
+ */
142
+ get pts() {
143
+ return this.native.pts;
144
+ }
145
+ set pts(value) {
146
+ this.native.pts = value;
147
+ }
148
+ /**
149
+ * DTS copied from the AVPacket that triggered returning this frame.
150
+ *
151
+ * If frame threading isn't used, this is also the presentation time
152
+ * calculated from only AVPacket.dts values without pts values.
153
+ *
154
+ * Direct mapping to AVFrame->pkt_dts
155
+ */
156
+ get pktDts() {
157
+ return this.native.pktDts;
158
+ }
159
+ set pktDts(value) {
160
+ this.native.pktDts = value;
161
+ }
162
+ /**
163
+ * Best effort timestamp.
164
+ *
165
+ * Direct mapping to AVFrame->best_effort_timestamp (computed value)
166
+ *
167
+ * Attempts to provide the most accurate timestamp for the frame.
168
+ * Uses pts if available, otherwise falls back to pkt_dts.
169
+ */
170
+ get bestEffortTimestamp() {
171
+ return this.native.bestEffortTimestamp;
172
+ }
173
+ set bestEffortTimestamp(value) {
174
+ this.native.bestEffortTimestamp = value;
175
+ }
176
+ /**
177
+ * Time base for pts/dts timestamps.
178
+ *
179
+ * Direct mapping to AVFrame->time_base
180
+ *
181
+ * This is the fundamental unit of time (in seconds) in terms
182
+ * of which frame timestamps are represented.
183
+ */
184
+ get timeBase() {
185
+ const tb = this.native.timeBase;
186
+ return new Rational(tb.num, tb.den);
187
+ }
188
+ set timeBase(value) {
189
+ this.native.timeBase = { num: value.num, den: value.den };
190
+ }
191
+ /**
192
+ * Whether this frame is a keyframe.
193
+ *
194
+ * Direct mapping to AVFrame->key_frame
195
+ *
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.
200
+ */
201
+ get keyFrame() {
202
+ return this.native.keyFrame;
203
+ }
204
+ set keyFrame(value) {
205
+ this.native.keyFrame = value;
206
+ }
207
+ /**
208
+ * Picture type of the frame.
209
+ *
210
+ * Direct mapping to AVFrame->pict_type
211
+ *
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.
216
+ */
217
+ get pictType() {
218
+ return this.native.pictType;
219
+ }
220
+ set pictType(value) {
221
+ this.native.pictType = value;
222
+ }
223
+ /**
224
+ * Sample aspect ratio for the video frame.
225
+ *
226
+ * Direct mapping to AVFrame->sample_aspect_ratio
227
+ *
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.
231
+ */
232
+ get sampleAspectRatio() {
233
+ const sar = this.native.sampleAspectRatio;
234
+ return new Rational(sar.num || 0, sar.den || 1);
235
+ }
236
+ set sampleAspectRatio(value) {
237
+ this.native.sampleAspectRatio = { num: value.num, den: value.den };
238
+ }
239
+ /**
240
+ * Sample rate of the audio data.
241
+ *
242
+ * Direct mapping to AVFrame->sample_rate
243
+ *
244
+ * In samples per second.
245
+ * - encoding: MUST be set by user.
246
+ * - decoding: MAY be set by libavcodec.
247
+ */
248
+ get sampleRate() {
249
+ return this.native.sampleRate;
250
+ }
251
+ set sampleRate(value) {
252
+ this.native.sampleRate = value;
253
+ }
254
+ /**
255
+ * Channel layout of the audio data.
256
+ *
257
+ * Direct mapping to AVFrame->ch_layout
258
+ *
259
+ * Describes the number and order of audio channels.
260
+ * Must be set before calling getBuffer() for audio frames.
261
+ */
262
+ get channelLayout() {
263
+ return this.native.channelLayout;
264
+ }
265
+ set channelLayout(value) {
266
+ this.native.channelLayout = value;
267
+ }
268
+ /**
269
+ * Number of audio channels.
270
+ *
271
+ * Direct mapping to AVFrame->channels
272
+ *
273
+ * Derived from channel layout.
274
+ * @readonly
275
+ */
276
+ get channels() {
277
+ return this.native.channels;
278
+ }
279
+ /**
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.
286
+ *
287
+ * For audio, only linesize[0] may be set. For planar audio, each channel
288
+ * plane must be the same size.
289
+ *
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
293
+ */
294
+ get linesize() {
295
+ return this.native.linesize;
296
+ }
297
+ /**
298
+ * MPEG vs JPEG YUV color range.
299
+ *
300
+ * Direct mapping to AVFrame->color_range
301
+ *
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
305
+ */
306
+ get colorRange() {
307
+ return this.native.colorRange;
308
+ }
309
+ set colorRange(value) {
310
+ this.native.colorRange = value;
311
+ }
312
+ /**
313
+ * Chromaticity coordinates of the source primaries.
314
+ *
315
+ * Direct mapping to AVFrame->color_primaries
316
+ *
317
+ * AVCOL_PRI_BT709, AVCOL_PRI_BT2020, etc.
318
+ * - encoding: Set by user
319
+ * - decoding: Set by libavcodec
320
+ */
321
+ get colorPrimaries() {
322
+ return this.native.colorPrimaries;
323
+ }
324
+ set colorPrimaries(value) {
325
+ this.native.colorPrimaries = value;
326
+ }
327
+ /**
328
+ * Color Transfer Characteristic.
329
+ *
330
+ * Direct mapping to AVFrame->color_trc
331
+ *
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
335
+ */
336
+ get colorTrc() {
337
+ return this.native.colorTrc;
338
+ }
339
+ set colorTrc(value) {
340
+ this.native.colorTrc = value;
341
+ }
342
+ /**
343
+ * YUV colorspace type.
344
+ *
345
+ * Direct mapping to AVFrame->colorspace
346
+ *
347
+ * AVCOL_SPC_BT709, AVCOL_SPC_BT2020_NCL, etc.
348
+ * - encoding: Set by user
349
+ * - decoding: Set by libavcodec
350
+ */
351
+ get colorSpace() {
352
+ return this.native.colorSpace;
353
+ }
354
+ set colorSpace(value) {
355
+ this.native.colorSpace = value;
356
+ }
357
+ /**
358
+ * Location of chroma samples.
359
+ *
360
+ * Direct mapping to AVFrame->chroma_location
361
+ *
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
365
+ */
366
+ get chromaLocation() {
367
+ return this.native.chromaLocation;
368
+ }
369
+ set chromaLocation(value) {
370
+ this.native.chromaLocation = value;
371
+ }
372
+ /**
373
+ * Pointers to the data planes/channels.
374
+ *
375
+ * Direct mapping to AVFrame->data
376
+ *
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
383
+ */
384
+ get data() {
385
+ return this.native.data;
386
+ }
387
+ /**
388
+ * Pointers to the data planes/channels for frames with more than 8 channels.
389
+ *
390
+ * Direct mapping to AVFrame->extended_data
391
+ *
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
395
+ */
396
+ get extendedData() {
397
+ return this.native.extendedData;
398
+ }
399
+ /**
400
+ * Check if the frame data is writable.
401
+ *
402
+ * Direct mapping to av_frame_is_writable()
403
+ *
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
407
+ */
408
+ get isWritable() {
409
+ return this.native.isWritable;
410
+ }
411
+ // Hardware Acceleration
412
+ /**
413
+ * Hardware frames context.
414
+ *
415
+ * Direct mapping to AVFrame->hw_frames_ctx
416
+ *
417
+ * For hwaccel-format frames, this should be a reference to the
418
+ * AVHWFramesContext describing the frame.
419
+ */
420
+ get hwFramesCtx() {
421
+ // Return cached wrapper if we already have one
422
+ if (this._hwFramesCtx !== undefined) {
423
+ return this._hwFramesCtx;
424
+ }
425
+ const native = this.native.hwFramesCtx;
426
+ if (!native) {
427
+ this._hwFramesCtx = null;
428
+ return null;
429
+ }
430
+ // Create and cache the wrapper
431
+ const frames = Object.create(HardwareFramesContext.prototype);
432
+ frames.native = native;
433
+ this._hwFramesCtx = frames;
434
+ return frames;
435
+ }
436
+ set hwFramesCtx(value) {
437
+ this.native.hwFramesCtx = value?.getNative() ?? null;
438
+ // Clear the cache as the underlying context has changed
439
+ this._hwFramesCtx = undefined;
440
+ }
441
+ /**
442
+ * Allocate an AVFrame and set its fields to default values.
443
+ *
444
+ * Allocates the AVFrame structure and initializes all fields to default values.
445
+ * This only allocates the frame structure itself, not the data buffers.
446
+ *
447
+ * Direct mapping to av_frame_alloc()
448
+ *
449
+ * @throws {Error} Memory allocation failure (ENOMEM)
450
+ *
451
+ * @example
452
+ * ```typescript
453
+ * import { Frame } from 'node-av';
454
+ *
455
+ * const frame = new Frame();
456
+ * frame.alloc();
457
+ * // Frame structure is now allocated
458
+ * // Still need to allocate data buffers with getBuffer()
459
+ * ```
460
+ *
461
+ * @see {@link getBuffer} To allocate data buffers
462
+ * @see {@link free} To free the frame
463
+ */
464
+ alloc() {
465
+ this.native.alloc();
466
+ }
467
+ /**
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.
472
+ *
473
+ * Direct mapping to av_frame_free()
474
+ *
475
+ * @note
476
+ * Calling this multiple times is safe, because we check the freed state
477
+ *
478
+ * @example
479
+ * ```typescript
480
+ * import { Frame } from 'node-av';
481
+ *
482
+ * frame.free();
483
+ * // frame is now invalid and should not be used
484
+ * ```
485
+ *
486
+ * @see {@link unref} To clear data but keep frame allocated
487
+ */
488
+ free() {
489
+ this.native.free();
490
+ }
491
+ /**
492
+ * Set up a new reference to the data described by the source frame.
493
+ *
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.
497
+ *
498
+ * Direct mapping to av_frame_ref()
499
+ *
500
+ * @param src - Source frame to reference
501
+ *
502
+ * @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
507
+ *
508
+ * @example
509
+ * ```typescript
510
+ * import { Frame, FFmpegError } from 'node-av';
511
+ *
512
+ * const ret = frame.ref(sourceFrame);
513
+ * FFmpegError.throwIfError(ret, 'frame.ref');
514
+ * // frame now references the same data as sourceFrame
515
+ * ```
516
+ *
517
+ * @see {@link unref} To remove references
518
+ * @see {@link clone} To create a new frame with same data
519
+ */
520
+ ref(src) {
521
+ return this.native.ref(src.getNative());
522
+ }
523
+ /**
524
+ * Unreference all the buffers referenced by frame and reset the frame fields.
525
+ *
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.
528
+ *
529
+ * Direct mapping to av_frame_unref()
530
+ *
531
+ * @example
532
+ * ```typescript
533
+ * import { Frame } from 'node-av';
534
+ *
535
+ * frame.unref();
536
+ * // Frame is now empty but still allocated
537
+ * // Can be reused for next decode/encode
538
+ * ```
539
+ *
540
+ * @see {@link free} To completely free the frame
541
+ */
542
+ unref() {
543
+ this.native.unref();
544
+ }
545
+ /**
546
+ * Create a new frame that references the same data as this frame.
547
+ *
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().
550
+ *
551
+ * Direct mapping to av_frame_clone()
552
+ *
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)
556
+ *
557
+ * @example
558
+ * ```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');
564
+ * }
565
+ * // clonedFrame references the same data as frame
566
+ * // Both frames must be freed independently
567
+ * ```
568
+ *
569
+ * @see {@link ref} To reference into existing frame
570
+ */
571
+ clone() {
572
+ const cloned = this.native.clone();
573
+ if (!cloned) {
574
+ return null;
575
+ }
576
+ // Wrap the native cloned frame
577
+ const frame = Object.create(Frame.prototype);
578
+ // Need to set private property - this is safe since we control the implementation
579
+ frame.native = cloned;
580
+ return frame;
581
+ }
582
+ /**
583
+ * Allocate new buffer(s) for audio or video data.
584
+ *
585
+ * Allocates data buffers for the frame based on its parameters.
586
+ * Frame parameters must be set before calling this function.
587
+ *
588
+ * Direct mapping to av_frame_get_buffer()
589
+ *
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
597
+ *
598
+ * @example
599
+ * ```typescript
600
+ * import { Frame, FFmpegError, AV_PIX_FMT_YUV420P } from 'node-av';
601
+ *
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
609
+ * ```
610
+ *
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
618
+ */
619
+ getBuffer(align = 0) {
620
+ return this.native.getBuffer(align);
621
+ }
622
+ /**
623
+ * Allocate buffer(s) for frame according to its parameters.
624
+ *
625
+ * Convenience wrapper for getBuffer() with default alignment.
626
+ * Frame parameters must be set before calling.
627
+ *
628
+ * Direct mapping to av_frame_get_buffer() with align=0
629
+ *
630
+ * @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
635
+ *
636
+ * @example
637
+ * ```typescript
638
+ * import { Frame, FFmpegError } from 'node-av';
639
+ *
640
+ * const ret = frame.allocBuffer();
641
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
642
+ * // Frame data buffers are now allocated
643
+ * ```
644
+ *
645
+ * @see {@link getBuffer} With custom alignment
646
+ */
647
+ allocBuffer() {
648
+ return this.native.allocBuffer();
649
+ }
650
+ /**
651
+ * Ensure that the frame data is writable.
652
+ *
653
+ * Makes a private copy of the frame data if it's currently shared.
654
+ * Does nothing if frame is already writable.
655
+ *
656
+ * Direct mapping to av_frame_make_writable()
657
+ *
658
+ * @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
663
+ *
664
+ * @example
665
+ * ```typescript
666
+ * import { Frame, FFmpegError } from 'node-av';
667
+ *
668
+ * if (!frame.isWritable) {
669
+ * const ret = frame.makeWritable();
670
+ * FFmpegError.throwIfError(ret, 'makeWritable');
671
+ * }
672
+ * // Frame data can now be modified safely
673
+ * ```
674
+ *
675
+ * @see {@link isWritable} Check if writable
676
+ */
677
+ makeWritable() {
678
+ return this.native.makeWritable();
679
+ }
680
+ /**
681
+ * Copy only "metadata" fields from src to this frame.
682
+ *
683
+ * Copies all frame properties except the actual data buffers.
684
+ * This includes timestamps, format, dimensions, side data, etc.
685
+ *
686
+ * Direct mapping to av_frame_copy_props()
687
+ *
688
+ * @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
694
+ *
695
+ * @example
696
+ * ```typescript
697
+ * import { Frame, FFmpegError } from 'node-av';
698
+ *
699
+ * const ret = dstFrame.copyProps(srcFrame);
700
+ * FFmpegError.throwIfError(ret, 'copyProps');
701
+ * // dstFrame now has same properties as srcFrame (but not data)
702
+ * ```
703
+ *
704
+ * @see {@link copy} To copy data as well
705
+ */
706
+ copyProps(src) {
707
+ return this.native.copyProps(src.getNative());
708
+ }
709
+ /**
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.
714
+ *
715
+ * Direct mapping to av_frame_copy()
716
+ *
717
+ * @param src - Source frame to copy data from
718
+ *
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
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * import { Frame, FFmpegError } from 'node-av';
727
+ *
728
+ * // Destination must be allocated with same parameters
729
+ * dstFrame.format = srcFrame.format;
730
+ * dstFrame.width = srcFrame.width;
731
+ * dstFrame.height = srcFrame.height;
732
+ * const allocRet = dstFrame.allocBuffer();
733
+ * FFmpegError.throwIfError(allocRet, 'allocBuffer');
734
+ *
735
+ * const ret = dstFrame.copy(srcFrame);
736
+ * FFmpegError.throwIfError(ret, 'copy');
737
+ * // Data has been copied to dstFrame
738
+ * ```
739
+ *
740
+ * @see {@link copyProps} To copy metadata only
741
+ */
742
+ copy(src) {
743
+ return this.native.copy(src.getNative());
744
+ }
745
+ /**
746
+ * Transfer data to or from hardware surfaces.
747
+ *
748
+ * Transfers frame data between hardware (GPU) and software (CPU) memory.
749
+ * Can be used for both upload and download operations.
750
+ *
751
+ * Direct mapping to av_hwframe_transfer_data()
752
+ *
753
+ * @param dst - Destination frame
754
+ * @param flags - Transfer flags (currently unused, should be set to zero)
755
+ *
756
+ * @returns Promise resolving to 0 on success, negative AVERROR on error:
757
+ * - 0: Success (data transferred)
758
+ * - AVERROR(ENOSYS): Operation not supported
759
+ * - AVERROR(EINVAL): Invalid parameters
760
+ * - AVERROR(ENOMEM): Memory allocation failure
761
+ * - <0: Other hardware-specific errors
762
+ *
763
+ * @example
764
+ * ```typescript
765
+ * import { Frame, FFmpegError } from 'node-av';
766
+ *
767
+ * // Transfer from hardware to software frame
768
+ * const swFrame = new Frame();
769
+ * swFrame.alloc();
770
+ * const ret = await hwFrame.hwframeTransferData(swFrame, 0);
771
+ * FFmpegError.throwIfError(ret, 'hwframeTransferData');
772
+ * // Data is now in CPU memory
773
+ * ```
774
+ *
775
+ * @see {@link isHwFrame} Check if frame is hardware frame
776
+ */
777
+ async hwframeTransferData(dst, flags) {
778
+ return this.native.hwframeTransferData(dst.getNative(), flags ?? 0);
779
+ }
780
+ /**
781
+ * Check if this is a hardware frame.
782
+ *
783
+ * A frame is considered a hardware frame if it has a hw_frames_ctx set.
784
+ *
785
+ * Direct check of AVFrame->hw_frames_ctx
786
+ *
787
+ * @returns True if this is a hardware frame, false otherwise
788
+ *
789
+ * @example
790
+ * ```typescript
791
+ * import { Frame } from 'node-av';
792
+ *
793
+ * if (frame.isHwFrame()) {
794
+ * console.log('Frame is in GPU memory');
795
+ * } else {
796
+ * console.log('Frame is in CPU memory');
797
+ * }
798
+ * ```
799
+ *
800
+ * @see {@link hwframeTransferData} To transfer between CPU and GPU
801
+ */
802
+ isHwFrame() {
803
+ return this.native.isHwFrame();
804
+ }
805
+ /**
806
+ * Check if this is a software frame.
807
+ *
808
+ * A frame is considered a software frame if it doesn't have hw_frames_ctx
809
+ * but has actual data pointers.
810
+ *
811
+ * Direct check of AVFrame->data[0] && !AVFrame->hw_frames_ctx
812
+ *
813
+ * @returns True if this is a software frame, false otherwise
814
+ *
815
+ * @example
816
+ * ```typescript
817
+ * import { Frame } from 'node-av';
818
+ *
819
+ * if (frame.isSwFrame()) {
820
+ * console.log('Frame is in CPU memory');
821
+ * // Safe to access frame.data
822
+ * }
823
+ * ```
824
+ *
825
+ * @see {@link isHwFrame} To check for hardware frames
826
+ */
827
+ isSwFrame() {
828
+ return this.native.isSwFrame();
829
+ }
830
+ /**
831
+ * Get side data from the frame.
832
+ *
833
+ * Direct mapping to av_frame_get_side_data()
834
+ *
835
+ * @param type - The type of side data to retrieve
836
+ * @returns Buffer containing the side data, or null if not found
837
+ *
838
+ * @example
839
+ * ```typescript
840
+ * import { Frame } from 'node-av';
841
+ * import { AV_FRAME_DATA_A53_CC } from 'node-av/constants';
842
+ *
843
+ * // Check for closed captions
844
+ * const ccData = frame.getSideData(AV_FRAME_DATA_A53_CC);
845
+ * if (ccData) {
846
+ * console.log('Found closed caption data:', ccData.length, 'bytes');
847
+ * }
848
+ * ```
849
+ */
850
+ getSideData(type) {
851
+ return this.native.getSideData(type);
852
+ }
853
+ /**
854
+ * Allocate new side data for the frame.
855
+ *
856
+ * Allocates a new side data buffer of the specified size.
857
+ * Returns a Buffer that references the allocated memory.
858
+ * Direct mapping to av_frame_new_side_data()
859
+ *
860
+ * @param type - The type of side data to allocate
861
+ * @param size - Size of the side data buffer to allocate
862
+ * @returns Buffer referencing the allocated side data
863
+ * @throws {Error} If allocation fails
864
+ *
865
+ * @example
866
+ * ```typescript
867
+ * import { Frame } from 'node-av';
868
+ * import { AV_FRAME_DATA_MASTERING_DISPLAY_METADATA } from 'node-av/constants';
869
+ *
870
+ * // Allocate HDR metadata
871
+ * const hdrBuffer = frame.newSideData(
872
+ * AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
873
+ * 24 // Size of mastering display metadata structure
874
+ * );
875
+ * // Write HDR metadata to the buffer
876
+ * ```
877
+ */
878
+ newSideData(type, size) {
879
+ return this.native.newSideData(type, size);
880
+ }
881
+ /**
882
+ * Remove side data from the frame.
883
+ *
884
+ * Removes and frees the specified type of side data from the frame.
885
+ * Direct mapping to av_frame_remove_side_data()
886
+ *
887
+ * @param type - The type of side data to remove
888
+ *
889
+ * @example
890
+ * ```typescript
891
+ * import { Frame } from 'node-av';
892
+ * import { AV_FRAME_DATA_MOTION_VECTORS } from 'node-av/constants';
893
+ *
894
+ * // Remove motion vectors data
895
+ * frame.removeSideData(AV_FRAME_DATA_MOTION_VECTORS);
896
+ * ```
897
+ */
898
+ removeSideData(type) {
899
+ this.native.removeSideData(type);
900
+ }
901
+ /**
902
+ * Get the native FFmpeg AVFrame pointer.
903
+ *
904
+ * @internal For use by other wrapper classes
905
+ * @returns The underlying native frame object
906
+ */
907
+ getNative() {
908
+ return this.native;
909
+ }
910
+ /**
911
+ * Dispose of the frame.
912
+ *
913
+ * Implements the Disposable interface for automatic cleanup.
914
+ * Equivalent to calling free().
915
+ *
916
+ * @example
917
+ * ```typescript
918
+ * import { Frame } from 'node-av';
919
+ *
920
+ * {
921
+ * using frame = new Frame();
922
+ * frame.alloc();
923
+ * // ... use frame
924
+ * } // Automatically freed when leaving scope
925
+ * ```
926
+ *
927
+ * @see {@link free} For manual cleanup
928
+ */
929
+ [Symbol.dispose]() {
930
+ this.native[Symbol.dispose]();
931
+ }
932
+ }
933
+ //# sourceMappingURL=frame.js.map