@lumen5/beamcoder 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/.circleci/config.yml +41 -0
- package/.circleci/images/testbeam10-4.1/Dockerfile +12 -0
- package/.circleci/test_image/Dockerfile +14 -0
- package/.circleci/test_image/build.md +13 -0
- package/.eslintrc.js +27 -0
- package/.github/workflows/publish-npm.yml +33 -0
- package/LICENSE +674 -0
- package/README.md +1221 -0
- package/beamstreams.js +692 -0
- package/binding.gyp +103 -0
- package/examples/encode_h264.js +92 -0
- package/examples/jpeg_app.js +55 -0
- package/examples/jpeg_filter_app.js +101 -0
- package/examples/make_mp4.js +123 -0
- package/images/beamcoder_small.jpg +0 -0
- package/index.d.ts +83 -0
- package/index.js +44 -0
- package/install_ffmpeg.js +240 -0
- package/package.json +45 -0
- package/scratch/decode_aac.js +38 -0
- package/scratch/decode_avci.js +50 -0
- package/scratch/decode_hevc.js +38 -0
- package/scratch/decode_pcm.js +39 -0
- package/scratch/make_a_mux.js +68 -0
- package/scratch/muxer.js +74 -0
- package/scratch/read_wav.js +35 -0
- package/scratch/simple_mux.js +39 -0
- package/scratch/stream_avci.js +127 -0
- package/scratch/stream_mp4.js +78 -0
- package/scratch/stream_mux.js +47 -0
- package/scratch/stream_pcm.js +82 -0
- package/scratch/stream_wav.js +62 -0
- package/scripts/install_beamcoder_dependencies.sh +25 -0
- package/src/adaptor.h +202 -0
- package/src/beamcoder.cc +937 -0
- package/src/beamcoder_util.cc +1129 -0
- package/src/beamcoder_util.h +206 -0
- package/src/codec.cc +7386 -0
- package/src/codec.h +44 -0
- package/src/codec_par.cc +1818 -0
- package/src/codec_par.h +40 -0
- package/src/decode.cc +569 -0
- package/src/decode.h +75 -0
- package/src/demux.cc +584 -0
- package/src/demux.h +88 -0
- package/src/encode.cc +496 -0
- package/src/encode.h +72 -0
- package/src/filter.cc +1888 -0
- package/src/filter.h +30 -0
- package/src/format.cc +5287 -0
- package/src/format.h +77 -0
- package/src/frame.cc +2681 -0
- package/src/frame.h +52 -0
- package/src/governor.cc +286 -0
- package/src/governor.h +30 -0
- package/src/hwcontext.cc +378 -0
- package/src/hwcontext.h +35 -0
- package/src/log.cc +186 -0
- package/src/log.h +20 -0
- package/src/mux.cc +834 -0
- package/src/mux.h +106 -0
- package/src/packet.cc +762 -0
- package/src/packet.h +49 -0
- package/test/codecParamsSpec.js +148 -0
- package/test/decoderSpec.js +56 -0
- package/test/demuxerSpec.js +41 -0
- package/test/encoderSpec.js +69 -0
- package/test/filtererSpec.js +47 -0
- package/test/formatSpec.js +343 -0
- package/test/frameSpec.js +145 -0
- package/test/introspectionSpec.js +73 -0
- package/test/muxerSpec.js +34 -0
- package/test/packetSpec.js +122 -0
- package/types/Beamstreams.d.ts +98 -0
- package/types/Codec.d.ts +123 -0
- package/types/CodecContext.d.ts +555 -0
- package/types/CodecPar.d.ts +108 -0
- package/types/Decoder.d.ts +137 -0
- package/types/Demuxer.d.ts +113 -0
- package/types/Encoder.d.ts +94 -0
- package/types/Filter.d.ts +324 -0
- package/types/FormatContext.d.ts +380 -0
- package/types/Frame.d.ts +295 -0
- package/types/HWContext.d.ts +62 -0
- package/types/Muxer.d.ts +121 -0
- package/types/Packet.d.ts +82 -0
- package/types/PrivClass.d.ts +25 -0
- package/types/Stream.d.ts +165 -0
package/src/beamcoder.cc
ADDED
|
@@ -0,0 +1,937 @@
|
|
|
1
|
+
/*
|
|
2
|
+
Aerostat Beam Coder - Node.js native bindings for FFmpeg.
|
|
3
|
+
Copyright (C) 2019 Streampunk Media Ltd.
|
|
4
|
+
|
|
5
|
+
This program is free software: you can redistribute it and/or modify
|
|
6
|
+
it under the terms of the GNU General Public License as published by
|
|
7
|
+
the Free Software Foundation, either version 3 of the License, or
|
|
8
|
+
(at your option) any later version.
|
|
9
|
+
|
|
10
|
+
This program is distributed in the hope that it will be useful,
|
|
11
|
+
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
12
|
+
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
13
|
+
GNU General Public License for more details.
|
|
14
|
+
|
|
15
|
+
You should have received a copy of the GNU General Public License
|
|
16
|
+
along with this program. If not, see <https://www.gnu.org/licenses/>.
|
|
17
|
+
|
|
18
|
+
https://www.streampunk.media/ mailto:furnace@streampunk.media
|
|
19
|
+
14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
|
|
20
|
+
*/
|
|
21
|
+
|
|
22
|
+
#include "node_api.h"
|
|
23
|
+
#include "beamcoder_util.h"
|
|
24
|
+
#include "log.h"
|
|
25
|
+
#include "governor.h"
|
|
26
|
+
#include "format.h"
|
|
27
|
+
#include "demux.h"
|
|
28
|
+
#include "decode.h"
|
|
29
|
+
#include "filter.h"
|
|
30
|
+
#include "encode.h"
|
|
31
|
+
#include "mux.h"
|
|
32
|
+
#include "packet.h"
|
|
33
|
+
#include "codec_par.h"
|
|
34
|
+
#include <stdio.h>
|
|
35
|
+
|
|
36
|
+
extern "C" {
|
|
37
|
+
#include <libavcodec/avcodec.h>
|
|
38
|
+
#include <libavdevice/avdevice.h>
|
|
39
|
+
#include <libavfilter/avfilter.h>
|
|
40
|
+
#include <libavformat/avformat.h>
|
|
41
|
+
#include <libavutil/avutil.h>
|
|
42
|
+
#include <libavutil/pixdesc.h>
|
|
43
|
+
#include <libpostproc/postprocess.h>
|
|
44
|
+
#include <libswresample/swresample.h>
|
|
45
|
+
#include <libswscale/swscale.h>
|
|
46
|
+
#include <libavcodec/bsf.h>
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
napi_value versions(napi_env env, napi_callback_info info) {
|
|
50
|
+
napi_status status;
|
|
51
|
+
napi_value result, value;
|
|
52
|
+
|
|
53
|
+
status = napi_create_object(env, &result);
|
|
54
|
+
CHECK_STATUS;
|
|
55
|
+
|
|
56
|
+
status = napi_create_uint32(env, avcodec_version(), &value);
|
|
57
|
+
CHECK_STATUS;
|
|
58
|
+
status = napi_set_named_property(env, result, "avcodec", value);
|
|
59
|
+
CHECK_STATUS;
|
|
60
|
+
status = napi_create_uint32(env, avdevice_version(), &value);
|
|
61
|
+
CHECK_STATUS;
|
|
62
|
+
status = napi_set_named_property(env, result, "avdevice", value);
|
|
63
|
+
CHECK_STATUS;
|
|
64
|
+
status = napi_create_uint32(env, avfilter_version(), &value);
|
|
65
|
+
CHECK_STATUS;
|
|
66
|
+
status = napi_set_named_property(env, result, "avfilter", value);
|
|
67
|
+
CHECK_STATUS;
|
|
68
|
+
status = napi_create_uint32(env, avformat_version(), &value);
|
|
69
|
+
CHECK_STATUS;
|
|
70
|
+
status = napi_set_named_property(env, result, "avformat", value);
|
|
71
|
+
CHECK_STATUS;
|
|
72
|
+
status = napi_create_uint32(env, avutil_version(), &value);
|
|
73
|
+
CHECK_STATUS;
|
|
74
|
+
status = napi_set_named_property(env, result, "avutil", value);
|
|
75
|
+
CHECK_STATUS;
|
|
76
|
+
status = napi_create_uint32(env, postproc_version(), &value);
|
|
77
|
+
CHECK_STATUS;
|
|
78
|
+
status = napi_set_named_property(env, result, "postproc", value);
|
|
79
|
+
CHECK_STATUS;
|
|
80
|
+
status = napi_create_uint32(env, swresample_version(), &value);
|
|
81
|
+
CHECK_STATUS;
|
|
82
|
+
status = napi_set_named_property(env, result, "swresample", value);
|
|
83
|
+
CHECK_STATUS;
|
|
84
|
+
status = napi_create_uint32(env, swscale_version(), &value);
|
|
85
|
+
CHECK_STATUS;
|
|
86
|
+
status = napi_set_named_property(env, result, "swscale", value);
|
|
87
|
+
CHECK_STATUS;
|
|
88
|
+
|
|
89
|
+
return result;
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
napi_value avVersionInfo(napi_env env, napi_callback_info info) {
|
|
93
|
+
napi_status status;
|
|
94
|
+
napi_value result;
|
|
95
|
+
|
|
96
|
+
const char* verInfo = av_version_info();
|
|
97
|
+
|
|
98
|
+
status = napi_create_string_utf8(env, verInfo, NAPI_AUTO_LENGTH, &result);
|
|
99
|
+
CHECK_STATUS;
|
|
100
|
+
|
|
101
|
+
return result;
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
napi_value versionStrings(napi_env env, napi_callback_info info) {
|
|
105
|
+
napi_status status;
|
|
106
|
+
napi_value result, value;
|
|
107
|
+
char vstr[16];
|
|
108
|
+
|
|
109
|
+
status = napi_create_object(env, &result);
|
|
110
|
+
CHECK_STATUS;
|
|
111
|
+
|
|
112
|
+
sprintf(vstr, "%i.%i.%i", LIBAVCODEC_VERSION_MAJOR, LIBAVCODEC_VERSION_MINOR,
|
|
113
|
+
LIBAVCODEC_VERSION_MICRO);
|
|
114
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
115
|
+
CHECK_STATUS;
|
|
116
|
+
status = napi_set_named_property(env, result, "avcodec", value);
|
|
117
|
+
CHECK_STATUS;
|
|
118
|
+
|
|
119
|
+
sprintf(vstr, "%i.%i.%i", LIBAVDEVICE_VERSION_MAJOR, LIBAVDEVICE_VERSION_MINOR,
|
|
120
|
+
LIBAVDEVICE_VERSION_MICRO);
|
|
121
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
122
|
+
CHECK_STATUS;
|
|
123
|
+
status = napi_set_named_property(env, result, "avdevice", value);
|
|
124
|
+
CHECK_STATUS;
|
|
125
|
+
|
|
126
|
+
sprintf(vstr, "%i.%i.%i", LIBAVFILTER_VERSION_MAJOR, LIBAVFILTER_VERSION_MINOR,
|
|
127
|
+
LIBAVFILTER_VERSION_MICRO);
|
|
128
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
129
|
+
CHECK_STATUS;
|
|
130
|
+
status = napi_set_named_property(env, result, "avfilter", value);
|
|
131
|
+
CHECK_STATUS;
|
|
132
|
+
|
|
133
|
+
sprintf(vstr, "%i.%i.%i", LIBAVFORMAT_VERSION_MAJOR, LIBAVFORMAT_VERSION_MINOR,
|
|
134
|
+
LIBAVFORMAT_VERSION_MICRO);
|
|
135
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
136
|
+
CHECK_STATUS;
|
|
137
|
+
status = napi_set_named_property(env, result, "avformat", value);
|
|
138
|
+
CHECK_STATUS;
|
|
139
|
+
|
|
140
|
+
sprintf(vstr, "%i.%i.%i", LIBAVUTIL_VERSION_MAJOR, LIBAVUTIL_VERSION_MINOR,
|
|
141
|
+
LIBAVUTIL_VERSION_MICRO);
|
|
142
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
143
|
+
CHECK_STATUS;
|
|
144
|
+
status = napi_set_named_property(env, result, "avutil", value);
|
|
145
|
+
CHECK_STATUS;
|
|
146
|
+
|
|
147
|
+
sprintf(vstr, "%i.%i.%i", LIBPOSTPROC_VERSION_MAJOR, LIBPOSTPROC_VERSION_MINOR,
|
|
148
|
+
LIBPOSTPROC_VERSION_MICRO);
|
|
149
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
150
|
+
CHECK_STATUS;
|
|
151
|
+
status = napi_set_named_property(env, result, "postproc", value);
|
|
152
|
+
CHECK_STATUS;
|
|
153
|
+
|
|
154
|
+
sprintf(vstr, "%i.%i.%i", LIBSWRESAMPLE_VERSION_MAJOR, LIBSWRESAMPLE_VERSION_MINOR,
|
|
155
|
+
LIBSWRESAMPLE_VERSION_MICRO);
|
|
156
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
157
|
+
CHECK_STATUS;
|
|
158
|
+
status = napi_set_named_property(env, result, "swresample", value);
|
|
159
|
+
CHECK_STATUS;
|
|
160
|
+
|
|
161
|
+
sprintf(vstr, "%i.%i.%i", LIBSWSCALE_VERSION_MAJOR, LIBSWSCALE_VERSION_MINOR,
|
|
162
|
+
LIBSWSCALE_VERSION_MICRO);
|
|
163
|
+
status = napi_create_string_utf8(env, vstr, NAPI_AUTO_LENGTH, &value);
|
|
164
|
+
CHECK_STATUS;
|
|
165
|
+
status = napi_set_named_property(env, result, "swscale", value);
|
|
166
|
+
CHECK_STATUS;
|
|
167
|
+
|
|
168
|
+
return result;
|
|
169
|
+
}
|
|
170
|
+
|
|
171
|
+
napi_value configurations(napi_env env, napi_callback_info info) {
|
|
172
|
+
napi_status status;
|
|
173
|
+
napi_value result, value;
|
|
174
|
+
|
|
175
|
+
status = napi_create_object(env, &result);
|
|
176
|
+
CHECK_STATUS;
|
|
177
|
+
|
|
178
|
+
status = napi_create_string_utf8(env, avcodec_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
179
|
+
CHECK_STATUS;
|
|
180
|
+
status = napi_set_named_property(env, result, "avcodec", value);
|
|
181
|
+
CHECK_STATUS;
|
|
182
|
+
status = napi_create_string_utf8(env, avdevice_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
183
|
+
CHECK_STATUS;
|
|
184
|
+
status = napi_set_named_property(env, result, "avdevice", value);
|
|
185
|
+
CHECK_STATUS;
|
|
186
|
+
status = napi_create_string_utf8(env, avfilter_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
187
|
+
CHECK_STATUS;
|
|
188
|
+
status = napi_set_named_property(env, result, "avfilter", value);
|
|
189
|
+
CHECK_STATUS;
|
|
190
|
+
status = napi_create_string_utf8(env, avformat_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
191
|
+
CHECK_STATUS;
|
|
192
|
+
status = napi_set_named_property(env, result, "avformat", value);
|
|
193
|
+
CHECK_STATUS;
|
|
194
|
+
status = napi_create_string_utf8(env, avutil_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
195
|
+
CHECK_STATUS;
|
|
196
|
+
status = napi_set_named_property(env, result, "avutil", value);
|
|
197
|
+
CHECK_STATUS;
|
|
198
|
+
status = napi_create_string_utf8(env, postproc_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
199
|
+
CHECK_STATUS;
|
|
200
|
+
status = napi_set_named_property(env, result, "postproc", value);
|
|
201
|
+
CHECK_STATUS;
|
|
202
|
+
status = napi_create_string_utf8(env, swresample_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
203
|
+
CHECK_STATUS;
|
|
204
|
+
status = napi_set_named_property(env, result, "swresample", value);
|
|
205
|
+
CHECK_STATUS;
|
|
206
|
+
status = napi_create_string_utf8(env, swscale_configuration(), NAPI_AUTO_LENGTH, &value);
|
|
207
|
+
CHECK_STATUS;
|
|
208
|
+
status = napi_set_named_property(env, result, "swscale", value);
|
|
209
|
+
CHECK_STATUS;
|
|
210
|
+
|
|
211
|
+
return result;
|
|
212
|
+
}
|
|
213
|
+
|
|
214
|
+
napi_value licenses(napi_env env, napi_callback_info info) {
|
|
215
|
+
napi_status status;
|
|
216
|
+
napi_value result, value;
|
|
217
|
+
|
|
218
|
+
status = napi_create_object(env, &result);
|
|
219
|
+
CHECK_STATUS;
|
|
220
|
+
|
|
221
|
+
status = napi_create_string_utf8(env, avcodec_license(), NAPI_AUTO_LENGTH, &value);
|
|
222
|
+
CHECK_STATUS;
|
|
223
|
+
status = napi_set_named_property(env, result, "avcodec", value);
|
|
224
|
+
CHECK_STATUS;
|
|
225
|
+
status = napi_create_string_utf8(env, avdevice_license(), NAPI_AUTO_LENGTH, &value);
|
|
226
|
+
CHECK_STATUS;
|
|
227
|
+
status = napi_set_named_property(env, result, "avdevice", value);
|
|
228
|
+
CHECK_STATUS;
|
|
229
|
+
status = napi_create_string_utf8(env, avfilter_license(), NAPI_AUTO_LENGTH, &value);
|
|
230
|
+
CHECK_STATUS;
|
|
231
|
+
status = napi_set_named_property(env, result, "avfilter", value);
|
|
232
|
+
CHECK_STATUS;
|
|
233
|
+
status = napi_create_string_utf8(env, avformat_license(), NAPI_AUTO_LENGTH, &value);
|
|
234
|
+
CHECK_STATUS;
|
|
235
|
+
status = napi_set_named_property(env, result, "avformat", value);
|
|
236
|
+
CHECK_STATUS;
|
|
237
|
+
status = napi_create_string_utf8(env, avutil_license(), NAPI_AUTO_LENGTH, &value);
|
|
238
|
+
CHECK_STATUS;
|
|
239
|
+
status = napi_set_named_property(env, result, "avutil", value);
|
|
240
|
+
CHECK_STATUS;
|
|
241
|
+
status = napi_create_string_utf8(env, postproc_license(), NAPI_AUTO_LENGTH, &value);
|
|
242
|
+
CHECK_STATUS;
|
|
243
|
+
status = napi_set_named_property(env, result, "postproc", value);
|
|
244
|
+
CHECK_STATUS;
|
|
245
|
+
status = napi_create_string_utf8(env, swresample_license(), NAPI_AUTO_LENGTH, &value);
|
|
246
|
+
CHECK_STATUS;
|
|
247
|
+
status = napi_set_named_property(env, result, "swresample", value);
|
|
248
|
+
CHECK_STATUS;
|
|
249
|
+
status = napi_create_string_utf8(env, swscale_license(), NAPI_AUTO_LENGTH, &value);
|
|
250
|
+
CHECK_STATUS;
|
|
251
|
+
status = napi_set_named_property(env, result, "swscale", value);
|
|
252
|
+
CHECK_STATUS;
|
|
253
|
+
|
|
254
|
+
return result;
|
|
255
|
+
}
|
|
256
|
+
|
|
257
|
+
napi_status fromAVCodec(napi_env env, const AVCodec* codec, napi_value *result) {
|
|
258
|
+
napi_status status;
|
|
259
|
+
napi_value array, element, subel, value, props, nullval;
|
|
260
|
+
const AVProfile* profile;
|
|
261
|
+
const AVRational* framerate;
|
|
262
|
+
const enum AVPixelFormat* pixfmt;
|
|
263
|
+
const int* samplerate;
|
|
264
|
+
const AVCodecDescriptor* codecDesc;
|
|
265
|
+
const enum AVSampleFormat* samplefmt;
|
|
266
|
+
const uint64_t* chanlay;
|
|
267
|
+
int32_t index = 0;
|
|
268
|
+
|
|
269
|
+
status = napi_get_null(env, &nullval);
|
|
270
|
+
PASS_STATUS;
|
|
271
|
+
|
|
272
|
+
status = napi_create_object(env, &value);
|
|
273
|
+
PASS_STATUS;
|
|
274
|
+
status = beam_set_string_utf8(env, value, "type", "Codec");
|
|
275
|
+
PASS_STATUS;
|
|
276
|
+
status = beam_set_string_utf8(env, value, "name", (char*) codec->name);
|
|
277
|
+
PASS_STATUS;
|
|
278
|
+
status = beam_set_string_utf8(env, value, "long_name", (char*) codec->long_name);
|
|
279
|
+
PASS_STATUS;
|
|
280
|
+
status = beam_set_string_utf8(env, value, "codec_type",
|
|
281
|
+
(char*) av_get_media_type_string(codec->type));
|
|
282
|
+
PASS_STATUS;
|
|
283
|
+
status = beam_set_int32(env, value, "id", (int32_t) codec->id);
|
|
284
|
+
PASS_STATUS;
|
|
285
|
+
status = beam_set_bool(env, value, "decoder", av_codec_is_decoder(codec));
|
|
286
|
+
PASS_STATUS;
|
|
287
|
+
status = beam_set_bool(env, value, "encoder", av_codec_is_encoder(codec));
|
|
288
|
+
PASS_STATUS;
|
|
289
|
+
|
|
290
|
+
status = napi_create_object(env, &props);
|
|
291
|
+
PASS_STATUS;
|
|
292
|
+
status = beam_set_bool(env, props, "DRAW_HORIZ_BAND", codec->capabilities & AV_CODEC_CAP_DRAW_HORIZ_BAND);
|
|
293
|
+
PASS_STATUS;
|
|
294
|
+
status = beam_set_bool(env, props, "DR1", codec->capabilities & AV_CODEC_CAP_DR1);
|
|
295
|
+
PASS_STATUS;
|
|
296
|
+
status = beam_set_bool(env, props, "TRUNCATED", codec->capabilities & AV_CODEC_CAP_TRUNCATED);
|
|
297
|
+
PASS_STATUS;
|
|
298
|
+
status = beam_set_bool(env, props, "DELAY", codec->capabilities & AV_CODEC_CAP_DELAY);
|
|
299
|
+
PASS_STATUS;
|
|
300
|
+
status = beam_set_bool(env, props, "SMALL_LAST_FRAME", codec->capabilities & AV_CODEC_CAP_SMALL_LAST_FRAME);
|
|
301
|
+
PASS_STATUS;
|
|
302
|
+
status = beam_set_bool(env, props, "SUBFRAMES", codec->capabilities & AV_CODEC_CAP_SUBFRAMES);
|
|
303
|
+
PASS_STATUS;
|
|
304
|
+
status = beam_set_bool(env, props, "EXPERIMENTAL", codec->capabilities & AV_CODEC_CAP_EXPERIMENTAL);
|
|
305
|
+
PASS_STATUS;
|
|
306
|
+
status = beam_set_bool(env, props, "CHANNEL_CONF", codec->capabilities & AV_CODEC_CAP_CHANNEL_CONF);
|
|
307
|
+
PASS_STATUS;
|
|
308
|
+
status = beam_set_bool(env, props, "FRAME_THREADS", codec->capabilities & AV_CODEC_CAP_FRAME_THREADS);
|
|
309
|
+
PASS_STATUS;
|
|
310
|
+
status = beam_set_bool(env, props, "SLICE_THREADS", codec->capabilities & AV_CODEC_CAP_SLICE_THREADS);
|
|
311
|
+
PASS_STATUS;
|
|
312
|
+
status = beam_set_bool(env, props, "PARAM_CHANGE", codec->capabilities & AV_CODEC_CAP_PARAM_CHANGE);
|
|
313
|
+
PASS_STATUS;
|
|
314
|
+
status = beam_set_bool(env, props, "AUTO_THREADS", codec->capabilities & AV_CODEC_CAP_AUTO_THREADS);
|
|
315
|
+
PASS_STATUS;
|
|
316
|
+
status = beam_set_bool(env, props, "VARIABLE_FRAME_SIZE", codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE);
|
|
317
|
+
PASS_STATUS;
|
|
318
|
+
status = beam_set_bool(env, props, "AVOID_PROBING", codec->capabilities & AV_CODEC_CAP_AVOID_PROBING);
|
|
319
|
+
PASS_STATUS;
|
|
320
|
+
status = beam_set_bool(env, props, "INTRA_ONLY", codec->capabilities & AV_CODEC_CAP_INTRA_ONLY);
|
|
321
|
+
PASS_STATUS;
|
|
322
|
+
status = beam_set_bool(env, props, "LOSSLESS", codec->capabilities & AV_CODEC_CAP_LOSSLESS);
|
|
323
|
+
PASS_STATUS;
|
|
324
|
+
status = beam_set_bool(env, props, "HARDWARE", codec->capabilities & AV_CODEC_CAP_HARDWARE);
|
|
325
|
+
PASS_STATUS;
|
|
326
|
+
status = beam_set_bool(env, props, "HYBRID", codec->capabilities & AV_CODEC_CAP_HYBRID);
|
|
327
|
+
PASS_STATUS;
|
|
328
|
+
status = napi_set_named_property(env, value, "capabilities", props);
|
|
329
|
+
PASS_STATUS;
|
|
330
|
+
|
|
331
|
+
if (codec->supported_framerates != nullptr) {
|
|
332
|
+
status = napi_create_array(env, &array);
|
|
333
|
+
PASS_STATUS;
|
|
334
|
+
framerate = codec->supported_framerates;
|
|
335
|
+
index = 0;
|
|
336
|
+
while ((framerate->num != 0) && (framerate->den != 0)) {
|
|
337
|
+
status = napi_create_array(env, &element);
|
|
338
|
+
PASS_STATUS;
|
|
339
|
+
status = napi_create_int32(env, framerate->num, &subel);
|
|
340
|
+
PASS_STATUS;
|
|
341
|
+
status = napi_set_element(env, element, 0, subel);
|
|
342
|
+
PASS_STATUS;
|
|
343
|
+
status = napi_create_int32(env, framerate->den, &subel);
|
|
344
|
+
PASS_STATUS;
|
|
345
|
+
status = napi_set_element(env, element, 1, subel);
|
|
346
|
+
PASS_STATUS;
|
|
347
|
+
status = napi_set_element(env, array, index++, element);
|
|
348
|
+
PASS_STATUS;
|
|
349
|
+
framerate = framerate + 1;
|
|
350
|
+
}
|
|
351
|
+
status = napi_set_named_property(env, value, "supported_framerates", array);
|
|
352
|
+
PASS_STATUS;
|
|
353
|
+
} else {
|
|
354
|
+
status = napi_set_named_property(env, value, "supported_framerates", nullval);
|
|
355
|
+
PASS_STATUS;
|
|
356
|
+
}
|
|
357
|
+
|
|
358
|
+
if (codec->pix_fmts != nullptr) {
|
|
359
|
+
status = napi_create_array(env, &array);
|
|
360
|
+
PASS_STATUS;
|
|
361
|
+
pixfmt = codec->pix_fmts;
|
|
362
|
+
index = 0;
|
|
363
|
+
while (*pixfmt != -1) {
|
|
364
|
+
status = napi_create_string_utf8(env,
|
|
365
|
+
(char*) av_get_pix_fmt_name(*pixfmt), NAPI_AUTO_LENGTH, &element);
|
|
366
|
+
PASS_STATUS;
|
|
367
|
+
status = napi_set_element(env, array, index++, element);
|
|
368
|
+
PASS_STATUS;
|
|
369
|
+
pixfmt = pixfmt + 1;
|
|
370
|
+
}
|
|
371
|
+
status = napi_set_named_property(env, value, "pix_fmts", array);
|
|
372
|
+
PASS_STATUS;
|
|
373
|
+
} else {
|
|
374
|
+
status = napi_set_named_property(env, value, "pix_fmts", nullval);
|
|
375
|
+
PASS_STATUS;
|
|
376
|
+
}
|
|
377
|
+
|
|
378
|
+
if (codec->supported_samplerates != nullptr) {
|
|
379
|
+
status = napi_create_array(env, &array);
|
|
380
|
+
PASS_STATUS;
|
|
381
|
+
samplerate = codec->supported_samplerates;
|
|
382
|
+
index = 0;
|
|
383
|
+
while (*samplerate != 0) {
|
|
384
|
+
status = napi_create_int32(env, *samplerate, &element);
|
|
385
|
+
PASS_STATUS;
|
|
386
|
+
status = napi_set_element(env, array, index++, element);
|
|
387
|
+
PASS_STATUS;
|
|
388
|
+
samplerate = samplerate + 1;
|
|
389
|
+
}
|
|
390
|
+
status = napi_set_named_property(env, value, "supported_samplerates", array);
|
|
391
|
+
PASS_STATUS;
|
|
392
|
+
} else {
|
|
393
|
+
status = napi_set_named_property(env, value, "supported_samplerates", nullval);
|
|
394
|
+
PASS_STATUS;
|
|
395
|
+
}
|
|
396
|
+
|
|
397
|
+
if (codec->sample_fmts) {
|
|
398
|
+
status = napi_create_array(env, &array);
|
|
399
|
+
PASS_STATUS;
|
|
400
|
+
samplefmt = codec->sample_fmts;
|
|
401
|
+
index = 0;
|
|
402
|
+
while (*samplefmt != -1) {
|
|
403
|
+
status = napi_create_string_utf8(env,
|
|
404
|
+
(char*) av_get_sample_fmt_name(*samplefmt), NAPI_AUTO_LENGTH, &element);
|
|
405
|
+
PASS_STATUS;
|
|
406
|
+
status = napi_set_element(env, array, index++, element);
|
|
407
|
+
PASS_STATUS;
|
|
408
|
+
samplefmt = samplefmt + 1;
|
|
409
|
+
}
|
|
410
|
+
status = napi_set_named_property(env, value, "sample_fmts", array);
|
|
411
|
+
PASS_STATUS;
|
|
412
|
+
} else {
|
|
413
|
+
status = napi_set_named_property(env, value, "sample_fmts", nullval);
|
|
414
|
+
PASS_STATUS;
|
|
415
|
+
}
|
|
416
|
+
|
|
417
|
+
if (codec->channel_layouts != nullptr) {
|
|
418
|
+
status = napi_create_array(env, &array);
|
|
419
|
+
PASS_STATUS;
|
|
420
|
+
chanlay = codec->channel_layouts;
|
|
421
|
+
index = 0;
|
|
422
|
+
while (*chanlay != 0) {
|
|
423
|
+
char chanLayStr[64];
|
|
424
|
+
av_get_channel_layout_string(chanLayStr, 64, 0, *chanlay);
|
|
425
|
+
status = napi_create_string_utf8(env, chanLayStr, NAPI_AUTO_LENGTH, &element);
|
|
426
|
+
PASS_STATUS;
|
|
427
|
+
status = napi_set_element(env, array, index++, element);
|
|
428
|
+
PASS_STATUS;
|
|
429
|
+
chanlay = chanlay + 1;
|
|
430
|
+
}
|
|
431
|
+
status = napi_set_named_property(env, value, "channel_layouts", array);
|
|
432
|
+
PASS_STATUS;
|
|
433
|
+
} else {
|
|
434
|
+
status = napi_set_named_property(env, value, "channel_layouts", nullval);
|
|
435
|
+
PASS_STATUS;
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
status = beam_set_uint32(env, value, "max_lowres", codec->max_lowres);
|
|
439
|
+
PASS_STATUS;
|
|
440
|
+
|
|
441
|
+
if (codec->priv_class != nullptr) {
|
|
442
|
+
status = fromAVClass(env, codec->priv_class, &element);
|
|
443
|
+
PASS_STATUS;
|
|
444
|
+
status = napi_set_named_property(env, value, "priv_class", element);
|
|
445
|
+
PASS_STATUS;
|
|
446
|
+
} else {
|
|
447
|
+
status = napi_set_named_property(env, value, "priv_class", nullval);
|
|
448
|
+
PASS_STATUS;
|
|
449
|
+
}
|
|
450
|
+
|
|
451
|
+
if (codec->profiles != nullptr) {
|
|
452
|
+
status = napi_create_array(env, &array);
|
|
453
|
+
PASS_STATUS;
|
|
454
|
+
profile = codec->profiles;
|
|
455
|
+
index = 0;
|
|
456
|
+
// printf("Profiles for %s %s\n", codec->name, profile->name);
|
|
457
|
+
while (profile->profile != FF_PROFILE_UNKNOWN) {
|
|
458
|
+
status = napi_create_string_utf8(env, profile->name, NAPI_AUTO_LENGTH, &element);
|
|
459
|
+
PASS_STATUS;
|
|
460
|
+
status = napi_set_element(env, array, index++, element);
|
|
461
|
+
PASS_STATUS;
|
|
462
|
+
profile = profile + 1;
|
|
463
|
+
}
|
|
464
|
+
status = napi_set_named_property(env, value, "profiles", array);
|
|
465
|
+
PASS_STATUS;
|
|
466
|
+
} else {
|
|
467
|
+
status = napi_set_named_property(env, value, "profiles", nullval);
|
|
468
|
+
PASS_STATUS;
|
|
469
|
+
}
|
|
470
|
+
|
|
471
|
+
if (codec->wrapper_name != nullptr) {
|
|
472
|
+
status = beam_set_string_utf8(env, value, "wrapper_name", (char*) codec->wrapper_name);
|
|
473
|
+
PASS_STATUS;
|
|
474
|
+
}
|
|
475
|
+
|
|
476
|
+
codecDesc = avcodec_descriptor_get(codec->id);
|
|
477
|
+
if (codecDesc != nullptr) {
|
|
478
|
+
status = fromAVCodecDescriptor(env, codecDesc, &element);
|
|
479
|
+
PASS_STATUS;
|
|
480
|
+
status = napi_set_named_property(env, value, "descriptor", element);
|
|
481
|
+
PASS_STATUS;
|
|
482
|
+
}
|
|
483
|
+
|
|
484
|
+
*result = value;
|
|
485
|
+
return napi_ok;
|
|
486
|
+
}
|
|
487
|
+
|
|
488
|
+
napi_value codecs(napi_env env, napi_callback_info info) {
|
|
489
|
+
napi_status status;
|
|
490
|
+
napi_value result, value, decEnc;
|
|
491
|
+
bool hasProp;
|
|
492
|
+
void* opaque = nullptr;
|
|
493
|
+
const AVCodec* codec;
|
|
494
|
+
|
|
495
|
+
status = napi_create_object(env, &result);
|
|
496
|
+
CHECK_STATUS;
|
|
497
|
+
codec = av_codec_iterate(&opaque);
|
|
498
|
+
while (codec != nullptr) {
|
|
499
|
+
status = fromAVCodec(env, codec, &value);
|
|
500
|
+
CHECK_STATUS;
|
|
501
|
+
status = napi_has_named_property(env, result, codec->name, &hasProp);
|
|
502
|
+
CHECK_STATUS;
|
|
503
|
+
if (hasProp) {
|
|
504
|
+
status = napi_get_named_property(env, result, codec->name, &decEnc);
|
|
505
|
+
CHECK_STATUS;
|
|
506
|
+
} else {
|
|
507
|
+
status = napi_create_object(env, &decEnc);
|
|
508
|
+
CHECK_STATUS;
|
|
509
|
+
status = napi_set_named_property(env, result, codec->name, decEnc);
|
|
510
|
+
CHECK_STATUS;
|
|
511
|
+
}
|
|
512
|
+
status = napi_set_named_property(env, decEnc,
|
|
513
|
+
av_codec_is_decoder(codec) ? "decoder" : "encoder", value);
|
|
514
|
+
CHECK_STATUS;
|
|
515
|
+
|
|
516
|
+
codec = av_codec_iterate(&opaque);
|
|
517
|
+
}
|
|
518
|
+
|
|
519
|
+
return result;
|
|
520
|
+
}
|
|
521
|
+
|
|
522
|
+
napi_value decoders(napi_env env, napi_callback_info info) {
|
|
523
|
+
napi_status status;
|
|
524
|
+
napi_value result, value;
|
|
525
|
+
void* opaque = nullptr;
|
|
526
|
+
const AVCodec* codec;
|
|
527
|
+
|
|
528
|
+
status = napi_create_object(env, &result);
|
|
529
|
+
CHECK_STATUS;
|
|
530
|
+
codec = av_codec_iterate(&opaque);
|
|
531
|
+
while (codec != nullptr) {
|
|
532
|
+
if (av_codec_is_decoder(codec)) {
|
|
533
|
+
status = fromAVCodec(env, codec, &value);
|
|
534
|
+
CHECK_STATUS;
|
|
535
|
+
status = napi_set_named_property(env, result, codec->name, value);
|
|
536
|
+
CHECK_STATUS;
|
|
537
|
+
}
|
|
538
|
+
|
|
539
|
+
codec = av_codec_iterate(&opaque);
|
|
540
|
+
}
|
|
541
|
+
|
|
542
|
+
return result;
|
|
543
|
+
}
|
|
544
|
+
|
|
545
|
+
napi_value encoders(napi_env env, napi_callback_info info) {
|
|
546
|
+
napi_status status;
|
|
547
|
+
napi_value result, value;
|
|
548
|
+
void* opaque = nullptr;
|
|
549
|
+
const AVCodec* codec;
|
|
550
|
+
|
|
551
|
+
status = napi_create_object(env, &result);
|
|
552
|
+
CHECK_STATUS;
|
|
553
|
+
codec = av_codec_iterate(&opaque);
|
|
554
|
+
while (codec != nullptr) {
|
|
555
|
+
if (av_codec_is_encoder(codec)) {
|
|
556
|
+
status = fromAVCodec(env, codec, &value);
|
|
557
|
+
CHECK_STATUS;
|
|
558
|
+
status = napi_set_named_property(env, result, codec->name, value);
|
|
559
|
+
CHECK_STATUS;
|
|
560
|
+
}
|
|
561
|
+
|
|
562
|
+
codec = av_codec_iterate(&opaque);
|
|
563
|
+
}
|
|
564
|
+
|
|
565
|
+
return result;
|
|
566
|
+
}
|
|
567
|
+
|
|
568
|
+
napi_value pix_fmts(napi_env env, napi_callback_info info) {
|
|
569
|
+
napi_status status;
|
|
570
|
+
napi_value result, pixfmt, flags, comps, comp;
|
|
571
|
+
const AVPixFmtDescriptor* desc = nullptr;
|
|
572
|
+
|
|
573
|
+
status = napi_create_object(env, &result);
|
|
574
|
+
CHECK_STATUS;
|
|
575
|
+
while ((desc = av_pix_fmt_desc_next(desc))) {
|
|
576
|
+
status = napi_create_object(env, &pixfmt);
|
|
577
|
+
CHECK_STATUS;
|
|
578
|
+
status = beam_set_string_utf8(env, pixfmt, "name", (char*) desc->name);
|
|
579
|
+
CHECK_STATUS;
|
|
580
|
+
status = beam_set_int32(env, pixfmt, "nb_components", desc->nb_components);
|
|
581
|
+
CHECK_STATUS;
|
|
582
|
+
status = beam_set_uint32(env, pixfmt, "log2_chroma_h", desc->log2_chroma_h);
|
|
583
|
+
CHECK_STATUS;
|
|
584
|
+
status = beam_set_uint32(env, pixfmt, "log2_chroma_w", desc->log2_chroma_w);
|
|
585
|
+
CHECK_STATUS;
|
|
586
|
+
status = napi_create_object(env, &flags);
|
|
587
|
+
CHECK_STATUS;
|
|
588
|
+
status = beam_set_bool(env, flags, "BE", desc->flags & AV_PIX_FMT_FLAG_BE);
|
|
589
|
+
CHECK_STATUS;
|
|
590
|
+
status = beam_set_bool(env, flags, "PAL", desc->flags & AV_PIX_FMT_FLAG_PAL);
|
|
591
|
+
CHECK_STATUS;
|
|
592
|
+
status = beam_set_bool(env, flags, "BITSTREAM", desc->flags & AV_PIX_FMT_FLAG_BITSTREAM);
|
|
593
|
+
CHECK_STATUS;
|
|
594
|
+
status = beam_set_bool(env, flags, "HWACCEL", desc->flags & AV_PIX_FMT_FLAG_HWACCEL);
|
|
595
|
+
CHECK_STATUS;
|
|
596
|
+
status = beam_set_bool(env, flags, "PLANAR", desc->flags & AV_PIX_FMT_FLAG_PLANAR);
|
|
597
|
+
CHECK_STATUS;
|
|
598
|
+
status = beam_set_bool(env, flags, "RGB", desc->flags & AV_PIX_FMT_FLAG_RGB);
|
|
599
|
+
CHECK_STATUS;
|
|
600
|
+
status = beam_set_bool(env, flags, "ALPHA", desc->flags & AV_PIX_FMT_FLAG_ALPHA);
|
|
601
|
+
CHECK_STATUS;
|
|
602
|
+
status = beam_set_bool(env, flags, "BAYER", desc->flags & AV_PIX_FMT_FLAG_BAYER);
|
|
603
|
+
CHECK_STATUS;
|
|
604
|
+
status = beam_set_bool(env, flags, "FLOAT", desc->flags & AV_PIX_FMT_FLAG_FLOAT);
|
|
605
|
+
CHECK_STATUS;
|
|
606
|
+
status = napi_set_named_property(env, pixfmt, "flags", flags);
|
|
607
|
+
CHECK_STATUS;
|
|
608
|
+
status = napi_create_array(env, &comps);
|
|
609
|
+
CHECK_STATUS;
|
|
610
|
+
for ( int x = 0 ; x < desc->nb_components ; x++ ) {
|
|
611
|
+
status = napi_create_object(env, &comp);
|
|
612
|
+
CHECK_STATUS;
|
|
613
|
+
char letter[] = { 'X', '\0' };
|
|
614
|
+
switch(x) {
|
|
615
|
+
case 0:
|
|
616
|
+
if (desc->nb_components < 3) { letter[0] = 'Y'; break; }
|
|
617
|
+
letter[0] = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 'R' : 'Y';
|
|
618
|
+
break;
|
|
619
|
+
case 1:
|
|
620
|
+
if (desc->nb_components < 3) { letter[0] = 'A'; break; }
|
|
621
|
+
letter[0] = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 'G' : 'U';
|
|
622
|
+
break;
|
|
623
|
+
case 2:
|
|
624
|
+
letter[0] = (desc->flags & AV_PIX_FMT_FLAG_RGB) ? 'B' : 'V';
|
|
625
|
+
break;
|
|
626
|
+
case 3:
|
|
627
|
+
letter[0] = 'A';
|
|
628
|
+
break;
|
|
629
|
+
default:
|
|
630
|
+
break;
|
|
631
|
+
}
|
|
632
|
+
status = beam_set_string_utf8(env, comp, "code", letter);
|
|
633
|
+
CHECK_STATUS;
|
|
634
|
+
|
|
635
|
+
status = beam_set_int32(env, comp, "plane", desc->comp[x].plane);
|
|
636
|
+
CHECK_STATUS;
|
|
637
|
+
status = beam_set_int32(env, comp, "step", desc->comp[x].step);
|
|
638
|
+
CHECK_STATUS;
|
|
639
|
+
status = beam_set_int32(env, comp, "offset", desc->comp[x].offset);
|
|
640
|
+
CHECK_STATUS;
|
|
641
|
+
status = beam_set_int32(env, comp, "shift", desc->comp[x].shift);
|
|
642
|
+
CHECK_STATUS;
|
|
643
|
+
status = beam_set_int32(env, comp, "depth", desc->comp[x].depth);
|
|
644
|
+
CHECK_STATUS;
|
|
645
|
+
|
|
646
|
+
status = napi_set_element(env, comps, x, comp);
|
|
647
|
+
CHECK_STATUS;
|
|
648
|
+
}
|
|
649
|
+
status = napi_set_named_property(env, pixfmt, "comp", comps);
|
|
650
|
+
CHECK_STATUS;
|
|
651
|
+
status = beam_set_string_utf8(env, pixfmt, "alias",
|
|
652
|
+
const_cast<char*>((desc->alias != nullptr) ? desc->alias : ""));
|
|
653
|
+
CHECK_STATUS;
|
|
654
|
+
status = napi_set_named_property(env, result, desc->name, pixfmt);
|
|
655
|
+
CHECK_STATUS;
|
|
656
|
+
}
|
|
657
|
+
|
|
658
|
+
return result;
|
|
659
|
+
}
|
|
660
|
+
|
|
661
|
+
napi_value protocols(napi_env env, napi_callback_info info) {
|
|
662
|
+
napi_status status;
|
|
663
|
+
napi_value result, inputs, outputs, element;
|
|
664
|
+
void* opaque = nullptr;
|
|
665
|
+
int pos = 0;
|
|
666
|
+
const char* protocol;
|
|
667
|
+
|
|
668
|
+
status = napi_create_object(env, &result);
|
|
669
|
+
CHECK_STATUS;
|
|
670
|
+
status = napi_create_array(env, &inputs);
|
|
671
|
+
CHECK_STATUS;
|
|
672
|
+
status = napi_create_array(env, &outputs);
|
|
673
|
+
CHECK_STATUS;
|
|
674
|
+
|
|
675
|
+
while ((protocol = avio_enum_protocols(&opaque, 0))) {
|
|
676
|
+
status = napi_create_string_utf8(env, (char*) protocol, NAPI_AUTO_LENGTH, &element);
|
|
677
|
+
CHECK_STATUS;
|
|
678
|
+
status = napi_set_element(env, inputs, pos++, element);
|
|
679
|
+
CHECK_STATUS;
|
|
680
|
+
}
|
|
681
|
+
|
|
682
|
+
opaque = nullptr;
|
|
683
|
+
pos = 0;
|
|
684
|
+
while ((protocol = avio_enum_protocols(&opaque, 1))) {
|
|
685
|
+
status = napi_create_string_utf8(env, (char*) protocol, NAPI_AUTO_LENGTH, &element);
|
|
686
|
+
CHECK_STATUS;
|
|
687
|
+
status = napi_set_element(env, outputs, pos++, element);
|
|
688
|
+
CHECK_STATUS;
|
|
689
|
+
}
|
|
690
|
+
|
|
691
|
+
status = napi_set_named_property(env, result, "inputs", inputs);
|
|
692
|
+
CHECK_STATUS;
|
|
693
|
+
status = napi_set_named_property(env, result, "outputs", outputs);
|
|
694
|
+
CHECK_STATUS;
|
|
695
|
+
|
|
696
|
+
return result;
|
|
697
|
+
}
|
|
698
|
+
|
|
699
|
+
napi_value filters(napi_env env, napi_callback_info info) {
|
|
700
|
+
napi_status status;
|
|
701
|
+
napi_value result, desc, flags, pads, pad;
|
|
702
|
+
void* opaque = nullptr;
|
|
703
|
+
const AVFilter* filter;
|
|
704
|
+
int padCount;
|
|
705
|
+
|
|
706
|
+
status = napi_create_object(env, &result);
|
|
707
|
+
CHECK_STATUS;
|
|
708
|
+
|
|
709
|
+
while ((filter = av_filter_iterate(&opaque))) {
|
|
710
|
+
status = napi_create_object(env, &desc);
|
|
711
|
+
CHECK_STATUS;
|
|
712
|
+
status = beam_set_string_utf8(env, desc, "name", (char*) filter->name);
|
|
713
|
+
CHECK_STATUS;
|
|
714
|
+
status = beam_set_string_utf8(env, desc, "description", (char*) filter->description);
|
|
715
|
+
CHECK_STATUS;
|
|
716
|
+
|
|
717
|
+
status = napi_create_array(env, &pads);
|
|
718
|
+
CHECK_STATUS;
|
|
719
|
+
padCount = avfilter_filter_pad_count(filter, false);
|
|
720
|
+
for ( int x = 0 ; x < padCount ; x++ ) {
|
|
721
|
+
status = napi_create_object(env, &pad);
|
|
722
|
+
CHECK_STATUS;
|
|
723
|
+
status = beam_set_string_utf8(env, pad, "name",
|
|
724
|
+
(char*) avfilter_pad_get_name(filter->inputs, x));
|
|
725
|
+
CHECK_STATUS;
|
|
726
|
+
status = beam_set_string_utf8(env, pad, "media_type",
|
|
727
|
+
(char*) av_get_media_type_string(avfilter_pad_get_type(filter->inputs, x)));
|
|
728
|
+
CHECK_STATUS;
|
|
729
|
+
status = napi_set_element(env, pads, x, pad);
|
|
730
|
+
CHECK_STATUS;
|
|
731
|
+
}
|
|
732
|
+
status = napi_set_named_property(env, desc, "inputs", pads);
|
|
733
|
+
CHECK_STATUS;
|
|
734
|
+
|
|
735
|
+
status = napi_create_array(env, &pads);
|
|
736
|
+
CHECK_STATUS;
|
|
737
|
+
padCount = avfilter_filter_pad_count(filter, true);
|
|
738
|
+
for ( int x = 0 ; x < padCount ; x++ ) {
|
|
739
|
+
status = napi_create_object(env, &pad);
|
|
740
|
+
CHECK_STATUS;
|
|
741
|
+
status = beam_set_string_utf8(env, pad, "name",
|
|
742
|
+
(char*) avfilter_pad_get_name(filter->outputs, x));
|
|
743
|
+
CHECK_STATUS;
|
|
744
|
+
status = beam_set_string_utf8(env, pad, "media_type",
|
|
745
|
+
(char*) av_get_media_type_string(avfilter_pad_get_type(filter->outputs, x)));
|
|
746
|
+
CHECK_STATUS;
|
|
747
|
+
status = napi_set_element(env, pads, x, pad);
|
|
748
|
+
CHECK_STATUS;
|
|
749
|
+
}
|
|
750
|
+
status = napi_set_named_property(env, desc, "outputs", pads);
|
|
751
|
+
CHECK_STATUS;
|
|
752
|
+
|
|
753
|
+
// TODO expand class details
|
|
754
|
+
if (filter->priv_class != nullptr) {
|
|
755
|
+
status = fromAVClass(env, filter->priv_class, &pad);
|
|
756
|
+
CHECK_STATUS;
|
|
757
|
+
} else {
|
|
758
|
+
status = napi_get_null(env, &pad);
|
|
759
|
+
CHECK_STATUS;
|
|
760
|
+
}
|
|
761
|
+
status = napi_set_named_property(env, desc, "priv_class", pad);
|
|
762
|
+
CHECK_STATUS;
|
|
763
|
+
|
|
764
|
+
status = napi_create_object(env, &flags);
|
|
765
|
+
CHECK_STATUS;
|
|
766
|
+
status = beam_set_bool(env, flags, "DYNAMIC_INPUTS",
|
|
767
|
+
filter->flags & AVFILTER_FLAG_DYNAMIC_INPUTS);
|
|
768
|
+
CHECK_STATUS;
|
|
769
|
+
status = beam_set_bool(env, flags, "DYNAMIC_OUTPUTS",
|
|
770
|
+
filter->flags & AVFILTER_FLAG_DYNAMIC_OUTPUTS);
|
|
771
|
+
CHECK_STATUS;
|
|
772
|
+
status = beam_set_bool(env, flags, "SLICE_THREADS",
|
|
773
|
+
filter->flags & AVFILTER_FLAG_SLICE_THREADS);
|
|
774
|
+
CHECK_STATUS;
|
|
775
|
+
status = beam_set_bool(env, flags, "SUPPORT_TIMELINE_GENERIC",
|
|
776
|
+
filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE_GENERIC);
|
|
777
|
+
CHECK_STATUS;
|
|
778
|
+
status = beam_set_bool(env, flags, "SUPPORT_TIMELINE_INTERNAL",
|
|
779
|
+
filter->flags & AVFILTER_FLAG_SUPPORT_TIMELINE_INTERNAL);
|
|
780
|
+
CHECK_STATUS;
|
|
781
|
+
status = napi_set_named_property(env, desc, "flags", flags);
|
|
782
|
+
CHECK_STATUS;
|
|
783
|
+
|
|
784
|
+
status = napi_set_named_property(env, result, filter->name, desc);
|
|
785
|
+
CHECK_STATUS;
|
|
786
|
+
}
|
|
787
|
+
|
|
788
|
+
return result;
|
|
789
|
+
}
|
|
790
|
+
|
|
791
|
+
napi_value bsfs(napi_env env, napi_callback_info info) {
|
|
792
|
+
napi_status status;
|
|
793
|
+
napi_value result, desc, codecs, codec;
|
|
794
|
+
void* opaque = nullptr;
|
|
795
|
+
const AVBitStreamFilter* bsf;
|
|
796
|
+
const AVCodecID* codecID;
|
|
797
|
+
int pos = 0;
|
|
798
|
+
|
|
799
|
+
status = napi_create_object(env, &result);
|
|
800
|
+
CHECK_STATUS;
|
|
801
|
+
|
|
802
|
+
while ((bsf = av_bsf_iterate(&opaque))) {
|
|
803
|
+
status = napi_create_object(env, &desc);
|
|
804
|
+
CHECK_STATUS;
|
|
805
|
+
status = beam_set_string_utf8(env, desc, "name", (char*) bsf->name);
|
|
806
|
+
CHECK_STATUS;
|
|
807
|
+
|
|
808
|
+
status = napi_create_array(env, &codecs);
|
|
809
|
+
CHECK_STATUS;
|
|
810
|
+
codecID = bsf->codec_ids;
|
|
811
|
+
if (codecID != nullptr) {
|
|
812
|
+
pos = 0;
|
|
813
|
+
while (*codecID != AV_CODEC_ID_NONE) {
|
|
814
|
+
status = napi_create_string_utf8(env,
|
|
815
|
+
(char*) avcodec_get_name(*codecID), NAPI_AUTO_LENGTH, &codec);
|
|
816
|
+
CHECK_STATUS;
|
|
817
|
+
status = napi_set_element(env, codecs, pos++, codec);
|
|
818
|
+
CHECK_STATUS;
|
|
819
|
+
codecID = codecID + 1;
|
|
820
|
+
}
|
|
821
|
+
}
|
|
822
|
+
status = napi_set_named_property(env, desc, "codec_ids", codecs);
|
|
823
|
+
CHECK_STATUS;
|
|
824
|
+
|
|
825
|
+
// TODO expand class details
|
|
826
|
+
if (bsf->priv_class != nullptr) {
|
|
827
|
+
status = fromAVClass(env, bsf->priv_class, &codec);
|
|
828
|
+
CHECK_STATUS;
|
|
829
|
+
} else {
|
|
830
|
+
status = napi_get_null(env, &codec);
|
|
831
|
+
CHECK_STATUS;
|
|
832
|
+
}
|
|
833
|
+
status = napi_set_named_property(env, desc, "priv_class", codec);
|
|
834
|
+
CHECK_STATUS;
|
|
835
|
+
|
|
836
|
+
status = napi_set_named_property(env, result, bsf->name, desc);
|
|
837
|
+
CHECK_STATUS;
|
|
838
|
+
}
|
|
839
|
+
|
|
840
|
+
return result;
|
|
841
|
+
}
|
|
842
|
+
|
|
843
|
+
napi_value sampleFormats(napi_env env, napi_callback_info info) {
|
|
844
|
+
napi_status status;
|
|
845
|
+
napi_value result, value;
|
|
846
|
+
int count = 0;
|
|
847
|
+
const char* name;
|
|
848
|
+
|
|
849
|
+
status = napi_create_object(env, &result);
|
|
850
|
+
CHECK_STATUS;
|
|
851
|
+
|
|
852
|
+
while ((name = av_get_sample_fmt_name((AVSampleFormat) count))) {
|
|
853
|
+
status = napi_create_object(env, &value);
|
|
854
|
+
CHECK_STATUS;
|
|
855
|
+
status = beam_set_string_utf8(env, value, "type", "SampleFormat");
|
|
856
|
+
CHECK_STATUS;
|
|
857
|
+
status = beam_set_string_utf8(env, value, "name", (char*) name);
|
|
858
|
+
CHECK_STATUS;
|
|
859
|
+
status = beam_set_string_utf8(env, value, "packed",
|
|
860
|
+
(char*) av_get_sample_fmt_name(av_get_packed_sample_fmt((AVSampleFormat) count)));
|
|
861
|
+
CHECK_STATUS;
|
|
862
|
+
status = beam_set_string_utf8(env, value, "planar",
|
|
863
|
+
(char*) av_get_sample_fmt_name(av_get_planar_sample_fmt((AVSampleFormat) count)));
|
|
864
|
+
CHECK_STATUS;
|
|
865
|
+
status = beam_set_int32(env, value, "bytes_per_sample",
|
|
866
|
+
av_get_bytes_per_sample((AVSampleFormat) count));
|
|
867
|
+
CHECK_STATUS;
|
|
868
|
+
status = beam_set_bool(env, value, "is_planar",
|
|
869
|
+
av_sample_fmt_is_planar((AVSampleFormat) count));
|
|
870
|
+
CHECK_STATUS;
|
|
871
|
+
status = napi_set_named_property(env, result, name, value);
|
|
872
|
+
CHECK_STATUS;
|
|
873
|
+
count++;
|
|
874
|
+
}
|
|
875
|
+
|
|
876
|
+
return result;
|
|
877
|
+
}
|
|
878
|
+
|
|
879
|
+
napi_value Init(napi_env env, napi_value exports) {
|
|
880
|
+
napi_status status;
|
|
881
|
+
napi_value padSize, noopts;
|
|
882
|
+
status = napi_create_int32(env, AV_INPUT_BUFFER_PADDING_SIZE, &padSize);
|
|
883
|
+
CHECK_STATUS;
|
|
884
|
+
status = napi_create_int64(env, AV_NOPTS_VALUE, &noopts);
|
|
885
|
+
CHECK_STATUS;
|
|
886
|
+
|
|
887
|
+
napi_property_descriptor desc[] = {
|
|
888
|
+
DECLARE_NAPI_METHOD("versions", versions),
|
|
889
|
+
DECLARE_NAPI_METHOD("avVersionInfo", avVersionInfo),
|
|
890
|
+
DECLARE_NAPI_METHOD("versionStrings", versionStrings),
|
|
891
|
+
DECLARE_NAPI_METHOD("configurations", configurations),
|
|
892
|
+
DECLARE_NAPI_METHOD("licenses", licenses),
|
|
893
|
+
DECLARE_NAPI_METHOD("logging", logging),
|
|
894
|
+
DECLARE_NAPI_METHOD("setLoggingCallback", setLoggingCallback),
|
|
895
|
+
DECLARE_NAPI_METHOD("governor", governor),
|
|
896
|
+
DECLARE_NAPI_METHOD("format", makeFormat),
|
|
897
|
+
DECLARE_NAPI_METHOD("decoder", decoder),
|
|
898
|
+
DECLARE_NAPI_METHOD("filterer", filterer), // 10
|
|
899
|
+
DECLARE_NAPI_METHOD("encoder", encoder),
|
|
900
|
+
DECLARE_NAPI_METHOD("codecs", codecs),
|
|
901
|
+
DECLARE_NAPI_METHOD("decoders", decoders),
|
|
902
|
+
DECLARE_NAPI_METHOD("encoders", encoders),
|
|
903
|
+
DECLARE_NAPI_METHOD("muxers", muxers),
|
|
904
|
+
DECLARE_NAPI_METHOD("demuxers", demuxers),
|
|
905
|
+
DECLARE_NAPI_METHOD("pix_fmts", pix_fmts),
|
|
906
|
+
DECLARE_NAPI_METHOD("sample_fmts", sampleFormats),
|
|
907
|
+
DECLARE_NAPI_METHOD("protocols", protocols),
|
|
908
|
+
DECLARE_NAPI_METHOD("filters", filters), // 20
|
|
909
|
+
DECLARE_NAPI_METHOD("bsfs", bsfs),
|
|
910
|
+
DECLARE_NAPI_METHOD("packet", makePacket),
|
|
911
|
+
DECLARE_NAPI_METHOD("frame", makeFrame),
|
|
912
|
+
DECLARE_NAPI_METHOD("codecParameters", makeCodecParameters),
|
|
913
|
+
DECLARE_NAPI_METHOD("demuxer", demuxer),
|
|
914
|
+
DECLARE_NAPI_METHOD("muxer", muxer),
|
|
915
|
+
DECLARE_NAPI_METHOD("guessFormat", guessFormat),
|
|
916
|
+
{ "AV_INPUT_BUFFER_PADDING_SIZE", nullptr, nullptr, nullptr, nullptr,
|
|
917
|
+
padSize, napi_enumerable, nullptr },
|
|
918
|
+
{ "AV_NOPTS_VALUE", nullptr, nullptr, nullptr, nullptr,
|
|
919
|
+
noopts, napi_enumerable, nullptr }
|
|
920
|
+
};
|
|
921
|
+
status = napi_define_properties(env, exports, 29, desc);
|
|
922
|
+
CHECK_STATUS;
|
|
923
|
+
|
|
924
|
+
avdevice_register_all();
|
|
925
|
+
avformat_network_init();
|
|
926
|
+
|
|
927
|
+
// Iterate over all codecs to makes sure they are registered
|
|
928
|
+
void* opaque = nullptr;
|
|
929
|
+
const AVCodec* codec;
|
|
930
|
+
do {
|
|
931
|
+
codec = av_codec_iterate(&opaque);
|
|
932
|
+
// printf("Registered '%s'\n", (codec != nullptr) ? codec->name : "(null)");
|
|
933
|
+
} while (codec != nullptr);
|
|
934
|
+
return exports;
|
|
935
|
+
}
|
|
936
|
+
|
|
937
|
+
NAPI_MODULE(beamcoder, Init)
|