node-av 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,505 @@
|
|
|
1
|
+
import { Filter } from './filter.js';
|
|
2
|
+
import { HardwareDeviceContext } from './hardware-device-context.js';
|
|
3
|
+
import { OptionMember } from './option.js';
|
|
4
|
+
import { Rational } from './rational.js';
|
|
5
|
+
/**
|
|
6
|
+
* Filter context for media processing.
|
|
7
|
+
*
|
|
8
|
+
* Represents an instance of a filter in a filter graph.
|
|
9
|
+
* Manages filter configuration, parameters, and connections.
|
|
10
|
+
* Must be created through FilterGraph.createFilter() and properly initialized before use.
|
|
11
|
+
*
|
|
12
|
+
* Direct mapping to FFmpeg's AVFilterContext.
|
|
13
|
+
*
|
|
14
|
+
* @example
|
|
15
|
+
* ```typescript
|
|
16
|
+
* import { FilterGraph, Filter, FFmpegError } from 'node-av';
|
|
17
|
+
*
|
|
18
|
+
* // Create filter context through FilterGraph
|
|
19
|
+
* const filterGraph = new FilterGraph();
|
|
20
|
+
* filterGraph.alloc();
|
|
21
|
+
*
|
|
22
|
+
* const bufferFilter = Filter.getByName('buffer');
|
|
23
|
+
* const bufferCtx = filterGraph.createFilter(bufferFilter, 'in');
|
|
24
|
+
* const initRet = bufferCtx.initStr('video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25:pixel_aspect=1/1');
|
|
25
|
+
* FFmpegError.throwIfError(initRet, 'initStr buffer');
|
|
26
|
+
*
|
|
27
|
+
* // Link filters
|
|
28
|
+
* const scaleFilter = Filter.getByName('scale');
|
|
29
|
+
* const scaleCtx = filterGraph.createFilter(scaleFilter, 'scale');
|
|
30
|
+
* const scaleRet = scaleCtx.initStr('1280:720');
|
|
31
|
+
* FFmpegError.throwIfError(scaleRet, 'initStr scale');
|
|
32
|
+
*
|
|
33
|
+
* const linkRet = bufferCtx.link(0, scaleCtx, 0);
|
|
34
|
+
* FFmpegError.throwIfError(linkRet, 'link');
|
|
35
|
+
*
|
|
36
|
+
* // Configure and use the graph
|
|
37
|
+
* const configRet = filterGraph.config();
|
|
38
|
+
* FFmpegError.throwIfError(configRet, 'config');
|
|
39
|
+
* ```
|
|
40
|
+
*/
|
|
41
|
+
export class FilterContext extends OptionMember {
|
|
42
|
+
_hwDeviceCtx; // Cache for hardware device context wrapper
|
|
43
|
+
/**
|
|
44
|
+
* Constructor is internal - use FilterGraph.createFilter().
|
|
45
|
+
*
|
|
46
|
+
* FilterContexts are created and managed by FilterGraph.
|
|
47
|
+
* Do not instantiate directly.
|
|
48
|
+
*
|
|
49
|
+
* @internal
|
|
50
|
+
*
|
|
51
|
+
* @param native - Native AVFilterContext to wrap
|
|
52
|
+
*/
|
|
53
|
+
constructor(native) {
|
|
54
|
+
super(native);
|
|
55
|
+
}
|
|
56
|
+
/**
|
|
57
|
+
* Filter instance name.
|
|
58
|
+
*
|
|
59
|
+
* The unique name of this filter instance in the graph.
|
|
60
|
+
*
|
|
61
|
+
* Direct mapping to AVFilterContext->name
|
|
62
|
+
*/
|
|
63
|
+
get name() {
|
|
64
|
+
return this.native.name;
|
|
65
|
+
}
|
|
66
|
+
set name(value) {
|
|
67
|
+
this.native.name = value;
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* The filter definition.
|
|
71
|
+
*
|
|
72
|
+
* The AVFilter that this context is an instance of.
|
|
73
|
+
*
|
|
74
|
+
* Direct mapping to AVFilterContext->filter
|
|
75
|
+
*
|
|
76
|
+
* @readonly
|
|
77
|
+
*/
|
|
78
|
+
get filter() {
|
|
79
|
+
const native = this.native.filter;
|
|
80
|
+
return native ? new Filter(native) : null;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* The parent filter graph.
|
|
84
|
+
*
|
|
85
|
+
* The filter graph that contains this filter context.
|
|
86
|
+
*
|
|
87
|
+
* Direct mapping to AVFilterContext->graph
|
|
88
|
+
*
|
|
89
|
+
* @readonly
|
|
90
|
+
*/
|
|
91
|
+
get graph() {
|
|
92
|
+
return this.native.graph;
|
|
93
|
+
}
|
|
94
|
+
/**
|
|
95
|
+
* Number of input pads.
|
|
96
|
+
*
|
|
97
|
+
* The number of input connections this filter can accept.
|
|
98
|
+
*
|
|
99
|
+
* Direct mapping to AVFilterContext->nb_inputs
|
|
100
|
+
*
|
|
101
|
+
* @readonly
|
|
102
|
+
*/
|
|
103
|
+
get nbInputs() {
|
|
104
|
+
return this.native.nbInputs;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* Number of output pads.
|
|
108
|
+
*
|
|
109
|
+
* Direct mapping to AVFilterContext->nb_outputs
|
|
110
|
+
*
|
|
111
|
+
* The number of output connections this filter can provide.
|
|
112
|
+
*/
|
|
113
|
+
get nbOutputs() {
|
|
114
|
+
return this.native.nbOutputs;
|
|
115
|
+
}
|
|
116
|
+
/**
|
|
117
|
+
* Filter readiness status.
|
|
118
|
+
*
|
|
119
|
+
* Direct mapping to AVFilterContext->ready
|
|
120
|
+
*
|
|
121
|
+
* Non-zero when the filter has been properly initialized.
|
|
122
|
+
*/
|
|
123
|
+
get ready() {
|
|
124
|
+
return this.native.ready;
|
|
125
|
+
}
|
|
126
|
+
/**
|
|
127
|
+
* Get or set the hardware device context.
|
|
128
|
+
*
|
|
129
|
+
* Direct mapping to AVFilterContext->hw_device_ctx
|
|
130
|
+
*
|
|
131
|
+
* Used for hardware-accelerated filters that need device context.
|
|
132
|
+
* Must be set before filter initialization for hardware filters.
|
|
133
|
+
*/
|
|
134
|
+
get hwDeviceCtx() {
|
|
135
|
+
const native = this.native.hwDeviceCtx;
|
|
136
|
+
if (!native) {
|
|
137
|
+
// Clear cache if native is null
|
|
138
|
+
this._hwDeviceCtx = undefined;
|
|
139
|
+
return null;
|
|
140
|
+
}
|
|
141
|
+
// Return cached wrapper if available and still valid
|
|
142
|
+
if (this._hwDeviceCtx && this._hwDeviceCtx.native === native) {
|
|
143
|
+
return this._hwDeviceCtx;
|
|
144
|
+
}
|
|
145
|
+
// Create and cache new wrapper
|
|
146
|
+
const device = Object.create(HardwareDeviceContext.prototype);
|
|
147
|
+
device.native = native;
|
|
148
|
+
this._hwDeviceCtx = device;
|
|
149
|
+
return device;
|
|
150
|
+
}
|
|
151
|
+
set hwDeviceCtx(value) {
|
|
152
|
+
this.native.hwDeviceCtx = value?.getNative() ?? null;
|
|
153
|
+
// Clear cache when setting new value
|
|
154
|
+
this._hwDeviceCtx = undefined;
|
|
155
|
+
}
|
|
156
|
+
/**
|
|
157
|
+
* Initialize the filter with options.
|
|
158
|
+
*
|
|
159
|
+
* Direct mapping to avfilter_init_dict()
|
|
160
|
+
*
|
|
161
|
+
* @param options - Optional dictionary of filter options
|
|
162
|
+
*
|
|
163
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
164
|
+
* - 0: Success
|
|
165
|
+
* - AVERROR(EINVAL): Invalid options
|
|
166
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
167
|
+
* - <0: Other filter-specific errors
|
|
168
|
+
*
|
|
169
|
+
* @example
|
|
170
|
+
* ```typescript
|
|
171
|
+
* import { Dictionary, FilterContext, FFmpegError } from 'node-av';
|
|
172
|
+
*
|
|
173
|
+
* const options = new Dictionary();
|
|
174
|
+
* const ret1 = options.set('width', '1280', 0);
|
|
175
|
+
* FFmpegError.throwIfError(ret1, 'set width');
|
|
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();
|
|
182
|
+
* ```
|
|
183
|
+
*
|
|
184
|
+
* @see initStr() - Alternative initialization with string arguments
|
|
185
|
+
*/
|
|
186
|
+
init(options = null) {
|
|
187
|
+
return this.native.init(options ?? null);
|
|
188
|
+
}
|
|
189
|
+
/**
|
|
190
|
+
* Initialize the filter with a string argument.
|
|
191
|
+
*
|
|
192
|
+
* Direct mapping to avfilter_init_str()
|
|
193
|
+
*
|
|
194
|
+
* @param args - Filter arguments string (format is filter-specific)
|
|
195
|
+
*
|
|
196
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
197
|
+
* - 0: Success
|
|
198
|
+
* - AVERROR(EINVAL): Invalid arguments
|
|
199
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
200
|
+
* - <0: Other filter-specific errors
|
|
201
|
+
*
|
|
202
|
+
* @example
|
|
203
|
+
* ```typescript
|
|
204
|
+
* import { FilterContext, FFmpegError } from 'node-av';
|
|
205
|
+
*
|
|
206
|
+
* // Initialize scale filter
|
|
207
|
+
* const scaleRet = scaleCtx.initStr('1280:720');
|
|
208
|
+
* FFmpegError.throwIfError(scaleRet, 'initStr scale');
|
|
209
|
+
*
|
|
210
|
+
* // Initialize buffer source
|
|
211
|
+
* const bufferRet = bufferCtx.initStr('video_size=1920x1080:pix_fmt=yuv420p:time_base=1/25');
|
|
212
|
+
* FFmpegError.throwIfError(bufferRet, 'initStr buffer');
|
|
213
|
+
* ```
|
|
214
|
+
*
|
|
215
|
+
* @see init() - Alternative initialization with dictionary
|
|
216
|
+
*/
|
|
217
|
+
initStr(args = null) {
|
|
218
|
+
return this.native.initStr(args ?? null);
|
|
219
|
+
}
|
|
220
|
+
/**
|
|
221
|
+
* Link this filter's output to another filter's input.
|
|
222
|
+
*
|
|
223
|
+
* Direct mapping to avfilter_link()
|
|
224
|
+
*
|
|
225
|
+
* @param srcPad - Output pad index on this filter
|
|
226
|
+
* @param dst - Destination filter context
|
|
227
|
+
* @param dstPad - Input pad index on destination filter
|
|
228
|
+
*
|
|
229
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
230
|
+
* - 0: Success
|
|
231
|
+
* - AVERROR(EINVAL): Invalid pad indices or incompatible formats
|
|
232
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
233
|
+
* - <0: Other linking errors
|
|
234
|
+
*
|
|
235
|
+
* @example
|
|
236
|
+
* ```typescript
|
|
237
|
+
* import { FilterContext, FFmpegError } from 'node-av';
|
|
238
|
+
*
|
|
239
|
+
* // Link buffer source to scale filter
|
|
240
|
+
* const linkRet1 = bufferCtx.link(0, scaleCtx, 0);
|
|
241
|
+
* FFmpegError.throwIfError(linkRet1, 'link buffer to scale');
|
|
242
|
+
*
|
|
243
|
+
* // Link scale to sink
|
|
244
|
+
* const linkRet2 = scaleCtx.link(0, sinkCtx, 0);
|
|
245
|
+
* FFmpegError.throwIfError(linkRet2, 'link scale to sink');
|
|
246
|
+
* ```
|
|
247
|
+
*/
|
|
248
|
+
link(srcPad, dst, dstPad) {
|
|
249
|
+
return this.native.link(srcPad, dst.native, dstPad);
|
|
250
|
+
}
|
|
251
|
+
/**
|
|
252
|
+
* Unlink a filter pad.
|
|
253
|
+
*
|
|
254
|
+
* Removes the connection from the specified input pad.
|
|
255
|
+
* Note: avfilter_link_free is deprecated, we set pointer to nullptr instead.
|
|
256
|
+
*
|
|
257
|
+
* @param pad - Input pad index to unlink
|
|
258
|
+
*
|
|
259
|
+
* @example
|
|
260
|
+
* ```typescript
|
|
261
|
+
* // Unlink the first input pad
|
|
262
|
+
* filterCtx.unlink(0);
|
|
263
|
+
* ```
|
|
264
|
+
*/
|
|
265
|
+
unlink(pad) {
|
|
266
|
+
this.native.unlink(pad);
|
|
267
|
+
}
|
|
268
|
+
/**
|
|
269
|
+
* Add a frame to a buffer source filter.
|
|
270
|
+
*
|
|
271
|
+
* Direct mapping to av_buffersrc_add_frame()
|
|
272
|
+
*
|
|
273
|
+
* This function is specific to buffer source filters and is used
|
|
274
|
+
* to feed frames into the filter graph.
|
|
275
|
+
*
|
|
276
|
+
* @param frame - The frame to add (can be null to signal EOF)
|
|
277
|
+
*
|
|
278
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
279
|
+
* - 0: Success
|
|
280
|
+
* - AVERROR(EAGAIN): The buffer is full, try again later
|
|
281
|
+
* - AVERROR(EINVAL): Invalid parameters
|
|
282
|
+
* - AVERROR_EOF: The filter has been closed
|
|
283
|
+
*
|
|
284
|
+
* @example
|
|
285
|
+
* ```typescript
|
|
286
|
+
* import { Frame, FilterContext, FFmpegError } from 'node-av';
|
|
287
|
+
*
|
|
288
|
+
* // Feed a frame to the buffer source
|
|
289
|
+
* const addRet = srcCtx.buffersrcAddFrame(frame);
|
|
290
|
+
* FFmpegError.throwIfError(addRet, 'buffersrcAddFrame');
|
|
291
|
+
*
|
|
292
|
+
* // Signal end of stream
|
|
293
|
+
* const eofRet = srcCtx.buffersrcAddFrame(null);
|
|
294
|
+
* FFmpegError.throwIfError(eofRet, 'buffersrcAddFrame EOF');
|
|
295
|
+
* ```
|
|
296
|
+
*/
|
|
297
|
+
async buffersrcAddFrame(frame) {
|
|
298
|
+
return this.native.buffersrcAddFrame(frame ? frame.getNative() : null);
|
|
299
|
+
}
|
|
300
|
+
/**
|
|
301
|
+
* Set parameters for a buffer source filter.
|
|
302
|
+
*
|
|
303
|
+
* Direct mapping to av_buffersrc_parameters_set()
|
|
304
|
+
*
|
|
305
|
+
* This function configures a buffer source filter with specific parameters,
|
|
306
|
+
* including hardware frames context for hardware-accelerated filtering.
|
|
307
|
+
*
|
|
308
|
+
* @param params - Parameters for the buffer source
|
|
309
|
+
* @returns 0 on success, negative error code on failure
|
|
310
|
+
*
|
|
311
|
+
* @example
|
|
312
|
+
* ```typescript
|
|
313
|
+
* const ret = srcCtx.buffersrcParametersSet({
|
|
314
|
+
* width: 1920,
|
|
315
|
+
* height: 1080,
|
|
316
|
+
* format: AV_PIX_FMT_YUV420P,
|
|
317
|
+
* timeBase: { num: 1, den: 30 },
|
|
318
|
+
* hwFramesCtx: hardware.framesContext
|
|
319
|
+
* });
|
|
320
|
+
* FFmpegError.throwIfError(ret, 'buffersrcParametersSet');
|
|
321
|
+
* ```
|
|
322
|
+
*/
|
|
323
|
+
buffersrcParametersSet(params) {
|
|
324
|
+
const nativeParams = { ...params };
|
|
325
|
+
if (params.hwFramesCtx) {
|
|
326
|
+
nativeParams.hwFramesCtx = params.hwFramesCtx.getNative();
|
|
327
|
+
}
|
|
328
|
+
return this.native.buffersrcParametersSet(nativeParams);
|
|
329
|
+
}
|
|
330
|
+
/**
|
|
331
|
+
* Get a frame from a buffer sink filter.
|
|
332
|
+
*
|
|
333
|
+
* Direct mapping to av_buffersink_get_frame()
|
|
334
|
+
*
|
|
335
|
+
* This function is specific to buffer sink filters and is used
|
|
336
|
+
* to retrieve filtered frames from the filter graph.
|
|
337
|
+
*
|
|
338
|
+
* @param frame - The frame to receive the filtered data
|
|
339
|
+
*
|
|
340
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
341
|
+
* - 0: Success, frame contains valid data
|
|
342
|
+
* - AVERROR(EAGAIN): No frame available, need more input
|
|
343
|
+
* - AVERROR_EOF: End of stream reached
|
|
344
|
+
* - AVERROR(EINVAL): Invalid parameters
|
|
345
|
+
*
|
|
346
|
+
* @example
|
|
347
|
+
* ```typescript
|
|
348
|
+
* import { Frame, FilterContext, FFmpegError } from 'node-av';
|
|
349
|
+
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av/constants';
|
|
350
|
+
*
|
|
351
|
+
* // Get filtered frames
|
|
352
|
+
* const frame = new Frame();
|
|
353
|
+
* frame.alloc();
|
|
354
|
+
*
|
|
355
|
+
* let ret = sinkCtx.buffersinkGetFrame(frame);
|
|
356
|
+
* while (ret >= 0) {
|
|
357
|
+
* // Process the filtered frame
|
|
358
|
+
* processFrame(frame);
|
|
359
|
+
* frame.unref();
|
|
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)) {
|
|
366
|
+
* FFmpegError.throwIfError(ret, 'buffersinkGetFrame');
|
|
367
|
+
* }
|
|
368
|
+
* ```
|
|
369
|
+
*/
|
|
370
|
+
async buffersinkGetFrame(frame) {
|
|
371
|
+
return this.native.buffersinkGetFrame(frame.getNative());
|
|
372
|
+
}
|
|
373
|
+
/**
|
|
374
|
+
* Set the frame size for a buffersink filter.
|
|
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.
|
|
394
|
+
*
|
|
395
|
+
* Direct mapping to av_buffersink_get_time_base()
|
|
396
|
+
*
|
|
397
|
+
* Returns the time base of the buffersink filter.
|
|
398
|
+
*
|
|
399
|
+
* @returns The time base as a Rational
|
|
400
|
+
*
|
|
401
|
+
* @example
|
|
402
|
+
* ```typescript
|
|
403
|
+
* const timeBase = buffersinkCtx.buffersinkGetTimeBase();
|
|
404
|
+
* console.log(`Time base: ${timeBase.num}/${timeBase.den}`);
|
|
405
|
+
* ```
|
|
406
|
+
*/
|
|
407
|
+
buffersinkGetTimeBase() {
|
|
408
|
+
const tb = this.native.buffersinkGetTimeBase();
|
|
409
|
+
return new Rational(tb.num, tb.den);
|
|
410
|
+
}
|
|
411
|
+
/**
|
|
412
|
+
* Free the filter context.
|
|
413
|
+
*
|
|
414
|
+
* Direct mapping to avfilter_free()
|
|
415
|
+
*
|
|
416
|
+
* @example
|
|
417
|
+
* ```typescript
|
|
418
|
+
* filterCtx.free();
|
|
419
|
+
* // filterCtx is now invalid and should not be used
|
|
420
|
+
* ```
|
|
421
|
+
*/
|
|
422
|
+
free() {
|
|
423
|
+
this.native.free();
|
|
424
|
+
}
|
|
425
|
+
/**
|
|
426
|
+
* Check if this is a source filter context.
|
|
427
|
+
*
|
|
428
|
+
* Source filters have no inputs and generate data.
|
|
429
|
+
*
|
|
430
|
+
* @returns true if the filter has no input pads, false otherwise
|
|
431
|
+
*
|
|
432
|
+
* @example
|
|
433
|
+
* ```typescript
|
|
434
|
+
* if (filterCtx.isSource()) {
|
|
435
|
+
* console.log('This is a source filter');
|
|
436
|
+
* }
|
|
437
|
+
* ```
|
|
438
|
+
*/
|
|
439
|
+
isSource() {
|
|
440
|
+
return this.nbInputs === 0;
|
|
441
|
+
}
|
|
442
|
+
/**
|
|
443
|
+
* Check if this is a sink filter context.
|
|
444
|
+
*
|
|
445
|
+
* Sink filters have no outputs and consume data.
|
|
446
|
+
*
|
|
447
|
+
* @returns true if the filter has no output pads, false otherwise
|
|
448
|
+
*
|
|
449
|
+
* @example
|
|
450
|
+
* ```typescript
|
|
451
|
+
* if (filterCtx.isSink()) {
|
|
452
|
+
* console.log('This is a sink filter');
|
|
453
|
+
* }
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
isSink() {
|
|
457
|
+
return this.nbOutputs === 0;
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Check if the filter is ready for processing.
|
|
461
|
+
*
|
|
462
|
+
* Filters must be initialized before they can process data.
|
|
463
|
+
*
|
|
464
|
+
* @returns true if the filter has been properly initialized, false otherwise
|
|
465
|
+
*
|
|
466
|
+
* @example
|
|
467
|
+
* ```typescript
|
|
468
|
+
* filterCtx.initStr('1280:720');
|
|
469
|
+
* if (filterCtx.isReady()) {
|
|
470
|
+
* console.log('Filter is ready for processing');
|
|
471
|
+
* }
|
|
472
|
+
* ```
|
|
473
|
+
*/
|
|
474
|
+
isReady() {
|
|
475
|
+
return this.ready !== 0;
|
|
476
|
+
}
|
|
477
|
+
/**
|
|
478
|
+
* Get the native FFmpeg AVFilterContext pointer.
|
|
479
|
+
*
|
|
480
|
+
* @internal For use by other wrapper classes
|
|
481
|
+
* @returns The underlying native filter context object
|
|
482
|
+
*/
|
|
483
|
+
getNative() {
|
|
484
|
+
return this.native;
|
|
485
|
+
}
|
|
486
|
+
/**
|
|
487
|
+
* Dispose of the filter context.
|
|
488
|
+
*
|
|
489
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
490
|
+
* Equivalent to calling free().
|
|
491
|
+
*
|
|
492
|
+
* @example
|
|
493
|
+
* ```typescript
|
|
494
|
+
* {
|
|
495
|
+
* using filterCtx = filterGraph.createFilter(filter, 'my_filter');
|
|
496
|
+
* filterCtx.initStr('args');
|
|
497
|
+
* // ... use filter context
|
|
498
|
+
* } // Automatically freed when leaving scope
|
|
499
|
+
* ```
|
|
500
|
+
*/
|
|
501
|
+
[Symbol.dispose]() {
|
|
502
|
+
this.native[Symbol.dispose]();
|
|
503
|
+
}
|
|
504
|
+
}
|
|
505
|
+
//# sourceMappingURL=filter-context.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"filter-context.js","sourceRoot":"","sources":["../../src/lib/filter-context.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,aAAa,CAAC;AACrC,OAAO,EAAE,qBAAqB,EAAE,MAAM,8BAA8B,CAAC;AACrE,OAAO,EAAE,YAAY,EAAE,MAAM,aAAa,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAOzC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAmCG;AACH,MAAM,OAAO,aAAc,SAAQ,YAAiC;IAC1D,YAAY,CAAyB,CAAC,4CAA4C;IAE1F;;;;;;;;;OASG;IACH,YAAY,MAA2B;QACrC,KAAK,CAAC,MAAM,CAAC,CAAC;IAChB,CAAC;IAED;;;;;;OAMG;IACH,IAAI,IAAI;QACN,OAAO,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC;IAC1B,CAAC;IAED,IAAI,IAAI,CAAC,KAAoB;QAC3B,IAAI,CAAC,MAAM,CAAC,IAAI,GAAG,KAAK,CAAC;IAC3B,CAAC;IAED;;;;;;;;OAQG;IACH,IAAI,MAAM;QACR,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC;QAClC,OAAO,MAAM,CAAC,CAAC,CAAC,IAAI,MAAM,CAAC,MAA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