node-av 1.1.0 → 1.3.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 -59
- package/dist/api/bitstream-filter.d.ts +183 -123
- package/dist/api/bitstream-filter.js +185 -127
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +282 -130
- package/dist/api/decoder.js +290 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +249 -160
- package/dist/api/encoder.js +276 -207
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +1944 -96
- package/dist/api/filter-presets.js +2059 -105
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +264 -200
- package/dist/api/filter.js +269 -231
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +246 -117
- package/dist/api/hardware.js +440 -217
- 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 -55
- package/dist/api/io-stream.js +43 -40
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -139
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +208 -126
- package/dist/api/media-output.js +212 -126
- package/dist/api/media-output.js.map +1 -1
- package/dist/api/pipeline.d.ts +361 -38
- package/dist/api/pipeline.js +255 -14
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/types.d.ts +26 -187
- 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.d.ts +1 -2
- package/dist/api/utils.js +11 -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/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.d.ts +1 -0
- package/dist/lib/binding.js +7 -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 +266 -283
- package/dist/lib/codec.js +270 -287
- 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 +3 -2
- package/dist/lib/index.js +3 -3
- 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 +118 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +437 -218
- package/dist/lib/option.js +462 -226
- 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 +435 -181
- package/dist/lib/utilities.js +438 -182
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +0 -1
- package/install/ffmpeg.js +0 -11
- package/package.json +25 -18
- package/release_notes.md +24 -59
- package/CHANGELOG.md +0 -8
|
@@ -1,83 +1,84 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MediaInput - Unified Input Handler for FFmpeg
|
|
3
|
-
*
|
|
4
|
-
* Provides a high-level interface for opening and reading media from various sources.
|
|
5
|
-
* Supports files, URLs, and Buffers with automatic format detection.
|
|
6
|
-
*
|
|
7
|
-
* Central entry point for all media input operations.
|
|
8
|
-
* Manages FormatContext lifecycle and provides stream information.
|
|
9
|
-
*
|
|
10
|
-
* @module api/media-input
|
|
11
|
-
*/
|
|
12
1
|
import { FormatContext, Packet } from '../lib/index.js';
|
|
13
2
|
import type { AVMediaType, AVSeekFlag } from '../constants/constants.js';
|
|
14
3
|
import type { Stream } from '../lib/index.js';
|
|
15
4
|
import type { MediaInputOptions, RawData } from './types.js';
|
|
16
5
|
/**
|
|
17
|
-
*
|
|
18
|
-
*
|
|
19
|
-
* Opens and provides access to media streams from various sources.
|
|
20
|
-
* Automatically detects format and finds stream information.
|
|
6
|
+
* High-level media input for reading and demuxing media files.
|
|
21
7
|
*
|
|
22
|
-
*
|
|
23
|
-
*
|
|
8
|
+
* Provides simplified access to media streams, packets, and metadata.
|
|
9
|
+
* Handles file opening, format detection, and stream information extraction.
|
|
10
|
+
* Supports files, URLs, buffers, and raw data input with automatic cleanup.
|
|
11
|
+
* Essential component for media processing pipelines and transcoding.
|
|
24
12
|
*
|
|
25
13
|
* @example
|
|
26
14
|
* ```typescript
|
|
27
15
|
* import { MediaInput } from 'node-av/api';
|
|
28
16
|
*
|
|
29
|
-
* // Open
|
|
30
|
-
*
|
|
31
|
-
* console.log(`
|
|
32
|
-
* console.log(`Duration: ${
|
|
17
|
+
* // Open media file
|
|
18
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
19
|
+
* console.log(`Format: ${input.formatName}`);
|
|
20
|
+
* console.log(`Duration: ${input.duration}s`);
|
|
33
21
|
*
|
|
34
|
-
* //
|
|
35
|
-
* const
|
|
36
|
-
* const media = await MediaInput.open(buffer);
|
|
37
|
-
*
|
|
38
|
-
* // Iterate packets
|
|
39
|
-
* for await (const packet of media.packets()) {
|
|
22
|
+
* // Process packets
|
|
23
|
+
* for await (const packet of input.packets()) {
|
|
40
24
|
* console.log(`Packet from stream ${packet.streamIndex}`);
|
|
25
|
+
* packet.free();
|
|
41
26
|
* }
|
|
42
27
|
* ```
|
|
28
|
+
*
|
|
29
|
+
* @example
|
|
30
|
+
* ```typescript
|
|
31
|
+
* // From buffer
|
|
32
|
+
* const buffer = await fs.readFile('video.mp4');
|
|
33
|
+
* await using input = await MediaInput.open(buffer);
|
|
34
|
+
*
|
|
35
|
+
* // Access streams
|
|
36
|
+
* const videoStream = input.video();
|
|
37
|
+
* const audioStream = input.audio();
|
|
38
|
+
* ```
|
|
39
|
+
*
|
|
40
|
+
* @see {@link MediaOutput} For writing media files
|
|
41
|
+
* @see {@link Decoder} For decoding packets to frames
|
|
42
|
+
* @see {@link FormatContext} For low-level API
|
|
43
43
|
*/
|
|
44
44
|
export declare class MediaInput implements AsyncDisposable {
|
|
45
45
|
private formatContext;
|
|
46
46
|
private _streams;
|
|
47
47
|
private ioContext?;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* Private constructor - use MediaInput.open() to create instances.
|
|
52
|
-
*
|
|
53
|
-
* Parses stream information immediately after construction.
|
|
54
|
-
*
|
|
55
|
-
* @param formatContext - Opened FormatContext
|
|
49
|
+
* @param formatContext - Opened format context
|
|
50
|
+
* @internal
|
|
56
51
|
*/
|
|
57
52
|
private constructor();
|
|
58
53
|
/**
|
|
59
|
-
* Probe
|
|
54
|
+
* Probe media format without fully opening the file.
|
|
60
55
|
*
|
|
61
|
-
* Detects
|
|
62
|
-
*
|
|
56
|
+
* Detects format by analyzing file headers and content.
|
|
57
|
+
* Useful for format validation before processing.
|
|
63
58
|
*
|
|
64
|
-
*
|
|
59
|
+
* Direct mapping to av_probe_input_format().
|
|
65
60
|
*
|
|
61
|
+
* @param input - File path or buffer to probe
|
|
66
62
|
* @returns Format information or null if unrecognized
|
|
67
63
|
*
|
|
68
64
|
* @example
|
|
69
65
|
* ```typescript
|
|
70
|
-
* // Probe a file
|
|
71
66
|
* const info = await MediaInput.probeFormat('video.mp4');
|
|
72
67
|
* if (info) {
|
|
73
68
|
* console.log(`Format: ${info.format}`);
|
|
74
69
|
* console.log(`Confidence: ${info.confidence}%`);
|
|
75
70
|
* }
|
|
71
|
+
* ```
|
|
76
72
|
*
|
|
77
|
-
*
|
|
78
|
-
*
|
|
73
|
+
* @example
|
|
74
|
+
* ```typescript
|
|
75
|
+
* // Probe from buffer
|
|
76
|
+
* const buffer = await fs.readFile('video.webm');
|
|
79
77
|
* const info = await MediaInput.probeFormat(buffer);
|
|
78
|
+
* console.log(`MIME type: ${info?.mimeType}`);
|
|
80
79
|
* ```
|
|
80
|
+
*
|
|
81
|
+
* @see {@link InputFormat.probe} For low-level probing
|
|
81
82
|
*/
|
|
82
83
|
static probeFormat(input: string | Buffer): Promise<{
|
|
83
84
|
format: string;
|
|
@@ -87,218 +88,320 @@ export declare class MediaInput implements AsyncDisposable {
|
|
|
87
88
|
confidence: number;
|
|
88
89
|
} | null>;
|
|
89
90
|
/**
|
|
90
|
-
* Open
|
|
91
|
+
* Open media from file, URL, buffer, or raw data.
|
|
91
92
|
*
|
|
92
|
-
*
|
|
93
|
-
*
|
|
93
|
+
* Automatically detects format and extracts stream information.
|
|
94
|
+
* Supports various input sources with flexible configuration.
|
|
95
|
+
* Creates demuxer ready for packet extraction.
|
|
94
96
|
*
|
|
95
|
-
*
|
|
97
|
+
* Direct mapping to avformat_open_input() and avformat_find_stream_info().
|
|
96
98
|
*
|
|
97
|
-
* @param input - File path, URL, or
|
|
98
|
-
* @param options -
|
|
99
|
+
* @param input - File path, URL, buffer, or raw data descriptor
|
|
100
|
+
* @param options - Input configuration options
|
|
101
|
+
* @returns Opened media input instance
|
|
99
102
|
*
|
|
100
|
-
* @
|
|
103
|
+
* @throws {Error} If format not found or open fails
|
|
101
104
|
*
|
|
102
|
-
* @throws {
|
|
105
|
+
* @throws {FFmpegError} If FFmpeg operations fail
|
|
103
106
|
*
|
|
104
107
|
* @example
|
|
105
108
|
* ```typescript
|
|
106
|
-
* //
|
|
107
|
-
*
|
|
108
|
-
*
|
|
109
|
-
* // From URL
|
|
110
|
-
* const media = await MediaInput.open('https://example.com/video.mp4');
|
|
111
|
-
*
|
|
112
|
-
* // From Buffer
|
|
113
|
-
* const buffer = await fs.readFile('video.mp4');
|
|
114
|
-
* const media = await MediaInput.open(buffer);
|
|
109
|
+
* // Open file
|
|
110
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
115
111
|
* ```
|
|
116
|
-
*/
|
|
117
|
-
static open(input: string | Buffer, options?: MediaInputOptions): Promise<MediaInput>;
|
|
118
|
-
/**
|
|
119
|
-
* Open raw video or audio data.
|
|
120
112
|
*
|
|
121
|
-
* @
|
|
122
|
-
*
|
|
123
|
-
*
|
|
113
|
+
* @example
|
|
114
|
+
* ```typescript
|
|
115
|
+
* // Open URL
|
|
116
|
+
* await using input = await MediaInput.open('http://example.com/stream.m3u8');
|
|
117
|
+
* ```
|
|
124
118
|
*
|
|
125
119
|
* @example
|
|
126
120
|
* ```typescript
|
|
127
|
-
* //
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
*
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
* frameRate: 30
|
|
121
|
+
* // Open with options
|
|
122
|
+
* await using input = await MediaInput.open('rtsp://camera.local', {
|
|
123
|
+
* format: 'rtsp',
|
|
124
|
+
* options: {
|
|
125
|
+
* rtsp_transport: 'tcp',
|
|
126
|
+
* analyzeduration: '5000000'
|
|
127
|
+
* }
|
|
135
128
|
* });
|
|
129
|
+
* ```
|
|
136
130
|
*
|
|
137
|
-
*
|
|
138
|
-
*
|
|
139
|
-
*
|
|
140
|
-
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
131
|
+
* @example
|
|
132
|
+
* ```typescript
|
|
133
|
+
* // Open raw video data
|
|
134
|
+
* await using input = await MediaInput.open({
|
|
135
|
+
* type: 'video',
|
|
136
|
+
* input: rawBuffer,
|
|
137
|
+
* width: 1920,
|
|
138
|
+
* height: 1080,
|
|
139
|
+
* pixelFormat: AV_PIX_FMT_YUV420P,
|
|
140
|
+
* frameRate: { num: 30, den: 1 }
|
|
144
141
|
* });
|
|
145
142
|
* ```
|
|
143
|
+
*
|
|
144
|
+
* @see {@link MediaInputOptions} For configuration options
|
|
145
|
+
* @see {@link RawData} For raw data input
|
|
146
146
|
*/
|
|
147
|
+
static open(input: string | Buffer, options?: MediaInputOptions): Promise<MediaInput>;
|
|
147
148
|
static open(rawData: RawData, options?: MediaInputOptions): Promise<MediaInput>;
|
|
148
149
|
/**
|
|
149
|
-
* Get all streams in the
|
|
150
|
+
* Get all streams in the media.
|
|
150
151
|
*
|
|
151
|
-
* @
|
|
152
|
+
* @example
|
|
153
|
+
* ```typescript
|
|
154
|
+
* for (const stream of input.streams) {
|
|
155
|
+
* console.log(`Stream ${stream.index}: ${stream.codecpar.codecType}`);
|
|
156
|
+
* }
|
|
157
|
+
* ```
|
|
152
158
|
*/
|
|
153
159
|
get streams(): Stream[];
|
|
154
160
|
/**
|
|
155
161
|
* Get media duration in seconds.
|
|
156
162
|
*
|
|
157
|
-
* Returns 0 if duration is not available.
|
|
163
|
+
* Returns 0 if duration is unknown or not available.
|
|
158
164
|
*
|
|
159
|
-
* @
|
|
165
|
+
* @example
|
|
166
|
+
* ```typescript
|
|
167
|
+
* console.log(`Duration: ${input.duration} seconds`);
|
|
168
|
+
* ```
|
|
160
169
|
*/
|
|
161
170
|
get duration(): number;
|
|
162
171
|
/**
|
|
163
|
-
* Get
|
|
172
|
+
* Get media bitrate in kilobits per second.
|
|
164
173
|
*
|
|
165
|
-
* Returns 0 if bitrate is
|
|
174
|
+
* Returns 0 if bitrate is unknown.
|
|
166
175
|
*
|
|
167
|
-
* @
|
|
176
|
+
* @example
|
|
177
|
+
* ```typescript
|
|
178
|
+
* console.log(`Bitrate: ${input.bitRate} kbps`);
|
|
179
|
+
* ```
|
|
168
180
|
*/
|
|
169
181
|
get bitRate(): number;
|
|
170
182
|
/**
|
|
171
|
-
* Get
|
|
183
|
+
* Get media metadata.
|
|
184
|
+
*
|
|
185
|
+
* Returns all metadata tags as key-value pairs.
|
|
172
186
|
*
|
|
173
|
-
* @
|
|
187
|
+
* @example
|
|
188
|
+
* ```typescript
|
|
189
|
+
* const metadata = input.metadata;
|
|
190
|
+
* console.log(`Title: ${metadata.title}`);
|
|
191
|
+
* console.log(`Artist: ${metadata.artist}`);
|
|
192
|
+
* ```
|
|
174
193
|
*/
|
|
175
194
|
get metadata(): Record<string, string>;
|
|
176
195
|
/**
|
|
177
|
-
* Get
|
|
196
|
+
* Get format name.
|
|
178
197
|
*
|
|
179
|
-
* @
|
|
198
|
+
* @example
|
|
199
|
+
* ```typescript
|
|
200
|
+
* console.log(`Format: ${input.formatName}`); // "mov,mp4,m4a,3gp,3g2,mj2"
|
|
201
|
+
* ```
|
|
180
202
|
*/
|
|
181
203
|
get formatName(): string;
|
|
182
204
|
/**
|
|
183
|
-
* Get
|
|
205
|
+
* Get format long name.
|
|
184
206
|
*
|
|
185
|
-
* @
|
|
207
|
+
* @example
|
|
208
|
+
* ```typescript
|
|
209
|
+
* console.log(`Format: ${input.formatLongName}`); // "QuickTime / MOV"
|
|
210
|
+
* ```
|
|
186
211
|
*/
|
|
187
212
|
get formatLongName(): string;
|
|
188
213
|
/**
|
|
189
|
-
* Get
|
|
214
|
+
* Get video stream by index.
|
|
190
215
|
*
|
|
191
|
-
*
|
|
216
|
+
* Returns the nth video stream (0-based index).
|
|
217
|
+
* Returns undefined if stream doesn't exist.
|
|
192
218
|
*
|
|
193
|
-
* @
|
|
219
|
+
* @param index - Video stream index (default: 0)
|
|
220
|
+
* @returns Video stream or undefined
|
|
194
221
|
*
|
|
195
222
|
* @example
|
|
196
223
|
* ```typescript
|
|
197
|
-
* const videoStream =
|
|
224
|
+
* const videoStream = input.video();
|
|
198
225
|
* if (videoStream) {
|
|
199
|
-
* console.log(`Video: ${videoStream.width}x${videoStream.height}`);
|
|
226
|
+
* console.log(`Video: ${videoStream.codecpar.width}x${videoStream.codecpar.height}`);
|
|
200
227
|
* }
|
|
201
228
|
* ```
|
|
229
|
+
*
|
|
230
|
+
* @example
|
|
231
|
+
* ```typescript
|
|
232
|
+
* // Get second video stream
|
|
233
|
+
* const secondVideo = input.video(1);
|
|
234
|
+
* ```
|
|
235
|
+
*
|
|
236
|
+
* @see {@link audio} For audio streams
|
|
237
|
+
* @see {@link findBestStream} For automatic selection
|
|
202
238
|
*/
|
|
203
239
|
video(index?: number): Stream | undefined;
|
|
204
240
|
/**
|
|
205
|
-
* Get
|
|
241
|
+
* Get audio stream by index.
|
|
206
242
|
*
|
|
207
|
-
*
|
|
243
|
+
* Returns the nth audio stream (0-based index).
|
|
244
|
+
* Returns undefined if stream doesn't exist.
|
|
208
245
|
*
|
|
209
|
-
* @
|
|
246
|
+
* @param index - Audio stream index (default: 0)
|
|
247
|
+
* @returns Audio stream or undefined
|
|
210
248
|
*
|
|
211
249
|
* @example
|
|
212
250
|
* ```typescript
|
|
213
|
-
* const audioStream =
|
|
251
|
+
* const audioStream = input.audio();
|
|
214
252
|
* if (audioStream) {
|
|
215
|
-
* console.log(`Audio: ${audioStream.sampleRate}Hz
|
|
253
|
+
* console.log(`Audio: ${audioStream.codecpar.sampleRate}Hz`);
|
|
216
254
|
* }
|
|
217
255
|
* ```
|
|
256
|
+
*
|
|
257
|
+
* @example
|
|
258
|
+
* ```typescript
|
|
259
|
+
* // Get second audio stream
|
|
260
|
+
* const secondAudio = input.audio(1);
|
|
261
|
+
* ```
|
|
262
|
+
*
|
|
263
|
+
* @see {@link video} For video streams
|
|
264
|
+
* @see {@link findBestStream} For automatic selection
|
|
218
265
|
*/
|
|
219
266
|
audio(index?: number): Stream | undefined;
|
|
220
267
|
/**
|
|
221
268
|
* Find the best stream of a given type.
|
|
222
269
|
*
|
|
223
|
-
* Uses FFmpeg's stream selection
|
|
270
|
+
* Uses FFmpeg's stream selection algorithm.
|
|
271
|
+
* Considers codec support, default flags, and quality.
|
|
224
272
|
*
|
|
225
|
-
*
|
|
273
|
+
* Direct mapping to av_find_best_stream().
|
|
226
274
|
*
|
|
227
|
-
* @param type - Media type to
|
|
275
|
+
* @param type - Media type to find
|
|
276
|
+
* @returns Best stream or undefined if not found
|
|
277
|
+
*
|
|
278
|
+
* @example
|
|
279
|
+
* ```typescript
|
|
280
|
+
* import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
|
|
281
|
+
*
|
|
282
|
+
* const bestVideo = input.findBestStream(AVMEDIA_TYPE_VIDEO);
|
|
283
|
+
* if (bestVideo) {
|
|
284
|
+
* const decoder = await Decoder.create(bestVideo);
|
|
285
|
+
* }
|
|
286
|
+
* ```
|
|
228
287
|
*
|
|
229
|
-
* @
|
|
288
|
+
* @see {@link video} For direct video stream access
|
|
289
|
+
* @see {@link audio} For direct audio stream access
|
|
230
290
|
*/
|
|
231
291
|
findBestStream(type: AVMediaType): Stream | undefined;
|
|
232
292
|
/**
|
|
233
|
-
*
|
|
293
|
+
* Read packets from media as async generator.
|
|
234
294
|
*
|
|
235
|
-
*
|
|
236
|
-
* Automatically
|
|
295
|
+
* Yields demuxed packets for processing.
|
|
296
|
+
* Automatically handles packet memory management.
|
|
297
|
+
* Optionally filters packets by stream index.
|
|
237
298
|
*
|
|
238
|
-
*
|
|
299
|
+
* Direct mapping to av_read_frame().
|
|
239
300
|
*
|
|
240
|
-
* @
|
|
301
|
+
* @param index - Optional stream index to filter
|
|
302
|
+
* @yields Demuxed packets (must be freed by caller)
|
|
303
|
+
* @throws {Error} If packet cloning fails
|
|
241
304
|
*
|
|
242
305
|
* @example
|
|
243
306
|
* ```typescript
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
247
|
-
*
|
|
248
|
-
* }
|
|
307
|
+
* // Read all packets
|
|
308
|
+
* for await (const packet of input.packets()) {
|
|
309
|
+
* console.log(`Packet: stream=${packet.streamIndex}, pts=${packet.pts}`);
|
|
310
|
+
* packet.free();
|
|
249
311
|
* }
|
|
250
312
|
* ```
|
|
313
|
+
*
|
|
314
|
+
* @example
|
|
315
|
+
* ```typescript
|
|
316
|
+
* // Read only video packets
|
|
317
|
+
* const videoStream = input.video();
|
|
318
|
+
* for await (const packet of input.packets(videoStream.index)) {
|
|
319
|
+
* // Process video packet
|
|
320
|
+
* packet.free();
|
|
321
|
+
* }
|
|
322
|
+
* ```
|
|
323
|
+
*
|
|
324
|
+
* @see {@link Decoder.frames} For decoding packets
|
|
251
325
|
*/
|
|
252
326
|
packets(index?: number): AsyncGenerator<Packet>;
|
|
253
327
|
/**
|
|
254
|
-
* Seek to
|
|
328
|
+
* Seek to timestamp in media.
|
|
255
329
|
*
|
|
256
|
-
*
|
|
330
|
+
* Seeks to the specified position in seconds.
|
|
331
|
+
* Can seek in specific stream or globally.
|
|
257
332
|
*
|
|
258
|
-
*
|
|
333
|
+
* Direct mapping to av_seek_frame().
|
|
259
334
|
*
|
|
260
|
-
* @param timestamp - Target
|
|
261
|
-
* @param streamIndex - Stream
|
|
262
|
-
* @param flags - Seek flags (
|
|
335
|
+
* @param timestamp - Target position in seconds
|
|
336
|
+
* @param streamIndex - Stream index or -1 for global (default: -1)
|
|
337
|
+
* @param flags - Seek flags (default: AVFLAG_NONE)
|
|
338
|
+
* @returns 0 on success, negative on error
|
|
263
339
|
*
|
|
264
|
-
* @
|
|
340
|
+
* @example
|
|
341
|
+
* ```typescript
|
|
342
|
+
* // Seek to 30 seconds
|
|
343
|
+
* const ret = await input.seek(30);
|
|
344
|
+
* FFmpegError.throwIfError(ret, 'seek failed');
|
|
345
|
+
* ```
|
|
346
|
+
*
|
|
347
|
+
* @example
|
|
348
|
+
* ```typescript
|
|
349
|
+
* import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
|
|
350
|
+
*
|
|
351
|
+
* // Seek to keyframe before 60 seconds
|
|
352
|
+
* await input.seek(60, -1, AVSEEK_FLAG_BACKWARD);
|
|
353
|
+
* ```
|
|
354
|
+
*
|
|
355
|
+
* @see {@link AVSeekFlag} For seek flags
|
|
265
356
|
*/
|
|
266
357
|
seek(timestamp: number, streamIndex?: number, flags?: AVSeekFlag): Promise<number>;
|
|
267
358
|
/**
|
|
268
|
-
* Close
|
|
359
|
+
* Close media input and free resources.
|
|
269
360
|
*
|
|
270
|
-
*
|
|
361
|
+
* Releases format context and I/O context.
|
|
362
|
+
* Safe to call multiple times.
|
|
363
|
+
* Automatically called by Symbol.asyncDispose.
|
|
364
|
+
*
|
|
365
|
+
* Direct mapping to avformat_close_input().
|
|
366
|
+
*
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* const input = await MediaInput.open('video.mp4');
|
|
370
|
+
* try {
|
|
371
|
+
* // Use input
|
|
372
|
+
* } finally {
|
|
373
|
+
* await input.close();
|
|
374
|
+
* }
|
|
375
|
+
* ```
|
|
271
376
|
*
|
|
272
|
-
*
|
|
273
|
-
* use-after-free errors.
|
|
377
|
+
* @see {@link Symbol.asyncDispose} For automatic cleanup
|
|
274
378
|
*/
|
|
275
379
|
close(): Promise<void>;
|
|
276
380
|
/**
|
|
277
|
-
* Get
|
|
381
|
+
* Get underlying format context.
|
|
278
382
|
*
|
|
279
|
-
*
|
|
383
|
+
* Returns the internal format context for advanced operations.
|
|
280
384
|
*
|
|
281
|
-
*
|
|
282
|
-
*
|
|
283
|
-
* @returns FFmpeg FormatContext
|
|
385
|
+
* @returns Format context
|
|
284
386
|
*
|
|
285
387
|
* @internal
|
|
286
388
|
*/
|
|
287
389
|
getFormatContext(): FormatContext;
|
|
288
390
|
/**
|
|
289
|
-
*
|
|
290
|
-
*
|
|
291
|
-
* Implements the AsyncDisposable interface for automatic cleanup.
|
|
391
|
+
* Dispose of media input.
|
|
292
392
|
*
|
|
293
|
-
*
|
|
393
|
+
* Implements AsyncDisposable interface for automatic cleanup.
|
|
394
|
+
* Equivalent to calling close().
|
|
294
395
|
*
|
|
295
396
|
* @example
|
|
296
397
|
* ```typescript
|
|
297
398
|
* {
|
|
298
|
-
* await using
|
|
299
|
-
* //
|
|
399
|
+
* await using input = await MediaInput.open('video.mp4');
|
|
400
|
+
* // Process media...
|
|
300
401
|
* } // Automatically closed
|
|
301
402
|
* ```
|
|
403
|
+
*
|
|
404
|
+
* @see {@link close} For manual cleanup
|
|
302
405
|
*/
|
|
303
406
|
[Symbol.asyncDispose](): Promise<void>;
|
|
304
407
|
}
|