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,72 +1,61 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* MediaOutput - Unified Output Handler for FFmpeg
|
|
3
|
-
*
|
|
4
|
-
* Provides a high-level interface for writing media to various destinations.
|
|
5
|
-
* Supports files, streams, and custom IO with automatic format configuration.
|
|
6
|
-
*
|
|
7
|
-
* Central entry point for all media output operations.
|
|
8
|
-
* Manages FormatContext lifecycle and provides stream management.
|
|
9
|
-
*
|
|
10
|
-
* @module api/media-output
|
|
11
|
-
*/
|
|
12
1
|
import { FormatContext } from '../lib/index.js';
|
|
13
2
|
import { Encoder } from './encoder.js';
|
|
14
3
|
import type { IRational, Packet, Stream } from '../lib/index.js';
|
|
15
4
|
import type { IOOutputCallbacks, MediaOutputOptions } from './types.js';
|
|
16
|
-
interface
|
|
5
|
+
export interface StreamDescription {
|
|
17
6
|
stream: Stream;
|
|
18
7
|
timeBase: IRational;
|
|
19
8
|
isStreamCopy: boolean;
|
|
20
9
|
sourceTimeBase?: IRational;
|
|
21
10
|
}
|
|
22
11
|
/**
|
|
23
|
-
*
|
|
12
|
+
* High-level media output for writing and muxing media files.
|
|
24
13
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
28
|
-
*
|
|
29
|
-
* adding streams, writing packets, and finalizing output.
|
|
14
|
+
* Provides simplified access to media muxing and file writing operations.
|
|
15
|
+
* Handles stream configuration, packet writing, and format management.
|
|
16
|
+
* Supports files, URLs, and custom I/O with automatic cleanup.
|
|
17
|
+
* Essential component for media encoding pipelines and transcoding.
|
|
30
18
|
*
|
|
31
19
|
* @example
|
|
32
20
|
* ```typescript
|
|
33
|
-
* import { MediaOutput
|
|
21
|
+
* import { MediaOutput } from 'node-av/api';
|
|
34
22
|
*
|
|
35
|
-
* //
|
|
36
|
-
*
|
|
23
|
+
* // Create output file
|
|
24
|
+
* await using output = await MediaOutput.open('output.mp4');
|
|
37
25
|
*
|
|
38
|
-
* // Add
|
|
39
|
-
* const
|
|
40
|
-
*
|
|
41
|
-
* height: 1080,
|
|
42
|
-
* pixelFormat: AV_PIX_FMT_YUV420P
|
|
43
|
-
* });
|
|
44
|
-
* const streamIdx = output.addStream(encoder);
|
|
26
|
+
* // Add streams from encoders
|
|
27
|
+
* const videoIdx = output.addStream(videoEncoder);
|
|
28
|
+
* const audioIdx = output.addStream(audioEncoder);
|
|
45
29
|
*
|
|
46
|
-
* // Write header
|
|
30
|
+
* // Write header
|
|
47
31
|
* await output.writeHeader();
|
|
48
|
-
*
|
|
32
|
+
*
|
|
33
|
+
* // Write packets
|
|
34
|
+
* await output.writePacket(packet, videoIdx);
|
|
35
|
+
*
|
|
36
|
+
* // Write trailer and close
|
|
49
37
|
* await output.writeTrailer();
|
|
50
|
-
* await output.close();
|
|
51
38
|
* ```
|
|
52
39
|
*
|
|
53
40
|
* @example
|
|
54
41
|
* ```typescript
|
|
55
|
-
* // Stream copy
|
|
56
|
-
*
|
|
57
|
-
*
|
|
58
|
-
*
|
|
59
|
-
* const videoStream = input.video();
|
|
60
|
-
* const streamIdx = output.addStream(videoStream);
|
|
42
|
+
* // Stream copy
|
|
43
|
+
* await using input = await MediaInput.open('input.mp4');
|
|
44
|
+
* await using output = await MediaOutput.open('output.mp4');
|
|
61
45
|
*
|
|
46
|
+
* // Copy stream configuration
|
|
47
|
+
* const videoIdx = output.addStream(input.video());
|
|
62
48
|
* await output.writeHeader();
|
|
49
|
+
*
|
|
63
50
|
* for await (const packet of input.packets()) {
|
|
64
|
-
*
|
|
65
|
-
*
|
|
66
|
-
* }
|
|
51
|
+
* await output.writePacket(packet, videoIdx);
|
|
52
|
+
* packet.free();
|
|
67
53
|
* }
|
|
68
|
-
* await output.writeTrailer();
|
|
69
54
|
* ```
|
|
55
|
+
*
|
|
56
|
+
* @see {@link MediaInput} For reading media files
|
|
57
|
+
* @see {@link Encoder} For encoding frames to packets
|
|
58
|
+
* @see {@link FormatContext} For low-level API
|
|
70
59
|
*/
|
|
71
60
|
export declare class MediaOutput implements AsyncDisposable {
|
|
72
61
|
private formatContext;
|
|
@@ -76,199 +65,292 @@ export declare class MediaOutput implements AsyncDisposable {
|
|
|
76
65
|
private trailerWritten;
|
|
77
66
|
private closed;
|
|
78
67
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* Initializes the output with a new FormatContext.
|
|
82
|
-
* The actual format setup happens in the static factory method.
|
|
68
|
+
* @internal
|
|
83
69
|
*/
|
|
84
70
|
private constructor();
|
|
85
71
|
/**
|
|
86
|
-
*
|
|
72
|
+
* Open media output for writing.
|
|
87
73
|
*
|
|
88
|
-
* Creates
|
|
89
|
-
* Automatically
|
|
74
|
+
* Creates and configures output context for muxing.
|
|
75
|
+
* Automatically creates directories for file output.
|
|
76
|
+
* Supports files, URLs, and custom I/O callbacks.
|
|
90
77
|
*
|
|
91
|
-
*
|
|
92
|
-
* Format must be explicitly specified for custom IO.
|
|
78
|
+
* Direct mapping to avformat_alloc_output_context2() and avio_open2().
|
|
93
79
|
*
|
|
94
|
-
*
|
|
80
|
+
* @param target - File path, URL, or I/O callbacks
|
|
81
|
+
* @param options - Output configuration options
|
|
82
|
+
* @returns Opened media output instance
|
|
95
83
|
*
|
|
96
|
-
* @
|
|
97
|
-
* @param options - Optional configuration
|
|
84
|
+
* @throws {Error} If format required for custom I/O
|
|
98
85
|
*
|
|
99
|
-
* @
|
|
100
|
-
*
|
|
101
|
-
* @throws {Error} If format not specified or context allocation fails
|
|
86
|
+
* @throws {FFmpegError} If allocation or opening fails
|
|
102
87
|
*
|
|
103
88
|
* @example
|
|
104
89
|
* ```typescript
|
|
105
|
-
*
|
|
106
|
-
*
|
|
107
|
-
* seek: (offset, whence) => offset
|
|
108
|
-
* };
|
|
109
|
-
* const output = await MediaOutput.open(callbacks, { format: 'mp4' });
|
|
90
|
+
* // Create file output
|
|
91
|
+
* await using output = await MediaOutput.open('output.mp4');
|
|
110
92
|
* ```
|
|
111
93
|
*
|
|
112
94
|
* @example
|
|
113
95
|
* ```typescript
|
|
114
|
-
*
|
|
96
|
+
* // Create output with specific format
|
|
97
|
+
* await using output = await MediaOutput.open('output.ts', {
|
|
98
|
+
* format: 'mpegts'
|
|
99
|
+
* });
|
|
115
100
|
* ```
|
|
116
101
|
*
|
|
117
102
|
* @example
|
|
118
103
|
* ```typescript
|
|
119
|
-
*
|
|
104
|
+
* // Custom I/O callbacks
|
|
105
|
+
* const callbacks = {
|
|
106
|
+
* write: async (buffer: Buffer) => {
|
|
107
|
+
* // Write to custom destination
|
|
108
|
+
* return buffer.length;
|
|
109
|
+
* },
|
|
110
|
+
* seek: async (offset: bigint, whence: number) => {
|
|
111
|
+
* // Seek in custom destination
|
|
112
|
+
* return offset;
|
|
113
|
+
* }
|
|
114
|
+
* };
|
|
115
|
+
*
|
|
116
|
+
* await using output = await MediaOutput.open(callbacks, {
|
|
117
|
+
* format: 'mp4',
|
|
118
|
+
* bufferSize: 8192
|
|
119
|
+
* });
|
|
120
120
|
* ```
|
|
121
|
+
*
|
|
122
|
+
* @see {@link MediaOutputOptions} For configuration options
|
|
123
|
+
* @see {@link IOOutputCallbacks} For custom I/O interface
|
|
121
124
|
*/
|
|
122
125
|
static open(target: string | IOOutputCallbacks, options?: MediaOutputOptions): Promise<MediaOutput>;
|
|
123
126
|
/**
|
|
124
|
-
*
|
|
127
|
+
* Add a stream to the output.
|
|
125
128
|
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
129
|
+
* Configures output stream from encoder or input stream.
|
|
130
|
+
* Must be called before writeHeader().
|
|
131
|
+
* Returns stream index for packet writing.
|
|
128
132
|
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* @param source - Encoder for transcoding or Stream for copying
|
|
132
|
-
* @param options - Optional stream configuration
|
|
133
|
-
* @param options.timeBase - Custom output timebase for the stream.
|
|
134
|
-
* If not specified, uses the source's timebase.
|
|
135
|
-
* When set, packets will be automatically rescaled
|
|
136
|
-
* from source timebase to this output timebase.
|
|
133
|
+
* Direct mapping to avformat_new_stream() and avcodec_parameters_copy().
|
|
137
134
|
*
|
|
135
|
+
* @param source - Encoder or stream to add
|
|
136
|
+
* @param options - Stream configuration options
|
|
137
|
+
* @param options.timeBase - Optional custom timebase for the stream
|
|
138
138
|
* @returns Stream index for packet writing
|
|
139
139
|
*
|
|
140
|
-
* @throws {Error} If called after header
|
|
141
|
-
*
|
|
142
|
-
* @example
|
|
143
|
-
* ```typescript
|
|
144
|
-
* // Add encoder stream (transcoding) - uses encoder's timebase
|
|
145
|
-
* const encoder = await Encoder.create('libx264', { width: 1920, height: 1080 });
|
|
146
|
-
* const streamIdx = output.addStream(encoder);
|
|
147
|
-
* ```
|
|
140
|
+
* @throws {Error} If called after header written or output closed
|
|
148
141
|
*
|
|
149
142
|
* @example
|
|
150
143
|
* ```typescript
|
|
151
|
-
* // Add stream
|
|
152
|
-
* const
|
|
153
|
-
* const
|
|
144
|
+
* // Add stream from encoder
|
|
145
|
+
* const videoIdx = output.addStream(videoEncoder);
|
|
146
|
+
* const audioIdx = output.addStream(audioEncoder);
|
|
154
147
|
* ```
|
|
155
148
|
*
|
|
156
149
|
* @example
|
|
157
150
|
* ```typescript
|
|
158
|
-
* //
|
|
159
|
-
* const streamIdx = output.addStream(
|
|
160
|
-
* timeBase: { num: 1, den: 90000 }
|
|
151
|
+
* // Stream copy with custom timebase
|
|
152
|
+
* const streamIdx = output.addStream(input.video(), {
|
|
153
|
+
* timeBase: { num: 1, den: 90000 }
|
|
161
154
|
* });
|
|
162
|
-
* // Packets from encoder will be automatically rescaled to 1/90000
|
|
163
155
|
* ```
|
|
156
|
+
*
|
|
157
|
+
* @see {@link writePacket} For writing packets to streams
|
|
158
|
+
* @see {@link Encoder} For transcoding source
|
|
164
159
|
*/
|
|
165
160
|
addStream(source: Encoder | Stream, options?: {
|
|
166
161
|
timeBase?: IRational;
|
|
167
162
|
}): number;
|
|
168
163
|
/**
|
|
169
|
-
*
|
|
164
|
+
* Write a packet to the output.
|
|
170
165
|
*
|
|
171
|
-
* Writes
|
|
172
|
-
* Automatically
|
|
166
|
+
* Writes muxed packet to the specified stream.
|
|
167
|
+
* Automatically handles timestamp rescaling.
|
|
168
|
+
* Must be called after writeHeader() and before writeTrailer().
|
|
173
169
|
*
|
|
174
|
-
*
|
|
170
|
+
* Direct mapping to av_interleaved_write_frame().
|
|
175
171
|
*
|
|
176
172
|
* @param packet - Packet to write
|
|
177
173
|
* @param streamIndex - Target stream index
|
|
174
|
+
* @throws {Error} If stream invalid or called at wrong time
|
|
178
175
|
*
|
|
179
|
-
* @throws {
|
|
176
|
+
* @throws {FFmpegError} If write fails
|
|
180
177
|
*
|
|
181
178
|
* @example
|
|
182
179
|
* ```typescript
|
|
183
|
-
*
|
|
184
|
-
*
|
|
185
|
-
*
|
|
186
|
-
*
|
|
180
|
+
* // Write encoded packet
|
|
181
|
+
* const packet = await encoder.encode(frame);
|
|
182
|
+
* if (packet) {
|
|
183
|
+
* await output.writePacket(packet, videoIdx);
|
|
184
|
+
* packet.free();
|
|
187
185
|
* }
|
|
188
186
|
* ```
|
|
187
|
+
*
|
|
188
|
+
* @example
|
|
189
|
+
* ```typescript
|
|
190
|
+
* // Stream copy with packet processing
|
|
191
|
+
* for await (const packet of input.packets()) {
|
|
192
|
+
* if (packet.streamIndex === inputVideoIdx) {
|
|
193
|
+
* await output.writePacket(packet, outputVideoIdx);
|
|
194
|
+
* }
|
|
195
|
+
* packet.free();
|
|
196
|
+
* }
|
|
197
|
+
* ```
|
|
198
|
+
*
|
|
199
|
+
* @see {@link addStream} For adding streams
|
|
200
|
+
* @see {@link writeHeader} Must be called first
|
|
189
201
|
*/
|
|
190
202
|
writePacket(packet: Packet, streamIndex: number): Promise<void>;
|
|
191
203
|
/**
|
|
192
|
-
*
|
|
204
|
+
* Write file header.
|
|
193
205
|
*
|
|
194
|
-
* Writes
|
|
195
|
-
* Must be called before writing
|
|
206
|
+
* Writes format header with stream configuration.
|
|
207
|
+
* Must be called after adding all streams and before writing packets.
|
|
208
|
+
* Finalizes stream parameters and initializes muxer.
|
|
196
209
|
*
|
|
197
|
-
*
|
|
210
|
+
* Direct mapping to avformat_write_header().
|
|
198
211
|
*
|
|
199
|
-
* @
|
|
212
|
+
* @throws {Error} If already written or output closed
|
|
200
213
|
*
|
|
201
|
-
* @throws {
|
|
214
|
+
* @throws {FFmpegError} If write fails
|
|
202
215
|
*
|
|
203
216
|
* @example
|
|
204
217
|
* ```typescript
|
|
218
|
+
* // Standard workflow
|
|
219
|
+
* const output = await MediaOutput.open('output.mp4');
|
|
220
|
+
* output.addStream(encoder);
|
|
205
221
|
* await output.writeHeader();
|
|
222
|
+
* // Now ready to write packets
|
|
206
223
|
* ```
|
|
224
|
+
*
|
|
225
|
+
* @see {@link addStream} Must add streams first
|
|
226
|
+
* @see {@link writePacket} Can write packets after
|
|
227
|
+
* @see {@link writeTrailer} Must call at end
|
|
207
228
|
*/
|
|
208
229
|
writeHeader(): Promise<void>;
|
|
209
230
|
/**
|
|
210
|
-
*
|
|
231
|
+
* Write file trailer.
|
|
232
|
+
*
|
|
233
|
+
* Writes format trailer and finalizes the file.
|
|
234
|
+
* Must be called after all packets are written.
|
|
235
|
+
* Flushes any buffered data and updates file headers.
|
|
211
236
|
*
|
|
212
|
-
*
|
|
213
|
-
* Should be called after all packets have been written.
|
|
237
|
+
* Direct mapping to av_write_trailer().
|
|
214
238
|
*
|
|
215
|
-
*
|
|
239
|
+
* @throws {Error} If header not written or already written
|
|
216
240
|
*
|
|
217
|
-
* @throws {
|
|
241
|
+
* @throws {FFmpegError} If write fails
|
|
218
242
|
*
|
|
219
243
|
* @example
|
|
220
244
|
* ```typescript
|
|
245
|
+
* // Finalize output
|
|
221
246
|
* await output.writeTrailer();
|
|
247
|
+
* await output.close();
|
|
222
248
|
* ```
|
|
249
|
+
*
|
|
250
|
+
* @see {@link writeHeader} Must be called first
|
|
251
|
+
* @see {@link close} For cleanup after trailer
|
|
223
252
|
*/
|
|
224
253
|
writeTrailer(): Promise<void>;
|
|
225
254
|
/**
|
|
226
|
-
*
|
|
255
|
+
* Close media output and free resources.
|
|
227
256
|
*
|
|
228
|
-
* Writes trailer if needed
|
|
257
|
+
* Writes trailer if needed and releases all resources.
|
|
229
258
|
* Safe to call multiple times.
|
|
230
|
-
*
|
|
231
|
-
* Uses av_write_trailer(), avio_closep(), and avformat_free_context() internally.
|
|
259
|
+
* Automatically called by Symbol.asyncDispose.
|
|
232
260
|
*
|
|
233
261
|
* @example
|
|
234
262
|
* ```typescript
|
|
235
|
-
* await output.
|
|
263
|
+
* const output = await MediaOutput.open('output.mp4');
|
|
264
|
+
* try {
|
|
265
|
+
* // Use output
|
|
266
|
+
* } finally {
|
|
267
|
+
* await output.close();
|
|
268
|
+
* }
|
|
236
269
|
* ```
|
|
270
|
+
*
|
|
271
|
+
* @see {@link Symbol.asyncDispose} For automatic cleanup
|
|
237
272
|
*/
|
|
238
273
|
close(): Promise<void>;
|
|
239
274
|
/**
|
|
240
|
-
*
|
|
275
|
+
* Get stream information.
|
|
276
|
+
*
|
|
277
|
+
* Returns internal stream info for the specified index.
|
|
278
|
+
*
|
|
279
|
+
* @param streamIndex - Stream index
|
|
280
|
+
* @returns Stream info or undefined
|
|
281
|
+
*
|
|
282
|
+
* @example
|
|
283
|
+
* ```typescript
|
|
284
|
+
* const info = output.getStreamInfo(0);
|
|
285
|
+
* console.log(`Stream 0 timebase: ${info?.timeBase.num}/${info?.timeBase.den}`);
|
|
286
|
+
* ```
|
|
241
287
|
*/
|
|
242
|
-
getStreamInfo(streamIndex: number):
|
|
288
|
+
getStreamInfo(streamIndex: number): StreamDescription | undefined;
|
|
243
289
|
/**
|
|
244
|
-
*
|
|
290
|
+
* Get all stream indices.
|
|
291
|
+
*
|
|
292
|
+
* Returns array of all added stream indices.
|
|
293
|
+
*
|
|
294
|
+
* @returns Array of stream indices
|
|
295
|
+
*
|
|
296
|
+
* @example
|
|
297
|
+
* ```typescript
|
|
298
|
+
* const indices = output.getStreamIndices();
|
|
299
|
+
* console.log(`Output has ${indices.length} streams`);
|
|
300
|
+
* ```
|
|
245
301
|
*/
|
|
246
302
|
getStreamIndices(): number[];
|
|
247
303
|
/**
|
|
248
|
-
*
|
|
304
|
+
* Check if header has been written.
|
|
305
|
+
*
|
|
306
|
+
* @returns true if header written
|
|
307
|
+
*
|
|
308
|
+
* @example
|
|
309
|
+
* ```typescript
|
|
310
|
+
* if (!output.isHeaderWritten()) {
|
|
311
|
+
* await output.writeHeader();
|
|
312
|
+
* }
|
|
313
|
+
* ```
|
|
249
314
|
*/
|
|
250
315
|
isHeaderWritten(): boolean;
|
|
251
316
|
/**
|
|
252
|
-
*
|
|
317
|
+
* Check if trailer has been written.
|
|
318
|
+
*
|
|
319
|
+
* @returns true if trailer written
|
|
320
|
+
*
|
|
321
|
+
* @example
|
|
322
|
+
* ```typescript
|
|
323
|
+
* if (!output.isTrailerWritten()) {
|
|
324
|
+
* await output.writeTrailer();
|
|
325
|
+
* }
|
|
326
|
+
* ```
|
|
253
327
|
*/
|
|
254
328
|
isTrailerWritten(): boolean;
|
|
255
329
|
/**
|
|
256
|
-
*
|
|
330
|
+
* Get underlying format context.
|
|
257
331
|
*
|
|
258
|
-
*
|
|
332
|
+
* Returns the internal format context for advanced operations.
|
|
333
|
+
*
|
|
334
|
+
* @returns Format context
|
|
335
|
+
*
|
|
336
|
+
* @internal
|
|
259
337
|
*/
|
|
260
338
|
getFormatContext(): FormatContext;
|
|
261
339
|
/**
|
|
262
|
-
*
|
|
340
|
+
* Dispose of media output.
|
|
263
341
|
*
|
|
264
|
-
*
|
|
342
|
+
* Implements AsyncDisposable interface for automatic cleanup.
|
|
343
|
+
* Equivalent to calling close().
|
|
265
344
|
*
|
|
266
345
|
* @example
|
|
267
346
|
* ```typescript
|
|
268
|
-
*
|
|
269
|
-
*
|
|
347
|
+
* {
|
|
348
|
+
* await using output = await MediaOutput.open('output.mp4');
|
|
349
|
+
* // Use output...
|
|
350
|
+
* } // Automatically closed
|
|
270
351
|
* ```
|
|
352
|
+
*
|
|
353
|
+
* @see {@link close} For manual cleanup
|
|
271
354
|
*/
|
|
272
355
|
[Symbol.asyncDispose](): Promise<void>;
|
|
273
356
|
}
|
|
274
|
-
export {};
|