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