node-av-light 0.0.0 → 7.1.0-beta.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 (311) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +711 -0
  3. package/dist/api/audio-frame-buffer.d.ts +636 -0
  4. package/dist/api/audio-frame-buffer.js +1027 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +938 -0
  7. package/dist/api/bitstream-filter.js +1427 -0
  8. package/dist/api/bitstream-filter.js.map +1 -0
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_h264.h264 +0 -0
  14. package/dist/api/data/test_hevc.h265 +0 -0
  15. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  16. package/dist/api/data/test_vp8.ivf +0 -0
  17. package/dist/api/data/test_vp9.ivf +0 -0
  18. package/dist/api/decoder.d.ts +1413 -0
  19. package/dist/api/decoder.js +2367 -0
  20. package/dist/api/decoder.js.map +1 -0
  21. package/dist/api/demuxer.d.ts +1295 -0
  22. package/dist/api/demuxer.js +2344 -0
  23. package/dist/api/demuxer.js.map +1 -0
  24. package/dist/api/device.d.ts +589 -0
  25. package/dist/api/device.js +964 -0
  26. package/dist/api/device.js.map +1 -0
  27. package/dist/api/encoder-pool.d.ts +262 -0
  28. package/dist/api/encoder-pool.js +397 -0
  29. package/dist/api/encoder-pool.js.map +1 -0
  30. package/dist/api/encoder.d.ts +1509 -0
  31. package/dist/api/encoder.js +2619 -0
  32. package/dist/api/encoder.js.map +1 -0
  33. package/dist/api/filter-complex.d.ts +828 -0
  34. package/dist/api/filter-complex.js +1661 -0
  35. package/dist/api/filter-complex.js.map +1 -0
  36. package/dist/api/filter-presets.d.ts +800 -0
  37. package/dist/api/filter-presets.js +1554 -0
  38. package/dist/api/filter-presets.js.map +1 -0
  39. package/dist/api/filter.d.ts +1339 -0
  40. package/dist/api/filter.js +2075 -0
  41. package/dist/api/filter.js.map +1 -0
  42. package/dist/api/fmp4-stream.d.ts +797 -0
  43. package/dist/api/fmp4-stream.js +1428 -0
  44. package/dist/api/fmp4-stream.js.map +1 -0
  45. package/dist/api/hardware.d.ts +677 -0
  46. package/dist/api/hardware.js +1300 -0
  47. package/dist/api/hardware.js.map +1 -0
  48. package/dist/api/index.d.ts +21 -0
  49. package/dist/api/index.js +38 -0
  50. package/dist/api/index.js.map +1 -0
  51. package/dist/api/io-stream.d.ts +308 -0
  52. package/dist/api/io-stream.js +358 -0
  53. package/dist/api/io-stream.js.map +1 -0
  54. package/dist/api/muxer.d.ts +1311 -0
  55. package/dist/api/muxer.js +2672 -0
  56. package/dist/api/muxer.js.map +1 -0
  57. package/dist/api/pipeline.d.ts +801 -0
  58. package/dist/api/pipeline.js +1344 -0
  59. package/dist/api/pipeline.js.map +1 -0
  60. package/dist/api/probe.d.ts +128 -0
  61. package/dist/api/probe.js +227 -0
  62. package/dist/api/probe.js.map +1 -0
  63. package/dist/api/rtp-stream.d.ts +497 -0
  64. package/dist/api/rtp-stream.js +1131 -0
  65. package/dist/api/rtp-stream.js.map +1 -0
  66. package/dist/api/scaler.d.ts +561 -0
  67. package/dist/api/scaler.js +918 -0
  68. package/dist/api/scaler.js.map +1 -0
  69. package/dist/api/types.d.ts +17 -0
  70. package/dist/api/types.js +2 -0
  71. package/dist/api/types.js.map +1 -0
  72. package/dist/api/utilities/async-queue.d.ts +149 -0
  73. package/dist/api/utilities/async-queue.js +254 -0
  74. package/dist/api/utilities/async-queue.js.map +1 -0
  75. package/dist/api/utilities/audio-sample.d.ts +117 -0
  76. package/dist/api/utilities/audio-sample.js +112 -0
  77. package/dist/api/utilities/audio-sample.js.map +1 -0
  78. package/dist/api/utilities/audio-transcode.d.ts +20 -0
  79. package/dist/api/utilities/audio-transcode.js +27 -0
  80. package/dist/api/utilities/audio-transcode.js.map +1 -0
  81. package/dist/api/utilities/channel-layout.d.ts +76 -0
  82. package/dist/api/utilities/channel-layout.js +80 -0
  83. package/dist/api/utilities/channel-layout.js.map +1 -0
  84. package/dist/api/utilities/codec-format.d.ts +87 -0
  85. package/dist/api/utilities/codec-format.js +117 -0
  86. package/dist/api/utilities/codec-format.js.map +1 -0
  87. package/dist/api/utilities/context-options.d.ts +25 -0
  88. package/dist/api/utilities/context-options.js +23 -0
  89. package/dist/api/utilities/context-options.js.map +1 -0
  90. package/dist/api/utilities/electron-shared-texture.d.ts +368 -0
  91. package/dist/api/utilities/electron-shared-texture.js +540 -0
  92. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  93. package/dist/api/utilities/image.d.ts +207 -0
  94. package/dist/api/utilities/image.js +213 -0
  95. package/dist/api/utilities/image.js.map +1 -0
  96. package/dist/api/utilities/index.d.ts +14 -0
  97. package/dist/api/utilities/index.js +27 -0
  98. package/dist/api/utilities/index.js.map +1 -0
  99. package/dist/api/utilities/live-decoding.d.ts +15 -0
  100. package/dist/api/utilities/live-decoding.js +32 -0
  101. package/dist/api/utilities/live-decoding.js.map +1 -0
  102. package/dist/api/utilities/media-type.d.ts +49 -0
  103. package/dist/api/utilities/media-type.js +53 -0
  104. package/dist/api/utilities/media-type.js.map +1 -0
  105. package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
  106. package/dist/api/utilities/packet-age-watchdog.js +594 -0
  107. package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
  108. package/dist/api/utilities/pixel-format.d.ts +89 -0
  109. package/dist/api/utilities/pixel-format.js +97 -0
  110. package/dist/api/utilities/pixel-format.js.map +1 -0
  111. package/dist/api/utilities/sample-format.d.ts +129 -0
  112. package/dist/api/utilities/sample-format.js +141 -0
  113. package/dist/api/utilities/sample-format.js.map +1 -0
  114. package/dist/api/utilities/scale-size.d.ts +51 -0
  115. package/dist/api/utilities/scale-size.js +55 -0
  116. package/dist/api/utilities/scale-size.js.map +1 -0
  117. package/dist/api/utilities/scheduler.d.ts +138 -0
  118. package/dist/api/utilities/scheduler.js +98 -0
  119. package/dist/api/utilities/scheduler.js.map +1 -0
  120. package/dist/api/utilities/streaming.d.ts +186 -0
  121. package/dist/api/utilities/streaming.js +309 -0
  122. package/dist/api/utilities/streaming.js.map +1 -0
  123. package/dist/api/utilities/timestamp.d.ts +193 -0
  124. package/dist/api/utilities/timestamp.js +206 -0
  125. package/dist/api/utilities/timestamp.js.map +1 -0
  126. package/dist/api/utilities/video-transcode.d.ts +218 -0
  127. package/dist/api/utilities/video-transcode.js +624 -0
  128. package/dist/api/utilities/video-transcode.js.map +1 -0
  129. package/dist/api/utilities/whisper-model.d.ts +330 -0
  130. package/dist/api/utilities/whisper-model.js +587 -0
  131. package/dist/api/utilities/whisper-model.js.map +1 -0
  132. package/dist/api/utils.d.ts +19 -0
  133. package/dist/api/utils.js +39 -0
  134. package/dist/api/utils.js.map +1 -0
  135. package/dist/api/webrtc-stream.d.ts +294 -0
  136. package/dist/api/webrtc-stream.js +546 -0
  137. package/dist/api/webrtc-stream.js.map +1 -0
  138. package/dist/api/whisper.d.ts +326 -0
  139. package/dist/api/whisper.js +402 -0
  140. package/dist/api/whisper.js.map +1 -0
  141. package/dist/constants/bsf-options.d.ts +364 -0
  142. package/dist/constants/bsf-options.js +7 -0
  143. package/dist/constants/bsf-options.js.map +1 -0
  144. package/dist/constants/channel-layouts.d.ts +53 -0
  145. package/dist/constants/channel-layouts.js +57 -0
  146. package/dist/constants/channel-layouts.js.map +1 -0
  147. package/dist/constants/constants.d.ts +2435 -0
  148. package/dist/constants/constants.js +1989 -0
  149. package/dist/constants/constants.js.map +1 -0
  150. package/dist/constants/decoders.d.ts +651 -0
  151. package/dist/constants/decoders.js +641 -0
  152. package/dist/constants/decoders.js.map +1 -0
  153. package/dist/constants/encoders.d.ts +314 -0
  154. package/dist/constants/encoders.js +309 -0
  155. package/dist/constants/encoders.js.map +1 -0
  156. package/dist/constants/filter-options.d.ts +12099 -0
  157. package/dist/constants/filter-options.js +7 -0
  158. package/dist/constants/filter-options.js.map +1 -0
  159. package/dist/constants/format-options.d.ts +4319 -0
  160. package/dist/constants/format-options.js +7 -0
  161. package/dist/constants/format-options.js.map +1 -0
  162. package/dist/constants/formats.d.ts +18 -0
  163. package/dist/constants/formats.js +7 -0
  164. package/dist/constants/formats.js.map +1 -0
  165. package/dist/constants/hardware.d.ts +26 -0
  166. package/dist/constants/hardware.js +27 -0
  167. package/dist/constants/hardware.js.map +1 -0
  168. package/dist/constants/index.d.ts +10 -0
  169. package/dist/constants/index.js +6 -0
  170. package/dist/constants/index.js.map +1 -0
  171. package/dist/constants/options.d.ts +6217 -0
  172. package/dist/constants/options.js +7 -0
  173. package/dist/constants/options.js.map +1 -0
  174. package/dist/ffmpeg/index.d.ts +101 -0
  175. package/dist/ffmpeg/index.js +161 -0
  176. package/dist/ffmpeg/index.js.map +1 -0
  177. package/dist/ffmpeg/version.d.ts +6 -0
  178. package/dist/ffmpeg/version.js +7 -0
  179. package/dist/ffmpeg/version.js.map +1 -0
  180. package/dist/index.d.ts +4 -0
  181. package/dist/index.js +9 -0
  182. package/dist/index.js.map +1 -0
  183. package/dist/lib/audio-fifo.d.ts +399 -0
  184. package/dist/lib/audio-fifo.js +431 -0
  185. package/dist/lib/audio-fifo.js.map +1 -0
  186. package/dist/lib/binding.d.ts +242 -0
  187. package/dist/lib/binding.js +102 -0
  188. package/dist/lib/binding.js.map +1 -0
  189. package/dist/lib/bitstream-filter-context.d.ts +381 -0
  190. package/dist/lib/bitstream-filter-context.js +443 -0
  191. package/dist/lib/bitstream-filter-context.js.map +1 -0
  192. package/dist/lib/bitstream-filter.d.ts +140 -0
  193. package/dist/lib/bitstream-filter.js +154 -0
  194. package/dist/lib/bitstream-filter.js.map +1 -0
  195. package/dist/lib/codec-context.d.ts +1069 -0
  196. package/dist/lib/codec-context.js +1336 -0
  197. package/dist/lib/codec-context.js.map +1 -0
  198. package/dist/lib/codec-parameters.d.ts +664 -0
  199. package/dist/lib/codec-parameters.js +813 -0
  200. package/dist/lib/codec-parameters.js.map +1 -0
  201. package/dist/lib/codec-parser.d.ts +201 -0
  202. package/dist/lib/codec-parser.js +213 -0
  203. package/dist/lib/codec-parser.js.map +1 -0
  204. package/dist/lib/codec.d.ts +617 -0
  205. package/dist/lib/codec.js +746 -0
  206. package/dist/lib/codec.js.map +1 -0
  207. package/dist/lib/device.d.ts +294 -0
  208. package/dist/lib/device.js +326 -0
  209. package/dist/lib/device.js.map +1 -0
  210. package/dist/lib/dictionary.d.ts +333 -0
  211. package/dist/lib/dictionary.js +372 -0
  212. package/dist/lib/dictionary.js.map +1 -0
  213. package/dist/lib/error.d.ts +311 -0
  214. package/dist/lib/error.js +395 -0
  215. package/dist/lib/error.js.map +1 -0
  216. package/dist/lib/fifo.d.ts +416 -0
  217. package/dist/lib/fifo.js +453 -0
  218. package/dist/lib/fifo.js.map +1 -0
  219. package/dist/lib/filter-context.d.ts +714 -0
  220. package/dist/lib/filter-context.js +783 -0
  221. package/dist/lib/filter-context.js.map +1 -0
  222. package/dist/lib/filter-graph-segment.d.ts +161 -0
  223. package/dist/lib/filter-graph-segment.js +172 -0
  224. package/dist/lib/filter-graph-segment.js.map +1 -0
  225. package/dist/lib/filter-graph.d.ts +641 -0
  226. package/dist/lib/filter-graph.js +704 -0
  227. package/dist/lib/filter-graph.js.map +1 -0
  228. package/dist/lib/filter-inout.d.ts +202 -0
  229. package/dist/lib/filter-inout.js +261 -0
  230. package/dist/lib/filter-inout.js.map +1 -0
  231. package/dist/lib/filter.d.ts +243 -0
  232. package/dist/lib/filter.js +272 -0
  233. package/dist/lib/filter.js.map +1 -0
  234. package/dist/lib/format-context.d.ts +1335 -0
  235. package/dist/lib/format-context.js +1455 -0
  236. package/dist/lib/format-context.js.map +1 -0
  237. package/dist/lib/frame-utils.d.ts +116 -0
  238. package/dist/lib/frame-utils.js +98 -0
  239. package/dist/lib/frame-utils.js.map +1 -0
  240. package/dist/lib/frame.d.ts +1315 -0
  241. package/dist/lib/frame.js +1535 -0
  242. package/dist/lib/frame.js.map +1 -0
  243. package/dist/lib/hardware-device-context.d.ts +362 -0
  244. package/dist/lib/hardware-device-context.js +383 -0
  245. package/dist/lib/hardware-device-context.js.map +1 -0
  246. package/dist/lib/hardware-frames-context.d.ts +418 -0
  247. package/dist/lib/hardware-frames-context.js +471 -0
  248. package/dist/lib/hardware-frames-context.js.map +1 -0
  249. package/dist/lib/index.d.ts +35 -0
  250. package/dist/lib/index.js +60 -0
  251. package/dist/lib/index.js.map +1 -0
  252. package/dist/lib/input-format.d.ts +249 -0
  253. package/dist/lib/input-format.js +306 -0
  254. package/dist/lib/input-format.js.map +1 -0
  255. package/dist/lib/io-context.d.ts +698 -0
  256. package/dist/lib/io-context.js +771 -0
  257. package/dist/lib/io-context.js.map +1 -0
  258. package/dist/lib/log.d.ts +174 -0
  259. package/dist/lib/log.js +184 -0
  260. package/dist/lib/log.js.map +1 -0
  261. package/dist/lib/native-types.d.ts +1024 -0
  262. package/dist/lib/native-types.js +2 -0
  263. package/dist/lib/native-types.js.map +1 -0
  264. package/dist/lib/option.d.ts +953 -0
  265. package/dist/lib/option.js +1607 -0
  266. package/dist/lib/option.js.map +1 -0
  267. package/dist/lib/output-format.d.ts +222 -0
  268. package/dist/lib/output-format.js +259 -0
  269. package/dist/lib/output-format.js.map +1 -0
  270. package/dist/lib/packet.d.ts +521 -0
  271. package/dist/lib/packet.js +613 -0
  272. package/dist/lib/packet.js.map +1 -0
  273. package/dist/lib/rational.d.ts +251 -0
  274. package/dist/lib/rational.js +278 -0
  275. package/dist/lib/rational.js.map +1 -0
  276. package/dist/lib/software-resample-context.d.ts +552 -0
  277. package/dist/lib/software-resample-context.js +592 -0
  278. package/dist/lib/software-resample-context.js.map +1 -0
  279. package/dist/lib/software-scale-context.d.ts +344 -0
  280. package/dist/lib/software-scale-context.js +366 -0
  281. package/dist/lib/software-scale-context.js.map +1 -0
  282. package/dist/lib/stream.d.ts +383 -0
  283. package/dist/lib/stream.js +524 -0
  284. package/dist/lib/stream.js.map +1 -0
  285. package/dist/lib/sync-queue.d.ts +179 -0
  286. package/dist/lib/sync-queue.js +197 -0
  287. package/dist/lib/sync-queue.js.map +1 -0
  288. package/dist/lib/types.d.ts +34 -0
  289. package/dist/lib/types.js +2 -0
  290. package/dist/lib/types.js.map +1 -0
  291. package/dist/lib/utilities.d.ts +1198 -0
  292. package/dist/lib/utilities.js +1302 -0
  293. package/dist/lib/utilities.js.map +1 -0
  294. package/dist/utils/electron.d.ts +49 -0
  295. package/dist/utils/electron.js +63 -0
  296. package/dist/utils/electron.js.map +1 -0
  297. package/dist/utils/index.d.ts +6 -0
  298. package/dist/utils/index.js +7 -0
  299. package/dist/utils/index.js.map +1 -0
  300. package/dist/utils/libc.d.ts +11 -0
  301. package/dist/utils/libc.js +35 -0
  302. package/dist/utils/libc.js.map +1 -0
  303. package/dist/utils/variant.d.ts +26 -0
  304. package/dist/utils/variant.js +31 -0
  305. package/dist/utils/variant.js.map +1 -0
  306. package/dist/webrtc/index.d.ts +4 -0
  307. package/dist/webrtc/index.js +7 -0
  308. package/dist/webrtc/index.js.map +1 -0
  309. package/install/check.js +124 -0
  310. package/install/ffmpeg.js +66 -0
  311. package/package.json +165 -3
@@ -0,0 +1,1315 @@
1
+ import { HardwareFramesContext } from './hardware-frames-context.js';
2
+ import { Rational } from './rational.js';
3
+ import type { AVAlphaMode, AVChromaLocation, AVColorPrimaries, AVColorRange, AVColorSpace, AVColorTransferCharacteristic, AVFrameSideDataType, AVMediaType, AVPictureType, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
4
+ import { Dictionary } from './dictionary.js';
5
+ import type { HardwareDeviceContext } from './hardware-device-context.js';
6
+ import type { NativeFrame, NativeWrapper } from './native-types.js';
7
+ import type { ChannelLayout, IRational } from './types.js';
8
+ /**
9
+ * Video Frame
10
+ */
11
+ export interface VideoFrame {
12
+ width: number;
13
+ height: number;
14
+ format: AVPixelFormat;
15
+ timeBase?: IRational;
16
+ sampleAspectRatio?: IRational;
17
+ pts?: bigint;
18
+ alphaMode?: AVAlphaMode;
19
+ }
20
+ /**
21
+ * Audio Frame
22
+ */
23
+ export interface AudioFrame {
24
+ nbSamples: number;
25
+ format: AVSampleFormat;
26
+ sampleRate: number;
27
+ channelLayout: ChannelLayout;
28
+ timeBase?: IRational;
29
+ pts?: bigint;
30
+ }
31
+ /**
32
+ * Options for {@link Frame.fromIOSurface} (macOS only).
33
+ *
34
+ * Creates a zero-copy hardware frame from an IOSurface handle.
35
+ * Width and height are auto-detected from the IOSurface.
36
+ */
37
+ export interface IOSurfaceFrame {
38
+ hwFramesCtx: HardwareFramesContext;
39
+ timeBase?: IRational;
40
+ pts?: bigint;
41
+ }
42
+ /**
43
+ * Options for {@link Frame.fromD3D11Texture} (Windows only).
44
+ *
45
+ * Creates a zero-copy hardware frame from a D3D11 shared texture handle.
46
+ * Width and height are auto-detected from the texture descriptor.
47
+ */
48
+ export interface D3D11TextureFrame {
49
+ hwDeviceCtx: HardwareDeviceContext;
50
+ timeBase?: IRational;
51
+ pts?: bigint;
52
+ }
53
+ /**
54
+ * Options for {@link Frame.fromNSImage} (macOS only).
55
+ *
56
+ * Creates a zero-copy software frame from an NSImage native handle.
57
+ * Width, height, and pixel format are auto-detected from NSBitmapImageRep.
58
+ */
59
+ export interface NSImageFrame {
60
+ timeBase?: IRational;
61
+ pts?: bigint;
62
+ }
63
+ /**
64
+ * DMA-BUF plane descriptors for Linux GPU buffer sharing.
65
+ */
66
+ export interface DmaBufPlanes {
67
+ planes: {
68
+ fd: number;
69
+ stride: number;
70
+ offset: number;
71
+ size: number;
72
+ }[];
73
+ modifier: string;
74
+ }
75
+ /**
76
+ * Options for {@link Frame.fromDmaBuf} (Linux only).
77
+ *
78
+ * Creates a zero-copy DRM PRIME frame from DMA-BUF file descriptors.
79
+ */
80
+ export interface DmaBufFrame {
81
+ width: number;
82
+ height: number;
83
+ swFormat?: AVPixelFormat;
84
+ timeBase?: IRational;
85
+ pts?: bigint;
86
+ }
87
+ /**
88
+ * Container for uncompressed audio/video data.
89
+ *
90
+ * Stores decoded audio samples or video pixels. Each frame contains raw data
91
+ * for a single video frame or a set of audio samples. Includes format information,
92
+ * timing data, and metadata. Supports both software and hardware (GPU) frames.
93
+ * Essential for decoding, encoding, and filter operations.
94
+ *
95
+ * Direct mapping to FFmpeg's AVFrame.
96
+ *
97
+ * @example
98
+ * ```typescript
99
+ * import { Frame, FFmpegError } from 'node-av';
100
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
101
+ *
102
+ * // Create and allocate frame
103
+ * const frame = new Frame();
104
+ * frame.alloc();
105
+ *
106
+ * // Configure video frame
107
+ * frame.format = AV_PIX_FMT_YUV420P;
108
+ * frame.width = 1920;
109
+ * frame.height = 1080;
110
+ * const ret = frame.allocBuffer();
111
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
112
+ *
113
+ * // Receive decoded frame
114
+ * const ret2 = await codecContext.receiveFrame(frame);
115
+ * if (ret2 >= 0) {
116
+ * console.log(`Frame PTS: ${frame.pts}`);
117
+ * console.log(`Frame type: ${frame.pictType}`);
118
+ * console.log(`Keyframe: ${frame.keyFrame}`);
119
+ * }
120
+ *
121
+ * // Cleanup
122
+ * frame.unref();
123
+ * ```
124
+ *
125
+ * @see [AVFrame](https://ffmpeg.org/doxygen/trunk/structAVFrame.html) - FFmpeg Doxygen
126
+ * @see {@link CodecContext} For encoding/decoding frames
127
+ * @see {@link FilterContext} For filtering frames
128
+ */
129
+ export declare class Frame implements Disposable, NativeWrapper<NativeFrame> {
130
+ private native;
131
+ constructor();
132
+ /**
133
+ * Create a video frame from a buffer with pixel data.
134
+ *
135
+ * Allocates frame buffers, sets properties, and copies buffer data.
136
+ * Convenience factory method that combines frame allocation and data copy.
137
+ *
138
+ * @param buffer - Buffer containing raw pixel data
139
+ *
140
+ * @param props - Video Frame properties
141
+ *
142
+ * @returns Allocated frame with data from buffer
143
+ *
144
+ * @throws {FFmpegError} If allocation or buffer copy fails
145
+ *
146
+ * @example
147
+ * ```typescript
148
+ * import { Frame, AV_PIX_FMT_RGBA, FFmpegError } from 'node-av';
149
+ *
150
+ * const rawPixels = Buffer.alloc(1920 * 1080 * 4); // RGBA data
151
+ * using frame = Frame.fromVideoBuffer(rawPixels, {
152
+ * width: 1920,
153
+ * height: 1080,
154
+ * format: AV_PIX_FMT_RGBA,
155
+ * timeBase: { num: 1, den: 30 }
156
+ * });
157
+ * ```
158
+ */
159
+ static fromVideoBuffer(buffer: Buffer, props: VideoFrame): Frame;
160
+ /**
161
+ * Create an audio frame from a buffer with sample data.
162
+ *
163
+ * Allocates frame buffers, sets properties, and copies buffer data.
164
+ * Convenience factory method that combines frame allocation and data copy.
165
+ *
166
+ * @param buffer - Buffer containing raw audio samples
167
+ *
168
+ * @param props - Frame properties
169
+ *
170
+ * @returns Allocated frame with data from buffer
171
+ *
172
+ * @throws {FFmpegError} If allocation or buffer copy fails
173
+ *
174
+ * @example
175
+ * ```typescript
176
+ * import { Frame, AV_SAMPLE_FMT_FLT, AV_CH_LAYOUT_STEREO, FFmpegError } from 'node-av';
177
+ *
178
+ * const samples = Buffer.alloc(960 * 2 * 4); // 960 samples, stereo, float32
179
+ * using frame = Frame.fromAudioBuffer(samples, {
180
+ * nbSamples: 960,
181
+ * format: AV_SAMPLE_FMT_FLT,
182
+ * sampleRate: 48000,
183
+ * channelLayout: AV_CH_LAYOUT_STEREO,
184
+ * timeBase: { num: 1, den: 48000 }
185
+ * });
186
+ * ```
187
+ */
188
+ static fromAudioBuffer(buffer: Buffer, props: AudioFrame): Frame;
189
+ /**
190
+ * Create a hardware frame from an IOSurface handle (macOS only).
191
+ *
192
+ * Zero-copy: the frame references the same GPU memory as the IOSurface.
193
+ * Width and height are auto-detected from the IOSurface.
194
+ *
195
+ * @param ioSurface - IOSurfaceRef pointer as Buffer
196
+ *
197
+ * @param props - Hardware context and timing options
198
+ *
199
+ * @returns Hardware frame referencing the IOSurface GPU memory
200
+ *
201
+ * @throws {FFmpegError} If the import fails (e.g., invalid handle, wrong platform)
202
+ *
203
+ * @example
204
+ * ```typescript
205
+ * import { Frame, HardwareFramesContext } from 'node-av/lib';
206
+ *
207
+ * const frame = Frame.fromIOSurface(ioSurfaceBuffer, {
208
+ * hwFramesCtx,
209
+ * pts: 0n,
210
+ * timeBase: { num: 1, den: 90000 },
211
+ * });
212
+ * ```
213
+ */
214
+ static fromIOSurface(ioSurface: Buffer, props: IOSurfaceFrame): Frame;
215
+ /**
216
+ * Create a software frame from an NSImage native handle (macOS only).
217
+ *
218
+ * Zero-copy: the frame references the NSBitmapImageRep pixel data directly.
219
+ * Width, height, and pixel format are auto-detected.
220
+ *
221
+ * @param nsImageHandle - NSImage pointer as Buffer
222
+ *
223
+ * @param props - Timing options
224
+ *
225
+ * @returns Software frame referencing the NSImage pixel data
226
+ *
227
+ * @throws {FFmpegError} If the import fails (e.g., no NSBitmapImageRep, wrong platform)
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * import { Frame } from 'node-av/lib';
232
+ *
233
+ * // Electron: nativeImage.getNativeHandle() returns 8-byte NSImage* pointer
234
+ * const frame = Frame.fromNSImage(nativeImage.getNativeHandle(), {
235
+ * pts: 0n,
236
+ * timeBase: { num: 1, den: 30 },
237
+ * });
238
+ * ```
239
+ */
240
+ static fromNSImage(nsImageHandle: Buffer, props?: NSImageFrame): Frame;
241
+ /**
242
+ * Create a hardware frame from a D3D11 shared texture (Windows only).
243
+ *
244
+ * Zero-copy: the frame references the shared GPU texture.
245
+ * Width and height are auto-detected from the texture descriptor.
246
+ *
247
+ * @param handle - D3D11 shared texture handle as Buffer
248
+ *
249
+ * @param props - Hardware context and timing options
250
+ *
251
+ * @returns Hardware frame referencing the D3D11 texture
252
+ *
253
+ * @throws {FFmpegError} If the import fails (e.g., invalid handle, wrong platform)
254
+ *
255
+ * @example
256
+ * ```typescript
257
+ * import { Frame, HardwareDeviceContext } from 'node-av/lib';
258
+ *
259
+ * const frame = Frame.fromD3D11Texture(sharedTextureHandle, {
260
+ * hwDeviceCtx,
261
+ * pts: 0n,
262
+ * timeBase: { num: 1, den: 90000 },
263
+ * });
264
+ * ```
265
+ */
266
+ static fromD3D11Texture(handle: Buffer, props: D3D11TextureFrame): Frame;
267
+ /**
268
+ * Create a DRM PRIME frame from DMA-BUF file descriptors (Linux only).
269
+ *
270
+ * Zero-copy: the frame references the DMA-BUF GPU memory.
271
+ *
272
+ * @param dmaBuf - DMA-BUF plane descriptors
273
+ *
274
+ * @param props - Dimensions and timing options
275
+ *
276
+ * @returns Hardware frame referencing the DMA-BUF memory
277
+ *
278
+ * @throws {FFmpegError} If the import fails (e.g., invalid descriptors, wrong platform)
279
+ *
280
+ * @example
281
+ * ```typescript
282
+ * import { Frame } from 'node-av/lib';
283
+ *
284
+ * // Create DRM PRIME frame from DMA-BUF
285
+ * const drmFrame = Frame.fromDmaBuf(dmaBufPlanes, {
286
+ * width: 1920,
287
+ * height: 1080,
288
+ * pts: 0n,
289
+ * timeBase: { num: 1, den: 90000 },
290
+ * });
291
+ * ```
292
+ */
293
+ static fromDmaBuf(dmaBuf: DmaBufPlanes, props: DmaBufFrame): Frame;
294
+ /**
295
+ * Pixel format for video frames or sample format for audio.
296
+ *
297
+ * Direct mapping to AVFrame->format.
298
+ */
299
+ get format(): AVPixelFormat | AVSampleFormat;
300
+ set format(value: AVPixelFormat | AVSampleFormat);
301
+ /**
302
+ * Width of video frame in pixels.
303
+ *
304
+ * Direct mapping to AVFrame->width.
305
+ */
306
+ get width(): number;
307
+ set width(value: number);
308
+ /**
309
+ * Height of video frame in pixels.
310
+ *
311
+ * Direct mapping to AVFrame->height.
312
+ */
313
+ get height(): number;
314
+ set height(value: number);
315
+ /**
316
+ * Number of audio samples per channel.
317
+ *
318
+ * Direct mapping to AVFrame->nb_samples.
319
+ */
320
+ get nbSamples(): number;
321
+ set nbSamples(value: number);
322
+ /**
323
+ * Presentation timestamp.
324
+ *
325
+ * Time when the frame should be presented.
326
+ * In time base units. AV_NOPTS_VALUE if unknown.
327
+ *
328
+ * Direct mapping to AVFrame->pts.
329
+ */
330
+ get pts(): bigint;
331
+ set pts(value: bigint);
332
+ /**
333
+ * DTS from the packet that produced this frame.
334
+ *
335
+ * Copy of packet DTS for reference.
336
+ * In time base units. AV_NOPTS_VALUE if unknown.
337
+ *
338
+ * Direct mapping to AVFrame->pkt_dts.
339
+ */
340
+ get pktDts(): bigint;
341
+ set pktDts(value: bigint);
342
+ /**
343
+ * Best effort timestamp.
344
+ *
345
+ * Frame timestamp estimated using various heuristics.
346
+ * In time base units.
347
+ *
348
+ * Direct mapping to AVFrame->best_effort_timestamp.
349
+ */
350
+ get bestEffortTimestamp(): bigint;
351
+ set bestEffortTimestamp(value: bigint);
352
+ /**
353
+ * Time base for timestamps.
354
+ *
355
+ * Defines the unit of the timestamps (seconds per tick).
356
+ *
357
+ * Direct mapping to AVFrame->time_base.
358
+ */
359
+ get timeBase(): Rational;
360
+ set timeBase(value: IRational);
361
+ /**
362
+ * Whether this frame is a keyframe.
363
+ *
364
+ * 1 if keyframe, 0 otherwise.
365
+ *
366
+ * Direct mapping to AVFrame->key_frame.
367
+ */
368
+ get keyFrame(): number;
369
+ set keyFrame(value: number);
370
+ /**
371
+ * Picture type of the frame.
372
+ *
373
+ * Type of frame (I, P, B, etc.).
374
+ *
375
+ * Direct mapping to AVFrame->pict_type.
376
+ */
377
+ get pictType(): AVPictureType;
378
+ set pictType(value: AVPictureType);
379
+ /**
380
+ * Quality (between 1 (good) and FF_LAMBDA_MAX (bad)).
381
+ *
382
+ * Set by libavcodec for some coded frames.
383
+ * Can be set before encoding to specify desired quality for encoders that support it.
384
+ * Used by FFmpeg CLI's frame_encode() to propagate encoder's global_quality setting.
385
+ *
386
+ * Direct mapping to AVFrame->quality.
387
+ */
388
+ get quality(): number;
389
+ set quality(value: number);
390
+ /**
391
+ * Sample aspect ratio.
392
+ *
393
+ * Pixel width/height ratio. 0/1 if unknown.
394
+ *
395
+ * Direct mapping to AVFrame->sample_aspect_ratio.
396
+ */
397
+ get sampleAspectRatio(): Rational;
398
+ set sampleAspectRatio(value: Rational);
399
+ /**
400
+ * Audio sample rate.
401
+ *
402
+ * Number of samples per second.
403
+ *
404
+ * Direct mapping to AVFrame->sample_rate.
405
+ */
406
+ get sampleRate(): number;
407
+ set sampleRate(value: number);
408
+ /**
409
+ * Audio channel layout.
410
+ *
411
+ * Describes the channel configuration.
412
+ *
413
+ * Direct mapping to AVFrame->ch_layout.
414
+ */
415
+ get channelLayout(): ChannelLayout;
416
+ set channelLayout(value: ChannelLayout);
417
+ /**
418
+ * Number of audio channels.
419
+ *
420
+ * Derived from channel layout.
421
+ */
422
+ get channels(): number;
423
+ /**
424
+ * Line sizes for each plane.
425
+ *
426
+ * Number of bytes per line for each data plane.
427
+ *
428
+ * Direct mapping to AVFrame->linesize.
429
+ */
430
+ get linesize(): number[];
431
+ /**
432
+ * Color range.
433
+ *
434
+ * MPEG (limited) or JPEG (full) range.
435
+ *
436
+ * Direct mapping to AVFrame->color_range.
437
+ */
438
+ get colorRange(): AVColorRange;
439
+ set colorRange(value: AVColorRange);
440
+ /**
441
+ * Color primaries.
442
+ *
443
+ * Chromaticity coordinates of the source primaries.
444
+ *
445
+ * Direct mapping to AVFrame->color_primaries.
446
+ */
447
+ get colorPrimaries(): AVColorPrimaries;
448
+ set colorPrimaries(value: AVColorPrimaries);
449
+ /**
450
+ * Color transfer characteristic.
451
+ *
452
+ * Transfer function (gamma).
453
+ *
454
+ * Direct mapping to AVFrame->color_trc.
455
+ */
456
+ get colorTrc(): AVColorTransferCharacteristic;
457
+ set colorTrc(value: AVColorTransferCharacteristic);
458
+ /**
459
+ * YUV color space.
460
+ *
461
+ * Color space type for YUV content.
462
+ *
463
+ * Direct mapping to AVFrame->colorspace.
464
+ */
465
+ get colorSpace(): AVColorSpace;
466
+ set colorSpace(value: AVColorSpace);
467
+ /**
468
+ * Chroma sample location.
469
+ *
470
+ * Position of chroma samples.
471
+ *
472
+ * Direct mapping to AVFrame->chroma_location.
473
+ */
474
+ get chromaLocation(): AVChromaLocation;
475
+ set chromaLocation(value: AVChromaLocation);
476
+ /**
477
+ * Alpha channel mode.
478
+ *
479
+ * Specifies how the alpha channel relates to color values.
480
+ *
481
+ * Direct mapping to AVFrame->alpha_mode.
482
+ */
483
+ get alphaMode(): AVAlphaMode;
484
+ set alphaMode(value: AVAlphaMode);
485
+ /**
486
+ * Raw frame data planes.
487
+ *
488
+ * Array of buffers containing the frame data.
489
+ * One buffer per plane (e.g., Y, U, V for YUV420P).
490
+ *
491
+ * Direct mapping to AVFrame->data.
492
+ */
493
+ get data(): Buffer[] | null;
494
+ /**
495
+ * Extended data planes.
496
+ *
497
+ * For audio with >8 channels or planar audio.
498
+ * Points to data planes beyond the first 8.
499
+ *
500
+ * Direct mapping to AVFrame->extended_data.
501
+ */
502
+ get extendedData(): Buffer[] | null;
503
+ /**
504
+ * Check if frame data is writable.
505
+ *
506
+ * True if the frame data can be modified.
507
+ */
508
+ get isWritable(): boolean;
509
+ /**
510
+ * Bytes of native buffer memory this frame currently reports to V8's GC via
511
+ * `napi_adjust_external_memory`. Exposed only so the accounting can be
512
+ * asserted in tests; the value is not observable through V8 heap statistics.
513
+ *
514
+ * @internal
515
+ */
516
+ get reportedExternalMemory(): number;
517
+ /**
518
+ * Hardware frames context.
519
+ *
520
+ * Reference to hardware frames context for GPU frames.
521
+ * Null for software frames.
522
+ *
523
+ * Direct mapping to AVFrame->hw_frames_ctx.
524
+ */
525
+ get hwFramesCtx(): HardwareFramesContext | null;
526
+ set hwFramesCtx(value: HardwareFramesContext | null);
527
+ /**
528
+ * Frame flags.
529
+ *
530
+ * Combination of AVFrameFlags (e.g., AV_FRAME_FLAG_CORRUPT, AV_FRAME_FLAG_KEY).
531
+ *
532
+ * Direct mapping to AVFrame->flags.
533
+ */
534
+ get flags(): number;
535
+ set flags(value: number);
536
+ /**
537
+ * Decode error flags.
538
+ *
539
+ * Indicates errors detected during decoding.
540
+ * Non-zero value means the frame may be corrupted.
541
+ *
542
+ * Direct mapping to AVFrame->decode_error_flags.
543
+ */
544
+ get decodeErrorFlags(): number;
545
+ set decodeErrorFlags(value: number);
546
+ /**
547
+ * Frame duration.
548
+ *
549
+ * Duration of this frame in units of time_base.
550
+ * This is FFmpeg's best guess for how long the frame should be displayed.
551
+ * May be 0 if unknown or unavailable.
552
+ *
553
+ * Direct mapping to AVFrame->duration.
554
+ */
555
+ get duration(): bigint;
556
+ set duration(value: bigint);
557
+ /**
558
+ * Number of fields in this frame that should be repeated.
559
+ *
560
+ * For interlaced video, indicates how many times the frame should be repeated
561
+ * when displayed. For progressive video, this is typically 0.
562
+ * Formula: display_time = (repeat_pict / (2*fps))
563
+ *
564
+ * Direct mapping to AVFrame->repeat_pict.
565
+ */
566
+ get repeatPict(): number;
567
+ set repeatPict(value: number);
568
+ /**
569
+ * Set frame flags.
570
+ *
571
+ * Sets one or more flags using bitwise OR. Allows setting multiple flags
572
+ * without manually performing bitwise operations.
573
+ *
574
+ * @param flags - One or more flag values to set
575
+ *
576
+ * @example
577
+ * ```typescript
578
+ * import { AV_FRAME_FLAG_KEY } from 'node-av/constants';
579
+ *
580
+ * // Mark frame as key frame
581
+ * frame.setFlags(AV_FRAME_FLAG_KEY);
582
+ * ```
583
+ *
584
+ * @see {@link clearFlags} To unset flags
585
+ * @see {@link hasFlags} To check flags
586
+ * @see {@link flags} For direct flag access
587
+ */
588
+ setFlags(...flags: number[]): void;
589
+ /**
590
+ * Clear frame flags.
591
+ *
592
+ * Clears one or more flags using bitwise AND NOT. Allows clearing multiple
593
+ * flags without manually performing bitwise operations.
594
+ *
595
+ * @param flags - One or more flag values to clear
596
+ *
597
+ * @example
598
+ * ```typescript
599
+ * import { AV_FRAME_FLAG_CORRUPT } from 'node-av/constants';
600
+ *
601
+ * // Clear corrupt flag
602
+ * frame.clearFlags(AV_FRAME_FLAG_CORRUPT);
603
+ * ```
604
+ *
605
+ * @see {@link setFlags} To set flags
606
+ * @see {@link hasFlags} To check flags
607
+ * @see {@link flags} For direct flag access
608
+ */
609
+ clearFlags(...flags: number[]): void;
610
+ /**
611
+ * Check if frame has specific flags.
612
+ *
613
+ * Tests whether all specified flags are set using bitwise AND.
614
+ *
615
+ * @param flags - One or more flag values to check
616
+ *
617
+ * @returns true if all specified flags are set, false otherwise
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * import { AV_FRAME_FLAG_CORRUPT } from 'node-av/constants';
622
+ *
623
+ * if (frame.hasFlags(AV_FRAME_FLAG_CORRUPT)) {
624
+ * console.log('Frame is corrupted');
625
+ * }
626
+ * ```
627
+ *
628
+ * @see {@link setFlags} To set flags
629
+ * @see {@link clearFlags} To unset flags
630
+ * @see {@link flags} For direct flag access
631
+ */
632
+ hasFlags(...flags: number[]): boolean;
633
+ /**
634
+ * Check if frame has decode errors.
635
+ *
636
+ * Tests whether all specified decode error flags are set using bitwise AND.
637
+ *
638
+ * @param flags - One or more decode error flag values to check
639
+ *
640
+ * @returns true if all specified error flags are set, false otherwise
641
+ *
642
+ * @example
643
+ * ```typescript
644
+ * import { FF_DECODE_ERROR_INVALID_BITSTREAM } from 'node-av/constants';
645
+ *
646
+ * if (frame.hasDecodeErrorFlags(FF_DECODE_ERROR_INVALID_BITSTREAM)) {
647
+ * console.log('Frame has invalid bitstream error');
648
+ * }
649
+ * ```
650
+ *
651
+ * @see {@link decodeErrorFlags} For direct error flag access
652
+ */
653
+ hasDecodeErrorFlags(...flags: number[]): boolean;
654
+ /**
655
+ * Check if this is a video frame.
656
+ *
657
+ * Video frames have width and height > 0.
658
+ *
659
+ * @returns true if this is a video frame
660
+ *
661
+ * @example
662
+ * ```typescript
663
+ * if (frame.isVideo()) {
664
+ * console.log(`Video frame: ${frame.width}x${frame.height}`);
665
+ * }
666
+ * ```
667
+ */
668
+ isVideo(): boolean;
669
+ /**
670
+ * Check if this is an audio frame.
671
+ *
672
+ * Audio frames have sampleRate > 0 and nbSamples > 0.
673
+ *
674
+ * @returns true if this is an audio frame
675
+ *
676
+ * @example
677
+ * ```typescript
678
+ * if (frame.isAudio()) {
679
+ * console.log(`Audio frame: ${frame.sampleRate}Hz, ${frame.nbSamples} samples`);
680
+ * }
681
+ * ```
682
+ */
683
+ isAudio(): boolean;
684
+ /**
685
+ * Get the media type of this frame.
686
+ *
687
+ * @returns AVMEDIA_TYPE_VIDEO for video frames, AVMEDIA_TYPE_AUDIO for audio frames, or AVMEDIA_TYPE_UNKNOWN
688
+ *
689
+ * @example
690
+ * ```typescript
691
+ * const type = frame.getMediaType();
692
+ * console.log(`Frame type: ${type}`);
693
+ * ```
694
+ */
695
+ getMediaType(): AVMediaType;
696
+ /**
697
+ * Allocate a new frame.
698
+ *
699
+ * Allocates the frame structure. Must be called before using the frame
700
+ * unless it was created by another function (e.g., clone()).
701
+ *
702
+ * Direct mapping to av_frame_alloc().
703
+ *
704
+ * @throws {Error} If allocation fails (ENOMEM)
705
+ *
706
+ * @example
707
+ * ```typescript
708
+ * const frame = new Frame();
709
+ * frame.alloc();
710
+ * // Frame structure is now ready
711
+ * ```
712
+ *
713
+ * @see {@link allocBuffer} To allocate data buffers
714
+ * @see {@link free} To deallocate the frame
715
+ */
716
+ alloc(): void;
717
+ /**
718
+ * Free the frame.
719
+ *
720
+ * Deallocates the frame and its data. The frame becomes invalid after this.
721
+ *
722
+ * Direct mapping to av_frame_free().
723
+ *
724
+ * @example
725
+ * ```typescript
726
+ * frame.free();
727
+ * // Frame is now invalid
728
+ * ```
729
+ *
730
+ * @see {@link unref} To only free data, keeping structure
731
+ */
732
+ free(): void;
733
+ /**
734
+ * Create a reference to another frame.
735
+ *
736
+ * Sets up this frame as a reference to the source frame's data.
737
+ * Both frames will share the same data buffers.
738
+ *
739
+ * Direct mapping to av_frame_ref().
740
+ *
741
+ * IMPORTANT: per FFmpeg's contract, this frame (the destination) MUST be
742
+ * unreferenced or freshly allocated before calling. Re-using a frame as the
743
+ * destination without {@link unref} first leaks its previous buffers (the old
744
+ * references are overwritten, not freed). When reusing one frame across a loop,
745
+ * call `frame.unref()` before each `frame.ref(src)`.
746
+ *
747
+ * @param src - Source frame to reference
748
+ *
749
+ * @returns 0 on success, negative AVERROR on error:
750
+ * - AVERROR_ENOMEM: Memory allocation failure
751
+ * - AVERROR_EINVAL: Invalid parameters
752
+ *
753
+ * @example
754
+ * ```typescript
755
+ * import { FFmpegError } from 'node-av';
756
+ *
757
+ * // Reusing one frame across a loop: unref before re-referencing.
758
+ * frame2.unref();
759
+ * const ret = frame2.ref(frame1);
760
+ * FFmpegError.throwIfError(ret, 'ref');
761
+ * // frame2 now references frame1's data
762
+ * ```
763
+ *
764
+ * @see {@link unref} To remove reference (call before re-referencing a reused frame)
765
+ * @see {@link clone} To create independent copy
766
+ */
767
+ ref(src: Frame): number;
768
+ /**
769
+ * Unreference the frame.
770
+ *
771
+ * Frees the frame data if this was the last reference.
772
+ * The frame structure remains allocated and can be reused.
773
+ *
774
+ * Direct mapping to av_frame_unref().
775
+ *
776
+ * @example
777
+ * ```typescript
778
+ * frame.unref();
779
+ * // Frame data is freed, structure can be reused
780
+ * ```
781
+ *
782
+ * @see {@link ref} To create reference
783
+ * @see {@link free} To free everything
784
+ */
785
+ unref(): void;
786
+ /**
787
+ * Clone the frame.
788
+ *
789
+ * Creates an independent copy of the frame with its own data buffers.
790
+ * The new frame has the same content but can be modified independently.
791
+ *
792
+ * Direct mapping to av_frame_clone().
793
+ *
794
+ * @returns New frame instance, or null on allocation failure
795
+ *
796
+ * @example
797
+ * ```typescript
798
+ * const copy = frame.clone();
799
+ * if (copy) {
800
+ * // Modify copy without affecting original
801
+ * copy.pts = frame.pts + 1000n;
802
+ * }
803
+ * ```
804
+ *
805
+ * @see {@link ref} To create reference instead of copy
806
+ * @see {@link copy} To copy into existing frame
807
+ */
808
+ clone(): Frame | null;
809
+ /**
810
+ * Allocate data buffers for the frame.
811
+ *
812
+ * Allocates buffers based on frame parameters.
813
+ * Must set format, width/height (video) or format, nb_samples, channel_layout (audio) first.
814
+ *
815
+ * Direct mapping to av_frame_get_buffer().
816
+ *
817
+ * @param align - Buffer size alignment (0 for default)
818
+ *
819
+ * @returns 0 on success, negative AVERROR on error:
820
+ * - AVERROR_EINVAL: Invalid frame parameters
821
+ * - AVERROR_ENOMEM: Memory allocation failure
822
+ *
823
+ * @example
824
+ * ```typescript
825
+ * import { FFmpegError } from 'node-av';
826
+ *
827
+ * const ret = frame.getBuffer();
828
+ * FFmpegError.throwIfError(ret, 'getBuffer');
829
+ * ```
830
+ *
831
+ * @see {@link allocBuffer} Equivalent without alignment parameter
832
+ */
833
+ getBuffer(align?: number): number;
834
+ /**
835
+ * Allocate data buffers for the frame.
836
+ *
837
+ * Allocates buffers based on frame format and dimensions.
838
+ * Frame parameters must be set before calling.
839
+ *
840
+ * Direct mapping to av_frame_get_buffer().
841
+ *
842
+ * @returns 0 on success, negative AVERROR on error:
843
+ * - AVERROR_EINVAL: Invalid frame parameters
844
+ * - AVERROR_ENOMEM: Memory allocation failure
845
+ *
846
+ * @example
847
+ * ```typescript
848
+ * import { FFmpegError } from 'node-av';
849
+ * import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
850
+ *
851
+ * frame.format = AV_PIX_FMT_YUV420P;
852
+ * frame.width = 1920;
853
+ * frame.height = 1080;
854
+ * const ret = frame.allocBuffer();
855
+ * FFmpegError.throwIfError(ret, 'allocBuffer');
856
+ * ```
857
+ *
858
+ * @see {@link getBuffer} Equivalent with an alignment parameter
859
+ */
860
+ allocBuffer(): number;
861
+ /**
862
+ * Ensure frame data is writable.
863
+ *
864
+ * Creates a private copy of the data if it's shared with other frames.
865
+ * Call before modifying frame data to avoid affecting other references.
866
+ *
867
+ * Direct mapping to av_frame_make_writable().
868
+ *
869
+ * @returns 0 on success, negative AVERROR on error:
870
+ * - AVERROR_ENOMEM: Memory allocation failure
871
+ * - AVERROR_EINVAL: Invalid frame
872
+ *
873
+ * @example
874
+ * ```typescript
875
+ * import { FFmpegError } from 'node-av';
876
+ *
877
+ * // Ensure we can safely modify data
878
+ * const ret = frame.makeWritable();
879
+ * FFmpegError.throwIfError(ret, 'makeWritable');
880
+ * // Now safe to modify frame.data
881
+ * ```
882
+ */
883
+ makeWritable(): number;
884
+ /**
885
+ * Copy non-layout frame properties without copying data.
886
+ *
887
+ * Copies metadata like timestamp, duration, etc., but not the actual data.
888
+ * Layout-defining properties, such as width, height, channel count, format, etc., are not copied.
889
+ * Useful for preparing output frames with same properties.
890
+ *
891
+ * Direct mapping to av_frame_copy_props().
892
+ *
893
+ * @param src - Source frame to copy properties from
894
+ *
895
+ * @returns 0 on success, negative AVERROR on error:
896
+ * - AVERROR_ENOMEM: Memory allocation failure
897
+ *
898
+ * @example
899
+ * ```typescript
900
+ * import { FFmpegError } from 'node-av';
901
+ *
902
+ * const ret = dstFrame.copyProps(srcFrame);
903
+ * FFmpegError.throwIfError(ret, 'copyProps');
904
+ * // dstFrame now has same non-layout properties as srcFrame
905
+ * ```
906
+ *
907
+ * @see {@link copy} To copy data
908
+ */
909
+ copyProps(src: Frame): number;
910
+ /**
911
+ * Copy frame data.
912
+ *
913
+ * Copies only data (but not metadata) from source frame.
914
+ * Destination must have allocated buffers of correct size.
915
+ *
916
+ * Direct mapping to av_frame_copy().
917
+ *
918
+ * @param src - Source frame to copy from
919
+ *
920
+ * @returns 0 on success, negative AVERROR on error:
921
+ * - AVERROR_EINVAL: Incompatible frames
922
+ *
923
+ * @example
924
+ * ```typescript
925
+ * import { FFmpegError } from 'node-av';
926
+ *
927
+ * // Allocate destination with same format
928
+ * dstFrame.format = srcFrame.format;
929
+ * dstFrame.width = srcFrame.width;
930
+ * dstFrame.height = srcFrame.height;
931
+ * dstFrame.allocBuffer();
932
+ *
933
+ * const ret = dstFrame.copy(srcFrame);
934
+ * FFmpegError.throwIfError(ret, 'copy');
935
+ * ```
936
+ *
937
+ * @see {@link copyProps} To copy non-format metadata
938
+ * @see {@link clone} To create new frame with copy
939
+ */
940
+ copy(src: Frame): number;
941
+ /**
942
+ * Fill frame data from buffer.
943
+ *
944
+ * Copies data from buffer into frame-owned data planes; the frame never
945
+ * references the source buffer, so it may be reused or garbage collected
946
+ * afterwards. Allocates the frame's buffers if not already allocated.
947
+ *
948
+ * @param buffer - Source buffer with frame data
949
+ *
950
+ * @returns 0 on success, negative AVERROR on error:
951
+ * - AVERROR_EINVAL: Invalid parameters
952
+ *
953
+ * @example
954
+ * ```typescript
955
+ * import { FFmpegError } from 'node-av';
956
+ *
957
+ * const buffer = Buffer.from(rawVideoData);
958
+ * const ret = frame.fromBuffer(buffer);
959
+ * FFmpegError.throwIfError(ret, 'fromBuffer');
960
+ * ```
961
+ */
962
+ fromBuffer(buffer: Buffer): number;
963
+ /**
964
+ * Convert frame data to buffer.
965
+ *
966
+ * Copies frame data into a single contiguous buffer.
967
+ * For video frames, converts all planes into packed format.
968
+ * For audio frames, handles both planar and interleaved formats.
969
+ * Cannot be used with hardware frames - use hwframeTransferData first.
970
+ *
971
+ * @param output - Optional Buffer to copy into instead of allocating one; it must hold at least the frame's size and must not overlap the frame's data
972
+ *
973
+ * @returns Buffer containing frame data (a view of `output` when given)
974
+ *
975
+ * @throws {Error} If frame is not allocated, has no data, or is a hardware frame
976
+ *
977
+ * @throws {TypeError} If `output` is not a Buffer or is smaller than the frame data
978
+ *
979
+ * @example Video frame to buffer
980
+ * ```typescript
981
+ * // Get YUV420P video frame as buffer
982
+ * const buffer = frame.toBuffer();
983
+ * console.log(`Frame buffer size: ${buffer.length} bytes`);
984
+ * // Buffer contains Y plane, then U plane, then V plane
985
+ * ```
986
+ *
987
+ * @example Audio frame to buffer
988
+ * ```typescript
989
+ * // Get audio samples as buffer
990
+ * const audioBuffer = frame.toBuffer();
991
+ * console.log(`Audio buffer size: ${audioBuffer.length} bytes`);
992
+ * // For planar audio: channel 0 samples, then channel 1 samples, etc.
993
+ * // For interleaved audio: sample0_ch0, sample0_ch1, sample1_ch0, sample1_ch1, etc.
994
+ * ```
995
+ *
996
+ * @example Error handling
997
+ * ```typescript
998
+ * try {
999
+ * const buffer = frame.toBuffer();
1000
+ * // Process buffer...
1001
+ * } catch (error) {
1002
+ * if (frame.isHwFrame()) {
1003
+ * // Transfer to software first
1004
+ * const swFrame = new Frame();
1005
+ * swFrame.alloc();
1006
+ * await frame.hwframeTransferData(swFrame);
1007
+ * const buffer = swFrame.toBuffer();
1008
+ * }
1009
+ * }
1010
+ * ```
1011
+ *
1012
+ * @see {@link fromBuffer} To create frame from buffer
1013
+ * @see {@link hwframeTransferData} To transfer hardware frames to software
1014
+ * @see {@link isHwFrame} To check if frame is hardware
1015
+ * @see {@link data} To access individual planes
1016
+ */
1017
+ toBuffer(output?: Buffer): Buffer;
1018
+ /**
1019
+ * Transfer data between hardware and software frames.
1020
+ *
1021
+ * Copies frame data between GPU and system memory.
1022
+ * Direction depends on source and destination frame types.
1023
+ *
1024
+ * Direct mapping to av_hwframe_transfer_data().
1025
+ *
1026
+ * @param dst - Destination frame (software or hardware)
1027
+ *
1028
+ * @param flags - Transfer flags (0 for default)
1029
+ *
1030
+ * @returns 0 on success, negative AVERROR on error:
1031
+ * - AVERROR_EINVAL: Invalid parameters
1032
+ * - AVERROR_ENOMEM: Memory allocation failure
1033
+ *
1034
+ * @example
1035
+ * ```typescript
1036
+ * import { FFmpegError } from 'node-av';
1037
+ *
1038
+ * // Download from GPU to CPU
1039
+ * const swFrame = new Frame();
1040
+ * swFrame.alloc();
1041
+ * const ret = await hwFrame.hwframeTransferData(swFrame);
1042
+ * FFmpegError.throwIfError(ret, 'hwframeTransferData');
1043
+ * ```
1044
+ *
1045
+ * @see {@link isHwFrame} To check if frame is hardware
1046
+ * @see {@link isSwFrame} To check if frame is software
1047
+ */
1048
+ hwframeTransferData(dst: Frame, flags?: number): Promise<number>;
1049
+ /**
1050
+ * Transfer data between hardware and software frames synchronously.
1051
+ * Synchronous version of hwframeTransferData.
1052
+ *
1053
+ * Copies frame data between GPU and system memory.
1054
+ * Direction depends on source and destination frame types.
1055
+ *
1056
+ * Direct mapping to av_hwframe_transfer_data().
1057
+ *
1058
+ * @param dst - Destination frame (software or hardware)
1059
+ *
1060
+ * @param flags - Transfer flags (0 for default)
1061
+ *
1062
+ * @returns 0 on success, negative AVERROR on error:
1063
+ * - AVERROR_EINVAL: Invalid parameters
1064
+ * - AVERROR_ENOMEM: Memory allocation failure
1065
+ *
1066
+ * @example
1067
+ * ```typescript
1068
+ * import { FFmpegError } from 'node-av';
1069
+ *
1070
+ * // Download from GPU to CPU
1071
+ * const swFrame = new Frame();
1072
+ * swFrame.alloc();
1073
+ * const ret = hwFrame.hwframeTransferData(swFrame);
1074
+ * FFmpegError.throwIfError(ret, 'hwframeTransferData');
1075
+ * ```
1076
+ *
1077
+ * @see {@link hwframeTransferData} For async version
1078
+ */
1079
+ hwframeTransferDataSync(dst: Frame, flags?: number): number;
1080
+ /**
1081
+ * Check if this is a hardware frame.
1082
+ *
1083
+ * Returns true if frame data is in GPU memory.
1084
+ *
1085
+ * @returns True if hardware frame, false otherwise
1086
+ *
1087
+ * @example
1088
+ * ```typescript
1089
+ * if (frame.isHwFrame()) {
1090
+ * console.log('Frame is in GPU memory');
1091
+ * }
1092
+ * ```
1093
+ *
1094
+ * @see {@link isSwFrame} To check for software frame
1095
+ * @see {@link hwframeTransferData} To transfer between GPU/CPU
1096
+ */
1097
+ isHwFrame(): boolean;
1098
+ /**
1099
+ * Check if this is a software frame.
1100
+ *
1101
+ * Returns true if frame data is in system memory.
1102
+ *
1103
+ * @returns True if software frame, false otherwise
1104
+ *
1105
+ * @example
1106
+ * ```typescript
1107
+ * if (frame.isSwFrame()) {
1108
+ * console.log('Frame is in system memory');
1109
+ * }
1110
+ * ```
1111
+ *
1112
+ * @see {@link isHwFrame} To check for hardware frame
1113
+ * @see {@link hwframeTransferData} To transfer between GPU/CPU
1114
+ */
1115
+ isSwFrame(): boolean;
1116
+ /**
1117
+ * Export the IOSurface backing a decoded VideoToolbox frame (macOS only).
1118
+ *
1119
+ * Returns the `IOSurfaceRef` carried by an `AV_PIX_FMT_VIDEOTOOLBOX` frame as
1120
+ * an 8-byte pointer Buffer — the same handle format accepted by
1121
+ * {@link Frame.fromIOSurface}. This enables zero-copy interop with Metal /
1122
+ * CoreVideo (e.g. feeding a hardware-decoded frame into a GPU compositor)
1123
+ * without a GPU→CPU readback.
1124
+ *
1125
+ * Returns `null` when the frame is not a decoded VideoToolbox hardware frame,
1126
+ * has no backing IOSurface, or on non-macOS platforms.
1127
+ *
1128
+ * **Lifetime:** the IOSurface stays owned by the frame's `CVPixelBuffer`.
1129
+ * Keep this `Frame` alive while using the handle. If the surface must outlive
1130
+ * the frame, retain it separately (e.g. `IOSurfaceIncrementUseCount`).
1131
+ *
1132
+ * @returns IOSurfaceRef pointer as Buffer, or null if not available
1133
+ *
1134
+ * @example
1135
+ * ```typescript
1136
+ * const handle = frame.exportIOSurface();
1137
+ * if (handle) {
1138
+ * // Pass to a Metal-based compositor; keep `frame` alive while in use.
1139
+ * }
1140
+ * ```
1141
+ *
1142
+ * @see {@link fromIOSurface} For the inverse (import) direction
1143
+ */
1144
+ exportIOSurface(): Buffer | null;
1145
+ /**
1146
+ * Get frame side data.
1147
+ *
1148
+ * Retrieves additional data associated with the frame
1149
+ * (e.g., motion vectors, film grain, HDR metadata).
1150
+ *
1151
+ * Direct mapping to av_frame_get_side_data().
1152
+ *
1153
+ * @param type - Type of side data to retrieve
1154
+ *
1155
+ * @returns Side data buffer, or null if not present
1156
+ *
1157
+ * @example
1158
+ * ```typescript
1159
+ * import { AV_FRAME_DATA_MOTION_VECTORS } from 'node-av/constants';
1160
+ *
1161
+ * const motionVectors = frame.getSideData(AV_FRAME_DATA_MOTION_VECTORS);
1162
+ * if (motionVectors) {
1163
+ * console.log(`Motion data size: ${motionVectors.length} bytes`);
1164
+ * }
1165
+ * ```
1166
+ *
1167
+ * @see {@link newSideData} To add side data
1168
+ * @see {@link removeSideData} To remove side data
1169
+ */
1170
+ getSideData(type: AVFrameSideDataType): Buffer | null;
1171
+ /**
1172
+ * Allocate new side data.
1173
+ *
1174
+ * Allocates side data buffer attached to the frame.
1175
+ * Returns buffer that can be written to directly.
1176
+ *
1177
+ * Direct mapping to av_frame_new_side_data().
1178
+ *
1179
+ * @param type - Type of side data
1180
+ *
1181
+ * @param size - Size in bytes to allocate
1182
+ *
1183
+ * @returns Allocated buffer for writing
1184
+ *
1185
+ * @throws {Error} If allocation fails
1186
+ *
1187
+ * @example
1188
+ * ```typescript
1189
+ * import { AV_FRAME_DATA_MASTERING_DISPLAY_METADATA } from 'node-av/constants';
1190
+ *
1191
+ * // Allocate and write HDR metadata
1192
+ * const hdrData = frame.newSideData(
1193
+ * AV_FRAME_DATA_MASTERING_DISPLAY_METADATA,
1194
+ * 40
1195
+ * );
1196
+ * // Write metadata to buffer...
1197
+ * ```
1198
+ *
1199
+ * @see {@link getSideData} To retrieve side data
1200
+ * @see {@link removeSideData} To remove side data
1201
+ */
1202
+ newSideData(type: AVFrameSideDataType, size: number): Buffer;
1203
+ /**
1204
+ * Remove side data from frame.
1205
+ *
1206
+ * Removes specific type of side data.
1207
+ *
1208
+ * Direct mapping to av_frame_remove_side_data().
1209
+ *
1210
+ * @param type - Type of side data to remove
1211
+ *
1212
+ * @example
1213
+ * ```typescript
1214
+ * import { AV_FRAME_DATA_MOTION_VECTORS } from 'node-av/constants';
1215
+ *
1216
+ * frame.removeSideData(AV_FRAME_DATA_MOTION_VECTORS);
1217
+ * // Motion vectors removed
1218
+ * ```
1219
+ *
1220
+ * @see {@link getSideData} To retrieve side data
1221
+ * @see {@link newSideData} To add side data
1222
+ */
1223
+ removeSideData(type: AVFrameSideDataType): void;
1224
+ /**
1225
+ * Get frame metadata dictionary.
1226
+ *
1227
+ * Returns metadata attached to the frame by filters or demuxers.
1228
+ * Metadata is stored as key-value pairs in a Dictionary.
1229
+ * Useful for reading filter-generated metadata (e.g., whisper transcription).
1230
+ *
1231
+ * Direct mapping to AVFrame->metadata.
1232
+ *
1233
+ * @returns Dictionary containing frame metadata
1234
+ *
1235
+ * @example
1236
+ * ```typescript
1237
+ * // Read whisper filter metadata
1238
+ * const metadata = frame.getMetadata();
1239
+ * const text = metadata.get('lavfi.whisper.text');
1240
+ * const duration = metadata.get('lavfi.whisper.duration');
1241
+ *
1242
+ * if (text) {
1243
+ * console.log(`Transcribed: ${text}`);
1244
+ * console.log(`Duration: ${duration}s`);
1245
+ * }
1246
+ * ```
1247
+ *
1248
+ * @example
1249
+ * ```typescript
1250
+ * // Read scene detection metadata
1251
+ * const metadata = frame.getMetadata();
1252
+ * const score = metadata.get('lavfi.scene_score');
1253
+ * if (score) {
1254
+ * console.log(`Scene change score: ${score}`);
1255
+ * }
1256
+ * ```
1257
+ *
1258
+ * @see {@link Dictionary} For metadata dictionary operations
1259
+ */
1260
+ getMetadata(): Dictionary;
1261
+ /**
1262
+ * Apply cropping to the frame.
1263
+ *
1264
+ * Crops the frame according to its crop metadata (AVFrame crop fields).
1265
+ * This adjusts the frame dimensions and data pointers to reflect the cropped region.
1266
+ * The cropped-out area is discarded, reducing frame size.
1267
+ *
1268
+ * Direct mapping to av_frame_apply_cropping().
1269
+ *
1270
+ * @param flags - Cropping flags (default: AV_FRAME_CROP_UNALIGNED = 1)
1271
+ * AV_FRAME_CROP_UNALIGNED allows unaligned cropping for lavfi compatibility
1272
+ *
1273
+ * @returns 0 on success, negative error code on failure
1274
+ *
1275
+ * @example
1276
+ * ```typescript
1277
+ * import { Frame, FFmpegError } from 'node-av';
1278
+ *
1279
+ * const frame = new Frame();
1280
+ * // ... decode frame with crop metadata ...
1281
+ *
1282
+ * // Apply cropping based on metadata
1283
+ * const ret = frame.applyCropping();
1284
+ * FFmpegError.throwIfError(ret, 'Failed to apply cropping');
1285
+ *
1286
+ * // Frame dimensions are now updated to cropped size
1287
+ * console.log(`Cropped to ${frame.width}x${frame.height}`);
1288
+ * ```
1289
+ */
1290
+ applyCropping(flags?: number): number;
1291
+ /**
1292
+ * Get the underlying native Frame object.
1293
+ *
1294
+ * @returns The native Frame binding object
1295
+ *
1296
+ * @internal
1297
+ */
1298
+ getNative(): NativeFrame;
1299
+ /**
1300
+ * Dispose of the frame.
1301
+ *
1302
+ * Implements the Disposable interface for automatic cleanup.
1303
+ * Equivalent to calling free().
1304
+ *
1305
+ * @example
1306
+ * ```typescript
1307
+ * {
1308
+ * using frame = new Frame();
1309
+ * frame.alloc();
1310
+ * // Use frame...
1311
+ * } // Automatically freed when leaving scope
1312
+ * ```
1313
+ */
1314
+ [Symbol.dispose](): void;
1315
+ }