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,550 @@
|
|
|
1
|
+
import { bindings } from './binding.js';
|
|
2
|
+
import { AVIO_FLAG_READ } from './constants.js';
|
|
3
|
+
import { OptionMember } from './option.js';
|
|
4
|
+
/**
|
|
5
|
+
* I/O context for custom input/output operations.
|
|
6
|
+
*
|
|
7
|
+
* Provides buffered I/O and protocol handling for reading/writing data
|
|
8
|
+
* from/to files, network streams, memory buffers, or custom sources.
|
|
9
|
+
* Can be used with FormatContext for custom I/O or standalone for direct I/O operations.
|
|
10
|
+
*
|
|
11
|
+
* Direct mapping to FFmpeg's AVIOContext.
|
|
12
|
+
*
|
|
13
|
+
* @example
|
|
14
|
+
* ```typescript
|
|
15
|
+
* import { IOContext, FFmpegError } from 'node-av';
|
|
16
|
+
* import { AVIO_FLAG_READ, AVSEEK_SET } from 'node-av/constants';
|
|
17
|
+
*
|
|
18
|
+
* // Open a file for reading
|
|
19
|
+
* const io = new IOContext();
|
|
20
|
+
* const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
|
|
21
|
+
* FFmpegError.throwIfError(ret, 'open2');
|
|
22
|
+
*
|
|
23
|
+
* // Read data
|
|
24
|
+
* const buffer = await io.read(4096);
|
|
25
|
+
*
|
|
26
|
+
* // Seek to position
|
|
27
|
+
* const seekRet = await io.seek(1024n, AVSEEK_SET);
|
|
28
|
+
* FFmpegError.throwIfError(seekRet < 0 ? -1 : 0, 'seek');
|
|
29
|
+
*
|
|
30
|
+
* // Get file size
|
|
31
|
+
* const size = await io.size();
|
|
32
|
+
*
|
|
33
|
+
* // Clean up
|
|
34
|
+
* await io.closep();
|
|
35
|
+
* ```
|
|
36
|
+
*
|
|
37
|
+
* @example
|
|
38
|
+
* ```typescript
|
|
39
|
+
* // Custom I/O with callbacks
|
|
40
|
+
* const io = new IOContext();
|
|
41
|
+
* io.allocContextWithCallbacks(
|
|
42
|
+
* 4096, // buffer size
|
|
43
|
+
* 0, // read mode
|
|
44
|
+
* (size) => { // custom read function
|
|
45
|
+
* return myBuffer.slice(pos, pos + size);
|
|
46
|
+
* },
|
|
47
|
+
* null, // no write
|
|
48
|
+
* (offset, whence) => { // custom seek function
|
|
49
|
+
* return BigInt(calculateNewPosition(offset, whence));
|
|
50
|
+
* }
|
|
51
|
+
* );
|
|
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
|
+
* ```
|
|
60
|
+
*
|
|
61
|
+
* @see {@link FormatContext} For using custom I/O with containers
|
|
62
|
+
*/
|
|
63
|
+
export class IOContext extends OptionMember {
|
|
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
|
+
constructor() {
|
|
83
|
+
super(new bindings.IOContext());
|
|
84
|
+
}
|
|
85
|
+
/**
|
|
86
|
+
* Create an IOContext wrapper from a native IOContext.
|
|
87
|
+
*
|
|
88
|
+
* Used internally when getting IOContext from other objects.
|
|
89
|
+
* @internal
|
|
90
|
+
*
|
|
91
|
+
* @param native - Native IOContext to wrap
|
|
92
|
+
* @returns Wrapped IOContext instance
|
|
93
|
+
*/
|
|
94
|
+
static fromNative(native) {
|
|
95
|
+
const io = Object.create(IOContext.prototype);
|
|
96
|
+
io.native = native;
|
|
97
|
+
return io;
|
|
98
|
+
}
|
|
99
|
+
/**
|
|
100
|
+
* Check if end of file reached.
|
|
101
|
+
*
|
|
102
|
+
* Direct mapping to avio_feof()
|
|
103
|
+
*
|
|
104
|
+
* @readonly
|
|
105
|
+
*/
|
|
106
|
+
get eof() {
|
|
107
|
+
return this.native.eof;
|
|
108
|
+
}
|
|
109
|
+
/**
|
|
110
|
+
* Error code if any.
|
|
111
|
+
*
|
|
112
|
+
* Direct mapping to AVIOContext->error
|
|
113
|
+
*
|
|
114
|
+
* @readonly
|
|
115
|
+
*/
|
|
116
|
+
get error() {
|
|
117
|
+
return this.native.error;
|
|
118
|
+
}
|
|
119
|
+
/**
|
|
120
|
+
* Whether seeking is possible.
|
|
121
|
+
*
|
|
122
|
+
* Direct mapping to AVIOContext->seekable
|
|
123
|
+
*
|
|
124
|
+
* Bitmask of AVIO_SEEKABLE_* flags.
|
|
125
|
+
* @readonly
|
|
126
|
+
*/
|
|
127
|
+
get seekable() {
|
|
128
|
+
return this.native.seekable;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Maximum packet size.
|
|
132
|
+
*
|
|
133
|
+
* Direct mapping to AVIOContext->max_packet_size
|
|
134
|
+
*
|
|
135
|
+
* If non-zero, indicates the maximum packet size.
|
|
136
|
+
*/
|
|
137
|
+
get maxPacketSize() {
|
|
138
|
+
return this.native.maxPacketSize;
|
|
139
|
+
}
|
|
140
|
+
set maxPacketSize(value) {
|
|
141
|
+
this.native.maxPacketSize = value;
|
|
142
|
+
}
|
|
143
|
+
/**
|
|
144
|
+
* Whether direct mode is enabled.
|
|
145
|
+
*
|
|
146
|
+
* Direct mapping to AVIOContext->direct
|
|
147
|
+
*
|
|
148
|
+
* avio_read and avio_write should if possible be satisfied directly
|
|
149
|
+
* instead of going through a buffer, and avio_seek will always call
|
|
150
|
+
* the underlying seek function directly.
|
|
151
|
+
*/
|
|
152
|
+
get direct() {
|
|
153
|
+
return this.native.direct;
|
|
154
|
+
}
|
|
155
|
+
set direct(value) {
|
|
156
|
+
this.native.direct = value;
|
|
157
|
+
}
|
|
158
|
+
/**
|
|
159
|
+
* Get current position in the file.
|
|
160
|
+
*
|
|
161
|
+
* Direct mapping to AVIOContext->pos
|
|
162
|
+
*
|
|
163
|
+
* @readonly
|
|
164
|
+
*/
|
|
165
|
+
get pos() {
|
|
166
|
+
return this.native.pos;
|
|
167
|
+
}
|
|
168
|
+
/**
|
|
169
|
+
* Get buffer size.
|
|
170
|
+
*
|
|
171
|
+
* Direct mapping to AVIOContext->buffer_size
|
|
172
|
+
*
|
|
173
|
+
* @readonly
|
|
174
|
+
*/
|
|
175
|
+
get bufferSize() {
|
|
176
|
+
return this.native.bufferSize;
|
|
177
|
+
}
|
|
178
|
+
/**
|
|
179
|
+
* Check if opened for writing.
|
|
180
|
+
*
|
|
181
|
+
* Direct mapping to AVIOContext->write_flag
|
|
182
|
+
*
|
|
183
|
+
* @readonly
|
|
184
|
+
*/
|
|
185
|
+
get writeFlag() {
|
|
186
|
+
return this.native.writeFlag;
|
|
187
|
+
}
|
|
188
|
+
/**
|
|
189
|
+
* Create and initialize a buffered I/O context.
|
|
190
|
+
*
|
|
191
|
+
* Allocates an I/O context with an internal buffer for efficient I/O operations.
|
|
192
|
+
* For file I/O, use open2() instead which handles allocation automatically.
|
|
193
|
+
*
|
|
194
|
+
* Direct mapping to avio_alloc_context()
|
|
195
|
+
*
|
|
196
|
+
* @param bufferSize - Size of the internal buffer in bytes
|
|
197
|
+
* @param writeFlag - 1 for writing, 0 for reading
|
|
198
|
+
*
|
|
199
|
+
* @example
|
|
200
|
+
* ```typescript
|
|
201
|
+
* import { IOContext } from 'node-av';
|
|
202
|
+
*
|
|
203
|
+
* const io = new IOContext();
|
|
204
|
+
* io.allocContext(4096, 0); // 4KB buffer for reading
|
|
205
|
+
*
|
|
206
|
+
* // For writing
|
|
207
|
+
* const writeIO = new IOContext();
|
|
208
|
+
* writeIO.allocContext(8192, 1); // 8KB buffer for writing
|
|
209
|
+
* ```
|
|
210
|
+
*
|
|
211
|
+
* @see {@link allocContextWithCallbacks} For custom I/O callbacks
|
|
212
|
+
* @see {@link open2} For file I/O
|
|
213
|
+
*/
|
|
214
|
+
allocContext(bufferSize, writeFlag) {
|
|
215
|
+
return this.native.allocContext(bufferSize, writeFlag);
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Allocate an AVIOContext with custom callbacks.
|
|
219
|
+
*
|
|
220
|
+
* Creates a custom I/O context with JavaScript callbacks for read, write, and seek operations.
|
|
221
|
+
*
|
|
222
|
+
* IMPORTANT: Callbacks must be synchronous! They are called from FFmpeg's thread and must
|
|
223
|
+
* return immediately. If you need async operations, buffer the data in JavaScript first.
|
|
224
|
+
*
|
|
225
|
+
* Direct mapping to avio_alloc_context() with custom callbacks
|
|
226
|
+
*
|
|
227
|
+
* @param bufferSize - Size of the buffer in bytes
|
|
228
|
+
* @param writeFlag - 0 for read, 1 for write
|
|
229
|
+
* @param readCallback - Synchronous callback for reading data. Returns Buffer, null for EOF, or negative error code
|
|
230
|
+
* @param writeCallback - Synchronous callback for writing data. Returns bytes written or negative error code
|
|
231
|
+
* @param seekCallback - Synchronous callback for seeking. Returns new position or negative error code
|
|
232
|
+
*
|
|
233
|
+
* @example
|
|
234
|
+
* ```typescript
|
|
235
|
+
* import { IOContext, AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av';
|
|
236
|
+
*
|
|
237
|
+
* const io = new IOContext();
|
|
238
|
+
* let position = 0;
|
|
239
|
+
* const buffer = Buffer.from('example data');
|
|
240
|
+
*
|
|
241
|
+
* io.allocContextWithCallbacks(
|
|
242
|
+
* 4096,
|
|
243
|
+
* 0,
|
|
244
|
+
* (size) => {
|
|
245
|
+
* // Read up to 'size' bytes - MUST BE SYNCHRONOUS
|
|
246
|
+
* return buffer.slice(position, position + size);
|
|
247
|
+
* },
|
|
248
|
+
* null,
|
|
249
|
+
* (offset, whence) => {
|
|
250
|
+
* // Seek to position - MUST BE SYNCHRONOUS
|
|
251
|
+
* if (whence === AVSEEK_SET) position = Number(offset);
|
|
252
|
+
* else if (whence === AVSEEK_CUR) position += Number(offset);
|
|
253
|
+
* else if (whence === AVSEEK_END) position = buffer.length + Number(offset);
|
|
254
|
+
* return BigInt(position);
|
|
255
|
+
* }
|
|
256
|
+
* );
|
|
257
|
+
* ```
|
|
258
|
+
*
|
|
259
|
+
* @see {@link allocContext} For simple buffer allocation
|
|
260
|
+
*/
|
|
261
|
+
allocContextWithCallbacks(bufferSize, writeFlag, readCallback, writeCallback, seekCallback) {
|
|
262
|
+
return this.native.allocContextWithCallbacks(bufferSize, writeFlag, readCallback ?? undefined, writeCallback ?? undefined, seekCallback ?? undefined);
|
|
263
|
+
}
|
|
264
|
+
/**
|
|
265
|
+
* Free the AVIOContext.
|
|
266
|
+
*
|
|
267
|
+
* Direct mapping to avio_context_free()
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* import { IOContext } from 'node-av';
|
|
272
|
+
*
|
|
273
|
+
* io.freeContext();
|
|
274
|
+
* // io is now invalid and should not be used
|
|
275
|
+
* ```
|
|
276
|
+
*/
|
|
277
|
+
freeContext() {
|
|
278
|
+
return this.native.freeContext();
|
|
279
|
+
}
|
|
280
|
+
/**
|
|
281
|
+
* Open a resource for reading or writing.
|
|
282
|
+
*
|
|
283
|
+
* Opens a URL using the appropriate protocol handler (file, http, etc.).
|
|
284
|
+
* Automatically allocates and initializes the I/O context.
|
|
285
|
+
*
|
|
286
|
+
* Direct mapping to avio_open2()
|
|
287
|
+
*
|
|
288
|
+
* @param url - URL to open (file://, http://, https://, etc.)
|
|
289
|
+
* @param flags - I/O flags (AVIO_FLAG_READ, AVIO_FLAG_WRITE, etc.)
|
|
290
|
+
*
|
|
291
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
292
|
+
* - 0: Success
|
|
293
|
+
* - AVERROR(ENOENT): File not found
|
|
294
|
+
* - AVERROR(EACCES): Permission denied
|
|
295
|
+
* - AVERROR(EIO): I/O error
|
|
296
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
297
|
+
* - <0: Other protocol-specific errors
|
|
298
|
+
*
|
|
299
|
+
* @example
|
|
300
|
+
* ```typescript
|
|
301
|
+
* import { IOContext, FFmpegError } from 'node-av';
|
|
302
|
+
* import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';
|
|
303
|
+
*
|
|
304
|
+
* // Open file for reading
|
|
305
|
+
* const io = new IOContext();
|
|
306
|
+
* const ret = await io.open2('input.mp4', AVIO_FLAG_READ);
|
|
307
|
+
* FFmpegError.throwIfError(ret, 'open2');
|
|
308
|
+
*
|
|
309
|
+
* // Open file for writing
|
|
310
|
+
* const writeIO = new IOContext();
|
|
311
|
+
* const writeRet = await writeIO.open2('output.mp4', AVIO_FLAG_WRITE);
|
|
312
|
+
* FFmpegError.throwIfError(writeRet, 'open2');
|
|
313
|
+
*
|
|
314
|
+
* // Open network stream
|
|
315
|
+
* const streamIO = new IOContext();
|
|
316
|
+
* const streamRet = await streamIO.open2('http://example.com/stream.m3u8', AVIO_FLAG_READ);
|
|
317
|
+
* FFmpegError.throwIfError(streamRet, 'open2');
|
|
318
|
+
* ```
|
|
319
|
+
*
|
|
320
|
+
* @see {@link closep} To close and free resources
|
|
321
|
+
*/
|
|
322
|
+
async open2(url, flags = AVIO_FLAG_READ) {
|
|
323
|
+
return this.native.open2(url, flags);
|
|
324
|
+
}
|
|
325
|
+
/**
|
|
326
|
+
* Close the resource and free the AVIOContext.
|
|
327
|
+
*
|
|
328
|
+
* Direct mapping to avio_closep()
|
|
329
|
+
*
|
|
330
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
331
|
+
* - 0: Success
|
|
332
|
+
* - AVERROR(EIO): I/O error during close
|
|
333
|
+
* - <0: Other errors
|
|
334
|
+
*
|
|
335
|
+
* @example
|
|
336
|
+
* ```typescript
|
|
337
|
+
* import { FFmpegError } from 'node-av';
|
|
338
|
+
*
|
|
339
|
+
* const ret = await io.closep();
|
|
340
|
+
* FFmpegError.throwIfError(ret, 'closep');
|
|
341
|
+
* // I/O context is now closed and freed
|
|
342
|
+
* ```
|
|
343
|
+
*/
|
|
344
|
+
async closep() {
|
|
345
|
+
return this.native.closep();
|
|
346
|
+
}
|
|
347
|
+
/**
|
|
348
|
+
* Read size bytes from AVIOContext.
|
|
349
|
+
*
|
|
350
|
+
* Direct mapping to avio_read()
|
|
351
|
+
*
|
|
352
|
+
* @param size - Number of bytes to read
|
|
353
|
+
*
|
|
354
|
+
* @returns Buffer with data or error code if negative:
|
|
355
|
+
* - Buffer: Successfully read data
|
|
356
|
+
* - AVERROR_EOF: End of file reached
|
|
357
|
+
* - AVERROR(EIO): I/O error
|
|
358
|
+
* - <0: Other errors
|
|
359
|
+
*
|
|
360
|
+
* @example
|
|
361
|
+
* ```typescript
|
|
362
|
+
* import { FFmpegError, AVERROR_EOF } from 'node-av';
|
|
363
|
+
*
|
|
364
|
+
* const data = await io.read(1024);
|
|
365
|
+
* if (typeof data === 'number' && data < 0) {
|
|
366
|
+
* if (data === AVERROR_EOF) {
|
|
367
|
+
* console.log('End of file');
|
|
368
|
+
* } else {
|
|
369
|
+
* FFmpegError.throwIfError(data, 'read');
|
|
370
|
+
* }
|
|
371
|
+
* } else {
|
|
372
|
+
* // Process buffer
|
|
373
|
+
* console.log(`Read ${data.length} bytes`);
|
|
374
|
+
* }
|
|
375
|
+
* ```
|
|
376
|
+
*/
|
|
377
|
+
async read(size) {
|
|
378
|
+
return this.native.read(size);
|
|
379
|
+
}
|
|
380
|
+
/**
|
|
381
|
+
* Write buffer to AVIOContext.
|
|
382
|
+
*
|
|
383
|
+
* Direct mapping to avio_write()
|
|
384
|
+
*
|
|
385
|
+
* @param buffer - Buffer to write
|
|
386
|
+
*
|
|
387
|
+
* @example
|
|
388
|
+
* ```typescript
|
|
389
|
+
* import { IOContext } from 'node-av';
|
|
390
|
+
*
|
|
391
|
+
* const data = Buffer.from('Hello, World!');
|
|
392
|
+
* await io.write(data);
|
|
393
|
+
* // Data written successfully
|
|
394
|
+
* ```
|
|
395
|
+
*
|
|
396
|
+
* @throws {Error} If write fails
|
|
397
|
+
*/
|
|
398
|
+
async write(buffer) {
|
|
399
|
+
return this.native.write(buffer);
|
|
400
|
+
}
|
|
401
|
+
/**
|
|
402
|
+
* Seek to a given offset.
|
|
403
|
+
*
|
|
404
|
+
* Direct mapping to avio_seek()
|
|
405
|
+
*
|
|
406
|
+
* @param offset - Offset to seek to
|
|
407
|
+
* @param whence - AVSEEK_SET (0), AVSEEK_CUR (1), AVSEEK_END (2), or AVSEEK_SIZE (0x10000)
|
|
408
|
+
*
|
|
409
|
+
* @returns New position or negative AVERROR:
|
|
410
|
+
* - >=0: New position in bytes
|
|
411
|
+
* - AVERROR(EINVAL): Invalid whence value
|
|
412
|
+
* - AVERROR(ESPIPE): Seek not supported
|
|
413
|
+
* - <0: Other errors
|
|
414
|
+
*
|
|
415
|
+
* @example
|
|
416
|
+
* ```typescript
|
|
417
|
+
* import { FFmpegError, AVSEEK_SET, AVSEEK_END, AVSEEK_SIZE } from 'node-av';
|
|
418
|
+
*
|
|
419
|
+
* // Seek to beginning
|
|
420
|
+
* const pos = await io.seek(0n, AVSEEK_SET);
|
|
421
|
+
* FFmpegError.throwIfError(pos < 0n ? Number(pos) : 0, 'seek');
|
|
422
|
+
*
|
|
423
|
+
* // Seek to end
|
|
424
|
+
* const endPos = await io.seek(0n, AVSEEK_END);
|
|
425
|
+
* FFmpegError.throwIfError(endPos < 0n ? Number(endPos) : 0, 'seek');
|
|
426
|
+
*
|
|
427
|
+
* // Get file size without changing position
|
|
428
|
+
* const size = await io.seek(0n, AVSEEK_SIZE);
|
|
429
|
+
* console.log(`File size: ${size} bytes`);
|
|
430
|
+
* ```
|
|
431
|
+
*/
|
|
432
|
+
async seek(offset, whence) {
|
|
433
|
+
return this.native.seek(offset, whence);
|
|
434
|
+
}
|
|
435
|
+
/**
|
|
436
|
+
* Get the file size.
|
|
437
|
+
*
|
|
438
|
+
* Direct mapping to avio_size()
|
|
439
|
+
*
|
|
440
|
+
* @returns File size or negative AVERROR:
|
|
441
|
+
* - >=0: File size in bytes
|
|
442
|
+
* - AVERROR(ENOSYS): Operation not supported
|
|
443
|
+
* - <0: Other errors
|
|
444
|
+
*
|
|
445
|
+
* @example
|
|
446
|
+
* ```typescript
|
|
447
|
+
* import { FFmpegError } from 'node-av';
|
|
448
|
+
*
|
|
449
|
+
* const size = await io.size();
|
|
450
|
+
* if (size < 0n) {
|
|
451
|
+
* // Handle unsupported or error
|
|
452
|
+
* console.error('Cannot determine file size');
|
|
453
|
+
* } else {
|
|
454
|
+
* console.log(`File size: ${size} bytes`);
|
|
455
|
+
* }
|
|
456
|
+
* ```
|
|
457
|
+
*/
|
|
458
|
+
async size() {
|
|
459
|
+
return this.native.size();
|
|
460
|
+
}
|
|
461
|
+
/**
|
|
462
|
+
* Force flushing of buffered data.
|
|
463
|
+
*
|
|
464
|
+
* Direct mapping to avio_flush()
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* import { IOContext } from 'node-av';
|
|
469
|
+
*
|
|
470
|
+
* await io.flush();
|
|
471
|
+
* // All buffered data has been written
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
async flush() {
|
|
475
|
+
return this.native.flush();
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Skip given number of bytes forward.
|
|
479
|
+
*
|
|
480
|
+
* Direct mapping to avio_skip()
|
|
481
|
+
*
|
|
482
|
+
* @param offset - Number of bytes to skip
|
|
483
|
+
*
|
|
484
|
+
* @returns New position or negative AVERROR:
|
|
485
|
+
* - >=0: New position in bytes
|
|
486
|
+
* - AVERROR_EOF: End of file reached
|
|
487
|
+
* - <0: Other errors
|
|
488
|
+
*
|
|
489
|
+
* @example
|
|
490
|
+
* ```typescript
|
|
491
|
+
* import { FFmpegError } from 'node-av';
|
|
492
|
+
*
|
|
493
|
+
* // Skip 1024 bytes
|
|
494
|
+
* const newPos = await io.skip(1024n);
|
|
495
|
+
* FFmpegError.throwIfError(newPos < 0n ? Number(newPos) : 0, 'skip');
|
|
496
|
+
* console.log(`New position: ${newPos}`);
|
|
497
|
+
* ```
|
|
498
|
+
*/
|
|
499
|
+
async skip(offset) {
|
|
500
|
+
return this.native.skip(offset);
|
|
501
|
+
}
|
|
502
|
+
/**
|
|
503
|
+
* Get the current position.
|
|
504
|
+
*
|
|
505
|
+
* Direct mapping to avio_tell()
|
|
506
|
+
*
|
|
507
|
+
* @returns Current position in bytes
|
|
508
|
+
*
|
|
509
|
+
* @example
|
|
510
|
+
* ```typescript
|
|
511
|
+
* import { IOContext } from 'node-av';
|
|
512
|
+
*
|
|
513
|
+
* const position = io.tell();
|
|
514
|
+
* console.log(`Current position: ${position} bytes`);
|
|
515
|
+
* ```
|
|
516
|
+
*/
|
|
517
|
+
tell() {
|
|
518
|
+
return this.native.tell();
|
|
519
|
+
}
|
|
520
|
+
/**
|
|
521
|
+
* Get the native FFmpeg AVIOContext pointer.
|
|
522
|
+
*
|
|
523
|
+
* @internal For use by other wrapper classes
|
|
524
|
+
* @returns The underlying native I/O context object
|
|
525
|
+
*/
|
|
526
|
+
getNative() {
|
|
527
|
+
return this.native;
|
|
528
|
+
}
|
|
529
|
+
/**
|
|
530
|
+
* Dispose of the I/O context.
|
|
531
|
+
*
|
|
532
|
+
* Implements the AsyncDisposable interface for automatic cleanup.
|
|
533
|
+
* Equivalent to calling closep().
|
|
534
|
+
*
|
|
535
|
+
* @example
|
|
536
|
+
* ```typescript
|
|
537
|
+
* import { IOContext, AVIO_FLAG_READ } from 'node-av';
|
|
538
|
+
*
|
|
539
|
+
* {
|
|
540
|
+
* await using io = new IOContext();
|
|
541
|
+
* await io.open2('file.mp4', AVIO_FLAG_READ);
|
|
542
|
+
* // ... use I/O context
|
|
543
|
+
* } // Automatically closed when leaving scope
|
|
544
|
+
* ```
|
|
545
|
+
*/
|
|
546
|
+
async [Symbol.asyncDispose]() {
|
|
547
|
+
await this.native[Symbol.asyncDispose]();
|
|
548
|
+
}
|
|
549
|
+
}
|
|
550
|
+
//# sourceMappingURL=io-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"io-context.js","sourceRoot":"","sources":["../../src/lib/io-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AACxC,OAAO,EAAE,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAChD,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAK3C;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GA0DG;AACH,MAAM,OAAO,SAAU,SAAQ,YAA6B;IAC1D;;;;;;;;;;;;;;;;;OAiBG;IACH;QACE,KAAK,CAAC,IAAI,QAAQ,CAAC,SAAS,EAAE,CAAC,CAAC;IAClC,CAAC;IAED;;;;;;;;OAQG;IACH,MAAM,CAAC,UAAU,CAAC,MAAuB;QACvC,MAAM,EAAE,GAAG,MAAM,CAAC,MAAM,CAAC,SAAS,CAAC,SAAS,CAAc,CAAC;QAC1D,EAAU,CAAC,MAAM,GAAG,MAAM,CAAC;QAC5B,OAAO,EAAE,CAAC;IACZ,CAAC;IAED;;;;;;OAMG;IACH,IAAI,GAAG;QACL,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC;IACzB,CAAC;IAED;;;;;;OAMG;IACH,IAAI,KAAK;QACP,OAAO,IAAI,CAAC,MAAM,CAAC,KAAK,CAAC;IAC3B,CAAC;IAED;;;;;;;OAOG;IACH,IAAI,QAAQ;QACV,OAAO,IAAI,CAAC,MAAM,CAAC,QAAQ,CAAC;IAC9B,CAAC;IAED;;;;;;OAMG;IACH,IAAI,aAAa;QACf,OAAO,IAAI,CAAC,MAAM,CAAC,aAAa,CAAC;IACnC,CAAC;IAED,IAAI,aAAa,CAAC,KAAa;QAC7B,IAAI,CAAC,MAAM,CAAC,aAAa,GAAG,KAAK,CAAC;IACpC,CAAC;IAED;;;;;;;;OAQ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