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
|
@@ -11,11 +11,12 @@ import type { NativeCodecContext, NativeWrapper } from './native-types.js';
|
|
|
11
11
|
import type { Packet } from './packet.js';
|
|
12
12
|
import type { ChannelLayout } from './types.js';
|
|
13
13
|
/**
|
|
14
|
-
* Codec context for encoding and decoding
|
|
14
|
+
* Codec context for encoding and decoding.
|
|
15
15
|
*
|
|
16
|
-
*
|
|
17
|
-
*
|
|
18
|
-
* Supports both software and hardware
|
|
16
|
+
* Main structure for codec operations, containing all codec parameters and state.
|
|
17
|
+
* Handles encoding raw frames to packets and decoding packets to frames.
|
|
18
|
+
* Supports both software and hardware-accelerated codecs.
|
|
19
|
+
* Must be configured and opened before use.
|
|
19
20
|
*
|
|
20
21
|
* Direct mapping to FFmpeg's AVCodecContext.
|
|
21
22
|
*
|
|
@@ -24,414 +25,399 @@ import type { ChannelLayout } from './types.js';
|
|
|
24
25
|
* import { CodecContext, Codec, FFmpegError } from 'node-av';
|
|
25
26
|
* import { AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
26
27
|
*
|
|
27
|
-
* // Create
|
|
28
|
+
* // Create decoder
|
|
29
|
+
* const decoder = new CodecContext();
|
|
28
30
|
* const codec = Codec.findDecoder(AV_CODEC_ID_H264);
|
|
29
|
-
*
|
|
30
|
-
* ctx.allocContext3(codec);
|
|
31
|
+
* decoder.allocContext3(codec);
|
|
31
32
|
*
|
|
32
|
-
* // Configure parameters
|
|
33
|
-
*
|
|
34
|
-
* ctx.height = 1080;
|
|
35
|
-
* ctx.pixelFormat = AV_PIX_FMT_YUV420P;
|
|
33
|
+
* // Configure from stream parameters
|
|
34
|
+
* decoder.parametersToContext(stream.codecpar);
|
|
36
35
|
*
|
|
37
|
-
* // Open
|
|
38
|
-
*
|
|
36
|
+
* // Open decoder
|
|
37
|
+
* let ret = await decoder.open2(codec);
|
|
39
38
|
* FFmpegError.throwIfError(ret, 'open2');
|
|
40
39
|
*
|
|
41
40
|
* // Decode packets
|
|
42
|
-
*
|
|
43
|
-
*
|
|
44
|
-
*
|
|
45
|
-
*
|
|
46
|
-
*
|
|
47
|
-
*
|
|
48
|
-
* FFmpegError.throwIfError(ret, 'receiveFrame');
|
|
49
|
-
* // Process frame
|
|
41
|
+
* ret = await decoder.sendPacket(packet);
|
|
42
|
+
* if (ret >= 0) {
|
|
43
|
+
* ret = await decoder.receiveFrame(frame);
|
|
44
|
+
* if (ret >= 0) {
|
|
45
|
+
* // Process decoded frame
|
|
46
|
+
* }
|
|
50
47
|
* }
|
|
51
48
|
*
|
|
52
49
|
* // Cleanup
|
|
53
|
-
*
|
|
50
|
+
* decoder.freeContext();
|
|
54
51
|
* ```
|
|
52
|
+
*
|
|
53
|
+
* @see [AVCodecContext](https://ffmpeg.org/doxygen/trunk/structAVCodecContext.html) - FFmpeg Doxygen
|
|
54
|
+
* @see {@link Codec} For finding codecs
|
|
55
|
+
* @see {@link CodecParameters} For stream parameters
|
|
55
56
|
*/
|
|
56
57
|
export declare class CodecContext extends OptionMember<NativeCodecContext> implements Disposable, NativeWrapper<NativeCodecContext> {
|
|
57
58
|
private _hwDeviceCtx?;
|
|
58
59
|
private _hwFramesCtx?;
|
|
59
|
-
/**
|
|
60
|
-
* Create a new codec context.
|
|
61
|
-
*
|
|
62
|
-
* The context is uninitialized - you must call allocContext3() before use.
|
|
63
|
-
* No FFmpeg resources are allocated until initialization.
|
|
64
|
-
*
|
|
65
|
-
* Direct wrapper around AVCodecContext.
|
|
66
|
-
*
|
|
67
|
-
* @example
|
|
68
|
-
* ```typescript
|
|
69
|
-
* import { CodecContext, Codec } from 'node-av';
|
|
70
|
-
*
|
|
71
|
-
* const ctx = new CodecContext();
|
|
72
|
-
* ctx.allocContext3(codec);
|
|
73
|
-
* // Context is now ready for configuration
|
|
74
|
-
* ```
|
|
75
|
-
*/
|
|
76
60
|
constructor();
|
|
77
61
|
/**
|
|
78
|
-
*
|
|
79
|
-
*
|
|
80
|
-
* Identifies whether this is a video, audio, subtitle, or data codec.
|
|
62
|
+
* Type of codec (video/audio/subtitle).
|
|
81
63
|
*
|
|
82
|
-
* Direct mapping to AVCodecContext->codec_type
|
|
64
|
+
* Direct mapping to AVCodecContext->codec_type.
|
|
83
65
|
*/
|
|
84
66
|
get codecType(): AVMediaType;
|
|
85
67
|
set codecType(value: AVMediaType);
|
|
86
68
|
/**
|
|
87
|
-
* Codec
|
|
69
|
+
* Codec identifier.
|
|
88
70
|
*
|
|
89
|
-
*
|
|
90
|
-
*
|
|
91
|
-
* Direct mapping to AVCodecContext->codec_id
|
|
71
|
+
* Direct mapping to AVCodecContext->codec_id.
|
|
92
72
|
*/
|
|
93
73
|
get codecId(): AVCodecID;
|
|
94
74
|
set codecId(value: AVCodecID);
|
|
95
75
|
/**
|
|
96
|
-
*
|
|
76
|
+
* Average bitrate.
|
|
97
77
|
*
|
|
98
|
-
*
|
|
78
|
+
* Target bitrate for encoding, detected bitrate for decoding.
|
|
79
|
+
* In bits per second.
|
|
99
80
|
*
|
|
100
|
-
*
|
|
101
|
-
* - decoding: Set by user, may be overwritten by libavcodec if this info is available in the stream.
|
|
81
|
+
* Direct mapping to AVCodecContext->bit_rate.
|
|
102
82
|
*/
|
|
103
83
|
get bitRate(): bigint;
|
|
104
84
|
set bitRate(value: bigint);
|
|
105
85
|
/**
|
|
106
86
|
* Time base for timestamps.
|
|
107
87
|
*
|
|
108
|
-
*
|
|
109
|
-
*
|
|
110
|
-
* Direct mapping to AVCodecContext->time_base
|
|
88
|
+
* Fundamental unit of time in seconds for this context.
|
|
111
89
|
*
|
|
112
|
-
*
|
|
113
|
-
* - decoding: the use of this field for decoding is deprecated. Use framerate instead.
|
|
90
|
+
* Direct mapping to AVCodecContext->time_base.
|
|
114
91
|
*/
|
|
115
92
|
get timeBase(): Rational;
|
|
116
93
|
set timeBase(value: Rational);
|
|
117
94
|
/**
|
|
118
|
-
*
|
|
119
|
-
*
|
|
120
|
-
* of
|
|
95
|
+
* Packet time base.
|
|
96
|
+
*
|
|
97
|
+
* Time base of the packets from/to the demuxer/muxer.
|
|
98
|
+
*
|
|
99
|
+
* Direct mapping to AVCodecContext->pkt_timebase.
|
|
121
100
|
*/
|
|
122
101
|
get pktTimebase(): Rational;
|
|
123
102
|
set pktTimebase(value: Rational);
|
|
124
103
|
/**
|
|
125
104
|
* Codec delay.
|
|
126
|
-
*
|
|
127
|
-
*
|
|
128
|
-
*
|
|
129
|
-
*
|
|
130
|
-
* @readonly
|
|
105
|
+
*
|
|
106
|
+
* Number of frames the decoder needs to output before first frame.
|
|
107
|
+
*
|
|
108
|
+
* Direct mapping to AVCodecContext->delay.
|
|
131
109
|
*/
|
|
132
110
|
get delay(): number;
|
|
133
111
|
/**
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
112
|
+
* Codec flags.
|
|
113
|
+
*
|
|
114
|
+
* Combination of AV_CODEC_FLAG_* values.
|
|
115
|
+
*
|
|
116
|
+
* Direct mapping to AVCodecContext->flags.
|
|
137
117
|
*/
|
|
138
118
|
get flags(): AVCodecFlag;
|
|
139
119
|
set flags(value: AVCodecFlag);
|
|
140
120
|
/**
|
|
141
|
-
*
|
|
142
|
-
*
|
|
143
|
-
*
|
|
121
|
+
* Additional codec flags.
|
|
122
|
+
*
|
|
123
|
+
* Combination of AV_CODEC_FLAG2_* values.
|
|
124
|
+
*
|
|
125
|
+
* Direct mapping to AVCodecContext->flags2.
|
|
144
126
|
*/
|
|
145
127
|
get flags2(): AVCodecFlag2;
|
|
146
128
|
set flags2(value: AVCodecFlag2);
|
|
147
129
|
/**
|
|
148
|
-
*
|
|
149
|
-
*
|
|
150
|
-
*
|
|
151
|
-
*
|
|
152
|
-
*
|
|
153
|
-
* than extradata_size to avoid problems if it is read with the bitstream reader.
|
|
154
|
-
* The bytewise contents of extradata must not depend on the architecture or CPU endianness.
|
|
155
|
-
* Must be allocated with the av_malloc() family of functions.
|
|
156
|
-
* - encoding: Set/allocated/freed by libavcodec.
|
|
157
|
-
* - decoding: Set/allocated/freed by user.
|
|
130
|
+
* Extra binary data for codec.
|
|
131
|
+
*
|
|
132
|
+
* Contains codec-specific initialization data.
|
|
133
|
+
*
|
|
134
|
+
* Direct mapping to AVCodecContext->extradata.
|
|
158
135
|
*/
|
|
159
136
|
get extraData(): Buffer | null;
|
|
160
137
|
set extraData(value: Buffer | null);
|
|
161
138
|
/**
|
|
162
|
-
*
|
|
163
|
-
*
|
|
164
|
-
*
|
|
139
|
+
* Codec profile.
|
|
140
|
+
*
|
|
141
|
+
* FF_PROFILE_* value indicating codec profile.
|
|
142
|
+
*
|
|
143
|
+
* Direct mapping to AVCodecContext->profile.
|
|
165
144
|
*/
|
|
166
145
|
get profile(): AVProfile;
|
|
167
146
|
set profile(value: AVProfile);
|
|
168
147
|
/**
|
|
169
|
-
*
|
|
170
|
-
*
|
|
171
|
-
*
|
|
148
|
+
* Codec level.
|
|
149
|
+
*
|
|
150
|
+
* Level within the specified profile.
|
|
151
|
+
*
|
|
152
|
+
* Direct mapping to AVCodecContext->level.
|
|
172
153
|
*/
|
|
173
154
|
get level(): number;
|
|
174
155
|
set level(value: number);
|
|
175
156
|
/**
|
|
176
|
-
* Thread count.
|
|
177
|
-
*
|
|
178
|
-
*
|
|
179
|
-
*
|
|
157
|
+
* Thread count for codec.
|
|
158
|
+
*
|
|
159
|
+
* Number of threads to use for decoding/encoding.
|
|
160
|
+
* 0 for automatic selection.
|
|
161
|
+
*
|
|
162
|
+
* Direct mapping to AVCodecContext->thread_count.
|
|
180
163
|
*/
|
|
181
164
|
get threadCount(): number;
|
|
182
165
|
set threadCount(value: number);
|
|
183
166
|
/**
|
|
184
|
-
* Picture width.
|
|
185
|
-
*
|
|
186
|
-
*
|
|
187
|
-
* from the container. Some decoders will require the dimensions
|
|
188
|
-
* to be set by the caller. During decoding, the decoder may
|
|
189
|
-
* overwrite those values as required while parsing the data.
|
|
167
|
+
* Picture width in pixels.
|
|
168
|
+
*
|
|
169
|
+
* Direct mapping to AVCodecContext->width.
|
|
190
170
|
*/
|
|
191
171
|
get width(): number;
|
|
192
172
|
set width(value: number);
|
|
193
173
|
/**
|
|
194
|
-
* Picture height.
|
|
195
|
-
*
|
|
196
|
-
*
|
|
197
|
-
* from the container. Some decoders will require the dimensions
|
|
198
|
-
* to be set by the caller. During decoding, the decoder may
|
|
199
|
-
* overwrite those values as required while parsing the data.
|
|
174
|
+
* Picture height in pixels.
|
|
175
|
+
*
|
|
176
|
+
* Direct mapping to AVCodecContext->height.
|
|
200
177
|
*/
|
|
201
178
|
get height(): number;
|
|
202
179
|
set height(value: number);
|
|
203
180
|
/**
|
|
204
|
-
*
|
|
205
|
-
*
|
|
206
|
-
*
|
|
181
|
+
* Group of pictures size.
|
|
182
|
+
*
|
|
183
|
+
* Maximum number of frames between keyframes.
|
|
184
|
+
*
|
|
185
|
+
* Direct mapping to AVCodecContext->gop_size.
|
|
207
186
|
*/
|
|
208
187
|
get gopSize(): number;
|
|
209
188
|
set gopSize(value: number);
|
|
210
189
|
/**
|
|
211
190
|
* Pixel format.
|
|
212
|
-
*
|
|
213
|
-
*
|
|
214
|
-
*
|
|
191
|
+
*
|
|
192
|
+
* Format of the video frames.
|
|
193
|
+
*
|
|
194
|
+
* Direct mapping to AVCodecContext->pix_fmt.
|
|
215
195
|
*/
|
|
216
196
|
get pixelFormat(): AVPixelFormat;
|
|
217
197
|
set pixelFormat(value: AVPixelFormat);
|
|
218
198
|
/**
|
|
219
|
-
* Maximum number of B-frames
|
|
220
|
-
*
|
|
221
|
-
* -
|
|
222
|
-
*
|
|
199
|
+
* Maximum number of B-frames.
|
|
200
|
+
*
|
|
201
|
+
* B-frames between non-B-frames.
|
|
202
|
+
*
|
|
203
|
+
* Direct mapping to AVCodecContext->max_b_frames.
|
|
223
204
|
*/
|
|
224
205
|
get maxBFrames(): number;
|
|
225
206
|
set maxBFrames(value: number);
|
|
226
207
|
/**
|
|
227
208
|
* Macroblock decision mode.
|
|
228
209
|
*
|
|
229
|
-
*
|
|
210
|
+
* Algorithm for macroblock decision.
|
|
230
211
|
*
|
|
231
|
-
*
|
|
232
|
-
* - decoding: unused
|
|
233
|
-
*
|
|
234
|
-
* Values:
|
|
235
|
-
* - 0 (FF_MB_DECISION_SIMPLE): uses mb_cmp
|
|
236
|
-
* - 1 (FF_MB_DECISION_BITS): chooses the one which needs the fewest bits
|
|
237
|
-
* - 2 (FF_MB_DECISION_RD): rate distortion
|
|
212
|
+
* Direct mapping to AVCodecContext->mb_decision.
|
|
238
213
|
*/
|
|
239
214
|
get mbDecision(): number;
|
|
240
215
|
set mbDecision(value: number);
|
|
241
216
|
/**
|
|
242
|
-
*
|
|
243
|
-
*
|
|
244
|
-
*
|
|
245
|
-
*
|
|
246
|
-
*
|
|
217
|
+
* Number of frames delay in decoder.
|
|
218
|
+
*
|
|
219
|
+
* For codecs with B-frames.
|
|
220
|
+
*
|
|
221
|
+
* Direct mapping to AVCodecContext->has_b_frames.
|
|
247
222
|
*/
|
|
248
223
|
get hasBFrames(): number;
|
|
249
224
|
/**
|
|
250
|
-
* Sample aspect ratio
|
|
251
|
-
*
|
|
252
|
-
*
|
|
253
|
-
*
|
|
254
|
-
*
|
|
225
|
+
* Sample aspect ratio.
|
|
226
|
+
*
|
|
227
|
+
* Pixel width/height ratio.
|
|
228
|
+
*
|
|
229
|
+
* Direct mapping to AVCodecContext->sample_aspect_ratio.
|
|
255
230
|
*/
|
|
256
231
|
get sampleAspectRatio(): Rational;
|
|
257
232
|
set sampleAspectRatio(value: Rational);
|
|
258
233
|
/**
|
|
259
|
-
*
|
|
260
|
-
*
|
|
261
|
-
*
|
|
262
|
-
*
|
|
263
|
-
*
|
|
234
|
+
* Frame rate.
|
|
235
|
+
*
|
|
236
|
+
* Frames per second for encoding.
|
|
237
|
+
*
|
|
238
|
+
* Direct mapping to AVCodecContext->framerate.
|
|
264
239
|
*/
|
|
265
240
|
get framerate(): Rational;
|
|
266
241
|
set framerate(value: Rational);
|
|
267
242
|
/**
|
|
268
|
-
* Color range
|
|
269
|
-
*
|
|
270
|
-
*
|
|
243
|
+
* Color range.
|
|
244
|
+
*
|
|
245
|
+
* MPEG (limited) or JPEG (full) range.
|
|
246
|
+
*
|
|
247
|
+
* Direct mapping to AVCodecContext->color_range.
|
|
271
248
|
*/
|
|
272
249
|
get colorRange(): AVColorRange;
|
|
273
250
|
set colorRange(value: AVColorRange);
|
|
274
251
|
/**
|
|
275
|
-
*
|
|
276
|
-
*
|
|
277
|
-
*
|
|
252
|
+
* Color primaries.
|
|
253
|
+
*
|
|
254
|
+
* Chromaticity coordinates of source primaries.
|
|
255
|
+
*
|
|
256
|
+
* Direct mapping to AVCodecContext->color_primaries.
|
|
278
257
|
*/
|
|
279
258
|
get colorPrimaries(): AVColorPrimaries;
|
|
280
259
|
set colorPrimaries(value: AVColorPrimaries);
|
|
281
260
|
/**
|
|
282
|
-
* Color
|
|
283
|
-
*
|
|
284
|
-
*
|
|
261
|
+
* Color transfer characteristic.
|
|
262
|
+
*
|
|
263
|
+
* Transfer function (gamma).
|
|
264
|
+
*
|
|
265
|
+
* Direct mapping to AVCodecContext->color_trc.
|
|
285
266
|
*/
|
|
286
267
|
get colorTrc(): AVColorTransferCharacteristic;
|
|
287
268
|
set colorTrc(value: AVColorTransferCharacteristic);
|
|
288
269
|
/**
|
|
289
|
-
* YUV
|
|
290
|
-
*
|
|
291
|
-
*
|
|
270
|
+
* YUV color space.
|
|
271
|
+
*
|
|
272
|
+
* Color space for YUV content.
|
|
273
|
+
*
|
|
274
|
+
* Direct mapping to AVCodecContext->colorspace.
|
|
292
275
|
*/
|
|
293
276
|
get colorSpace(): AVColorSpace;
|
|
294
277
|
set colorSpace(value: AVColorSpace);
|
|
295
278
|
/**
|
|
296
|
-
*
|
|
297
|
-
*
|
|
298
|
-
*
|
|
279
|
+
* Chroma sample location.
|
|
280
|
+
*
|
|
281
|
+
* Position of chroma samples.
|
|
282
|
+
*
|
|
283
|
+
* Direct mapping to AVCodecContext->chroma_sample_location.
|
|
299
284
|
*/
|
|
300
285
|
get chromaLocation(): AVChromaLocation;
|
|
301
286
|
set chromaLocation(value: AVChromaLocation);
|
|
302
287
|
/**
|
|
303
|
-
*
|
|
304
|
-
*
|
|
305
|
-
*
|
|
306
|
-
*
|
|
288
|
+
* Audio sample rate.
|
|
289
|
+
*
|
|
290
|
+
* Samples per second.
|
|
291
|
+
*
|
|
292
|
+
* Direct mapping to AVCodecContext->sample_rate.
|
|
307
293
|
*/
|
|
308
294
|
get sampleRate(): number;
|
|
309
295
|
set sampleRate(value: number);
|
|
310
296
|
/**
|
|
311
297
|
* Number of audio channels.
|
|
312
|
-
*
|
|
298
|
+
*
|
|
299
|
+
* Direct mapping to AVCodecContext->channels.
|
|
313
300
|
*/
|
|
314
301
|
get channels(): number;
|
|
315
302
|
set channels(value: number);
|
|
316
303
|
/**
|
|
317
304
|
* Audio sample format.
|
|
318
|
-
*
|
|
319
|
-
*
|
|
305
|
+
*
|
|
306
|
+
* Format of audio samples.
|
|
307
|
+
*
|
|
308
|
+
* Direct mapping to AVCodecContext->sample_fmt.
|
|
320
309
|
*/
|
|
321
310
|
get sampleFormat(): AVSampleFormat;
|
|
322
311
|
set sampleFormat(value: AVSampleFormat);
|
|
323
312
|
/**
|
|
324
|
-
* Number of samples per
|
|
325
|
-
*
|
|
326
|
-
*
|
|
327
|
-
* May be 0 when the codec has AV_CODEC_CAP_VARIABLE_FRAME_SIZE set, then the
|
|
328
|
-
* frame size is not restricted.
|
|
329
|
-
* - decoding: May be set by some decoders to indicate constant frame size.
|
|
313
|
+
* Number of samples per audio frame.
|
|
314
|
+
*
|
|
315
|
+
* Direct mapping to AVCodecContext->frame_size.
|
|
330
316
|
*/
|
|
331
317
|
get frameSize(): number;
|
|
332
318
|
set frameSize(value: number);
|
|
333
319
|
/**
|
|
334
|
-
*
|
|
335
|
-
*
|
|
336
|
-
*
|
|
337
|
-
*
|
|
320
|
+
* Current frame number.
|
|
321
|
+
*
|
|
322
|
+
* Frame counter for debugging.
|
|
323
|
+
*
|
|
324
|
+
* Direct mapping to AVCodecContext->frame_number.
|
|
338
325
|
*/
|
|
339
326
|
get frameNumber(): number;
|
|
340
327
|
/**
|
|
341
328
|
* Audio channel layout.
|
|
342
|
-
*
|
|
343
|
-
*
|
|
344
|
-
*
|
|
329
|
+
*
|
|
330
|
+
* Describes channel configuration.
|
|
331
|
+
*
|
|
332
|
+
* Direct mapping to AVCodecContext->ch_layout.
|
|
345
333
|
*/
|
|
346
334
|
get channelLayout(): ChannelLayout;
|
|
347
335
|
set channelLayout(value: ChannelLayout);
|
|
348
336
|
/**
|
|
349
337
|
* Minimum quantizer.
|
|
350
|
-
*
|
|
351
|
-
*
|
|
338
|
+
*
|
|
339
|
+
* Minimum quantization parameter.
|
|
340
|
+
*
|
|
341
|
+
* Direct mapping to AVCodecContext->qmin.
|
|
352
342
|
*/
|
|
353
343
|
get qMin(): number;
|
|
354
344
|
set qMin(value: number);
|
|
355
345
|
/**
|
|
356
346
|
* Maximum quantizer.
|
|
357
|
-
*
|
|
358
|
-
*
|
|
347
|
+
*
|
|
348
|
+
* Maximum quantization parameter.
|
|
349
|
+
*
|
|
350
|
+
* Direct mapping to AVCodecContext->qmax.
|
|
359
351
|
*/
|
|
360
352
|
get qMax(): number;
|
|
361
353
|
set qMax(value: number);
|
|
362
354
|
/**
|
|
355
|
+
* Rate control buffer size.
|
|
356
|
+
*
|
|
363
357
|
* Decoder bitstream buffer size.
|
|
364
|
-
*
|
|
365
|
-
*
|
|
358
|
+
*
|
|
359
|
+
* Direct mapping to AVCodecContext->rc_buffer_size.
|
|
366
360
|
*/
|
|
367
361
|
get rcBufferSize(): number;
|
|
368
362
|
set rcBufferSize(value: number);
|
|
369
363
|
/**
|
|
370
364
|
* Maximum bitrate.
|
|
371
|
-
*
|
|
372
|
-
*
|
|
365
|
+
*
|
|
366
|
+
* Maximum bitrate in bits per second.
|
|
367
|
+
*
|
|
368
|
+
* Direct mapping to AVCodecContext->rc_max_rate.
|
|
373
369
|
*/
|
|
374
370
|
get rcMaxRate(): bigint;
|
|
375
371
|
set rcMaxRate(value: bigint);
|
|
376
372
|
/**
|
|
377
373
|
* Minimum bitrate.
|
|
378
|
-
*
|
|
379
|
-
*
|
|
374
|
+
*
|
|
375
|
+
* Minimum bitrate in bits per second.
|
|
376
|
+
*
|
|
377
|
+
* Direct mapping to AVCodecContext->rc_min_rate.
|
|
380
378
|
*/
|
|
381
379
|
get rcMinRate(): bigint;
|
|
382
380
|
set rcMinRate(value: bigint);
|
|
383
381
|
/**
|
|
384
|
-
* Hardware device context
|
|
382
|
+
* Hardware device context.
|
|
385
383
|
*
|
|
386
|
-
*
|
|
384
|
+
* Reference to hardware device for acceleration.
|
|
387
385
|
*
|
|
388
|
-
*
|
|
389
|
-
* to the hardware device context before opening the codec.
|
|
386
|
+
* Direct mapping to AVCodecContext->hw_device_ctx.
|
|
390
387
|
*/
|
|
391
388
|
get hwDeviceCtx(): HardwareDeviceContext | null;
|
|
392
389
|
set hwDeviceCtx(value: HardwareDeviceContext | null);
|
|
393
390
|
/**
|
|
394
|
-
* Hardware frames context
|
|
391
|
+
* Hardware frames context.
|
|
395
392
|
*
|
|
396
|
-
*
|
|
393
|
+
* Reference to hardware frames for GPU memory.
|
|
397
394
|
*
|
|
398
|
-
*
|
|
399
|
-
* to provide the caller with hardware frames. For encoders, this
|
|
400
|
-
* must be set by the caller before opening the encoder.
|
|
395
|
+
* Direct mapping to AVCodecContext->hw_frames_ctx.
|
|
401
396
|
*/
|
|
402
397
|
get hwFramesCtx(): HardwareFramesContext | null;
|
|
403
398
|
set hwFramesCtx(value: HardwareFramesContext | null);
|
|
404
399
|
/**
|
|
405
|
-
* Check if
|
|
406
|
-
*
|
|
407
|
-
* Direct mapping to avcodec_is_open()
|
|
400
|
+
* Check if codec is open.
|
|
408
401
|
*
|
|
409
|
-
*
|
|
402
|
+
* True if the codec has been opened.
|
|
410
403
|
*/
|
|
411
404
|
get isOpen(): boolean;
|
|
412
405
|
/**
|
|
413
|
-
* Allocate
|
|
414
|
-
*
|
|
415
|
-
* Allocates the codec context and initializes with codec-specific defaults.
|
|
416
|
-
* Must be called before using the context.
|
|
406
|
+
* Allocate codec context.
|
|
417
407
|
*
|
|
418
|
-
*
|
|
408
|
+
* Allocates and initializes the context for the given codec.
|
|
419
409
|
*
|
|
420
|
-
*
|
|
421
|
-
* for the given codec. It is illegal to then call open2()
|
|
422
|
-
* with a different codec.
|
|
410
|
+
* Direct mapping to avcodec_alloc_context3().
|
|
423
411
|
*
|
|
424
|
-
* @
|
|
412
|
+
* @param codec - Codec to use (null for default)
|
|
425
413
|
*
|
|
426
414
|
* @example
|
|
427
415
|
* ```typescript
|
|
428
|
-
* import {
|
|
416
|
+
* import { Codec } from 'node-av';
|
|
429
417
|
* import { AV_CODEC_ID_H264 } from 'node-av/constants';
|
|
430
418
|
*
|
|
431
419
|
* const codec = Codec.findDecoder(AV_CODEC_ID_H264);
|
|
432
|
-
* const ctx = new CodecContext();
|
|
433
420
|
* ctx.allocContext3(codec);
|
|
434
|
-
* // Context is now allocated with H264 defaults
|
|
435
421
|
* ```
|
|
436
422
|
*
|
|
437
423
|
* @see {@link open2} To open the codec
|
|
@@ -439,309 +425,258 @@ export declare class CodecContext extends OptionMember<NativeCodecContext> imple
|
|
|
439
425
|
*/
|
|
440
426
|
allocContext3(codec?: Codec | null): void;
|
|
441
427
|
/**
|
|
442
|
-
* Free the codec context
|
|
428
|
+
* Free the codec context.
|
|
443
429
|
*
|
|
444
|
-
* Releases all resources
|
|
445
|
-
* The context becomes invalid after this call.
|
|
430
|
+
* Releases all resources. The context becomes invalid.
|
|
446
431
|
*
|
|
447
|
-
* Direct mapping to avcodec_free_context()
|
|
432
|
+
* Direct mapping to avcodec_free_context().
|
|
448
433
|
*
|
|
449
434
|
* @example
|
|
450
435
|
* ```typescript
|
|
451
436
|
* ctx.freeContext();
|
|
452
|
-
* //
|
|
437
|
+
* // Context is now invalid
|
|
453
438
|
* ```
|
|
439
|
+
*
|
|
440
|
+
* @see {@link Symbol.dispose} For automatic cleanup
|
|
441
|
+
* @see {@link allocContext3} To allocate a new context
|
|
454
442
|
*/
|
|
455
443
|
freeContext(): void;
|
|
456
444
|
/**
|
|
457
|
-
*
|
|
458
|
-
*
|
|
459
|
-
* Opens the codec and prepares it for encoding or decoding.
|
|
460
|
-
* Prior to using this function the context has to be allocated with allocContext3().
|
|
445
|
+
* Open the codec.
|
|
461
446
|
*
|
|
462
|
-
*
|
|
447
|
+
* Initializes the codec for encoding/decoding.
|
|
448
|
+
* Must be called before processing frames/packets.
|
|
463
449
|
*
|
|
464
|
-
*
|
|
465
|
-
* previously passed to allocContext3() for this context, then this
|
|
466
|
-
* parameter MUST be either NULL or equal to the previously passed codec.
|
|
467
|
-
* @param options - A dictionary filled with AVCodecContext and codec-private options.
|
|
450
|
+
* Direct mapping to avcodec_open2().
|
|
468
451
|
*
|
|
452
|
+
* @param codec - Codec to open with (null to use already set)
|
|
453
|
+
* @param options - Codec-specific options
|
|
469
454
|
* @returns 0 on success, negative AVERROR on error:
|
|
470
|
-
* -
|
|
471
|
-
* -
|
|
472
|
-
* - AVERROR(ENOMEM): Memory allocation failure
|
|
473
|
-
* - <0: Other codec-specific errors
|
|
455
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
456
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
474
457
|
*
|
|
475
458
|
* @example
|
|
476
459
|
* ```typescript
|
|
477
460
|
* import { FFmpegError } from 'node-av';
|
|
478
461
|
*
|
|
479
|
-
* const ret = await ctx.open2(codec
|
|
462
|
+
* const ret = await ctx.open2(codec);
|
|
480
463
|
* FFmpegError.throwIfError(ret, 'open2');
|
|
464
|
+
* // Codec is now open and ready
|
|
481
465
|
* ```
|
|
482
466
|
*
|
|
483
|
-
* @see {@link
|
|
484
|
-
* @see {@link
|
|
467
|
+
* @see {@link allocContext3} Must be called first
|
|
468
|
+
* @see {@link isOpen} To check if open
|
|
485
469
|
*/
|
|
486
470
|
open2(codec?: Codec | null, options?: Dictionary | null): Promise<number>;
|
|
487
471
|
/**
|
|
488
|
-
* Fill
|
|
472
|
+
* Fill codec context from parameters.
|
|
489
473
|
*
|
|
490
|
-
*
|
|
474
|
+
* Copies codec parameters from stream to context.
|
|
475
|
+
* Used when setting up decoders.
|
|
491
476
|
*
|
|
492
|
-
*
|
|
477
|
+
* Direct mapping to avcodec_parameters_to_context().
|
|
493
478
|
*
|
|
479
|
+
* @param params - Source codec parameters
|
|
494
480
|
* @returns 0 on success, negative AVERROR on error:
|
|
495
|
-
* -
|
|
496
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
497
|
-
* - <0: Other errors
|
|
481
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
498
482
|
*
|
|
499
483
|
* @example
|
|
500
484
|
* ```typescript
|
|
501
|
-
*
|
|
485
|
+
* import { FFmpegError } from 'node-av';
|
|
486
|
+
*
|
|
502
487
|
* const ret = ctx.parametersToContext(stream.codecpar);
|
|
503
|
-
*
|
|
504
|
-
* throw new FFmpegError(ret);
|
|
505
|
-
* }
|
|
488
|
+
* FFmpegError.throwIfError(ret, 'parametersToContext');
|
|
506
489
|
* ```
|
|
507
490
|
*
|
|
508
|
-
* @see parametersFromContext
|
|
491
|
+
* @see {@link parametersFromContext} For the reverse
|
|
509
492
|
*/
|
|
510
493
|
parametersToContext(params: CodecParameters): number;
|
|
511
494
|
/**
|
|
512
|
-
* Fill
|
|
495
|
+
* Fill parameters from codec context.
|
|
513
496
|
*
|
|
514
|
-
*
|
|
497
|
+
* Copies codec parameters from context to stream.
|
|
498
|
+
* Used when setting up encoders.
|
|
515
499
|
*
|
|
516
|
-
*
|
|
500
|
+
* Direct mapping to avcodec_parameters_from_context().
|
|
517
501
|
*
|
|
502
|
+
* @param params - Destination codec parameters
|
|
518
503
|
* @returns 0 on success, negative AVERROR on error:
|
|
519
|
-
* -
|
|
520
|
-
* - AVERROR(EINVAL): Invalid parameters
|
|
521
|
-
* - <0: Other errors
|
|
504
|
+
* - AVERROR_EINVAL: Invalid parameters
|
|
522
505
|
*
|
|
523
506
|
* @example
|
|
524
507
|
* ```typescript
|
|
525
|
-
*
|
|
526
|
-
*
|
|
527
|
-
*
|
|
528
|
-
*
|
|
529
|
-
* }
|
|
508
|
+
* import { FFmpegError } from 'node-av';
|
|
509
|
+
*
|
|
510
|
+
* const ret = ctx.parametersFromContext(stream.codecpar);
|
|
511
|
+
* FFmpegError.throwIfError(ret, 'parametersFromContext');
|
|
530
512
|
* ```
|
|
531
513
|
*
|
|
532
|
-
* @see parametersToContext
|
|
514
|
+
* @see {@link parametersToContext} For the reverse
|
|
533
515
|
*/
|
|
534
516
|
parametersFromContext(params: CodecParameters): number;
|
|
535
517
|
/**
|
|
536
|
-
*
|
|
537
|
-
*
|
|
518
|
+
* Flush codec buffers.
|
|
519
|
+
*
|
|
520
|
+
* Resets the internal codec state.
|
|
521
|
+
* Used when seeking or switching streams.
|
|
538
522
|
*
|
|
539
|
-
* Direct mapping to avcodec_flush_buffers()
|
|
523
|
+
* Direct mapping to avcodec_flush_buffers().
|
|
540
524
|
*
|
|
541
525
|
* @example
|
|
542
526
|
* ```typescript
|
|
543
|
-
* // Flush
|
|
544
|
-
*
|
|
545
|
-
*
|
|
527
|
+
* // Flush when seeking
|
|
528
|
+
* ctx.flushBuffers();
|
|
529
|
+
* // Codec is now ready for new data
|
|
546
530
|
* ```
|
|
547
531
|
*/
|
|
548
532
|
flushBuffers(): void;
|
|
549
533
|
/**
|
|
550
|
-
*
|
|
551
|
-
*
|
|
552
|
-
* Sends compressed data to the decoder for processing.
|
|
553
|
-
* The decoder may buffer the packet internally.
|
|
534
|
+
* Send packet to decoder.
|
|
554
535
|
*
|
|
555
|
-
*
|
|
536
|
+
* Submits encoded data for decoding.
|
|
537
|
+
* Call receiveFrame() to get decoded frames.
|
|
556
538
|
*
|
|
557
|
-
*
|
|
539
|
+
* Direct mapping to avcodec_send_packet().
|
|
558
540
|
*
|
|
541
|
+
* @param packet - Packet to decode (null to flush)
|
|
559
542
|
* @returns 0 on success, negative AVERROR on error:
|
|
560
|
-
* -
|
|
561
|
-
* -
|
|
562
|
-
* -
|
|
563
|
-
* -
|
|
564
|
-
* - AVERROR(ENOMEM): Failed to add packet to internal queue
|
|
565
|
-
* - <0: Other legitimate decoding errors
|
|
543
|
+
* - AVERROR_EAGAIN: Must receive frames first
|
|
544
|
+
* - AVERROR_EOF: Decoder has been flushed
|
|
545
|
+
* - AVERROR_EINVAL: Invalid decoder state
|
|
546
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
566
547
|
*
|
|
567
548
|
* @example
|
|
568
549
|
* ```typescript
|
|
569
|
-
* import { FFmpegError
|
|
570
|
-
* import { AVERROR_EAGAIN } from 'node-av
|
|
550
|
+
* import { FFmpegError } from 'node-av';
|
|
551
|
+
* import { AVERROR_EAGAIN } from 'node-av';
|
|
571
552
|
*
|
|
572
|
-
*
|
|
573
|
-
* const ret = await decoder.sendPacket(packet);
|
|
553
|
+
* const ret = await ctx.sendPacket(packet);
|
|
574
554
|
* if (ret === AVERROR_EAGAIN) {
|
|
575
|
-
* // Need to
|
|
576
|
-
* const frame = new Frame();
|
|
577
|
-
* frame.alloc();
|
|
578
|
-
* const recvRet = await decoder.receiveFrame(frame);
|
|
579
|
-
* FFmpegError.throwIfError(recvRet, 'receiveFrame');
|
|
555
|
+
* // Need to receive frames first
|
|
580
556
|
* } else {
|
|
581
557
|
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
582
558
|
* }
|
|
583
559
|
* ```
|
|
584
560
|
*
|
|
585
|
-
* @see {@link receiveFrame} To
|
|
561
|
+
* @see {@link receiveFrame} To get decoded frames
|
|
586
562
|
*/
|
|
587
563
|
sendPacket(packet: Packet | null): Promise<number>;
|
|
588
564
|
/**
|
|
589
|
-
*
|
|
590
|
-
*
|
|
591
|
-
* Retrieves decoded frames from the decoder.
|
|
592
|
-
* The frame must be allocated before calling this function.
|
|
565
|
+
* Receive decoded frame.
|
|
593
566
|
*
|
|
594
|
-
*
|
|
567
|
+
* Gets a decoded frame from the decoder.
|
|
568
|
+
* Call after sendPacket().
|
|
595
569
|
*
|
|
596
|
-
*
|
|
570
|
+
* Direct mapping to avcodec_receive_frame().
|
|
597
571
|
*
|
|
572
|
+
* @param frame - Frame to receive into
|
|
598
573
|
* @returns 0 on success, negative AVERROR on error:
|
|
599
|
-
* -
|
|
600
|
-
* -
|
|
601
|
-
* -
|
|
602
|
-
* - AVERROR(EINVAL): Codec not opened or is an encoder
|
|
603
|
-
* - <0: Other legitimate decoding errors
|
|
574
|
+
* - AVERROR_EAGAIN: Need more input
|
|
575
|
+
* - AVERROR_EOF: All frames have been output
|
|
576
|
+
* - AVERROR_EINVAL: Invalid decoder state
|
|
604
577
|
*
|
|
605
578
|
* @example
|
|
606
579
|
* ```typescript
|
|
607
|
-
* import {
|
|
608
|
-
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av
|
|
609
|
-
*
|
|
610
|
-
* // Receive all frames from decoder
|
|
611
|
-
* const frame = new Frame();
|
|
612
|
-
* frame.alloc();
|
|
613
|
-
*
|
|
614
|
-
* while (true) {
|
|
615
|
-
* const ret = await decoder.receiveFrame(frame);
|
|
616
|
-
* if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
|
|
617
|
-
* break;
|
|
618
|
-
* }
|
|
619
|
-
* FFmpegError.throwIfError(ret, 'receiveFrame');
|
|
580
|
+
* import { FFmpegError } from 'node-av';
|
|
581
|
+
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
|
|
620
582
|
*
|
|
621
|
-
*
|
|
622
|
-
*
|
|
623
|
-
* frame
|
|
583
|
+
* const ret = await ctx.receiveFrame(frame);
|
|
584
|
+
* if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
|
|
585
|
+
* // No frame available
|
|
586
|
+
* } else {
|
|
587
|
+
* FFmpegError.throwIfError(ret, 'receiveFrame');
|
|
588
|
+
* // Process decoded frame
|
|
624
589
|
* }
|
|
625
590
|
* ```
|
|
626
591
|
*
|
|
627
|
-
* @see {@link sendPacket} To send
|
|
592
|
+
* @see {@link sendPacket} To send packets for decoding
|
|
628
593
|
*/
|
|
629
594
|
receiveFrame(frame: Frame): Promise<number>;
|
|
630
595
|
/**
|
|
631
|
-
*
|
|
596
|
+
* Send frame to encoder.
|
|
632
597
|
*
|
|
633
|
-
*
|
|
634
|
-
*
|
|
598
|
+
* Submits raw frame for encoding.
|
|
599
|
+
* Call receivePacket() to get encoded packets.
|
|
635
600
|
*
|
|
636
|
-
* Direct mapping to avcodec_send_frame()
|
|
637
|
-
*
|
|
638
|
-
* @param frame - AVFrame containing the raw audio or video frame to be encoded.
|
|
639
|
-
* Can be NULL for flush packet (signals end of stream).
|
|
601
|
+
* Direct mapping to avcodec_send_frame().
|
|
640
602
|
*
|
|
603
|
+
* @param frame - Frame to encode (null to flush)
|
|
641
604
|
* @returns 0 on success, negative AVERROR on error:
|
|
642
|
-
* -
|
|
643
|
-
* -
|
|
644
|
-
* -
|
|
645
|
-
* -
|
|
646
|
-
* - AVERROR(ENOMEM): Failed to add packet to internal queue
|
|
647
|
-
* - <0: Other legitimate encoding errors
|
|
605
|
+
* - AVERROR_EAGAIN: Must receive packets first
|
|
606
|
+
* - AVERROR_EOF: Encoder has been flushed
|
|
607
|
+
* - AVERROR_EINVAL: Invalid encoder state
|
|
608
|
+
* - AVERROR_ENOMEM: Memory allocation failure
|
|
648
609
|
*
|
|
649
610
|
* @example
|
|
650
611
|
* ```typescript
|
|
651
|
-
* import {
|
|
652
|
-
* import { AVERROR_EAGAIN } from 'node-av
|
|
612
|
+
* import { FFmpegError } from 'node-av';
|
|
613
|
+
* import { AVERROR_EAGAIN } from 'node-av';
|
|
653
614
|
*
|
|
654
|
-
*
|
|
655
|
-
* const ret = await encoder.sendFrame(frame);
|
|
615
|
+
* const ret = await ctx.sendFrame(frame);
|
|
656
616
|
* if (ret === AVERROR_EAGAIN) {
|
|
657
|
-
* // Need to
|
|
658
|
-
* const packet = new Packet();
|
|
659
|
-
* packet.alloc();
|
|
660
|
-
* const recvRet = await encoder.receivePacket(packet);
|
|
661
|
-
* FFmpegError.throwIfError(recvRet, 'receivePacket');
|
|
617
|
+
* // Need to receive packets first
|
|
662
618
|
* } else {
|
|
663
619
|
* FFmpegError.throwIfError(ret, 'sendFrame');
|
|
664
620
|
* }
|
|
665
621
|
* ```
|
|
666
622
|
*
|
|
667
|
-
* @see {@link receivePacket} To
|
|
668
|
-
*
|
|
669
|
-
* @note For audio: If AV_CODEC_CAP_VARIABLE_FRAME_SIZE is set, then each frame
|
|
670
|
-
* can have any number of samples. If not set, frame.nbSamples must equal
|
|
671
|
-
* avctx.frameSize for all frames except the last.
|
|
623
|
+
* @see {@link receivePacket} To get encoded packets
|
|
672
624
|
*/
|
|
673
625
|
sendFrame(frame: Frame | null): Promise<number>;
|
|
674
626
|
/**
|
|
675
|
-
*
|
|
627
|
+
* Receive encoded packet.
|
|
676
628
|
*
|
|
677
|
-
*
|
|
678
|
-
*
|
|
629
|
+
* Gets an encoded packet from the encoder.
|
|
630
|
+
* Call after sendFrame().
|
|
679
631
|
*
|
|
680
|
-
* Direct mapping to avcodec_receive_packet()
|
|
681
|
-
*
|
|
682
|
-
* @param packet - Packet to receive encoded data. Must be allocated.
|
|
632
|
+
* Direct mapping to avcodec_receive_packet().
|
|
683
633
|
*
|
|
634
|
+
* @param packet - Packet to receive into
|
|
684
635
|
* @returns 0 on success, negative AVERROR on error:
|
|
685
|
-
* -
|
|
686
|
-
* -
|
|
687
|
-
* -
|
|
688
|
-
* - AVERROR(EINVAL): Codec not opened or is a decoder
|
|
689
|
-
* - <0: Other legitimate encoding errors
|
|
636
|
+
* - AVERROR_EAGAIN: Need more input
|
|
637
|
+
* - AVERROR_EOF: All packets have been output
|
|
638
|
+
* - AVERROR_EINVAL: Invalid encoder state
|
|
690
639
|
*
|
|
691
640
|
* @example
|
|
692
641
|
* ```typescript
|
|
693
|
-
* import {
|
|
694
|
-
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av
|
|
695
|
-
*
|
|
696
|
-
*
|
|
697
|
-
*
|
|
698
|
-
* packet
|
|
699
|
-
*
|
|
700
|
-
*
|
|
701
|
-
*
|
|
702
|
-
* if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
|
|
703
|
-
* break;
|
|
704
|
-
* }
|
|
705
|
-
* if (ret < 0) {
|
|
706
|
-
* throw new FFmpegError(ret);
|
|
707
|
-
* }
|
|
708
|
-
* // Write packet to output
|
|
709
|
-
* await formatContext.writeFrame(packet);
|
|
710
|
-
* packet.unref();
|
|
642
|
+
* import { FFmpegError } from 'node-av';
|
|
643
|
+
* import { AVERROR_EAGAIN, AVERROR_EOF } from 'node-av';
|
|
644
|
+
*
|
|
645
|
+
* const ret = await ctx.receivePacket(packet);
|
|
646
|
+
* if (ret === AVERROR_EAGAIN || ret === AVERROR_EOF) {
|
|
647
|
+
* // No packet available
|
|
648
|
+
* } else {
|
|
649
|
+
* FFmpegError.throwIfError(ret, 'receivePacket');
|
|
650
|
+
* // Process encoded packet
|
|
711
651
|
* }
|
|
712
652
|
* ```
|
|
713
653
|
*
|
|
714
|
-
* @see sendFrame
|
|
654
|
+
* @see {@link sendFrame} To send frames for encoding
|
|
715
655
|
*/
|
|
716
656
|
receivePacket(packet: Packet): Promise<number>;
|
|
717
657
|
/**
|
|
718
|
-
* Set
|
|
658
|
+
* Set hardware pixel format.
|
|
719
659
|
*
|
|
720
|
-
*
|
|
721
|
-
*
|
|
722
|
-
* can be specified.
|
|
660
|
+
* Configures hardware acceleration pixel formats.
|
|
661
|
+
* Used in get_format callback for hardware decoding.
|
|
723
662
|
*
|
|
724
|
-
* @param hwFormat -
|
|
725
|
-
* @param swFormat -
|
|
663
|
+
* @param hwFormat - Hardware pixel format
|
|
664
|
+
* @param swFormat - Software pixel format (optional)
|
|
726
665
|
*
|
|
727
666
|
* @example
|
|
728
667
|
* ```typescript
|
|
729
|
-
*
|
|
730
|
-
*
|
|
731
|
-
*
|
|
732
|
-
* // With software fallback
|
|
733
|
-
* codecContext.setHardwarePixelFormat(
|
|
734
|
-
* AV_PIX_FMT_VIDEOTOOLBOX,
|
|
735
|
-
* AV_PIX_FMT_YUV420P // Fallback to YUV420P if hardware not available
|
|
736
|
-
* );
|
|
668
|
+
* import { AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12 } from 'node-av/constants';
|
|
669
|
+
*
|
|
670
|
+
* ctx.setHardwarePixelFormat(AV_PIX_FMT_CUDA, AV_PIX_FMT_NV12);
|
|
737
671
|
* ```
|
|
738
672
|
*/
|
|
739
673
|
setHardwarePixelFormat(hwFormat: AVPixelFormat, swFormat?: AVPixelFormat): void;
|
|
740
674
|
/**
|
|
741
|
-
* Get the native
|
|
675
|
+
* Get the underlying native CodecContext object.
|
|
676
|
+
*
|
|
677
|
+
* @returns The native CodecContext binding object
|
|
742
678
|
*
|
|
743
|
-
* @internal
|
|
744
|
-
* @returns The underlying native codec context object
|
|
679
|
+
* @internal
|
|
745
680
|
*/
|
|
746
681
|
getNative(): NativeCodecContext;
|
|
747
682
|
/**
|
|
@@ -755,7 +690,8 @@ export declare class CodecContext extends OptionMember<NativeCodecContext> imple
|
|
|
755
690
|
* {
|
|
756
691
|
* using ctx = new CodecContext();
|
|
757
692
|
* ctx.allocContext3(codec);
|
|
758
|
-
*
|
|
693
|
+
* await ctx.open2();
|
|
694
|
+
* // Use context...
|
|
759
695
|
* } // Automatically freed when leaving scope
|
|
760
696
|
* ```
|
|
761
697
|
*/
|