node-av 1.1.0 → 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.
- package/README.md +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +168 -38
- package/dist/api/pipeline.js +238 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +21 -187
- package/dist/api/utils.d.ts +1 -2
- package/dist/api/utils.js +9 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.js +5 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/bitstream-filter-context.d.ts +139 -184
- package/dist/lib/bitstream-filter-context.js +139 -188
- package/dist/lib/bitstream-filter-context.js.map +1 -1
- package/dist/lib/bitstream-filter.d.ts +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- package/dist/lib/filter-graph.js +253 -294
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter-inout.d.ts +87 -95
- package/dist/lib/filter-inout.js +87 -95
- package/dist/lib/filter-inout.js.map +1 -1
- package/dist/lib/filter.d.ts +93 -111
- package/dist/lib/filter.js +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- package/dist/lib/hardware-device-context.js +149 -203
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/hardware-frames-context.d.ts +170 -180
- package/dist/lib/hardware-frames-context.js +171 -181
- package/dist/lib/hardware-frames-context.js.map +1 -1
- package/dist/lib/index.d.ts +2 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- package/dist/lib/packet.js +172 -241
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/rational.d.ts +0 -2
- package/dist/lib/rational.js +0 -2
- package/dist/lib/rational.js.map +1 -1
- package/dist/lib/software-resample-context.d.ts +241 -325
- package/dist/lib/software-resample-context.js +242 -326
- package/dist/lib/software-resample-context.js.map +1 -1
- package/dist/lib/software-scale-context.d.ts +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/utilities.d.ts +372 -181
- package/dist/lib/utilities.js +373 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/package.json +21 -12
- package/release_notes.md +43 -59
- package/CHANGELOG.md +0 -8
package/dist/api/encoder.d.ts
CHANGED
|
@@ -1,310 +1,394 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Encoder - High-level wrapper for media encoding
|
|
3
|
-
*
|
|
4
|
-
* Simplifies FFmpeg's encoding API with automatic codec selection,
|
|
5
|
-
* parameter configuration, and packet management.
|
|
6
|
-
*
|
|
7
|
-
* Handles codec initialization, frame encoding, and packet output.
|
|
8
|
-
* Supports hardware acceleration and zero-copy transcoding.
|
|
9
|
-
*
|
|
10
|
-
* @module api/encoder
|
|
11
|
-
*/
|
|
12
1
|
import { Codec, CodecContext, Packet } from '../lib/index.js';
|
|
13
|
-
import type { AVCodecID
|
|
2
|
+
import type { AVCodecID } from '../constants/constants.js';
|
|
14
3
|
import type { FFEncoderCodec } from '../constants/encoders.js';
|
|
15
4
|
import type { Frame } from '../lib/index.js';
|
|
16
5
|
import type { EncoderOptions, StreamInfo } from './types.js';
|
|
17
6
|
/**
|
|
18
|
-
* High-level encoder for
|
|
19
|
-
*
|
|
20
|
-
* Handles codec initialization, frame encoding, and packet output.
|
|
21
|
-
* Supports various codecs with flexible configuration options.
|
|
7
|
+
* High-level encoder for audio and video streams.
|
|
22
8
|
*
|
|
23
|
-
*
|
|
24
|
-
*
|
|
9
|
+
* Provides a simplified interface for encoding media frames to packets.
|
|
10
|
+
* Handles codec initialization, hardware acceleration setup, and packet management.
|
|
11
|
+
* Supports both synchronous frame-by-frame encoding and async iteration over packets.
|
|
12
|
+
* Essential component in media processing pipelines for converting raw frames to compressed data.
|
|
25
13
|
*
|
|
26
14
|
* @example
|
|
27
15
|
* ```typescript
|
|
16
|
+
* import { Encoder } from 'node-av/api';
|
|
17
|
+
* import { AV_CODEC_ID_H264 } from 'node-av/constants';
|
|
18
|
+
*
|
|
28
19
|
* // Create H.264 encoder
|
|
29
20
|
* const encoder = await Encoder.create('libx264', {
|
|
21
|
+
* type: 'video',
|
|
30
22
|
* width: 1920,
|
|
31
23
|
* height: 1080,
|
|
32
|
-
* pixelFormat:
|
|
24
|
+
* pixelFormat: AV_PIX_FMT_YUV420P,
|
|
25
|
+
* timeBase: { num: 1, den: 30 },
|
|
26
|
+
* frameRate: { num: 30, den: 1 }
|
|
27
|
+
* }, {
|
|
33
28
|
* bitrate: '5M',
|
|
34
|
-
* gopSize: 60
|
|
35
|
-
* options: {
|
|
36
|
-
* preset: 'fast',
|
|
37
|
-
* crf: 23
|
|
38
|
-
* }
|
|
29
|
+
* gopSize: 60
|
|
39
30
|
* });
|
|
40
31
|
*
|
|
41
32
|
* // Encode frames
|
|
42
33
|
* const packet = await encoder.encode(frame);
|
|
43
34
|
* if (packet) {
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
* // Flush encoder
|
|
48
|
-
* let packet;
|
|
49
|
-
* while ((packet = await encoder.flush()) !== null) {
|
|
50
|
-
* // Process final packets
|
|
35
|
+
* await output.writePacket(packet);
|
|
36
|
+
* packet.free();
|
|
51
37
|
* }
|
|
52
|
-
* encoder.close();
|
|
53
38
|
* ```
|
|
54
39
|
*
|
|
55
40
|
* @example
|
|
56
41
|
* ```typescript
|
|
57
|
-
* //
|
|
58
|
-
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
42
|
+
* // Hardware-accelerated encoding
|
|
43
|
+
* import { HardwareContext } from 'node-av/api';
|
|
44
|
+
* import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
|
|
45
|
+
*
|
|
46
|
+
* const hw = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
|
|
47
|
+
* const encoder = await Encoder.create('h264_nvenc', streamInfo, {
|
|
48
|
+
* hardware: hw,
|
|
49
|
+
* bitrate: '10M'
|
|
65
50
|
* });
|
|
66
|
-
*
|
|
67
|
-
*
|
|
68
|
-
*
|
|
51
|
+
*
|
|
52
|
+
* // Frames with hw_frames_ctx will be encoded on GPU
|
|
53
|
+
* for await (const packet of encoder.packets(frames)) {
|
|
54
|
+
* await output.writePacket(packet);
|
|
55
|
+
* packet.free();
|
|
56
|
+
* }
|
|
69
57
|
* ```
|
|
58
|
+
*
|
|
59
|
+
* @see {@link Decoder} For decoding packets to frames
|
|
60
|
+
* @see {@link MediaOutput} For writing encoded packets
|
|
61
|
+
* @see {@link HardwareContext} For GPU acceleration
|
|
70
62
|
*/
|
|
71
63
|
export declare class Encoder implements Disposable {
|
|
72
64
|
private codecContext;
|
|
73
65
|
private packet;
|
|
74
|
-
private
|
|
66
|
+
private codec;
|
|
75
67
|
private isOpen;
|
|
76
|
-
private supportedFormats;
|
|
77
|
-
private preferredFormat?;
|
|
78
68
|
private hardware?;
|
|
79
69
|
/**
|
|
80
|
-
*
|
|
81
|
-
*
|
|
82
|
-
*
|
|
83
|
-
*
|
|
84
|
-
* @param codecContext - Initialized codec context
|
|
85
|
-
* @param codecName - Name of the codec
|
|
86
|
-
* @param hardware - Optional hardware context for hardware pixel format
|
|
70
|
+
* @param codecContext - Configured codec context
|
|
71
|
+
* @param codec - Encoder codec
|
|
72
|
+
* @param hardware - Optional hardware context
|
|
73
|
+
* @internal
|
|
87
74
|
*/
|
|
88
75
|
private constructor();
|
|
89
76
|
/**
|
|
90
77
|
* Create an encoder with specified codec and options.
|
|
91
78
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
79
|
+
* Initializes an encoder with the appropriate codec and configuration.
|
|
80
|
+
* Automatically configures parameters based on input stream info.
|
|
81
|
+
* Handles hardware acceleration setup if provided.
|
|
94
82
|
*
|
|
95
|
-
*
|
|
96
|
-
* configures the context with provided options, and opens it.
|
|
97
|
-
* Handles hardware setup including shared frames context for zero-copy.
|
|
83
|
+
* Direct mapping to avcodec_find_encoder_by_name() or avcodec_find_encoder().
|
|
98
84
|
*
|
|
99
|
-
* @param encoderCodec - Codec to use for encoding
|
|
100
|
-
* @param input - Stream
|
|
85
|
+
* @param encoderCodec - Codec name, ID, or instance to use for encoding
|
|
86
|
+
* @param input - Stream information to configure encoder
|
|
101
87
|
* @param options - Encoder configuration options
|
|
88
|
+
* @returns Configured encoder instance
|
|
102
89
|
*
|
|
103
|
-
* @
|
|
104
|
-
*
|
|
105
|
-
* @throws {Error} If codec not found or configuration fails
|
|
90
|
+
* @throws {Error} If encoder not found or unsupported format
|
|
91
|
+
* @throws {FFmpegError} If codec initialization fails
|
|
106
92
|
*
|
|
107
93
|
* @example
|
|
108
94
|
* ```typescript
|
|
109
|
-
* //
|
|
110
|
-
* const
|
|
111
|
-
* const
|
|
95
|
+
* // From decoder stream info
|
|
96
|
+
* const streamInfo = decoder.getOutputStreamInfo();
|
|
97
|
+
* const encoder = await Encoder.create('libx264', streamInfo, {
|
|
112
98
|
* bitrate: '5M',
|
|
113
|
-
* gopSize: 60
|
|
99
|
+
* gopSize: 60,
|
|
100
|
+
* options: {
|
|
101
|
+
* preset: 'fast',
|
|
102
|
+
* crf: '23'
|
|
103
|
+
* }
|
|
114
104
|
* });
|
|
105
|
+
* ```
|
|
115
106
|
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
118
|
-
*
|
|
107
|
+
* @example
|
|
108
|
+
* ```typescript
|
|
109
|
+
* // With custom stream info
|
|
110
|
+
* const encoder = await Encoder.create('aac', {
|
|
111
|
+
* type: 'audio',
|
|
112
|
+
* sampleRate: 48000,
|
|
113
|
+
* sampleFormat: AV_SAMPLE_FMT_FLTP,
|
|
114
|
+
* channelLayout: AV_CH_LAYOUT_STEREO,
|
|
115
|
+
* timeBase: { num: 1, den: 48000 }
|
|
116
|
+
* }, {
|
|
119
117
|
* bitrate: '192k'
|
|
120
118
|
* });
|
|
119
|
+
* ```
|
|
121
120
|
*
|
|
121
|
+
* @example
|
|
122
|
+
* ```typescript
|
|
123
|
+
* // Hardware encoder
|
|
124
|
+
* const hw = HardwareContext.auto();
|
|
125
|
+
* const encoder = await Encoder.create('hevc_videotoolbox', streamInfo, {
|
|
126
|
+
* hardware: hw,
|
|
127
|
+
* bitrate: '8M'
|
|
128
|
+
* });
|
|
122
129
|
* ```
|
|
130
|
+
*
|
|
131
|
+
* @see {@link Decoder.getOutputStreamInfo} For stream info source
|
|
132
|
+
* @see {@link EncoderOptions} For configuration options
|
|
123
133
|
*/
|
|
124
134
|
static create(encoderCodec: FFEncoderCodec | AVCodecID | Codec, input: StreamInfo, options?: EncoderOptions): Promise<Encoder>;
|
|
125
135
|
/**
|
|
126
136
|
* Check if encoder is open.
|
|
137
|
+
*
|
|
138
|
+
* @example
|
|
139
|
+
* ```typescript
|
|
140
|
+
* if (encoder.isEncoderOpen) {
|
|
141
|
+
* const packet = await encoder.encode(frame);
|
|
142
|
+
* }
|
|
143
|
+
* ```
|
|
127
144
|
*/
|
|
128
145
|
get isEncoderOpen(): boolean;
|
|
129
146
|
/**
|
|
130
|
-
*
|
|
147
|
+
* Check if encoder uses hardware acceleration.
|
|
131
148
|
*
|
|
132
|
-
*
|
|
133
|
-
* Useful for setting up subsequent processing stages.
|
|
149
|
+
* @returns true if hardware-accelerated
|
|
134
150
|
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
151
|
+
* @example
|
|
152
|
+
* ```typescript
|
|
153
|
+
* if (encoder.isHardware()) {
|
|
154
|
+
* console.log('Using GPU acceleration');
|
|
155
|
+
* }
|
|
156
|
+
* ```
|
|
137
157
|
*
|
|
138
|
-
* @
|
|
158
|
+
* @see {@link HardwareContext} For hardware setup
|
|
139
159
|
*/
|
|
140
|
-
|
|
160
|
+
isHardware(): boolean;
|
|
141
161
|
/**
|
|
142
|
-
* Encode a frame
|
|
143
|
-
*
|
|
144
|
-
* Sends frame to encoder and attempts to receive a packet.
|
|
145
|
-
* May return null if encoder needs more data.
|
|
162
|
+
* Encode a frame to a packet.
|
|
146
163
|
*
|
|
147
|
-
*
|
|
148
|
-
*
|
|
164
|
+
* Sends a frame to the encoder and attempts to receive an encoded packet.
|
|
165
|
+
* Handles internal buffering - may return null if more frames needed.
|
|
166
|
+
* Automatically manages encoder state and hardware context binding.
|
|
149
167
|
*
|
|
150
|
-
*
|
|
168
|
+
* Direct mapping to avcodec_send_frame() and avcodec_receive_packet().
|
|
151
169
|
*
|
|
152
|
-
* @
|
|
170
|
+
* @param frame - Raw frame to encode (or null to flush)
|
|
171
|
+
* @returns Encoded packet or null if more data needed
|
|
153
172
|
*
|
|
154
|
-
* @throws {Error} If encoder is closed
|
|
173
|
+
* @throws {Error} If encoder is closed
|
|
174
|
+
* @throws {FFmpegError} If encoding fails
|
|
155
175
|
*
|
|
156
176
|
* @example
|
|
157
177
|
* ```typescript
|
|
158
178
|
* const packet = await encoder.encode(frame);
|
|
159
179
|
* if (packet) {
|
|
160
|
-
*
|
|
180
|
+
* console.log(`Encoded packet with PTS: ${packet.pts}`);
|
|
161
181
|
* await output.writePacket(packet);
|
|
182
|
+
* packet.free();
|
|
162
183
|
* }
|
|
163
184
|
* ```
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* // Encode loop
|
|
189
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
190
|
+
* const packet = await encoder.encode(frame);
|
|
191
|
+
* if (packet) {
|
|
192
|
+
* await output.writePacket(packet);
|
|
193
|
+
* packet.free();
|
|
194
|
+
* }
|
|
195
|
+
* frame.free();
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @see {@link packets} For automatic frame iteration
|
|
200
|
+
* @see {@link flush} For end-of-stream handling
|
|
164
201
|
*/
|
|
165
202
|
encode(frame: Frame | null): Promise<Packet | null>;
|
|
166
203
|
/**
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* Encodes all provided frames and yields resulting packets.
|
|
170
|
-
* Automatically handles encoder flushing at the end.
|
|
171
|
-
* Input frames are automatically freed after encoding.
|
|
204
|
+
* Encode frame stream to packet stream.
|
|
172
205
|
*
|
|
173
|
-
*
|
|
174
|
-
*
|
|
206
|
+
* High-level async generator for complete encoding pipeline.
|
|
207
|
+
* Automatically manages frame memory, encoder state,
|
|
208
|
+
* and flushes buffered packets at end.
|
|
209
|
+
* Primary interface for stream-based encoding.
|
|
175
210
|
*
|
|
176
|
-
*
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
* @
|
|
211
|
+
* @param frames - Async iterable of frames (freed automatically)
|
|
212
|
+
* @yields Encoded packets (caller must free)
|
|
213
|
+
* @throws {Error} If encoder is closed
|
|
214
|
+
* @throws {FFmpegError} If encoding fails
|
|
180
215
|
*
|
|
181
|
-
* @
|
|
216
|
+
* @example
|
|
217
|
+
* ```typescript
|
|
218
|
+
* // Basic encoding pipeline
|
|
219
|
+
* for await (const packet of encoder.packets(decoder.frames(input.packets()))) {
|
|
220
|
+
* await output.writePacket(packet);
|
|
221
|
+
* packet.free(); // Must free output packets
|
|
222
|
+
* }
|
|
223
|
+
* ```
|
|
182
224
|
*
|
|
183
225
|
* @example
|
|
184
226
|
* ```typescript
|
|
185
|
-
* //
|
|
186
|
-
*
|
|
227
|
+
* // With frame filtering
|
|
228
|
+
* async function* filteredFrames() {
|
|
229
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
230
|
+
* await filter.filterFrame(frame);
|
|
231
|
+
* const filtered = await filter.getFrame();
|
|
232
|
+
* if (filtered) {
|
|
233
|
+
* yield filtered;
|
|
234
|
+
* }
|
|
235
|
+
* }
|
|
236
|
+
* }
|
|
237
|
+
*
|
|
238
|
+
* for await (const packet of encoder.packets(filteredFrames())) {
|
|
187
239
|
* await output.writePacket(packet);
|
|
188
|
-
* packet.free();
|
|
240
|
+
* packet.free();
|
|
189
241
|
* }
|
|
190
242
|
* ```
|
|
243
|
+
*
|
|
244
|
+
* @example
|
|
245
|
+
* ```typescript
|
|
246
|
+
* // Pipeline integration
|
|
247
|
+
* import { pipeline } from 'node-av/api';
|
|
248
|
+
*
|
|
249
|
+
* const control = pipeline(
|
|
250
|
+
* input,
|
|
251
|
+
* decoder,
|
|
252
|
+
* encoder,
|
|
253
|
+
* output
|
|
254
|
+
* );
|
|
255
|
+
* await control.completion;
|
|
256
|
+
* ```
|
|
257
|
+
*
|
|
258
|
+
* @see {@link encode} For single frame encoding
|
|
259
|
+
* @see {@link Decoder.frames} For frame source
|
|
191
260
|
*/
|
|
192
261
|
packets(frames: AsyncIterable<Frame>): AsyncGenerator<Packet>;
|
|
193
262
|
/**
|
|
194
|
-
* Flush encoder and get
|
|
263
|
+
* Flush encoder and get buffered packet.
|
|
195
264
|
*
|
|
196
|
-
*
|
|
197
|
-
* Call repeatedly until
|
|
265
|
+
* Signals end-of-stream and retrieves remaining packets.
|
|
266
|
+
* Call repeatedly until null to get all buffered packets.
|
|
267
|
+
* Essential for ensuring all frames are encoded.
|
|
198
268
|
*
|
|
199
|
-
*
|
|
200
|
-
* Retrieves buffered packets from the encoder.
|
|
269
|
+
* Direct mapping to avcodec_send_frame(NULL).
|
|
201
270
|
*
|
|
202
|
-
* @returns
|
|
271
|
+
* @returns Buffered packet or null if none remaining
|
|
203
272
|
*
|
|
204
273
|
* @throws {Error} If encoder is closed
|
|
205
274
|
*
|
|
206
275
|
* @example
|
|
207
276
|
* ```typescript
|
|
208
|
-
* // Flush
|
|
277
|
+
* // Flush remaining packets
|
|
209
278
|
* let packet;
|
|
210
279
|
* while ((packet = await encoder.flush()) !== null) {
|
|
211
|
-
*
|
|
280
|
+
* console.log('Got buffered packet');
|
|
212
281
|
* await output.writePacket(packet);
|
|
282
|
+
* packet.free();
|
|
213
283
|
* }
|
|
214
284
|
* ```
|
|
285
|
+
*
|
|
286
|
+
* @see {@link flushPackets} For async iteration
|
|
287
|
+
* @see {@link packets} For complete encoding pipeline
|
|
215
288
|
*/
|
|
216
289
|
flush(): Promise<Packet | null>;
|
|
217
290
|
/**
|
|
218
|
-
* Flush
|
|
291
|
+
* Flush all buffered packets as async generator.
|
|
219
292
|
*
|
|
220
|
-
*
|
|
221
|
-
* Automatically
|
|
222
|
-
*
|
|
223
|
-
* @returns Async generator of remaining packets
|
|
293
|
+
* Convenient async iteration over remaining packets.
|
|
294
|
+
* Automatically handles repeated flush calls.
|
|
295
|
+
* Useful for end-of-stream processing.
|
|
224
296
|
*
|
|
297
|
+
* @yields Buffered packets
|
|
225
298
|
* @throws {Error} If encoder is closed
|
|
226
299
|
*
|
|
227
300
|
* @example
|
|
228
301
|
* ```typescript
|
|
229
|
-
* //
|
|
302
|
+
* // Flush at end of encoding
|
|
230
303
|
* for await (const packet of encoder.flushPackets()) {
|
|
231
|
-
*
|
|
232
|
-
*
|
|
304
|
+
* console.log('Processing buffered packet');
|
|
305
|
+
* await output.writePacket(packet);
|
|
306
|
+
* packet.free();
|
|
233
307
|
* }
|
|
234
308
|
* ```
|
|
309
|
+
*
|
|
310
|
+
* @see {@link flush} For single packet flush
|
|
311
|
+
* @see {@link packets} For complete pipeline
|
|
235
312
|
*/
|
|
236
313
|
flushPackets(): AsyncGenerator<Packet>;
|
|
237
314
|
/**
|
|
238
315
|
* Close encoder and free resources.
|
|
239
316
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*/
|
|
245
|
-
close(): void;
|
|
246
|
-
/**
|
|
247
|
-
* Get the codec name.
|
|
248
|
-
*/
|
|
249
|
-
getCodecName(): string;
|
|
250
|
-
/**
|
|
251
|
-
* Get codec context for advanced configuration.
|
|
252
|
-
*
|
|
253
|
-
* Use with caution - direct manipulation may cause issues.
|
|
254
|
-
*
|
|
255
|
-
* Provides access to the underlying AVCodecContext for advanced operations.
|
|
317
|
+
* Releases codec context and internal packet buffer.
|
|
318
|
+
* Safe to call multiple times.
|
|
319
|
+
* Does NOT dispose hardware context - caller is responsible.
|
|
320
|
+
* Automatically called by Symbol.dispose.
|
|
256
321
|
*
|
|
257
|
-
* @
|
|
322
|
+
* @example
|
|
323
|
+
* ```typescript
|
|
324
|
+
* const encoder = await Encoder.create('libx264', streamInfo);
|
|
325
|
+
* try {
|
|
326
|
+
* // Use encoder
|
|
327
|
+
* } finally {
|
|
328
|
+
* encoder.close();
|
|
329
|
+
* }
|
|
330
|
+
* ```
|
|
258
331
|
*
|
|
259
|
-
* @
|
|
332
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
260
333
|
*/
|
|
261
|
-
|
|
334
|
+
close(): void;
|
|
262
335
|
/**
|
|
263
|
-
* Get
|
|
336
|
+
* Get encoder codec.
|
|
264
337
|
*
|
|
265
|
-
* Returns the
|
|
338
|
+
* Returns the codec used by this encoder.
|
|
339
|
+
* Useful for checking codec capabilities and properties.
|
|
266
340
|
*
|
|
267
|
-
* @returns
|
|
341
|
+
* @returns Codec instance
|
|
268
342
|
*
|
|
269
343
|
* @example
|
|
270
344
|
* ```typescript
|
|
271
|
-
* const
|
|
272
|
-
*
|
|
273
|
-
*
|
|
274
|
-
* }
|
|
345
|
+
* const codec = encoder.getCodec();
|
|
346
|
+
* console.log(`Using codec: ${codec.name}`);
|
|
347
|
+
* console.log(`Capabilities: ${codec.capabilities}`);
|
|
275
348
|
* ```
|
|
349
|
+
*
|
|
350
|
+
* @see {@link Codec} For codec properties
|
|
276
351
|
*/
|
|
277
|
-
|
|
352
|
+
getCodec(): Codec;
|
|
278
353
|
/**
|
|
279
|
-
* Get
|
|
354
|
+
* Get underlying codec context.
|
|
280
355
|
*
|
|
281
|
-
* Returns
|
|
356
|
+
* Returns the internal codec context for advanced operations.
|
|
357
|
+
* Returns null if encoder is closed.
|
|
282
358
|
*
|
|
283
|
-
* @returns
|
|
359
|
+
* @returns Codec context or null
|
|
284
360
|
*
|
|
285
|
-
* @
|
|
286
|
-
* ```typescript
|
|
287
|
-
* const formats = encoder.getSupportedPixelFormats();
|
|
288
|
-
* console.log(`Encoder supports: ${formats.join(', ')}`);
|
|
289
|
-
* ```
|
|
361
|
+
* @internal
|
|
290
362
|
*/
|
|
291
|
-
|
|
363
|
+
getCodecContext(): CodecContext | null;
|
|
292
364
|
/**
|
|
293
|
-
* Receive
|
|
365
|
+
* Receive packet from encoder.
|
|
366
|
+
*
|
|
367
|
+
* Internal method to get encoded packets from codec.
|
|
368
|
+
* Handles packet cloning and error checking.
|
|
294
369
|
*
|
|
295
|
-
*
|
|
370
|
+
* Direct mapping to avcodec_receive_packet().
|
|
296
371
|
*
|
|
297
|
-
*
|
|
298
|
-
* Clones the packet for the user to prevent internal buffer corruption.
|
|
372
|
+
* @returns Cloned packet or null
|
|
299
373
|
*
|
|
300
|
-
* @
|
|
374
|
+
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
301
375
|
*/
|
|
302
376
|
private receivePacket;
|
|
303
377
|
/**
|
|
304
|
-
*
|
|
378
|
+
* Dispose of encoder.
|
|
379
|
+
*
|
|
380
|
+
* Implements Disposable interface for automatic cleanup.
|
|
381
|
+
* Equivalent to calling close().
|
|
382
|
+
*
|
|
383
|
+
* @example
|
|
384
|
+
* ```typescript
|
|
385
|
+
* {
|
|
386
|
+
* using encoder = await Encoder.create('libx264', streamInfo);
|
|
387
|
+
* // Encode frames...
|
|
388
|
+
* } // Automatically closed
|
|
389
|
+
* ```
|
|
305
390
|
*
|
|
306
|
-
*
|
|
307
|
-
* Calls close() to free all resources.
|
|
391
|
+
* @see {@link close} For manual cleanup
|
|
308
392
|
*/
|
|
309
393
|
[Symbol.dispose](): void;
|
|
310
394
|
}
|