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
|
@@ -9,816 +9,708 @@ import type { IOContext } from './io-context.js';
|
|
|
9
9
|
import type { NativeFormatContext, NativeWrapper } from './native-types.js';
|
|
10
10
|
import type { Packet } from './packet.js';
|
|
11
11
|
/**
|
|
12
|
-
*
|
|
12
|
+
* Container format context for reading/writing multimedia files.
|
|
13
13
|
*
|
|
14
|
-
* Central structure for
|
|
15
|
-
*
|
|
16
|
-
*
|
|
14
|
+
* Central structure for demuxing (reading) and muxing (writing) media files.
|
|
15
|
+
* Manages streams, packets, metadata, and format-specific operations.
|
|
16
|
+
* Supports both file-based and custom I/O through IOContext.
|
|
17
|
+
* Essential for all file-based media operations.
|
|
17
18
|
*
|
|
18
19
|
* Direct mapping to FFmpeg's AVFormatContext.
|
|
19
20
|
*
|
|
20
21
|
* @example
|
|
21
22
|
* ```typescript
|
|
22
|
-
* import { FormatContext,
|
|
23
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
24
|
+
* import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
|
|
23
25
|
*
|
|
24
|
-
* //
|
|
26
|
+
* // Open input file
|
|
25
27
|
* const ctx = new FormatContext();
|
|
26
|
-
* ctx.
|
|
27
|
-
*
|
|
28
|
-
* const ret = await ctx.openInput('video.mp4', null, null);
|
|
28
|
+
* let ret = await ctx.openInput('input.mp4');
|
|
29
29
|
* FFmpegError.throwIfError(ret, 'openInput');
|
|
30
30
|
*
|
|
31
|
-
*
|
|
32
|
-
* FFmpegError.throwIfError(
|
|
31
|
+
* ret = await ctx.findStreamInfo();
|
|
32
|
+
* FFmpegError.throwIfError(ret, 'findStreamInfo');
|
|
33
|
+
*
|
|
34
|
+
* // Find video stream
|
|
35
|
+
* const videoIndex = ctx.findBestStream(AVMEDIA_TYPE_VIDEO);
|
|
36
|
+
* if (videoIndex < 0) {
|
|
37
|
+
* throw new Error('No video stream found');
|
|
38
|
+
* }
|
|
33
39
|
*
|
|
40
|
+
* // Read packets
|
|
34
41
|
* const packet = new Packet();
|
|
35
42
|
* packet.alloc();
|
|
36
|
-
*
|
|
37
|
-
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
* // Process packet
|
|
43
|
+
* while ((ret = await ctx.readFrame(packet)) >= 0) {
|
|
44
|
+
* if (packet.streamIndex === videoIndex) {
|
|
45
|
+
* // Process video packet
|
|
46
|
+
* }
|
|
41
47
|
* packet.unref();
|
|
42
48
|
* }
|
|
43
49
|
*
|
|
50
|
+
* // Cleanup
|
|
44
51
|
* await ctx.closeInput();
|
|
45
|
-
* ctx.freeContext();
|
|
46
|
-
* ```
|
|
47
|
-
*
|
|
48
|
-
* @example
|
|
49
|
-
* ```typescript
|
|
50
|
-
* import { FormatContext, FFmpegError } from 'node-av';
|
|
51
|
-
*
|
|
52
|
-
* // Muxing - explicit control
|
|
53
|
-
* const ctx = new FormatContext();
|
|
54
|
-
* const ret = ctx.allocOutputContext2(null, 'mp4', 'output.mp4');
|
|
55
|
-
* FFmpegError.throwIfError(ret, 'allocOutputContext2');
|
|
56
|
-
*
|
|
57
|
-
* // Add streams
|
|
58
|
-
* const stream = ctx.newStream(null);
|
|
59
|
-
*
|
|
60
|
-
* // Write header
|
|
61
|
-
* const headerRet = await ctx.writeHeader(null);
|
|
62
|
-
* FFmpegError.throwIfError(headerRet, 'writeHeader');
|
|
63
|
-
*
|
|
64
|
-
* // Write packets
|
|
65
|
-
* const writeRet = await ctx.interleavedWriteFrame(packet);
|
|
66
|
-
* FFmpegError.throwIfError(writeRet, 'interleavedWriteFrame');
|
|
67
|
-
*
|
|
68
|
-
* // Finalize
|
|
69
|
-
* const trailerRet = await ctx.writeTrailer();
|
|
70
|
-
* FFmpegError.throwIfError(trailerRet, 'writeTrailer');
|
|
71
|
-
* ctx.freeContext();
|
|
72
52
|
* ```
|
|
73
53
|
*
|
|
74
|
-
* @see
|
|
75
|
-
* @see {@link
|
|
54
|
+
* @see [AVFormatContext](https://ffmpeg.org/doxygen/trunk/structAVFormatContext.html) - FFmpeg Doxygen
|
|
55
|
+
* @see {@link InputFormat} For supported input formats
|
|
56
|
+
* @see {@link OutputFormat} For supported output formats
|
|
76
57
|
* @see {@link Stream} For stream management
|
|
77
|
-
* @see {@link Packet} For packet handling
|
|
78
58
|
*/
|
|
79
59
|
export declare class FormatContext extends OptionMember<NativeFormatContext> implements AsyncDisposable, NativeWrapper<NativeFormatContext> {
|
|
80
60
|
private _ioContext;
|
|
81
|
-
/**
|
|
82
|
-
* Create a new format context.
|
|
83
|
-
*
|
|
84
|
-
* The context is uninitialized - you must call allocContext() or allocOutputContext2() before use.
|
|
85
|
-
* No FFmpeg resources are allocated until initialization.
|
|
86
|
-
*
|
|
87
|
-
* Direct wrapper around AVFormatContext.
|
|
88
|
-
*
|
|
89
|
-
* @example
|
|
90
|
-
* ```typescript
|
|
91
|
-
* import { FormatContext, FFmpegError } from 'node-av';
|
|
92
|
-
*
|
|
93
|
-
* const ctx = new FormatContext();
|
|
94
|
-
* ctx.allocContext(); // For demuxing
|
|
95
|
-
* // OR
|
|
96
|
-
* const ret = ctx.allocOutputContext2(null, 'mp4', 'output.mp4'); // For muxing
|
|
97
|
-
* FFmpegError.throwIfError(ret, 'allocOutputContext2');
|
|
98
|
-
* ```
|
|
99
|
-
*/
|
|
100
61
|
constructor();
|
|
101
62
|
/**
|
|
102
|
-
*
|
|
63
|
+
* URL or filename of the media.
|
|
103
64
|
*
|
|
104
|
-
*
|
|
65
|
+
* For input: the opened file path.
|
|
66
|
+
* For output: the target file path.
|
|
105
67
|
*
|
|
106
|
-
*
|
|
107
|
-
* - demuxing: Set by avformat_open_input
|
|
68
|
+
* Direct mapping to AVFormatContext->url.
|
|
108
69
|
*/
|
|
109
70
|
get url(): string | null;
|
|
110
71
|
set url(value: string | null);
|
|
111
72
|
/**
|
|
112
|
-
*
|
|
73
|
+
* Start time of the stream.
|
|
113
74
|
*
|
|
114
|
-
*
|
|
75
|
+
* Position of the first frame in microseconds.
|
|
76
|
+
* AV_NOPTS_VALUE if unknown.
|
|
115
77
|
*
|
|
116
|
-
*
|
|
117
|
-
* - demuxing: Set by libavformat
|
|
78
|
+
* Direct mapping to AVFormatContext->start_time.
|
|
118
79
|
*/
|
|
119
80
|
get startTime(): bigint;
|
|
120
81
|
/**
|
|
121
|
-
* Duration of the stream
|
|
82
|
+
* Duration of the stream.
|
|
122
83
|
*
|
|
123
|
-
*
|
|
84
|
+
* Total stream duration in microseconds.
|
|
85
|
+
* AV_NOPTS_VALUE if unknown.
|
|
124
86
|
*
|
|
125
|
-
*
|
|
126
|
-
* - demuxing: Set by libavformat
|
|
127
|
-
* - muxing: May be set by user
|
|
87
|
+
* Direct mapping to AVFormatContext->duration.
|
|
128
88
|
*/
|
|
129
89
|
get duration(): bigint;
|
|
130
90
|
/**
|
|
131
|
-
* Total stream bitrate
|
|
91
|
+
* Total stream bitrate.
|
|
132
92
|
*
|
|
133
|
-
*
|
|
93
|
+
* Bitrate in bits per second.
|
|
94
|
+
* 0 if unknown.
|
|
134
95
|
*
|
|
135
|
-
*
|
|
96
|
+
* Direct mapping to AVFormatContext->bit_rate.
|
|
136
97
|
*/
|
|
137
98
|
get bitRate(): bigint;
|
|
138
99
|
/**
|
|
139
|
-
*
|
|
100
|
+
* Format-specific flags.
|
|
140
101
|
*
|
|
141
|
-
*
|
|
102
|
+
* Combination of AVFMT_FLAG_* values controlling
|
|
103
|
+
* format behavior (e.g., AVFMT_FLAG_GENPTS).
|
|
142
104
|
*
|
|
143
|
-
*
|
|
144
|
-
* - encoding: Set by user
|
|
145
|
-
* - decoding: Set by user
|
|
105
|
+
* Direct mapping to AVFormatContext->flags.
|
|
146
106
|
*/
|
|
147
107
|
get flags(): AVFormatFlag;
|
|
148
108
|
set flags(value: AVFormatFlag);
|
|
149
109
|
/**
|
|
150
|
-
* Maximum
|
|
110
|
+
* Maximum bytes to probe for format detection.
|
|
151
111
|
*
|
|
152
|
-
*
|
|
112
|
+
* Larger values improve format detection accuracy
|
|
113
|
+
* but increase startup time.
|
|
153
114
|
*
|
|
154
|
-
*
|
|
155
|
-
* - decoding: Set by user
|
|
115
|
+
* Direct mapping to AVFormatContext->probesize.
|
|
156
116
|
*/
|
|
157
117
|
get probesize(): bigint;
|
|
158
118
|
set probesize(value: bigint);
|
|
159
119
|
/**
|
|
160
|
-
* Maximum duration
|
|
120
|
+
* Maximum duration to analyze streams.
|
|
161
121
|
*
|
|
162
|
-
*
|
|
122
|
+
* Time in microseconds to spend analyzing streams.
|
|
123
|
+
* Larger values improve stream detection accuracy.
|
|
163
124
|
*
|
|
164
|
-
*
|
|
165
|
-
* - decoding: Set by user
|
|
125
|
+
* Direct mapping to AVFormatContext->max_analyze_duration.
|
|
166
126
|
*/
|
|
167
127
|
get maxAnalyzeDuration(): bigint;
|
|
168
128
|
set maxAnalyzeDuration(value: bigint);
|
|
169
129
|
/**
|
|
170
|
-
*
|
|
130
|
+
* Container metadata.
|
|
171
131
|
*
|
|
172
|
-
*
|
|
132
|
+
* Key-value pairs of metadata (title, author, etc.).
|
|
173
133
|
*
|
|
174
|
-
*
|
|
175
|
-
* - muxing: May be set by user
|
|
134
|
+
* Direct mapping to AVFormatContext->metadata.
|
|
176
135
|
*/
|
|
177
136
|
get metadata(): Dictionary | null;
|
|
178
137
|
set metadata(value: Dictionary | null);
|
|
179
138
|
/**
|
|
180
|
-
* Input format
|
|
139
|
+
* Input format descriptor.
|
|
181
140
|
*
|
|
182
|
-
*
|
|
141
|
+
* Format used for demuxing. Null for output contexts.
|
|
183
142
|
*
|
|
184
|
-
*
|
|
143
|
+
* Direct mapping to AVFormatContext->iformat.
|
|
185
144
|
*/
|
|
186
145
|
get iformat(): InputFormat | null;
|
|
187
146
|
/**
|
|
188
|
-
* Output format
|
|
147
|
+
* Output format descriptor.
|
|
189
148
|
*
|
|
190
|
-
*
|
|
149
|
+
* Format used for muxing. Null for input contexts.
|
|
191
150
|
*
|
|
192
|
-
*
|
|
151
|
+
* Direct mapping to AVFormatContext->oformat.
|
|
193
152
|
*/
|
|
194
153
|
get oformat(): OutputFormat | null;
|
|
195
154
|
set oformat(value: OutputFormat | null);
|
|
196
155
|
/**
|
|
197
|
-
* I/O context.
|
|
156
|
+
* Custom I/O context.
|
|
198
157
|
*
|
|
199
|
-
*
|
|
158
|
+
* For custom I/O operations instead of file I/O.
|
|
200
159
|
*
|
|
201
|
-
*
|
|
202
|
-
* - muxing: Set by user for custom I/O. Otherwise internal
|
|
203
|
-
*
|
|
204
|
-
* The FormatContext keeps track of the IOContext set by the user.
|
|
205
|
-
* This prevents ownership confusion.
|
|
160
|
+
* Direct mapping to AVFormatContext->pb.
|
|
206
161
|
*/
|
|
207
162
|
get pb(): IOContext | null;
|
|
208
163
|
set pb(value: IOContext | null);
|
|
209
164
|
/**
|
|
210
|
-
* Number of streams in the
|
|
165
|
+
* Number of streams in the container.
|
|
211
166
|
*
|
|
212
|
-
* Direct mapping to AVFormatContext->nb_streams
|
|
167
|
+
* Direct mapping to AVFormatContext->nb_streams.
|
|
213
168
|
*/
|
|
214
169
|
get nbStreams(): number;
|
|
215
170
|
/**
|
|
216
|
-
* Array of streams in the
|
|
171
|
+
* Array of streams in the container.
|
|
172
|
+
*
|
|
173
|
+
* All audio, video, subtitle, and data streams.
|
|
217
174
|
*
|
|
218
|
-
* Direct mapping to AVFormatContext->streams
|
|
175
|
+
* Direct mapping to AVFormatContext->streams.
|
|
219
176
|
*/
|
|
220
177
|
get streams(): Stream[] | null;
|
|
221
178
|
/**
|
|
222
|
-
*
|
|
179
|
+
* Strictness level for standards compliance.
|
|
223
180
|
*
|
|
224
|
-
*
|
|
181
|
+
* FF_COMPLIANCE_* value controlling how strictly
|
|
182
|
+
* to follow specifications.
|
|
225
183
|
*
|
|
226
|
-
*
|
|
184
|
+
* Direct mapping to AVFormatContext->strict_std_compliance.
|
|
227
185
|
*/
|
|
228
186
|
get strictStdCompliance(): number;
|
|
229
187
|
set strictStdCompliance(value: number);
|
|
230
188
|
/**
|
|
231
189
|
* Maximum number of streams.
|
|
232
190
|
*
|
|
233
|
-
*
|
|
191
|
+
* Limit on stream count for security/resource reasons.
|
|
234
192
|
*
|
|
235
|
-
*
|
|
236
|
-
* - decoding: Set by user
|
|
193
|
+
* Direct mapping to AVFormatContext->max_streams.
|
|
237
194
|
*/
|
|
238
195
|
get maxStreams(): number;
|
|
239
196
|
set maxStreams(value: number);
|
|
240
197
|
/**
|
|
241
|
-
* Number of programs
|
|
198
|
+
* Number of programs.
|
|
242
199
|
*
|
|
243
|
-
*
|
|
200
|
+
* For containers with multiple programs (e.g., MPEG-TS).
|
|
244
201
|
*
|
|
245
|
-
*
|
|
202
|
+
* Direct mapping to AVFormatContext->nb_programs.
|
|
246
203
|
*/
|
|
247
204
|
get nbPrograms(): number;
|
|
248
205
|
/**
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
* Direct mapping to avio_tell(AVFormatContext->pb)
|
|
206
|
+
* Number of bytes read/written through I/O context.
|
|
252
207
|
*
|
|
253
|
-
*
|
|
254
|
-
* - demuxing: Current read position
|
|
255
|
-
* - muxing: Current write position
|
|
208
|
+
* Direct mapping to avio_tell(AVFormatContext->pb).
|
|
256
209
|
*/
|
|
257
210
|
get pbBytes(): bigint;
|
|
258
211
|
/**
|
|
259
|
-
* Format
|
|
212
|
+
* Format probe score.
|
|
260
213
|
*
|
|
261
|
-
*
|
|
214
|
+
* Confidence score from format detection (0-100).
|
|
215
|
+
* Higher values indicate more confident detection.
|
|
262
216
|
*
|
|
263
|
-
*
|
|
264
|
-
* - demuxing: Set by format probing
|
|
217
|
+
* Direct mapping to AVFormatContext->probe_score.
|
|
265
218
|
*/
|
|
266
219
|
get probeScore(): number;
|
|
267
220
|
/**
|
|
268
|
-
* Allocate
|
|
221
|
+
* Allocate a format context.
|
|
269
222
|
*
|
|
270
|
-
*
|
|
223
|
+
* Allocates the context structure. Usually not needed
|
|
224
|
+
* as openInput/allocOutputContext2 handle this.
|
|
225
|
+
*
|
|
226
|
+
* Direct mapping to avformat_alloc_context().
|
|
271
227
|
*
|
|
272
228
|
* @example
|
|
273
229
|
* ```typescript
|
|
274
230
|
* const ctx = new FormatContext();
|
|
275
231
|
* ctx.allocContext();
|
|
276
|
-
* // Context is now allocated
|
|
232
|
+
* // Context is now allocated
|
|
277
233
|
* ```
|
|
278
|
-
*
|
|
279
|
-
* @throws {Error} If allocation fails (ENOMEM)
|
|
280
234
|
*/
|
|
281
235
|
allocContext(): void;
|
|
282
236
|
/**
|
|
283
|
-
* Allocate an
|
|
237
|
+
* Allocate an output format context.
|
|
284
238
|
*
|
|
285
|
-
*
|
|
239
|
+
* Allocates and configures context for writing.
|
|
240
|
+
* Format is determined by parameters in priority order.
|
|
286
241
|
*
|
|
287
|
-
*
|
|
288
|
-
* @param formatName - Format name. May be null to auto-detect
|
|
289
|
-
* @param filename - Filename for output. Used to guess format if not specified
|
|
242
|
+
* Direct mapping to avformat_alloc_output_context2().
|
|
290
243
|
*
|
|
244
|
+
* @param oformat - Specific output format to use
|
|
245
|
+
* @param formatName - Format name (e.g., 'mp4', 'mkv')
|
|
246
|
+
* @param filename - Filename to guess format from extension
|
|
291
247
|
* @returns 0 on success, negative AVERROR on error:
|
|
292
|
-
* -
|
|
293
|
-
* -
|
|
294
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
248
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
249
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
295
250
|
*
|
|
296
251
|
* @example
|
|
297
252
|
* ```typescript
|
|
253
|
+
* import { FFmpegError } from 'node-av';
|
|
254
|
+
*
|
|
298
255
|
* const ctx = new FormatContext();
|
|
299
256
|
* const ret = ctx.allocOutputContext2(null, 'mp4', 'output.mp4');
|
|
300
|
-
*
|
|
301
|
-
* throw new FFmpegError(ret);
|
|
302
|
-
* }
|
|
257
|
+
* FFmpegError.throwIfError(ret, 'allocOutputContext2');
|
|
303
258
|
* ```
|
|
259
|
+
*
|
|
260
|
+
* @see {@link openOutput} To open output file
|
|
261
|
+
* @see {@link writeHeader} To write file header
|
|
304
262
|
*/
|
|
305
263
|
allocOutputContext2(oformat: OutputFormat | null, formatName: string | null, filename: string | null): number;
|
|
306
264
|
/**
|
|
307
|
-
* Free
|
|
265
|
+
* Free the format context.
|
|
308
266
|
*
|
|
309
|
-
*
|
|
267
|
+
* Releases all resources. The context becomes invalid.
|
|
268
|
+
*
|
|
269
|
+
* Direct mapping to avformat_free_context().
|
|
310
270
|
*
|
|
311
271
|
* @example
|
|
312
272
|
* ```typescript
|
|
313
273
|
* ctx.freeContext();
|
|
314
|
-
* //
|
|
274
|
+
* // Context is now invalid
|
|
315
275
|
* ```
|
|
276
|
+
*
|
|
277
|
+
* @see {@link Symbol.asyncDispose} For automatic cleanup
|
|
316
278
|
*/
|
|
317
279
|
freeContext(): void;
|
|
318
280
|
/**
|
|
319
|
-
* Close an
|
|
281
|
+
* Close an input format context.
|
|
282
|
+
*
|
|
283
|
+
* Closes input file and releases resources.
|
|
320
284
|
*
|
|
321
|
-
* Direct mapping to avformat_close_input()
|
|
285
|
+
* Direct mapping to avformat_close_input().
|
|
286
|
+
*
|
|
287
|
+
* @returns Promise that resolves when closed
|
|
322
288
|
*
|
|
323
289
|
* @example
|
|
324
290
|
* ```typescript
|
|
325
291
|
* await ctx.closeInput();
|
|
326
|
-
* // Input
|
|
292
|
+
* // Input closed and context freed
|
|
327
293
|
* ```
|
|
294
|
+
*
|
|
295
|
+
* @see {@link openInput} To open input
|
|
328
296
|
*/
|
|
329
297
|
closeInput(): Promise<void>;
|
|
330
298
|
/**
|
|
331
|
-
* Open
|
|
299
|
+
* Open output file for writing.
|
|
332
300
|
*
|
|
333
|
-
*
|
|
334
|
-
*
|
|
301
|
+
* Opens the output file specified in url.
|
|
302
|
+
* Must call allocOutputContext2 first.
|
|
335
303
|
*
|
|
336
|
-
* Direct mapping to
|
|
304
|
+
* Direct mapping to avio_open2().
|
|
337
305
|
*
|
|
338
|
-
* @returns
|
|
339
|
-
* -
|
|
340
|
-
* -
|
|
341
|
-
* -
|
|
342
|
-
* - AVERROR(EIO): I/O error
|
|
306
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
307
|
+
* - AVERROR_ENOENT: File not found
|
|
308
|
+
* - AVERROR_EACCES: Permission denied
|
|
309
|
+
* - AVERROR_EIO: I/O error
|
|
343
310
|
*
|
|
344
311
|
* @example
|
|
345
312
|
* ```typescript
|
|
346
|
-
* import {
|
|
313
|
+
* import { FFmpegError } from 'node-av';
|
|
347
314
|
*
|
|
348
|
-
* ctx.
|
|
349
|
-
* const ret = await ctx.openOutput(); // Opens the file for writing
|
|
315
|
+
* const ret = await ctx.openOutput();
|
|
350
316
|
* FFmpegError.throwIfError(ret, 'openOutput');
|
|
351
|
-
* await ctx.writeHeader(null);
|
|
352
317
|
* ```
|
|
318
|
+
*
|
|
319
|
+
* @see {@link allocOutputContext2} Must be called first
|
|
320
|
+
* @see {@link closeOutput} To close output
|
|
353
321
|
*/
|
|
354
322
|
openOutput(): Promise<number>;
|
|
355
323
|
/**
|
|
356
|
-
* Close
|
|
324
|
+
* Close output file.
|
|
325
|
+
*
|
|
326
|
+
* Closes the output file and releases I/O resources.
|
|
357
327
|
*
|
|
358
|
-
* Direct mapping to avio_closep()
|
|
328
|
+
* Direct mapping to avio_closep().
|
|
359
329
|
*
|
|
360
|
-
*
|
|
361
|
-
* The file is automatically closed by freeContext() as well.
|
|
330
|
+
* @returns Promise that resolves when closed
|
|
362
331
|
*
|
|
363
332
|
* @example
|
|
364
333
|
* ```typescript
|
|
365
|
-
* await ctx.writeTrailer();
|
|
366
334
|
* await ctx.closeOutput();
|
|
367
|
-
*
|
|
335
|
+
* // Output file closed
|
|
368
336
|
* ```
|
|
337
|
+
*
|
|
338
|
+
* @see {@link openOutput} To open output
|
|
369
339
|
*/
|
|
370
340
|
closeOutput(): Promise<void>;
|
|
371
341
|
/**
|
|
372
|
-
* Open
|
|
373
|
-
*
|
|
374
|
-
* Opens the specified URL, reads the format header, and initializes the stream information.
|
|
375
|
-
* Automatically detects the format if not specified.
|
|
342
|
+
* Open input file for reading.
|
|
376
343
|
*
|
|
377
|
-
*
|
|
344
|
+
* Opens and probes the input file, detecting format automatically
|
|
345
|
+
* unless specified.
|
|
378
346
|
*
|
|
379
|
-
*
|
|
380
|
-
* @param fmt - Input format. May be null to auto-detect
|
|
381
|
-
* @param options - Dictionary of options. May be null
|
|
347
|
+
* Direct mapping to avformat_open_input().
|
|
382
348
|
*
|
|
349
|
+
* @param url - URL or file path to open
|
|
350
|
+
* @param fmt - Force specific input format (null for auto-detect)
|
|
351
|
+
* @param options - Format-specific options
|
|
383
352
|
* @returns 0 on success, negative AVERROR on error:
|
|
384
|
-
* -
|
|
385
|
-
* -
|
|
386
|
-
* -
|
|
387
|
-
* - AVERROR(EINVAL): Invalid data found
|
|
388
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
389
|
-
* - <0: Other format-specific errors
|
|
353
|
+
* - AVERROR_ENOENT: File not found
|
|
354
|
+
* - AVERROR_INVALIDDATA: Invalid file format
|
|
355
|
+
* - AVERROR_EIO: I/O error
|
|
390
356
|
*
|
|
391
357
|
* @example
|
|
392
358
|
* ```typescript
|
|
393
|
-
* import {
|
|
359
|
+
* import { FFmpegError } from 'node-av';
|
|
394
360
|
*
|
|
395
|
-
* const ret = await ctx.openInput('
|
|
361
|
+
* const ret = await ctx.openInput('input.mp4');
|
|
396
362
|
* FFmpegError.throwIfError(ret, 'openInput');
|
|
397
|
-
* // Context is now open and header is read
|
|
398
363
|
* ```
|
|
364
|
+
*
|
|
365
|
+
* @see {@link findStreamInfo} To analyze streams after opening
|
|
366
|
+
* @see {@link closeInput} To close input
|
|
399
367
|
*/
|
|
400
368
|
openInput(url: string, fmt?: InputFormat | null, options?: Dictionary | null): Promise<number>;
|
|
401
369
|
/**
|
|
402
|
-
*
|
|
370
|
+
* Analyze streams to get stream info.
|
|
403
371
|
*
|
|
404
|
-
*
|
|
405
|
-
*
|
|
372
|
+
* Reads packet headers to fill in stream information.
|
|
373
|
+
* Should be called after openInput for accurate stream data.
|
|
406
374
|
*
|
|
407
|
-
* Direct mapping to avformat_find_stream_info()
|
|
408
|
-
*
|
|
409
|
-
* @param options - Dictionary of options per stream. May be null
|
|
375
|
+
* Direct mapping to avformat_find_stream_info().
|
|
410
376
|
*
|
|
377
|
+
* @param options - Per-stream options array
|
|
411
378
|
* @returns >=0 on success, negative AVERROR on error:
|
|
412
|
-
* -
|
|
413
|
-
* -
|
|
414
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
415
|
-
* - <0: Other errors
|
|
379
|
+
* - AVERROR_EOF: End of file reached
|
|
380
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
416
381
|
*
|
|
417
382
|
* @example
|
|
418
383
|
* ```typescript
|
|
419
|
-
* import {
|
|
384
|
+
* import { FFmpegError } from 'node-av';
|
|
420
385
|
*
|
|
421
|
-
* const ret = await ctx.findStreamInfo(
|
|
386
|
+
* const ret = await ctx.findStreamInfo();
|
|
422
387
|
* FFmpegError.throwIfError(ret, 'findStreamInfo');
|
|
423
388
|
* console.log(`Found ${ctx.nbStreams} streams`);
|
|
424
389
|
* ```
|
|
390
|
+
*
|
|
391
|
+
* @see {@link openInput} Must be called first
|
|
425
392
|
*/
|
|
426
393
|
findStreamInfo(options?: Dictionary[] | null): Promise<number>;
|
|
427
394
|
/**
|
|
428
|
-
* Read
|
|
395
|
+
* Read next packet from the input.
|
|
429
396
|
*
|
|
430
|
-
* Reads and returns the next packet
|
|
431
|
-
*
|
|
397
|
+
* Reads and returns the next packet in the stream.
|
|
398
|
+
* Packet must be unreferenced after use.
|
|
432
399
|
*
|
|
433
|
-
* Direct mapping to av_read_frame()
|
|
434
|
-
*
|
|
435
|
-
* @param pkt - Packet to fill with data
|
|
400
|
+
* Direct mapping to av_read_frame().
|
|
436
401
|
*
|
|
402
|
+
* @param pkt - Packet to read into
|
|
437
403
|
* @returns 0 on success, negative AVERROR on error:
|
|
438
|
-
* -
|
|
439
|
-
* -
|
|
440
|
-
* - AVERROR(EAGAIN): Temporarily unavailable
|
|
441
|
-
* - AVERROR(EIO): I/O error
|
|
442
|
-
* - <0: Other errors
|
|
404
|
+
* - AVERROR_EOF: End of file
|
|
405
|
+
* - AVERROR_EAGAIN: Temporarily unavailable
|
|
443
406
|
*
|
|
444
407
|
* @example
|
|
445
408
|
* ```typescript
|
|
446
|
-
* import {
|
|
409
|
+
* import { FFmpegError } from 'node-av';
|
|
410
|
+
* import { AVERROR_EOF } from 'node-av';
|
|
447
411
|
*
|
|
448
412
|
* const packet = new Packet();
|
|
449
413
|
* packet.alloc();
|
|
450
414
|
*
|
|
451
|
-
*
|
|
452
|
-
*
|
|
453
|
-
* if (ret === AVERROR_EOF) break;
|
|
454
|
-
* FFmpegError.throwIfError(ret, 'readFrame');
|
|
455
|
-
*
|
|
415
|
+
* let ret;
|
|
416
|
+
* while ((ret = await ctx.readFrame(packet)) >= 0) {
|
|
456
417
|
* // Process packet
|
|
457
418
|
* console.log(`Stream ${packet.streamIndex}, PTS: ${packet.pts}`);
|
|
458
419
|
* packet.unref();
|
|
459
420
|
* }
|
|
421
|
+
*
|
|
422
|
+
* if (ret !== AVERROR_EOF) {
|
|
423
|
+
* FFmpegError.throwIfError(ret, 'readFrame');
|
|
424
|
+
* }
|
|
460
425
|
* ```
|
|
426
|
+
*
|
|
427
|
+
* @see {@link seekFrame} To seek before reading
|
|
461
428
|
*/
|
|
462
429
|
readFrame(pkt: Packet): Promise<number>;
|
|
463
430
|
/**
|
|
464
|
-
* Seek to
|
|
465
|
-
*
|
|
466
|
-
* Seeks to the keyframe at or before the specified timestamp.
|
|
467
|
-
* The next packet read will be from the new position.
|
|
431
|
+
* Seek to timestamp in stream.
|
|
468
432
|
*
|
|
469
|
-
*
|
|
433
|
+
* Seeks to the keyframe at or before the given timestamp.
|
|
470
434
|
*
|
|
471
|
-
*
|
|
472
|
-
* @param timestamp - Timestamp in stream time_base units or AV_TIME_BASE if stream_index is -1
|
|
473
|
-
* @param flags - AVSEEK_FLAG_* flags
|
|
435
|
+
* Direct mapping to av_seek_frame().
|
|
474
436
|
*
|
|
437
|
+
* @param streamIndex - Stream to seek in (-1 for default)
|
|
438
|
+
* @param timestamp - Target timestamp in stream time base
|
|
439
|
+
* @param flags - Seek flags (AVSEEK_FLAG_*)
|
|
475
440
|
* @returns >=0 on success, negative AVERROR on error:
|
|
476
|
-
* -
|
|
477
|
-
* -
|
|
478
|
-
* - AVERROR(EIO): I/O error
|
|
479
|
-
* - <0: Other errors
|
|
441
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
442
|
+
* - AVERROR_EOF: Seek beyond file
|
|
480
443
|
*
|
|
481
444
|
* @example
|
|
482
445
|
* ```typescript
|
|
483
|
-
* import {
|
|
446
|
+
* import { FFmpegError } from 'node-av';
|
|
447
|
+
* import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
|
|
484
448
|
*
|
|
485
|
-
* // Seek to 10 seconds
|
|
486
|
-
* const
|
|
487
|
-
* const ret = await ctx.seekFrame(-1, timestamp, AVSEEK_FLAG_BACKWARD);
|
|
449
|
+
* // Seek to 10 seconds (assuming 1/1000 time base)
|
|
450
|
+
* const ret = await ctx.seekFrame(videoStreamIndex, 10000n, AVSEEK_FLAG_BACKWARD);
|
|
488
451
|
* FFmpegError.throwIfError(ret, 'seekFrame');
|
|
489
|
-
* // Next readFrame will return packet from new position
|
|
490
452
|
* ```
|
|
453
|
+
*
|
|
454
|
+
* @see {@link seekFile} For more precise seeking
|
|
491
455
|
*/
|
|
492
456
|
seekFrame(streamIndex: number, timestamp: bigint, flags?: AVSeekFlag): Promise<number>;
|
|
493
457
|
/**
|
|
494
|
-
* Seek to timestamp
|
|
458
|
+
* Seek to timestamp with bounds.
|
|
495
459
|
*
|
|
496
|
-
*
|
|
497
|
-
* More precise than seekFrame() with tolerance control.
|
|
460
|
+
* More precise seeking with min/max timestamp bounds.
|
|
498
461
|
*
|
|
499
|
-
* Direct mapping to avformat_seek_file()
|
|
462
|
+
* Direct mapping to avformat_seek_file().
|
|
500
463
|
*
|
|
501
|
-
* @param streamIndex - Stream
|
|
502
|
-
* @param minTs -
|
|
464
|
+
* @param streamIndex - Stream to seek in (-1 for default)
|
|
465
|
+
* @param minTs - Minimum acceptable timestamp
|
|
503
466
|
* @param ts - Target timestamp
|
|
504
|
-
* @param maxTs -
|
|
505
|
-
* @param flags -
|
|
506
|
-
*
|
|
507
|
-
* @returns >=0 on success, negative AVERROR on error:
|
|
508
|
-
* - >=0: Success
|
|
509
|
-
* - AVERROR(EINVAL): Invalid arguments
|
|
510
|
-
* - AVERROR(EIO): I/O error
|
|
511
|
-
* - <0: Other errors
|
|
467
|
+
* @param maxTs - Maximum acceptable timestamp
|
|
468
|
+
* @param flags - Seek flags
|
|
469
|
+
* @returns >=0 on success, negative AVERROR on error
|
|
512
470
|
*
|
|
513
471
|
* @example
|
|
514
472
|
* ```typescript
|
|
515
|
-
* import {
|
|
473
|
+
* import { FFmpegError } from 'node-av';
|
|
516
474
|
*
|
|
517
|
-
* // Seek to
|
|
518
|
-
* const target =
|
|
519
|
-
* const tolerance = BigInt(AV_TIME_BASE);
|
|
475
|
+
* // Seek to 10s with 0.5s tolerance
|
|
476
|
+
* const target = 10000n;
|
|
520
477
|
* const ret = await ctx.seekFile(
|
|
521
478
|
* -1,
|
|
522
|
-
* target -
|
|
523
|
-
* target,
|
|
524
|
-
* target +
|
|
525
|
-
* 0
|
|
479
|
+
* target - 500n,
|
|
480
|
+
* target,
|
|
481
|
+
* target + 500n
|
|
526
482
|
* );
|
|
527
483
|
* FFmpegError.throwIfError(ret, 'seekFile');
|
|
528
484
|
* ```
|
|
485
|
+
*
|
|
486
|
+
* @see {@link seekFrame} For simpler seeking
|
|
529
487
|
*/
|
|
530
488
|
seekFile(streamIndex: number, minTs: bigint, ts: bigint, maxTs: bigint, flags?: AVSeekFlag): Promise<number>;
|
|
531
489
|
/**
|
|
532
|
-
*
|
|
533
|
-
*
|
|
534
|
-
* Initializes the output file and writes the file header.
|
|
535
|
-
* Must be called before writing any packets.
|
|
490
|
+
* Write file header.
|
|
536
491
|
*
|
|
537
|
-
*
|
|
492
|
+
* Writes the file header and initializes output.
|
|
493
|
+
* Must be called before writing packets.
|
|
538
494
|
*
|
|
539
|
-
*
|
|
495
|
+
* Direct mapping to avformat_write_header().
|
|
540
496
|
*
|
|
497
|
+
* @param options - Muxer-specific options
|
|
541
498
|
* @returns 0 on success, negative AVERROR on error:
|
|
542
|
-
* -
|
|
543
|
-
* -
|
|
544
|
-
* - AVERROR(EIO): I/O error
|
|
545
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
546
|
-
* - <0: Other muxer-specific errors
|
|
499
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
500
|
+
* - AVERROR_EIO: I/O error
|
|
547
501
|
*
|
|
548
502
|
* @example
|
|
549
503
|
* ```typescript
|
|
550
|
-
* import {
|
|
551
|
-
*
|
|
552
|
-
* const options = new Dictionary();
|
|
553
|
-
* options.set('movflags', 'faststart', 0);
|
|
504
|
+
* import { FFmpegError } from 'node-av';
|
|
554
505
|
*
|
|
555
|
-
* const ret = await ctx.writeHeader(
|
|
506
|
+
* const ret = await ctx.writeHeader();
|
|
556
507
|
* FFmpegError.throwIfError(ret, 'writeHeader');
|
|
557
|
-
*
|
|
558
|
-
* // Header written, ready to write packets
|
|
508
|
+
* // Now ready to write packets
|
|
559
509
|
* ```
|
|
510
|
+
*
|
|
511
|
+
* @see {@link writeTrailer} To finalize file
|
|
512
|
+
* @see {@link writeFrame} To write packets
|
|
560
513
|
*/
|
|
561
514
|
writeHeader(options?: Dictionary | null): Promise<number>;
|
|
562
515
|
/**
|
|
563
|
-
* Write
|
|
564
|
-
*
|
|
565
|
-
* Writes a packet directly without reordering.
|
|
566
|
-
* Use interleavedWriteFrame() for automatic interleaving.
|
|
516
|
+
* Write packet to output.
|
|
567
517
|
*
|
|
568
|
-
*
|
|
518
|
+
* Writes a packet directly without interleaving.
|
|
519
|
+
* Caller must handle correct interleaving.
|
|
569
520
|
*
|
|
570
|
-
*
|
|
521
|
+
* Direct mapping to av_write_frame().
|
|
571
522
|
*
|
|
523
|
+
* @param pkt - Packet to write (null to flush)
|
|
572
524
|
* @returns 0 on success, negative AVERROR on error:
|
|
573
|
-
* -
|
|
574
|
-
* -
|
|
575
|
-
* - AVERROR(EIO): I/O error
|
|
576
|
-
* - <0: Other muxer-specific errors
|
|
525
|
+
* - AVERROR_EINVAL: Invalid packet
|
|
526
|
+
* - AVERROR_EIO: I/O error
|
|
577
527
|
*
|
|
578
528
|
* @example
|
|
579
529
|
* ```typescript
|
|
580
|
-
* import {
|
|
530
|
+
* import { FFmpegError } from 'node-av';
|
|
581
531
|
*
|
|
582
532
|
* const ret = await ctx.writeFrame(packet);
|
|
583
533
|
* FFmpegError.throwIfError(ret, 'writeFrame');
|
|
584
|
-
*
|
|
585
|
-
* // Flush at the end
|
|
586
|
-
* const flushRet = await ctx.writeFrame(null);
|
|
587
|
-
* FFmpegError.throwIfError(flushRet, 'writeFrame flush');
|
|
588
534
|
* ```
|
|
589
535
|
*
|
|
590
|
-
* @note This function does NOT take ownership of the packet.
|
|
591
|
-
*
|
|
592
536
|
* @see {@link interleavedWriteFrame} For automatic interleaving
|
|
593
537
|
*/
|
|
594
538
|
writeFrame(pkt: Packet | null): Promise<number>;
|
|
595
539
|
/**
|
|
596
|
-
* Write
|
|
597
|
-
*
|
|
598
|
-
* Automatically interleaves packets from different streams based on DTS.
|
|
599
|
-
* Preferred method for writing packets in most cases.
|
|
540
|
+
* Write packet with automatic interleaving.
|
|
600
541
|
*
|
|
601
|
-
*
|
|
542
|
+
* Writes packet with proper interleaving for muxing.
|
|
543
|
+
* Preferred method for writing packets.
|
|
602
544
|
*
|
|
603
|
-
*
|
|
545
|
+
* Direct mapping to av_interleaved_write_frame().
|
|
604
546
|
*
|
|
547
|
+
* @param pkt - Packet to write (null to flush)
|
|
605
548
|
* @returns 0 on success, negative AVERROR on error:
|
|
606
|
-
* -
|
|
607
|
-
* -
|
|
608
|
-
* - AVERROR(EIO): I/O error
|
|
609
|
-
* - <0: Other muxer-specific errors
|
|
549
|
+
* - AVERROR_EINVAL: Invalid packet
|
|
550
|
+
* - AVERROR_EIO: I/O error
|
|
610
551
|
*
|
|
611
552
|
* @example
|
|
612
553
|
* ```typescript
|
|
613
|
-
* import {
|
|
554
|
+
* import { FFmpegError } from 'node-av';
|
|
614
555
|
*
|
|
615
|
-
* // Write
|
|
556
|
+
* // Write with proper interleaving
|
|
616
557
|
* const ret = await ctx.interleavedWriteFrame(packet);
|
|
617
558
|
* FFmpegError.throwIfError(ret, 'interleavedWriteFrame');
|
|
618
|
-
* // Packet is automatically freed after writing
|
|
619
|
-
* ```
|
|
620
559
|
*
|
|
621
|
-
*
|
|
560
|
+
* // Flush buffered packets
|
|
561
|
+
* await ctx.interleavedWriteFrame(null);
|
|
562
|
+
* ```
|
|
622
563
|
*
|
|
623
|
-
* @see {@link writeFrame} For
|
|
564
|
+
* @see {@link writeFrame} For direct writing
|
|
624
565
|
*/
|
|
625
566
|
interleavedWriteFrame(pkt: Packet | null): Promise<number>;
|
|
626
567
|
/**
|
|
627
|
-
* Write
|
|
568
|
+
* Write file trailer.
|
|
628
569
|
*
|
|
629
|
-
* Finalizes the output file
|
|
630
|
-
* Must be called
|
|
570
|
+
* Finalizes the output file, writing index and metadata.
|
|
571
|
+
* Must be called to properly close output files.
|
|
631
572
|
*
|
|
632
|
-
* Direct mapping to av_write_trailer()
|
|
573
|
+
* Direct mapping to av_write_trailer().
|
|
633
574
|
*
|
|
634
575
|
* @returns 0 on success, negative AVERROR on error:
|
|
635
|
-
* -
|
|
636
|
-
* - AVERROR(EIO): I/O error
|
|
637
|
-
* - <0: Other muxer-specific errors
|
|
576
|
+
* - AVERROR_EIO: I/O error
|
|
638
577
|
*
|
|
639
578
|
* @example
|
|
640
579
|
* ```typescript
|
|
641
|
-
* import {
|
|
580
|
+
* import { FFmpegError } from 'node-av';
|
|
642
581
|
*
|
|
643
|
-
* // Finalize the output file
|
|
644
582
|
* const ret = await ctx.writeTrailer();
|
|
645
583
|
* FFmpegError.throwIfError(ret, 'writeTrailer');
|
|
646
|
-
* // File is now
|
|
584
|
+
* // File is now finalized
|
|
647
585
|
* ```
|
|
648
586
|
*
|
|
649
|
-
* @
|
|
587
|
+
* @see {@link writeHeader} Must be called first
|
|
650
588
|
*/
|
|
651
589
|
writeTrailer(): Promise<number>;
|
|
652
590
|
/**
|
|
653
|
-
* Flush
|
|
591
|
+
* Flush buffered data.
|
|
592
|
+
*
|
|
593
|
+
* Flushes any buffered packets in muxers.
|
|
654
594
|
*
|
|
655
|
-
* Direct mapping to avio_flush()
|
|
595
|
+
* Direct mapping to avio_flush().
|
|
656
596
|
*
|
|
657
597
|
* @example
|
|
658
598
|
* ```typescript
|
|
659
|
-
* import { FormatContext } from 'node-av';
|
|
660
|
-
*
|
|
661
|
-
* // Flush buffered data
|
|
662
599
|
* ctx.flush();
|
|
663
|
-
* //
|
|
600
|
+
* // Buffered data written to output
|
|
664
601
|
* ```
|
|
665
602
|
*/
|
|
666
603
|
flush(): void;
|
|
667
604
|
/**
|
|
668
|
-
*
|
|
605
|
+
* Print format information.
|
|
669
606
|
*
|
|
670
|
-
*
|
|
671
|
-
* Useful for debugging
|
|
607
|
+
* Dumps human-readable format info to stderr.
|
|
608
|
+
* Useful for debugging.
|
|
672
609
|
*
|
|
673
|
-
* Direct mapping to av_dump_format()
|
|
610
|
+
* Direct mapping to av_dump_format().
|
|
674
611
|
*
|
|
675
|
-
* @param index - Stream index
|
|
676
|
-
* @param url - URL
|
|
677
|
-
* @param isOutput -
|
|
612
|
+
* @param index - Stream index to highlight (-1 for none)
|
|
613
|
+
* @param url - URL to display
|
|
614
|
+
* @param isOutput - True for output format, false for input
|
|
678
615
|
*
|
|
679
616
|
* @example
|
|
680
617
|
* ```typescript
|
|
681
|
-
* import { FormatContext } from 'node-av';
|
|
682
|
-
*
|
|
683
618
|
* // Dump input format info
|
|
684
|
-
*
|
|
619
|
+
* ctx.dumpFormat(0, 'input.mp4', false);
|
|
685
620
|
*
|
|
686
621
|
* // Dump output format info
|
|
687
|
-
*
|
|
622
|
+
* ctx.dumpFormat(0, 'output.mp4', true);
|
|
688
623
|
* ```
|
|
689
624
|
*/
|
|
690
625
|
dumpFormat(index: number, url: string, isOutput: boolean): void;
|
|
691
626
|
/**
|
|
692
|
-
* Find the
|
|
693
|
-
*
|
|
694
|
-
* The best stream is determined according to various heuristics as the most
|
|
695
|
-
* likely to be what the user expects.
|
|
627
|
+
* Find the best stream of a given type.
|
|
696
628
|
*
|
|
697
|
-
*
|
|
629
|
+
* Selects the most suitable stream (e.g., default audio/video).
|
|
698
630
|
*
|
|
699
|
-
*
|
|
700
|
-
* @param wantedStreamNb - User-requested stream number, or -1 for automatic selection
|
|
701
|
-
* @param relatedStream - Try to find a stream related to this one, or -1 if none
|
|
631
|
+
* Direct mapping to av_find_best_stream().
|
|
702
632
|
*
|
|
703
|
-
* @
|
|
704
|
-
*
|
|
705
|
-
*
|
|
706
|
-
*
|
|
707
|
-
* - <0: Other errors
|
|
633
|
+
* @param type - Media type to find (AVMEDIA_TYPE_*)
|
|
634
|
+
* @param wantedStreamNb - Preferred stream index (-1 for auto)
|
|
635
|
+
* @param relatedStream - Related stream for audio/video sync (-1 for none)
|
|
636
|
+
* @returns Stream index, or negative AVERROR if not found
|
|
708
637
|
*
|
|
709
638
|
* @example
|
|
710
639
|
* ```typescript
|
|
711
|
-
* import {
|
|
640
|
+
* import { AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO } from 'node-av/constants';
|
|
712
641
|
*
|
|
713
|
-
*
|
|
714
|
-
*
|
|
715
|
-
*
|
|
716
|
-
*
|
|
717
|
-
* -1 // no related stream
|
|
718
|
-
* );
|
|
642
|
+
* const videoIndex = ctx.findBestStream(AVMEDIA_TYPE_VIDEO);
|
|
643
|
+
* if (videoIndex >= 0) {
|
|
644
|
+
* console.log(`Best video stream: ${videoIndex}`);
|
|
645
|
+
* }
|
|
719
646
|
*
|
|
720
|
-
*
|
|
721
|
-
*
|
|
647
|
+
* const audioIndex = ctx.findBestStream(AVMEDIA_TYPE_AUDIO);
|
|
648
|
+
* if (audioIndex >= 0) {
|
|
649
|
+
* console.log(`Best audio stream: ${audioIndex}`);
|
|
722
650
|
* }
|
|
723
|
-
* const videoStream = ctx.streams[videoStreamIndex];
|
|
724
|
-
* // Process video stream
|
|
725
651
|
* ```
|
|
726
652
|
*/
|
|
727
653
|
findBestStream(type: AVMediaType, wantedStreamNb?: number, relatedStream?: number): number;
|
|
728
654
|
/**
|
|
729
|
-
* Find the
|
|
730
|
-
*
|
|
731
|
-
* The best stream is determined according to various heuristics as the most
|
|
732
|
-
* likely to be what the user expects.
|
|
733
|
-
*
|
|
734
|
-
* Direct mapping to av_find_best_stream()
|
|
735
|
-
*
|
|
736
|
-
* @param type - Media type (AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, etc.)
|
|
737
|
-
* @param wantedStreamNb - User-requested stream number, or -1 for automatic selection
|
|
738
|
-
* @param relatedStream - Try to find a stream related to this one, or -1 if none
|
|
739
|
-
* @param wantDecoder - Whether to return the decoder for the stream
|
|
740
|
-
* @param flags - Currently unused, pass 0
|
|
741
|
-
*
|
|
742
|
-
* @returns Object with stream index and decoder if found
|
|
743
|
-
*
|
|
744
|
-
* @example
|
|
745
|
-
* ```typescript
|
|
746
|
-
* import { FormatContext, FFmpegError, AVMEDIA_TYPE_VIDEO } from 'node-av';
|
|
747
|
-
*
|
|
748
|
-
* // Find best video stream with decoder
|
|
749
|
-
* const result = ctx.findBestStream(
|
|
750
|
-
* AVMEDIA_TYPE_VIDEO,
|
|
751
|
-
* -1, // automatic selection
|
|
752
|
-
* -1, // no related stream
|
|
753
|
-
* true, // want decoder
|
|
754
|
-
* 0
|
|
755
|
-
* );
|
|
655
|
+
* Find the best stream and its decoder.
|
|
756
656
|
*
|
|
757
|
-
*
|
|
758
|
-
*
|
|
759
|
-
*
|
|
760
|
-
*
|
|
761
|
-
*
|
|
762
|
-
*
|
|
763
|
-
* ```
|
|
657
|
+
* @param type - Media type to find
|
|
658
|
+
* @param wantedStreamNb - Preferred stream index
|
|
659
|
+
* @param relatedStream - Related stream index
|
|
660
|
+
* @param wantDecoder - True to also find decoder
|
|
661
|
+
* @param flags - Reserved flags
|
|
662
|
+
* @returns Object with stream index and decoder
|
|
764
663
|
*/
|
|
765
664
|
findBestStream(type: AVMediaType, wantedStreamNb: number, relatedStream: number, wantDecoder: true, flags?: number): {
|
|
766
665
|
streamIndex: number;
|
|
767
666
|
decoder: Codec | null;
|
|
768
667
|
};
|
|
769
668
|
/**
|
|
770
|
-
* Add a new stream to
|
|
771
|
-
*
|
|
772
|
-
* Creates a new stream in the output format context.
|
|
773
|
-
* The stream must be configured before calling writeHeader().
|
|
669
|
+
* Add a new stream to output context.
|
|
774
670
|
*
|
|
775
|
-
*
|
|
671
|
+
* Creates a new stream for writing.
|
|
776
672
|
*
|
|
777
|
-
*
|
|
673
|
+
* Direct mapping to avformat_new_stream().
|
|
778
674
|
*
|
|
779
|
-
* @
|
|
780
|
-
*
|
|
781
|
-
* @throws {Error} If stream creation fails (ENOMEM)
|
|
675
|
+
* @param c - Codec for the stream (optional)
|
|
676
|
+
* @returns New stream instance
|
|
782
677
|
*
|
|
783
678
|
* @example
|
|
784
679
|
* ```typescript
|
|
785
|
-
* import {
|
|
786
|
-
* import { AV_CODEC_ID_H264
|
|
787
|
-
*
|
|
788
|
-
*
|
|
789
|
-
* const
|
|
790
|
-
*
|
|
791
|
-
*
|
|
792
|
-
* // Configure stream parameters
|
|
793
|
-
* videoStream.codecpar.codecType = AVMEDIA_TYPE_VIDEO;
|
|
794
|
-
* videoStream.codecpar.codecId = AV_CODEC_ID_H264;
|
|
795
|
-
* videoStream.codecpar.width = 1920;
|
|
796
|
-
* videoStream.codecpar.height = 1080;
|
|
680
|
+
* import { Codec } from 'node-av';
|
|
681
|
+
* import { AV_CODEC_ID_H264 } from 'node-av/constants';
|
|
682
|
+
*
|
|
683
|
+
* const codec = Codec.findEncoder(AV_CODEC_ID_H264);
|
|
684
|
+
* const stream = ctx.newStream(codec);
|
|
685
|
+
* stream.id = ctx.nbStreams - 1;
|
|
797
686
|
* ```
|
|
687
|
+
*
|
|
688
|
+
* @see {@link Stream} For stream configuration
|
|
798
689
|
*/
|
|
799
690
|
newStream(c?: Codec | null): Stream;
|
|
800
691
|
/**
|
|
801
|
-
* Get the native
|
|
692
|
+
* Get the underlying native FormatContext object.
|
|
802
693
|
*
|
|
803
|
-
* @
|
|
804
|
-
*
|
|
694
|
+
* @returns The native FormatContext binding object
|
|
695
|
+
*
|
|
696
|
+
* @internal
|
|
805
697
|
*/
|
|
806
698
|
getNative(): NativeFormatContext;
|
|
807
699
|
/**
|
|
808
|
-
* Dispose of the format context
|
|
700
|
+
* Dispose of the format context.
|
|
809
701
|
*
|
|
810
702
|
* Implements the AsyncDisposable interface for automatic cleanup.
|
|
811
|
-
*
|
|
703
|
+
* Closes input/output and frees resources.
|
|
704
|
+
*
|
|
705
|
+
* @returns Promise that resolves when disposed
|
|
812
706
|
*
|
|
813
707
|
* @example
|
|
814
708
|
* ```typescript
|
|
815
|
-
* import { FormatContext } from 'node-av';
|
|
816
|
-
*
|
|
817
709
|
* {
|
|
818
710
|
* await using ctx = new FormatContext();
|
|
819
|
-
* await ctx.openInput('
|
|
820
|
-
* //
|
|
821
|
-
* } // Automatically closed
|
|
711
|
+
* await ctx.openInput('input.mp4');
|
|
712
|
+
* // Use context...
|
|
713
|
+
* } // Automatically closed and freed
|
|
822
714
|
* ```
|
|
823
715
|
*/
|
|
824
716
|
[Symbol.asyncDispose](): Promise<void>;
|