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.
Files changed (162) hide show
  1. package/README.md +56 -41
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +182 -126
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +286 -130
  6. package/dist/api/decoder.js +321 -159
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +254 -158
  9. package/dist/api/encoder.js +326 -298
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +912 -0
  12. package/dist/api/filter-presets.js +1407 -0
  13. package/dist/api/filter-presets.js.map +1 -0
  14. package/dist/api/filter.d.ts +280 -284
  15. package/dist/api/filter.js +435 -509
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +226 -159
  18. package/dist/api/hardware.js +405 -287
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -2
  21. package/dist/api/index.js +1 -0
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +45 -47
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +244 -141
  27. package/dist/api/media-input.js +207 -104
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +212 -129
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +22 -182
  36. package/dist/api/utilities/audio-sample.d.ts +1 -1
  37. package/dist/api/utilities/image.d.ts +1 -1
  38. package/dist/api/utilities/media-type.d.ts +1 -1
  39. package/dist/api/utilities/pixel-format.d.ts +1 -1
  40. package/dist/api/utilities/sample-format.d.ts +1 -1
  41. package/dist/api/utilities/timestamp.d.ts +1 -1
  42. package/dist/api/utils.d.ts +1 -2
  43. package/dist/api/utils.js +9 -0
  44. package/dist/api/utils.js.map +1 -1
  45. package/dist/{lib → constants}/channel-layouts.d.ts +1 -1
  46. package/dist/constants/channel-layouts.js.map +1 -0
  47. package/dist/{lib → constants}/constants.d.ts +19 -4
  48. package/dist/{lib → constants}/constants.js +15 -1
  49. package/dist/constants/constants.js.map +1 -0
  50. package/dist/constants/decoders.d.ts +609 -0
  51. package/dist/constants/decoders.js +617 -0
  52. package/dist/constants/decoders.js.map +1 -0
  53. package/dist/constants/encoders.d.ts +285 -0
  54. package/dist/constants/encoders.js +298 -0
  55. package/dist/constants/encoders.js.map +1 -0
  56. package/dist/constants/index.d.ts +4 -0
  57. package/dist/constants/index.js +5 -0
  58. package/dist/constants/index.js.map +1 -0
  59. package/dist/index.d.ts +1 -0
  60. package/dist/index.js +2 -0
  61. package/dist/index.js.map +1 -1
  62. package/dist/lib/audio-fifo.d.ts +128 -171
  63. package/dist/lib/audio-fifo.js +130 -173
  64. package/dist/lib/audio-fifo.js.map +1 -1
  65. package/dist/lib/binding.d.ts +7 -5
  66. package/dist/lib/binding.js +5 -0
  67. package/dist/lib/binding.js.map +1 -1
  68. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  69. package/dist/lib/bitstream-filter-context.js +139 -188
  70. package/dist/lib/bitstream-filter-context.js.map +1 -1
  71. package/dist/lib/bitstream-filter.d.ts +69 -55
  72. package/dist/lib/bitstream-filter.js +68 -54
  73. package/dist/lib/bitstream-filter.js.map +1 -1
  74. package/dist/lib/codec-context.d.ts +317 -381
  75. package/dist/lib/codec-context.js +316 -381
  76. package/dist/lib/codec-context.js.map +1 -1
  77. package/dist/lib/codec-parameters.d.ts +161 -171
  78. package/dist/lib/codec-parameters.js +162 -172
  79. package/dist/lib/codec-parameters.js.map +1 -1
  80. package/dist/lib/codec-parser.d.ts +92 -105
  81. package/dist/lib/codec-parser.js +92 -103
  82. package/dist/lib/codec-parser.js.map +1 -1
  83. package/dist/lib/codec.d.ts +328 -217
  84. package/dist/lib/codec.js +392 -218
  85. package/dist/lib/codec.js.map +1 -1
  86. package/dist/lib/dictionary.d.ts +150 -204
  87. package/dist/lib/dictionary.js +159 -213
  88. package/dist/lib/dictionary.js.map +1 -1
  89. package/dist/lib/error.d.ts +97 -131
  90. package/dist/lib/error.js +98 -128
  91. package/dist/lib/error.js.map +1 -1
  92. package/dist/lib/filter-context.d.ts +317 -194
  93. package/dist/lib/filter-context.js +335 -200
  94. package/dist/lib/filter-context.js.map +1 -1
  95. package/dist/lib/filter-graph.d.ts +252 -293
  96. package/dist/lib/filter-graph.js +253 -294
  97. package/dist/lib/filter-graph.js.map +1 -1
  98. package/dist/lib/filter-inout.d.ts +87 -95
  99. package/dist/lib/filter-inout.js +87 -95
  100. package/dist/lib/filter-inout.js.map +1 -1
  101. package/dist/lib/filter.d.ts +93 -111
  102. package/dist/lib/filter.js +94 -112
  103. package/dist/lib/filter.js.map +1 -1
  104. package/dist/lib/format-context.d.ts +321 -429
  105. package/dist/lib/format-context.js +314 -386
  106. package/dist/lib/format-context.js.map +1 -1
  107. package/dist/lib/frame.d.ts +263 -406
  108. package/dist/lib/frame.js +263 -408
  109. package/dist/lib/frame.js.map +1 -1
  110. package/dist/lib/hardware-device-context.d.ts +150 -204
  111. package/dist/lib/hardware-device-context.js +149 -203
  112. package/dist/lib/hardware-device-context.js.map +1 -1
  113. package/dist/lib/hardware-frames-context.d.ts +171 -181
  114. package/dist/lib/hardware-frames-context.js +171 -181
  115. package/dist/lib/hardware-frames-context.js.map +1 -1
  116. package/dist/lib/index.d.ts +2 -3
  117. package/dist/lib/index.js +2 -5
  118. package/dist/lib/index.js.map +1 -1
  119. package/dist/lib/input-format.d.ts +90 -118
  120. package/dist/lib/input-format.js +89 -117
  121. package/dist/lib/input-format.js.map +1 -1
  122. package/dist/lib/io-context.d.ts +210 -242
  123. package/dist/lib/io-context.js +221 -253
  124. package/dist/lib/io-context.js.map +1 -1
  125. package/dist/lib/log.d.ts +86 -120
  126. package/dist/lib/log.js +85 -122
  127. package/dist/lib/log.js.map +1 -1
  128. package/dist/lib/native-types.d.ts +127 -112
  129. package/dist/lib/native-types.js +9 -0
  130. package/dist/lib/native-types.js.map +1 -1
  131. package/dist/lib/option.d.ts +285 -242
  132. package/dist/lib/option.js +310 -250
  133. package/dist/lib/option.js.map +1 -1
  134. package/dist/lib/output-format.d.ts +78 -102
  135. package/dist/lib/output-format.js +77 -101
  136. package/dist/lib/output-format.js.map +1 -1
  137. package/dist/lib/packet.d.ts +173 -241
  138. package/dist/lib/packet.js +172 -241
  139. package/dist/lib/packet.js.map +1 -1
  140. package/dist/lib/rational.d.ts +0 -2
  141. package/dist/lib/rational.js +0 -2
  142. package/dist/lib/rational.js.map +1 -1
  143. package/dist/lib/software-resample-context.d.ts +242 -326
  144. package/dist/lib/software-resample-context.js +242 -326
  145. package/dist/lib/software-resample-context.js.map +1 -1
  146. package/dist/lib/software-scale-context.d.ts +130 -174
  147. package/dist/lib/software-scale-context.js +132 -176
  148. package/dist/lib/software-scale-context.js.map +1 -1
  149. package/dist/lib/stream.d.ts +88 -198
  150. package/dist/lib/stream.js +87 -197
  151. package/dist/lib/stream.js.map +1 -1
  152. package/dist/lib/types.d.ts +1 -1
  153. package/dist/lib/utilities.d.ts +372 -181
  154. package/dist/lib/utilities.js +373 -182
  155. package/dist/lib/utilities.js.map +1 -1
  156. package/install/check.js +0 -1
  157. package/package.json +32 -24
  158. package/release_notes.md +43 -13
  159. package/CHANGELOG.md +0 -8
  160. package/dist/lib/channel-layouts.js.map +0 -1
  161. package/dist/lib/constants.js.map +0 -1
  162. /package/dist/{lib → constants}/channel-layouts.js +0 -0
@@ -1,493 +1,461 @@
1
1
  import { OptionMember } from './option.js';
2
- import type { AVIOFlag, AVSeekWhence } from './constants.js';
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 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.
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 a file for reading
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 buffer = await io.read(4096);
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 seekRet = await io.seek(1024n, AVSEEK_SET);
28
- * FFmpegError.throwIfError(seekRet < 0 ? -1 : 0, 'seek');
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 size = await io.size();
35
+ * const fileSize = await io.size();
36
+ * console.log(`File size: ${fileSize}`);
32
37
  *
33
- * // Clean up
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 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);
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, // no write
48
- * (offset, whence) => { // custom seek function
49
- * return BigInt(calculateNewPosition(offset, whence));
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 {@link FormatContext} For using custom I/O with containers
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
- * Create an IOContext wrapper from a native IOContext.
73
+ * Find input format by short name.
85
74
  *
86
- * Used internally when getting IOContext from other objects.
87
- * @internal
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 to wrap
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
- * Check if end of file reached.
85
+ * End of file indicator.
95
86
  *
96
- * Direct mapping to avio_feof()
87
+ * True if end of file has been reached during reading.
97
88
  *
98
- * @readonly
89
+ * Direct mapping to AVIOContext->eof_reached.
99
90
  */
100
91
  get eof(): boolean;
101
92
  /**
102
- * Error code if any.
93
+ * Error code.
103
94
  *
104
- * Direct mapping to AVIOContext->error
95
+ * Contains the last error that occurred, or 0 if no error.
105
96
  *
106
- * @readonly
97
+ * Direct mapping to AVIOContext->error.
107
98
  */
108
99
  get error(): number;
109
100
  /**
110
- * Whether seeking is possible.
101
+ * Seekability indicator.
111
102
  *
112
- * Direct mapping to AVIOContext->seekable
103
+ * Non-zero if the underlying resource supports seeking.
104
+ * Some protocols like pipes or network streams may not be seekable.
113
105
  *
114
- * Bitmask of AVIO_SEEKABLE_* flags.
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
- * Direct mapping to AVIOContext->max_packet_size
112
+ * Used to limit packet sizes in network protocols.
113
+ * 0 means no limit.
122
114
  *
123
- * If non-zero, indicates the maximum packet size.
115
+ * Direct mapping to AVIOContext->max_packet_size.
124
116
  */
125
117
  get maxPacketSize(): number;
126
118
  set maxPacketSize(value: number);
127
119
  /**
128
- * Whether direct mode is enabled.
120
+ * Direct mode flag.
129
121
  *
130
- * Direct mapping to AVIOContext->direct
122
+ * If set, the I/O context will attempt to avoid buffering.
131
123
  *
132
- * avio_read and avio_write should if possible be satisfied directly
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
- * Get current position in the file.
129
+ * Current position.
140
130
  *
141
- * Direct mapping to AVIOContext->pos
131
+ * Current byte position in the stream.
142
132
  *
143
- * @readonly
133
+ * Direct mapping to AVIOContext->pos.
144
134
  */
145
135
  get pos(): bigint;
146
136
  /**
147
- * Get buffer size.
137
+ * Internal buffer size.
148
138
  *
149
- * Direct mapping to AVIOContext->buffer_size
139
+ * Size of the internal buffer used for I/O operations.
150
140
  *
151
- * @readonly
141
+ * Direct mapping to AVIOContext->buffer_size.
152
142
  */
153
143
  get bufferSize(): number;
154
144
  /**
155
- * Check if opened for writing.
145
+ * Write flag.
156
146
  *
157
- * Direct mapping to AVIOContext->write_flag
147
+ * True if opened for writing, false for reading.
158
148
  *
159
- * @readonly
149
+ * Direct mapping to AVIOContext->write_flag.
160
150
  */
161
151
  get writeFlag(): boolean;
162
152
  /**
163
- * Create and initialize a buffered I/O context.
153
+ * Allocate I/O context with buffer.
164
154
  *
165
- * Allocates an I/O context with an internal buffer for efficient I/O operations.
166
- * For file I/O, use open2() instead which handles allocation automatically.
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 the internal buffer in bytes
171
- * @param writeFlag - 1 for writing, 0 for reading
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 callbacks
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 an AVIOContext with custom callbacks.
173
+ * Allocate I/O context with custom callbacks.
191
174
  *
192
- * Creates a custom I/O context with JavaScript callbacks for read, write, and seek operations.
175
+ * Creates an I/O context with custom read, write, and seek callbacks.
176
+ * Enables implementing custom protocols or data sources.
193
177
  *
194
- * IMPORTANT: Callbacks must be synchronous! They are called from FFmpeg's thread and must
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
- * Direct mapping to avio_alloc_context() with custom callbacks
198
- *
199
- * @param bufferSize - Size of the buffer in bytes
200
- * @param writeFlag - 0 for read, 1 for write
201
- * @param readCallback - Synchronous callback for reading data. Returns Buffer, null for EOF, or negative error code
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 { IOContext, AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av';
188
+ * import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END, AVSEEK_SIZE } from 'node-av/constants';
208
189
  *
209
- * const io = new IOContext();
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 up to 'size' bytes - MUST BE SYNCHRONOUS
218
- * return buffer.slice(position, position + size);
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 to position - MUST BE SYNCHRONOUS
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 = buffer.length + Number(offset);
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 buffer allocation
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 the AVIOContext.
219
+ * Free I/O context.
236
220
  *
237
- * Direct mapping to avio_context_free()
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
- * // io is now invalid and should not be used
229
+ * // Context is now invalid
245
230
  * ```
246
231
  */
247
232
  freeContext(): void;
248
233
  /**
249
- * Open a resource for reading or writing.
234
+ * Open resource for I/O.
250
235
  *
251
- * Opens a URL using the appropriate protocol handler (file, http, etc.).
252
- * Automatically allocates and initializes the I/O context.
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
- * - 0: Success
261
- * - AVERROR(ENOENT): File not found
262
- * - AVERROR(EACCES): Permission denied
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 { IOContext, FFmpegError } from 'node-av';
250
+ * import { FFmpegError } from 'node-av';
270
251
  * import { AVIO_FLAG_READ, AVIO_FLAG_WRITE } from 'node-av/constants';
271
252
  *
272
- * // Open file for reading
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 file for writing
278
- * const writeIO = new IOContext();
279
- * const writeRet = await writeIO.open2('output.mp4', AVIO_FLAG_WRITE);
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 and free resources
262
+ * @see {@link closep} To close after use
289
263
  */
290
264
  open2(url: string, flags?: AVIOFlag): Promise<number>;
291
265
  /**
292
- * Close the resource and free the AVIOContext.
266
+ * Close I/O context.
293
267
  *
294
- * Direct mapping to avio_closep()
268
+ * Closes the I/O context and releases associated resources.
269
+ * Flushes any buffered data before closing.
295
270
  *
296
- * @returns 0 on success, negative AVERROR on error:
297
- * - 0: Success
298
- * - AVERROR(EIO): I/O error during close
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
- * FFmpegError.throwIfError(ret, 'closep');
307
- * // I/O context is now closed and freed
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 size bytes from AVIOContext.
287
+ * Read data from I/O context.
313
288
  *
314
- * Direct mapping to avio_read()
289
+ * Reads up to the specified number of bytes from the stream.
315
290
  *
316
- * @param size - Number of bytes to read
291
+ * Direct mapping to avio_read().
317
292
  *
318
- * @returns Buffer with data or error code if negative:
319
- * - Buffer: Successfully read data
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
- * - AVERROR(EIO): I/O error
322
- * - <0: Other errors
296
+ * - AVERROR_EIO: I/O error
323
297
  *
324
298
  * @example
325
299
  * ```typescript
326
- * import { FFmpegError, AVERROR_EOF } from 'node-av';
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 buffer to AVIOContext.
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 - Buffer to write
318
+ * @param buffer - Data to write
348
319
  *
349
320
  * @example
350
321
  * ```typescript
351
- * import { IOContext } from 'node-av';
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
- * @throws {Error} If write fails
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 a given offset.
331
+ * Seek to position in stream.
363
332
  *
364
- * Direct mapping to avio_seek()
333
+ * Changes the current position in the stream.
334
+ * Not all streams support seeking.
365
335
  *
366
- * @param offset - Offset to seek to
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
- * @returns New position or negative AVERROR:
370
- * - >=0: New position in bytes
371
- * - AVERROR(EINVAL): Invalid whence value
372
- * - AVERROR(ESPIPE): Seek not supported
373
- * - <0: Other errors
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 { FFmpegError, AVSEEK_SET, AVSEEK_END, AVSEEK_SIZE } from 'node-av';
346
+ * import { AVSEEK_SET, AVSEEK_CUR, AVSEEK_END } from 'node-av/constants';
378
347
  *
379
- * // Seek to beginning
380
- * const pos = await io.seek(0n, AVSEEK_SET);
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 end
384
- * const endPos = await io.seek(0n, AVSEEK_END);
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
- * // Get file size without changing position
388
- * const size = await io.seek(0n, AVSEEK_SIZE);
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 the file size.
363
+ * Get stream size.
395
364
  *
396
- * Direct mapping to avio_size()
365
+ * Returns the total size of the stream in bytes.
366
+ * Not all streams have a known size.
397
367
  *
398
- * @returns File size or negative AVERROR:
399
- * - >=0: File size in bytes
400
- * - AVERROR(ENOSYS): Operation not supported
401
- * - <0: Other errors
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 < 0n) {
409
- * // Handle unsupported or error
410
- * console.error('Cannot determine file size');
376
+ * if (size >= 0n) {
377
+ * console.log(`Stream size: ${size} bytes`);
411
378
  * } else {
412
- * console.log(`File size: ${size} bytes`);
379
+ * console.log('Stream size unknown');
413
380
  * }
414
381
  * ```
415
382
  */
416
383
  size(): Promise<bigint>;
417
384
  /**
418
- * Force flushing of buffered data.
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
- * import { IOContext } from 'node-av';
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 given number of bytes forward.
401
+ * Skip bytes in stream.
433
402
  *
434
- * Direct mapping to avio_skip()
403
+ * Advances the position by the specified offset.
404
+ * More efficient than reading and discarding data.
435
405
  *
436
- * @param offset - Number of bytes to skip
406
+ * Direct mapping to avio_skip().
437
407
  *
438
- * @returns New position or negative AVERROR:
439
- * - >=0: New position in bytes
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
- * import { FFmpegError } from 'node-av';
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 the current position.
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} bytes`);
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 FFmpeg AVIOContext pointer.
440
+ * Get the underlying native IOContext object.
472
441
  *
473
- * @internal For use by other wrapper classes
474
- * @returns The underlying native I/O context object
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
- * Equivalent to calling closep().
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('file.mp4', AVIO_FLAG_READ);
490
- * // ... use I/O context
457
+ * await io.open2('input.mp4');
458
+ * // Use io...
491
459
  * } // Automatically closed when leaving scope
492
460
  * ```
493
461
  */