node-av-lgpl 0.0.0 → 7.1.0-beta.2

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 +384 -0
  283. package/dist/lib/stream.js +525 -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,677 @@
1
+ import { Codec } from '../lib/codec.js';
2
+ import { HardwareDeviceContext } from '../lib/hardware-device-context.js';
3
+ import { Stream } from '../lib/stream.js';
4
+ import type { AVCodecID, AVHWDeviceType, AVPixelFormat, FFDecoderCodec, FFEncoderCodec, FFHWDeviceType } from '../constants/index.js';
5
+ /**
6
+ * Base codec names supported across different hardware types.
7
+ */
8
+ export type BaseCodecName = 'av1' | 'h264' | 'hevc' | 'h263' | 'mpeg2' | 'mpeg4' | 'vp8' | 'vp9' | 'mjpeg' | 'prores';
9
+ /**
10
+ * Hardware acceleration configuration options.
11
+ */
12
+ export interface HardwareOptions {
13
+ /**
14
+ * Device path or index (e.g., '0' for first GPU).
15
+ */
16
+ device?: string;
17
+ /**
18
+ * Device initialization options.
19
+ */
20
+ options?: Record<string, string>;
21
+ /**
22
+ * Preferred hardware type(s) for {@link HardwareContext.auto}, in priority order.
23
+ *
24
+ * The given types are tested first (and only kept if actually available),
25
+ * before falling back to the platform default order. Use it to prioritise one
26
+ * backend over another - e.g. `prefer: AV_HWDEVICE_TYPE_VAAPI` to pick VAAPI
27
+ * ahead of QSV on Intel. Ignored by {@link HardwareContext.create}.
28
+ *
29
+ * @example
30
+ * ```typescript
31
+ * const hw = HardwareContext.auto({ prefer: AV_HWDEVICE_TYPE_VAAPI });
32
+ * ```
33
+ */
34
+ prefer?: AVHWDeviceType | AVHWDeviceType[];
35
+ }
36
+ /**
37
+ * High-level hardware acceleration management.
38
+ *
39
+ * Provides automatic detection and configuration of hardware acceleration for media processing.
40
+ * Manages device contexts for GPU-accelerated encoding and decoding operations.
41
+ * Supports various hardware types including VideoToolbox, CUDA, VAAPI, D3D11VA, and more.
42
+ * Essential for high-performance video processing with reduced CPU usage.
43
+ *
44
+ * @example
45
+ * ```typescript
46
+ * import { HardwareContext } from 'node-av/api';
47
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
48
+ *
49
+ * // Auto-detect best available hardware
50
+ * const hw = HardwareContext.auto();
51
+ * if (hw) {
52
+ * console.log(`Using hardware: ${hw.deviceTypeName}`);
53
+ * const decoder = await Decoder.create(stream, { hardware: hw });
54
+ * }
55
+ * ```
56
+ *
57
+ * @example
58
+ * ```typescript
59
+ * // Use specific hardware type
60
+ * const hw = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
61
+ * const encoderCodec = hw?.getEncoderCodec('h264') ?? FF_ENCODER_LIBX264;
62
+ * const encoder = await Encoder.create(encoderCodec, { ... });
63
+ * hw.dispose();
64
+ * ```
65
+ *
66
+ * @see {@link Decoder} For hardware-accelerated decoding
67
+ * @see {@link Encoder} For hardware-accelerated encoding
68
+ */
69
+ export declare class HardwareContext implements Disposable {
70
+ private static _autoTested;
71
+ private static _autoCachedType;
72
+ private static _rockchip;
73
+ private _deviceContext;
74
+ private _deviceType;
75
+ private _deviceTypeName;
76
+ private _devicePixelFormat;
77
+ private _isDisposed;
78
+ /**
79
+ * @param deviceContext - Initialized hardware device context
80
+ *
81
+ * @param deviceType - Hardware device type enum
82
+ *
83
+ * @param deviceTypeName - Human-readable device type name
84
+ *
85
+ * @internal
86
+ */
87
+ private constructor();
88
+ /**
89
+ * Auto-detect and create the best available hardware context.
90
+ *
91
+ * Tries hardware types in order of preference based on platform.
92
+ * Returns null if no hardware acceleration is available.
93
+ * Platform-specific preference order ensures optimal performance.
94
+ *
95
+ * @param options - Optional hardware configuration
96
+ *
97
+ * @returns Hardware context or null if unavailable
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * const hw = HardwareContext.auto();
102
+ * if (hw) {
103
+ * console.log(`Auto-detected: ${hw.deviceTypeName}`);
104
+ * // Use for decoder/encoder
105
+ * }
106
+ * ```
107
+ *
108
+ * @example
109
+ * ```typescript
110
+ * // With specific device
111
+ * const hw = HardwareContext.auto({
112
+ * deviceName: '/dev/dri/renderD128'
113
+ * });
114
+ * ```
115
+ *
116
+ * @example
117
+ * ```typescript
118
+ * // Prioritise VAAPI over the platform default (e.g. ahead of QSV on Intel)
119
+ * const hw = HardwareContext.auto({ prefer: AV_HWDEVICE_TYPE_VAAPI });
120
+ * ```
121
+ *
122
+ * @see {@link create} For specific hardware type
123
+ * @see {@link listAvailable} To check available types
124
+ */
125
+ static auto(options?: HardwareOptions): HardwareContext | null;
126
+ /**
127
+ * Reset the auto-detection cache.
128
+ *
129
+ * Forces the next call to auto() to re-test hardware availability.
130
+ * Useful for testing or if hardware availability may have changed.
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * HardwareContext.resetAutoCache();
135
+ * const hw = HardwareContext.auto(); // Will re-test
136
+ * ```
137
+ */
138
+ static resetAutoCache(): void;
139
+ /**
140
+ * Create a hardware context for a specific device type.
141
+ *
142
+ * Creates and initializes a hardware device context.
143
+ * Throws if the device type is not supported or initialization fails.
144
+ *
145
+ * Direct mapping to av_hwdevice_ctx_create().
146
+ *
147
+ * @param deviceType - Hardware device type from AVHWDeviceType
148
+ *
149
+ * @param device - Optional device specifier (e.g., GPU index, device path)
150
+ *
151
+ * @param options - Optional device initialization options
152
+ *
153
+ * @returns Initialized hardware context or null if HardwareContext could not be created
154
+ *
155
+ * @example
156
+ * ```typescript
157
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
158
+ *
159
+ * // CUDA with specific GPU
160
+ * const cuda = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA, '0');
161
+ * ```
162
+ *
163
+ * @example
164
+ * ```typescript
165
+ * import { AV_HWDEVICE_TYPE_VAAPI } from 'node-av/constants';
166
+ *
167
+ * // VAAPI with render device
168
+ * const vaapi = HardwareContext.create(
169
+ * AV_HWDEVICE_TYPE_VAAPI,
170
+ * '/dev/dri/renderD128'
171
+ * );
172
+ * ```
173
+ *
174
+ * @see {@link auto} For automatic detection
175
+ * @see {@link HardwareDeviceContext} For low-level API
176
+ */
177
+ static create(deviceType: AVHWDeviceType | FFHWDeviceType, device?: string, options?: Record<string, string>): HardwareContext | null;
178
+ /**
179
+ * Create a derived hardware device context.
180
+ *
181
+ * Creates a new hardware context derived from an existing one.
182
+ * Allows creating contexts on different device types that can share
183
+ * memory or resources with the source device. Useful for cross-device
184
+ * pipelines (e.g., VAAPI → OpenCL, CUDA → Vulkan).
185
+ *
186
+ * Direct mapping to av_hwdevice_ctx_create_derived().
187
+ *
188
+ * @param source - Source hardware context to derive from
189
+ *
190
+ * @param targetType - Target device type to create
191
+ *
192
+ * @returns New hardware context or null if derivation fails
193
+ *
194
+ * @example
195
+ * ```typescript
196
+ * import { AV_HWDEVICE_TYPE_VAAPI, AV_HWDEVICE_TYPE_OPENCL } from 'node-av/constants';
197
+ *
198
+ * // Create VAAPI device for decoding
199
+ * const vaapi = HardwareContext.create(AV_HWDEVICE_TYPE_VAAPI);
200
+ *
201
+ * // Derive OpenCL device for filtering (shares memory with VAAPI)
202
+ * const opencl = HardwareContext.derive(vaapi, AV_HWDEVICE_TYPE_OPENCL);
203
+ *
204
+ * if (opencl) {
205
+ * // Decode with VAAPI
206
+ * const decoder = await Decoder.create(stream, { hardware: vaapi });
207
+ *
208
+ * // Filter with OpenCL (overrides frame's VAAPI context)
209
+ * const filter = FilterAPI.create('program_opencl=...', { hardware: opencl });
210
+ *
211
+ * for await (const frame of decoder.frames()) {
212
+ * // frame has VAAPI context, but filter uses OpenCL
213
+ * const filtered = await filter.apply(frame);
214
+ * }
215
+ * }
216
+ * ```
217
+ *
218
+ * @example
219
+ * ```typescript
220
+ * // CUDA → Vulkan derivation
221
+ * const cuda = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
222
+ * const vulkan = HardwareContext.derive(cuda, AV_HWDEVICE_TYPE_VULKAN);
223
+ * ```
224
+ *
225
+ * @see {@link create} For creating independent device
226
+ */
227
+ static derive(source: HardwareContext, targetType: AVHWDeviceType | FFHWDeviceType): HardwareContext | null;
228
+ /**
229
+ * List all available hardware device types.
230
+ *
231
+ * Enumerates all hardware types supported by the FFmpeg build.
232
+ * Useful for checking hardware capabilities at runtime.
233
+ *
234
+ * Direct mapping to av_hwdevice_iterate_types().
235
+ *
236
+ * @returns Array of available device type names
237
+ *
238
+ * @example
239
+ * ```typescript
240
+ * const available = HardwareContext.listAvailable();
241
+ * console.log('Available hardware:', available.join(', '));
242
+ * // Output: "cuda, vaapi, videotoolbox"
243
+ * ```
244
+ *
245
+ * @see {@link auto} For automatic selection
246
+ */
247
+ static listAvailable(): string[];
248
+ /**
249
+ * Get the hardware device context.
250
+ *
251
+ * Used internally by encoders and decoders for hardware acceleration.
252
+ * Can be assigned to CodecContext.hwDeviceCtx.
253
+ *
254
+ * @example
255
+ * ```typescript
256
+ * codecContext.hwDeviceCtx = hw.deviceContext;
257
+ * ```
258
+ */
259
+ get deviceContext(): HardwareDeviceContext;
260
+ /**
261
+ * Get the device type enum value.
262
+ *
263
+ * @example
264
+ * ```typescript
265
+ * if (hw.deviceType === AV_HWDEVICE_TYPE_CUDA) {
266
+ * console.log('Using NVIDIA GPU');
267
+ * }
268
+ * ```
269
+ */
270
+ get deviceType(): AVHWDeviceType;
271
+ /**
272
+ * Get the hardware device type name.
273
+ *
274
+ * Human-readable device type string.
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * console.log(`Hardware type: ${hw.deviceTypeName}`);
279
+ * // Output: "cuda" or "videotoolbox" etc.
280
+ * ```
281
+ */
282
+ get deviceTypeName(): FFHWDeviceType;
283
+ /**
284
+ * Get the device pixel format.
285
+ *
286
+ * Hardware-specific pixel format for frame allocation.
287
+ *
288
+ * @example
289
+ * ```typescript
290
+ * frame.format = hw.devicePixelFormat;
291
+ * ```
292
+ */
293
+ get devicePixelFormat(): AVPixelFormat;
294
+ /**
295
+ * Check if this hardware context has been disposed.
296
+ *
297
+ * @example
298
+ * ```typescript
299
+ * if (!hw.isDisposed) {
300
+ * hw.dispose();
301
+ * }
302
+ * ```
303
+ */
304
+ get isDisposed(): boolean;
305
+ /**
306
+ * Get hardware frame constraints.
307
+ *
308
+ * Returns the resolution limits and supported pixel formats for this hardware device.
309
+ * Essential for validating encoder/decoder parameters before initialization.
310
+ *
311
+ * Direct mapping to av_hwdevice_get_hwframe_constraints().
312
+ *
313
+ * @param hwconfig - Optional hardware configuration pointer
314
+ *
315
+ * @returns Constraints object with resolution limits and formats, or null if not available
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const hw = HardwareContext.auto();
320
+ * if (hw) {
321
+ * const constraints = hw.getFrameConstraints();
322
+ * if (constraints) {
323
+ * console.log(`Resolution: ${constraints.minWidth}x${constraints.minHeight} to ${constraints.maxWidth}x${constraints.maxHeight}`);
324
+ * console.log('Hardware formats:', constraints.validHwFormats);
325
+ * console.log('Software formats:', constraints.validSwFormats);
326
+ * }
327
+ * }
328
+ * ```
329
+ *
330
+ * @example
331
+ * ```typescript
332
+ * import { AV_HWDEVICE_TYPE_VIDEOTOOLBOX } from 'node-av/constants';
333
+ *
334
+ * // VideoToolbox has resolution limits
335
+ * const hw = HardwareContext.create(AV_HWDEVICE_TYPE_VIDEOTOOLBOX);
336
+ * const constraints = hw?.getFrameConstraints();
337
+ * if (constraints && (width > constraints.maxWidth || height > constraints.maxHeight)) {
338
+ * console.log('Resolution exceeds hardware limits, falling back to software encoder');
339
+ * }
340
+ * ```
341
+ *
342
+ * @see {@link HardwareDeviceContext.getHwframeConstraints} For low-level API
343
+ */
344
+ getFrameConstraints(hwconfig?: bigint): {
345
+ validHwFormats?: number[];
346
+ validSwFormats?: number[];
347
+ minWidth: number;
348
+ minHeight: number;
349
+ maxWidth: number;
350
+ maxHeight: number;
351
+ } | null;
352
+ /**
353
+ * Check if this hardware type supports a specific codec.
354
+ *
355
+ * Queries FFmpeg's codec configurations to verify hardware support.
356
+ * Checks both decoder and encoder support based on parameters.
357
+ *
358
+ * Direct mapping to avcodec_get_hw_config().
359
+ *
360
+ * @param codecId - Codec ID from AVCodecID enum
361
+ *
362
+ * @param isEncoder - Check for encoder support (default: decoder)
363
+ *
364
+ * @returns true if codec is supported
365
+ *
366
+ * @example
367
+ * ```typescript
368
+ * import { AV_CODEC_ID_H264 } from 'node-av/constants';
369
+ *
370
+ * if (hw.supportsCodec(AV_CODEC_ID_H264, true)) {
371
+ * // Can use hardware H.264 encoder
372
+ * }
373
+ * ```
374
+ *
375
+ * @see {@link findSupportedCodecs} For all supported codecs
376
+ */
377
+ supportsCodec(codecId: AVCodecID, isEncoder?: boolean): boolean;
378
+ /**
379
+ * Check if this hardware supports a specific pixel format for a codec.
380
+ *
381
+ * Verifies pixel format compatibility with hardware codec.
382
+ * Important for ensuring format compatibility in pipelines.
383
+ *
384
+ * @param codecId - Codec ID from AVCodecID enum
385
+ *
386
+ * @param pixelFormat - Pixel format to check
387
+ *
388
+ * @param isEncoder - Check for encoder (default: decoder)
389
+ *
390
+ * @returns true if pixel format is supported
391
+ *
392
+ * @example
393
+ * ```typescript
394
+ * import { AV_CODEC_ID_H264, AV_PIX_FMT_NV12 } from 'node-av/constants';
395
+ *
396
+ * if (hw.supportsPixelFormat(AV_CODEC_ID_H264, AV_PIX_FMT_NV12)) {
397
+ * // Can use NV12 format with H.264
398
+ * }
399
+ * ```
400
+ *
401
+ * @see {@link supportsCodec} For basic codec support
402
+ */
403
+ supportsPixelFormat(codecId: AVCodecID, pixelFormat: AVPixelFormat, isEncoder?: boolean): boolean;
404
+ /**
405
+ * Get the appropriate encoder codec for a given base codec name.
406
+ *
407
+ * Maps generic codec names to hardware-specific encoder implementations.
408
+ * Returns null if no hardware encoder is available for the codec.
409
+ * Automatically tests encoder viability before returning.
410
+ *
411
+ * @param codecOrStream - Generic codec name (e.g., 'h264', 'hevc', 'av1'), AVCodecID or Stream
412
+ *
413
+ * @param validate - Whether to validate encoder by testing (default: false)
414
+ *
415
+ * @returns Hardware encoder codec or null if unsupported
416
+ *
417
+ * @example
418
+ * ```typescript
419
+ * const encoderCodec = hw.getEncoderCodec('h264');
420
+ * if (encoderCodec) {
421
+ * console.log(`Using encoder: ${encoderCodec.name}`);
422
+ * // e.g., "h264_nvenc" for CUDA
423
+ * }
424
+ * ```
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * // Use with Encoder.create
429
+ * const codec = hw.getEncoderCodec('hevc');
430
+ * if (codec) {
431
+ * const encoder = await Encoder.create(codec, { ... });
432
+ * }
433
+ * ```
434
+ *
435
+ * @see {@link Encoder.create} For using the codec
436
+ */
437
+ getEncoderCodec(codecOrStream: BaseCodecName | AVCodecID | Stream, validate?: boolean): Codec | null;
438
+ /**
439
+ * Get the appropriate decoder codec for a given base codec name.
440
+ *
441
+ * Maps generic codec names to hardware-specific decoder implementations.
442
+ * Returns null if no hardware decoder is available for the codec.
443
+ * Automatically searches for decoders that support this hardware device type.
444
+ *
445
+ * @param codec - Generic codec name (e.g., 'h264', 'hevc', 'av1') or AVCodecID
446
+ *
447
+ * @returns Hardware decoder codec or null if unsupported
448
+ *
449
+ * @example
450
+ * ```typescript
451
+ * const decoderCodec = hw.getDecoderCodec('hevc');
452
+ * if (decoderCodec) {
453
+ * console.log(`Using decoder: ${decoderCodec.name}`);
454
+ * // e.g., "hevc_qsv" for QSV
455
+ * }
456
+ * ```
457
+ *
458
+ * @example
459
+ * ```typescript
460
+ * // Use with Decoder.create
461
+ * const codec = hw.getDecoderCodec(AV_CODEC_ID_H264);
462
+ * if (codec) {
463
+ * const decoder = await Decoder.create(stream, { hardware: hw });
464
+ * }
465
+ * ```
466
+ *
467
+ * @see {@link Decoder.create} For using the codec
468
+ * @see {@link getEncoderCodec} For hardware encoders
469
+ */
470
+ getDecoderCodec(codec: BaseCodecName | AVCodecID): Codec | null;
471
+ /**
472
+ * Test if hardware acceleration is working by decoding a test frame.
473
+ *
474
+ * Creates a simple decoder and attempts to decode with hardware acceleration.
475
+ * Returns true if hardware decoding succeeds, false otherwise.
476
+ * Useful for validating hardware setup before processing.
477
+ *
478
+ * @param codecId - Codec ID to test (default: H.264)
479
+ *
480
+ * @returns Promise that resolves to true if hardware works
481
+ *
482
+ * @example
483
+ * ```typescript
484
+ * const hw = HardwareContext.auto();
485
+ * if (hw && await hw.testDecoder()) {
486
+ * console.log('Hardware acceleration working!');
487
+ * // Proceed with hardware decoding/encoding
488
+ * } else {
489
+ * console.log('Hardware acceleration not available');
490
+ * // Fall back to software
491
+ * }
492
+ * ```
493
+ *
494
+ * @example
495
+ * ```typescript
496
+ * // Test specific hardware
497
+ * const cuda = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
498
+ * if (cuda && await cuda.testDecoder()) {
499
+ * console.log('CUDA acceleration works');
500
+ * }
501
+ * ```
502
+ *
503
+ * @see {@link supportsCodec} For checking codec support
504
+ */
505
+ testDecoder(codecId?: AVCodecID): boolean;
506
+ /**
507
+ * Test if hardware encoding works with a specific codec pair.
508
+ *
509
+ * Attempts to decode and re-encode a test frame using hardware acceleration.
510
+ * Validates both decoding and encoding paths for the given codecs.
511
+ *
512
+ * @param decoderCodec - Codec name, ID, or instance to use for decoding
513
+ *
514
+ * @param encoderCodec - Codec name or instance to use for encoding
515
+ *
516
+ * @returns true if both decoding and encoding succeed
517
+ *
518
+ * @example
519
+ * ```typescript
520
+ * import { AV_CODEC_ID_H264 } from 'node-av/constants';
521
+ *
522
+ * const hw = HardwareContext.auto();
523
+ * if (hw && hw.testEncoder(AV_CODEC_ID_H264, AV_CODEC_ID_H264)) {
524
+ * console.log('Hardware H.264 encoding works!');
525
+ * }
526
+ * ```
527
+ *
528
+ * @see {@link getEncoderCodec} For obtaining hardware encoder codec
529
+ */
530
+ testEncoder(decoderCodec: FFDecoderCodec | Codec | AVCodecID, encoderCodec: FFEncoderCodec | Codec): boolean;
531
+ /**
532
+ * Find all codecs that support this hardware device.
533
+ *
534
+ * Iterates through all available codecs and checks hardware compatibility.
535
+ * Useful for discovering available hardware acceleration options.
536
+ *
537
+ * Direct mapping to av_codec_iterate() with hardware config checks.
538
+ *
539
+ * @param isEncoder - Find encoders (true) or decoders (false)
540
+ *
541
+ * @returns Array of codec names that support this hardware
542
+ *
543
+ * @example
544
+ * ```typescript
545
+ * const decoders = hw.findSupportedCodecs(false);
546
+ * console.log('Hardware decoders:', decoders);
547
+ * // ["h264_cuvid", "hevc_cuvid", ...]
548
+ *
549
+ * const encoders = hw.findSupportedCodecs(true);
550
+ * console.log('Hardware encoders:', encoders);
551
+ * // ["h264_nvenc", "hevc_nvenc", ...]
552
+ * ```
553
+ *
554
+ * @see {@link supportsCodec} For checking specific codec
555
+ */
556
+ findSupportedCodecs(isEncoder?: boolean): string[];
557
+ /**
558
+ * Clean up and free hardware resources.
559
+ *
560
+ * Releases the hardware device context.
561
+ * Safe to call multiple times.
562
+ * Automatically called by Symbol.dispose.
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * const hw = HardwareContext.auto();
567
+ * try {
568
+ * // Use hardware
569
+ * } finally {
570
+ * hw?.dispose();
571
+ * }
572
+ * ```
573
+ *
574
+ * @see {@link Symbol.dispose} For automatic cleanup
575
+ */
576
+ dispose(): void;
577
+ /**
578
+ * Test hardware decoding with a specific codec.
579
+ *
580
+ * @param decoderCodec - Decoder codec name, ID, or instance to test
581
+ *
582
+ * @param encoderCodec - Optional encoder codec name or instance to test
583
+ *
584
+ * @param useFilter - Whether to test hwdownload filter (default: true)
585
+ *
586
+ * @returns true if decoding succeeds
587
+ *
588
+ * @internal
589
+ */
590
+ private testCodec;
591
+ /**
592
+ * Map AVCodecID to base codec name for hardware encoder lookup.
593
+ *
594
+ * Converts codec IDs to generic codec names used for encoder naming.
595
+ * Used internally to find hardware-specific encoder implementations.
596
+ *
597
+ * @param codecId - AVCodecID enum value
598
+ *
599
+ * @returns Base codec name or null if unsupported
600
+ *
601
+ * @internal
602
+ */
603
+ private getBaseCodecName;
604
+ /**
605
+ * Map base codec name to AVCodecID for internal use.
606
+ *
607
+ * Converts generic codec names to AVCodecID enum values.
608
+ * Used internally for codec testing and validation.
609
+ *
610
+ * @param codecBaseName - Base codec name string
611
+ *
612
+ * @returns Corresponding AVCodecID or null if unsupported
613
+ *
614
+ * @internal
615
+ */
616
+ private getCodecIDFromBaseName;
617
+ /**
618
+ * Get the hardware decoder pixel format for this device type.
619
+ *
620
+ * Maps device types to their corresponding pixel formats.
621
+ * Used internally for frame format configuration.
622
+ *
623
+ * @returns Hardware-specific pixel format
624
+ *
625
+ * @internal
626
+ */
627
+ private getHardwareDecoderPixelFormat;
628
+ /**
629
+ * Create hardware context from device type.
630
+ *
631
+ * Internal factory method using av_hwdevice_ctx_create().
632
+ *
633
+ * @param deviceType - AVHWDeviceType enum value
634
+ *
635
+ * @param device - Optional device specifier
636
+ *
637
+ * @param options - Optional device options
638
+ *
639
+ * @returns Hardware context or null if creation fails
640
+ *
641
+ * @internal
642
+ */
643
+ private static createFromType;
644
+ private static isRockchip;
645
+ /**
646
+ * Get platform-specific preference order for hardware types.
647
+ *
648
+ * Returns available hardware types sorted by platform preference. Any
649
+ * caller-supplied preferred types are placed first (in the given order),
650
+ * followed by the platform default order and finally any remaining available
651
+ * types. Unavailable types are dropped.
652
+ *
653
+ * @param prefer - Hardware types to try first, in priority order
654
+ *
655
+ * @returns Array of AVHWDeviceType values in preference order
656
+ *
657
+ * @internal
658
+ */
659
+ private static getPreferenceOrder;
660
+ /**
661
+ * Dispose of hardware context.
662
+ *
663
+ * Implements Disposable interface for automatic cleanup.
664
+ * Equivalent to calling dispose().
665
+ *
666
+ * @example
667
+ * ```typescript
668
+ * {
669
+ * using hw = HardwareContext.auto();
670
+ * // Use hardware context...
671
+ * } // Automatically disposed
672
+ * ```
673
+ *
674
+ * @see {@link dispose} For manual cleanup
675
+ */
676
+ [Symbol.dispose](): void;
677
+ }