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/io-context.d.ts
CHANGED
|
@@ -1,493 +1,461 @@
|
|
|
1
1
|
import { OptionMember } from './option.js';
|
|
2
|
-
import type { AVIOFlag, AVSeekWhence } from '
|
|
2
|
+
import type { AVIOFlag, AVSeekWhence } from '../constants/constants.js';
|
|
3
3
|
import type { NativeIOContext, NativeWrapper } from './native-types.js';
|
|
4
4
|
/**
|
|
5
5
|
* I/O context for custom input/output operations.
|
|
6
6
|
*
|
|
7
|
-
* Provides
|
|
8
|
-
* from
|
|
9
|
-
*
|
|
7
|
+
* Provides an abstraction layer for all I/O operations in FFmpeg.
|
|
8
|
+
* Enables reading from and writing to various sources including files,
|
|
9
|
+
* network streams, memory buffers, and custom callbacks. Essential for
|
|
10
|
+
* implementing custom protocols or handling non-standard I/O scenarios.
|
|
10
11
|
*
|
|
11
12
|
* Direct mapping to FFmpeg's AVIOContext.
|
|
12
13
|
*
|
|
13
14
|
* @example
|
|
14
15
|
* ```typescript
|
|
15
16
|
* import { IOContext, FFmpegError } from 'node-av';
|
|
16
|
-
* import { AVIO_FLAG_READ, AVSEEK_SET } from 'node-av/constants';
|
|
17
|
+
* import { AVIO_FLAG_READ, AVIO_FLAG_WRITE, AVSEEK_SET } from 'node-av/constants';
|
|
17
18
|
*
|
|
18
|
-
* // Open
|
|
19
|
+
* // Open file for reading
|
|
19
20
|
* const io = new IOContext();
|
|
20
21
|
* const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
|
|
21
22
|
* FFmpegError.throwIfError(ret, 'open2');
|
|
22
23
|
*
|
|
23
24
|
* // Read data
|
|
24
|
-
* const
|
|
25
|
+
* const data = await io.read(4096);
|
|
26
|
+
* if (data instanceof Buffer) {
|
|
27
|
+
* console.log(`Read ${data.length} bytes`);
|
|
28
|
+
* }
|
|
25
29
|
*
|
|
26
30
|
* // Seek to position
|
|
27
|
-
* const
|
|
28
|
-
*
|
|
31
|
+
* const pos = await io.seek(1024n, AVSEEK_SET);
|
|
32
|
+
* console.log(`Seeked to position ${pos}`);
|
|
29
33
|
*
|
|
30
34
|
* // Get file size
|
|
31
|
-
* const
|
|
35
|
+
* const fileSize = await io.size();
|
|
36
|
+
* console.log(`File size: ${fileSize}`);
|
|
32
37
|
*
|
|
33
|
-
* //
|
|
38
|
+
* // Close when done
|
|
34
39
|
* await io.closep();
|
|
35
|
-
* ```
|
|
36
40
|
*
|
|
37
|
-
* @example
|
|
38
|
-
* ```typescript
|
|
39
41
|
* // Custom I/O with callbacks
|
|
40
|
-
* const
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
42
|
+
* const customIO = new IOContext();
|
|
43
|
+
* let position = 0n;
|
|
44
|
+
* const buffer = Buffer.from('Hello World');
|
|
45
|
+
*
|
|
46
|
+
* customIO.allocContextWithCallbacks(
|
|
47
|
+
* 4096, // Buffer size
|
|
48
|
+
* 0, // Read mode
|
|
49
|
+
* (size) => {
|
|
50
|
+
* // Read callback
|
|
51
|
+
* const end = Number(position) + size;
|
|
52
|
+
* const chunk = buffer.subarray(Number(position), end);
|
|
53
|
+
* position = BigInt(end);
|
|
54
|
+
* return chunk;
|
|
46
55
|
* },
|
|
47
|
-
* null,
|
|
48
|
-
* (offset, whence) => {
|
|
49
|
-
*
|
|
56
|
+
* null, // No write callback for read mode
|
|
57
|
+
* (offset, whence) => {
|
|
58
|
+
* // Seek callback
|
|
59
|
+
* if (whence === AVSEEK_SET) position = offset;
|
|
60
|
+
* else if (whence === AVSEEK_CUR) position += offset;
|
|
61
|
+
* else if (whence === AVSEEK_END) position = BigInt(buffer.length) + offset;
|
|
62
|
+
* return position;
|
|
50
63
|
* }
|
|
51
64
|
* );
|
|
52
|
-
*
|
|
53
|
-
* // Use with FormatContext
|
|
54
|
-
* const ctx = new FormatContext();
|
|
55
|
-
* ctx.allocOutputContext2(null, 'mp4', null);
|
|
56
|
-
* ctx.pb = io;
|
|
57
|
-
* const openRet = await ctx.openInput(null, null, null);
|
|
58
|
-
* FFmpegError.throwIfError(openRet, 'openInput');
|
|
59
65
|
* ```
|
|
60
66
|
*
|
|
61
|
-
* @see
|
|
67
|
+
* @see [AVIOContext](https://ffmpeg.org/doxygen/trunk/structAVIOContext.html) - FFmpeg Doxygen
|
|
68
|
+
* @see {@link FormatContext} For using with demuxing/muxing
|
|
62
69
|
*/
|
|
63
70
|
export declare class IOContext extends OptionMember<NativeIOContext> implements AsyncDisposable, NativeWrapper<NativeIOContext> {
|
|
64
|
-
/**
|
|
65
|
-
* Create a new I/O context instance.
|
|
66
|
-
*
|
|
67
|
-
* The context is uninitialized - you must call allocContext() or open2() before use.
|
|
68
|
-
* No FFmpeg resources are allocated until initialization.
|
|
69
|
-
*
|
|
70
|
-
* Direct wrapper around AVIOContext allocation.
|
|
71
|
-
*
|
|
72
|
-
* @example
|
|
73
|
-
* ```typescript
|
|
74
|
-
* import { IOContext, FFmpegError, AVIO_FLAG_READ } from 'node-av';
|
|
75
|
-
*
|
|
76
|
-
* const io = new IOContext();
|
|
77
|
-
* const ret = await io.open2('file.mp4', AVIO_FLAG_READ);
|
|
78
|
-
* FFmpegError.throwIfError(ret, 'open2');
|
|
79
|
-
* // I/O context is now ready for use
|
|
80
|
-
* ```
|
|
81
|
-
*/
|
|
82
71
|
constructor();
|
|
83
72
|
/**
|
|
84
|
-
*
|
|
73
|
+
* Find input format by short name.
|
|
85
74
|
*
|
|
86
|
-
*
|
|
87
|
-
*
|
|
75
|
+
* Creates an IOContext instance from a native binding object.
|
|
76
|
+
* Used internally for wrapping native I/O contexts.
|
|
88
77
|
*
|
|
89
|
-
* @param native - Native IOContext
|
|
78
|
+
* @param native - Native IOContext binding object
|
|
90
79
|
* @returns Wrapped IOContext instance
|
|
80
|
+
*
|
|
81
|
+
* @internal
|
|
91
82
|
*/
|
|
92
83
|
static fromNative(native: NativeIOContext): IOContext;
|
|
93
84
|
/**
|
|
94
|
-
*
|
|
85
|
+
* End of file indicator.
|
|
95
86
|
*
|
|
96
|
-
*
|
|
87
|
+
* True if end of file has been reached during reading.
|
|
97
88
|
*
|
|
98
|
-
*
|
|
89
|
+
* Direct mapping to AVIOContext->eof_reached.
|
|
99
90
|
*/
|
|
100
91
|
get eof(): boolean;
|
|
101
92
|
/**
|
|
102
|
-
* Error code
|
|
93
|
+
* Error code.
|
|
103
94
|
*
|
|
104
|
-
*
|
|
95
|
+
* Contains the last error that occurred, or 0 if no error.
|
|
105
96
|
*
|
|
106
|
-
*
|
|
97
|
+
* Direct mapping to AVIOContext->error.
|
|
107
98
|
*/
|
|
108
99
|
get error(): number;
|
|
109
100
|
/**
|
|
110
|
-
*
|
|
101
|
+
* Seekability indicator.
|
|
111
102
|
*
|
|
112
|
-
*
|
|
103
|
+
* Non-zero if the underlying resource supports seeking.
|
|
104
|
+
* Some protocols like pipes or network streams may not be seekable.
|
|
113
105
|
*
|
|
114
|
-
*
|
|
115
|
-
* @readonly
|
|
106
|
+
* Direct mapping to AVIOContext->seekable.
|
|
116
107
|
*/
|
|
117
108
|
get seekable(): number;
|
|
118
109
|
/**
|
|
119
110
|
* Maximum packet size.
|
|
120
111
|
*
|
|
121
|
-
*
|
|
112
|
+
* Used to limit packet sizes in network protocols.
|
|
113
|
+
* 0 means no limit.
|
|
122
114
|
*
|
|
123
|
-
*
|
|
115
|
+
* Direct mapping to AVIOContext->max_packet_size.
|
|
124
116
|
*/
|
|
125
117
|
get maxPacketSize(): number;
|
|
126
118
|
set maxPacketSize(value: number);
|
|
127
119
|
/**
|
|
128
|
-
*
|
|
120
|
+
* Direct mode flag.
|
|
129
121
|
*
|
|
130
|
-
*
|
|
122
|
+
* If set, the I/O context will attempt to avoid buffering.
|
|
131
123
|
*
|
|
132
|
-
*
|
|
133
|
-
* instead of going through a buffer, and avio_seek will always call
|
|
134
|
-
* the underlying seek function directly.
|
|
124
|
+
* Direct mapping to AVIOContext->direct.
|
|
135
125
|
*/
|
|
136
126
|
get direct(): number;
|
|
137
127
|
set direct(value: number);
|
|
138
128
|
/**
|
|
139
|
-
*
|
|
129
|
+
* Current position.
|
|
140
130
|
*
|
|
141
|
-
*
|
|
131
|
+
* Current byte position in the stream.
|
|
142
132
|
*
|
|
143
|
-
*
|
|
133
|
+
* Direct mapping to AVIOContext->pos.
|
|
144
134
|
*/
|
|
145
135
|
get pos(): bigint;
|
|
146
136
|
/**
|
|
147
|
-
*
|
|
137
|
+
* Internal buffer size.
|
|
148
138
|
*
|
|
149
|
-
*
|
|
139
|
+
* Size of the internal buffer used for I/O operations.
|
|
150
140
|
*
|
|
151
|
-
*
|
|
141
|
+
* Direct mapping to AVIOContext->buffer_size.
|
|
152
142
|
*/
|
|
153
143
|
get bufferSize(): number;
|
|
154
144
|
/**
|
|
155
|
-
*
|
|
145
|
+
* Write flag.
|
|
156
146
|
*
|
|
157
|
-
*
|
|
147
|
+
* True if opened for writing, false for reading.
|
|
158
148
|
*
|
|
159
|
-
*
|
|
149
|
+
* Direct mapping to AVIOContext->write_flag.
|
|
160
150
|
*/
|
|
161
151
|
get writeFlag(): boolean;
|
|
162
152
|
/**
|
|
163
|
-
*
|
|
153
|
+
* Allocate I/O context with buffer.
|
|
164
154
|
*
|
|
165
|
-
* Allocates
|
|
166
|
-
* For
|
|
155
|
+
* Allocates a basic I/O context with an internal buffer.
|
|
156
|
+
* For custom I/O, use allocContextWithCallbacks instead.
|
|
167
157
|
*
|
|
168
|
-
* Direct mapping to avio_alloc_context()
|
|
158
|
+
* Direct mapping to avio_alloc_context() without callbacks.
|
|
169
159
|
*
|
|
170
|
-
* @param bufferSize - Size of
|
|
171
|
-
* @param writeFlag - 1 for
|
|
160
|
+
* @param bufferSize - Size of internal buffer
|
|
161
|
+
* @param writeFlag - 1 for write, 0 for read
|
|
172
162
|
*
|
|
173
163
|
* @example
|
|
174
164
|
* ```typescript
|
|
175
|
-
* import { IOContext } from 'node-av';
|
|
176
|
-
*
|
|
177
165
|
* const io = new IOContext();
|
|
178
166
|
* io.allocContext(4096, 0); // 4KB buffer for reading
|
|
179
|
-
*
|
|
180
|
-
* // For writing
|
|
181
|
-
* const writeIO = new IOContext();
|
|
182
|
-
* writeIO.allocContext(8192, 1); // 8KB buffer for writing
|
|
183
167
|
* ```
|
|
184
168
|
*
|
|
185
|
-
* @see {@link allocContextWithCallbacks} For custom I/O
|
|
186
|
-
* @see {@link open2} For file I/O
|
|
169
|
+
* @see {@link allocContextWithCallbacks} For custom I/O
|
|
187
170
|
*/
|
|
188
171
|
allocContext(bufferSize: number, writeFlag: number): void;
|
|
189
172
|
/**
|
|
190
|
-
* Allocate
|
|
173
|
+
* Allocate I/O context with custom callbacks.
|
|
191
174
|
*
|
|
192
|
-
* Creates
|
|
175
|
+
* Creates an I/O context with custom read, write, and seek callbacks.
|
|
176
|
+
* Enables implementing custom protocols or data sources.
|
|
193
177
|
*
|
|
194
|
-
*
|
|
195
|
-
* return immediately. If you need async operations, buffer the data in JavaScript first.
|
|
178
|
+
* Direct mapping to avio_alloc_context() with callbacks.
|
|
196
179
|
*
|
|
197
|
-
*
|
|
198
|
-
*
|
|
199
|
-
* @param
|
|
200
|
-
* @param
|
|
201
|
-
* @param
|
|
202
|
-
* @param writeCallback - Synchronous callback for writing data. Returns bytes written or negative error code
|
|
203
|
-
* @param seekCallback - Synchronous callback for seeking. Returns new position or negative error code
|
|
180
|
+
* @param bufferSize - Size of internal buffer
|
|
181
|
+
* @param writeFlag - 1 for write mode, 0 for read mode
|
|
182
|
+
* @param readCallback - Function to read data (null for write-only)
|
|
183
|
+
* @param writeCallback - Function to write data (null for read-only)
|
|
184
|
+
* @param seekCallback - Function to seek in stream (optional)
|
|
204
185
|
*
|
|
205
186
|
* @example
|
|
206
187
|
* ```typescript
|
|
207
|
-
* import {
|
|
188
|
+
* import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END, AVSEEK_SIZE } from 'node-av/constants';
|
|
208
189
|
*
|
|
209
|
-
* const
|
|
190
|
+
* const data = Buffer.from('Custom data source');
|
|
210
191
|
* let position = 0;
|
|
211
|
-
* const buffer = Buffer.from('example data');
|
|
212
192
|
*
|
|
213
193
|
* io.allocContextWithCallbacks(
|
|
214
194
|
* 4096,
|
|
215
|
-
* 0,
|
|
195
|
+
* 0, // Read mode
|
|
216
196
|
* (size) => {
|
|
217
|
-
* // Read
|
|
218
|
-
*
|
|
197
|
+
* // Read callback
|
|
198
|
+
* if (position >= data.length) return -541; // EOF
|
|
199
|
+
* const chunk = data.subarray(position, position + size);
|
|
200
|
+
* position += chunk.length;
|
|
201
|
+
* return chunk;
|
|
219
202
|
* },
|
|
220
203
|
* null,
|
|
221
204
|
* (offset, whence) => {
|
|
222
|
-
* // Seek
|
|
205
|
+
* // Seek callback
|
|
206
|
+
* if (whence === AVSEEK_SIZE) return BigInt(data.length);
|
|
223
207
|
* if (whence === AVSEEK_SET) position = Number(offset);
|
|
224
208
|
* else if (whence === AVSEEK_CUR) position += Number(offset);
|
|
225
|
-
* else if (whence === AVSEEK_END) position =
|
|
209
|
+
* else if (whence === AVSEEK_END) position = data.length + Number(offset);
|
|
226
210
|
* return BigInt(position);
|
|
227
211
|
* }
|
|
228
212
|
* );
|
|
229
213
|
* ```
|
|
230
214
|
*
|
|
231
|
-
* @see {@link allocContext} For simple
|
|
215
|
+
* @see {@link allocContext} For simple allocation
|
|
232
216
|
*/
|
|
233
217
|
allocContextWithCallbacks(bufferSize: number, writeFlag: 0 | 1, readCallback?: ((size: number) => Buffer | null | number) | null, writeCallback?: ((buffer: Buffer) => number | void) | null, seekCallback?: ((offset: bigint, whence: number) => bigint | number) | null): void;
|
|
234
218
|
/**
|
|
235
|
-
* Free
|
|
219
|
+
* Free I/O context.
|
|
236
220
|
*
|
|
237
|
-
*
|
|
221
|
+
* Releases the I/O context and its resources.
|
|
222
|
+
* The context becomes invalid after calling this.
|
|
223
|
+
*
|
|
224
|
+
* Direct mapping to avio_context_free().
|
|
238
225
|
*
|
|
239
226
|
* @example
|
|
240
227
|
* ```typescript
|
|
241
|
-
* import { IOContext } from 'node-av';
|
|
242
|
-
*
|
|
243
228
|
* io.freeContext();
|
|
244
|
-
* //
|
|
229
|
+
* // Context is now invalid
|
|
245
230
|
* ```
|
|
246
231
|
*/
|
|
247
232
|
freeContext(): void;
|
|
248
233
|
/**
|
|
249
|
-
* Open
|
|
234
|
+
* Open resource for I/O.
|
|
250
235
|
*
|
|
251
|
-
* Opens a URL
|
|
252
|
-
* Automatically
|
|
236
|
+
* Opens a URL or file for reading or writing.
|
|
237
|
+
* Automatically selects the appropriate protocol handler.
|
|
253
238
|
*
|
|
254
|
-
* Direct mapping to avio_open2()
|
|
255
|
-
*
|
|
256
|
-
* @param url - URL to open (file://, http://, https://, etc.)
|
|
257
|
-
* @param flags - I/O flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)
|
|
239
|
+
* Direct mapping to avio_open2().
|
|
258
240
|
*
|
|
241
|
+
* @param url - URL or file path to open
|
|
242
|
+
* @param flags - Open flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)
|
|
259
243
|
* @returns 0 on success, negative AVERROR on error:
|
|
260
|
-
* -
|
|
261
|
-
* -
|
|
262
|
-
* -
|
|
263
|
-
* - AVERROR(EIO): I/O error
|
|
264
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
265
|
-
* - <0: Other protocol-specific errors
|
|
244
|
+
* - AVERROR_ENOENT: File not found
|
|
245
|
+
* - AVERROR_EACCES: Permission denied
|
|
246
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
266
247
|
*
|
|
267
248
|
* @example
|
|
268
249
|
* ```typescript
|
|
269
|
-
* import {
|
|
250
|
+
* import { FFmpegError } from 'node-av';
|
|
270
251
|
* import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';
|
|
271
252
|
*
|
|
272
|
-
* // Open
|
|
273
|
-
* const io = new IOContext();
|
|
253
|
+
* // Open for reading
|
|
274
254
|
* const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
|
|
275
255
|
* FFmpegError.throwIfError(ret, 'open2');
|
|
276
256
|
*
|
|
277
|
-
* // Open
|
|
278
|
-
* const
|
|
279
|
-
*
|
|
280
|
-
* FFmpegError.throwIfError(writeRet, 'open2');
|
|
281
|
-
*
|
|
282
|
-
* // Open network stream
|
|
283
|
-
* const streamIO = new IOContext();
|
|
284
|
-
* const streamRet = await streamIO.open2('http://example.com/stream.m3u8', AVIO_FLAG_READ);
|
|
285
|
-
* FFmpegError.throwIfError(streamRet, 'open2');
|
|
257
|
+
* // Open for writing
|
|
258
|
+
* const ret2 = await io.open2('output.mp4', AVIO_FLAG_WRITE);
|
|
259
|
+
* FFmpegError.throwIfError(ret2, 'open2');
|
|
286
260
|
* ```
|
|
287
261
|
*
|
|
288
|
-
* @see {@link closep} To close
|
|
262
|
+
* @see {@link closep} To close after use
|
|
289
263
|
*/
|
|
290
264
|
open2(url: string, flags?: AVIOFlag): Promise<number>;
|
|
291
265
|
/**
|
|
292
|
-
* Close
|
|
266
|
+
* Close I/O context.
|
|
293
267
|
*
|
|
294
|
-
*
|
|
268
|
+
* Closes the I/O context and releases associated resources.
|
|
269
|
+
* Flushes any buffered data before closing.
|
|
295
270
|
*
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
299
|
-
* - <0: Other errors
|
|
271
|
+
* Direct mapping to avio_closep().
|
|
272
|
+
*
|
|
273
|
+
* @returns 0 on success, negative AVERROR on error
|
|
300
274
|
*
|
|
301
275
|
* @example
|
|
302
276
|
* ```typescript
|
|
303
|
-
* import { FFmpegError } from 'node-av';
|
|
304
|
-
*
|
|
305
277
|
* const ret = await io.closep();
|
|
306
|
-
*
|
|
307
|
-
*
|
|
278
|
+
* if (ret < 0) {
|
|
279
|
+
* console.error('Error closing I/O context');
|
|
280
|
+
* }
|
|
308
281
|
* ```
|
|
282
|
+
*
|
|
283
|
+
* @see {@link open2} To open resources
|
|
309
284
|
*/
|
|
310
285
|
closep(): Promise<number>;
|
|
311
286
|
/**
|
|
312
|
-
* Read
|
|
287
|
+
* Read data from I/O context.
|
|
313
288
|
*
|
|
314
|
-
*
|
|
289
|
+
* Reads up to the specified number of bytes from the stream.
|
|
315
290
|
*
|
|
316
|
-
*
|
|
291
|
+
* Direct mapping to avio_read().
|
|
317
292
|
*
|
|
318
|
-
* @
|
|
319
|
-
*
|
|
293
|
+
* @param size - Maximum number of bytes to read
|
|
294
|
+
* @returns Buffer with data, or error code if negative:
|
|
320
295
|
* - AVERROR_EOF: End of file reached
|
|
321
|
-
* -
|
|
322
|
-
* - <0: Other errors
|
|
296
|
+
* - AVERROR_EIO: I/O error
|
|
323
297
|
*
|
|
324
298
|
* @example
|
|
325
299
|
* ```typescript
|
|
326
|
-
*
|
|
327
|
-
*
|
|
328
|
-
* const data = await io.read(1024);
|
|
329
|
-
* if (typeof data === 'number' && data < 0) {
|
|
330
|
-
* if (data === AVERROR_EOF) {
|
|
331
|
-
* console.log('End of file');
|
|
332
|
-
* } else {
|
|
333
|
-
* FFmpegError.throwIfError(data, 'read');
|
|
334
|
-
* }
|
|
335
|
-
* } else {
|
|
336
|
-
* // Process buffer
|
|
300
|
+
* const data = await io.read(4096);
|
|
301
|
+
* if (data instanceof Buffer) {
|
|
337
302
|
* console.log(`Read ${data.length} bytes`);
|
|
303
|
+
* } else {
|
|
304
|
+
* console.error(`Read error: ${data}`);
|
|
338
305
|
* }
|
|
339
306
|
* ```
|
|
307
|
+
*
|
|
308
|
+
* @see {@link write} For writing data
|
|
340
309
|
*/
|
|
341
310
|
read(size: number): Promise<Buffer | number>;
|
|
342
311
|
/**
|
|
343
|
-
* Write
|
|
312
|
+
* Write data to I/O context.
|
|
313
|
+
*
|
|
314
|
+
* Writes buffer data to the stream.
|
|
344
315
|
*
|
|
345
|
-
* Direct mapping to avio_write()
|
|
316
|
+
* Direct mapping to avio_write().
|
|
346
317
|
*
|
|
347
|
-
* @param buffer -
|
|
318
|
+
* @param buffer - Data to write
|
|
348
319
|
*
|
|
349
320
|
* @example
|
|
350
321
|
* ```typescript
|
|
351
|
-
*
|
|
352
|
-
*
|
|
353
|
-
* const data = Buffer.from('Hello, World!');
|
|
322
|
+
* const data = Buffer.from('Hello World');
|
|
354
323
|
* await io.write(data);
|
|
355
|
-
* // Data written successfully
|
|
356
324
|
* ```
|
|
357
325
|
*
|
|
358
|
-
* @
|
|
326
|
+
* @see {@link read} For reading data
|
|
327
|
+
* @see {@link flush} To flush buffers
|
|
359
328
|
*/
|
|
360
329
|
write(buffer: Buffer): Promise<void>;
|
|
361
330
|
/**
|
|
362
|
-
* Seek to
|
|
331
|
+
* Seek to position in stream.
|
|
363
332
|
*
|
|
364
|
-
*
|
|
333
|
+
* Changes the current position in the stream.
|
|
334
|
+
* Not all streams support seeking.
|
|
365
335
|
*
|
|
366
|
-
*
|
|
367
|
-
* @param whence - AVSEEK_SET (0), AVSEEK_CUR (1), AVSEEK_END (2), or AVSEEK_SIZE (0x10000)
|
|
336
|
+
* Direct mapping to avio_seek().
|
|
368
337
|
*
|
|
369
|
-
* @
|
|
370
|
-
*
|
|
371
|
-
*
|
|
372
|
-
* -
|
|
373
|
-
* -
|
|
338
|
+
* @param offset - Byte offset to seek to
|
|
339
|
+
* @param whence - Seek origin (AVSEEK_SET, AVSEEK_CUR, AVSEEK_END)
|
|
340
|
+
* @returns New position, or negative AVERROR on error:
|
|
341
|
+
* - AVERROR_EINVAL: Invalid arguments
|
|
342
|
+
* - AVERROR_ENOSYS: Seeking not supported
|
|
374
343
|
*
|
|
375
344
|
* @example
|
|
376
345
|
* ```typescript
|
|
377
|
-
* import {
|
|
346
|
+
* import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av/constants';
|
|
378
347
|
*
|
|
379
|
-
* // Seek to
|
|
380
|
-
* const
|
|
381
|
-
* FFmpegError.throwIfError(pos < 0n ? Number(pos) : 0, 'seek');
|
|
348
|
+
* // Seek to absolute position
|
|
349
|
+
* const pos1 = await io.seek(1024n, AVSEEK_SET);
|
|
382
350
|
*
|
|
383
|
-
* // Seek to
|
|
384
|
-
* const
|
|
385
|
-
* FFmpegError.throwIfError(endPos < 0n ? Number(endPos) : 0, 'seek');
|
|
351
|
+
* // Seek relative to current position
|
|
352
|
+
* const pos2 = await io.seek(512n, AVSEEK_CUR);
|
|
386
353
|
*
|
|
387
|
-
* //
|
|
388
|
-
* const
|
|
389
|
-
* console.log(`File size: ${size} bytes`);
|
|
354
|
+
* // Seek relative to end
|
|
355
|
+
* const pos3 = await io.seek(-1024n, AVSEEK_END);
|
|
390
356
|
* ```
|
|
357
|
+
*
|
|
358
|
+
* @see {@link tell} To get current position
|
|
359
|
+
* @see {@link skip} For relative seeking
|
|
391
360
|
*/
|
|
392
361
|
seek(offset: bigint, whence: AVSeekWhence): Promise<bigint>;
|
|
393
362
|
/**
|
|
394
|
-
* Get
|
|
363
|
+
* Get stream size.
|
|
395
364
|
*
|
|
396
|
-
*
|
|
365
|
+
* Returns the total size of the stream in bytes.
|
|
366
|
+
* Not all streams have a known size.
|
|
397
367
|
*
|
|
398
|
-
*
|
|
399
|
-
*
|
|
400
|
-
*
|
|
401
|
-
* -
|
|
368
|
+
* Direct mapping to avio_size().
|
|
369
|
+
*
|
|
370
|
+
* @returns Size in bytes, or negative AVERROR if unknown:
|
|
371
|
+
* - AVERROR_ENOSYS: Size not available
|
|
402
372
|
*
|
|
403
373
|
* @example
|
|
404
374
|
* ```typescript
|
|
405
|
-
* import { FFmpegError } from 'node-av';
|
|
406
|
-
*
|
|
407
375
|
* const size = await io.size();
|
|
408
|
-
* if (size
|
|
409
|
-
*
|
|
410
|
-
* console.error('Cannot determine file size');
|
|
376
|
+
* if (size >= 0n) {
|
|
377
|
+
* console.log(`Stream size: ${size} bytes`);
|
|
411
378
|
* } else {
|
|
412
|
-
* console.log(
|
|
379
|
+
* console.log('Stream size unknown');
|
|
413
380
|
* }
|
|
414
381
|
* ```
|
|
415
382
|
*/
|
|
416
383
|
size(): Promise<bigint>;
|
|
417
384
|
/**
|
|
418
|
-
*
|
|
385
|
+
* Flush buffered data.
|
|
386
|
+
*
|
|
387
|
+
* Forces any buffered data to be written to the underlying resource.
|
|
419
388
|
*
|
|
420
|
-
* Direct mapping to avio_flush()
|
|
389
|
+
* Direct mapping to avio_flush().
|
|
421
390
|
*
|
|
422
391
|
* @example
|
|
423
392
|
* ```typescript
|
|
424
|
-
*
|
|
425
|
-
*
|
|
426
|
-
* await io.flush();
|
|
427
|
-
* // All buffered data has been written
|
|
393
|
+
* await io.write(data);
|
|
394
|
+
* await io.flush(); // Ensure data is written
|
|
428
395
|
* ```
|
|
396
|
+
*
|
|
397
|
+
* @see {@link write} For writing data
|
|
429
398
|
*/
|
|
430
399
|
flush(): Promise<void>;
|
|
431
400
|
/**
|
|
432
|
-
* Skip
|
|
401
|
+
* Skip bytes in stream.
|
|
433
402
|
*
|
|
434
|
-
*
|
|
403
|
+
* Advances the position by the specified offset.
|
|
404
|
+
* More efficient than reading and discarding data.
|
|
435
405
|
*
|
|
436
|
-
*
|
|
406
|
+
* Direct mapping to avio_skip().
|
|
437
407
|
*
|
|
438
|
-
* @
|
|
439
|
-
*
|
|
440
|
-
* - AVERROR_EOF: End of file reached
|
|
441
|
-
* - <0: Other errors
|
|
408
|
+
* @param offset - Number of bytes to skip
|
|
409
|
+
* @returns New position after skipping
|
|
442
410
|
*
|
|
443
411
|
* @example
|
|
444
412
|
* ```typescript
|
|
445
|
-
*
|
|
446
|
-
*
|
|
447
|
-
* // Skip 1024 bytes
|
|
413
|
+
* // Skip 1024 bytes forward
|
|
448
414
|
* const newPos = await io.skip(1024n);
|
|
449
|
-
* FFmpegError.throwIfError(newPos < 0n ? Number(newPos) : 0, 'skip');
|
|
450
415
|
* console.log(`New position: ${newPos}`);
|
|
451
416
|
* ```
|
|
417
|
+
*
|
|
418
|
+
* @see {@link seek} For absolute positioning
|
|
452
419
|
*/
|
|
453
420
|
skip(offset: bigint): Promise<bigint>;
|
|
454
421
|
/**
|
|
455
|
-
* Get
|
|
422
|
+
* Get current position.
|
|
423
|
+
*
|
|
424
|
+
* Returns the current byte position in the stream.
|
|
456
425
|
*
|
|
457
|
-
* Direct mapping to avio_tell()
|
|
426
|
+
* Direct mapping to avio_tell().
|
|
458
427
|
*
|
|
459
428
|
* @returns Current position in bytes
|
|
460
429
|
*
|
|
461
430
|
* @example
|
|
462
431
|
* ```typescript
|
|
463
|
-
* import { IOContext } from 'node-av';
|
|
464
|
-
*
|
|
465
432
|
* const position = io.tell();
|
|
466
|
-
* console.log(`Current position: ${position}
|
|
433
|
+
* console.log(`Current position: ${position}`);
|
|
467
434
|
* ```
|
|
435
|
+
*
|
|
436
|
+
* @see {@link seek} To change position
|
|
468
437
|
*/
|
|
469
438
|
tell(): bigint;
|
|
470
439
|
/**
|
|
471
|
-
* Get the native
|
|
440
|
+
* Get the underlying native IOContext object.
|
|
472
441
|
*
|
|
473
|
-
* @
|
|
474
|
-
*
|
|
442
|
+
* @returns The native IOContext binding object
|
|
443
|
+
*
|
|
444
|
+
* @internal
|
|
475
445
|
*/
|
|
476
446
|
getNative(): NativeIOContext;
|
|
477
447
|
/**
|
|
478
|
-
* Dispose of the I/O context.
|
|
448
|
+
* Dispose of the I/O context asynchronously.
|
|
479
449
|
*
|
|
480
450
|
* Implements the AsyncDisposable interface for automatic cleanup.
|
|
481
|
-
*
|
|
451
|
+
* Closes the context and releases resources.
|
|
482
452
|
*
|
|
483
453
|
* @example
|
|
484
454
|
* ```typescript
|
|
485
|
-
* import { IOContext, AVIO_FLAG_READ } from 'node-av';
|
|
486
|
-
*
|
|
487
455
|
* {
|
|
488
456
|
* await using io = new IOContext();
|
|
489
|
-
* await io.open2('
|
|
490
|
-
* // ...
|
|
457
|
+
* await io.open2('input.mp4');
|
|
458
|
+
* // Use io...
|
|
491
459
|
* } // Automatically closed when leaving scope
|
|
492
460
|
* ```
|
|
493
461
|
*/
|