bare-ffmpeg 1.0.0-28 → 1.0.0-29
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 +12 -0
- package/binding.cc +71 -35
- package/lib/codec-context.js +4 -1
- package/lib/constants.js +8 -0
- package/lib/format-context.js +14 -4
- package/lib/input-format.js +16 -2
- package/lib/output-format.js +16 -2
- package/lib/packet.js +5 -3
- package/lib/rational.js +4 -2
- package/package.json +1 -1
- package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
package/README.md
CHANGED
|
@@ -266,6 +266,12 @@ Parameters:
|
|
|
266
266
|
|
|
267
267
|
#### Methods
|
|
268
268
|
|
|
269
|
+
##### `InputFormatContext.inputFormat`
|
|
270
|
+
|
|
271
|
+
Gets the input format associated with this context.
|
|
272
|
+
|
|
273
|
+
**Returns**: `InputFormat` instance or `undefined` if not available
|
|
274
|
+
|
|
269
275
|
##### `InputFormatContext.destroy()`
|
|
270
276
|
|
|
271
277
|
Destroys the `InputFormatContext` and closes the input format. Automatically called when the object is managed by a `using` declaration.
|
|
@@ -299,6 +305,12 @@ Parameters:
|
|
|
299
305
|
|
|
300
306
|
**Returns**: A new `Stream` instance
|
|
301
307
|
|
|
308
|
+
##### `OutputFormatContext.outputFormat`
|
|
309
|
+
|
|
310
|
+
Gets the output format associated with this context.
|
|
311
|
+
|
|
312
|
+
**Returns**: `OutputFormat` instance or `undefined` if not available
|
|
313
|
+
|
|
302
314
|
##### `OutputFormatContext.destroy()`
|
|
303
315
|
|
|
304
316
|
Destroys the `OutputFormatContext` and closes the output format. Automatically called when the object is managed by a `using` declaration.
|
package/binding.cc
CHANGED
|
@@ -29,6 +29,7 @@ extern "C" {
|
|
|
29
29
|
#include <libavutil/frame.h>
|
|
30
30
|
#include <libavutil/imgutils.h>
|
|
31
31
|
#include <libavutil/log.h>
|
|
32
|
+
#include <libavutil/mathematics.h>
|
|
32
33
|
#include <libavutil/mem.h>
|
|
33
34
|
#include <libavutil/pixfmt.h>
|
|
34
35
|
#include <libavutil/rational.h>
|
|
@@ -129,12 +130,6 @@ typedef struct {
|
|
|
129
130
|
|
|
130
131
|
static uv_once_t bare_ffmpeg__init_guard = UV_ONCE_INIT;
|
|
131
132
|
|
|
132
|
-
static inline bool
|
|
133
|
-
bare_ffmpeg__bad_timebase(const AVRational r) {
|
|
134
|
-
return r.den < 1 || // Invalid denominator
|
|
135
|
-
av_q2d(r) == 0; // Initial state (0 / 1)
|
|
136
|
-
}
|
|
137
|
-
|
|
138
133
|
static void
|
|
139
134
|
bare_ffmpeg__on_init(void) {
|
|
140
135
|
av_log_set_level(AV_LOG_ERROR);
|
|
@@ -711,6 +706,48 @@ bare_ffmpeg_format_context_dump(
|
|
|
711
706
|
}
|
|
712
707
|
}
|
|
713
708
|
|
|
709
|
+
static std::optional<js_arraybuffer_t>
|
|
710
|
+
get_bare_ffmpeg_format_context_output_format(
|
|
711
|
+
js_env_t *env,
|
|
712
|
+
js_receiver_t,
|
|
713
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
714
|
+
) {
|
|
715
|
+
int err;
|
|
716
|
+
|
|
717
|
+
if (!context->handle->oformat) return std::nullopt;
|
|
718
|
+
|
|
719
|
+
js_arraybuffer_t handle;
|
|
720
|
+
|
|
721
|
+
bare_ffmpeg_output_format_t *format;
|
|
722
|
+
err = js_create_arraybuffer(env, format, handle);
|
|
723
|
+
assert(err == 0);
|
|
724
|
+
|
|
725
|
+
format->handle = context->handle->oformat;
|
|
726
|
+
|
|
727
|
+
return handle;
|
|
728
|
+
}
|
|
729
|
+
|
|
730
|
+
static std::optional<js_arraybuffer_t>
|
|
731
|
+
get_bare_ffmpeg_format_context_input_format(
|
|
732
|
+
js_env_t *env,
|
|
733
|
+
js_receiver_t,
|
|
734
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
735
|
+
) {
|
|
736
|
+
int err;
|
|
737
|
+
|
|
738
|
+
if (!context->handle->iformat) return std::nullopt;
|
|
739
|
+
|
|
740
|
+
js_arraybuffer_t handle;
|
|
741
|
+
|
|
742
|
+
bare_ffmpeg_input_format_t *format;
|
|
743
|
+
err = js_create_arraybuffer(env, format, handle);
|
|
744
|
+
assert(err == 0);
|
|
745
|
+
|
|
746
|
+
format->handle = context->handle->iformat;
|
|
747
|
+
|
|
748
|
+
return handle;
|
|
749
|
+
}
|
|
750
|
+
|
|
714
751
|
static int32_t
|
|
715
752
|
bare_ffmpeg_stream_get_index(
|
|
716
753
|
js_env_t *env,
|
|
@@ -2775,30 +2812,20 @@ bare_ffmpeg_packet_set_time_base(
|
|
|
2775
2812
|
packet->handle->time_base.den = den;
|
|
2776
2813
|
}
|
|
2777
2814
|
|
|
2778
|
-
static
|
|
2815
|
+
static void
|
|
2779
2816
|
bare_ffmpeg_packet_rescale_ts(
|
|
2780
2817
|
js_env_t *env,
|
|
2781
2818
|
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
2782
|
-
int32_t
|
|
2783
|
-
int32_t
|
|
2784
|
-
|
|
2785
|
-
|
|
2786
|
-
|
|
2787
|
-
|
|
2788
|
-
|
|
2789
|
-
|
|
2790
|
-
|
|
2791
|
-
|
|
2792
|
-
packet->handle->pts == AV_NOPTS_VALUE
|
|
2793
|
-
) {
|
|
2794
|
-
return false;
|
|
2795
|
-
}
|
|
2796
|
-
|
|
2797
|
-
av_packet_rescale_ts(packet->handle, src, dst);
|
|
2798
|
-
|
|
2799
|
-
packet->handle->time_base = dst;
|
|
2800
|
-
|
|
2801
|
-
return true;
|
|
2819
|
+
int32_t src_num,
|
|
2820
|
+
int32_t src_den,
|
|
2821
|
+
int32_t dst_num,
|
|
2822
|
+
int32_t dst_den
|
|
2823
|
+
) {
|
|
2824
|
+
av_packet_rescale_ts(
|
|
2825
|
+
packet->handle,
|
|
2826
|
+
{src_num, src_den},
|
|
2827
|
+
{dst_num, dst_den}
|
|
2828
|
+
);
|
|
2802
2829
|
}
|
|
2803
2830
|
|
|
2804
2831
|
static int64_t
|
|
@@ -2945,11 +2972,6 @@ bare_ffmpeg_scaler_scale(
|
|
|
2945
2972
|
int height,
|
|
2946
2973
|
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> target
|
|
2947
2974
|
) {
|
|
2948
|
-
int err;
|
|
2949
|
-
|
|
2950
|
-
err = av_frame_copy_props(target->handle, source->handle);
|
|
2951
|
-
assert(err == 0);
|
|
2952
|
-
|
|
2953
2975
|
return sws_scale(
|
|
2954
2976
|
scaler->handle,
|
|
2955
2977
|
reinterpret_cast<const uint8_t *const *>(source->handle->data),
|
|
@@ -3628,9 +3650,15 @@ bare_ffmpeg_rational_rescale_q(
|
|
|
3628
3650
|
int32_t bq_num,
|
|
3629
3651
|
int32_t bq_den,
|
|
3630
3652
|
int32_t cq_num,
|
|
3631
|
-
int32_t cq_den
|
|
3632
|
-
|
|
3633
|
-
|
|
3653
|
+
int32_t cq_den,
|
|
3654
|
+
int64_t av_round
|
|
3655
|
+
) {
|
|
3656
|
+
return av_rescale_q_rnd(
|
|
3657
|
+
ts,
|
|
3658
|
+
{bq_num, bq_den},
|
|
3659
|
+
{cq_num, cq_den},
|
|
3660
|
+
static_cast<AVRounding>(av_round)
|
|
3661
|
+
);
|
|
3634
3662
|
}
|
|
3635
3663
|
|
|
3636
3664
|
static js_value_t *
|
|
@@ -3674,6 +3702,8 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
3674
3702
|
V("writeFormatContextFrame", bare_ffmpeg_format_context_write_frame)
|
|
3675
3703
|
V("writeFormatContextTrailer", bare_ffmpeg_format_context_write_trailer)
|
|
3676
3704
|
V("dumpFormatContext", bare_ffmpeg_format_context_dump)
|
|
3705
|
+
V("getFormatContextOutputFormat", get_bare_ffmpeg_format_context_output_format)
|
|
3706
|
+
V("getFormatContextInputFormat", get_bare_ffmpeg_format_context_input_format)
|
|
3677
3707
|
|
|
3678
3708
|
V("getStreamIndex", bare_ffmpeg_stream_get_index)
|
|
3679
3709
|
V("getStreamId", bare_ffmpeg_stream_get_id)
|
|
@@ -4176,6 +4206,12 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
4176
4206
|
V(AV_CODEC_CONFIG_COLOR_RANGE)
|
|
4177
4207
|
V(AV_CODEC_CONFIG_COLOR_SPACE)
|
|
4178
4208
|
|
|
4209
|
+
V(AV_ROUND_ZERO)
|
|
4210
|
+
V(AV_ROUND_INF)
|
|
4211
|
+
V(AV_ROUND_DOWN)
|
|
4212
|
+
V(AV_ROUND_UP)
|
|
4213
|
+
V(AV_ROUND_NEAR_INF) // default
|
|
4214
|
+
V(AV_ROUND_PASS_MINMAX)
|
|
4179
4215
|
#undef V
|
|
4180
4216
|
|
|
4181
4217
|
return exports;
|
package/lib/codec-context.js
CHANGED
|
@@ -217,7 +217,10 @@ module.exports = class FFmpegCodecContext {
|
|
|
217
217
|
timeBase: this.timeBase,
|
|
218
218
|
channelLayout: this.channelLayout,
|
|
219
219
|
gopSize: this.gopSize,
|
|
220
|
-
extraData: this.extraData
|
|
220
|
+
extraData: this.extraData,
|
|
221
|
+
frameRate: this.frameRate,
|
|
222
|
+
frameSize: this.frameSize,
|
|
223
|
+
frameNum: this.frameNum
|
|
221
224
|
}
|
|
222
225
|
}
|
|
223
226
|
}
|
package/lib/constants.js
CHANGED
|
@@ -193,6 +193,14 @@ module.exports = exports = {
|
|
|
193
193
|
CHANNEL_LAYOUT: binding.AV_CODEC_CONFIG_CHANNEL_LAYOUT,
|
|
194
194
|
COLOR_RANGE: binding.AV_CODEC_CONFIG_COLOR_RANGE,
|
|
195
195
|
COLOR_SPACE: binding.AV_CODEC_CONFIG_COLOR_SPACE
|
|
196
|
+
},
|
|
197
|
+
rounding: {
|
|
198
|
+
AV_ROUND_ZERO: binding.AV_ROUND_ZERO,
|
|
199
|
+
AV_ROUND_INF: binding.AV_ROUND_INF,
|
|
200
|
+
AV_ROUND_DOWN: binding.AV_ROUND_DOWN,
|
|
201
|
+
AV_ROUND_UP: binding.AV_ROUND_UP,
|
|
202
|
+
AV_ROUND_NEAR_INF: binding.AV_ROUND_NEAR_INF,
|
|
203
|
+
AV_ROUND_PASS_MINMAX: binding.AV_ROUND_PASS_MINMAX
|
|
196
204
|
}
|
|
197
205
|
}
|
|
198
206
|
|
package/lib/format-context.js
CHANGED
|
@@ -111,16 +111,21 @@ exports.InputFormatContext = class FFmpegInputFormatContext extends (
|
|
|
111
111
|
}
|
|
112
112
|
}
|
|
113
113
|
|
|
114
|
-
dump(printIdx = 0, printUrl = '') {
|
|
115
|
-
binding.dumpFormatContext(this._handle, false, printIdx, printUrl)
|
|
116
|
-
}
|
|
117
|
-
|
|
118
114
|
destroy() {
|
|
119
115
|
super.destroy()
|
|
120
116
|
|
|
121
117
|
binding.closeInputFormatContext(this._handle)
|
|
122
118
|
this._handle = null
|
|
123
119
|
}
|
|
120
|
+
|
|
121
|
+
dump(printIdx = 0, printUrl = '') {
|
|
122
|
+
binding.dumpFormatContext(this._handle, false, printIdx, printUrl)
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
get inputFormat() {
|
|
126
|
+
const handle = binding.getFormatContextInputFormat(this._handle)
|
|
127
|
+
if (handle) return InputFormat.from(handle)
|
|
128
|
+
}
|
|
124
129
|
}
|
|
125
130
|
|
|
126
131
|
exports.OutputFormatContext = class FFmpegOutputFormatContext extends (
|
|
@@ -167,4 +172,9 @@ exports.OutputFormatContext = class FFmpegOutputFormatContext extends (
|
|
|
167
172
|
dump(printIdx = 0, printUrl = '') {
|
|
168
173
|
binding.dumpFormatContext(this._handle, true, printIdx, printUrl)
|
|
169
174
|
}
|
|
175
|
+
|
|
176
|
+
get outputFormat() {
|
|
177
|
+
const handle = binding.getFormatContextOutputFormat(this._handle)
|
|
178
|
+
if (handle) return OutputFormat.from(handle)
|
|
179
|
+
}
|
|
170
180
|
}
|
package/lib/input-format.js
CHANGED
|
@@ -19,8 +19,13 @@ switch (Bare.platform) {
|
|
|
19
19
|
}
|
|
20
20
|
|
|
21
21
|
module.exports = class FFmpegInputFormat {
|
|
22
|
-
constructor(name = defaultName) {
|
|
23
|
-
this._handle =
|
|
22
|
+
constructor(name = defaultName, handle) {
|
|
23
|
+
if (handle) this._handle = handle
|
|
24
|
+
else this._handle = binding.initInputFormat(name)
|
|
25
|
+
}
|
|
26
|
+
|
|
27
|
+
static from(handle) {
|
|
28
|
+
return new FFmpegInputFormat(null, handle)
|
|
24
29
|
}
|
|
25
30
|
|
|
26
31
|
get flags() {
|
|
@@ -34,4 +39,13 @@ module.exports = class FFmpegInputFormat {
|
|
|
34
39
|
get mimeType() {
|
|
35
40
|
return binding.getInputFormatMimeType(this._handle)
|
|
36
41
|
}
|
|
42
|
+
|
|
43
|
+
[Symbol.for('bare.inspect')]() {
|
|
44
|
+
return {
|
|
45
|
+
__proto__: { constructor: FFmpegInputFormat },
|
|
46
|
+
flags: this.flags,
|
|
47
|
+
extensions: this.extensions,
|
|
48
|
+
mimeType: this.mimeType
|
|
49
|
+
}
|
|
50
|
+
}
|
|
37
51
|
}
|
package/lib/output-format.js
CHANGED
|
@@ -1,8 +1,13 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
2
|
|
|
3
3
|
module.exports = class FFmpegOutputFormat {
|
|
4
|
-
constructor(name) {
|
|
5
|
-
this._handle =
|
|
4
|
+
constructor(name, handle) {
|
|
5
|
+
if (handle) this._handle = handle
|
|
6
|
+
else this._handle = binding.initOutputFormat(name)
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
static from(handle) {
|
|
10
|
+
return new FFmpegOutputFormat(null, handle)
|
|
6
11
|
}
|
|
7
12
|
|
|
8
13
|
get flags() {
|
|
@@ -16,4 +21,13 @@ module.exports = class FFmpegOutputFormat {
|
|
|
16
21
|
get mimeType() {
|
|
17
22
|
return binding.getOutputFormatMimeType(this._handle)
|
|
18
23
|
}
|
|
24
|
+
|
|
25
|
+
[Symbol.for('bare.inspect')]() {
|
|
26
|
+
return {
|
|
27
|
+
__proto__: { constructor: FFmpegOutputFormat },
|
|
28
|
+
flags: this.flags,
|
|
29
|
+
extensions: this.extensions,
|
|
30
|
+
mimeType: this.mimeType
|
|
31
|
+
}
|
|
32
|
+
}
|
|
19
33
|
}
|
package/lib/packet.js
CHANGED
|
@@ -130,11 +130,13 @@ module.exports = class FFmpegPacket {
|
|
|
130
130
|
binding.setPacketTimeBase(this._handle, value.numerator, value.denominator)
|
|
131
131
|
}
|
|
132
132
|
|
|
133
|
-
rescaleTimestamps(
|
|
133
|
+
rescaleTimestamps(srcTimeBase, dstTimeBase) {
|
|
134
134
|
return binding.rescalePacketTimestamps(
|
|
135
135
|
this._handle,
|
|
136
|
-
|
|
137
|
-
|
|
136
|
+
srcTimeBase.numerator,
|
|
137
|
+
srcTimeBase.denominator,
|
|
138
|
+
dstTimeBase.numerator,
|
|
139
|
+
dstTimeBase.denominator
|
|
138
140
|
)
|
|
139
141
|
}
|
|
140
142
|
|
package/lib/rational.js
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
|
+
const { AV_ROUND_NEAR_INF } = require('./constants').rounding
|
|
2
3
|
|
|
3
4
|
module.exports = class FFmpegRational {
|
|
4
5
|
constructor(numerator = 0, denominator = 1) {
|
|
@@ -38,7 +39,7 @@ module.exports = class FFmpegRational {
|
|
|
38
39
|
return new FFmpegRational(view[0], view[1])
|
|
39
40
|
}
|
|
40
41
|
|
|
41
|
-
static rescaleQ(n, src, dst) {
|
|
42
|
+
static rescaleQ(n, src, dst, round = AV_ROUND_NEAR_INF) {
|
|
42
43
|
if (src.equals(dst)) return n
|
|
43
44
|
|
|
44
45
|
return binding.rationalRescaleQ(
|
|
@@ -46,7 +47,8 @@ module.exports = class FFmpegRational {
|
|
|
46
47
|
src.numerator,
|
|
47
48
|
src.denominator,
|
|
48
49
|
dst.numerator,
|
|
49
|
-
dst.denominator
|
|
50
|
+
dst.denominator,
|
|
51
|
+
round
|
|
50
52
|
)
|
|
51
53
|
}
|
|
52
54
|
}
|
package/package.json
CHANGED
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|
|
Binary file
|