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