@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,242 @@
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
+ * Get the underlying native FFmpegError object.
236
+ *
237
+ * @returns The native FFmpegError binding object
238
+ *
239
+ * @internal
240
+ */
241
+ getNative(): NativeFFmpegError;
242
+ }
@@ -0,0 +1,303 @@
1
+ import { bindings } from './binding.js';
2
+ /**
3
+ * POSIX error names that can be converted to FFmpeg error codes.
4
+ * These are platform-specific and resolved at runtime.
5
+ *
6
+ * @example
7
+ * ```typescript
8
+ * import { PosixError, FFmpegError } from 'node-av';
9
+ *
10
+ * // Get platform-specific error code
11
+ * const errorCode = FFmpegError.AVERROR(PosixError.EAGAIN);
12
+ * console.log(`EAGAIN on this platform: ${errorCode}`);
13
+ * ```
14
+ */
15
+ export var PosixError;
16
+ (function (PosixError) {
17
+ PosixError["EAGAIN"] = "EAGAIN";
18
+ PosixError["ENOMEM"] = "ENOMEM";
19
+ PosixError["EINVAL"] = "EINVAL";
20
+ PosixError["EIO"] = "EIO";
21
+ PosixError["EPIPE"] = "EPIPE";
22
+ PosixError["ENOSPC"] = "ENOSPC";
23
+ PosixError["ENOENT"] = "ENOENT";
24
+ PosixError["EACCES"] = "EACCES";
25
+ PosixError["EPERM"] = "EPERM";
26
+ PosixError["EEXIST"] = "EEXIST";
27
+ PosixError["ENODEV"] = "ENODEV";
28
+ PosixError["ENOTDIR"] = "ENOTDIR";
29
+ PosixError["EISDIR"] = "EISDIR";
30
+ PosixError["EBUSY"] = "EBUSY";
31
+ PosixError["EMFILE"] = "EMFILE";
32
+ PosixError["ERANGE"] = "ERANGE";
33
+ })(PosixError || (PosixError = {}));
34
+ // Cache for error codes to avoid repeated native calls
35
+ const errorCache = {};
36
+ /**
37
+ * Get a cached FFmpeg error code by name.
38
+ *
39
+ * @param name - POSIX error name
40
+ *
41
+ * @returns FFmpeg error code
42
+ *
43
+ * @internal
44
+ */
45
+ function getCachedError(name) {
46
+ if (!(name in errorCache)) {
47
+ errorCache[name] = bindings.FFmpegError.getAverror(name);
48
+ }
49
+ return errorCache[name];
50
+ }
51
+ // Platform-specific POSIX errors used by FFmpeg
52
+ // These MUST be computed at runtime because POSIX error codes
53
+ // differ between operating systems (e.g., EAGAIN is 35 on macOS but 11 on Linux)
54
+ /** FFmpeg error code for EAGAIN (resource temporarily unavailable) */
55
+ export const AVERROR_EAGAIN = getCachedError(PosixError.EAGAIN);
56
+ /** FFmpeg error code for ENOMEM (out of memory) */
57
+ export const AVERROR_ENOMEM = getCachedError(PosixError.ENOMEM);
58
+ /** FFmpeg error code for EINVAL (invalid argument) */
59
+ export const AVERROR_EINVAL = getCachedError(PosixError.EINVAL);
60
+ /** FFmpeg error code for EIO (I/O error) */
61
+ export const AVERROR_EIO = getCachedError(PosixError.EIO);
62
+ /** FFmpeg error code for EPIPE (broken pipe) */
63
+ export const AVERROR_EPIPE = getCachedError(PosixError.EPIPE);
64
+ /** FFmpeg error code for ENOSPC (no space left on device) */
65
+ export const AVERROR_ENOSPC = getCachedError(PosixError.ENOSPC);
66
+ /** FFmpeg error code for ENOENT (no such file or directory) */
67
+ export const AVERROR_ENOENT = getCachedError(PosixError.ENOENT);
68
+ /** FFmpeg error code for EACCES (permission denied) */
69
+ export const AVERROR_EACCES = getCachedError(PosixError.EACCES);
70
+ /** FFmpeg error code for EPERM (operation not permitted) */
71
+ export const AVERROR_EPERM = getCachedError(PosixError.EPERM);
72
+ /** FFmpeg error code for EEXIST (file exists) */
73
+ export const AVERROR_EEXIST = getCachedError(PosixError.EEXIST);
74
+ /** FFmpeg error code for ENODEV (no such device) */
75
+ export const AVERROR_ENODEV = getCachedError(PosixError.ENODEV);
76
+ /** FFmpeg error code for ENOTDIR (not a directory) */
77
+ export const AVERROR_ENOTDIR = getCachedError(PosixError.ENOTDIR);
78
+ /** FFmpeg error code for EISDIR (is a directory) */
79
+ export const AVERROR_EISDIR = getCachedError(PosixError.EISDIR);
80
+ /** FFmpeg error code for EBUSY (device or resource busy) */
81
+ export const AVERROR_EBUSY = getCachedError(PosixError.EBUSY);
82
+ /** FFmpeg error code for EMFILE (too many open files) */
83
+ export const AVERROR_EMFILE = getCachedError(PosixError.EMFILE);
84
+ /** FFmpeg error code for ERANGE (result too large) */
85
+ export const AVERROR_ERANGE = getCachedError(PosixError.ERANGE);
86
+ /**
87
+ * FFmpeg error handling class.
88
+ *
89
+ * Provides utilities for handling and converting FFmpeg error codes.
90
+ * FFmpeg uses negative values for errors, with both FFmpeg-specific codes
91
+ * and POSIX error codes converted to negative values. This class provides
92
+ * methods to check, convert, and throw errors based on FFmpeg return codes.
93
+ *
94
+ * @example
95
+ * ```typescript
96
+ * import { FFmpegError } from 'node-av';
97
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
98
+ *
99
+ * // Check and throw errors
100
+ * const ret = await codecContext.sendPacket(packet);
101
+ * FFmpegError.throwIfError(ret, 'sendPacket');
102
+ *
103
+ * // Handle specific errors
104
+ * if (ret === AVERROR_EAGAIN) {
105
+ * // Need to receive frames first
106
+ * } else if (ret === AVERROR_EOF) {
107
+ * // End of stream
108
+ * }
109
+ *
110
+ * // Get error description
111
+ * const errorMsg = FFmpegError.strerror(ret);
112
+ * console.error(`Error: ${errorMsg}`);
113
+ * ```
114
+ *
115
+ * @see [av_strerror](https://ffmpeg.org/doxygen/trunk/group__lavu__error.html) - FFmpeg Doxygen
116
+ */
117
+ export class FFmpegError extends Error {
118
+ native;
119
+ constructor(code) {
120
+ const native = new bindings.FFmpegError(code);
121
+ const message = code !== undefined ? native.message : 'FFmpeg Error';
122
+ super(message);
123
+ this.native = native;
124
+ this.name = 'FFmpegError';
125
+ // Maintain proper stack trace for where our error was thrown (only available on V8)
126
+ if (Error.captureStackTrace) {
127
+ Error.captureStackTrace(this, FFmpegError);
128
+ }
129
+ }
130
+ /**
131
+ * Get human-readable error message for code.
132
+ *
133
+ * Converts an FFmpeg error code to a descriptive string.
134
+ *
135
+ * Direct mapping to av_strerror().
136
+ *
137
+ * @param errnum - FFmpeg error code
138
+ *
139
+ * @returns Error description string
140
+ *
141
+ * @example
142
+ * ```typescript
143
+ * const message = FFmpegError.strerror(-22);
144
+ * console.log(message); // "Invalid argument"
145
+ * ```
146
+ */
147
+ static strerror(errnum) {
148
+ return bindings.FFmpegError.strerror(errnum);
149
+ }
150
+ /**
151
+ * Convert POSIX error name to FFmpeg error code.
152
+ *
153
+ * Converts platform-specific POSIX error to FFmpeg's negative error code.
154
+ *
155
+ * Direct mapping to AVERROR() macro.
156
+ *
157
+ * @param errorName - POSIX error name
158
+ *
159
+ * @returns FFmpeg error code
160
+ *
161
+ * @example
162
+ * ```typescript
163
+ * import { PosixError } from 'node-av';
164
+ *
165
+ * const code = FFmpegError.AVERROR(PosixError.ENOMEM);
166
+ * // Returns platform-specific negative error code
167
+ * ```
168
+ *
169
+ * @see {@link PosixError} For available error names
170
+ */
171
+ static AVERROR(errorName) {
172
+ return bindings.FFmpegError.getAverror(errorName);
173
+ }
174
+ /**
175
+ * Check if a code is an FFmpeg error.
176
+ *
177
+ * FFmpeg errors are negative values.
178
+ *
179
+ * @param code - Return code to check
180
+ *
181
+ * @returns True if code is an error
182
+ *
183
+ * @example
184
+ * ```typescript
185
+ * const ret = await formatContext.readFrame(packet);
186
+ * if (FFmpegError.isFFmpegError(ret)) {
187
+ * console.error('Read failed');
188
+ * }
189
+ * ```
190
+ */
191
+ static isFFmpegError(code) {
192
+ if (typeof code !== 'number') {
193
+ return false;
194
+ }
195
+ return code < 0;
196
+ }
197
+ /**
198
+ * Create error from code.
199
+ *
200
+ * Creates an FFmpegError instance if the code is an error.
201
+ *
202
+ * @param code - FFmpeg return code
203
+ *
204
+ * @returns Error instance or null if not an error
205
+ *
206
+ * @example
207
+ * ```typescript
208
+ * const error = FFmpegError.fromCode(ret);
209
+ * if (error) {
210
+ * console.error(`Error: ${error.message}`);
211
+ * }
212
+ * ```
213
+ */
214
+ static fromCode(code) {
215
+ if (code >= 0) {
216
+ return null;
217
+ }
218
+ return new FFmpegError(code);
219
+ }
220
+ /**
221
+ * Throw if code indicates an error.
222
+ *
223
+ * Checks if the code is an error and throws an FFmpegError if so.
224
+ * Commonly used pattern for FFmpeg API calls.
225
+ *
226
+ * @param code - FFmpeg return code
227
+ *
228
+ * @param operation - Optional operation name for context
229
+ *
230
+ * @throws {FFmpegError} If code is negative
231
+ *
232
+ * @example
233
+ * ```typescript
234
+ * // Simple error check
235
+ * const ret = codecContext.open(codec);
236
+ * FFmpegError.throwIfError(ret);
237
+ *
238
+ * // With operation context
239
+ * const ret2 = await formatContext.writeHeader();
240
+ * FFmpegError.throwIfError(ret2, 'writeHeader');
241
+ * // Throws: "writeHeader failed: [error message]"
242
+ * ```
243
+ */
244
+ static throwIfError(code, operation) {
245
+ if (FFmpegError.isFFmpegError(code)) {
246
+ const error = new FFmpegError(code);
247
+ if (operation) {
248
+ error.message = `${operation}: ${error.message}`;
249
+ }
250
+ throw error;
251
+ }
252
+ }
253
+ /**
254
+ * Check if code matches specific error.
255
+ *
256
+ * Convenience method to check for specific error codes.
257
+ *
258
+ * @param code - Return code to check
259
+ *
260
+ * @param errorCode - Error code to compare against
261
+ *
262
+ * @returns True if codes match
263
+ *
264
+ * @example
265
+ * ```typescript
266
+ * import { AVERROR_EOF } from 'node-av/constants';
267
+ *
268
+ * if (FFmpegError.is(ret, AVERROR_EOF)) {
269
+ * console.log('End of file reached');
270
+ * }
271
+ * ```
272
+ */
273
+ static is(code, errorCode) {
274
+ return code === errorCode;
275
+ }
276
+ /**
277
+ * Error code.
278
+ *
279
+ * The FFmpeg error code (negative value).
280
+ */
281
+ get code() {
282
+ return this.native.code;
283
+ }
284
+ /**
285
+ * Error message.
286
+ *
287
+ * Human-readable description of the error.
288
+ */
289
+ get message() {
290
+ return this.native.message;
291
+ }
292
+ /**
293
+ * Get the underlying native FFmpegError object.
294
+ *
295
+ * @returns The native FFmpegError binding object
296
+ *
297
+ * @internal
298
+ */
299
+ getNative() {
300
+ return this.native;
301
+ }
302
+ }
303
+ //# sourceMappingURL=error.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"error.js","sourceRoot":"","sources":["../../src/lib/error.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAA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