node-av 4.0.0 → 5.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 +23 -0
- package/binding.gyp +19 -11
- package/dist/api/bitstream-filter.d.ts +13 -12
- package/dist/api/bitstream-filter.js +33 -29
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +211 -96
- package/dist/api/decoder.js +396 -375
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/demuxer.d.ts +10 -10
- package/dist/api/demuxer.js +7 -10
- package/dist/api/demuxer.js.map +1 -1
- package/dist/api/encoder.d.ts +155 -122
- package/dist/api/encoder.js +368 -541
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-complex.d.ts +769 -0
- package/dist/api/filter-complex.js +1596 -0
- package/dist/api/filter-complex.js.map +1 -0
- package/dist/api/filter-presets.d.ts +68 -0
- package/dist/api/filter-presets.js +96 -0
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +183 -113
- package/dist/api/filter.js +347 -365
- package/dist/api/filter.js.map +1 -1
- package/dist/api/fmp4-stream.d.ts +2 -2
- package/dist/api/fmp4-stream.js.map +1 -1
- package/dist/api/index.d.ts +2 -0
- package/dist/api/index.js +3 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +3 -3
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/muxer.d.ts +10 -10
- package/dist/api/muxer.js +6 -6
- package/dist/api/muxer.js.map +1 -1
- package/dist/api/pipeline.d.ts +2 -2
- package/dist/api/pipeline.js +22 -22
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/rtp-stream.d.ts +2 -2
- package/dist/api/rtp-stream.js.map +1 -1
- package/dist/api/types.d.ts +63 -7
- package/dist/api/utilities/audio-sample.d.ts +10 -0
- package/dist/api/utilities/audio-sample.js +10 -0
- package/dist/api/utilities/audio-sample.js.map +1 -1
- package/dist/api/utilities/channel-layout.d.ts +1 -0
- package/dist/api/utilities/channel-layout.js +1 -0
- package/dist/api/utilities/channel-layout.js.map +1 -1
- package/dist/api/utilities/image.d.ts +38 -0
- package/dist/api/utilities/image.js +38 -0
- package/dist/api/utilities/image.js.map +1 -1
- package/dist/api/utilities/index.d.ts +1 -0
- package/dist/api/utilities/index.js +2 -0
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -0
- package/dist/api/utilities/media-type.js +1 -0
- package/dist/api/utilities/media-type.js.map +1 -1
- package/dist/api/utilities/pixel-format.d.ts +3 -0
- package/dist/api/utilities/pixel-format.js +3 -0
- package/dist/api/utilities/pixel-format.js.map +1 -1
- package/dist/api/utilities/sample-format.d.ts +5 -0
- package/dist/api/utilities/sample-format.js +5 -0
- package/dist/api/utilities/sample-format.js.map +1 -1
- package/dist/api/utilities/scheduler.d.ts +21 -52
- package/dist/api/utilities/scheduler.js +20 -58
- package/dist/api/utilities/scheduler.js.map +1 -1
- package/dist/api/utilities/streaming.d.ts +32 -1
- package/dist/api/utilities/streaming.js +32 -1
- package/dist/api/utilities/streaming.js.map +1 -1
- package/dist/api/utilities/timestamp.d.ts +14 -0
- package/dist/api/utilities/timestamp.js +14 -0
- package/dist/api/utilities/timestamp.js.map +1 -1
- package/dist/api/utilities/whisper-model.d.ts +310 -0
- package/dist/api/utilities/whisper-model.js +528 -0
- package/dist/api/utilities/whisper-model.js.map +1 -0
- package/dist/api/whisper.d.ts +324 -0
- package/dist/api/whisper.js +362 -0
- package/dist/api/whisper.js.map +1 -0
- package/dist/constants/constants.d.ts +3 -1
- package/dist/constants/constants.js +1 -0
- package/dist/constants/constants.js.map +1 -1
- package/dist/ffmpeg/index.d.ts +3 -3
- package/dist/ffmpeg/index.js +3 -3
- package/dist/ffmpeg/utils.d.ts +27 -0
- package/dist/ffmpeg/utils.js +28 -16
- package/dist/ffmpeg/utils.js.map +1 -1
- package/dist/lib/binding.d.ts +4 -4
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +47 -1
- package/dist/lib/codec-parameters.js +55 -0
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/fifo.d.ts +416 -0
- package/dist/lib/fifo.js +453 -0
- package/dist/lib/fifo.js.map +1 -0
- package/dist/lib/frame.d.ts +96 -1
- package/dist/lib/frame.js +139 -1
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/native-types.d.ts +29 -2
- package/dist/lib/rational.d.ts +18 -0
- package/dist/lib/rational.js +19 -0
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/types.d.ts +23 -1
- package/install/check.js +2 -2
- package/package.json +30 -20
package/dist/api/encoder.d.ts
CHANGED
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import { CodecContext } from '../lib/codec-context.js';
|
|
2
2
|
import { Codec } from '../lib/codec.js';
|
|
3
|
+
import { Frame } from '../lib/frame.js';
|
|
3
4
|
import { Packet } from '../lib/packet.js';
|
|
4
5
|
import { SchedulerControl } from './utilities/scheduler.js';
|
|
5
|
-
import type { AVCodecFlag, AVCodecID, FFEncoderCodec } from '../constants/index.js';
|
|
6
|
-
import type { Frame } from '../lib/frame.js';
|
|
6
|
+
import type { AVCodecFlag, AVCodecID, EOFSignal, FFEncoderCodec } from '../constants/index.js';
|
|
7
7
|
import type { Muxer } from './muxer.js';
|
|
8
8
|
import type { EncoderOptions } from './types.js';
|
|
9
9
|
/**
|
|
@@ -342,28 +342,31 @@ export declare class Encoder implements Disposable {
|
|
|
342
342
|
*/
|
|
343
343
|
isReady(): boolean;
|
|
344
344
|
/**
|
|
345
|
-
*
|
|
345
|
+
* Send a frame to the encoder.
|
|
346
346
|
*
|
|
347
|
-
* Sends a frame to the encoder
|
|
347
|
+
* Sends a raw frame to the encoder for encoding.
|
|
348
|
+
* Does not return encoded packets - use {@link receive} to retrieve packets.
|
|
348
349
|
* On first frame, automatically initializes encoder with frame properties.
|
|
349
|
-
*
|
|
350
|
+
* A single frame can produce zero, one, or multiple packets depending on codec buffering.
|
|
350
351
|
*
|
|
351
|
-
* **
|
|
352
|
-
*
|
|
353
|
-
* To receive all packets from a frame, use {@link encodeAll} or {@link packets} instead.
|
|
352
|
+
* **Important**: This method only SENDS the frame to the encoder.
|
|
353
|
+
* You must call {@link receive} separately (potentially multiple times) to get encoded packets.
|
|
354
354
|
*
|
|
355
|
-
* Direct mapping to avcodec_send_frame()
|
|
356
|
-
*
|
|
357
|
-
* @param frame - Raw frame to encode (or null to flush)
|
|
355
|
+
* Direct mapping to avcodec_send_frame().
|
|
358
356
|
*
|
|
359
|
-
* @
|
|
357
|
+
* @param frame - Raw frame to send to encoder
|
|
360
358
|
*
|
|
361
|
-
* @throws {FFmpegError} If
|
|
359
|
+
* @throws {FFmpegError} If sending frame fails
|
|
362
360
|
*
|
|
363
361
|
* @example
|
|
364
362
|
* ```typescript
|
|
365
|
-
*
|
|
366
|
-
*
|
|
363
|
+
* // Send frame and receive packets
|
|
364
|
+
* await encoder.encode(frame);
|
|
365
|
+
*
|
|
366
|
+
* // Receive all available packets
|
|
367
|
+
* while (true) {
|
|
368
|
+
* const packet = await encoder.receive();
|
|
369
|
+
* if (!packet) break;
|
|
367
370
|
* console.log(`Encoded packet with PTS: ${packet.pts}`);
|
|
368
371
|
* await output.writePacket(packet);
|
|
369
372
|
* packet.free();
|
|
@@ -372,10 +375,13 @@ export declare class Encoder implements Disposable {
|
|
|
372
375
|
*
|
|
373
376
|
* @example
|
|
374
377
|
* ```typescript
|
|
375
|
-
* // Encode loop
|
|
376
378
|
* for await (const frame of decoder.frames(input.packets())) {
|
|
377
|
-
*
|
|
378
|
-
*
|
|
379
|
+
* // Send frame
|
|
380
|
+
* await encoder.encode(frame);
|
|
381
|
+
*
|
|
382
|
+
* // Receive available packets
|
|
383
|
+
* let packet;
|
|
384
|
+
* while ((packet = await encoder.receive())) {
|
|
379
385
|
* await output.writePacket(packet);
|
|
380
386
|
* packet.free();
|
|
381
387
|
* }
|
|
@@ -383,61 +389,52 @@ export declare class Encoder implements Disposable {
|
|
|
383
389
|
* }
|
|
384
390
|
* ```
|
|
385
391
|
*
|
|
386
|
-
* @see {@link
|
|
392
|
+
* @see {@link receive} For receiving encoded packets
|
|
393
|
+
* @see {@link encodeAll} For combined send+receive operation
|
|
387
394
|
* @see {@link packets} For automatic frame iteration
|
|
388
395
|
* @see {@link flush} For end-of-stream handling
|
|
389
396
|
* @see {@link encodeSync} For synchronous version
|
|
390
397
|
*/
|
|
391
|
-
encode(frame: Frame
|
|
398
|
+
encode(frame: Frame): Promise<void>;
|
|
392
399
|
/**
|
|
393
|
-
*
|
|
400
|
+
* Send a frame to the encoder synchronously.
|
|
394
401
|
* Synchronous version of encode.
|
|
395
402
|
*
|
|
396
|
-
* Sends a frame to the encoder
|
|
403
|
+
* Sends a raw frame to the encoder for encoding.
|
|
404
|
+
* Does not return encoded packets - use {@link receiveSync} to retrieve packets.
|
|
397
405
|
* On first frame, automatically initializes encoder with frame properties.
|
|
398
|
-
*
|
|
406
|
+
* A single frame can produce zero, one, or multiple packets depending on codec buffering.
|
|
399
407
|
*
|
|
400
|
-
* **
|
|
401
|
-
*
|
|
402
|
-
* To receive all packets from a frame, use {@link encodeAllSync} or {@link packetsSync} instead.
|
|
408
|
+
* **Important**: This method only SENDS the frame to the encoder.
|
|
409
|
+
* You must call {@link receiveSync} separately (potentially multiple times) to get encoded packets.
|
|
403
410
|
*
|
|
404
|
-
* Direct mapping to avcodec_send_frame()
|
|
405
|
-
*
|
|
406
|
-
* @param frame - Raw frame to encode (or null to flush)
|
|
411
|
+
* Direct mapping to avcodec_send_frame().
|
|
407
412
|
*
|
|
408
|
-
* @
|
|
413
|
+
* @param frame - Raw frame to send to encoder
|
|
409
414
|
*
|
|
410
|
-
* @throws {FFmpegError} If
|
|
415
|
+
* @throws {FFmpegError} If sending frame fails
|
|
411
416
|
*
|
|
412
417
|
* @example
|
|
413
418
|
* ```typescript
|
|
414
|
-
*
|
|
415
|
-
*
|
|
419
|
+
* // Send frame and receive packets
|
|
420
|
+
* encoder.encodeSync(frame);
|
|
421
|
+
*
|
|
422
|
+
* // Receive all available packets
|
|
423
|
+
* let packet;
|
|
424
|
+
* while ((packet = encoder.receiveSync())) {
|
|
416
425
|
* console.log(`Encoded packet with PTS: ${packet.pts}`);
|
|
417
426
|
* output.writePacketSync(packet);
|
|
418
427
|
* packet.free();
|
|
419
428
|
* }
|
|
420
429
|
* ```
|
|
421
430
|
*
|
|
422
|
-
* @
|
|
423
|
-
*
|
|
424
|
-
* // Encode loop
|
|
425
|
-
* for (const frame of decoder.framesSync(packets)) {
|
|
426
|
-
* const packet = encoder.encodeSync(frame);
|
|
427
|
-
* if (packet) {
|
|
428
|
-
* output.writePacketSync(packet);
|
|
429
|
-
* packet.free();
|
|
430
|
-
* }
|
|
431
|
-
* frame.free();
|
|
432
|
-
* }
|
|
433
|
-
* ```
|
|
434
|
-
*
|
|
435
|
-
* @see {@link encodeAllSync} For multiple packet encoding
|
|
431
|
+
* @see {@link receiveSync} For receiving encoded packets
|
|
432
|
+
* @see {@link encodeAllSync} For combined send+receive operation
|
|
436
433
|
* @see {@link packetsSync} For automatic frame iteration
|
|
437
434
|
* @see {@link flushSync} For end-of-stream handling
|
|
438
435
|
* @see {@link encode} For async version
|
|
439
436
|
*/
|
|
440
|
-
encodeSync(frame: Frame
|
|
437
|
+
encodeSync(frame: Frame): void;
|
|
441
438
|
/**
|
|
442
439
|
* Encode a frame to packets.
|
|
443
440
|
*
|
|
@@ -533,20 +530,28 @@ export declare class Encoder implements Disposable {
|
|
|
533
530
|
* Encode frame stream to packet stream.
|
|
534
531
|
*
|
|
535
532
|
* High-level async generator for complete encoding pipeline.
|
|
536
|
-
*
|
|
537
|
-
* and flushes buffered packets at end.
|
|
533
|
+
* Encoder is only flushed when EOF (null) signal is explicitly received.
|
|
538
534
|
* Primary interface for stream-based encoding.
|
|
539
535
|
*
|
|
540
|
-
*
|
|
536
|
+
* **EOF Handling:**
|
|
537
|
+
* - Send null to flush encoder and get remaining buffered packets
|
|
538
|
+
* - Generator yields null after flushing when null is received
|
|
539
|
+
* - No automatic flushing - encoder stays open until EOF or close()
|
|
540
|
+
*
|
|
541
|
+
* @param frames - Async iterable of frames, single frame, or null to flush
|
|
541
542
|
*
|
|
542
|
-
* @yields {Packet} Encoded packets
|
|
543
|
+
* @yields {Packet | null} Encoded packets, followed by null when explicitly flushed
|
|
543
544
|
*
|
|
544
545
|
* @throws {FFmpegError} If encoding fails
|
|
545
546
|
*
|
|
546
547
|
* @example
|
|
547
548
|
* ```typescript
|
|
548
|
-
* //
|
|
549
|
+
* // Stream of frames with automatic EOF propagation
|
|
549
550
|
* for await (const packet of encoder.packets(decoder.frames(input.packets()))) {
|
|
551
|
+
* if (packet === null) {
|
|
552
|
+
* console.log('Encoder flushed');
|
|
553
|
+
* break;
|
|
554
|
+
* }
|
|
550
555
|
* await output.writePacket(packet);
|
|
551
556
|
* packet.free(); // Must free output packets
|
|
552
557
|
* }
|
|
@@ -554,61 +559,60 @@ export declare class Encoder implements Disposable {
|
|
|
554
559
|
*
|
|
555
560
|
* @example
|
|
556
561
|
* ```typescript
|
|
557
|
-
* //
|
|
558
|
-
*
|
|
559
|
-
* for await (const frame of decoder.frames(input.packets())) {
|
|
560
|
-
* const filtered = await filter.process(frame);
|
|
561
|
-
* if (filtered) {
|
|
562
|
-
* yield filtered;
|
|
563
|
-
* }
|
|
564
|
-
* frame.free();
|
|
565
|
-
* }
|
|
566
|
-
* }
|
|
567
|
-
*
|
|
568
|
-
* for await (const packet of encoder.packets(filteredFrames())) {
|
|
562
|
+
* // Single frame - no automatic flush
|
|
563
|
+
* for await (const packet of encoder.packets(singleFrame)) {
|
|
569
564
|
* await output.writePacket(packet);
|
|
570
565
|
* packet.free();
|
|
571
566
|
* }
|
|
567
|
+
* // Encoder remains open, buffered packets not flushed
|
|
572
568
|
* ```
|
|
573
569
|
*
|
|
574
570
|
* @example
|
|
575
571
|
* ```typescript
|
|
576
|
-
* //
|
|
577
|
-
*
|
|
578
|
-
*
|
|
579
|
-
*
|
|
580
|
-
*
|
|
581
|
-
*
|
|
582
|
-
*
|
|
583
|
-
* output
|
|
584
|
-
*
|
|
585
|
-
*
|
|
572
|
+
* // Explicit flush with EOF
|
|
573
|
+
* for await (const packet of encoder.packets(null)) {
|
|
574
|
+
* if (packet === null) {
|
|
575
|
+
* console.log('All buffered packets flushed');
|
|
576
|
+
* break;
|
|
577
|
+
* }
|
|
578
|
+
* console.log('Buffered packet:', packet.pts);
|
|
579
|
+
* await output.writePacket(packet);
|
|
580
|
+
* packet.free();
|
|
581
|
+
* }
|
|
586
582
|
* ```
|
|
587
583
|
*
|
|
588
584
|
* @see {@link encode} For single frame encoding
|
|
589
585
|
* @see {@link Decoder.frames} For frame source
|
|
590
586
|
* @see {@link packetsSync} For sync version
|
|
591
587
|
*/
|
|
592
|
-
packets(frames: AsyncIterable<Frame | null>): AsyncGenerator<Packet | null>;
|
|
588
|
+
packets(frames: AsyncIterable<Frame | null> | Frame | null): AsyncGenerator<Packet | null>;
|
|
593
589
|
/**
|
|
594
590
|
* Encode frame stream to packet stream synchronously.
|
|
595
591
|
* Synchronous version of packets.
|
|
596
592
|
*
|
|
597
593
|
* High-level sync generator for complete encoding pipeline.
|
|
598
|
-
*
|
|
599
|
-
* and flushes buffered packets at end.
|
|
594
|
+
* Encoder is only flushed when EOF (null) signal is explicitly received.
|
|
600
595
|
* Primary interface for stream-based encoding.
|
|
601
596
|
*
|
|
602
|
-
*
|
|
597
|
+
* **EOF Handling:**
|
|
598
|
+
* - Send null to flush encoder and get remaining buffered packets
|
|
599
|
+
* - Generator yields null after flushing when null is received
|
|
600
|
+
* - No automatic flushing - encoder stays open until EOF or close()
|
|
603
601
|
*
|
|
604
|
-
* @
|
|
602
|
+
* @param frames - Iterable of frames, single frame, or null to flush
|
|
603
|
+
*
|
|
604
|
+
* @yields {Packet | null} Encoded packets, followed by null when explicitly flushed
|
|
605
605
|
*
|
|
606
606
|
* @throws {FFmpegError} If encoding fails
|
|
607
607
|
*
|
|
608
608
|
* @example
|
|
609
609
|
* ```typescript
|
|
610
|
-
* //
|
|
610
|
+
* // Stream of frames with automatic EOF propagation
|
|
611
611
|
* for (const packet of encoder.packetsSync(decoder.framesSync(packets))) {
|
|
612
|
+
* if (packet === null) {
|
|
613
|
+
* console.log('Encoder flushed');
|
|
614
|
+
* break;
|
|
615
|
+
* }
|
|
612
616
|
* output.writePacketSync(packet);
|
|
613
617
|
* packet.free(); // Must free output packets
|
|
614
618
|
* }
|
|
@@ -616,18 +620,23 @@ export declare class Encoder implements Disposable {
|
|
|
616
620
|
*
|
|
617
621
|
* @example
|
|
618
622
|
* ```typescript
|
|
619
|
-
* //
|
|
620
|
-
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
* if (filtered) {
|
|
624
|
-
* yield filtered;
|
|
625
|
-
* }
|
|
626
|
-
* frame.free();
|
|
627
|
-
* }
|
|
623
|
+
* // Single frame - no automatic flush
|
|
624
|
+
* for (const packet of encoder.packetsSync(singleFrame)) {
|
|
625
|
+
* output.writePacketSync(packet);
|
|
626
|
+
* packet.free();
|
|
628
627
|
* }
|
|
628
|
+
* // Encoder remains open, buffered packets not flushed
|
|
629
|
+
* ```
|
|
629
630
|
*
|
|
630
|
-
*
|
|
631
|
+
* @example
|
|
632
|
+
* ```typescript
|
|
633
|
+
* // Explicit flush with EOF
|
|
634
|
+
* for (const packet of encoder.packetsSync(null)) {
|
|
635
|
+
* if (packet === null) {
|
|
636
|
+
* console.log('All buffered packets flushed');
|
|
637
|
+
* break;
|
|
638
|
+
* }
|
|
639
|
+
* console.log('Buffered packet:', packet.pts);
|
|
631
640
|
* output.writePacketSync(packet);
|
|
632
641
|
* packet.free();
|
|
633
642
|
* }
|
|
@@ -637,7 +646,7 @@ export declare class Encoder implements Disposable {
|
|
|
637
646
|
* @see {@link Decoder.framesSync} For frame source
|
|
638
647
|
* @see {@link packets} For async version
|
|
639
648
|
*/
|
|
640
|
-
packetsSync(frames: Iterable<Frame | null>): Generator<Packet | null>;
|
|
649
|
+
packetsSync(frames: Iterable<Frame | null> | Frame | null): Generator<Packet | null>;
|
|
641
650
|
/**
|
|
642
651
|
* Flush encoder and signal end-of-stream.
|
|
643
652
|
*
|
|
@@ -749,19 +758,25 @@ export declare class Encoder implements Disposable {
|
|
|
749
758
|
*
|
|
750
759
|
* Gets encoded packets from the codec's internal buffer.
|
|
751
760
|
* Handles packet cloning and error checking.
|
|
752
|
-
*
|
|
753
|
-
*
|
|
761
|
+
* Implements FFmpeg's send/receive pattern.
|
|
762
|
+
*
|
|
763
|
+
* **Return Values:**
|
|
764
|
+
* - `Packet` - Successfully encoded packet (AVERROR >= 0)
|
|
765
|
+
* - `null` - Need more input frames (AVERROR_EAGAIN), or encoder not initialized
|
|
766
|
+
* - `undefined` - End of stream reached (AVERROR_EOF), or encoder is closed
|
|
754
767
|
*
|
|
755
768
|
* Direct mapping to avcodec_receive_packet().
|
|
756
769
|
*
|
|
757
|
-
* @returns Cloned packet or
|
|
770
|
+
* @returns Cloned packet, null if need more data, or undefined if stream ended
|
|
758
771
|
*
|
|
759
772
|
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
760
773
|
*
|
|
761
774
|
* @example
|
|
762
775
|
* ```typescript
|
|
763
|
-
*
|
|
764
|
-
*
|
|
776
|
+
* // Process all buffered packets
|
|
777
|
+
* while (true) {
|
|
778
|
+
* const packet = await encoder.receive();
|
|
779
|
+
* if (!packet) break; // Stop on EAGAIN or EOF
|
|
765
780
|
* console.log(`Got packet with PTS: ${packet.pts}`);
|
|
766
781
|
* await output.writePacket(packet);
|
|
767
782
|
* packet.free();
|
|
@@ -770,10 +785,14 @@ export declare class Encoder implements Disposable {
|
|
|
770
785
|
*
|
|
771
786
|
* @example
|
|
772
787
|
* ```typescript
|
|
773
|
-
* //
|
|
774
|
-
*
|
|
775
|
-
*
|
|
776
|
-
* console.log(
|
|
788
|
+
* // Handle each return value explicitly
|
|
789
|
+
* const packet = await encoder.receive();
|
|
790
|
+
* if (packet === EOF) {
|
|
791
|
+
* console.log('Encoder stream ended');
|
|
792
|
+
* } else if (packet === null) {
|
|
793
|
+
* console.log('Need more input frames');
|
|
794
|
+
* } else {
|
|
795
|
+
* console.log(`Got packet: pts=${packet.pts}`);
|
|
777
796
|
* await output.writePacket(packet);
|
|
778
797
|
* packet.free();
|
|
779
798
|
* }
|
|
@@ -782,27 +801,34 @@ export declare class Encoder implements Disposable {
|
|
|
782
801
|
* @see {@link encode} For sending frames and receiving packets
|
|
783
802
|
* @see {@link flush} For signaling end-of-stream
|
|
784
803
|
* @see {@link receiveSync} For synchronous version
|
|
804
|
+
* @see {@link EOF} For end-of-stream signal
|
|
785
805
|
*/
|
|
786
|
-
receive(): Promise<Packet | null>;
|
|
806
|
+
receive(): Promise<Packet | EOFSignal | null>;
|
|
787
807
|
/**
|
|
788
808
|
* Receive packet from encoder synchronously.
|
|
789
809
|
* Synchronous version of receive.
|
|
790
810
|
*
|
|
791
811
|
* Gets encoded packets from the codec's internal buffer.
|
|
792
812
|
* Handles packet cloning and error checking.
|
|
793
|
-
*
|
|
794
|
-
*
|
|
813
|
+
* Implements FFmpeg's send/receive pattern.
|
|
814
|
+
*
|
|
815
|
+
* **Return Values:**
|
|
816
|
+
* - `Packet` - Successfully encoded packet (AVERROR >= 0)
|
|
817
|
+
* - `null` - Need more input frames (AVERROR_EAGAIN), or encoder not initialized
|
|
818
|
+
* - `undefined` - End of stream reached (AVERROR_EOF), or encoder is closed
|
|
795
819
|
*
|
|
796
820
|
* Direct mapping to avcodec_receive_packet().
|
|
797
821
|
*
|
|
798
|
-
* @returns Cloned packet or
|
|
822
|
+
* @returns Cloned packet, null if need more data, or undefined if stream ended
|
|
799
823
|
*
|
|
800
824
|
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
801
825
|
*
|
|
802
826
|
* @example
|
|
803
827
|
* ```typescript
|
|
804
|
-
*
|
|
805
|
-
*
|
|
828
|
+
* // Process all buffered packets
|
|
829
|
+
* while (true) {
|
|
830
|
+
* const packet = encoder.receiveSync();
|
|
831
|
+
* if (!packet) break; // Stop on EAGAIN or EOF
|
|
806
832
|
* console.log(`Got packet with PTS: ${packet.pts}`);
|
|
807
833
|
* output.writePacketSync(packet);
|
|
808
834
|
* packet.free();
|
|
@@ -811,10 +837,14 @@ export declare class Encoder implements Disposable {
|
|
|
811
837
|
*
|
|
812
838
|
* @example
|
|
813
839
|
* ```typescript
|
|
814
|
-
* //
|
|
815
|
-
*
|
|
816
|
-
*
|
|
817
|
-
* console.log(
|
|
840
|
+
* // Handle each return value explicitly
|
|
841
|
+
* const packet = encoder.receiveSync();
|
|
842
|
+
* if (packet === EOF) {
|
|
843
|
+
* console.log('Encoder stream ended');
|
|
844
|
+
* } else if (packet === null) {
|
|
845
|
+
* console.log('Need more input frames');
|
|
846
|
+
* } else {
|
|
847
|
+
* console.log(`Got packet: pts=${packet.pts}`);
|
|
818
848
|
* output.writePacketSync(packet);
|
|
819
849
|
* packet.free();
|
|
820
850
|
* }
|
|
@@ -823,8 +853,9 @@ export declare class Encoder implements Disposable {
|
|
|
823
853
|
* @see {@link encodeSync} For sending frames and receiving packets
|
|
824
854
|
* @see {@link flushSync} For signaling end-of-stream
|
|
825
855
|
* @see {@link receive} For async version
|
|
856
|
+
* @see {@link EOF} For end-of-stream signal
|
|
826
857
|
*/
|
|
827
|
-
receiveSync(): Packet | null;
|
|
858
|
+
receiveSync(): Packet | EOFSignal | null;
|
|
828
859
|
/**
|
|
829
860
|
* Pipe encoded packets to muxer.
|
|
830
861
|
*
|
|
@@ -894,9 +925,19 @@ export declare class Encoder implements Disposable {
|
|
|
894
925
|
*/
|
|
895
926
|
private runWorker;
|
|
896
927
|
/**
|
|
897
|
-
* Send frame to input queue.
|
|
928
|
+
* Send frame to input queue or flush the pipeline.
|
|
898
929
|
*
|
|
899
|
-
*
|
|
930
|
+
* When frame is provided, queues it for encoding.
|
|
931
|
+
* When null is provided, triggers flush sequence:
|
|
932
|
+
* - Closes input queue
|
|
933
|
+
* - Waits for worker completion
|
|
934
|
+
* - Flushes encoder and sends remaining packets to output queue
|
|
935
|
+
* - Closes output queue
|
|
936
|
+
* - Waits for pipeTo task completion (writes to muxer)
|
|
937
|
+
*
|
|
938
|
+
* Used by scheduler system for pipeline control.
|
|
939
|
+
*
|
|
940
|
+
* @param frame - Frame to send, or null to flush
|
|
900
941
|
*
|
|
901
942
|
* @internal
|
|
902
943
|
*/
|
|
@@ -909,14 +950,6 @@ export declare class Encoder implements Disposable {
|
|
|
909
950
|
* @internal
|
|
910
951
|
*/
|
|
911
952
|
private receiveFromQueue;
|
|
912
|
-
/**
|
|
913
|
-
* Flush the entire filter pipeline.
|
|
914
|
-
*
|
|
915
|
-
* Propagates flush through worker, output queue, and next component.
|
|
916
|
-
*
|
|
917
|
-
* @internal
|
|
918
|
-
*/
|
|
919
|
-
private flushPipeline;
|
|
920
953
|
/**
|
|
921
954
|
* Initialize encoder from first frame.
|
|
922
955
|
*
|