@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,249 @@
1
+ import type { AVFormatFlag } from '../constants/constants.js';
2
+ import type { NativeInputFormat, NativeIOContext, NativeWrapper } from './native-types.js';
3
+ /**
4
+ * Input format descriptor for demuxing media files.
5
+ *
6
+ * Represents a demuxer that can read and parse specific media container formats.
7
+ * Each format handles specific file types (e.g., MP4, MKV, AVI) and knows how to
8
+ * extract streams and packets from them. Used to identify and open media files
9
+ * for reading.
10
+ *
11
+ * Direct mapping to FFmpeg's AVInputFormat.
12
+ *
13
+ * @example
14
+ * ```typescript
15
+ * import { InputFormat, FormatContext, FFmpegError } from 'node-av';
16
+ *
17
+ * // Find format by name
18
+ * const mp4Format = InputFormat.findInputFormat('mp4');
19
+ * if (mp4Format) {
20
+ * console.log(`Format: ${mp4Format.name}`);
21
+ * console.log(`Description: ${mp4Format.longName}`);
22
+ * console.log(`Extensions: ${mp4Format.extensions}`);
23
+ * }
24
+ *
25
+ * // Probe format from file data
26
+ * const fileData = Buffer.from([...]); // First few KB of file
27
+ * const detectedFormat = InputFormat.probe(fileData, 'video.mp4');
28
+ * if (detectedFormat) {
29
+ * console.log(`Detected: ${detectedFormat.name}`);
30
+ * }
31
+ *
32
+ * // Use with format context
33
+ * const formatContext = new FormatContext();
34
+ * formatContext.inputFormat = mp4Format;
35
+ * const ret = await formatContext.openInput('video.mp4');
36
+ * FFmpegError.throwIfError(ret, 'openInput');
37
+ * ```
38
+ *
39
+ * @see [AVInputFormat](https://ffmpeg.org/doxygen/trunk/structAVInputFormat.html) - FFmpeg Doxygen
40
+ * @see {@link FormatContext} For using formats to open files
41
+ * @see {@link OutputFormat} For muxing formats
42
+ */
43
+ export declare class InputFormat implements NativeWrapper<NativeInputFormat> {
44
+ private native;
45
+ /**
46
+ * @param native - The native input format instance
47
+ *
48
+ * @internal
49
+ */
50
+ constructor(native: NativeInputFormat);
51
+ /**
52
+ * Find input format by short name.
53
+ *
54
+ * Searches for a demuxer by its short name identifier.
55
+ *
56
+ * Direct mapping to av_find_input_format().
57
+ *
58
+ * @param shortName - Format short name (e.g., 'mp4', 'mkv', 'avi')
59
+ *
60
+ * @returns Input format if found, null otherwise
61
+ *
62
+ * @example
63
+ * ```typescript
64
+ * // Find specific formats
65
+ * const mp4 = InputFormat.findInputFormat('mp4');
66
+ * const mkv = InputFormat.findInputFormat('matroska');
67
+ * const avi = InputFormat.findInputFormat('avi');
68
+ *
69
+ * // Check if format is available
70
+ * if (!mp4) {
71
+ * console.error('MP4 format not available');
72
+ * }
73
+ * ```
74
+ *
75
+ * @see {@link probe} To auto-detect format
76
+ */
77
+ static findInputFormat(shortName: string): InputFormat | null;
78
+ /**
79
+ * Probe format from buffer data.
80
+ *
81
+ * Analyzes buffer content to determine the media format.
82
+ * Optionally uses filename for additional format hints.
83
+ *
84
+ * Direct mapping to av_probe_input_format2().
85
+ *
86
+ * @param buffer - Buffer containing file header/start
87
+ *
88
+ * @param filename - Optional filename for format hints
89
+ *
90
+ * @returns Detected format, or null if not recognized
91
+ *
92
+ * @example
93
+ * ```typescript
94
+ * import { readFileSync } from 'fs';
95
+ *
96
+ * // Read first 4KB for probing
97
+ * const data = readFileSync('video.mp4').subarray(0, 4096);
98
+ * const format = InputFormat.probe(data, 'video.mp4');
99
+ *
100
+ * if (format) {
101
+ * console.log(`Detected format: ${format.name}`);
102
+ * } else {
103
+ * console.error('Unknown format');
104
+ * }
105
+ * ```
106
+ *
107
+ * @see {@link probeBuffer} For IO context probing
108
+ * @see {@link findInputFormat} To get format by name
109
+ */
110
+ static probe(buffer: Buffer, filename?: string): InputFormat | null;
111
+ /**
112
+ * Probe format from IO context.
113
+ *
114
+ * Reads data from an IO context to determine format.
115
+ * Useful for custom IO scenarios and network streams.
116
+ *
117
+ * Direct mapping to av_probe_input_buffer2().
118
+ *
119
+ * @param ioContext - IO context to read from
120
+ *
121
+ * @param ioContext.getNative - Method to get native IO context
122
+ *
123
+ * @param maxProbeSize - Maximum bytes to read for probing
124
+ *
125
+ * @returns Detected format, or null if not recognized
126
+ *
127
+ * @example
128
+ * ```typescript
129
+ * import { IOContext } from 'node-av';
130
+ *
131
+ * // Create custom IO context
132
+ * const ioContext = new IOContext();
133
+ * // ... configure IO context ...
134
+ *
135
+ * // Probe format
136
+ * const format = await InputFormat.probeBuffer(ioContext, 32768);
137
+ * if (format) {
138
+ * console.log(`Stream format: ${format.name}`);
139
+ * }
140
+ * ```
141
+ *
142
+ * @see {@link probe} For buffer probing
143
+ */
144
+ static probeBuffer(ioContext: NativeWrapper<NativeIOContext>, maxProbeSize?: number): Promise<InputFormat | null>;
145
+ /**
146
+ * Probe format from IO context synchronously.
147
+ * Synchronous version of probeBuffer.
148
+ *
149
+ * Reads data from an IO context to determine format.
150
+ * Useful for custom IO scenarios and network streams.
151
+ *
152
+ * Direct mapping to av_probe_input_buffer2().
153
+ *
154
+ * @param ioContext - IO context to read from
155
+ *
156
+ * @param ioContext.getNative - Method to get native IO context
157
+ *
158
+ * @param maxProbeSize - Maximum bytes to read for probing
159
+ *
160
+ * @returns Detected format, or null if not recognized
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * import { IOContext } from 'node-av';
165
+ *
166
+ * // Create IO context
167
+ * const ioContext = new IOContext();
168
+ * // ... configure IO context ...
169
+ *
170
+ * // Probe format
171
+ * const format = InputFormat.probeBufferSync(ioContext, 32768);
172
+ * if (format) {
173
+ * console.log(`Format: ${format.name}`);
174
+ * }
175
+ * ```
176
+ *
177
+ * @see {@link probeBuffer} For async version
178
+ */
179
+ static probeBufferSync(ioContext: NativeWrapper<NativeIOContext>, maxProbeSize?: number): InputFormat | null;
180
+ /**
181
+ * Format short name.
182
+ *
183
+ * Short identifier for the format (e.g., 'mp4', 'mkv').
184
+ *
185
+ * Direct mapping to AVInputFormat->name.
186
+ */
187
+ get name(): string | null;
188
+ /**
189
+ * Format long name.
190
+ *
191
+ * Human-readable description of the format.
192
+ *
193
+ * Direct mapping to AVInputFormat->long_name.
194
+ */
195
+ get longName(): string | null;
196
+ /**
197
+ * File extensions.
198
+ *
199
+ * Comma-separated list of file extensions for this format.
200
+ *
201
+ * Direct mapping to AVInputFormat->extensions.
202
+ */
203
+ get extensions(): string | null;
204
+ /**
205
+ * MIME type.
206
+ *
207
+ * MIME type(s) associated with this format.
208
+ *
209
+ * Direct mapping to AVInputFormat->mime_type.
210
+ */
211
+ get mimeType(): string | null;
212
+ /**
213
+ * Format flags.
214
+ *
215
+ * Combination of AVFMT_* flags indicating format capabilities.
216
+ *
217
+ * Direct mapping to AVInputFormat->flags.
218
+ */
219
+ get flags(): AVFormatFlag;
220
+ /**
221
+ * Check if input format has specific flags.
222
+ *
223
+ * Tests whether all specified flags are set using bitwise AND.
224
+ *
225
+ * @param flags - One or more flag values to check
226
+ *
227
+ * @returns true if all specified flags are set, false otherwise
228
+ *
229
+ * @example
230
+ * ```typescript
231
+ * import { AVFMT_NOFILE } from 'node-av/constants';
232
+ *
233
+ * if (inputFormat.hasFlags(AVFMT_NOFILE)) {
234
+ * console.log('This format does not need a file');
235
+ * }
236
+ * ```
237
+ *
238
+ * @see {@link flags} For direct flags access
239
+ */
240
+ hasFlags(...flags: AVFormatFlag[]): boolean;
241
+ /**
242
+ * Get the underlying native InputFormat object.
243
+ *
244
+ * @returns The native InputFormat binding object
245
+ *
246
+ * @internal
247
+ */
248
+ getNative(): NativeInputFormat;
249
+ }
@@ -0,0 +1,306 @@
1
+ import { bindings } from './binding.js';
2
+ /**
3
+ * Input format descriptor for demuxing media files.
4
+ *
5
+ * Represents a demuxer that can read and parse specific media container formats.
6
+ * Each format handles specific file types (e.g., MP4, MKV, AVI) and knows how to
7
+ * extract streams and packets from them. Used to identify and open media files
8
+ * for reading.
9
+ *
10
+ * Direct mapping to FFmpeg's AVInputFormat.
11
+ *
12
+ * @example
13
+ * ```typescript
14
+ * import { InputFormat, FormatContext, FFmpegError } from 'node-av';
15
+ *
16
+ * // Find format by name
17
+ * const mp4Format = InputFormat.findInputFormat('mp4');
18
+ * if (mp4Format) {
19
+ * console.log(`Format: ${mp4Format.name}`);
20
+ * console.log(`Description: ${mp4Format.longName}`);
21
+ * console.log(`Extensions: ${mp4Format.extensions}`);
22
+ * }
23
+ *
24
+ * // Probe format from file data
25
+ * const fileData = Buffer.from([...]); // First few KB of file
26
+ * const detectedFormat = InputFormat.probe(fileData, 'video.mp4');
27
+ * if (detectedFormat) {
28
+ * console.log(`Detected: ${detectedFormat.name}`);
29
+ * }
30
+ *
31
+ * // Use with format context
32
+ * const formatContext = new FormatContext();
33
+ * formatContext.inputFormat = mp4Format;
34
+ * const ret = await formatContext.openInput('video.mp4');
35
+ * FFmpegError.throwIfError(ret, 'openInput');
36
+ * ```
37
+ *
38
+ * @see [AVInputFormat](https://ffmpeg.org/doxygen/trunk/structAVInputFormat.html) - FFmpeg Doxygen
39
+ * @see {@link FormatContext} For using formats to open files
40
+ * @see {@link OutputFormat} For muxing formats
41
+ */
42
+ export class InputFormat {
43
+ native;
44
+ /**
45
+ * @param native - The native input format instance
46
+ *
47
+ * @internal
48
+ */
49
+ constructor(native) {
50
+ this.native = native;
51
+ }
52
+ /**
53
+ * Find input format by short name.
54
+ *
55
+ * Searches for a demuxer by its short name identifier.
56
+ *
57
+ * Direct mapping to av_find_input_format().
58
+ *
59
+ * @param shortName - Format short name (e.g., 'mp4', 'mkv', 'avi')
60
+ *
61
+ * @returns Input format if found, null otherwise
62
+ *
63
+ * @example
64
+ * ```typescript
65
+ * // Find specific formats
66
+ * const mp4 = InputFormat.findInputFormat('mp4');
67
+ * const mkv = InputFormat.findInputFormat('matroska');
68
+ * const avi = InputFormat.findInputFormat('avi');
69
+ *
70
+ * // Check if format is available
71
+ * if (!mp4) {
72
+ * console.error('MP4 format not available');
73
+ * }
74
+ * ```
75
+ *
76
+ * @see {@link probe} To auto-detect format
77
+ */
78
+ static findInputFormat(shortName) {
79
+ const native = bindings.InputFormat.findInputFormat(shortName);
80
+ if (!native) {
81
+ return null;
82
+ }
83
+ return new InputFormat(native);
84
+ }
85
+ /**
86
+ * Probe format from buffer data.
87
+ *
88
+ * Analyzes buffer content to determine the media format.
89
+ * Optionally uses filename for additional format hints.
90
+ *
91
+ * Direct mapping to av_probe_input_format2().
92
+ *
93
+ * @param buffer - Buffer containing file header/start
94
+ *
95
+ * @param filename - Optional filename for format hints
96
+ *
97
+ * @returns Detected format, or null if not recognized
98
+ *
99
+ * @example
100
+ * ```typescript
101
+ * import { readFileSync } from 'fs';
102
+ *
103
+ * // Read first 4KB for probing
104
+ * const data = readFileSync('video.mp4').subarray(0, 4096);
105
+ * const format = InputFormat.probe(data, 'video.mp4');
106
+ *
107
+ * if (format) {
108
+ * console.log(`Detected format: ${format.name}`);
109
+ * } else {
110
+ * console.error('Unknown format');
111
+ * }
112
+ * ```
113
+ *
114
+ * @see {@link probeBuffer} For IO context probing
115
+ * @see {@link findInputFormat} To get format by name
116
+ */
117
+ static probe(buffer, filename) {
118
+ const native = bindings.InputFormat.probe(buffer, filename);
119
+ if (!native) {
120
+ return null;
121
+ }
122
+ return new InputFormat(native);
123
+ }
124
+ /**
125
+ * Probe format from IO context.
126
+ *
127
+ * Reads data from an IO context to determine format.
128
+ * Useful for custom IO scenarios and network streams.
129
+ *
130
+ * Direct mapping to av_probe_input_buffer2().
131
+ *
132
+ * @param ioContext - IO context to read from
133
+ *
134
+ * @param ioContext.getNative - Method to get native IO context
135
+ *
136
+ * @param maxProbeSize - Maximum bytes to read for probing
137
+ *
138
+ * @returns Detected format, or null if not recognized
139
+ *
140
+ * @example
141
+ * ```typescript
142
+ * import { IOContext } from 'node-av';
143
+ *
144
+ * // Create custom IO context
145
+ * const ioContext = new IOContext();
146
+ * // ... configure IO context ...
147
+ *
148
+ * // Probe format
149
+ * const format = await InputFormat.probeBuffer(ioContext, 32768);
150
+ * if (format) {
151
+ * console.log(`Stream format: ${format.name}`);
152
+ * }
153
+ * ```
154
+ *
155
+ * @see {@link probe} For buffer probing
156
+ */
157
+ static async probeBuffer(ioContext, maxProbeSize) {
158
+ let native = null;
159
+ try {
160
+ native = await bindings.InputFormat.probeBuffer(ioContext.getNative(), maxProbeSize);
161
+ }
162
+ catch {
163
+ //
164
+ }
165
+ if (!native) {
166
+ return null;
167
+ }
168
+ return new InputFormat(native);
169
+ }
170
+ /**
171
+ * Probe format from IO context synchronously.
172
+ * Synchronous version of probeBuffer.
173
+ *
174
+ * Reads data from an IO context to determine format.
175
+ * Useful for custom IO scenarios and network streams.
176
+ *
177
+ * Direct mapping to av_probe_input_buffer2().
178
+ *
179
+ * @param ioContext - IO context to read from
180
+ *
181
+ * @param ioContext.getNative - Method to get native IO context
182
+ *
183
+ * @param maxProbeSize - Maximum bytes to read for probing
184
+ *
185
+ * @returns Detected format, or null if not recognized
186
+ *
187
+ * @example
188
+ * ```typescript
189
+ * import { IOContext } from 'node-av';
190
+ *
191
+ * // Create IO context
192
+ * const ioContext = new IOContext();
193
+ * // ... configure IO context ...
194
+ *
195
+ * // Probe format
196
+ * const format = InputFormat.probeBufferSync(ioContext, 32768);
197
+ * if (format) {
198
+ * console.log(`Format: ${format.name}`);
199
+ * }
200
+ * ```
201
+ *
202
+ * @see {@link probeBuffer} For async version
203
+ */
204
+ static probeBufferSync(ioContext, maxProbeSize) {
205
+ let native = null;
206
+ try {
207
+ native = bindings.InputFormat.probeBufferSync(ioContext.getNative(), maxProbeSize);
208
+ }
209
+ catch {
210
+ //
211
+ }
212
+ if (!native) {
213
+ return null;
214
+ }
215
+ return new InputFormat(native);
216
+ }
217
+ /**
218
+ * Format short name.
219
+ *
220
+ * Short identifier for the format (e.g., 'mp4', 'mkv').
221
+ *
222
+ * Direct mapping to AVInputFormat->name.
223
+ */
224
+ get name() {
225
+ return this.native.name;
226
+ }
227
+ /**
228
+ * Format long name.
229
+ *
230
+ * Human-readable description of the format.
231
+ *
232
+ * Direct mapping to AVInputFormat->long_name.
233
+ */
234
+ get longName() {
235
+ return this.native.longName;
236
+ }
237
+ /**
238
+ * File extensions.
239
+ *
240
+ * Comma-separated list of file extensions for this format.
241
+ *
242
+ * Direct mapping to AVInputFormat->extensions.
243
+ */
244
+ get extensions() {
245
+ return this.native.extensions;
246
+ }
247
+ /**
248
+ * MIME type.
249
+ *
250
+ * MIME type(s) associated with this format.
251
+ *
252
+ * Direct mapping to AVInputFormat->mime_type.
253
+ */
254
+ get mimeType() {
255
+ return this.native.mimeType;
256
+ }
257
+ /**
258
+ * Format flags.
259
+ *
260
+ * Combination of AVFMT_* flags indicating format capabilities.
261
+ *
262
+ * Direct mapping to AVInputFormat->flags.
263
+ */
264
+ get flags() {
265
+ return this.native.flags;
266
+ }
267
+ /**
268
+ * Check if input format has specific flags.
269
+ *
270
+ * Tests whether all specified flags are set using bitwise AND.
271
+ *
272
+ * @param flags - One or more flag values to check
273
+ *
274
+ * @returns true if all specified flags are set, false otherwise
275
+ *
276
+ * @example
277
+ * ```typescript
278
+ * import { AVFMT_NOFILE } from 'node-av/constants';
279
+ *
280
+ * if (inputFormat.hasFlags(AVFMT_NOFILE)) {
281
+ * console.log('This format does not need a file');
282
+ * }
283
+ * ```
284
+ *
285
+ * @see {@link flags} For direct flags access
286
+ */
287
+ hasFlags(...flags) {
288
+ for (const flag of flags) {
289
+ if ((this.native.flags & flag) !== flag) {
290
+ return false;
291
+ }
292
+ }
293
+ return true;
294
+ }
295
+ /**
296
+ * Get the underlying native InputFormat object.
297
+ *
298
+ * @returns The native InputFormat binding object
299
+ *
300
+ * @internal
301
+ */
302
+ getNative() {
303
+ return this.native;
304
+ }
305
+ }
306
+ //# sourceMappingURL=input-format.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"input-format.js","sourceRoot":"","sources":["../../src/lib/input-format.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