node-av 1.1.0 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -3
  21. package/dist/api/index.js +1 -1
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  27. package/dist/api/media-input.js +205 -103
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +210 -128
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. package/CHANGELOG.md +0 -8
@@ -5,348 +5,343 @@ import type { NativeHardwareFramesContext, NativeWrapper } from './native-types.
5
5
  /**
6
6
  * Hardware frames context for GPU memory management.
7
7
  *
8
- * Manages pools of hardware frames for efficient GPU memory allocation.
9
- * Handles format conversions and data transfers between CPU and GPU memory.
10
- * Required for hardware-accelerated video processing pipelines.
8
+ * Manages pools of hardware frames (textures/surfaces) on the GPU.
9
+ * Essential for zero-copy hardware acceleration, allowing frames to stay
10
+ * in GPU memory throughout the processing pipeline. Provides frame allocation,
11
+ * format conversion, and data transfer between hardware and system memory.
11
12
  *
12
13
  * Direct mapping to FFmpeg's AVHWFramesContext.
13
14
  *
14
15
  * @example
15
16
  * ```typescript
16
- * import { HardwareDeviceContext, HardwareFramesContext, Frame, FFmpegError } from 'node-av';
17
- * import { AV_HWDEVICE_TYPE_CUDA, AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12 } from 'node-av/constants';
17
+ * import { HardwareFramesContext, HardwareDeviceContext, Frame, FFmpegError } from 'node-av';
18
+ * import { AV_PIX_FMT_NV12, AV_PIX_FMT_CUDA, AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
18
19
  *
19
20
  * // Create hardware frames context
20
21
  * const device = new HardwareDeviceContext();
21
- * const deviceRet = device.create(AV_HWDEVICE_TYPE_CUDA, null, null);
22
- * FFmpegError.throwIfError(deviceRet, 'create device');
22
+ * device.create(AV_HWDEVICE_TYPE_CUDA);
23
23
  *
24
24
  * const frames = new HardwareFramesContext();
25
- * frames.alloc(device);
26
- *
27
- * // Configure frame parameters
28
25
  * frames.format = AV_PIX_FMT_CUDA; // Hardware format
29
26
  * frames.swFormat = AV_PIX_FMT_NV12; // Software format
30
27
  * frames.width = 1920;
31
28
  * frames.height = 1080;
32
- * frames.initialPoolSize = 10;
29
+ * frames.initialPoolSize = 20; // Pre-allocate 20 frames
33
30
  *
34
- * // Initialize the context
31
+ * frames.alloc(device);
35
32
  * const ret = frames.init();
36
- * FFmpegError.throwIfError(ret, 'init frames');
33
+ * FFmpegError.throwIfError(ret, 'init');
37
34
  *
38
35
  * // Allocate hardware frame
39
36
  * const hwFrame = new Frame();
40
- * hwFrame.alloc();
41
37
  * const ret2 = frames.getBuffer(hwFrame, 0);
42
38
  * FFmpegError.throwIfError(ret2, 'getBuffer');
43
39
  *
44
- * // Transfer between hardware and software
45
- * const swFrame = new Frame();
46
- * swFrame.alloc();
47
- * swFrame.width = 1920;
48
- * swFrame.height = 1080;
49
- * swFrame.format = AV_PIX_FMT_NV12;
50
- * const swRet = swFrame.getBuffer();
51
- * FFmpegError.throwIfError(swRet, 'getBuffer sw');
52
- *
53
- * // Download from hardware
54
- * const dlRet = await frames.transferData(swFrame, hwFrame, 0);
55
- * FFmpegError.throwIfError(dlRet, 'download');
40
+ * // Transfer from CPU to GPU
41
+ * const cpuFrame = new Frame();
42
+ * // ... fill cpuFrame with data ...
43
+ * await frames.transferData(hwFrame, cpuFrame);
56
44
  *
57
- * // Upload to hardware
58
- * const ulRet = await frames.transferData(hwFrame, swFrame, 0);
59
- * FFmpegError.throwIfError(ulRet, 'upload');
60
- *
61
- * // Cleanup
62
- * hwFrame.free();
63
- * swFrame.free();
64
- * frames.free();
65
- * device.free();
45
+ * // Map hardware frame to CPU for access
46
+ * const mappedFrame = new Frame();
47
+ * const ret3 = frames.map(mappedFrame, hwFrame, AV_HWFRAME_MAP_READ);
48
+ * FFmpegError.throwIfError(ret3, 'map');
66
49
  * ```
67
50
  *
51
+ * @see [AVHWFramesContext](https://ffmpeg.org/doxygen/trunk/structAVHWFramesContext.html) - FFmpeg Doxygen
68
52
  * @see {@link HardwareDeviceContext} For device management
69
- * @see {@link Frame} For frame allocation
53
+ * @see {@link Frame} For frame operations
70
54
  */
71
55
  export declare class HardwareFramesContext implements Disposable, NativeWrapper<NativeHardwareFramesContext> {
72
56
  private native;
73
57
  private _deviceRef?;
74
- /**
75
- * Create a new hardware frames context.
76
- *
77
- * The context is uninitialized - you must call alloc() before use.
78
- * No FFmpeg resources are allocated until initialization.
79
- *
80
- * Direct wrapper around AVHWFramesContext.
81
- *
82
- * @example
83
- * ```typescript
84
- * import { HardwareFramesContext, FFmpegError } from 'node-av';
85
- *
86
- * const frames = new HardwareFramesContext();
87
- * frames.alloc(device);
88
- * // Configure parameters
89
- * const ret = frames.init();
90
- * FFmpegError.throwIfError(ret, 'init');
91
- * ```
92
- */
93
58
  constructor();
94
59
  /**
95
60
  * Hardware pixel format.
96
61
  *
97
- * The pixel format identifying the underlying HW surface type.
62
+ * The pixel format used for frames in GPU memory.
63
+ * Hardware-specific format like AV_PIX_FMT_CUDA or AV_PIX_FMT_VAAPI.
98
64
  *
99
- * Direct mapping to AVHWFramesContext->format
65
+ * Direct mapping to AVHWFramesContext->format.
100
66
  */
101
67
  get format(): AVPixelFormat;
102
68
  set format(value: AVPixelFormat);
103
69
  /**
104
70
  * Software pixel format.
105
71
  *
106
- * The pixel format identifying the actual data layout of the hardware frames.
72
+ * The pixel format frames are converted to when transferred
73
+ * to system memory. Standard format like AV_PIX_FMT_YUV420P.
107
74
  *
108
- * Direct mapping to AVHWFramesContext->sw_format
75
+ * Direct mapping to AVHWFramesContext->sw_format.
109
76
  */
110
77
  get swFormat(): AVPixelFormat;
111
78
  set swFormat(value: AVPixelFormat);
112
79
  /**
113
80
  * Frame width.
114
81
  *
115
- * The allocated dimensions of the frames in this pool.
82
+ * Width of frames in pixels.
116
83
  *
117
- * Direct mapping to AVHWFramesContext->width
84
+ * Direct mapping to AVHWFramesContext->width.
118
85
  */
119
86
  get width(): number;
120
87
  set width(value: number);
121
88
  /**
122
89
  * Frame height.
123
90
  *
124
- * The allocated dimensions of the frames in this pool.
91
+ * Height of frames in pixels.
125
92
  *
126
- * Direct mapping to AVHWFramesContext->height
93
+ * Direct mapping to AVHWFramesContext->height.
127
94
  */
128
95
  get height(): number;
129
96
  set height(value: number);
130
97
  /**
131
98
  * Initial pool size.
132
99
  *
133
- * Initial size of the frame pool. If a device type does not support
134
- * dynamically resizing the pool, then this is also the maximum pool size.
100
+ * Number of frames to pre-allocate in the pool.
101
+ * Set before calling init() for optimal performance.
102
+ *
103
+ * Direct mapping to AVHWFramesContext->initial_pool_size.
135
104
  */
136
105
  get initialPoolSize(): number;
137
106
  set initialPoolSize(value: number);
138
107
  /**
139
- * Associated device context.
108
+ * Associated hardware device.
140
109
  *
141
- * Direct mapping to AVHWFramesContext->device_ref
110
+ * Reference to the device context this frames context belongs to.
111
+ * Automatically set when calling alloc().
142
112
  *
143
- * @readonly
113
+ * Direct mapping to AVHWFramesContext->device_ref.
144
114
  */
145
115
  get deviceRef(): HardwareDeviceContext | null;
146
116
  /**
147
- * Allocate an AVHWFramesContext tied to a given device context.
117
+ * Allocate hardware frames context.
118
+ *
119
+ * Allocates the frames context and associates it with a device.
120
+ * Must be called before init().
121
+ *
122
+ * Direct mapping to av_hwframe_ctx_alloc().
148
123
  *
149
- * Direct mapping to av_hwframe_ctx_alloc()
124
+ * @param device - Hardware device context to use
150
125
  *
151
- * @param device - Hardware device context
126
+ * @throws {Error} If allocation fails (ENOMEM)
152
127
  *
153
128
  * @example
154
129
  * ```typescript
130
+ * import { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12 } from 'node-av/constants';
131
+ *
155
132
  * const frames = new HardwareFramesContext();
156
- * frames.alloc(device);
157
- * // Set parameters before init()
158
133
  * frames.format = AV_PIX_FMT_CUDA;
159
134
  * frames.swFormat = AV_PIX_FMT_NV12;
160
135
  * frames.width = 1920;
161
136
  * frames.height = 1080;
137
+ * frames.alloc(device);
162
138
  * ```
163
139
  *
164
- * @throws {Error} If allocation fails
140
+ * @see {@link init} To initialize after allocation
165
141
  */
166
142
  alloc(device: HardwareDeviceContext): void;
167
143
  /**
168
- * Finalize the context before use.
144
+ * Initialize hardware frames context.
145
+ *
146
+ * Initializes the frame pool after configuration.
147
+ * Must be called after alloc() and property setup.
169
148
  *
170
- * Direct mapping to av_hwframe_ctx_init()
149
+ * Direct mapping to av_hwframe_ctx_init().
171
150
  *
172
151
  * @returns 0 on success, negative AVERROR on error:
173
- * - 0: Success
174
- * - AVERROR(EINVAL): Invalid parameters
175
- * - AVERROR(ENOMEM): Memory allocation failure
176
- * - <0: Device-specific errors
152
+ * - AVERROR_EINVAL: Invalid parameters
153
+ * - AVERROR_ENOMEM: Memory allocation failure
154
+ * - AVERROR_ENOSYS: Operation not supported
155
+ * - Hardware-specific errors
177
156
  *
178
157
  * @example
179
158
  * ```typescript
159
+ * import { FFmpegError } from 'node-av';
160
+ *
161
+ * frames.alloc(device);
180
162
  * const ret = frames.init();
181
- * if (ret < 0) {
182
- * throw new FFmpegError(ret);
183
- * }
163
+ * FFmpegError.throwIfError(ret, 'init');
184
164
  * ```
165
+ *
166
+ * @see {@link alloc} Must be called first
185
167
  */
186
168
  init(): number;
187
169
  /**
188
- * Free the frames context.
170
+ * Free hardware frames context.
189
171
  *
190
- * Unreferences the AVBufferRef.
172
+ * Releases all frames and resources associated with the context.
173
+ * The context becomes invalid after calling this.
174
+ *
175
+ * Direct mapping to av_buffer_unref() on frames context.
191
176
  *
192
177
  * @example
193
178
  * ```typescript
194
179
  * frames.free();
195
- * // frames is now invalid and should not be used
180
+ * // Frames context is now invalid
196
181
  * ```
182
+ *
183
+ * @see {@link Symbol.dispose} For automatic cleanup
197
184
  */
198
185
  free(): void;
199
186
  /**
200
- * Allocate a new frame attached to the given AVHWFramesContext.
187
+ * Allocate hardware frame from pool.
201
188
  *
202
- * Direct mapping to av_hwframe_get_buffer()
189
+ * Gets a frame from the hardware frame pool.
190
+ * The frame will have hardware-backed storage.
203
191
  *
204
- * @param frame - Frame to allocate (must be allocated but empty)
205
- * @param flags - Currently unused, should be set to 0
192
+ * Direct mapping to av_hwframe_get_buffer().
206
193
  *
194
+ * @param frame - Frame to allocate buffer for
195
+ * @param flags - Allocation flags (usually 0)
207
196
  * @returns 0 on success, negative AVERROR on error:
208
- * - 0: Success
209
- * - AVERROR(EINVAL): Invalid parameters
210
- * - AVERROR(ENOMEM): Memory allocation failure
211
- * - <0: Device-specific errors
197
+ * - AVERROR_ENOMEM: No frames available in pool
198
+ * - AVERROR_EINVAL: Invalid parameters
212
199
  *
213
200
  * @example
214
201
  * ```typescript
215
- * const frame = new Frame();
216
- * frame.alloc();
217
- * const ret = frames.getBuffer(frame, 0);
218
- * if (ret < 0) {
219
- * throw new FFmpegError(ret);
220
- * }
221
- * // frame now contains a hardware frame
202
+ * import { Frame, FFmpegError } from 'node-av';
203
+ *
204
+ * const hwFrame = new Frame();
205
+ * const ret = frames.getBuffer(hwFrame, 0);
206
+ * FFmpegError.throwIfError(ret, 'getBuffer');
207
+ * // hwFrame now has GPU memory allocated
222
208
  * ```
209
+ *
210
+ * @see {@link transferData} To upload data to hardware frame
223
211
  */
224
212
  getBuffer(frame: Frame, flags?: number): number;
225
213
  /**
226
- * Copy data to or from a hardware surface.
214
+ * Transfer data between hardware and system memory.
227
215
  *
228
- * Direct mapping to av_hwframe_transfer_data()
216
+ * Copies frame data between GPU and CPU memory.
217
+ * Direction is determined by frame types.
218
+ *
219
+ * Direct mapping to av_hwframe_transfer_data().
229
220
  *
230
221
  * @param dst - Destination frame
231
222
  * @param src - Source frame
232
- * @param flags - Currently unused, should be set to 0
233
- *
234
- * @returns Promise resolving to 0 on success, negative AVERROR on error:
235
- * - 0: Success
236
- * - AVERROR(ENOSYS): Transfer not supported
237
- * - AVERROR(EINVAL): Invalid parameters
238
- * - <0: Other errors
223
+ * @param flags - Transfer flags (usually 0)
224
+ * @returns 0 on success, negative AVERROR on error:
225
+ * - AVERROR_EINVAL: Invalid parameters
226
+ * - AVERROR_ENOSYS: Transfer not supported
227
+ * - AVERROR_ENOMEM: Memory allocation failure
239
228
  *
240
229
  * @example
241
230
  * ```typescript
242
- * // Download from hardware to software
243
- * const ret = await frames.transferData(swFrame, hwFrame, 0);
244
- * if (ret < 0) {
245
- * throw new FFmpegError(ret);
246
- * }
247
- *
248
- * // Upload from software to hardware
249
- * const ret2 = await frames.transferData(hwFrame, swFrame, 0);
250
- * if (ret2 < 0) {
251
- * throw new FFmpegError(ret2);
252
- * }
231
+ * import { FFmpegError } from 'node-av';
232
+ *
233
+ * // Upload: CPU -> GPU
234
+ * const cpuFrame = new Frame();
235
+ * // ... fill cpuFrame with data ...
236
+ * const hwFrame = new Frame();
237
+ * frames.getBuffer(hwFrame, 0);
238
+ * const ret = await frames.transferData(hwFrame, cpuFrame);
239
+ * FFmpegError.throwIfError(ret, 'transferData');
240
+ *
241
+ * // Download: GPU -> CPU
242
+ * const downloadFrame = new Frame();
243
+ * const ret2 = await frames.transferData(downloadFrame, hwFrame);
244
+ * FFmpegError.throwIfError(ret2, 'transferData');
253
245
  * ```
246
+ *
247
+ * @see {@link getBuffer} To allocate hardware frame
248
+ * @see {@link map} For zero-copy access
254
249
  */
255
250
  transferData(dst: Frame, src: Frame, flags?: number): Promise<number>;
256
251
  /**
257
- * Get a list of possible source/target formats.
252
+ * Get supported transfer formats.
258
253
  *
259
- * Direct mapping to av_hwframe_transfer_get_formats()
254
+ * Returns pixel formats supported for frame transfer
255
+ * in the specified direction.
260
256
  *
261
- * @param direction - Transfer direction (AV_HWFRAME_TRANSFER_DIRECTION_*)
257
+ * Direct mapping to av_hwframe_transfer_get_formats().
262
258
  *
263
- * @returns Array of pixel formats or error code:
264
- * - Array: List of supported formats
265
- * - <0: AVERROR on failure
259
+ * @param direction - Transfer direction (FROM/TO hardware)
260
+ * @returns Array of supported formats, or error code:
261
+ * - AVERROR_ENOSYS: Query not supported
262
+ * - AVERROR_ENOMEM: Memory allocation failure
266
263
  *
267
264
  * @example
268
265
  * ```typescript
269
- * // Get formats for downloading from hardware
266
+ * import { AV_HWFRAME_TRANSFER_DIRECTION_FROM } from 'node-av/constants';
267
+ *
270
268
  * const formats = frames.transferGetFormats(AV_HWFRAME_TRANSFER_DIRECTION_FROM);
271
269
  * if (Array.isArray(formats)) {
272
270
  * console.log('Supported download formats:', formats);
273
- * }
274
- *
275
- * // Get formats for uploading to hardware
276
- * const formats2 = frames.transferGetFormats(AV_HWFRAME_TRANSFER_DIRECTION_TO);
277
- * if (Array.isArray(formats2)) {
278
- * console.log('Supported upload formats:', formats2);
271
+ * } else {
272
+ * console.error('Error querying formats:', formats);
279
273
  * }
280
274
  * ```
281
275
  */
282
276
  transferGetFormats(direction: AVHWFrameTransferDirection): AVPixelFormat[] | number;
283
277
  /**
284
- * Map a hardware frame.
278
+ * Map hardware frame to system memory.
285
279
  *
286
- * Direct mapping to av_hwframe_map()
280
+ * Creates a mapping of hardware frame data accessible from CPU.
281
+ * More efficient than transferData() for read-only access.
287
282
  *
288
- * This has a number of different possible effects, depending on the format
289
- * and origin of the src and dst frames. On input, src should be a usable
290
- * frame with valid hardware/software format and allocated data.
291
- *
292
- * @param dst - Destination frame
293
- * @param src - Source frame to map
294
- * @param flags - Combination of AV_HWFRAME_MAP_* flags
283
+ * Direct mapping to av_hwframe_map().
295
284
  *
285
+ * @param dst - Destination frame for mapped data
286
+ * @param src - Hardware frame to map
287
+ * @param flags - Mapping flags (AV_HWFRAME_MAP_*)
296
288
  * @returns 0 on success, negative AVERROR on error:
297
- * - 0: Success
298
- * - AVERROR(ENOSYS): Mapping not supported
299
- * - AVERROR(EINVAL): Invalid parameters
300
- * - <0: Other errors
289
+ * - AVERROR_EINVAL: Invalid parameters
290
+ * - AVERROR_ENOSYS: Mapping not supported
301
291
  *
302
292
  * @example
303
293
  * ```typescript
294
+ * import { FFmpegError } from 'node-av';
295
+ * import { AV_HWFRAME_MAP_READ } from 'node-av/constants';
296
+ *
304
297
  * const mappedFrame = new Frame();
305
- * mappedFrame.alloc();
306
298
  * const ret = frames.map(mappedFrame, hwFrame, AV_HWFRAME_MAP_READ);
307
- * if (ret < 0) {
308
- * throw new FFmpegError(ret);
309
- * }
310
- * // mappedFrame now provides CPU access to hwFrame
299
+ * FFmpegError.throwIfError(ret, 'map');
300
+ * // Can now read hwFrame data through mappedFrame
311
301
  * ```
302
+ *
303
+ * @see {@link transferData} For full data copy
312
304
  */
313
305
  map(dst: Frame, src: Frame, flags?: number): number;
314
306
  /**
315
- * Create a new frame context derived from an existing one.
307
+ * Create derived frames context.
316
308
  *
317
- * Direct mapping to av_hwframe_ctx_create_derived()
309
+ * Creates a new frames context derived from another,
310
+ * potentially on a different device.
318
311
  *
319
- * @param format - Pixel format for the derived context
320
- * @param derivedDevice - Device context for the derived frames
321
- * @param source - Source frames context
322
- * @param flags - Currently unused, should be 0
312
+ * Direct mapping to av_hwframe_ctx_create_derived().
323
313
  *
314
+ * @param format - Pixel format for derived frames
315
+ * @param derivedDevice - Target device context
316
+ * @param source - Source frames context
317
+ * @param flags - Creation flags
324
318
  * @returns 0 on success, negative AVERROR on error:
325
- * - 0: Success
326
- * - AVERROR(ENOSYS): Derivation not supported
327
- * - AVERROR(EINVAL): Invalid parameters
328
- * - <0: Other errors
319
+ * - AVERROR_EINVAL: Invalid parameters
320
+ * - AVERROR_ENOSYS: Derivation not supported
321
+ * - AVERROR_ENOMEM: Memory allocation failure
329
322
  *
330
323
  * @example
331
324
  * ```typescript
332
- * const derived = new HardwareFramesContext();
333
- * const ret = derived.createDerived(
334
- * AV_PIX_FMT_NV12,
335
- * derivedDevice,
336
- * sourceFrames,
325
+ * import { FFmpegError } from 'node-av';
326
+ * import { AV_PIX_FMT_VULKAN } from 'node-av/constants';
327
+ *
328
+ * const derivedFrames = new HardwareFramesContext();
329
+ * const ret = derivedFrames.createDerived(
330
+ * AV_PIX_FMT_VULKAN,
331
+ * vulkanDevice,
332
+ * cudaFrames,
337
333
  * 0
338
334
  * );
339
- * if (ret < 0) {
340
- * throw new FFmpegError(ret);
341
- * }
335
+ * FFmpegError.throwIfError(ret, 'createDerived');
342
336
  * ```
343
337
  */
344
338
  createDerived(format: AVPixelFormat, derivedDevice: HardwareDeviceContext, source: HardwareFramesContext, flags?: number): number;
345
339
  /**
346
- * Get the native FFmpeg AVHWFramesContext pointer.
340
+ * Get the underlying native HardwareFramesContext object.
347
341
  *
348
- * @internal For use by other wrapper classes
349
- * @returns The underlying native hardware frames context object
342
+ * @returns The native HardwareFramesContext binding object
343
+ *
344
+ * @internal
350
345
  */
351
346
  getNative(): NativeHardwareFramesContext;
352
347
  /**
@@ -357,18 +352,13 @@ export declare class HardwareFramesContext implements Disposable, NativeWrapper<
357
352
  *
358
353
  * @example
359
354
  * ```typescript
360
- * import { HardwareFramesContext, FFmpegError } from 'node-av';
361
- *
362
355
  * {
363
356
  * using frames = new HardwareFramesContext();
364
357
  * frames.alloc(device);
365
- * const ret = frames.init();
366
- * FFmpegError.throwIfError(ret, 'init');
367
- * // ... use frames
358
+ * frames.init();
359
+ * // Use frames...
368
360
  * } // Automatically freed when leaving scope
369
361
  * ```
370
- *
371
- * @see {@link free} For manual cleanup
372
362
  */
373
363
  [Symbol.dispose](): void;
374
364
  }