@revizly/node-av 5.2.2-beta.1

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