node-av 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,406 @@
|
|
|
1
|
+
import { bindings } from './binding.js';
|
|
2
|
+
import { AVFLAG_NONE } from './constants.js';
|
|
3
|
+
/**
|
|
4
|
+
* Dictionary for options and metadata.
|
|
5
|
+
*
|
|
6
|
+
* Key-value storage for codec options, format options, and metadata.
|
|
7
|
+
* Used throughout FFmpeg for configuration and information storage.
|
|
8
|
+
* Supports parsing from strings and conversion back to strings.
|
|
9
|
+
*
|
|
10
|
+
* Direct mapping to FFmpeg's AVDictionary.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Dictionary, CodecContext, FFmpegError } from 'node-av';
|
|
15
|
+
*
|
|
16
|
+
* // Using Dictionary for codec options
|
|
17
|
+
* const options = new Dictionary();
|
|
18
|
+
* const ret1 = options.set('preset', 'fast', 0);
|
|
19
|
+
* FFmpegError.throwIfError(ret1, 'set preset');
|
|
20
|
+
* const ret2 = options.set('crf', '23', 0);
|
|
21
|
+
* FFmpegError.throwIfError(ret2, 'set crf');
|
|
22
|
+
*
|
|
23
|
+
* const codecContext = new CodecContext();
|
|
24
|
+
* codecContext.allocContext3(codec);
|
|
25
|
+
* const openRet = await codecContext.open2(codec, options);
|
|
26
|
+
* FFmpegError.throwIfError(openRet, 'open2');
|
|
27
|
+
*
|
|
28
|
+
* // Using Dictionary for format options
|
|
29
|
+
* const formatOptions = new Dictionary();
|
|
30
|
+
* const ret3 = formatOptions.set('movflags', 'faststart', 0);
|
|
31
|
+
* FFmpegError.throwIfError(ret3, 'set movflags');
|
|
32
|
+
* const headerRet = await formatContext.writeHeader(formatOptions);
|
|
33
|
+
* FFmpegError.throwIfError(headerRet, 'writeHeader');
|
|
34
|
+
*
|
|
35
|
+
* // Reading metadata
|
|
36
|
+
* const metadata = stream.metadata;
|
|
37
|
+
* if (metadata) {
|
|
38
|
+
* const title = metadata.get('title', 0);
|
|
39
|
+
* const artist = metadata.get('artist', 0);
|
|
40
|
+
* console.log(`Title: ${title}, Artist: ${artist}`);
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* // Cleanup
|
|
44
|
+
* options.free();
|
|
45
|
+
* formatOptions.free();
|
|
46
|
+
* ```
|
|
47
|
+
*
|
|
48
|
+
* @example
|
|
49
|
+
* ```typescript
|
|
50
|
+
* import { Dictionary, FFmpegError } from 'node-av';
|
|
51
|
+
*
|
|
52
|
+
* // Parsing options from string
|
|
53
|
+
* const dict = new Dictionary();
|
|
54
|
+
* const ret = dict.parseString('bitrate=128k:preset=fast', '=', ':', 0);
|
|
55
|
+
* FFmpegError.throwIfError(ret, 'parseString');
|
|
56
|
+
*
|
|
57
|
+
* // Getting all options as object
|
|
58
|
+
* const allOptions = dict.getAll();
|
|
59
|
+
* console.log(allOptions); // { bitrate: '128k', preset: 'fast' }
|
|
60
|
+
*
|
|
61
|
+
* // Converting back to string
|
|
62
|
+
* const str = dict.getString('=', ':');
|
|
63
|
+
* console.log(str); // "bitrate=128k:preset=fast"
|
|
64
|
+
*
|
|
65
|
+
* dict.free();
|
|
66
|
+
* ```
|
|
67
|
+
*/
|
|
68
|
+
export class Dictionary {
|
|
69
|
+
native;
|
|
70
|
+
/**
|
|
71
|
+
* Create a new dictionary.
|
|
72
|
+
*
|
|
73
|
+
* The dictionary is uninitialized and will be auto-allocated on first set() call.
|
|
74
|
+
* No FFmpeg resources are allocated until first use.
|
|
75
|
+
*
|
|
76
|
+
* Direct wrapper around AVDictionary.
|
|
77
|
+
*
|
|
78
|
+
* @example
|
|
79
|
+
* ```typescript
|
|
80
|
+
* import { Dictionary, FFmpegError } from 'node-av';
|
|
81
|
+
*
|
|
82
|
+
* const dict = new Dictionary();
|
|
83
|
+
* const ret = dict.set('key', 'value', 0); // Auto-allocates on first use
|
|
84
|
+
* FFmpegError.throwIfError(ret, 'set');
|
|
85
|
+
* ```
|
|
86
|
+
*/
|
|
87
|
+
constructor() {
|
|
88
|
+
this.native = new bindings.Dictionary();
|
|
89
|
+
}
|
|
90
|
+
/**
|
|
91
|
+
* Create a Dictionary wrapper from an existing native dictionary.
|
|
92
|
+
* Used internally when wrapping dictionaries from FFmpeg.
|
|
93
|
+
* @internal
|
|
94
|
+
*/
|
|
95
|
+
static fromNative(native) {
|
|
96
|
+
const dict = Object.create(Dictionary.prototype);
|
|
97
|
+
dict.native = native;
|
|
98
|
+
return dict;
|
|
99
|
+
}
|
|
100
|
+
/**
|
|
101
|
+
* Create a Dictionary from a JavaScript object.
|
|
102
|
+
*
|
|
103
|
+
* Converts a plain JavaScript object to a Dictionary.
|
|
104
|
+
* Useful for converting option objects to FFmpeg format.
|
|
105
|
+
*
|
|
106
|
+
* @param obj - Object with string key-value pairs
|
|
107
|
+
* @param flags - AV_DICT_* flags for set operations
|
|
108
|
+
*
|
|
109
|
+
* @returns New Dictionary containing all entries from the object
|
|
110
|
+
*
|
|
111
|
+
* @example
|
|
112
|
+
* ```typescript
|
|
113
|
+
* import { Dictionary } from 'node-av';
|
|
114
|
+
*
|
|
115
|
+
* const options = {
|
|
116
|
+
* bitrate: '128k',
|
|
117
|
+
* preset: 'fast',
|
|
118
|
+
* crf: '23'
|
|
119
|
+
* };
|
|
120
|
+
*
|
|
121
|
+
* const dict = Dictionary.fromObject(options);
|
|
122
|
+
* // Use with codec or format context
|
|
123
|
+
* await codecContext.open2(codec, dict);
|
|
124
|
+
* dict.free();
|
|
125
|
+
* ```
|
|
126
|
+
*/
|
|
127
|
+
static fromObject(obj, flags = AVFLAG_NONE) {
|
|
128
|
+
const dict = new Dictionary();
|
|
129
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
130
|
+
dict.set(key, value, flags);
|
|
131
|
+
}
|
|
132
|
+
return dict;
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Allocate a new dictionary.
|
|
136
|
+
*
|
|
137
|
+
* Usually not needed as set() will auto-allocate.
|
|
138
|
+
* This is mainly for compatibility - FFmpeg doesn't have explicit av_dict_alloc.
|
|
139
|
+
*
|
|
140
|
+
* @example
|
|
141
|
+
* ```typescript
|
|
142
|
+
* const dict = new Dictionary();
|
|
143
|
+
* dict.alloc(); // Explicit allocation (optional)
|
|
144
|
+
* ```
|
|
145
|
+
*/
|
|
146
|
+
alloc() {
|
|
147
|
+
return this.native.alloc();
|
|
148
|
+
}
|
|
149
|
+
/**
|
|
150
|
+
* Free all the memory allocated for an AVDictionary struct and all keys and values.
|
|
151
|
+
*
|
|
152
|
+
* Direct mapping to av_dict_free()
|
|
153
|
+
* After calling this, the dictionary is empty and can be reused.
|
|
154
|
+
*
|
|
155
|
+
* @example
|
|
156
|
+
* ```typescript
|
|
157
|
+
* dict.free();
|
|
158
|
+
* // Dictionary is now empty and can be reused
|
|
159
|
+
* dict.set('new_key', 'new_value', 0);
|
|
160
|
+
* ```
|
|
161
|
+
*/
|
|
162
|
+
free() {
|
|
163
|
+
return this.native.free();
|
|
164
|
+
}
|
|
165
|
+
/**
|
|
166
|
+
* Copy entries from this dictionary to destination.
|
|
167
|
+
*
|
|
168
|
+
* Copies all entries to the destination dictionary.
|
|
169
|
+
* Destination entries can be preserved or overwritten based on flags.
|
|
170
|
+
*
|
|
171
|
+
* Direct mapping to av_dict_copy()
|
|
172
|
+
*
|
|
173
|
+
* @param dst - Target dictionary to copy to
|
|
174
|
+
* @param flags - AV_DICT_* flags for the copy operation
|
|
175
|
+
*
|
|
176
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
177
|
+
* - 0: Success
|
|
178
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* import { Dictionary, FFmpegError } from 'node-av';
|
|
183
|
+
*
|
|
184
|
+
* const src = new Dictionary();
|
|
185
|
+
* src.set('key1', 'value1');
|
|
186
|
+
* src.set('key2', 'value2');
|
|
187
|
+
*
|
|
188
|
+
* const dst = new Dictionary();
|
|
189
|
+
* const ret = src.copy(dst);
|
|
190
|
+
* FFmpegError.throwIfError(ret, 'copy');
|
|
191
|
+
* ```
|
|
192
|
+
*
|
|
193
|
+
* @note Common flags:
|
|
194
|
+
* - AVFLAG_NONE: Default behavior
|
|
195
|
+
* - AV_DICT_DONT_OVERWRITE: Don't overwrite existing entries
|
|
196
|
+
* - AV_DICT_MULTIKEY: Allow multiple entries with same key
|
|
197
|
+
*/
|
|
198
|
+
copy(dst, flags = AVFLAG_NONE) {
|
|
199
|
+
return this.native.copy(dst.getNative(), flags);
|
|
200
|
+
}
|
|
201
|
+
/**
|
|
202
|
+
* Set the given entry in the dictionary.
|
|
203
|
+
*
|
|
204
|
+
* Adds or modifies a key-value pair in the dictionary.
|
|
205
|
+
* If key or value are empty, the entry is deleted.
|
|
206
|
+
* The dictionary will be auto-allocated on first call if needed.
|
|
207
|
+
*
|
|
208
|
+
* Direct mapping to av_dict_set()
|
|
209
|
+
*
|
|
210
|
+
* @param key - Entry key to add/modify
|
|
211
|
+
* @param value - Entry value to add/modify
|
|
212
|
+
* @param flags - AV_DICT_* flags
|
|
213
|
+
*
|
|
214
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
215
|
+
* - 0: Success
|
|
216
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
217
|
+
*
|
|
218
|
+
* @example
|
|
219
|
+
* ```typescript
|
|
220
|
+
* import { Dictionary, FFmpegError } from 'node-av';
|
|
221
|
+
* import { AV_DICT_DONT_OVERWRITE } from 'node-av/constants';
|
|
222
|
+
*
|
|
223
|
+
* const ret1 = dict.set('bitrate', '128k');
|
|
224
|
+
* FFmpegError.throwIfError(ret1, 'set bitrate');
|
|
225
|
+
*
|
|
226
|
+
* const ret2 = dict.set('preset', 'fast', AV_DICT_DONT_OVERWRITE);
|
|
227
|
+
* FFmpegError.throwIfError(ret2, 'set preset');
|
|
228
|
+
*
|
|
229
|
+
* // Delete an entry
|
|
230
|
+
* dict.set('bitrate', '');
|
|
231
|
+
* ```
|
|
232
|
+
*
|
|
233
|
+
* @note Common flags:
|
|
234
|
+
* - AVFLAG_NONE: Default behavior (replace existing, copy strings)
|
|
235
|
+
* - AV_DICT_DONT_OVERWRITE: Don't overwrite existing entries
|
|
236
|
+
* - AV_DICT_APPEND: Append to existing value (with comma separator)
|
|
237
|
+
* - AV_DICT_MULTIKEY: Allow multiple entries with same key
|
|
238
|
+
* - AV_DICT_MATCH_CASE: Case sensitive key matching
|
|
239
|
+
*/
|
|
240
|
+
set(key, value, flags = AVFLAG_NONE) {
|
|
241
|
+
return this.native.set(key, value, flags);
|
|
242
|
+
}
|
|
243
|
+
/**
|
|
244
|
+
* Get a dictionary entry with matching key.
|
|
245
|
+
*
|
|
246
|
+
* Direct mapping to av_dict_get()
|
|
247
|
+
*
|
|
248
|
+
* @param key - Key to search for
|
|
249
|
+
* @param flags - AV_DICT_* flags for matching
|
|
250
|
+
*
|
|
251
|
+
* @returns Entry value or null if not found
|
|
252
|
+
*
|
|
253
|
+
* @example
|
|
254
|
+
* ```typescript
|
|
255
|
+
* const value = dict.get('bitrate');
|
|
256
|
+
* if (value) {
|
|
257
|
+
* console.log(`Bitrate: ${value}`);
|
|
258
|
+
* }
|
|
259
|
+
*
|
|
260
|
+
* // Case sensitive search
|
|
261
|
+
* const title = dict.get('Title', AV_DICT_MATCH_CASE);
|
|
262
|
+
* ```
|
|
263
|
+
*
|
|
264
|
+
* Common flags:
|
|
265
|
+
* - AVFLAG_NONE: Default (case insensitive)
|
|
266
|
+
* - AV_DICT_MATCH_CASE: Case sensitive matching
|
|
267
|
+
* - AV_DICT_IGNORE_SUFFIX: Match entries starting with key
|
|
268
|
+
*/
|
|
269
|
+
get(key, flags = AVFLAG_NONE) {
|
|
270
|
+
return this.native.get(key, flags);
|
|
271
|
+
}
|
|
272
|
+
/**
|
|
273
|
+
* Get number of entries in dictionary.
|
|
274
|
+
*
|
|
275
|
+
* Direct mapping to av_dict_count()
|
|
276
|
+
*
|
|
277
|
+
* @returns Number of entries
|
|
278
|
+
*
|
|
279
|
+
* @example
|
|
280
|
+
* ```typescript
|
|
281
|
+
* const count = dict.count();
|
|
282
|
+
* console.log(`Dictionary has ${count} entries`);
|
|
283
|
+
* ```
|
|
284
|
+
*/
|
|
285
|
+
count() {
|
|
286
|
+
return this.native.count();
|
|
287
|
+
}
|
|
288
|
+
/**
|
|
289
|
+
* Get all entries as a JavaScript object.
|
|
290
|
+
*
|
|
291
|
+
* Helper method for easier access from JavaScript.
|
|
292
|
+
* Internally iterates through all entries using av_dict_get().
|
|
293
|
+
*
|
|
294
|
+
* @returns Object with all key-value pairs
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const allOptions = dict.getAll();
|
|
299
|
+
* for (const [key, value] of Object.entries(allOptions)) {
|
|
300
|
+
* console.log(`${key}: ${value}`);
|
|
301
|
+
* }
|
|
302
|
+
*
|
|
303
|
+
* // Check if dictionary is empty
|
|
304
|
+
* if (Object.keys(dict.getAll()).length === 0) {
|
|
305
|
+
* console.log('Dictionary is empty');
|
|
306
|
+
* }
|
|
307
|
+
* ```
|
|
308
|
+
*/
|
|
309
|
+
getAll() {
|
|
310
|
+
return this.native.getAll();
|
|
311
|
+
}
|
|
312
|
+
/**
|
|
313
|
+
* Parse the key/value pairs from a string.
|
|
314
|
+
*
|
|
315
|
+
* Parses a formatted string into key-value pairs.
|
|
316
|
+
* Supports both single and multi-character separators.
|
|
317
|
+
*
|
|
318
|
+
* Direct mapping to av_dict_parse_string()
|
|
319
|
+
*
|
|
320
|
+
* @param str - String to parse (e.g., "key1=value1:key2=value2")
|
|
321
|
+
* @param keyValSep - String separator between key and value (e.g., '=' or ':=')
|
|
322
|
+
* @param pairsSep - String separator between pairs (e.g., ':' or ',' or ';')
|
|
323
|
+
* @param flags - AV_DICT_* flags (default: AVFLAG_NONE)
|
|
324
|
+
*
|
|
325
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
326
|
+
* - 0: Success
|
|
327
|
+
* - AVERROR(EINVAL): Invalid parameters
|
|
328
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
329
|
+
*
|
|
330
|
+
* @example
|
|
331
|
+
* ```typescript
|
|
332
|
+
* import { Dictionary, FFmpegError } from 'node-av';
|
|
333
|
+
*
|
|
334
|
+
* // Parse codec options with single-char separators
|
|
335
|
+
* const ret = dict.parseString('bitrate=128k:preset=fast', '=', ':');
|
|
336
|
+
* FFmpegError.throwIfError(ret, 'parseString');
|
|
337
|
+
*
|
|
338
|
+
* // Parse with multi-char separators
|
|
339
|
+
* const ret2 = dict.parseString('title:=My Video;;artist:=Me', ':=', ';;');
|
|
340
|
+
* FFmpegError.throwIfError(ret2, 'parseString');
|
|
341
|
+
* ```
|
|
342
|
+
*
|
|
343
|
+
* @see {@link getString} To convert back to string
|
|
344
|
+
*/
|
|
345
|
+
parseString(str, keyValSep, pairsSep, flags = AVFLAG_NONE) {
|
|
346
|
+
return this.native.parseString(str, keyValSep, pairsSep, flags);
|
|
347
|
+
}
|
|
348
|
+
/**
|
|
349
|
+
* Get dictionary as a string.
|
|
350
|
+
*
|
|
351
|
+
* Direct mapping to av_dict_get_string()
|
|
352
|
+
*
|
|
353
|
+
* @param keyValSep - Character to separate key from value
|
|
354
|
+
* @param pairsSep - Character to separate pairs
|
|
355
|
+
*
|
|
356
|
+
* @returns String representation or null on error
|
|
357
|
+
*
|
|
358
|
+
* @example
|
|
359
|
+
* ```typescript
|
|
360
|
+
* const str = dict.getString('=', ':');
|
|
361
|
+
* console.log(str); // "key1=value1:key2=value2"
|
|
362
|
+
*
|
|
363
|
+
* // Export as comma-separated
|
|
364
|
+
* const csv = dict.getString('=', ',');
|
|
365
|
+
* console.log(csv); // "key1=value1,key2=value2"
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @see parseString() - To parse a string back to dictionary
|
|
369
|
+
*/
|
|
370
|
+
getString(keyValSep, pairsSep) {
|
|
371
|
+
return this.native.getString(keyValSep, pairsSep);
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Get the native FFmpeg AVDictionary pointer.
|
|
375
|
+
*
|
|
376
|
+
* @internal For use by other wrapper classes
|
|
377
|
+
* @returns The underlying native dictionary object
|
|
378
|
+
*/
|
|
379
|
+
getNative() {
|
|
380
|
+
return this.native;
|
|
381
|
+
}
|
|
382
|
+
/**
|
|
383
|
+
* Dispose of the dictionary.
|
|
384
|
+
*
|
|
385
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
386
|
+
* Equivalent to calling free().
|
|
387
|
+
*
|
|
388
|
+
* @example
|
|
389
|
+
* ```typescript
|
|
390
|
+
* import { Dictionary, FFmpegError } from 'node-av';
|
|
391
|
+
*
|
|
392
|
+
* {
|
|
393
|
+
* using dict = new Dictionary();
|
|
394
|
+
* const ret = dict.set('key', 'value', 0);
|
|
395
|
+
* FFmpegError.throwIfError(ret, 'set');
|
|
396
|
+
* // ... use dictionary
|
|
397
|
+
* } // Automatically freed when leaving scope
|
|
398
|
+
* ```
|
|
399
|
+
*
|
|
400
|
+
* @see {@link free} For manual cleanup
|
|
401
|
+
*/
|
|
402
|
+
[Symbol.dispose]() {
|
|
403
|
+
this.native[Symbol.dispose]();
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
//# sourceMappingURL=dictionary.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../src/lib/dictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAExC,OAAO,EAAE,WAAW,EAAmB,MAAM,gBAAgB,CAAC;AAG9D;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAgEG;AACH,MAAM,OAAO,UAAU;IACb,MAAM,CAAmB;IAEjC;;;;;;;;;;;;;;;;OAgBG;IACH;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED;;;;OAIG;IACH,MAAM,CAAC,UAAU,CAAC,MAAwB;QACxC,MAAM,IAAI,GAAG,MAAM,CAAC,MAAM,CAAC,UAAU,CAAC,SAAS,CAAe,CAAC;QAC9D,IAAY,CAAC,MAAM,GAAG,MAAM,CAAC;QAC9B,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;OA0BG;IACH,MAAM,CAAC,UAAU,CAAC,GAA2B,EAAE,QAAoB,WAAW;QAC5E,MAAM,IAAI,GAAG,IAAI,UAAU,EAAE,CAAC;QAC9B,KAAK,MAAM,CAAC,GAAG,EAAE,KAAK,CAAC,IAAI,MAAM,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,CAAC;YAC/C,IAAI,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;QAC9B,CAAC;QACD,OAAO,IAAI,CAAC;IACd,CAAC;IAED;;;;;;;;;;;OAWG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,IAAI;QACF,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,EAAE,CAAC;IAC5B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,IAAI,CAAC,GAAe,EAAE,QAAoB,WAAW;QACnD,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,SAAS,EAAE,EAAE,KAAK,CAAC,CAAC;IAClD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAsCG;IACH,GAAG,CAAC,GAAW,EAAE,KAAa,EAAE,QAAoB,WAAW;QAC7D,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,EAAE,KAAK,CAAC,CAAC;IAC5C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,GAAG,CAAC,GAAW,EAAE,QAAoB,WAAW;QAC9C,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,GAAG,EAAE,KAAK,CAAC,CAAC;IACrC,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,KAAK;QACH,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IAC7B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;OAoBG;IACH,MAAM;QACJ,OAAO,IAAI,CAAC,MAAM,CAAC,MAAM,EAAE,CAAC;IAC9B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAgCG;IACH,WAAW,CAAC,GAAW,EAAE,SAAiB,EAAE,QAAgB,EAAE,QAAoB,WAAW;QAC3F,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,GAAG,EAAE,SAAS,EAAE,QAAQ,EAAE,KAAK,CAAC,CAAC;IAClE,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,SAAS,CAAC,SAAiB,EAAE,QAAgB;QAC3C,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,EAAE,QAAQ,CAAC,CAAC;IACpD,CAAC;IAED;;;;;OAKG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;;;;;;OAmBG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
import type { NativeFFmpegError } from './native-types.js';
|
|
2
|
+
/**
|
|
3
|
+
* FFmpeg error handling.
|
|
4
|
+
*
|
|
5
|
+
* Represents FFmpeg errors with error codes and human-readable messages.
|
|
6
|
+
* Provides utilities for error checking and throwing.
|
|
7
|
+
* Essential for proper error handling in FFmpeg operations.
|
|
8
|
+
*
|
|
9
|
+
* Direct mapping to FFmpeg's error system.
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { FFmpegError } from 'node-av';
|
|
14
|
+
*
|
|
15
|
+
* // Check return codes
|
|
16
|
+
* const ret = await codecContext.sendPacket(packet);
|
|
17
|
+
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
18
|
+
*
|
|
19
|
+
* // Handle specific errors
|
|
20
|
+
* try {
|
|
21
|
+
* const openRet = await formatContext.openInput('file.mp4', null, null);
|
|
22
|
+
* FFmpegError.throwIfError(openRet, 'openInput');
|
|
23
|
+
* } catch (error) {
|
|
24
|
+
* if (error instanceof FFmpegError) {
|
|
25
|
+
* console.error(`Error code: ${error.code}`);
|
|
26
|
+
* console.error(`Message: ${error.message}`);
|
|
27
|
+
* }
|
|
28
|
+
* }
|
|
29
|
+
* ```
|
|
30
|
+
*/
|
|
31
|
+
export declare class FFmpegError extends Error {
|
|
32
|
+
private native;
|
|
33
|
+
/**
|
|
34
|
+
* Create a new FFmpegError instance.
|
|
35
|
+
*
|
|
36
|
+
* Wraps an FFmpeg error code with a JavaScript Error.
|
|
37
|
+
* Automatically retrieves the error message from FFmpeg.
|
|
38
|
+
*
|
|
39
|
+
* Direct wrapper around FFmpeg error codes.
|
|
40
|
+
*
|
|
41
|
+
* @param code - FFmpeg error code (negative number)
|
|
42
|
+
*
|
|
43
|
+
* @example
|
|
44
|
+
* ```typescript
|
|
45
|
+
* import { FFmpegError } from 'node-av';
|
|
46
|
+
* import { AVERROR_EOF } from 'node-av/constants';
|
|
47
|
+
*
|
|
48
|
+
* const error = new FFmpegError(AVERROR_EOF);
|
|
49
|
+
* console.log(error.message); // "End of file"
|
|
50
|
+
* console.log(error.code); // -541478725
|
|
51
|
+
* ```
|
|
52
|
+
*/
|
|
53
|
+
constructor(code?: number);
|
|
54
|
+
/**
|
|
55
|
+
* Put a description of the AVERROR code errnum in a string.
|
|
56
|
+
*
|
|
57
|
+
* Converts an error code to a human-readable message.
|
|
58
|
+
*
|
|
59
|
+
* Direct mapping to av_strerror()
|
|
60
|
+
*
|
|
61
|
+
* @param errnum - Error code to describe
|
|
62
|
+
*
|
|
63
|
+
* @returns Error description string
|
|
64
|
+
*
|
|
65
|
+
* @example
|
|
66
|
+
* ```typescript
|
|
67
|
+
* import { FFmpegError } from 'node-av';
|
|
68
|
+
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
|
|
69
|
+
*
|
|
70
|
+
* const message = FFmpegError.strerror(AVERROR_EAGAIN);
|
|
71
|
+
* console.log(message); // "Resource temporarily unavailable"
|
|
72
|
+
*
|
|
73
|
+
* const message2 = FFmpegError.strerror(AVERROR_EOF);
|
|
74
|
+
* console.log(message2); // "End of file"
|
|
75
|
+
* ```
|
|
76
|
+
*/
|
|
77
|
+
static strerror(errnum: number): string;
|
|
78
|
+
/**
|
|
79
|
+
* Convert a POSIX error code to FFmpeg error code.
|
|
80
|
+
*
|
|
81
|
+
* Converts standard POSIX error codes to FFmpeg's error format.
|
|
82
|
+
*
|
|
83
|
+
* Direct mapping to AVERROR() macro
|
|
84
|
+
*
|
|
85
|
+
* @param posixError - POSIX error code (positive)
|
|
86
|
+
*
|
|
87
|
+
* @returns FFmpeg error code (negative)
|
|
88
|
+
*
|
|
89
|
+
* @example
|
|
90
|
+
* ```typescript
|
|
91
|
+
* import { FFmpegError } from 'node-av';
|
|
92
|
+
* import { EAGAIN } from 'errno';
|
|
93
|
+
*
|
|
94
|
+
* const ffmpegError = FFmpegError.makeError(EAGAIN);
|
|
95
|
+
* // ffmpegError is now AVERROR(EAGAIN)
|
|
96
|
+
*
|
|
97
|
+
* if (ret === ffmpegError) {
|
|
98
|
+
* console.log('Resource temporarily unavailable');
|
|
99
|
+
* }
|
|
100
|
+
* ```
|
|
101
|
+
*/
|
|
102
|
+
static makeError(posixError: number): number;
|
|
103
|
+
/**
|
|
104
|
+
* Check if a value is an error code.
|
|
105
|
+
*
|
|
106
|
+
* @param code - Value to check
|
|
107
|
+
*
|
|
108
|
+
* @returns true if code is negative (error), false otherwise
|
|
109
|
+
*
|
|
110
|
+
* @example
|
|
111
|
+
* ```typescript
|
|
112
|
+
* const ret = await formatContext.readFrame(packet);
|
|
113
|
+
* if (FFmpegError.isFFmpegError(ret)) {
|
|
114
|
+
* console.error('Read frame failed');
|
|
115
|
+
* }
|
|
116
|
+
* ```
|
|
117
|
+
*/
|
|
118
|
+
static isFFmpegError(code: number): boolean;
|
|
119
|
+
/**
|
|
120
|
+
* Create FFmpegError from error code if it's an error.
|
|
121
|
+
*
|
|
122
|
+
* Helper method to conditionally create error objects.
|
|
123
|
+
*
|
|
124
|
+
* @param code - FFmpeg return code
|
|
125
|
+
*
|
|
126
|
+
* @returns FFmpegError if code < 0, null otherwise
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* const ret = await formatContext.openInput('video.mp4', null, null);
|
|
131
|
+
* const error = FFmpegError.fromCode(ret);
|
|
132
|
+
* if (error) {
|
|
133
|
+
* console.error(`Failed: ${error.message}`);
|
|
134
|
+
* console.error(`Code: ${error.code}`);
|
|
135
|
+
* }
|
|
136
|
+
* ```
|
|
137
|
+
*/
|
|
138
|
+
static fromCode(code: number): FFmpegError | null;
|
|
139
|
+
/**
|
|
140
|
+
* Throw FFmpegError if code indicates error.
|
|
141
|
+
*
|
|
142
|
+
* Checks return code and throws an error if negative.
|
|
143
|
+
* Essential for FFmpeg error handling pattern.
|
|
144
|
+
*
|
|
145
|
+
* @param code - FFmpeg return code
|
|
146
|
+
* @param operation - Optional operation name for better error messages
|
|
147
|
+
*
|
|
148
|
+
* @throws {FFmpegError} If code < 0
|
|
149
|
+
*
|
|
150
|
+
* @example
|
|
151
|
+
* ```typescript
|
|
152
|
+
* import { FFmpegError } from 'node-av';
|
|
153
|
+
*
|
|
154
|
+
* const ret = await codecContext.sendPacket(packet);
|
|
155
|
+
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
156
|
+
* // Continues if successful, throws if error
|
|
157
|
+
*
|
|
158
|
+
* // With operation name for better error messages
|
|
159
|
+
* const ret2 = formatContext.allocOutputContext2(null, 'mp4', 'out.mp4');
|
|
160
|
+
* FFmpegError.throwIfError(ret2, 'allocOutputContext2');
|
|
161
|
+
* // Error message: "allocOutputContext2 failed: ..."
|
|
162
|
+
* ```
|
|
163
|
+
*
|
|
164
|
+
* @see {@link fromCode} To create error without throwing
|
|
165
|
+
* @see {@link isFFmpegError} To check if value is error
|
|
166
|
+
*/
|
|
167
|
+
static throwIfError(code: number, operation?: string): void;
|
|
168
|
+
/**
|
|
169
|
+
* Check if error code matches specific error.
|
|
170
|
+
*
|
|
171
|
+
* Compares return code with specific error constant.
|
|
172
|
+
* Useful for handling different error conditions.
|
|
173
|
+
*
|
|
174
|
+
* @param code - FFmpeg return code
|
|
175
|
+
* @param errorCode - Error code to check against
|
|
176
|
+
*
|
|
177
|
+
* @returns true if codes match, false otherwise
|
|
178
|
+
*
|
|
179
|
+
* @example
|
|
180
|
+
* ```typescript
|
|
181
|
+
* import { FFmpegError } from 'node-av';
|
|
182
|
+
* import { AVERROR_EOF, AVERROR_EAGAIN } from 'node-av/constants';
|
|
183
|
+
*
|
|
184
|
+
* const ret = await codecContext.receiveFrame(frame);
|
|
185
|
+
* if (FFmpegError.is(ret, AVERROR_EOF)) {
|
|
186
|
+
* console.log('End of stream reached');
|
|
187
|
+
* } else if (FFmpegError.is(ret, AVERROR_EAGAIN)) {
|
|
188
|
+
* console.log('Need more input');
|
|
189
|
+
* }
|
|
190
|
+
* ```
|
|
191
|
+
*/
|
|
192
|
+
static is(code: number, errorCode: number): boolean;
|
|
193
|
+
/**
|
|
194
|
+
* Get error code.
|
|
195
|
+
*
|
|
196
|
+
* Direct mapping to AVERROR code
|
|
197
|
+
*
|
|
198
|
+
* FFmpeg error code (negative number).
|
|
199
|
+
*/
|
|
200
|
+
get code(): number;
|
|
201
|
+
/**
|
|
202
|
+
* Get human-readable error message.
|
|
203
|
+
*
|
|
204
|
+
* Direct mapping to av_strerror() output
|
|
205
|
+
*
|
|
206
|
+
* Error description string.
|
|
207
|
+
*/
|
|
208
|
+
get message(): string;
|
|
209
|
+
/**
|
|
210
|
+
* Get the native FFmpeg error object.
|
|
211
|
+
*
|
|
212
|
+
* @internal For use by other wrapper classes
|
|
213
|
+
* @returns The underlying native error object
|
|
214
|
+
*/
|
|
215
|
+
getNative(): NativeFFmpegError;
|
|
216
|
+
}
|