node-av 0.0.1
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/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,798 @@
|
|
|
1
|
+
import { Codec } from './codec.js';
|
|
2
|
+
import { Dictionary } from './dictionary.js';
|
|
3
|
+
import { InputFormat } from './input-format.js';
|
|
4
|
+
import { OptionMember } from './option.js';
|
|
5
|
+
import { OutputFormat } from './output-format.js';
|
|
6
|
+
import { Stream } from './stream.js';
|
|
7
|
+
import type { AVFormatFlag, AVMediaType, AVSeekFlag } from './constants.js';
|
|
8
|
+
import type { IOContext } from './io-context.js';
|
|
9
|
+
import type { NativeFormatContext, NativeWrapper } from './native-types.js';
|
|
10
|
+
import type { Packet } from './packet.js';
|
|
11
|
+
/**
|
|
12
|
+
* FFmpeg format context for demuxing and muxing.
|
|
13
|
+
*
|
|
14
|
+
* Central structure for media file handling, managing both input (demuxing) and output (muxing).
|
|
15
|
+
* Provides full control over allocation, configuration and lifecycle with no hidden operations.
|
|
16
|
+
* Handles container formats, streams, metadata, and packet I/O operations.
|
|
17
|
+
*
|
|
18
|
+
* Direct mapping to FFmpeg's AVFormatContext.
|
|
19
|
+
*
|
|
20
|
+
* @example
|
|
21
|
+
* ```typescript
|
|
22
|
+
* import { FormatContext, Packet, FFmpegError } from 'node-av';
|
|
23
|
+
*
|
|
24
|
+
* // Demuxing - full control over every step
|
|
25
|
+
* const ctx = new FormatContext();
|
|
26
|
+
* ctx.allocContext();
|
|
27
|
+
*
|
|
28
|
+
* const ret = await ctx.openInput('video.mp4', null, null);
|
|
29
|
+
* FFmpegError.throwIfError(ret, 'openInput');
|
|
30
|
+
*
|
|
31
|
+
* const infoRet = await ctx.findStreamInfo(null);
|
|
32
|
+
* FFmpegError.throwIfError(infoRet, 'findStreamInfo');
|
|
33
|
+
*
|
|
34
|
+
* const packet = new Packet();
|
|
35
|
+
* packet.alloc();
|
|
36
|
+
*
|
|
37
|
+
* while (true) {
|
|
38
|
+
* const readRet = await ctx.readFrame(packet);
|
|
39
|
+
* if (readRet < 0) break; // EOF or error
|
|
40
|
+
* // Process packet
|
|
41
|
+
* packet.unref();
|
|
42
|
+
* }
|
|
43
|
+
*
|
|
44
|
+
* 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
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @see {@link InputFormat} For input format handling
|
|
75
|
+
* @see {@link OutputFormat} For output format handling
|
|
76
|
+
* @see {@link Stream} For stream management
|
|
77
|
+
* @see {@link Packet} For packet handling
|
|
78
|
+
*/
|
|
79
|
+
export declare class FormatContext extends OptionMember<NativeFormatContext> implements AsyncDisposable, NativeWrapper<NativeFormatContext> {
|
|
80
|
+
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
|
+
constructor();
|
|
101
|
+
/**
|
|
102
|
+
* Input or output URL/filename.
|
|
103
|
+
*
|
|
104
|
+
* Direct mapping to AVFormatContext->url
|
|
105
|
+
*
|
|
106
|
+
* - muxing: Set by user
|
|
107
|
+
* - demuxing: Set by avformat_open_input
|
|
108
|
+
*/
|
|
109
|
+
get url(): string | null;
|
|
110
|
+
set url(value: string | null);
|
|
111
|
+
/**
|
|
112
|
+
* Position of the first frame of the component, in AV_TIME_BASE units.
|
|
113
|
+
*
|
|
114
|
+
* Direct mapping to AVFormatContext->start_time
|
|
115
|
+
*
|
|
116
|
+
* NEVER set this value directly: it is deduced from the AVStream values.
|
|
117
|
+
* - demuxing: Set by libavformat
|
|
118
|
+
*/
|
|
119
|
+
get startTime(): bigint;
|
|
120
|
+
/**
|
|
121
|
+
* Duration of the stream, in AV_TIME_BASE units.
|
|
122
|
+
*
|
|
123
|
+
* Direct mapping to AVFormatContext->duration
|
|
124
|
+
*
|
|
125
|
+
* Only set this value if you know none of the individual stream durations.
|
|
126
|
+
* - demuxing: Set by libavformat
|
|
127
|
+
* - muxing: May be set by user
|
|
128
|
+
*/
|
|
129
|
+
get duration(): bigint;
|
|
130
|
+
/**
|
|
131
|
+
* Total stream bitrate in bit/s, 0 if not available.
|
|
132
|
+
*
|
|
133
|
+
* Direct mapping to AVFormatContext->bit_rate
|
|
134
|
+
*
|
|
135
|
+
* Never set directly if the file_size and duration are known.
|
|
136
|
+
*/
|
|
137
|
+
get bitRate(): bigint;
|
|
138
|
+
/**
|
|
139
|
+
* Flags modifying demuxer/muxer behavior.
|
|
140
|
+
*
|
|
141
|
+
* Direct mapping to AVFormatContext->flags
|
|
142
|
+
*
|
|
143
|
+
* AVFMT_FLAG_GENPTS, AVFMT_FLAG_IGNIDX, etc.
|
|
144
|
+
* - encoding: Set by user
|
|
145
|
+
* - decoding: Set by user
|
|
146
|
+
*/
|
|
147
|
+
get flags(): AVFormatFlag;
|
|
148
|
+
set flags(value: AVFormatFlag);
|
|
149
|
+
/**
|
|
150
|
+
* Maximum size of the data read from input for determining format.
|
|
151
|
+
*
|
|
152
|
+
* Direct mapping to AVFormatContext->probesize
|
|
153
|
+
*
|
|
154
|
+
* - encoding: unused
|
|
155
|
+
* - decoding: Set by user
|
|
156
|
+
*/
|
|
157
|
+
get probesize(): bigint;
|
|
158
|
+
set probesize(value: bigint);
|
|
159
|
+
/**
|
|
160
|
+
* Maximum duration (in AV_TIME_BASE units) of the data read from input.
|
|
161
|
+
*
|
|
162
|
+
* Direct mapping to AVFormatContext->max_analyze_duration
|
|
163
|
+
*
|
|
164
|
+
* - encoding: unused
|
|
165
|
+
* - decoding: Set by user
|
|
166
|
+
*/
|
|
167
|
+
get maxAnalyzeDuration(): bigint;
|
|
168
|
+
set maxAnalyzeDuration(value: bigint);
|
|
169
|
+
/**
|
|
170
|
+
* Metadata that applies to the whole file.
|
|
171
|
+
*
|
|
172
|
+
* Direct mapping to AVFormatContext->metadata
|
|
173
|
+
*
|
|
174
|
+
* - demuxing: Set by libavformat
|
|
175
|
+
* - muxing: May be set by user
|
|
176
|
+
*/
|
|
177
|
+
get metadata(): Dictionary | null;
|
|
178
|
+
set metadata(value: Dictionary | null);
|
|
179
|
+
/**
|
|
180
|
+
* Input format (demuxing only).
|
|
181
|
+
*
|
|
182
|
+
* Direct mapping to AVFormatContext->iformat
|
|
183
|
+
*
|
|
184
|
+
* The detected or specified input format.
|
|
185
|
+
*/
|
|
186
|
+
get iformat(): InputFormat | null;
|
|
187
|
+
/**
|
|
188
|
+
* Output format (muxing only).
|
|
189
|
+
*
|
|
190
|
+
* Direct mapping to AVFormatContext->oformat
|
|
191
|
+
*
|
|
192
|
+
* The specified output format.
|
|
193
|
+
*/
|
|
194
|
+
get oformat(): OutputFormat | null;
|
|
195
|
+
set oformat(value: OutputFormat | null);
|
|
196
|
+
/**
|
|
197
|
+
* I/O context.
|
|
198
|
+
*
|
|
199
|
+
* Direct mapping to AVFormatContext->pb
|
|
200
|
+
*
|
|
201
|
+
* - demuxing: Either set by user or internal (for protocols like file:)
|
|
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.
|
|
206
|
+
*/
|
|
207
|
+
get pb(): IOContext | null;
|
|
208
|
+
set pb(value: IOContext | null);
|
|
209
|
+
/**
|
|
210
|
+
* Number of streams in the file.
|
|
211
|
+
*
|
|
212
|
+
* Direct mapping to AVFormatContext->nb_streams
|
|
213
|
+
*/
|
|
214
|
+
get nbStreams(): number;
|
|
215
|
+
/**
|
|
216
|
+
* Array of streams in the file.
|
|
217
|
+
*
|
|
218
|
+
* Direct mapping to AVFormatContext->streams
|
|
219
|
+
*/
|
|
220
|
+
get streams(): Stream[] | null;
|
|
221
|
+
/**
|
|
222
|
+
* Allow non-standard and experimental extension.
|
|
223
|
+
*
|
|
224
|
+
* Direct mapping to AVFormatContext->strict_std_compliance
|
|
225
|
+
*
|
|
226
|
+
* @see AVCodecContext.strict_std_compliance
|
|
227
|
+
*/
|
|
228
|
+
get strictStdCompliance(): number;
|
|
229
|
+
set strictStdCompliance(value: number);
|
|
230
|
+
/**
|
|
231
|
+
* Maximum number of streams.
|
|
232
|
+
*
|
|
233
|
+
* Direct mapping to AVFormatContext->max_streams
|
|
234
|
+
*
|
|
235
|
+
* - encoding: unused
|
|
236
|
+
* - decoding: Set by user
|
|
237
|
+
*/
|
|
238
|
+
get maxStreams(): number;
|
|
239
|
+
set maxStreams(value: number);
|
|
240
|
+
/**
|
|
241
|
+
* Allocate an AVFormatContext for input.
|
|
242
|
+
*
|
|
243
|
+
* Direct mapping to avformat_alloc_context()
|
|
244
|
+
*
|
|
245
|
+
* @example
|
|
246
|
+
* ```typescript
|
|
247
|
+
* const ctx = new FormatContext();
|
|
248
|
+
* ctx.allocContext();
|
|
249
|
+
* // Context is now allocated for demuxing
|
|
250
|
+
* ```
|
|
251
|
+
*
|
|
252
|
+
* @throws {Error} If allocation fails (ENOMEM)
|
|
253
|
+
*/
|
|
254
|
+
allocContext(): void;
|
|
255
|
+
/**
|
|
256
|
+
* Allocate an AVFormatContext for output.
|
|
257
|
+
*
|
|
258
|
+
* Direct mapping to avformat_alloc_output_context2()
|
|
259
|
+
*
|
|
260
|
+
* @param oformat - Output format. May be null to auto-detect from filename
|
|
261
|
+
* @param formatName - Format name. May be null to auto-detect
|
|
262
|
+
* @param filename - Filename for output. Used to guess format if not specified
|
|
263
|
+
*
|
|
264
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
265
|
+
* - 0: Success
|
|
266
|
+
* - AVERROR(EINVAL): Invalid arguments
|
|
267
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
268
|
+
*
|
|
269
|
+
* @example
|
|
270
|
+
* ```typescript
|
|
271
|
+
* const ctx = new FormatContext();
|
|
272
|
+
* const ret = ctx.allocOutputContext2(null, 'mp4', 'output.mp4');
|
|
273
|
+
* if (ret < 0) {
|
|
274
|
+
* throw new FFmpegError(ret);
|
|
275
|
+
* }
|
|
276
|
+
* ```
|
|
277
|
+
*/
|
|
278
|
+
allocOutputContext2(oformat: OutputFormat | null, formatName: string | null, filename: string | null): number;
|
|
279
|
+
/**
|
|
280
|
+
* Free an AVFormatContext and all its streams.
|
|
281
|
+
*
|
|
282
|
+
* Direct mapping to avformat_free_context()
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* ctx.freeContext();
|
|
287
|
+
* // ctx is now invalid and should not be used
|
|
288
|
+
* ```
|
|
289
|
+
*/
|
|
290
|
+
freeContext(): void;
|
|
291
|
+
/**
|
|
292
|
+
* Close an opened input AVFormatContext.
|
|
293
|
+
*
|
|
294
|
+
* Direct mapping to avformat_close_input()
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* await ctx.closeInput();
|
|
299
|
+
* // Input is closed and context is freed
|
|
300
|
+
* ```
|
|
301
|
+
*/
|
|
302
|
+
closeInput(): Promise<void>;
|
|
303
|
+
/**
|
|
304
|
+
* Open the output file for writing.
|
|
305
|
+
*
|
|
306
|
+
* Must be called after allocOutputContext2() and before writeHeader()
|
|
307
|
+
* for file-based formats (not NOFILE formats).
|
|
308
|
+
*
|
|
309
|
+
* Direct mapping to avio_open()
|
|
310
|
+
*
|
|
311
|
+
* @returns Promise resolving to 0 on success, negative AVERROR on failure:
|
|
312
|
+
* - 0: Success
|
|
313
|
+
* - AVERROR(ENOENT): File cannot be created
|
|
314
|
+
* - AVERROR(EACCES): Permission denied
|
|
315
|
+
* - AVERROR(EIO): I/O error
|
|
316
|
+
*
|
|
317
|
+
* @example
|
|
318
|
+
* ```typescript
|
|
319
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
320
|
+
*
|
|
321
|
+
* ctx.allocOutputContext2(null, null, 'output.mp4');
|
|
322
|
+
* const ret = await ctx.openOutput(); // Opens the file for writing
|
|
323
|
+
* FFmpegError.throwIfError(ret, 'openOutput');
|
|
324
|
+
* await ctx.writeHeader(null);
|
|
325
|
+
* ```
|
|
326
|
+
*/
|
|
327
|
+
openOutput(): Promise<number>;
|
|
328
|
+
/**
|
|
329
|
+
* Close the output file.
|
|
330
|
+
*
|
|
331
|
+
* Direct mapping to avio_closep()
|
|
332
|
+
*
|
|
333
|
+
* Should be called after writeTrailer() for file-based formats.
|
|
334
|
+
* The file is automatically closed by freeContext() as well.
|
|
335
|
+
*
|
|
336
|
+
* @example
|
|
337
|
+
* ```typescript
|
|
338
|
+
* await ctx.writeTrailer();
|
|
339
|
+
* await ctx.closeOutput();
|
|
340
|
+
* ctx.freeContext();
|
|
341
|
+
* ```
|
|
342
|
+
*/
|
|
343
|
+
closeOutput(): Promise<void>;
|
|
344
|
+
/**
|
|
345
|
+
* Open an input stream and read the header.
|
|
346
|
+
*
|
|
347
|
+
* Opens the specified URL, reads the format header, and initializes the stream information.
|
|
348
|
+
* Automatically detects the format if not specified.
|
|
349
|
+
*
|
|
350
|
+
* Direct mapping to avformat_open_input()
|
|
351
|
+
*
|
|
352
|
+
* @param url - URL of the stream to open
|
|
353
|
+
* @param fmt - Input format. May be null to auto-detect
|
|
354
|
+
* @param options - Dictionary of options. May be null
|
|
355
|
+
*
|
|
356
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
357
|
+
* - 0: Success
|
|
358
|
+
* - AVERROR(ENOENT): File not found
|
|
359
|
+
* - AVERROR(EIO): I/O error
|
|
360
|
+
* - AVERROR(EINVAL): Invalid data found
|
|
361
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
362
|
+
* - <0: Other format-specific errors
|
|
363
|
+
*
|
|
364
|
+
* @example
|
|
365
|
+
* ```typescript
|
|
366
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
367
|
+
*
|
|
368
|
+
* const ret = await ctx.openInput('video.mp4', null, null);
|
|
369
|
+
* FFmpegError.throwIfError(ret, 'openInput');
|
|
370
|
+
* // Context is now open and header is read
|
|
371
|
+
* ```
|
|
372
|
+
*/
|
|
373
|
+
openInput(url: string, fmt?: InputFormat | null, options?: Dictionary | null): Promise<number>;
|
|
374
|
+
/**
|
|
375
|
+
* Read packets of a media file to get stream information.
|
|
376
|
+
*
|
|
377
|
+
* Analyzes the media file by reading packets to determine stream parameters
|
|
378
|
+
* like codec, dimensions, sample rate, etc. Required after openInput().
|
|
379
|
+
*
|
|
380
|
+
* Direct mapping to avformat_find_stream_info()
|
|
381
|
+
*
|
|
382
|
+
* @param options - Dictionary of options per stream. May be null
|
|
383
|
+
*
|
|
384
|
+
* @returns >=0 on success, negative AVERROR on error:
|
|
385
|
+
* - >=0: Success (number of stream info found)
|
|
386
|
+
* - AVERROR(EIO): I/O error
|
|
387
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
388
|
+
* - <0: Other errors
|
|
389
|
+
*
|
|
390
|
+
* @example
|
|
391
|
+
* ```typescript
|
|
392
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
393
|
+
*
|
|
394
|
+
* const ret = await ctx.findStreamInfo(null);
|
|
395
|
+
* FFmpegError.throwIfError(ret, 'findStreamInfo');
|
|
396
|
+
* console.log(`Found ${ctx.nbStreams} streams`);
|
|
397
|
+
* ```
|
|
398
|
+
*/
|
|
399
|
+
findStreamInfo(options?: Dictionary[] | null): Promise<number>;
|
|
400
|
+
/**
|
|
401
|
+
* Read the next packet in the file.
|
|
402
|
+
*
|
|
403
|
+
* Reads and returns the next packet from the input file.
|
|
404
|
+
* Packets must be unreferenced after use to free memory.
|
|
405
|
+
*
|
|
406
|
+
* Direct mapping to av_read_frame()
|
|
407
|
+
*
|
|
408
|
+
* @param pkt - Packet to fill with data
|
|
409
|
+
*
|
|
410
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
411
|
+
* - 0: Success
|
|
412
|
+
* - AVERROR_EOF: End of file reached
|
|
413
|
+
* - AVERROR(EAGAIN): Temporarily unavailable
|
|
414
|
+
* - AVERROR(EIO): I/O error
|
|
415
|
+
* - <0: Other errors
|
|
416
|
+
*
|
|
417
|
+
* @example
|
|
418
|
+
* ```typescript
|
|
419
|
+
* import { Packet, FormatContext, FFmpegError, AVERROR_EOF } from 'node-av';
|
|
420
|
+
*
|
|
421
|
+
* const packet = new Packet();
|
|
422
|
+
* packet.alloc();
|
|
423
|
+
*
|
|
424
|
+
* while (true) {
|
|
425
|
+
* const ret = await ctx.readFrame(packet);
|
|
426
|
+
* if (ret === AVERROR_EOF) break;
|
|
427
|
+
* FFmpegError.throwIfError(ret, 'readFrame');
|
|
428
|
+
*
|
|
429
|
+
* // Process packet
|
|
430
|
+
* console.log(`Stream ${packet.streamIndex}, PTS: ${packet.pts}`);
|
|
431
|
+
* packet.unref();
|
|
432
|
+
* }
|
|
433
|
+
* ```
|
|
434
|
+
*/
|
|
435
|
+
readFrame(pkt: Packet): Promise<number>;
|
|
436
|
+
/**
|
|
437
|
+
* Seek to the keyframe at timestamp.
|
|
438
|
+
*
|
|
439
|
+
* Seeks to the keyframe at or before the specified timestamp.
|
|
440
|
+
* The next packet read will be from the new position.
|
|
441
|
+
*
|
|
442
|
+
* Direct mapping to av_seek_frame()
|
|
443
|
+
*
|
|
444
|
+
* @param streamIndex - Stream index or -1 for default
|
|
445
|
+
* @param timestamp - Timestamp in stream time_base units or AV_TIME_BASE if stream_index is -1
|
|
446
|
+
* @param flags - AVSEEK_FLAG_* flags
|
|
447
|
+
*
|
|
448
|
+
* @returns >=0 on success, negative AVERROR on error:
|
|
449
|
+
* - >=0: Success
|
|
450
|
+
* - AVERROR(EINVAL): Invalid arguments
|
|
451
|
+
* - AVERROR(EIO): I/O error
|
|
452
|
+
* - <0: Other errors
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* import { FormatContext, FFmpegError, AV_TIME_BASE, AVSEEK_FLAG_BACKWARD } from 'node-av';
|
|
457
|
+
*
|
|
458
|
+
* // Seek to 10 seconds
|
|
459
|
+
* const timestamp = 10n * BigInt(AV_TIME_BASE);
|
|
460
|
+
* const ret = await ctx.seekFrame(-1, timestamp, AVSEEK_FLAG_BACKWARD);
|
|
461
|
+
* FFmpegError.throwIfError(ret, 'seekFrame');
|
|
462
|
+
* // Next readFrame will return packet from new position
|
|
463
|
+
* ```
|
|
464
|
+
*/
|
|
465
|
+
seekFrame(streamIndex: number, timestamp: bigint, flags?: AVSeekFlag): Promise<number>;
|
|
466
|
+
/**
|
|
467
|
+
* Seek to timestamp ts with more control.
|
|
468
|
+
*
|
|
469
|
+
* Seeks to a timestamp within the specified min/max range.
|
|
470
|
+
* More precise than seekFrame() with tolerance control.
|
|
471
|
+
*
|
|
472
|
+
* Direct mapping to avformat_seek_file()
|
|
473
|
+
*
|
|
474
|
+
* @param streamIndex - Stream index or -1 for default
|
|
475
|
+
* @param minTs - Smallest acceptable timestamp
|
|
476
|
+
* @param ts - Target timestamp
|
|
477
|
+
* @param maxTs - Largest acceptable timestamp
|
|
478
|
+
* @param flags - AVSEEK_FLAG_* flags
|
|
479
|
+
*
|
|
480
|
+
* @returns >=0 on success, negative AVERROR on error:
|
|
481
|
+
* - >=0: Success
|
|
482
|
+
* - AVERROR(EINVAL): Invalid arguments
|
|
483
|
+
* - AVERROR(EIO): I/O error
|
|
484
|
+
* - <0: Other errors
|
|
485
|
+
*
|
|
486
|
+
* @example
|
|
487
|
+
* ```typescript
|
|
488
|
+
* import { FormatContext, FFmpegError, AV_TIME_BASE } from 'node-av';
|
|
489
|
+
*
|
|
490
|
+
* // Seek to timestamp with tolerance
|
|
491
|
+
* const target = 10n * BigInt(AV_TIME_BASE);
|
|
492
|
+
* const tolerance = BigInt(AV_TIME_BASE);
|
|
493
|
+
* const ret = await ctx.seekFile(
|
|
494
|
+
* -1,
|
|
495
|
+
* target - tolerance, // min: 9 seconds
|
|
496
|
+
* target, // target: 10 seconds
|
|
497
|
+
* target + tolerance, // max: 11 seconds
|
|
498
|
+
* 0
|
|
499
|
+
* );
|
|
500
|
+
* FFmpegError.throwIfError(ret, 'seekFile');
|
|
501
|
+
* ```
|
|
502
|
+
*/
|
|
503
|
+
seekFile(streamIndex: number, minTs: bigint, ts: bigint, maxTs: bigint, flags?: AVSeekFlag): Promise<number>;
|
|
504
|
+
/**
|
|
505
|
+
* Allocate the stream private data and write the stream header.
|
|
506
|
+
*
|
|
507
|
+
* Initializes the output file and writes the file header.
|
|
508
|
+
* Must be called before writing any packets.
|
|
509
|
+
*
|
|
510
|
+
* Direct mapping to avformat_write_header()
|
|
511
|
+
*
|
|
512
|
+
* @param options - Dictionary of options. May be null
|
|
513
|
+
*
|
|
514
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
515
|
+
* - 0: Success
|
|
516
|
+
* - AVERROR(EINVAL): Invalid parameters
|
|
517
|
+
* - AVERROR(EIO): I/O error
|
|
518
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
519
|
+
* - <0: Other muxer-specific errors
|
|
520
|
+
*
|
|
521
|
+
* @example
|
|
522
|
+
* ```typescript
|
|
523
|
+
* import { Dictionary, FormatContext, FFmpegError } from 'node-av';
|
|
524
|
+
*
|
|
525
|
+
* const options = new Dictionary();
|
|
526
|
+
* options.set('movflags', 'faststart', 0);
|
|
527
|
+
*
|
|
528
|
+
* const ret = await ctx.writeHeader(options);
|
|
529
|
+
* FFmpegError.throwIfError(ret, 'writeHeader');
|
|
530
|
+
* options.free();
|
|
531
|
+
* // Header written, ready to write packets
|
|
532
|
+
* ```
|
|
533
|
+
*/
|
|
534
|
+
writeHeader(options?: Dictionary | null): Promise<number>;
|
|
535
|
+
/**
|
|
536
|
+
* Write a packet to an output media file.
|
|
537
|
+
*
|
|
538
|
+
* Writes a packet directly without reordering.
|
|
539
|
+
* Use interleavedWriteFrame() for automatic interleaving.
|
|
540
|
+
*
|
|
541
|
+
* Direct mapping to av_write_frame()
|
|
542
|
+
*
|
|
543
|
+
* @param pkt - Packet to write. May be null to flush
|
|
544
|
+
*
|
|
545
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
546
|
+
* - 0: Success
|
|
547
|
+
* - AVERROR(EINVAL): Invalid packet
|
|
548
|
+
* - AVERROR(EIO): I/O error
|
|
549
|
+
* - <0: Other muxer-specific errors
|
|
550
|
+
*
|
|
551
|
+
* @example
|
|
552
|
+
* ```typescript
|
|
553
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
554
|
+
*
|
|
555
|
+
* const ret = await ctx.writeFrame(packet);
|
|
556
|
+
* FFmpegError.throwIfError(ret, 'writeFrame');
|
|
557
|
+
*
|
|
558
|
+
* // Flush at the end
|
|
559
|
+
* const flushRet = await ctx.writeFrame(null);
|
|
560
|
+
* FFmpegError.throwIfError(flushRet, 'writeFrame flush');
|
|
561
|
+
* ```
|
|
562
|
+
*
|
|
563
|
+
* @note This function does NOT take ownership of the packet.
|
|
564
|
+
*
|
|
565
|
+
* @see {@link interleavedWriteFrame} For automatic interleaving
|
|
566
|
+
*/
|
|
567
|
+
writeFrame(pkt: Packet | null): Promise<number>;
|
|
568
|
+
/**
|
|
569
|
+
* Write a packet to an output media file ensuring correct interleaving.
|
|
570
|
+
*
|
|
571
|
+
* Automatically interleaves packets from different streams based on DTS.
|
|
572
|
+
* Preferred method for writing packets in most cases.
|
|
573
|
+
*
|
|
574
|
+
* Direct mapping to av_interleaved_write_frame()
|
|
575
|
+
*
|
|
576
|
+
* @param pkt - Packet to write. May be null to flush
|
|
577
|
+
*
|
|
578
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
579
|
+
* - 0: Success
|
|
580
|
+
* - AVERROR(EINVAL): Invalid packet
|
|
581
|
+
* - AVERROR(EIO): I/O error
|
|
582
|
+
* - <0: Other muxer-specific errors
|
|
583
|
+
*
|
|
584
|
+
* @example
|
|
585
|
+
* ```typescript
|
|
586
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
587
|
+
*
|
|
588
|
+
* // Write packets with automatic interleaving
|
|
589
|
+
* const ret = await ctx.interleavedWriteFrame(packet);
|
|
590
|
+
* FFmpegError.throwIfError(ret, 'interleavedWriteFrame');
|
|
591
|
+
* // Packet is automatically freed after writing
|
|
592
|
+
* ```
|
|
593
|
+
*
|
|
594
|
+
* @note This function TAKES OWNERSHIP of the packet and will free it.
|
|
595
|
+
*
|
|
596
|
+
* @see {@link writeFrame} For manual interleaving control
|
|
597
|
+
*/
|
|
598
|
+
interleavedWriteFrame(pkt: Packet | null): Promise<number>;
|
|
599
|
+
/**
|
|
600
|
+
* Write the stream trailer to an output media file.
|
|
601
|
+
*
|
|
602
|
+
* Finalizes the output file by writing the trailer.
|
|
603
|
+
* Must be called after all packets have been written.
|
|
604
|
+
*
|
|
605
|
+
* Direct mapping to av_write_trailer()
|
|
606
|
+
*
|
|
607
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
608
|
+
* - 0: Success
|
|
609
|
+
* - AVERROR(EIO): I/O error
|
|
610
|
+
* - <0: Other muxer-specific errors
|
|
611
|
+
*
|
|
612
|
+
* @example
|
|
613
|
+
* ```typescript
|
|
614
|
+
* import { FormatContext, FFmpegError } from 'node-av';
|
|
615
|
+
*
|
|
616
|
+
* // Finalize the output file
|
|
617
|
+
* const ret = await ctx.writeTrailer();
|
|
618
|
+
* FFmpegError.throwIfError(ret, 'writeTrailer');
|
|
619
|
+
* // File is now complete and finalized
|
|
620
|
+
* ```
|
|
621
|
+
*
|
|
622
|
+
* @note Must be called after all packets have been written.
|
|
623
|
+
*/
|
|
624
|
+
writeTrailer(): Promise<number>;
|
|
625
|
+
/**
|
|
626
|
+
* Flush any buffered data to the output.
|
|
627
|
+
*
|
|
628
|
+
* Direct mapping to avio_flush()
|
|
629
|
+
*
|
|
630
|
+
* @example
|
|
631
|
+
* ```typescript
|
|
632
|
+
* import { FormatContext } from 'node-av';
|
|
633
|
+
*
|
|
634
|
+
* // Flush buffered data
|
|
635
|
+
* ctx.flush();
|
|
636
|
+
* // All buffered data written to output
|
|
637
|
+
* ```
|
|
638
|
+
*/
|
|
639
|
+
flush(): void;
|
|
640
|
+
/**
|
|
641
|
+
* Dump format information to stderr.
|
|
642
|
+
*
|
|
643
|
+
* Prints detailed information about the format and streams to stderr.
|
|
644
|
+
* Useful for debugging and understanding file structure.
|
|
645
|
+
*
|
|
646
|
+
* Direct mapping to av_dump_format()
|
|
647
|
+
*
|
|
648
|
+
* @param index - Stream index or program index to dump
|
|
649
|
+
* @param url - URL or filename to display
|
|
650
|
+
* @param isOutput - true for output format, false for input format
|
|
651
|
+
*
|
|
652
|
+
* @example
|
|
653
|
+
* ```typescript
|
|
654
|
+
* import { FormatContext } from 'node-av';
|
|
655
|
+
*
|
|
656
|
+
* // Dump input format info
|
|
657
|
+
* formatCtx.dumpFormat(0, 'input.mp4', false);
|
|
658
|
+
*
|
|
659
|
+
* // Dump output format info
|
|
660
|
+
* formatCtx.dumpFormat(0, 'output.mp4', true);
|
|
661
|
+
* ```
|
|
662
|
+
*/
|
|
663
|
+
dumpFormat(index: number, url: string, isOutput: boolean): void;
|
|
664
|
+
/**
|
|
665
|
+
* Find the "best" stream in the file.
|
|
666
|
+
*
|
|
667
|
+
* The best stream is determined according to various heuristics as the most
|
|
668
|
+
* likely to be what the user expects.
|
|
669
|
+
*
|
|
670
|
+
* Direct mapping to av_find_best_stream()
|
|
671
|
+
*
|
|
672
|
+
* @param type - Media type (AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, etc.)
|
|
673
|
+
* @param wantedStreamNb - User-requested stream number, or -1 for automatic selection
|
|
674
|
+
* @param relatedStream - Try to find a stream related to this one, or -1 if none
|
|
675
|
+
*
|
|
676
|
+
* @returns The stream index if found, or negative AVERROR on error:
|
|
677
|
+
* - >=0: Stream index of the best stream
|
|
678
|
+
* - AVERROR_STREAM_NOT_FOUND: No stream of the requested type found
|
|
679
|
+
* - AVERROR_DECODER_NOT_FOUND: Streams were found but no decoder
|
|
680
|
+
* - <0: Other errors
|
|
681
|
+
*
|
|
682
|
+
* @example
|
|
683
|
+
* ```typescript
|
|
684
|
+
* import { FormatContext, FFmpegError, AVMEDIA_TYPE_VIDEO } from 'node-av';
|
|
685
|
+
*
|
|
686
|
+
* // Find best video stream
|
|
687
|
+
* const videoStreamIndex = ctx.findBestStream(
|
|
688
|
+
* AVMEDIA_TYPE_VIDEO,
|
|
689
|
+
* -1, // automatic selection
|
|
690
|
+
* -1 // no related stream
|
|
691
|
+
* );
|
|
692
|
+
*
|
|
693
|
+
* if (videoStreamIndex < 0) {
|
|
694
|
+
* FFmpegError.throwIfError(videoStreamIndex, 'findBestStream');
|
|
695
|
+
* }
|
|
696
|
+
* const videoStream = ctx.streams[videoStreamIndex];
|
|
697
|
+
* // Process video stream
|
|
698
|
+
* ```
|
|
699
|
+
*/
|
|
700
|
+
findBestStream(type: AVMediaType, wantedStreamNb?: number, relatedStream?: number): number;
|
|
701
|
+
/**
|
|
702
|
+
* Find the "best" stream in the file and optionally return the decoder.
|
|
703
|
+
*
|
|
704
|
+
* The best stream is determined according to various heuristics as the most
|
|
705
|
+
* likely to be what the user expects.
|
|
706
|
+
*
|
|
707
|
+
* Direct mapping to av_find_best_stream()
|
|
708
|
+
*
|
|
709
|
+
* @param type - Media type (AVMEDIA_TYPE_VIDEO, AVMEDIA_TYPE_AUDIO, etc.)
|
|
710
|
+
* @param wantedStreamNb - User-requested stream number, or -1 for automatic selection
|
|
711
|
+
* @param relatedStream - Try to find a stream related to this one, or -1 if none
|
|
712
|
+
* @param wantDecoder - Whether to return the decoder for the stream
|
|
713
|
+
* @param flags - Currently unused, pass 0
|
|
714
|
+
*
|
|
715
|
+
* @returns Object with stream index and decoder if found
|
|
716
|
+
*
|
|
717
|
+
* @example
|
|
718
|
+
* ```typescript
|
|
719
|
+
* import { FormatContext, FFmpegError, AVMEDIA_TYPE_VIDEO } from 'node-av';
|
|
720
|
+
*
|
|
721
|
+
* // Find best video stream with decoder
|
|
722
|
+
* const result = ctx.findBestStream(
|
|
723
|
+
* AVMEDIA_TYPE_VIDEO,
|
|
724
|
+
* -1, // automatic selection
|
|
725
|
+
* -1, // no related stream
|
|
726
|
+
* true, // want decoder
|
|
727
|
+
* 0
|
|
728
|
+
* );
|
|
729
|
+
*
|
|
730
|
+
* if (result.streamIndex < 0) {
|
|
731
|
+
* FFmpegError.throwIfError(result.streamIndex, 'findBestStream');
|
|
732
|
+
* }
|
|
733
|
+
* const videoStream = ctx.streams[result.streamIndex];
|
|
734
|
+
* const decoder = result.decoder;
|
|
735
|
+
* // Use decoder directly
|
|
736
|
+
* ```
|
|
737
|
+
*/
|
|
738
|
+
findBestStream(type: AVMediaType, wantedStreamNb: number, relatedStream: number, wantDecoder: true, flags?: number): {
|
|
739
|
+
streamIndex: number;
|
|
740
|
+
decoder: Codec | null;
|
|
741
|
+
};
|
|
742
|
+
/**
|
|
743
|
+
* Add a new stream to the media file.
|
|
744
|
+
*
|
|
745
|
+
* Creates a new stream in the output format context.
|
|
746
|
+
* The stream must be configured before calling writeHeader().
|
|
747
|
+
*
|
|
748
|
+
* Direct mapping to avformat_new_stream()
|
|
749
|
+
*
|
|
750
|
+
* @param c - Codec to use for the stream. May be null
|
|
751
|
+
*
|
|
752
|
+
* @returns The newly created stream
|
|
753
|
+
*
|
|
754
|
+
* @throws {Error} If stream creation fails (ENOMEM)
|
|
755
|
+
*
|
|
756
|
+
* @example
|
|
757
|
+
* ```typescript
|
|
758
|
+
* import { FormatContext, Codec, FFmpegError } from 'node-av';
|
|
759
|
+
* import { AV_CODEC_ID_H264, AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
|
|
760
|
+
*
|
|
761
|
+
* // Add a video stream
|
|
762
|
+
* const videoCodec = Codec.findEncoder(AV_CODEC_ID_H264);
|
|
763
|
+
* const videoStream = ctx.newStream(videoCodec);
|
|
764
|
+
*
|
|
765
|
+
* // Configure stream parameters
|
|
766
|
+
* videoStream.codecpar.codecType = AVMEDIA_TYPE_VIDEO;
|
|
767
|
+
* videoStream.codecpar.codecId = AV_CODEC_ID_H264;
|
|
768
|
+
* videoStream.codecpar.width = 1920;
|
|
769
|
+
* videoStream.codecpar.height = 1080;
|
|
770
|
+
* ```
|
|
771
|
+
*/
|
|
772
|
+
newStream(c?: Codec | null): Stream;
|
|
773
|
+
/**
|
|
774
|
+
* Get the native FFmpeg AVFormatContext pointer.
|
|
775
|
+
*
|
|
776
|
+
* @internal For use by other wrapper classes
|
|
777
|
+
* @returns The underlying native format context object
|
|
778
|
+
*/
|
|
779
|
+
getNative(): NativeFormatContext;
|
|
780
|
+
/**
|
|
781
|
+
* Dispose of the format context asynchronously.
|
|
782
|
+
*
|
|
783
|
+
* Implements the AsyncDisposable interface for automatic cleanup.
|
|
784
|
+
* Properly handles network connections and I/O operations.
|
|
785
|
+
*
|
|
786
|
+
* @example
|
|
787
|
+
* ```typescript
|
|
788
|
+
* import { FormatContext } from 'node-av';
|
|
789
|
+
*
|
|
790
|
+
* {
|
|
791
|
+
* await using ctx = new FormatContext();
|
|
792
|
+
* await ctx.openInput('rtsp://camera/stream');
|
|
793
|
+
* // ... use context
|
|
794
|
+
* } // Automatically closed when leaving scope
|
|
795
|
+
* ```
|
|
796
|
+
*/
|
|
797
|
+
[Symbol.asyncDispose](): Promise<void>;
|
|
798
|
+
}
|