node-av 1.3.0 → 2.0.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 +37 -38
- package/dist/api/bitstream-filter.d.ts +2 -2
- package/dist/api/bitstream-filter.js +2 -2
- package/dist/api/decoder.d.ts +131 -120
- package/dist/api/decoder.js +191 -203
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +135 -77
- package/dist/api/encoder.js +235 -192
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +408 -1534
- package/dist/api/filter-presets.js +1005 -2058
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +160 -165
- package/dist/api/filter.js +294 -374
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +8 -31
- package/dist/api/hardware.js +19 -70
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/media-input.d.ts +1 -1
- package/dist/api/media-input.js +3 -8
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +35 -128
- package/dist/api/media-output.js +136 -208
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +17 -17
- package/dist/api/pipeline.js +19 -42
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +17 -57
- package/dist/lib/dictionary.d.ts +2 -2
- package/dist/lib/dictionary.js +2 -2
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/filter-context.d.ts +19 -2
- package/dist/lib/filter-context.js +15 -0
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/format-context.d.ts +18 -18
- package/dist/lib/format-context.js +20 -20
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +43 -1
- package/dist/lib/frame.js +53 -0
- package/dist/lib/frame.js.map +1 -1
- package/package.json +17 -17
- package/release_notes.md +0 -29
|
@@ -3,15 +3,20 @@ import { Encoder } from './encoder.js';
|
|
|
3
3
|
import type { IRational, Packet, Stream } from '../lib/index.js';
|
|
4
4
|
import type { IOOutputCallbacks, MediaOutputOptions } from './types.js';
|
|
5
5
|
export interface StreamDescription {
|
|
6
|
+
initialized: boolean;
|
|
6
7
|
stream: Stream;
|
|
7
|
-
|
|
8
|
-
|
|
8
|
+
source: Encoder | Stream;
|
|
9
|
+
timeBase?: IRational;
|
|
9
10
|
sourceTimeBase?: IRational;
|
|
11
|
+
isStreamCopy: boolean;
|
|
12
|
+
bufferedPackets: Packet[];
|
|
10
13
|
}
|
|
11
14
|
/**
|
|
12
15
|
* High-level media output for writing and muxing media files.
|
|
13
16
|
*
|
|
14
17
|
* Provides simplified access to media muxing and file writing operations.
|
|
18
|
+
* Automatically manages header and trailer writing - header is written on first packet,
|
|
19
|
+
* trailer is written on close. Supports lazy initialization for both encoders and streams.
|
|
15
20
|
* Handles stream configuration, packet writing, and format management.
|
|
16
21
|
* Supports files, URLs, and custom I/O with automatic cleanup.
|
|
17
22
|
* Essential component for media encoding pipelines and transcoding.
|
|
@@ -27,14 +32,11 @@ export interface StreamDescription {
|
|
|
27
32
|
* const videoIdx = output.addStream(videoEncoder);
|
|
28
33
|
* const audioIdx = output.addStream(audioEncoder);
|
|
29
34
|
*
|
|
30
|
-
* // Write header
|
|
31
|
-
* await output.writeHeader();
|
|
32
|
-
*
|
|
33
|
-
* // Write packets
|
|
35
|
+
* // Write packets - header written automatically on first packet
|
|
34
36
|
* await output.writePacket(packet, videoIdx);
|
|
35
37
|
*
|
|
36
|
-
* //
|
|
37
|
-
* await
|
|
38
|
+
* // Close - trailer written automatically
|
|
39
|
+
* // (automatic with await using)
|
|
38
40
|
* ```
|
|
39
41
|
*
|
|
40
42
|
* @example
|
|
@@ -45,8 +47,8 @@ export interface StreamDescription {
|
|
|
45
47
|
*
|
|
46
48
|
* // Copy stream configuration
|
|
47
49
|
* const videoIdx = output.addStream(input.video());
|
|
48
|
-
* await output.writeHeader();
|
|
49
50
|
*
|
|
51
|
+
* // Process packets - header/trailer handled automatically
|
|
50
52
|
* for await (const packet of input.packets()) {
|
|
51
53
|
* await output.writePacket(packet, videoIdx);
|
|
52
54
|
* packet.free();
|
|
@@ -63,7 +65,8 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
63
65
|
private ioContext?;
|
|
64
66
|
private headerWritten;
|
|
65
67
|
private trailerWritten;
|
|
66
|
-
private
|
|
68
|
+
private isClosed;
|
|
69
|
+
private headerWritePromise?;
|
|
67
70
|
/**
|
|
68
71
|
* @internal
|
|
69
72
|
*/
|
|
@@ -127,21 +130,25 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
127
130
|
* Add a stream to the output.
|
|
128
131
|
*
|
|
129
132
|
* Configures output stream from encoder or input stream.
|
|
130
|
-
* Must be called before
|
|
133
|
+
* Must be called before writing any packets.
|
|
131
134
|
* Returns stream index for packet writing.
|
|
132
135
|
*
|
|
133
|
-
*
|
|
136
|
+
* Streams are initialized lazily - codec parameters are configured
|
|
137
|
+
* automatically when the first packet is written. This allows encoders
|
|
138
|
+
* to be initialized from frame properties.
|
|
139
|
+
*
|
|
140
|
+
* Direct mapping to avformat_new_stream().
|
|
134
141
|
*
|
|
135
142
|
* @param source - Encoder or stream to add
|
|
136
143
|
* @param options - Stream configuration options
|
|
137
144
|
* @param options.timeBase - Optional custom timebase for the stream
|
|
138
145
|
* @returns Stream index for packet writing
|
|
139
146
|
*
|
|
140
|
-
* @throws {Error} If called after
|
|
147
|
+
* @throws {Error} If called after packets have been written or output closed
|
|
141
148
|
*
|
|
142
149
|
* @example
|
|
143
150
|
* ```typescript
|
|
144
|
-
* // Add stream from encoder
|
|
151
|
+
* // Add stream from encoder (lazy initialization)
|
|
145
152
|
* const videoIdx = output.addStream(videoEncoder);
|
|
146
153
|
* const audioIdx = output.addStream(audioEncoder);
|
|
147
154
|
* ```
|
|
@@ -164,20 +171,26 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
164
171
|
* Write a packet to the output.
|
|
165
172
|
*
|
|
166
173
|
* Writes muxed packet to the specified stream.
|
|
167
|
-
* Automatically handles
|
|
168
|
-
*
|
|
174
|
+
* Automatically handles:
|
|
175
|
+
* - Stream initialization on first packet (lazy initialization)
|
|
176
|
+
* - Codec parameter configuration from encoder or input stream
|
|
177
|
+
* - Header writing on first packet
|
|
178
|
+
* - Timestamp rescaling between source and output timebases
|
|
169
179
|
*
|
|
170
|
-
*
|
|
180
|
+
* For encoder sources, the encoder must have processed at least one frame
|
|
181
|
+
* before packets can be written (encoder must be initialized).
|
|
182
|
+
*
|
|
183
|
+
* Direct mapping to avformat_write_header() (on first packet) and av_interleaved_write_frame().
|
|
171
184
|
*
|
|
172
185
|
* @param packet - Packet to write
|
|
173
186
|
* @param streamIndex - Target stream index
|
|
174
|
-
* @throws {Error} If stream invalid or
|
|
187
|
+
* @throws {Error} If stream invalid or encoder not initialized
|
|
175
188
|
*
|
|
176
189
|
* @throws {FFmpegError} If write fails
|
|
177
190
|
*
|
|
178
191
|
* @example
|
|
179
192
|
* ```typescript
|
|
180
|
-
* // Write encoded packet
|
|
193
|
+
* // Write encoded packet - header written automatically on first packet
|
|
181
194
|
* const packet = await encoder.encode(frame);
|
|
182
195
|
* if (packet) {
|
|
183
196
|
* await output.writePacket(packet, videoIdx);
|
|
@@ -197,64 +210,13 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
197
210
|
* ```
|
|
198
211
|
*
|
|
199
212
|
* @see {@link addStream} For adding streams
|
|
200
|
-
* @see {@link writeHeader} Must be called first
|
|
201
213
|
*/
|
|
202
214
|
writePacket(packet: Packet, streamIndex: number): Promise<void>;
|
|
203
|
-
/**
|
|
204
|
-
* Write file header.
|
|
205
|
-
*
|
|
206
|
-
* Writes format header with stream configuration.
|
|
207
|
-
* Must be called after adding all streams and before writing packets.
|
|
208
|
-
* Finalizes stream parameters and initializes muxer.
|
|
209
|
-
*
|
|
210
|
-
* Direct mapping to avformat_write_header().
|
|
211
|
-
*
|
|
212
|
-
* @throws {Error} If already written or output closed
|
|
213
|
-
*
|
|
214
|
-
* @throws {FFmpegError} If write fails
|
|
215
|
-
*
|
|
216
|
-
* @example
|
|
217
|
-
* ```typescript
|
|
218
|
-
* // Standard workflow
|
|
219
|
-
* const output = await MediaOutput.open('output.mp4');
|
|
220
|
-
* output.addStream(encoder);
|
|
221
|
-
* await output.writeHeader();
|
|
222
|
-
* // Now ready to write packets
|
|
223
|
-
* ```
|
|
224
|
-
*
|
|
225
|
-
* @see {@link addStream} Must add streams first
|
|
226
|
-
* @see {@link writePacket} Can write packets after
|
|
227
|
-
* @see {@link writeTrailer} Must call at end
|
|
228
|
-
*/
|
|
229
|
-
writeHeader(): Promise<void>;
|
|
230
|
-
/**
|
|
231
|
-
* Write file trailer.
|
|
232
|
-
*
|
|
233
|
-
* Writes format trailer and finalizes the file.
|
|
234
|
-
* Must be called after all packets are written.
|
|
235
|
-
* Flushes any buffered data and updates file headers.
|
|
236
|
-
*
|
|
237
|
-
* Direct mapping to av_write_trailer().
|
|
238
|
-
*
|
|
239
|
-
* @throws {Error} If header not written or already written
|
|
240
|
-
*
|
|
241
|
-
* @throws {FFmpegError} If write fails
|
|
242
|
-
*
|
|
243
|
-
* @example
|
|
244
|
-
* ```typescript
|
|
245
|
-
* // Finalize output
|
|
246
|
-
* await output.writeTrailer();
|
|
247
|
-
* await output.close();
|
|
248
|
-
* ```
|
|
249
|
-
*
|
|
250
|
-
* @see {@link writeHeader} Must be called first
|
|
251
|
-
* @see {@link close} For cleanup after trailer
|
|
252
|
-
*/
|
|
253
|
-
writeTrailer(): Promise<void>;
|
|
254
215
|
/**
|
|
255
216
|
* Close media output and free resources.
|
|
256
217
|
*
|
|
257
|
-
*
|
|
218
|
+
* Automatically writes trailer if header was written.
|
|
219
|
+
* Closes the output file and releases all resources.
|
|
258
220
|
* Safe to call multiple times.
|
|
259
221
|
* Automatically called by Symbol.asyncDispose.
|
|
260
222
|
*
|
|
@@ -262,7 +224,7 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
262
224
|
* ```typescript
|
|
263
225
|
* const output = await MediaOutput.open('output.mp4');
|
|
264
226
|
* try {
|
|
265
|
-
* // Use output
|
|
227
|
+
* // Use output - trailer written automatically on close
|
|
266
228
|
* } finally {
|
|
267
229
|
* await output.close();
|
|
268
230
|
* }
|
|
@@ -271,61 +233,6 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
271
233
|
* @see {@link Symbol.asyncDispose} For automatic cleanup
|
|
272
234
|
*/
|
|
273
235
|
close(): Promise<void>;
|
|
274
|
-
/**
|
|
275
|
-
* Get stream information.
|
|
276
|
-
*
|
|
277
|
-
* Returns internal stream info for the specified index.
|
|
278
|
-
*
|
|
279
|
-
* @param streamIndex - Stream index
|
|
280
|
-
* @returns Stream info or undefined
|
|
281
|
-
*
|
|
282
|
-
* @example
|
|
283
|
-
* ```typescript
|
|
284
|
-
* const info = output.getStreamInfo(0);
|
|
285
|
-
* console.log(`Stream 0 timebase: ${info?.timeBase.num}/${info?.timeBase.den}`);
|
|
286
|
-
* ```
|
|
287
|
-
*/
|
|
288
|
-
getStreamInfo(streamIndex: number): StreamDescription | undefined;
|
|
289
|
-
/**
|
|
290
|
-
* Get all stream indices.
|
|
291
|
-
*
|
|
292
|
-
* Returns array of all added stream indices.
|
|
293
|
-
*
|
|
294
|
-
* @returns Array of stream indices
|
|
295
|
-
*
|
|
296
|
-
* @example
|
|
297
|
-
* ```typescript
|
|
298
|
-
* const indices = output.getStreamIndices();
|
|
299
|
-
* console.log(`Output has ${indices.length} streams`);
|
|
300
|
-
* ```
|
|
301
|
-
*/
|
|
302
|
-
getStreamIndices(): number[];
|
|
303
|
-
/**
|
|
304
|
-
* Check if header has been written.
|
|
305
|
-
*
|
|
306
|
-
* @returns true if header written
|
|
307
|
-
*
|
|
308
|
-
* @example
|
|
309
|
-
* ```typescript
|
|
310
|
-
* if (!output.isHeaderWritten()) {
|
|
311
|
-
* await output.writeHeader();
|
|
312
|
-
* }
|
|
313
|
-
* ```
|
|
314
|
-
*/
|
|
315
|
-
isHeaderWritten(): boolean;
|
|
316
|
-
/**
|
|
317
|
-
* Check if trailer has been written.
|
|
318
|
-
*
|
|
319
|
-
* @returns true if trailer written
|
|
320
|
-
*
|
|
321
|
-
* @example
|
|
322
|
-
* ```typescript
|
|
323
|
-
* if (!output.isTrailerWritten()) {
|
|
324
|
-
* await output.writeTrailer();
|
|
325
|
-
* }
|
|
326
|
-
* ```
|
|
327
|
-
*/
|
|
328
|
-
isTrailerWritten(): boolean;
|
|
329
236
|
/**
|
|
330
237
|
* Get underlying format context.
|
|
331
238
|
*
|