node-av 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,853 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Option - FFmpeg AVOption System Bindings
|
|
3
|
+
*
|
|
4
|
+
* Provides low-level access to FFmpeg's AVOption API for getting and setting
|
|
5
|
+
* options on various FFmpeg objects (CodecContext, FormatContext, FilterContext, etc).
|
|
6
|
+
*
|
|
7
|
+
* The AVOption API is FFmpeg's unified system for runtime configuration,
|
|
8
|
+
* allowing type-safe access to object properties with validation.
|
|
9
|
+
*
|
|
10
|
+
* @module lib/option
|
|
11
|
+
*/
|
|
12
|
+
import { bindings } from './binding.js';
|
|
13
|
+
import { AV_OPT_SEARCH_CHILDREN, AV_OPT_TYPE_BINARY, AV_OPT_TYPE_BINARY_INT_ARRAY, AV_OPT_TYPE_BOOL, AV_OPT_TYPE_CHLAYOUT, AV_OPT_TYPE_COLOR, AV_OPT_TYPE_CONST, AV_OPT_TYPE_DICT, AV_OPT_TYPE_DOUBLE, AV_OPT_TYPE_DURATION, AV_OPT_TYPE_FLAGS, AV_OPT_TYPE_FLOAT, AV_OPT_TYPE_IMAGE_SIZE, AV_OPT_TYPE_INT, AV_OPT_TYPE_INT64, AV_OPT_TYPE_PIXEL_FMT, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_SAMPLE_FMT, AV_OPT_TYPE_STRING, AV_OPT_TYPE_UINT, AV_OPT_TYPE_UINT64, AV_OPT_TYPE_VIDEO_RATE, AVFLAG_NONE, } from './constants.js';
|
|
14
|
+
import { Dictionary } from './dictionary.js';
|
|
15
|
+
import { Rational } from './rational.js';
|
|
16
|
+
/**
|
|
17
|
+
* Low-level wrapper for a single AVOption.
|
|
18
|
+
*
|
|
19
|
+
* Provides metadata about an option including its name, type, range, and default value.
|
|
20
|
+
* Options are not created directly but retrieved through Option.next() or Option.find().
|
|
21
|
+
*
|
|
22
|
+
* @example
|
|
23
|
+
* ```typescript
|
|
24
|
+
* const opt = Option.find(codecContext, 'bitrate');
|
|
25
|
+
* if (opt) {
|
|
26
|
+
* console.log(`Option ${opt.name}: ${opt.help}`);
|
|
27
|
+
* console.log(`Type: ${opt.type}, Default: ${opt.defaultValue}`);
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export class OptionInfo {
|
|
32
|
+
native;
|
|
33
|
+
/** @internal */
|
|
34
|
+
constructor(native) {
|
|
35
|
+
this.native = native;
|
|
36
|
+
}
|
|
37
|
+
/**
|
|
38
|
+
* Option name.
|
|
39
|
+
*
|
|
40
|
+
* The key used to get/set this option.
|
|
41
|
+
*/
|
|
42
|
+
get name() {
|
|
43
|
+
return this.native.name;
|
|
44
|
+
}
|
|
45
|
+
/**
|
|
46
|
+
* Option help text.
|
|
47
|
+
*
|
|
48
|
+
* Human-readable description of the option.
|
|
49
|
+
*/
|
|
50
|
+
get help() {
|
|
51
|
+
return this.native.help;
|
|
52
|
+
}
|
|
53
|
+
/**
|
|
54
|
+
* Option type.
|
|
55
|
+
*
|
|
56
|
+
* Determines the data type and valid range of values.
|
|
57
|
+
*/
|
|
58
|
+
get type() {
|
|
59
|
+
return this.native.type;
|
|
60
|
+
}
|
|
61
|
+
/**
|
|
62
|
+
* Default value.
|
|
63
|
+
*
|
|
64
|
+
* The value used if not explicitly set.
|
|
65
|
+
* Type depends on the option type.
|
|
66
|
+
*/
|
|
67
|
+
get defaultValue() {
|
|
68
|
+
return this.native.defaultValue;
|
|
69
|
+
}
|
|
70
|
+
/**
|
|
71
|
+
* Minimum value.
|
|
72
|
+
*
|
|
73
|
+
* For numeric types, the minimum allowed value.
|
|
74
|
+
*/
|
|
75
|
+
get min() {
|
|
76
|
+
return this.native.min;
|
|
77
|
+
}
|
|
78
|
+
/**
|
|
79
|
+
* Maximum value.
|
|
80
|
+
*
|
|
81
|
+
* For numeric types, the maximum allowed value.
|
|
82
|
+
*/
|
|
83
|
+
get max() {
|
|
84
|
+
return this.native.max;
|
|
85
|
+
}
|
|
86
|
+
/**
|
|
87
|
+
* Option flags.
|
|
88
|
+
*
|
|
89
|
+
* Bitfield of AV_OPT_FLAG_* values indicating option properties.
|
|
90
|
+
*/
|
|
91
|
+
get flags() {
|
|
92
|
+
return this.native.flags;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Option unit.
|
|
96
|
+
*
|
|
97
|
+
* For options that are part of a named group.
|
|
98
|
+
*/
|
|
99
|
+
get unit() {
|
|
100
|
+
return this.native.unit;
|
|
101
|
+
}
|
|
102
|
+
/**
|
|
103
|
+
* Get the native FFmpeg AVOption pointer.
|
|
104
|
+
*
|
|
105
|
+
* @internal For use by other wrapper classes
|
|
106
|
+
* @returns The underlying native option object
|
|
107
|
+
*/
|
|
108
|
+
getNative() {
|
|
109
|
+
return this.native;
|
|
110
|
+
}
|
|
111
|
+
}
|
|
112
|
+
/**
|
|
113
|
+
* Low-level FFmpeg AVOption API.
|
|
114
|
+
*
|
|
115
|
+
* Provides static methods for accessing and modifying options on FFmpeg objects.
|
|
116
|
+
* All methods work with native objects from the low-level API.
|
|
117
|
+
*
|
|
118
|
+
* Uses av_opt_* functions internally.
|
|
119
|
+
*
|
|
120
|
+
* @example
|
|
121
|
+
* ```typescript
|
|
122
|
+
* // Set codec bitrate
|
|
123
|
+
* Option.setInt(codecContext, 'b', 2000000);
|
|
124
|
+
*
|
|
125
|
+
* // Get current bitrate
|
|
126
|
+
* const bitrate = Option.getInt(codecContext, 'b');
|
|
127
|
+
*
|
|
128
|
+
* // Iterate through all options
|
|
129
|
+
* let opt = null;
|
|
130
|
+
* while ((opt = Option.next(codecContext, opt))) {
|
|
131
|
+
* console.log(`${opt.name}: ${opt.help}`);
|
|
132
|
+
* }
|
|
133
|
+
* ```
|
|
134
|
+
*/
|
|
135
|
+
export class Option {
|
|
136
|
+
// Private constructor - static class only
|
|
137
|
+
constructor() {
|
|
138
|
+
throw new Error('Option is a static class and cannot be instantiated');
|
|
139
|
+
}
|
|
140
|
+
// Static Methods - Iteration
|
|
141
|
+
/**
|
|
142
|
+
* Iterate through options of an object.
|
|
143
|
+
*
|
|
144
|
+
* Uses av_opt_next() internally.
|
|
145
|
+
*
|
|
146
|
+
* @param obj - Native object (CodecContext, FormatContext, FilterContext, etc.)
|
|
147
|
+
* @param prev - Previous option for iteration, or null to start
|
|
148
|
+
*
|
|
149
|
+
* @returns Next option or null when done
|
|
150
|
+
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* let opt = null;
|
|
154
|
+
* while ((opt = Option.next(codecContext, opt))) {
|
|
155
|
+
* console.log(`${opt.name}: ${opt.help}`);
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
158
|
+
*/
|
|
159
|
+
static next(obj, prev = null) {
|
|
160
|
+
const result = bindings.Option.next(obj, prev?.getNative());
|
|
161
|
+
return result ? new OptionInfo(result) : null;
|
|
162
|
+
}
|
|
163
|
+
/**
|
|
164
|
+
* Find an option by name.
|
|
165
|
+
*
|
|
166
|
+
* Uses av_opt_find() internally.
|
|
167
|
+
*
|
|
168
|
+
* @param obj - Native object
|
|
169
|
+
* @param name - Option name to find
|
|
170
|
+
* @param searchFlags - Search flags (default: 0)
|
|
171
|
+
*
|
|
172
|
+
* @returns Found option or null
|
|
173
|
+
*
|
|
174
|
+
* @example
|
|
175
|
+
* ```typescript
|
|
176
|
+
* const opt = Option.find(codecContext, 'bitrate');
|
|
177
|
+
* if (opt) {
|
|
178
|
+
* console.log(`Found option: ${opt.name}`);
|
|
179
|
+
* }
|
|
180
|
+
* ```
|
|
181
|
+
*/
|
|
182
|
+
static find(obj, name, searchFlags = AVFLAG_NONE) {
|
|
183
|
+
const result = bindings.Option.find(obj, name, searchFlags);
|
|
184
|
+
return result ? new OptionInfo(result) : null;
|
|
185
|
+
}
|
|
186
|
+
/**
|
|
187
|
+
* Find an option by name with target object information.
|
|
188
|
+
*
|
|
189
|
+
* Uses av_opt_find2() internally.
|
|
190
|
+
*
|
|
191
|
+
* @param obj - Native object
|
|
192
|
+
* @param name - Option name to find
|
|
193
|
+
* @param searchFlags - Search flags (default: 0)
|
|
194
|
+
*
|
|
195
|
+
* @returns Object with option and whether target differs, or null
|
|
196
|
+
*/
|
|
197
|
+
static find2(obj, name, searchFlags = AVFLAG_NONE) {
|
|
198
|
+
const result = bindings.Option.find2(obj, name, searchFlags);
|
|
199
|
+
if (!result)
|
|
200
|
+
return null;
|
|
201
|
+
return {
|
|
202
|
+
option: result.option ? new OptionInfo(result.option) : null,
|
|
203
|
+
isDifferentTarget: result.isDifferentTarget,
|
|
204
|
+
};
|
|
205
|
+
}
|
|
206
|
+
/**
|
|
207
|
+
* Get option value as string.
|
|
208
|
+
*
|
|
209
|
+
* Uses av_opt_get() internally.
|
|
210
|
+
* Converts any option type to its string representation.
|
|
211
|
+
*
|
|
212
|
+
* @param obj - Native object
|
|
213
|
+
* @param name - Option name
|
|
214
|
+
* @param searchFlags - Search flags (default: 0)
|
|
215
|
+
*
|
|
216
|
+
* @returns Value string on success, null if option not found or on error
|
|
217
|
+
*/
|
|
218
|
+
static get(obj, name, searchFlags = AVFLAG_NONE) {
|
|
219
|
+
return bindings.Option.get(obj, name, searchFlags);
|
|
220
|
+
}
|
|
221
|
+
/**
|
|
222
|
+
* Get option value as integer.
|
|
223
|
+
*
|
|
224
|
+
* Uses av_opt_get_int() internally.
|
|
225
|
+
* Option must be of integer type.
|
|
226
|
+
*
|
|
227
|
+
* @param obj - Native object
|
|
228
|
+
* @param name - Option name
|
|
229
|
+
* @param searchFlags - Search flags (default: 0)
|
|
230
|
+
*
|
|
231
|
+
* @returns Integer value on success, null if option not found or on error
|
|
232
|
+
*/
|
|
233
|
+
static getInt(obj, name, searchFlags = AVFLAG_NONE) {
|
|
234
|
+
return bindings.Option.getInt(obj, name, searchFlags);
|
|
235
|
+
}
|
|
236
|
+
/**
|
|
237
|
+
* Get option value as double.
|
|
238
|
+
*
|
|
239
|
+
* Uses av_opt_get_double() internally.
|
|
240
|
+
* Option must be of double/float type.
|
|
241
|
+
*
|
|
242
|
+
* @param obj - Native object
|
|
243
|
+
* @param name - Option name
|
|
244
|
+
* @param searchFlags - Search flags (default: 0)
|
|
245
|
+
*
|
|
246
|
+
* @returns Double value on success, null if option not found or on error
|
|
247
|
+
*/
|
|
248
|
+
static getDouble(obj, name, searchFlags = AVFLAG_NONE) {
|
|
249
|
+
return bindings.Option.getDouble(obj, name, searchFlags);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Get option value as rational.
|
|
253
|
+
*
|
|
254
|
+
* Uses av_opt_get_q() internally.
|
|
255
|
+
* Option must be of rational type.
|
|
256
|
+
*
|
|
257
|
+
* @param obj - Native object
|
|
258
|
+
* @param name - Option name
|
|
259
|
+
* @param searchFlags - Search flags (default: 0)
|
|
260
|
+
*
|
|
261
|
+
* @returns Rational object {num, den} on success, null if option not found or on error
|
|
262
|
+
*/
|
|
263
|
+
static getRational(obj, name, searchFlags = AVFLAG_NONE) {
|
|
264
|
+
return bindings.Option.getRational(obj, name, searchFlags);
|
|
265
|
+
}
|
|
266
|
+
/**
|
|
267
|
+
* Get option value as pixel format.
|
|
268
|
+
*
|
|
269
|
+
* Uses av_opt_get_pixel_fmt() internally.
|
|
270
|
+
* Option must be of pixel format type.
|
|
271
|
+
*
|
|
272
|
+
* @param obj - Native object
|
|
273
|
+
* @param name - Option name
|
|
274
|
+
* @param searchFlags - Search flags (default: 0)
|
|
275
|
+
*
|
|
276
|
+
* @returns AVPixelFormat enum value on success, null if option not found or on error
|
|
277
|
+
*/
|
|
278
|
+
static getPixelFormat(obj, name, searchFlags = AVFLAG_NONE) {
|
|
279
|
+
return bindings.Option.getPixelFormat(obj, name, searchFlags);
|
|
280
|
+
}
|
|
281
|
+
/**
|
|
282
|
+
* Get option value as sample format.
|
|
283
|
+
*
|
|
284
|
+
* Uses av_opt_get_sample_fmt() internally.
|
|
285
|
+
* Option must be of sample format type.
|
|
286
|
+
*
|
|
287
|
+
* @param obj - Native object
|
|
288
|
+
* @param name - Option name
|
|
289
|
+
* @param searchFlags - Search flags (default: 0)
|
|
290
|
+
*
|
|
291
|
+
* @returns AVSampleFormat enum value on success, null if option not found or on error
|
|
292
|
+
*/
|
|
293
|
+
static getSampleFormat(obj, name, searchFlags = AVFLAG_NONE) {
|
|
294
|
+
return bindings.Option.getSampleFormat(obj, name, searchFlags);
|
|
295
|
+
}
|
|
296
|
+
/**
|
|
297
|
+
* Get option value as image size.
|
|
298
|
+
*
|
|
299
|
+
* Uses av_opt_get_image_size() internally.
|
|
300
|
+
* Option must be of image size type.
|
|
301
|
+
*
|
|
302
|
+
* @param obj - Native object
|
|
303
|
+
* @param name - Option name
|
|
304
|
+
* @param searchFlags - Search flags (default: 0)
|
|
305
|
+
*
|
|
306
|
+
* @returns Size object {width, height} on success, null if option not found or on error
|
|
307
|
+
*/
|
|
308
|
+
static getImageSize(obj, name, searchFlags = AVFLAG_NONE) {
|
|
309
|
+
return bindings.Option.getImageSize(obj, name, searchFlags);
|
|
310
|
+
}
|
|
311
|
+
/**
|
|
312
|
+
* Get option value as channel layout.
|
|
313
|
+
*
|
|
314
|
+
* Uses av_opt_get_chlayout() internally.
|
|
315
|
+
* Option must be of channel layout type.
|
|
316
|
+
*
|
|
317
|
+
* @param obj - Native object
|
|
318
|
+
* @param name - Option name
|
|
319
|
+
* @param searchFlags - Search flags (default: 0)
|
|
320
|
+
*
|
|
321
|
+
* @returns ChannelLayout object on success, null if option not found or on error
|
|
322
|
+
*/
|
|
323
|
+
static getChannelLayout(obj, name, searchFlags = AVFLAG_NONE) {
|
|
324
|
+
return bindings.Option.getChannelLayout(obj, name, searchFlags);
|
|
325
|
+
}
|
|
326
|
+
/**
|
|
327
|
+
* Get option value as dictionary.
|
|
328
|
+
*
|
|
329
|
+
* Uses av_opt_get_dict_val() internally.
|
|
330
|
+
* Option must be of dictionary type.
|
|
331
|
+
*
|
|
332
|
+
* @param obj - Native object
|
|
333
|
+
* @param name - Option name
|
|
334
|
+
* @param searchFlags - Search flags (default: 0)
|
|
335
|
+
*
|
|
336
|
+
* @returns Dictionary object on success, null if option not found or on error
|
|
337
|
+
*/
|
|
338
|
+
static getDict(obj, name, searchFlags = AVFLAG_NONE) {
|
|
339
|
+
const native = bindings.Option.getDict(obj, name, searchFlags);
|
|
340
|
+
return native ? Dictionary.fromNative(native) : null;
|
|
341
|
+
}
|
|
342
|
+
/**
|
|
343
|
+
* Set option value from string.
|
|
344
|
+
*
|
|
345
|
+
* Uses av_opt_set() internally.
|
|
346
|
+
* Can be used for any option type - FFmpeg will parse the string.
|
|
347
|
+
*
|
|
348
|
+
* @param obj - Native object
|
|
349
|
+
* @param name - Option name
|
|
350
|
+
* @param value - String value to set
|
|
351
|
+
* @param searchFlags - Search flags (default: 0)
|
|
352
|
+
*
|
|
353
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
354
|
+
*/
|
|
355
|
+
static set(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
356
|
+
return bindings.Option.set(obj, name, value, searchFlags);
|
|
357
|
+
}
|
|
358
|
+
/**
|
|
359
|
+
* Set option value as integer.
|
|
360
|
+
*
|
|
361
|
+
* Uses av_opt_set_int() internally.
|
|
362
|
+
* More efficient than set() for numeric options.
|
|
363
|
+
*
|
|
364
|
+
* @param obj - Native object
|
|
365
|
+
* @param name - Option name
|
|
366
|
+
* @param value - Number or BigInt value to set
|
|
367
|
+
* @param searchFlags - Search flags (default: 0)
|
|
368
|
+
*
|
|
369
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
370
|
+
*/
|
|
371
|
+
static setInt(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
372
|
+
return bindings.Option.setInt(obj, name, value, searchFlags);
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Set option value as double.
|
|
376
|
+
*
|
|
377
|
+
* Uses av_opt_set_double() internally.
|
|
378
|
+
* More efficient than set() for floating point options.
|
|
379
|
+
*
|
|
380
|
+
* @param obj - Native object
|
|
381
|
+
* @param name - Option name
|
|
382
|
+
* @param value - Double value to set
|
|
383
|
+
* @param searchFlags - Search flags (default: 0)
|
|
384
|
+
*
|
|
385
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
386
|
+
*/
|
|
387
|
+
static setDouble(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
388
|
+
return bindings.Option.setDouble(obj, name, value, searchFlags);
|
|
389
|
+
}
|
|
390
|
+
/**
|
|
391
|
+
* Set option value as rational.
|
|
392
|
+
*
|
|
393
|
+
* Uses av_opt_set_q() internally.
|
|
394
|
+
* For framerates, aspect ratios, time bases, etc.
|
|
395
|
+
*
|
|
396
|
+
* @param obj - Native object
|
|
397
|
+
* @param name - Option name
|
|
398
|
+
* @param value - Rational object {num, den} to set
|
|
399
|
+
* @param searchFlags - Search flags (default: 0)
|
|
400
|
+
*
|
|
401
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
402
|
+
*/
|
|
403
|
+
static setRational(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
404
|
+
return bindings.Option.setRational(obj, name, value, searchFlags);
|
|
405
|
+
}
|
|
406
|
+
/**
|
|
407
|
+
* Set option value as pixel format.
|
|
408
|
+
*
|
|
409
|
+
* Uses av_opt_set_pixel_fmt() internally.
|
|
410
|
+
* More type-safe than using set() with string names.
|
|
411
|
+
*
|
|
412
|
+
* @param obj - Native object
|
|
413
|
+
* @param name - Option name
|
|
414
|
+
* @param value - AVPixelFormat enum value
|
|
415
|
+
* @param searchFlags - Search flags (default: 0)
|
|
416
|
+
*
|
|
417
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
418
|
+
*/
|
|
419
|
+
static setPixelFormat(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
420
|
+
return bindings.Option.setPixelFormat(obj, name, value, searchFlags);
|
|
421
|
+
}
|
|
422
|
+
/**
|
|
423
|
+
* Set option value as sample format.
|
|
424
|
+
*
|
|
425
|
+
* Uses av_opt_set_sample_fmt() internally.
|
|
426
|
+
* More type-safe than using set() with string names.
|
|
427
|
+
*
|
|
428
|
+
* @param obj - Native object
|
|
429
|
+
* @param name - Option name
|
|
430
|
+
* @param value - AVSampleFormat enum value
|
|
431
|
+
* @param searchFlags - Search flags (default: 0)
|
|
432
|
+
*
|
|
433
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
434
|
+
*/
|
|
435
|
+
static setSampleFormat(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
436
|
+
return bindings.Option.setSampleFormat(obj, name, value, searchFlags);
|
|
437
|
+
}
|
|
438
|
+
/**
|
|
439
|
+
* Set option value as image size.
|
|
440
|
+
*
|
|
441
|
+
* Uses av_opt_set_image_size() internally.
|
|
442
|
+
* Convenient for setting width and height together.
|
|
443
|
+
*
|
|
444
|
+
* @param obj - Native object
|
|
445
|
+
* @param name - Option name
|
|
446
|
+
* @param width - Width in pixels
|
|
447
|
+
* @param height - Height in pixels
|
|
448
|
+
* @param searchFlags - Search flags (default: 0)
|
|
449
|
+
*
|
|
450
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
451
|
+
*/
|
|
452
|
+
static setImageSize(obj, name, width, height, searchFlags = AVFLAG_NONE) {
|
|
453
|
+
return bindings.Option.setImageSize(obj, name, width, height, searchFlags);
|
|
454
|
+
}
|
|
455
|
+
/**
|
|
456
|
+
* Set option value as channel layout.
|
|
457
|
+
*
|
|
458
|
+
* Uses av_opt_set_chlayout() internally.
|
|
459
|
+
* For audio channel configuration.
|
|
460
|
+
*
|
|
461
|
+
* @param obj - Native object
|
|
462
|
+
* @param name - Option name
|
|
463
|
+
* @param value - Channel layout mask (e.g., AV_CH_LAYOUT_STEREO)
|
|
464
|
+
* @param searchFlags - Search flags (default: 0)
|
|
465
|
+
*
|
|
466
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
467
|
+
*/
|
|
468
|
+
static setChannelLayout(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
469
|
+
return bindings.Option.setChannelLayout(obj, name, value, searchFlags);
|
|
470
|
+
}
|
|
471
|
+
/**
|
|
472
|
+
* Set option value as dictionary.
|
|
473
|
+
*
|
|
474
|
+
* Uses av_opt_set_dict_val() internally.
|
|
475
|
+
* For options that accept key-value pairs.
|
|
476
|
+
*
|
|
477
|
+
* @param obj - Native object
|
|
478
|
+
* @param name - Option name
|
|
479
|
+
* @param value - Dictionary object
|
|
480
|
+
* @param searchFlags - Search flags (default: 0)
|
|
481
|
+
*
|
|
482
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
483
|
+
*/
|
|
484
|
+
static setDict(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
485
|
+
return bindings.Option.setDict(obj, name, value.getNative(), searchFlags);
|
|
486
|
+
}
|
|
487
|
+
/**
|
|
488
|
+
* Set option value as binary data.
|
|
489
|
+
*
|
|
490
|
+
* Uses av_opt_set_bin() internally.
|
|
491
|
+
* For options that accept raw binary data.
|
|
492
|
+
*
|
|
493
|
+
* @param obj - Native object
|
|
494
|
+
* @param name - Option name
|
|
495
|
+
* @param value - Binary data as Buffer
|
|
496
|
+
* @param searchFlags - Search flags (default: 0)
|
|
497
|
+
*
|
|
498
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
499
|
+
*/
|
|
500
|
+
static setBin(obj, name, value, searchFlags = AVFLAG_NONE) {
|
|
501
|
+
return bindings.Option.setBin(obj, name, value, searchFlags);
|
|
502
|
+
}
|
|
503
|
+
/**
|
|
504
|
+
* Set all options to their default values.
|
|
505
|
+
*
|
|
506
|
+
* Uses av_opt_set_defaults() internally.
|
|
507
|
+
*
|
|
508
|
+
* @param obj - Native object
|
|
509
|
+
*/
|
|
510
|
+
static setDefaults(obj) {
|
|
511
|
+
bindings.Option.setDefaults(obj);
|
|
512
|
+
}
|
|
513
|
+
/**
|
|
514
|
+
* Copy options from source to destination.
|
|
515
|
+
*
|
|
516
|
+
* Uses av_opt_copy() internally.
|
|
517
|
+
* Copies all option values from one object to another.
|
|
518
|
+
*
|
|
519
|
+
* @param dest - Destination object
|
|
520
|
+
* @param src - Source object
|
|
521
|
+
*
|
|
522
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
523
|
+
*/
|
|
524
|
+
static copy(dest, src) {
|
|
525
|
+
return bindings.Option.copy(dest, src);
|
|
526
|
+
}
|
|
527
|
+
/**
|
|
528
|
+
* Check if option is set to its default value.
|
|
529
|
+
*
|
|
530
|
+
* Uses av_opt_is_set_to_default_by_name() internally.
|
|
531
|
+
*
|
|
532
|
+
* @param obj - Native object
|
|
533
|
+
* @param name - Option name
|
|
534
|
+
* @param searchFlags - Search flags (default: 0)
|
|
535
|
+
*
|
|
536
|
+
* @returns true if set to default, false if not, null if option not found or on error
|
|
537
|
+
*/
|
|
538
|
+
static isSetToDefault(obj, name, searchFlags = AVFLAG_NONE) {
|
|
539
|
+
return bindings.Option.isSetToDefault(obj, name, searchFlags);
|
|
540
|
+
}
|
|
541
|
+
/**
|
|
542
|
+
* Serialize options to string.
|
|
543
|
+
*
|
|
544
|
+
* Uses av_opt_serialize() internally.
|
|
545
|
+
* Converts all non-default options to a string representation.
|
|
546
|
+
*
|
|
547
|
+
* @param obj - Native object
|
|
548
|
+
* @param optFlags - Option flags to include (default: 0)
|
|
549
|
+
* @param flags - Serialization flags (default: 0)
|
|
550
|
+
* @param keyValSep - Key-value separator (default: '=')
|
|
551
|
+
* @param pairsSep - Pairs separator (default: ',')
|
|
552
|
+
*
|
|
553
|
+
* @returns Serialized string on success, null on error or if no options to serialize
|
|
554
|
+
*/
|
|
555
|
+
static serialize(obj, optFlags = 0, flags = 0, keyValSep = '=', pairsSep = ',') {
|
|
556
|
+
return bindings.Option.serialize(obj, optFlags, flags, keyValSep, pairsSep);
|
|
557
|
+
}
|
|
558
|
+
/**
|
|
559
|
+
* Free options of an object.
|
|
560
|
+
*
|
|
561
|
+
* Uses av_opt_free() internally.
|
|
562
|
+
*
|
|
563
|
+
* @param obj - Native object
|
|
564
|
+
*/
|
|
565
|
+
static free(obj) {
|
|
566
|
+
bindings.Option.free(obj);
|
|
567
|
+
}
|
|
568
|
+
/**
|
|
569
|
+
* Show options to stderr for debugging.
|
|
570
|
+
*
|
|
571
|
+
* Uses av_opt_show2() internally.
|
|
572
|
+
* Prints all available options to stderr.
|
|
573
|
+
*
|
|
574
|
+
* @param obj - Native object
|
|
575
|
+
* @param reqFlags - Required flags (default: 0)
|
|
576
|
+
* @param rejFlags - Rejected flags (default: 0)
|
|
577
|
+
*
|
|
578
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
579
|
+
*/
|
|
580
|
+
static show(obj, reqFlags = 0, rejFlags = 0) {
|
|
581
|
+
return bindings.Option.show(obj, reqFlags, rejFlags);
|
|
582
|
+
}
|
|
583
|
+
}
|
|
584
|
+
/**
|
|
585
|
+
* Base class for FFmpeg objects that support AVOptions.
|
|
586
|
+
*
|
|
587
|
+
* Provides a common interface for getting, setting, and listing options
|
|
588
|
+
* on FFmpeg objects that have an AVClass structure. This includes codecs,
|
|
589
|
+
* formats, filters, and various processing contexts.
|
|
590
|
+
*
|
|
591
|
+
* Classes that support AVOptions should extend this class to inherit
|
|
592
|
+
* the option management functionality.
|
|
593
|
+
*
|
|
594
|
+
* @template T - The native FFmpeg object type that supports AVOptions
|
|
595
|
+
*
|
|
596
|
+
* @example
|
|
597
|
+
* ```typescript
|
|
598
|
+
* class CodecContext extends OptionMember<NativeCodecContext> {
|
|
599
|
+
* // Inherits setOption, getOption, listOptions
|
|
600
|
+
* }
|
|
601
|
+
* ```
|
|
602
|
+
*/
|
|
603
|
+
export class OptionMember {
|
|
604
|
+
native;
|
|
605
|
+
constructor(native) {
|
|
606
|
+
this.native = native;
|
|
607
|
+
}
|
|
608
|
+
/**
|
|
609
|
+
* Set an option on this object.
|
|
610
|
+
*
|
|
611
|
+
* Uses the AVOption API to set options.
|
|
612
|
+
* Available options depend on the specific object type.
|
|
613
|
+
*
|
|
614
|
+
* @param name - Option name
|
|
615
|
+
* @param value - Option value
|
|
616
|
+
* @param type - Option type (defaults to AV_OPT_TYPE_STRING)
|
|
617
|
+
* @param searchFlags - Search flags (default: AV_OPT_SEARCH_CHILDREN)
|
|
618
|
+
* @returns 0 on success, negative AVERROR code on failure
|
|
619
|
+
*
|
|
620
|
+
* @example
|
|
621
|
+
* ```typescript
|
|
622
|
+
* // String options (default)
|
|
623
|
+
* ret = obj.setOption('preset', 'fast');
|
|
624
|
+
* ret = obj.setOption('codec', 'h264', AV_OPT_TYPE_STRING);
|
|
625
|
+
*
|
|
626
|
+
* // Integer options
|
|
627
|
+
* ret = obj.setOption('bitrate', 2000000, AV_OPT_TYPE_INT64);
|
|
628
|
+
* ret = obj.setOption('threads', 4, AV_OPT_TYPE_INT);
|
|
629
|
+
*
|
|
630
|
+
* // Complex types with proper types
|
|
631
|
+
* ret = obj.setOption('framerate', {num: 30, den: 1}, AV_OPT_TYPE_RATIONAL);
|
|
632
|
+
* ret = obj.setOption('pix_fmt', AV_PIX_FMT_YUV420P, AV_OPT_TYPE_PIXEL_FMT);
|
|
633
|
+
* ```
|
|
634
|
+
*/
|
|
635
|
+
setOption(name, value, type = AV_OPT_TYPE_STRING, searchFlags = AV_OPT_SEARCH_CHILDREN) {
|
|
636
|
+
// Use specific setter based on type
|
|
637
|
+
switch (type) {
|
|
638
|
+
case AV_OPT_TYPE_STRING:
|
|
639
|
+
case AV_OPT_TYPE_COLOR: // Colors are set as strings
|
|
640
|
+
return Option.set(this.native, name, String(value), searchFlags);
|
|
641
|
+
case AV_OPT_TYPE_INT:
|
|
642
|
+
const intVal = Number(value);
|
|
643
|
+
if (!Number.isInteger(intVal)) {
|
|
644
|
+
throw new TypeError(`Option '${name}': Expected integer value, got ${value}`);
|
|
645
|
+
}
|
|
646
|
+
return Option.setInt(this.native, name, intVal, searchFlags);
|
|
647
|
+
case AV_OPT_TYPE_UINT:
|
|
648
|
+
const uintVal = Number(value);
|
|
649
|
+
if (!Number.isInteger(uintVal) || uintVal < 0) {
|
|
650
|
+
throw new RangeError(`Option '${name}': Expected non-negative integer value, got ${value}`);
|
|
651
|
+
}
|
|
652
|
+
return Option.setInt(this.native, name, uintVal, searchFlags);
|
|
653
|
+
case AV_OPT_TYPE_FLAGS:
|
|
654
|
+
case AV_OPT_TYPE_DURATION:
|
|
655
|
+
case AV_OPT_TYPE_CONST:
|
|
656
|
+
return Option.setInt(this.native, name, Number(value), searchFlags);
|
|
657
|
+
case AV_OPT_TYPE_BOOL:
|
|
658
|
+
// Convert to 0 or 1 for FFmpeg
|
|
659
|
+
return Option.setInt(this.native, name, value ? 1 : 0, searchFlags);
|
|
660
|
+
case AV_OPT_TYPE_INT64:
|
|
661
|
+
// Accept both bigint and number
|
|
662
|
+
if (typeof value === 'bigint') {
|
|
663
|
+
return Option.setInt(this.native, name, value, searchFlags);
|
|
664
|
+
}
|
|
665
|
+
else if (typeof value === 'number') {
|
|
666
|
+
if (!Number.isInteger(value)) {
|
|
667
|
+
throw new TypeError(`Option '${name}': Expected integer value for INT64, got ${value}`);
|
|
668
|
+
}
|
|
669
|
+
return Option.setInt(this.native, name, value, searchFlags);
|
|
670
|
+
}
|
|
671
|
+
else {
|
|
672
|
+
throw new TypeError(`Option '${name}': Expected bigint or number for INT64, got ${typeof value}`);
|
|
673
|
+
}
|
|
674
|
+
case AV_OPT_TYPE_UINT64:
|
|
675
|
+
// Accept both bigint and number, but must be non-negative
|
|
676
|
+
if (typeof value === 'bigint') {
|
|
677
|
+
if (value < 0n) {
|
|
678
|
+
throw new RangeError(`Option '${name}': Expected non-negative value for UINT64, got ${value}`);
|
|
679
|
+
}
|
|
680
|
+
return Option.setInt(this.native, name, value, searchFlags);
|
|
681
|
+
}
|
|
682
|
+
else if (typeof value === 'number') {
|
|
683
|
+
if (!Number.isInteger(value) || value < 0) {
|
|
684
|
+
throw new RangeError(`Option '${name}': Expected non-negative integer for UINT64, got ${value}`);
|
|
685
|
+
}
|
|
686
|
+
return Option.setInt(this.native, name, value, searchFlags);
|
|
687
|
+
}
|
|
688
|
+
else {
|
|
689
|
+
throw new TypeError(`Option '${name}': Expected bigint or number for UINT64, got ${typeof value}`);
|
|
690
|
+
}
|
|
691
|
+
case AV_OPT_TYPE_DOUBLE:
|
|
692
|
+
case AV_OPT_TYPE_FLOAT:
|
|
693
|
+
return Option.setDouble(this.native, name, Number(value), searchFlags);
|
|
694
|
+
case AV_OPT_TYPE_RATIONAL:
|
|
695
|
+
case AV_OPT_TYPE_VIDEO_RATE:
|
|
696
|
+
if (typeof value !== 'object' || !('num' in value) || !('den' in value)) {
|
|
697
|
+
throw new TypeError(`Option '${name}': Expected Rational object with {num, den}, got ${JSON.stringify(value)}`);
|
|
698
|
+
}
|
|
699
|
+
if (value.den === 0) {
|
|
700
|
+
throw new RangeError(`Option '${name}': Rational denominator cannot be zero`);
|
|
701
|
+
}
|
|
702
|
+
return Option.setRational(this.native, name, value, searchFlags);
|
|
703
|
+
case AV_OPT_TYPE_PIXEL_FMT:
|
|
704
|
+
const pixFmt = Number(value);
|
|
705
|
+
if (!Number.isInteger(pixFmt)) {
|
|
706
|
+
throw new TypeError(`Option '${name}': Expected integer pixel format value, got ${value}`);
|
|
707
|
+
}
|
|
708
|
+
return Option.setPixelFormat(this.native, name, pixFmt, searchFlags);
|
|
709
|
+
case AV_OPT_TYPE_SAMPLE_FMT:
|
|
710
|
+
const sampleFmt = Number(value);
|
|
711
|
+
if (!Number.isInteger(sampleFmt)) {
|
|
712
|
+
throw new TypeError(`Option '${name}': Expected integer sample format value, got ${value}`);
|
|
713
|
+
}
|
|
714
|
+
return Option.setSampleFormat(this.native, name, sampleFmt, searchFlags);
|
|
715
|
+
case AV_OPT_TYPE_IMAGE_SIZE:
|
|
716
|
+
// Expect value as {width, height}
|
|
717
|
+
if (typeof value === 'object' && 'width' in value && 'height' in value) {
|
|
718
|
+
const width = Number(value.width);
|
|
719
|
+
const height = Number(value.height);
|
|
720
|
+
if (!Number.isInteger(width) || width <= 0) {
|
|
721
|
+
throw new RangeError(`Option '${name}': Width must be a positive integer, got ${value.width}`);
|
|
722
|
+
}
|
|
723
|
+
if (!Number.isInteger(height) || height <= 0) {
|
|
724
|
+
throw new RangeError(`Option '${name}': Height must be a positive integer, got ${value.height}`);
|
|
725
|
+
}
|
|
726
|
+
return Option.setImageSize(this.native, name, width, height, searchFlags);
|
|
727
|
+
}
|
|
728
|
+
throw new TypeError(`Option '${name}': Expected object with {width, height}, got ${JSON.stringify(value)}`);
|
|
729
|
+
case AV_OPT_TYPE_CHLAYOUT:
|
|
730
|
+
return Option.setChannelLayout(this.native, name, Number(value), searchFlags);
|
|
731
|
+
case AV_OPT_TYPE_BINARY:
|
|
732
|
+
if (Buffer.isBuffer(value)) {
|
|
733
|
+
return Option.setBin(this.native, name, value, searchFlags);
|
|
734
|
+
}
|
|
735
|
+
throw new Error('Invalid value for BINARY option: expected Buffer');
|
|
736
|
+
case AV_OPT_TYPE_BINARY_INT_ARRAY:
|
|
737
|
+
if (Array.isArray(value)) {
|
|
738
|
+
// Convert array of integers to buffer
|
|
739
|
+
const buffer = Buffer.allocUnsafe(value.length * 4);
|
|
740
|
+
for (let i = 0; i < value.length; i++) {
|
|
741
|
+
buffer.writeInt32LE(value[i], i * 4);
|
|
742
|
+
}
|
|
743
|
+
return Option.setBin(this.native, name, buffer, searchFlags);
|
|
744
|
+
}
|
|
745
|
+
throw new Error('Invalid value for BINARY_INT_ARRAY option: expected number[]');
|
|
746
|
+
case AV_OPT_TYPE_DICT:
|
|
747
|
+
if (value instanceof Dictionary) {
|
|
748
|
+
return Option.setDict(this.native, name, value, searchFlags);
|
|
749
|
+
}
|
|
750
|
+
throw new Error('Invalid value for DICT option: expected Dictionary');
|
|
751
|
+
default:
|
|
752
|
+
// Fallback to string
|
|
753
|
+
return Option.set(this.native, name, String(value), searchFlags);
|
|
754
|
+
}
|
|
755
|
+
}
|
|
756
|
+
/**
|
|
757
|
+
* Get an option value from this object.
|
|
758
|
+
*
|
|
759
|
+
* Uses the AVOption API to retrieve options.
|
|
760
|
+
*
|
|
761
|
+
* @param name - Option name
|
|
762
|
+
* @param type - Option type (defaults to AV_OPT_TYPE_STRING)
|
|
763
|
+
* @param searchFlags - Search flags (default: AV_OPT_SEARCH_CHILDREN)
|
|
764
|
+
* @returns Option value (type depends on type parameter)
|
|
765
|
+
*
|
|
766
|
+
* @example
|
|
767
|
+
* ```typescript
|
|
768
|
+
* // String options (default)
|
|
769
|
+
* const preset = obj.getOption('preset');
|
|
770
|
+
* const codec = obj.getOption('codec', AV_OPT_TYPE_STRING);
|
|
771
|
+
*
|
|
772
|
+
* // Typed options
|
|
773
|
+
* const framerate = obj.getOption('framerate', AV_OPT_TYPE_RATIONAL); // Returns {num, den}
|
|
774
|
+
* const pixFmt = obj.getOption('pix_fmt', AV_OPT_TYPE_PIXEL_FMT); // Returns AVPixelFormat
|
|
775
|
+
* const bitrate = obj.getOption('bitrate', AV_OPT_TYPE_INT64); // Returns number
|
|
776
|
+
* ```
|
|
777
|
+
*/
|
|
778
|
+
getOption(name, type = AV_OPT_TYPE_STRING, searchFlags = AV_OPT_SEARCH_CHILDREN) {
|
|
779
|
+
// Use specific getter based on type
|
|
780
|
+
switch (type) {
|
|
781
|
+
case AV_OPT_TYPE_STRING:
|
|
782
|
+
case AV_OPT_TYPE_COLOR:
|
|
783
|
+
return Option.get(this.native, name, searchFlags);
|
|
784
|
+
case AV_OPT_TYPE_INT:
|
|
785
|
+
case AV_OPT_TYPE_UINT:
|
|
786
|
+
case AV_OPT_TYPE_FLAGS:
|
|
787
|
+
case AV_OPT_TYPE_DURATION:
|
|
788
|
+
case AV_OPT_TYPE_CONST:
|
|
789
|
+
return Option.getInt(this.native, name, searchFlags);
|
|
790
|
+
case AV_OPT_TYPE_INT64:
|
|
791
|
+
case AV_OPT_TYPE_UINT64:
|
|
792
|
+
// For INT64/UINT64, we should return bigint for proper precision
|
|
793
|
+
const int64Val = Option.getInt(this.native, name, searchFlags);
|
|
794
|
+
return int64Val !== null ? BigInt(int64Val) : null;
|
|
795
|
+
case AV_OPT_TYPE_BOOL:
|
|
796
|
+
const val = Option.getInt(this.native, name, searchFlags);
|
|
797
|
+
return val !== null ? Boolean(val) : null;
|
|
798
|
+
case AV_OPT_TYPE_DOUBLE:
|
|
799
|
+
case AV_OPT_TYPE_FLOAT:
|
|
800
|
+
return Option.getDouble(this.native, name, searchFlags);
|
|
801
|
+
case AV_OPT_TYPE_RATIONAL:
|
|
802
|
+
case AV_OPT_TYPE_VIDEO_RATE:
|
|
803
|
+
const rational = Option.getRational(this.native, name, searchFlags);
|
|
804
|
+
return rational ? new Rational(rational.num, rational.den) : null;
|
|
805
|
+
case AV_OPT_TYPE_PIXEL_FMT:
|
|
806
|
+
return Option.getPixelFormat(this.native, name, searchFlags);
|
|
807
|
+
case AV_OPT_TYPE_SAMPLE_FMT:
|
|
808
|
+
return Option.getSampleFormat(this.native, name, searchFlags);
|
|
809
|
+
case AV_OPT_TYPE_IMAGE_SIZE:
|
|
810
|
+
return Option.getImageSize(this.native, name, searchFlags);
|
|
811
|
+
case AV_OPT_TYPE_CHLAYOUT:
|
|
812
|
+
return Option.getChannelLayout(this.native, name, searchFlags);
|
|
813
|
+
case AV_OPT_TYPE_DICT:
|
|
814
|
+
return Option.getDict(this.native, name, searchFlags);
|
|
815
|
+
case AV_OPT_TYPE_BINARY:
|
|
816
|
+
// Binary data can only be retrieved as string
|
|
817
|
+
return Option.get(this.native, name, searchFlags);
|
|
818
|
+
case AV_OPT_TYPE_BINARY_INT_ARRAY:
|
|
819
|
+
// Getting binary int arrays is not supported (requires av_opt_get_bin())
|
|
820
|
+
// These are typically write-only options like 'pix_fmts' in buffersink
|
|
821
|
+
throw new Error('Getting BINARY_INT_ARRAY options is not supported. These are typically write-only options.');
|
|
822
|
+
default:
|
|
823
|
+
// Fallback to string
|
|
824
|
+
return Option.get(this.native, name, searchFlags);
|
|
825
|
+
}
|
|
826
|
+
}
|
|
827
|
+
/**
|
|
828
|
+
* List all available options for this object.
|
|
829
|
+
*
|
|
830
|
+
* Uses the AVOption API to enumerate all options.
|
|
831
|
+
* Useful for discovering available settings and their types.
|
|
832
|
+
*
|
|
833
|
+
* @returns Array of option information objects
|
|
834
|
+
*
|
|
835
|
+
* @example
|
|
836
|
+
* ```typescript
|
|
837
|
+
* const options = obj.listOptions();
|
|
838
|
+
* for (const opt of options) {
|
|
839
|
+
* console.log(`${opt.name}: ${opt.help}`);
|
|
840
|
+
* console.log(` Type: ${opt.type}, Default: ${opt.defaultValue}`);
|
|
841
|
+
* }
|
|
842
|
+
* ```
|
|
843
|
+
*/
|
|
844
|
+
listOptions() {
|
|
845
|
+
const options = [];
|
|
846
|
+
let opt = null;
|
|
847
|
+
while ((opt = Option.next(this.native, opt))) {
|
|
848
|
+
options.push(opt);
|
|
849
|
+
}
|
|
850
|
+
return options;
|
|
851
|
+
}
|
|
852
|
+
}
|
|
853
|
+
//# sourceMappingURL=option.js.map
|