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
|
@@ -8,272 +8,282 @@ import type { HardwareFramesContext } from './hardware-frames-context.js';
|
|
|
8
8
|
import type { NativeDictionary, NativeFilterContext, NativeFilterGraph, NativeWrapper } from './native-types.js';
|
|
9
9
|
import type { ChannelLayout, IRational } from './types.js';
|
|
10
10
|
/**
|
|
11
|
-
* Filter
|
|
11
|
+
* Filter instance in a filter graph.
|
|
12
12
|
*
|
|
13
|
-
* Represents an
|
|
14
|
-
*
|
|
15
|
-
*
|
|
13
|
+
* Represents an instantiated filter within a filter graph. Each context contains
|
|
14
|
+
* a specific filter configuration with its parameters, connections to other filters,
|
|
15
|
+
* and input/output pads. Supports both software and hardware filtering operations.
|
|
16
|
+
* Essential for building complex filter chains for audio/video processing.
|
|
16
17
|
*
|
|
17
18
|
* Direct mapping to FFmpeg's AVFilterContext.
|
|
18
19
|
*
|
|
19
20
|
* @example
|
|
20
21
|
* ```typescript
|
|
21
|
-
* import { FilterGraph, Filter, FFmpegError } from 'node-av';
|
|
22
|
+
* import { FilterContext, FilterGraph, Filter, FFmpegError } from 'node-av';
|
|
22
23
|
*
|
|
23
|
-
* // Create filter context
|
|
24
|
-
* const
|
|
25
|
-
*
|
|
24
|
+
* // Create filter context in a graph
|
|
25
|
+
* const graph = new FilterGraph();
|
|
26
|
+
* const filter = Filter.getByName('scale');
|
|
27
|
+
* const context = graph.createFilter(filter, 'scaler');
|
|
26
28
|
*
|
|
27
|
-
*
|
|
28
|
-
* const
|
|
29
|
-
*
|
|
30
|
-
* FFmpegError.throwIfError(initRet, 'initStr buffer');
|
|
29
|
+
* // Initialize with parameters
|
|
30
|
+
* const ret = context.initStr('640:480');
|
|
31
|
+
* FFmpegError.throwIfError(ret, 'initStr');
|
|
31
32
|
*
|
|
32
|
-
* // Link filters
|
|
33
|
-
* const
|
|
34
|
-
*
|
|
35
|
-
* const scaleRet = scaleCtx.initStr('1280:720');
|
|
36
|
-
* FFmpegError.throwIfError(scaleRet, 'initStr scale');
|
|
33
|
+
* // Link filters together
|
|
34
|
+
* const ret2 = source.link(0, context, 0);
|
|
35
|
+
* FFmpegError.throwIfError(ret2, 'link');
|
|
37
36
|
*
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* // Configure and use the graph
|
|
42
|
-
* const configRet = filterGraph.config();
|
|
43
|
-
* FFmpegError.throwIfError(configRet, 'config');
|
|
37
|
+
* // For buffer source/sink
|
|
38
|
+
* const ret3 = await bufferSrc.buffersrcAddFrame(frame);
|
|
39
|
+
* FFmpegError.throwIfError(ret3, 'buffersrcAddFrame');
|
|
44
40
|
* ```
|
|
41
|
+
*
|
|
42
|
+
* @see [AVFilterContext](https://ffmpeg.org/doxygen/trunk/structAVFilterContext.html) - FFmpeg Doxygen
|
|
43
|
+
* @see {@link FilterGraph} For managing filter graphs
|
|
44
|
+
* @see {@link Filter} For filter descriptors
|
|
45
45
|
*/
|
|
46
46
|
export declare class FilterContext extends OptionMember<NativeFilterContext> implements Disposable, NativeWrapper<NativeFilterContext> {
|
|
47
47
|
private _hwDeviceCtx?;
|
|
48
48
|
/**
|
|
49
|
-
*
|
|
50
|
-
*
|
|
51
|
-
* FilterContexts are created and managed by FilterGraph.
|
|
52
|
-
* Do not instantiate directly.
|
|
53
|
-
*
|
|
49
|
+
* @param native - The native filter context instance
|
|
54
50
|
* @internal
|
|
55
|
-
*
|
|
56
|
-
* @param native - Native AVFilterContext to wrap
|
|
57
51
|
*/
|
|
58
52
|
constructor(native: NativeFilterContext);
|
|
59
53
|
/**
|
|
60
54
|
* Filter instance name.
|
|
61
55
|
*
|
|
62
|
-
*
|
|
56
|
+
* User-assigned name for this filter instance in the graph.
|
|
57
|
+
* Used for identification and debugging.
|
|
63
58
|
*
|
|
64
|
-
* Direct mapping to AVFilterContext->name
|
|
59
|
+
* Direct mapping to AVFilterContext->name.
|
|
65
60
|
*/
|
|
66
61
|
get name(): string | null;
|
|
67
62
|
set name(value: string | null);
|
|
68
63
|
/**
|
|
69
|
-
*
|
|
64
|
+
* Filter descriptor.
|
|
70
65
|
*
|
|
71
|
-
*
|
|
66
|
+
* Reference to the filter type this context instantiates.
|
|
72
67
|
*
|
|
73
|
-
* Direct mapping to AVFilterContext->filter
|
|
74
|
-
*
|
|
75
|
-
* @readonly
|
|
68
|
+
* Direct mapping to AVFilterContext->filter.
|
|
76
69
|
*/
|
|
77
70
|
get filter(): Filter | null;
|
|
78
71
|
/**
|
|
79
|
-
*
|
|
80
|
-
*
|
|
81
|
-
* The filter graph that contains this filter context.
|
|
72
|
+
* Parent filter graph.
|
|
82
73
|
*
|
|
83
|
-
*
|
|
74
|
+
* Reference to the graph containing this filter context.
|
|
84
75
|
*
|
|
85
|
-
*
|
|
76
|
+
* Direct mapping to AVFilterContext->graph.
|
|
86
77
|
*/
|
|
87
78
|
get graph(): NativeFilterGraph | null;
|
|
88
79
|
/**
|
|
89
80
|
* Number of input pads.
|
|
90
81
|
*
|
|
91
|
-
*
|
|
82
|
+
* Total number of input connections this filter can accept.
|
|
92
83
|
*
|
|
93
|
-
* Direct mapping to AVFilterContext->nb_inputs
|
|
94
|
-
*
|
|
95
|
-
* @readonly
|
|
84
|
+
* Direct mapping to AVFilterContext->nb_inputs.
|
|
96
85
|
*/
|
|
97
86
|
get nbInputs(): number;
|
|
98
87
|
/**
|
|
99
88
|
* Number of output pads.
|
|
100
89
|
*
|
|
101
|
-
*
|
|
90
|
+
* Total number of output connections this filter can provide.
|
|
102
91
|
*
|
|
103
|
-
*
|
|
92
|
+
* Direct mapping to AVFilterContext->nb_outputs.
|
|
104
93
|
*/
|
|
105
94
|
get nbOutputs(): number;
|
|
106
95
|
/**
|
|
107
|
-
* Filter readiness
|
|
96
|
+
* Filter readiness state.
|
|
108
97
|
*
|
|
109
|
-
*
|
|
98
|
+
* Indicates if the filter is ready for processing.
|
|
99
|
+
* Non-zero when ready.
|
|
110
100
|
*
|
|
111
|
-
*
|
|
101
|
+
* Direct mapping to AVFilterContext->ready.
|
|
112
102
|
*/
|
|
113
103
|
get ready(): number;
|
|
114
104
|
/**
|
|
115
|
-
*
|
|
105
|
+
* Hardware device context.
|
|
116
106
|
*
|
|
117
|
-
*
|
|
107
|
+
* Hardware acceleration context for GPU-based filtering.
|
|
108
|
+
* Set to enable hardware-accelerated filter operations.
|
|
118
109
|
*
|
|
119
|
-
*
|
|
120
|
-
* Must be set before filter initialization for hardware filters.
|
|
110
|
+
* Direct mapping to AVFilterContext->hw_device_ctx.
|
|
121
111
|
*/
|
|
122
112
|
get hwDeviceCtx(): HardwareDeviceContext | null;
|
|
123
113
|
set hwDeviceCtx(value: HardwareDeviceContext | null);
|
|
124
114
|
/**
|
|
125
|
-
* Initialize
|
|
115
|
+
* Initialize filter with dictionary options.
|
|
126
116
|
*
|
|
127
|
-
*
|
|
117
|
+
* Configures the filter with key-value option pairs.
|
|
118
|
+
* Must be called after creation and before processing.
|
|
128
119
|
*
|
|
129
|
-
*
|
|
120
|
+
* Direct mapping to avfilter_init_dict().
|
|
130
121
|
*
|
|
122
|
+
* @param options - Dictionary of filter options
|
|
131
123
|
* @returns 0 on success, negative AVERROR on error:
|
|
132
|
-
* -
|
|
133
|
-
* -
|
|
134
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
135
|
-
* - <0: Other filter-specific errors
|
|
124
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
125
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
136
126
|
*
|
|
137
127
|
* @example
|
|
138
128
|
* ```typescript
|
|
139
|
-
* import {
|
|
140
|
-
*
|
|
141
|
-
* const options = new Dictionary();
|
|
142
|
-
* const ret1 = options.set('width', '1280', 0);
|
|
143
|
-
* FFmpegError.throwIfError(ret1, 'set width');
|
|
144
|
-
* const ret2 = options.set('height', '720', 0);
|
|
145
|
-
* FFmpegError.throwIfError(ret2, 'set height');
|
|
129
|
+
* import { FFmpegError } from 'node-av';
|
|
146
130
|
*
|
|
147
|
-
* const
|
|
148
|
-
*
|
|
149
|
-
*
|
|
131
|
+
* const options = { width: '1920', height: '1080' };
|
|
132
|
+
* const ret = context.init(options);
|
|
133
|
+
* FFmpegError.throwIfError(ret, 'init');
|
|
150
134
|
* ```
|
|
151
135
|
*
|
|
152
|
-
* @see initStr
|
|
136
|
+
* @see {@link initStr} For string-based initialization
|
|
153
137
|
*/
|
|
154
138
|
init(options?: NativeDictionary | null): number;
|
|
155
139
|
/**
|
|
156
|
-
* Initialize
|
|
140
|
+
* Initialize filter with string arguments.
|
|
157
141
|
*
|
|
158
|
-
*
|
|
142
|
+
* Configures the filter using a string representation of parameters.
|
|
143
|
+
* Format depends on the specific filter.
|
|
159
144
|
*
|
|
160
|
-
*
|
|
145
|
+
* Direct mapping to avfilter_init_str().
|
|
161
146
|
*
|
|
147
|
+
* @param args - Filter arguments string
|
|
162
148
|
* @returns 0 on success, negative AVERROR on error:
|
|
163
|
-
* -
|
|
164
|
-
* -
|
|
165
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
166
|
-
* - <0: Other filter-specific errors
|
|
149
|
+
* - AVERROR_EINVAL: Invalid arguments
|
|
150
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
167
151
|
*
|
|
168
152
|
* @example
|
|
169
153
|
* ```typescript
|
|
170
|
-
* import {
|
|
154
|
+
* import { FFmpegError } from 'node-av';
|
|
171
155
|
*
|
|
172
|
-
* //
|
|
173
|
-
* const
|
|
174
|
-
* FFmpegError.throwIfError(
|
|
156
|
+
* // Scale filter with width:height
|
|
157
|
+
* const ret = scaleContext.initStr('1920:1080');
|
|
158
|
+
* FFmpegError.throwIfError(ret, 'initStr');
|
|
175
159
|
*
|
|
176
|
-
* //
|
|
177
|
-
* const
|
|
178
|
-
* FFmpegError.throwIfError(
|
|
160
|
+
* // Crop filter with width:height:x:y
|
|
161
|
+
* const ret2 = cropContext.initStr('640:480:100:50');
|
|
162
|
+
* FFmpegError.throwIfError(ret2, 'initStr');
|
|
179
163
|
* ```
|
|
180
164
|
*
|
|
181
|
-
* @see init
|
|
165
|
+
* @see {@link init} For dictionary-based initialization
|
|
182
166
|
*/
|
|
183
167
|
initStr(args?: string | null): number;
|
|
184
168
|
/**
|
|
185
169
|
* Link this filter's output to another filter's input.
|
|
186
170
|
*
|
|
187
|
-
*
|
|
171
|
+
* Creates a connection between two filters in the graph.
|
|
172
|
+
* Data flows from this filter's output pad to the destination's input pad.
|
|
188
173
|
*
|
|
189
|
-
*
|
|
190
|
-
* @param dst - Destination filter context
|
|
191
|
-
* @param dstPad - Input pad index on destination filter
|
|
174
|
+
* Direct mapping to avfilter_link().
|
|
192
175
|
*
|
|
176
|
+
* @param srcPad - Output pad index of this filter
|
|
177
|
+
* @param dst - Destination filter context
|
|
178
|
+
* @param dstPad - Input pad index of destination filter
|
|
193
179
|
* @returns 0 on success, negative AVERROR on error:
|
|
194
|
-
* -
|
|
195
|
-
* -
|
|
196
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
197
|
-
* - <0: Other linking errors
|
|
180
|
+
* - AVERROR_EINVAL: Invalid pad indices or incompatible formats
|
|
181
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
198
182
|
*
|
|
199
183
|
* @example
|
|
200
184
|
* ```typescript
|
|
201
|
-
* import {
|
|
185
|
+
* import { FFmpegError } from 'node-av';
|
|
202
186
|
*
|
|
203
|
-
* // Link
|
|
204
|
-
* const
|
|
205
|
-
* FFmpegError.throwIfError(
|
|
187
|
+
* // Link source output 0 to scale input 0
|
|
188
|
+
* const ret = source.link(0, scale, 0);
|
|
189
|
+
* FFmpegError.throwIfError(ret, 'link');
|
|
206
190
|
*
|
|
207
|
-
* // Link scale to sink
|
|
208
|
-
* const
|
|
209
|
-
* FFmpegError.throwIfError(
|
|
191
|
+
* // Link scale output 0 to sink input 0
|
|
192
|
+
* const ret2 = scale.link(0, sink, 0);
|
|
193
|
+
* FFmpegError.throwIfError(ret2, 'link');
|
|
210
194
|
* ```
|
|
195
|
+
*
|
|
196
|
+
* @see {@link unlink} To disconnect filters
|
|
211
197
|
*/
|
|
212
198
|
link(srcPad: number, dst: FilterContext, dstPad: number): number;
|
|
213
199
|
/**
|
|
214
200
|
* Unlink a filter pad.
|
|
215
201
|
*
|
|
216
|
-
*
|
|
217
|
-
*
|
|
202
|
+
* Disconnects a pad from its linked filter.
|
|
203
|
+
* Used to reconfigure filter connections.
|
|
218
204
|
*
|
|
219
|
-
*
|
|
205
|
+
* Direct mapping to avfilter_link_free().
|
|
206
|
+
*
|
|
207
|
+
* @param pad - Pad index to unlink
|
|
220
208
|
*
|
|
221
209
|
* @example
|
|
222
210
|
* ```typescript
|
|
223
|
-
* //
|
|
224
|
-
*
|
|
211
|
+
* // Disconnect output pad 0
|
|
212
|
+
* context.unlink(0);
|
|
225
213
|
* ```
|
|
214
|
+
*
|
|
215
|
+
* @see {@link link} To connect filters
|
|
226
216
|
*/
|
|
227
217
|
unlink(pad: number): void;
|
|
228
218
|
/**
|
|
229
219
|
* Add a frame to a buffer source filter.
|
|
230
220
|
*
|
|
231
|
-
*
|
|
221
|
+
* Sends a frame into the filter graph through a buffer source.
|
|
222
|
+
* Only valid for buffer source filters. Send null to signal EOF.
|
|
232
223
|
*
|
|
233
|
-
*
|
|
234
|
-
* to feed frames into the filter graph.
|
|
235
|
-
*
|
|
236
|
-
* @param frame - The frame to add (can be null to signal EOF)
|
|
224
|
+
* Direct mapping to av_buffersrc_add_frame().
|
|
237
225
|
*
|
|
226
|
+
* @param frame - Frame to send, or null for EOF
|
|
238
227
|
* @returns 0 on success, negative AVERROR on error:
|
|
239
|
-
* -
|
|
240
|
-
* -
|
|
241
|
-
* -
|
|
242
|
-
* -
|
|
228
|
+
* - AVERROR_EAGAIN: Filter needs more output consumption
|
|
229
|
+
* - AVERROR_EOF: Filter has been closed
|
|
230
|
+
* - AVERROR_EINVAL: Not a buffer source filter
|
|
231
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
243
232
|
*
|
|
244
233
|
* @example
|
|
245
234
|
* ```typescript
|
|
246
|
-
* import {
|
|
247
|
-
*
|
|
248
|
-
*
|
|
249
|
-
*
|
|
250
|
-
*
|
|
235
|
+
* import { FFmpegError } from 'node-av';
|
|
236
|
+
* import { AVERROR_EAGAIN } from 'node-av/constants';
|
|
237
|
+
*
|
|
238
|
+
* // Send frame to filter graph
|
|
239
|
+
* const ret = await bufferSrc.buffersrcAddFrame(frame);
|
|
240
|
+
* if (ret === AVERROR_EAGAIN) {
|
|
241
|
+
* // Need to consume output first
|
|
242
|
+
* } else {
|
|
243
|
+
* FFmpegError.throwIfError(ret, 'buffersrcAddFrame');
|
|
244
|
+
* }
|
|
251
245
|
*
|
|
252
|
-
* // Signal
|
|
253
|
-
*
|
|
254
|
-
* FFmpegError.throwIfError(eofRet, 'buffersrcAddFrame EOF');
|
|
246
|
+
* // Signal EOF
|
|
247
|
+
* await bufferSrc.buffersrcAddFrame(null);
|
|
255
248
|
* ```
|
|
249
|
+
*
|
|
250
|
+
* @see {@link buffersinkGetFrame} To retrieve filtered frames
|
|
256
251
|
*/
|
|
257
252
|
buffersrcAddFrame(frame: Frame | null): Promise<number>;
|
|
258
253
|
/**
|
|
259
254
|
* Set parameters for a buffer source filter.
|
|
260
255
|
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
264
|
-
*
|
|
265
|
-
*
|
|
266
|
-
* @param params -
|
|
267
|
-
* @
|
|
256
|
+
* Configures the format and properties of frames that will be sent
|
|
257
|
+
* to the buffer source. Must be called before sending frames.
|
|
258
|
+
*
|
|
259
|
+
* Direct mapping to av_buffersrc_parameters_set().
|
|
260
|
+
*
|
|
261
|
+
* @param params - Source parameters
|
|
262
|
+
* @param params.width - Video frame width
|
|
263
|
+
* @param params.height - Video frame height
|
|
264
|
+
* @param params.format - Pixel or sample format
|
|
265
|
+
* @param params.timeBase - Time base for timestamps
|
|
266
|
+
* @param params.frameRate - Video frame rate
|
|
267
|
+
* @param params.sampleAspectRatio - Pixel aspect ratio
|
|
268
|
+
* @param params.hwFramesCtx - Hardware frames context
|
|
269
|
+
* @param params.sampleRate - Audio sample rate
|
|
270
|
+
* @param params.channelLayout - Audio channel layout
|
|
271
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
272
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
273
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
268
274
|
*
|
|
269
275
|
* @example
|
|
270
276
|
* ```typescript
|
|
271
|
-
*
|
|
277
|
+
* import { FFmpegError, Rational } from 'node-av';
|
|
278
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
279
|
+
*
|
|
280
|
+
* // Configure video buffer source
|
|
281
|
+
* const ret = bufferSrc.buffersrcParametersSet({
|
|
272
282
|
* width: 1920,
|
|
273
283
|
* height: 1080,
|
|
274
284
|
* format: AV_PIX_FMT_YUV420P,
|
|
275
|
-
* timeBase: { num: 1, den:
|
|
276
|
-
*
|
|
285
|
+
* timeBase: { num: 1, den: 25 },
|
|
286
|
+
* frameRate: { num: 25, den: 1 }
|
|
277
287
|
* });
|
|
278
288
|
* FFmpegError.throwIfError(ret, 'buffersrcParametersSet');
|
|
279
289
|
* ```
|
|
@@ -292,195 +302,251 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
|
|
|
292
302
|
/**
|
|
293
303
|
* Get a frame from a buffer sink filter.
|
|
294
304
|
*
|
|
295
|
-
*
|
|
296
|
-
*
|
|
297
|
-
* This function is specific to buffer sink filters and is used
|
|
298
|
-
* to retrieve filtered frames from the filter graph.
|
|
305
|
+
* Retrieves a filtered frame from the filter graph through a buffer sink.
|
|
306
|
+
* Only valid for buffer sink filters.
|
|
299
307
|
*
|
|
300
|
-
*
|
|
308
|
+
* Direct mapping to av_buffersink_get_frame().
|
|
301
309
|
*
|
|
310
|
+
* @param frame - Frame to receive filtered data
|
|
302
311
|
* @returns 0 on success, negative AVERROR on error:
|
|
303
|
-
* -
|
|
304
|
-
* -
|
|
305
|
-
* -
|
|
306
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
312
|
+
* - AVERROR_EAGAIN: No frame available yet
|
|
313
|
+
* - AVERROR_EOF: No more frames will be produced
|
|
314
|
+
* - AVERROR_EINVAL: Not a buffer sink filter
|
|
307
315
|
*
|
|
308
316
|
* @example
|
|
309
317
|
* ```typescript
|
|
310
|
-
* import {
|
|
318
|
+
* import { FFmpegError, Frame } from 'node-av';
|
|
311
319
|
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
|
|
312
320
|
*
|
|
313
|
-
* // Get filtered frames
|
|
314
321
|
* const frame = new Frame();
|
|
315
322
|
* frame.alloc();
|
|
316
323
|
*
|
|
317
|
-
*
|
|
318
|
-
*
|
|
319
|
-
* //
|
|
320
|
-
*
|
|
321
|
-
*
|
|
322
|
-
*
|
|
323
|
-
* // Try to get another frame
|
|
324
|
-
* ret = sinkCtx.buffersinkGetFrame(frame);
|
|
325
|
-
* }
|
|
326
|
-
*
|
|
327
|
-
* if (!FFmpegError.is(ret, AVERROR_EAGAIN) && !FFmpegError.is(ret, AVERROR_EOF)) {
|
|
324
|
+
* const ret = await bufferSink.buffersinkGetFrame(frame);
|
|
325
|
+
* if (ret === AVERROR_EAGAIN) {
|
|
326
|
+
* // No frame available yet
|
|
327
|
+
* } else if (ret === AVERROR_EOF) {
|
|
328
|
+
* // End of stream
|
|
329
|
+
* } else {
|
|
328
330
|
* FFmpegError.throwIfError(ret, 'buffersinkGetFrame');
|
|
331
|
+
* // Process filtered frame
|
|
329
332
|
* }
|
|
330
333
|
* ```
|
|
334
|
+
*
|
|
335
|
+
* @see {@link buffersrcAddFrame} To send frames for filtering
|
|
331
336
|
*/
|
|
332
337
|
buffersinkGetFrame(frame: Frame): Promise<number>;
|
|
333
338
|
/**
|
|
334
|
-
*
|
|
339
|
+
* Get time base from buffer sink.
|
|
335
340
|
*
|
|
336
|
-
*
|
|
341
|
+
* Returns the time base of frames from a buffer sink filter.
|
|
342
|
+
* Only valid for buffer sink filters.
|
|
337
343
|
*
|
|
338
|
-
*
|
|
344
|
+
* Direct mapping to av_buffersink_get_time_base().
|
|
339
345
|
*
|
|
340
|
-
* @
|
|
346
|
+
* @returns Time base as Rational
|
|
341
347
|
*
|
|
342
348
|
* @example
|
|
343
349
|
* ```typescript
|
|
344
|
-
*
|
|
345
|
-
*
|
|
346
|
-
* }
|
|
350
|
+
* const timeBase = bufferSink.buffersinkGetTimeBase();
|
|
351
|
+
* console.log(`Time base: ${timeBase.num}/${timeBase.den}`);
|
|
347
352
|
* ```
|
|
348
353
|
*/
|
|
354
|
+
buffersinkGetTimeBase(): Rational;
|
|
349
355
|
/**
|
|
350
|
-
* Get
|
|
356
|
+
* Get pixel/sample format from buffer sink.
|
|
351
357
|
*
|
|
352
|
-
*
|
|
358
|
+
* Returns the format of frames from a buffer sink filter.
|
|
359
|
+
* Only valid for buffer sink filters.
|
|
353
360
|
*
|
|
354
|
-
*
|
|
361
|
+
* Direct mapping to av_buffersink_get_format().
|
|
355
362
|
*
|
|
356
|
-
* @returns
|
|
363
|
+
* @returns Pixel format for video, sample format for audio
|
|
357
364
|
*
|
|
358
365
|
* @example
|
|
359
366
|
* ```typescript
|
|
360
|
-
*
|
|
361
|
-
*
|
|
367
|
+
* import { AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
368
|
+
*
|
|
369
|
+
* const format = bufferSink.buffersinkGetFormat();
|
|
370
|
+
* if (format === AV_PIX_FMT_YUV420P) {
|
|
371
|
+
* console.log('Output is YUV420P');
|
|
372
|
+
* }
|
|
362
373
|
* ```
|
|
363
374
|
*/
|
|
364
|
-
|
|
375
|
+
buffersinkGetFormat(): AVPixelFormat | AVSampleFormat;
|
|
365
376
|
/**
|
|
366
|
-
* Get
|
|
377
|
+
* Get frame width from buffer sink.
|
|
367
378
|
*
|
|
368
|
-
*
|
|
379
|
+
* Returns the width of video frames from a buffer sink filter.
|
|
380
|
+
* Only valid for video buffer sink filters.
|
|
369
381
|
*
|
|
370
|
-
*
|
|
371
|
-
*/
|
|
372
|
-
buffersinkGetFormat(): AVPixelFormat | AVSampleFormat;
|
|
373
|
-
/**
|
|
374
|
-
* Get the width from a video buffersink filter.
|
|
382
|
+
* Direct mapping to av_buffersink_get_w().
|
|
375
383
|
*
|
|
376
|
-
*
|
|
384
|
+
* @returns Frame width in pixels
|
|
377
385
|
*
|
|
378
|
-
* @
|
|
386
|
+
* @example
|
|
387
|
+
* ```typescript
|
|
388
|
+
* const width = bufferSink.buffersinkGetWidth();
|
|
389
|
+
* console.log(`Output width: ${width}px`);
|
|
390
|
+
* ```
|
|
379
391
|
*/
|
|
380
392
|
buffersinkGetWidth(): number;
|
|
381
393
|
/**
|
|
382
|
-
* Get
|
|
394
|
+
* Get frame height from buffer sink.
|
|
383
395
|
*
|
|
384
|
-
*
|
|
396
|
+
* Returns the height of video frames from a buffer sink filter.
|
|
397
|
+
* Only valid for video buffer sink filters.
|
|
385
398
|
*
|
|
386
|
-
*
|
|
399
|
+
* Direct mapping to av_buffersink_get_h().
|
|
400
|
+
*
|
|
401
|
+
* @returns Frame height in pixels
|
|
402
|
+
*
|
|
403
|
+
* @example
|
|
404
|
+
* ```typescript
|
|
405
|
+
* const height = bufferSink.buffersinkGetHeight();
|
|
406
|
+
* console.log(`Output height: ${height}px`);
|
|
407
|
+
* ```
|
|
387
408
|
*/
|
|
388
409
|
buffersinkGetHeight(): number;
|
|
389
410
|
/**
|
|
390
|
-
* Get
|
|
411
|
+
* Get sample aspect ratio from buffer sink.
|
|
412
|
+
*
|
|
413
|
+
* Returns the pixel aspect ratio of video frames from a buffer sink filter.
|
|
414
|
+
* Only valid for video buffer sink filters.
|
|
415
|
+
*
|
|
416
|
+
* Direct mapping to av_buffersink_get_sample_aspect_ratio().
|
|
391
417
|
*
|
|
392
|
-
*
|
|
418
|
+
* @returns Sample aspect ratio as Rational
|
|
393
419
|
*
|
|
394
|
-
* @
|
|
420
|
+
* @example
|
|
421
|
+
* ```typescript
|
|
422
|
+
* const sar = bufferSink.buffersinkGetSampleAspectRatio();
|
|
423
|
+
* console.log(`SAR: ${sar.num}:${sar.den}`);
|
|
424
|
+
* ```
|
|
395
425
|
*/
|
|
396
426
|
buffersinkGetSampleAspectRatio(): Rational;
|
|
397
427
|
/**
|
|
398
|
-
* Get
|
|
428
|
+
* Get frame rate from buffer sink.
|
|
429
|
+
*
|
|
430
|
+
* Returns the frame rate of video from a buffer sink filter.
|
|
431
|
+
* Only valid for video buffer sink filters.
|
|
399
432
|
*
|
|
400
|
-
* Direct mapping to av_buffersink_get_frame_rate()
|
|
433
|
+
* Direct mapping to av_buffersink_get_frame_rate().
|
|
401
434
|
*
|
|
402
|
-
* @returns
|
|
435
|
+
* @returns Frame rate as Rational
|
|
436
|
+
*
|
|
437
|
+
* @example
|
|
438
|
+
* ```typescript
|
|
439
|
+
* const frameRate = bufferSink.buffersinkGetFrameRate();
|
|
440
|
+
* console.log(`Frame rate: ${frameRate.num}/${frameRate.den} fps`);
|
|
441
|
+
* ```
|
|
403
442
|
*/
|
|
404
443
|
buffersinkGetFrameRate(): Rational;
|
|
405
444
|
/**
|
|
406
|
-
* Get
|
|
445
|
+
* Get sample rate from buffer sink.
|
|
446
|
+
*
|
|
447
|
+
* Returns the sample rate of audio from a buffer sink filter.
|
|
448
|
+
* Only valid for audio buffer sink filters.
|
|
407
449
|
*
|
|
408
|
-
* Direct mapping to av_buffersink_get_sample_rate()
|
|
450
|
+
* Direct mapping to av_buffersink_get_sample_rate().
|
|
409
451
|
*
|
|
410
|
-
* @returns
|
|
452
|
+
* @returns Sample rate in Hz
|
|
453
|
+
*
|
|
454
|
+
* @example
|
|
455
|
+
* ```typescript
|
|
456
|
+
* const sampleRate = bufferSink.buffersinkGetSampleRate();
|
|
457
|
+
* console.log(`Sample rate: ${sampleRate} Hz`);
|
|
458
|
+
* ```
|
|
411
459
|
*/
|
|
412
460
|
buffersinkGetSampleRate(): number;
|
|
413
461
|
/**
|
|
414
|
-
* Get
|
|
462
|
+
* Get channel layout from buffer sink.
|
|
463
|
+
*
|
|
464
|
+
* Returns the channel layout of audio from a buffer sink filter.
|
|
465
|
+
* Only valid for audio buffer sink filters.
|
|
466
|
+
*
|
|
467
|
+
* Direct mapping to av_buffersink_get_channel_layout().
|
|
415
468
|
*
|
|
416
|
-
*
|
|
469
|
+
* @returns Channel layout configuration
|
|
417
470
|
*
|
|
418
|
-
* @
|
|
471
|
+
* @example
|
|
472
|
+
* ```typescript
|
|
473
|
+
* const layout = bufferSink.buffersinkGetChannelLayout();
|
|
474
|
+
* console.log(`Channels: ${layout.nbChannels}`);
|
|
475
|
+
* ```
|
|
419
476
|
*/
|
|
420
477
|
buffersinkGetChannelLayout(): ChannelLayout;
|
|
421
478
|
/**
|
|
422
479
|
* Free the filter context.
|
|
423
480
|
*
|
|
424
|
-
*
|
|
481
|
+
* Releases all resources associated with the filter context.
|
|
482
|
+
* The context becomes invalid after calling this.
|
|
483
|
+
*
|
|
484
|
+
* Direct mapping to avfilter_free().
|
|
425
485
|
*
|
|
426
486
|
* @example
|
|
427
487
|
* ```typescript
|
|
428
|
-
*
|
|
429
|
-
* //
|
|
488
|
+
* context.free();
|
|
489
|
+
* // Context is now invalid
|
|
430
490
|
* ```
|
|
491
|
+
*
|
|
492
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
431
493
|
*/
|
|
432
494
|
free(): void;
|
|
433
495
|
/**
|
|
434
|
-
* Check if
|
|
496
|
+
* Check if filter is a source.
|
|
435
497
|
*
|
|
436
|
-
* Source filters
|
|
498
|
+
* Source filters generate frames without input.
|
|
437
499
|
*
|
|
438
|
-
* @returns
|
|
500
|
+
* @returns True if filter has no inputs
|
|
439
501
|
*
|
|
440
502
|
* @example
|
|
441
503
|
* ```typescript
|
|
442
|
-
* if (
|
|
504
|
+
* if (context.isSource()) {
|
|
443
505
|
* console.log('This is a source filter');
|
|
444
506
|
* }
|
|
445
507
|
* ```
|
|
508
|
+
*
|
|
509
|
+
* @see {@link isSink} To check for sink filters
|
|
446
510
|
*/
|
|
447
511
|
isSource(): boolean;
|
|
448
512
|
/**
|
|
449
|
-
* Check if
|
|
513
|
+
* Check if filter is a sink.
|
|
450
514
|
*
|
|
451
|
-
* Sink filters
|
|
515
|
+
* Sink filters consume frames without output.
|
|
452
516
|
*
|
|
453
|
-
* @returns
|
|
517
|
+
* @returns True if filter has no outputs
|
|
454
518
|
*
|
|
455
519
|
* @example
|
|
456
520
|
* ```typescript
|
|
457
|
-
* if (
|
|
521
|
+
* if (context.isSink()) {
|
|
458
522
|
* console.log('This is a sink filter');
|
|
459
523
|
* }
|
|
460
524
|
* ```
|
|
525
|
+
*
|
|
526
|
+
* @see {@link isSource} To check for source filters
|
|
461
527
|
*/
|
|
462
528
|
isSink(): boolean;
|
|
463
529
|
/**
|
|
464
|
-
* Check if
|
|
530
|
+
* Check if filter is ready.
|
|
465
531
|
*
|
|
466
|
-
*
|
|
532
|
+
* Indicates whether the filter is ready for processing.
|
|
467
533
|
*
|
|
468
|
-
* @returns
|
|
534
|
+
* @returns True if filter is ready
|
|
469
535
|
*
|
|
470
536
|
* @example
|
|
471
537
|
* ```typescript
|
|
472
|
-
*
|
|
473
|
-
*
|
|
474
|
-
* console.log('Filter is ready for processing');
|
|
538
|
+
* if (context.isReady()) {
|
|
539
|
+
* // Filter is ready for processing
|
|
475
540
|
* }
|
|
476
541
|
* ```
|
|
477
542
|
*/
|
|
478
543
|
isReady(): boolean;
|
|
479
544
|
/**
|
|
480
|
-
* Get the native
|
|
545
|
+
* Get the underlying native FilterContext object.
|
|
481
546
|
*
|
|
482
|
-
* @
|
|
483
|
-
*
|
|
547
|
+
* @returns The native FilterContext binding object
|
|
548
|
+
*
|
|
549
|
+
* @internal
|
|
484
550
|
*/
|
|
485
551
|
getNative(): NativeFilterContext;
|
|
486
552
|
/**
|
|
@@ -492,9 +558,9 @@ export declare class FilterContext extends OptionMember<NativeFilterContext> imp
|
|
|
492
558
|
* @example
|
|
493
559
|
* ```typescript
|
|
494
560
|
* {
|
|
495
|
-
* using
|
|
496
|
-
*
|
|
497
|
-
* //
|
|
561
|
+
* using context = graph.createFilter(filter, 'test');
|
|
562
|
+
* context.initStr('640:480');
|
|
563
|
+
* // Use context...
|
|
498
564
|
* } // Automatically freed when leaving scope
|
|
499
565
|
* ```
|
|
500
566
|
*/
|