node-av-light 0.0.0-stage → 7.1.0-beta.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (311) hide show
  1. package/LICENSE.md +22 -0
  2. package/README.md +710 -2
  3. package/dist/api/audio-frame-buffer.d.ts +636 -0
  4. package/dist/api/audio-frame-buffer.js +1027 -0
  5. package/dist/api/audio-frame-buffer.js.map +1 -0
  6. package/dist/api/bitstream-filter.d.ts +938 -0
  7. package/dist/api/bitstream-filter.js +1427 -0
  8. package/dist/api/bitstream-filter.js.map +1 -0
  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_h264.h264 +0 -0
  14. package/dist/api/data/test_hevc.h265 +0 -0
  15. package/dist/api/data/test_mjpeg.mjpeg +0 -0
  16. package/dist/api/data/test_vp8.ivf +0 -0
  17. package/dist/api/data/test_vp9.ivf +0 -0
  18. package/dist/api/decoder.d.ts +1413 -0
  19. package/dist/api/decoder.js +2367 -0
  20. package/dist/api/decoder.js.map +1 -0
  21. package/dist/api/demuxer.d.ts +1295 -0
  22. package/dist/api/demuxer.js +2344 -0
  23. package/dist/api/demuxer.js.map +1 -0
  24. package/dist/api/device.d.ts +589 -0
  25. package/dist/api/device.js +964 -0
  26. package/dist/api/device.js.map +1 -0
  27. package/dist/api/encoder-pool.d.ts +262 -0
  28. package/dist/api/encoder-pool.js +397 -0
  29. package/dist/api/encoder-pool.js.map +1 -0
  30. package/dist/api/encoder.d.ts +1509 -0
  31. package/dist/api/encoder.js +2619 -0
  32. package/dist/api/encoder.js.map +1 -0
  33. package/dist/api/filter-complex.d.ts +828 -0
  34. package/dist/api/filter-complex.js +1661 -0
  35. package/dist/api/filter-complex.js.map +1 -0
  36. package/dist/api/filter-presets.d.ts +800 -0
  37. package/dist/api/filter-presets.js +1554 -0
  38. package/dist/api/filter-presets.js.map +1 -0
  39. package/dist/api/filter.d.ts +1339 -0
  40. package/dist/api/filter.js +2075 -0
  41. package/dist/api/filter.js.map +1 -0
  42. package/dist/api/fmp4-stream.d.ts +797 -0
  43. package/dist/api/fmp4-stream.js +1428 -0
  44. package/dist/api/fmp4-stream.js.map +1 -0
  45. package/dist/api/hardware.d.ts +677 -0
  46. package/dist/api/hardware.js +1300 -0
  47. package/dist/api/hardware.js.map +1 -0
  48. package/dist/api/index.d.ts +21 -0
  49. package/dist/api/index.js +38 -0
  50. package/dist/api/index.js.map +1 -0
  51. package/dist/api/io-stream.d.ts +308 -0
  52. package/dist/api/io-stream.js +358 -0
  53. package/dist/api/io-stream.js.map +1 -0
  54. package/dist/api/muxer.d.ts +1311 -0
  55. package/dist/api/muxer.js +2672 -0
  56. package/dist/api/muxer.js.map +1 -0
  57. package/dist/api/pipeline.d.ts +801 -0
  58. package/dist/api/pipeline.js +1344 -0
  59. package/dist/api/pipeline.js.map +1 -0
  60. package/dist/api/probe.d.ts +128 -0
  61. package/dist/api/probe.js +227 -0
  62. package/dist/api/probe.js.map +1 -0
  63. package/dist/api/rtp-stream.d.ts +497 -0
  64. package/dist/api/rtp-stream.js +1131 -0
  65. package/dist/api/rtp-stream.js.map +1 -0
  66. package/dist/api/scaler.d.ts +561 -0
  67. package/dist/api/scaler.js +918 -0
  68. package/dist/api/scaler.js.map +1 -0
  69. package/dist/api/types.d.ts +17 -0
  70. package/dist/api/types.js +2 -0
  71. package/dist/api/types.js.map +1 -0
  72. package/dist/api/utilities/async-queue.d.ts +149 -0
  73. package/dist/api/utilities/async-queue.js +254 -0
  74. package/dist/api/utilities/async-queue.js.map +1 -0
  75. package/dist/api/utilities/audio-sample.d.ts +117 -0
  76. package/dist/api/utilities/audio-sample.js +112 -0
  77. package/dist/api/utilities/audio-sample.js.map +1 -0
  78. package/dist/api/utilities/audio-transcode.d.ts +20 -0
  79. package/dist/api/utilities/audio-transcode.js +27 -0
  80. package/dist/api/utilities/audio-transcode.js.map +1 -0
  81. package/dist/api/utilities/channel-layout.d.ts +76 -0
  82. package/dist/api/utilities/channel-layout.js +80 -0
  83. package/dist/api/utilities/channel-layout.js.map +1 -0
  84. package/dist/api/utilities/codec-format.d.ts +87 -0
  85. package/dist/api/utilities/codec-format.js +117 -0
  86. package/dist/api/utilities/codec-format.js.map +1 -0
  87. package/dist/api/utilities/context-options.d.ts +25 -0
  88. package/dist/api/utilities/context-options.js +23 -0
  89. package/dist/api/utilities/context-options.js.map +1 -0
  90. package/dist/api/utilities/electron-shared-texture.d.ts +368 -0
  91. package/dist/api/utilities/electron-shared-texture.js +540 -0
  92. package/dist/api/utilities/electron-shared-texture.js.map +1 -0
  93. package/dist/api/utilities/image.d.ts +207 -0
  94. package/dist/api/utilities/image.js +213 -0
  95. package/dist/api/utilities/image.js.map +1 -0
  96. package/dist/api/utilities/index.d.ts +14 -0
  97. package/dist/api/utilities/index.js +27 -0
  98. package/dist/api/utilities/index.js.map +1 -0
  99. package/dist/api/utilities/live-decoding.d.ts +15 -0
  100. package/dist/api/utilities/live-decoding.js +32 -0
  101. package/dist/api/utilities/live-decoding.js.map +1 -0
  102. package/dist/api/utilities/media-type.d.ts +49 -0
  103. package/dist/api/utilities/media-type.js +53 -0
  104. package/dist/api/utilities/media-type.js.map +1 -0
  105. package/dist/api/utilities/packet-age-watchdog.d.ts +198 -0
  106. package/dist/api/utilities/packet-age-watchdog.js +594 -0
  107. package/dist/api/utilities/packet-age-watchdog.js.map +1 -0
  108. package/dist/api/utilities/pixel-format.d.ts +89 -0
  109. package/dist/api/utilities/pixel-format.js +97 -0
  110. package/dist/api/utilities/pixel-format.js.map +1 -0
  111. package/dist/api/utilities/sample-format.d.ts +129 -0
  112. package/dist/api/utilities/sample-format.js +141 -0
  113. package/dist/api/utilities/sample-format.js.map +1 -0
  114. package/dist/api/utilities/scale-size.d.ts +51 -0
  115. package/dist/api/utilities/scale-size.js +55 -0
  116. package/dist/api/utilities/scale-size.js.map +1 -0
  117. package/dist/api/utilities/scheduler.d.ts +138 -0
  118. package/dist/api/utilities/scheduler.js +98 -0
  119. package/dist/api/utilities/scheduler.js.map +1 -0
  120. package/dist/api/utilities/streaming.d.ts +186 -0
  121. package/dist/api/utilities/streaming.js +309 -0
  122. package/dist/api/utilities/streaming.js.map +1 -0
  123. package/dist/api/utilities/timestamp.d.ts +193 -0
  124. package/dist/api/utilities/timestamp.js +206 -0
  125. package/dist/api/utilities/timestamp.js.map +1 -0
  126. package/dist/api/utilities/video-transcode.d.ts +218 -0
  127. package/dist/api/utilities/video-transcode.js +624 -0
  128. package/dist/api/utilities/video-transcode.js.map +1 -0
  129. package/dist/api/utilities/whisper-model.d.ts +330 -0
  130. package/dist/api/utilities/whisper-model.js +587 -0
  131. package/dist/api/utilities/whisper-model.js.map +1 -0
  132. package/dist/api/utils.d.ts +19 -0
  133. package/dist/api/utils.js +39 -0
  134. package/dist/api/utils.js.map +1 -0
  135. package/dist/api/webrtc-stream.d.ts +294 -0
  136. package/dist/api/webrtc-stream.js +546 -0
  137. package/dist/api/webrtc-stream.js.map +1 -0
  138. package/dist/api/whisper.d.ts +326 -0
  139. package/dist/api/whisper.js +402 -0
  140. package/dist/api/whisper.js.map +1 -0
  141. package/dist/constants/bsf-options.d.ts +364 -0
  142. package/dist/constants/bsf-options.js +7 -0
  143. package/dist/constants/bsf-options.js.map +1 -0
  144. package/dist/constants/channel-layouts.d.ts +53 -0
  145. package/dist/constants/channel-layouts.js +57 -0
  146. package/dist/constants/channel-layouts.js.map +1 -0
  147. package/dist/constants/constants.d.ts +2435 -0
  148. package/dist/constants/constants.js +1989 -0
  149. package/dist/constants/constants.js.map +1 -0
  150. package/dist/constants/decoders.d.ts +651 -0
  151. package/dist/constants/decoders.js +641 -0
  152. package/dist/constants/decoders.js.map +1 -0
  153. package/dist/constants/encoders.d.ts +314 -0
  154. package/dist/constants/encoders.js +309 -0
  155. package/dist/constants/encoders.js.map +1 -0
  156. package/dist/constants/filter-options.d.ts +12099 -0
  157. package/dist/constants/filter-options.js +7 -0
  158. package/dist/constants/filter-options.js.map +1 -0
  159. package/dist/constants/format-options.d.ts +4319 -0
  160. package/dist/constants/format-options.js +7 -0
  161. package/dist/constants/format-options.js.map +1 -0
  162. package/dist/constants/formats.d.ts +18 -0
  163. package/dist/constants/formats.js +7 -0
  164. package/dist/constants/formats.js.map +1 -0
  165. package/dist/constants/hardware.d.ts +26 -0
  166. package/dist/constants/hardware.js +27 -0
  167. package/dist/constants/hardware.js.map +1 -0
  168. package/dist/constants/index.d.ts +10 -0
  169. package/dist/constants/index.js +6 -0
  170. package/dist/constants/index.js.map +1 -0
  171. package/dist/constants/options.d.ts +6217 -0
  172. package/dist/constants/options.js +7 -0
  173. package/dist/constants/options.js.map +1 -0
  174. package/dist/ffmpeg/index.d.ts +101 -0
  175. package/dist/ffmpeg/index.js +161 -0
  176. package/dist/ffmpeg/index.js.map +1 -0
  177. package/dist/ffmpeg/version.d.ts +6 -0
  178. package/dist/ffmpeg/version.js +7 -0
  179. package/dist/ffmpeg/version.js.map +1 -0
  180. package/dist/index.d.ts +4 -0
  181. package/dist/index.js +9 -0
  182. package/dist/index.js.map +1 -0
  183. package/dist/lib/audio-fifo.d.ts +399 -0
  184. package/dist/lib/audio-fifo.js +431 -0
  185. package/dist/lib/audio-fifo.js.map +1 -0
  186. package/dist/lib/binding.d.ts +242 -0
  187. package/dist/lib/binding.js +102 -0
  188. package/dist/lib/binding.js.map +1 -0
  189. package/dist/lib/bitstream-filter-context.d.ts +381 -0
  190. package/dist/lib/bitstream-filter-context.js +443 -0
  191. package/dist/lib/bitstream-filter-context.js.map +1 -0
  192. package/dist/lib/bitstream-filter.d.ts +140 -0
  193. package/dist/lib/bitstream-filter.js +154 -0
  194. package/dist/lib/bitstream-filter.js.map +1 -0
  195. package/dist/lib/codec-context.d.ts +1069 -0
  196. package/dist/lib/codec-context.js +1336 -0
  197. package/dist/lib/codec-context.js.map +1 -0
  198. package/dist/lib/codec-parameters.d.ts +664 -0
  199. package/dist/lib/codec-parameters.js +813 -0
  200. package/dist/lib/codec-parameters.js.map +1 -0
  201. package/dist/lib/codec-parser.d.ts +201 -0
  202. package/dist/lib/codec-parser.js +213 -0
  203. package/dist/lib/codec-parser.js.map +1 -0
  204. package/dist/lib/codec.d.ts +617 -0
  205. package/dist/lib/codec.js +746 -0
  206. package/dist/lib/codec.js.map +1 -0
  207. package/dist/lib/device.d.ts +294 -0
  208. package/dist/lib/device.js +326 -0
  209. package/dist/lib/device.js.map +1 -0
  210. package/dist/lib/dictionary.d.ts +333 -0
  211. package/dist/lib/dictionary.js +372 -0
  212. package/dist/lib/dictionary.js.map +1 -0
  213. package/dist/lib/error.d.ts +311 -0
  214. package/dist/lib/error.js +395 -0
  215. package/dist/lib/error.js.map +1 -0
  216. package/dist/lib/fifo.d.ts +416 -0
  217. package/dist/lib/fifo.js +453 -0
  218. package/dist/lib/fifo.js.map +1 -0
  219. package/dist/lib/filter-context.d.ts +714 -0
  220. package/dist/lib/filter-context.js +783 -0
  221. package/dist/lib/filter-context.js.map +1 -0
  222. package/dist/lib/filter-graph-segment.d.ts +161 -0
  223. package/dist/lib/filter-graph-segment.js +172 -0
  224. package/dist/lib/filter-graph-segment.js.map +1 -0
  225. package/dist/lib/filter-graph.d.ts +641 -0
  226. package/dist/lib/filter-graph.js +704 -0
  227. package/dist/lib/filter-graph.js.map +1 -0
  228. package/dist/lib/filter-inout.d.ts +202 -0
  229. package/dist/lib/filter-inout.js +261 -0
  230. package/dist/lib/filter-inout.js.map +1 -0
  231. package/dist/lib/filter.d.ts +243 -0
  232. package/dist/lib/filter.js +272 -0
  233. package/dist/lib/filter.js.map +1 -0
  234. package/dist/lib/format-context.d.ts +1335 -0
  235. package/dist/lib/format-context.js +1455 -0
  236. package/dist/lib/format-context.js.map +1 -0
  237. package/dist/lib/frame-utils.d.ts +116 -0
  238. package/dist/lib/frame-utils.js +98 -0
  239. package/dist/lib/frame-utils.js.map +1 -0
  240. package/dist/lib/frame.d.ts +1315 -0
  241. package/dist/lib/frame.js +1535 -0
  242. package/dist/lib/frame.js.map +1 -0
  243. package/dist/lib/hardware-device-context.d.ts +362 -0
  244. package/dist/lib/hardware-device-context.js +383 -0
  245. package/dist/lib/hardware-device-context.js.map +1 -0
  246. package/dist/lib/hardware-frames-context.d.ts +418 -0
  247. package/dist/lib/hardware-frames-context.js +471 -0
  248. package/dist/lib/hardware-frames-context.js.map +1 -0
  249. package/dist/lib/index.d.ts +35 -0
  250. package/dist/lib/index.js +60 -0
  251. package/dist/lib/index.js.map +1 -0
  252. package/dist/lib/input-format.d.ts +249 -0
  253. package/dist/lib/input-format.js +306 -0
  254. package/dist/lib/input-format.js.map +1 -0
  255. package/dist/lib/io-context.d.ts +698 -0
  256. package/dist/lib/io-context.js +771 -0
  257. package/dist/lib/io-context.js.map +1 -0
  258. package/dist/lib/log.d.ts +174 -0
  259. package/dist/lib/log.js +184 -0
  260. package/dist/lib/log.js.map +1 -0
  261. package/dist/lib/native-types.d.ts +1024 -0
  262. package/dist/lib/native-types.js +2 -0
  263. package/dist/lib/native-types.js.map +1 -0
  264. package/dist/lib/option.d.ts +953 -0
  265. package/dist/lib/option.js +1607 -0
  266. package/dist/lib/option.js.map +1 -0
  267. package/dist/lib/output-format.d.ts +222 -0
  268. package/dist/lib/output-format.js +259 -0
  269. package/dist/lib/output-format.js.map +1 -0
  270. package/dist/lib/packet.d.ts +521 -0
  271. package/dist/lib/packet.js +613 -0
  272. package/dist/lib/packet.js.map +1 -0
  273. package/dist/lib/rational.d.ts +251 -0
  274. package/dist/lib/rational.js +278 -0
  275. package/dist/lib/rational.js.map +1 -0
  276. package/dist/lib/software-resample-context.d.ts +552 -0
  277. package/dist/lib/software-resample-context.js +592 -0
  278. package/dist/lib/software-resample-context.js.map +1 -0
  279. package/dist/lib/software-scale-context.d.ts +344 -0
  280. package/dist/lib/software-scale-context.js +366 -0
  281. package/dist/lib/software-scale-context.js.map +1 -0
  282. package/dist/lib/stream.d.ts +383 -0
  283. package/dist/lib/stream.js +524 -0
  284. package/dist/lib/stream.js.map +1 -0
  285. package/dist/lib/sync-queue.d.ts +179 -0
  286. package/dist/lib/sync-queue.js +197 -0
  287. package/dist/lib/sync-queue.js.map +1 -0
  288. package/dist/lib/types.d.ts +34 -0
  289. package/dist/lib/types.js +2 -0
  290. package/dist/lib/types.js.map +1 -0
  291. package/dist/lib/utilities.d.ts +1198 -0
  292. package/dist/lib/utilities.js +1302 -0
  293. package/dist/lib/utilities.js.map +1 -0
  294. package/dist/utils/electron.d.ts +49 -0
  295. package/dist/utils/electron.js +63 -0
  296. package/dist/utils/electron.js.map +1 -0
  297. package/dist/utils/index.d.ts +6 -0
  298. package/dist/utils/index.js +7 -0
  299. package/dist/utils/index.js.map +1 -0
  300. package/dist/utils/libc.d.ts +11 -0
  301. package/dist/utils/libc.js +35 -0
  302. package/dist/utils/libc.js.map +1 -0
  303. package/dist/utils/variant.d.ts +26 -0
  304. package/dist/utils/variant.js +31 -0
  305. package/dist/utils/variant.js.map +1 -0
  306. package/dist/webrtc/index.d.ts +4 -0
  307. package/dist/webrtc/index.js +7 -0
  308. package/dist/webrtc/index.js.map +1 -0
  309. package/install/check.js +124 -0
  310. package/install/ffmpeg.js +66 -0
  311. package/package.json +167 -4
@@ -0,0 +1,1295 @@
1
+ import { Readable } from 'node:stream';
2
+ import { FormatContext } from '../lib/format-context.js';
3
+ import { InputFormat } from '../lib/input-format.js';
4
+ import { IOContext } from '../lib/io-context.js';
5
+ import { Packet } from '../lib/packet.js';
6
+ import type { RtpPacket } from 'werift';
7
+ import type { AVMediaType, AVPixelFormat, AVSampleFormat, AVSeekFlag, DemuxerFormat, DemuxerOptionsFor } from '../constants/index.js';
8
+ import type { Stream } from '../lib/stream.js';
9
+ import type { IRational } from '../lib/types.js';
10
+ import type { IOInputCallbacks } from './io-stream.js';
11
+ /**
12
+ * Raw video data configuration.
13
+ */
14
+ export interface VideoRawData {
15
+ /**
16
+ * Type discriminator for TypeScript.
17
+ *
18
+ * Must be set to 'video' to identify this as video raw data.
19
+ */
20
+ type: 'video';
21
+ /**
22
+ * Raw video input source.
23
+ *
24
+ * Can be a file path, Buffer containing raw video data, or custom I/O callbacks.
25
+ */
26
+ input: string | Buffer | IOInputCallbacks;
27
+ /**
28
+ * Video frame width in pixels.
29
+ *
30
+ * Must match the actual width of the raw video data.
31
+ */
32
+ width: number;
33
+ /**
34
+ * Video frame height in pixels.
35
+ *
36
+ * Must match the actual height of the raw video data.
37
+ */
38
+ height: number;
39
+ /**
40
+ * Pixel format of the raw video data.
41
+ *
42
+ * Specifies how pixel data is stored (e.g., YUV420P, NV12, RGB24).
43
+ */
44
+ pixelFormat: AVPixelFormat;
45
+ /**
46
+ * Frame rate of the raw video.
47
+ *
48
+ * Specified as a rational number (numerator/denominator).
49
+ */
50
+ frameRate: IRational;
51
+ }
52
+ /**
53
+ * Raw audio data configuration.
54
+ */
55
+ export interface AudioRawData {
56
+ /**
57
+ * Type discriminator for TypeScript.
58
+ *
59
+ * Must be set to 'audio' to identify this as audio raw data.
60
+ */
61
+ type: 'audio';
62
+ /**
63
+ * Raw audio input source.
64
+ *
65
+ * Can be a file path, Buffer containing raw audio data, or custom I/O callbacks.
66
+ */
67
+ input: string | Buffer | IOInputCallbacks;
68
+ /**
69
+ * Sample rate in Hz.
70
+ *
71
+ * Number of audio samples per second (e.g., 44100, 48000).
72
+ */
73
+ sampleRate: number;
74
+ /**
75
+ * Number of audio channels.
76
+ *
77
+ * Typical values: 1 (mono), 2 (stereo), 6 (5.1 surround).
78
+ */
79
+ channels: number;
80
+ /**
81
+ * Sample format of the raw audio data.
82
+ *
83
+ * Specifies how audio samples are stored (e.g., S16, FLT, S32).
84
+ */
85
+ sampleFormat: AVSampleFormat;
86
+ }
87
+ /**
88
+ * Options for Demuxer opening.
89
+ */
90
+ export interface DemuxerOptions<F extends DemuxerFormat | (string & {}) = DemuxerFormat | (string & {})> {
91
+ /**
92
+ * Buffer size for reading/writing operations.
93
+ *
94
+ * This option allows you to specify the buffer size used for I/O operations.
95
+ *
96
+ * @default 65536
97
+ *
98
+ */
99
+ bufferSize?: number;
100
+ /**
101
+ * Force specific input format.
102
+ *
103
+ * Use this to specify the input format explicitly instead of auto-detection.
104
+ * Useful for raw formats like 'rawvideo', 'rawaudio', etc.
105
+ *
106
+ * When given as a literal (e.g. `'mov'`), `options` is strongly typed to that
107
+ * demuxer's known options plus the generic AVFormatContext options.
108
+ */
109
+ format?: F;
110
+ /**
111
+ * Skip reading stream information on open.
112
+ *
113
+ * If true, stream info (codecs, formats, etc.) will not be read during opening.
114
+ * This can speed up opening time for certain use cases where stream info is not needed.
115
+ *
116
+ * @default false
117
+ */
118
+ skipStreamInfo?: boolean;
119
+ /**
120
+ * Start reading packets from the first keyframe.
121
+ *
122
+ * When enabled, all packets before the first keyframe will be skipped.
123
+ * Useful for seeking and trimming operations.
124
+ *
125
+ * @default false
126
+ */
127
+ startWithKeyframe?: boolean;
128
+ /**
129
+ * DTS delta threshold in seconds.
130
+ *
131
+ * Timestamp discontinuity detection threshold for formats with AVFMT_TS_DISCONT flag.
132
+ * When DTS delta exceeds this value, it's considered a discontinuity.
133
+ *
134
+ * Matches FFmpeg CLI's -dts_delta_threshold option.
135
+ *
136
+ * @default 10
137
+ */
138
+ dtsDeltaThreshold?: number;
139
+ /**
140
+ * DTS error threshold in seconds.
141
+ *
142
+ * Timestamp discontinuity detection threshold for continuous formats (without AVFMT_TS_DISCONT).
143
+ * When DTS delta exceeds this value, it's considered a timestamp error.
144
+ *
145
+ * Matches FFmpeg CLI's -dts_error_threshold option.
146
+ *
147
+ * @default 108000 (30 hours)
148
+ */
149
+ dtsErrorThreshold?: number;
150
+ /**
151
+ * Copy timestamps from input to output.
152
+ *
153
+ * When enabled, timestamps are passed through without modification.
154
+ * This disables most timestamp discontinuity corrections except for
155
+ * PTS wrap-around detection in discontinuous formats.
156
+ *
157
+ * Matches FFmpeg CLI's -copyts option.
158
+ *
159
+ * @default false
160
+ */
161
+ copyTs?: boolean;
162
+ /**
163
+ * FFmpeg format options passed directly to the input.
164
+ *
165
+ * Key-value pairs of FFmpeg AVFormatContext / demuxer-private / protocol
166
+ * options, passed to avformat_open_input(). When `format` is a known literal,
167
+ * these are typed to that demuxer's options (autocomplete + value typing);
168
+ * arbitrary keys remain allowed so protocol options (e.g. `rtsp_transport`)
169
+ * still pass.
170
+ */
171
+ options?: DemuxerOptionsFor<F>;
172
+ /**
173
+ * Configure the underlying format context just after the input is opened.
174
+ *
175
+ * Called with the input {@link FormatContext} after `avformat_open_input` and
176
+ * `avformat_find_stream_info` (so the streams are available) and before any
177
+ * packets are read. Use it to inspect or tweak the open input context or its
178
+ * streams directly. Most input-side tuning (probesize, analyzeduration,
179
+ * protocol options, …) is better passed via {@link DemuxerOptions.options},
180
+ * which is applied at open time.
181
+ *
182
+ * @example
183
+ * ```typescript
184
+ * await Demuxer.open('input.mp4', {
185
+ * configure: (fmt) => {
186
+ * console.log(`Opened ${fmt.streams.length} streams`);
187
+ * },
188
+ * });
189
+ * ```
190
+ */
191
+ configure?: (context: FormatContext) => void;
192
+ /**
193
+ * AbortSignal for cancellation.
194
+ *
195
+ * When aborted, async generators stop yielding and async methods throw AbortError.
196
+ * The demux thread is stopped automatically. Aborting also fires the native
197
+ * interrupt callback, unblocking a blocking open (e.g. an unresponsive RTSP
198
+ * source) or a stalled av_read_frame().
199
+ */
200
+ signal?: AbortSignal;
201
+ }
202
+ /**
203
+ * RTP Demuxer interface.
204
+ */
205
+ export interface RTPDemuxer {
206
+ /**
207
+ * Demuxer configured for RTP/SRTP reception.
208
+ *
209
+ * Receives RTP packets via localhost UDP and feeds them to FFmpeg for decoding.
210
+ */
211
+ input: Demuxer;
212
+ /**
213
+ * Send RTP packet to FFmpeg for decoding.
214
+ *
215
+ * @param rtpPacket - RTP packet as Buffer or RtpPacket object
216
+ *
217
+ * @param streamIndex - Optional stream index for multiplexed RTP
218
+ */
219
+ sendPacket: (rtpPacket: Buffer | RtpPacket, streamIndex?: number) => void;
220
+ /**
221
+ * Cleanup function.
222
+ *
223
+ * Closes the demuxer and UDP socket asynchronously.
224
+ */
225
+ close: () => Promise<void>;
226
+ /**
227
+ * Synchronous cleanup function.
228
+ *
229
+ * Closes the demuxer and UDP socket synchronously.
230
+ */
231
+ closeSync: () => void;
232
+ }
233
+ /**
234
+ * High-level demuxer for reading and demuxing media files.
235
+ *
236
+ * Provides simplified access to media streams, packets, and metadata.
237
+ * Handles file opening, format detection, and stream information extraction.
238
+ * Supports files, URLs, buffers, and raw data input with automatic cleanup.
239
+ * Essential component for media processing pipelines and transcoding.
240
+ *
241
+ * @example
242
+ * ```typescript
243
+ * import { Demuxer } from 'node-av/api';
244
+ *
245
+ * // Open media file
246
+ * await using input = await Demuxer.open('video.mp4');
247
+ * console.log(`Format: ${input.formatName}`);
248
+ * console.log(`Duration: ${input.duration}s`);
249
+ *
250
+ * // Process packets
251
+ * for await (const packet of input.packets()) {
252
+ * console.log(`Packet from stream ${packet.streamIndex}`);
253
+ * packet.free();
254
+ * }
255
+ * ```
256
+ *
257
+ * @example
258
+ * ```typescript
259
+ * // From buffer
260
+ * const buffer = await fs.readFile('video.mp4');
261
+ * await using input = await Demuxer.open(buffer);
262
+ *
263
+ * // Access streams
264
+ * const videoStream = input.video();
265
+ * const audioStream = input.audio();
266
+ * ```
267
+ *
268
+ * @see {@link Muxer} For writing media files
269
+ * @see {@link Decoder} For decoding packets to frames
270
+ * @see {@link FormatContext} For low-level API
271
+ */
272
+ export declare class Demuxer implements AsyncDisposable, Disposable {
273
+ private formatContext;
274
+ private _streams;
275
+ private ioContext?;
276
+ private externalIO;
277
+ private isClosed;
278
+ private options;
279
+ private streamStates;
280
+ private tsOffsetDiscont;
281
+ private lastTs;
282
+ private activeGenerators;
283
+ private demuxThread;
284
+ private packetQueues;
285
+ private packetQueueConsumers;
286
+ private queueResolvers;
287
+ private drainResolver;
288
+ private demuxThreadActive;
289
+ private demuxEof;
290
+ private lastError;
291
+ private signal?;
292
+ private signalCleanup?;
293
+ /**
294
+ * @param formatContext - Opened format context
295
+ *
296
+ * @param options - Media input options
297
+ *
298
+ * @param ioContext - Optional IO context for custom I/O (e.g., from Buffer)
299
+ *
300
+ * @param externalIO - Whether ioContext was supplied by the caller instead of built here
301
+ *
302
+ * @internal
303
+ */
304
+ private constructor();
305
+ /**
306
+ * Probe media format without fully opening the file.
307
+ *
308
+ * Detects format by analyzing file headers and content.
309
+ * Useful for format validation before processing.
310
+ *
311
+ * Direct mapping to av_probe_input_format().
312
+ *
313
+ * @param input - File path or buffer to probe
314
+ *
315
+ * @returns Format information or null if unrecognized
316
+ *
317
+ * @example
318
+ * ```typescript
319
+ * const info = await Demuxer.probeFormat('video.mp4');
320
+ * if (info) {
321
+ * console.log(`Format: ${info.format}`);
322
+ * console.log(`Confidence: ${info.confidence}%`);
323
+ * }
324
+ * ```
325
+ *
326
+ * @example
327
+ * ```typescript
328
+ * // Probe from buffer
329
+ * const buffer = await fs.readFile('video.webm');
330
+ * const info = await Demuxer.probeFormat(buffer);
331
+ * console.log(`MIME type: ${info?.mimeType}`);
332
+ * ```
333
+ *
334
+ * @see {@link InputFormat.probe} For low-level probing
335
+ */
336
+ static probeFormat(input: string | Buffer): Promise<{
337
+ format: string;
338
+ longName?: string;
339
+ extensions?: string;
340
+ mimeType?: string;
341
+ confidence: number;
342
+ } | null>;
343
+ /**
344
+ * Probe media format without fully opening the file synchronously.
345
+ * Synchronous version of probeFormat.
346
+ *
347
+ * Detects format by analyzing file headers and content.
348
+ * Useful for format validation before processing.
349
+ *
350
+ * Direct mapping to av_probe_input_format().
351
+ *
352
+ * @param input - File path or buffer to probe
353
+ *
354
+ * @returns Format information or null if unrecognized
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * const info = Demuxer.probeFormatSync('video.mp4');
359
+ * if (info) {
360
+ * console.log(`Format: ${info.format}`);
361
+ * console.log(`Confidence: ${info.confidence}%`);
362
+ * }
363
+ * ```
364
+ *
365
+ * @example
366
+ * ```typescript
367
+ * // Probe from buffer
368
+ * const buffer = fs.readFileSync('video.webm');
369
+ * const info = Demuxer.probeFormatSync(buffer);
370
+ * console.log(`MIME type: ${info?.mimeType}`);
371
+ * ```
372
+ *
373
+ * @see {@link probeFormat} For async version
374
+ */
375
+ static probeFormatSync(input: string | Buffer): {
376
+ format: string;
377
+ longName?: string;
378
+ extensions?: string;
379
+ mimeType?: string;
380
+ confidence: number;
381
+ } | null;
382
+ /**
383
+ * Open media from file, URL, buffer, raw data, or custom I/O callbacks.
384
+ *
385
+ * Automatically detects format and extracts stream information.
386
+ * Supports various input sources with flexible configuration.
387
+ * Creates demuxer ready for packet extraction.
388
+ * A supplied IOContext is taken over by the demuxer and released on close.
389
+ *
390
+ * Direct mapping to avformat_open_input() and avformat_find_stream_info().
391
+ *
392
+ * @param input - File path, URL, buffer, raw data descriptor, or custom I/O callbacks
393
+ *
394
+ * @param options - Input configuration options
395
+ *
396
+ * @returns Opened demuxer instance
397
+ *
398
+ * @throws {Error} If format not found or open fails, or format required for custom I/O
399
+ *
400
+ * @throws {FFmpegError} If FFmpeg operations fail
401
+ *
402
+ * @example
403
+ * ```typescript
404
+ * // Open file
405
+ * await using input = await Demuxer.open('video.mp4');
406
+ * ```
407
+ *
408
+ * @example
409
+ * ```typescript
410
+ * // Open URL
411
+ * await using input = await Demuxer.open('http://example.com/stream.m3u8');
412
+ * ```
413
+ *
414
+ * @example
415
+ * ```typescript
416
+ * // Open with options
417
+ * await using input = await Demuxer.open('rtsp://camera.local', {
418
+ * format: 'rtsp',
419
+ * options: {
420
+ * rtsp_transport: 'tcp',
421
+ * analyzeduration: '5000000'
422
+ * }
423
+ * });
424
+ * ```
425
+ *
426
+ * @example
427
+ * ```typescript
428
+ * // Open raw video data
429
+ * await using input = await Demuxer.open({
430
+ * type: 'video',
431
+ * input: rawBuffer,
432
+ * width: 1920,
433
+ * height: 1080,
434
+ * pixelFormat: AV_PIX_FMT_YUV420P,
435
+ * frameRate: { num: 30, den: 1 }
436
+ * });
437
+ * ```
438
+ *
439
+ * @example
440
+ * ```typescript
441
+ * // Custom I/O callbacks
442
+ * const callbacks = {
443
+ * read: (size: number) => {
444
+ * // Read data from custom source
445
+ * return buffer; // or null for EOF, or negative error code
446
+ * },
447
+ * seek: (offset: bigint, whence: AVSeekWhence) => {
448
+ * // Seek in custom source
449
+ * return offset; // or negative error code
450
+ * }
451
+ * };
452
+ *
453
+ * await using input = await Demuxer.open(callbacks, {
454
+ * format: 'mp4',
455
+ * bufferSize: 8192
456
+ * });
457
+ * ```
458
+ *
459
+ * @see {@link DemuxerOptions} For configuration options
460
+ * @see {@link VideoRawData} For raw video data input
461
+ * @see {@link AudioRawData} For raw audio data input
462
+ * @see {@link IOInputCallbacks} For custom I/O interface
463
+ */
464
+ static open<const F extends DemuxerFormat | (string & {}) = DemuxerFormat | (string & {})>(input: string | Buffer, options?: DemuxerOptions<F>): Promise<Demuxer>;
465
+ static open<const F extends DemuxerFormat | (string & {})>(input: IOInputCallbacks, options: DemuxerOptions<F> & {
466
+ format: F;
467
+ }): Promise<Demuxer>;
468
+ static open<const F extends DemuxerFormat | (string & {})>(input: IOContext, options: DemuxerOptions<F> & {
469
+ format: F;
470
+ }): Promise<Demuxer>;
471
+ static open<const F extends DemuxerFormat | (string & {})>(input: Readable, options: DemuxerOptions<F> & {
472
+ format: F;
473
+ }): Promise<Demuxer>;
474
+ static open<const F extends DemuxerFormat | (string & {}) = DemuxerFormat | (string & {})>(rawData: VideoRawData | AudioRawData, options?: DemuxerOptions<F>): Promise<Demuxer>;
475
+ /**
476
+ * Open media from file, URL, Buffer, raw data, or custom I/O callbacks synchronously.
477
+ * Synchronous version of open.
478
+ *
479
+ * Automatically detects format and extracts stream information.
480
+ * Supports various input sources with flexible configuration.
481
+ * Creates demuxer ready for packet extraction.
482
+ * A supplied IOContext is taken over by the demuxer and released on close.
483
+ *
484
+ * Direct mapping to avformat_open_input() and avformat_find_stream_info().
485
+ *
486
+ * @param input - File path, URL, Buffer, raw data descriptor, or custom I/O callbacks
487
+ *
488
+ * @param options - Input configuration options
489
+ *
490
+ * @returns Opened muxer instance
491
+ *
492
+ * @throws {Error} If format not found or open fails, or format required for custom I/O
493
+ *
494
+ * @throws {FFmpegError} If FFmpeg operations fail
495
+ *
496
+ * @example
497
+ * ```typescript
498
+ * // Open file
499
+ * using input = Demuxer.openSync('video.mp4');
500
+ * ```
501
+ *
502
+ * @example
503
+ * ```typescript
504
+ * // Open from buffer
505
+ * const buffer = await fs.readFile('video.mp4');
506
+ * using input = Demuxer.openSync(buffer);
507
+ * ```
508
+ *
509
+ * @example
510
+ * ```typescript
511
+ * // Open with options
512
+ * using input = Demuxer.openSync('rtsp://camera.local', {
513
+ * format: 'rtsp',
514
+ * options: {
515
+ * rtsp_transport: 'tcp',
516
+ * analyzeduration: '5000000'
517
+ * }
518
+ * });
519
+ * ```
520
+ *
521
+ * @example
522
+ * ```typescript
523
+ * // Custom I/O callbacks
524
+ * const callbacks = {
525
+ * read: (size: number) => {
526
+ * // Read data from custom source
527
+ * return buffer; // or null for EOF, or negative error code
528
+ * },
529
+ * seek: (offset: bigint, whence: AVSeekWhence) => {
530
+ * // Seek in custom source
531
+ * return offset; // or negative error code
532
+ * }
533
+ * };
534
+ *
535
+ * using input = Demuxer.openSync(callbacks, {
536
+ * format: 'mp4',
537
+ * bufferSize: 8192
538
+ * });
539
+ * ```
540
+ *
541
+ * @see {@link open} For async version
542
+ * @see {@link IOInputCallbacks} For custom I/O interface
543
+ */
544
+ static openSync<const F extends DemuxerFormat | (string & {}) = DemuxerFormat | (string & {})>(input: string | Buffer, options?: DemuxerOptions<F>): Demuxer;
545
+ static openSync<const F extends DemuxerFormat | (string & {})>(input: IOInputCallbacks, options: DemuxerOptions<F> & {
546
+ format: F;
547
+ }): Demuxer;
548
+ static openSync<const F extends DemuxerFormat | (string & {})>(input: IOContext, options: DemuxerOptions<F> & {
549
+ format: F;
550
+ }): Demuxer;
551
+ static openSync<const F extends DemuxerFormat | (string & {})>(input: Readable, options: DemuxerOptions<F> & {
552
+ format: F;
553
+ }): Demuxer;
554
+ static openSync<const F extends DemuxerFormat | (string & {}) = DemuxerFormat | (string & {})>(rawData: VideoRawData | AudioRawData, options?: DemuxerOptions<F>): Demuxer;
555
+ /**
556
+ * Open RTP/SRTP input stream via localhost UDP.
557
+ *
558
+ * Creates a Demuxer from SDP string received via UDP socket.
559
+ * Opens UDP socket and configures FFmpeg to receive and parse RTP packets.
560
+ *
561
+ * @param sdpContent - SDP content string describing the RTP stream
562
+ *
563
+ * @throws {Error} If SDP parsing or socket setup fails
564
+ *
565
+ * @throws {FFmpegError} If FFmpeg operations fail
566
+ *
567
+ * @returns Promise with Demuxer, sendPacket function and cleanup
568
+ *
569
+ * @example
570
+ * ```typescript
571
+ * import { Demuxer, StreamingUtils } from 'node-av/api';
572
+ * import { AV_CODEC_ID_OPUS } from 'node-av/constants';
573
+ *
574
+ * // Generate SDP for SRTP encrypted Opus
575
+ * const sdp = StreamingUtils.createRTPInputSDP([{
576
+ * port: 5004,
577
+ * codecId: AV_CODEC_ID_OPUS,
578
+ * payloadType: 111,
579
+ * clockRate: 16000,
580
+ * channels: 1,
581
+ * srtp: { key: srtpKey, salt: srtpSalt }
582
+ * }]);
583
+ *
584
+ * // Open RTP input
585
+ * const { input, sendPacket, close } = await Demuxer.openSDP(sdp);
586
+ *
587
+ * // Route encrypted RTP packets from network
588
+ * socket.on('message', (msg) => sendPacket(msg));
589
+ *
590
+ * // Decode audio
591
+ * const decoder = await Decoder.create(input.audio()!);
592
+ * for await (const packet of input.packets()) {
593
+ * const frame = await decoder.decode(packet);
594
+ * // Process frame...
595
+ * }
596
+ *
597
+ * // Cleanup
598
+ * await close();
599
+ * ```
600
+ *
601
+ * @see {@link StreamingUtils.createInputSDP} to generate SDP content.
602
+ */
603
+ static openSDP(sdpContent: string): Promise<RTPDemuxer>;
604
+ /**
605
+ * Open RTP/SRTP input stream via localhost UDP synchronously.
606
+ * Synchronous version of openSDP.
607
+ *
608
+ * Creates a Demuxer from SDP string received via UDP socket.
609
+ * Opens UDP socket and configures FFmpeg to receive and parse RTP packets.
610
+ *
611
+ * @param sdpContent - SDP content string describing the RTP stream
612
+ *
613
+ * @throws {Error} If SDP parsing or socket setup fails
614
+ *
615
+ * @throws {FFmpegError} If FFmpeg operations fail
616
+ *
617
+ * @returns Object with Demuxer, sendPacket function and cleanup
618
+ *
619
+ * @example
620
+ * ```typescript
621
+ * import { Demuxer, StreamingUtils } from 'node-av/api';
622
+ * import { AV_CODEC_ID_OPUS } from 'node-av/constants';
623
+ *
624
+ * // Generate SDP for SRTP encrypted Opus
625
+ * const sdp = StreamingUtils.createRTPInputSDP([{
626
+ * port: 5004,
627
+ * codecId: AV_CODEC_ID_OPUS,
628
+ * payloadType: 111,
629
+ * clockRate: 16000,
630
+ * channels: 1,
631
+ * srtp: { key: srtpKey, salt: srtpSalt }
632
+ * }]);
633
+ *
634
+ * // Open RTP input
635
+ * const { input, sendPacket, closeSync } = Demuxer.openSDPSync(sdp);
636
+ *
637
+ * // Route encrypted RTP packets from network
638
+ * socket.on('message', (msg) => sendPacket(msg));
639
+ *
640
+ * // Decode audio
641
+ * const decoder = await Decoder.create(input.audio()!);
642
+ * for await (const packet of input.packets()) {
643
+ * const frame = await decoder.decode(packet);
644
+ * // Process frame...
645
+ * }
646
+ *
647
+ * // Cleanup synchronously
648
+ * closeSync();
649
+ * ```
650
+ *
651
+ * @see {@link StreamingUtils.createInputSDP} to generate SDP content.
652
+ * @see {@link openSDP} For async version
653
+ */
654
+ static openSDPSync(sdpContent: string): RTPDemuxer;
655
+ /**
656
+ * Check if input is open.
657
+ *
658
+ * @example
659
+ * ```typescript
660
+ * if (!input.isInputOpen) {
661
+ * console.log('Input is not open');
662
+ * }
663
+ * ```
664
+ */
665
+ get isInputOpen(): boolean;
666
+ /**
667
+ * Get all streams in the media.
668
+ *
669
+ * @example
670
+ * ```typescript
671
+ * for (const stream of input.streams) {
672
+ * console.log(`Stream ${stream.index}: ${stream.codecpar.codecType}`);
673
+ * }
674
+ * ```
675
+ */
676
+ get streams(): Stream[];
677
+ /**
678
+ * Get media duration in seconds.
679
+ *
680
+ * Returns 0 if duration is unknown or not available or input is closed.
681
+ *
682
+ * @example
683
+ * ```typescript
684
+ * console.log(`Duration: ${input.duration} seconds`);
685
+ * ```
686
+ */
687
+ get duration(): number;
688
+ /**
689
+ * Get media start time in seconds.
690
+ *
691
+ * For device inputs (e.g., avfoundation), this reflects the system uptime
692
+ * at capture start. Pass this value to `Muxer.open()` via the `startTime`
693
+ * option to produce correct output timestamps.
694
+ *
695
+ * Returns 0 if start time is unknown or not available or input is closed.
696
+ *
697
+ * @example
698
+ * ```typescript
699
+ * await using input = await Demuxer.open(source);
700
+ * await using output = await Muxer.open('output.mp4', { startTime: input.startTime });
701
+ * ```
702
+ */
703
+ get startTime(): number;
704
+ /**
705
+ * Get media bitrate in kilobits per second.
706
+ *
707
+ * Returns 0 if bitrate is unknown or not available or input is closed.
708
+ *
709
+ * @example
710
+ * ```typescript
711
+ * console.log(`Bitrate: ${input.bitRate} kbps`);
712
+ * ```
713
+ */
714
+ get bitRate(): number;
715
+ /**
716
+ * Get media metadata.
717
+ *
718
+ * Returns all metadata tags as key-value pairs.
719
+ *
720
+ * @example
721
+ * ```typescript
722
+ * const metadata = input.metadata;
723
+ * console.log(`Title: ${metadata.title}`);
724
+ * console.log(`Artist: ${metadata.artist}`);
725
+ * ```
726
+ */
727
+ get metadata(): Record<string, string>;
728
+ /**
729
+ * Get format name.
730
+ *
731
+ * Returns 'unknown' if input is closed or format is not available.
732
+ *
733
+ * @example
734
+ * ```typescript
735
+ * console.log(`Format: ${input.formatName}`); // "mov,mp4,m4a,3gp,3g2,mj2"
736
+ * ```
737
+ */
738
+ get formatName(): string;
739
+ /**
740
+ * Get format long name.
741
+ *
742
+ * Returns 'Unknown Format' if input is closed or format is not available.
743
+ *
744
+ * @example
745
+ * ```typescript
746
+ * console.log(`Format: ${input.formatLongName}`); // "QuickTime / MOV"
747
+ * ```
748
+ */
749
+ get formatLongName(): string;
750
+ /**
751
+ * Get MIME type of the input format.
752
+ *
753
+ * Returns null if input is closed or format is not available.
754
+ *
755
+ * @example
756
+ * ```typescript
757
+ * console.log(`MIME Type: ${input.mimeType}`); // "video/mp4"
758
+ * ```
759
+ */
760
+ get mimeType(): string | null;
761
+ /**
762
+ * Get input stream by index.
763
+ *
764
+ * Returns the stream at the specified index.
765
+ *
766
+ * @param index - Stream index
767
+ *
768
+ * @returns Stream or undefined if index is invalid
769
+ *
770
+ * @example
771
+ * ```typescript
772
+ * const input = await Demuxer.open('input.mp4');
773
+ *
774
+ * // Get the input stream to inspect codec parameters
775
+ * const stream = input.getStream(1); // Get stream at index 1
776
+ * if (stream) {
777
+ * console.log(`Input codec: ${stream.codecpar.codecId}`);
778
+ * }
779
+ * ```
780
+ *
781
+ * @see {@link video} For getting video streams
782
+ * @see {@link audio} For getting audio streams
783
+ */
784
+ getStream(index: number): Stream | undefined;
785
+ /**
786
+ * Get video stream by index.
787
+ *
788
+ * Returns the nth video stream (0-based index).
789
+ * Returns undefined if stream doesn't exist.
790
+ *
791
+ * @param index - Video stream index (default: 0)
792
+ *
793
+ * @returns Video stream or undefined
794
+ *
795
+ * @example
796
+ * ```typescript
797
+ * const videoStream = input.video();
798
+ * if (videoStream) {
799
+ * console.log(`Video: ${videoStream.codecpar.width}x${videoStream.codecpar.height}`);
800
+ * }
801
+ * ```
802
+ *
803
+ * @example
804
+ * ```typescript
805
+ * // Get second video stream
806
+ * const secondVideo = input.video(1);
807
+ * ```
808
+ *
809
+ * @see {@link audio} For audio streams
810
+ * @see {@link findBestStream} For automatic selection
811
+ */
812
+ video(index?: number): Stream | undefined;
813
+ /**
814
+ * Get audio stream by index.
815
+ *
816
+ * Returns the nth audio stream (0-based index).
817
+ * Returns undefined if stream doesn't exist.
818
+ *
819
+ * @param index - Audio stream index (default: 0)
820
+ *
821
+ * @returns Audio stream or undefined
822
+ *
823
+ * @example
824
+ * ```typescript
825
+ * const audioStream = input.audio();
826
+ * if (audioStream) {
827
+ * console.log(`Audio: ${audioStream.codecpar.sampleRate}Hz`);
828
+ * }
829
+ * ```
830
+ *
831
+ * @example
832
+ * ```typescript
833
+ * // Get second audio stream
834
+ * const secondAudio = input.audio(1);
835
+ * ```
836
+ *
837
+ * @see {@link video} For video streams
838
+ * @see {@link findBestStream} For automatic selection
839
+ */
840
+ audio(index?: number): Stream | undefined;
841
+ /**
842
+ * Get input format details.
843
+ *
844
+ * Returns null if input is closed or format is not available.
845
+ *
846
+ * @returns Input format or null
847
+ *
848
+ * @example
849
+ * ```typescript
850
+ * const inputFormat = input.inputFormat;
851
+ * if (inputFormat) {
852
+ * console.log(`Input Format: ${inputFormat.name}`);
853
+ * }
854
+ * ```
855
+ */
856
+ inputFormat(): InputFormat | null;
857
+ /**
858
+ * Find the best stream of a given type.
859
+ *
860
+ * Uses FFmpeg's stream selection algorithm.
861
+ * Considers codec support, default flags, and quality.
862
+ *
863
+ * Direct mapping to av_find_best_stream().
864
+ *
865
+ * @param type - Media type to find
866
+ *
867
+ * @returns Best stream or undefined if not found or input is closed
868
+ *
869
+ * @example
870
+ * ```typescript
871
+ * import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
872
+ *
873
+ * const bestVideo = input.findBestStream(AVMEDIA_TYPE_VIDEO);
874
+ * if (bestVideo) {
875
+ * const decoder = await Decoder.create(bestVideo);
876
+ * }
877
+ * ```
878
+ *
879
+ * @see {@link video} For direct video stream access
880
+ * @see {@link audio} For direct audio stream access
881
+ */
882
+ findBestStream(type: AVMediaType): Stream | undefined;
883
+ /**
884
+ * Read packets from media as async generator.
885
+ *
886
+ * Yields demuxed packets for processing.
887
+ * Automatically handles packet memory management.
888
+ * Optionally filters packets by stream index.
889
+ *
890
+ * **Supports parallel generators**: Multiple `packets()` iterators can run concurrently.
891
+ * When multiple generators are active, an internal demux thread automatically handles
892
+ * packet distribution to avoid race conditions.
893
+ *
894
+ * Direct mapping to av_read_frame().
895
+ *
896
+ * @param index - Optional stream index to filter
897
+ *
898
+ * @yields {Packet} Demuxed packets (must be freed by caller)
899
+ *
900
+ * @throws {FFmpegError} If reading fails with an error other than EOF (e.g. I/O failure
901
+ * or a dropped network source) - only a real end-of-file ends the stream cleanly
902
+ *
903
+ * @throws {Error} If packet cloning fails
904
+ *
905
+ * @example
906
+ * ```typescript
907
+ * // Read all packets
908
+ * for await (const packet of input.packets()) {
909
+ * console.log(`Packet: stream=${packet.streamIndex}, pts=${packet.pts}`);
910
+ * packet.free();
911
+ * }
912
+ * ```
913
+ *
914
+ * @example
915
+ * ```typescript
916
+ * // Read only video packets
917
+ * const videoStream = input.video();
918
+ * for await (const packet of input.packets(videoStream.index)) {
919
+ * // Process video packet
920
+ * packet.free();
921
+ * }
922
+ * ```
923
+ *
924
+ * @example
925
+ * ```typescript
926
+ * // Parallel processing of video and audio streams
927
+ * const videoGen = input.packets(videoStream.index);
928
+ * const audioGen = input.packets(audioStream.index);
929
+ *
930
+ * await Promise.all([
931
+ * (async () => {
932
+ * for await (const packet of videoGen) {
933
+ * // Process video
934
+ * packet.free();
935
+ * }
936
+ * })(),
937
+ * (async () => {
938
+ * for await (const packet of audioGen) {
939
+ * // Process audio
940
+ * packet.free();
941
+ * }
942
+ * })()
943
+ * ]);
944
+ * ```
945
+ *
946
+ * @see {@link Decoder.frames} For decoding packets
947
+ */
948
+ packets(index?: number): AsyncGenerator<Packet | null>;
949
+ /**
950
+ * Read packets from media as generator synchronously.
951
+ * Synchronous version of packets.
952
+ *
953
+ * Yields demuxed packets for processing.
954
+ * Automatically handles packet memory management.
955
+ * Optionally filters packets by stream index.
956
+ *
957
+ * Direct mapping to av_read_frame().
958
+ *
959
+ * @param index - Optional stream index to filter
960
+ *
961
+ * @yields {Packet} Demuxed packets (must be freed by caller)
962
+ *
963
+ * @throws {FFmpegError} If reading fails with an error other than EOF (e.g. I/O failure
964
+ * or a dropped network source) - only a real end-of-file ends the stream cleanly
965
+ *
966
+ * @throws {Error} If packet cloning fails
967
+ *
968
+ * @example
969
+ * ```typescript
970
+ * // Read all packets
971
+ * for (const packet of input.packetsSync()) {
972
+ * console.log(`Packet: stream=${packet.streamIndex}, pts=${packet.pts}`);
973
+ * packet.free();
974
+ * }
975
+ * ```
976
+ *
977
+ * @example
978
+ * ```typescript
979
+ * // Read only video packets
980
+ * const videoStream = input.video();
981
+ * for (const packet of input.packetsSync(videoStream.index)) {
982
+ * // Process video packet
983
+ * packet.free();
984
+ * }
985
+ * ```
986
+ *
987
+ * @see {@link packets} For async version
988
+ */
989
+ packetsSync(index?: number): Generator<Packet | null>;
990
+ /**
991
+ * Seek to timestamp in media.
992
+ *
993
+ * Seeks to the specified position in seconds.
994
+ * Can seek in specific stream or globally.
995
+ *
996
+ * Direct mapping to av_seek_frame().
997
+ *
998
+ * @param timestamp - Target position in seconds
999
+ *
1000
+ * @param streamIndex - Stream index or -1 for global (default: -1)
1001
+ *
1002
+ * @param flags - Seek flags (default: AVFLAG_NONE)
1003
+ *
1004
+ * @returns 0 on success, negative on error
1005
+ *
1006
+ * @throws {Error} If input is closed
1007
+ *
1008
+ * @example
1009
+ * ```typescript
1010
+ * // Seek to 30 seconds
1011
+ * const ret = await input.seek(30);
1012
+ * FFmpegError.throwIfError(ret, 'seek failed');
1013
+ * ```
1014
+ *
1015
+ * @example
1016
+ * ```typescript
1017
+ * import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
1018
+ *
1019
+ * // Seek to keyframe before 60 seconds
1020
+ * await input.seek(60, -1, AVSEEK_FLAG_BACKWARD);
1021
+ * ```
1022
+ *
1023
+ * @see {@link AVSeekFlag} For seek flags
1024
+ */
1025
+ seek(timestamp: number, streamIndex?: number, flags?: AVSeekFlag): Promise<number>;
1026
+ /**
1027
+ * Seek to timestamp in media synchronously.
1028
+ * Synchronous version of seek.
1029
+ *
1030
+ * Seeks to the specified position in seconds.
1031
+ * Can seek in specific stream or globally.
1032
+ *
1033
+ * Direct mapping to av_seek_frame().
1034
+ *
1035
+ * @param timestamp - Target position in seconds
1036
+ *
1037
+ * @param streamIndex - Stream index or -1 for global (default: -1)
1038
+ *
1039
+ * @param flags - Seek flags (default: AVFLAG_NONE)
1040
+ *
1041
+ * @returns 0 on success, negative on error
1042
+ *
1043
+ * @throws {Error} If input is closed
1044
+ *
1045
+ * @example
1046
+ * ```typescript
1047
+ * // Seek to 30 seconds
1048
+ * const ret = input.seekSync(30);
1049
+ * FFmpegError.throwIfError(ret, 'seek failed');
1050
+ * ```
1051
+ *
1052
+ * @example
1053
+ * ```typescript
1054
+ * import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
1055
+ *
1056
+ * // Seek to keyframe before 60 seconds
1057
+ * input.seekSync(60, -1, AVSEEK_FLAG_BACKWARD);
1058
+ * ```
1059
+ *
1060
+ * @see {@link seek} For async version
1061
+ */
1062
+ seekSync(timestamp: number, streamIndex?: number, flags?: AVSeekFlag): number;
1063
+ /**
1064
+ * Wake the demux thread if it is parked waiting for a full queue to drain.
1065
+ *
1066
+ * @internal
1067
+ */
1068
+ private wakeDemuxThread;
1069
+ /**
1070
+ * Interrupt a blocking read without closing the demuxer.
1071
+ *
1072
+ * Aborts any in-progress `av_read_frame()` (e.g. on a quiet RTSP/network source
1073
+ * or a stalled Readable/custom I/O source that is waiting for data) and signals
1074
+ * end-of-stream to packet consumers, so an active pipeline can drain and finish.
1075
+ * The demuxer is not freed and its streams stay valid - call {@link close}
1076
+ * afterwards to release resources.
1077
+ *
1078
+ * Mainly used by pipeline teardown: a blocking read only unblocks on close, but
1079
+ * closing while the pipeline is still draining would free the context too early,
1080
+ * so the read is interrupted first and the input closed once processing settles.
1081
+ *
1082
+ * @example
1083
+ * ```typescript
1084
+ * control.stop();
1085
+ * input.interrupt(); // unblock a stalled read so completion can resolve
1086
+ * await control.completion;
1087
+ * await input.close();
1088
+ * ```
1089
+ *
1090
+ * @see {@link close} To close and free the demuxer
1091
+ */
1092
+ interrupt(): void;
1093
+ /**
1094
+ * Start the internal demux thread for handling multiple parallel packet generators.
1095
+ * This thread reads packets from the format context and distributes them to queues.
1096
+ *
1097
+ * @internal
1098
+ */
1099
+ private startDemuxThread;
1100
+ /**
1101
+ * Stop the internal demux thread.
1102
+ *
1103
+ * @internal
1104
+ */
1105
+ private stopDemuxThread;
1106
+ /**
1107
+ * Get or create stream state for timestamp processing.
1108
+ *
1109
+ * @param streamIndex - Stream index
1110
+ *
1111
+ * @returns Stream state
1112
+ *
1113
+ * @internal
1114
+ */
1115
+ private getStreamState;
1116
+ /**
1117
+ * PTS Wrap-Around Correction.
1118
+ *
1119
+ * Based on FFmpeg's ts_fixup().
1120
+ *
1121
+ * Corrects timestamp wrap-around for streams with limited timestamp bits.
1122
+ * DVB streams typically use 31-bit timestamps that wrap around.
1123
+ * Without correction, timestamps become negative causing playback errors.
1124
+ *
1125
+ * Handles:
1126
+ * - Detects wrap-around based on pts_wrap_bits from stream
1127
+ * - Applies correction once per stream
1128
+ * - Corrects both PTS and DTS
1129
+ *
1130
+ * @param packet - Packet to correct
1131
+ *
1132
+ * @param stream - Stream metadata
1133
+ *
1134
+ * @internal
1135
+ */
1136
+ private ptsWrapAroundCorrection;
1137
+ /**
1138
+ * DTS Prediction and Update.
1139
+ *
1140
+ * Based on FFmpeg's ist_dts_update().
1141
+ *
1142
+ * Predicts next expected DTS for frame ordering validation and discontinuity detection.
1143
+ * Uses codec-specific logic:
1144
+ * - Audio: Based on sample_rate and frame_size
1145
+ * - Video: Based on framerate or duration
1146
+ *
1147
+ * Handles:
1148
+ * - First timestamp initialization
1149
+ * - Codec-specific duration calculation
1150
+ * - DTS sequence tracking
1151
+ *
1152
+ * @param packet - Packet to process
1153
+ *
1154
+ * @param stream - Stream metadata
1155
+ *
1156
+ * @internal
1157
+ */
1158
+ private dtsPredict;
1159
+ /**
1160
+ * Timestamp Discontinuity Detection.
1161
+ *
1162
+ * Based on FFmpeg's ts_discontinuity_detect().
1163
+ *
1164
+ * Detects and corrects timestamp discontinuities in streams.
1165
+ * Handles two cases:
1166
+ * - Discontinuous formats (MPEG-TS): Apply offset correction
1167
+ * - Continuous formats (MP4): Mark timestamps as invalid
1168
+ *
1169
+ * Handles:
1170
+ * - Format-specific discontinuity handling (AVFMT_TS_DISCONT flag)
1171
+ * - PTS wrap-around detection for streams with limited timestamp bits
1172
+ * - Intra-stream discontinuity detection
1173
+ * - Inter-stream discontinuity detection
1174
+ * - Offset accumulation and application
1175
+ * - copyTs mode with selective correction
1176
+ *
1177
+ * @param packet - Packet to check for discontinuities
1178
+ *
1179
+ * @param stream - Stream metadata
1180
+ *
1181
+ * @internal
1182
+ */
1183
+ private timestampDiscontinuityDetect;
1184
+ /**
1185
+ * Timestamp Discontinuity Processing - main entry point.
1186
+ *
1187
+ * Based on FFmpeg's ts_discontinuity_process().
1188
+ *
1189
+ * Applies accumulated discontinuity offset and detects new discontinuities.
1190
+ * Must be called for every packet before other timestamp processing.
1191
+ *
1192
+ * Handles:
1193
+ * - Applying previously-detected offset to all streams
1194
+ * - Detecting new discontinuities for audio/video streams
1195
+ *
1196
+ * @param packet - Packet to process
1197
+ *
1198
+ * @param stream - Stream metadata
1199
+ *
1200
+ * @internal
1201
+ */
1202
+ private timestampDiscontinuityProcess;
1203
+ /**
1204
+ * Close demuxer and free resources.
1205
+ *
1206
+ * Releases format context and I/O context.
1207
+ * A read waiting for a stalled Readable or custom I/O source is abandoned,
1208
+ * so closing never waits for the source to deliver.
1209
+ * Safe to call multiple times.
1210
+ * Automatically called by Symbol.asyncDispose.
1211
+ *
1212
+ * Direct mapping to avformat_close_input().
1213
+ *
1214
+ * @example
1215
+ * ```typescript
1216
+ * const input = await Demuxer.open('video.mp4');
1217
+ * try {
1218
+ * // Use input
1219
+ * } finally {
1220
+ * await input.close();
1221
+ * }
1222
+ * ```
1223
+ *
1224
+ * @see {@link Symbol.asyncDispose} For automatic cleanup
1225
+ */
1226
+ close(): Promise<void>;
1227
+ /**
1228
+ * Close demuxer and free resources synchronously.
1229
+ * Synchronous version of close.
1230
+ *
1231
+ * Releases format context and I/O context.
1232
+ * A read waiting for a stalled Readable or custom I/O source is abandoned.
1233
+ * Safe to call multiple times.
1234
+ * Automatically called by Symbol.dispose.
1235
+ *
1236
+ * Direct mapping to avformat_close_input().
1237
+ *
1238
+ * @example
1239
+ * ```typescript
1240
+ * const input = Demuxer.openSync('video.mp4');
1241
+ * try {
1242
+ * // Use input
1243
+ * } finally {
1244
+ * input.closeSync();
1245
+ * }
1246
+ * ```
1247
+ *
1248
+ * @see {@link close} For async version
1249
+ */
1250
+ closeSync(): void;
1251
+ /**
1252
+ * Get underlying format context.
1253
+ *
1254
+ * Returns the internal format context for advanced operations.
1255
+ *
1256
+ * @returns Format context
1257
+ *
1258
+ * @internal
1259
+ */
1260
+ getFormatContext(): FormatContext;
1261
+ /**
1262
+ * Dispose of demuxer.
1263
+ *
1264
+ * Implements AsyncDisposable interface for automatic cleanup.
1265
+ * Equivalent to calling close().
1266
+ *
1267
+ * @example
1268
+ * ```typescript
1269
+ * {
1270
+ * await using input = await Demuxer.open('video.mp4');
1271
+ * // Process media...
1272
+ * } // Automatically closed
1273
+ * ```
1274
+ *
1275
+ * @see {@link close} For manual cleanup
1276
+ */
1277
+ [Symbol.asyncDispose](): Promise<void>;
1278
+ /**
1279
+ * Dispose of demuxer synchronously.
1280
+ *
1281
+ * Implements Disposable interface for automatic cleanup.
1282
+ * Equivalent to calling closeSync().
1283
+ *
1284
+ * @example
1285
+ * ```typescript
1286
+ * {
1287
+ * using input = Demuxer.openSync('video.mp4');
1288
+ * // Process media...
1289
+ * } // Automatically closed
1290
+ * ```
1291
+ *
1292
+ * @see {@link closeSync} For manual cleanup
1293
+ */
1294
+ [Symbol.dispose](): void;
1295
+ }