node-av-light 0.0.0-stage → 7.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +710 -2
  3. package/dist/api/audio-frame-buffer.d.ts +636 -0
  4. package/dist/api/audio-frame-buffer.js +1027 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +938 -0
  7. package/dist/api/bitstream-filter.js +1427 -0
  8. package/dist/api/bitstream-filter.js.map +1 -0
  9. package/dist/api/constants.d.ts +44 -0
  10. package/dist/api/constants.js +45 -0
  11. package/dist/api/constants.js.map +1 -0
  12. package/dist/api/data/test_av1.ivf +0 -0
  13. package/dist/api/data/test_h264.h264 +0 -0
  14. package/dist/api/data/test_hevc.h265 +0 -0
  15. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  16. package/dist/api/data/test_vp8.ivf +0 -0
  17. package/dist/api/data/test_vp9.ivf +0 -0
  18. package/dist/api/decoder.d.ts +1413 -0
  19. package/dist/api/decoder.js +2367 -0
  20. package/dist/api/decoder.js.map +1 -0
  21. package/dist/api/demuxer.d.ts +1295 -0
  22. package/dist/api/demuxer.js +2344 -0
  23. package/dist/api/demuxer.js.map +1 -0
  24. package/dist/api/device.d.ts +589 -0
  25. package/dist/api/device.js +964 -0
  26. package/dist/api/device.js.map +1 -0
  27. package/dist/api/encoder-pool.d.ts +262 -0
  28. package/dist/api/encoder-pool.js +397 -0
  29. package/dist/api/encoder-pool.js.map +1 -0
  30. package/dist/api/encoder.d.ts +1509 -0
  31. package/dist/api/encoder.js +2619 -0
  32. package/dist/api/encoder.js.map +1 -0
  33. package/dist/api/filter-complex.d.ts +828 -0
  34. package/dist/api/filter-complex.js +1661 -0
  35. package/dist/api/filter-complex.js.map +1 -0
  36. package/dist/api/filter-presets.d.ts +800 -0
  37. package/dist/api/filter-presets.js +1554 -0
  38. package/dist/api/filter-presets.js.map +1 -0
  39. package/dist/api/filter.d.ts +1339 -0
  40. package/dist/api/filter.js +2075 -0
  41. package/dist/api/filter.js.map +1 -0
  42. package/dist/api/fmp4-stream.d.ts +797 -0
  43. package/dist/api/fmp4-stream.js +1428 -0
  44. package/dist/api/fmp4-stream.js.map +1 -0
  45. package/dist/api/hardware.d.ts +677 -0
  46. package/dist/api/hardware.js +1300 -0
  47. package/dist/api/hardware.js.map +1 -0
  48. package/dist/api/index.d.ts +21 -0
  49. package/dist/api/index.js +38 -0
  50. package/dist/api/index.js.map +1 -0
  51. package/dist/api/io-stream.d.ts +308 -0
  52. package/dist/api/io-stream.js +358 -0
  53. package/dist/api/io-stream.js.map +1 -0
  54. package/dist/api/muxer.d.ts +1311 -0
  55. package/dist/api/muxer.js +2672 -0
  56. package/dist/api/muxer.js.map +1 -0
  57. package/dist/api/pipeline.d.ts +801 -0
  58. package/dist/api/pipeline.js +1344 -0
  59. package/dist/api/pipeline.js.map +1 -0
  60. package/dist/api/probe.d.ts +128 -0
  61. package/dist/api/probe.js +227 -0
  62. package/dist/api/probe.js.map +1 -0
  63. package/dist/api/rtp-stream.d.ts +497 -0
  64. package/dist/api/rtp-stream.js +1131 -0
  65. package/dist/api/rtp-stream.js.map +1 -0
  66. package/dist/api/scaler.d.ts +561 -0
  67. package/dist/api/scaler.js +918 -0
  68. package/dist/api/scaler.js.map +1 -0
  69. package/dist/api/types.d.ts +17 -0
  70. package/dist/api/types.js +2 -0
  71. package/dist/api/types.js.map +1 -0
  72. package/dist/api/utilities/async-queue.d.ts +149 -0
  73. package/dist/api/utilities/async-queue.js +254 -0
  74. package/dist/api/utilities/async-queue.js.map +1 -0
  75. package/dist/api/utilities/audio-sample.d.ts +117 -0
  76. package/dist/api/utilities/audio-sample.js +112 -0
  77. package/dist/api/utilities/audio-sample.js.map +1 -0
  78. package/dist/api/utilities/audio-transcode.d.ts +20 -0
  79. package/dist/api/utilities/audio-transcode.js +27 -0
  80. package/dist/api/utilities/audio-transcode.js.map +1 -0
  81. package/dist/api/utilities/channel-layout.d.ts +76 -0
  82. package/dist/api/utilities/channel-layout.js +80 -0
  83. package/dist/api/utilities/channel-layout.js.map +1 -0
  84. package/dist/api/utilities/codec-format.d.ts +87 -0
  85. package/dist/api/utilities/codec-format.js +117 -0
  86. package/dist/api/utilities/codec-format.js.map +1 -0
  87. package/dist/api/utilities/context-options.d.ts +25 -0
  88. package/dist/api/utilities/context-options.js +23 -0
  89. package/dist/api/utilities/context-options.js.map +1 -0
  90. package/dist/api/utilities/electron-shared-texture.d.ts +368 -0
  91. package/dist/api/utilities/electron-shared-texture.js +540 -0
  92. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  93. package/dist/api/utilities/image.d.ts +207 -0
  94. package/dist/api/utilities/image.js +213 -0
  95. package/dist/api/utilities/image.js.map +1 -0
  96. package/dist/api/utilities/index.d.ts +14 -0
  97. package/dist/api/utilities/index.js +27 -0
  98. package/dist/api/utilities/index.js.map +1 -0
  99. package/dist/api/utilities/live-decoding.d.ts +15 -0
  100. package/dist/api/utilities/live-decoding.js +32 -0
  101. package/dist/api/utilities/live-decoding.js.map +1 -0
  102. package/dist/api/utilities/media-type.d.ts +49 -0
  103. package/dist/api/utilities/media-type.js +53 -0
  104. package/dist/api/utilities/media-type.js.map +1 -0
  105. package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
  106. package/dist/api/utilities/packet-age-watchdog.js +594 -0
  107. package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
  108. package/dist/api/utilities/pixel-format.d.ts +89 -0
  109. package/dist/api/utilities/pixel-format.js +97 -0
  110. package/dist/api/utilities/pixel-format.js.map +1 -0
  111. package/dist/api/utilities/sample-format.d.ts +129 -0
  112. package/dist/api/utilities/sample-format.js +141 -0
  113. package/dist/api/utilities/sample-format.js.map +1 -0
  114. package/dist/api/utilities/scale-size.d.ts +51 -0
  115. package/dist/api/utilities/scale-size.js +55 -0
  116. package/dist/api/utilities/scale-size.js.map +1 -0
  117. package/dist/api/utilities/scheduler.d.ts +138 -0
  118. package/dist/api/utilities/scheduler.js +98 -0
  119. package/dist/api/utilities/scheduler.js.map +1 -0
  120. package/dist/api/utilities/streaming.d.ts +186 -0
  121. package/dist/api/utilities/streaming.js +309 -0
  122. package/dist/api/utilities/streaming.js.map +1 -0
  123. package/dist/api/utilities/timestamp.d.ts +193 -0
  124. package/dist/api/utilities/timestamp.js +206 -0
  125. package/dist/api/utilities/timestamp.js.map +1 -0
  126. package/dist/api/utilities/video-transcode.d.ts +218 -0
  127. package/dist/api/utilities/video-transcode.js +624 -0
  128. package/dist/api/utilities/video-transcode.js.map +1 -0
  129. package/dist/api/utilities/whisper-model.d.ts +330 -0
  130. package/dist/api/utilities/whisper-model.js +587 -0
  131. package/dist/api/utilities/whisper-model.js.map +1 -0
  132. package/dist/api/utils.d.ts +19 -0
  133. package/dist/api/utils.js +39 -0
  134. package/dist/api/utils.js.map +1 -0
  135. package/dist/api/webrtc-stream.d.ts +294 -0
  136. package/dist/api/webrtc-stream.js +546 -0
  137. package/dist/api/webrtc-stream.js.map +1 -0
  138. package/dist/api/whisper.d.ts +326 -0
  139. package/dist/api/whisper.js +402 -0
  140. package/dist/api/whisper.js.map +1 -0
  141. package/dist/constants/bsf-options.d.ts +364 -0
  142. package/dist/constants/bsf-options.js +7 -0
  143. package/dist/constants/bsf-options.js.map +1 -0
  144. package/dist/constants/channel-layouts.d.ts +53 -0
  145. package/dist/constants/channel-layouts.js +57 -0
  146. package/dist/constants/channel-layouts.js.map +1 -0
  147. package/dist/constants/constants.d.ts +2435 -0
  148. package/dist/constants/constants.js +1989 -0
  149. package/dist/constants/constants.js.map +1 -0
  150. package/dist/constants/decoders.d.ts +651 -0
  151. package/dist/constants/decoders.js +641 -0
  152. package/dist/constants/decoders.js.map +1 -0
  153. package/dist/constants/encoders.d.ts +314 -0
  154. package/dist/constants/encoders.js +309 -0
  155. package/dist/constants/encoders.js.map +1 -0
  156. package/dist/constants/filter-options.d.ts +12099 -0
  157. package/dist/constants/filter-options.js +7 -0
  158. package/dist/constants/filter-options.js.map +1 -0
  159. package/dist/constants/format-options.d.ts +4319 -0
  160. package/dist/constants/format-options.js +7 -0
  161. package/dist/constants/format-options.js.map +1 -0
  162. package/dist/constants/formats.d.ts +18 -0
  163. package/dist/constants/formats.js +7 -0
  164. package/dist/constants/formats.js.map +1 -0
  165. package/dist/constants/hardware.d.ts +26 -0
  166. package/dist/constants/hardware.js +27 -0
  167. package/dist/constants/hardware.js.map +1 -0
  168. package/dist/constants/index.d.ts +10 -0
  169. package/dist/constants/index.js +6 -0
  170. package/dist/constants/index.js.map +1 -0
  171. package/dist/constants/options.d.ts +6217 -0
  172. package/dist/constants/options.js +7 -0
  173. package/dist/constants/options.js.map +1 -0
  174. package/dist/ffmpeg/index.d.ts +101 -0
  175. package/dist/ffmpeg/index.js +161 -0
  176. package/dist/ffmpeg/index.js.map +1 -0
  177. package/dist/ffmpeg/version.d.ts +6 -0
  178. package/dist/ffmpeg/version.js +7 -0
  179. package/dist/ffmpeg/version.js.map +1 -0
  180. package/dist/index.d.ts +4 -0
  181. package/dist/index.js +9 -0
  182. package/dist/index.js.map +1 -0
  183. package/dist/lib/audio-fifo.d.ts +399 -0
  184. package/dist/lib/audio-fifo.js +431 -0
  185. package/dist/lib/audio-fifo.js.map +1 -0
  186. package/dist/lib/binding.d.ts +242 -0
  187. package/dist/lib/binding.js +102 -0
  188. package/dist/lib/binding.js.map +1 -0
  189. package/dist/lib/bitstream-filter-context.d.ts +381 -0
  190. package/dist/lib/bitstream-filter-context.js +443 -0
  191. package/dist/lib/bitstream-filter-context.js.map +1 -0
  192. package/dist/lib/bitstream-filter.d.ts +140 -0
  193. package/dist/lib/bitstream-filter.js +154 -0
  194. package/dist/lib/bitstream-filter.js.map +1 -0
  195. package/dist/lib/codec-context.d.ts +1069 -0
  196. package/dist/lib/codec-context.js +1336 -0
  197. package/dist/lib/codec-context.js.map +1 -0
  198. package/dist/lib/codec-parameters.d.ts +664 -0
  199. package/dist/lib/codec-parameters.js +813 -0
  200. package/dist/lib/codec-parameters.js.map +1 -0
  201. package/dist/lib/codec-parser.d.ts +201 -0
  202. package/dist/lib/codec-parser.js +213 -0
  203. package/dist/lib/codec-parser.js.map +1 -0
  204. package/dist/lib/codec.d.ts +617 -0
  205. package/dist/lib/codec.js +746 -0
  206. package/dist/lib/codec.js.map +1 -0
  207. package/dist/lib/device.d.ts +294 -0
  208. package/dist/lib/device.js +326 -0
  209. package/dist/lib/device.js.map +1 -0
  210. package/dist/lib/dictionary.d.ts +333 -0
  211. package/dist/lib/dictionary.js +372 -0
  212. package/dist/lib/dictionary.js.map +1 -0
  213. package/dist/lib/error.d.ts +311 -0
  214. package/dist/lib/error.js +395 -0
  215. package/dist/lib/error.js.map +1 -0
  216. package/dist/lib/fifo.d.ts +416 -0
  217. package/dist/lib/fifo.js +453 -0
  218. package/dist/lib/fifo.js.map +1 -0
  219. package/dist/lib/filter-context.d.ts +714 -0
  220. package/dist/lib/filter-context.js +783 -0
  221. package/dist/lib/filter-context.js.map +1 -0
  222. package/dist/lib/filter-graph-segment.d.ts +161 -0
  223. package/dist/lib/filter-graph-segment.js +172 -0
  224. package/dist/lib/filter-graph-segment.js.map +1 -0
  225. package/dist/lib/filter-graph.d.ts +641 -0
  226. package/dist/lib/filter-graph.js +704 -0
  227. package/dist/lib/filter-graph.js.map +1 -0
  228. package/dist/lib/filter-inout.d.ts +202 -0
  229. package/dist/lib/filter-inout.js +261 -0
  230. package/dist/lib/filter-inout.js.map +1 -0
  231. package/dist/lib/filter.d.ts +243 -0
  232. package/dist/lib/filter.js +272 -0
  233. package/dist/lib/filter.js.map +1 -0
  234. package/dist/lib/format-context.d.ts +1335 -0
  235. package/dist/lib/format-context.js +1455 -0
  236. package/dist/lib/format-context.js.map +1 -0
  237. package/dist/lib/frame-utils.d.ts +116 -0
  238. package/dist/lib/frame-utils.js +98 -0
  239. package/dist/lib/frame-utils.js.map +1 -0
  240. package/dist/lib/frame.d.ts +1315 -0
  241. package/dist/lib/frame.js +1535 -0
  242. package/dist/lib/frame.js.map +1 -0
  243. package/dist/lib/hardware-device-context.d.ts +362 -0
  244. package/dist/lib/hardware-device-context.js +383 -0
  245. package/dist/lib/hardware-device-context.js.map +1 -0
  246. package/dist/lib/hardware-frames-context.d.ts +418 -0
  247. package/dist/lib/hardware-frames-context.js +471 -0
  248. package/dist/lib/hardware-frames-context.js.map +1 -0
  249. package/dist/lib/index.d.ts +35 -0
  250. package/dist/lib/index.js +60 -0
  251. package/dist/lib/index.js.map +1 -0
  252. package/dist/lib/input-format.d.ts +249 -0
  253. package/dist/lib/input-format.js +306 -0
  254. package/dist/lib/input-format.js.map +1 -0
  255. package/dist/lib/io-context.d.ts +698 -0
  256. package/dist/lib/io-context.js +771 -0
  257. package/dist/lib/io-context.js.map +1 -0
  258. package/dist/lib/log.d.ts +174 -0
  259. package/dist/lib/log.js +184 -0
  260. package/dist/lib/log.js.map +1 -0
  261. package/dist/lib/native-types.d.ts +1024 -0
  262. package/dist/lib/native-types.js +2 -0
  263. package/dist/lib/native-types.js.map +1 -0
  264. package/dist/lib/option.d.ts +953 -0
  265. package/dist/lib/option.js +1607 -0
  266. package/dist/lib/option.js.map +1 -0
  267. package/dist/lib/output-format.d.ts +222 -0
  268. package/dist/lib/output-format.js +259 -0
  269. package/dist/lib/output-format.js.map +1 -0
  270. package/dist/lib/packet.d.ts +521 -0
  271. package/dist/lib/packet.js +613 -0
  272. package/dist/lib/packet.js.map +1 -0
  273. package/dist/lib/rational.d.ts +251 -0
  274. package/dist/lib/rational.js +278 -0
  275. package/dist/lib/rational.js.map +1 -0
  276. package/dist/lib/software-resample-context.d.ts +552 -0
  277. package/dist/lib/software-resample-context.js +592 -0
  278. package/dist/lib/software-resample-context.js.map +1 -0
  279. package/dist/lib/software-scale-context.d.ts +344 -0
  280. package/dist/lib/software-scale-context.js +366 -0
  281. package/dist/lib/software-scale-context.js.map +1 -0
  282. package/dist/lib/stream.d.ts +383 -0
  283. package/dist/lib/stream.js +524 -0
  284. package/dist/lib/stream.js.map +1 -0
  285. package/dist/lib/sync-queue.d.ts +179 -0
  286. package/dist/lib/sync-queue.js +197 -0
  287. package/dist/lib/sync-queue.js.map +1 -0
  288. package/dist/lib/types.d.ts +34 -0
  289. package/dist/lib/types.js +2 -0
  290. package/dist/lib/types.js.map +1 -0
  291. package/dist/lib/utilities.d.ts +1198 -0
  292. package/dist/lib/utilities.js +1302 -0
  293. package/dist/lib/utilities.js.map +1 -0
  294. package/dist/utils/electron.d.ts +49 -0
  295. package/dist/utils/electron.js +63 -0
  296. package/dist/utils/electron.js.map +1 -0
  297. package/dist/utils/index.d.ts +6 -0
  298. package/dist/utils/index.js +7 -0
  299. package/dist/utils/index.js.map +1 -0
  300. package/dist/utils/libc.d.ts +11 -0
  301. package/dist/utils/libc.js +35 -0
  302. package/dist/utils/libc.js.map +1 -0
  303. package/dist/utils/variant.d.ts +26 -0
  304. package/dist/utils/variant.js +31 -0
  305. package/dist/utils/variant.js.map +1 -0
  306. package/dist/webrtc/index.d.ts +4 -0
  307. package/dist/webrtc/index.js +7 -0
  308. package/dist/webrtc/index.js.map +1 -0
  309. package/install/check.js +124 -0
  310. package/install/ffmpeg.js +66 -0
  311. package/package.json +167 -4
@@ -0,0 +1,1607 @@
1
+ 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/constants.js';
2
+ import { bindings } from './binding.js';
3
+ import { Dictionary } from './dictionary.js';
4
+ import { FFmpegError, PosixError } from './error.js';
5
+ import { Rational } from './rational.js';
6
+ import { avGetPixFmtFromName, avGetSampleFmtFromName } from './utilities.js';
7
+ /**
8
+ * Option information descriptor.
9
+ *
10
+ * Describes a single option available on an FFmpeg object.
11
+ * Contains metadata about the option including name, type, default value,
12
+ * valid range, and documentation. Used to discover and validate options.
13
+ *
14
+ * Direct mapping to FFmpeg's AVOption.
15
+ *
16
+ * @example
17
+ * ```typescript
18
+ * import { Option } from 'node-av';
19
+ *
20
+ * // Get option info
21
+ * const optInfo = Option.find(obj, 'bitrate');
22
+ * if (optInfo) {
23
+ * console.log(`Option: ${optInfo.name}`);
24
+ * console.log(`Help: ${optInfo.help}`);
25
+ * console.log(`Type: ${optInfo.type}`);
26
+ * console.log(`Default: ${optInfo.defaultValue}`);
27
+ * console.log(`Range: ${optInfo.min} - ${optInfo.max}`);
28
+ * }
29
+ * ```
30
+ *
31
+ * @see [AVOption](https://ffmpeg.org/doxygen/trunk/structAVOption.html) - FFmpeg Doxygen
32
+ */
33
+ export class OptionInfo {
34
+ native;
35
+ /**
36
+ * @param native - The native option instance
37
+ *
38
+ * @internal
39
+ */
40
+ constructor(native) {
41
+ this.native = native;
42
+ }
43
+ /**
44
+ * Option name.
45
+ *
46
+ * The name used to get/set this option.
47
+ *
48
+ * Direct mapping to AVOption->name.
49
+ */
50
+ get name() {
51
+ return this.native.name;
52
+ }
53
+ /**
54
+ * Option help text.
55
+ *
56
+ * Human-readable description of the option's purpose.
57
+ *
58
+ * Direct mapping to AVOption->help.
59
+ */
60
+ get help() {
61
+ return this.native.help;
62
+ }
63
+ /**
64
+ * Option type.
65
+ *
66
+ * Data type of the option value (AV_OPT_TYPE_*).
67
+ *
68
+ * Direct mapping to AVOption->type.
69
+ */
70
+ get type() {
71
+ return this.native.type;
72
+ }
73
+ /**
74
+ * Default value.
75
+ *
76
+ * The default value for this option.
77
+ * Type depends on the option type.
78
+ *
79
+ * Direct mapping to AVOption->default_val.
80
+ */
81
+ get defaultValue() {
82
+ return this.native.defaultValue;
83
+ }
84
+ /**
85
+ * Minimum value.
86
+ *
87
+ * Minimum valid value for numeric options.
88
+ *
89
+ * Direct mapping to AVOption->min.
90
+ */
91
+ get min() {
92
+ return this.native.min;
93
+ }
94
+ /**
95
+ * Maximum value.
96
+ *
97
+ * Maximum valid value for numeric options.
98
+ *
99
+ * Direct mapping to AVOption->max.
100
+ */
101
+ get max() {
102
+ return this.native.max;
103
+ }
104
+ /**
105
+ * Option flags.
106
+ *
107
+ * Combination of AV_OPT_FLAG_* indicating option properties.
108
+ *
109
+ * Direct mapping to AVOption->flags.
110
+ */
111
+ get flags() {
112
+ return this.native.flags;
113
+ }
114
+ /**
115
+ * Check if option has specific flags.
116
+ *
117
+ * Tests whether all specified flags are set using bitwise AND.
118
+ *
119
+ * @param flags - One or more flag values to check
120
+ *
121
+ * @returns true if all specified flags are set, false otherwise
122
+ *
123
+ * @example
124
+ * ```typescript
125
+ * import { AV_OPT_FLAG_ENCODING_PARAM } from 'node-av/constants';
126
+ *
127
+ * if (option.hasFlags(AV_OPT_FLAG_ENCODING_PARAM)) {
128
+ * console.log('This option is used for encoding');
129
+ * }
130
+ * ```
131
+ *
132
+ * @see {@link flags} For direct flags access
133
+ */
134
+ hasFlags(...flags) {
135
+ for (const flag of flags) {
136
+ if ((this.native.flags & flag) !== flag) {
137
+ return false;
138
+ }
139
+ }
140
+ return true;
141
+ }
142
+ /**
143
+ * Option unit.
144
+ *
145
+ * Unit string for grouping related options.
146
+ *
147
+ * Direct mapping to AVOption->unit.
148
+ */
149
+ get unit() {
150
+ return this.native.unit;
151
+ }
152
+ /**
153
+ * Get the underlying native Option object.
154
+ *
155
+ * @returns The native Option binding object
156
+ *
157
+ * @internal
158
+ */
159
+ getNative() {
160
+ return this.native;
161
+ }
162
+ }
163
+ /**
164
+ * FFmpeg option management utilities.
165
+ *
166
+ * Provides static methods for getting, setting, and querying options
167
+ * on FFmpeg objects that support the AVOption API. Handles type conversion
168
+ * and validation for various option types including strings, numbers,
169
+ * rationals, pixel formats, and more.
170
+ *
171
+ * Direct mapping to FFmpeg's AVOption API.
172
+ *
173
+ * @example
174
+ * ```typescript
175
+ * import { Option, FFmpegError } from 'node-av';
176
+ * import { AV_OPT_SEARCH_CHILDREN, AV_PIX_FMT_YUV420P } from 'node-av/constants';
177
+ *
178
+ * // Set various option types
179
+ * let ret = Option.set(obj, 'preset', 'fast');
180
+ * FFmpegError.throwIfError(ret, 'set preset');
181
+ *
182
+ * ret = Option.setInt(obj, 'bitrate', 2000000);
183
+ * FFmpegError.throwIfError(ret, 'set bitrate');
184
+ *
185
+ * ret = Option.setRational(obj, 'framerate', { num: 30, den: 1 });
186
+ * FFmpegError.throwIfError(ret, 'set framerate');
187
+ *
188
+ * // Get option values
189
+ * const preset = Option.get(obj, 'preset');
190
+ * const bitrate = Option.getInt(obj, 'bitrate');
191
+ * const framerate = Option.getRational(obj, 'framerate');
192
+ *
193
+ * // List all options
194
+ * let opt = null;
195
+ * while ((opt = Option.next(obj, opt))) {
196
+ * console.log(`${opt.name}: ${opt.help}`);
197
+ * }
198
+ * ```
199
+ *
200
+ * @see [AVOption API](https://ffmpeg.org/doxygen/trunk/group__avoptions.html) - FFmpeg Doxygen
201
+ * @see {@link OptionMember} For inherited option support
202
+ */
203
+ export class Option {
204
+ /**
205
+ * Iterate to next option.
206
+ *
207
+ * Iterates through available options on an object.
208
+ *
209
+ * Direct mapping to av_opt_next().
210
+ *
211
+ * @param obj - Object with options
212
+ *
213
+ * @param prev - Previous option (null to get first)
214
+ *
215
+ * @returns Next option, or null if no more
216
+ *
217
+ * @example
218
+ * ```typescript
219
+ * let opt = null;
220
+ * while ((opt = Option.next(obj, opt))) {
221
+ * console.log(`Option: ${opt.name}`);
222
+ * }
223
+ * ```
224
+ */
225
+ static next(obj, prev = null) {
226
+ const result = bindings.Option.next(obj, prev?.getNative());
227
+ return result ? new OptionInfo(result) : null;
228
+ }
229
+ /**
230
+ * Find option by name.
231
+ *
232
+ * Searches for an option with the specified name.
233
+ *
234
+ * Direct mapping to av_opt_find().
235
+ *
236
+ * @param obj - Object to search
237
+ *
238
+ * @param name - Option name
239
+ *
240
+ * @param searchFlags - Search flags
241
+ *
242
+ * @returns Option info if found, null otherwise
243
+ *
244
+ * @example
245
+ * ```typescript
246
+ * const opt = Option.find(obj, 'bitrate');
247
+ * if (opt) {
248
+ * console.log(`Found: ${opt.name}, Type: ${opt.type}`);
249
+ * }
250
+ * ```
251
+ */
252
+ static find(obj, name, searchFlags = AVFLAG_NONE) {
253
+ const result = bindings.Option.find(obj, name, searchFlags);
254
+ return result ? new OptionInfo(result) : null;
255
+ }
256
+ /**
257
+ * Find option with target info.
258
+ *
259
+ * Like find() but also indicates if option was found on different target.
260
+ *
261
+ * Direct mapping to av_opt_find2().
262
+ *
263
+ * @param obj - Object to search
264
+ *
265
+ * @param name - Option name
266
+ *
267
+ * @param searchFlags - Search flags
268
+ *
269
+ * @returns Object with option and target info
270
+ *
271
+ * @example
272
+ * ```typescript
273
+ * const result = Option.find2(obj, 'bitrate', AV_OPT_SEARCH_CHILDREN);
274
+ * if (result?.option) {
275
+ * console.log(`Found on ${result.isDifferentTarget ? 'child' : 'object'}`);
276
+ * }
277
+ * ```
278
+ */
279
+ static find2(obj, name, searchFlags = AVFLAG_NONE) {
280
+ const result = bindings.Option.find2(obj, name, searchFlags);
281
+ if (!result)
282
+ return null;
283
+ return {
284
+ option: result.option ? new OptionInfo(result.option) : null,
285
+ isDifferentTarget: result.isDifferentTarget,
286
+ };
287
+ }
288
+ /**
289
+ * Get string option value.
290
+ *
291
+ * Direct mapping to av_opt_get().
292
+ *
293
+ * @param obj - Object to query
294
+ *
295
+ * @param name - Option name
296
+ *
297
+ * @param searchFlags - Search flags
298
+ *
299
+ * @returns Option value as string, or null
300
+ *
301
+ * @example
302
+ * ```typescript
303
+ * // Get codec preset option
304
+ * const preset = Option.get(codecContext, 'preset', AV_OPT_SEARCH_CHILDREN);
305
+ * console.log('Codec preset:', preset); // 'medium', 'fast', etc.
306
+ * ```
307
+ */
308
+ static get(obj, name, searchFlags = AVFLAG_NONE) {
309
+ return bindings.Option.get(obj, name, searchFlags);
310
+ }
311
+ /**
312
+ * Get integer option value.
313
+ *
314
+ * Direct mapping to av_opt_get_int().
315
+ *
316
+ * @param obj - Object to query
317
+ *
318
+ * @param name - Option name
319
+ *
320
+ * @param searchFlags - Search flags
321
+ *
322
+ * @returns Option value as integer, or null
323
+ *
324
+ * @example
325
+ * ```typescript
326
+ * // Get codec GOP size
327
+ * const gopSize = Option.getInt(codecContext, 'g', AV_OPT_SEARCH_CHILDREN);
328
+ * console.log('GOP size:', gopSize); // 60, 120, etc.
329
+ * ```
330
+ */
331
+ static getInt(obj, name, searchFlags = AVFLAG_NONE) {
332
+ return bindings.Option.getInt(obj, name, searchFlags);
333
+ }
334
+ /**
335
+ * Get 64-bit integer option value.
336
+ *
337
+ * Returns a bigint to keep full int64 precision - getInt goes through a
338
+ * double and truncates values above 2^53.
339
+ *
340
+ * Direct mapping to av_opt_get_int().
341
+ *
342
+ * @param obj - Object to query
343
+ *
344
+ * @param name - Option name
345
+ *
346
+ * @param searchFlags - Search flags
347
+ *
348
+ * @returns Option value as bigint, or null
349
+ *
350
+ * @example
351
+ * ```typescript
352
+ * // Get maximum interleave delta
353
+ * const delta = Option.getInt64(formatContext, 'max_interleave_delta', AV_OPT_SEARCH_CHILDREN);
354
+ * console.log('Max interleave delta:', delta); // 10000000n
355
+ * ```
356
+ *
357
+ * @see {@link getInt} For 32-bit safe integer options
358
+ */
359
+ static getInt64(obj, name, searchFlags = AVFLAG_NONE) {
360
+ return bindings.Option.getInt64(obj, name, searchFlags);
361
+ }
362
+ /**
363
+ * Get double option value.
364
+ *
365
+ * Direct mapping to av_opt_get_double().
366
+ *
367
+ * @param obj - Object to query
368
+ *
369
+ * @param name - Option name
370
+ *
371
+ * @param searchFlags - Search flags
372
+ *
373
+ * @returns Option value as double, or null
374
+ *
375
+ * @example
376
+ * ```typescript
377
+ * // Get codec quality scale
378
+ * const crf = Option.getDouble(codecContext, 'crf', AV_OPT_SEARCH_CHILDREN);
379
+ * console.log('CRF value:', crf); // 23.0, 18.0, etc.
380
+ * ```
381
+ */
382
+ static getDouble(obj, name, searchFlags = AVFLAG_NONE) {
383
+ return bindings.Option.getDouble(obj, name, searchFlags);
384
+ }
385
+ /**
386
+ * Get rational option value.
387
+ *
388
+ * Direct mapping to av_opt_get_q().
389
+ *
390
+ * @param obj - Object to query
391
+ *
392
+ * @param name - Option name
393
+ *
394
+ * @param searchFlags - Search flags
395
+ *
396
+ * @returns Option value as rational, or null
397
+ *
398
+ * @example
399
+ * ```typescript
400
+ * // Get codec time base
401
+ * const timeBase = Option.getRational(codecContext, 'time_base', AV_OPT_SEARCH_CHILDREN);
402
+ * console.log('Time base:', timeBase); // { num: 1, den: 30 }
403
+ * ```
404
+ */
405
+ static getRational(obj, name, searchFlags = AVFLAG_NONE) {
406
+ return bindings.Option.getRational(obj, name, searchFlags);
407
+ }
408
+ /**
409
+ * Get pixel format option value.
410
+ *
411
+ * Direct mapping to av_opt_get_pixel_fmt().
412
+ *
413
+ * @param obj - Object to query
414
+ *
415
+ * @param name - Option name
416
+ *
417
+ * @param searchFlags - Search flags
418
+ *
419
+ * @returns Pixel format value, or null
420
+ *
421
+ * @example
422
+ * ```typescript
423
+ * // Get filter pixel format
424
+ * const pixFmt = Option.getPixelFormat(filterContext, 'pix_fmt', AV_OPT_SEARCH_CHILDREN);
425
+ * console.log('Pixel format:', pixFmt); // AV_PIX_FMT_YUV420P, etc.
426
+ * ```
427
+ */
428
+ static getPixelFormat(obj, name, searchFlags = AVFLAG_NONE) {
429
+ return bindings.Option.getPixelFormat(obj, name, searchFlags);
430
+ }
431
+ /**
432
+ * Get sample format option value.
433
+ *
434
+ * Direct mapping to av_opt_get_sample_fmt().
435
+ *
436
+ * @param obj - Object to query
437
+ *
438
+ * @param name - Option name
439
+ *
440
+ * @param searchFlags - Search flags
441
+ *
442
+ * @returns Sample format value, or null
443
+ *
444
+ * @example
445
+ * ```typescript
446
+ * // Get audio codec sample format
447
+ * const sampleFmt = Option.getSampleFormat(codecContext, 'sample_fmt', AV_OPT_SEARCH_CHILDREN);
448
+ * console.log('Sample format:', sampleFmt); // AV_SAMPLE_FMT_FLTP, etc.
449
+ * ```
450
+ */
451
+ static getSampleFormat(obj, name, searchFlags = AVFLAG_NONE) {
452
+ return bindings.Option.getSampleFormat(obj, name, searchFlags);
453
+ }
454
+ /**
455
+ * Get image size option value.
456
+ *
457
+ * Direct mapping to av_opt_get_image_size().
458
+ *
459
+ * @param obj - Object to query
460
+ *
461
+ * @param name - Option name
462
+ *
463
+ * @param searchFlags - Search flags
464
+ *
465
+ * @returns Width and height, or null
466
+ *
467
+ * @example
468
+ * ```typescript
469
+ * // Get filter output size
470
+ * const size = Option.getImageSize(filterContext, 'size', AV_OPT_SEARCH_CHILDREN);
471
+ * console.log('Output size:', size); // { width: 1920, height: 1080 }
472
+ * ```
473
+ */
474
+ static getImageSize(obj, name, searchFlags = AVFLAG_NONE) {
475
+ return bindings.Option.getImageSize(obj, name, searchFlags);
476
+ }
477
+ /**
478
+ * Get channel layout option value.
479
+ *
480
+ * Direct mapping to av_opt_get_chlayout().
481
+ *
482
+ * @param obj - Object to query
483
+ *
484
+ * @param name - Option name
485
+ *
486
+ * @param searchFlags - Search flags
487
+ *
488
+ * @returns Channel layout, or null
489
+ *
490
+ * @example
491
+ * ```typescript
492
+ * // Get audio channel layout
493
+ * const layout = Option.getChannelLayout(codecContext, 'channel_layout', AV_OPT_SEARCH_CHILDREN);
494
+ * console.log('Channel layout:', layout); // stereo, 5.1, etc.
495
+ * ```
496
+ */
497
+ static getChannelLayout(obj, name, searchFlags = AVFLAG_NONE) {
498
+ return bindings.Option.getChannelLayout(obj, name, searchFlags);
499
+ }
500
+ /**
501
+ * Get dictionary option value.
502
+ *
503
+ * Direct mapping to av_opt_get_dict_val().
504
+ *
505
+ * @param obj - Object to query
506
+ *
507
+ * @param name - Option name
508
+ *
509
+ * @param searchFlags - Search flags
510
+ *
511
+ * @returns Dictionary value, or null
512
+ *
513
+ * @example
514
+ * ```typescript
515
+ * // Get metadata dictionary
516
+ * const metadata = Option.getDict(formatContext, 'metadata', AV_OPT_SEARCH_CHILDREN);
517
+ * console.log('Metadata:', metadata?.get('title'));
518
+ * ```
519
+ */
520
+ static getDict(obj, name, searchFlags = AVFLAG_NONE) {
521
+ const native = bindings.Option.getDict(obj, name, searchFlags);
522
+ return native ? Dictionary.fromNative(native) : null;
523
+ }
524
+ /**
525
+ * Set string option value.
526
+ *
527
+ * Direct mapping to av_opt_set().
528
+ *
529
+ * @param obj - Object to modify
530
+ *
531
+ * @param name - Option name
532
+ *
533
+ * @param value - String value
534
+ *
535
+ * @param searchFlags - Search flags
536
+ *
537
+ * @returns 0 on success, negative AVERROR on error
538
+ *
539
+ * @example
540
+ * ```typescript
541
+ * // Set codec preset
542
+ * const ret = Option.set(codecContext, 'preset', 'fast', AV_OPT_SEARCH_CHILDREN);
543
+ * FFmpegError.throwIfError(ret, 'Failed to set preset');
544
+ * ```
545
+ */
546
+ static set(obj, name, value, searchFlags = AVFLAG_NONE) {
547
+ return bindings.Option.set(obj, name, value, searchFlags);
548
+ }
549
+ /**
550
+ * Set integer option value.
551
+ *
552
+ * Direct mapping to av_opt_set_int().
553
+ *
554
+ * @param obj - Object to modify
555
+ *
556
+ * @param name - Option name
557
+ *
558
+ * @param value - Integer value
559
+ *
560
+ * @param searchFlags - Search flags
561
+ *
562
+ * @returns 0 on success, negative AVERROR on error
563
+ *
564
+ * @example
565
+ * ```typescript
566
+ * // Set codec bitrate
567
+ * const ret = Option.setInt(codecContext, 'b', 2000000, AV_OPT_SEARCH_CHILDREN);
568
+ * FFmpegError.throwIfError(ret, 'Failed to set bitrate');
569
+ * ```
570
+ */
571
+ static setInt(obj, name, value, searchFlags = AVFLAG_NONE) {
572
+ return bindings.Option.setInt(obj, name, value, searchFlags);
573
+ }
574
+ /**
575
+ * Set double option value.
576
+ *
577
+ * Direct mapping to av_opt_set_double().
578
+ *
579
+ * @param obj - Object to modify
580
+ *
581
+ * @param name - Option name
582
+ *
583
+ * @param value - Double value
584
+ *
585
+ * @param searchFlags - Search flags
586
+ *
587
+ * @returns 0 on success, negative AVERROR on error
588
+ *
589
+ * @example
590
+ * ```typescript
591
+ * // Set codec CRF value
592
+ * const ret = Option.setDouble(codecContext, 'crf', 23.0, AV_OPT_SEARCH_CHILDREN);
593
+ * FFmpegError.throwIfError(ret, 'Failed to set CRF');
594
+ * ```
595
+ */
596
+ static setDouble(obj, name, value, searchFlags = AVFLAG_NONE) {
597
+ return bindings.Option.setDouble(obj, name, value, searchFlags);
598
+ }
599
+ /**
600
+ * Set rational option value.
601
+ *
602
+ * Direct mapping to av_opt_set_q().
603
+ *
604
+ * @param obj - Object to modify
605
+ *
606
+ * @param name - Option name
607
+ *
608
+ * @param value - Rational value
609
+ *
610
+ * @param searchFlags - Search flags
611
+ *
612
+ * @returns 0 on success, negative AVERROR on error
613
+ *
614
+ * @example
615
+ * ```typescript
616
+ * // Set codec frame rate
617
+ * const ret = Option.setRational(codecContext, 'framerate', { num: 30, den: 1 }, AV_OPT_SEARCH_CHILDREN);
618
+ * FFmpegError.throwIfError(ret, 'Failed to set framerate');
619
+ * ```
620
+ */
621
+ static setRational(obj, name, value, searchFlags = AVFLAG_NONE) {
622
+ return bindings.Option.setRational(obj, name, value, searchFlags);
623
+ }
624
+ /**
625
+ * Set pixel format option value.
626
+ *
627
+ * Direct mapping to av_opt_set_pixel_fmt().
628
+ *
629
+ * @param obj - Object to modify
630
+ *
631
+ * @param name - Option name
632
+ *
633
+ * @param value - Pixel format
634
+ *
635
+ * @param searchFlags - Search flags
636
+ *
637
+ * @returns 0 on success, negative AVERROR on error
638
+ *
639
+ * @example
640
+ * ```typescript
641
+ * // Set filter pixel format
642
+ * const ret = Option.setPixelFormat(filterContext, 'pix_fmt', AV_PIX_FMT_YUV420P, AV_OPT_SEARCH_CHILDREN);
643
+ * FFmpegError.throwIfError(ret, 'Failed to set pixel format');
644
+ * ```
645
+ */
646
+ static setPixelFormat(obj, name, value, searchFlags = AVFLAG_NONE) {
647
+ return bindings.Option.setPixelFormat(obj, name, value, searchFlags);
648
+ }
649
+ /**
650
+ * Set sample format option value.
651
+ *
652
+ * Direct mapping to av_opt_set_sample_fmt().
653
+ *
654
+ * @param obj - Object to modify
655
+ *
656
+ * @param name - Option name
657
+ *
658
+ * @param value - Sample format
659
+ *
660
+ * @param searchFlags - Search flags
661
+ *
662
+ * @returns 0 on success, negative AVERROR on error
663
+ *
664
+ * @example
665
+ * ```typescript
666
+ * // Set audio codec sample format
667
+ * const ret = Option.setSampleFormat(codecContext, 'sample_fmt', AV_SAMPLE_FMT_FLTP, AV_OPT_SEARCH_CHILDREN);
668
+ * FFmpegError.throwIfError(ret, 'Failed to set sample format');
669
+ * ```
670
+ */
671
+ static setSampleFormat(obj, name, value, searchFlags = AVFLAG_NONE) {
672
+ return bindings.Option.setSampleFormat(obj, name, value, searchFlags);
673
+ }
674
+ /**
675
+ * Set image size option value.
676
+ *
677
+ * Direct mapping to av_opt_set_image_size().
678
+ *
679
+ * @param obj - Object to modify
680
+ *
681
+ * @param name - Option name
682
+ *
683
+ * @param width - Image width
684
+ *
685
+ * @param height - Image height
686
+ *
687
+ * @param searchFlags - Search flags
688
+ *
689
+ * @returns 0 on success, negative AVERROR on error
690
+ *
691
+ * @example
692
+ * ```typescript
693
+ * // Set filter output size
694
+ * const ret = Option.setImageSize(filterContext, 'size', 1920, 1080, AV_OPT_SEARCH_CHILDREN);
695
+ * FFmpegError.throwIfError(ret, 'Failed to set image size');
696
+ * ```
697
+ */
698
+ static setImageSize(obj, name, width, height, searchFlags = AVFLAG_NONE) {
699
+ return bindings.Option.setImageSize(obj, name, width, height, searchFlags);
700
+ }
701
+ /**
702
+ * Set channel layout option value.
703
+ *
704
+ * Direct mapping to av_opt_set_chlayout().
705
+ *
706
+ * @param obj - Object to modify
707
+ *
708
+ * @param name - Option name
709
+ *
710
+ * @param value - Channel layout
711
+ *
712
+ * @param searchFlags - Search flags
713
+ *
714
+ * @returns 0 on success, negative AVERROR on error
715
+ *
716
+ * @example
717
+ * ```typescript
718
+ * // Set audio channel layout to stereo
719
+ * const ret = Option.setChannelLayout(codecContext, 'channel_layout', AV_CHANNEL_LAYOUT_STEREO, AV_OPT_SEARCH_CHILDREN);
720
+ * FFmpegError.throwIfError(ret, 'Failed to set channel layout');
721
+ * ```
722
+ */
723
+ static setChannelLayout(obj, name, value, searchFlags = AVFLAG_NONE) {
724
+ return bindings.Option.setChannelLayout(obj, name, value, searchFlags);
725
+ }
726
+ /**
727
+ * Set dictionary option value.
728
+ *
729
+ * Direct mapping to av_opt_set_dict_val().
730
+ *
731
+ * @param obj - Object to modify
732
+ *
733
+ * @param name - Option name
734
+ *
735
+ * @param value - Dictionary value
736
+ *
737
+ * @param searchFlags - Search flags
738
+ *
739
+ * @returns 0 on success, negative AVERROR on error
740
+ *
741
+ * @example
742
+ * ```typescript
743
+ * // Set metadata dictionary
744
+ * const dict = new Dictionary();
745
+ * dict.set('title', 'My Video');
746
+ * const ret = Option.setDict(formatContext, 'metadata', dict, AV_OPT_SEARCH_CHILDREN);
747
+ * FFmpegError.throwIfError(ret, 'Failed to set metadata');
748
+ * ```
749
+ */
750
+ static setDict(obj, name, value, searchFlags = AVFLAG_NONE) {
751
+ return bindings.Option.setDict(obj, name, value.getNative(), searchFlags);
752
+ }
753
+ /**
754
+ * Set binary option value.
755
+ *
756
+ * Direct mapping to av_opt_set_bin().
757
+ *
758
+ * @param obj - Object to modify
759
+ *
760
+ * @param name - Option name
761
+ *
762
+ * @param value - Binary data
763
+ *
764
+ * @param searchFlags - Search flags
765
+ *
766
+ * @returns 0 on success, negative AVERROR on error
767
+ *
768
+ * @example
769
+ * ```typescript
770
+ * // Set binary extradata
771
+ * const extradata = Buffer.from([0x00, 0x01, 0x02, 0x03]);
772
+ * const ret = Option.setBin(codecContext, 'extradata', extradata, AV_OPT_SEARCH_CHILDREN);
773
+ * FFmpegError.throwIfError(ret, 'Failed to set extradata');
774
+ * ```
775
+ */
776
+ static setBin(obj, name, value, searchFlags = AVFLAG_NONE) {
777
+ return bindings.Option.setBin(obj, name, value, searchFlags);
778
+ }
779
+ /**
780
+ * Set defaults on object.
781
+ *
782
+ * Sets all options to their default values.
783
+ *
784
+ * Direct mapping to av_opt_set_defaults().
785
+ *
786
+ * @param obj - Object to reset
787
+ *
788
+ * @example
789
+ * ```typescript
790
+ * // Reset all codec options to defaults
791
+ * Option.setDefaults(codecContext);
792
+ * ```
793
+ */
794
+ static setDefaults(obj) {
795
+ bindings.Option.setDefaults(obj);
796
+ }
797
+ /**
798
+ * Copy options between objects.
799
+ *
800
+ * Copies option values from source to destination.
801
+ *
802
+ * Direct mapping to av_opt_copy().
803
+ *
804
+ * @param dest - Destination object
805
+ *
806
+ * @param src - Source object
807
+ *
808
+ * @returns 0 on success, negative AVERROR on error
809
+ *
810
+ * @example
811
+ * ```typescript
812
+ * // Copy options from one codec context to another
813
+ * const ret = Option.copy(destCodecContext, srcCodecContext);
814
+ * FFmpegError.throwIfError(ret, 'Failed to copy options');
815
+ * ```
816
+ */
817
+ static copy(dest, src) {
818
+ return bindings.Option.copy(dest, src);
819
+ }
820
+ /**
821
+ * Check if option is set to default.
822
+ *
823
+ * Direct mapping to av_opt_is_set_to_default().
824
+ *
825
+ * @param obj - Object to check
826
+ *
827
+ * @param name - Option name
828
+ *
829
+ * @param searchFlags - Search flags
830
+ *
831
+ * @returns True if default, false if modified, null if not found
832
+ *
833
+ * @example
834
+ * ```typescript
835
+ * // Check if bitrate is at default value
836
+ * const isDefault = Option.isSetToDefault(codecContext, 'b', AV_OPT_SEARCH_CHILDREN);
837
+ * console.log('Bitrate is default:', isDefault);
838
+ * ```
839
+ */
840
+ static isSetToDefault(obj, name, searchFlags = AVFLAG_NONE) {
841
+ return bindings.Option.isSetToDefault(obj, name, searchFlags);
842
+ }
843
+ /**
844
+ * Serialize options to string.
845
+ *
846
+ * Direct mapping to av_opt_serialize().
847
+ *
848
+ * @param obj - Object to serialize
849
+ *
850
+ * @param optFlags - Option flags filter
851
+ *
852
+ * @param flags - Serialization flags
853
+ *
854
+ * @param keyValSep - Key-value separator
855
+ *
856
+ * @param pairsSep - Pairs separator
857
+ *
858
+ * @returns Serialized string, or null on error
859
+ *
860
+ * @example
861
+ * ```typescript
862
+ * // Serialize codec options to string
863
+ * const serialized = Option.serialize(codecContext, 0, 0, '=', ':');
864
+ * console.log('Options:', serialized); // 'bitrate=2000000:preset=fast'
865
+ * ```
866
+ */
867
+ static serialize(obj, optFlags = 0, flags = 0, keyValSep = '=', pairsSep = ',') {
868
+ return bindings.Option.serialize(obj, optFlags, flags, keyValSep, pairsSep);
869
+ }
870
+ /**
871
+ * Free option resources.
872
+ *
873
+ * Direct mapping to av_opt_free().
874
+ *
875
+ * @param obj - Object to free options from
876
+ *
877
+ * @example
878
+ * ```typescript
879
+ * // Free codec context options
880
+ * Option.free(codecContext);
881
+ * ```
882
+ */
883
+ static free(obj) {
884
+ bindings.Option.free(obj);
885
+ }
886
+ /**
887
+ * Show options for debugging.
888
+ *
889
+ * Direct mapping to av_opt_show2().
890
+ *
891
+ * @param obj - Object to show options for
892
+ *
893
+ * @param reqFlags - Required flags
894
+ *
895
+ * @param rejFlags - Rejected flags
896
+ *
897
+ * @returns 0 on success, negative AVERROR on error
898
+ *
899
+ * @example
900
+ * ```typescript
901
+ * // Show all codec options for debugging
902
+ * const ret = Option.show(codecContext, 0, 0);
903
+ * FFmpegError.throwIfError(ret, 'Failed to show options');
904
+ * ```
905
+ */
906
+ static show(obj, reqFlags = 0, rejFlags = 0) {
907
+ return bindings.Option.show(obj, reqFlags, rejFlags);
908
+ }
909
+ }
910
+ /**
911
+ * Base class for FFmpeg objects that support AVOptions.
912
+ *
913
+ * Provides a common interface for getting, setting, and listing options
914
+ * on FFmpeg objects that have an AVClass structure. This includes codecs,
915
+ * formats, filters, and various processing contexts.
916
+ *
917
+ * Classes that support AVOptions should extend this class to inherit
918
+ * the option management functionality.
919
+ *
920
+ * @template T - The native FFmpeg object type that supports AVOptions
921
+ *
922
+ * @example
923
+ * ```typescript
924
+ * import { OptionMember, FFmpegError } from 'node-av';
925
+ * import { AV_OPT_TYPE_INT, AV_OPT_TYPE_STRING, AV_OPT_TYPE_RATIONAL } from 'node-av/constants';
926
+ *
927
+ * class CodecContext extends OptionMember<NativeCodecContext> {
928
+ * constructor(native: NativeCodecContext) {
929
+ * super(native);
930
+ * }
931
+ * }
932
+ *
933
+ * // Use inherited methods
934
+ * const codec = new CodecContext(native);
935
+ *
936
+ * // Set options with automatic type handling
937
+ * let ret = codec.setOption('preset', 'fast');
938
+ * FFmpegError.throwIfError(ret, 'set preset');
939
+ *
940
+ * ret = codec.setOption('bitrate', 2000000, AV_OPT_TYPE_INT);
941
+ * FFmpegError.throwIfError(ret, 'set bitrate');
942
+ *
943
+ * ret = codec.setOption('framerate', { num: 30, den: 1 }, AV_OPT_TYPE_RATIONAL);
944
+ * FFmpegError.throwIfError(ret, 'set framerate');
945
+ *
946
+ * // Get typed options
947
+ * const preset = codec.getOption('preset');
948
+ * const bitrate = codec.getOption('bitrate', AV_OPT_TYPE_INT);
949
+ * const framerate = codec.getOption('framerate', AV_OPT_TYPE_RATIONAL);
950
+ *
951
+ * // List all available options
952
+ * const options = codec.listOptions();
953
+ * for (const opt of options) {
954
+ * console.log(`${opt.name}: ${opt.help}`);
955
+ * }
956
+ * ```
957
+ *
958
+ * @see {@link Option} For static option methods
959
+ * @see {@link OptionInfo} For option metadata
960
+ */
961
+ export class OptionMember {
962
+ native;
963
+ constructor(native) {
964
+ this.native = native;
965
+ }
966
+ /**
967
+ * Set an option on this object.
968
+ *
969
+ * Uses the AVOption API to set options.
970
+ * Available options depend on the specific object type.
971
+ *
972
+ * Direct mapping to av_opt_set* functions.
973
+ *
974
+ * @param name - Option name
975
+ *
976
+ * @param value - Option value
977
+ *
978
+ * @param type - Option type; when omitted, the option's declared type is
979
+ * looked up via av_opt_find and the value converted accordingly
980
+ *
981
+ * @param searchFlags - Search flags (default: AV_OPT_SEARCH_CHILDREN)
982
+ *
983
+ * @returns 0 on success, negative AVERROR on error:
984
+ * - AVERROR_ENOENT: Option not found
985
+ * - AVERROR_ERANGE: Value out of range
986
+ * - AVERROR_EINVAL: Invalid value
987
+ *
988
+ * @example
989
+ * ```typescript
990
+ * import { FFmpegError } from 'node-av';
991
+ * import { AV_OPT_TYPE_STRING, AV_OPT_TYPE_INT64, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_PIXEL_FMT } from 'node-av/constants';
992
+ *
993
+ * // Untyped - the option's declared type is inferred
994
+ * let ret = obj.setOption('preset', 'fast');
995
+ * FFmpegError.throwIfError(ret, 'set preset');
996
+ *
997
+ * ret = obj.setOption('codec', 'h264', AV_OPT_TYPE_STRING);
998
+ * FFmpegError.throwIfError(ret, 'set codec');
999
+ *
1000
+ * // Integer options
1001
+ * ret = obj.setOption('bitrate', 2000000, AV_OPT_TYPE_INT64);
1002
+ * FFmpegError.throwIfError(ret, 'set bitrate');
1003
+ *
1004
+ * ret = obj.setOption('threads', 4, AV_OPT_TYPE_INT);
1005
+ * FFmpegError.throwIfError(ret, 'set threads');
1006
+ *
1007
+ * // Complex types with proper types
1008
+ * ret = obj.setOption('framerate', {num: 30, den: 1}, AV_OPT_TYPE_RATIONAL);
1009
+ * FFmpegError.throwIfError(ret, 'set framerate');
1010
+ *
1011
+ * ret = obj.setOption('pix_fmt', AV_PIX_FMT_YUV420P, AV_OPT_TYPE_PIXEL_FMT);
1012
+ * FFmpegError.throwIfError(ret, 'set pixel format');
1013
+ * ```
1014
+ */
1015
+ setOption(name, value, type, searchFlags = AV_OPT_SEARCH_CHILDREN) {
1016
+ if (value === undefined || value === null) {
1017
+ return 0;
1018
+ }
1019
+ // No explicit type: look up the option's declared type and convert the value
1020
+ // (a default of AV_OPT_TYPE_STRING here would make this branch unreachable)
1021
+ if (type === undefined) {
1022
+ return this.setUnknownOption(name, value);
1023
+ }
1024
+ switch (type) {
1025
+ case AV_OPT_TYPE_STRING:
1026
+ case AV_OPT_TYPE_COLOR: // Colors are set as strings
1027
+ return Option.set(this.native, name, String(value), searchFlags);
1028
+ case AV_OPT_TYPE_INT:
1029
+ const intVal = Number(value);
1030
+ if (!Number.isInteger(intVal)) {
1031
+ throw new TypeError(`Option '${name}': Expected integer value, got ${value}`);
1032
+ }
1033
+ return Option.setInt(this.native, name, intVal, searchFlags);
1034
+ case AV_OPT_TYPE_UINT:
1035
+ const uintVal = Number(value);
1036
+ if (!Number.isInteger(uintVal) || uintVal < 0) {
1037
+ throw new RangeError(`Option '${name}': Expected non-negative integer value, got ${value}`);
1038
+ }
1039
+ return Option.setInt(this.native, name, uintVal, searchFlags);
1040
+ case AV_OPT_TYPE_FLAGS:
1041
+ case AV_OPT_TYPE_DURATION:
1042
+ case AV_OPT_TYPE_CONST:
1043
+ return Option.setInt(this.native, name, Number(value), searchFlags);
1044
+ case AV_OPT_TYPE_BOOL:
1045
+ // Convert to 0 or 1 for FFmpeg
1046
+ return Option.setInt(this.native, name, value ? 1 : 0, searchFlags);
1047
+ case AV_OPT_TYPE_INT64:
1048
+ // Accept both bigint and number
1049
+ if (typeof value === 'bigint') {
1050
+ return Option.setInt(this.native, name, value, searchFlags);
1051
+ }
1052
+ else if (typeof value === 'number') {
1053
+ if (!Number.isInteger(value)) {
1054
+ throw new TypeError(`Option '${name}': Expected integer value for INT64, got ${value}`);
1055
+ }
1056
+ return Option.setInt(this.native, name, value, searchFlags);
1057
+ }
1058
+ else {
1059
+ throw new TypeError(`Option '${name}': Expected bigint or number for INT64, got ${typeof value}`);
1060
+ }
1061
+ case AV_OPT_TYPE_UINT64:
1062
+ // Accept both bigint and number, but must be non-negative
1063
+ if (typeof value === 'bigint') {
1064
+ if (value < 0n) {
1065
+ throw new RangeError(`Option '${name}': Expected non-negative value for UINT64, got ${value}`);
1066
+ }
1067
+ return Option.setInt(this.native, name, value, searchFlags);
1068
+ }
1069
+ else if (typeof value === 'number') {
1070
+ if (!Number.isInteger(value) || value < 0) {
1071
+ throw new RangeError(`Option '${name}': Expected non-negative integer for UINT64, got ${value}`);
1072
+ }
1073
+ return Option.setInt(this.native, name, value, searchFlags);
1074
+ }
1075
+ else {
1076
+ throw new TypeError(`Option '${name}': Expected bigint or number for UINT64, got ${typeof value}`);
1077
+ }
1078
+ case AV_OPT_TYPE_DOUBLE:
1079
+ case AV_OPT_TYPE_FLOAT:
1080
+ return Option.setDouble(this.native, name, Number(value), searchFlags);
1081
+ case AV_OPT_TYPE_RATIONAL:
1082
+ case AV_OPT_TYPE_VIDEO_RATE:
1083
+ if (typeof value !== 'object' || !('num' in value) || !('den' in value)) {
1084
+ throw new TypeError(`Option '${name}': Expected Rational object with {num, den}, got ${JSON.stringify(value)}`);
1085
+ }
1086
+ if (value.den === 0) {
1087
+ throw new RangeError(`Option '${name}': Rational denominator cannot be zero`);
1088
+ }
1089
+ return Option.setRational(this.native, name, value, searchFlags);
1090
+ case AV_OPT_TYPE_PIXEL_FMT:
1091
+ const pixFmt = Number(value);
1092
+ if (!Number.isInteger(pixFmt)) {
1093
+ throw new TypeError(`Option '${name}': Expected integer pixel format value, got ${value}`);
1094
+ }
1095
+ return Option.setPixelFormat(this.native, name, pixFmt, searchFlags);
1096
+ case AV_OPT_TYPE_SAMPLE_FMT:
1097
+ const sampleFmt = Number(value);
1098
+ if (!Number.isInteger(sampleFmt)) {
1099
+ throw new TypeError(`Option '${name}': Expected integer sample format value, got ${value}`);
1100
+ }
1101
+ return Option.setSampleFormat(this.native, name, sampleFmt, searchFlags);
1102
+ case AV_OPT_TYPE_IMAGE_SIZE:
1103
+ // Expect value as {width, height}
1104
+ if (typeof value === 'object' && 'width' in value && 'height' in value) {
1105
+ const width = Number(value.width);
1106
+ const height = Number(value.height);
1107
+ if (!Number.isInteger(width) || width <= 0) {
1108
+ throw new RangeError(`Option '${name}': Width must be a positive integer, got ${value.width}`);
1109
+ }
1110
+ if (!Number.isInteger(height) || height <= 0) {
1111
+ throw new RangeError(`Option '${name}': Height must be a positive integer, got ${value.height}`);
1112
+ }
1113
+ return Option.setImageSize(this.native, name, width, height, searchFlags);
1114
+ }
1115
+ throw new TypeError(`Option '${name}': Expected object with {width, height}, got ${JSON.stringify(value)}`);
1116
+ case AV_OPT_TYPE_CHLAYOUT:
1117
+ return Option.setChannelLayout(this.native, name, Number(value), searchFlags);
1118
+ case AV_OPT_TYPE_BINARY:
1119
+ if (Buffer.isBuffer(value)) {
1120
+ return Option.setBin(this.native, name, value, searchFlags);
1121
+ }
1122
+ throw new Error('Invalid value for BINARY option: expected Buffer');
1123
+ case AV_OPT_TYPE_BINARY_INT_ARRAY:
1124
+ if (Array.isArray(value)) {
1125
+ // Convert array of integers to buffer
1126
+ const buffer = Buffer.allocUnsafe(value.length * 4);
1127
+ for (let i = 0; i < value.length; i++) {
1128
+ buffer.writeInt32LE(value[i], i * 4);
1129
+ }
1130
+ return Option.setBin(this.native, name, buffer, searchFlags);
1131
+ }
1132
+ throw new Error('Invalid value for BINARY_INT_ARRAY option: expected number[]');
1133
+ case AV_OPT_TYPE_DICT:
1134
+ if (value instanceof Dictionary) {
1135
+ return Option.setDict(this.native, name, value, searchFlags);
1136
+ }
1137
+ throw new Error('Invalid value for DICT option: expected Dictionary');
1138
+ default:
1139
+ // Fallback to string
1140
+ return Option.set(this.native, name, String(value), searchFlags);
1141
+ }
1142
+ }
1143
+ /**
1144
+ * Get an option value from this object.
1145
+ *
1146
+ * Uses the AVOption API to retrieve options.
1147
+ *
1148
+ * Direct mapping to av_opt_get* functions.
1149
+ *
1150
+ * @param name - Option name
1151
+ *
1152
+ * @param type - Option type (defaults to AV_OPT_TYPE_STRING)
1153
+ *
1154
+ * @param searchFlags - Search flags (default: AV_OPT_SEARCH_CHILDREN)
1155
+ *
1156
+ * @returns Option value (type depends on type parameter), or null if not found
1157
+ *
1158
+ * @example
1159
+ * ```typescript
1160
+ * import { AV_OPT_TYPE_STRING, AV_OPT_TYPE_RATIONAL, AV_OPT_TYPE_PIXEL_FMT, AV_OPT_TYPE_INT64 } from 'node-av/constants';
1161
+ *
1162
+ * // String options (default)
1163
+ * const preset = obj.getOption('preset');
1164
+ * const codec = obj.getOption('codec', AV_OPT_TYPE_STRING);
1165
+ *
1166
+ * // Typed options
1167
+ * const framerate = obj.getOption('framerate', AV_OPT_TYPE_RATIONAL); // Returns {num, den}
1168
+ * const pixFmt = obj.getOption('pix_fmt', AV_OPT_TYPE_PIXEL_FMT); // Returns AVPixelFormat
1169
+ * const bitrate = obj.getOption('bitrate', AV_OPT_TYPE_INT64); // Returns bigint
1170
+ * ```
1171
+ */
1172
+ getOption(name, type = AV_OPT_TYPE_STRING, searchFlags = AV_OPT_SEARCH_CHILDREN) {
1173
+ // Use specific getter based on type
1174
+ switch (type) {
1175
+ case AV_OPT_TYPE_STRING:
1176
+ case AV_OPT_TYPE_COLOR:
1177
+ return Option.get(this.native, name, searchFlags);
1178
+ case AV_OPT_TYPE_INT:
1179
+ case AV_OPT_TYPE_UINT:
1180
+ case AV_OPT_TYPE_FLAGS:
1181
+ case AV_OPT_TYPE_DURATION:
1182
+ case AV_OPT_TYPE_CONST:
1183
+ return Option.getInt(this.native, name, searchFlags);
1184
+ case AV_OPT_TYPE_INT64:
1185
+ case AV_OPT_TYPE_UINT64:
1186
+ // getInt64 returns bigint natively - getInt would truncate above 2^53
1187
+ return Option.getInt64(this.native, name, searchFlags);
1188
+ case AV_OPT_TYPE_BOOL:
1189
+ const val = Option.getInt(this.native, name, searchFlags);
1190
+ return val !== null ? Boolean(val) : null;
1191
+ case AV_OPT_TYPE_DOUBLE:
1192
+ case AV_OPT_TYPE_FLOAT:
1193
+ return Option.getDouble(this.native, name, searchFlags);
1194
+ case AV_OPT_TYPE_RATIONAL:
1195
+ case AV_OPT_TYPE_VIDEO_RATE:
1196
+ const rational = Option.getRational(this.native, name, searchFlags);
1197
+ return rational ? new Rational(rational.num, rational.den) : null;
1198
+ case AV_OPT_TYPE_PIXEL_FMT:
1199
+ return Option.getPixelFormat(this.native, name, searchFlags);
1200
+ case AV_OPT_TYPE_SAMPLE_FMT:
1201
+ return Option.getSampleFormat(this.native, name, searchFlags);
1202
+ case AV_OPT_TYPE_IMAGE_SIZE:
1203
+ return Option.getImageSize(this.native, name, searchFlags);
1204
+ case AV_OPT_TYPE_CHLAYOUT:
1205
+ return Option.getChannelLayout(this.native, name, searchFlags);
1206
+ case AV_OPT_TYPE_DICT:
1207
+ return Option.getDict(this.native, name, searchFlags);
1208
+ case AV_OPT_TYPE_BINARY:
1209
+ // Binary data can only be retrieved as string
1210
+ return Option.get(this.native, name, searchFlags);
1211
+ case AV_OPT_TYPE_BINARY_INT_ARRAY:
1212
+ // Getting binary int arrays is not supported (requires av_opt_get_bin())
1213
+ // These are typically write-only options like 'pix_fmts' in buffersink
1214
+ throw new Error('Getting BINARY_INT_ARRAY options is not supported. These are typically write-only options.');
1215
+ default:
1216
+ // Fallback to string
1217
+ return Option.get(this.native, name, searchFlags);
1218
+ }
1219
+ }
1220
+ /**
1221
+ * List all available options for this object.
1222
+ *
1223
+ * Uses the AVOption API to enumerate all options.
1224
+ * Useful for discovering available settings and their types.
1225
+ *
1226
+ * Direct mapping to av_opt_next() iteration.
1227
+ *
1228
+ * @returns Array of option information objects
1229
+ *
1230
+ * @example
1231
+ * ```typescript
1232
+ * const options = obj.listOptions();
1233
+ * for (const opt of options) {
1234
+ * console.log(`${opt.name}: ${opt.help}`);
1235
+ * console.log(` Type: ${opt.type}, Default: ${opt.defaultValue}`);
1236
+ * console.log(` Range: ${opt.min} - ${opt.max}`);
1237
+ * }
1238
+ * ```
1239
+ *
1240
+ * @see {@link OptionInfo} For option metadata structure
1241
+ */
1242
+ listOptions() {
1243
+ const options = [];
1244
+ let opt = null;
1245
+ while ((opt = Option.next(this.native, opt))) {
1246
+ options.push(opt);
1247
+ }
1248
+ return options;
1249
+ }
1250
+ /**
1251
+ * Intelligently set a format option based on its FFmpeg type.
1252
+ *
1253
+ * Queries the option type using av_opt_find() and calls the appropriate
1254
+ * typed setOption() overload. Handles automatic type conversion from
1255
+ * JavaScript types to FFmpeg option types.
1256
+ *
1257
+ * @param name - Option name
1258
+ *
1259
+ * @param value - Option value (null/undefined are skipped)
1260
+ *
1261
+ * @returns 0 on success, negative on error
1262
+ *
1263
+ * @internal
1264
+ */
1265
+ setUnknownOption(name, value) {
1266
+ if (value === undefined || value === null) {
1267
+ return 0;
1268
+ }
1269
+ // Strings always go through av_opt_set: FFmpeg parses them for every option
1270
+ // type (flag names like '+frag_keyframe', named constants, rationals) -
1271
+ // per-type conversion like parseInt would silently mangle them
1272
+ if (typeof value === 'string') {
1273
+ return this.setOption(name, value, AV_OPT_TYPE_STRING);
1274
+ }
1275
+ // Try to find the option to get its type
1276
+ const optInfo = Option.find(this.native, name, AV_OPT_SEARCH_CHILDREN);
1277
+ if (optInfo) {
1278
+ const optType = optInfo.type;
1279
+ // Handle based on FFmpeg option type
1280
+ switch (optType) {
1281
+ case AV_OPT_TYPE_INT:
1282
+ if (typeof value === 'number') {
1283
+ return this.setOption(name, value, AV_OPT_TYPE_INT);
1284
+ }
1285
+ else if (typeof value === 'boolean') {
1286
+ return this.setOption(name, value ? 1 : 0, AV_OPT_TYPE_INT);
1287
+ }
1288
+ else if (typeof value === 'bigint') {
1289
+ return this.setOption(name, Number(value), AV_OPT_TYPE_INT);
1290
+ }
1291
+ else if (typeof value === 'string') {
1292
+ return this.setOption(name, parseInt(value, 10), AV_OPT_TYPE_INT);
1293
+ }
1294
+ else {
1295
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1296
+ }
1297
+ case AV_OPT_TYPE_UINT:
1298
+ if (typeof value === 'number') {
1299
+ return this.setOption(name, value, AV_OPT_TYPE_UINT);
1300
+ }
1301
+ else if (typeof value === 'boolean') {
1302
+ return this.setOption(name, value ? 1 : 0, AV_OPT_TYPE_UINT);
1303
+ }
1304
+ else if (typeof value === 'bigint') {
1305
+ return this.setOption(name, Number(value), AV_OPT_TYPE_UINT);
1306
+ }
1307
+ else if (typeof value === 'string') {
1308
+ return this.setOption(name, parseInt(value, 10), AV_OPT_TYPE_UINT);
1309
+ }
1310
+ else {
1311
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1312
+ }
1313
+ case AV_OPT_TYPE_FLAGS:
1314
+ if (typeof value === 'number') {
1315
+ return this.setOption(name, value, AV_OPT_TYPE_FLAGS);
1316
+ }
1317
+ else if (typeof value === 'boolean') {
1318
+ return this.setOption(name, value ? 1 : 0, AV_OPT_TYPE_FLAGS);
1319
+ }
1320
+ else if (typeof value === 'bigint') {
1321
+ return this.setOption(name, Number(value), AV_OPT_TYPE_FLAGS);
1322
+ }
1323
+ else if (typeof value === 'string') {
1324
+ return this.setOption(name, parseInt(value, 10), AV_OPT_TYPE_FLAGS);
1325
+ }
1326
+ else {
1327
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1328
+ }
1329
+ case AV_OPT_TYPE_CONST:
1330
+ if (typeof value === 'number') {
1331
+ return this.setOption(name, value, AV_OPT_TYPE_CONST);
1332
+ }
1333
+ else if (typeof value === 'boolean') {
1334
+ return this.setOption(name, value ? 1 : 0, AV_OPT_TYPE_CONST);
1335
+ }
1336
+ else if (typeof value === 'bigint') {
1337
+ return this.setOption(name, Number(value), AV_OPT_TYPE_CONST);
1338
+ }
1339
+ else if (typeof value === 'string') {
1340
+ return this.setOption(name, parseInt(value, 10), AV_OPT_TYPE_CONST);
1341
+ }
1342
+ else {
1343
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1344
+ }
1345
+ case AV_OPT_TYPE_DURATION:
1346
+ if (typeof value === 'number') {
1347
+ return this.setOption(name, value, AV_OPT_TYPE_DURATION);
1348
+ }
1349
+ else if (typeof value === 'boolean') {
1350
+ return this.setOption(name, value ? 1 : 0, AV_OPT_TYPE_DURATION);
1351
+ }
1352
+ else if (typeof value === 'bigint') {
1353
+ return this.setOption(name, Number(value), AV_OPT_TYPE_DURATION);
1354
+ }
1355
+ else if (typeof value === 'string') {
1356
+ return this.setOption(name, parseInt(value, 10), AV_OPT_TYPE_DURATION);
1357
+ }
1358
+ else {
1359
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1360
+ }
1361
+ case AV_OPT_TYPE_INT64:
1362
+ if (typeof value === 'bigint') {
1363
+ return this.setOption(name, value, AV_OPT_TYPE_INT64);
1364
+ }
1365
+ else if (typeof value === 'number') {
1366
+ return this.setOption(name, BigInt(value), AV_OPT_TYPE_INT64);
1367
+ }
1368
+ else if (typeof value === 'boolean') {
1369
+ return this.setOption(name, value ? 1n : 0n, AV_OPT_TYPE_INT64);
1370
+ }
1371
+ else if (typeof value === 'string') {
1372
+ return this.setOption(name, BigInt(value), AV_OPT_TYPE_INT64);
1373
+ }
1374
+ else {
1375
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1376
+ }
1377
+ case AV_OPT_TYPE_UINT64:
1378
+ if (typeof value === 'bigint') {
1379
+ return this.setOption(name, value, AV_OPT_TYPE_UINT64);
1380
+ }
1381
+ else if (typeof value === 'number') {
1382
+ return this.setOption(name, BigInt(value), AV_OPT_TYPE_UINT64);
1383
+ }
1384
+ else if (typeof value === 'boolean') {
1385
+ return this.setOption(name, value ? 1n : 0n, AV_OPT_TYPE_UINT64);
1386
+ }
1387
+ else if (typeof value === 'string') {
1388
+ return this.setOption(name, BigInt(value), AV_OPT_TYPE_UINT64);
1389
+ }
1390
+ else {
1391
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1392
+ }
1393
+ case AV_OPT_TYPE_CHLAYOUT:
1394
+ if (typeof value === 'bigint') {
1395
+ return this.setOption(name, value, AV_OPT_TYPE_CHLAYOUT);
1396
+ }
1397
+ else if (typeof value === 'number') {
1398
+ return this.setOption(name, BigInt(value), AV_OPT_TYPE_CHLAYOUT);
1399
+ }
1400
+ else if (typeof value === 'boolean') {
1401
+ return this.setOption(name, value ? 1n : 0n, AV_OPT_TYPE_CHLAYOUT);
1402
+ }
1403
+ else if (typeof value === 'string') {
1404
+ return this.setOption(name, BigInt(value), AV_OPT_TYPE_CHLAYOUT);
1405
+ }
1406
+ else {
1407
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1408
+ }
1409
+ case AV_OPT_TYPE_FLOAT:
1410
+ if (typeof value === 'number') {
1411
+ return this.setOption(name, value, AV_OPT_TYPE_FLOAT);
1412
+ }
1413
+ else if (typeof value === 'boolean') {
1414
+ return this.setOption(name, value ? 1.0 : 0.0, AV_OPT_TYPE_FLOAT);
1415
+ }
1416
+ else if (typeof value === 'bigint') {
1417
+ return this.setOption(name, Number(value), AV_OPT_TYPE_FLOAT);
1418
+ }
1419
+ else if (typeof value === 'string') {
1420
+ return this.setOption(name, parseFloat(value), AV_OPT_TYPE_FLOAT);
1421
+ }
1422
+ else {
1423
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1424
+ }
1425
+ case AV_OPT_TYPE_DOUBLE:
1426
+ if (typeof value === 'number') {
1427
+ return this.setOption(name, value, AV_OPT_TYPE_DOUBLE);
1428
+ }
1429
+ else if (typeof value === 'boolean') {
1430
+ return this.setOption(name, value ? 1.0 : 0.0, AV_OPT_TYPE_DOUBLE);
1431
+ }
1432
+ else if (typeof value === 'bigint') {
1433
+ return this.setOption(name, Number(value), AV_OPT_TYPE_DOUBLE);
1434
+ }
1435
+ else if (typeof value === 'string') {
1436
+ return this.setOption(name, parseFloat(value), AV_OPT_TYPE_DOUBLE);
1437
+ }
1438
+ else {
1439
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1440
+ }
1441
+ case AV_OPT_TYPE_BOOL:
1442
+ if (typeof value === 'boolean') {
1443
+ return this.setOption(name, value, AV_OPT_TYPE_BOOL);
1444
+ }
1445
+ else if (typeof value === 'number') {
1446
+ return this.setOption(name, value !== 0, AV_OPT_TYPE_BOOL);
1447
+ }
1448
+ else if (typeof value === 'bigint') {
1449
+ return this.setOption(name, value !== 0n, AV_OPT_TYPE_BOOL);
1450
+ }
1451
+ else {
1452
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1453
+ }
1454
+ case AV_OPT_TYPE_STRING:
1455
+ if (typeof value === 'string') {
1456
+ return this.setOption(name, value, AV_OPT_TYPE_STRING);
1457
+ }
1458
+ else if (typeof value === 'object') {
1459
+ return this.setOption(name, JSON.stringify(value), AV_OPT_TYPE_STRING);
1460
+ }
1461
+ else {
1462
+ return this.setOption(name, String(value), AV_OPT_TYPE_STRING);
1463
+ }
1464
+ case AV_OPT_TYPE_COLOR:
1465
+ if (typeof value === 'string') {
1466
+ return this.setOption(name, value, AV_OPT_TYPE_COLOR);
1467
+ }
1468
+ else if (typeof value === 'object') {
1469
+ return this.setOption(name, JSON.stringify(value), AV_OPT_TYPE_COLOR);
1470
+ }
1471
+ else {
1472
+ return this.setOption(name, String(value), AV_OPT_TYPE_COLOR);
1473
+ }
1474
+ case AV_OPT_TYPE_RATIONAL:
1475
+ case AV_OPT_TYPE_VIDEO_RATE:
1476
+ if (typeof value === 'object' && 'num' in value && 'den' in value) {
1477
+ return this.setOption(name, value, AV_OPT_TYPE_RATIONAL);
1478
+ }
1479
+ else if (typeof value === 'string') {
1480
+ // Try to parse "30/1" or "30:1" format
1481
+ const match = /^(\d+)[/:](\d+)$/.exec(value);
1482
+ if (match) {
1483
+ return this.setOption(name, { num: parseInt(match[1], 10), den: parseInt(match[2], 10) }, AV_OPT_TYPE_RATIONAL);
1484
+ }
1485
+ // Fallback to string (let FFmpeg parse it)
1486
+ return this.setOption(name, value, AV_OPT_TYPE_STRING);
1487
+ }
1488
+ else {
1489
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1490
+ }
1491
+ // Image size type - handle all input types
1492
+ case AV_OPT_TYPE_IMAGE_SIZE:
1493
+ if (typeof value === 'object' && 'width' in value && 'height' in value) {
1494
+ return this.setOption(name, value, AV_OPT_TYPE_IMAGE_SIZE);
1495
+ }
1496
+ else if (typeof value === 'string') {
1497
+ // Try to parse "1920x1080" format
1498
+ const match = /^(\d+)x(\d+)$/.exec(value);
1499
+ if (match) {
1500
+ return this.setOption(name, { width: parseInt(match[1], 10), height: parseInt(match[2], 10) }, AV_OPT_TYPE_IMAGE_SIZE);
1501
+ }
1502
+ // Fallback to string (let FFmpeg parse it)
1503
+ return this.setOption(name, value, AV_OPT_TYPE_STRING);
1504
+ }
1505
+ else {
1506
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1507
+ }
1508
+ // Pixel/Sample format types - handle all input types
1509
+ case AV_OPT_TYPE_PIXEL_FMT:
1510
+ if (typeof value === 'number') {
1511
+ return this.setOption(name, value, AV_OPT_TYPE_PIXEL_FMT);
1512
+ }
1513
+ else if (typeof value === 'bigint') {
1514
+ return this.setOption(name, Number(value), AV_OPT_TYPE_PIXEL_FMT);
1515
+ }
1516
+ else if (typeof value === 'string') {
1517
+ return this.setOption(name, avGetPixFmtFromName(value), AV_OPT_TYPE_PIXEL_FMT);
1518
+ }
1519
+ else {
1520
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1521
+ }
1522
+ case AV_OPT_TYPE_SAMPLE_FMT:
1523
+ if (typeof value === 'number') {
1524
+ return this.setOption(name, value, AV_OPT_TYPE_SAMPLE_FMT);
1525
+ }
1526
+ else if (typeof value === 'bigint') {
1527
+ return this.setOption(name, Number(value), AV_OPT_TYPE_SAMPLE_FMT);
1528
+ }
1529
+ else if (typeof value === 'string') {
1530
+ return this.setOption(name, avGetSampleFmtFromName(value), AV_OPT_TYPE_SAMPLE_FMT);
1531
+ }
1532
+ else {
1533
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1534
+ }
1535
+ // Binary type - handle all input types
1536
+ case AV_OPT_TYPE_BINARY:
1537
+ if (Buffer.isBuffer(value)) {
1538
+ return this.setOption(name, value, AV_OPT_TYPE_BINARY);
1539
+ }
1540
+ else if (typeof value === 'string') {
1541
+ return this.setOption(name, Buffer.from(value), AV_OPT_TYPE_BINARY);
1542
+ }
1543
+ else {
1544
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1545
+ }
1546
+ // Binary int array type - handle all input types
1547
+ case AV_OPT_TYPE_BINARY_INT_ARRAY:
1548
+ if (Array.isArray(value)) {
1549
+ // Convert all elements to numbers
1550
+ return this.setOption(name, value.map((v) => (typeof v === 'number' ? v : Number(v))), AV_OPT_TYPE_BINARY_INT_ARRAY);
1551
+ }
1552
+ else if (typeof value === 'number') {
1553
+ // Single number → single-element array
1554
+ return this.setOption(name, [value], AV_OPT_TYPE_BINARY_INT_ARRAY);
1555
+ }
1556
+ else if (typeof value === 'bigint') {
1557
+ // Single bigint → single-element array
1558
+ return this.setOption(name, [Number(value)], AV_OPT_TYPE_BINARY_INT_ARRAY);
1559
+ }
1560
+ else if (typeof value === 'boolean') {
1561
+ // Boolean → single-element array
1562
+ return this.setOption(name, [value ? 1 : 0], AV_OPT_TYPE_BINARY_INT_ARRAY);
1563
+ }
1564
+ else {
1565
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1566
+ }
1567
+ // Dictionary type - handle all input types
1568
+ case AV_OPT_TYPE_DICT:
1569
+ if (value instanceof Dictionary) {
1570
+ return this.setOption(name, value, AV_OPT_TYPE_DICT);
1571
+ }
1572
+ else if (typeof value === 'object' && !Array.isArray(value)) {
1573
+ // Convert plain object to Dictionary
1574
+ const dict = Dictionary.fromObject(value);
1575
+ return this.setOption(name, dict, AV_OPT_TYPE_DICT);
1576
+ }
1577
+ else {
1578
+ return FFmpegError.AVERROR(PosixError.EINVAL);
1579
+ }
1580
+ // Unknown type - fallback to string
1581
+ default:
1582
+ if (typeof value === 'string') {
1583
+ return this.setOption(name, value, AV_OPT_TYPE_STRING);
1584
+ }
1585
+ else if (typeof value === 'object') {
1586
+ return this.setOption(name, JSON.stringify(value), AV_OPT_TYPE_STRING);
1587
+ }
1588
+ else {
1589
+ return this.setOption(name, String(value), AV_OPT_TYPE_STRING);
1590
+ }
1591
+ }
1592
+ }
1593
+ else {
1594
+ // Option not found - fallback to string (for private/undocumented options)
1595
+ if (typeof value === 'string') {
1596
+ return this.setOption(name, value, AV_OPT_TYPE_STRING);
1597
+ }
1598
+ else if (typeof value === 'object') {
1599
+ return this.setOption(name, JSON.stringify(value), AV_OPT_TYPE_STRING);
1600
+ }
1601
+ else {
1602
+ return this.setOption(name, String(value), AV_OPT_TYPE_STRING);
1603
+ }
1604
+ }
1605
+ }
1606
+ }
1607
+ //# sourceMappingURL=option.js.map