node-av 3.1.2 → 4.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +65 -52
- package/binding.gyp +4 -0
- package/dist/api/audio-frame-buffer.d.ts +201 -0
- package/dist/api/audio-frame-buffer.js +275 -0
- package/dist/api/audio-frame-buffer.js.map +1 -0
- package/dist/api/bitstream-filter.d.ts +319 -78
- package/dist/api/bitstream-filter.js +680 -151
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/constants.d.ts +44 -0
- package/dist/api/constants.js +45 -0
- package/dist/api/constants.js.map +1 -0
- package/dist/api/data/test_av1.ivf +0 -0
- package/dist/api/data/test_mjpeg.mjpeg +0 -0
- package/dist/api/data/test_vp8.ivf +0 -0
- package/dist/api/data/test_vp9.ivf +0 -0
- package/dist/api/decoder.d.ts +279 -17
- package/dist/api/decoder.js +998 -209
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/{media-input.d.ts → demuxer.d.ts} +294 -44
- package/dist/api/demuxer.js +1968 -0
- package/dist/api/demuxer.js.map +1 -0
- package/dist/api/encoder.d.ts +308 -50
- package/dist/api/encoder.js +1133 -111
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +12 -5
- package/dist/api/filter-presets.js +21 -7
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +406 -40
- package/dist/api/filter.js +966 -139
- package/dist/api/filter.js.map +1 -1
- package/dist/api/{fmp4.d.ts → fmp4-stream.d.ts} +141 -140
- package/dist/api/fmp4-stream.js +539 -0
- package/dist/api/fmp4-stream.js.map +1 -0
- package/dist/api/hardware.d.ts +58 -6
- package/dist/api/hardware.js +127 -11
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +6 -4
- package/dist/api/index.js +14 -8
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +3 -3
- package/dist/api/io-stream.js +5 -4
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/{media-output.d.ts → muxer.d.ts} +274 -60
- package/dist/api/muxer.js +1934 -0
- package/dist/api/muxer.js.map +1 -0
- package/dist/api/pipeline.d.ts +77 -29
- package/dist/api/pipeline.js +435 -425
- package/dist/api/pipeline.js.map +1 -1
- package/dist/api/rtp-stream.d.ts +312 -0
- package/dist/api/rtp-stream.js +630 -0
- package/dist/api/rtp-stream.js.map +1 -0
- package/dist/api/types.d.ts +476 -55
- package/dist/api/utilities/async-queue.d.ts +91 -0
- package/dist/api/utilities/async-queue.js +162 -0
- package/dist/api/utilities/async-queue.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +1 -1
- package/dist/api/utilities/image.d.ts +1 -1
- package/dist/api/utilities/index.d.ts +2 -0
- package/dist/api/utilities/index.js +4 -0
- package/dist/api/utilities/index.js.map +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -1
- package/dist/api/utilities/pixel-format.d.ts +1 -1
- package/dist/api/utilities/sample-format.d.ts +1 -1
- package/dist/api/utilities/scheduler.d.ts +169 -0
- package/dist/api/utilities/scheduler.js +136 -0
- package/dist/api/utilities/scheduler.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +74 -15
- package/dist/api/utilities/streaming.js +170 -12
- package/dist/api/utilities/streaming.js.map +1 -1
- package/dist/api/utilities/timestamp.d.ts +1 -1
- package/dist/api/webrtc-stream.d.ts +288 -0
- package/dist/api/webrtc-stream.js +440 -0
- package/dist/api/webrtc-stream.js.map +1 -0
- package/dist/constants/constants.d.ts +51 -1
- package/dist/constants/constants.js +47 -1
- package/dist/constants/constants.js.map +1 -1
- package/dist/constants/encoders.d.ts +2 -1
- package/dist/constants/encoders.js +4 -3
- package/dist/constants/encoders.js.map +1 -1
- package/dist/constants/hardware.d.ts +26 -0
- package/dist/constants/hardware.js +27 -0
- package/dist/constants/hardware.js.map +1 -0
- package/dist/constants/index.d.ts +1 -0
- package/dist/constants/index.js +1 -0
- package/dist/constants/index.js.map +1 -1
- package/dist/lib/binding.d.ts +19 -8
- package/dist/lib/binding.js.map +1 -1
- package/dist/lib/codec-context.d.ts +87 -0
- package/dist/lib/codec-context.js +125 -4
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +183 -1
- package/dist/lib/codec-parameters.js +209 -0
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +23 -0
- package/dist/lib/codec-parser.js +25 -0
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +26 -4
- package/dist/lib/codec.js +35 -0
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.js +1 -0
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.js +1 -1
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +52 -11
- package/dist/lib/filter-context.js +56 -12
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +9 -0
- package/dist/lib/filter-graph.js +13 -0
- package/dist/lib/filter-graph.js.map +1 -1
- package/dist/lib/filter.d.ts +21 -0
- package/dist/lib/filter.js +28 -0
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +48 -14
- package/dist/lib/format-context.js +76 -7
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +168 -0
- package/dist/lib/frame.js +212 -0
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +3 -2
- package/dist/lib/hardware-device-context.js.map +1 -1
- package/dist/lib/index.d.ts +1 -0
- package/dist/lib/index.js +2 -0
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +21 -0
- package/dist/lib/input-format.js +42 -2
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/native-types.d.ts +48 -26
- package/dist/lib/option.d.ts +25 -13
- package/dist/lib/option.js +28 -0
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +22 -1
- package/dist/lib/output-format.js +28 -0
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +35 -0
- package/dist/lib/packet.js +52 -2
- package/dist/lib/packet.js.map +1 -1
- package/dist/lib/stream.d.ts +126 -0
- package/dist/lib/stream.js +188 -5
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/sync-queue.d.ts +179 -0
- package/dist/lib/sync-queue.js +197 -0
- package/dist/lib/sync-queue.js.map +1 -0
- package/dist/lib/types.d.ts +27 -1
- package/dist/lib/utilities.d.ts +281 -53
- package/dist/lib/utilities.js +298 -55
- package/dist/lib/utilities.js.map +1 -1
- package/install/check.js +18 -7
- package/package.json +20 -19
- package/dist/api/fmp4.js +0 -710
- package/dist/api/fmp4.js.map +0 -1
- package/dist/api/media-input.js +0 -1075
- package/dist/api/media-input.js.map +0 -1
- package/dist/api/media-output.js +0 -1040
- package/dist/api/media-output.js.map +0 -1
- package/dist/api/webrtc.d.ts +0 -664
- package/dist/api/webrtc.js +0 -1132
- package/dist/api/webrtc.js.map +0 -1
package/dist/api/types.d.ts
CHANGED
|
@@ -1,23 +1,55 @@
|
|
|
1
|
-
import type {
|
|
1
|
+
import type { RtpPacket } from 'werift';
|
|
2
|
+
import type { AVPixelFormat, AVSampleFormat, AVSeekWhence } from '../constants/index.js';
|
|
2
3
|
import type { IRational } from '../lib/index.js';
|
|
4
|
+
import type { Decoder } from './decoder.js';
|
|
5
|
+
import type { Demuxer } from './demuxer.js';
|
|
6
|
+
import type { FilterAPI } from './filter.js';
|
|
3
7
|
import type { HardwareContext } from './hardware.js';
|
|
8
|
+
/**
|
|
9
|
+
* Base codec names supported across different hardware types.
|
|
10
|
+
*/
|
|
11
|
+
export type BaseCodecName = 'av1' | 'h264' | 'hevc' | 'h263' | 'mpeg2' | 'mpeg4' | 'vp8' | 'vp9' | 'mjpeg' | 'prores';
|
|
4
12
|
/**
|
|
5
13
|
* Raw video data configuration.
|
|
6
14
|
*
|
|
7
15
|
* Specifies parameters for opening raw video files like YUV.
|
|
8
16
|
*/
|
|
9
17
|
export interface VideoRawData {
|
|
10
|
-
/**
|
|
18
|
+
/**
|
|
19
|
+
* Type discriminator for TypeScript.
|
|
20
|
+
*
|
|
21
|
+
* Must be set to 'video' to identify this as video raw data.
|
|
22
|
+
*/
|
|
11
23
|
type: 'video';
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
24
|
+
/**
|
|
25
|
+
* Raw video input source.
|
|
26
|
+
*
|
|
27
|
+
* Can be a file path, Buffer containing raw video data, or custom I/O callbacks.
|
|
28
|
+
*/
|
|
29
|
+
input: string | Buffer | IOInputCallbacks;
|
|
30
|
+
/**
|
|
31
|
+
* Video frame width in pixels.
|
|
32
|
+
*
|
|
33
|
+
* Must match the actual width of the raw video data.
|
|
34
|
+
*/
|
|
15
35
|
width: number;
|
|
16
|
-
/**
|
|
36
|
+
/**
|
|
37
|
+
* Video frame height in pixels.
|
|
38
|
+
*
|
|
39
|
+
* Must match the actual height of the raw video data.
|
|
40
|
+
*/
|
|
17
41
|
height: number;
|
|
18
|
-
/**
|
|
42
|
+
/**
|
|
43
|
+
* Pixel format of the raw video data.
|
|
44
|
+
*
|
|
45
|
+
* Specifies how pixel data is stored (e.g., YUV420P, NV12, RGB24).
|
|
46
|
+
*/
|
|
19
47
|
pixelFormat: AVPixelFormat;
|
|
20
|
-
/**
|
|
48
|
+
/**
|
|
49
|
+
* Frame rate of the raw video.
|
|
50
|
+
*
|
|
51
|
+
* Specified as a rational number (numerator/denominator).
|
|
52
|
+
*/
|
|
21
53
|
frameRate: IRational;
|
|
22
54
|
}
|
|
23
55
|
/**
|
|
@@ -26,20 +58,40 @@ export interface VideoRawData {
|
|
|
26
58
|
* Specifies parameters for opening raw audio files like PCM.
|
|
27
59
|
*/
|
|
28
60
|
export interface AudioRawData {
|
|
29
|
-
/**
|
|
61
|
+
/**
|
|
62
|
+
* Type discriminator for TypeScript.
|
|
63
|
+
*
|
|
64
|
+
* Must be set to 'audio' to identify this as audio raw data.
|
|
65
|
+
*/
|
|
30
66
|
type: 'audio';
|
|
31
|
-
/**
|
|
32
|
-
|
|
33
|
-
|
|
67
|
+
/**
|
|
68
|
+
* Raw audio input source.
|
|
69
|
+
*
|
|
70
|
+
* Can be a file path, Buffer containing raw audio data, or custom I/O callbacks.
|
|
71
|
+
*/
|
|
72
|
+
input: string | Buffer | IOInputCallbacks;
|
|
73
|
+
/**
|
|
74
|
+
* Sample rate in Hz.
|
|
75
|
+
*
|
|
76
|
+
* Number of audio samples per second (e.g., 44100, 48000).
|
|
77
|
+
*/
|
|
34
78
|
sampleRate: number;
|
|
35
|
-
/**
|
|
79
|
+
/**
|
|
80
|
+
* Number of audio channels.
|
|
81
|
+
*
|
|
82
|
+
* Typical values: 1 (mono), 2 (stereo), 6 (5.1 surround).
|
|
83
|
+
*/
|
|
36
84
|
channels: number;
|
|
37
|
-
/**
|
|
85
|
+
/**
|
|
86
|
+
* Sample format of the raw audio data.
|
|
87
|
+
*
|
|
88
|
+
* Specifies how audio samples are stored (e.g., S16, FLT, S32).
|
|
89
|
+
*/
|
|
38
90
|
sampleFormat: AVSampleFormat;
|
|
39
91
|
}
|
|
40
92
|
export type RawData = VideoRawData | AudioRawData;
|
|
41
93
|
/**
|
|
42
|
-
* Options for
|
|
94
|
+
* Options for Demuxer opening.
|
|
43
95
|
*
|
|
44
96
|
* Configures how media files are opened and packets are read.
|
|
45
97
|
* Supports format detection, buffering, and FFmpeg options.
|
|
@@ -49,10 +101,8 @@ export interface MediaInputOptions {
|
|
|
49
101
|
* Buffer size for reading/writing operations.
|
|
50
102
|
*
|
|
51
103
|
* This option allows you to specify the buffer size used for I/O operations.
|
|
52
|
-
* A larger buffer size may improve performance by reducing the number of I/O calls,
|
|
53
|
-
* while a smaller buffer size may reduce memory usage.
|
|
54
104
|
*
|
|
55
|
-
* @default
|
|
105
|
+
* @default 65536
|
|
56
106
|
*
|
|
57
107
|
*/
|
|
58
108
|
bufferSize?: number;
|
|
@@ -64,38 +114,228 @@ export interface MediaInputOptions {
|
|
|
64
114
|
*
|
|
65
115
|
*/
|
|
66
116
|
format?: string;
|
|
117
|
+
/**
|
|
118
|
+
* Skip reading stream information on open.
|
|
119
|
+
*
|
|
120
|
+
* If true, stream info (codecs, formats, etc.) will not be read during opening.
|
|
121
|
+
* This can speed up opening time for certain use cases where stream info is not needed.
|
|
122
|
+
*
|
|
123
|
+
* @default false
|
|
124
|
+
*/
|
|
125
|
+
skipStreamInfo?: boolean;
|
|
126
|
+
/**
|
|
127
|
+
* Start reading packets from the first keyframe.
|
|
128
|
+
*
|
|
129
|
+
* When enabled, all packets before the first keyframe will be skipped.
|
|
130
|
+
* Useful for seeking and trimming operations.
|
|
131
|
+
*
|
|
132
|
+
* @default false
|
|
133
|
+
*/
|
|
134
|
+
startWithKeyframe?: boolean;
|
|
135
|
+
/**
|
|
136
|
+
* DTS delta threshold in seconds.
|
|
137
|
+
*
|
|
138
|
+
* Timestamp discontinuity detection threshold for formats with AVFMT_TS_DISCONT flag.
|
|
139
|
+
* When DTS delta exceeds this value, it's considered a discontinuity.
|
|
140
|
+
*
|
|
141
|
+
* Matches FFmpeg CLI's -dts_delta_threshold option.
|
|
142
|
+
*
|
|
143
|
+
* @default 10
|
|
144
|
+
*/
|
|
145
|
+
dtsDeltaThreshold?: number;
|
|
146
|
+
/**
|
|
147
|
+
* DTS error threshold in seconds.
|
|
148
|
+
*
|
|
149
|
+
* Timestamp discontinuity detection threshold for continuous formats (without AVFMT_TS_DISCONT).
|
|
150
|
+
* When DTS delta exceeds this value, it's considered a timestamp error.
|
|
151
|
+
*
|
|
152
|
+
* Matches FFmpeg CLI's -dts_error_threshold option.
|
|
153
|
+
*
|
|
154
|
+
* @default 108000 (30 hours)
|
|
155
|
+
*/
|
|
156
|
+
dtsErrorThreshold?: number;
|
|
157
|
+
/**
|
|
158
|
+
* Copy timestamps from input to output.
|
|
159
|
+
*
|
|
160
|
+
* When enabled, timestamps are passed through without modification.
|
|
161
|
+
* This disables most timestamp discontinuity corrections except for
|
|
162
|
+
* PTS wrap-around detection in discontinuous formats.
|
|
163
|
+
*
|
|
164
|
+
* Matches FFmpeg CLI's -copyts option.
|
|
165
|
+
*
|
|
166
|
+
* @default false
|
|
167
|
+
*/
|
|
168
|
+
copyTs?: boolean;
|
|
67
169
|
/**
|
|
68
170
|
* FFmpeg format options passed directly to the input.
|
|
171
|
+
*
|
|
172
|
+
* Key-value pairs of FFmpeg AVFormatContext options.
|
|
173
|
+
* These are passed directly to avformat_open_input().
|
|
69
174
|
*/
|
|
70
175
|
options?: Record<string, string | number | boolean | undefined | null>;
|
|
71
176
|
}
|
|
72
177
|
/**
|
|
73
|
-
* Options for
|
|
178
|
+
* Options for Muxer creation.
|
|
74
179
|
*
|
|
75
180
|
* Configures output container format and buffering.
|
|
76
181
|
*/
|
|
77
182
|
export interface MediaOutputOptions {
|
|
183
|
+
/**
|
|
184
|
+
* Input media for automatic metadata and property copying.
|
|
185
|
+
*
|
|
186
|
+
* When provided, Muxer will automatically copy:
|
|
187
|
+
* - Container-level metadata (title, artist, etc.)
|
|
188
|
+
* - Stream-level metadata
|
|
189
|
+
* - Disposition flags (DEFAULT, FORCED, etc.)
|
|
190
|
+
* - Duration hints for encoding
|
|
191
|
+
*
|
|
192
|
+
* This matches FFmpeg CLI behavior which copies metadata by default.
|
|
193
|
+
*/
|
|
194
|
+
input?: Demuxer | RTPMediaInput;
|
|
78
195
|
/**
|
|
79
196
|
* Preferred output format.
|
|
80
197
|
*
|
|
81
198
|
* If not specified, format is guessed from file extension.
|
|
82
199
|
* Use this to override automatic format detection.
|
|
83
200
|
*
|
|
201
|
+
* Matches FFmpeg CLI's -f option.
|
|
84
202
|
*/
|
|
85
203
|
format?: string;
|
|
86
204
|
/**
|
|
87
205
|
* Buffer size for I/O operations.
|
|
88
206
|
*
|
|
89
207
|
* This option controls the size of the internal buffer used for
|
|
90
|
-
* reading and writing data.
|
|
91
|
-
* by reducing the number of I/O operations, but will also increase
|
|
92
|
-
* memory usage.
|
|
208
|
+
* reading and writing data.
|
|
93
209
|
*
|
|
94
|
-
* @default
|
|
210
|
+
* @default 32768 (32 KB, matches FFmpeg CLI default)
|
|
95
211
|
*/
|
|
96
212
|
bufferSize?: number;
|
|
213
|
+
/**
|
|
214
|
+
* Maximum packet size for I/O operations.
|
|
215
|
+
*
|
|
216
|
+
* This option controls the maximum size of individual packets
|
|
217
|
+
* for protocols that require specific packet sizes (e.g., RTP with MTU constraints).
|
|
218
|
+
*
|
|
219
|
+
* Matches FFmpeg's max_packet_size in AVIOContext.
|
|
220
|
+
*
|
|
221
|
+
* @default 1200
|
|
222
|
+
*/
|
|
223
|
+
maxPacketSize?: number;
|
|
224
|
+
/**
|
|
225
|
+
* Exit immediately on first write error.
|
|
226
|
+
*
|
|
227
|
+
* When enabled, the muxer will terminate on the first write error.
|
|
228
|
+
* When disabled, errors are logged but processing continues.
|
|
229
|
+
*
|
|
230
|
+
* @default true
|
|
231
|
+
*/
|
|
232
|
+
exitOnError?: boolean;
|
|
233
|
+
/**
|
|
234
|
+
* Maximum number of packets to buffer per stream in the sync queue.
|
|
235
|
+
*
|
|
236
|
+
* Matches FFmpeg CLI's -max_muxing_queue_size option.
|
|
237
|
+
* Limits memory usage when encoders are still initializing.
|
|
238
|
+
* Takes effect after muxingQueueDataThreshold is reached.
|
|
239
|
+
* If exceeded, an error is thrown.
|
|
240
|
+
*
|
|
241
|
+
* @default 128 (same as FFmpeg CLI)
|
|
242
|
+
*/
|
|
243
|
+
maxMuxingQueueSize?: number;
|
|
244
|
+
/**
|
|
245
|
+
* Threshold in bytes after which maxMuxingQueueSize takes effect.
|
|
246
|
+
*
|
|
247
|
+
* Matches FFmpeg CLI's -muxing_queue_data_threshold option.
|
|
248
|
+
* Once this threshold is reached, maxMuxingQueueSize limit applies.
|
|
249
|
+
* This is an intelligent system: small streams (audio) can buffer many packets,
|
|
250
|
+
* large streams (video) are limited by packet count.
|
|
251
|
+
*
|
|
252
|
+
* @default 52428800 (50 MB, same as FFmpeg CLI)
|
|
253
|
+
*/
|
|
254
|
+
muxingQueueDataThreshold?: number;
|
|
255
|
+
/**
|
|
256
|
+
* Maximum buffering duration in seconds for sync queue interleaving.
|
|
257
|
+
*
|
|
258
|
+
* Matches FFmpeg CLI's -shortest_buf_duration option.
|
|
259
|
+
* Controls how much buffering is allowed in the native sync queue
|
|
260
|
+
* for packet interleaving across multiple streams.
|
|
261
|
+
*
|
|
262
|
+
* @default 10 (same as FFmpeg CLI)
|
|
263
|
+
*/
|
|
264
|
+
syncQueueBufferDuration?: number;
|
|
265
|
+
/**
|
|
266
|
+
* Start time offset in seconds for output timestamps.
|
|
267
|
+
*
|
|
268
|
+
* Matches FFmpeg CLI's -ss (output) option.
|
|
269
|
+
* Subtracts this offset from all packet timestamps.
|
|
270
|
+
* Use for trimming from start of stream.
|
|
271
|
+
*
|
|
272
|
+
* @default AV_NOPTS_VALUE (no offset)
|
|
273
|
+
*/
|
|
274
|
+
startTime?: number;
|
|
275
|
+
/**
|
|
276
|
+
* Whether to copy initial non-keyframe packets in streamcopy mode.
|
|
277
|
+
*
|
|
278
|
+
* Matches FFmpeg CLI's -copyinkf option.
|
|
279
|
+
* If false (default), packets before first keyframe are skipped.
|
|
280
|
+
* If true, all packets from start are copied.
|
|
281
|
+
*
|
|
282
|
+
* @default false
|
|
283
|
+
*/
|
|
284
|
+
copyInitialNonkeyframes?: boolean;
|
|
285
|
+
/**
|
|
286
|
+
* Copy or discard frames before start time.
|
|
287
|
+
*
|
|
288
|
+
* Matches FFmpeg CLI's -copypriorss option.
|
|
289
|
+
* Controls whether packets before the start time are copied:
|
|
290
|
+
* - -1 (default): Use FFmpeg's internal ts_copy_start calculation
|
|
291
|
+
* - 0: Discard packets before start time
|
|
292
|
+
* - 1: Copy all packets regardless of start time
|
|
293
|
+
*
|
|
294
|
+
* @default -1
|
|
295
|
+
*/
|
|
296
|
+
copyPriorStart?: number;
|
|
297
|
+
/**
|
|
298
|
+
* Use synchronous packet queue for interleaving.
|
|
299
|
+
*
|
|
300
|
+
* When true and there are stream copy streams present, enables FFmpeg's
|
|
301
|
+
* sync queue for proper interleaving of packets based on timestamps.
|
|
302
|
+
*
|
|
303
|
+
* The sync queue is only activated when both conditions are met:
|
|
304
|
+
* - `useSyncQueue` is `true`
|
|
305
|
+
* - Output contains at least one stream copy stream
|
|
306
|
+
*
|
|
307
|
+
* This includes scenarios with:
|
|
308
|
+
* - Only stream copy streams (e.g., 1 streamcopy stream)
|
|
309
|
+
* - Mixed streams (e.g., 1 streamcopy + 1 encoded stream)
|
|
310
|
+
*
|
|
311
|
+
* For outputs with only encoded streams, the sync queue is not used.
|
|
312
|
+
*
|
|
313
|
+
* @default true
|
|
314
|
+
*/
|
|
315
|
+
useSyncQueue?: boolean;
|
|
316
|
+
/**
|
|
317
|
+
* Use asynchronous write queue to prevent race conditions.
|
|
318
|
+
*
|
|
319
|
+
* When true and there are multiple streams (> 1), all write operations
|
|
320
|
+
* are serialized through an async queue, preventing concurrent access
|
|
321
|
+
* to AVFormatContext which can cause "Packet duration out of range"
|
|
322
|
+
* errors with parallel encoding.
|
|
323
|
+
*
|
|
324
|
+
* The async queue is only activated when both conditions are met:
|
|
325
|
+
* - `useAsyncWrite` is `true`
|
|
326
|
+
* - Output has more than one stream
|
|
327
|
+
*
|
|
328
|
+
* For single-stream outputs, writes are performed directly without
|
|
329
|
+
* queuing, regardless of this setting.
|
|
330
|
+
*
|
|
331
|
+
* @default true
|
|
332
|
+
*/
|
|
333
|
+
useAsyncWrite?: boolean;
|
|
97
334
|
/**
|
|
98
335
|
* FFmpeg format options passed directly to the output.
|
|
336
|
+
*
|
|
337
|
+
* Key-value pairs of FFmpeg AVFormatContext options.
|
|
338
|
+
* These are passed directly to avformat_write_header().
|
|
99
339
|
*/
|
|
100
340
|
options?: Record<string, string | number | boolean | bigint | undefined | null>;
|
|
101
341
|
}
|
|
@@ -106,17 +346,67 @@ export interface MediaOutputOptions {
|
|
|
106
346
|
* Supports hardware acceleration and threading configuration.
|
|
107
347
|
*/
|
|
108
348
|
export interface DecoderOptions {
|
|
109
|
-
/**
|
|
110
|
-
|
|
111
|
-
|
|
349
|
+
/**
|
|
350
|
+
* Exit immediately on first decode error.
|
|
351
|
+
*
|
|
352
|
+
* When enabled, the decoder will terminate on the first decode error.
|
|
353
|
+
* When disabled, errors are logged but decoding continues with next packet.
|
|
354
|
+
*
|
|
355
|
+
* @default true
|
|
356
|
+
*/
|
|
112
357
|
exitOnError?: boolean;
|
|
113
|
-
/**
|
|
358
|
+
/**
|
|
359
|
+
* Hardware acceleration context.
|
|
360
|
+
*
|
|
361
|
+
* Pass a HardwareContext instance to enable hardware-accelerated decoding.
|
|
362
|
+
* Set to null to disable hardware acceleration.
|
|
363
|
+
*/
|
|
114
364
|
hardware?: HardwareContext | null;
|
|
115
365
|
/**
|
|
116
|
-
* Number of extra hardware frames to allocate.
|
|
366
|
+
* Number of extra hardware frames to allocate.
|
|
367
|
+
*
|
|
368
|
+
* Useful for hardware decoders requiring additional frame buffering.
|
|
369
|
+
* Some hardware decoders need extra frames for reference or look-ahead.
|
|
117
370
|
*/
|
|
118
371
|
extraHWFrames?: number;
|
|
119
|
-
/**
|
|
372
|
+
/**
|
|
373
|
+
* Hardware frame output format.
|
|
374
|
+
*
|
|
375
|
+
* When set, hardware frames will be automatically transferred to this software pixel format.
|
|
376
|
+
* Useful when you need software frames for further processing but want to use hardware decoding.
|
|
377
|
+
*/
|
|
378
|
+
hwaccelOutputFormat?: AVPixelFormat;
|
|
379
|
+
/**
|
|
380
|
+
* Force constant framerate mode.
|
|
381
|
+
*
|
|
382
|
+
* When set, ignores all timestamps and generates frames at a constant rate.
|
|
383
|
+
* Sets frame PTS to AV_NOPTS_VALUE, duration to 1, and time_base to 1/framerate.
|
|
384
|
+
* Matches FFmpeg CLI's DECODER_FLAG_FRAMERATE_FORCED behavior.
|
|
385
|
+
*/
|
|
386
|
+
forcedFramerate?: IRational;
|
|
387
|
+
/**
|
|
388
|
+
* Override sample aspect ratio.
|
|
389
|
+
*
|
|
390
|
+
* When set, overrides the frame's sample_aspect_ratio with this value.
|
|
391
|
+
* Useful for fixing incorrect SAR in source material.
|
|
392
|
+
*/
|
|
393
|
+
sarOverride?: IRational;
|
|
394
|
+
/**
|
|
395
|
+
* Apply cropping from frame metadata.
|
|
396
|
+
*
|
|
397
|
+
* When true, automatically crops frames based on their crop metadata.
|
|
398
|
+
* Uses av_frame_apply_cropping() with AV_FRAME_CROP_UNALIGNED flag.
|
|
399
|
+
* Useful for streams with letterboxing/pillarboxing metadata.
|
|
400
|
+
*
|
|
401
|
+
* @default false
|
|
402
|
+
*/
|
|
403
|
+
applyCropping?: boolean;
|
|
404
|
+
/**
|
|
405
|
+
* Additional codec-specific options.
|
|
406
|
+
*
|
|
407
|
+
* Key-value pairs of FFmpeg AVCodecContext options.
|
|
408
|
+
* These are passed directly to the decoder.
|
|
409
|
+
*/
|
|
120
410
|
options?: Record<string, string | number | boolean | undefined | null>;
|
|
121
411
|
}
|
|
122
412
|
/**
|
|
@@ -126,25 +416,70 @@ export interface DecoderOptions {
|
|
|
126
416
|
* Stream parameters (width, height, format, etc.) are taken from the provided stream.
|
|
127
417
|
*/
|
|
128
418
|
export interface EncoderOptions {
|
|
129
|
-
/**
|
|
419
|
+
/**
|
|
420
|
+
* Target bitrate.
|
|
421
|
+
*
|
|
422
|
+
* Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
|
|
423
|
+
* Used for rate control in video and audio encoding.
|
|
424
|
+
*
|
|
425
|
+
* @default 128k for audio, 1M for video
|
|
426
|
+
*/
|
|
130
427
|
bitrate?: number | bigint | string;
|
|
131
|
-
/**
|
|
428
|
+
/**
|
|
429
|
+
* Minimum bitrate for rate control.
|
|
430
|
+
*
|
|
431
|
+
* Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
|
|
432
|
+
* Used with variable bitrate encoding to enforce quality floor.
|
|
433
|
+
*/
|
|
132
434
|
minRate?: number | bigint | string;
|
|
133
|
-
/**
|
|
435
|
+
/**
|
|
436
|
+
* Maximum bitrate for rate control.
|
|
437
|
+
*
|
|
438
|
+
* Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
|
|
439
|
+
* Used with variable bitrate encoding to enforce bitrate ceiling.
|
|
440
|
+
*/
|
|
134
441
|
maxRate?: number | bigint | string;
|
|
135
|
-
/**
|
|
442
|
+
/**
|
|
443
|
+
* Rate control buffer size.
|
|
444
|
+
*
|
|
445
|
+
* Can be specified as number, bigint, or string with suffix (e.g., '5M', '128k').
|
|
446
|
+
* Determines the decoder buffer model size for rate control.
|
|
447
|
+
*/
|
|
136
448
|
bufSize?: number | bigint | string;
|
|
137
|
-
/**
|
|
449
|
+
/**
|
|
450
|
+
* Group of Pictures (GOP) size.
|
|
451
|
+
*
|
|
452
|
+
* Number of frames between keyframes.
|
|
453
|
+
* Larger GOP improves compression but reduces seekability.
|
|
454
|
+
*/
|
|
138
455
|
gopSize?: number;
|
|
139
|
-
/**
|
|
456
|
+
/**
|
|
457
|
+
* Maximum number of consecutive B-frames.
|
|
458
|
+
*
|
|
459
|
+
* B-frames improve compression but increase encoding complexity.
|
|
460
|
+
* Maximum B-frames allowed between I or P frames.
|
|
461
|
+
*/
|
|
140
462
|
maxBFrames?: number;
|
|
141
|
-
/**
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
463
|
+
/**
|
|
464
|
+
* Optional decoder reference for metadata extraction.
|
|
465
|
+
*
|
|
466
|
+
* Used to extract bits_per_raw_sample and other decoder-specific properties.
|
|
467
|
+
* Helps maintain quality during transcoding.
|
|
468
|
+
*/
|
|
469
|
+
decoder?: Decoder;
|
|
470
|
+
/**
|
|
471
|
+
* Optional filter reference for metadata extraction.
|
|
472
|
+
*
|
|
473
|
+
* Used to extract filter output parameters.
|
|
474
|
+
* Ensures encoder matches filter output characteristics.
|
|
475
|
+
*/
|
|
476
|
+
filter?: FilterAPI;
|
|
477
|
+
/**
|
|
478
|
+
* Additional codec-specific options.
|
|
479
|
+
*
|
|
480
|
+
* Key-value pairs of FFmpeg AVCodecContext options.
|
|
481
|
+
* These are passed directly to the encoder.
|
|
482
|
+
*/
|
|
148
483
|
options?: Record<string, string | number | boolean | undefined | null>;
|
|
149
484
|
}
|
|
150
485
|
/**
|
|
@@ -153,24 +488,86 @@ export interface EncoderOptions {
|
|
|
153
488
|
export interface FilterOptions {
|
|
154
489
|
/**
|
|
155
490
|
* Number of threads for parallel processing.
|
|
156
|
-
*
|
|
491
|
+
*
|
|
492
|
+
* Controls the number of threads used for filter processing.
|
|
493
|
+
* Set to 0 to auto-detect based on CPU cores.
|
|
494
|
+
*
|
|
495
|
+
* @default 0 (auto-detect)
|
|
157
496
|
*/
|
|
158
497
|
threads?: number;
|
|
159
498
|
/**
|
|
160
|
-
* Software scaler options
|
|
161
|
-
*
|
|
499
|
+
* Software scaler options for video filters.
|
|
500
|
+
*
|
|
501
|
+
* Options passed to libswscale when scaling video within filters.
|
|
502
|
+
* Maps to AVFilterGraph->scale_sws_opts.
|
|
162
503
|
*/
|
|
163
504
|
scaleSwsOpts?: string;
|
|
164
|
-
/**
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
505
|
+
/**
|
|
506
|
+
* Audio resampler options for audio filters.
|
|
507
|
+
*
|
|
508
|
+
* Options passed to libswresample when resampling audio within filters.
|
|
509
|
+
* Maps to AVFilterGraph->aresample_swr_opts.
|
|
510
|
+
*/
|
|
511
|
+
audioResampleOpts?: string;
|
|
512
|
+
/**
|
|
513
|
+
* Hardware acceleration context.
|
|
514
|
+
*
|
|
515
|
+
* Pass a HardwareContext instance to enable hardware-accelerated filtering.
|
|
516
|
+
* Set to null to disable hardware acceleration.
|
|
517
|
+
*/
|
|
169
518
|
hardware?: HardwareContext | null;
|
|
170
519
|
/**
|
|
171
520
|
* Number of extra hardware frames to allocate.
|
|
521
|
+
*
|
|
522
|
+
* Useful for hardware filters requiring additional frame buffering.
|
|
523
|
+
* Some hardware filters need extra frames for look-ahead or reference.
|
|
172
524
|
*/
|
|
173
525
|
extraHWFrames?: number;
|
|
526
|
+
/**
|
|
527
|
+
* Force constant framerate mode (CFR).
|
|
528
|
+
*
|
|
529
|
+
* When true, timeBase is automatically set to 1/framerate (like FFmpeg CLI -fps_mode cfr).
|
|
530
|
+
* When false (default), timeBase is taken from frame.timeBase (VFR mode).
|
|
531
|
+
*
|
|
532
|
+
* Maps to FFmpeg's IFILTER_FLAG_CFR.
|
|
533
|
+
* Requires `framerate` to be set when enabled.
|
|
534
|
+
*
|
|
535
|
+
* @default false (VFR mode)
|
|
536
|
+
*/
|
|
537
|
+
cfr?: boolean;
|
|
538
|
+
/**
|
|
539
|
+
* Framerate for CFR mode or as hint for buffer source.
|
|
540
|
+
*
|
|
541
|
+
* Required when `cfr=true` to calculate timeBase = 1/framerate.
|
|
542
|
+
* Also passed to AVBufferSrcParameters->frame_rate.
|
|
543
|
+
*
|
|
544
|
+
* Maps to FFmpeg's InputFilterOptions->framerate.
|
|
545
|
+
*/
|
|
546
|
+
framerate?: IRational;
|
|
547
|
+
/**
|
|
548
|
+
* Drop frames on format/parameter changes instead of reinitializing filtergraph.
|
|
549
|
+
*
|
|
550
|
+
* When true, frames with changed properties (resolution, format, etc.) are dropped
|
|
551
|
+
* instead of triggering filtergraph reinitialization. Useful for live streams
|
|
552
|
+
* with unstable properties.
|
|
553
|
+
*
|
|
554
|
+
* Maps to FFmpeg's IFILTER_FLAG_DROPCHANGED.
|
|
555
|
+
*
|
|
556
|
+
* @default false
|
|
557
|
+
*/
|
|
558
|
+
dropOnChange?: boolean;
|
|
559
|
+
/**
|
|
560
|
+
* Allow filtergraph reinitialization when frame parameters change.
|
|
561
|
+
*
|
|
562
|
+
* When false, parameter changes (resolution, format) will cause errors
|
|
563
|
+
* instead of reinitializing the filtergraph.
|
|
564
|
+
* When true (default), filtergraph is reinitialized on parameter changes.
|
|
565
|
+
*
|
|
566
|
+
* Maps to FFmpeg's IFILTER_FLAG_REINIT.
|
|
567
|
+
*
|
|
568
|
+
* @default true
|
|
569
|
+
*/
|
|
570
|
+
allowReinit?: boolean;
|
|
174
571
|
}
|
|
175
572
|
/**
|
|
176
573
|
* Hardware acceleration configuration options.
|
|
@@ -220,7 +617,7 @@ export interface IOInputCallbacks {
|
|
|
220
617
|
* Custom I/O callbacks for implementing custom output targets.
|
|
221
618
|
*
|
|
222
619
|
* Defines callback functions for custom write operations with FFmpeg.
|
|
223
|
-
* Used internally by
|
|
620
|
+
* Used internally by Muxer for custom output protocols.
|
|
224
621
|
*
|
|
225
622
|
*/
|
|
226
623
|
export interface IOOutputCallbacks {
|
|
@@ -251,7 +648,31 @@ export interface IOOutputCallbacks {
|
|
|
251
648
|
*/
|
|
252
649
|
read?: (size: number) => Buffer | null | number;
|
|
253
650
|
}
|
|
254
|
-
|
|
255
|
-
|
|
256
|
-
|
|
257
|
-
|
|
651
|
+
export interface RTPMediaInput {
|
|
652
|
+
/**
|
|
653
|
+
* Demuxer configured for RTP/SRTP reception.
|
|
654
|
+
*
|
|
655
|
+
* Receives RTP packets via localhost UDP and feeds them to FFmpeg for decoding.
|
|
656
|
+
*/
|
|
657
|
+
input: Demuxer;
|
|
658
|
+
/**
|
|
659
|
+
* Send RTP packet to FFmpeg for decoding.
|
|
660
|
+
*
|
|
661
|
+
* @param rtpPacket - RTP packet as Buffer or RtpPacket object
|
|
662
|
+
*
|
|
663
|
+
* @param streamIndex - Optional stream index for multiplexed RTP
|
|
664
|
+
*/
|
|
665
|
+
sendPacket: (rtpPacket: Buffer | RtpPacket, streamIndex?: number) => void;
|
|
666
|
+
/**
|
|
667
|
+
* Cleanup function.
|
|
668
|
+
*
|
|
669
|
+
* Closes the demuxer and UDP socket asynchronously.
|
|
670
|
+
*/
|
|
671
|
+
close: () => Promise<void>;
|
|
672
|
+
/**
|
|
673
|
+
* Synchronous cleanup function.
|
|
674
|
+
*
|
|
675
|
+
* Closes the demuxer and UDP socket synchronously.
|
|
676
|
+
*/
|
|
677
|
+
closeSync: () => void;
|
|
678
|
+
}
|