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.
- package/README.md +56 -41
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +182 -126
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +286 -130
- package/dist/api/decoder.js +321 -159
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +254 -158
- package/dist/api/encoder.js +326 -298
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +912 -0
- package/dist/api/filter-presets.js +1407 -0
- package/dist/api/filter-presets.js.map +1 -0
- package/dist/api/filter.d.ts +280 -284
- package/dist/api/filter.js +435 -509
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +226 -159
- package/dist/api/hardware.js +405 -287
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +45 -47
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +244 -141
- package/dist/api/media-input.js +207 -104
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +212 -129
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +22 -182
- package/dist/api/utilities/audio-sample.d.ts +1 -1
- package/dist/api/utilities/image.d.ts +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -1
- package/dist/api/utilities/pixel-format.d.ts +1 -1
- package/dist/api/utilities/sample-format.d.ts +1 -1
- package/dist/api/utilities/timestamp.d.ts +1 -1
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
- package/dist/constants/channel-layouts.js.map +1 -0
- package/dist/{lib → constants}/constants.d.ts +19 -4
- package/dist/{lib → constants}/constants.js +15 -1
- package/dist/constants/constants.js.map +1 -0
- package/dist/constants/decoders.d.ts +609 -0
- package/dist/constants/decoders.js +617 -0
- package/dist/constants/decoders.js.map +1 -0
- package/dist/constants/encoders.d.ts +285 -0
- package/dist/constants/encoders.js +298 -0
- package/dist/constants/encoders.js.map +1 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.js +5 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +128 -171
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.d.ts +7 -5
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +69 -55
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +317 -381
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +161 -171
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +92 -105
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +328 -217
- package/dist/lib/codec.js +392 -218
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +150 -204
- package/dist/lib/dictionary.js +159 -213
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +97 -131
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +317 -194
- package/dist/lib/filter-context.js +335 -200
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +252 -293
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +94 -112
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +321 -429
- package/dist/lib/format-context.js +314 -386
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +263 -406
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +150 -204
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +171 -181
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -3
- package/dist/lib/index.js +2 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +90 -118
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +210 -242
- package/dist/lib/io-context.js +221 -253
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +86 -120
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +127 -112
- package/dist/lib/native-types.js +9 -0
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +285 -242
- package/dist/lib/option.js +310 -250
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +78 -102
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +173 -241
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +242 -326
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +130 -174
- package/dist/lib/software-scale-context.js +132 -176
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +88 -198
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +32 -24
- package/release_notes.md +43 -13
- package/CHANGELOG.md +0 -8
- package/dist/lib/channel-layouts.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- /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
|
|
5
|
+
* Codec descriptor for audio/video encoding and decoding.
|
|
5
6
|
*
|
|
6
|
-
* Represents
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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
|
|
19
|
-
* if (!
|
|
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
|
|
23
|
-
* if (!
|
|
24
|
-
*
|
|
25
|
-
*
|
|
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
|
-
* //
|
|
32
|
-
*
|
|
33
|
-
* console.log(`
|
|
31
|
+
* // Check capabilities
|
|
32
|
+
* console.log(`Codec: ${decoder.name}`);
|
|
33
|
+
* console.log(`Type: ${decoder.type}`);
|
|
34
|
+
* console.log(`Hardware: ${decoder.hasHardwareAcceleration()}`);
|
|
34
35
|
*
|
|
35
|
-
* //
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
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
|
-
*
|
|
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
|
-
*
|
|
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
|
-
* @
|
|
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 {
|
|
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
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
89
|
+
* Searches for a specific decoder implementation by name.
|
|
90
|
+
* Useful when multiple decoders exist for the same codec.
|
|
118
91
|
*
|
|
119
|
-
*
|
|
92
|
+
* Direct mapping to avcodec_find_decoder_by_name().
|
|
120
93
|
*
|
|
121
|
-
* @
|
|
94
|
+
* @param name - Decoder name
|
|
95
|
+
* @returns Decoder if found, null otherwise
|
|
122
96
|
*
|
|
123
97
|
* @example
|
|
124
98
|
* ```typescript
|
|
125
|
-
*
|
|
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
|
-
*
|
|
128
|
-
*
|
|
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
|
|
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
|
-
* @
|
|
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 {
|
|
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
|
-
*
|
|
155
|
-
*
|
|
156
|
-
*
|
|
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
|
|
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
|
|
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
|
-
*
|
|
149
|
+
* Searches for a specific encoder implementation by name.
|
|
150
|
+
* Useful when multiple encoders exist for the same codec.
|
|
174
151
|
*
|
|
175
|
-
*
|
|
152
|
+
* Direct mapping to avcodec_find_encoder_by_name().
|
|
176
153
|
*
|
|
177
|
-
* @
|
|
154
|
+
* @param name - Encoder name
|
|
155
|
+
* @returns Encoder if found, null otherwise
|
|
178
156
|
*
|
|
179
157
|
* @example
|
|
180
158
|
* ```typescript
|
|
181
|
-
*
|
|
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
|
|
184
|
-
* const
|
|
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
|
|
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
|
|
180
|
+
* @returns Array of all available codecs
|
|
202
181
|
*
|
|
203
182
|
* @example
|
|
204
183
|
* ```typescript
|
|
205
|
-
*
|
|
206
|
-
* import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
|
|
207
|
-
*
|
|
184
|
+
* // List all codecs
|
|
208
185
|
* const codecs = Codec.getCodecList();
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
*
|
|
212
|
-
*
|
|
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
|
-
*
|
|
216
|
-
*
|
|
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
|
|
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
|
-
*
|
|
206
|
+
* Memory-efficient way to iterate through all codecs.
|
|
207
|
+
* Uses an opaque pointer to track iteration state.
|
|
231
208
|
*
|
|
232
|
-
*
|
|
209
|
+
* Direct mapping to av_codec_iterate().
|
|
233
210
|
*
|
|
234
|
-
* @
|
|
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
|
-
*
|
|
239
|
-
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
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}
|
|
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
|
-
*
|
|
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
|
-
*
|
|
247
|
+
* Codec long name.
|
|
278
248
|
*
|
|
279
|
-
*
|
|
280
|
-
*
|
|
281
|
-
*
|
|
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
|
|
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
|
-
*
|
|
299
|
-
*
|
|
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
|
-
*
|
|
308
|
-
*
|
|
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
|
|
287
|
+
* Maximum lowres value.
|
|
315
288
|
*
|
|
316
|
-
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
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
|
-
*
|
|
297
|
+
* Supported profiles.
|
|
298
|
+
*
|
|
299
|
+
* Array of profiles this codec can handle (e.g., baseline, main, high).
|
|
328
300
|
*
|
|
329
|
-
*
|
|
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
|
-
*
|
|
307
|
+
* Wrapper name.
|
|
339
308
|
*
|
|
340
|
-
*
|
|
341
|
-
*
|
|
342
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
331
|
+
* Supported pixel formats.
|
|
363
332
|
*
|
|
364
|
-
*
|
|
365
|
-
*
|
|
366
|
-
*
|
|
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
|
|
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
|
-
*
|
|
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
|
-
*
|
|
353
|
+
* Supported sample formats.
|
|
383
354
|
*
|
|
384
|
-
*
|
|
385
|
-
*
|
|
386
|
-
*
|
|
387
|
-
*
|
|
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
|
-
*
|
|
364
|
+
* Supported channel layouts.
|
|
365
|
+
*
|
|
366
|
+
* Array of channel layouts this audio codec supports.
|
|
367
|
+
* Null for video codecs.
|
|
394
368
|
*
|
|
395
|
-
*
|
|
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
|
|
375
|
+
* Check if codec is an encoder.
|
|
405
376
|
*
|
|
406
|
-
*
|
|
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
|
|
414
|
-
* console.log('
|
|
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
|
|
393
|
+
* Check if codec is a decoder.
|
|
423
394
|
*
|
|
424
|
-
*
|
|
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
|
|
432
|
-
* console.log('
|
|
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
|
|
411
|
+
* Check if codec is experimental.
|
|
441
412
|
*
|
|
442
|
-
* Experimental codecs require explicit
|
|
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
|
|
415
|
+
* @returns True if codec is marked experimental
|
|
447
416
|
*
|
|
448
417
|
* @example
|
|
449
418
|
* ```typescript
|
|
450
|
-
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
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
|
-
*
|
|
429
|
+
* Check if codec supports hardware acceleration.
|
|
462
430
|
*
|
|
463
|
-
*
|
|
431
|
+
* Checks if the codec has any hardware configuration.
|
|
464
432
|
*
|
|
465
|
-
* @
|
|
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.
|
|
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
|
-
*
|
|
476
|
-
*
|
|
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
|
|
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
|