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