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/audio-fifo.js
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import { bindings } from './binding.js';
|
|
2
2
|
/**
|
|
3
|
-
* Audio FIFO buffer for
|
|
3
|
+
* Audio FIFO (First-In-First-Out) buffer for managing audio samples.
|
|
4
4
|
*
|
|
5
|
-
* Provides a
|
|
6
|
-
*
|
|
7
|
-
*
|
|
5
|
+
* Provides a thread-safe buffer for audio sample data, supporting both planar and interleaved formats.
|
|
6
|
+
* Automatically handles buffer reallocation when needed. Essential for audio resampling,
|
|
7
|
+
* format conversion, and buffering operations.
|
|
8
8
|
*
|
|
9
9
|
* Direct mapping to FFmpeg's AVAudioFifo.
|
|
10
10
|
*
|
|
@@ -13,256 +13,211 @@ import { bindings } from './binding.js';
|
|
|
13
13
|
* import { AudioFifo, FFmpegError } from 'node-av';
|
|
14
14
|
* import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
15
15
|
*
|
|
16
|
-
* // Create
|
|
16
|
+
* // Create FIFO for stereo float planar audio
|
|
17
17
|
* const fifo = new AudioFifo();
|
|
18
18
|
* fifo.alloc(AV_SAMPLE_FMT_FLTP, 2, 4096);
|
|
19
19
|
*
|
|
20
|
-
* // Write samples
|
|
21
|
-
* const
|
|
22
|
-
*
|
|
20
|
+
* // Write samples
|
|
21
|
+
* const leftChannel = Buffer.alloc(1024 * 4); // 1024 float samples
|
|
22
|
+
* const rightChannel = Buffer.alloc(1024 * 4);
|
|
23
|
+
* const written = await fifo.write([leftChannel, rightChannel], 1024);
|
|
24
|
+
* FFmpegError.throwIfError(written, 'write');
|
|
23
25
|
*
|
|
24
|
-
* // Read samples
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
*
|
|
26
|
+
* // Read samples when enough available
|
|
27
|
+
* if (fifo.size >= 512) {
|
|
28
|
+
* const outLeft = Buffer.alloc(512 * 4);
|
|
29
|
+
* const outRight = Buffer.alloc(512 * 4);
|
|
30
|
+
* const read = await fifo.read([outLeft, outRight], 512);
|
|
31
|
+
* FFmpegError.throwIfError(read, 'read');
|
|
32
|
+
* }
|
|
30
33
|
*
|
|
31
34
|
* // Cleanup
|
|
32
35
|
* fifo.free();
|
|
33
36
|
* ```
|
|
37
|
+
*
|
|
38
|
+
* @see [AudioFifo](https://ffmpeg.org/doxygen/trunk/structAVAudioFifo.html) - FFmpeg Doxygen
|
|
34
39
|
*/
|
|
35
40
|
export class AudioFifo {
|
|
36
41
|
native;
|
|
37
|
-
/**
|
|
38
|
-
* Create a new audio FIFO buffer.
|
|
39
|
-
*
|
|
40
|
-
* The FIFO is uninitialized - you must call alloc() before use.
|
|
41
|
-
* No FFmpeg resources are allocated until alloc() is called.
|
|
42
|
-
*
|
|
43
|
-
* Direct wrapper around AVAudioFifo.
|
|
44
|
-
*
|
|
45
|
-
* @example
|
|
46
|
-
* ```typescript
|
|
47
|
-
* import { AudioFifo } from 'node-av';
|
|
48
|
-
* import { AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
49
|
-
*
|
|
50
|
-
* const fifo = new AudioFifo();
|
|
51
|
-
* fifo.alloc(AV_SAMPLE_FMT_S16, 2, 1024);
|
|
52
|
-
* // FIFO is now ready for use
|
|
53
|
-
* ```
|
|
54
|
-
*/
|
|
55
42
|
constructor() {
|
|
56
43
|
this.native = new bindings.AudioFifo();
|
|
57
44
|
}
|
|
58
45
|
/**
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
* Returns the number of samples currently buffered in the FIFO.
|
|
62
|
-
*
|
|
63
|
-
* Direct mapping to av_audio_fifo_size()
|
|
64
|
-
*
|
|
65
|
-
* @returns Number of samples currently in the FIFO
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import { FFmpegError } from 'node-av';
|
|
70
|
-
*
|
|
71
|
-
* if (fifo.size >= frameSize) {
|
|
72
|
-
* // Enough samples available for a full frame
|
|
73
|
-
* const ret = await fifo.read(outputBuffer, frameSize);
|
|
74
|
-
* FFmpegError.throwIfError(ret, 'read');
|
|
75
|
-
* }
|
|
76
|
-
* ```
|
|
46
|
+
* Number of samples currently in the FIFO.
|
|
77
47
|
*
|
|
78
|
-
*
|
|
48
|
+
* Direct mapping to av_audio_fifo_size().
|
|
79
49
|
*/
|
|
80
50
|
get size() {
|
|
81
51
|
return this.native.size;
|
|
82
52
|
}
|
|
83
53
|
/**
|
|
84
|
-
*
|
|
54
|
+
* Number of samples that can be written without reallocation.
|
|
85
55
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
88
|
-
* Direct mapping to av_audio_fifo_space()
|
|
89
|
-
*
|
|
90
|
-
* @returns Number of samples that can be written to the FIFO
|
|
91
|
-
*
|
|
92
|
-
* @example
|
|
93
|
-
* ```typescript
|
|
94
|
-
* import { FFmpegError } from 'node-av';
|
|
95
|
-
*
|
|
96
|
-
* if (fifo.space >= frameSize) {
|
|
97
|
-
* // Enough space for a full frame
|
|
98
|
-
* const ret = await fifo.write(inputBuffer, frameSize);
|
|
99
|
-
* FFmpegError.throwIfError(ret, 'write');
|
|
100
|
-
* }
|
|
101
|
-
* ```
|
|
102
|
-
*
|
|
103
|
-
* @readonly
|
|
56
|
+
* Direct mapping to av_audio_fifo_space().
|
|
104
57
|
*/
|
|
105
58
|
get space() {
|
|
106
59
|
return this.native.space;
|
|
107
60
|
}
|
|
108
61
|
/**
|
|
109
|
-
* Allocate an AVAudioFifo.
|
|
62
|
+
* Allocate an AVAudioFifo buffer.
|
|
110
63
|
*
|
|
111
|
-
*
|
|
64
|
+
* Creates a FIFO buffer for the specified audio format and size.
|
|
112
65
|
* The FIFO will automatically grow if more data is written than allocated.
|
|
113
66
|
*
|
|
114
|
-
* Direct mapping to av_audio_fifo_alloc()
|
|
67
|
+
* Direct mapping to av_audio_fifo_alloc().
|
|
115
68
|
*
|
|
116
69
|
* @param sampleFmt - Sample format (e.g., AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP)
|
|
117
|
-
* @param channels - Number of channels
|
|
118
|
-
* @param nbSamples - Initial
|
|
70
|
+
* @param channels - Number of audio channels
|
|
71
|
+
* @param nbSamples - Initial buffer size in samples
|
|
119
72
|
*
|
|
120
|
-
* @throws {Error}
|
|
73
|
+
* @throws {Error} If allocation fails (ENOMEM)
|
|
121
74
|
*
|
|
122
75
|
* @example
|
|
123
76
|
* ```typescript
|
|
124
77
|
* import { AudioFifo } from 'node-av';
|
|
125
|
-
* import { AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
78
|
+
* import { AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_FLTP } from 'node-av/constants';
|
|
79
|
+
*
|
|
80
|
+
* // For interleaved 16-bit stereo
|
|
81
|
+
* const fifo1 = new AudioFifo();
|
|
82
|
+
* fifo1.alloc(AV_SAMPLE_FMT_S16, 2, 4096);
|
|
126
83
|
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
84
|
+
* // For planar float 5.1 audio
|
|
85
|
+
* const fifo2 = new AudioFifo();
|
|
86
|
+
* fifo2.alloc(AV_SAMPLE_FMT_FLTP, 6, 8192);
|
|
130
87
|
* ```
|
|
131
88
|
*
|
|
132
89
|
* @see {@link realloc} To resize the FIFO
|
|
90
|
+
* @see {@link free} To release the FIFO
|
|
133
91
|
*/
|
|
134
92
|
alloc(sampleFmt, channels, nbSamples) {
|
|
135
93
|
this.native.alloc(sampleFmt, channels, nbSamples);
|
|
136
94
|
}
|
|
137
95
|
/**
|
|
138
|
-
* Free
|
|
96
|
+
* Free the FIFO buffer and all associated resources.
|
|
139
97
|
*
|
|
140
|
-
*
|
|
141
|
-
* The FIFO object becomes invalid after this call.
|
|
98
|
+
* After calling this, the FIFO is invalid and must be reallocated before use.
|
|
142
99
|
*
|
|
143
|
-
* Direct mapping to av_audio_fifo_free()
|
|
100
|
+
* Direct mapping to av_audio_fifo_free().
|
|
144
101
|
*
|
|
145
102
|
* @example
|
|
146
103
|
* ```typescript
|
|
147
104
|
* fifo.free();
|
|
148
|
-
* // FIFO is now invalid
|
|
105
|
+
* // FIFO is now invalid, must call alloc() before using again
|
|
149
106
|
* ```
|
|
107
|
+
*
|
|
108
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
109
|
+
* @see {@link alloc} To allocate
|
|
150
110
|
*/
|
|
151
111
|
free() {
|
|
152
112
|
this.native.free();
|
|
153
113
|
}
|
|
154
114
|
/**
|
|
155
|
-
* Write
|
|
115
|
+
* Write audio samples to the FIFO.
|
|
156
116
|
*
|
|
157
|
-
* Writes
|
|
158
|
-
*
|
|
117
|
+
* Writes samples to the FIFO buffer. Automatically reallocates if more space is needed.
|
|
118
|
+
* For planar formats, provide an array of buffers (one per channel).
|
|
119
|
+
* For interleaved formats, provide a single buffer.
|
|
159
120
|
*
|
|
160
|
-
* Direct mapping to av_audio_fifo_write()
|
|
121
|
+
* Direct mapping to av_audio_fifo_write().
|
|
161
122
|
*
|
|
162
|
-
* @param data - Audio buffer(s)
|
|
163
|
-
* For planar formats: array of buffers (one per channel).
|
|
164
|
-
* For interleaved formats: single buffer.
|
|
123
|
+
* @param data - Audio data buffer(s). Array for planar, single Buffer for interleaved
|
|
165
124
|
* @param nbSamples - Number of samples to write
|
|
166
125
|
*
|
|
167
|
-
* @returns Number of samples
|
|
168
|
-
* -
|
|
169
|
-
* -
|
|
170
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
126
|
+
* @returns Number of samples written, or negative AVERROR:
|
|
127
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
128
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
171
129
|
*
|
|
172
130
|
* @example
|
|
173
131
|
* ```typescript
|
|
174
132
|
* import { FFmpegError } from 'node-av';
|
|
175
133
|
*
|
|
176
|
-
* // Planar format (separate buffers per channel
|
|
177
|
-
* const
|
|
178
|
-
* const
|
|
179
|
-
* const written = await fifo.write([
|
|
134
|
+
* // Planar format (e.g., FLTP) - separate buffers per channel
|
|
135
|
+
* const leftData = Buffer.alloc(1024 * 4); // 1024 float samples
|
|
136
|
+
* const rightData = Buffer.alloc(1024 * 4);
|
|
137
|
+
* const written = await fifo.write([leftData, rightData], 1024);
|
|
180
138
|
* FFmpegError.throwIfError(written, 'write');
|
|
139
|
+
* console.log(`Wrote ${written} samples`);
|
|
181
140
|
*
|
|
182
|
-
* // Interleaved format (single buffer
|
|
183
|
-
* const
|
|
184
|
-
* const written2 = await fifo.write(
|
|
141
|
+
* // Interleaved format (e.g., S16) - single buffer
|
|
142
|
+
* const interleavedData = Buffer.alloc(1024 * 2 * 2); // 1024 stereo S16 samples
|
|
143
|
+
* const written2 = await fifo.write(interleavedData, 1024);
|
|
185
144
|
* FFmpegError.throwIfError(written2, 'write');
|
|
186
145
|
* ```
|
|
187
146
|
*
|
|
188
|
-
* @see {@link read} To
|
|
147
|
+
* @see {@link read} To retrieve samples from FIFO
|
|
148
|
+
* @see {@link space} To check available space
|
|
189
149
|
*/
|
|
190
150
|
async write(data, nbSamples) {
|
|
191
|
-
return this.native.write(data, nbSamples);
|
|
151
|
+
return await this.native.write(data, nbSamples);
|
|
192
152
|
}
|
|
193
153
|
/**
|
|
194
|
-
* Read
|
|
154
|
+
* Read and remove samples from the FIFO.
|
|
195
155
|
*
|
|
196
|
-
* Reads
|
|
197
|
-
*
|
|
156
|
+
* Reads up to the specified number of samples from the FIFO.
|
|
157
|
+
* The samples are removed from the FIFO after reading.
|
|
158
|
+
* Buffers must be pre-allocated with sufficient size.
|
|
198
159
|
*
|
|
199
|
-
* Direct mapping to av_audio_fifo_read()
|
|
160
|
+
* Direct mapping to av_audio_fifo_read().
|
|
200
161
|
*
|
|
201
|
-
* @param data -
|
|
202
|
-
*
|
|
203
|
-
* For interleaved formats: single buffer.
|
|
204
|
-
* Buffers must be pre-allocated with sufficient size.
|
|
205
|
-
* @param nbSamples - Number of samples to read
|
|
162
|
+
* @param data - Pre-allocated buffer(s) to read into. Array for planar, single Buffer for interleaved
|
|
163
|
+
* @param nbSamples - Maximum number of samples to read
|
|
206
164
|
*
|
|
207
|
-
* @returns Number of samples
|
|
208
|
-
* -
|
|
209
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
165
|
+
* @returns Number of samples read, or negative AVERROR:
|
|
166
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
210
167
|
*
|
|
211
168
|
* @example
|
|
212
169
|
* ```typescript
|
|
213
170
|
* import { FFmpegError } from 'node-av';
|
|
214
171
|
*
|
|
215
|
-
* //
|
|
216
|
-
* const
|
|
217
|
-
*
|
|
218
|
-
*
|
|
219
|
-
*
|
|
220
|
-
*
|
|
221
|
-
*
|
|
222
|
-
*
|
|
223
|
-
*
|
|
224
|
-
*
|
|
172
|
+
* // Check available samples
|
|
173
|
+
* const available = fifo.size;
|
|
174
|
+
* if (available >= 1024) {
|
|
175
|
+
* // Planar format
|
|
176
|
+
* const leftOut = Buffer.alloc(1024 * 4);
|
|
177
|
+
* const rightOut = Buffer.alloc(1024 * 4);
|
|
178
|
+
* const read = await fifo.read([leftOut, rightOut], 1024);
|
|
179
|
+
* FFmpegError.throwIfError(read, 'read');
|
|
180
|
+
* console.log(`Read ${read} samples`);
|
|
181
|
+
* }
|
|
225
182
|
* ```
|
|
226
183
|
*
|
|
227
184
|
* @see {@link peek} To read without removing
|
|
228
|
-
* @see {@link
|
|
185
|
+
* @see {@link size} To check available samples
|
|
229
186
|
*/
|
|
230
187
|
async read(data, nbSamples) {
|
|
231
|
-
return this.native.read(data, nbSamples);
|
|
188
|
+
return await this.native.read(data, nbSamples);
|
|
232
189
|
}
|
|
233
190
|
/**
|
|
234
|
-
*
|
|
191
|
+
* Read samples from the FIFO without removing them.
|
|
235
192
|
*
|
|
236
|
-
*
|
|
237
|
-
* Useful for inspecting upcoming data.
|
|
193
|
+
* Similar to read() but leaves the samples in the FIFO.
|
|
194
|
+
* Useful for inspecting upcoming data without consuming it.
|
|
238
195
|
*
|
|
239
|
-
* Direct mapping to av_audio_fifo_peek()
|
|
196
|
+
* Direct mapping to av_audio_fifo_peek().
|
|
240
197
|
*
|
|
241
|
-
* @param data -
|
|
242
|
-
*
|
|
243
|
-
* For interleaved formats: single buffer.
|
|
244
|
-
* Buffers must be pre-allocated.
|
|
245
|
-
* @param nbSamples - Number of samples to peek
|
|
198
|
+
* @param data - Pre-allocated buffer(s) to peek into. Array for planar, single Buffer for interleaved
|
|
199
|
+
* @param nbSamples - Maximum number of samples to peek
|
|
246
200
|
*
|
|
247
|
-
* @returns Number of samples
|
|
248
|
-
* -
|
|
249
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
201
|
+
* @returns Number of samples peeked, or negative AVERROR:
|
|
202
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
250
203
|
*
|
|
251
204
|
* @example
|
|
252
205
|
* ```typescript
|
|
253
206
|
* import { FFmpegError } from 'node-av';
|
|
254
207
|
*
|
|
255
208
|
* // Peek at next samples without removing them
|
|
256
|
-
* const peekBuffer = Buffer.alloc(
|
|
257
|
-
* const peeked = await fifo.peek(peekBuffer,
|
|
209
|
+
* const peekBuffer = Buffer.alloc(256 * 4);
|
|
210
|
+
* const peeked = await fifo.peek(peekBuffer, 256);
|
|
258
211
|
* FFmpegError.throwIfError(peeked, 'peek');
|
|
259
|
-
*
|
|
212
|
+
*
|
|
213
|
+
* // Samples are still in FIFO
|
|
214
|
+
* console.log(`FIFO still has ${fifo.size} samples`);
|
|
260
215
|
* ```
|
|
261
216
|
*
|
|
262
217
|
* @see {@link read} To read and remove samples
|
|
263
218
|
*/
|
|
264
219
|
async peek(data, nbSamples) {
|
|
265
|
-
return this.native.peek(data, nbSamples);
|
|
220
|
+
return await this.native.peek(data, nbSamples);
|
|
266
221
|
}
|
|
267
222
|
/**
|
|
268
223
|
* Remove samples from the FIFO without reading them.
|
|
@@ -270,58 +225,64 @@ export class AudioFifo {
|
|
|
270
225
|
* Discards the specified number of samples from the FIFO.
|
|
271
226
|
* Useful for skipping unwanted audio data.
|
|
272
227
|
*
|
|
273
|
-
* Direct mapping to av_audio_fifo_drain()
|
|
228
|
+
* Direct mapping to av_audio_fifo_drain().
|
|
274
229
|
*
|
|
275
|
-
* @param nbSamples - Number of samples to
|
|
230
|
+
* @param nbSamples - Number of samples to discard
|
|
276
231
|
*
|
|
277
232
|
* @example
|
|
278
233
|
* ```typescript
|
|
279
|
-
* // Skip
|
|
234
|
+
* // Skip 100 samples
|
|
280
235
|
* fifo.drain(100);
|
|
236
|
+
* console.log(`FIFO now has ${fifo.size} samples`);
|
|
281
237
|
* ```
|
|
238
|
+
*
|
|
239
|
+
* @see {@link reset} To remove all samples
|
|
282
240
|
*/
|
|
283
241
|
drain(nbSamples) {
|
|
284
242
|
this.native.drain(nbSamples);
|
|
285
243
|
}
|
|
286
244
|
/**
|
|
287
|
-
*
|
|
245
|
+
* Remove all samples from the FIFO.
|
|
288
246
|
*
|
|
289
|
-
* Empties
|
|
290
|
-
* The FIFO remains allocated and ready for
|
|
247
|
+
* Empties the FIFO buffer without deallocating it.
|
|
248
|
+
* The FIFO remains allocated and ready for new data.
|
|
291
249
|
*
|
|
292
|
-
* Direct mapping to av_audio_fifo_reset()
|
|
250
|
+
* Direct mapping to av_audio_fifo_reset().
|
|
293
251
|
*
|
|
294
252
|
* @example
|
|
295
253
|
* ```typescript
|
|
296
254
|
* fifo.reset();
|
|
297
|
-
* //
|
|
255
|
+
* console.log(fifo.size); // 0
|
|
256
|
+
* console.log(fifo.space); // Original allocation size
|
|
298
257
|
* ```
|
|
258
|
+
*
|
|
259
|
+
* @see {@link drain} To remove specific number of samples
|
|
299
260
|
*/
|
|
300
261
|
reset() {
|
|
301
262
|
this.native.reset();
|
|
302
263
|
}
|
|
303
264
|
/**
|
|
304
|
-
*
|
|
265
|
+
* Resize the FIFO buffer.
|
|
305
266
|
*
|
|
306
|
-
* Changes the size of the FIFO buffer.
|
|
307
|
-
*
|
|
267
|
+
* Changes the allocated size of the FIFO. Can grow or shrink the buffer.
|
|
268
|
+
* Existing samples are preserved up to the new size.
|
|
308
269
|
*
|
|
309
|
-
* Direct mapping to av_audio_fifo_realloc()
|
|
270
|
+
* Direct mapping to av_audio_fifo_realloc().
|
|
310
271
|
*
|
|
311
|
-
* @param nbSamples - New allocation size
|
|
272
|
+
* @param nbSamples - New allocation size in samples
|
|
312
273
|
*
|
|
313
274
|
* @returns 0 on success, negative AVERROR on error:
|
|
314
|
-
* -
|
|
315
|
-
* -
|
|
316
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
275
|
+
* - AVERROR_EINVAL: Invalid size
|
|
276
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
317
277
|
*
|
|
318
278
|
* @example
|
|
319
279
|
* ```typescript
|
|
320
280
|
* import { FFmpegError } from 'node-av';
|
|
321
281
|
*
|
|
322
|
-
* //
|
|
323
|
-
* const ret = fifo.realloc(
|
|
282
|
+
* // Grow FIFO to handle larger buffers
|
|
283
|
+
* const ret = fifo.realloc(16384);
|
|
324
284
|
* FFmpegError.throwIfError(ret, 'realloc');
|
|
285
|
+
* console.log(`New space: ${fifo.space} samples`);
|
|
325
286
|
* ```
|
|
326
287
|
*
|
|
327
288
|
* @see {@link alloc} For initial allocation
|
|
@@ -330,10 +291,11 @@ export class AudioFifo {
|
|
|
330
291
|
return this.native.realloc(nbSamples);
|
|
331
292
|
}
|
|
332
293
|
/**
|
|
333
|
-
* Get the native
|
|
294
|
+
* Get the underlying native AudioFifo object.
|
|
295
|
+
*
|
|
296
|
+
* @returns The native AudioFifo binding object
|
|
334
297
|
*
|
|
335
|
-
* @internal
|
|
336
|
-
* @returns The underlying native AudioFifo object
|
|
298
|
+
* @internal
|
|
337
299
|
*/
|
|
338
300
|
getNative() {
|
|
339
301
|
return this.native;
|
|
@@ -346,17 +308,12 @@ export class AudioFifo {
|
|
|
346
308
|
*
|
|
347
309
|
* @example
|
|
348
310
|
* ```typescript
|
|
349
|
-
* import { AudioFifo } from 'node-av';
|
|
350
|
-
* import { AV_SAMPLE_FMT_S16 } from 'node-av/constants';
|
|
351
|
-
*
|
|
352
311
|
* {
|
|
353
312
|
* using fifo = new AudioFifo();
|
|
354
|
-
* fifo.alloc(
|
|
355
|
-
* // ...
|
|
313
|
+
* fifo.alloc(AV_SAMPLE_FMT_FLTP, 2, 4096);
|
|
314
|
+
* // Use fifo...
|
|
356
315
|
* } // Automatically freed when leaving scope
|
|
357
316
|
* ```
|
|
358
|
-
*
|
|
359
|
-
* @see {@link free} For manual cleanup
|
|
360
317
|
*/
|
|
361
318
|
[Symbol.dispose]() {
|
|
362
319
|
this.native[Symbol.dispose]();
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"audio-fifo.js","sourceRoot":"","sources":["../../src/lib/audio-fifo.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAKxC
|
|
1
|
+
{"version":3,"file":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I,CAAC,IAAuB,EAAE,SAAiB;QACnD,OAAO,MAAM,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,IAAI,EAAE,SAAS,CAAC,CAAC;IACjD,CAAC;IAED;;;;;;;;;;;;;;;;;;OAkBG;IACH,KAAK,CAAC,SAAiB;QACrB,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC,SAAS,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;OAgBG;IACH,KAAK;QACH,IAAI,CAAC,MAAM,CAAC,KAAK,EAAE,CAAC;IACtB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,OAAO,CAAC,SAAiB;QACvB,OAAO,IAAI,CAAC,MAAM,CAAC,OAAO,CAAC,SAAS,CAAC,CAAC;IACxC,CAAC;IAED;;;;;;OAMG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,CAAC;CACF"}
|
package/dist/lib/binding.d.ts
CHANGED
|
@@ -4,7 +4,9 @@
|
|
|
4
4
|
* This module loads the native C++ bindings compiled by node-gyp.
|
|
5
5
|
* All native classes are accessed through this single entry point.
|
|
6
6
|
*/
|
|
7
|
-
import type { AVError, AVHWDeviceType, AVLogLevel, AVMediaType, AVOptionSearchFlags, AVPixelFormat, AVSampleFormat } from '
|
|
7
|
+
import type { AVCodecID, AVError, AVHWDeviceType, AVLogLevel, AVMediaType, AVOptionSearchFlags, AVPixelFormat, AVSampleFormat } from '../constants/constants.js';
|
|
8
|
+
import type { FFDecoderCodec } from '../constants/decoders.js';
|
|
9
|
+
import type { FFEncoderCodec } from '../constants/encoders.js';
|
|
8
10
|
import type { PosixError } from './error.js';
|
|
9
11
|
import type { NativeAudioFifo, NativeBitStreamFilter, NativeBitStreamFilterContext, NativeCodec, NativeCodecContext, NativeCodecParameters, NativeCodecParser, NativeDictionary, NativeFFmpegError, NativeFilter, NativeFilterContext, NativeFilterGraph, NativeFilterInOut, NativeFormatContext, NativeFrame, NativeHardwareDeviceContext, NativeHardwareFramesContext, NativeInputFormat, NativeIOContext, NativeLog, NativeOption, NativeOutputFormat, NativePacket, NativeSoftwareResampleContext, NativeSoftwareScaleContext, NativeStream } from './native-types.js';
|
|
10
12
|
import type { ChannelLayout, IRational } from './types.js';
|
|
@@ -12,10 +14,10 @@ type NativePacketConstructor = new () => NativePacket;
|
|
|
12
14
|
type NativeFrameConstructor = new () => NativeFrame;
|
|
13
15
|
interface NativeCodecConstructor {
|
|
14
16
|
new (): NativeCodec;
|
|
15
|
-
findDecoder(id:
|
|
16
|
-
findEncoder(id:
|
|
17
|
-
findDecoderByName(name:
|
|
18
|
-
findEncoderByName(name:
|
|
17
|
+
findDecoder(id: AVCodecID): NativeCodec | null;
|
|
18
|
+
findEncoder(id: AVCodecID): NativeCodec | null;
|
|
19
|
+
findDecoderByName(name: FFDecoderCodec): NativeCodec | null;
|
|
20
|
+
findEncoderByName(name: FFEncoderCodec): NativeCodec | null;
|
|
19
21
|
getCodecList(): NativeCodec[];
|
|
20
22
|
iterateCodecs(opaque?: bigint | null): {
|
|
21
23
|
codec: NativeCodec;
|
package/dist/lib/binding.js
CHANGED
|
@@ -10,6 +10,11 @@ import { dirname, resolve } from 'node:path';
|
|
|
10
10
|
import { fileURLToPath } from 'node:url';
|
|
11
11
|
const __filename = fileURLToPath(import.meta.url);
|
|
12
12
|
const __dirname = dirname(__filename);
|
|
13
|
+
/**
|
|
14
|
+
* Load the native binding
|
|
15
|
+
*
|
|
16
|
+
* @returns The loaded native binding interface
|
|
17
|
+
*/
|
|
13
18
|
function loadBinding() {
|
|
14
19
|
const require = createRequire(import.meta.url);
|
|
15
20
|
const errors = [];
|
package/dist/lib/binding.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/lib/binding.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;
|
|
1
|
+
{"version":3,"file":"binding.js","sourceRoot":"","sources":["../../src/lib/binding.ts"],"names":[],"mappings":"AAAA;;;;;GAKG;AAEH,OAAO,EAAE,UAAU,EAAE,MAAM,SAAS,CAAC;AACrC,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AAC7C,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AAoCzC,MAAM,UAAU,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;AAClD,MAAM,SAAS,GAAG,OAAO,CAAC,UAAU,CAAC,CAAC;AA+OtC;;;;GAIG;AACH,SAAS,WAAW;IAClB,MAAM,OAAO,GAAG,aAAa,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,CAAC,CAAC;IAC/C,MAAM,MAAM,GAAY,EAAE,CAAC;IAE3B,kBAAkB;IAClB,MAAM,QAAQ,GAAG,OAAO,CAAC,QAAQ,CAAC;IAClC,MAAM,IAAI,GAAG,OAAO,CAAC,IAAI,CAAC;IAC1B,MAAM,YAAY,GAAG,GAAG,QAAQ,IAAI,IAAI,EAAE,CAAC;IAE3C,8CAA8C;IAC9C,IAAI,CAAC;QACH,MAAM,WAAW,GAAG,OAAO,CAAC,SAAS,EAAE,IAAI,EAAE,IAAI,EAAE,OAAO,EAAE,SAAS,EAAE,cAAc,CAAC,CAAC;QACvF,MAAM,UAAU,GAAG,OAAO,CAAC,SAAS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