node-av 0.0.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.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,201 @@
|
|
|
1
|
+
import type { AVLogLevel } from './constants.js';
|
|
2
|
+
import type { LogOptions } from './types.js';
|
|
3
|
+
/**
|
|
4
|
+
* FFmpeg logging system control.
|
|
5
|
+
*
|
|
6
|
+
* Controls FFmpeg's global logging behavior including log levels and message capture.
|
|
7
|
+
* Provides direct access to FFmpeg's logging system with options for performance optimization.
|
|
8
|
+
* FFmpeg can generate thousands of log messages per second, so filtering is important.
|
|
9
|
+
*
|
|
10
|
+
* Direct mapping to FFmpeg's logging API (av_log_*).
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { Log, AV_LOG_WARNING, AV_LOG_ERROR, AV_LOG_QUIET } from 'node-av';
|
|
15
|
+
*
|
|
16
|
+
* // Set log level (simple, no performance impact)
|
|
17
|
+
* Log.setLevel(AV_LOG_WARNING);
|
|
18
|
+
*
|
|
19
|
+
* // Capture errors only (minimal performance impact)
|
|
20
|
+
* Log.setCallback((level, message) => {
|
|
21
|
+
* console.error(`FFmpeg Error: ${message}`);
|
|
22
|
+
* }, { maxLevel: AV_LOG_ERROR });
|
|
23
|
+
*
|
|
24
|
+
* // Non-blocking callback with no performance impact
|
|
25
|
+
* Log.setCallback((level, message) => {
|
|
26
|
+
* myLogger.log(level, message);
|
|
27
|
+
* });
|
|
28
|
+
*
|
|
29
|
+
* // Reset to default logging
|
|
30
|
+
* Log.resetCallback();
|
|
31
|
+
* ```
|
|
32
|
+
*
|
|
33
|
+
* Warning: Setting a callback can significantly impact performance!
|
|
34
|
+
* FFmpeg can generate thousands of log messages per second.
|
|
35
|
+
* Use maxLevel to filter messages and buffered mode for better performance.
|
|
36
|
+
*/
|
|
37
|
+
export declare class Log {
|
|
38
|
+
private constructor();
|
|
39
|
+
/**
|
|
40
|
+
* Set FFmpeg's global log level.
|
|
41
|
+
*
|
|
42
|
+
* Lower levels mean fewer log messages and better performance.
|
|
43
|
+
* Messages above this level are not generated at all by FFmpeg.
|
|
44
|
+
*
|
|
45
|
+
* Direct mapping to av_log_set_level()
|
|
46
|
+
*
|
|
47
|
+
* @param level - Log level (AV_LOG_* constant):
|
|
48
|
+
* - AV_LOG_QUIET: Disable all logging
|
|
49
|
+
* - AV_LOG_PANIC: Only extremely fatal issues
|
|
50
|
+
* - AV_LOG_FATAL: Fatal errors only
|
|
51
|
+
* - AV_LOG_ERROR: Errors that can't be recovered
|
|
52
|
+
* - AV_LOG_WARNING: Warnings about potential issues
|
|
53
|
+
* - AV_LOG_INFO: Informational messages
|
|
54
|
+
* - AV_LOG_VERBOSE: Detailed information
|
|
55
|
+
* - AV_LOG_DEBUG: Debug information
|
|
56
|
+
* - AV_LOG_TRACE: Very detailed trace information
|
|
57
|
+
*
|
|
58
|
+
* @example
|
|
59
|
+
* ```typescript
|
|
60
|
+
* import { Log, AV_LOG_ERROR, AV_LOG_TRACE, AV_LOG_QUIET } from 'node-av';
|
|
61
|
+
*
|
|
62
|
+
* // Only show errors and fatal messages
|
|
63
|
+
* Log.setLevel(AV_LOG_ERROR);
|
|
64
|
+
*
|
|
65
|
+
* // Show everything (warning: very verbose!)
|
|
66
|
+
* Log.setLevel(AV_LOG_TRACE);
|
|
67
|
+
*
|
|
68
|
+
* // Disable all logging for maximum performance
|
|
69
|
+
* Log.setLevel(AV_LOG_QUIET);
|
|
70
|
+
* ```
|
|
71
|
+
*
|
|
72
|
+
* @see {@link getLevel} To retrieve current level
|
|
73
|
+
*/
|
|
74
|
+
static setLevel(level: AVLogLevel): void;
|
|
75
|
+
/**
|
|
76
|
+
* Get the current global log level.
|
|
77
|
+
*
|
|
78
|
+
* Returns the current FFmpeg log level setting.
|
|
79
|
+
*
|
|
80
|
+
* Direct mapping to av_log_get_level()
|
|
81
|
+
*
|
|
82
|
+
* @returns Current log level (AV_LOG_* constant)
|
|
83
|
+
*
|
|
84
|
+
* @example
|
|
85
|
+
* ```typescript
|
|
86
|
+
* import { Log, AV_LOG_INFO } from 'node-av';
|
|
87
|
+
*
|
|
88
|
+
* const currentLevel = Log.getLevel();
|
|
89
|
+
* console.log(`Current log level: ${currentLevel}`);
|
|
90
|
+
*
|
|
91
|
+
* // Temporarily change log level
|
|
92
|
+
* const savedLevel = Log.getLevel();
|
|
93
|
+
* Log.setLevel(AV_LOG_INFO);
|
|
94
|
+
* // ... do something ...
|
|
95
|
+
* Log.setLevel(savedLevel); // Restore
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @see {@link setLevel} To change the level
|
|
99
|
+
*/
|
|
100
|
+
static getLevel(): AVLogLevel;
|
|
101
|
+
/**
|
|
102
|
+
* Log a message through FFmpeg's logging system.
|
|
103
|
+
*
|
|
104
|
+
* Sends a message through FFmpeg's internal logging system.
|
|
105
|
+
* The message will be processed according to the current log level and callback.
|
|
106
|
+
*
|
|
107
|
+
* Direct mapping to av_log()
|
|
108
|
+
*
|
|
109
|
+
* @param level - Log level (AV_LOG_* constant)
|
|
110
|
+
* @param message - Message to log
|
|
111
|
+
*
|
|
112
|
+
* @example
|
|
113
|
+
* ```typescript
|
|
114
|
+
* import { Log, AV_LOG_INFO, AV_LOG_ERROR, AV_LOG_WARNING } from 'node-av';
|
|
115
|
+
*
|
|
116
|
+
* Log.log(AV_LOG_INFO, 'Starting processing...');
|
|
117
|
+
* Log.log(AV_LOG_WARNING, 'Frame rate might be inaccurate');
|
|
118
|
+
* Log.log(AV_LOG_ERROR, 'Failed to open codec');
|
|
119
|
+
*
|
|
120
|
+
* // With formatting
|
|
121
|
+
* const frameNum = 42;
|
|
122
|
+
* Log.log(AV_LOG_INFO, `Processing frame ${frameNum}`);
|
|
123
|
+
* ```
|
|
124
|
+
*/
|
|
125
|
+
static log(level: AVLogLevel, message: string): void;
|
|
126
|
+
/**
|
|
127
|
+
* Set a callback to capture FFmpeg log messages.
|
|
128
|
+
*
|
|
129
|
+
* Installs a custom callback to intercept FFmpeg's log messages.
|
|
130
|
+
* This implementation uses ThreadSafeFunction for zero-blocking operation.
|
|
131
|
+
* Messages are processed asynchronously without impacting FFmpeg performance.
|
|
132
|
+
* Use options.maxLevel to filter messages at the C level for best performance.
|
|
133
|
+
*
|
|
134
|
+
* Direct mapping to av_log_set_callback()
|
|
135
|
+
*
|
|
136
|
+
* @param callback - Function to receive log messages, or null to reset
|
|
137
|
+
* @param options - Options to control performance impact:
|
|
138
|
+
* - maxLevel: Only capture messages at or below this level (filtered in C++)
|
|
139
|
+
* - buffered: Buffer messages for batch processing
|
|
140
|
+
*
|
|
141
|
+
* @example
|
|
142
|
+
* ```typescript
|
|
143
|
+
* import { Log, AV_LOG_ERROR, AV_LOG_WARNING } from 'node-av';
|
|
144
|
+
*
|
|
145
|
+
* // Simple callback (warning: can be slow!)
|
|
146
|
+
* Log.setCallback((level, message) => {
|
|
147
|
+
* console.log(`[${level}] ${message}`);
|
|
148
|
+
* });
|
|
149
|
+
*
|
|
150
|
+
* // Performance-optimized callback (filters at C level)
|
|
151
|
+
* Log.setCallback((level, message) => {
|
|
152
|
+
* errorReporter.log(message);
|
|
153
|
+
* }, {
|
|
154
|
+
* maxLevel: AV_LOG_ERROR // Only capture errors (filtered in C++)
|
|
155
|
+
* });
|
|
156
|
+
*
|
|
157
|
+
* // Structured logging
|
|
158
|
+
* Log.setCallback((level, message) => {
|
|
159
|
+
* myLogger.log({
|
|
160
|
+
* level: level,
|
|
161
|
+
* message: message,
|
|
162
|
+
* timestamp: Date.now(),
|
|
163
|
+
* source: 'ffmpeg'
|
|
164
|
+
* });
|
|
165
|
+
* }, {
|
|
166
|
+
* maxLevel: AV_LOG_WARNING
|
|
167
|
+
* });
|
|
168
|
+
*
|
|
169
|
+
* // Reset to default (output to stderr)
|
|
170
|
+
* Log.setCallback(null);
|
|
171
|
+
* ```
|
|
172
|
+
*
|
|
173
|
+
* Note: Messages are processed asynchronously and non-blocking.
|
|
174
|
+
*
|
|
175
|
+
* @see {@link resetCallback} To remove callback
|
|
176
|
+
*/
|
|
177
|
+
static setCallback(callback: ((level: AVLogLevel, message: string) => void) | null, options?: LogOptions): void;
|
|
178
|
+
/**
|
|
179
|
+
* Reset logging to default behavior.
|
|
180
|
+
*
|
|
181
|
+
* Removes any custom callback and restores FFmpeg's default logging to stderr.
|
|
182
|
+
* Also clears any buffered messages from previous callbacks.
|
|
183
|
+
*
|
|
184
|
+
* Direct mapping to av_log_set_callback(av_log_default_callback)
|
|
185
|
+
*
|
|
186
|
+
* @example
|
|
187
|
+
* ```typescript
|
|
188
|
+
* import { Log } from 'node-av';
|
|
189
|
+
*
|
|
190
|
+
* // Remove custom callback
|
|
191
|
+
* Log.resetCallback();
|
|
192
|
+
* // Now logs go to stderr again
|
|
193
|
+
*
|
|
194
|
+
* // Equivalent to:
|
|
195
|
+
* Log.setCallback(null);
|
|
196
|
+
* ```
|
|
197
|
+
*
|
|
198
|
+
* @see {@link setCallback} To install custom callback
|
|
199
|
+
*/
|
|
200
|
+
static resetCallback(): void;
|
|
201
|
+
}
|
package/dist/lib/log.js
ADDED
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
import { bindings } from './binding.js';
|
|
2
|
+
/**
|
|
3
|
+
* FFmpeg logging system control.
|
|
4
|
+
*
|
|
5
|
+
* Controls FFmpeg's global logging behavior including log levels and message capture.
|
|
6
|
+
* Provides direct access to FFmpeg's logging system with options for performance optimization.
|
|
7
|
+
* FFmpeg can generate thousands of log messages per second, so filtering is important.
|
|
8
|
+
*
|
|
9
|
+
* Direct mapping to FFmpeg's logging API (av_log_*).
|
|
10
|
+
*
|
|
11
|
+
* @example
|
|
12
|
+
* ```typescript
|
|
13
|
+
* import { Log, AV_LOG_WARNING, AV_LOG_ERROR, AV_LOG_QUIET } from 'node-av';
|
|
14
|
+
*
|
|
15
|
+
* // Set log level (simple, no performance impact)
|
|
16
|
+
* Log.setLevel(AV_LOG_WARNING);
|
|
17
|
+
*
|
|
18
|
+
* // Capture errors only (minimal performance impact)
|
|
19
|
+
* Log.setCallback((level, message) => {
|
|
20
|
+
* console.error(`FFmpeg Error: ${message}`);
|
|
21
|
+
* }, { maxLevel: AV_LOG_ERROR });
|
|
22
|
+
*
|
|
23
|
+
* // Non-blocking callback with no performance impact
|
|
24
|
+
* Log.setCallback((level, message) => {
|
|
25
|
+
* myLogger.log(level, message);
|
|
26
|
+
* });
|
|
27
|
+
*
|
|
28
|
+
* // Reset to default logging
|
|
29
|
+
* Log.resetCallback();
|
|
30
|
+
* ```
|
|
31
|
+
*
|
|
32
|
+
* Warning: Setting a callback can significantly impact performance!
|
|
33
|
+
* FFmpeg can generate thousands of log messages per second.
|
|
34
|
+
* Use maxLevel to filter messages and buffered mode for better performance.
|
|
35
|
+
*/
|
|
36
|
+
export class Log {
|
|
37
|
+
// Private constructor - this is a static-only class
|
|
38
|
+
constructor() {
|
|
39
|
+
throw new Error('Log class cannot be instantiated');
|
|
40
|
+
}
|
|
41
|
+
/**
|
|
42
|
+
* Set FFmpeg's global log level.
|
|
43
|
+
*
|
|
44
|
+
* Lower levels mean fewer log messages and better performance.
|
|
45
|
+
* Messages above this level are not generated at all by FFmpeg.
|
|
46
|
+
*
|
|
47
|
+
* Direct mapping to av_log_set_level()
|
|
48
|
+
*
|
|
49
|
+
* @param level - Log level (AV_LOG_* constant):
|
|
50
|
+
* - AV_LOG_QUIET: Disable all logging
|
|
51
|
+
* - AV_LOG_PANIC: Only extremely fatal issues
|
|
52
|
+
* - AV_LOG_FATAL: Fatal errors only
|
|
53
|
+
* - AV_LOG_ERROR: Errors that can't be recovered
|
|
54
|
+
* - AV_LOG_WARNING: Warnings about potential issues
|
|
55
|
+
* - AV_LOG_INFO: Informational messages
|
|
56
|
+
* - AV_LOG_VERBOSE: Detailed information
|
|
57
|
+
* - AV_LOG_DEBUG: Debug information
|
|
58
|
+
* - AV_LOG_TRACE: Very detailed trace information
|
|
59
|
+
*
|
|
60
|
+
* @example
|
|
61
|
+
* ```typescript
|
|
62
|
+
* import { Log, AV_LOG_ERROR, AV_LOG_TRACE, AV_LOG_QUIET } from 'node-av';
|
|
63
|
+
*
|
|
64
|
+
* // Only show errors and fatal messages
|
|
65
|
+
* Log.setLevel(AV_LOG_ERROR);
|
|
66
|
+
*
|
|
67
|
+
* // Show everything (warning: very verbose!)
|
|
68
|
+
* Log.setLevel(AV_LOG_TRACE);
|
|
69
|
+
*
|
|
70
|
+
* // Disable all logging for maximum performance
|
|
71
|
+
* Log.setLevel(AV_LOG_QUIET);
|
|
72
|
+
* ```
|
|
73
|
+
*
|
|
74
|
+
* @see {@link getLevel} To retrieve current level
|
|
75
|
+
*/
|
|
76
|
+
static setLevel(level) {
|
|
77
|
+
bindings.Log.setLevel(level);
|
|
78
|
+
}
|
|
79
|
+
/**
|
|
80
|
+
* Get the current global log level.
|
|
81
|
+
*
|
|
82
|
+
* Returns the current FFmpeg log level setting.
|
|
83
|
+
*
|
|
84
|
+
* Direct mapping to av_log_get_level()
|
|
85
|
+
*
|
|
86
|
+
* @returns Current log level (AV_LOG_* constant)
|
|
87
|
+
*
|
|
88
|
+
* @example
|
|
89
|
+
* ```typescript
|
|
90
|
+
* import { Log, AV_LOG_INFO } from 'node-av';
|
|
91
|
+
*
|
|
92
|
+
* const currentLevel = Log.getLevel();
|
|
93
|
+
* console.log(`Current log level: ${currentLevel}`);
|
|
94
|
+
*
|
|
95
|
+
* // Temporarily change log level
|
|
96
|
+
* const savedLevel = Log.getLevel();
|
|
97
|
+
* Log.setLevel(AV_LOG_INFO);
|
|
98
|
+
* // ... do something ...
|
|
99
|
+
* Log.setLevel(savedLevel); // Restore
|
|
100
|
+
* ```
|
|
101
|
+
*
|
|
102
|
+
* @see {@link setLevel} To change the level
|
|
103
|
+
*/
|
|
104
|
+
static getLevel() {
|
|
105
|
+
return bindings.Log.getLevel();
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Log a message through FFmpeg's logging system.
|
|
109
|
+
*
|
|
110
|
+
* Sends a message through FFmpeg's internal logging system.
|
|
111
|
+
* The message will be processed according to the current log level and callback.
|
|
112
|
+
*
|
|
113
|
+
* Direct mapping to av_log()
|
|
114
|
+
*
|
|
115
|
+
* @param level - Log level (AV_LOG_* constant)
|
|
116
|
+
* @param message - Message to log
|
|
117
|
+
*
|
|
118
|
+
* @example
|
|
119
|
+
* ```typescript
|
|
120
|
+
* import { Log, AV_LOG_INFO, AV_LOG_ERROR, AV_LOG_WARNING } from 'node-av';
|
|
121
|
+
*
|
|
122
|
+
* Log.log(AV_LOG_INFO, 'Starting processing...');
|
|
123
|
+
* Log.log(AV_LOG_WARNING, 'Frame rate might be inaccurate');
|
|
124
|
+
* Log.log(AV_LOG_ERROR, 'Failed to open codec');
|
|
125
|
+
*
|
|
126
|
+
* // With formatting
|
|
127
|
+
* const frameNum = 42;
|
|
128
|
+
* Log.log(AV_LOG_INFO, `Processing frame ${frameNum}`);
|
|
129
|
+
* ```
|
|
130
|
+
*/
|
|
131
|
+
static log(level, message) {
|
|
132
|
+
bindings.Log.log(level, message);
|
|
133
|
+
}
|
|
134
|
+
/**
|
|
135
|
+
* Set a callback to capture FFmpeg log messages.
|
|
136
|
+
*
|
|
137
|
+
* Installs a custom callback to intercept FFmpeg's log messages.
|
|
138
|
+
* This implementation uses ThreadSafeFunction for zero-blocking operation.
|
|
139
|
+
* Messages are processed asynchronously without impacting FFmpeg performance.
|
|
140
|
+
* Use options.maxLevel to filter messages at the C level for best performance.
|
|
141
|
+
*
|
|
142
|
+
* Direct mapping to av_log_set_callback()
|
|
143
|
+
*
|
|
144
|
+
* @param callback - Function to receive log messages, or null to reset
|
|
145
|
+
* @param options - Options to control performance impact:
|
|
146
|
+
* - maxLevel: Only capture messages at or below this level (filtered in C++)
|
|
147
|
+
* - buffered: Buffer messages for batch processing
|
|
148
|
+
*
|
|
149
|
+
* @example
|
|
150
|
+
* ```typescript
|
|
151
|
+
* import { Log, AV_LOG_ERROR, AV_LOG_WARNING } from 'node-av';
|
|
152
|
+
*
|
|
153
|
+
* // Simple callback (warning: can be slow!)
|
|
154
|
+
* Log.setCallback((level, message) => {
|
|
155
|
+
* console.log(`[${level}] ${message}`);
|
|
156
|
+
* });
|
|
157
|
+
*
|
|
158
|
+
* // Performance-optimized callback (filters at C level)
|
|
159
|
+
* Log.setCallback((level, message) => {
|
|
160
|
+
* errorReporter.log(message);
|
|
161
|
+
* }, {
|
|
162
|
+
* maxLevel: AV_LOG_ERROR // Only capture errors (filtered in C++)
|
|
163
|
+
* });
|
|
164
|
+
*
|
|
165
|
+
* // Structured logging
|
|
166
|
+
* Log.setCallback((level, message) => {
|
|
167
|
+
* myLogger.log({
|
|
168
|
+
* level: level,
|
|
169
|
+
* message: message,
|
|
170
|
+
* timestamp: Date.now(),
|
|
171
|
+
* source: 'ffmpeg'
|
|
172
|
+
* });
|
|
173
|
+
* }, {
|
|
174
|
+
* maxLevel: AV_LOG_WARNING
|
|
175
|
+
* });
|
|
176
|
+
*
|
|
177
|
+
* // Reset to default (output to stderr)
|
|
178
|
+
* Log.setCallback(null);
|
|
179
|
+
* ```
|
|
180
|
+
*
|
|
181
|
+
* Note: Messages are processed asynchronously and non-blocking.
|
|
182
|
+
*
|
|
183
|
+
* @see {@link resetCallback} To remove callback
|
|
184
|
+
*/
|
|
185
|
+
static setCallback(callback, options) {
|
|
186
|
+
if (callback === null) {
|
|
187
|
+
bindings.Log.setCallback(null);
|
|
188
|
+
}
|
|
189
|
+
else {
|
|
190
|
+
bindings.Log.setCallback(callback, options);
|
|
191
|
+
}
|
|
192
|
+
}
|
|
193
|
+
/**
|
|
194
|
+
* Reset logging to default behavior.
|
|
195
|
+
*
|
|
196
|
+
* Removes any custom callback and restores FFmpeg's default logging to stderr.
|
|
197
|
+
* Also clears any buffered messages from previous callbacks.
|
|
198
|
+
*
|
|
199
|
+
* Direct mapping to av_log_set_callback(av_log_default_callback)
|
|
200
|
+
*
|
|
201
|
+
* @example
|
|
202
|
+
* ```typescript
|
|
203
|
+
* import { Log } from 'node-av';
|
|
204
|
+
*
|
|
205
|
+
* // Remove custom callback
|
|
206
|
+
* Log.resetCallback();
|
|
207
|
+
* // Now logs go to stderr again
|
|
208
|
+
*
|
|
209
|
+
* // Equivalent to:
|
|
210
|
+
* Log.setCallback(null);
|
|
211
|
+
* ```
|
|
212
|
+
*
|
|
213
|
+
* @see {@link setCallback} To install custom callback
|
|
214
|
+
*/
|
|
215
|
+
static resetCallback() {
|
|
216
|
+
bindings.Log.resetCallback();
|
|
217
|
+
}
|
|
218
|
+
}
|
|
219
|
+
//# sourceMappingURL=log.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"log.js","sourceRoot":"","sources":["../../src/lib/log.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,EAAE,MAAM,cAAc,CAAC;AAKxC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAiCG;AACH,MAAM,OAAO,GAAG;IACd,oDAAoD;IACpD;QACE,MAAM,IAAI,KAAK,CAAC,kCAAkC,CAAC,CAAC;IACtD,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkCG;IACH,MAAM,CAAC,QAAQ,CAAC,KAAiB;QAC/B,QAAQ,CAAC,GAAG,CAAC,QAAQ,CAAC,KAAK,CAAC,CAAC;IAC/B,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;OAwBG;IACH,MAAM,CAAC,QAAQ;QACb,OAAO,QAAQ,CAAC,GAAG,CAAC,QAAQ,EAAE,CAAC;IACjC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;OAuBG;IACH,MAAM,CAAC,GAAG,CAAC,KAAiB,EAAE,OAAe;QAC3C,QAAQ,CAAC,GAAG,CAAC,GAAG,CAAC,KAAK,EAAE,OAAO,CAAC,CAAC;IACnC,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;OAkDG;IACH,MAAM,CAAC,WAAW,CAAC,QAA+D,EAAE,OAAoB;QACtG,IAAI,QAAQ,KAAK,IAAI,EAAE,CAAC;YACtB,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,IAAI,CAAC,CAAC;QACjC,CAAC;aAAM,CAAC;YACN,QAAQ,CAAC,GAAG,CAAC,WAAW,CAAC,QAAQ,EAAE,OAAO,CAAC,CAAC;QAC9C,CAAC;IACH,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;OAqBG;IACH,MAAM,CAAC,aAAa;QAClB,QAAQ,CAAC,GAAG,CAAC,aAAa,EAAE,CAAC;IAC/B,CAAC;CACF"}
|