node-av 1.2.0 → 2.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +37 -59
- package/dist/api/bitstream-filter.d.ts +5 -2
- package/dist/api/bitstream-filter.js +7 -4
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +135 -119
- package/dist/api/decoder.js +195 -202
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +141 -78
- package/dist/api/encoder.js +241 -193
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +699 -573
- package/dist/api/filter-presets.js +1157 -840
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +180 -157
- package/dist/api/filter.js +314 -366
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +28 -29
- package/dist/api/hardware.js +80 -74
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +1 -1
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +6 -0
- package/dist/api/io-stream.js +6 -0
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +2 -1
- package/dist/api/media-input.js +3 -8
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +37 -126
- package/dist/api/media-output.js +138 -206
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +193 -0
- package/dist/api/pipeline.js +36 -42
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +22 -57
- package/dist/api/utilities/audio-sample.d.ts +0 -8
- package/dist/api/utilities/audio-sample.js +0 -8
- package/dist/api/utilities/audio-sample.js.map +1 -1
- package/dist/api/utilities/channel-layout.d.ts +0 -8
- package/dist/api/utilities/channel-layout.js +0 -8
- package/dist/api/utilities/channel-layout.js.map +1 -1
- package/dist/api/utilities/image.d.ts +0 -8
- package/dist/api/utilities/image.js +0 -8
- package/dist/api/utilities/image.js.map +1 -1
- package/dist/api/utilities/index.d.ts +3 -3
- package/dist/api/utilities/index.js +3 -3
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -9
- package/dist/api/utilities/media-type.js +1 -9
- package/dist/api/utilities/media-type.js.map +1 -1
- package/dist/api/utilities/pixel-format.d.ts +1 -9
- package/dist/api/utilities/pixel-format.js +1 -9
- package/dist/api/utilities/pixel-format.js.map +1 -1
- package/dist/api/utilities/sample-format.d.ts +1 -9
- package/dist/api/utilities/sample-format.js +1 -9
- package/dist/api/utilities/sample-format.js.map +1 -1
- package/dist/api/utilities/streaming.d.ts +0 -8
- package/dist/api/utilities/streaming.js +0 -8
- package/dist/api/utilities/streaming.js.map +1 -1
- package/dist/api/utilities/timestamp.d.ts +0 -8
- package/dist/api/utilities/timestamp.js +0 -8
- package/dist/api/utilities/timestamp.js.map +1 -1
- package/dist/api/utils.js +2 -0
- package/dist/api/utils.js.map +1 -1
- package/dist/constants/constants.d.ts +1 -1
- package/dist/constants/constants.js +2 -0
- package/dist/constants/constants.js.map +1 -1
- package/dist/lib/binding.d.ts +1 -0
- package/dist/lib/binding.js +2 -0
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/codec.d.ts +4 -4
- package/dist/lib/codec.js +4 -4
- package/dist/lib/dictionary.d.ts +2 -2
- package/dist/lib/dictionary.js +2 -2
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +1 -1
- package/dist/lib/error.js +1 -1
- package/dist/lib/filter-context.d.ts +19 -2
- package/dist/lib/filter-context.js +15 -0
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/format-context.d.ts +18 -18
- package/dist/lib/format-context.js +20 -20
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +43 -1
- package/dist/lib/frame.js +53 -0
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/index.d.ts +1 -1
- package/dist/lib/index.js +1 -1
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/native-types.d.ts +1 -0
- package/dist/lib/option.d.ts +176 -0
- package/dist/lib/option.js +176 -0
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/utilities.d.ts +64 -1
- package/dist/lib/utilities.js +65 -0
- package/dist/lib/utilities.js.map +1 -1
- package/install/ffmpeg.js +0 -11
- package/package.json +16 -18
- package/release_notes.md +0 -48
package/README.md
CHANGED
|
@@ -34,46 +34,45 @@ await using input = await MediaInput.open('input.mp4');
|
|
|
34
34
|
await using output = await MediaOutput.open('output.mp4');
|
|
35
35
|
|
|
36
36
|
// Get video stream
|
|
37
|
-
const videoStream = input.video()
|
|
37
|
+
const videoStream = input.video()!;
|
|
38
38
|
|
|
39
|
-
// Create decoder
|
|
40
|
-
using decoder = await Decoder.create(videoStream
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
39
|
+
// Create decoder
|
|
40
|
+
using decoder = await Decoder.create(videoStream);
|
|
41
|
+
|
|
42
|
+
// Create encoder
|
|
43
|
+
using encoder = await Encoder.create(FF_ENCODER_LIBX264, {
|
|
44
|
+
timeBase: videoStream.timeBase,
|
|
45
|
+
frameRate: videoStream.avgFrameRate,
|
|
44
46
|
});
|
|
45
47
|
|
|
46
48
|
// Add stream to output
|
|
47
49
|
const outputIndex = output.addStream(encoder);
|
|
48
|
-
await output.writeHeader();
|
|
49
50
|
|
|
50
51
|
// Process packets
|
|
51
|
-
for await (
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
await output.writePacket(encoded, outputIndex);
|
|
58
|
-
}
|
|
52
|
+
for await (using packet of input.packets(videoStream.index)) {
|
|
53
|
+
using frame = await decoder.decode(packet);
|
|
54
|
+
if (frame) {
|
|
55
|
+
using encoded = await encoder.encode(frame);
|
|
56
|
+
if (encoded) {
|
|
57
|
+
await output.writePacket(encoded, outputIndex);
|
|
59
58
|
}
|
|
60
59
|
}
|
|
61
60
|
}
|
|
62
61
|
|
|
63
|
-
// Flush decoder
|
|
64
|
-
for await (
|
|
62
|
+
// Flush decoder
|
|
63
|
+
for await (using frame of decoder.flushFrames()) {
|
|
65
64
|
using encoded = await encoder.encode(frame);
|
|
66
65
|
if (encoded) {
|
|
67
66
|
await output.writePacket(encoded, outputIndex);
|
|
68
67
|
}
|
|
69
68
|
}
|
|
70
69
|
|
|
71
|
-
|
|
70
|
+
// Flush encoder
|
|
71
|
+
for await (using packet of encoder.flushPackets()) {
|
|
72
72
|
await output.writePacket(packet, outputIndex);
|
|
73
73
|
}
|
|
74
74
|
|
|
75
|
-
//
|
|
76
|
-
await output.writeTrailer();
|
|
75
|
+
// Done
|
|
77
76
|
```
|
|
78
77
|
|
|
79
78
|
### Pipeline API
|
|
@@ -85,36 +84,15 @@ import { pipeline, MediaInput, MediaOutput, Decoder, Encoder } from 'node-av/api
|
|
|
85
84
|
const input = await MediaInput.open('input.mp4');
|
|
86
85
|
const output = await MediaOutput.open('output.mp4');
|
|
87
86
|
const decoder = await Decoder.create(input.video());
|
|
88
|
-
const encoder = await Encoder.create(FF_ENCODER_LIBX264,
|
|
89
|
-
|
|
90
|
-
|
|
87
|
+
const encoder = await Encoder.create(FF_ENCODER_LIBX264, {
|
|
88
|
+
timeBase: videoStream.timeBase,
|
|
89
|
+
frameRate: videoStream.avgFrameRate,
|
|
91
90
|
});
|
|
92
91
|
|
|
93
92
|
const control = pipeline(input, decoder, encoder, output);
|
|
94
93
|
await control.completion;
|
|
95
|
-
|
|
96
|
-
// The pipeline automatically handles:
|
|
97
|
-
// - Flow control between components
|
|
98
|
-
// - Resource management and cleanup
|
|
99
|
-
// - Error propagation
|
|
100
|
-
// - Backpressure handling
|
|
101
94
|
```
|
|
102
95
|
|
|
103
|
-
## More Examples
|
|
104
|
-
|
|
105
|
-
The `examples/` directory contains comprehensive examples for all API levels:
|
|
106
|
-
|
|
107
|
-
**High-Level API** (`api-*.ts`)
|
|
108
|
-
- Hardware acceleration, muxing, streaming, custom I/O, and more
|
|
109
|
-
|
|
110
|
-
**Low-Level API** (direct FFmpeg bindings)
|
|
111
|
-
- Ported FFmpeg C examples showing fine-grained control
|
|
112
|
-
|
|
113
|
-
**Pipeline API** (`api-pipeline-*.ts`)
|
|
114
|
-
- Complex workflows with automatic flow control
|
|
115
|
-
|
|
116
|
-
See the [Examples Table](#examples) for a complete list.
|
|
117
|
-
|
|
118
96
|
## Hardware Acceleration
|
|
119
97
|
|
|
120
98
|
The library supports all hardware acceleration methods available in FFmpeg. The specific hardware types available depend on your FFmpeg build and system configuration.
|
|
@@ -123,23 +101,23 @@ The library supports all hardware acceleration methods available in FFmpeg. The
|
|
|
123
101
|
|
|
124
102
|
```typescript
|
|
125
103
|
import { HardwareContext } from 'node-av/api';
|
|
126
|
-
import {
|
|
104
|
+
import { FF_ENCODER_LIBX264 } from 'node-av/constants';
|
|
127
105
|
|
|
128
106
|
// Automatically detect best available hardware
|
|
129
107
|
const hw = HardwareContext.auto();
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
108
|
+
console.log(`Using hardware: ${hw.deviceTypeName}`);
|
|
109
|
+
|
|
110
|
+
// Use with decoder
|
|
111
|
+
const decoder = await Decoder.create(stream, {
|
|
112
|
+
hardware: hw
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
// Use with encoder (use hardware-specific codec)
|
|
116
|
+
const encoderCodec = hw?.getEncoderCodec('h264') ?? FF_ENCODER_LIBX264;
|
|
117
|
+
const encoder = await Encoder.create(encoderCodec, {
|
|
118
|
+
timeBase: videoStream.timeBase,
|
|
119
|
+
frameRate: videoStream.avgFrameRate,
|
|
120
|
+
});
|
|
143
121
|
```
|
|
144
122
|
|
|
145
123
|
### Specific Hardware
|
|
@@ -309,7 +287,7 @@ This project is licensed under the MIT License. See the LICENSE file for details
|
|
|
309
287
|
|
|
310
288
|
## Contributing
|
|
311
289
|
|
|
312
|
-
Contributions are welcome! Please read [
|
|
290
|
+
Contributions are welcome! Please read [CONTRIBUTING.md](https://github.com/seydx/av/tree/main/CONTRIBUTING.md) for development setup, code standards, and contribution guidelines before submitting pull requests.
|
|
313
291
|
|
|
314
292
|
## Support
|
|
315
293
|
|
|
@@ -63,6 +63,7 @@ export declare class BitStreamFilterAPI implements Disposable {
|
|
|
63
63
|
* @returns Configured bitstream filter
|
|
64
64
|
*
|
|
65
65
|
* @throws {Error} If filter not found or initialization fails
|
|
66
|
+
*
|
|
66
67
|
* @throws {FFmpegError} If allocation or initialization fails
|
|
67
68
|
*
|
|
68
69
|
* @example
|
|
@@ -133,6 +134,7 @@ export declare class BitStreamFilterAPI implements Disposable {
|
|
|
133
134
|
* @returns Array of filtered packets
|
|
134
135
|
*
|
|
135
136
|
* @throws {Error} If filter is disposed
|
|
137
|
+
*
|
|
136
138
|
* @throws {FFmpegError} If filtering fails
|
|
137
139
|
*
|
|
138
140
|
* @example
|
|
@@ -162,8 +164,9 @@ export declare class BitStreamFilterAPI implements Disposable {
|
|
|
162
164
|
* Yields filtered packets ready for output.
|
|
163
165
|
*
|
|
164
166
|
* @param packets - Async iterable of packets
|
|
165
|
-
* @yields Filtered packets
|
|
167
|
+
* @yields {Packet} Filtered packets
|
|
166
168
|
* @throws {Error} If filter is disposed
|
|
169
|
+
*
|
|
167
170
|
* @throws {FFmpegError} If filtering fails
|
|
168
171
|
*
|
|
169
172
|
* @example
|
|
@@ -222,7 +225,7 @@ export declare class BitStreamFilterAPI implements Disposable {
|
|
|
222
225
|
* Convenient async iteration over remaining packets.
|
|
223
226
|
* Combines flush and iteration.
|
|
224
227
|
*
|
|
225
|
-
* @yields Remaining packets
|
|
228
|
+
* @yields {Packet} Remaining packets
|
|
226
229
|
* @throws {Error} If filter is disposed
|
|
227
230
|
*
|
|
228
231
|
* @example
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import { AVERROR_EOF } from '../constants/constants.js';
|
|
2
|
-
import {
|
|
1
|
+
import { AVERROR_EAGAIN, AVERROR_EOF } from '../constants/constants.js';
|
|
2
|
+
import { BitStreamFilter, BitStreamFilterContext, FFmpegError, Packet } from '../lib/index.js';
|
|
3
3
|
/**
|
|
4
4
|
* High-level bitstream filter for packet processing.
|
|
5
5
|
*
|
|
@@ -67,6 +67,7 @@ export class BitStreamFilterAPI {
|
|
|
67
67
|
* @returns Configured bitstream filter
|
|
68
68
|
*
|
|
69
69
|
* @throws {Error} If filter not found or initialization fails
|
|
70
|
+
*
|
|
70
71
|
* @throws {FFmpegError} If allocation or initialization fails
|
|
71
72
|
*
|
|
72
73
|
* @example
|
|
@@ -174,6 +175,7 @@ export class BitStreamFilterAPI {
|
|
|
174
175
|
* @returns Array of filtered packets
|
|
175
176
|
*
|
|
176
177
|
* @throws {Error} If filter is disposed
|
|
178
|
+
*
|
|
177
179
|
* @throws {FFmpegError} If filtering fails
|
|
178
180
|
*
|
|
179
181
|
* @example
|
|
@@ -229,8 +231,9 @@ export class BitStreamFilterAPI {
|
|
|
229
231
|
* Yields filtered packets ready for output.
|
|
230
232
|
*
|
|
231
233
|
* @param packets - Async iterable of packets
|
|
232
|
-
* @yields Filtered packets
|
|
234
|
+
* @yields {Packet} Filtered packets
|
|
233
235
|
* @throws {Error} If filter is disposed
|
|
236
|
+
*
|
|
234
237
|
* @throws {FFmpegError} If filtering fails
|
|
235
238
|
*
|
|
236
239
|
* @example
|
|
@@ -321,7 +324,7 @@ export class BitStreamFilterAPI {
|
|
|
321
324
|
* Convenient async iteration over remaining packets.
|
|
322
325
|
* Combines flush and iteration.
|
|
323
326
|
*
|
|
324
|
-
* @yields Remaining packets
|
|
327
|
+
* @yields {Packet} Remaining packets
|
|
325
328
|
* @throws {Error} If filter is disposed
|
|
326
329
|
*
|
|
327
330
|
* @example
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"bitstream-filter.js","sourceRoot":"","sources":["../../src/api/bitstream-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;
|
|
1
|
+
{"version":3,"file":"bitstream-filter.js","sourceRoot":"","sources":["../../src/api/bitstream-filter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,cAAc,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxE,OAAO,EAAE,eAAe,EAAE,sBAAsB,EAAE,WAAW,EAAE,MAAM,EAAE,MAAM,iBAAiB,CAAC;AAI/F;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAqCG;AACH,MAAM,OAAO,kBAAkB;IACrB,GAAG,CAAyB;IAC5B,MAAM,CAAkB;IACxB,MAAM,CAAS;IACf,UAAU,GAAG,KAAK,CAAC;IAE3B;;;;;OAKG;IACH,YAAoB,MAAuB,EAAE,GAA2B,EAAE,MAAc;QACtF,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;QACrB,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC;QACf,IAAI,CAAC,MAAM,GAAG,MAAM,CAAC;IACvB,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAmCG;IACH,MAAM,CAAC,MAAM,CAAC,UAAkB,EAAE,MAAc;QAC9C,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,oBAAoB,CAAC,CAAC;QACxC,CAAC;QAED,4BAA4B;QAC5B,MAAM,MAAM,GAAG,eAAe,CAAC,SAAS,CAAC,UAAU,CAAC,CAAC;QACrD,IAAI,CAAC,MAAM,EAAE,CAAC;YACZ,MAAM,IAAI,KAAK,CAAC,qBAAqB,UAAU,aAAa,CAAC,CAAC;QAChE,CAAC;QAED,8BAA8B;QAC9B,MAAM,GAAG,GAAG,IAAI,sBAAsB,EAAE,CAAC;QACzC,MAAM,QAAQ,GAAG,GAAG,CAAC,KAAK,CAAC,MAAM,CAAC,CAAC;QACnC,W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AK,CAAC,gCAAgC,CAAC,CAAC;QACpD,CAAC;QAED,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,CAAC;IACnB,CAAC;IAED;;;;;;;;;;;;OAYG;IACH,OAAO;QACL,IAAI,CAAC,IAAI,CAAC,UAAU,EAAE,CAAC;YACrB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,CAAC;YAChB,IAAI,CAAC,UAAU,GAAG,IAAI,CAAC;QACzB,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;OAeG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,OAAO,EAAE,CAAC;IACjB,CAAC;CACF"}
|
package/dist/api/decoder.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
import { CodecContext, Frame } from '../lib/index.js';
|
|
1
|
+
import { Codec, CodecContext, Frame } from '../lib/index.js';
|
|
2
2
|
import type { Packet, Stream } from '../lib/index.js';
|
|
3
|
-
import type { DecoderOptions
|
|
3
|
+
import type { DecoderOptions } from './types.js';
|
|
4
4
|
/**
|
|
5
5
|
* High-level decoder for audio and video streams.
|
|
6
6
|
*
|
|
@@ -45,13 +45,15 @@ import type { DecoderOptions, StreamInfo } from './types.js';
|
|
|
45
45
|
*/
|
|
46
46
|
export declare class Decoder implements Disposable {
|
|
47
47
|
private codecContext;
|
|
48
|
+
private codec;
|
|
48
49
|
private frame;
|
|
49
|
-
private streamIndex;
|
|
50
50
|
private stream;
|
|
51
|
-
private
|
|
51
|
+
private initialized;
|
|
52
|
+
private isClosed;
|
|
52
53
|
private hardware?;
|
|
53
54
|
/**
|
|
54
55
|
* @param codecContext - Configured codec context
|
|
56
|
+
* @param codec - Codec being used
|
|
55
57
|
* @param stream - Media stream being decoded
|
|
56
58
|
* @param hardware - Optional hardware context
|
|
57
59
|
* Use {@link create} factory method
|
|
@@ -71,6 +73,7 @@ export declare class Decoder implements Disposable {
|
|
|
71
73
|
* @returns Configured decoder instance
|
|
72
74
|
*
|
|
73
75
|
* @throws {Error} If decoder not found for codec
|
|
76
|
+
*
|
|
74
77
|
* @throws {FFmpegError} If codec initialization fails
|
|
75
78
|
*
|
|
76
79
|
* @example
|
|
@@ -119,36 +122,21 @@ export declare class Decoder implements Disposable {
|
|
|
119
122
|
*/
|
|
120
123
|
get isDecoderOpen(): boolean;
|
|
121
124
|
/**
|
|
122
|
-
*
|
|
125
|
+
* Check if decoder has been initialized.
|
|
123
126
|
*
|
|
124
|
-
* Returns
|
|
125
|
-
*
|
|
126
|
-
* Essential for configuring downstream components like encoders or filters.
|
|
127
|
+
* Returns true if decoder is initialized (true by default for decoders).
|
|
128
|
+
* Decoders are pre-initialized from stream parameters.
|
|
127
129
|
*
|
|
128
|
-
* @returns
|
|
130
|
+
* @returns true if decoder has been initialized
|
|
129
131
|
*
|
|
130
132
|
* @example
|
|
131
133
|
* ```typescript
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* console.log(`Video: ${info.width}x${info.height} @ ${info.pixelFormat}`);
|
|
135
|
-
* console.log(`Frame rate: ${info.frameRate.num}/${info.frameRate.den}`);
|
|
134
|
+
* if (decoder.isDecoderInitialized) {
|
|
135
|
+
* console.log('Decoder is ready to process frames');
|
|
136
136
|
* }
|
|
137
137
|
* ```
|
|
138
|
-
*
|
|
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
|
|
150
138
|
*/
|
|
151
|
-
|
|
139
|
+
get isDecoderInitialized(): boolean;
|
|
152
140
|
/**
|
|
153
141
|
* Check if decoder uses hardware acceleration.
|
|
154
142
|
*
|
|
@@ -164,6 +152,19 @@ export declare class Decoder implements Disposable {
|
|
|
164
152
|
* @see {@link HardwareContext} For hardware setup
|
|
165
153
|
*/
|
|
166
154
|
isHardware(): boolean;
|
|
155
|
+
/**
|
|
156
|
+
* Check if decoder is ready for processing.
|
|
157
|
+
*
|
|
158
|
+
* @returns true if initialized and ready
|
|
159
|
+
*
|
|
160
|
+
* @example
|
|
161
|
+
* ```typescript
|
|
162
|
+
* if (decoder.isReady()) {
|
|
163
|
+
* const frame = await decoder.decode(packet);
|
|
164
|
+
* }
|
|
165
|
+
* ```
|
|
166
|
+
*/
|
|
167
|
+
isReady(): boolean;
|
|
167
168
|
/**
|
|
168
169
|
* Decode a packet to a frame.
|
|
169
170
|
*
|
|
@@ -177,6 +178,7 @@ export declare class Decoder implements Disposable {
|
|
|
177
178
|
* @returns Decoded frame or null if more data needed
|
|
178
179
|
*
|
|
179
180
|
* @throws {Error} If decoder is closed
|
|
181
|
+
*
|
|
180
182
|
* @throws {FFmpegError} If decoding fails
|
|
181
183
|
*
|
|
182
184
|
* @example
|
|
@@ -191,7 +193,7 @@ export declare class Decoder implements Disposable {
|
|
|
191
193
|
* @example
|
|
192
194
|
* ```typescript
|
|
193
195
|
* for await (const packet of input.packets()) {
|
|
194
|
-
* if (packet.streamIndex === decoder.
|
|
196
|
+
* if (packet.streamIndex === decoder.getStream().index) {
|
|
195
197
|
* const frame = await decoder.decode(packet);
|
|
196
198
|
* if (frame) {
|
|
197
199
|
* await processFrame(frame);
|
|
@@ -207,42 +209,94 @@ export declare class Decoder implements Disposable {
|
|
|
207
209
|
*/
|
|
208
210
|
decode(packet: Packet): Promise<Frame | null>;
|
|
209
211
|
/**
|
|
210
|
-
*
|
|
212
|
+
* Decode packet stream to frame stream.
|
|
211
213
|
*
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
214
|
+
* High-level async generator for complete decoding pipeline.
|
|
215
|
+
* Automatically filters packets for this stream, manages memory,
|
|
216
|
+
* and flushes buffered frames at end.
|
|
217
|
+
* Primary interface for stream-based decoding.
|
|
215
218
|
*
|
|
216
|
-
*
|
|
219
|
+
* @param packets - Async iterable of packets
|
|
220
|
+
* @yields {Frame} Decoded frames
|
|
221
|
+
* @throws {Error} If decoder is closed
|
|
217
222
|
*
|
|
218
|
-
* @
|
|
223
|
+
* @throws {FFmpegError} If decoding fails
|
|
219
224
|
*
|
|
220
|
-
* @
|
|
225
|
+
* @example
|
|
226
|
+
* ```typescript
|
|
227
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
228
|
+
* using decoder = await Decoder.create(input.video());
|
|
229
|
+
*
|
|
230
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
231
|
+
* console.log(`Frame: ${frame.width}x${frame.height}`);
|
|
232
|
+
* frame.free();
|
|
233
|
+
* }
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @example
|
|
237
|
+
* ```typescript
|
|
238
|
+
* for await (const frame of decoder.frames(input.packets())) {
|
|
239
|
+
* // Process frame
|
|
240
|
+
* await filter.process(frame);
|
|
241
|
+
*
|
|
242
|
+
* // Frame automatically freed
|
|
243
|
+
* frame.free();
|
|
244
|
+
* }
|
|
245
|
+
* ```
|
|
246
|
+
*
|
|
247
|
+
* @example
|
|
248
|
+
* ```typescript
|
|
249
|
+
* import { pipeline } from 'node-av/api';
|
|
250
|
+
*
|
|
251
|
+
* const control = pipeline(
|
|
252
|
+
* input,
|
|
253
|
+
* decoder,
|
|
254
|
+
* encoder,
|
|
255
|
+
* output
|
|
256
|
+
* );
|
|
257
|
+
* await control.completion;
|
|
258
|
+
* ```
|
|
259
|
+
*
|
|
260
|
+
* @see {@link decode} For single packet decoding
|
|
261
|
+
* @see {@link MediaInput.packets} For packet source
|
|
262
|
+
*/
|
|
263
|
+
frames(packets: AsyncIterable<Packet>): AsyncGenerator<Frame>;
|
|
264
|
+
/**
|
|
265
|
+
* Flush decoder and signal end-of-stream.
|
|
266
|
+
*
|
|
267
|
+
* Sends null packet to decoder to signal end-of-stream.
|
|
268
|
+
* Does nothing if decoder is closed.
|
|
269
|
+
* Must use receive() or flushFrames() to get remaining buffered frames.
|
|
270
|
+
*
|
|
271
|
+
* Direct mapping to avcodec_send_packet(NULL).
|
|
272
|
+
*
|
|
273
|
+
* @throws {FFmpegError} If flush fails
|
|
221
274
|
*
|
|
222
275
|
* @example
|
|
223
276
|
* ```typescript
|
|
224
|
-
* //
|
|
277
|
+
* // Signal end of stream
|
|
278
|
+
* await decoder.flush();
|
|
279
|
+
*
|
|
280
|
+
* // Then get remaining frames
|
|
225
281
|
* let frame;
|
|
226
|
-
* while ((frame = await decoder.
|
|
282
|
+
* while ((frame = await decoder.receive()) !== null) {
|
|
227
283
|
* console.log('Got buffered frame');
|
|
228
|
-
* await processFrame(frame);
|
|
229
284
|
* frame.free();
|
|
230
285
|
* }
|
|
231
286
|
* ```
|
|
232
287
|
*
|
|
233
|
-
* @see {@link flushFrames} For async iteration
|
|
234
|
-
* @see {@link
|
|
288
|
+
* @see {@link flushFrames} For convenient async iteration
|
|
289
|
+
* @see {@link receive} For getting buffered frames
|
|
235
290
|
*/
|
|
236
|
-
flush(): Promise<
|
|
291
|
+
flush(): Promise<void>;
|
|
237
292
|
/**
|
|
238
293
|
* Flush all buffered frames as async generator.
|
|
239
294
|
*
|
|
240
295
|
* Convenient async iteration over remaining frames.
|
|
241
|
-
* Automatically
|
|
296
|
+
* Automatically sends flush signal and retrieves buffered frames.
|
|
242
297
|
* Useful for end-of-stream processing.
|
|
243
298
|
*
|
|
244
|
-
* @yields Buffered frames
|
|
245
|
-
* @throws {Error} If decoder is closed
|
|
299
|
+
* @yields {Frame} Buffered frames
|
|
246
300
|
*
|
|
247
301
|
* @example
|
|
248
302
|
* ```typescript
|
|
@@ -254,62 +308,47 @@ export declare class Decoder implements Disposable {
|
|
|
254
308
|
* }
|
|
255
309
|
* ```
|
|
256
310
|
*
|
|
257
|
-
* @see {@link flush} For
|
|
311
|
+
* @see {@link flush} For signaling end-of-stream
|
|
258
312
|
* @see {@link frames} For complete pipeline
|
|
259
313
|
*/
|
|
260
314
|
flushFrames(): AsyncGenerator<Frame>;
|
|
261
315
|
/**
|
|
262
|
-
*
|
|
316
|
+
* Receive frame from decoder.
|
|
263
317
|
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
*
|
|
267
|
-
*
|
|
318
|
+
* Gets decoded frames from the codec's internal buffer.
|
|
319
|
+
* Handles frame cloning and error checking.
|
|
320
|
+
* Hardware frames include hw_frames_ctx reference.
|
|
321
|
+
* Call repeatedly until null to drain all buffered frames.
|
|
268
322
|
*
|
|
269
|
-
*
|
|
270
|
-
* @yields Decoded frames
|
|
271
|
-
* @throws {Error} If decoder is closed
|
|
272
|
-
* @throws {FFmpegError} If decoding fails
|
|
323
|
+
* Direct mapping to avcodec_receive_frame().
|
|
273
324
|
*
|
|
274
|
-
* @
|
|
275
|
-
* ```typescript
|
|
276
|
-
* await using input = await MediaInput.open('video.mp4');
|
|
277
|
-
* using decoder = await Decoder.create(input.video());
|
|
325
|
+
* @returns Cloned frame or null if no frames available
|
|
278
326
|
*
|
|
279
|
-
*
|
|
280
|
-
* console.log(`Frame: ${frame.width}x${frame.height}`);
|
|
281
|
-
* frame.free();
|
|
282
|
-
* }
|
|
283
|
-
* ```
|
|
327
|
+
* @throws {FFmpegError} If receive fails with error other than AVERROR_EAGAIN or AVERROR_EOF
|
|
284
328
|
*
|
|
285
329
|
* @example
|
|
286
330
|
* ```typescript
|
|
287
|
-
*
|
|
288
|
-
*
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* // Frame automatically freed
|
|
331
|
+
* const frame = await decoder.receive();
|
|
332
|
+
* if (frame) {
|
|
333
|
+
* console.log('Got decoded frame');
|
|
292
334
|
* frame.free();
|
|
293
335
|
* }
|
|
294
336
|
* ```
|
|
295
337
|
*
|
|
296
338
|
* @example
|
|
297
339
|
* ```typescript
|
|
298
|
-
*
|
|
299
|
-
*
|
|
300
|
-
*
|
|
301
|
-
*
|
|
302
|
-
*
|
|
303
|
-
*
|
|
304
|
-
* output
|
|
305
|
-
* );
|
|
306
|
-
* await control.completion;
|
|
340
|
+
* // Drain all buffered frames
|
|
341
|
+
* let frame;
|
|
342
|
+
* while ((frame = await decoder.receive()) !== null) {
|
|
343
|
+
* console.log(`Frame PTS: ${frame.pts}`);
|
|
344
|
+
* frame.free();
|
|
345
|
+
* }
|
|
307
346
|
* ```
|
|
308
347
|
*
|
|
309
|
-
* @see {@link decode} For
|
|
310
|
-
* @see {@link
|
|
348
|
+
* @see {@link decode} For sending packets and receiving frames
|
|
349
|
+
* @see {@link flush} For signaling end-of-stream
|
|
311
350
|
*/
|
|
312
|
-
|
|
351
|
+
receive(): Promise<Frame | null>;
|
|
313
352
|
/**
|
|
314
353
|
* Close decoder and free resources.
|
|
315
354
|
*
|
|
@@ -330,24 +369,6 @@ export declare class Decoder implements Disposable {
|
|
|
330
369
|
* @see {@link Symbol.dispose} For automatic cleanup
|
|
331
370
|
*/
|
|
332
371
|
close(): void;
|
|
333
|
-
/**
|
|
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
|
|
349
|
-
*/
|
|
350
|
-
getStreamIndex(): number;
|
|
351
372
|
/**
|
|
352
373
|
* Get stream object.
|
|
353
374
|
*
|
|
@@ -356,43 +377,38 @@ export declare class Decoder implements Disposable {
|
|
|
356
377
|
*
|
|
357
378
|
* @returns Stream object
|
|
358
379
|
*
|
|
359
|
-
* @
|
|
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
|
-
* ```
|
|
380
|
+
* @internal
|
|
365
381
|
*
|
|
366
|
-
* @see {@link Stream} For stream
|
|
367
|
-
* @see {@link getStreamIndex} For index only
|
|
382
|
+
* @see {@link Stream} For stream details
|
|
368
383
|
*/
|
|
369
384
|
getStream(): Stream;
|
|
370
385
|
/**
|
|
371
|
-
* Get
|
|
386
|
+
* Get decoder codec.
|
|
372
387
|
*
|
|
373
|
-
* Returns the
|
|
374
|
-
*
|
|
388
|
+
* Returns the codec used by this decoder.
|
|
389
|
+
* Useful for checking codec capabilities and properties.
|
|
375
390
|
*
|
|
376
|
-
* @returns Codec
|
|
391
|
+
* @returns Codec instance
|
|
377
392
|
*
|
|
378
393
|
* @internal
|
|
394
|
+
*
|
|
395
|
+
* @see {@link Codec} For codec details
|
|
379
396
|
*/
|
|
380
|
-
|
|
397
|
+
getCodec(): Codec;
|
|
381
398
|
/**
|
|
382
|
-
*
|
|
383
|
-
*
|
|
384
|
-
* Internal method to get decoded frames from codec.
|
|
385
|
-
* Handles frame cloning and error checking.
|
|
386
|
-
* Hardware frames include hw_frames_ctx reference.
|
|
399
|
+
* Get underlying codec context.
|
|
387
400
|
*
|
|
388
|
-
*
|
|
401
|
+
* Returns the codec context for advanced operations.
|
|
402
|
+
* Useful for accessing low-level codec properties and settings.
|
|
403
|
+
* Returns null if decoder is closed.
|
|
389
404
|
*
|
|
390
|
-
* @returns
|
|
405
|
+
* @returns Codec context or null if closed
|
|
391
406
|
*
|
|
392
|
-
* @
|
|
407
|
+
* @internal
|
|
393
408
|
*
|
|
409
|
+
* @see {@link CodecContext} For context details
|
|
394
410
|
*/
|
|
395
|
-
|
|
411
|
+
getCodecContext(): CodecContext | null;
|
|
396
412
|
/**
|
|
397
413
|
* Dispose of decoder.
|
|
398
414
|
*
|