node-av 1.0.3 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +56 -41
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +182 -126
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +286 -130
- package/dist/api/decoder.js +321 -159
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +254 -158
- package/dist/api/encoder.js +326 -298
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +912 -0
- package/dist/api/filter-presets.js +1407 -0
- package/dist/api/filter-presets.js.map +1 -0
- package/dist/api/filter.d.ts +280 -284
- package/dist/api/filter.js +435 -509
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +226 -159
- package/dist/api/hardware.js +405 -287
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +45 -47
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +244 -141
- package/dist/api/media-input.js +207 -104
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +212 -129
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +22 -182
- package/dist/api/utilities/audio-sample.d.ts +1 -1
- package/dist/api/utilities/image.d.ts +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -1
- package/dist/api/utilities/pixel-format.d.ts +1 -1
- package/dist/api/utilities/sample-format.d.ts +1 -1
- package/dist/api/utilities/timestamp.d.ts +1 -1
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
- package/dist/constants/channel-layouts.js.map +1 -0
- package/dist/{lib → constants}/constants.d.ts +19 -4
- package/dist/{lib → constants}/constants.js +15 -1
- package/dist/constants/constants.js.map +1 -0
- package/dist/constants/decoders.d.ts +609 -0
- package/dist/constants/decoders.js +617 -0
- package/dist/constants/decoders.js.map +1 -0
- package/dist/constants/encoders.d.ts +285 -0
- package/dist/constants/encoders.js +298 -0
- package/dist/constants/encoders.js.map +1 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.js +5 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +128 -171
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.d.ts +7 -5
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +69 -55
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +317 -381
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +161 -171
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +92 -105
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +328 -217
- package/dist/lib/codec.js +392 -218
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +150 -204
- package/dist/lib/dictionary.js +159 -213
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +97 -131
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +317 -194
- package/dist/lib/filter-context.js +335 -200
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +252 -293
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +94 -112
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +321 -429
- package/dist/lib/format-context.js +314 -386
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +263 -406
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +150 -204
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +171 -181
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -3
- package/dist/lib/index.js +2 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +90 -118
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +210 -242
- package/dist/lib/io-context.js +221 -253
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +86 -120
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +127 -112
- package/dist/lib/native-types.js +9 -0
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +285 -242
- package/dist/lib/option.js +310 -250
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +78 -102
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +173 -241
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +242 -326
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +130 -174
- package/dist/lib/software-scale-context.js +132 -176
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +88 -198
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/types.d.ts +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +32 -24
- package/release_notes.md +43 -13
- package/CHANGELOG.md +0 -8
- package/dist/lib/channel-layouts.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- /package/dist/{lib → constants}/channel-layouts.js +0 -0
package/dist/lib/dictionary.js
CHANGED
|
@@ -1,127 +1,75 @@
|
|
|
1
|
+
import { AVFLAG_NONE } from '../constants/constants.js';
|
|
1
2
|
import { bindings } from './binding.js';
|
|
2
|
-
import { AVFLAG_NONE } from './constants.js';
|
|
3
3
|
/**
|
|
4
|
-
*
|
|
4
|
+
* Key-value dictionary for FFmpeg options and metadata.
|
|
5
5
|
*
|
|
6
|
-
*
|
|
7
|
-
*
|
|
8
|
-
*
|
|
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.
|
|
9
10
|
*
|
|
10
11
|
* Direct mapping to FFmpeg's AVDictionary.
|
|
11
12
|
*
|
|
12
13
|
* @example
|
|
13
14
|
* ```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
15
|
* import { Dictionary, FFmpegError } from 'node-av';
|
|
16
|
+
* import { AV_DICT_IGNORE_SUFFIX } from 'node-av/constants';
|
|
51
17
|
*
|
|
52
|
-
* //
|
|
53
|
-
* const dict =
|
|
54
|
-
*
|
|
55
|
-
*
|
|
18
|
+
* // Create from object
|
|
19
|
+
* const dict = Dictionary.fromObject({
|
|
20
|
+
* 'title': 'My Video',
|
|
21
|
+
* 'artist': 'Me',
|
|
22
|
+
* 'year': '2024'
|
|
23
|
+
* });
|
|
56
24
|
*
|
|
57
|
-
* //
|
|
58
|
-
* const
|
|
59
|
-
*
|
|
25
|
+
* // Set individual values
|
|
26
|
+
* const dict2 = new Dictionary();
|
|
27
|
+
* dict2.alloc();
|
|
28
|
+
* let ret = dict2.set('preset', 'fast');
|
|
29
|
+
* FFmpegError.throwIfError(ret, 'set');
|
|
60
30
|
*
|
|
61
|
-
* //
|
|
62
|
-
*
|
|
63
|
-
*
|
|
31
|
+
* // Parse from string
|
|
32
|
+
* ret = dict2.parseString('key1=value1:key2=value2', '=', ':');
|
|
33
|
+
* FFmpegError.throwIfError(ret, 'parseString');
|
|
64
34
|
*
|
|
65
|
-
*
|
|
35
|
+
* // Get all entries
|
|
36
|
+
* const entries = dict2.getAll();
|
|
37
|
+
* console.log(entries); // { key1: 'value1', key2: 'value2' }
|
|
66
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
|
|
67
43
|
*/
|
|
68
44
|
export class Dictionary {
|
|
69
45
|
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
46
|
constructor() {
|
|
88
47
|
this.native = new bindings.Dictionary();
|
|
89
48
|
}
|
|
90
49
|
/**
|
|
91
|
-
* Create
|
|
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.
|
|
50
|
+
* Create dictionary from JavaScript object.
|
|
102
51
|
*
|
|
103
|
-
*
|
|
104
|
-
* Useful for converting option objects to FFmpeg format.
|
|
52
|
+
* Convenience method to create a dictionary from a plain object.
|
|
105
53
|
*
|
|
106
54
|
* @param obj - Object with string key-value pairs
|
|
107
|
-
* @param flags -
|
|
108
|
-
*
|
|
109
|
-
* @returns New Dictionary containing all entries from the object
|
|
55
|
+
* @param flags - Flags for setting entries
|
|
56
|
+
* @returns New dictionary with entries from object
|
|
110
57
|
*
|
|
111
58
|
* @example
|
|
112
59
|
* ```typescript
|
|
113
|
-
*
|
|
114
|
-
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
*
|
|
121
|
-
* const
|
|
122
|
-
*
|
|
123
|
-
*
|
|
124
|
-
*
|
|
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
|
+
* });
|
|
125
73
|
* ```
|
|
126
74
|
*/
|
|
127
75
|
static fromObject(obj, flags = AVFLAG_NONE) {
|
|
@@ -132,123 +80,127 @@ export class Dictionary {
|
|
|
132
80
|
return dict;
|
|
133
81
|
}
|
|
134
82
|
/**
|
|
135
|
-
*
|
|
83
|
+
* Create dictionary from native instance.
|
|
136
84
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
85
|
+
* @param native - Native dictionary instance
|
|
86
|
+
* @returns Dictionary wrapper
|
|
87
|
+
*
|
|
88
|
+
* @internal
|
|
89
|
+
*/
|
|
90
|
+
static fromNative(native) {
|
|
91
|
+
const dict = Object.create(Dictionary.prototype);
|
|
92
|
+
dict.native = native;
|
|
93
|
+
return dict;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Allocate a dictionary.
|
|
97
|
+
*
|
|
98
|
+
* Allocates memory for the dictionary structure.
|
|
99
|
+
* Must be called before using the dictionary.
|
|
100
|
+
*
|
|
101
|
+
* Direct mapping to av_dict_alloc().
|
|
102
|
+
*
|
|
103
|
+
* @throws {Error} If allocation fails (ENOMEM)
|
|
139
104
|
*
|
|
140
105
|
* @example
|
|
141
106
|
* ```typescript
|
|
142
107
|
* const dict = new Dictionary();
|
|
143
|
-
* dict.alloc();
|
|
108
|
+
* dict.alloc();
|
|
109
|
+
* // Dictionary is now ready for use
|
|
144
110
|
* ```
|
|
111
|
+
*
|
|
112
|
+
* @see {@link free} To deallocate
|
|
145
113
|
*/
|
|
146
114
|
alloc() {
|
|
147
|
-
|
|
115
|
+
this.native.alloc();
|
|
148
116
|
}
|
|
149
117
|
/**
|
|
150
|
-
* Free
|
|
118
|
+
* Free the dictionary.
|
|
119
|
+
*
|
|
120
|
+
* Releases all memory associated with the dictionary.
|
|
121
|
+
* The dictionary becomes invalid after calling this.
|
|
151
122
|
*
|
|
152
|
-
* Direct mapping to av_dict_free()
|
|
153
|
-
* After calling this, the dictionary is empty and can be reused.
|
|
123
|
+
* Direct mapping to av_dict_free().
|
|
154
124
|
*
|
|
155
125
|
* @example
|
|
156
126
|
* ```typescript
|
|
157
127
|
* dict.free();
|
|
158
|
-
* // Dictionary is now
|
|
159
|
-
* dict.set('new_key', 'new_value', 0);
|
|
128
|
+
* // Dictionary is now invalid
|
|
160
129
|
* ```
|
|
130
|
+
*
|
|
131
|
+
* @see {@link alloc} To allocate
|
|
132
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
161
133
|
*/
|
|
162
134
|
free() {
|
|
163
|
-
|
|
135
|
+
this.native.free();
|
|
164
136
|
}
|
|
165
137
|
/**
|
|
166
|
-
* Copy entries
|
|
167
|
-
*
|
|
168
|
-
* Copies all entries to the destination dictionary.
|
|
169
|
-
* Destination entries can be preserved or overwritten based on flags.
|
|
138
|
+
* Copy entries to another dictionary.
|
|
170
139
|
*
|
|
171
|
-
*
|
|
140
|
+
* Copies all entries from this dictionary to the destination.
|
|
172
141
|
*
|
|
173
|
-
*
|
|
174
|
-
* @param flags - AV_DICT_* flags for the copy operation
|
|
142
|
+
* Direct mapping to av_dict_copy().
|
|
175
143
|
*
|
|
144
|
+
* @param dst - Destination dictionary
|
|
145
|
+
* @param flags - Copy flags
|
|
176
146
|
* @returns 0 on success, negative AVERROR on error:
|
|
177
|
-
* -
|
|
178
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
147
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
179
148
|
*
|
|
180
149
|
* @example
|
|
181
150
|
* ```typescript
|
|
182
|
-
* import {
|
|
183
|
-
*
|
|
184
|
-
* const src = new Dictionary();
|
|
185
|
-
* src.set('key1', 'value1');
|
|
186
|
-
* src.set('key2', 'value2');
|
|
151
|
+
* import { FFmpegError } from 'node-av';
|
|
187
152
|
*
|
|
188
153
|
* const dst = new Dictionary();
|
|
154
|
+
* dst.alloc();
|
|
189
155
|
* const ret = src.copy(dst);
|
|
190
156
|
* FFmpegError.throwIfError(ret, 'copy');
|
|
191
157
|
* ```
|
|
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
158
|
*/
|
|
198
159
|
copy(dst, flags = AVFLAG_NONE) {
|
|
199
160
|
return this.native.copy(dst.getNative(), flags);
|
|
200
161
|
}
|
|
201
162
|
/**
|
|
202
|
-
* Set
|
|
163
|
+
* Set a dictionary entry.
|
|
203
164
|
*
|
|
204
|
-
*
|
|
205
|
-
* If key or value are empty, the entry is deleted.
|
|
206
|
-
* The dictionary will be auto-allocated on first call if needed.
|
|
165
|
+
* Sets or updates a key-value pair in the dictionary.
|
|
207
166
|
*
|
|
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
|
|
167
|
+
* Direct mapping to av_dict_set().
|
|
213
168
|
*
|
|
169
|
+
* @param key - Entry key
|
|
170
|
+
* @param value - Entry value
|
|
171
|
+
* @param flags - Set flags (e.g., AV_DICT_DONT_OVERWRITE)
|
|
214
172
|
* @returns 0 on success, negative AVERROR on error:
|
|
215
|
-
* -
|
|
216
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
173
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
217
174
|
*
|
|
218
175
|
* @example
|
|
219
176
|
* ```typescript
|
|
220
|
-
* import {
|
|
177
|
+
* import { FFmpegError } from 'node-av';
|
|
221
178
|
* import { AV_DICT_DONT_OVERWRITE } from 'node-av/constants';
|
|
222
179
|
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
226
|
-
* const ret2 = dict.set('preset', 'fast', AV_DICT_DONT_OVERWRITE);
|
|
227
|
-
* FFmpegError.throwIfError(ret2, 'set preset');
|
|
180
|
+
* // Set or update entry
|
|
181
|
+
* let ret = dict.set('bitrate', '128k');
|
|
182
|
+
* FFmpegError.throwIfError(ret, 'set');
|
|
228
183
|
*
|
|
229
|
-
* //
|
|
230
|
-
* dict.set('
|
|
184
|
+
* // Set only if not exists
|
|
185
|
+
* ret = dict.set('preset', 'fast', AV_DICT_DONT_OVERWRITE);
|
|
186
|
+
* FFmpegError.throwIfError(ret, 'set');
|
|
231
187
|
* ```
|
|
232
188
|
*
|
|
233
|
-
* @
|
|
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
|
|
189
|
+
* @see {@link get} To retrieve values
|
|
239
190
|
*/
|
|
240
191
|
set(key, value, flags = AVFLAG_NONE) {
|
|
241
192
|
return this.native.set(key, value, flags);
|
|
242
193
|
}
|
|
243
194
|
/**
|
|
244
|
-
* Get a dictionary entry
|
|
195
|
+
* Get a dictionary entry.
|
|
245
196
|
*
|
|
246
|
-
*
|
|
197
|
+
* Retrieves the value for a given key.
|
|
247
198
|
*
|
|
248
|
-
*
|
|
249
|
-
* @param flags - AV_DICT_* flags for matching
|
|
199
|
+
* Direct mapping to av_dict_get().
|
|
250
200
|
*
|
|
251
|
-
* @
|
|
201
|
+
* @param key - Entry key to look up
|
|
202
|
+
* @param flags - Search flags (e.g., AV_DICT_IGNORE_SUFFIX)
|
|
203
|
+
* @returns Entry value, or null if not found
|
|
252
204
|
*
|
|
253
205
|
* @example
|
|
254
206
|
* ```typescript
|
|
@@ -257,22 +209,23 @@ export class Dictionary {
|
|
|
257
209
|
* console.log(`Bitrate: ${value}`);
|
|
258
210
|
* }
|
|
259
211
|
*
|
|
260
|
-
* // Case
|
|
212
|
+
* // Case-insensitive search
|
|
213
|
+
* import { AV_DICT_MATCH_CASE } from 'node-av/constants';
|
|
261
214
|
* const title = dict.get('Title', AV_DICT_MATCH_CASE);
|
|
262
215
|
* ```
|
|
263
216
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* - AV_DICT_MATCH_CASE: Case sensitive matching
|
|
267
|
-
* - AV_DICT_IGNORE_SUFFIX: Match entries starting with key
|
|
217
|
+
* @see {@link set} To set values
|
|
218
|
+
* @see {@link getAll} To get all entries
|
|
268
219
|
*/
|
|
269
220
|
get(key, flags = AVFLAG_NONE) {
|
|
270
221
|
return this.native.get(key, flags);
|
|
271
222
|
}
|
|
272
223
|
/**
|
|
273
|
-
*
|
|
224
|
+
* Count dictionary entries.
|
|
274
225
|
*
|
|
275
|
-
*
|
|
226
|
+
* Returns the number of key-value pairs in the dictionary.
|
|
227
|
+
*
|
|
228
|
+
* Direct mapping to av_dict_count().
|
|
276
229
|
*
|
|
277
230
|
* @returns Number of entries
|
|
278
231
|
*
|
|
@@ -286,95 +239,92 @@ export class Dictionary {
|
|
|
286
239
|
return this.native.count();
|
|
287
240
|
}
|
|
288
241
|
/**
|
|
289
|
-
* Get all entries
|
|
242
|
+
* Get all dictionary entries.
|
|
290
243
|
*
|
|
291
|
-
*
|
|
292
|
-
* Internally iterates through all entries using av_dict_get().
|
|
244
|
+
* Returns all key-value pairs as a JavaScript object.
|
|
293
245
|
*
|
|
294
|
-
* @returns Object with all
|
|
246
|
+
* @returns Object with all entries
|
|
295
247
|
*
|
|
296
248
|
* @example
|
|
297
249
|
* ```typescript
|
|
298
|
-
* const
|
|
299
|
-
* for (const [key, value] of Object.entries(
|
|
250
|
+
* const entries = dict.getAll();
|
|
251
|
+
* for (const [key, value] of Object.entries(entries)) {
|
|
300
252
|
* console.log(`${key}: ${value}`);
|
|
301
253
|
* }
|
|
302
|
-
*
|
|
303
|
-
* // Check if dictionary is empty
|
|
304
|
-
* if (Object.keys(dict.getAll()).length === 0) {
|
|
305
|
-
* console.log('Dictionary is empty');
|
|
306
|
-
* }
|
|
307
254
|
* ```
|
|
255
|
+
*
|
|
256
|
+
* @see {@link get} To get individual entries
|
|
308
257
|
*/
|
|
309
258
|
getAll() {
|
|
310
259
|
return this.native.getAll();
|
|
311
260
|
}
|
|
312
261
|
/**
|
|
313
|
-
* Parse
|
|
262
|
+
* Parse entries from a string.
|
|
314
263
|
*
|
|
315
|
-
* Parses a formatted string
|
|
316
|
-
*
|
|
264
|
+
* Parses key-value pairs from a formatted string and adds them
|
|
265
|
+
* to the dictionary.
|
|
317
266
|
*
|
|
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)
|
|
267
|
+
* Direct mapping to av_dict_parse_string().
|
|
324
268
|
*
|
|
269
|
+
* @param str - String to parse
|
|
270
|
+
* @param keyValSep - Separator between key and value
|
|
271
|
+
* @param pairsSep - Separator between pairs
|
|
272
|
+
* @param flags - Parse flags
|
|
325
273
|
* @returns 0 on success, negative AVERROR on error:
|
|
326
|
-
* -
|
|
327
|
-
* -
|
|
328
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
274
|
+
* - AVERROR_EINVAL: Invalid format
|
|
275
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
329
276
|
*
|
|
330
277
|
* @example
|
|
331
278
|
* ```typescript
|
|
332
|
-
* import {
|
|
279
|
+
* import { FFmpegError } from 'node-av';
|
|
333
280
|
*
|
|
334
|
-
* // Parse
|
|
335
|
-
*
|
|
281
|
+
* // Parse colon-separated pairs
|
|
282
|
+
* let ret = dict.parseString('key1=val1:key2=val2', '=', ':');
|
|
336
283
|
* FFmpegError.throwIfError(ret, 'parseString');
|
|
337
284
|
*
|
|
338
|
-
* // Parse
|
|
339
|
-
*
|
|
340
|
-
* FFmpegError.throwIfError(
|
|
285
|
+
* // Parse comma-separated pairs
|
|
286
|
+
* ret = dict.parseString('width=1920,height=1080', '=', ',');
|
|
287
|
+
* FFmpegError.throwIfError(ret, 'parseString');
|
|
341
288
|
* ```
|
|
342
289
|
*
|
|
343
|
-
* @see {@link getString} To
|
|
290
|
+
* @see {@link getString} To serialize to string
|
|
344
291
|
*/
|
|
345
292
|
parseString(str, keyValSep, pairsSep, flags = AVFLAG_NONE) {
|
|
346
293
|
return this.native.parseString(str, keyValSep, pairsSep, flags);
|
|
347
294
|
}
|
|
348
295
|
/**
|
|
349
|
-
*
|
|
296
|
+
* Convert dictionary to string.
|
|
350
297
|
*
|
|
351
|
-
*
|
|
298
|
+
* Serializes all entries to a formatted string.
|
|
352
299
|
*
|
|
353
|
-
*
|
|
354
|
-
* @param pairsSep - Character to separate pairs
|
|
300
|
+
* Direct mapping to av_dict_get_string().
|
|
355
301
|
*
|
|
356
|
-
* @
|
|
302
|
+
* @param keyValSep - Separator between key and value
|
|
303
|
+
* @param pairsSep - Separator between pairs
|
|
304
|
+
* @returns Formatted string, or null on error
|
|
357
305
|
*
|
|
358
306
|
* @example
|
|
359
307
|
* ```typescript
|
|
308
|
+
* // Serialize to colon-separated format
|
|
360
309
|
* const str = dict.getString('=', ':');
|
|
361
|
-
* console.log(str); // "key1=
|
|
310
|
+
* console.log(str); // "key1=val1:key2=val2"
|
|
362
311
|
*
|
|
363
|
-
* //
|
|
312
|
+
* // Serialize to comma-separated format
|
|
364
313
|
* const csv = dict.getString('=', ',');
|
|
365
|
-
* console.log(csv); // "key1=
|
|
314
|
+
* console.log(csv); // "key1=val1,key2=val2"
|
|
366
315
|
* ```
|
|
367
316
|
*
|
|
368
|
-
* @see parseString
|
|
317
|
+
* @see {@link parseString} To parse from string
|
|
369
318
|
*/
|
|
370
319
|
getString(keyValSep, pairsSep) {
|
|
371
320
|
return this.native.getString(keyValSep, pairsSep);
|
|
372
321
|
}
|
|
373
322
|
/**
|
|
374
|
-
* Get the native
|
|
323
|
+
* Get the underlying native Dictionary object.
|
|
375
324
|
*
|
|
376
|
-
* @
|
|
377
|
-
*
|
|
325
|
+
* @returns The native Dictionary binding object
|
|
326
|
+
*
|
|
327
|
+
* @internal
|
|
378
328
|
*/
|
|
379
329
|
getNative() {
|
|
380
330
|
return this.native;
|
|
@@ -387,17 +337,13 @@ export class Dictionary {
|
|
|
387
337
|
*
|
|
388
338
|
* @example
|
|
389
339
|
* ```typescript
|
|
390
|
-
* import { Dictionary, FFmpegError } from 'node-av';
|
|
391
|
-
*
|
|
392
340
|
* {
|
|
393
341
|
* using dict = new Dictionary();
|
|
394
|
-
*
|
|
395
|
-
*
|
|
396
|
-
* // ...
|
|
342
|
+
* dict.alloc();
|
|
343
|
+
* dict.set('key', 'value');
|
|
344
|
+
* // Use dict...
|
|
397
345
|
* } // Automatically freed when leaving scope
|
|
398
346
|
* ```
|
|
399
|
-
*
|
|
400
|
-
* @see {@link free} For manual cleanup
|
|
401
347
|
*/
|
|
402
348
|
[Symbol.dispose]() {
|
|
403
349
|
this.native[Symbol.dispose]();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../src/lib/dictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,
|
|
1
|
+
{"version":3,"file":"dictionary.js","sourceRoot":"","sources":["../../src/lib/dictionary.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAKxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAwCG;AACH,MAAM,OAAO,UAAU;IACb,MAAM,CAAmB;IAEjC;QACE,IAAI,CAAC,MAAM,GAAG,IAAI,QAAQ,CAAC,UAAU,EAAE,CAAC;IAC1C,CAAC;IAED;;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