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,746 @@
1
+ import { AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX, AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX } from '../constants/constants.js';
2
+ import { bindings } from './binding.js';
3
+ import { Rational } from './rational.js';
4
+ import { avGetHardwareDeviceTypeFromName } from './utilities.js';
5
+ /**
6
+ * Codec descriptor for audio/video encoding and decoding.
7
+ *
8
+ * Represents an encoder or decoder implementation that can process media data.
9
+ * Contains codec capabilities, supported formats, and hardware acceleration information.
10
+ * Used to create codec contexts for actual encoding/decoding operations.
11
+ * Supports both software and hardware-accelerated codecs.
12
+ *
13
+ * Direct mapping to FFmpeg's AVCodec.
14
+ *
15
+ * @example
16
+ * ```typescript
17
+ * import { Codec, FFmpegError } from 'node-av';
18
+ * import { AV_CODEC_ID_H264, FF_ENCODER_LIBX264 } from 'node-av/constants';
19
+ *
20
+ * // Find decoder by ID
21
+ * const decoder = Codec.findDecoder(AV_CODEC_ID_H264);
22
+ * if (!decoder) {
23
+ * throw new Error('H.264 decoder not available');
24
+ * }
25
+ *
26
+ * // Find encoder by name
27
+ * const encoder = Codec.findEncoderByName(FF_ENCODER_LIBX264);
28
+ * if (!encoder) {
29
+ * throw new Error('libx264 encoder not available');
30
+ * }
31
+ *
32
+ * // Check capabilities
33
+ * console.log(`Codec: ${decoder.name}`);
34
+ * console.log(`Type: ${decoder.type}`);
35
+ * console.log(`Hardware: ${decoder.hasHardwareAcceleration()}`);
36
+ *
37
+ * // Get supported pixel formats
38
+ * const formats = decoder.pixelFormats;
39
+ * if (formats) {
40
+ * console.log(`Supported formats: ${formats.join(', ')}`);
41
+ * }
42
+ * ```
43
+ *
44
+ * @see [AVCodec](https://ffmpeg.org/doxygen/trunk/structAVCodec.html) - FFmpeg Doxygen
45
+ * @see {@link CodecContext} For encoding/decoding operations
46
+ */
47
+ export class Codec {
48
+ native;
49
+ /**
50
+ * @param native - The native codec instance
51
+ *
52
+ * @internal
53
+ */
54
+ constructor(native) {
55
+ this.native = native;
56
+ }
57
+ /**
58
+ * Find a decoder by codec ID.
59
+ *
60
+ * Searches for a decoder that can decode the specified codec format.
61
+ *
62
+ * Direct mapping to avcodec_find_decoder().
63
+ *
64
+ * @param id - Codec ID to search for
65
+ *
66
+ * @returns Decoder if found, null otherwise
67
+ *
68
+ * @example
69
+ * ```typescript
70
+ * import { AV_CODEC_ID_H264, AV_CODEC_ID_AAC } from 'node-av/constants';
71
+ *
72
+ * // Find H.264 video decoder
73
+ * const h264 = Codec.findDecoder(AV_CODEC_ID_H264);
74
+ * if (h264) {
75
+ * console.log(`Found: ${h264.name}`);
76
+ * }
77
+ *
78
+ * // Find AAC audio decoder
79
+ * const aac = Codec.findDecoder(AV_CODEC_ID_AAC);
80
+ * ```
81
+ *
82
+ * @see {@link findDecoderByName} To find by name
83
+ * @see {@link findEncoder} To find encoders
84
+ */
85
+ static findDecoder(id) {
86
+ const native = bindings.Codec.findDecoder(id);
87
+ return native ? new Codec(native) : null;
88
+ }
89
+ /**
90
+ * Find a decoder by name.
91
+ *
92
+ * Searches for a specific decoder implementation by name.
93
+ * Useful when multiple decoders exist for the same codec.
94
+ *
95
+ * Direct mapping to avcodec_find_decoder_by_name().
96
+ *
97
+ * @param name - Decoder name
98
+ *
99
+ * @returns Decoder if found, null otherwise
100
+ *
101
+ * @example
102
+ * ```typescript
103
+ * import { FF_DECODER_H264, FF_DECODER_H264_CUVID } from 'node-av/constants';
104
+ *
105
+ * // Find specific H.264 decoder
106
+ * const decoder = Codec.findDecoderByName(FF_DECODER_H264_CUVID);
107
+ * if (decoder) {
108
+ * console.log('Found NVIDIA hardware decoder');
109
+ * }
110
+ *
111
+ * // Find software decoder
112
+ * const sw = Codec.findDecoderByName(FF_DECODER_H264);
113
+ * ```
114
+ *
115
+ * @see {@link findDecoder} To find by codec ID
116
+ */
117
+ static findDecoderByName(name) {
118
+ const native = bindings.Codec.findDecoderByName(name);
119
+ return native ? new Codec(native) : null;
120
+ }
121
+ /**
122
+ * Find an encoder by codec ID.
123
+ *
124
+ * Searches for an encoder that can encode to the specified codec format.
125
+ *
126
+ * Direct mapping to avcodec_find_encoder().
127
+ *
128
+ * @param id - Codec ID to search for
129
+ *
130
+ * @returns Encoder if found, null otherwise
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * import { AV_CODEC_ID_H264, AV_CODEC_ID_AAC } from 'node-av/constants';
135
+ *
136
+ * // Find H.264 video encoder
137
+ * const h264 = Codec.findEncoder(AV_CODEC_ID_H264);
138
+ * if (h264) {
139
+ * console.log(`Found: ${h264.name}`);
140
+ * }
141
+ *
142
+ * // Find AAC audio encoder
143
+ * const aac = Codec.findEncoder(AV_CODEC_ID_AAC);
144
+ * ```
145
+ *
146
+ * @see {@link findEncoderByName} To find by name
147
+ * @see {@link findDecoder} To find decoders
148
+ */
149
+ static findEncoder(id) {
150
+ const native = bindings.Codec.findEncoder(id);
151
+ return native ? new Codec(native) : null;
152
+ }
153
+ /**
154
+ * Find an encoder by name.
155
+ *
156
+ * Searches for a specific encoder implementation by name.
157
+ * Useful when multiple encoders exist for the same codec.
158
+ *
159
+ * Direct mapping to avcodec_find_encoder_by_name().
160
+ *
161
+ * @param name - Encoder name
162
+ *
163
+ * @returns Encoder if found, null otherwise
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * import { FF_ENCODER_H264_NVENC, FF_ENCODER_LIBX264 } from 'node-av/constants';
168
+ *
169
+ * // Find specific H.264 encoder
170
+ * const x264 = Codec.findEncoderByName(FF_ENCODER_LIBX264);
171
+ * if (x264) {
172
+ * console.log('Found x264 encoder');
173
+ * }
174
+ *
175
+ * // Find hardware encoder
176
+ * const nvenc = Codec.findEncoderByName(FF_ENCODER_H264_NVENC);
177
+ * ```
178
+ *
179
+ * @see {@link findEncoder} To find by codec ID
180
+ */
181
+ static findEncoderByName(name) {
182
+ const native = bindings.Codec.findEncoderByName(name);
183
+ return native ? new Codec(native) : null;
184
+ }
185
+ /**
186
+ * Get list of all available codecs.
187
+ *
188
+ * Returns all registered codecs (both encoders and decoders).
189
+ *
190
+ * @returns Array of all available codecs
191
+ *
192
+ * @example
193
+ * ```typescript
194
+ * // List all codecs
195
+ * const codecs = Codec.getCodecList();
196
+ * console.log(`Total codecs: ${codecs.length}`);
197
+ *
198
+ * // Filter encoders
199
+ * const encoders = codecs.filter(c => c.isEncoder());
200
+ * console.log(`Encoders: ${encoders.length}`);
201
+ *
202
+ * // Filter hardware codecs
203
+ * const hw = codecs.filter(c => c.hasHardwareAcceleration());
204
+ * console.log(`Hardware codecs: ${hw.length}`);
205
+ * ```
206
+ *
207
+ * @see {@link iterateCodecs} For memory-efficient iteration
208
+ */
209
+ static getCodecList() {
210
+ const natives = bindings.Codec.getCodecList();
211
+ return natives.map((n) => new Codec(n));
212
+ }
213
+ /**
214
+ * Iterate through available codecs.
215
+ *
216
+ * Memory-efficient way to iterate through all codecs.
217
+ * Uses an opaque pointer to track iteration state.
218
+ *
219
+ * Direct mapping to av_codec_iterate().
220
+ *
221
+ * @param opaque - Iteration state (null to start)
222
+ *
223
+ * @returns Next codec and state, or null when done
224
+ *
225
+ * @example
226
+ * ```typescript
227
+ * // Iterate all codecs
228
+ * let iter = null;
229
+ * let result;
230
+ * while ((result = Codec.iterateCodecs(iter))) {
231
+ * console.log(`Codec: ${result.codec.name}`);
232
+ * iter = result.opaque;
233
+ * }
234
+ * ```
235
+ *
236
+ * @see {@link getCodecList} For simple array access
237
+ */
238
+ static iterateCodecs(opaque = null) {
239
+ const result = bindings.Codec.iterateCodecs(opaque);
240
+ if (!result)
241
+ return null;
242
+ return {
243
+ codec: new Codec(result.codec),
244
+ opaque: result.opaque,
245
+ };
246
+ }
247
+ /**
248
+ * Codec name.
249
+ *
250
+ * Short name identifier for the codec (e.g., 'h264', 'aac').
251
+ *
252
+ * Direct mapping to AVCodec->name.
253
+ */
254
+ get name() {
255
+ return this.native.name;
256
+ }
257
+ /**
258
+ * Codec long name.
259
+ *
260
+ * Human-readable description of the codec.
261
+ *
262
+ * Direct mapping to AVCodec->long_name.
263
+ */
264
+ get longName() {
265
+ return this.native.longName;
266
+ }
267
+ /**
268
+ * Media type.
269
+ *
270
+ * Type of media this codec processes (video, audio, subtitle, etc.).
271
+ *
272
+ * Direct mapping to AVCodec->type.
273
+ */
274
+ get type() {
275
+ return this.native.type;
276
+ }
277
+ /**
278
+ * Codec ID.
279
+ *
280
+ * Unique identifier for the codec format.
281
+ *
282
+ * Direct mapping to AVCodec->id.
283
+ */
284
+ get id() {
285
+ return this.native.id;
286
+ }
287
+ /**
288
+ * Codec capabilities.
289
+ *
290
+ * Bitfield of AV_CODEC_CAP_* flags indicating codec features.
291
+ *
292
+ * Direct mapping to AVCodec->capabilities.
293
+ */
294
+ get capabilities() {
295
+ return this.native.capabilities;
296
+ }
297
+ /**
298
+ * Check if codec has specific capabilities.
299
+ *
300
+ * Tests whether all specified capabilities are present using bitwise AND.
301
+ *
302
+ * @param caps - One or more capability values to check
303
+ *
304
+ * @returns true if all specified capabilities are present, false otherwise
305
+ *
306
+ * @example
307
+ * ```typescript
308
+ * import { AV_CODEC_CAP_HARDWARE } from 'node-av/constants';
309
+ *
310
+ * if (codec.hasCapabilities(AV_CODEC_CAP_HARDWARE)) {
311
+ * console.log('This codec supports hardware acceleration');
312
+ * }
313
+ * ```
314
+ *
315
+ * @see {@link capabilities} For direct capabilities access
316
+ */
317
+ hasCapabilities(...caps) {
318
+ for (const cap of caps) {
319
+ if ((this.native.capabilities & cap) !== cap) {
320
+ return false;
321
+ }
322
+ }
323
+ return true;
324
+ }
325
+ /**
326
+ * Maximum lowres value.
327
+ *
328
+ * Maximum value for lowres decoding (0 = no lowres support).
329
+ *
330
+ * Direct mapping to AVCodec->max_lowres.
331
+ */
332
+ get maxLowres() {
333
+ return this.native.maxLowres;
334
+ }
335
+ /**
336
+ * Supported profiles.
337
+ *
338
+ * Array of profiles this codec can handle (e.g., baseline, main, high).
339
+ *
340
+ * Direct mapping to AVCodec->profiles.
341
+ */
342
+ get profiles() {
343
+ return this.native.profiles;
344
+ }
345
+ /**
346
+ * Wrapper name.
347
+ *
348
+ * Name of the codec wrapper, if this is a wrapper codec.
349
+ *
350
+ * Direct mapping to AVCodec->wrapper_name.
351
+ */
352
+ get wrapper() {
353
+ return this.native.wrapper;
354
+ }
355
+ /**
356
+ * Supported frame rates.
357
+ *
358
+ * Array of frame rates this video codec supports.
359
+ * Null for audio codecs or if all rates are supported.
360
+ *
361
+ * Direct mapping to AVCodec->supported_framerates.
362
+ */
363
+ get supportedFramerates() {
364
+ const rates = this.native.supportedFramerates;
365
+ if (!rates)
366
+ return null;
367
+ return rates.map((r) => new Rational(r.num, r.den));
368
+ }
369
+ /**
370
+ * Supported pixel formats.
371
+ *
372
+ * Array of pixel formats this video codec supports.
373
+ * Null for audio codecs.
374
+ *
375
+ * Direct mapping to AVCodec->pix_fmts.
376
+ */
377
+ get pixelFormats() {
378
+ return this.native.pixelFormats;
379
+ }
380
+ /**
381
+ * Supported sample rates.
382
+ *
383
+ * Array of sample rates this audio codec supports.
384
+ * Null for video codecs or if all rates are supported.
385
+ *
386
+ * Direct mapping to AVCodec->supported_samplerates.
387
+ */
388
+ get supportedSamplerates() {
389
+ return this.native.supportedSamplerates;
390
+ }
391
+ /**
392
+ * Supported sample formats.
393
+ *
394
+ * Array of sample formats this audio codec supports.
395
+ * Null for video codecs.
396
+ *
397
+ * Direct mapping to AVCodec->sample_fmts.
398
+ */
399
+ get sampleFormats() {
400
+ return this.native.sampleFormats;
401
+ }
402
+ /**
403
+ * Supported channel layouts.
404
+ *
405
+ * Array of channel layouts this audio codec supports.
406
+ * Null for video codecs.
407
+ *
408
+ * Direct mapping to AVCodec->ch_layouts.
409
+ */
410
+ get channelLayouts() {
411
+ return this.native.channelLayouts;
412
+ }
413
+ /**
414
+ * Check if codec is an encoder.
415
+ *
416
+ * @returns True if this codec can encode
417
+ *
418
+ * @example
419
+ * ```typescript
420
+ * const codec = Codec.findEncoderByName(FF_ENCODER_LIBX264);
421
+ * if (codec?.isEncoder()) {
422
+ * console.log('This is an encoder');
423
+ * }
424
+ * ```
425
+ *
426
+ * @see {@link isDecoder} To check for decoders
427
+ */
428
+ isEncoder() {
429
+ return this.native.isEncoder();
430
+ }
431
+ /**
432
+ * Check if codec is a decoder.
433
+ *
434
+ * @returns True if this codec can decode
435
+ *
436
+ * @example
437
+ * ```typescript
438
+ * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
439
+ * if (codec?.isDecoder()) {
440
+ * console.log('This is a decoder');
441
+ * }
442
+ * ```
443
+ *
444
+ * @see {@link isEncoder} To check for encoders
445
+ */
446
+ isDecoder() {
447
+ return this.native.isDecoder();
448
+ }
449
+ /**
450
+ * Check if codec is experimental.
451
+ *
452
+ * Experimental codecs require explicit opt-in to use.
453
+ *
454
+ * @returns True if codec is marked experimental
455
+ *
456
+ * @example
457
+ * ```typescript
458
+ * if (codec.isExperimental()) {
459
+ * console.warn('This codec is experimental');
460
+ * // Need to set strict_std_compliance = -2
461
+ * }
462
+ * ```
463
+ */
464
+ isExperimental() {
465
+ return this.native.isExperimental();
466
+ }
467
+ /**
468
+ * Check if codec supports hardware acceleration.
469
+ *
470
+ * Checks if the codec has any hardware configuration.
471
+ *
472
+ * @returns True if hardware acceleration is available
473
+ *
474
+ * @example
475
+ * ```typescript
476
+ * import { FF_DECODER_H264_CUVID } from 'node-av/constants';
477
+ *
478
+ * const codec = Codec.findDecoderByName(FF_DECODER_H264_CUVID);
479
+ * if (codec?.hasHardwareAcceleration()) {
480
+ * console.log('Hardware acceleration available');
481
+ * }
482
+ * ```
483
+ *
484
+ * @see {@link getSupportedDeviceTypes} For specific device types
485
+ */
486
+ hasHardwareAcceleration() {
487
+ // A codec is considered hardware if it has any hw_config with:
488
+ // - HW_DEVICE_CTX support (decoders typically use this)
489
+ // - HW_FRAMES_CTX support (encoders typically use this)
490
+ for (let i = 0;; i++) {
491
+ const config = this.getHwConfig(i);
492
+ if (!config)
493
+ break;
494
+ // Check for either HW_DEVICE_CTX or HW_FRAMES_CTX
495
+ if ((config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) !== 0 || (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) !== 0) {
496
+ return true;
497
+ }
498
+ }
499
+ return false;
500
+ }
501
+ /**
502
+ * Check if codec supports specific device type.
503
+ *
504
+ * @param deviceType - Hardware device type to check
505
+ *
506
+ * @returns True if device type is supported
507
+ *
508
+ * @example
509
+ * ```typescript
510
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
511
+ *
512
+ * if (codec.supportsDevice(AV_HWDEVICE_TYPE_CUDA)) {
513
+ * console.log('Supports NVIDIA CUDA');
514
+ * }
515
+ * ```
516
+ *
517
+ * @see {@link getSupportedDeviceTypes} For all supported types
518
+ */
519
+ supportsDevice(deviceType) {
520
+ for (let i = 0;; i++) {
521
+ const config = this.getHwConfig(i);
522
+ if (!config)
523
+ break;
524
+ if (typeof deviceType === 'string') {
525
+ deviceType = avGetHardwareDeviceTypeFromName(deviceType);
526
+ }
527
+ // Check if this config is for the requested device type
528
+ if (config.deviceType === deviceType) {
529
+ // Check if it has any valid hardware method
530
+ if ((config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) !== 0 || (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) !== 0) {
531
+ return true;
532
+ }
533
+ }
534
+ }
535
+ return false;
536
+ }
537
+ /**
538
+ * Check if decoder supports hardware acceleration.
539
+ *
540
+ * @param deviceType - Optional specific device type
541
+ *
542
+ * @returns True if hardware decoding is supported
543
+ *
544
+ * @example
545
+ * ```typescript
546
+ * import { AV_HWDEVICE_TYPE_VIDEOTOOLBOX } from 'node-av/constants';
547
+ *
548
+ * // Check any hardware support
549
+ * if (codec.isHardwareAcceleratedDecoder()) {
550
+ * console.log('Hardware decoding available');
551
+ * }
552
+ *
553
+ * // Check specific device
554
+ * if (codec.isHardwareAcceleratedDecoder(AV_HWDEVICE_TYPE_VIDEOTOOLBOX)) {
555
+ * console.log('VideoToolbox decoding available');
556
+ * }
557
+ * ```
558
+ */
559
+ isHardwareAcceleratedDecoder(deviceType) {
560
+ if (!this.isDecoder())
561
+ return false;
562
+ if (deviceType !== undefined) {
563
+ return this.supportsDevice(deviceType);
564
+ }
565
+ return this.hasHardwareAcceleration();
566
+ }
567
+ /**
568
+ * Check if encoder supports hardware acceleration.
569
+ *
570
+ * @param deviceType - Optional specific device type
571
+ *
572
+ * @returns True if hardware encoding is supported
573
+ *
574
+ * @example
575
+ * ```typescript
576
+ * import { AV_HWDEVICE_TYPE_VAAPI } from 'node-av/constants';
577
+ *
578
+ * // Check any hardware support
579
+ * if (codec.isHardwareAcceleratedEncoder()) {
580
+ * console.log('Hardware encoding available');
581
+ * }
582
+ *
583
+ * // Check specific device
584
+ * if (codec.isHardwareAcceleratedEncoder(AV_HWDEVICE_TYPE_VAAPI)) {
585
+ * console.log('VAAPI encoding available');
586
+ * }
587
+ * ```
588
+ */
589
+ isHardwareAcceleratedEncoder(deviceType) {
590
+ if (!this.isEncoder())
591
+ return false;
592
+ if (deviceType !== undefined) {
593
+ return this.supportsDevice(deviceType);
594
+ }
595
+ return this.hasHardwareAcceleration();
596
+ }
597
+ /**
598
+ * Get supported hardware device types.
599
+ *
600
+ * Returns all hardware acceleration types this codec supports.
601
+ *
602
+ * @returns Array of supported device types
603
+ *
604
+ * @example
605
+ * ```typescript
606
+ * const devices = codec.getSupportedDeviceTypes();
607
+ * console.log('Supported devices:', devices.map(d => {
608
+ * switch(d) {
609
+ * case AV_HWDEVICE_TYPE_CUDA: return 'CUDA';
610
+ * case AV_HWDEVICE_TYPE_VAAPI: return 'VAAPI';
611
+ * default: return 'Unknown';
612
+ * }
613
+ * }));
614
+ * ```
615
+ *
616
+ * @see {@link supportsDevice} To check specific device
617
+ */
618
+ getSupportedDeviceTypes() {
619
+ const deviceTypes = new Set();
620
+ for (let i = 0;; i++) {
621
+ const config = this.getHwConfig(i);
622
+ if (!config)
623
+ break;
624
+ // Only add if it has valid hw methods
625
+ if ((config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) !== 0 || (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) !== 0) {
626
+ deviceTypes.add(config.deviceType);
627
+ }
628
+ }
629
+ return Array.from(deviceTypes);
630
+ }
631
+ /**
632
+ * Get hardware method flags for device type.
633
+ *
634
+ * Returns the hardware configuration methods for a specific device.
635
+ *
636
+ * @param deviceType - Device type to query
637
+ *
638
+ * @returns Method flags, or null if not supported
639
+ *
640
+ * @example
641
+ * ```typescript
642
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
643
+ *
644
+ * const methods = codec.getHardwareMethod(AV_HWDEVICE_TYPE_CUDA);
645
+ * if (methods) {
646
+ * if (methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
647
+ * console.log('Supports device context');
648
+ * }
649
+ * }
650
+ * ```
651
+ */
652
+ getHardwareMethod(deviceType) {
653
+ for (let i = 0;; i++) {
654
+ const config = this.getHwConfig(i);
655
+ if (!config)
656
+ break;
657
+ if (typeof deviceType === 'string') {
658
+ deviceType = avGetHardwareDeviceTypeFromName(deviceType);
659
+ }
660
+ if (config.deviceType === deviceType) {
661
+ return config.methods;
662
+ }
663
+ }
664
+ return null;
665
+ }
666
+ /**
667
+ * Get hardware configuration at index.
668
+ *
669
+ * Retrieves hardware acceleration configuration details.
670
+ *
671
+ * Direct mapping to avcodec_get_hw_config().
672
+ *
673
+ * @param index - Configuration index
674
+ *
675
+ * @returns Hardware configuration, or null if index out of range
676
+ *
677
+ * @example
678
+ * ```typescript
679
+ * // Enumerate all hardware configs
680
+ * for (let i = 0; ; i++) {
681
+ * const config = codec.getHwConfig(i);
682
+ * if (!config) break;
683
+ *
684
+ * console.log(`Config ${i}:`);
685
+ * console.log(` Pixel format: ${config.pixFmt}`);
686
+ * console.log(` Device type: ${config.deviceType}`);
687
+ * console.log(` Methods: 0x${config.methods.toString(16)}`);
688
+ * }
689
+ * ```
690
+ */
691
+ getHwConfig(index) {
692
+ return this.native.getHwConfig(index);
693
+ }
694
+ /**
695
+ * Enumerate the codec's private options.
696
+ *
697
+ * Returns the codec-specific tunables exposed by the codec's private
698
+ * `AVClass` (e.g. libx264's `preset`, `crf`, `tune`). These are the options
699
+ * accepted via the `options` dictionary when creating an encoder/decoder, and
700
+ * are distinct from the generic `AVCodecContext` fields (bitrate, gop_size, ...).
701
+ *
702
+ * Options of type `AV_OPT_TYPE_CONST` are the named values belonging to a
703
+ * parent option's `unit` (i.e. enum members). Returns an empty array when the
704
+ * codec has no private options.
705
+ *
706
+ * Direct mapping to iterating `codec->priv_class` via av_opt_next().
707
+ *
708
+ * @returns Array of private option descriptors
709
+ *
710
+ * @example
711
+ * ```typescript
712
+ * const codec = Codec.findEncoderByName(FF_ENCODER_LIBX264);
713
+ * for (const opt of codec?.getOptions() ?? []) {
714
+ * console.log(opt.name, opt.type, opt.unit);
715
+ * }
716
+ * ```
717
+ */
718
+ getOptions() {
719
+ return this.native.getOptions();
720
+ }
721
+ /**
722
+ * Get the underlying native Codec object.
723
+ *
724
+ * @returns The native Codec binding object
725
+ *
726
+ * @internal
727
+ */
728
+ getNative() {
729
+ return this.native;
730
+ }
731
+ /**
732
+ * Create codec from native instance.
733
+ *
734
+ * @param native - Native codec instance
735
+ *
736
+ * @returns Codec wrapper or null
737
+ *
738
+ * @internal
739
+ */
740
+ static fromNative(native) {
741
+ if (!native)
742
+ return null;
743
+ return new Codec(native);
744
+ }
745
+ }
746
+ //# sourceMappingURL=codec.js.map