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,1455 @@
1
+ import { AVFLAG_NONE } from '../constants/constants.js';
2
+ import { bindings } from './binding.js';
3
+ import { Codec } from './codec.js';
4
+ import { Dictionary } from './dictionary.js';
5
+ import { InputFormat } from './input-format.js';
6
+ import { OptionMember } from './option.js';
7
+ import { OutputFormat } from './output-format.js';
8
+ import { Stream } from './stream.js';
9
+ /**
10
+ * Container format context for reading/writing multimedia files.
11
+ *
12
+ * Central structure for demuxing (reading) and muxing (writing) media files.
13
+ * Manages streams, packets, metadata, and format-specific operations.
14
+ * Supports both file-based and custom I/O through IOContext.
15
+ * Essential for all file-based media operations.
16
+ *
17
+ * Direct mapping to FFmpeg's AVFormatContext.
18
+ *
19
+ * @example
20
+ * ```typescript
21
+ * import { FormatContext, FFmpegError } from 'node-av';
22
+ * import { AVMEDIA_TYPE_VIDEO } from 'node-av/constants';
23
+ *
24
+ * // Open input file
25
+ * const ctx = new FormatContext();
26
+ * let ret = await ctx.openInput('input.mp4');
27
+ * FFmpegError.throwIfError(ret, 'openInput');
28
+ *
29
+ * ret = await ctx.findStreamInfo();
30
+ * FFmpegError.throwIfError(ret, 'findStreamInfo');
31
+ *
32
+ * // Find video stream
33
+ * const videoIndex = ctx.findBestStream(AVMEDIA_TYPE_VIDEO);
34
+ * if (videoIndex < 0) {
35
+ * throw new Error('No video stream found');
36
+ * }
37
+ *
38
+ * // Read packets
39
+ * const packet = new Packet();
40
+ * packet.alloc();
41
+ * while ((ret = await ctx.readFrame(packet)) >= 0) {
42
+ * if (packet.streamIndex === videoIndex) {
43
+ * // Process video packet
44
+ * }
45
+ * packet.unref();
46
+ * }
47
+ *
48
+ * // Cleanup
49
+ * await ctx.closeInput();
50
+ * ```
51
+ *
52
+ * @see [AVFormatContext](https://ffmpeg.org/doxygen/trunk/structAVFormatContext.html) - FFmpeg Doxygen
53
+ * @see {@link InputFormat} For supported input formats
54
+ * @see {@link OutputFormat} For supported output formats
55
+ * @see {@link Stream} For stream management
56
+ */
57
+ export class FormatContext extends OptionMember {
58
+ _ioContext = null;
59
+ constructor() {
60
+ super(new bindings.FormatContext());
61
+ }
62
+ /**
63
+ * URL or filename of the media.
64
+ *
65
+ * For input: the opened file path.
66
+ * For output: the target file path.
67
+ *
68
+ * Direct mapping to AVFormatContext->url.
69
+ */
70
+ get url() {
71
+ return this.native.url;
72
+ }
73
+ set url(value) {
74
+ this.native.url = value;
75
+ }
76
+ /**
77
+ * Start time of the stream.
78
+ *
79
+ * Position of the first frame in microseconds.
80
+ * AV_NOPTS_VALUE if unknown.
81
+ *
82
+ * Direct mapping to AVFormatContext->start_time.
83
+ */
84
+ get startTime() {
85
+ return this.native.startTime;
86
+ }
87
+ /**
88
+ * Duration of the stream.
89
+ *
90
+ * Total stream duration in microseconds.
91
+ * AV_NOPTS_VALUE if unknown.
92
+ *
93
+ * Direct mapping to AVFormatContext->duration.
94
+ */
95
+ get duration() {
96
+ return this.native.duration;
97
+ }
98
+ /**
99
+ * Total stream bitrate.
100
+ *
101
+ * Bitrate in bits per second.
102
+ * 0 if unknown.
103
+ *
104
+ * Direct mapping to AVFormatContext->bit_rate.
105
+ */
106
+ get bitRate() {
107
+ return this.native.bitRate;
108
+ }
109
+ /**
110
+ * Format-specific flags.
111
+ *
112
+ * Combination of AVFMT_FLAG_* values controlling
113
+ * format behavior (e.g., AVFMT_FLAG_GENPTS).
114
+ *
115
+ * Direct mapping to AVFormatContext->flags.
116
+ */
117
+ get flags() {
118
+ return this.native.flags;
119
+ }
120
+ set flags(value) {
121
+ this.native.flags = value;
122
+ }
123
+ /**
124
+ * Maximum bytes to probe for format detection.
125
+ *
126
+ * Larger values improve format detection accuracy
127
+ * but increase startup time.
128
+ *
129
+ * Direct mapping to AVFormatContext->probesize.
130
+ */
131
+ get probesize() {
132
+ return this.native.probesize;
133
+ }
134
+ set probesize(value) {
135
+ this.native.probesize = value;
136
+ }
137
+ /**
138
+ * Maximum duration to analyze streams.
139
+ *
140
+ * Time in microseconds to spend analyzing streams.
141
+ * Larger values improve stream detection accuracy.
142
+ *
143
+ * Direct mapping to AVFormatContext->max_analyze_duration.
144
+ */
145
+ get maxAnalyzeDuration() {
146
+ return this.native.maxAnalyzeDuration;
147
+ }
148
+ set maxAnalyzeDuration(value) {
149
+ this.native.maxAnalyzeDuration = value;
150
+ }
151
+ /**
152
+ * Maximum buffering duration for interleaving.
153
+ *
154
+ * Specifies the maximum difference between the timestamps of the
155
+ * first and the last packet in the muxing queue, above which libavformat
156
+ * will output a packet regardless of whether it has queued a packet for all
157
+ * the streams.
158
+ *
159
+ * Set to 0 for unlimited buffering
160
+ *
161
+ * Default: 10000000 (10 seconds in microseconds)
162
+ *
163
+ * Muxing only, set before avformat_write_header().
164
+ *
165
+ * Direct mapping to AVFormatContext->max_interleave_delta.
166
+ */
167
+ get maxInterleaveDelta() {
168
+ return this.native.maxInterleaveDelta;
169
+ }
170
+ set maxInterleaveDelta(value) {
171
+ this.native.maxInterleaveDelta = value;
172
+ }
173
+ /**
174
+ * Container metadata.
175
+ *
176
+ * Key-value pairs of metadata (title, author, etc.).
177
+ *
178
+ * Returns a copy of AVFormatContext->metadata - mutating the returned
179
+ * Dictionary does not affect the context. Assign it back to apply changes.
180
+ */
181
+ get metadata() {
182
+ const native = this.native.metadata;
183
+ if (!native) {
184
+ return null;
185
+ }
186
+ const dict = Object.create(Dictionary.prototype);
187
+ dict.native = native;
188
+ return dict;
189
+ }
190
+ set metadata(value) {
191
+ this.native.metadata = value?.getNative() ?? null;
192
+ }
193
+ /**
194
+ * Input format descriptor.
195
+ *
196
+ * Format used for demuxing. Null for output contexts.
197
+ *
198
+ * Direct mapping to AVFormatContext->iformat.
199
+ */
200
+ get iformat() {
201
+ const nativeFormat = this.native.iformat;
202
+ if (!nativeFormat) {
203
+ return null;
204
+ }
205
+ return new InputFormat(nativeFormat);
206
+ }
207
+ /**
208
+ * Output format descriptor.
209
+ *
210
+ * Format used for muxing. Null for input contexts.
211
+ *
212
+ * Direct mapping to AVFormatContext->oformat.
213
+ */
214
+ get oformat() {
215
+ const nativeFormat = this.native.oformat;
216
+ if (!nativeFormat) {
217
+ return null;
218
+ }
219
+ return new OutputFormat(nativeFormat);
220
+ }
221
+ set oformat(value) {
222
+ this.native.oformat = value?.getNative() ?? null;
223
+ }
224
+ /**
225
+ * Custom I/O context.
226
+ *
227
+ * For custom I/O operations instead of file I/O.
228
+ * Assigning a callback-backed context also sets AVFMT_FLAG_CUSTOM_IO so libavformat never closes it.
229
+ * A context opened with open2() is closed once, by whichever comes first: its closep(), which
230
+ * also clears this pb like `avio_closep(&ctx->pb)` in C, or closing or freeing this output context.
231
+ * An IOContext can be the pb of one FormatContext at a time.
232
+ *
233
+ * Direct mapping to AVFormatContext->pb.
234
+ */
235
+ get pb() {
236
+ return this._ioContext;
237
+ }
238
+ set pb(value) {
239
+ this.native.pb = value?.getNative() ?? null;
240
+ this._ioContext = value;
241
+ }
242
+ /**
243
+ * Number of streams in the container.
244
+ *
245
+ * Direct mapping to AVFormatContext->nb_streams.
246
+ */
247
+ get nbStreams() {
248
+ return this.native.nbStreams;
249
+ }
250
+ /**
251
+ * Array of streams in the container.
252
+ *
253
+ * All audio, video, subtitle, and data streams.
254
+ *
255
+ * Direct mapping to AVFormatContext->streams.
256
+ */
257
+ get streams() {
258
+ const nativeStreams = this.native.streams;
259
+ if (!nativeStreams) {
260
+ return [];
261
+ }
262
+ return nativeStreams.map((nativeStream) => new Stream(nativeStream));
263
+ }
264
+ /**
265
+ * Strictness level for standards compliance.
266
+ *
267
+ * FF_COMPLIANCE_* value controlling how strictly
268
+ * to follow specifications.
269
+ *
270
+ * Direct mapping to AVFormatContext->strict_std_compliance.
271
+ */
272
+ get strictStdCompliance() {
273
+ return this.native.strictStdCompliance;
274
+ }
275
+ set strictStdCompliance(value) {
276
+ this.native.strictStdCompliance = value;
277
+ }
278
+ /**
279
+ * Maximum number of streams.
280
+ *
281
+ * Limit on stream count for security/resource reasons.
282
+ *
283
+ * Direct mapping to AVFormatContext->max_streams.
284
+ */
285
+ get maxStreams() {
286
+ return this.native.maxStreams;
287
+ }
288
+ set maxStreams(value) {
289
+ this.native.maxStreams = value;
290
+ }
291
+ /**
292
+ * Number of programs.
293
+ *
294
+ * For containers with multiple programs (e.g., MPEG-TS).
295
+ *
296
+ * Direct mapping to AVFormatContext->nb_programs.
297
+ */
298
+ get nbPrograms() {
299
+ return this.native.nbPrograms;
300
+ }
301
+ /**
302
+ * Number of bytes read/written through I/O context.
303
+ *
304
+ * Direct mapping to avio_tell(AVFormatContext->pb).
305
+ */
306
+ get pbBytes() {
307
+ return this.native.pbBytes;
308
+ }
309
+ /**
310
+ * Format probe score.
311
+ *
312
+ * Confidence score from format detection (0-100).
313
+ * Higher values indicate more confident detection.
314
+ *
315
+ * Direct mapping to AVFormatContext->probe_score.
316
+ */
317
+ get probeScore() {
318
+ return this.native.probeScore;
319
+ }
320
+ /**
321
+ * Allocate a format context.
322
+ *
323
+ * Allocates the context structure. Usually not needed
324
+ * as openInput/allocOutputContext2 handle this.
325
+ *
326
+ * Direct mapping to avformat_alloc_context().
327
+ *
328
+ * @example
329
+ * ```typescript
330
+ * const ctx = new FormatContext();
331
+ * ctx.allocContext();
332
+ * // Context is now allocated
333
+ * ```
334
+ */
335
+ allocContext() {
336
+ this.native.allocContext();
337
+ }
338
+ /**
339
+ * Allocate an output format context.
340
+ *
341
+ * Allocates and configures context for writing.
342
+ * Format is determined by parameters in priority order.
343
+ *
344
+ * Direct mapping to avformat_alloc_output_context2().
345
+ *
346
+ * @param oformat - Specific output format to use
347
+ *
348
+ * @param formatName - Format name (e.g., 'mp4', 'mkv')
349
+ *
350
+ * @param filename - Filename to guess format from extension
351
+ *
352
+ * @returns 0 on success, negative AVERROR on error:
353
+ * - AVERROR_ENOMEM: Memory allocation failure
354
+ * - AVERROR_EINVAL: Invalid parameters
355
+ *
356
+ * @example
357
+ * ```typescript
358
+ * import { FFmpegError } from 'node-av';
359
+ *
360
+ * const ctx = new FormatContext();
361
+ * const ret = ctx.allocOutputContext2(null, 'mp4', 'output.mp4');
362
+ * FFmpegError.throwIfError(ret, 'allocOutputContext2');
363
+ * ```
364
+ *
365
+ * @see {@link openOutput} To open output file
366
+ * @see {@link writeHeader} To write file header
367
+ */
368
+ allocOutputContext2(oformat, formatName, filename) {
369
+ if (!oformat && !formatName && !filename) {
370
+ throw new Error('At least one of oformat, formatName, or filename must be specified');
371
+ }
372
+ return this.native.allocOutputContext2(oformat?.getNative() ?? null, formatName, filename);
373
+ }
374
+ /**
375
+ * Free the format context.
376
+ *
377
+ * Releases all resources. The context becomes invalid.
378
+ *
379
+ * Direct mapping to avformat_free_context().
380
+ *
381
+ * @example
382
+ * ```typescript
383
+ * ctx.freeContext();
384
+ * // Context is now invalid
385
+ * ```
386
+ *
387
+ * @see {@link Symbol.asyncDispose} For automatic cleanup
388
+ */
389
+ freeContext() {
390
+ this.native.freeContext();
391
+ }
392
+ /**
393
+ * Open output file for writing.
394
+ *
395
+ * Opens the output file specified in url.
396
+ * Must call allocOutputContext2 first.
397
+ *
398
+ * Direct mapping to avio_open2().
399
+ *
400
+ * @returns 0 on success, negative AVERROR on error:
401
+ * - AVERROR_ENOENT: File not found
402
+ * - AVERROR_EACCES: Permission denied
403
+ * - AVERROR_EIO: I/O error
404
+ *
405
+ * @example
406
+ * ```typescript
407
+ * import { FFmpegError } from 'node-av';
408
+ *
409
+ * const ret = await ctx.openOutput();
410
+ * FFmpegError.throwIfError(ret, 'openOutput');
411
+ * ```
412
+ *
413
+ * @see {@link allocOutputContext2} Must be called first
414
+ * @see {@link closeOutput} To close output
415
+ */
416
+ async openOutput() {
417
+ return await this.native.openOutput();
418
+ }
419
+ /**
420
+ * Open output file synchronously.
421
+ * Synchronous version of openOutput.
422
+ *
423
+ * Opens output file for writing.
424
+ * I/O context must be set before calling.
425
+ *
426
+ * Direct mapping to avio_open2().
427
+ *
428
+ * @returns 0 on success, negative AVERROR on error:
429
+ * - AVERROR(EIO): I/O error
430
+ * - AVERROR(ENOMEM): Memory allocation failure
431
+ *
432
+ * @example
433
+ * ```typescript
434
+ * import { FFmpegError } from 'node-av';
435
+ *
436
+ * const ret = ctx.openOutputSync();
437
+ * FFmpegError.throwIfError(ret, 'openOutputSync');
438
+ * ```
439
+ *
440
+ * @see {@link openOutput} For async version
441
+ */
442
+ openOutputSync() {
443
+ return this.native.openOutputSync();
444
+ }
445
+ /**
446
+ * Close output file.
447
+ *
448
+ * Closes the output file and releases I/O resources.
449
+ *
450
+ * Direct mapping to avio_closep().
451
+ *
452
+ * @returns Promise that resolves when closed
453
+ *
454
+ * @example
455
+ * ```typescript
456
+ * await ctx.closeOutput();
457
+ * // Output file closed
458
+ * ```
459
+ *
460
+ * @see {@link openOutput} To open output
461
+ */
462
+ async closeOutput() {
463
+ return await this.native.closeOutput();
464
+ }
465
+ /**
466
+ * Close output file synchronously.
467
+ * Synchronous version of closeOutput.
468
+ *
469
+ * Closes the output file and releases I/O resources.
470
+ *
471
+ * Direct mapping to avio_closep().
472
+ *
473
+ * @example
474
+ * ```typescript
475
+ * ctx.closeOutputSync();
476
+ * // Output file closed
477
+ * ```
478
+ *
479
+ * @see {@link closeOutput} For async version
480
+ */
481
+ closeOutputSync() {
482
+ this.native.closeOutputSync();
483
+ }
484
+ /**
485
+ * Open input file for reading.
486
+ *
487
+ * Opens and probes the input file, detecting format automatically
488
+ * unless specified.
489
+ *
490
+ * Direct mapping to avformat_open_input().
491
+ *
492
+ * @param url - URL or file path to open
493
+ *
494
+ * @param fmt - Force specific input format (null for auto-detect)
495
+ *
496
+ * @param options - Format-specific options
497
+ *
498
+ * @returns 0 on success, negative AVERROR on error:
499
+ * - AVERROR_ENOENT: File not found
500
+ * - AVERROR_INVALIDDATA: Invalid file format
501
+ * - AVERROR_EIO: I/O error
502
+ *
503
+ * @example
504
+ * ```typescript
505
+ * import { FFmpegError } from 'node-av';
506
+ *
507
+ * const ret = await ctx.openInput('input.mp4');
508
+ * FFmpegError.throwIfError(ret, 'openInput');
509
+ * ```
510
+ *
511
+ * @see {@link findStreamInfo} To analyze streams after opening
512
+ * @see {@link closeInput} To close input
513
+ */
514
+ async openInput(url, fmt = null, options = null) {
515
+ return await this.native.openInput(url, fmt?.getNative() ?? null, options?.getNative() ?? null);
516
+ }
517
+ /**
518
+ * Open an input file or URL synchronously.
519
+ * Synchronous version of openInput.
520
+ *
521
+ * Opens a media file or stream for reading.
522
+ * The format is auto-detected if not specified.
523
+ *
524
+ * Direct mapping to avformat_open_input().
525
+ *
526
+ * @param url - File path or URL to open
527
+ *
528
+ * @param fmt - Force specific format (null for auto-detect)
529
+ *
530
+ * @param options - Format-specific options
531
+ *
532
+ * @returns 0 on success, negative AVERROR on error:
533
+ * - AVERROR_EINVAL: Invalid arguments
534
+ * - AVERROR(EIO): I/O error
535
+ * - AVERROR(ENOMEM): Memory allocation failure
536
+ *
537
+ * @example
538
+ * ```typescript
539
+ * import { FFmpegError } from 'node-av';
540
+ *
541
+ * const ret = ctx.openInputSync('input.mp4');
542
+ * FFmpegError.throwIfError(ret, 'openInputSync');
543
+ * ```
544
+ *
545
+ * @see {@link openInput} For async version
546
+ */
547
+ openInputSync(url, fmt = null, options = null) {
548
+ return this.native.openInputSync(url, fmt?.getNative() ?? null, options?.getNative() ?? null);
549
+ }
550
+ /**
551
+ * Close an input format context.
552
+ *
553
+ * Closes input file and releases resources.
554
+ * A pb with JS callbacks stops serving this input: a read, seek or open
555
+ * still waiting for one of its callbacks fails with AVERROR_EXIT, and its
556
+ * callbacks are not called again, so a stalled source cannot block the close.
557
+ *
558
+ * Direct mapping to avformat_close_input().
559
+ *
560
+ * @param detachPb - Forget a caller-owned pb (custom IOContext) once the
561
+ * reader thread has stopped, so it is not closed with the input. Setting
562
+ * `pb = null` yourself throws while an async reader is active.
563
+ *
564
+ * @returns Promise that resolves when closed
565
+ *
566
+ * @example
567
+ * ```typescript
568
+ * await ctx.closeInput();
569
+ * // Input closed and context freed
570
+ * ```
571
+ *
572
+ * @see {@link openInput} To open input
573
+ */
574
+ async closeInput(detachPb = false) {
575
+ return await this.native.closeInput(detachPb);
576
+ }
577
+ /**
578
+ * Close an input format context synchronously.
579
+ * Synchronous version of closeInput.
580
+ *
581
+ * Closes input file and releases resources.
582
+ * A pb with JS callbacks stops serving this input (see closeInput).
583
+ *
584
+ * Direct mapping to avformat_close_input().
585
+ *
586
+ * @example
587
+ * ```typescript
588
+ * ctx.closeInputSync();
589
+ * // Input closed and context freed
590
+ * ```
591
+ *
592
+ * @see {@link closeInput} For async version
593
+ *
594
+ * @param detachPb - Forget a caller-owned pb once the reader stopped (see closeInput)
595
+ */
596
+ closeInputSync(detachPb = false) {
597
+ this.native.closeInputSync(detachPb);
598
+ }
599
+ /**
600
+ * Analyze streams to get stream info.
601
+ *
602
+ * Reads packet headers to fill in stream information.
603
+ * Should be called after openInput for accurate stream data.
604
+ *
605
+ * Direct mapping to avformat_find_stream_info().
606
+ *
607
+ * @param options - Per-stream options array
608
+ *
609
+ * @returns >=0 on success, negative AVERROR on error:
610
+ * - AVERROR_EOF: End of file reached
611
+ * - AVERROR_ENOMEM: Memory allocation failure
612
+ *
613
+ * @example
614
+ * ```typescript
615
+ * import { FFmpegError } from 'node-av';
616
+ *
617
+ * const ret = await ctx.findStreamInfo();
618
+ * FFmpegError.throwIfError(ret, 'findStreamInfo');
619
+ * console.log(`Found ${ctx.nbStreams} streams`);
620
+ * ```
621
+ *
622
+ * @see {@link findStreamInfoSync} For synchronous version
623
+ * @see {@link openInput} Must be called first
624
+ */
625
+ async findStreamInfo(options = null) {
626
+ return await this.native.findStreamInfo(options?.map((d) => d.getNative()) ?? null);
627
+ }
628
+ /**
629
+ * Analyze streams to get stream info synchronously.
630
+ * Synchronous version of findStreamInfo.
631
+ *
632
+ * Reads packet headers to fill in stream information.
633
+ * Should be called after openInputSync for accurate stream data.
634
+ *
635
+ * Direct mapping to avformat_find_stream_info().
636
+ *
637
+ * @param options - Per-stream options array
638
+ *
639
+ * @returns >=0 on success, negative AVERROR on error:
640
+ * - AVERROR_EOF: End of file reached
641
+ * - AVERROR_ENOMEM: Memory allocation failure
642
+ *
643
+ * @example
644
+ * ```typescript
645
+ * import { FFmpegError } from 'node-av';
646
+ *
647
+ * const ret = ctx.findStreamInfoSync();
648
+ * FFmpegError.throwIfError(ret, 'findStreamInfoSync');
649
+ * console.log(`Found ${ctx.nbStreams} streams`);
650
+ * ```
651
+ *
652
+ * @see {@link findStreamInfo} For async version
653
+ */
654
+ findStreamInfoSync(options = null) {
655
+ return this.native.findStreamInfoSync(options?.map((d) => d.getNative()) ?? null);
656
+ }
657
+ /**
658
+ * Read next packet from the input.
659
+ *
660
+ * Reads and returns the next packet in the stream.
661
+ * Packet must be unreferenced after use.
662
+ *
663
+ * Direct mapping to av_read_frame().
664
+ *
665
+ * @param pkt - Packet to read into
666
+ *
667
+ * @returns 0 on success, negative AVERROR on error:
668
+ * - AVERROR_EOF: End of file
669
+ * - AVERROR_EXIT: Aborted by interrupt() or closeInput()
670
+ *
671
+ * The first call starts the context's own reader thread, which is the only
672
+ * thread touching the input from then on: it blocks in av_read_frame(),
673
+ * retries EAGAIN itself and hands packets over through a bounded queue, so
674
+ * a waiting read never occupies a libuv threadpool thread. seekFrame(),
675
+ * seekFile(), sendRTSPPacket() and findStreamInfo() run on that thread
676
+ * between two reads; the sync variants throw while it is active.
677
+ *
678
+ * @example
679
+ * ```typescript
680
+ * import { FFmpegError } from 'node-av';
681
+ * import { AVERROR_EOF } from 'node-av';
682
+ *
683
+ * const packet = new Packet();
684
+ * packet.alloc();
685
+ *
686
+ * let ret;
687
+ * while ((ret = await ctx.readFrame(packet)) >= 0) {
688
+ * // Process packet
689
+ * console.log(`Stream ${packet.streamIndex}, PTS: ${packet.pts}`);
690
+ * packet.unref();
691
+ * }
692
+ *
693
+ * if (ret !== AVERROR_EOF) {
694
+ * FFmpegError.throwIfError(ret, 'readFrame');
695
+ * }
696
+ * ```
697
+ *
698
+ * @see {@link seekFrame} To seek before reading
699
+ */
700
+ async readFrame(pkt) {
701
+ return await this.native.readFrame(pkt.getNative());
702
+ }
703
+ /**
704
+ * Read next packet from the input synchronously.
705
+ * Synchronous version of readFrame.
706
+ *
707
+ * Reads and returns the next packet in the stream.
708
+ * Packet must be unreferenced after use.
709
+ *
710
+ * Direct mapping to av_read_frame().
711
+ *
712
+ * @param pkt - Packet to read into
713
+ *
714
+ * @returns 0 on success, negative AVERROR on error:
715
+ * - AVERROR_EOF: End of file
716
+ * - AVERROR_EAGAIN: Temporarily unavailable
717
+ *
718
+ * @example
719
+ * ```typescript
720
+ * import { FFmpegError } from 'node-av';
721
+ * import { AVERROR_EOF } from 'node-av';
722
+ *
723
+ * const packet = new Packet();
724
+ * packet.alloc();
725
+ *
726
+ * let ret;
727
+ * while ((ret = ctx.readFrameSync(packet)) >= 0) {
728
+ * // Process packet
729
+ * console.log(`Stream ${packet.streamIndex}, PTS: ${packet.pts}`);
730
+ * packet.unref();
731
+ * }
732
+ *
733
+ * if (ret !== AVERROR_EOF) {
734
+ * FFmpegError.throwIfError(ret, 'readFrameSync');
735
+ * }
736
+ * ```
737
+ *
738
+ * @see {@link readFrame} For async version
739
+ */
740
+ readFrameSync(pkt) {
741
+ return this.native.readFrameSync(pkt.getNative());
742
+ }
743
+ /**
744
+ * Seek to timestamp in stream.
745
+ *
746
+ * Seeks to the keyframe at or before the given timestamp.
747
+ *
748
+ * Direct mapping to av_seek_frame().
749
+ *
750
+ * @param streamIndex - Stream to seek in (-1 for default)
751
+ *
752
+ * @param timestamp - Target timestamp in stream time base
753
+ *
754
+ * @param flags - Seek flags (AVSEEK_FLAG_*)
755
+ *
756
+ * @returns >=0 on success, negative AVERROR on error:
757
+ * - AVERROR_EINVAL: Invalid parameters
758
+ * - AVERROR_EOF: Seek beyond file
759
+ *
760
+ * @example
761
+ * ```typescript
762
+ * import { FFmpegError } from 'node-av';
763
+ * import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
764
+ *
765
+ * // Seek to 10 seconds (assuming 1/1000 time base)
766
+ * const ret = await ctx.seekFrame(videoStreamIndex, 10000n, AVSEEK_FLAG_BACKWARD);
767
+ * FFmpegError.throwIfError(ret, 'seekFrame');
768
+ * ```
769
+ *
770
+ * @see {@link seekFile} For more precise seeking
771
+ */
772
+ async seekFrame(streamIndex, timestamp, flags = AVFLAG_NONE) {
773
+ return await this.native.seekFrame(streamIndex, timestamp, flags);
774
+ }
775
+ /**
776
+ * Seek to timestamp in stream synchronously.
777
+ * Synchronous version of seekFrame.
778
+ *
779
+ * Seeks to closest keyframe at or before timestamp.
780
+ * Timestamp is in stream timebase units.
781
+ *
782
+ * Direct mapping to av_seek_frame().
783
+ *
784
+ * @param streamIndex - Stream to seek in (-1 for default)
785
+ *
786
+ * @param timestamp - Target timestamp in stream timebase
787
+ *
788
+ * @param flags - Seek flags (AVSEEK_FLAG_*)
789
+ *
790
+ * @returns >=0 on success, negative AVERROR on error:
791
+ * - AVERROR_EINVAL: Invalid arguments
792
+ * - AVERROR(EIO): I/O error
793
+ *
794
+ * @example
795
+ * ```typescript
796
+ * import { FFmpegError } from 'node-av';
797
+ * import { AVSEEK_FLAG_BACKWARD } from 'node-av/constants';
798
+ *
799
+ * // Seek to 10 seconds
800
+ * const timestamp = 10n * 1000000n; // Assuming microsecond timebase
801
+ * const ret = ctx.seekFrameSync(-1, timestamp, AVSEEK_FLAG_BACKWARD);
802
+ * FFmpegError.throwIfError(ret, 'seekFrameSync');
803
+ * ```
804
+ *
805
+ * @see {@link seekFrame} For async version
806
+ */
807
+ seekFrameSync(streamIndex, timestamp, flags = AVFLAG_NONE) {
808
+ return this.native.seekFrameSync(streamIndex, timestamp, flags);
809
+ }
810
+ /**
811
+ * Seek to timestamp with bounds.
812
+ *
813
+ * More precise seeking with min/max timestamp bounds.
814
+ *
815
+ * Direct mapping to avformat_seek_file().
816
+ *
817
+ * @param streamIndex - Stream to seek in (-1 for default)
818
+ *
819
+ * @param minTs - Minimum acceptable timestamp
820
+ *
821
+ * @param ts - Target timestamp
822
+ *
823
+ * @param maxTs - Maximum acceptable timestamp
824
+ *
825
+ * @param flags - Seek flags
826
+ *
827
+ * @returns >=0 on success, negative AVERROR on error
828
+ *
829
+ * @example
830
+ * ```typescript
831
+ * import { FFmpegError } from 'node-av';
832
+ *
833
+ * // Seek to 10s with 0.5s tolerance
834
+ * const target = 10000n;
835
+ * const ret = await ctx.seekFile(
836
+ * -1,
837
+ * target - 500n,
838
+ * target,
839
+ * target + 500n
840
+ * );
841
+ * FFmpegError.throwIfError(ret, 'seekFile');
842
+ * ```
843
+ *
844
+ * @see {@link seekFileSync} For synchronous version
845
+ * @see {@link seekFrame} For simpler seeking
846
+ */
847
+ async seekFile(streamIndex, minTs, ts, maxTs, flags = AVFLAG_NONE) {
848
+ return await this.native.seekFile(streamIndex, minTs, ts, maxTs, flags);
849
+ }
850
+ /**
851
+ * Seek to timestamp with bounds synchronously.
852
+ * Synchronous version of seekFile.
853
+ *
854
+ * More precise seeking with min/max timestamp bounds.
855
+ *
856
+ * Direct mapping to avformat_seek_file().
857
+ *
858
+ * @param streamIndex - Stream to seek in (-1 for default)
859
+ *
860
+ * @param minTs - Minimum acceptable timestamp
861
+ *
862
+ * @param ts - Target timestamp
863
+ *
864
+ * @param maxTs - Maximum acceptable timestamp
865
+ *
866
+ * @param flags - Seek flags
867
+ *
868
+ * @returns >=0 on success, negative AVERROR on error
869
+ *
870
+ * @example
871
+ * ```typescript
872
+ * import { FFmpegError } from 'node-av';
873
+ *
874
+ * // Seek to 10s with 0.5s tolerance
875
+ * const target = 10000n;
876
+ * const ret = ctx.seekFileSync(
877
+ * -1,
878
+ * target - 500n,
879
+ * target,
880
+ * target + 500n
881
+ * );
882
+ * FFmpegError.throwIfError(ret, 'seekFileSync');
883
+ * ```
884
+ *
885
+ * @see {@link seekFile} For async version
886
+ * @see {@link seekFrameSync} For simpler seeking
887
+ */
888
+ seekFileSync(streamIndex, minTs, ts, maxTs, flags = AVFLAG_NONE) {
889
+ return this.native.seekFileSync(streamIndex, minTs, ts, maxTs, flags);
890
+ }
891
+ /**
892
+ * Write file header.
893
+ *
894
+ * Writes the file header and initializes output.
895
+ * Must be called before writing packets.
896
+ *
897
+ * Direct mapping to avformat_write_header().
898
+ *
899
+ * @param options - Muxer-specific options
900
+ *
901
+ * @returns 0 on success, negative AVERROR on error:
902
+ * - AVERROR_EINVAL: Invalid parameters
903
+ * - AVERROR_EIO: I/O error
904
+ *
905
+ * @example
906
+ * ```typescript
907
+ * import { FFmpegError } from 'node-av';
908
+ *
909
+ * const ret = await ctx.writeHeader();
910
+ * FFmpegError.throwIfError(ret, 'writeHeader');
911
+ * // Now ready to write packets
912
+ * ```
913
+ *
914
+ * @see {@link writeTrailer} To finalize file
915
+ * @see {@link writeFrame} To write packets
916
+ */
917
+ async writeHeader(options = null) {
918
+ return await this.native.writeHeader(options?.getNative() ?? null);
919
+ }
920
+ /**
921
+ * Write file header synchronously.
922
+ * Synchronous version of writeHeader.
923
+ *
924
+ * Writes format header to output file.
925
+ * Must be called before writing packets.
926
+ *
927
+ * Direct mapping to avformat_write_header().
928
+ *
929
+ * @param options - Muxer-specific options
930
+ *
931
+ * @returns 0 on success, negative AVERROR on error:
932
+ * - AVERROR_EINVAL: Invalid parameters
933
+ *
934
+ * @example
935
+ * ```typescript
936
+ * import { FFmpegError } from 'node-av';
937
+ *
938
+ * const ret = ctx.writeHeaderSync();
939
+ * FFmpegError.throwIfError(ret, 'writeHeaderSync');
940
+ * ```
941
+ *
942
+ * @see {@link writeHeader} For async version
943
+ */
944
+ writeHeaderSync(options = null) {
945
+ return this.native.writeHeaderSync(options?.getNative() ?? null);
946
+ }
947
+ /**
948
+ * Write packet to output.
949
+ *
950
+ * Writes a packet directly without interleaving.
951
+ * Caller must handle correct interleaving.
952
+ *
953
+ * Direct mapping to av_write_frame().
954
+ *
955
+ * @param pkt - Packet to write (null to flush)
956
+ *
957
+ * @returns 0 on success, negative AVERROR on error:
958
+ * - AVERROR_EINVAL: Invalid packet
959
+ * - AVERROR_EIO: I/O error
960
+ *
961
+ * @example
962
+ * ```typescript
963
+ * import { FFmpegError } from 'node-av';
964
+ *
965
+ * const ret = await ctx.writeFrame(packet);
966
+ * FFmpegError.throwIfError(ret, 'writeFrame');
967
+ * ```
968
+ *
969
+ * @see {@link interleavedWriteFrame} For automatic interleaving
970
+ */
971
+ async writeFrame(pkt) {
972
+ return await this.native.writeFrame(pkt ? pkt.getNative() : null);
973
+ }
974
+ /**
975
+ * Write packet to output synchronously.
976
+ * Synchronous version of writeFrame.
977
+ *
978
+ * Writes a packet directly without interleaving.
979
+ * Caller must handle correct interleaving.
980
+ *
981
+ * Direct mapping to av_write_frame().
982
+ *
983
+ * @param pkt - Packet to write (null to flush)
984
+ *
985
+ * @returns 0 on success, negative AVERROR on error
986
+ *
987
+ * @example
988
+ * ```typescript
989
+ * import { FFmpegError } from 'node-av';
990
+ *
991
+ * const ret = ctx.writeFrameSync(packet);
992
+ * FFmpegError.throwIfError(ret, 'writeFrameSync');
993
+ * ```
994
+ *
995
+ * @see {@link writeFrame} For async version
996
+ */
997
+ writeFrameSync(pkt) {
998
+ return this.native.writeFrameSync(pkt ? pkt.getNative() : null);
999
+ }
1000
+ /**
1001
+ * Write packet with automatic interleaving.
1002
+ *
1003
+ * Writes packet with proper interleaving for muxing.
1004
+ * Preferred method for writing packets.
1005
+ *
1006
+ * Direct mapping to av_interleaved_write_frame().
1007
+ *
1008
+ * @param pkt - Packet to write (null to flush)
1009
+ *
1010
+ * @returns 0 on success, negative AVERROR on error:
1011
+ * - AVERROR_EINVAL: Invalid packet
1012
+ * - AVERROR_EIO: I/O error
1013
+ *
1014
+ * @example
1015
+ * ```typescript
1016
+ * import { FFmpegError } from 'node-av';
1017
+ *
1018
+ * // Write with proper interleaving
1019
+ * const ret = await ctx.interleavedWriteFrame(packet);
1020
+ * FFmpegError.throwIfError(ret, 'interleavedWriteFrame');
1021
+ *
1022
+ * // Flush buffered packets
1023
+ * await ctx.interleavedWriteFrame(null);
1024
+ * ```
1025
+ *
1026
+ * @see {@link writeFrame} For direct writing
1027
+ */
1028
+ async interleavedWriteFrame(pkt) {
1029
+ return await this.native.interleavedWriteFrame(pkt ? pkt.getNative() : null);
1030
+ }
1031
+ /**
1032
+ * Write packet with automatic interleaving synchronously.
1033
+ * Synchronous version of interleavedWriteFrame.
1034
+ *
1035
+ * Writes packet with proper interleaving for muxing.
1036
+ * Preferred method for writing packets.
1037
+ *
1038
+ * Direct mapping to av_interleaved_write_frame().
1039
+ *
1040
+ * @param pkt - Packet to write (null to flush)
1041
+ *
1042
+ * @returns 0 on success, negative AVERROR on error:
1043
+ * - AVERROR_EINVAL: Invalid parameters
1044
+ * - AVERROR(EIO): I/O error
1045
+ *
1046
+ * @example
1047
+ * ```typescript
1048
+ * import { FFmpegError } from 'node-av';
1049
+ *
1050
+ * // Write packet
1051
+ * const ret = ctx.interleavedWriteFrameSync(packet);
1052
+ * FFmpegError.throwIfError(ret, 'interleavedWriteFrameSync');
1053
+ *
1054
+ * // Flush interleaved packets
1055
+ * ctx.interleavedWriteFrameSync(null);
1056
+ * ```
1057
+ *
1058
+ * @see {@link interleavedWriteFrame} For async version
1059
+ */
1060
+ interleavedWriteFrameSync(pkt) {
1061
+ return this.native.interleavedWriteFrameSync(pkt ? pkt.getNative() : null);
1062
+ }
1063
+ /**
1064
+ * Write file trailer.
1065
+ *
1066
+ * Finalizes the output file, writing index and metadata.
1067
+ * Must be called to properly close output files.
1068
+ *
1069
+ * Direct mapping to av_write_trailer().
1070
+ *
1071
+ * @returns 0 on success, negative AVERROR on error:
1072
+ * - AVERROR_EIO: I/O error
1073
+ *
1074
+ * @example
1075
+ * ```typescript
1076
+ * import { FFmpegError } from 'node-av';
1077
+ *
1078
+ * const ret = await ctx.writeTrailer();
1079
+ * FFmpegError.throwIfError(ret, 'writeTrailer');
1080
+ * // File is now finalized
1081
+ * ```
1082
+ *
1083
+ * @see {@link writeHeader} Must be called first
1084
+ */
1085
+ async writeTrailer() {
1086
+ return await this.native.writeTrailer();
1087
+ }
1088
+ /**
1089
+ * Write file trailer synchronously.
1090
+ * Synchronous version of writeTrailer.
1091
+ *
1092
+ * Finalizes the output file, writing index and metadata.
1093
+ * Must be called to properly close output files.
1094
+ *
1095
+ * Direct mapping to av_write_trailer().
1096
+ *
1097
+ * @returns 0 on success, negative AVERROR on error
1098
+ *
1099
+ * @example
1100
+ * ```typescript
1101
+ * import { FFmpegError } from 'node-av';
1102
+ *
1103
+ * const ret = ctx.writeTrailerSync();
1104
+ * FFmpegError.throwIfError(ret, 'writeTrailerSync');
1105
+ * // File is now finalized
1106
+ * ```
1107
+ *
1108
+ * @see {@link writeTrailer} For async version
1109
+ */
1110
+ writeTrailerSync() {
1111
+ return this.native.writeTrailerSync();
1112
+ }
1113
+ /**
1114
+ * Flush buffered data.
1115
+ *
1116
+ * Flushes any buffered packets in muxers.
1117
+ *
1118
+ * Direct mapping to avio_flush().
1119
+ *
1120
+ * @example
1121
+ * ```typescript
1122
+ * await ctx.flush();
1123
+ * // Buffered data written to output
1124
+ * ```
1125
+ */
1126
+ async flush() {
1127
+ await this.native.flush();
1128
+ }
1129
+ /**
1130
+ * Flush buffered data synchronously.
1131
+ * Synchronous version of flush.
1132
+ *
1133
+ * Flushes any buffered packets in muxers.
1134
+ *
1135
+ * Direct mapping to avio_flush().
1136
+ *
1137
+ * @example
1138
+ * ```typescript
1139
+ * ctx.flushSync();
1140
+ * // Buffered data written to output
1141
+ * ```
1142
+ *
1143
+ * @see {@link flush} For async version
1144
+ */
1145
+ flushSync() {
1146
+ this.native.flushSync();
1147
+ }
1148
+ /**
1149
+ * Print format information.
1150
+ *
1151
+ * Dumps human-readable format info to stderr.
1152
+ * Useful for debugging.
1153
+ *
1154
+ * Direct mapping to av_dump_format().
1155
+ *
1156
+ * @param index - Stream index to highlight (-1 for none)
1157
+ *
1158
+ * @param url - URL to display
1159
+ *
1160
+ * @param isOutput - True for output format, false for input
1161
+ *
1162
+ * @example
1163
+ * ```typescript
1164
+ * // Dump input format info
1165
+ * ctx.dumpFormat(0, 'input.mp4', false);
1166
+ *
1167
+ * // Dump output format info
1168
+ * ctx.dumpFormat(0, 'output.mp4', true);
1169
+ * ```
1170
+ */
1171
+ dumpFormat(index, url, isOutput) {
1172
+ this.native.dumpFormat(index, url, isOutput);
1173
+ }
1174
+ findBestStream(type, wantedStreamNb = -1, relatedStream = -1, wantDecoder = false, flags = 0) {
1175
+ if (wantDecoder === true) {
1176
+ const result = this.native.findBestStream(type, wantedStreamNb, relatedStream, true, flags ?? 0);
1177
+ if (typeof result === 'object' && result !== null) {
1178
+ // Wrap the native decoder in a Codec instance
1179
+ return {
1180
+ streamIndex: result.streamIndex,
1181
+ decoder: Codec.fromNative(result.decoder),
1182
+ };
1183
+ }
1184
+ // If not an object, return as error code
1185
+ return { streamIndex: result, decoder: null };
1186
+ }
1187
+ return this.native.findBestStream(type, wantedStreamNb, relatedStream, false, flags ?? 0);
1188
+ }
1189
+ /**
1190
+ * Add a new stream to output context.
1191
+ *
1192
+ * Creates a new stream for writing.
1193
+ *
1194
+ * Direct mapping to avformat_new_stream().
1195
+ *
1196
+ * @param c - Codec for the stream (optional)
1197
+ *
1198
+ * @returns New stream instance
1199
+ *
1200
+ * @example
1201
+ * ```typescript
1202
+ * import { Codec } from 'node-av';
1203
+ * import { AV_CODEC_ID_H264 } from 'node-av/constants';
1204
+ *
1205
+ * const codec = Codec.findEncoder(AV_CODEC_ID_H264);
1206
+ * const stream = ctx.newStream(codec);
1207
+ * stream.id = ctx.nbStreams - 1;
1208
+ * ```
1209
+ *
1210
+ * @see {@link Stream} For stream configuration
1211
+ */
1212
+ newStream(c = null) {
1213
+ const nativeStream = this.native.newStream(c?.getNative() ?? null);
1214
+ return new Stream(nativeStream);
1215
+ }
1216
+ /**
1217
+ * Set format flags.
1218
+ *
1219
+ * Sets one or more flags using bitwise OR. Allows setting multiple flags
1220
+ * without manually performing bitwise operations.
1221
+ *
1222
+ * @param flags - One or more flag values to set
1223
+ *
1224
+ * @example
1225
+ * ```typescript
1226
+ * import { AVFMT_FLAG_GENPTS, AVFMT_FLAG_IGNIDX } from 'node-av/constants';
1227
+ *
1228
+ * // Set multiple flags at once
1229
+ * formatContext.setFlags(AVFMT_FLAG_GENPTS, AVFMT_FLAG_IGNIDX);
1230
+ * ```
1231
+ *
1232
+ * @see {@link clearFlags} To unset flags
1233
+ * @see {@link hasFlags} To check flags
1234
+ * @see {@link flags} For direct flag access
1235
+ */
1236
+ setFlags(...flags) {
1237
+ for (const flag of flags) {
1238
+ this.native.flags = (this.native.flags | flag);
1239
+ }
1240
+ }
1241
+ /**
1242
+ * Clear format flags.
1243
+ *
1244
+ * Clears one or more flags using bitwise AND NOT. Allows clearing multiple
1245
+ * flags without manually performing bitwise operations.
1246
+ *
1247
+ * @param flags - One or more flag values to clear
1248
+ *
1249
+ * @example
1250
+ * ```typescript
1251
+ * import { AVFMT_FLAG_IGNIDX } from 'node-av/constants';
1252
+ *
1253
+ * // Clear specific flag
1254
+ * formatContext.clearFlags(AVFMT_FLAG_IGNIDX);
1255
+ * ```
1256
+ *
1257
+ * @see {@link setFlags} To set flags
1258
+ * @see {@link hasFlags} To check flags
1259
+ * @see {@link flags} For direct flag access
1260
+ */
1261
+ clearFlags(...flags) {
1262
+ for (const flag of flags) {
1263
+ this.native.flags = (this.native.flags & ~flag);
1264
+ }
1265
+ }
1266
+ /**
1267
+ * Check if format context has specific flags.
1268
+ *
1269
+ * Tests whether all specified flags are set using bitwise AND.
1270
+ *
1271
+ * @param flags - One or more flag values to check
1272
+ *
1273
+ * @returns true if all specified flags are set, false otherwise
1274
+ *
1275
+ * @example
1276
+ * ```typescript
1277
+ * import { AVFMT_FLAG_GENPTS } from 'node-av/constants';
1278
+ *
1279
+ * if (formatContext.hasFlags(AVFMT_FLAG_GENPTS)) {
1280
+ * console.log('GENPTS flag is set');
1281
+ * }
1282
+ * ```
1283
+ *
1284
+ * @see {@link setFlags} To set flags
1285
+ * @see {@link clearFlags} To unset flags
1286
+ * @see {@link flags} For direct flag access
1287
+ */
1288
+ hasFlags(...flags) {
1289
+ for (const flag of flags) {
1290
+ if ((this.native.flags & flag) !== flag) {
1291
+ return false;
1292
+ }
1293
+ }
1294
+ return true;
1295
+ }
1296
+ /**
1297
+ * Get RTSP stream information.
1298
+ *
1299
+ * Returns information about all RTSP streams including codec details.
1300
+ * Only works with RTSP input contexts.
1301
+ *
1302
+ * @returns Array of stream information objects with codec details, or null if not RTSP
1303
+ *
1304
+ * @example
1305
+ * ```typescript
1306
+ * const ctx = new FormatContext();
1307
+ * await ctx.openInput('rtsp://camera/stream?backchannel=1');
1308
+ *
1309
+ * const rtspStreams = ctx.getRTSPStreamInfo();
1310
+ * if (rtspStreams) {
1311
+ * // Find sendonly stream (backchannel)
1312
+ * const backchannel = rtspStreams.find(s => s.direction === 'sendonly');
1313
+ * if (backchannel) {
1314
+ * console.log(`Transport: ${backchannel.transport}`);
1315
+ * console.log(`Codec ID: ${backchannel.codecId}`);
1316
+ * console.log(`MIME Type: ${backchannel.mimeType}`);
1317
+ * console.log(`Payload Type: ${backchannel.payloadType}`);
1318
+ * if (backchannel.sampleRate) {
1319
+ * console.log(`Audio: ${backchannel.sampleRate}Hz, ${backchannel.channels} channels`);
1320
+ * }
1321
+ * }
1322
+ * }
1323
+ * ```
1324
+ */
1325
+ getRTSPStreamInfo() {
1326
+ return this.native.getRTSPStreamInfo();
1327
+ }
1328
+ /**
1329
+ * Interrupt any in-progress blocking I/O operation.
1330
+ *
1331
+ * Signals the interrupt callback so a blocking call (e.g. av_read_frame() on a
1332
+ * quiet RTSP socket) returns immediately instead of waiting for data. The
1333
+ * context is not freed and remains valid - this only aborts the pending
1334
+ * operation, so a reader can drain and shut down before closing the input.
1335
+ * An input pb with JS callbacks stops serving the input as on close: a call
1336
+ * waiting for one of its callbacks fails with AVERROR_EXIT, and its callbacks
1337
+ * are not called again.
1338
+ *
1339
+ * @example
1340
+ * ```typescript
1341
+ * ctx.interrupt(); // unblock a stalled readFrame()
1342
+ * ```
1343
+ *
1344
+ * @see {@link closeInput} To close and free the input
1345
+ */
1346
+ interrupt() {
1347
+ this.native.interrupt();
1348
+ }
1349
+ /**
1350
+ * Send RTP packet to RTSP stream (supports both TCP and UDP)
1351
+ *
1352
+ * Automatically handles transport-specific packet formatting:
1353
+ * - TCP: Sends with interleaved header ($channelId + length + RTP)
1354
+ * - UDP: Sends raw RTP packet directly to UDP socket
1355
+ *
1356
+ * Used for backchannel/talkback audio streaming.
1357
+ * Only works with RTSP input contexts.
1358
+ *
1359
+ * @param streamIndex - RTSP stream index
1360
+ *
1361
+ * @param rtpData - Raw RTP packet data (12-byte header + payload)
1362
+ *
1363
+ * @returns Promise resolving to number of bytes written on success, negative AVERROR on failure
1364
+ *
1365
+ * @example
1366
+ * ```typescript
1367
+ * // Get backchannel stream info
1368
+ * const streams = ctx.getRTSPStreamInfo();
1369
+ * const backchannel = streams.find(s => s.direction === 'sendonly');
1370
+ *
1371
+ * if (backchannel) {
1372
+ * // Send to camera (works with both TCP and UDP)
1373
+ * const ret = await ctx.sendRTSPPacket(backchannel.streamIndex, rtpPacket);
1374
+ * if (ret < 0) {
1375
+ * throw new Error(`Failed to send: ${ret}`);
1376
+ * }
1377
+ * }
1378
+ * ```
1379
+ *
1380
+ * @see {@link sendRTSPPacketSync} For synchronous version
1381
+ * @see {@link getRTSPStreamInfo} For getting stream info and transport type
1382
+ */
1383
+ async sendRTSPPacket(streamIndex, rtpData) {
1384
+ return this.native.sendRTSPPacket(streamIndex, rtpData);
1385
+ }
1386
+ /**
1387
+ * Send RTP packet to RTSP stream (supports both TCP and UDP) synchronously.
1388
+ * Synchronous version of sendRTSPPacket.
1389
+ *
1390
+ * Automatically handles transport-specific packet formatting:
1391
+ * - TCP: Sends with interleaved header ($channelId + length + RTP)
1392
+ * - UDP: Sends raw RTP packet directly to UDP socket
1393
+ *
1394
+ * Used for backchannel/talkback audio streaming.
1395
+ * Only works with RTSP input contexts.
1396
+ *
1397
+ * @param streamIndex - RTSP stream index
1398
+ *
1399
+ * @param rtpData - Raw RTP packet data (12-byte header + payload)
1400
+ *
1401
+ * @returns Number of bytes written on success, negative AVERROR on failure
1402
+ *
1403
+ * @example
1404
+ * ```typescript
1405
+ * // Get backchannel stream info
1406
+ * const streams = ctx.getRTSPStreamInfo();
1407
+ * const backchannel = streams.find(s => s.direction === 'sendonly');
1408
+ *
1409
+ * if (backchannel) {
1410
+ * // Send to camera (works with both TCP and UDP)
1411
+ * const ret = ctx.sendRTSPPacketSync(backchannel.streamIndex, rtpPacket);
1412
+ * if (ret < 0) {
1413
+ * throw new Error(`Failed to send: ${ret}`);
1414
+ * }
1415
+ * }
1416
+ * ```
1417
+ *
1418
+ * @see {@link sendRTSPPacket} For asynchronous version
1419
+ * @see {@link getRTSPStreamInfo} For getting stream info and transport type
1420
+ */
1421
+ sendRTSPPacketSync(streamIndex, rtpData) {
1422
+ return this.native.sendRTSPPacketSync(streamIndex, rtpData);
1423
+ }
1424
+ /**
1425
+ * Get the underlying native FormatContext object.
1426
+ *
1427
+ * @returns The native FormatContext binding object
1428
+ *
1429
+ * @internal
1430
+ */
1431
+ getNative() {
1432
+ return this.native;
1433
+ }
1434
+ /**
1435
+ * Dispose of the format context.
1436
+ *
1437
+ * Implements the AsyncDisposable interface for automatic cleanup.
1438
+ * Closes input/output and frees resources.
1439
+ *
1440
+ * @returns Promise that resolves when disposed
1441
+ *
1442
+ * @example
1443
+ * ```typescript
1444
+ * {
1445
+ * await using ctx = new FormatContext();
1446
+ * await ctx.openInput('input.mp4');
1447
+ * // Use context...
1448
+ * } // Automatically closed and freed
1449
+ * ```
1450
+ */
1451
+ async [Symbol.asyncDispose]() {
1452
+ await this.native[Symbol.asyncDispose]();
1453
+ }
1454
+ }
1455
+ //# sourceMappingURL=format-context.js.map