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.
- package/README.md +51 -38
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +180 -125
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +279 -132
- package/dist/api/decoder.js +285 -142
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +246 -162
- package/dist/api/encoder.js +272 -208
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +690 -94
- package/dist/api/filter-presets.js +686 -102
- package/dist/api/filter-presets.js.map +1 -1
- package/dist/api/filter.d.ts +249 -213
- package/dist/api/filter.js +252 -242
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +224 -117
- package/dist/api/hardware.js +380 -214
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -3
- package/dist/api/index.js +1 -1
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +43 -46
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +242 -140
- package/dist/api/media-input.js +205 -103
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +210 -128
- 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 +21 -187
- 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/audio-fifo.d.ts +127 -170
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- 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 +68 -54
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +316 -380
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +160 -170
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +91 -104
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +264 -281
- package/dist/lib/codec.js +268 -285
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +149 -203
- package/dist/lib/dictionary.js +158 -212
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +96 -130
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +284 -218
- package/dist/lib/filter-context.js +290 -227
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +251 -292
- 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 +93 -111
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +320 -428
- package/dist/lib/format-context.js +313 -385
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +262 -405
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +149 -203
- 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 +170 -180
- 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 -1
- package/dist/lib/index.js +2 -2
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +89 -117
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +209 -241
- package/dist/lib/io-context.js +220 -252
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +85 -119
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +117 -106
- package/dist/lib/native-types.js +0 -7
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +284 -241
- package/dist/lib/option.js +309 -249
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +77 -101
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +172 -240
- 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 +241 -325
- 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 +129 -173
- package/dist/lib/software-scale-context.js +131 -175
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +87 -197
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +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 +21 -12
- package/release_notes.md +43 -59
- package/CHANGELOG.md +0 -8
package/dist/api/filter.d.ts
CHANGED
|
@@ -1,68 +1,43 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Filter - High-level wrapper for media filtering
|
|
3
|
-
*
|
|
4
|
-
* Implements FFmpeg CLI's filter graph behavior with proper hardware context handling.
|
|
5
|
-
* Uses lazy initialization for hardware inputs: graph is built when first frame arrives
|
|
6
|
-
* with hw_frames_ctx. For software inputs, initializes immediately.
|
|
7
|
-
*
|
|
8
|
-
* Handles filter graph creation, frame processing, and format conversion.
|
|
9
|
-
* Supports complex filter chains and hardware-accelerated filters.
|
|
10
|
-
*
|
|
11
|
-
* @module api/filter
|
|
12
|
-
*/
|
|
13
1
|
import { Frame } from '../lib/index.js';
|
|
14
2
|
import type { AVFilterCmdFlag, AVMediaType } from '../constants/constants.js';
|
|
15
3
|
import type { FilterOptions, StreamInfo } from './types.js';
|
|
16
4
|
/**
|
|
17
|
-
* High-level filter API for
|
|
5
|
+
* High-level filter API for audio and video processing.
|
|
18
6
|
*
|
|
19
|
-
* Provides
|
|
20
|
-
*
|
|
21
|
-
*
|
|
22
|
-
*
|
|
23
|
-
* The filter graph uses lazy initialization for hardware inputs - it's built when
|
|
24
|
-
* the first frame arrives with hw_frames_ctx. This matches FFmpeg CLI behavior
|
|
25
|
-
* for proper hardware context propagation.
|
|
7
|
+
* Provides simplified interface for applying FFmpeg filters to frames.
|
|
8
|
+
* Handles filter graph construction, frame buffering, and command control.
|
|
9
|
+
* Supports both software and hardware-accelerated filtering operations.
|
|
10
|
+
* Essential component for effects, transformations, and format conversions.
|
|
26
11
|
*
|
|
27
12
|
* @example
|
|
28
13
|
* ```typescript
|
|
29
|
-
* import { FilterAPI
|
|
30
|
-
*
|
|
31
|
-
* // Simple video filter from a stream
|
|
32
|
-
* const videoStream = media.video();
|
|
33
|
-
* const filter = await FilterAPI.create('scale=1280:720,format=yuv420p', videoStream);
|
|
14
|
+
* import { FilterAPI } from 'node-av/api';
|
|
34
15
|
*
|
|
35
|
-
* //
|
|
36
|
-
* const
|
|
37
|
-
* ```
|
|
16
|
+
* // Create video filter
|
|
17
|
+
* const filter = await FilterAPI.create('scale=1280:720', videoInfo);
|
|
38
18
|
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
*
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
* hardware: hw
|
|
46
|
-
* });
|
|
19
|
+
* // Process frame
|
|
20
|
+
* const output = await filter.process(inputFrame);
|
|
21
|
+
* if (output) {
|
|
22
|
+
* console.log(`Filtered frame: ${output.width}x${output.height}`);
|
|
23
|
+
* output.free();
|
|
24
|
+
* }
|
|
47
25
|
* ```
|
|
48
26
|
*
|
|
49
27
|
* @example
|
|
50
28
|
* ```typescript
|
|
51
|
-
* //
|
|
52
|
-
* const
|
|
53
|
-
* const
|
|
54
|
-
*
|
|
55
|
-
*
|
|
56
|
-
* }
|
|
29
|
+
* // Hardware-accelerated filtering
|
|
30
|
+
* const hw = HardwareContext.auto();
|
|
31
|
+
* const filter = await FilterAPI.create(
|
|
32
|
+
* 'hwupload,scale_cuda=1920:1080,hwdownload',
|
|
33
|
+
* videoInfo,
|
|
34
|
+
* { hardware: hw }
|
|
35
|
+
* );
|
|
57
36
|
* ```
|
|
58
37
|
*
|
|
59
|
-
* @
|
|
60
|
-
*
|
|
61
|
-
*
|
|
62
|
-
* const hw = await HardwareContext.auto();
|
|
63
|
-
* const decoder = await Decoder.create(stream, { hardware: hw });
|
|
64
|
-
* const filter = await FilterAPI.create('hwdownload,format=yuv420p', decoder.getOutputStreamInfo());
|
|
65
|
-
* ```
|
|
38
|
+
* @see {@link FilterGraph} For low-level filter graph API
|
|
39
|
+
* @see {@link HardwareContext} For hardware acceleration
|
|
40
|
+
* @see {@link Frame} For frame operations
|
|
66
41
|
*/
|
|
67
42
|
export declare class FilterAPI implements Disposable {
|
|
68
43
|
private graph;
|
|
@@ -75,343 +50,404 @@ export declare class FilterAPI implements Disposable {
|
|
|
75
50
|
private description;
|
|
76
51
|
private options;
|
|
77
52
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* @param
|
|
81
|
-
* @param description - Filter graph description
|
|
82
|
-
* @param options - Filter options including hardware context
|
|
53
|
+
* @param config - Stream configuration
|
|
54
|
+
* @param description - Filter description string
|
|
55
|
+
* @param options - Filter options
|
|
83
56
|
* @internal
|
|
84
57
|
*/
|
|
85
58
|
private constructor();
|
|
86
59
|
/**
|
|
87
|
-
* Create a filter
|
|
60
|
+
* Create a filter with specified description and configuration.
|
|
88
61
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
62
|
+
* Constructs filter graph from description string.
|
|
63
|
+
* Configures input/output buffers and threading.
|
|
64
|
+
* For video filters, uses lazy initialization to detect hardware frames.
|
|
91
65
|
*
|
|
92
|
-
*
|
|
93
|
-
* with hw_frames_ctx before configuring the filter graph.
|
|
94
|
-
* For software formats: Initializes immediately.
|
|
66
|
+
* Direct mapping to avfilter_graph_parse_ptr() and avfilter_graph_config().
|
|
95
67
|
*
|
|
96
|
-
*
|
|
97
|
-
*
|
|
98
|
-
*
|
|
99
|
-
*
|
|
100
|
-
*
|
|
101
|
-
* @param description - Filter graph description (e.g., "scale=1280:720" or complex chains)
|
|
102
|
-
* @param input - Stream or StreamInfo describing the input
|
|
103
|
-
* @param options - Optional filter options including hardware context
|
|
104
|
-
*
|
|
105
|
-
* @returns Promise resolving to configured Filter instance
|
|
68
|
+
* @param description - Filter graph description
|
|
69
|
+
* @param input - Input stream configuration
|
|
70
|
+
* @param options - Filter options
|
|
71
|
+
* @returns Configured filter instance
|
|
106
72
|
*
|
|
107
|
-
* @throws {
|
|
108
|
-
* @throws {
|
|
73
|
+
* @throws {Error} If filter creation or configuration fails
|
|
74
|
+
* @throws {FFmpegError} If graph parsing or config fails
|
|
109
75
|
*
|
|
110
76
|
* @example
|
|
111
77
|
* ```typescript
|
|
112
|
-
* // Simple filter
|
|
113
|
-
* const filter = await FilterAPI.create('scale=640:480',
|
|
78
|
+
* // Simple video filter
|
|
79
|
+
* const filter = await FilterAPI.create('scale=640:480', videoInfo);
|
|
80
|
+
* ```
|
|
114
81
|
*
|
|
115
|
-
*
|
|
116
|
-
*
|
|
117
|
-
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* // Complex filter chain
|
|
118
85
|
* const filter = await FilterAPI.create(
|
|
119
|
-
* '
|
|
120
|
-
*
|
|
121
|
-
* { hardware: hw }
|
|
86
|
+
* 'crop=640:480:0:0,rotate=PI/4',
|
|
87
|
+
* videoInfo
|
|
122
88
|
* );
|
|
89
|
+
* ```
|
|
123
90
|
*
|
|
124
|
-
*
|
|
125
|
-
*
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
*
|
|
131
|
-
* });
|
|
91
|
+
* @example
|
|
92
|
+
* ```typescript
|
|
93
|
+
* // Audio filter
|
|
94
|
+
* const filter = await FilterAPI.create(
|
|
95
|
+
* 'volume=0.5,aecho=0.8:0.9:1000:0.3',
|
|
96
|
+
* audioInfo
|
|
97
|
+
* );
|
|
132
98
|
* ```
|
|
99
|
+
*
|
|
100
|
+
* @see {@link process} For frame processing
|
|
101
|
+
* @see {@link FilterOptions} For configuration options
|
|
133
102
|
*/
|
|
134
103
|
static create(description: string, input: StreamInfo, options?: FilterOptions): Promise<FilterAPI>;
|
|
135
104
|
/**
|
|
136
|
-
* Process a
|
|
137
|
-
*
|
|
138
|
-
* Sends a frame through the filter graph and returns the filtered result.
|
|
139
|
-
* May return null if the filter needs more input frames.
|
|
105
|
+
* Process a frame through the filter.
|
|
140
106
|
*
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
107
|
+
* Applies filter operations to input frame.
|
|
108
|
+
* May buffer frames internally before producing output.
|
|
109
|
+
* For video, performs lazy initialization on first frame.
|
|
144
110
|
*
|
|
145
|
-
*
|
|
111
|
+
* Direct mapping to av_buffersrc_add_frame() and av_buffersink_get_frame().
|
|
146
112
|
*
|
|
147
|
-
* @
|
|
113
|
+
* @param frame - Input frame to process
|
|
114
|
+
* @returns Filtered frame or null if buffered
|
|
148
115
|
*
|
|
116
|
+
* @throws {Error} If filter not ready
|
|
149
117
|
* @throws {FFmpegError} If processing fails
|
|
150
|
-
* @throws {Error} If filter not initialized or hardware frame required but not provided
|
|
151
118
|
*
|
|
152
119
|
* @example
|
|
153
120
|
* ```typescript
|
|
154
|
-
* const
|
|
155
|
-
* if (
|
|
156
|
-
*
|
|
121
|
+
* const output = await filter.process(inputFrame);
|
|
122
|
+
* if (output) {
|
|
123
|
+
* console.log(`Got filtered frame: pts=${output.pts}`);
|
|
124
|
+
* output.free();
|
|
125
|
+
* }
|
|
126
|
+
* ```
|
|
127
|
+
*
|
|
128
|
+
* @example
|
|
129
|
+
* ```typescript
|
|
130
|
+
* // Process and drain
|
|
131
|
+
* const output = await filter.process(frame);
|
|
132
|
+
* if (output) yield output;
|
|
133
|
+
*
|
|
134
|
+
* // Drain buffered frames
|
|
135
|
+
* let buffered;
|
|
136
|
+
* while ((buffered = await filter.receive()) !== null) {
|
|
137
|
+
* yield buffered;
|
|
157
138
|
* }
|
|
158
139
|
* ```
|
|
140
|
+
*
|
|
141
|
+
* @see {@link receive} For draining buffered frames
|
|
142
|
+
* @see {@link frames} For stream processing
|
|
159
143
|
*/
|
|
160
144
|
process(frame: Frame): Promise<Frame | null>;
|
|
161
145
|
/**
|
|
162
|
-
* Process multiple frames
|
|
146
|
+
* Process multiple frames at once.
|
|
163
147
|
*
|
|
164
|
-
*
|
|
165
|
-
*
|
|
148
|
+
* Processes batch of frames and drains all output.
|
|
149
|
+
* Useful for filters that buffer multiple frames.
|
|
166
150
|
*
|
|
167
151
|
* @param frames - Array of input frames
|
|
152
|
+
* @returns Array of all output frames
|
|
168
153
|
*
|
|
169
|
-
* @
|
|
170
|
-
*
|
|
154
|
+
* @throws {Error} If filter not ready
|
|
171
155
|
* @throws {FFmpegError} If processing fails
|
|
172
156
|
*
|
|
173
157
|
* @example
|
|
174
158
|
* ```typescript
|
|
175
|
-
* const
|
|
159
|
+
* const outputs = await filter.processMultiple([frame1, frame2, frame3]);
|
|
160
|
+
* for (const output of outputs) {
|
|
161
|
+
* console.log(`Output frame: pts=${output.pts}`);
|
|
162
|
+
* output.free();
|
|
163
|
+
* }
|
|
176
164
|
* ```
|
|
165
|
+
*
|
|
166
|
+
* @see {@link process} For single frame processing
|
|
177
167
|
*/
|
|
178
168
|
processMultiple(frames: Frame[]): Promise<Frame[]>;
|
|
179
169
|
/**
|
|
180
|
-
* Receive
|
|
170
|
+
* Receive buffered frame from filter.
|
|
171
|
+
*
|
|
172
|
+
* Drains frames buffered by the filter.
|
|
173
|
+
* Call repeatedly until null to get all buffered frames.
|
|
181
174
|
*
|
|
182
|
-
*
|
|
183
|
-
* Returns null when no more frames are available.
|
|
175
|
+
* Direct mapping to av_buffersink_get_frame().
|
|
184
176
|
*
|
|
185
|
-
* @returns
|
|
177
|
+
* @returns Buffered frame or null if none available
|
|
186
178
|
*
|
|
187
|
-
* @throws {
|
|
179
|
+
* @throws {Error} If filter not ready
|
|
180
|
+
* @throws {FFmpegError} If receive fails
|
|
188
181
|
*
|
|
189
182
|
* @example
|
|
190
183
|
* ```typescript
|
|
191
|
-
* // Drain
|
|
192
|
-
*
|
|
193
|
-
*
|
|
194
|
-
*
|
|
195
|
-
*
|
|
184
|
+
* // Drain buffered frames
|
|
185
|
+
* let frame;
|
|
186
|
+
* while ((frame = await filter.receive()) !== null) {
|
|
187
|
+
* console.log(`Buffered frame: pts=${frame.pts}`);
|
|
188
|
+
* frame.free();
|
|
196
189
|
* }
|
|
197
190
|
* ```
|
|
191
|
+
*
|
|
192
|
+
* @see {@link process} For input processing
|
|
193
|
+
* @see {@link flush} For end-of-stream
|
|
198
194
|
*/
|
|
199
195
|
receive(): Promise<Frame | null>;
|
|
200
196
|
/**
|
|
201
|
-
* Flush
|
|
197
|
+
* Flush filter and signal end-of-stream.
|
|
202
198
|
*
|
|
203
|
-
*
|
|
204
|
-
*
|
|
199
|
+
* Sends null frame to flush buffered data.
|
|
200
|
+
* Must call receive() to get flushed frames.
|
|
205
201
|
*
|
|
206
|
-
*
|
|
202
|
+
* Direct mapping to av_buffersrc_add_frame(NULL).
|
|
207
203
|
*
|
|
204
|
+
* @throws {Error} If filter not ready
|
|
208
205
|
* @throws {FFmpegError} If flush fails
|
|
209
206
|
*
|
|
210
207
|
* @example
|
|
211
208
|
* ```typescript
|
|
212
209
|
* await filter.flush();
|
|
213
210
|
* // Get remaining frames
|
|
214
|
-
*
|
|
215
|
-
*
|
|
216
|
-
*
|
|
217
|
-
* // Process final frames
|
|
211
|
+
* let frame;
|
|
212
|
+
* while ((frame = await filter.receive()) !== null) {
|
|
213
|
+
* frame.free();
|
|
218
214
|
* }
|
|
219
215
|
* ```
|
|
216
|
+
*
|
|
217
|
+
* @see {@link flushFrames} For async iteration
|
|
218
|
+
* @see {@link receive} For draining frames
|
|
220
219
|
*/
|
|
221
220
|
flush(): Promise<void>;
|
|
222
221
|
/**
|
|
223
|
-
* Flush filter and yield
|
|
222
|
+
* Flush filter and yield remaining frames.
|
|
224
223
|
*
|
|
225
|
-
*
|
|
226
|
-
*
|
|
224
|
+
* Convenient async generator for flushing.
|
|
225
|
+
* Combines flush and receive operations.
|
|
227
226
|
*
|
|
228
|
-
* @
|
|
229
|
-
*
|
|
230
|
-
* @throws {
|
|
227
|
+
* @yields Remaining frames from filter
|
|
228
|
+
* @throws {Error} If filter not ready
|
|
229
|
+
* @throws {FFmpegError} If flush fails
|
|
231
230
|
*
|
|
232
231
|
* @example
|
|
233
232
|
* ```typescript
|
|
234
|
-
* // Process all remaining frames with generator
|
|
235
233
|
* for await (const frame of filter.flushFrames()) {
|
|
236
|
-
*
|
|
237
|
-
*
|
|
234
|
+
* console.log(`Flushed frame: pts=${frame.pts}`);
|
|
235
|
+
* frame.free();
|
|
238
236
|
* }
|
|
239
237
|
* ```
|
|
238
|
+
*
|
|
239
|
+
* @see {@link flush} For manual flush
|
|
240
|
+
* @see {@link frames} For complete pipeline
|
|
240
241
|
*/
|
|
241
242
|
flushFrames(): AsyncGenerator<Frame>;
|
|
242
243
|
/**
|
|
243
|
-
* Process
|
|
244
|
+
* Process frame stream through filter.
|
|
244
245
|
*
|
|
245
|
-
*
|
|
246
|
-
* Automatically handles buffering and
|
|
247
|
-
*
|
|
246
|
+
* High-level async generator for filtering frame streams.
|
|
247
|
+
* Automatically handles buffering and flushing.
|
|
248
|
+
* Frees input frames after processing.
|
|
248
249
|
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
251
|
-
*
|
|
252
|
-
* @
|
|
250
|
+
* @param frames - Async generator of input frames
|
|
251
|
+
* @yields Filtered frames
|
|
252
|
+
* @throws {Error} If filter not ready
|
|
253
|
+
* @throws {FFmpegError} If processing fails
|
|
253
254
|
*
|
|
254
|
-
* @
|
|
255
|
+
* @example
|
|
256
|
+
* ```typescript
|
|
257
|
+
* // Filter decoded frames
|
|
258
|
+
* for await (const frame of filter.frames(decoder.frames(packets))) {
|
|
259
|
+
* await encoder.encode(frame);
|
|
260
|
+
* frame.free();
|
|
261
|
+
* }
|
|
262
|
+
* ```
|
|
255
263
|
*
|
|
256
264
|
* @example
|
|
257
265
|
* ```typescript
|
|
258
|
-
*
|
|
259
|
-
*
|
|
260
|
-
*
|
|
266
|
+
* // Chain filters
|
|
267
|
+
* const filter1 = await FilterAPI.create('scale=640:480', info);
|
|
268
|
+
* const filter2 = await FilterAPI.create('rotate=PI/4', info);
|
|
269
|
+
*
|
|
270
|
+
* for await (const frame of filter2.frames(filter1.frames(input))) {
|
|
271
|
+
* // Process filtered frames
|
|
272
|
+
* frame.free();
|
|
261
273
|
* }
|
|
262
274
|
* ```
|
|
275
|
+
*
|
|
276
|
+
* @see {@link process} For single frame processing
|
|
277
|
+
* @see {@link flush} For end-of-stream handling
|
|
263
278
|
*/
|
|
264
279
|
frames(frames: AsyncGenerator<Frame>): AsyncGenerator<Frame>;
|
|
265
280
|
/**
|
|
266
|
-
* Send
|
|
281
|
+
* Send command to filter.
|
|
282
|
+
*
|
|
283
|
+
* Sends runtime command to specific filter in graph.
|
|
284
|
+
* Allows dynamic parameter adjustment.
|
|
267
285
|
*
|
|
268
|
-
*
|
|
269
|
-
* Not all filters support commands - check filter documentation.
|
|
286
|
+
* Direct mapping to avfilter_graph_send_command().
|
|
270
287
|
*
|
|
271
|
-
* @param target -
|
|
272
|
-
* @param cmd - Command name
|
|
273
|
-
* @param arg - Command argument
|
|
274
|
-
* @param flags -
|
|
288
|
+
* @param target - Target filter name
|
|
289
|
+
* @param cmd - Command name
|
|
290
|
+
* @param arg - Command argument
|
|
291
|
+
* @param flags - Command flags
|
|
292
|
+
* @returns Response string from filter
|
|
275
293
|
*
|
|
276
|
-
* @
|
|
294
|
+
* @throws {Error} If filter not ready
|
|
295
|
+
* @throws {FFmpegError} If command fails
|
|
277
296
|
*
|
|
278
297
|
* @example
|
|
279
298
|
* ```typescript
|
|
280
|
-
* // Change volume
|
|
299
|
+
* // Change volume at runtime
|
|
281
300
|
* const response = filter.sendCommand('volume', 'volume', '0.5');
|
|
282
|
-
*
|
|
283
|
-
* console.log('Volume changed successfully');
|
|
284
|
-
* }
|
|
301
|
+
* console.log(`Volume changed: ${response}`);
|
|
285
302
|
* ```
|
|
286
303
|
*
|
|
287
|
-
* @
|
|
288
|
-
* ```typescript
|
|
289
|
-
* // Enable/disable all filters at runtime
|
|
290
|
-
* filter.sendCommand('all', 'enable', 'expr=gte(t,10)');
|
|
291
|
-
* ```
|
|
304
|
+
* @see {@link queueCommand} For delayed commands
|
|
292
305
|
*/
|
|
293
306
|
sendCommand(target: string, cmd: string, arg: string, flags?: AVFilterCmdFlag): string;
|
|
294
307
|
/**
|
|
295
|
-
* Queue
|
|
308
|
+
* Queue command for later execution.
|
|
309
|
+
*
|
|
310
|
+
* Schedules command to execute at specific timestamp.
|
|
311
|
+
* Useful for synchronized parameter changes.
|
|
296
312
|
*
|
|
297
|
-
*
|
|
298
|
-
* Useful for scripted filter changes synchronized with media playback.
|
|
313
|
+
* Direct mapping to avfilter_graph_queue_command().
|
|
299
314
|
*
|
|
300
|
-
* @param target -
|
|
301
|
-
* @param cmd - Command name
|
|
302
|
-
* @param arg - Command argument
|
|
303
|
-
* @param ts - Timestamp
|
|
304
|
-
* @param flags -
|
|
315
|
+
* @param target - Target filter name
|
|
316
|
+
* @param cmd - Command name
|
|
317
|
+
* @param arg - Command argument
|
|
318
|
+
* @param ts - Timestamp for execution
|
|
319
|
+
* @param flags - Command flags
|
|
320
|
+
* @throws {Error} If filter not ready
|
|
321
|
+
* @throws {FFmpegError} If queue fails
|
|
305
322
|
*
|
|
306
323
|
* @example
|
|
307
324
|
* ```typescript
|
|
308
|
-
* //
|
|
309
|
-
* filter.queueCommand('volume', 'volume', '0.
|
|
310
|
-
* filter.queueCommand('volume', 'volume', '0.8', 10.0); // At 10 seconds
|
|
311
|
-
* filter.queueCommand('volume', 'volume', '0.2', 15.0); // At 15 seconds
|
|
325
|
+
* // Queue volume change at 10 seconds
|
|
326
|
+
* filter.queueCommand('volume', 'volume', '0.8', 10.0);
|
|
312
327
|
* ```
|
|
328
|
+
*
|
|
329
|
+
* @see {@link sendCommand} For immediate commands
|
|
313
330
|
*/
|
|
314
331
|
queueCommand(target: string, cmd: string, arg: string, ts: number, flags?: AVFilterCmdFlag): void;
|
|
315
332
|
/**
|
|
316
|
-
* Get
|
|
333
|
+
* Get filter graph description.
|
|
317
334
|
*
|
|
318
|
-
* Returns
|
|
319
|
-
* Useful for debugging
|
|
335
|
+
* Returns human-readable graph structure.
|
|
336
|
+
* Useful for debugging filter chains.
|
|
337
|
+
*
|
|
338
|
+
* Direct mapping to avfilter_graph_dump().
|
|
320
339
|
*
|
|
321
340
|
* @returns Graph description or null if not initialized
|
|
322
341
|
*
|
|
323
342
|
* @example
|
|
324
343
|
* ```typescript
|
|
325
344
|
* const description = filter.getGraphDescription();
|
|
326
|
-
* console.log(description);
|
|
345
|
+
* console.log('Filter graph:', description);
|
|
327
346
|
* ```
|
|
328
347
|
*/
|
|
329
348
|
getGraphDescription(): string | null;
|
|
330
349
|
/**
|
|
331
|
-
* Check if
|
|
350
|
+
* Check if filter is ready for processing.
|
|
351
|
+
*
|
|
352
|
+
* @returns true if initialized and ready
|
|
332
353
|
*
|
|
333
|
-
* @
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* if (filter.isReady()) {
|
|
357
|
+
* const output = await filter.process(frame);
|
|
358
|
+
* }
|
|
359
|
+
* ```
|
|
334
360
|
*/
|
|
335
361
|
isReady(): boolean;
|
|
336
362
|
/**
|
|
337
|
-
* Get
|
|
363
|
+
* Get media type of filter.
|
|
364
|
+
*
|
|
365
|
+
* @returns AVMEDIA_TYPE_VIDEO or AVMEDIA_TYPE_AUDIO
|
|
338
366
|
*
|
|
339
|
-
* @
|
|
367
|
+
* @example
|
|
368
|
+
* ```typescript
|
|
369
|
+
* if (filter.getMediaType() === AVMEDIA_TYPE_VIDEO) {
|
|
370
|
+
* console.log('Video filter');
|
|
371
|
+
* }
|
|
372
|
+
* ```
|
|
340
373
|
*/
|
|
341
374
|
getMediaType(): AVMediaType;
|
|
342
375
|
/**
|
|
343
|
-
* Free
|
|
376
|
+
* Free filter resources.
|
|
344
377
|
*
|
|
345
|
-
* Releases
|
|
346
|
-
*
|
|
378
|
+
* Releases filter graph and contexts.
|
|
379
|
+
* Safe to call multiple times.
|
|
347
380
|
*
|
|
348
381
|
* @example
|
|
349
382
|
* ```typescript
|
|
350
383
|
* filter.free();
|
|
351
|
-
* // filter is now invalid
|
|
352
384
|
* ```
|
|
385
|
+
*
|
|
386
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
353
387
|
*/
|
|
354
388
|
free(): void;
|
|
355
389
|
/**
|
|
356
|
-
* Initialize
|
|
390
|
+
* Initialize filter graph.
|
|
357
391
|
*
|
|
358
|
-
*
|
|
359
|
-
*
|
|
392
|
+
* Creates and configures filter graph components.
|
|
393
|
+
* For video, may use hardware frames context from first frame.
|
|
360
394
|
*
|
|
361
|
-
*
|
|
362
|
-
*
|
|
363
|
-
*
|
|
364
|
-
* @internal
|
|
395
|
+
* @param firstFrame - First frame for hardware detection (video only)
|
|
396
|
+
* @throws {Error} If initialization fails
|
|
397
|
+
* @throws {FFmpegError} If configuration fails
|
|
365
398
|
*/
|
|
366
399
|
private initialize;
|
|
367
400
|
/**
|
|
368
401
|
* Create buffer source with hardware frames context.
|
|
369
402
|
*
|
|
370
|
-
* @
|
|
403
|
+
* @param frame - Frame with hw_frames_ctx
|
|
404
|
+
* @throws {Error} If creation fails
|
|
405
|
+
* @throws {FFmpegError} If configuration fails
|
|
371
406
|
*/
|
|
372
407
|
private createBufferSourceWithHwFrames;
|
|
373
408
|
/**
|
|
374
|
-
* Create
|
|
409
|
+
* Create standard buffer source.
|
|
375
410
|
*
|
|
376
|
-
* @
|
|
411
|
+
* @throws {Error} If creation fails
|
|
377
412
|
*/
|
|
378
413
|
private createBufferSource;
|
|
379
414
|
/**
|
|
380
|
-
* Create
|
|
415
|
+
* Create buffer sink.
|
|
381
416
|
*
|
|
382
|
-
* @
|
|
417
|
+
* @throws {Error} If creation fails
|
|
383
418
|
*/
|
|
384
419
|
private createBufferSink;
|
|
385
420
|
/**
|
|
386
|
-
* Parse
|
|
421
|
+
* Parse filter description and build graph.
|
|
387
422
|
*
|
|
388
|
-
* @
|
|
423
|
+
* @param description - Filter description string
|
|
424
|
+
* @throws {Error} If parsing fails
|
|
425
|
+
* @throws {FFmpegError} If graph construction fails
|
|
389
426
|
*/
|
|
390
427
|
private parseFilterDescription;
|
|
391
428
|
/**
|
|
392
|
-
* Check
|
|
393
|
-
*
|
|
394
|
-
* Validates that hardware context is provided when needed:
|
|
395
|
-
* - hwupload: Always requires hardware context
|
|
396
|
-
* - Hardware filters (AVFILTER_FLAG_HWDEVICE): Recommend hardware context
|
|
397
|
-
* - hwdownload: Warns if input is not hardware format
|
|
429
|
+
* Check hardware requirements for filters.
|
|
398
430
|
*
|
|
399
|
-
* @
|
|
431
|
+
* @param description - Filter description
|
|
432
|
+
* @param options - Filter options
|
|
433
|
+
* @throws {Error} If hardware requirements not met
|
|
400
434
|
*/
|
|
401
435
|
private checkHardwareRequirements;
|
|
402
436
|
/**
|
|
403
|
-
* Dispose of
|
|
437
|
+
* Dispose of filter.
|
|
404
438
|
*
|
|
405
|
-
* Implements
|
|
439
|
+
* Implements Disposable interface for automatic cleanup.
|
|
406
440
|
* Equivalent to calling free().
|
|
407
441
|
*
|
|
408
442
|
* @example
|
|
409
443
|
* ```typescript
|
|
410
444
|
* {
|
|
411
|
-
* using filter = await
|
|
412
|
-
* //
|
|
413
|
-
* } // Automatically freed
|
|
445
|
+
* using filter = await FilterAPI.create('scale=640:480', info);
|
|
446
|
+
* // Use filter...
|
|
447
|
+
* } // Automatically freed
|
|
414
448
|
* ```
|
|
449
|
+
*
|
|
450
|
+
* @see {@link free} For manual cleanup
|
|
415
451
|
*/
|
|
416
452
|
[Symbol.dispose](): void;
|
|
417
453
|
}
|