node-av 1.0.3 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (162) hide show
  1. package/README.md +56 -41
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +182 -126
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +286 -130
  6. package/dist/api/decoder.js +321 -159
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +254 -158
  9. package/dist/api/encoder.js +326 -298
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +912 -0
  12. package/dist/api/filter-presets.js +1407 -0
  13. package/dist/api/filter-presets.js.map +1 -0
  14. package/dist/api/filter.d.ts +280 -284
  15. package/dist/api/filter.js +435 -509
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +226 -159
  18. package/dist/api/hardware.js +405 -287
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -2
  21. package/dist/api/index.js +1 -0
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +45 -47
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +244 -141
  27. package/dist/api/media-input.js +207 -104
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +212 -129
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +22 -182
  36. package/dist/api/utilities/audio-sample.d.ts +1 -1
  37. package/dist/api/utilities/image.d.ts +1 -1
  38. package/dist/api/utilities/media-type.d.ts +1 -1
  39. package/dist/api/utilities/pixel-format.d.ts +1 -1
  40. package/dist/api/utilities/sample-format.d.ts +1 -1
  41. package/dist/api/utilities/timestamp.d.ts +1 -1
  42. package/dist/api/utils.d.ts +1 -2
  43. package/dist/api/utils.js +9 -0
  44. package/dist/api/utils.js.map +1 -1
  45. package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
  46. package/dist/constants/channel-layouts.js.map +1 -0
  47. package/dist/{lib → constants}/constants.d.ts +19 -4
  48. package/dist/{lib → constants}/constants.js +15 -1
  49. package/dist/constants/constants.js.map +1 -0
  50. package/dist/constants/decoders.d.ts +609 -0
  51. package/dist/constants/decoders.js +617 -0
  52. package/dist/constants/decoders.js.map +1 -0
  53. package/dist/constants/encoders.d.ts +285 -0
  54. package/dist/constants/encoders.js +298 -0
  55. package/dist/constants/encoders.js.map +1 -0
  56. package/dist/constants/index.d.ts +4 -0
  57. package/dist/constants/index.js +5 -0
  58. package/dist/constants/index.js.map +1 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +2 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/audio-fifo.d.ts +128 -171
  63. package/dist/lib/audio-fifo.js +130 -173
  64. package/dist/lib/audio-fifo.js.map +1 -1
  65. package/dist/lib/binding.d.ts +7 -5
  66. package/dist/lib/binding.js +5 -0
  67. package/dist/lib/binding.js.map +1 -1
  68. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  69. package/dist/lib/bitstream-filter-context.js +139 -188
  70. package/dist/lib/bitstream-filter-context.js.map +1 -1
  71. package/dist/lib/bitstream-filter.d.ts +69 -55
  72. package/dist/lib/bitstream-filter.js +68 -54
  73. package/dist/lib/bitstream-filter.js.map +1 -1
  74. package/dist/lib/codec-context.d.ts +317 -381
  75. package/dist/lib/codec-context.js +316 -381
  76. package/dist/lib/codec-context.js.map +1 -1
  77. package/dist/lib/codec-parameters.d.ts +161 -171
  78. package/dist/lib/codec-parameters.js +162 -172
  79. package/dist/lib/codec-parameters.js.map +1 -1
  80. package/dist/lib/codec-parser.d.ts +92 -105
  81. package/dist/lib/codec-parser.js +92 -103
  82. package/dist/lib/codec-parser.js.map +1 -1
  83. package/dist/lib/codec.d.ts +328 -217
  84. package/dist/lib/codec.js +392 -218
  85. package/dist/lib/codec.js.map +1 -1
  86. package/dist/lib/dictionary.d.ts +150 -204
  87. package/dist/lib/dictionary.js +159 -213
  88. package/dist/lib/dictionary.js.map +1 -1
  89. package/dist/lib/error.d.ts +97 -131
  90. package/dist/lib/error.js +98 -128
  91. package/dist/lib/error.js.map +1 -1
  92. package/dist/lib/filter-context.d.ts +317 -194
  93. package/dist/lib/filter-context.js +335 -200
  94. package/dist/lib/filter-context.js.map +1 -1
  95. package/dist/lib/filter-graph.d.ts +252 -293
  96. package/dist/lib/filter-graph.js +253 -294
  97. package/dist/lib/filter-graph.js.map +1 -1
  98. package/dist/lib/filter-inout.d.ts +87 -95
  99. package/dist/lib/filter-inout.js +87 -95
  100. package/dist/lib/filter-inout.js.map +1 -1
  101. package/dist/lib/filter.d.ts +93 -111
  102. package/dist/lib/filter.js +94 -112
  103. package/dist/lib/filter.js.map +1 -1
  104. package/dist/lib/format-context.d.ts +321 -429
  105. package/dist/lib/format-context.js +314 -386
  106. package/dist/lib/format-context.js.map +1 -1
  107. package/dist/lib/frame.d.ts +263 -406
  108. package/dist/lib/frame.js +263 -408
  109. package/dist/lib/frame.js.map +1 -1
  110. package/dist/lib/hardware-device-context.d.ts +150 -204
  111. package/dist/lib/hardware-device-context.js +149 -203
  112. package/dist/lib/hardware-device-context.js.map +1 -1
  113. package/dist/lib/hardware-frames-context.d.ts +171 -181
  114. package/dist/lib/hardware-frames-context.js +171 -181
  115. package/dist/lib/hardware-frames-context.js.map +1 -1
  116. package/dist/lib/index.d.ts +2 -3
  117. package/dist/lib/index.js +2 -5
  118. package/dist/lib/index.js.map +1 -1
  119. package/dist/lib/input-format.d.ts +90 -118
  120. package/dist/lib/input-format.js +89 -117
  121. package/dist/lib/input-format.js.map +1 -1
  122. package/dist/lib/io-context.d.ts +210 -242
  123. package/dist/lib/io-context.js +221 -253
  124. package/dist/lib/io-context.js.map +1 -1
  125. package/dist/lib/log.d.ts +86 -120
  126. package/dist/lib/log.js +85 -122
  127. package/dist/lib/log.js.map +1 -1
  128. package/dist/lib/native-types.d.ts +127 -112
  129. package/dist/lib/native-types.js +9 -0
  130. package/dist/lib/native-types.js.map +1 -1
  131. package/dist/lib/option.d.ts +285 -242
  132. package/dist/lib/option.js +310 -250
  133. package/dist/lib/option.js.map +1 -1
  134. package/dist/lib/output-format.d.ts +78 -102
  135. package/dist/lib/output-format.js +77 -101
  136. package/dist/lib/output-format.js.map +1 -1
  137. package/dist/lib/packet.d.ts +173 -241
  138. package/dist/lib/packet.js +172 -241
  139. package/dist/lib/packet.js.map +1 -1
  140. package/dist/lib/rational.d.ts +0 -2
  141. package/dist/lib/rational.js +0 -2
  142. package/dist/lib/rational.js.map +1 -1
  143. package/dist/lib/software-resample-context.d.ts +242 -326
  144. package/dist/lib/software-resample-context.js +242 -326
  145. package/dist/lib/software-resample-context.js.map +1 -1
  146. package/dist/lib/software-scale-context.d.ts +130 -174
  147. package/dist/lib/software-scale-context.js +132 -176
  148. package/dist/lib/software-scale-context.js.map +1 -1
  149. package/dist/lib/stream.d.ts +88 -198
  150. package/dist/lib/stream.js +87 -197
  151. package/dist/lib/stream.js.map +1 -1
  152. package/dist/lib/types.d.ts +1 -1
  153. package/dist/lib/utilities.d.ts +372 -181
  154. package/dist/lib/utilities.js +373 -182
  155. package/dist/lib/utilities.js.map +1 -1
  156. package/install/check.js +0 -1
  157. package/package.json +32 -24
  158. package/release_notes.md +43 -13
  159. package/CHANGELOG.md +0 -8
  160. package/dist/lib/channel-layouts.js.map +0 -1
  161. package/dist/lib/constants.js.map +0 -1
  162. /package/dist/{lib → constants}/channel-layouts.js +0 -0
package/dist/lib/codec.js CHANGED
@@ -1,132 +1,109 @@
1
+ import { AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX, AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX } from '../constants/constants.js';
1
2
  import { bindings } from './binding.js';
2
3
  import { Rational } from './rational.js';
3
4
  /**
4
- * Codec (encoder/decoder) definition.
5
+ * Codec descriptor for audio/video encoding and decoding.
5
6
  *
6
- * Represents a codec implementation for encoding or decoding media.
7
- * Provides codec information, capabilities, and supported formats.
8
- * This is an immutable descriptor - actual encoding/decoding happens via CodecContext.
7
+ * Represents an encoder or decoder implementation that can process media data.
8
+ * Contains codec capabilities, supported formats, and hardware acceleration information.
9
+ * Used to create codec contexts for actual encoding/decoding operations.
10
+ * Supports both software and hardware-accelerated codecs.
9
11
  *
10
12
  * Direct mapping to FFmpeg's AVCodec.
11
13
  *
12
14
  * @example
13
15
  * ```typescript
14
- * import { Codec } from 'node-av';
16
+ * import { Codec, FFmpegError } from 'node-av';
15
17
  * import { AV_CODEC_ID_H264 } from 'node-av/constants';
16
18
  *
17
19
  * // Find decoder by ID
18
- * const h264Decoder = Codec.findDecoder(AV_CODEC_ID_H264);
19
- * if (!h264Decoder) throw new Error('H264 decoder not found');
20
+ * const decoder = Codec.findDecoder(AV_CODEC_ID_H264);
21
+ * if (!decoder) {
22
+ * throw new Error('H.264 decoder not available');
23
+ * }
20
24
  *
21
25
  * // Find encoder by name
22
- * const x264Encoder = Codec.findEncoderByName('libx264');
23
- * if (!x264Encoder) throw new Error('x264 encoder not found');
24
- *
25
- * // Check codec capabilities
26
- * console.log(`Codec: ${h264Decoder.name}`);
27
- * console.log(`Long name: ${h264Decoder.longName}`);
28
- * console.log(`Type: ${h264Decoder.type}`);
29
- * console.log(`Is decoder: ${h264Decoder.isDecoder()}`);
26
+ * const encoder = Codec.findEncoderByName('libx264');
27
+ * if (!encoder) {
28
+ * throw new Error('libx264 encoder not available');
29
+ * }
30
30
  *
31
- * // Get supported formats
32
- * const pixelFormats = h264Decoder.pixelFormats;
33
- * console.log(`Supported pixel formats: ${pixelFormats}`);
31
+ * // Check capabilities
32
+ * console.log(`Codec: ${decoder.name}`);
33
+ * console.log(`Type: ${decoder.type}`);
34
+ * console.log(`Hardware: ${decoder.hasHardwareAcceleration()}`);
34
35
  *
35
- * // Iterate through all codecs
36
- * let iter = null;
37
- * while (true) {
38
- * const result = Codec.iterateCodecs(iter);
39
- * if (!result) break;
40
- * console.log(`Found codec: ${result.codec.name}`);
41
- * iter = result.opaque;
36
+ * // Get supported pixel formats
37
+ * const formats = decoder.pixelFormats;
38
+ * if (formats) {
39
+ * console.log(`Supported formats: ${formats.join(', ')}`);
42
40
  * }
43
41
  * ```
42
+ *
43
+ * @see [AVCodec](https://ffmpeg.org/doxygen/trunk/structAVCodec.html) - FFmpeg Doxygen
44
+ * @see {@link CodecContext} For encoding/decoding operations
44
45
  */
45
46
  export class Codec {
46
47
  native;
47
48
  /**
48
- * Constructor is internal - use static factory methods.
49
- *
50
- * Codecs are global immutable objects managed by FFmpeg.
51
- * Use the static find methods to obtain codec instances.
52
- *
49
+ * @param native - The native codec instance
53
50
  * @internal
54
- *
55
- * @param native - Native AVCodec to wrap
56
- *
57
- * @example
58
- * ```typescript
59
- * import { Codec } from 'node-av';
60
- * import { AV_CODEC_ID_H264 } from 'node-av/constants';
61
- *
62
- * // Don't use constructor directly
63
- * // const codec = new Codec(); // Wrong
64
- *
65
- * // Use static factory methods instead
66
- * const decoder = Codec.findDecoder(AV_CODEC_ID_H264); // Correct
67
- * const encoder = Codec.findEncoderByName('libx264'); // Correct
68
- * ```
69
51
  */
70
52
  constructor(native) {
71
53
  this.native = native;
72
54
  }
73
55
  /**
74
- * Create a Codec instance from a native codec object.
75
- * @internal Used by the bindings layer
76
- */
77
- static fromNative(native) {
78
- if (!native)
79
- return null;
80
- return new Codec(native);
81
- }
82
- /**
83
- * Find a registered decoder with a matching codec ID.
56
+ * Find a decoder by codec ID.
84
57
  *
85
58
  * Searches for a decoder that can decode the specified codec format.
86
59
  *
87
- * Direct mapping to avcodec_find_decoder()
88
- *
89
- * @param id - AVCodecID of the requested decoder
60
+ * Direct mapping to avcodec_find_decoder().
90
61
  *
91
- * @returns Codec object or null if no decoder found
62
+ * @param id - Codec ID to search for
63
+ * @returns Decoder if found, null otherwise
92
64
  *
93
65
  * @example
94
66
  * ```typescript
95
- * import { Codec } from 'node-av';
96
- * import { AV_CODEC_ID_H264 } from 'node-av/constants';
67
+ * import { AV_CODEC_ID_H264, AV_CODEC_ID_AAC } from 'node-av/constants';
97
68
  *
98
- * const decoder = Codec.findDecoder(AV_CODEC_ID_H264);
99
- * if (!decoder) {
100
- * throw new Error('H.264 decoder not available');
69
+ * // Find H.264 video decoder
70
+ * const h264 = Codec.findDecoder(AV_CODEC_ID_H264);
71
+ * if (h264) {
72
+ * console.log(`Found: ${h264.name}`);
101
73
  * }
74
+ *
75
+ * // Find AAC audio decoder
76
+ * const aac = Codec.findDecoder(AV_CODEC_ID_AAC);
102
77
  * ```
103
78
  *
104
79
  * @see {@link findDecoderByName} To find by name
105
- * @see {@link findEncoder} To find encoder
80
+ * @see {@link findEncoder} To find encoders
106
81
  */
107
82
  static findDecoder(id) {
108
83
  const native = bindings.Codec.findDecoder(id);
109
84
  return native ? new Codec(native) : null;
110
85
  }
111
86
  /**
112
- * Find a registered decoder with the specified name.
113
- *
114
- * Searches for a decoder by its exact name.
115
- * Useful for selecting specific decoder implementations.
87
+ * Find a decoder by name.
116
88
  *
117
- * Direct mapping to avcodec_find_decoder_by_name()
89
+ * Searches for a specific decoder implementation by name.
90
+ * Useful when multiple decoders exist for the same codec.
118
91
  *
119
- * @param name - Name of the requested decoder
92
+ * Direct mapping to avcodec_find_decoder_by_name().
120
93
  *
121
- * @returns Codec object or null if no decoder found
94
+ * @param name - Decoder name
95
+ * @returns Decoder if found, null otherwise
122
96
  *
123
97
  * @example
124
98
  * ```typescript
125
- * import { Codec } from 'node-av';
99
+ * // Find specific H.264 decoder
100
+ * const decoder = Codec.findDecoderByName('h264_cuvid');
101
+ * if (decoder) {
102
+ * console.log('Found NVIDIA hardware decoder');
103
+ * }
126
104
  *
127
- * const decoder = Codec.findDecoderByName('h264');
128
- * // Can also use specific implementations:
129
- * const cudaDecoder = Codec.findDecoderByName('h264_cuvid'); // NVIDIA hardware decoder
105
+ * // Find software decoder
106
+ * const sw = Codec.findDecoderByName('h264');
130
107
  * ```
131
108
  *
132
109
  * @see {@link findDecoder} To find by codec ID
@@ -136,54 +113,57 @@ export class Codec {
136
113
  return native ? new Codec(native) : null;
137
114
  }
138
115
  /**
139
- * Find a registered encoder with a matching codec ID.
116
+ * Find an encoder by codec ID.
140
117
  *
141
118
  * Searches for an encoder that can encode to the specified codec format.
142
119
  *
143
- * Direct mapping to avcodec_find_encoder()
144
- *
145
- * @param id - AVCodecID of the requested encoder
120
+ * Direct mapping to avcodec_find_encoder().
146
121
  *
147
- * @returns Codec object or null if no encoder found
122
+ * @param id - Codec ID to search for
123
+ * @returns Encoder if found, null otherwise
148
124
  *
149
125
  * @example
150
126
  * ```typescript
151
- * import { Codec } from 'node-av';
152
- * import { AV_CODEC_ID_H264 } from 'node-av/constants';
127
+ * import { AV_CODEC_ID_H264, AV_CODEC_ID_AAC } from 'node-av/constants';
153
128
  *
154
- * const encoder = Codec.findEncoder(AV_CODEC_ID_H264);
155
- * if (!encoder) {
156
- * throw new Error('H.264 encoder not available');
129
+ * // Find H.264 video encoder
130
+ * const h264 = Codec.findEncoder(AV_CODEC_ID_H264);
131
+ * if (h264) {
132
+ * console.log(`Found: ${h264.name}`);
157
133
  * }
134
+ *
135
+ * // Find AAC audio encoder
136
+ * const aac = Codec.findEncoder(AV_CODEC_ID_AAC);
158
137
  * ```
159
138
  *
160
139
  * @see {@link findEncoderByName} To find by name
161
- * @see {@link findDecoder} To find decoder
140
+ * @see {@link findDecoder} To find decoders
162
141
  */
163
142
  static findEncoder(id) {
164
143
  const native = bindings.Codec.findEncoder(id);
165
144
  return native ? new Codec(native) : null;
166
145
  }
167
146
  /**
168
- * Find a registered encoder with the specified name.
169
- *
170
- * Searches for an encoder by its exact name.
171
- * Useful for selecting specific encoder implementations.
147
+ * Find an encoder by name.
172
148
  *
173
- * Direct mapping to avcodec_find_encoder_by_name()
149
+ * Searches for a specific encoder implementation by name.
150
+ * Useful when multiple encoders exist for the same codec.
174
151
  *
175
- * @param name - Name of the requested encoder
152
+ * Direct mapping to avcodec_find_encoder_by_name().
176
153
  *
177
- * @returns Codec object or null if no encoder found
154
+ * @param name - Encoder name
155
+ * @returns Encoder if found, null otherwise
178
156
  *
179
157
  * @example
180
158
  * ```typescript
181
- * import { Codec } from 'node-av';
159
+ * // Find specific H.264 encoder
160
+ * const x264 = Codec.findEncoderByName('libx264');
161
+ * if (x264) {
162
+ * console.log('Found x264 encoder');
163
+ * }
182
164
  *
183
- * // Find specific encoder implementation
184
- * const x264 = Codec.findEncoderByName('libx264'); // Software H.264 encoder
185
- * const nvenc = Codec.findEncoderByName('h264_nvenc'); // NVIDIA hardware encoder
186
- * const vaapi = Codec.findEncoderByName('h264_vaapi'); // VAAPI hardware encoder
165
+ * // Find hardware encoder
166
+ * const nvenc = Codec.findEncoderByName('h264_nvenc');
187
167
  * ```
188
168
  *
189
169
  * @see {@link findEncoder} To find by codec ID
@@ -195,25 +175,24 @@ export class Codec {
195
175
  /**
196
176
  * Get list of all available codecs.
197
177
  *
198
- * Returns all registered codecs in the system.
199
- * Internally uses av_codec_iterate() to collect all codecs.
178
+ * Returns all registered codecs (both encoders and decoders).
200
179
  *
201
- * @returns Array of all registered codecs
180
+ * @returns Array of all available codecs
202
181
  *
203
182
  * @example
204
183
  * ```typescript
205
- * import { Codec } from 'node-av';
206
- * import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
207
- *
184
+ * // List all codecs
208
185
  * const codecs = Codec.getCodecList();
209
- * const videoEncoders = codecs.filter(c =>
210
- * c.type === AVMEDIA_TYPE_VIDEO && c.isEncoder()
211
- * );
212
- * console.log(`Found ${videoEncoders.length} video encoders`);
213
- * ```
186
+ * console.log(`Total codecs: ${codecs.length}`);
187
+ *
188
+ * // Filter encoders
189
+ * const encoders = codecs.filter(c => c.isEncoder());
190
+ * console.log(`Encoders: ${encoders.length}`);
214
191
  *
215
- * @note This loads all codecs at once. For large codec lists,
216
- * consider using iterateCodecs() instead.
192
+ * // Filter hardware codecs
193
+ * const hw = codecs.filter(c => c.hasHardwareAcceleration());
194
+ * console.log(`Hardware codecs: ${hw.length}`);
195
+ * ```
217
196
  *
218
197
  * @see {@link iterateCodecs} For memory-efficient iteration
219
198
  */
@@ -222,37 +201,28 @@ export class Codec {
222
201
  return natives.map((n) => new Codec(n));
223
202
  }
224
203
  /**
225
- * Iterate through codecs one by one.
226
- *
227
- * Memory-efficient codec iteration.
228
- * Processes codecs one at a time instead of loading all at once.
204
+ * Iterate through available codecs.
229
205
  *
230
- * Direct mapping to av_codec_iterate()
206
+ * Memory-efficient way to iterate through all codecs.
207
+ * Uses an opaque pointer to track iteration state.
231
208
  *
232
- * @param opaque - Iterator state (null to start, or value from previous call)
209
+ * Direct mapping to av_codec_iterate().
233
210
  *
234
- * @returns Object with codec and next iterator state, or null when done
211
+ * @param opaque - Iteration state (null to start)
212
+ * @returns Next codec and state, or null when done
235
213
  *
236
214
  * @example
237
215
  * ```typescript
238
- * import { Codec } from 'node-av';
239
- * import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
240
- *
241
- * let opaque = null;
242
- * while (true) {
243
- * const result = Codec.iterateCodecs(opaque);
244
- * if (!result) break;
245
- *
246
- * const codec = result.codec;
247
- * if (codec.type === AVMEDIA_TYPE_VIDEO && codec.isEncoder()) {
248
- * console.log(`Video encoder: ${codec.name}`);
249
- * }
250
- *
251
- * opaque = result.opaque;
216
+ * // Iterate all codecs
217
+ * let iter = null;
218
+ * let result;
219
+ * while ((result = Codec.iterateCodecs(iter))) {
220
+ * console.log(`Codec: ${result.codec.name}`);
221
+ * iter = result.opaque;
252
222
  * }
253
223
  * ```
254
224
  *
255
- * @see {@link getCodecList} To get all codecs at once
225
+ * @see {@link getCodecList} For simple array access
256
226
  */
257
227
  static iterateCodecs(opaque = null) {
258
228
  const result = bindings.Codec.iterateCodecs(opaque);
@@ -264,30 +234,31 @@ export class Codec {
264
234
  };
265
235
  }
266
236
  /**
267
- * Short name of the codec.
237
+ * Codec name.
238
+ *
239
+ * Short name identifier for the codec (e.g., 'h264', 'aac').
268
240
  *
269
- * Direct mapping to AVCodec->name
270
- * Typically matches the name of the codec specification.
271
- * For example: "h264", "aac", "vp9", "opus"
241
+ * Direct mapping to AVCodec->name.
272
242
  */
273
243
  get name() {
274
244
  return this.native.name;
275
245
  }
276
246
  /**
277
- * Descriptive name for the codec.
247
+ * Codec long name.
278
248
  *
279
- * Direct mapping to AVCodec->long_name
280
- * More human-readable than name.
281
- * For example: "H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10"
249
+ * Human-readable description of the codec.
250
+ *
251
+ * Direct mapping to AVCodec->long_name.
282
252
  */
283
253
  get longName() {
284
254
  return this.native.longName;
285
255
  }
286
256
  /**
287
- * Media type handled by this codec.
257
+ * Media type.
258
+ *
259
+ * Type of media this codec processes (video, audio, subtitle, etc.).
288
260
  *
289
- * Direct mapping to AVCodec->type
290
- * AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, AVMEDIA_TYPE_SUBTITLE, etc.
261
+ * Direct mapping to AVCodec->type.
291
262
  */
292
263
  get type() {
293
264
  return this.native.type;
@@ -295,8 +266,9 @@ export class Codec {
295
266
  /**
296
267
  * Codec ID.
297
268
  *
298
- * Direct mapping to AVCodec->id
299
- * Unique identifier for this codec type (AV_CODEC_ID_H264, AV_CODEC_ID_AAC, etc.)
269
+ * Unique identifier for the codec format.
270
+ *
271
+ * Direct mapping to AVCodec->id.
300
272
  */
301
273
  get id() {
302
274
  return this.native.id;
@@ -304,53 +276,50 @@ export class Codec {
304
276
  /**
305
277
  * Codec capabilities.
306
278
  *
307
- * Direct mapping to AVCodec->capabilities
308
- * Bitfield of AV_CODEC_CAP_* flags describing codec features.
279
+ * Bitfield of AV_CODEC_CAP_* flags indicating codec features.
280
+ *
281
+ * Direct mapping to AVCodec->capabilities.
309
282
  */
310
283
  get capabilities() {
311
284
  return this.native.capabilities;
312
285
  }
313
286
  /**
314
- * Maximum lowres value supported by the decoder.
287
+ * Maximum lowres value.
315
288
  *
316
- * Lowres decoding allows decoding at reduced resolution for faster preview.
317
- * 0 means lowres decoding is not supported.
318
- * 1 means 1/2 resolution is supported.
319
- * 2 means 1/4 resolution is supported.
320
- * 3 means 1/8 resolution is supported.
321
- * @readonly
289
+ * Maximum value for lowres decoding (0 = no lowres support).
290
+ *
291
+ * Direct mapping to AVCodec->max_lowres.
322
292
  */
323
293
  get maxLowres() {
324
294
  return this.native.maxLowres;
325
295
  }
326
296
  /**
327
- * Array of supported codec profiles.
297
+ * Supported profiles.
298
+ *
299
+ * Array of profiles this codec can handle (e.g., baseline, main, high).
328
300
  *
329
- * Profiles define subsets of codec features.
330
- * For example, H.264 has Baseline, Main, High profiles.
331
- * null if codec doesn't support profiles or none are defined.
332
- * @readonly
301
+ * Direct mapping to AVCodec->profiles.
333
302
  */
334
303
  get profiles() {
335
304
  return this.native.profiles;
336
305
  }
337
306
  /**
338
- * Group name of the codec implementation.
307
+ * Wrapper name.
339
308
  *
340
- * This is a short symbolic name of the wrapper backing this codec.
341
- * For example "lavc" for internal codecs, "libopenh264" for OpenH264 wrapper.
342
- * null if codec is not wrapped.
343
- * @readonly
309
+ * Name of the codec wrapper, if this is a wrapper codec.
310
+ *
311
+ * Direct mapping to AVCodec->wrapper_name.
344
312
  */
345
313
  get wrapper() {
346
314
  return this.native.wrapper;
347
315
  }
348
316
  /**
349
- * Supported framerates (video only).
317
+ * Supported frame rates.
318
+ *
319
+ * Array of frame rates this video codec supports.
320
+ * Null for audio codecs or if all rates are supported.
350
321
  *
351
- * Terminated by {0,0}. null if any framerate is supported.
352
- * Some codecs like MPEG-1/2 only support specific framerates.
353
- * @readonly
322
+ * Direct mapping to AVCodec->supported_framerates.
354
323
  */
355
324
  get supportedFramerates() {
356
325
  const rates = this.native.supportedFramerates;
@@ -359,98 +328,97 @@ export class Codec {
359
328
  return rates.map((r) => new Rational(r.num, r.den));
360
329
  }
361
330
  /**
362
- * Array of supported pixel formats (video only).
331
+ * Supported pixel formats.
363
332
  *
364
- * Terminated by AV_PIX_FMT_NONE. null if unknown.
365
- * Lists all pixel formats this codec can encode/decode.
366
- * @readonly
333
+ * Array of pixel formats this video codec supports.
334
+ * Null for audio codecs.
335
+ *
336
+ * Direct mapping to AVCodec->pix_fmts.
367
337
  */
368
338
  get pixelFormats() {
369
339
  return this.native.pixelFormats;
370
340
  }
371
341
  /**
372
- * Supported sample rates (audio only).
342
+ * Supported sample rates.
343
+ *
344
+ * Array of sample rates this audio codec supports.
345
+ * Null for video codecs or if all rates are supported.
373
346
  *
374
- * Terminated by 0. null if any sample rate is supported.
375
- * Common rates: 8000, 16000, 22050, 44100, 48000, 96000, 192000 Hz.
376
- * @readonly
347
+ * Direct mapping to AVCodec->supported_samplerates.
377
348
  */
378
349
  get supportedSamplerates() {
379
350
  return this.native.supportedSamplerates;
380
351
  }
381
352
  /**
382
- * Array of supported sample formats (audio only).
353
+ * Supported sample formats.
383
354
  *
384
- * Terminated by AV_SAMPLE_FMT_NONE. null if unknown.
385
- * Lists all sample formats this codec can encode/decode.
386
- * Common formats: S16, S32, FLT, DBL (planar and interleaved variants).
387
- * @readonly
355
+ * Array of sample formats this audio codec supports.
356
+ * Null for video codecs.
357
+ *
358
+ * Direct mapping to AVCodec->sample_fmts.
388
359
  */
389
360
  get sampleFormats() {
390
361
  return this.native.sampleFormats;
391
362
  }
392
363
  /**
393
- * Array of supported channel layouts (audio only).
364
+ * Supported channel layouts.
365
+ *
366
+ * Array of channel layouts this audio codec supports.
367
+ * Null for video codecs.
394
368
  *
395
- * Lists all channel configurations this codec supports.
396
- * Common layouts: mono, stereo, 5.1, 7.1.
397
- * null if unknown or all layouts are supported.
398
- * @readonly
369
+ * Direct mapping to AVCodec->ch_layouts.
399
370
  */
400
371
  get channelLayouts() {
401
372
  return this.native.channelLayouts;
402
373
  }
403
374
  /**
404
- * Check if the codec is an encoder.
375
+ * Check if codec is an encoder.
405
376
  *
406
- * Direct mapping to av_codec_is_encoder()
407
- *
408
- * @returns true if the codec is an encoder, false otherwise
377
+ * @returns True if this codec can encode
409
378
  *
410
379
  * @example
411
380
  * ```typescript
412
381
  * const codec = Codec.findEncoderByName('libx264');
413
- * if (codec && codec.isEncoder()) {
414
- * console.log('Found H.264 encoder');
382
+ * if (codec?.isEncoder()) {
383
+ * console.log('This is an encoder');
415
384
  * }
416
385
  * ```
386
+ *
387
+ * @see {@link isDecoder} To check for decoders
417
388
  */
418
389
  isEncoder() {
419
390
  return this.native.isEncoder();
420
391
  }
421
392
  /**
422
- * Check if the codec is a decoder.
393
+ * Check if codec is a decoder.
423
394
  *
424
- * Direct mapping to av_codec_is_decoder()
425
- *
426
- * @returns true if the codec is a decoder, false otherwise
395
+ * @returns True if this codec can decode
427
396
  *
428
397
  * @example
429
398
  * ```typescript
430
399
  * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
431
- * if (codec && codec.isDecoder()) {
432
- * console.log('Found H.264 decoder');
400
+ * if (codec?.isDecoder()) {
401
+ * console.log('This is a decoder');
433
402
  * }
434
403
  * ```
404
+ *
405
+ * @see {@link isEncoder} To check for encoders
435
406
  */
436
407
  isDecoder() {
437
408
  return this.native.isDecoder();
438
409
  }
439
410
  /**
440
- * Check if the codec is experimental.
411
+ * Check if codec is experimental.
441
412
  *
442
- * Experimental codecs require explicit allowance to use.
443
- * You must set strict_std_compliance to FF_COMPLIANCE_EXPERIMENTAL
444
- * or lower in the codec context to use experimental codecs.
413
+ * Experimental codecs require explicit opt-in to use.
445
414
  *
446
- * @returns true if the codec is experimental, false otherwise
415
+ * @returns True if codec is marked experimental
447
416
  *
448
417
  * @example
449
418
  * ```typescript
450
- * const codec = Codec.findEncoderByName('some_experimental_codec');
451
- * if (codec && codec.isExperimental()) {
452
- * console.warn('This codec is experimental and may not be stable');
453
- * // codecContext.strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL;
419
+ * if (codec.isExperimental()) {
420
+ * console.warn('This codec is experimental');
421
+ * // Need to set strict_std_compliance = -2
454
422
  * }
455
423
  * ```
456
424
  */
@@ -458,23 +426,213 @@ export class Codec {
458
426
  return this.native.isExperimental();
459
427
  }
460
428
  /**
461
- * Get hardware configuration at specified index.
429
+ * Check if codec supports hardware acceleration.
462
430
  *
463
- * Direct mapping to avcodec_get_hw_config()
431
+ * Checks if the codec has any hardware configuration.
464
432
  *
465
- * @param index - Configuration index (0-based)
466
- * @returns Hardware configuration or null if not available
433
+ * @returns True if hardware acceleration is available
467
434
  *
468
435
  * @example
469
436
  * ```typescript
470
- * const codec = Codec.findDecoder(AV_CODEC_ID_H264);
437
+ * const codec = Codec.findDecoderByName('h264_cuvid');
438
+ * if (codec?.hasHardwareAcceleration()) {
439
+ * console.log('Hardware acceleration available');
440
+ * }
441
+ * ```
442
+ *
443
+ * @see {@link getSupportedDeviceTypes} For specific device types
444
+ */
445
+ hasHardwareAcceleration() {
446
+ // A codec is considered hardware if it has any hw_config with:
447
+ // - HW_DEVICE_CTX support (decoders typically use this)
448
+ // - HW_FRAMES_CTX support (encoders typically use this)
449
+ for (let i = 0;; i++) {
450
+ const config = this.getHwConfig(i);
451
+ if (!config)
452
+ break;
453
+ // Check for either HW_DEVICE_CTX or HW_FRAMES_CTX
454
+ if ((config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) !== 0 || (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) !== 0) {
455
+ return true;
456
+ }
457
+ }
458
+ return false;
459
+ }
460
+ /**
461
+ * Check if codec supports specific device type.
462
+ *
463
+ * @param deviceType - Hardware device type to check
464
+ * @returns True if device type is supported
465
+ *
466
+ * @example
467
+ * ```typescript
468
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
469
+ *
470
+ * if (codec.supportsDevice(AV_HWDEVICE_TYPE_CUDA)) {
471
+ * console.log('Supports NVIDIA CUDA');
472
+ * }
473
+ * ```
474
+ *
475
+ * @see {@link getSupportedDeviceTypes} For all supported types
476
+ */
477
+ supportsDevice(deviceType) {
478
+ for (let i = 0;; i++) {
479
+ const config = this.getHwConfig(i);
480
+ if (!config)
481
+ break;
482
+ // Check if this config is for the requested device type
483
+ if (config.deviceType === deviceType) {
484
+ // Check if it has any valid hardware method
485
+ if ((config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) !== 0 || (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) !== 0) {
486
+ return true;
487
+ }
488
+ }
489
+ }
490
+ return false;
491
+ }
492
+ /**
493
+ * Check if decoder supports hardware acceleration.
494
+ *
495
+ * @param deviceType - Optional specific device type
496
+ * @returns True if hardware decoding is supported
497
+ *
498
+ * @example
499
+ * ```typescript
500
+ * import { AV_HWDEVICE_TYPE_VIDEOTOOLBOX } from 'node-av/constants';
501
+ *
502
+ * // Check any hardware support
503
+ * if (codec.isHardwareAcceleratedDecoder()) {
504
+ * console.log('Hardware decoding available');
505
+ * }
506
+ *
507
+ * // Check specific device
508
+ * if (codec.isHardwareAcceleratedDecoder(AV_HWDEVICE_TYPE_VIDEOTOOLBOX)) {
509
+ * console.log('VideoToolbox decoding available');
510
+ * }
511
+ * ```
512
+ */
513
+ isHardwareAcceleratedDecoder(deviceType) {
514
+ if (!this.isDecoder())
515
+ return false;
516
+ if (deviceType !== undefined) {
517
+ return this.supportsDevice(deviceType);
518
+ }
519
+ return this.hasHardwareAcceleration();
520
+ }
521
+ /**
522
+ * Check if encoder supports hardware acceleration.
523
+ *
524
+ * @param deviceType - Optional specific device type
525
+ * @returns True if hardware encoding is supported
526
+ *
527
+ * @example
528
+ * ```typescript
529
+ * import { AV_HWDEVICE_TYPE_VAAPI } from 'node-av/constants';
530
+ *
531
+ * // Check any hardware support
532
+ * if (codec.isHardwareAcceleratedEncoder()) {
533
+ * console.log('Hardware encoding available');
534
+ * }
535
+ *
536
+ * // Check specific device
537
+ * if (codec.isHardwareAcceleratedEncoder(AV_HWDEVICE_TYPE_VAAPI)) {
538
+ * console.log('VAAPI encoding available');
539
+ * }
540
+ * ```
541
+ */
542
+ isHardwareAcceleratedEncoder(deviceType) {
543
+ if (!this.isEncoder())
544
+ return false;
545
+ if (deviceType !== undefined) {
546
+ return this.supportsDevice(deviceType);
547
+ }
548
+ return this.hasHardwareAcceleration();
549
+ }
550
+ /**
551
+ * Get supported hardware device types.
552
+ *
553
+ * Returns all hardware acceleration types this codec supports.
554
+ *
555
+ * @returns Array of supported device types
556
+ *
557
+ * @example
558
+ * ```typescript
559
+ * const devices = codec.getSupportedDeviceTypes();
560
+ * console.log('Supported devices:', devices.map(d => {
561
+ * switch(d) {
562
+ * case AV_HWDEVICE_TYPE_CUDA: return 'CUDA';
563
+ * case AV_HWDEVICE_TYPE_VAAPI: return 'VAAPI';
564
+ * default: return 'Unknown';
565
+ * }
566
+ * }));
567
+ * ```
568
+ *
569
+ * @see {@link supportsDevice} To check specific device
570
+ */
571
+ getSupportedDeviceTypes() {
572
+ const deviceTypes = new Set();
573
+ for (let i = 0;; i++) {
574
+ const config = this.getHwConfig(i);
575
+ if (!config)
576
+ break;
577
+ // Only add if it has valid hw methods
578
+ if ((config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) !== 0 || (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX) !== 0) {
579
+ deviceTypes.add(config.deviceType);
580
+ }
581
+ }
582
+ return Array.from(deviceTypes);
583
+ }
584
+ /**
585
+ * Get hardware method flags for device type.
586
+ *
587
+ * Returns the hardware configuration methods for a specific device.
588
+ *
589
+ * @param deviceType - Device type to query
590
+ * @returns Method flags, or null if not supported
591
+ *
592
+ * @example
593
+ * ```typescript
594
+ * import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
595
+ *
596
+ * const methods = codec.getHardwareMethod(AV_HWDEVICE_TYPE_CUDA);
597
+ * if (methods) {
598
+ * if (methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
599
+ * console.log('Supports device context');
600
+ * }
601
+ * }
602
+ * ```
603
+ */
604
+ getHardwareMethod(deviceType) {
605
+ for (let i = 0;; i++) {
606
+ const config = this.getHwConfig(i);
607
+ if (!config)
608
+ break;
609
+ if (config.deviceType === deviceType) {
610
+ return config.methods;
611
+ }
612
+ }
613
+ return null;
614
+ }
615
+ /**
616
+ * Get hardware configuration at index.
617
+ *
618
+ * Retrieves hardware acceleration configuration details.
619
+ *
620
+ * Direct mapping to avcodec_get_hw_config().
621
+ *
622
+ * @param index - Configuration index
623
+ * @returns Hardware configuration, or null if index out of range
624
+ *
625
+ * @example
626
+ * ```typescript
627
+ * // Enumerate all hardware configs
471
628
  * for (let i = 0; ; i++) {
472
629
  * const config = codec.getHwConfig(i);
473
630
  * if (!config) break;
474
631
  *
475
- * if (config.methods & AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX) {
476
- * console.log(`Supports device type: ${config.deviceType}`);
477
- * }
632
+ * console.log(`Config ${i}:`);
633
+ * console.log(` Pixel format: ${config.pixFmt}`);
634
+ * console.log(` Device type: ${config.deviceType}`);
635
+ * console.log(` Methods: 0x${config.methods.toString(16)}`);
478
636
  * }
479
637
  * ```
480
638
  */
@@ -482,11 +640,27 @@ export class Codec {
482
640
  return this.native.getHwConfig(index);
483
641
  }
484
642
  /**
485
- * Get the native codec object for use with C++ bindings
643
+ * Get the underlying native Codec object.
644
+ *
645
+ * @returns The native Codec binding object
646
+ *
486
647
  * @internal
487
648
  */
488
649
  getNative() {
489
650
  return this.native;
490
651
  }
652
+ /**
653
+ * Create codec from native instance.
654
+ *
655
+ * @param native - Native codec instance
656
+ * @returns Codec wrapper or null
657
+ *
658
+ * @internal
659
+ */
660
+ static fromNative(native) {
661
+ if (!native)
662
+ return null;
663
+ return new Codec(native);
664
+ }
491
665
  }
492
666
  //# sourceMappingURL=codec.js.map