node-av 1.0.3 → 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 +56 -41
- package/dist/api/bitstream-filter.d.ts +180 -123
- package/dist/api/bitstream-filter.js +182 -126
- package/dist/api/bitstream-filter.js.map +1 -1
- package/dist/api/decoder.d.ts +286 -130
- package/dist/api/decoder.js +321 -159
- package/dist/api/decoder.js.map +1 -1
- package/dist/api/encoder.d.ts +254 -158
- package/dist/api/encoder.js +326 -298
- package/dist/api/encoder.js.map +1 -1
- package/dist/api/filter-presets.d.ts +912 -0
- package/dist/api/filter-presets.js +1407 -0
- package/dist/api/filter-presets.js.map +1 -0
- package/dist/api/filter.d.ts +280 -284
- package/dist/api/filter.js +435 -509
- package/dist/api/filter.js.map +1 -1
- package/dist/api/hardware.d.ts +226 -159
- package/dist/api/hardware.js +405 -287
- package/dist/api/hardware.js.map +1 -1
- package/dist/api/index.d.ts +3 -2
- package/dist/api/index.js +1 -0
- package/dist/api/index.js.map +1 -1
- package/dist/api/io-stream.d.ts +65 -61
- package/dist/api/io-stream.js +45 -47
- package/dist/api/io-stream.js.map +1 -1
- package/dist/api/media-input.d.ts +244 -141
- package/dist/api/media-input.js +207 -104
- package/dist/api/media-input.js.map +1 -1
- package/dist/api/media-output.d.ts +206 -128
- package/dist/api/media-output.js +212 -129
- 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 +22 -182
- package/dist/api/utilities/audio-sample.d.ts +1 -1
- package/dist/api/utilities/image.d.ts +1 -1
- package/dist/api/utilities/media-type.d.ts +1 -1
- package/dist/api/utilities/pixel-format.d.ts +1 -1
- package/dist/api/utilities/sample-format.d.ts +1 -1
- package/dist/api/utilities/timestamp.d.ts +1 -1
- 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 → constants}/channel-layouts.d.ts +1 -1
- package/dist/constants/channel-layouts.js.map +1 -0
- package/dist/{lib → constants}/constants.d.ts +19 -4
- package/dist/{lib → constants}/constants.js +15 -1
- package/dist/constants/constants.js.map +1 -0
- package/dist/constants/decoders.d.ts +609 -0
- package/dist/constants/decoders.js +617 -0
- package/dist/constants/decoders.js.map +1 -0
- package/dist/constants/encoders.d.ts +285 -0
- package/dist/constants/encoders.js +298 -0
- package/dist/constants/encoders.js.map +1 -0
- package/dist/constants/index.d.ts +4 -0
- package/dist/constants/index.js +5 -0
- package/dist/constants/index.js.map +1 -0
- package/dist/index.d.ts +1 -0
- package/dist/index.js +2 -0
- package/dist/index.js.map +1 -1
- package/dist/lib/audio-fifo.d.ts +128 -171
- package/dist/lib/audio-fifo.js +130 -173
- package/dist/lib/audio-fifo.js.map +1 -1
- package/dist/lib/binding.d.ts +7 -5
- 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 +69 -55
- package/dist/lib/bitstream-filter.js +68 -54
- package/dist/lib/bitstream-filter.js.map +1 -1
- package/dist/lib/codec-context.d.ts +317 -381
- package/dist/lib/codec-context.js +316 -381
- package/dist/lib/codec-context.js.map +1 -1
- package/dist/lib/codec-parameters.d.ts +161 -171
- package/dist/lib/codec-parameters.js +162 -172
- package/dist/lib/codec-parameters.js.map +1 -1
- package/dist/lib/codec-parser.d.ts +92 -105
- package/dist/lib/codec-parser.js +92 -103
- package/dist/lib/codec-parser.js.map +1 -1
- package/dist/lib/codec.d.ts +328 -217
- package/dist/lib/codec.js +392 -218
- package/dist/lib/codec.js.map +1 -1
- package/dist/lib/dictionary.d.ts +150 -204
- package/dist/lib/dictionary.js +159 -213
- package/dist/lib/dictionary.js.map +1 -1
- package/dist/lib/error.d.ts +97 -131
- package/dist/lib/error.js +98 -128
- package/dist/lib/error.js.map +1 -1
- package/dist/lib/filter-context.d.ts +317 -194
- package/dist/lib/filter-context.js +335 -200
- package/dist/lib/filter-context.js.map +1 -1
- package/dist/lib/filter-graph.d.ts +252 -293
- 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 +94 -112
- package/dist/lib/filter.js.map +1 -1
- package/dist/lib/format-context.d.ts +321 -429
- package/dist/lib/format-context.js +314 -386
- package/dist/lib/format-context.js.map +1 -1
- package/dist/lib/frame.d.ts +263 -406
- package/dist/lib/frame.js +263 -408
- package/dist/lib/frame.js.map +1 -1
- package/dist/lib/hardware-device-context.d.ts +150 -204
- 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 +171 -181
- 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 -3
- package/dist/lib/index.js +2 -5
- package/dist/lib/index.js.map +1 -1
- package/dist/lib/input-format.d.ts +90 -118
- package/dist/lib/input-format.js +89 -117
- package/dist/lib/input-format.js.map +1 -1
- package/dist/lib/io-context.d.ts +210 -242
- package/dist/lib/io-context.js +221 -253
- package/dist/lib/io-context.js.map +1 -1
- package/dist/lib/log.d.ts +86 -120
- package/dist/lib/log.js +85 -122
- package/dist/lib/log.js.map +1 -1
- package/dist/lib/native-types.d.ts +127 -112
- package/dist/lib/native-types.js +9 -0
- package/dist/lib/native-types.js.map +1 -1
- package/dist/lib/option.d.ts +285 -242
- package/dist/lib/option.js +310 -250
- package/dist/lib/option.js.map +1 -1
- package/dist/lib/output-format.d.ts +78 -102
- package/dist/lib/output-format.js +77 -101
- package/dist/lib/output-format.js.map +1 -1
- package/dist/lib/packet.d.ts +173 -241
- 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 +242 -326
- 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 +130 -174
- package/dist/lib/software-scale-context.js +132 -176
- package/dist/lib/software-scale-context.js.map +1 -1
- package/dist/lib/stream.d.ts +88 -198
- package/dist/lib/stream.js +87 -197
- package/dist/lib/stream.js.map +1 -1
- package/dist/lib/types.d.ts +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 +32 -24
- package/release_notes.md +43 -13
- package/CHANGELOG.md +0 -8
- package/dist/lib/channel-layouts.js.map +0 -1
- package/dist/lib/constants.js.map +0 -1
- /package/dist/{lib → constants}/channel-layouts.js +0 -0
|
@@ -5,339 +5,294 @@ import { Rational } from './rational.js';
|
|
|
5
5
|
import type { NativeBitStreamFilterContext, NativeWrapper } from './native-types.js';
|
|
6
6
|
import type { Packet } from './packet.js';
|
|
7
7
|
/**
|
|
8
|
-
* Bitstream filter context for processing
|
|
8
|
+
* Bitstream filter context for processing compressed video/audio streams.
|
|
9
9
|
*
|
|
10
|
-
*
|
|
11
|
-
*
|
|
12
|
-
*
|
|
10
|
+
* Applies bitstream filters to modify or analyze compressed packets without
|
|
11
|
+
* full decoding/encoding. Common uses include format conversion (e.g., H.264 MP4 to Annex B),
|
|
12
|
+
* metadata extraction, parameter set manipulation, and packet splitting/merging.
|
|
13
|
+
* Essential for stream compatibility between different containers and decoders.
|
|
13
14
|
*
|
|
14
15
|
* Direct mapping to FFmpeg's AVBSFContext.
|
|
15
16
|
*
|
|
16
17
|
* @example
|
|
17
18
|
* ```typescript
|
|
18
|
-
* import {
|
|
19
|
-
* import { AVERROR_EOF, AVERROR } from 'node-av/constants';
|
|
19
|
+
* import { BitStreamFilterContext, BitStreamFilter, Packet, FFmpegError } from 'node-av';
|
|
20
20
|
*
|
|
21
|
-
* // Create and initialize
|
|
22
|
-
* const filter = BitStreamFilter.getByName('h264_mp4toannexb');
|
|
21
|
+
* // Create and initialize H.264 stream format converter
|
|
23
22
|
* const ctx = new BitStreamFilterContext();
|
|
23
|
+
* const filter = BitStreamFilter.getByName('h264_mp4toannexb');
|
|
24
|
+
* if (!filter) {
|
|
25
|
+
* throw new Error('H.264 filter not available');
|
|
26
|
+
* }
|
|
24
27
|
*
|
|
25
|
-
* // Allocate and configure
|
|
26
28
|
* let ret = ctx.alloc(filter);
|
|
27
29
|
* FFmpegError.throwIfError(ret, 'alloc');
|
|
28
30
|
*
|
|
29
|
-
* // Copy input parameters from stream to BSF context
|
|
30
|
-
* stream.codecpar.copy(ctx.inputCodecParameters);
|
|
31
|
-
* ctx.inputTimeBase = stream.timeBase;
|
|
32
|
-
*
|
|
33
|
-
* // Initialize filter
|
|
34
31
|
* ret = ctx.init();
|
|
35
32
|
* FFmpegError.throwIfError(ret, 'init');
|
|
36
33
|
*
|
|
37
34
|
* // Process packets
|
|
38
|
-
*
|
|
39
|
-
*
|
|
40
|
-
*
|
|
41
|
-
* // Send packet to filter
|
|
42
|
-
* ret = await ctx.sendPacket(inputPacket);
|
|
43
|
-
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
44
|
-
*
|
|
45
|
-
* // Receive filtered packets
|
|
46
|
-
* while (true) {
|
|
47
|
-
* const outputPacket = new Packet();
|
|
48
|
-
* const result = await ctx.receivePacket(outputPacket);
|
|
49
|
-
*
|
|
50
|
-
* if (result.eagain || result.eof) break;
|
|
51
|
-
* FFmpegError.throwIfError(result.ret || result, 'receivePacket');
|
|
52
|
-
*
|
|
53
|
-
* // Process filtered packet
|
|
54
|
-
* processPacket(outputPacket);
|
|
55
|
-
* outputPacket.unref();
|
|
56
|
-
* }
|
|
57
|
-
* }
|
|
35
|
+
* const inputPacket = new Packet();
|
|
36
|
+
* const outputPacket = new Packet();
|
|
58
37
|
*
|
|
59
|
-
*
|
|
60
|
-
*
|
|
38
|
+
* ret = await ctx.sendPacket(inputPacket);
|
|
39
|
+
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
61
40
|
*
|
|
62
|
-
*
|
|
63
|
-
*
|
|
64
|
-
*
|
|
65
|
-
* const result = await ctx.receivePacket(outputPacket);
|
|
66
|
-
* if (result.eof) break;
|
|
67
|
-
* // Process remaining packets
|
|
41
|
+
* ret = await ctx.receivePacket(outputPacket);
|
|
42
|
+
* if (ret >= 0) {
|
|
43
|
+
* // Process filtered packet
|
|
68
44
|
* }
|
|
69
45
|
*
|
|
70
46
|
* // Cleanup
|
|
71
47
|
* ctx.free();
|
|
72
48
|
* ```
|
|
49
|
+
*
|
|
50
|
+
* @see {@link BitStreamFilter} For available filter types
|
|
51
|
+
* @see {@link Packet} For packet manipulation
|
|
73
52
|
*/
|
|
74
53
|
export declare class BitStreamFilterContext extends OptionMember<NativeBitStreamFilterContext> implements Disposable, NativeWrapper<NativeBitStreamFilterContext> {
|
|
75
54
|
private _filter?;
|
|
76
|
-
/**
|
|
77
|
-
* Create a new bitstream filter context.
|
|
78
|
-
*
|
|
79
|
-
* The context is uninitialized - you must call alloc() and init() before use.
|
|
80
|
-
* No FFmpeg resources are allocated until initialization.
|
|
81
|
-
*
|
|
82
|
-
* Direct wrapper around AVBSFContext.
|
|
83
|
-
*
|
|
84
|
-
* @example
|
|
85
|
-
* ```typescript
|
|
86
|
-
* const ctx = new BitStreamFilterContext();
|
|
87
|
-
* ctx.alloc(filter);
|
|
88
|
-
* ctx.init();
|
|
89
|
-
* // Context is now ready for filtering
|
|
90
|
-
* ```
|
|
91
|
-
*/
|
|
92
55
|
constructor();
|
|
93
56
|
/**
|
|
94
|
-
* Check if the context
|
|
57
|
+
* Check if the context has been initialized.
|
|
95
58
|
*
|
|
96
|
-
* Returns true if init() has been called
|
|
97
|
-
*
|
|
98
|
-
* @returns True if initialized, false otherwise
|
|
59
|
+
* Returns true if init() has been successfully called.
|
|
60
|
+
* The context must be initialized before sending/receiving packets.
|
|
99
61
|
*/
|
|
100
62
|
get isInitialized(): boolean;
|
|
101
63
|
/**
|
|
102
|
-
* Input codec parameters
|
|
103
|
-
*
|
|
104
|
-
* Returns a reference to the BSF context's internal codec parameters.
|
|
105
|
-
* While you cannot replace this object (no setter), you can modify its contents
|
|
106
|
-
* or use it as a destination for copy operations.
|
|
64
|
+
* Input codec parameters.
|
|
107
65
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* Maps to AVBSFContext->par_in.
|
|
111
|
-
*
|
|
112
|
-
* @example
|
|
113
|
-
* ```typescript
|
|
114
|
-
* // Copy parameters from input stream to BSF context
|
|
115
|
-
* if (ctx.inputCodecParameters) {
|
|
116
|
-
* stream.codecpar.copy(ctx.inputCodecParameters);
|
|
66
|
+
* Parameters describing the input stream format.
|
|
67
|
+
* These are automatically configured from the input packets in most cases.
|
|
117
68
|
*
|
|
118
|
-
*
|
|
119
|
-
* ctx.inputCodecParameters.codecType = AVMEDIA_TYPE_VIDEO;
|
|
120
|
-
* ctx.inputCodecParameters.codecId = AV_CODEC_ID_H264;
|
|
121
|
-
* }
|
|
122
|
-
* ```
|
|
69
|
+
* Direct mapping to AVBSFContext->par_in.
|
|
123
70
|
*/
|
|
124
71
|
get inputCodecParameters(): CodecParameters | null;
|
|
125
72
|
/**
|
|
126
|
-
* Output codec parameters
|
|
127
|
-
*
|
|
128
|
-
* Returns a reference to the BSF context's output codec parameters.
|
|
129
|
-
* These are automatically configured by the filter during init().
|
|
130
|
-
* You should not modify these parameters.
|
|
131
|
-
*
|
|
132
|
-
* Maps to AVBSFContext->par_out.
|
|
73
|
+
* Output codec parameters.
|
|
133
74
|
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
* // After initialization, read the output parameters
|
|
137
|
-
* console.log(`Output codec: ${ctx.outputCodecParameters?.codecId}`);
|
|
75
|
+
* Parameters describing the output stream format after filtering.
|
|
76
|
+
* These reflect any changes made by the bitstream filter.
|
|
138
77
|
*
|
|
139
|
-
*
|
|
140
|
-
* if (ctx.outputCodecParameters) {
|
|
141
|
-
* ctx.outputCodecParameters.copy(nextStream.codecpar);
|
|
142
|
-
* }
|
|
143
|
-
* ```
|
|
78
|
+
* Direct mapping to AVBSFContext->par_out.
|
|
144
79
|
*/
|
|
145
80
|
get outputCodecParameters(): CodecParameters | null;
|
|
146
81
|
/**
|
|
147
82
|
* Input time base.
|
|
148
83
|
*
|
|
149
|
-
* Time base
|
|
150
|
-
* Must be set before
|
|
84
|
+
* Time base of the input packets (timestamps per second).
|
|
85
|
+
* Must be set before init() for proper timestamp handling.
|
|
151
86
|
*
|
|
152
|
-
*
|
|
153
|
-
*
|
|
154
|
-
* @example
|
|
155
|
-
* ```typescript
|
|
156
|
-
* ctx.inputTimeBase = new Rational(1, 1000); // 1ms time base
|
|
157
|
-
* ```
|
|
87
|
+
* Direct mapping to AVBSFContext->time_base_in.
|
|
158
88
|
*/
|
|
159
89
|
get inputTimeBase(): Rational;
|
|
160
90
|
set inputTimeBase(value: Rational);
|
|
161
91
|
/**
|
|
162
92
|
* Output time base.
|
|
163
93
|
*
|
|
164
|
-
* Time base
|
|
165
|
-
*
|
|
94
|
+
* Time base of the output packets after filtering.
|
|
95
|
+
* May differ from input if the filter modifies timing.
|
|
166
96
|
*
|
|
167
|
-
*
|
|
168
|
-
*
|
|
169
|
-
* @example
|
|
170
|
-
* ```typescript
|
|
171
|
-
* // After initialization
|
|
172
|
-
* console.log(`Output time base: ${ctx.outputTimeBase.num}/${ctx.outputTimeBase.den}`);
|
|
173
|
-
* ```
|
|
97
|
+
* Direct mapping to AVBSFContext->time_base_out.
|
|
174
98
|
*/
|
|
175
99
|
get outputTimeBase(): Rational | null;
|
|
176
100
|
/**
|
|
177
101
|
* The bitstream filter being used.
|
|
178
102
|
*
|
|
179
|
-
* Reference to the filter
|
|
103
|
+
* Reference to the filter descriptor allocated to this context.
|
|
180
104
|
*
|
|
181
|
-
*
|
|
182
|
-
*
|
|
183
|
-
* @example
|
|
184
|
-
* ```typescript
|
|
185
|
-
* console.log(`Using filter: ${ctx.filter?.name}`);
|
|
186
|
-
* ```
|
|
105
|
+
* Direct mapping to AVBSFContext->filter.
|
|
187
106
|
*/
|
|
188
107
|
get filter(): BitStreamFilter | null;
|
|
189
108
|
/**
|
|
190
|
-
* Allocate
|
|
109
|
+
* Allocate a bitstream filter context.
|
|
191
110
|
*
|
|
192
|
-
* Allocates the context for the specified filter.
|
|
193
|
-
* Must be called before
|
|
194
|
-
* After allocation, configure input parameters before calling init().
|
|
111
|
+
* Allocates and configures the context for the specified filter.
|
|
112
|
+
* Must be called before init().
|
|
195
113
|
*
|
|
196
|
-
*
|
|
114
|
+
* Direct mapping to av_bsf_alloc().
|
|
197
115
|
*
|
|
198
116
|
* @param filter - The bitstream filter to use
|
|
199
|
-
* @returns 0 on success, negative
|
|
117
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
118
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
119
|
+
* - AVERROR_EINVAL: Invalid filter
|
|
200
120
|
*
|
|
201
121
|
* @example
|
|
202
122
|
* ```typescript
|
|
123
|
+
* import { FFmpegError } from 'node-av';
|
|
124
|
+
*
|
|
203
125
|
* const filter = BitStreamFilter.getByName('h264_mp4toannexb');
|
|
204
|
-
*
|
|
126
|
+
* if (!filter) {
|
|
127
|
+
* throw new Error('Filter not found');
|
|
128
|
+
* }
|
|
129
|
+
*
|
|
205
130
|
* const ret = ctx.alloc(filter);
|
|
206
131
|
* FFmpegError.throwIfError(ret, 'alloc');
|
|
207
132
|
* ```
|
|
133
|
+
*
|
|
134
|
+
* @see {@link init} To initialize after allocation
|
|
135
|
+
* @see {@link BitStreamFilter.getByName} To get filter by name
|
|
208
136
|
*/
|
|
209
137
|
alloc(filter: BitStreamFilter): number;
|
|
210
138
|
/**
|
|
211
139
|
* Initialize the bitstream filter context.
|
|
212
140
|
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
215
|
-
* Must be called after alloc() and parameter configuration.
|
|
141
|
+
* Initializes the filter with the configured parameters.
|
|
142
|
+
* Must be called after alloc() and before processing packets.
|
|
216
143
|
*
|
|
217
|
-
*
|
|
144
|
+
* Direct mapping to av_bsf_init().
|
|
218
145
|
*
|
|
219
|
-
* @returns 0 on success, negative
|
|
146
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
147
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
148
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
220
149
|
*
|
|
221
150
|
* @example
|
|
222
151
|
* ```typescript
|
|
223
|
-
*
|
|
224
|
-
*
|
|
225
|
-
*
|
|
152
|
+
* import { FFmpegError } from 'node-av';
|
|
153
|
+
*
|
|
154
|
+
* // Allocate and initialize
|
|
155
|
+
* const ret1 = ctx.alloc(filter);
|
|
156
|
+
* FFmpegError.throwIfError(ret1, 'alloc');
|
|
157
|
+
*
|
|
158
|
+
* // Set parameters if needed
|
|
159
|
+
* ctx.inputTimeBase = new Rational(1, 25);
|
|
160
|
+
*
|
|
161
|
+
* const ret2 = ctx.init();
|
|
162
|
+
* FFmpegError.throwIfError(ret2, 'init');
|
|
226
163
|
* ```
|
|
164
|
+
*
|
|
165
|
+
* @see {@link alloc} Must be called first
|
|
166
|
+
* @see {@link isInitialized} To check initialization status
|
|
227
167
|
*/
|
|
228
168
|
init(): number;
|
|
229
169
|
/**
|
|
230
170
|
* Free the bitstream filter context.
|
|
231
171
|
*
|
|
232
172
|
* Releases all resources associated with the context.
|
|
233
|
-
* The context
|
|
173
|
+
* The context becomes invalid after calling this.
|
|
234
174
|
*
|
|
235
|
-
*
|
|
175
|
+
* Direct mapping to av_bsf_free().
|
|
236
176
|
*
|
|
237
177
|
* @example
|
|
238
178
|
* ```typescript
|
|
239
179
|
* ctx.free();
|
|
240
|
-
* // Context is now
|
|
180
|
+
* // Context is now invalid
|
|
241
181
|
* ```
|
|
182
|
+
*
|
|
183
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
184
|
+
* @see {@link alloc} To allocate
|
|
242
185
|
*/
|
|
243
186
|
free(): void;
|
|
244
187
|
/**
|
|
245
188
|
* Flush the bitstream filter.
|
|
246
189
|
*
|
|
247
|
-
* Resets the internal
|
|
248
|
-
*
|
|
190
|
+
* Resets the internal state and discards any buffered data.
|
|
191
|
+
* Useful when seeking or switching streams.
|
|
249
192
|
*
|
|
250
|
-
*
|
|
193
|
+
* Direct mapping to av_bsf_flush().
|
|
251
194
|
*
|
|
252
195
|
* @example
|
|
253
196
|
* ```typescript
|
|
254
|
-
* //
|
|
197
|
+
* // Flush when seeking
|
|
255
198
|
* ctx.flush();
|
|
256
|
-
* //
|
|
199
|
+
* // Now ready to process packets from new position
|
|
257
200
|
* ```
|
|
258
201
|
*/
|
|
259
202
|
flush(): void;
|
|
260
203
|
/**
|
|
261
|
-
* Send a packet to the filter.
|
|
262
|
-
*
|
|
263
|
-
* Submits a packet for filtering.
|
|
264
|
-
* The filter takes ownership of the packet.
|
|
265
|
-
* Pass null to signal end of stream.
|
|
204
|
+
* Send a packet to the bitstream filter.
|
|
266
205
|
*
|
|
267
|
-
*
|
|
268
|
-
*
|
|
206
|
+
* Submits a packet for filtering. The filter may buffer the packet
|
|
207
|
+
* internally and require multiple calls to receivePacket() to retrieve
|
|
208
|
+
* all output. Send null to signal end of stream.
|
|
269
209
|
*
|
|
270
|
-
*
|
|
210
|
+
* Direct mapping to av_bsf_send_packet().
|
|
271
211
|
*
|
|
272
|
-
* @param packet - Packet to filter, or null
|
|
273
|
-
* @returns
|
|
212
|
+
* @param packet - Packet to filter, or null to signal EOF
|
|
213
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
214
|
+
* - AVERROR_EAGAIN: Filter needs output to be consumed first
|
|
215
|
+
* - AVERROR_EOF: Filter has been flushed
|
|
216
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
217
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
274
218
|
*
|
|
275
219
|
* @example
|
|
276
220
|
* ```typescript
|
|
277
|
-
*
|
|
221
|
+
* import { FFmpegError } from 'node-av';
|
|
222
|
+
* import { AVERROR_EAGAIN } from 'node-av';
|
|
223
|
+
*
|
|
278
224
|
* const ret = await ctx.sendPacket(inputPacket);
|
|
279
|
-
* if (ret
|
|
280
|
-
*
|
|
225
|
+
* if (ret === AVERROR_EAGAIN) {
|
|
226
|
+
* // Need to receive packets first
|
|
227
|
+
* const ret2 = await ctx.receivePacket(outputPacket);
|
|
228
|
+
* FFmpegError.throwIfError(ret2, 'receivePacket');
|
|
229
|
+
* } else {
|
|
230
|
+
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
281
231
|
* }
|
|
282
232
|
*
|
|
283
233
|
* // Send EOF
|
|
284
234
|
* await ctx.sendPacket(null);
|
|
285
235
|
* ```
|
|
236
|
+
*
|
|
237
|
+
* @see {@link receivePacket} To retrieve filtered packets
|
|
286
238
|
*/
|
|
287
239
|
sendPacket(packet: Packet | null): Promise<number>;
|
|
288
240
|
/**
|
|
289
|
-
* Receive a filtered packet.
|
|
241
|
+
* Receive a filtered packet from the bitstream filter.
|
|
290
242
|
*
|
|
291
|
-
*
|
|
292
|
-
*
|
|
293
|
-
* One input packet may produce multiple output packets.
|
|
243
|
+
* Retrieves a packet that has been processed by the filter.
|
|
244
|
+
* May need to be called multiple times after each sendPacket().
|
|
294
245
|
*
|
|
295
|
-
*
|
|
246
|
+
* Direct mapping to av_bsf_receive_packet().
|
|
296
247
|
*
|
|
297
248
|
* @param packet - Packet to receive filtered data into
|
|
298
|
-
* @returns
|
|
249
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
250
|
+
* - AVERROR_EAGAIN: Need more input
|
|
251
|
+
* - AVERROR_EOF: No more packets available
|
|
252
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
299
253
|
*
|
|
300
254
|
* @example
|
|
301
255
|
* ```typescript
|
|
302
|
-
* import {
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
307
|
-
*
|
|
308
|
-
*
|
|
309
|
-
*
|
|
310
|
-
*
|
|
311
|
-
*
|
|
312
|
-
*
|
|
313
|
-
*
|
|
314
|
-
*
|
|
315
|
-
* processPacket(packet);
|
|
256
|
+
* import { FFmpegError } from 'node-av';
|
|
257
|
+
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
|
|
258
|
+
*
|
|
259
|
+
* // Receive all available packets
|
|
260
|
+
* while (true) {
|
|
261
|
+
* const ret = await ctx.receivePacket(outputPacket);
|
|
262
|
+
* if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
|
|
263
|
+
* break;
|
|
264
|
+
* }
|
|
265
|
+
* FFmpegError.throwIfError(ret, 'receivePacket');
|
|
266
|
+
*
|
|
267
|
+
* // Process filtered packet
|
|
268
|
+
* console.log(`Filtered packet size: ${outputPacket.size}`);
|
|
316
269
|
* }
|
|
317
270
|
* ```
|
|
271
|
+
*
|
|
272
|
+
* @see {@link sendPacket} To submit packets for filtering
|
|
318
273
|
*/
|
|
319
274
|
receivePacket(packet: Packet): Promise<number>;
|
|
320
275
|
/**
|
|
321
|
-
* Get the underlying native object.
|
|
276
|
+
* Get the underlying native BitStreamFilterContext object.
|
|
322
277
|
*
|
|
323
|
-
*
|
|
278
|
+
* @returns The native BitStreamFilterContext binding object
|
|
324
279
|
*
|
|
325
|
-
* @returns Native BitStreamFilterContext object
|
|
326
280
|
* @internal
|
|
327
281
|
*/
|
|
328
282
|
getNative(): NativeBitStreamFilterContext;
|
|
329
283
|
/**
|
|
330
|
-
* Dispose of the context
|
|
284
|
+
* Dispose of the bitstream filter context.
|
|
331
285
|
*
|
|
332
|
-
*
|
|
333
|
-
*
|
|
286
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
287
|
+
* Equivalent to calling free().
|
|
334
288
|
*
|
|
335
289
|
* @example
|
|
336
290
|
* ```typescript
|
|
337
291
|
* {
|
|
338
292
|
* using ctx = new BitStreamFilterContext();
|
|
339
293
|
* ctx.alloc(filter);
|
|
340
|
-
*
|
|
294
|
+
* ctx.init();
|
|
295
|
+
* // Use context...
|
|
341
296
|
* } // Automatically freed when leaving scope
|
|
342
297
|
* ```
|
|
343
298
|
*/
|