node-av 2.0.0 → 2.4.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 +18 -5
- package/binding.gyp +12 -0
- package/dist/api/bitstream-filter.d.ts +132 -0
- package/dist/api/bitstream-filter.js +198 -0
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +194 -0
- package/dist/api/decoder.js +313 -0
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +263 -0
- package/dist/api/encoder.js +427 -0
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +92 -0
- package/dist/api/filter-presets.js +92 -0
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +234 -9
- package/dist/api/filter.js +372 -9
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +17 -0
- package/dist/api/hardware.js +28 -17
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/io-stream.d.ts +6 -0
- package/dist/api/io-stream.js +2 -0
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +214 -1
- package/dist/api/media-input.js +341 -0
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +132 -1
- package/dist/api/media-output.js +339 -0
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +73 -8
- package/dist/api/pipeline.js +61 -0
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +7 -0
- package/dist/api/utils.js +2 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +103 -0
- package/dist/lib/audio-fifo.js +109 -0
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.d.ts +1 -0
- package/dist/lib/binding.js +32 -7
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +79 -0
- package/dist/lib/bitstream-filter-context.js +83 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +2 -0
- package/dist/lib/bitstream-filter.js +2 -0
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +168 -0
- package/dist/lib/codec-context.js +178 -0
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +3 -0
- package/dist/lib/codec-parameters.js +3 -0
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +6 -0
- package/dist/lib/codec-parser.js +6 -0
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +12 -0
- package/dist/lib/codec.js +12 -0
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +16 -0
- package/dist/lib/dictionary.js +16 -0
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +8 -0
- package/dist/lib/error.js +9 -0
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +100 -0
- package/dist/lib/filter-context.js +104 -0
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +80 -0
- package/dist/lib/filter-graph.js +84 -0
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +1 -0
- package/dist/lib/filter-inout.js +1 -0
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +2 -0
- package/dist/lib/filter.js +2 -0
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +338 -2
- package/dist/lib/format-context.js +355 -3
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +41 -0
- package/dist/lib/frame.js +43 -0
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +8 -0
- package/dist/lib/hardware-device-context.js +8 -0
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +55 -0
- package/dist/lib/hardware-frames-context.js +57 -0
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/input-format.d.ts +43 -3
- package/dist/lib/input-format.js +48 -0
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +218 -0
- package/dist/lib/io-context.js +234 -0
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +2 -0
- package/dist/lib/log.js +2 -0
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +39 -1
- package/dist/lib/option.d.ts +90 -0
- package/dist/lib/option.js +97 -0
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +4 -0
- package/dist/lib/output-format.js +4 -0
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +7 -0
- package/dist/lib/packet.js +7 -0
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +1 -0
- package/dist/lib/rational.js +1 -0
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +64 -0
- package/dist/lib/software-resample-context.js +66 -0
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +98 -0
- package/dist/lib/software-scale-context.js +102 -0
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +1 -0
- package/dist/lib/stream.js +1 -0
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +60 -0
- package/dist/lib/utilities.js +60 -0
- package/dist/lib/utilities.js.map +1 -1
- package/package.json +19 -17
package/dist/api/encoder.d.ts
CHANGED
|
@@ -70,8 +70,11 @@ export declare class Encoder implements Disposable {
|
|
|
70
70
|
private opts?;
|
|
71
71
|
/**
|
|
72
72
|
* @param codecContext - Configured codec context
|
|
73
|
+
*
|
|
73
74
|
* @param codec - Encoder codec
|
|
75
|
+
*
|
|
74
76
|
* @param opts - Encoder options as Dictionary
|
|
77
|
+
*
|
|
75
78
|
* @internal
|
|
76
79
|
*/
|
|
77
80
|
private constructor();
|
|
@@ -85,7 +88,9 @@ export declare class Encoder implements Disposable {
|
|
|
85
88
|
* Direct mapping to avcodec_find_encoder_by_name() or avcodec_find_encoder().
|
|
86
89
|
*
|
|
87
90
|
* @param encoderCodec - Codec name, ID, or instance to use for encoding
|
|
91
|
+
*
|
|
88
92
|
* @param options - Encoder configuration options including required timeBase
|
|
93
|
+
*
|
|
89
94
|
* @returns Configured encoder instance
|
|
90
95
|
*
|
|
91
96
|
* @throws {Error} If encoder not found or timeBase not provided
|
|
@@ -129,6 +134,63 @@ export declare class Encoder implements Disposable {
|
|
|
129
134
|
* @see {@link EncoderOptions} For configuration options
|
|
130
135
|
*/
|
|
131
136
|
static create(encoderCodec: FFEncoderCodec | AVCodecID | Codec, options: EncoderOptions): Promise<Encoder>;
|
|
137
|
+
/**
|
|
138
|
+
* Create an encoder with specified codec and options synchronously.
|
|
139
|
+
* Synchronous version of create.
|
|
140
|
+
*
|
|
141
|
+
* Initializes an encoder with the appropriate codec and configuration.
|
|
142
|
+
* Uses lazy initialization - encoder is opened when first frame is received.
|
|
143
|
+
* Hardware context will be automatically detected from first frame if not provided.
|
|
144
|
+
*
|
|
145
|
+
* Direct mapping to avcodec_find_encoder_by_name() or avcodec_find_encoder().
|
|
146
|
+
*
|
|
147
|
+
* @param encoderCodec - Codec name, ID, or instance to use for encoding
|
|
148
|
+
*
|
|
149
|
+
* @param options - Encoder configuration options including required timeBase
|
|
150
|
+
*
|
|
151
|
+
* @returns Configured encoder instance
|
|
152
|
+
*
|
|
153
|
+
* @throws {Error} If encoder not found or timeBase not provided
|
|
154
|
+
*
|
|
155
|
+
* @throws {FFmpegError} If codec allocation fails
|
|
156
|
+
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* // From decoder stream info
|
|
160
|
+
* const encoder = await Encoder.create(FF_ENCODER_LIBX264, {
|
|
161
|
+
* timeBase: video.timeBase,
|
|
162
|
+
* bitrate: '5M',
|
|
163
|
+
* gopSize: 60,
|
|
164
|
+
* options: {
|
|
165
|
+
* preset: 'fast',
|
|
166
|
+
* crf: '23'
|
|
167
|
+
* }
|
|
168
|
+
* });
|
|
169
|
+
* ```
|
|
170
|
+
*
|
|
171
|
+
* @example
|
|
172
|
+
* ```typescript
|
|
173
|
+
* // With custom stream info
|
|
174
|
+
* const encoder = await Encoder.create(FF_ENCODER_AAC, {
|
|
175
|
+
* timeBase: audio.timeBase,
|
|
176
|
+
* bitrate: '192k'
|
|
177
|
+
* });
|
|
178
|
+
* ```
|
|
179
|
+
*
|
|
180
|
+
* @example
|
|
181
|
+
* ```typescript
|
|
182
|
+
* // Hardware encoder
|
|
183
|
+
* const hw = HardwareContext.auto();
|
|
184
|
+
* const encoderCodec = hw?.getEncoderCodec('h264') ?? FF_ENCODER_H264_VIDEOTOOLBOX;
|
|
185
|
+
* const encoder = await Encoder.create(encoderCodec, {
|
|
186
|
+
* timeBase: video.timeBase,
|
|
187
|
+
* bitrate: '8M'
|
|
188
|
+
* });
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @see {@link create} For async version
|
|
192
|
+
*/
|
|
193
|
+
static createSync(encoderCodec: FFEncoderCodec | AVCodecID | Codec, options: EncoderOptions): Encoder;
|
|
132
194
|
/**
|
|
133
195
|
* Check if encoder is open.
|
|
134
196
|
*
|
|
@@ -194,6 +256,7 @@ export declare class Encoder implements Disposable {
|
|
|
194
256
|
* Direct mapping to avcodec_send_frame() and avcodec_receive_packet().
|
|
195
257
|
*
|
|
196
258
|
* @param frame - Raw frame to encode (or null to flush)
|
|
259
|
+
*
|
|
197
260
|
* @returns Encoded packet or null if more data needed
|
|
198
261
|
*
|
|
199
262
|
* @throws {Error} If encoder is closed
|
|
@@ -227,6 +290,50 @@ export declare class Encoder implements Disposable {
|
|
|
227
290
|
* @see {@link flush} For end-of-stream handling
|
|
228
291
|
*/
|
|
229
292
|
encode(frame: Frame | null): Promise<Packet | null>;
|
|
293
|
+
/**
|
|
294
|
+
* Encode a frame to a packet synchronously.
|
|
295
|
+
* Synchronous version of encode.
|
|
296
|
+
*
|
|
297
|
+
* Sends a frame to the encoder and attempts to receive an encoded packet.
|
|
298
|
+
* On first frame, automatically initializes encoder with frame properties.
|
|
299
|
+
* Handles internal buffering - may return null if more frames needed.
|
|
300
|
+
*
|
|
301
|
+
* Direct mapping to avcodec_send_frame() and avcodec_receive_packet().
|
|
302
|
+
*
|
|
303
|
+
* @param frame - Raw frame to encode (or null to flush)
|
|
304
|
+
*
|
|
305
|
+
* @returns Encoded packet or null if more data needed
|
|
306
|
+
*
|
|
307
|
+
* @throws {Error} If encoder is closed
|
|
308
|
+
*
|
|
309
|
+
* @throws {FFmpegError} If encoding fails
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* const packet = encoder.encodeSync(frame);
|
|
314
|
+
* if (packet) {
|
|
315
|
+
* console.log(`Encoded packet with PTS: ${packet.pts}`);
|
|
316
|
+
* output.writePacketSync(packet);
|
|
317
|
+
* packet.free();
|
|
318
|
+
* }
|
|
319
|
+
* ```
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* // Encode loop
|
|
324
|
+
* for (const frame of decoder.framesSync(packets)) {
|
|
325
|
+
* const packet = encoder.encodeSync(frame);
|
|
326
|
+
* if (packet) {
|
|
327
|
+
* output.writePacketSync(packet);
|
|
328
|
+
* packet.free();
|
|
329
|
+
* }
|
|
330
|
+
* frame.free();
|
|
331
|
+
* }
|
|
332
|
+
* ```
|
|
333
|
+
*
|
|
334
|
+
* @see {@link encode} For async version
|
|
335
|
+
*/
|
|
336
|
+
encodeSync(frame: Frame | null): Packet | null;
|
|
230
337
|
/**
|
|
231
338
|
* Encode frame stream to packet stream.
|
|
232
339
|
*
|
|
@@ -236,7 +343,9 @@ export declare class Encoder implements Disposable {
|
|
|
236
343
|
* Primary interface for stream-based encoding.
|
|
237
344
|
*
|
|
238
345
|
* @param frames - Async iterable of frames (freed automatically)
|
|
346
|
+
*
|
|
239
347
|
* @yields {Packet} Encoded packets (caller must free)
|
|
348
|
+
*
|
|
240
349
|
* @throws {Error} If encoder is closed
|
|
241
350
|
*
|
|
242
351
|
* @throws {FFmpegError} If encoding fails
|
|
@@ -287,6 +396,54 @@ export declare class Encoder implements Disposable {
|
|
|
287
396
|
* @see {@link Decoder.frames} For frame source
|
|
288
397
|
*/
|
|
289
398
|
packets(frames: AsyncIterable<Frame>): AsyncGenerator<Packet>;
|
|
399
|
+
/**
|
|
400
|
+
* Encode frame stream to packet stream synchronously.
|
|
401
|
+
* Synchronous version of packets.
|
|
402
|
+
*
|
|
403
|
+
* High-level sync generator for complete encoding pipeline.
|
|
404
|
+
* Automatically manages frame memory, encoder state,
|
|
405
|
+
* and flushes buffered packets at end.
|
|
406
|
+
* Primary interface for stream-based encoding.
|
|
407
|
+
*
|
|
408
|
+
* @param frames - Iterable of frames (freed automatically)
|
|
409
|
+
*
|
|
410
|
+
* @yields {Packet} Encoded packets (caller must free)
|
|
411
|
+
*
|
|
412
|
+
* @throws {Error} If encoder is closed
|
|
413
|
+
*
|
|
414
|
+
* @throws {FFmpegError} If encoding fails
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* // Basic encoding pipeline
|
|
419
|
+
* for (const packet of encoder.packetsSync(decoder.framesSync(packets))) {
|
|
420
|
+
* output.writePacketSync(packet);
|
|
421
|
+
* packet.free(); // Must free output packets
|
|
422
|
+
* }
|
|
423
|
+
* ```
|
|
424
|
+
*
|
|
425
|
+
* @example
|
|
426
|
+
* ```typescript
|
|
427
|
+
* // With frame filtering
|
|
428
|
+
* function* filteredFrames() {
|
|
429
|
+
* for (const frame of decoder.framesSync(packets)) {
|
|
430
|
+
* const filtered = filter.processSync(frame);
|
|
431
|
+
* if (filtered) {
|
|
432
|
+
* yield filtered;
|
|
433
|
+
* }
|
|
434
|
+
* frame.free();
|
|
435
|
+
* }
|
|
436
|
+
* }
|
|
437
|
+
*
|
|
438
|
+
* for (const packet of encoder.packetsSync(filteredFrames())) {
|
|
439
|
+
* output.writePacketSync(packet);
|
|
440
|
+
* packet.free();
|
|
441
|
+
* }
|
|
442
|
+
* ```
|
|
443
|
+
*
|
|
444
|
+
* @see {@link packets} For async version
|
|
445
|
+
*/
|
|
446
|
+
packetsSync(frames: Iterable<Frame>): Generator<Packet>;
|
|
290
447
|
/**
|
|
291
448
|
* Flush encoder and signal end-of-stream.
|
|
292
449
|
*
|
|
@@ -314,6 +471,33 @@ export declare class Encoder implements Disposable {
|
|
|
314
471
|
* @see {@link receive} For getting buffered packets
|
|
315
472
|
*/
|
|
316
473
|
flush(): Promise<void>;
|
|
474
|
+
/**
|
|
475
|
+
* Flush encoder and signal end-of-stream synchronously.
|
|
476
|
+
* Synchronous version of flush.
|
|
477
|
+
*
|
|
478
|
+
* Sends null frame to encoder to signal end-of-stream.
|
|
479
|
+
* Does nothing if encoder was never initialized or is closed.
|
|
480
|
+
* Must call receiveSync() to get remaining buffered packets.
|
|
481
|
+
*
|
|
482
|
+
* Direct mapping to avcodec_send_frame(NULL).
|
|
483
|
+
*
|
|
484
|
+
* @example
|
|
485
|
+
* ```typescript
|
|
486
|
+
* // Signal end of stream
|
|
487
|
+
* encoder.flushSync();
|
|
488
|
+
*
|
|
489
|
+
* // Then get remaining packets
|
|
490
|
+
* let packet;
|
|
491
|
+
* while ((packet = encoder.receiveSync()) !== null) {
|
|
492
|
+
* console.log('Got buffered packet');
|
|
493
|
+
* output.writePacketSync(packet);
|
|
494
|
+
* packet.free();
|
|
495
|
+
* }
|
|
496
|
+
* ```
|
|
497
|
+
*
|
|
498
|
+
* @see {@link flush} For async version
|
|
499
|
+
*/
|
|
500
|
+
flushSync(): void;
|
|
317
501
|
/**
|
|
318
502
|
* Flush all buffered packets as async generator.
|
|
319
503
|
*
|
|
@@ -337,6 +521,29 @@ export declare class Encoder implements Disposable {
|
|
|
337
521
|
* @see {@link packets} For complete pipeline
|
|
338
522
|
*/
|
|
339
523
|
flushPackets(): AsyncGenerator<Packet>;
|
|
524
|
+
/**
|
|
525
|
+
* Flush all buffered packets as generator synchronously.
|
|
526
|
+
* Synchronous version of flushPackets.
|
|
527
|
+
*
|
|
528
|
+
* Convenient sync iteration over remaining packets.
|
|
529
|
+
* Automatically handles flush and repeated receive calls.
|
|
530
|
+
* Returns immediately if encoder was never initialized or is closed.
|
|
531
|
+
*
|
|
532
|
+
* @yields {Packet} Buffered packets
|
|
533
|
+
*
|
|
534
|
+
* @example
|
|
535
|
+
* ```typescript
|
|
536
|
+
* // Flush at end of encoding
|
|
537
|
+
* for (const packet of encoder.flushPacketsSync()) {
|
|
538
|
+
* console.log('Processing buffered packet');
|
|
539
|
+
* output.writePacketSync(packet);
|
|
540
|
+
* packet.free();
|
|
541
|
+
* }
|
|
542
|
+
* ```
|
|
543
|
+
*
|
|
544
|
+
* @see {@link flushPackets} For async version
|
|
545
|
+
*/
|
|
546
|
+
flushPacketsSync(): Generator<Packet>;
|
|
340
547
|
/**
|
|
341
548
|
* Receive packet from encoder.
|
|
342
549
|
*
|
|
@@ -376,6 +583,45 @@ export declare class Encoder implements Disposable {
|
|
|
376
583
|
* @see {@link flush} For signaling end-of-stream
|
|
377
584
|
*/
|
|
378
585
|
receive(): Promise<Packet | null>;
|
|
586
|
+
/**
|
|
587
|
+
* Receive packet from encoder synchronously.
|
|
588
|
+
* Synchronous version of receive.
|
|
589
|
+
*
|
|
590
|
+
* Gets encoded packets from the codec's internal buffer.
|
|
591
|
+
* Handles packet cloning and error checking.
|
|
592
|
+
* Returns null if encoder is closed, not initialized, or no packets available.
|
|
593
|
+
* Call repeatedly until null to drain all buffered packets.
|
|
594
|
+
*
|
|
595
|
+
* Direct mapping to avcodec_receive_packet().
|
|
596
|
+
*
|
|
597
|
+
* @returns Cloned packet or null if no packets available
|
|
598
|
+
*
|
|
599
|
+
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
600
|
+
*
|
|
601
|
+
* @example
|
|
602
|
+
* ```typescript
|
|
603
|
+
* const packet = encoder.receiveSync();
|
|
604
|
+
* if (packet) {
|
|
605
|
+
* console.log(`Got packet with PTS: ${packet.pts}`);
|
|
606
|
+
* output.writePacketSync(packet);
|
|
607
|
+
* packet.free();
|
|
608
|
+
* }
|
|
609
|
+
* ```
|
|
610
|
+
*
|
|
611
|
+
* @example
|
|
612
|
+
* ```typescript
|
|
613
|
+
* // Drain all buffered packets
|
|
614
|
+
* let packet;
|
|
615
|
+
* while ((packet = encoder.receiveSync()) !== null) {
|
|
616
|
+
* console.log(`Packet size: ${packet.size}`);
|
|
617
|
+
* output.writePacketSync(packet);
|
|
618
|
+
* packet.free();
|
|
619
|
+
* }
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* @see {@link receive} For async version
|
|
623
|
+
*/
|
|
624
|
+
receiveSync(): Packet | null;
|
|
379
625
|
/**
|
|
380
626
|
* Close encoder and free resources.
|
|
381
627
|
*
|
|
@@ -410,6 +656,23 @@ export declare class Encoder implements Disposable {
|
|
|
410
656
|
* @internal
|
|
411
657
|
*/
|
|
412
658
|
private initialize;
|
|
659
|
+
/**
|
|
660
|
+
* Initialize encoder from first frame synchronously.
|
|
661
|
+
* Synchronous version of initialize.
|
|
662
|
+
*
|
|
663
|
+
* Sets codec context parameters from frame properties.
|
|
664
|
+
* Configures hardware context if present in frame.
|
|
665
|
+
* Opens encoder with accumulated options.
|
|
666
|
+
*
|
|
667
|
+
* @param frame - First frame to encode
|
|
668
|
+
*
|
|
669
|
+
* @throws {FFmpegError} If encoder open fails
|
|
670
|
+
*
|
|
671
|
+
* @internal
|
|
672
|
+
*
|
|
673
|
+
* @see {@link initialize} For async version
|
|
674
|
+
*/
|
|
675
|
+
private initializeSync;
|
|
413
676
|
/**
|
|
414
677
|
* Get encoder codec.
|
|
415
678
|
*
|