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