node-av-light 0.0.0 → 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 +711 -0
  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 +165 -3
@@ -0,0 +1,311 @@
1
+ import type { AVError } from '../constants/constants.js';
2
+ import type { NativeFFmpegError, NativeWrapper } from './native-types.js';
3
+ /**
4
+ * POSIX error names that can be converted to FFmpeg error codes.
5
+ * These are platform-specific and resolved at runtime.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { PosixError, FFmpegError } from 'node-av';
10
+ *
11
+ * // Get platform-specific error code
12
+ * const errorCode = FFmpegError.AVERROR(PosixError.EAGAIN);
13
+ * console.log(`EAGAIN on this platform: ${errorCode}`);
14
+ * ```
15
+ */
16
+ export declare enum PosixError {
17
+ EAGAIN = "EAGAIN",
18
+ ENOMEM = "ENOMEM",
19
+ EINVAL = "EINVAL",
20
+ EIO = "EIO",
21
+ EPIPE = "EPIPE",
22
+ ENOSPC = "ENOSPC",
23
+ ENOENT = "ENOENT",
24
+ EACCES = "EACCES",
25
+ EPERM = "EPERM",
26
+ EEXIST = "EEXIST",
27
+ ENODEV = "ENODEV",
28
+ ENOTDIR = "ENOTDIR",
29
+ EISDIR = "EISDIR",
30
+ EBUSY = "EBUSY",
31
+ EMFILE = "EMFILE",
32
+ ERANGE = "ERANGE"
33
+ }
34
+ /** FFmpeg error code for EAGAIN (resource temporarily unavailable) */
35
+ export declare const AVERROR_EAGAIN: AVError;
36
+ /** FFmpeg error code for ENOMEM (out of memory) */
37
+ export declare const AVERROR_ENOMEM: AVError;
38
+ /** FFmpeg error code for EINVAL (invalid argument) */
39
+ export declare const AVERROR_EINVAL: AVError;
40
+ /** FFmpeg error code for EIO (I/O error) */
41
+ export declare const AVERROR_EIO: AVError;
42
+ /** FFmpeg error code for EPIPE (broken pipe) */
43
+ export declare const AVERROR_EPIPE: AVError;
44
+ /** FFmpeg error code for ENOSPC (no space left on device) */
45
+ export declare const AVERROR_ENOSPC: AVError;
46
+ /** FFmpeg error code for ENOENT (no such file or directory) */
47
+ export declare const AVERROR_ENOENT: AVError;
48
+ /** FFmpeg error code for EACCES (permission denied) */
49
+ export declare const AVERROR_EACCES: AVError;
50
+ /** FFmpeg error code for EPERM (operation not permitted) */
51
+ export declare const AVERROR_EPERM: AVError;
52
+ /** FFmpeg error code for EEXIST (file exists) */
53
+ export declare const AVERROR_EEXIST: AVError;
54
+ /** FFmpeg error code for ENODEV (no such device) */
55
+ export declare const AVERROR_ENODEV: AVError;
56
+ /** FFmpeg error code for ENOTDIR (not a directory) */
57
+ export declare const AVERROR_ENOTDIR: AVError;
58
+ /** FFmpeg error code for EISDIR (is a directory) */
59
+ export declare const AVERROR_EISDIR: AVError;
60
+ /** FFmpeg error code for EBUSY (device or resource busy) */
61
+ export declare const AVERROR_EBUSY: AVError;
62
+ /** FFmpeg error code for EMFILE (too many open files) */
63
+ export declare const AVERROR_EMFILE: AVError;
64
+ /** FFmpeg error code for ERANGE (result too large) */
65
+ export declare const AVERROR_ERANGE: AVError;
66
+ /**
67
+ * FFmpeg error handling class.
68
+ *
69
+ * Provides utilities for handling and converting FFmpeg error codes.
70
+ * FFmpeg uses negative values for errors, with both FFmpeg-specific codes
71
+ * and POSIX error codes converted to negative values. This class provides
72
+ * methods to check, convert, and throw errors based on FFmpeg return codes.
73
+ *
74
+ * @example
75
+ * ```typescript
76
+ * import { FFmpegError } from 'node-av';
77
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
78
+ *
79
+ * // Check and throw errors
80
+ * const ret = await codecContext.sendPacket(packet);
81
+ * FFmpegError.throwIfError(ret, 'sendPacket');
82
+ *
83
+ * // Handle specific errors
84
+ * if (ret === AVERROR_EAGAIN) {
85
+ * // Need to receive frames first
86
+ * } else if (ret === AVERROR_EOF) {
87
+ * // End of stream
88
+ * }
89
+ *
90
+ * // Get error description
91
+ * const errorMsg = FFmpegError.strerror(ret);
92
+ * console.error(`Error: ${errorMsg}`);
93
+ * ```
94
+ *
95
+ * @see [av_strerror](https://ffmpeg.org/doxygen/trunk/group__lavu__error.html) - FFmpeg Doxygen
96
+ */
97
+ export declare class FFmpegError extends Error implements NativeWrapper<NativeFFmpegError> {
98
+ private native;
99
+ constructor(code?: number);
100
+ /**
101
+ * Get human-readable error message for code.
102
+ *
103
+ * Converts an FFmpeg error code to a descriptive string.
104
+ *
105
+ * Direct mapping to av_strerror().
106
+ *
107
+ * @param errnum - FFmpeg error code
108
+ *
109
+ * @returns Error description string
110
+ *
111
+ * @example
112
+ * ```typescript
113
+ * const message = FFmpegError.strerror(-22);
114
+ * console.log(message); // "Invalid argument"
115
+ * ```
116
+ */
117
+ static strerror(errnum: number): string;
118
+ /**
119
+ * Convert POSIX error name to FFmpeg error code.
120
+ *
121
+ * Converts platform-specific POSIX error to FFmpeg's negative error code.
122
+ *
123
+ * Direct mapping to AVERROR() macro.
124
+ *
125
+ * @param errorName - POSIX error name
126
+ *
127
+ * @returns FFmpeg error code
128
+ *
129
+ * @example
130
+ * ```typescript
131
+ * import { PosixError } from 'node-av';
132
+ *
133
+ * const code = FFmpegError.AVERROR(PosixError.ENOMEM);
134
+ * // Returns platform-specific negative error code
135
+ * ```
136
+ *
137
+ * @see {@link PosixError} For available error names
138
+ */
139
+ static AVERROR(errorName: PosixError): AVError;
140
+ /**
141
+ * Check if a code is an FFmpeg error.
142
+ *
143
+ * FFmpeg errors are negative values.
144
+ *
145
+ * @param code - Return code to check
146
+ *
147
+ * @returns True if code is an error
148
+ *
149
+ * @example
150
+ * ```typescript
151
+ * const ret = await formatContext.readFrame(packet);
152
+ * if (FFmpegError.isFFmpegError(ret)) {
153
+ * console.error('Read failed');
154
+ * }
155
+ * ```
156
+ */
157
+ static isFFmpegError(code: number): boolean;
158
+ /**
159
+ * Create error from code.
160
+ *
161
+ * Creates an FFmpegError instance if the code is an error.
162
+ *
163
+ * @param code - FFmpeg return code
164
+ *
165
+ * @returns Error instance or null if not an error
166
+ *
167
+ * @example
168
+ * ```typescript
169
+ * const error = FFmpegError.fromCode(ret);
170
+ * if (error) {
171
+ * console.error(`Error: ${error.message}`);
172
+ * }
173
+ * ```
174
+ */
175
+ static fromCode(code: number): FFmpegError | null;
176
+ /**
177
+ * Throw if code indicates an error.
178
+ *
179
+ * Checks if the code is an error and throws an FFmpegError if so.
180
+ * Commonly used pattern for FFmpeg API calls.
181
+ *
182
+ * @param code - FFmpeg return code
183
+ *
184
+ * @param operation - Optional operation name for context
185
+ *
186
+ * @throws {FFmpegError} If code is negative
187
+ *
188
+ * @example
189
+ * ```typescript
190
+ * // Simple error check
191
+ * const ret = codecContext.open(codec);
192
+ * FFmpegError.throwIfError(ret);
193
+ *
194
+ * // With operation context
195
+ * const ret2 = await formatContext.writeHeader();
196
+ * FFmpegError.throwIfError(ret2, 'writeHeader');
197
+ * // Throws: "writeHeader failed: [error message]"
198
+ * ```
199
+ */
200
+ static throwIfError(code: number, operation?: string): void;
201
+ /**
202
+ * Check if code matches specific error.
203
+ *
204
+ * Convenience method to check for specific error codes.
205
+ *
206
+ * @param code - Return code to check
207
+ *
208
+ * @param errorCode - Error code to compare against
209
+ *
210
+ * @returns True if codes match
211
+ *
212
+ * @example
213
+ * ```typescript
214
+ * import { AVERROR_EOF } from 'node-av/constants';
215
+ *
216
+ * if (FFmpegError.is(ret, AVERROR_EOF)) {
217
+ * console.log('End of file reached');
218
+ * }
219
+ * ```
220
+ */
221
+ static is(code: number, errorCode: number): boolean;
222
+ /**
223
+ * Error code.
224
+ *
225
+ * The FFmpeg error code (negative value).
226
+ */
227
+ get code(): number;
228
+ /**
229
+ * Error message.
230
+ *
231
+ * Human-readable description of the error.
232
+ */
233
+ get message(): string;
234
+ /**
235
+ * Whether this is EAGAIN (resource temporarily unavailable).
236
+ *
237
+ * In codec/filter contexts this means "output not available yet, feed more
238
+ * input" rather than a hard failure.
239
+ *
240
+ * @example
241
+ * ```typescript
242
+ * const error = FFmpegError.fromCode(ret);
243
+ * if (error?.isEAGAIN) {
244
+ * // send more input, then retry
245
+ * }
246
+ * ```
247
+ */
248
+ get isEAGAIN(): boolean;
249
+ /**
250
+ * Whether this is the end of stream (AVERROR_EOF).
251
+ */
252
+ get isEOF(): boolean;
253
+ /**
254
+ * Whether this is invalid data found while processing input (AVERROR_INVALIDDATA).
255
+ */
256
+ get isInvalidData(): boolean;
257
+ /**
258
+ * Whether this is EINVAL (invalid argument).
259
+ */
260
+ get isEINVAL(): boolean;
261
+ /**
262
+ * Whether this is ENOMEM (out of memory).
263
+ */
264
+ get isENOMEM(): boolean;
265
+ /**
266
+ * Whether this is ENOENT (no such file or directory).
267
+ */
268
+ get isENOENT(): boolean;
269
+ /**
270
+ * Whether this is EACCES (permission denied).
271
+ */
272
+ get isEACCES(): boolean;
273
+ /**
274
+ * Whether this is EIO (I/O error).
275
+ */
276
+ get isEIO(): boolean;
277
+ /**
278
+ * Whether this is EPIPE (broken pipe).
279
+ */
280
+ get isEPIPE(): boolean;
281
+ /**
282
+ * Whether this is the immediate-exit request (AVERROR_EXIT).
283
+ */
284
+ get isExit(): boolean;
285
+ /**
286
+ * Check if this error matches a specific code.
287
+ *
288
+ * @param errorCode - FFmpeg error code to compare against
289
+ *
290
+ * @returns True if this error's code matches
291
+ *
292
+ * @example
293
+ * ```typescript
294
+ * import { AVERROR_DECODER_NOT_FOUND } from 'node-av/constants';
295
+ *
296
+ * const error = FFmpegError.fromCode(ret);
297
+ * if (error?.is(AVERROR_DECODER_NOT_FOUND)) {
298
+ * // handle missing decoder
299
+ * }
300
+ * ```
301
+ */
302
+ is(errorCode: number): boolean;
303
+ /**
304
+ * Get the underlying native FFmpegError object.
305
+ *
306
+ * @returns The native FFmpegError binding object
307
+ *
308
+ * @internal
309
+ */
310
+ getNative(): NativeFFmpegError;
311
+ }
@@ -0,0 +1,395 @@
1
+ import { AVERROR_EOF, AVERROR_EXIT, AVERROR_INVALIDDATA } from '../constants/constants.js';
2
+ import { bindings } from './binding.js';
3
+ /**
4
+ * POSIX error names that can be converted to FFmpeg error codes.
5
+ * These are platform-specific and resolved at runtime.
6
+ *
7
+ * @example
8
+ * ```typescript
9
+ * import { PosixError, FFmpegError } from 'node-av';
10
+ *
11
+ * // Get platform-specific error code
12
+ * const errorCode = FFmpegError.AVERROR(PosixError.EAGAIN);
13
+ * console.log(`EAGAIN on this platform: ${errorCode}`);
14
+ * ```
15
+ */
16
+ export var PosixError;
17
+ (function (PosixError) {
18
+ PosixError["EAGAIN"] = "EAGAIN";
19
+ PosixError["ENOMEM"] = "ENOMEM";
20
+ PosixError["EINVAL"] = "EINVAL";
21
+ PosixError["EIO"] = "EIO";
22
+ PosixError["EPIPE"] = "EPIPE";
23
+ PosixError["ENOSPC"] = "ENOSPC";
24
+ PosixError["ENOENT"] = "ENOENT";
25
+ PosixError["EACCES"] = "EACCES";
26
+ PosixError["EPERM"] = "EPERM";
27
+ PosixError["EEXIST"] = "EEXIST";
28
+ PosixError["ENODEV"] = "ENODEV";
29
+ PosixError["ENOTDIR"] = "ENOTDIR";
30
+ PosixError["EISDIR"] = "EISDIR";
31
+ PosixError["EBUSY"] = "EBUSY";
32
+ PosixError["EMFILE"] = "EMFILE";
33
+ PosixError["ERANGE"] = "ERANGE";
34
+ })(PosixError || (PosixError = {}));
35
+ // Cache for error codes to avoid repeated native calls
36
+ const errorCache = {};
37
+ /**
38
+ * Get a cached FFmpeg error code by name.
39
+ *
40
+ * @param name - POSIX error name
41
+ *
42
+ * @returns FFmpeg error code
43
+ *
44
+ * @internal
45
+ */
46
+ function getCachedError(name) {
47
+ if (!(name in errorCache)) {
48
+ errorCache[name] = bindings.FFmpegError.getAverror(name);
49
+ }
50
+ return errorCache[name];
51
+ }
52
+ // Platform-specific POSIX errors used by FFmpeg
53
+ // These MUST be computed at runtime because POSIX error codes
54
+ // differ between operating systems (e.g., EAGAIN is 35 on macOS but 11 on Linux)
55
+ /** FFmpeg error code for EAGAIN (resource temporarily unavailable) */
56
+ export const AVERROR_EAGAIN = getCachedError(PosixError.EAGAIN);
57
+ /** FFmpeg error code for ENOMEM (out of memory) */
58
+ export const AVERROR_ENOMEM = getCachedError(PosixError.ENOMEM);
59
+ /** FFmpeg error code for EINVAL (invalid argument) */
60
+ export const AVERROR_EINVAL = getCachedError(PosixError.EINVAL);
61
+ /** FFmpeg error code for EIO (I/O error) */
62
+ export const AVERROR_EIO = getCachedError(PosixError.EIO);
63
+ /** FFmpeg error code for EPIPE (broken pipe) */
64
+ export const AVERROR_EPIPE = getCachedError(PosixError.EPIPE);
65
+ /** FFmpeg error code for ENOSPC (no space left on device) */
66
+ export const AVERROR_ENOSPC = getCachedError(PosixError.ENOSPC);
67
+ /** FFmpeg error code for ENOENT (no such file or directory) */
68
+ export const AVERROR_ENOENT = getCachedError(PosixError.ENOENT);
69
+ /** FFmpeg error code for EACCES (permission denied) */
70
+ export const AVERROR_EACCES = getCachedError(PosixError.EACCES);
71
+ /** FFmpeg error code for EPERM (operation not permitted) */
72
+ export const AVERROR_EPERM = getCachedError(PosixError.EPERM);
73
+ /** FFmpeg error code for EEXIST (file exists) */
74
+ export const AVERROR_EEXIST = getCachedError(PosixError.EEXIST);
75
+ /** FFmpeg error code for ENODEV (no such device) */
76
+ export const AVERROR_ENODEV = getCachedError(PosixError.ENODEV);
77
+ /** FFmpeg error code for ENOTDIR (not a directory) */
78
+ export const AVERROR_ENOTDIR = getCachedError(PosixError.ENOTDIR);
79
+ /** FFmpeg error code for EISDIR (is a directory) */
80
+ export const AVERROR_EISDIR = getCachedError(PosixError.EISDIR);
81
+ /** FFmpeg error code for EBUSY (device or resource busy) */
82
+ export const AVERROR_EBUSY = getCachedError(PosixError.EBUSY);
83
+ /** FFmpeg error code for EMFILE (too many open files) */
84
+ export const AVERROR_EMFILE = getCachedError(PosixError.EMFILE);
85
+ /** FFmpeg error code for ERANGE (result too large) */
86
+ export const AVERROR_ERANGE = getCachedError(PosixError.ERANGE);
87
+ /**
88
+ * FFmpeg error handling class.
89
+ *
90
+ * Provides utilities for handling and converting FFmpeg error codes.
91
+ * FFmpeg uses negative values for errors, with both FFmpeg-specific codes
92
+ * and POSIX error codes converted to negative values. This class provides
93
+ * methods to check, convert, and throw errors based on FFmpeg return codes.
94
+ *
95
+ * @example
96
+ * ```typescript
97
+ * import { FFmpegError } from 'node-av';
98
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
99
+ *
100
+ * // Check and throw errors
101
+ * const ret = await codecContext.sendPacket(packet);
102
+ * FFmpegError.throwIfError(ret, 'sendPacket');
103
+ *
104
+ * // Handle specific errors
105
+ * if (ret === AVERROR_EAGAIN) {
106
+ * // Need to receive frames first
107
+ * } else if (ret === AVERROR_EOF) {
108
+ * // End of stream
109
+ * }
110
+ *
111
+ * // Get error description
112
+ * const errorMsg = FFmpegError.strerror(ret);
113
+ * console.error(`Error: ${errorMsg}`);
114
+ * ```
115
+ *
116
+ * @see [av_strerror](https://ffmpeg.org/doxygen/trunk/group__lavu__error.html) - FFmpeg Doxygen
117
+ */
118
+ export class FFmpegError extends Error {
119
+ native;
120
+ constructor(code) {
121
+ const native = new bindings.FFmpegError(code);
122
+ const message = code !== undefined ? native.message : 'FFmpeg Error';
123
+ super(message);
124
+ this.native = native;
125
+ this.name = 'FFmpegError';
126
+ // Maintain proper stack trace for where our error was thrown (only available on V8)
127
+ if (Error.captureStackTrace) {
128
+ Error.captureStackTrace(this, FFmpegError);
129
+ }
130
+ }
131
+ /**
132
+ * Get human-readable error message for code.
133
+ *
134
+ * Converts an FFmpeg error code to a descriptive string.
135
+ *
136
+ * Direct mapping to av_strerror().
137
+ *
138
+ * @param errnum - FFmpeg error code
139
+ *
140
+ * @returns Error description string
141
+ *
142
+ * @example
143
+ * ```typescript
144
+ * const message = FFmpegError.strerror(-22);
145
+ * console.log(message); // "Invalid argument"
146
+ * ```
147
+ */
148
+ static strerror(errnum) {
149
+ return bindings.FFmpegError.strerror(errnum);
150
+ }
151
+ /**
152
+ * Convert POSIX error name to FFmpeg error code.
153
+ *
154
+ * Converts platform-specific POSIX error to FFmpeg's negative error code.
155
+ *
156
+ * Direct mapping to AVERROR() macro.
157
+ *
158
+ * @param errorName - POSIX error name
159
+ *
160
+ * @returns FFmpeg error code
161
+ *
162
+ * @example
163
+ * ```typescript
164
+ * import { PosixError } from 'node-av';
165
+ *
166
+ * const code = FFmpegError.AVERROR(PosixError.ENOMEM);
167
+ * // Returns platform-specific negative error code
168
+ * ```
169
+ *
170
+ * @see {@link PosixError} For available error names
171
+ */
172
+ static AVERROR(errorName) {
173
+ return bindings.FFmpegError.getAverror(errorName);
174
+ }
175
+ /**
176
+ * Check if a code is an FFmpeg error.
177
+ *
178
+ * FFmpeg errors are negative values.
179
+ *
180
+ * @param code - Return code to check
181
+ *
182
+ * @returns True if code is an error
183
+ *
184
+ * @example
185
+ * ```typescript
186
+ * const ret = await formatContext.readFrame(packet);
187
+ * if (FFmpegError.isFFmpegError(ret)) {
188
+ * console.error('Read failed');
189
+ * }
190
+ * ```
191
+ */
192
+ static isFFmpegError(code) {
193
+ if (typeof code !== 'number') {
194
+ return false;
195
+ }
196
+ return code < 0;
197
+ }
198
+ /**
199
+ * Create error from code.
200
+ *
201
+ * Creates an FFmpegError instance if the code is an error.
202
+ *
203
+ * @param code - FFmpeg return code
204
+ *
205
+ * @returns Error instance or null if not an error
206
+ *
207
+ * @example
208
+ * ```typescript
209
+ * const error = FFmpegError.fromCode(ret);
210
+ * if (error) {
211
+ * console.error(`Error: ${error.message}`);
212
+ * }
213
+ * ```
214
+ */
215
+ static fromCode(code) {
216
+ if (code >= 0) {
217
+ return null;
218
+ }
219
+ return new FFmpegError(code);
220
+ }
221
+ /**
222
+ * Throw if code indicates an error.
223
+ *
224
+ * Checks if the code is an error and throws an FFmpegError if so.
225
+ * Commonly used pattern for FFmpeg API calls.
226
+ *
227
+ * @param code - FFmpeg return code
228
+ *
229
+ * @param operation - Optional operation name for context
230
+ *
231
+ * @throws {FFmpegError} If code is negative
232
+ *
233
+ * @example
234
+ * ```typescript
235
+ * // Simple error check
236
+ * const ret = codecContext.open(codec);
237
+ * FFmpegError.throwIfError(ret);
238
+ *
239
+ * // With operation context
240
+ * const ret2 = await formatContext.writeHeader();
241
+ * FFmpegError.throwIfError(ret2, 'writeHeader');
242
+ * // Throws: "writeHeader failed: [error message]"
243
+ * ```
244
+ */
245
+ static throwIfError(code, operation) {
246
+ if (FFmpegError.isFFmpegError(code)) {
247
+ const error = new FFmpegError(code);
248
+ if (operation) {
249
+ error.message = `${operation}: ${error.message}`;
250
+ }
251
+ throw error;
252
+ }
253
+ }
254
+ /**
255
+ * Check if code matches specific error.
256
+ *
257
+ * Convenience method to check for specific error codes.
258
+ *
259
+ * @param code - Return code to check
260
+ *
261
+ * @param errorCode - Error code to compare against
262
+ *
263
+ * @returns True if codes match
264
+ *
265
+ * @example
266
+ * ```typescript
267
+ * import { AVERROR_EOF } from 'node-av/constants';
268
+ *
269
+ * if (FFmpegError.is(ret, AVERROR_EOF)) {
270
+ * console.log('End of file reached');
271
+ * }
272
+ * ```
273
+ */
274
+ static is(code, errorCode) {
275
+ return code === errorCode;
276
+ }
277
+ /**
278
+ * Error code.
279
+ *
280
+ * The FFmpeg error code (negative value).
281
+ */
282
+ get code() {
283
+ return this.native.code;
284
+ }
285
+ /**
286
+ * Error message.
287
+ *
288
+ * Human-readable description of the error.
289
+ */
290
+ get message() {
291
+ return this.native.message;
292
+ }
293
+ /**
294
+ * Whether this is EAGAIN (resource temporarily unavailable).
295
+ *
296
+ * In codec/filter contexts this means "output not available yet, feed more
297
+ * input" rather than a hard failure.
298
+ *
299
+ * @example
300
+ * ```typescript
301
+ * const error = FFmpegError.fromCode(ret);
302
+ * if (error?.isEAGAIN) {
303
+ * // send more input, then retry
304
+ * }
305
+ * ```
306
+ */
307
+ get isEAGAIN() {
308
+ return this.native.code === AVERROR_EAGAIN;
309
+ }
310
+ /**
311
+ * Whether this is the end of stream (AVERROR_EOF).
312
+ */
313
+ get isEOF() {
314
+ return this.native.code === AVERROR_EOF;
315
+ }
316
+ /**
317
+ * Whether this is invalid data found while processing input (AVERROR_INVALIDDATA).
318
+ */
319
+ get isInvalidData() {
320
+ return this.native.code === AVERROR_INVALIDDATA;
321
+ }
322
+ /**
323
+ * Whether this is EINVAL (invalid argument).
324
+ */
325
+ get isEINVAL() {
326
+ return this.native.code === AVERROR_EINVAL;
327
+ }
328
+ /**
329
+ * Whether this is ENOMEM (out of memory).
330
+ */
331
+ get isENOMEM() {
332
+ return this.native.code === AVERROR_ENOMEM;
333
+ }
334
+ /**
335
+ * Whether this is ENOENT (no such file or directory).
336
+ */
337
+ get isENOENT() {
338
+ return this.native.code === AVERROR_ENOENT;
339
+ }
340
+ /**
341
+ * Whether this is EACCES (permission denied).
342
+ */
343
+ get isEACCES() {
344
+ return this.native.code === AVERROR_EACCES;
345
+ }
346
+ /**
347
+ * Whether this is EIO (I/O error).
348
+ */
349
+ get isEIO() {
350
+ return this.native.code === AVERROR_EIO;
351
+ }
352
+ /**
353
+ * Whether this is EPIPE (broken pipe).
354
+ */
355
+ get isEPIPE() {
356
+ return this.native.code === AVERROR_EPIPE;
357
+ }
358
+ /**
359
+ * Whether this is the immediate-exit request (AVERROR_EXIT).
360
+ */
361
+ get isExit() {
362
+ return this.native.code === AVERROR_EXIT;
363
+ }
364
+ /**
365
+ * Check if this error matches a specific code.
366
+ *
367
+ * @param errorCode - FFmpeg error code to compare against
368
+ *
369
+ * @returns True if this error's code matches
370
+ *
371
+ * @example
372
+ * ```typescript
373
+ * import { AVERROR_DECODER_NOT_FOUND } from 'node-av/constants';
374
+ *
375
+ * const error = FFmpegError.fromCode(ret);
376
+ * if (error?.is(AVERROR_DECODER_NOT_FOUND)) {
377
+ * // handle missing decoder
378
+ * }
379
+ * ```
380
+ */
381
+ is(errorCode) {
382
+ return this.native.code === errorCode;
383
+ }
384
+ /**
385
+ * Get the underlying native FFmpegError object.
386
+ *
387
+ * @returns The native FFmpegError binding object
388
+ *
389
+ * @internal
390
+ */
391
+ getNative() {
392
+ return this.native;
393
+ }
394
+ }
395
+ //# sourceMappingURL=error.js.map