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/decoder.d.ts
CHANGED
|
@@ -1,61 +1,47 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Decoder - High-level wrapper for media decoding
|
|
3
|
-
*
|
|
4
|
-
* Simplifies FFmpeg's decoding API with automatic codec selection,
|
|
5
|
-
* parameter configuration, and frame management.
|
|
6
|
-
*
|
|
7
|
-
* Handles codec initialization, packet decoding, and frame output.
|
|
8
|
-
* Supports hardware acceleration and zero-copy transcoding.
|
|
9
|
-
*
|
|
10
|
-
* @module api/decoder
|
|
11
|
-
*/
|
|
12
1
|
import { CodecContext, Frame } from '../lib/index.js';
|
|
13
2
|
import type { Packet, Stream } from '../lib/index.js';
|
|
14
3
|
import type { DecoderOptions, StreamInfo } from './types.js';
|
|
15
4
|
/**
|
|
16
|
-
* High-level decoder for
|
|
17
|
-
*
|
|
18
|
-
* Handles codec initialization, packet decoding, and frame output.
|
|
19
|
-
* Designed for simple, efficient decoding workflows.
|
|
5
|
+
* High-level decoder for audio and video streams.
|
|
20
6
|
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
7
|
+
* Provides a simplified interface for decoding media streams from packets to frames.
|
|
8
|
+
* Handles codec initialization, hardware acceleration setup, and frame management.
|
|
9
|
+
* Supports both synchronous packet-by-packet decoding and async iteration over frames.
|
|
10
|
+
* Essential component in media processing pipelines for converting compressed data to raw frames.
|
|
23
11
|
*
|
|
24
12
|
* @example
|
|
25
13
|
* ```typescript
|
|
26
|
-
*
|
|
27
|
-
* const media = await MediaInput.open('video.mp4');
|
|
28
|
-
* const stream = media.video(); // Get video stream
|
|
29
|
-
* const decoder = await Decoder.create(stream);
|
|
14
|
+
* import { MediaInput, Decoder } from 'node-av/api';
|
|
30
15
|
*
|
|
31
|
-
* //
|
|
32
|
-
*
|
|
33
|
-
*
|
|
34
|
-
* const frame = await decoder.decode(packet);
|
|
35
|
-
* if (frame) {
|
|
36
|
-
* console.log(`Decoded frame: ${frame.width}x${frame.height}`);
|
|
37
|
-
* // Process frame...
|
|
38
|
-
* }
|
|
39
|
-
* }
|
|
40
|
-
* }
|
|
16
|
+
* // Open media and create decoder
|
|
17
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
18
|
+
* using decoder = await Decoder.create(input.video());
|
|
41
19
|
*
|
|
42
|
-
* //
|
|
43
|
-
* const
|
|
44
|
-
*
|
|
20
|
+
* // Decode frames
|
|
21
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
22
|
+
* console.log(`Decoded frame: ${frame.width}x${frame.height}`);
|
|
23
|
+
* frame.free();
|
|
24
|
+
* }
|
|
45
25
|
* ```
|
|
46
26
|
*
|
|
47
27
|
* @example
|
|
48
28
|
* ```typescript
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
*
|
|
52
|
-
*
|
|
53
|
-
*
|
|
54
|
-
* });
|
|
55
|
-
*
|
|
56
|
-
*
|
|
57
|
-
*
|
|
29
|
+
* import { HardwareContext } from 'node-av/api';
|
|
30
|
+
* import { AV_HWDEVICE_TYPE_CUDA } from 'node-av/constants';
|
|
31
|
+
*
|
|
32
|
+
* // Setup hardware acceleration
|
|
33
|
+
* const hw = HardwareContext.create(AV_HWDEVICE_TYPE_CUDA);
|
|
34
|
+
* using decoder = await Decoder.create(stream, { hardware: hw });
|
|
35
|
+
*
|
|
36
|
+
* // Frames will be decoded on GPU
|
|
37
|
+
* for await (const frame of decoder.frames(packets)) {
|
|
38
|
+
* // frame.hwFramesCtx contains GPU memory reference
|
|
39
|
+
* }
|
|
58
40
|
* ```
|
|
41
|
+
*
|
|
42
|
+
* @see {@link Encoder} For encoding frames to packets
|
|
43
|
+
* @see {@link MediaInput} For reading media files
|
|
44
|
+
* @see {@link HardwareContext} For GPU acceleration
|
|
59
45
|
*/
|
|
60
46
|
export declare class Decoder implements Disposable {
|
|
61
47
|
private codecContext;
|
|
@@ -65,202 +51,363 @@ export declare class Decoder implements Disposable {
|
|
|
65
51
|
private isOpen;
|
|
66
52
|
private hardware?;
|
|
67
53
|
/**
|
|
68
|
-
*
|
|
69
|
-
*
|
|
70
|
-
*
|
|
54
|
+
* @param codecContext - Configured codec context
|
|
55
|
+
* @param stream - Media stream being decoded
|
|
56
|
+
* @param hardware - Optional hardware context
|
|
57
|
+
* Use {@link create} factory method
|
|
71
58
|
*
|
|
72
|
-
* @
|
|
73
|
-
* @param stream - The stream this decoder is for
|
|
74
|
-
* @param hardware - Optional hardware context for auto-sharing frames context
|
|
59
|
+
* @internal
|
|
75
60
|
*/
|
|
76
61
|
private constructor();
|
|
77
62
|
/**
|
|
78
|
-
* Create a decoder for a
|
|
63
|
+
* Create a decoder for a media stream.
|
|
79
64
|
*
|
|
80
|
-
*
|
|
81
|
-
* and
|
|
65
|
+
* Initializes a decoder with the appropriate codec and configuration.
|
|
66
|
+
* Automatically detects and configures hardware acceleration if provided.
|
|
67
|
+
* Applies custom codec options and threading configuration.
|
|
82
68
|
*
|
|
83
|
-
*
|
|
84
|
-
* then initializes and opens the codec context.
|
|
85
|
-
*
|
|
86
|
-
* @param stream - Stream to decode
|
|
69
|
+
* @param stream - Media stream to decode
|
|
87
70
|
* @param options - Decoder configuration options
|
|
71
|
+
* @returns Configured decoder instance
|
|
88
72
|
*
|
|
89
|
-
* @
|
|
73
|
+
* @throws {Error} If decoder not found for codec
|
|
74
|
+
* @throws {FFmpegError} If codec initialization fails
|
|
90
75
|
*
|
|
91
|
-
* @
|
|
76
|
+
* @example
|
|
77
|
+
* ```typescript
|
|
78
|
+
* import { MediaInput, Decoder } from 'node-av/api';
|
|
79
|
+
*
|
|
80
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
81
|
+
* using decoder = await Decoder.create(input.video());
|
|
82
|
+
* ```
|
|
92
83
|
*
|
|
93
84
|
* @example
|
|
94
85
|
* ```typescript
|
|
95
|
-
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
86
|
+
* using decoder = await Decoder.create(stream, {
|
|
87
|
+
* threads: 4,
|
|
88
|
+
* options: {
|
|
89
|
+
* 'refcounted_frames': '1',
|
|
90
|
+
* 'skip_frame': 'nonkey' // Only decode keyframes
|
|
91
|
+
* }
|
|
92
|
+
* });
|
|
98
93
|
* ```
|
|
94
|
+
*
|
|
95
|
+
* @example
|
|
96
|
+
* ```typescript
|
|
97
|
+
* const hw = HardwareContext.auto();
|
|
98
|
+
* using decoder = await Decoder.create(stream, {
|
|
99
|
+
* hardware: hw,
|
|
100
|
+
* threads: 0 // Auto-detect thread count
|
|
101
|
+
* });
|
|
102
|
+
* ```
|
|
103
|
+
*
|
|
104
|
+
* @see {@link HardwareContext} For GPU acceleration setup
|
|
105
|
+
* @see {@link DecoderOptions} For configuration options
|
|
99
106
|
*/
|
|
100
107
|
static create(stream: Stream, options?: DecoderOptions): Promise<Decoder>;
|
|
101
108
|
/**
|
|
102
109
|
* Check if decoder is open.
|
|
110
|
+
*
|
|
111
|
+
* @returns true if decoder is open and ready
|
|
112
|
+
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* if (decoder.isDecoderOpen) {
|
|
116
|
+
* const frame = await decoder.decode(packet);
|
|
117
|
+
* }
|
|
118
|
+
* ```
|
|
103
119
|
*/
|
|
104
120
|
get isDecoderOpen(): boolean;
|
|
105
121
|
/**
|
|
106
122
|
* Get output stream information.
|
|
107
123
|
*
|
|
108
|
-
* Returns
|
|
109
|
-
* For hardware
|
|
124
|
+
* Returns format information about decoded frames.
|
|
125
|
+
* For hardware decoding, returns the hardware pixel format.
|
|
126
|
+
* Essential for configuring downstream components like encoders or filters.
|
|
127
|
+
*
|
|
128
|
+
* @returns Stream format information
|
|
129
|
+
*
|
|
130
|
+
* @example
|
|
131
|
+
* ```typescript
|
|
132
|
+
* const info = decoder.getOutputStreamInfo();
|
|
133
|
+
* if (info.type === 'video') {
|
|
134
|
+
* console.log(`Video: ${info.width}x${info.height} @ ${info.pixelFormat}`);
|
|
135
|
+
* console.log(`Frame rate: ${info.frameRate.num}/${info.frameRate.den}`);
|
|
136
|
+
* }
|
|
137
|
+
* ```
|
|
110
138
|
*
|
|
111
|
-
* @
|
|
139
|
+
* @example
|
|
140
|
+
* ```typescript
|
|
141
|
+
* const info = decoder.getOutputStreamInfo();
|
|
142
|
+
* if (info.type === 'audio') {
|
|
143
|
+
* console.log(`Audio: ${info.sampleRate}Hz ${info.sampleFormat}`);
|
|
144
|
+
* console.log(`Channels: ${info.channelLayout}`);
|
|
145
|
+
* }
|
|
146
|
+
* ```
|
|
147
|
+
*
|
|
148
|
+
* @see {@link StreamInfo} For format details
|
|
149
|
+
* @see {@link Encoder.create} For matching encoder configuration
|
|
112
150
|
*/
|
|
113
151
|
getOutputStreamInfo(): StreamInfo;
|
|
114
152
|
/**
|
|
115
|
-
*
|
|
153
|
+
* Check if decoder uses hardware acceleration.
|
|
116
154
|
*
|
|
117
|
-
*
|
|
118
|
-
* May return null if decoder needs more data.
|
|
155
|
+
* @returns true if hardware-accelerated
|
|
119
156
|
*
|
|
120
|
-
*
|
|
121
|
-
*
|
|
157
|
+
* @example
|
|
158
|
+
* ```typescript
|
|
159
|
+
* if (decoder.isHardware()) {
|
|
160
|
+
* console.log('Using GPU acceleration');
|
|
161
|
+
* }
|
|
162
|
+
* ```
|
|
122
163
|
*
|
|
123
|
-
* @
|
|
164
|
+
* @see {@link HardwareContext} For hardware setup
|
|
165
|
+
*/
|
|
166
|
+
isHardware(): boolean;
|
|
167
|
+
/**
|
|
168
|
+
* Decode a packet to a frame.
|
|
124
169
|
*
|
|
125
|
-
*
|
|
170
|
+
* Sends a packet to the decoder and attempts to receive a decoded frame.
|
|
171
|
+
* Handles internal buffering - may return null if more packets needed.
|
|
172
|
+
* Automatically manages decoder state and error recovery.
|
|
126
173
|
*
|
|
127
|
-
*
|
|
174
|
+
* Direct mapping to avcodec_send_packet() and avcodec_receive_frame().
|
|
175
|
+
*
|
|
176
|
+
* @param packet - Compressed packet to decode
|
|
177
|
+
* @returns Decoded frame or null if more data needed
|
|
178
|
+
*
|
|
179
|
+
* @throws {Error} If decoder is closed
|
|
180
|
+
* @throws {FFmpegError} If decoding fails
|
|
128
181
|
*
|
|
129
182
|
* @example
|
|
130
183
|
* ```typescript
|
|
131
184
|
* const frame = await decoder.decode(packet);
|
|
132
185
|
* if (frame) {
|
|
133
|
-
*
|
|
186
|
+
* console.log(`Decoded frame with PTS: ${frame.pts}`);
|
|
187
|
+
* frame.free();
|
|
188
|
+
* }
|
|
189
|
+
* ```
|
|
190
|
+
*
|
|
191
|
+
* @example
|
|
192
|
+
* ```typescript
|
|
193
|
+
* for await (const packet of input.packets()) {
|
|
194
|
+
* if (packet.streamIndex === decoder.getStreamIndex()) {
|
|
195
|
+
* const frame = await decoder.decode(packet);
|
|
196
|
+
* if (frame) {
|
|
197
|
+
* await processFrame(frame);
|
|
198
|
+
* frame.free();
|
|
199
|
+
* }
|
|
200
|
+
* }
|
|
201
|
+
* packet.free();
|
|
134
202
|
* }
|
|
135
203
|
* ```
|
|
204
|
+
*
|
|
205
|
+
* @see {@link frames} For automatic packet iteration
|
|
206
|
+
* @see {@link flush} For end-of-stream handling
|
|
136
207
|
*/
|
|
137
208
|
decode(packet: Packet): Promise<Frame | null>;
|
|
138
209
|
/**
|
|
139
|
-
* Flush decoder and get
|
|
210
|
+
* Flush decoder and get buffered frame.
|
|
140
211
|
*
|
|
141
|
-
*
|
|
142
|
-
* Call repeatedly until
|
|
212
|
+
* Signals end-of-stream and retrieves remaining frames.
|
|
213
|
+
* Call repeatedly until null to get all buffered frames.
|
|
214
|
+
* Essential for ensuring all frames are decoded.
|
|
143
215
|
*
|
|
144
|
-
*
|
|
145
|
-
* Retrieves buffered frames from the decoder.
|
|
216
|
+
* Direct mapping to avcodec_send_packet(NULL).
|
|
146
217
|
*
|
|
147
|
-
* @returns
|
|
218
|
+
* @returns Buffered frame or null if none remaining
|
|
148
219
|
*
|
|
149
220
|
* @throws {Error} If decoder is closed
|
|
150
221
|
*
|
|
151
222
|
* @example
|
|
152
223
|
* ```typescript
|
|
153
|
-
* //
|
|
224
|
+
* // After all packets processed
|
|
154
225
|
* let frame;
|
|
155
226
|
* while ((frame = await decoder.flush()) !== null) {
|
|
156
|
-
*
|
|
227
|
+
* console.log('Got buffered frame');
|
|
228
|
+
* await processFrame(frame);
|
|
229
|
+
* frame.free();
|
|
157
230
|
* }
|
|
158
231
|
* ```
|
|
232
|
+
*
|
|
233
|
+
* @see {@link flushFrames} For async iteration
|
|
234
|
+
* @see {@link frames} For complete decoding pipeline
|
|
159
235
|
*/
|
|
160
236
|
flush(): Promise<Frame | null>;
|
|
161
237
|
/**
|
|
162
|
-
* Flush
|
|
163
|
-
*
|
|
164
|
-
* More convenient than calling flush() in a loop.
|
|
165
|
-
* Automatically sends flush signal and yields all buffered frames.
|
|
166
|
-
*
|
|
167
|
-
* IMPORTANT: The yielded frames MUST be freed by the caller!
|
|
168
|
-
* Use 'using' statement or manually call frame.free() to avoid memory leaks.
|
|
238
|
+
* Flush all buffered frames as async generator.
|
|
169
239
|
*
|
|
170
|
-
*
|
|
240
|
+
* Convenient async iteration over remaining frames.
|
|
241
|
+
* Automatically handles repeated flush calls.
|
|
242
|
+
* Useful for end-of-stream processing.
|
|
171
243
|
*
|
|
244
|
+
* @yields Buffered frames
|
|
172
245
|
* @throws {Error} If decoder is closed
|
|
173
246
|
*
|
|
174
247
|
* @example
|
|
175
248
|
* ```typescript
|
|
176
|
-
* //
|
|
249
|
+
* // Flush at end of decoding
|
|
177
250
|
* for await (const frame of decoder.flushFrames()) {
|
|
178
|
-
*
|
|
179
|
-
*
|
|
251
|
+
* console.log('Processing buffered frame');
|
|
252
|
+
* await encoder.encode(frame);
|
|
253
|
+
* frame.free();
|
|
180
254
|
* }
|
|
181
255
|
* ```
|
|
256
|
+
*
|
|
257
|
+
* @see {@link flush} For single frame flush
|
|
258
|
+
* @see {@link frames} For complete pipeline
|
|
182
259
|
*/
|
|
183
260
|
flushFrames(): AsyncGenerator<Frame>;
|
|
184
261
|
/**
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* Filters packets for this decoder's stream and yields decoded frames.
|
|
188
|
-
* Automatically handles packet cleanup and decoder flushing.
|
|
189
|
-
*
|
|
190
|
-
* Processes packets in sequence, decoding each and yielding frames.
|
|
191
|
-
* After all packets are processed, flushes the decoder for remaining frames.
|
|
192
|
-
*
|
|
193
|
-
* IMPORTANT: The yielded frames MUST be freed by the caller!
|
|
194
|
-
* Use 'using' statement or manually call frame.free() to avoid memory leaks.
|
|
262
|
+
* Decode packet stream to frame stream.
|
|
195
263
|
*
|
|
196
|
-
*
|
|
264
|
+
* High-level async generator for complete decoding pipeline.
|
|
265
|
+
* Automatically filters packets for this stream, manages memory,
|
|
266
|
+
* and flushes buffered frames at end.
|
|
267
|
+
* Primary interface for stream-based decoding.
|
|
197
268
|
*
|
|
198
|
-
* @
|
|
269
|
+
* @param packets - Async iterable of packets
|
|
270
|
+
* @yields Decoded frames
|
|
271
|
+
* @throws {Error} If decoder is closed
|
|
272
|
+
* @throws {FFmpegError} If decoding fails
|
|
199
273
|
*
|
|
200
274
|
* @example
|
|
201
275
|
* ```typescript
|
|
202
|
-
*
|
|
203
|
-
*
|
|
276
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
277
|
+
* using decoder = await Decoder.create(input.video());
|
|
278
|
+
*
|
|
279
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
204
280
|
* console.log(`Frame: ${frame.width}x${frame.height}`);
|
|
205
|
-
*
|
|
281
|
+
* frame.free();
|
|
206
282
|
* }
|
|
283
|
+
* ```
|
|
207
284
|
*
|
|
208
|
-
*
|
|
209
|
-
*
|
|
210
|
-
*
|
|
211
|
-
* // Process frame
|
|
212
|
-
*
|
|
285
|
+
* @example
|
|
286
|
+
* ```typescript
|
|
287
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
288
|
+
* // Process frame
|
|
289
|
+
* await filter.filterFrame(frame);
|
|
290
|
+
*
|
|
291
|
+
* // Frame automatically freed
|
|
292
|
+
* frame.free();
|
|
213
293
|
* }
|
|
214
294
|
* ```
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* import { pipeline } from 'node-av/api';
|
|
299
|
+
*
|
|
300
|
+
* const control = pipeline(
|
|
301
|
+
* input,
|
|
302
|
+
* decoder,
|
|
303
|
+
* encoder,
|
|
304
|
+
* output
|
|
305
|
+
* );
|
|
306
|
+
* await control.completion;
|
|
307
|
+
* ```
|
|
308
|
+
*
|
|
309
|
+
* @see {@link decode} For single packet decoding
|
|
310
|
+
* @see {@link MediaInput.packets} For packet source
|
|
215
311
|
*/
|
|
216
312
|
frames(packets: AsyncIterable<Packet>): AsyncGenerator<Frame>;
|
|
217
313
|
/**
|
|
218
314
|
* Close decoder and free resources.
|
|
219
315
|
*
|
|
220
|
-
*
|
|
316
|
+
* Releases codec context and internal frame buffer.
|
|
317
|
+
* Safe to call multiple times.
|
|
318
|
+
* Automatically called by Symbol.dispose.
|
|
319
|
+
*
|
|
320
|
+
* @example
|
|
321
|
+
* ```typescript
|
|
322
|
+
* const decoder = await Decoder.create(stream);
|
|
323
|
+
* try {
|
|
324
|
+
* // Use decoder
|
|
325
|
+
* } finally {
|
|
326
|
+
* decoder.close();
|
|
327
|
+
* }
|
|
328
|
+
* ```
|
|
221
329
|
*
|
|
222
|
-
*
|
|
223
|
-
* Note: Does NOT dispose the HardwareContext - caller is responsible for that.
|
|
330
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
224
331
|
*/
|
|
225
332
|
close(): void;
|
|
226
333
|
/**
|
|
227
|
-
* Get
|
|
334
|
+
* Get stream index.
|
|
335
|
+
*
|
|
336
|
+
* Returns the index of the stream being decoded.
|
|
337
|
+
* Used for packet filtering in multi-stream files.
|
|
338
|
+
*
|
|
339
|
+
* @returns Stream index
|
|
340
|
+
*
|
|
341
|
+
* @example
|
|
342
|
+
* ```typescript
|
|
343
|
+
* if (packet.streamIndex === decoder.getStreamIndex()) {
|
|
344
|
+
* const frame = await decoder.decode(packet);
|
|
345
|
+
* }
|
|
346
|
+
* ```
|
|
347
|
+
*
|
|
348
|
+
* @see {@link getStream} For full stream object
|
|
228
349
|
*/
|
|
229
350
|
getStreamIndex(): number;
|
|
230
351
|
/**
|
|
231
|
-
* Get
|
|
232
|
-
*
|
|
352
|
+
* Get stream object.
|
|
353
|
+
*
|
|
354
|
+
* Returns the underlying stream being decoded.
|
|
355
|
+
* Provides access to stream metadata and parameters.
|
|
356
|
+
*
|
|
357
|
+
* @returns Stream object
|
|
358
|
+
*
|
|
359
|
+
* @example
|
|
360
|
+
* ```typescript
|
|
361
|
+
* const stream = decoder.getStream();
|
|
362
|
+
* console.log(`Duration: ${stream.duration}`);
|
|
363
|
+
* console.log(`Time base: ${stream.timeBase.num}/${stream.timeBase.den}`);
|
|
364
|
+
* ```
|
|
365
|
+
*
|
|
366
|
+
* @see {@link Stream} For stream properties
|
|
367
|
+
* @see {@link getStreamIndex} For index only
|
|
233
368
|
*/
|
|
234
369
|
getStream(): Stream;
|
|
235
370
|
/**
|
|
236
|
-
* Get codec context
|
|
371
|
+
* Get underlying codec context.
|
|
237
372
|
*
|
|
238
|
-
*
|
|
373
|
+
* Returns the internal codec context for advanced operations.
|
|
374
|
+
* Returns null if decoder is closed.
|
|
239
375
|
*
|
|
240
|
-
*
|
|
241
|
-
*
|
|
242
|
-
* @returns CodecContext or null if closed
|
|
376
|
+
* @returns Codec context or null
|
|
243
377
|
*
|
|
244
378
|
* @internal
|
|
245
379
|
*/
|
|
246
380
|
getCodecContext(): CodecContext | null;
|
|
247
381
|
/**
|
|
248
|
-
* Receive
|
|
382
|
+
* Receive frame from decoder.
|
|
249
383
|
*
|
|
250
|
-
* Internal method to
|
|
384
|
+
* Internal method to get decoded frames from codec.
|
|
385
|
+
* Handles frame cloning and error checking.
|
|
386
|
+
* Hardware frames include hw_frames_ctx reference.
|
|
251
387
|
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
388
|
+
* Direct mapping to avcodec_receive_frame().
|
|
389
|
+
*
|
|
390
|
+
* @returns Cloned frame or null
|
|
391
|
+
*
|
|
392
|
+
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
254
393
|
*
|
|
255
|
-
* @returns Frame or null if no frame available
|
|
256
|
-
* @internal
|
|
257
394
|
*/
|
|
258
395
|
private receiveFrameInternal;
|
|
259
396
|
/**
|
|
260
|
-
*
|
|
397
|
+
* Dispose of decoder.
|
|
398
|
+
*
|
|
399
|
+
* Implements Disposable interface for automatic cleanup.
|
|
400
|
+
* Equivalent to calling close().
|
|
401
|
+
*
|
|
402
|
+
* @example
|
|
403
|
+
* ```typescript
|
|
404
|
+
* {
|
|
405
|
+
* using decoder = await Decoder.create(stream);
|
|
406
|
+
* // Decode frames...
|
|
407
|
+
* } // Automatically closed
|
|
408
|
+
* ```
|
|
261
409
|
*
|
|
262
|
-
*
|
|
263
|
-
* Calls close() to free all resources.
|
|
410
|
+
* @see {@link close} For manual cleanup
|
|
264
411
|
*/
|
|
265
412
|
[Symbol.dispose](): void;
|
|
266
413
|
}
|