node-av 1.1.0 → 1.2.0

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 (134) hide show
  1. package/README.md +51 -38
  2. package/dist/api/bitstream-filter.d.ts +180 -123
  3. package/dist/api/bitstream-filter.js +180 -125
  4. package/dist/api/bitstream-filter.js.map +1 -1
  5. package/dist/api/decoder.d.ts +279 -132
  6. package/dist/api/decoder.js +285 -142
  7. package/dist/api/decoder.js.map +1 -1
  8. package/dist/api/encoder.d.ts +246 -162
  9. package/dist/api/encoder.js +272 -208
  10. package/dist/api/encoder.js.map +1 -1
  11. package/dist/api/filter-presets.d.ts +690 -94
  12. package/dist/api/filter-presets.js +686 -102
  13. package/dist/api/filter-presets.js.map +1 -1
  14. package/dist/api/filter.d.ts +249 -213
  15. package/dist/api/filter.js +252 -242
  16. package/dist/api/filter.js.map +1 -1
  17. package/dist/api/hardware.d.ts +224 -117
  18. package/dist/api/hardware.js +380 -214
  19. package/dist/api/hardware.js.map +1 -1
  20. package/dist/api/index.d.ts +3 -3
  21. package/dist/api/index.js +1 -1
  22. package/dist/api/index.js.map +1 -1
  23. package/dist/api/io-stream.d.ts +65 -61
  24. package/dist/api/io-stream.js +43 -46
  25. package/dist/api/io-stream.js.map +1 -1
  26. package/dist/api/media-input.d.ts +242 -140
  27. package/dist/api/media-input.js +205 -103
  28. package/dist/api/media-input.js.map +1 -1
  29. package/dist/api/media-output.d.ts +206 -128
  30. package/dist/api/media-output.js +210 -128
  31. package/dist/api/media-output.js.map +1 -1
  32. package/dist/api/pipeline.d.ts +168 -38
  33. package/dist/api/pipeline.js +238 -14
  34. package/dist/api/pipeline.js.map +1 -1
  35. package/dist/api/types.d.ts +21 -187
  36. package/dist/api/utils.d.ts +1 -2
  37. package/dist/api/utils.js +9 -0
  38. package/dist/api/utils.js.map +1 -1
  39. package/dist/lib/audio-fifo.d.ts +127 -170
  40. package/dist/lib/audio-fifo.js +130 -173
  41. package/dist/lib/audio-fifo.js.map +1 -1
  42. package/dist/lib/binding.js +5 -0
  43. package/dist/lib/binding.js.map +1 -1
  44. package/dist/lib/bitstream-filter-context.d.ts +139 -184
  45. package/dist/lib/bitstream-filter-context.js +139 -188
  46. package/dist/lib/bitstream-filter-context.js.map +1 -1
  47. package/dist/lib/bitstream-filter.d.ts +68 -54
  48. package/dist/lib/bitstream-filter.js +68 -54
  49. package/dist/lib/bitstream-filter.js.map +1 -1
  50. package/dist/lib/codec-context.d.ts +316 -380
  51. package/dist/lib/codec-context.js +316 -381
  52. package/dist/lib/codec-context.js.map +1 -1
  53. package/dist/lib/codec-parameters.d.ts +160 -170
  54. package/dist/lib/codec-parameters.js +162 -172
  55. package/dist/lib/codec-parameters.js.map +1 -1
  56. package/dist/lib/codec-parser.d.ts +91 -104
  57. package/dist/lib/codec-parser.js +92 -103
  58. package/dist/lib/codec-parser.js.map +1 -1
  59. package/dist/lib/codec.d.ts +264 -281
  60. package/dist/lib/codec.js +268 -285
  61. package/dist/lib/codec.js.map +1 -1
  62. package/dist/lib/dictionary.d.ts +149 -203
  63. package/dist/lib/dictionary.js +158 -212
  64. package/dist/lib/dictionary.js.map +1 -1
  65. package/dist/lib/error.d.ts +96 -130
  66. package/dist/lib/error.js +98 -128
  67. package/dist/lib/error.js.map +1 -1
  68. package/dist/lib/filter-context.d.ts +284 -218
  69. package/dist/lib/filter-context.js +290 -227
  70. package/dist/lib/filter-context.js.map +1 -1
  71. package/dist/lib/filter-graph.d.ts +251 -292
  72. package/dist/lib/filter-graph.js +253 -294
  73. package/dist/lib/filter-graph.js.map +1 -1
  74. package/dist/lib/filter-inout.d.ts +87 -95
  75. package/dist/lib/filter-inout.js +87 -95
  76. package/dist/lib/filter-inout.js.map +1 -1
  77. package/dist/lib/filter.d.ts +93 -111
  78. package/dist/lib/filter.js +93 -111
  79. package/dist/lib/filter.js.map +1 -1
  80. package/dist/lib/format-context.d.ts +320 -428
  81. package/dist/lib/format-context.js +313 -385
  82. package/dist/lib/format-context.js.map +1 -1
  83. package/dist/lib/frame.d.ts +262 -405
  84. package/dist/lib/frame.js +263 -408
  85. package/dist/lib/frame.js.map +1 -1
  86. package/dist/lib/hardware-device-context.d.ts +149 -203
  87. package/dist/lib/hardware-device-context.js +149 -203
  88. package/dist/lib/hardware-device-context.js.map +1 -1
  89. package/dist/lib/hardware-frames-context.d.ts +170 -180
  90. package/dist/lib/hardware-frames-context.js +171 -181
  91. package/dist/lib/hardware-frames-context.js.map +1 -1
  92. package/dist/lib/index.d.ts +2 -1
  93. package/dist/lib/index.js +2 -2
  94. package/dist/lib/index.js.map +1 -1
  95. package/dist/lib/input-format.d.ts +89 -117
  96. package/dist/lib/input-format.js +89 -117
  97. package/dist/lib/input-format.js.map +1 -1
  98. package/dist/lib/io-context.d.ts +209 -241
  99. package/dist/lib/io-context.js +220 -252
  100. package/dist/lib/io-context.js.map +1 -1
  101. package/dist/lib/log.d.ts +85 -119
  102. package/dist/lib/log.js +85 -122
  103. package/dist/lib/log.js.map +1 -1
  104. package/dist/lib/native-types.d.ts +117 -106
  105. package/dist/lib/native-types.js +0 -7
  106. package/dist/lib/native-types.js.map +1 -1
  107. package/dist/lib/option.d.ts +284 -241
  108. package/dist/lib/option.js +309 -249
  109. package/dist/lib/option.js.map +1 -1
  110. package/dist/lib/output-format.d.ts +77 -101
  111. package/dist/lib/output-format.js +77 -101
  112. package/dist/lib/output-format.js.map +1 -1
  113. package/dist/lib/packet.d.ts +172 -240
  114. package/dist/lib/packet.js +172 -241
  115. package/dist/lib/packet.js.map +1 -1
  116. package/dist/lib/rational.d.ts +0 -2
  117. package/dist/lib/rational.js +0 -2
  118. package/dist/lib/rational.js.map +1 -1
  119. package/dist/lib/software-resample-context.d.ts +241 -325
  120. package/dist/lib/software-resample-context.js +242 -326
  121. package/dist/lib/software-resample-context.js.map +1 -1
  122. package/dist/lib/software-scale-context.d.ts +129 -173
  123. package/dist/lib/software-scale-context.js +131 -175
  124. package/dist/lib/software-scale-context.js.map +1 -1
  125. package/dist/lib/stream.d.ts +87 -197
  126. package/dist/lib/stream.js +87 -197
  127. package/dist/lib/stream.js.map +1 -1
  128. package/dist/lib/utilities.d.ts +372 -181
  129. package/dist/lib/utilities.js +373 -182
  130. package/dist/lib/utilities.js.map +1 -1
  131. package/install/check.js +0 -1
  132. package/package.json +21 -12
  133. package/release_notes.md +43 -59
  134. package/CHANGELOG.md +0 -8
@@ -1,8 +1,17 @@
1
1
  import type { AVError } from '../constants/constants.js';
2
- import type { NativeFFmpegError } from './native-types.js';
2
+ import type { NativeFFmpegError, NativeWrapper } from './native-types.js';
3
3
  /**
4
4
  * POSIX error names that can be converted to FFmpeg error codes.
5
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
+ * ```
6
15
  */
7
16
  export declare enum PosixError {
8
17
  EAGAIN = "EAGAIN",
@@ -22,247 +31,204 @@ export declare enum PosixError {
22
31
  EMFILE = "EMFILE",
23
32
  ERANGE = "ERANGE"
24
33
  }
34
+ /** FFmpeg error code for EAGAIN (resource temporarily unavailable) */
25
35
  export declare const AVERROR_EAGAIN: AVError;
36
+ /** FFmpeg error code for ENOMEM (out of memory) */
26
37
  export declare const AVERROR_ENOMEM: AVError;
38
+ /** FFmpeg error code for EINVAL (invalid argument) */
27
39
  export declare const AVERROR_EINVAL: AVError;
40
+ /** FFmpeg error code for EIO (I/O error) */
28
41
  export declare const AVERROR_EIO: AVError;
42
+ /** FFmpeg error code for EPIPE (broken pipe) */
29
43
  export declare const AVERROR_EPIPE: AVError;
44
+ /** FFmpeg error code for ENOSPC (no space left on device) */
30
45
  export declare const AVERROR_ENOSPC: AVError;
46
+ /** FFmpeg error code for ENOENT (no such file or directory) */
31
47
  export declare const AVERROR_ENOENT: AVError;
48
+ /** FFmpeg error code for EACCES (permission denied) */
32
49
  export declare const AVERROR_EACCES: AVError;
50
+ /** FFmpeg error code for EPERM (operation not permitted) */
33
51
  export declare const AVERROR_EPERM: AVError;
52
+ /** FFmpeg error code for EEXIST (file exists) */
34
53
  export declare const AVERROR_EEXIST: AVError;
54
+ /** FFmpeg error code for ENODEV (no such device) */
35
55
  export declare const AVERROR_ENODEV: AVError;
56
+ /** FFmpeg error code for ENOTDIR (not a directory) */
36
57
  export declare const AVERROR_ENOTDIR: AVError;
58
+ /** FFmpeg error code for EISDIR (is a directory) */
37
59
  export declare const AVERROR_EISDIR: AVError;
60
+ /** FFmpeg error code for EBUSY (device or resource busy) */
38
61
  export declare const AVERROR_EBUSY: AVError;
62
+ /** FFmpeg error code for EMFILE (too many open files) */
39
63
  export declare const AVERROR_EMFILE: AVError;
64
+ /** FFmpeg error code for ERANGE (result too large) */
40
65
  export declare const AVERROR_ERANGE: AVError;
41
66
  /**
42
- * FFmpeg error handling.
67
+ * FFmpeg error handling class.
43
68
  *
44
- * Represents FFmpeg errors with error codes and human-readable messages.
45
- * Provides utilities for error checking and throwing.
46
- * Essential for proper error handling in FFmpeg operations.
47
- *
48
- * Direct mapping to FFmpeg's error system.
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.
49
73
  *
50
74
  * @example
51
75
  * ```typescript
52
76
  * import { FFmpegError } from 'node-av';
77
+ * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
53
78
  *
54
- * // Check return codes
79
+ * // Check and throw errors
55
80
  * const ret = await codecContext.sendPacket(packet);
56
81
  * FFmpegError.throwIfError(ret, 'sendPacket');
57
82
  *
58
83
  * // Handle specific errors
59
- * try {
60
- * const openRet = await formatContext.openInput('file.mp4', null, null);
61
- * FFmpegError.throwIfError(openRet, 'openInput');
62
- * } catch (error) {
63
- * if (error instanceof FFmpegError) {
64
- * console.error(`Error code: ${error.code}`);
65
- * console.error(`Message: ${error.message}`);
66
- * }
84
+ * if (ret === AVERROR_EAGAIN) {
85
+ * // Need to receive frames first
86
+ * } else if (ret === AVERROR_EOF) {
87
+ * // End of stream
67
88
  * }
89
+ *
90
+ * // Get error description
91
+ * const errorMsg = FFmpegError.strerror(ret);
92
+ * console.error(`Error: ${errorMsg}`);
68
93
  * ```
94
+ *
95
+ * @see [av_strerror](https://ffmpeg.org/doxygen/trunk/group__lavu__error.html#ga5792b4a2d18d7d9cb0efbcfc335dce2d) - FFmpeg Doxygen
69
96
  */
70
- export declare class FFmpegError extends Error {
97
+ export declare class FFmpegError extends Error implements NativeWrapper<NativeFFmpegError> {
71
98
  private native;
72
- /**
73
- * Create a new FFmpegError instance.
74
- *
75
- * Wraps an FFmpeg error code with a JavaScript Error.
76
- * Automatically retrieves the error message from FFmpeg.
77
- *
78
- * Direct wrapper around FFmpeg error codes.
79
- *
80
- * @param code - FFmpeg error code (negative number)
81
- *
82
- * @example
83
- * ```typescript
84
- * import { FFmpegError } from 'node-av';
85
- * import { AVERROR_EOF } from 'node-av/constants';
86
- *
87
- * const error = new FFmpegError(AVERROR_EOF);
88
- * console.log(error.message); // "End of file"
89
- * console.log(error.code); // -541478725
90
- * ```
91
- */
92
99
  constructor(code?: number);
93
100
  /**
94
- * Put a description of the AVERROR code errnum in a string.
101
+ * Get human-readable error message for code.
95
102
  *
96
- * Converts an error code to a human-readable message.
103
+ * Converts an FFmpeg error code to a descriptive string.
97
104
  *
98
- * Direct mapping to av_strerror()
99
- *
100
- * @param errnum - Error code to describe
105
+ * Direct mapping to av_strerror().
101
106
  *
107
+ * @param errnum - FFmpeg error code
102
108
  * @returns Error description string
103
109
  *
104
110
  * @example
105
111
  * ```typescript
106
- * import { FFmpegError } from 'node-av';
107
- * import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
108
- *
109
- * const message = FFmpegError.strerror(AVERROR_EAGAIN);
110
- * console.log(message); // "Resource temporarily unavailable"
111
- *
112
- * const message2 = FFmpegError.strerror(AVERROR_EOF);
113
- * console.log(message2); // "End of file"
112
+ * const message = FFmpegError.strerror(-22);
113
+ * console.log(message); // "Invalid argument"
114
114
  * ```
115
115
  */
116
116
  static strerror(errnum: number): string;
117
117
  /**
118
- * Get FFmpeg error code by POSIX error name dynamically.
118
+ * Convert POSIX error name to FFmpeg error code.
119
119
  *
120
- * This method provides platform-independent access to POSIX error codes
121
- * converted to FFmpeg format. The POSIX error codes are resolved at runtime
122
- * to ensure correct platform-specific values.
120
+ * Converts platform-specific POSIX error to FFmpeg's negative error code.
123
121
  *
124
- * @param errorName - POSIX error name from the PosixError enum
122
+ * Direct mapping to AVERROR() macro.
125
123
  *
126
- * @returns FFmpeg error code (negative)
127
- *
128
- * @throws {TypeError} If the error name is unknown
124
+ * @param errorName - POSIX error name
125
+ * @returns FFmpeg error code
129
126
  *
130
127
  * @example
131
128
  * ```typescript
132
- * import { FFmpegError, PosixError } from 'node-av';
133
- *
134
- * // Get platform-specific error codes at runtime
135
- * const AVERROR_EAGAIN = FFmpegError.AVERROR(PosixError.EAGAIN);
136
- * const AVERROR_EIO = FFmpegError.AVERROR(PosixError.EIO);
129
+ * import { PosixError } from 'node-av';
137
130
  *
138
- * // Use in comparisons
139
- * const ret = await codecContext.receiveFrame(frame);
140
- * if (ret === FFmpegError.AVERROR(PosixError.EAGAIN)) {
141
- * console.log('Need more input');
142
- * }
143
- *
144
- * // Or use the pre-cached constants
145
- * import { AVERROR_EAGAIN } from 'node-av';
146
- * if (ret === AVERROR_EAGAIN) {
147
- * console.log('Need more input');
148
- * }
131
+ * const code = FFmpegError.AVERROR(PosixError.ENOMEM);
132
+ * // Returns platform-specific negative error code
149
133
  * ```
150
134
  *
151
- * @see {@link getKnownErrors} To get all available POSIX error codes
152
- * @see {@link PosixError} For the list of supported POSIX errors
135
+ * @see {@link PosixError} For available error names
153
136
  */
154
137
  static AVERROR(errorName: PosixError): AVError;
155
138
  /**
156
- * Check if a value is an error code.
139
+ * Check if a code is an FFmpeg error.
157
140
  *
158
- * @param code - Value to check
141
+ * FFmpeg errors are negative values.
159
142
  *
160
- * @returns true if code is negative (error), false otherwise
143
+ * @param code - Return code to check
144
+ * @returns True if code is an error
161
145
  *
162
146
  * @example
163
147
  * ```typescript
164
148
  * const ret = await formatContext.readFrame(packet);
165
149
  * if (FFmpegError.isFFmpegError(ret)) {
166
- * console.error('Read frame failed');
150
+ * console.error('Read failed');
167
151
  * }
168
152
  * ```
169
153
  */
170
154
  static isFFmpegError(code: number): boolean;
171
155
  /**
172
- * Create FFmpegError from error code if it's an error.
156
+ * Create error from code.
173
157
  *
174
- * Helper method to conditionally create error objects.
158
+ * Creates an FFmpegError instance if the code is an error.
175
159
  *
176
160
  * @param code - FFmpeg return code
177
- *
178
- * @returns FFmpegError if code < 0, null otherwise
161
+ * @returns Error instance or null if not an error
179
162
  *
180
163
  * @example
181
164
  * ```typescript
182
- * const ret = await formatContext.openInput('video.mp4', null, null);
183
165
  * const error = FFmpegError.fromCode(ret);
184
166
  * if (error) {
185
- * console.error(`Failed: ${error.message}`);
186
- * console.error(`Code: ${error.code}`);
167
+ * console.error(`Error: ${error.message}`);
187
168
  * }
188
169
  * ```
189
170
  */
190
171
  static fromCode(code: number): FFmpegError | null;
191
172
  /**
192
- * Throw FFmpegError if code indicates error.
173
+ * Throw if code indicates an error.
193
174
  *
194
- * Checks return code and throws an error if negative.
195
- * Essential for FFmpeg error handling pattern.
175
+ * Checks if the code is an error and throws an FFmpegError if so.
176
+ * Commonly used pattern for FFmpeg API calls.
196
177
  *
197
178
  * @param code - FFmpeg return code
198
- * @param operation - Optional operation name for better error messages
199
- *
200
- * @throws {FFmpegError} If code < 0
179
+ * @param operation - Optional operation name for context
180
+ * @throws {FFmpegError} If code is negative
201
181
  *
202
182
  * @example
203
183
  * ```typescript
204
- * import { FFmpegError } from 'node-av';
205
- *
206
- * const ret = await codecContext.sendPacket(packet);
207
- * FFmpegError.throwIfError(ret, 'sendPacket');
208
- * // Continues if successful, throws if error
209
- *
210
- * // With operation name for better error messages
211
- * const ret2 = formatContext.allocOutputContext2(null, 'mp4', 'out.mp4');
212
- * FFmpegError.throwIfError(ret2, 'allocOutputContext2');
213
- * // Error message: "allocOutputContext2 failed: ..."
184
+ * // Simple error check
185
+ * const ret = codecContext.open(codec);
186
+ * FFmpegError.throwIfError(ret);
187
+ *
188
+ * // With operation context
189
+ * const ret2 = await formatContext.writeHeader();
190
+ * FFmpegError.throwIfError(ret2, 'writeHeader');
191
+ * // Throws: "writeHeader failed: [error message]"
214
192
  * ```
215
- *
216
- * @see {@link fromCode} To create error without throwing
217
- * @see {@link isFFmpegError} To check if value is error
218
193
  */
219
194
  static throwIfError(code: number, operation?: string): void;
220
195
  /**
221
- * Check if error code matches specific error.
196
+ * Check if code matches specific error.
222
197
  *
223
- * Compares return code with specific error constant.
224
- * Useful for handling different error conditions.
225
- *
226
- * @param code - FFmpeg return code
227
- * @param errorCode - Error code to check against
198
+ * Convenience method to check for specific error codes.
228
199
  *
229
- * @returns true if codes match, false otherwise
200
+ * @param code - Return code to check
201
+ * @param errorCode - Error code to compare against
202
+ * @returns True if codes match
230
203
  *
231
204
  * @example
232
205
  * ```typescript
233
- * import { FFmpegError } from 'node-av';
234
- * import { AVERROR_EOF, AVERROR_EAGAIN } from 'node-av/constants';
206
+ * import { AVERROR_EOF } from 'node-av/constants';
235
207
  *
236
- * const ret = await codecContext.receiveFrame(frame);
237
208
  * if (FFmpegError.is(ret, AVERROR_EOF)) {
238
- * console.log('End of stream reached');
239
- * } else if (FFmpegError.is(ret, AVERROR_EAGAIN)) {
240
- * console.log('Need more input');
209
+ * console.log('End of file reached');
241
210
  * }
242
211
  * ```
243
212
  */
244
213
  static is(code: number, errorCode: number): boolean;
245
214
  /**
246
- * Get error code.
247
- *
248
- * Direct mapping to AVERROR code
215
+ * Error code.
249
216
  *
250
- * FFmpeg error code (negative number).
217
+ * The FFmpeg error code (negative value).
251
218
  */
252
219
  get code(): number;
253
220
  /**
254
- * Get human-readable error message.
221
+ * Error message.
255
222
  *
256
- * Direct mapping to av_strerror() output
257
- *
258
- * Error description string.
223
+ * Human-readable description of the error.
259
224
  */
260
225
  get message(): string;
261
226
  /**
262
- * Get the native FFmpeg error object.
227
+ * Get the underlying native FFmpegError object.
228
+ *
229
+ * @returns The native FFmpegError binding object
263
230
  *
264
- * @internal For use by other wrapper classes
265
- * @returns The underlying native error object
231
+ * @internal
266
232
  */
267
233
  getNative(): NativeFFmpegError;
268
234
  }