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