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.
- package/README.md +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -59
- 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
|
|
9
|
-
*
|
|
10
|
-
*
|
|
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 {
|
|
17
|
-
* import {
|
|
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
|
-
*
|
|
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 =
|
|
29
|
+
* frames.initialPoolSize = 20; // Pre-allocate 20 frames
|
|
33
30
|
*
|
|
34
|
-
*
|
|
31
|
+
* frames.alloc(device);
|
|
35
32
|
* const ret = frames.init();
|
|
36
|
-
* FFmpegError.throwIfError(ret, 'init
|
|
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
|
|
45
|
-
* const
|
|
46
|
-
*
|
|
47
|
-
*
|
|
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
|
-
* //
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
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
|
|
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
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
134
|
-
*
|
|
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
|
|
108
|
+
* Associated hardware device.
|
|
140
109
|
*
|
|
141
|
-
*
|
|
110
|
+
* Reference to the device context this frames context belongs to.
|
|
111
|
+
* Automatically set when calling alloc().
|
|
142
112
|
*
|
|
143
|
-
*
|
|
113
|
+
* Direct mapping to AVHWFramesContext->device_ref.
|
|
144
114
|
*/
|
|
145
115
|
get deviceRef(): HardwareDeviceContext | null;
|
|
146
116
|
/**
|
|
147
|
-
* Allocate
|
|
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
|
-
*
|
|
124
|
+
* @param device - Hardware device context to use
|
|
150
125
|
*
|
|
151
|
-
* @
|
|
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
|
-
* @
|
|
140
|
+
* @see {@link init} To initialize after allocation
|
|
165
141
|
*/
|
|
166
142
|
alloc(device: HardwareDeviceContext): void;
|
|
167
143
|
/**
|
|
168
|
-
*
|
|
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
|
-
* -
|
|
174
|
-
* -
|
|
175
|
-
* -
|
|
176
|
-
* -
|
|
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
|
-
*
|
|
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
|
|
170
|
+
* Free hardware frames context.
|
|
189
171
|
*
|
|
190
|
-
*
|
|
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
|
-
* //
|
|
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
|
|
187
|
+
* Allocate hardware frame from pool.
|
|
201
188
|
*
|
|
202
|
-
*
|
|
189
|
+
* Gets a frame from the hardware frame pool.
|
|
190
|
+
* The frame will have hardware-backed storage.
|
|
203
191
|
*
|
|
204
|
-
*
|
|
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
|
-
* -
|
|
209
|
-
* -
|
|
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
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* const
|
|
218
|
-
*
|
|
219
|
-
*
|
|
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
|
-
*
|
|
214
|
+
* Transfer data between hardware and system memory.
|
|
227
215
|
*
|
|
228
|
-
*
|
|
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 -
|
|
233
|
-
*
|
|
234
|
-
*
|
|
235
|
-
* -
|
|
236
|
-
* -
|
|
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
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
* const
|
|
250
|
-
*
|
|
251
|
-
*
|
|
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
|
|
252
|
+
* Get supported transfer formats.
|
|
258
253
|
*
|
|
259
|
-
*
|
|
254
|
+
* Returns pixel formats supported for frame transfer
|
|
255
|
+
* in the specified direction.
|
|
260
256
|
*
|
|
261
|
-
*
|
|
257
|
+
* Direct mapping to av_hwframe_transfer_get_formats().
|
|
262
258
|
*
|
|
263
|
-
* @
|
|
264
|
-
*
|
|
265
|
-
* -
|
|
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
|
-
*
|
|
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
|
|
278
|
+
* Map hardware frame to system memory.
|
|
285
279
|
*
|
|
286
|
-
*
|
|
280
|
+
* Creates a mapping of hardware frame data accessible from CPU.
|
|
281
|
+
* More efficient than transferData() for read-only access.
|
|
287
282
|
*
|
|
288
|
-
*
|
|
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
|
-
* -
|
|
298
|
-
* -
|
|
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
|
-
*
|
|
308
|
-
*
|
|
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
|
|
307
|
+
* Create derived frames context.
|
|
316
308
|
*
|
|
317
|
-
*
|
|
309
|
+
* Creates a new frames context derived from another,
|
|
310
|
+
* potentially on a different device.
|
|
318
311
|
*
|
|
319
|
-
*
|
|
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
|
-
* -
|
|
326
|
-
* -
|
|
327
|
-
* -
|
|
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
|
-
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
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
|
-
*
|
|
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
|
|
340
|
+
* Get the underlying native HardwareFramesContext object.
|
|
347
341
|
*
|
|
348
|
-
* @
|
|
349
|
-
*
|
|
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
|
-
*
|
|
366
|
-
*
|
|
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
|
}
|