node-av 0.0.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +8 -0
- package/LICENSE.md +22 -0
- package/README.md +377 -0
- package/binding.gyp +78 -0
- package/dist/api/bitstream-filter.d.ts +246 -0
- package/dist/api/bitstream-filter.js +369 -0
- package/dist/api/bitstream-filter.js.map +1 -0
- package/dist/api/decoder.d.ts +257 -0
- package/dist/api/decoder.js +424 -0
- package/dist/api/decoder.js.map +1 -0
- package/dist/api/encoder.d.ts +298 -0
- package/dist/api/encoder.js +574 -0
- package/dist/api/encoder.js.map +1 -0
- package/dist/api/filter.d.ts +457 -0
- package/dist/api/filter.js +876 -0
- package/dist/api/filter.js.map +1 -0
- package/dist/api/hardware.d.ts +318 -0
- package/dist/api/hardware.js +558 -0
- package/dist/api/hardware.js.map +1 -0
- package/dist/api/index.d.ts +12 -0
- package/dist/api/index.js +20 -0
- package/dist/api/index.js.map +1 -0
- package/dist/api/io-stream.d.ts +109 -0
- package/dist/api/io-stream.js +124 -0
- package/dist/api/io-stream.js.map +1 -0
- package/dist/api/media-input.d.ts +295 -0
- package/dist/api/media-input.js +456 -0
- package/dist/api/media-input.js.map +1 -0
- package/dist/api/media-output.d.ts +274 -0
- package/dist/api/media-output.js +486 -0
- package/dist/api/media-output.js.map +1 -0
- package/dist/api/pipeline.d.ts +117 -0
- package/dist/api/pipeline.js +836 -0
- package/dist/api/pipeline.js.map +1 -0
- package/dist/api/types.d.ts +440 -0
- package/dist/api/types.js +2 -0
- package/dist/api/types.js.map +1 -0
- package/dist/api/utilities/audio-sample.d.ts +115 -0
- package/dist/api/utilities/audio-sample.js +110 -0
- package/dist/api/utilities/audio-sample.js.map +1 -0
- package/dist/api/utilities/channel-layout.d.ts +83 -0
- package/dist/api/utilities/channel-layout.js +87 -0
- package/dist/api/utilities/channel-layout.js.map +1 -0
- package/dist/api/utilities/image.d.ts +177 -0
- package/dist/api/utilities/image.js +183 -0
- package/dist/api/utilities/image.js.map +1 -0
- package/dist/api/utilities/index.d.ts +8 -0
- package/dist/api/utilities/index.js +17 -0
- package/dist/api/utilities/index.js.map +1 -0
- package/dist/api/utilities/media-type.d.ts +56 -0
- package/dist/api/utilities/media-type.js +60 -0
- package/dist/api/utilities/media-type.js.map +1 -0
- package/dist/api/utilities/pixel-format.d.ts +94 -0
- package/dist/api/utilities/pixel-format.js +102 -0
- package/dist/api/utilities/pixel-format.js.map +1 -0
- package/dist/api/utilities/sample-format.d.ts +132 -0
- package/dist/api/utilities/sample-format.js +144 -0
- package/dist/api/utilities/sample-format.js.map +1 -0
- package/dist/api/utilities/streaming.d.ts +104 -0
- package/dist/api/utilities/streaming.js +137 -0
- package/dist/api/utilities/streaming.js.map +1 -0
- package/dist/api/utilities/timestamp.d.ts +187 -0
- package/dist/api/utilities/timestamp.js +200 -0
- package/dist/api/utilities/timestamp.js.map +1 -0
- package/dist/api/utils.d.ts +61 -0
- package/dist/api/utils.js +330 -0
- package/dist/api/utils.js.map +1 -0
- package/dist/index.d.ts +2 -0
- package/dist/index.js +5 -0
- package/dist/index.js.map +1 -0
- package/dist/lib/audio-fifo.d.ts +339 -0
- package/dist/lib/audio-fifo.js +365 -0
- package/dist/lib/audio-fifo.js.map +1 -0
- package/dist/lib/binding.d.ts +192 -0
- package/dist/lib/binding.js +70 -0
- package/dist/lib/binding.js.map +1 -0
- package/dist/lib/bitstream-filter-context.d.ts +345 -0
- package/dist/lib/bitstream-filter-context.js +407 -0
- package/dist/lib/bitstream-filter-context.js.map +1 -0
- package/dist/lib/bitstream-filter.d.ts +124 -0
- package/dist/lib/bitstream-filter.js +138 -0
- package/dist/lib/bitstream-filter.js.map +1 -0
- package/dist/lib/channel-layouts.d.ts +51 -0
- package/dist/lib/channel-layouts.js +55 -0
- package/dist/lib/channel-layouts.js.map +1 -0
- package/dist/lib/codec-context.d.ts +763 -0
- package/dist/lib/codec-context.js +974 -0
- package/dist/lib/codec-context.js.map +1 -0
- package/dist/lib/codec-parameters.d.ts +362 -0
- package/dist/lib/codec-parameters.js +460 -0
- package/dist/lib/codec-parameters.js.map +1 -0
- package/dist/lib/codec-parser.d.ts +185 -0
- package/dist/lib/codec-parser.js +193 -0
- package/dist/lib/codec-parser.js.map +1 -0
- package/dist/lib/codec.d.ts +432 -0
- package/dist/lib/codec.js +492 -0
- package/dist/lib/codec.js.map +1 -0
- package/dist/lib/constants.d.ts +2037 -0
- package/dist/lib/constants.js +1659 -0
- package/dist/lib/constants.js.map +1 -0
- package/dist/lib/dictionary.d.ts +371 -0
- package/dist/lib/dictionary.js +406 -0
- package/dist/lib/dictionary.js.map +1 -0
- package/dist/lib/error.d.ts +216 -0
- package/dist/lib/error.js +254 -0
- package/dist/lib/error.js.map +1 -0
- package/dist/lib/filter-context.d.ts +445 -0
- package/dist/lib/filter-context.js +505 -0
- package/dist/lib/filter-context.js.map +1 -0
- package/dist/lib/filter-graph.d.ts +556 -0
- package/dist/lib/filter-graph.js +608 -0
- package/dist/lib/filter-graph.js.map +1 -0
- package/dist/lib/filter-inout.d.ts +205 -0
- package/dist/lib/filter-inout.js +264 -0
- package/dist/lib/filter-inout.js.map +1 -0
- package/dist/lib/filter.d.ts +231 -0
- package/dist/lib/filter.js +260 -0
- package/dist/lib/filter.js.map +1 -0
- package/dist/lib/format-context.d.ts +798 -0
- package/dist/lib/format-context.js +845 -0
- package/dist/lib/format-context.js.map +1 -0
- package/dist/lib/frame.d.ts +784 -0
- package/dist/lib/frame.js +933 -0
- package/dist/lib/frame.js.map +1 -0
- package/dist/lib/hardware-device-context.d.ts +407 -0
- package/dist/lib/hardware-device-context.js +429 -0
- package/dist/lib/hardware-device-context.js.map +1 -0
- package/dist/lib/hardware-frames-context.d.ts +374 -0
- package/dist/lib/hardware-frames-context.js +430 -0
- package/dist/lib/hardware-frames-context.js.map +1 -0
- package/dist/lib/index.d.ts +31 -0
- package/dist/lib/index.js +54 -0
- package/dist/lib/index.js.map +1 -0
- package/dist/lib/input-format.d.ts +216 -0
- package/dist/lib/input-format.js +246 -0
- package/dist/lib/input-format.js.map +1 -0
- package/dist/lib/io-context.d.ts +495 -0
- package/dist/lib/io-context.js +550 -0
- package/dist/lib/io-context.js.map +1 -0
- package/dist/lib/log.d.ts +201 -0
- package/dist/lib/log.js +219 -0
- package/dist/lib/log.js.map +1 -0
- package/dist/lib/native-types.d.ts +719 -0
- package/dist/lib/native-types.js +2 -0
- package/dist/lib/native-types.js.map +1 -0
- package/dist/lib/option.d.ts +589 -0
- package/dist/lib/option.js +853 -0
- package/dist/lib/option.js.map +1 -0
- package/dist/lib/output-format.d.ts +179 -0
- package/dist/lib/output-format.js +205 -0
- package/dist/lib/output-format.js.map +1 -0
- package/dist/lib/packet.d.ts +487 -0
- package/dist/lib/packet.js +558 -0
- package/dist/lib/packet.js.map +1 -0
- package/dist/lib/rational.d.ts +210 -0
- package/dist/lib/rational.js +233 -0
- package/dist/lib/rational.js.map +1 -0
- package/dist/lib/software-resample-context.d.ts +572 -0
- package/dist/lib/software-resample-context.js +610 -0
- package/dist/lib/software-resample-context.js.map +1 -0
- package/dist/lib/software-scale-context.d.ts +290 -0
- package/dist/lib/software-scale-context.js +308 -0
- package/dist/lib/software-scale-context.js.map +1 -0
- package/dist/lib/stream.d.ts +322 -0
- package/dist/lib/stream.js +408 -0
- package/dist/lib/stream.js.map +1 -0
- package/dist/lib/types.d.ts +59 -0
- package/dist/lib/types.js +8 -0
- package/dist/lib/types.js.map +1 -0
- package/dist/lib/utilities.d.ts +346 -0
- package/dist/lib/utilities.js +424 -0
- package/dist/lib/utilities.js.map +1 -0
- package/install/check.js +113 -0
- package/install/ffmpeg.js +163 -0
- package/package.json +107 -0
|
@@ -0,0 +1,460 @@
|
|
|
1
|
+
import { bindings } from './binding.js';
|
|
2
|
+
import { Rational } from './rational.js';
|
|
3
|
+
/**
|
|
4
|
+
* Codec parameters for stream configuration.
|
|
5
|
+
*
|
|
6
|
+
* Describes the properties of an encoded media stream.
|
|
7
|
+
* Used to transfer codec parameters between contexts and streams.
|
|
8
|
+
* Contains essential information like codec type, dimensions, and format.
|
|
9
|
+
*
|
|
10
|
+
* Direct mapping to FFmpeg's AVCodecParameters.
|
|
11
|
+
*
|
|
12
|
+
* @example
|
|
13
|
+
* ```typescript
|
|
14
|
+
* import { CodecParameters, FFmpegError } from 'node-av';
|
|
15
|
+
* import { AVMEDIA_TYPE_VIDEO, AV_CODEC_ID_H264, AV_PIX_FMT_YUV420P } from 'node-av/constants';
|
|
16
|
+
*
|
|
17
|
+
* // Create and allocate codec parameters
|
|
18
|
+
* const params = new CodecParameters();
|
|
19
|
+
* params.alloc();
|
|
20
|
+
*
|
|
21
|
+
* // Copy parameters from a codec context
|
|
22
|
+
* const ret = params.fromContext(codecContext);
|
|
23
|
+
* FFmpegError.throwIfError(ret, 'fromContext');
|
|
24
|
+
*
|
|
25
|
+
* // Set video parameters manually
|
|
26
|
+
* params.codecType = AVMEDIA_TYPE_VIDEO;
|
|
27
|
+
* params.codecId = AV_CODEC_ID_H264;
|
|
28
|
+
* params.width = 1920;
|
|
29
|
+
* params.height = 1080;
|
|
30
|
+
* params.format = AV_PIX_FMT_YUV420P;
|
|
31
|
+
*
|
|
32
|
+
* // Apply parameters to another codec context
|
|
33
|
+
* const ret2 = params.toContext(otherCodecContext);
|
|
34
|
+
* FFmpegError.throwIfError(ret2, 'toContext');
|
|
35
|
+
*
|
|
36
|
+
* // Copy to another parameters struct
|
|
37
|
+
* const params2 = new CodecParameters();
|
|
38
|
+
* params2.alloc();
|
|
39
|
+
* const copyRet = params.copy(params2);
|
|
40
|
+
* FFmpegError.throwIfError(copyRet, 'copy');
|
|
41
|
+
*
|
|
42
|
+
* // Clean up
|
|
43
|
+
* params.free();
|
|
44
|
+
* params2.free();
|
|
45
|
+
* ```
|
|
46
|
+
*/
|
|
47
|
+
export class CodecParameters {
|
|
48
|
+
native;
|
|
49
|
+
/**
|
|
50
|
+
* Create new codec parameters.
|
|
51
|
+
*
|
|
52
|
+
* The parameters are uninitialized - you must call alloc() before use.
|
|
53
|
+
* No FFmpeg resources are allocated until alloc() is called.
|
|
54
|
+
*
|
|
55
|
+
* Direct wrapper around AVCodecParameters.
|
|
56
|
+
*
|
|
57
|
+
* @example
|
|
58
|
+
* ```typescript
|
|
59
|
+
* import { CodecParameters } from 'node-av';
|
|
60
|
+
*
|
|
61
|
+
* const params = new CodecParameters();
|
|
62
|
+
* params.alloc();
|
|
63
|
+
* // Parameters are now ready for use
|
|
64
|
+
* ```
|
|
65
|
+
*/
|
|
66
|
+
constructor() {
|
|
67
|
+
this.native = new bindings.CodecParameters();
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* General type of the encoded data.
|
|
71
|
+
*
|
|
72
|
+
* Identifies the media type (video, audio, subtitle, etc.).
|
|
73
|
+
*
|
|
74
|
+
* Direct mapping to AVCodecParameters->codec_type
|
|
75
|
+
*/
|
|
76
|
+
get codecType() {
|
|
77
|
+
return this.native.codecType;
|
|
78
|
+
}
|
|
79
|
+
set codecType(value) {
|
|
80
|
+
this.native.codecType = value;
|
|
81
|
+
}
|
|
82
|
+
/**
|
|
83
|
+
* Specific type of the encoded data.
|
|
84
|
+
*
|
|
85
|
+
* Identifies the exact codec (H.264, AAC, etc.).
|
|
86
|
+
*
|
|
87
|
+
* Direct mapping to AVCodecParameters->codec_id
|
|
88
|
+
*/
|
|
89
|
+
get codecId() {
|
|
90
|
+
return this.native.codecId;
|
|
91
|
+
}
|
|
92
|
+
set codecId(value) {
|
|
93
|
+
this.native.codecId = value;
|
|
94
|
+
}
|
|
95
|
+
/**
|
|
96
|
+
* Codec tag.
|
|
97
|
+
*
|
|
98
|
+
* Direct mapping to AVCodecParameters->codec_tag
|
|
99
|
+
* Additional information about the codec (corresponds to the AVI FOURCC).
|
|
100
|
+
*/
|
|
101
|
+
get codecTag() {
|
|
102
|
+
return this.native.codecTag;
|
|
103
|
+
}
|
|
104
|
+
set codecTag(value) {
|
|
105
|
+
this.native.codecTag = value;
|
|
106
|
+
}
|
|
107
|
+
/**
|
|
108
|
+
* Extra binary data needed for initializing the decoder.
|
|
109
|
+
*
|
|
110
|
+
* Direct mapping to AVCodecParameters->extradata
|
|
111
|
+
* The allocated memory should be AV_INPUT_BUFFER_PADDING_SIZE bytes larger
|
|
112
|
+
* than extradata_size to avoid problems if it is read with the bitstream reader.
|
|
113
|
+
* The bytewise contents of extradata must not depend on the architecture or CPU endianness.
|
|
114
|
+
* Must be allocated with the av_malloc() family of functions.
|
|
115
|
+
*/
|
|
116
|
+
get extradata() {
|
|
117
|
+
return this.native.extradata;
|
|
118
|
+
}
|
|
119
|
+
set extradata(value) {
|
|
120
|
+
this.native.extradata = value;
|
|
121
|
+
}
|
|
122
|
+
/**
|
|
123
|
+
* Size of the extradata content in bytes.
|
|
124
|
+
*
|
|
125
|
+
* Direct mapping to AVCodecParameters->extradata_size
|
|
126
|
+
*/
|
|
127
|
+
get extradataSize() {
|
|
128
|
+
return this.native.extradataSize;
|
|
129
|
+
}
|
|
130
|
+
/**
|
|
131
|
+
* Format of the encoded data.
|
|
132
|
+
* - video: the pixel format (AVPixelFormat)
|
|
133
|
+
* - audio: the sample format (AVSampleFormat)
|
|
134
|
+
*/
|
|
135
|
+
get format() {
|
|
136
|
+
return this.native.format;
|
|
137
|
+
}
|
|
138
|
+
set format(value) {
|
|
139
|
+
this.native.format = value;
|
|
140
|
+
}
|
|
141
|
+
/**
|
|
142
|
+
* The average bitrate of the encoded data (in bits per second).
|
|
143
|
+
*/
|
|
144
|
+
get bitRate() {
|
|
145
|
+
return this.native.bitRate;
|
|
146
|
+
}
|
|
147
|
+
set bitRate(value) {
|
|
148
|
+
this.native.bitRate = value;
|
|
149
|
+
}
|
|
150
|
+
/**
|
|
151
|
+
* Codec-specific bitstream restrictions that the stream conforms to.
|
|
152
|
+
* FF_PROFILE_H264_BASELINE, FF_PROFILE_H264_MAIN, etc.
|
|
153
|
+
*/
|
|
154
|
+
get profile() {
|
|
155
|
+
return this.native.profile;
|
|
156
|
+
}
|
|
157
|
+
set profile(value) {
|
|
158
|
+
this.native.profile = value;
|
|
159
|
+
}
|
|
160
|
+
/**
|
|
161
|
+
* Level of the bitstream.
|
|
162
|
+
* FF_LEVEL_UNKNOWN or codec-specific values.
|
|
163
|
+
*/
|
|
164
|
+
get level() {
|
|
165
|
+
return this.native.level;
|
|
166
|
+
}
|
|
167
|
+
set level(value) {
|
|
168
|
+
this.native.level = value;
|
|
169
|
+
}
|
|
170
|
+
/**
|
|
171
|
+
* Video frame width in pixels.
|
|
172
|
+
*
|
|
173
|
+
* Direct mapping to AVCodecParameters->width
|
|
174
|
+
*/
|
|
175
|
+
get width() {
|
|
176
|
+
return this.native.width;
|
|
177
|
+
}
|
|
178
|
+
set width(value) {
|
|
179
|
+
this.native.width = value;
|
|
180
|
+
}
|
|
181
|
+
/**
|
|
182
|
+
* Video frame height in pixels.
|
|
183
|
+
*
|
|
184
|
+
* Direct mapping to AVCodecParameters->height
|
|
185
|
+
*/
|
|
186
|
+
get height() {
|
|
187
|
+
return this.native.height;
|
|
188
|
+
}
|
|
189
|
+
set height(value) {
|
|
190
|
+
this.native.height = value;
|
|
191
|
+
}
|
|
192
|
+
/**
|
|
193
|
+
* The pixel aspect ratio (width / height) which a single pixel should have when displayed.
|
|
194
|
+
*
|
|
195
|
+
* When the aspect ratio is unknown / undefined, the numerator should be set to 0
|
|
196
|
+
* (the denominator may have any value).
|
|
197
|
+
*/
|
|
198
|
+
get sampleAspectRatio() {
|
|
199
|
+
const sar = this.native.sampleAspectRatio;
|
|
200
|
+
return new Rational(sar.num, sar.den);
|
|
201
|
+
}
|
|
202
|
+
set sampleAspectRatio(value) {
|
|
203
|
+
this.native.sampleAspectRatio = { num: value.num, den: value.den };
|
|
204
|
+
}
|
|
205
|
+
/**
|
|
206
|
+
* Video only. The framerate of the video.
|
|
207
|
+
* This is the fundamental unit of time (in seconds) in terms
|
|
208
|
+
* of which frame timestamps are represented.
|
|
209
|
+
*/
|
|
210
|
+
get frameRate() {
|
|
211
|
+
const fr = this.native.frameRate;
|
|
212
|
+
return new Rational(fr.num, fr.den);
|
|
213
|
+
}
|
|
214
|
+
set frameRate(value) {
|
|
215
|
+
this.native.frameRate = { num: value.num, den: value.den };
|
|
216
|
+
}
|
|
217
|
+
/**
|
|
218
|
+
* Video only. Additional colorspace characteristics.
|
|
219
|
+
* AVCOL_RANGE_MPEG, AVCOL_RANGE_JPEG, etc.
|
|
220
|
+
*/
|
|
221
|
+
get colorRange() {
|
|
222
|
+
return this.native.colorRange;
|
|
223
|
+
}
|
|
224
|
+
set colorRange(value) {
|
|
225
|
+
this.native.colorRange = value;
|
|
226
|
+
}
|
|
227
|
+
/**
|
|
228
|
+
* Chromaticity coordinates of the source primaries.
|
|
229
|
+
* AVCOL_PRI_BT709, AVCOL_PRI_BT2020, etc.
|
|
230
|
+
*/
|
|
231
|
+
get colorPrimaries() {
|
|
232
|
+
return this.native.colorPrimaries;
|
|
233
|
+
}
|
|
234
|
+
set colorPrimaries(value) {
|
|
235
|
+
this.native.colorPrimaries = value;
|
|
236
|
+
}
|
|
237
|
+
/**
|
|
238
|
+
* Color Transfer Characteristic.
|
|
239
|
+
* AVCOL_TRC_BT709, AVCOL_TRC_SMPTE2084, etc.
|
|
240
|
+
*/
|
|
241
|
+
get colorTrc() {
|
|
242
|
+
return this.native.colorTrc;
|
|
243
|
+
}
|
|
244
|
+
set colorTrc(value) {
|
|
245
|
+
this.native.colorTrc = value;
|
|
246
|
+
}
|
|
247
|
+
/**
|
|
248
|
+
* YUV colorspace type.
|
|
249
|
+
* AVCOL_SPC_BT709, AVCOL_SPC_BT2020_NCL, etc.
|
|
250
|
+
*/
|
|
251
|
+
get colorSpace() {
|
|
252
|
+
return this.native.colorSpace;
|
|
253
|
+
}
|
|
254
|
+
set colorSpace(value) {
|
|
255
|
+
this.native.colorSpace = value;
|
|
256
|
+
}
|
|
257
|
+
/**
|
|
258
|
+
* Location of chroma samples.
|
|
259
|
+
* AVCHROMA_LOC_LEFT, AVCHROMA_LOC_CENTER, etc.
|
|
260
|
+
*/
|
|
261
|
+
get chromaLocation() {
|
|
262
|
+
return this.native.chromaLocation;
|
|
263
|
+
}
|
|
264
|
+
set chromaLocation(value) {
|
|
265
|
+
this.native.chromaLocation = value;
|
|
266
|
+
}
|
|
267
|
+
/**
|
|
268
|
+
* Audio channel layout.
|
|
269
|
+
* @deprecated use ch_layout
|
|
270
|
+
*/
|
|
271
|
+
get channelLayout() {
|
|
272
|
+
return this.native.channelLayout;
|
|
273
|
+
}
|
|
274
|
+
set channelLayout(value) {
|
|
275
|
+
this.native.channelLayout = value;
|
|
276
|
+
}
|
|
277
|
+
/**
|
|
278
|
+
* Audio only. The number of audio channels.
|
|
279
|
+
* @deprecated use ch_layout.nb_channels
|
|
280
|
+
*/
|
|
281
|
+
get channels() {
|
|
282
|
+
return this.native.channels;
|
|
283
|
+
}
|
|
284
|
+
set channels(value) {
|
|
285
|
+
this.native.channels = value;
|
|
286
|
+
}
|
|
287
|
+
/**
|
|
288
|
+
* Audio sample rate.
|
|
289
|
+
*
|
|
290
|
+
* Direct mapping to AVCodecParameters->sample_rate
|
|
291
|
+
* The number of audio samples per second.
|
|
292
|
+
*/
|
|
293
|
+
get sampleRate() {
|
|
294
|
+
return this.native.sampleRate;
|
|
295
|
+
}
|
|
296
|
+
set sampleRate(value) {
|
|
297
|
+
this.native.sampleRate = value;
|
|
298
|
+
}
|
|
299
|
+
/**
|
|
300
|
+
* Allocate a new AVCodecParameters and set its fields to default values.
|
|
301
|
+
*
|
|
302
|
+
* Allocates the parameters structure and initializes with defaults.
|
|
303
|
+
* Must be called before using the parameters.
|
|
304
|
+
*
|
|
305
|
+
* Direct mapping to avcodec_parameters_alloc()
|
|
306
|
+
*
|
|
307
|
+
* @throws {Error} Memory allocation failure (ENOMEM)
|
|
308
|
+
*
|
|
309
|
+
* @example
|
|
310
|
+
* ```typescript
|
|
311
|
+
* import { CodecParameters } from 'node-av';
|
|
312
|
+
*
|
|
313
|
+
* const params = new CodecParameters();
|
|
314
|
+
* params.alloc();
|
|
315
|
+
* // Parameters are now allocated with default values
|
|
316
|
+
* ```
|
|
317
|
+
*
|
|
318
|
+
* @see {@link free} To free the parameters
|
|
319
|
+
*/
|
|
320
|
+
alloc() {
|
|
321
|
+
this.native.alloc();
|
|
322
|
+
}
|
|
323
|
+
/**
|
|
324
|
+
* Free the codec parameters and everything associated with it.
|
|
325
|
+
*
|
|
326
|
+
* Releases all resources associated with the parameters.
|
|
327
|
+
* The parameters become invalid after this call.
|
|
328
|
+
*
|
|
329
|
+
* Direct mapping to avcodec_parameters_free()
|
|
330
|
+
*
|
|
331
|
+
* @example
|
|
332
|
+
* ```typescript
|
|
333
|
+
* params.free();
|
|
334
|
+
* // params is now invalid and should not be used
|
|
335
|
+
* ```
|
|
336
|
+
*/
|
|
337
|
+
free() {
|
|
338
|
+
this.native.free();
|
|
339
|
+
}
|
|
340
|
+
/**
|
|
341
|
+
* Copy the contents of this CodecParameters to dst.
|
|
342
|
+
*
|
|
343
|
+
* Copies all parameter values to the destination.
|
|
344
|
+
* Any allocated fields in dst are freed and replaced with newly allocated duplicates.
|
|
345
|
+
*
|
|
346
|
+
* Direct mapping to avcodec_parameters_copy()
|
|
347
|
+
*
|
|
348
|
+
* @param dst - Destination CodecParameters. Must be allocated.
|
|
349
|
+
*
|
|
350
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
351
|
+
* - 0: Success
|
|
352
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
353
|
+
*
|
|
354
|
+
* @example
|
|
355
|
+
* ```typescript
|
|
356
|
+
* import { CodecParameters, FFmpegError } from 'node-av';
|
|
357
|
+
*
|
|
358
|
+
* const src = new CodecParameters();
|
|
359
|
+
* src.alloc();
|
|
360
|
+
* // ... set up src parameters ...
|
|
361
|
+
*
|
|
362
|
+
* const dst = new CodecParameters();
|
|
363
|
+
* dst.alloc();
|
|
364
|
+
* const ret = src.copy(dst);
|
|
365
|
+
* FFmpegError.throwIfError(ret, 'copy');
|
|
366
|
+
* ```
|
|
367
|
+
*
|
|
368
|
+
* @see {@link fromContext} To copy from codec context
|
|
369
|
+
* @see {@link toContext} To copy to codec context
|
|
370
|
+
*/
|
|
371
|
+
copy(dst) {
|
|
372
|
+
return this.native.copy(dst.getNative());
|
|
373
|
+
}
|
|
374
|
+
/**
|
|
375
|
+
* Fill this parameters struct based on the values from the supplied codec context.
|
|
376
|
+
*
|
|
377
|
+
* Copies codec parameters from a codec context to this parameters struct.
|
|
378
|
+
* Any allocated fields are freed and replaced with duplicates.
|
|
379
|
+
*
|
|
380
|
+
* Direct mapping to avcodec_parameters_from_context()
|
|
381
|
+
*
|
|
382
|
+
* @param codecContext - Source CodecContext to copy from
|
|
383
|
+
*
|
|
384
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
385
|
+
* - 0: Success
|
|
386
|
+
* - AVERROR(EINVAL): Invalid codec context
|
|
387
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
388
|
+
*
|
|
389
|
+
* @example
|
|
390
|
+
* ```typescript
|
|
391
|
+
* import { FFmpegError } from 'node-av';
|
|
392
|
+
*
|
|
393
|
+
* // Copy encoder parameters to stream
|
|
394
|
+
* const ret = outputStream.codecpar.fromContext(encoderContext);
|
|
395
|
+
* FFmpegError.throwIfError(ret, 'fromContext');
|
|
396
|
+
* ```
|
|
397
|
+
*
|
|
398
|
+
* @see {@link toContext} To copy in the opposite direction
|
|
399
|
+
*/
|
|
400
|
+
fromContext(codecContext) {
|
|
401
|
+
return this.native.fromContext(codecContext.getNative());
|
|
402
|
+
}
|
|
403
|
+
/**
|
|
404
|
+
* Fill the codec context based on the values from this codec parameters.
|
|
405
|
+
*
|
|
406
|
+
* Copies parameters from this struct to a codec context.
|
|
407
|
+
* Any allocated fields in the codec context are freed and replaced with duplicates.
|
|
408
|
+
*
|
|
409
|
+
* Direct mapping to avcodec_parameters_to_context()
|
|
410
|
+
*
|
|
411
|
+
* @param codecContext - Destination CodecContext to copy to
|
|
412
|
+
*
|
|
413
|
+
* @returns 0 on success, negative AVERROR on error:
|
|
414
|
+
* - 0: Success
|
|
415
|
+
* - AVERROR(EINVAL): Invalid codec context
|
|
416
|
+
* - AVERROR(ENOMEM): Memory allocation failure
|
|
417
|
+
*
|
|
418
|
+
* @example
|
|
419
|
+
* ```typescript
|
|
420
|
+
* import { FFmpegError } from 'node-av';
|
|
421
|
+
*
|
|
422
|
+
* // Copy stream parameters to decoder
|
|
423
|
+
* const ret = inputStream.codecpar.toContext(decoderContext);
|
|
424
|
+
* FFmpegError.throwIfError(ret, 'toContext');
|
|
425
|
+
* ```
|
|
426
|
+
*
|
|
427
|
+
* @see {@link fromContext} To copy in the opposite direction
|
|
428
|
+
*/
|
|
429
|
+
toContext(codecContext) {
|
|
430
|
+
return this.native.toContext(codecContext.getNative());
|
|
431
|
+
}
|
|
432
|
+
/**
|
|
433
|
+
* Get the native FFmpeg AVCodecParameters pointer.
|
|
434
|
+
*
|
|
435
|
+
* @internal For use by other wrapper classes
|
|
436
|
+
* @returns The underlying native codec parameters object
|
|
437
|
+
*/
|
|
438
|
+
getNative() {
|
|
439
|
+
return this.native;
|
|
440
|
+
}
|
|
441
|
+
/**
|
|
442
|
+
* Dispose of the codec parameters.
|
|
443
|
+
*
|
|
444
|
+
* Implements the Disposable interface for automatic cleanup.
|
|
445
|
+
* Equivalent to calling free().
|
|
446
|
+
*
|
|
447
|
+
* @example
|
|
448
|
+
* ```typescript
|
|
449
|
+
* {
|
|
450
|
+
* using params = new CodecParameters();
|
|
451
|
+
* params.alloc();
|
|
452
|
+
* // ... use parameters
|
|
453
|
+
* } // Automatically freed when leaving scope
|
|
454
|
+
* ```
|
|
455
|
+
*/
|
|
456
|
+
[Symbol.dispose]() {
|
|
457
|
+
this.native[Symbol.dispose]();
|
|
458
|
+
}
|
|
459
|
+
}
|
|
460
|
+
//# sourceMappingURL=codec-parameters.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"codec-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,SAAS,EAAE,CAAC,CAAC;IAC3C,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,WAAW,CAAC,YAA0B;QACpC,OAAO,IAAI,CAAC,MAAM,CAAC,WAAW,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;IAC3D,CAAC;IAED;;;;;;;;;;;;;;;;;;;;;;;;;OAyBG;IACH,SAAS,CAAC,YAA0B;QAClC,OAAO,IAAI,CAAC,MAAM,CAAC,SAAS,CAAC,YAAY,CAAC,SAAS,EAAE,CAAC,CAAC;IACzD,CAAC;IAED;;;;;OAKG;IACH,SAAS;QACP,OAAO,IAAI,CAAC,MAAM,CAAC;IACrB,CAAC;IAED;;;;;;;;;;;;;;OAcG;IACH,CAAC,MAAM,CAAC,OAAO,CAAC;QACd,IAAI,CAAC,MAAM,CAAC,MAAM,CAAC,OAAO,CAAC,EAAE,CAAC;IAChC,CAAC;CACF"}
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import type { CodecContext } from './codec-context.js';
|
|
2
|
+
import type { AVCodecID } from './constants.js';
|
|
3
|
+
import type { NativeCodecParser, NativeWrapper } from './native-types.js';
|
|
4
|
+
import type { Packet } from './packet.js';
|
|
5
|
+
/**
|
|
6
|
+
* Codec parser for splitting elementary streams into frames.
|
|
7
|
+
*
|
|
8
|
+
* Parsers split raw byte streams (currently only video) into coded frames.
|
|
9
|
+
* Many decoders require that coded video frames are preceded by a start code,
|
|
10
|
+
* and this parser splits the stream at these boundaries. Parsers are essential
|
|
11
|
+
* for handling raw elementary streams from sources like network streams or
|
|
12
|
+
* raw video files without container format.
|
|
13
|
+
*
|
|
14
|
+
* Direct wrapper around AVCodecParserContext.
|
|
15
|
+
*
|
|
16
|
+
* @example
|
|
17
|
+
* ```typescript
|
|
18
|
+
* import { CodecParser, CodecContext, Packet, FFmpegError } from 'node-av';
|
|
19
|
+
* import { AV_CODEC_ID_H264, AV_NOPTS_VALUE } from 'node-av/constants';
|
|
20
|
+
*
|
|
21
|
+
* const parser = new CodecParser();
|
|
22
|
+
* parser.init(AV_CODEC_ID_H264);
|
|
23
|
+
*
|
|
24
|
+
* // Parse raw H.264 stream
|
|
25
|
+
* const packet = new Packet();
|
|
26
|
+
* packet.alloc();
|
|
27
|
+
*
|
|
28
|
+
* const bytesConsumed = parser.parse2(
|
|
29
|
+
* codecContext,
|
|
30
|
+
* packet,
|
|
31
|
+
* inputBuffer,
|
|
32
|
+
* AV_NOPTS_VALUE,
|
|
33
|
+
* AV_NOPTS_VALUE,
|
|
34
|
+
* 0
|
|
35
|
+
* );
|
|
36
|
+
*
|
|
37
|
+
* if (packet.size > 0) {
|
|
38
|
+
* // We have a complete frame in packet
|
|
39
|
+
* const ret = await codecContext.sendPacket(packet);
|
|
40
|
+
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
41
|
+
* }
|
|
42
|
+
*
|
|
43
|
+
* parser.close();
|
|
44
|
+
* ```
|
|
45
|
+
*
|
|
46
|
+
* @see {@link CodecContext} For decoding parsed packets
|
|
47
|
+
* @see {@link Packet} For storing parsed frame data
|
|
48
|
+
*/
|
|
49
|
+
export declare class CodecParser implements NativeWrapper<NativeCodecParser> {
|
|
50
|
+
private native;
|
|
51
|
+
/**
|
|
52
|
+
* Create a new CodecParser instance.
|
|
53
|
+
*
|
|
54
|
+
* The parser is uninitialized - you must call init() before use.
|
|
55
|
+
* No FFmpeg resources are allocated until init() is called.
|
|
56
|
+
*
|
|
57
|
+
* Direct wrapper around AVCodecParserContext allocation.
|
|
58
|
+
*
|
|
59
|
+
* @example
|
|
60
|
+
* ```typescript
|
|
61
|
+
* import { CodecParser } from 'node-av';
|
|
62
|
+
* import { AV_CODEC_ID_MPEG1VIDEO } from 'node-av/constants';
|
|
63
|
+
*
|
|
64
|
+
* const parser = new CodecParser();
|
|
65
|
+
* parser.init(AV_CODEC_ID_MPEG1VIDEO);
|
|
66
|
+
* // parser is now ready for use
|
|
67
|
+
* ```
|
|
68
|
+
*/
|
|
69
|
+
constructor();
|
|
70
|
+
/**
|
|
71
|
+
* Initialize the parser with a specific codec ID.
|
|
72
|
+
*
|
|
73
|
+
* Allocates and initializes the AVCodecParserContext for the specified codec.
|
|
74
|
+
* Must be called before parse2() can be used.
|
|
75
|
+
*
|
|
76
|
+
* Direct mapping to av_parser_init()
|
|
77
|
+
*
|
|
78
|
+
* @param codecId - AVCodecID of the codec to parse
|
|
79
|
+
*
|
|
80
|
+
* @throws {Error} Parser for codec ID not found
|
|
81
|
+
*
|
|
82
|
+
* @example
|
|
83
|
+
* ```typescript
|
|
84
|
+
* import { CodecParser } from 'node-av';
|
|
85
|
+
* import { AV_CODEC_ID_H264, AV_CODEC_ID_HEVC } from 'node-av/constants';
|
|
86
|
+
*
|
|
87
|
+
* const parser = new CodecParser();
|
|
88
|
+
*
|
|
89
|
+
* // Initialize for H.264
|
|
90
|
+
* parser.init(AV_CODEC_ID_H264);
|
|
91
|
+
* // Parser is now ready to parse H.264 streams
|
|
92
|
+
*
|
|
93
|
+
* // For HEVC/H.265
|
|
94
|
+
* const hevcParser = new CodecParser();
|
|
95
|
+
* hevcParser.init(AV_CODEC_ID_HEVC);
|
|
96
|
+
* ```
|
|
97
|
+
*
|
|
98
|
+
* @see {@link parse2} For parsing data after initialization
|
|
99
|
+
*/
|
|
100
|
+
init(codecId: AVCodecID): void;
|
|
101
|
+
/**
|
|
102
|
+
* Parse a buffer and extract packets from elementary stream.
|
|
103
|
+
*
|
|
104
|
+
* Parses the input buffer and extracts complete coded frames. The parser
|
|
105
|
+
* maintains internal state to handle partial frames across multiple calls.
|
|
106
|
+
* The parser may combine multiple frames into one packet or split one frame
|
|
107
|
+
* into multiple packets, depending on the codec and stream format.
|
|
108
|
+
*
|
|
109
|
+
* Direct mapping to av_parser_parse2()
|
|
110
|
+
*
|
|
111
|
+
* @param codecContext - Codec context (used for stream parameters)
|
|
112
|
+
* @param packet - Packet to fill with parsed data
|
|
113
|
+
* @param data - Input buffer containing elementary stream data
|
|
114
|
+
* @param pts - Presentation timestamp of the first byte in data
|
|
115
|
+
* @param dts - Decoding timestamp of the first byte in data
|
|
116
|
+
* @param pos - Byte position of the first byte in data in the stream
|
|
117
|
+
*
|
|
118
|
+
* @returns Number of bytes consumed from the input buffer:
|
|
119
|
+
* - >0: Number of bytes consumed from input
|
|
120
|
+
* - 0: More data needed to complete a frame
|
|
121
|
+
*
|
|
122
|
+
* @example
|
|
123
|
+
* ```typescript
|
|
124
|
+
* import { CodecParser, CodecContext, Packet, FFmpegError } from 'node-av';
|
|
125
|
+
* import { AV_NOPTS_VALUE } from 'node-av/constants';
|
|
126
|
+
* import * as fs from 'fs';
|
|
127
|
+
*
|
|
128
|
+
* const inbuf = Buffer.alloc(4096);
|
|
129
|
+
* const bytesRead = fs.readSync(fd, inbuf, 0, 4096, null);
|
|
130
|
+
*
|
|
131
|
+
* let offset = 0;
|
|
132
|
+
* while (offset < bytesRead) {
|
|
133
|
+
* const consumed = parser.parse2(
|
|
134
|
+
* codecContext,
|
|
135
|
+
* packet,
|
|
136
|
+
* inbuf.subarray(offset),
|
|
137
|
+
* AV_NOPTS_VALUE,
|
|
138
|
+
* AV_NOPTS_VALUE,
|
|
139
|
+
* 0
|
|
140
|
+
* );
|
|
141
|
+
*
|
|
142
|
+
* offset += consumed;
|
|
143
|
+
*
|
|
144
|
+
* if (packet.size > 0) {
|
|
145
|
+
* // Complete packet ready for decoding
|
|
146
|
+
* const ret = await codecContext.sendPacket(packet);
|
|
147
|
+
* FFmpegError.throwIfError(ret, 'sendPacket');
|
|
148
|
+
* }
|
|
149
|
+
* }
|
|
150
|
+
* ```
|
|
151
|
+
*
|
|
152
|
+
* @see {@link init} Must be called before parse2
|
|
153
|
+
* @see {@link close} Should be called when done parsing
|
|
154
|
+
*/
|
|
155
|
+
parse2(codecContext: CodecContext, packet: Packet, data: Buffer, pts: bigint, dts: bigint, pos: number): number;
|
|
156
|
+
/**
|
|
157
|
+
* Close the parser and free all resources.
|
|
158
|
+
*
|
|
159
|
+
* Releases all resources associated with the parser context.
|
|
160
|
+
* After calling close(), the parser instance should not be used anymore.
|
|
161
|
+
*
|
|
162
|
+
* Direct mapping to av_parser_close()
|
|
163
|
+
*
|
|
164
|
+
* @example
|
|
165
|
+
* ```typescript
|
|
166
|
+
* import { CodecParser } from 'node-av';
|
|
167
|
+
*
|
|
168
|
+
* const parser = new CodecParser();
|
|
169
|
+
* // ... use parser ...
|
|
170
|
+
*
|
|
171
|
+
* parser.close();
|
|
172
|
+
* // Parser resources are now freed
|
|
173
|
+
* // Do not use parser after this point
|
|
174
|
+
* ```
|
|
175
|
+
*/
|
|
176
|
+
close(): void;
|
|
177
|
+
/**
|
|
178
|
+
* @internal
|
|
179
|
+
* Get the underlying native codec parser object.
|
|
180
|
+
* This method is for internal use by other FFmpeg classes.
|
|
181
|
+
*
|
|
182
|
+
* @returns The underlying native codec parser object
|
|
183
|
+
*/
|
|
184
|
+
getNative(): NativeCodecParser;
|
|
185
|
+
}
|