@revizly/node-av 5.2.2-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 (254) hide show
  1. package/BUILD_LINUX.md +61 -0
  2. package/LICENSE.md +22 -0
  3. package/README.md +662 -0
  4. package/build_mac_local.sh +69 -0
  5. package/dist/api/audio-frame-buffer.d.ts +205 -0
  6. package/dist/api/audio-frame-buffer.js +287 -0
  7. package/dist/api/audio-frame-buffer.js.map +1 -0
  8. package/dist/api/bitstream-filter.d.ts +820 -0
  9. package/dist/api/bitstream-filter.js +1242 -0
  10. package/dist/api/bitstream-filter.js.map +1 -0
  11. package/dist/api/constants.d.ts +44 -0
  12. package/dist/api/constants.js +45 -0
  13. package/dist/api/constants.js.map +1 -0
  14. package/dist/api/data/test_av1.ivf +0 -0
  15. package/dist/api/data/test_h264.h264 +0 -0
  16. package/dist/api/data/test_hevc.h265 +0 -0
  17. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  18. package/dist/api/data/test_vp8.ivf +0 -0
  19. package/dist/api/data/test_vp9.ivf +0 -0
  20. package/dist/api/decoder.d.ts +1088 -0
  21. package/dist/api/decoder.js +1775 -0
  22. package/dist/api/decoder.js.map +1 -0
  23. package/dist/api/demuxer.d.ts +1219 -0
  24. package/dist/api/demuxer.js +2081 -0
  25. package/dist/api/demuxer.js.map +1 -0
  26. package/dist/api/device.d.ts +586 -0
  27. package/dist/api/device.js +961 -0
  28. package/dist/api/device.js.map +1 -0
  29. package/dist/api/encoder.d.ts +1132 -0
  30. package/dist/api/encoder.js +1988 -0
  31. package/dist/api/encoder.js.map +1 -0
  32. package/dist/api/filter-complex.d.ts +821 -0
  33. package/dist/api/filter-complex.js +1604 -0
  34. package/dist/api/filter-complex.js.map +1 -0
  35. package/dist/api/filter-presets.d.ts +1286 -0
  36. package/dist/api/filter-presets.js +2152 -0
  37. package/dist/api/filter-presets.js.map +1 -0
  38. package/dist/api/filter.d.ts +1234 -0
  39. package/dist/api/filter.js +1976 -0
  40. package/dist/api/filter.js.map +1 -0
  41. package/dist/api/fmp4-stream.d.ts +426 -0
  42. package/dist/api/fmp4-stream.js +739 -0
  43. package/dist/api/fmp4-stream.js.map +1 -0
  44. package/dist/api/hardware.d.ts +651 -0
  45. package/dist/api/hardware.js +1260 -0
  46. package/dist/api/hardware.js.map +1 -0
  47. package/dist/api/index.d.ts +17 -0
  48. package/dist/api/index.js +32 -0
  49. package/dist/api/index.js.map +1 -0
  50. package/dist/api/io-stream.d.ts +307 -0
  51. package/dist/api/io-stream.js +282 -0
  52. package/dist/api/io-stream.js.map +1 -0
  53. package/dist/api/muxer.d.ts +957 -0
  54. package/dist/api/muxer.js +2002 -0
  55. package/dist/api/muxer.js.map +1 -0
  56. package/dist/api/pipeline.d.ts +607 -0
  57. package/dist/api/pipeline.js +1145 -0
  58. package/dist/api/pipeline.js.map +1 -0
  59. package/dist/api/utilities/async-queue.d.ts +120 -0
  60. package/dist/api/utilities/async-queue.js +211 -0
  61. package/dist/api/utilities/async-queue.js.map +1 -0
  62. package/dist/api/utilities/audio-sample.d.ts +117 -0
  63. package/dist/api/utilities/audio-sample.js +112 -0
  64. package/dist/api/utilities/audio-sample.js.map +1 -0
  65. package/dist/api/utilities/channel-layout.d.ts +76 -0
  66. package/dist/api/utilities/channel-layout.js +80 -0
  67. package/dist/api/utilities/channel-layout.js.map +1 -0
  68. package/dist/api/utilities/electron-shared-texture.d.ts +328 -0
  69. package/dist/api/utilities/electron-shared-texture.js +503 -0
  70. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  71. package/dist/api/utilities/image.d.ts +207 -0
  72. package/dist/api/utilities/image.js +213 -0
  73. package/dist/api/utilities/image.js.map +1 -0
  74. package/dist/api/utilities/index.d.ts +12 -0
  75. package/dist/api/utilities/index.js +25 -0
  76. package/dist/api/utilities/index.js.map +1 -0
  77. package/dist/api/utilities/media-type.d.ts +49 -0
  78. package/dist/api/utilities/media-type.js +53 -0
  79. package/dist/api/utilities/media-type.js.map +1 -0
  80. package/dist/api/utilities/pixel-format.d.ts +89 -0
  81. package/dist/api/utilities/pixel-format.js +97 -0
  82. package/dist/api/utilities/pixel-format.js.map +1 -0
  83. package/dist/api/utilities/sample-format.d.ts +129 -0
  84. package/dist/api/utilities/sample-format.js +141 -0
  85. package/dist/api/utilities/sample-format.js.map +1 -0
  86. package/dist/api/utilities/scheduler.d.ts +138 -0
  87. package/dist/api/utilities/scheduler.js +98 -0
  88. package/dist/api/utilities/scheduler.js.map +1 -0
  89. package/dist/api/utilities/streaming.d.ts +186 -0
  90. package/dist/api/utilities/streaming.js +309 -0
  91. package/dist/api/utilities/streaming.js.map +1 -0
  92. package/dist/api/utilities/timestamp.d.ts +193 -0
  93. package/dist/api/utilities/timestamp.js +206 -0
  94. package/dist/api/utilities/timestamp.js.map +1 -0
  95. package/dist/api/utilities/whisper-model.d.ts +310 -0
  96. package/dist/api/utilities/whisper-model.js +528 -0
  97. package/dist/api/utilities/whisper-model.js.map +1 -0
  98. package/dist/api/utils.d.ts +19 -0
  99. package/dist/api/utils.js +39 -0
  100. package/dist/api/utils.js.map +1 -0
  101. package/dist/api/whisper.d.ts +324 -0
  102. package/dist/api/whisper.js +362 -0
  103. package/dist/api/whisper.js.map +1 -0
  104. package/dist/constants/channel-layouts.d.ts +53 -0
  105. package/dist/constants/channel-layouts.js +57 -0
  106. package/dist/constants/channel-layouts.js.map +1 -0
  107. package/dist/constants/constants.d.ts +2325 -0
  108. package/dist/constants/constants.js +1887 -0
  109. package/dist/constants/constants.js.map +1 -0
  110. package/dist/constants/decoders.d.ts +633 -0
  111. package/dist/constants/decoders.js +641 -0
  112. package/dist/constants/decoders.js.map +1 -0
  113. package/dist/constants/encoders.d.ts +295 -0
  114. package/dist/constants/encoders.js +308 -0
  115. package/dist/constants/encoders.js.map +1 -0
  116. package/dist/constants/hardware.d.ts +26 -0
  117. package/dist/constants/hardware.js +27 -0
  118. package/dist/constants/hardware.js.map +1 -0
  119. package/dist/constants/index.d.ts +5 -0
  120. package/dist/constants/index.js +6 -0
  121. package/dist/constants/index.js.map +1 -0
  122. package/dist/ffmpeg/index.d.ts +99 -0
  123. package/dist/ffmpeg/index.js +115 -0
  124. package/dist/ffmpeg/index.js.map +1 -0
  125. package/dist/ffmpeg/utils.d.ts +31 -0
  126. package/dist/ffmpeg/utils.js +68 -0
  127. package/dist/ffmpeg/utils.js.map +1 -0
  128. package/dist/ffmpeg/version.d.ts +6 -0
  129. package/dist/ffmpeg/version.js +7 -0
  130. package/dist/ffmpeg/version.js.map +1 -0
  131. package/dist/index.d.ts +4 -0
  132. package/dist/index.js +9 -0
  133. package/dist/index.js.map +1 -0
  134. package/dist/lib/audio-fifo.d.ts +399 -0
  135. package/dist/lib/audio-fifo.js +431 -0
  136. package/dist/lib/audio-fifo.js.map +1 -0
  137. package/dist/lib/binding.d.ts +228 -0
  138. package/dist/lib/binding.js +60 -0
  139. package/dist/lib/binding.js.map +1 -0
  140. package/dist/lib/bitstream-filter-context.d.ts +379 -0
  141. package/dist/lib/bitstream-filter-context.js +441 -0
  142. package/dist/lib/bitstream-filter-context.js.map +1 -0
  143. package/dist/lib/bitstream-filter.d.ts +140 -0
  144. package/dist/lib/bitstream-filter.js +154 -0
  145. package/dist/lib/bitstream-filter.js.map +1 -0
  146. package/dist/lib/codec-context.d.ts +1071 -0
  147. package/dist/lib/codec-context.js +1354 -0
  148. package/dist/lib/codec-context.js.map +1 -0
  149. package/dist/lib/codec-parameters.d.ts +616 -0
  150. package/dist/lib/codec-parameters.js +761 -0
  151. package/dist/lib/codec-parameters.js.map +1 -0
  152. package/dist/lib/codec-parser.d.ts +201 -0
  153. package/dist/lib/codec-parser.js +213 -0
  154. package/dist/lib/codec-parser.js.map +1 -0
  155. package/dist/lib/codec.d.ts +586 -0
  156. package/dist/lib/codec.js +713 -0
  157. package/dist/lib/codec.js.map +1 -0
  158. package/dist/lib/device.d.ts +291 -0
  159. package/dist/lib/device.js +324 -0
  160. package/dist/lib/device.js.map +1 -0
  161. package/dist/lib/dictionary.d.ts +333 -0
  162. package/dist/lib/dictionary.js +372 -0
  163. package/dist/lib/dictionary.js.map +1 -0
  164. package/dist/lib/error.d.ts +242 -0
  165. package/dist/lib/error.js +303 -0
  166. package/dist/lib/error.js.map +1 -0
  167. package/dist/lib/fifo.d.ts +416 -0
  168. package/dist/lib/fifo.js +453 -0
  169. package/dist/lib/fifo.js.map +1 -0
  170. package/dist/lib/filter-context.d.ts +712 -0
  171. package/dist/lib/filter-context.js +789 -0
  172. package/dist/lib/filter-context.js.map +1 -0
  173. package/dist/lib/filter-graph-segment.d.ts +160 -0
  174. package/dist/lib/filter-graph-segment.js +171 -0
  175. package/dist/lib/filter-graph-segment.js.map +1 -0
  176. package/dist/lib/filter-graph.d.ts +641 -0
  177. package/dist/lib/filter-graph.js +704 -0
  178. package/dist/lib/filter-graph.js.map +1 -0
  179. package/dist/lib/filter-inout.d.ts +198 -0
  180. package/dist/lib/filter-inout.js +257 -0
  181. package/dist/lib/filter-inout.js.map +1 -0
  182. package/dist/lib/filter.d.ts +243 -0
  183. package/dist/lib/filter.js +272 -0
  184. package/dist/lib/filter.js.map +1 -0
  185. package/dist/lib/format-context.d.ts +1254 -0
  186. package/dist/lib/format-context.js +1379 -0
  187. package/dist/lib/format-context.js.map +1 -0
  188. package/dist/lib/frame-utils.d.ts +116 -0
  189. package/dist/lib/frame-utils.js +98 -0
  190. package/dist/lib/frame-utils.js.map +1 -0
  191. package/dist/lib/frame.d.ts +1222 -0
  192. package/dist/lib/frame.js +1435 -0
  193. package/dist/lib/frame.js.map +1 -0
  194. package/dist/lib/hardware-device-context.d.ts +362 -0
  195. package/dist/lib/hardware-device-context.js +383 -0
  196. package/dist/lib/hardware-device-context.js.map +1 -0
  197. package/dist/lib/hardware-frames-context.d.ts +419 -0
  198. package/dist/lib/hardware-frames-context.js +477 -0
  199. package/dist/lib/hardware-frames-context.js.map +1 -0
  200. package/dist/lib/index.d.ts +35 -0
  201. package/dist/lib/index.js +60 -0
  202. package/dist/lib/index.js.map +1 -0
  203. package/dist/lib/input-format.d.ts +249 -0
  204. package/dist/lib/input-format.js +306 -0
  205. package/dist/lib/input-format.js.map +1 -0
  206. package/dist/lib/io-context.d.ts +696 -0
  207. package/dist/lib/io-context.js +769 -0
  208. package/dist/lib/io-context.js.map +1 -0
  209. package/dist/lib/log.d.ts +174 -0
  210. package/dist/lib/log.js +184 -0
  211. package/dist/lib/log.js.map +1 -0
  212. package/dist/lib/native-types.d.ts +946 -0
  213. package/dist/lib/native-types.js +2 -0
  214. package/dist/lib/native-types.js.map +1 -0
  215. package/dist/lib/option.d.ts +927 -0
  216. package/dist/lib/option.js +1583 -0
  217. package/dist/lib/option.js.map +1 -0
  218. package/dist/lib/output-format.d.ts +180 -0
  219. package/dist/lib/output-format.js +213 -0
  220. package/dist/lib/output-format.js.map +1 -0
  221. package/dist/lib/packet.d.ts +501 -0
  222. package/dist/lib/packet.js +590 -0
  223. package/dist/lib/packet.js.map +1 -0
  224. package/dist/lib/rational.d.ts +251 -0
  225. package/dist/lib/rational.js +278 -0
  226. package/dist/lib/rational.js.map +1 -0
  227. package/dist/lib/software-resample-context.d.ts +552 -0
  228. package/dist/lib/software-resample-context.js +592 -0
  229. package/dist/lib/software-resample-context.js.map +1 -0
  230. package/dist/lib/software-scale-context.d.ts +344 -0
  231. package/dist/lib/software-scale-context.js +366 -0
  232. package/dist/lib/software-scale-context.js.map +1 -0
  233. package/dist/lib/stream.d.ts +379 -0
  234. package/dist/lib/stream.js +526 -0
  235. package/dist/lib/stream.js.map +1 -0
  236. package/dist/lib/sync-queue.d.ts +179 -0
  237. package/dist/lib/sync-queue.js +197 -0
  238. package/dist/lib/sync-queue.js.map +1 -0
  239. package/dist/lib/types.d.ts +34 -0
  240. package/dist/lib/types.js +2 -0
  241. package/dist/lib/types.js.map +1 -0
  242. package/dist/lib/utilities.d.ts +1127 -0
  243. package/dist/lib/utilities.js +1225 -0
  244. package/dist/lib/utilities.js.map +1 -0
  245. package/dist/utils/electron.d.ts +49 -0
  246. package/dist/utils/electron.js +63 -0
  247. package/dist/utils/electron.js.map +1 -0
  248. package/dist/utils/index.d.ts +4 -0
  249. package/dist/utils/index.js +5 -0
  250. package/dist/utils/index.js.map +1 -0
  251. package/install/check.js +121 -0
  252. package/install/ffmpeg.js +66 -0
  253. package/jellyfin-ffmpeg.patch +181 -0
  254. package/package.json +129 -0
@@ -0,0 +1,333 @@
1
+ import type { AVDictFlag } from '../constants/constants.js';
2
+ import type { NativeDictionary, NativeWrapper } from './native-types.js';
3
+ /**
4
+ * Key-value dictionary for FFmpeg options and metadata.
5
+ *
6
+ * Stores string key-value pairs used throughout FFmpeg for options, metadata,
7
+ * and configuration. Provides methods for setting, getting, and manipulating
8
+ * dictionary entries. Used extensively for codec options, format options,
9
+ * and metadata handling.
10
+ *
11
+ * Direct mapping to FFmpeg's AVDictionary.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { Dictionary, FFmpegError } from 'node-av';
16
+ * import { AV_DICT_IGNORE_SUFFIX } from 'node-av/constants';
17
+ *
18
+ * // Create from object
19
+ * const dict = Dictionary.fromObject({
20
+ * 'title': 'My Video',
21
+ * 'artist': 'Me',
22
+ * 'year': '2024'
23
+ * });
24
+ *
25
+ * // Set individual values
26
+ * const dict2 = new Dictionary();
27
+ * dict2.alloc();
28
+ * let ret = dict2.set('preset', 'fast');
29
+ * FFmpegError.throwIfError(ret, 'set');
30
+ *
31
+ * // Parse from string
32
+ * ret = dict2.parseString('key1=value1:key2=value2', '=', ':');
33
+ * FFmpegError.throwIfError(ret, 'parseString');
34
+ *
35
+ * // Get all entries
36
+ * const entries = dict2.getAll();
37
+ * console.log(entries); // { key1: 'value1', key2: 'value2' }
38
+ * ```
39
+ *
40
+ * @see [AVDictionary](https://ffmpeg.org/doxygen/trunk/group__lavu__dict.html) - FFmpeg Doxygen
41
+ * @see {@link CodecContext} For codec options
42
+ * @see {@link FormatContext} For format options
43
+ */
44
+ export declare class Dictionary implements Disposable, NativeWrapper<NativeDictionary> {
45
+ private native;
46
+ constructor();
47
+ /**
48
+ * Create dictionary from JavaScript object.
49
+ *
50
+ * Convenience method to create a dictionary from a plain object.
51
+ *
52
+ * @param obj - Object with string key-value pairs
53
+ *
54
+ * @param flags - Flags for setting entries
55
+ *
56
+ * @returns New dictionary with entries from object
57
+ *
58
+ * @example
59
+ * ```typescript
60
+ * const metadata = Dictionary.fromObject({
61
+ * 'title': 'My Song',
62
+ * 'album': 'My Album',
63
+ * 'date': '2024',
64
+ * 'track': '1/10'
65
+ * });
66
+ *
67
+ * // Use for codec options
68
+ * const options = Dictionary.fromObject({
69
+ * 'preset': 'medium',
70
+ * 'crf': 23,
71
+ * 'profile': 'high'
72
+ * });
73
+ * ```
74
+ */
75
+ static fromObject(obj: Record<string, string | number | boolean | undefined | null>, flags?: AVDictFlag): Dictionary;
76
+ /**
77
+ * Create dictionary from native instance.
78
+ *
79
+ * @param native - Native dictionary instance
80
+ *
81
+ * @returns Dictionary wrapper
82
+ *
83
+ * @internal
84
+ */
85
+ static fromNative(native: NativeDictionary): Dictionary;
86
+ /**
87
+ * Allocate a dictionary.
88
+ *
89
+ * Allocates memory for the dictionary structure.
90
+ * Must be called before using the dictionary.
91
+ *
92
+ * Direct mapping to av_dict_alloc().
93
+ *
94
+ * @throws {Error} If allocation fails (ENOMEM)
95
+ *
96
+ * @example
97
+ * ```typescript
98
+ * const dict = new Dictionary();
99
+ * dict.alloc();
100
+ * // Dictionary is now ready for use
101
+ * ```
102
+ *
103
+ * @see {@link free} To deallocate
104
+ */
105
+ alloc(): void;
106
+ /**
107
+ * Free the dictionary.
108
+ *
109
+ * Releases all memory associated with the dictionary.
110
+ * The dictionary becomes invalid after calling this.
111
+ *
112
+ * Direct mapping to av_dict_free().
113
+ *
114
+ * @example
115
+ * ```typescript
116
+ * dict.free();
117
+ * // Dictionary is now invalid
118
+ * ```
119
+ *
120
+ * @see {@link alloc} To allocate
121
+ * @see {@link Symbol.dispose} For automatic cleanup
122
+ */
123
+ free(): void;
124
+ /**
125
+ * Copy entries to another dictionary.
126
+ *
127
+ * Copies all entries from this dictionary to the destination.
128
+ *
129
+ * Direct mapping to av_dict_copy().
130
+ *
131
+ * @param dst - Destination dictionary
132
+ *
133
+ * @param flags - Copy flags
134
+ *
135
+ * @returns 0 on success, negative AVERROR on error:
136
+ * - AVERROR_ENOMEM: Memory allocation failure
137
+ *
138
+ * @example
139
+ * ```typescript
140
+ * import { FFmpegError } from 'node-av';
141
+ *
142
+ * const dst = new Dictionary();
143
+ * dst.alloc();
144
+ * const ret = src.copy(dst);
145
+ * FFmpegError.throwIfError(ret, 'copy');
146
+ * ```
147
+ */
148
+ copy(dst: Dictionary, flags?: AVDictFlag): number;
149
+ /**
150
+ * Set a dictionary entry.
151
+ *
152
+ * Sets or updates a key-value pair in the dictionary.
153
+ *
154
+ * Direct mapping to av_dict_set().
155
+ *
156
+ * @param key - Entry key
157
+ *
158
+ * @param value - Entry value
159
+ *
160
+ * @param flags - Set flags (e.g., AV_DICT_DONT_OVERWRITE)
161
+ *
162
+ * @returns 0 on success, negative AVERROR on error:
163
+ * - AVERROR_ENOMEM: Memory allocation failure
164
+ *
165
+ * @example
166
+ * ```typescript
167
+ * import { FFmpegError } from 'node-av';
168
+ * import { AV_DICT_DONT_OVERWRITE } from 'node-av/constants';
169
+ *
170
+ * // Set or update entry
171
+ * let ret = dict.set('bitrate', '128k');
172
+ * FFmpegError.throwIfError(ret, 'set');
173
+ *
174
+ * // Set only if not exists
175
+ * ret = dict.set('preset', 'fast', AV_DICT_DONT_OVERWRITE);
176
+ * FFmpegError.throwIfError(ret, 'set');
177
+ * ```
178
+ *
179
+ * @see {@link get} To retrieve values
180
+ */
181
+ set(key: string, value: string, flags?: AVDictFlag): number;
182
+ /**
183
+ * Get a dictionary entry.
184
+ *
185
+ * Retrieves the value for a given key.
186
+ *
187
+ * Direct mapping to av_dict_get().
188
+ *
189
+ * @param key - Entry key to look up
190
+ *
191
+ * @param flags - Search flags (e.g., AV_DICT_IGNORE_SUFFIX)
192
+ *
193
+ * @returns Entry value, or null if not found
194
+ *
195
+ * @example
196
+ * ```typescript
197
+ * const value = dict.get('bitrate');
198
+ * if (value) {
199
+ * console.log(`Bitrate: ${value}`);
200
+ * }
201
+ *
202
+ * // Case-insensitive search
203
+ * import { AV_DICT_MATCH_CASE } from 'node-av/constants';
204
+ * const title = dict.get('Title', AV_DICT_MATCH_CASE);
205
+ * ```
206
+ *
207
+ * @see {@link set} To set values
208
+ * @see {@link getAll} To get all entries
209
+ */
210
+ get(key: string, flags?: AVDictFlag): string | null;
211
+ /**
212
+ * Count dictionary entries.
213
+ *
214
+ * Returns the number of key-value pairs in the dictionary.
215
+ *
216
+ * Direct mapping to av_dict_count().
217
+ *
218
+ * @returns Number of entries
219
+ *
220
+ * @example
221
+ * ```typescript
222
+ * const count = dict.count();
223
+ * console.log(`Dictionary has ${count} entries`);
224
+ * ```
225
+ */
226
+ count(): number;
227
+ /**
228
+ * Get all dictionary entries.
229
+ *
230
+ * Returns all key-value pairs as a JavaScript object.
231
+ *
232
+ * @returns Object with all entries
233
+ *
234
+ * @example
235
+ * ```typescript
236
+ * const entries = dict.getAll();
237
+ * for (const [key, value] of Object.entries(entries)) {
238
+ * console.log(`${key}: ${value}`);
239
+ * }
240
+ * ```
241
+ *
242
+ * @see {@link get} To get individual entries
243
+ */
244
+ getAll(): Record<string, string>;
245
+ /**
246
+ * Parse entries from a string.
247
+ *
248
+ * Parses key-value pairs from a formatted string and adds them
249
+ * to the dictionary.
250
+ *
251
+ * Direct mapping to av_dict_parse_string().
252
+ *
253
+ * @param str - String to parse
254
+ *
255
+ * @param keyValSep - Separator between key and value
256
+ *
257
+ * @param pairsSep - Separator between pairs
258
+ *
259
+ * @param flags - Parse flags
260
+ *
261
+ * @returns 0 on success, negative AVERROR on error:
262
+ * - AVERROR_EINVAL: Invalid format
263
+ * - AVERROR_ENOMEM: Memory allocation failure
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * import { FFmpegError } from 'node-av';
268
+ *
269
+ * // Parse colon-separated pairs
270
+ * let ret = dict.parseString('key1=val1:key2=val2', '=', ':');
271
+ * FFmpegError.throwIfError(ret, 'parseString');
272
+ *
273
+ * // Parse comma-separated pairs
274
+ * ret = dict.parseString('width=1920,height=1080', '=', ',');
275
+ * FFmpegError.throwIfError(ret, 'parseString');
276
+ * ```
277
+ *
278
+ * @see {@link getString} To serialize to string
279
+ */
280
+ parseString(str: string, keyValSep: string, pairsSep: string, flags?: AVDictFlag): number;
281
+ /**
282
+ * Convert dictionary to string.
283
+ *
284
+ * Serializes all entries to a formatted string.
285
+ *
286
+ * Direct mapping to av_dict_get_string().
287
+ *
288
+ * @param keyValSep - Separator between key and value
289
+ *
290
+ * @param pairsSep - Separator between pairs
291
+ *
292
+ * @returns Formatted string, or null on error
293
+ *
294
+ * @example
295
+ * ```typescript
296
+ * // Serialize to colon-separated format
297
+ * const str = dict.getString('=', ':');
298
+ * console.log(str); // "key1=val1:key2=val2"
299
+ *
300
+ * // Serialize to comma-separated format
301
+ * const csv = dict.getString('=', ',');
302
+ * console.log(csv); // "key1=val1,key2=val2"
303
+ * ```
304
+ *
305
+ * @see {@link parseString} To parse from string
306
+ */
307
+ getString(keyValSep: string, pairsSep: string): string | null;
308
+ /**
309
+ * Get the underlying native Dictionary object.
310
+ *
311
+ * @returns The native Dictionary binding object
312
+ *
313
+ * @internal
314
+ */
315
+ getNative(): NativeDictionary;
316
+ /**
317
+ * Dispose of the dictionary.
318
+ *
319
+ * Implements the Disposable interface for automatic cleanup.
320
+ * Equivalent to calling free().
321
+ *
322
+ * @example
323
+ * ```typescript
324
+ * {
325
+ * using dict = new Dictionary();
326
+ * dict.alloc();
327
+ * dict.set('key', 'value');
328
+ * // Use dict...
329
+ * } // Automatically freed when leaving scope
330
+ * ```
331
+ */
332
+ [Symbol.dispose](): void;
333
+ }
@@ -0,0 +1,372 @@
1
+ import { AVFLAG_NONE } from '../constants/constants.js';
2
+ import { bindings } from './binding.js';
3
+ /**
4
+ * Key-value dictionary for FFmpeg options and metadata.
5
+ *
6
+ * Stores string key-value pairs used throughout FFmpeg for options, metadata,
7
+ * and configuration. Provides methods for setting, getting, and manipulating
8
+ * dictionary entries. Used extensively for codec options, format options,
9
+ * and metadata handling.
10
+ *
11
+ * Direct mapping to FFmpeg's AVDictionary.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { Dictionary, FFmpegError } from 'node-av';
16
+ * import { AV_DICT_IGNORE_SUFFIX } from 'node-av/constants';
17
+ *
18
+ * // Create from object
19
+ * const dict = Dictionary.fromObject({
20
+ * 'title': 'My Video',
21
+ * 'artist': 'Me',
22
+ * 'year': '2024'
23
+ * });
24
+ *
25
+ * // Set individual values
26
+ * const dict2 = new Dictionary();
27
+ * dict2.alloc();
28
+ * let ret = dict2.set('preset', 'fast');
29
+ * FFmpegError.throwIfError(ret, 'set');
30
+ *
31
+ * // Parse from string
32
+ * ret = dict2.parseString('key1=value1:key2=value2', '=', ':');
33
+ * FFmpegError.throwIfError(ret, 'parseString');
34
+ *
35
+ * // Get all entries
36
+ * const entries = dict2.getAll();
37
+ * console.log(entries); // { key1: 'value1', key2: 'value2' }
38
+ * ```
39
+ *
40
+ * @see [AVDictionary](https://ffmpeg.org/doxygen/trunk/group__lavu__dict.html) - FFmpeg Doxygen
41
+ * @see {@link CodecContext} For codec options
42
+ * @see {@link FormatContext} For format options
43
+ */
44
+ export class Dictionary {
45
+ native;
46
+ constructor() {
47
+ this.native = new bindings.Dictionary();
48
+ }
49
+ /**
50
+ * Create dictionary from JavaScript object.
51
+ *
52
+ * Convenience method to create a dictionary from a plain object.
53
+ *
54
+ * @param obj - Object with string key-value pairs
55
+ *
56
+ * @param flags - Flags for setting entries
57
+ *
58
+ * @returns New dictionary with entries from object
59
+ *
60
+ * @example
61
+ * ```typescript
62
+ * const metadata = Dictionary.fromObject({
63
+ * 'title': 'My Song',
64
+ * 'album': 'My Album',
65
+ * 'date': '2024',
66
+ * 'track': '1/10'
67
+ * });
68
+ *
69
+ * // Use for codec options
70
+ * const options = Dictionary.fromObject({
71
+ * 'preset': 'medium',
72
+ * 'crf': 23,
73
+ * 'profile': 'high'
74
+ * });
75
+ * ```
76
+ */
77
+ static fromObject(obj, flags = AVFLAG_NONE) {
78
+ const dict = new Dictionary();
79
+ dict.alloc();
80
+ for (const [key, value] of Object.entries(obj)) {
81
+ if (value === undefined || value === null) {
82
+ continue;
83
+ }
84
+ dict.set(key, value.toString(), flags);
85
+ }
86
+ return dict;
87
+ }
88
+ /**
89
+ * Create dictionary from native instance.
90
+ *
91
+ * @param native - Native dictionary instance
92
+ *
93
+ * @returns Dictionary wrapper
94
+ *
95
+ * @internal
96
+ */
97
+ static fromNative(native) {
98
+ const dict = Object.create(Dictionary.prototype);
99
+ dict.native = native;
100
+ return dict;
101
+ }
102
+ /**
103
+ * Allocate a dictionary.
104
+ *
105
+ * Allocates memory for the dictionary structure.
106
+ * Must be called before using the dictionary.
107
+ *
108
+ * Direct mapping to av_dict_alloc().
109
+ *
110
+ * @throws {Error} If allocation fails (ENOMEM)
111
+ *
112
+ * @example
113
+ * ```typescript
114
+ * const dict = new Dictionary();
115
+ * dict.alloc();
116
+ * // Dictionary is now ready for use
117
+ * ```
118
+ *
119
+ * @see {@link free} To deallocate
120
+ */
121
+ alloc() {
122
+ this.native.alloc();
123
+ }
124
+ /**
125
+ * Free the dictionary.
126
+ *
127
+ * Releases all memory associated with the dictionary.
128
+ * The dictionary becomes invalid after calling this.
129
+ *
130
+ * Direct mapping to av_dict_free().
131
+ *
132
+ * @example
133
+ * ```typescript
134
+ * dict.free();
135
+ * // Dictionary is now invalid
136
+ * ```
137
+ *
138
+ * @see {@link alloc} To allocate
139
+ * @see {@link Symbol.dispose} For automatic cleanup
140
+ */
141
+ free() {
142
+ this.native.free();
143
+ }
144
+ /**
145
+ * Copy entries to another dictionary.
146
+ *
147
+ * Copies all entries from this dictionary to the destination.
148
+ *
149
+ * Direct mapping to av_dict_copy().
150
+ *
151
+ * @param dst - Destination dictionary
152
+ *
153
+ * @param flags - Copy flags
154
+ *
155
+ * @returns 0 on success, negative AVERROR on error:
156
+ * - AVERROR_ENOMEM: Memory allocation failure
157
+ *
158
+ * @example
159
+ * ```typescript
160
+ * import { FFmpegError } from 'node-av';
161
+ *
162
+ * const dst = new Dictionary();
163
+ * dst.alloc();
164
+ * const ret = src.copy(dst);
165
+ * FFmpegError.throwIfError(ret, 'copy');
166
+ * ```
167
+ */
168
+ copy(dst, flags = AVFLAG_NONE) {
169
+ return this.native.copy(dst.getNative(), flags);
170
+ }
171
+ /**
172
+ * Set a dictionary entry.
173
+ *
174
+ * Sets or updates a key-value pair in the dictionary.
175
+ *
176
+ * Direct mapping to av_dict_set().
177
+ *
178
+ * @param key - Entry key
179
+ *
180
+ * @param value - Entry value
181
+ *
182
+ * @param flags - Set flags (e.g., AV_DICT_DONT_OVERWRITE)
183
+ *
184
+ * @returns 0 on success, negative AVERROR on error:
185
+ * - AVERROR_ENOMEM: Memory allocation failure
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { FFmpegError } from 'node-av';
190
+ * import { AV_DICT_DONT_OVERWRITE } from 'node-av/constants';
191
+ *
192
+ * // Set or update entry
193
+ * let ret = dict.set('bitrate', '128k');
194
+ * FFmpegError.throwIfError(ret, 'set');
195
+ *
196
+ * // Set only if not exists
197
+ * ret = dict.set('preset', 'fast', AV_DICT_DONT_OVERWRITE);
198
+ * FFmpegError.throwIfError(ret, 'set');
199
+ * ```
200
+ *
201
+ * @see {@link get} To retrieve values
202
+ */
203
+ set(key, value, flags = AVFLAG_NONE) {
204
+ return this.native.set(key, value, flags);
205
+ }
206
+ /**
207
+ * Get a dictionary entry.
208
+ *
209
+ * Retrieves the value for a given key.
210
+ *
211
+ * Direct mapping to av_dict_get().
212
+ *
213
+ * @param key - Entry key to look up
214
+ *
215
+ * @param flags - Search flags (e.g., AV_DICT_IGNORE_SUFFIX)
216
+ *
217
+ * @returns Entry value, or null if not found
218
+ *
219
+ * @example
220
+ * ```typescript
221
+ * const value = dict.get('bitrate');
222
+ * if (value) {
223
+ * console.log(`Bitrate: ${value}`);
224
+ * }
225
+ *
226
+ * // Case-insensitive search
227
+ * import { AV_DICT_MATCH_CASE } from 'node-av/constants';
228
+ * const title = dict.get('Title', AV_DICT_MATCH_CASE);
229
+ * ```
230
+ *
231
+ * @see {@link set} To set values
232
+ * @see {@link getAll} To get all entries
233
+ */
234
+ get(key, flags = AVFLAG_NONE) {
235
+ return this.native.get(key, flags);
236
+ }
237
+ /**
238
+ * Count dictionary entries.
239
+ *
240
+ * Returns the number of key-value pairs in the dictionary.
241
+ *
242
+ * Direct mapping to av_dict_count().
243
+ *
244
+ * @returns Number of entries
245
+ *
246
+ * @example
247
+ * ```typescript
248
+ * const count = dict.count();
249
+ * console.log(`Dictionary has ${count} entries`);
250
+ * ```
251
+ */
252
+ count() {
253
+ return this.native.count();
254
+ }
255
+ /**
256
+ * Get all dictionary entries.
257
+ *
258
+ * Returns all key-value pairs as a JavaScript object.
259
+ *
260
+ * @returns Object with all entries
261
+ *
262
+ * @example
263
+ * ```typescript
264
+ * const entries = dict.getAll();
265
+ * for (const [key, value] of Object.entries(entries)) {
266
+ * console.log(`${key}: ${value}`);
267
+ * }
268
+ * ```
269
+ *
270
+ * @see {@link get} To get individual entries
271
+ */
272
+ getAll() {
273
+ return this.native.getAll();
274
+ }
275
+ /**
276
+ * Parse entries from a string.
277
+ *
278
+ * Parses key-value pairs from a formatted string and adds them
279
+ * to the dictionary.
280
+ *
281
+ * Direct mapping to av_dict_parse_string().
282
+ *
283
+ * @param str - String to parse
284
+ *
285
+ * @param keyValSep - Separator between key and value
286
+ *
287
+ * @param pairsSep - Separator between pairs
288
+ *
289
+ * @param flags - Parse flags
290
+ *
291
+ * @returns 0 on success, negative AVERROR on error:
292
+ * - AVERROR_EINVAL: Invalid format
293
+ * - AVERROR_ENOMEM: Memory allocation failure
294
+ *
295
+ * @example
296
+ * ```typescript
297
+ * import { FFmpegError } from 'node-av';
298
+ *
299
+ * // Parse colon-separated pairs
300
+ * let ret = dict.parseString('key1=val1:key2=val2', '=', ':');
301
+ * FFmpegError.throwIfError(ret, 'parseString');
302
+ *
303
+ * // Parse comma-separated pairs
304
+ * ret = dict.parseString('width=1920,height=1080', '=', ',');
305
+ * FFmpegError.throwIfError(ret, 'parseString');
306
+ * ```
307
+ *
308
+ * @see {@link getString} To serialize to string
309
+ */
310
+ parseString(str, keyValSep, pairsSep, flags = AVFLAG_NONE) {
311
+ return this.native.parseString(str, keyValSep, pairsSep, flags);
312
+ }
313
+ /**
314
+ * Convert dictionary to string.
315
+ *
316
+ * Serializes all entries to a formatted string.
317
+ *
318
+ * Direct mapping to av_dict_get_string().
319
+ *
320
+ * @param keyValSep - Separator between key and value
321
+ *
322
+ * @param pairsSep - Separator between pairs
323
+ *
324
+ * @returns Formatted string, or null on error
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * // Serialize to colon-separated format
329
+ * const str = dict.getString('=', ':');
330
+ * console.log(str); // "key1=val1:key2=val2"
331
+ *
332
+ * // Serialize to comma-separated format
333
+ * const csv = dict.getString('=', ',');
334
+ * console.log(csv); // "key1=val1,key2=val2"
335
+ * ```
336
+ *
337
+ * @see {@link parseString} To parse from string
338
+ */
339
+ getString(keyValSep, pairsSep) {
340
+ return this.native.getString(keyValSep, pairsSep);
341
+ }
342
+ /**
343
+ * Get the underlying native Dictionary object.
344
+ *
345
+ * @returns The native Dictionary binding object
346
+ *
347
+ * @internal
348
+ */
349
+ getNative() {
350
+ return this.native;
351
+ }
352
+ /**
353
+ * Dispose of the dictionary.
354
+ *
355
+ * Implements the Disposable interface for automatic cleanup.
356
+ * Equivalent to calling free().
357
+ *
358
+ * @example
359
+ * ```typescript
360
+ * {
361
+ * using dict = new Dictionary();
362
+ * dict.alloc();
363
+ * dict.set('key', 'value');
364
+ * // Use dict...
365
+ * } // Automatically freed when leaving scope
366
+ * ```
367
+ */
368
+ [Symbol.dispose]() {
369
+ this.native[Symbol.dispose]();
370
+ }
371
+ }
372
+ //# sourceMappingURL=dictionary.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../src/lib/dictionary.ts"],"names":[],"mappings":"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"}