node-av 1.1.0 → 1.2.0

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