bare-ffmpeg 1.0.0-14 → 1.0.0-16
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 +10 -0
- package/binding.cc +848 -20
- package/cmake/ports/opus/port.cmake +4 -0
- package/index.d.ts +46 -0
- package/index.js +5 -3
- package/lib/audio-fifo.d.ts +20 -0
- package/lib/channel-layout.d.ts +9 -0
- package/lib/channel-layout.js +11 -0
- package/lib/codec-context.d.ts +34 -0
- package/lib/codec-context.js +51 -1
- package/lib/codec-parameters.d.ts +20 -0
- package/lib/codec-parameters.js +38 -0
- package/lib/codec.d.ts +20 -0
- package/lib/codec.js +14 -0
- package/lib/constants.d.ts +74 -0
- package/lib/constants.js +58 -2
- package/lib/decoder.d.ts +7 -0
- package/lib/dictionary.d.ts +11 -0
- package/lib/dictionary.js +2 -0
- package/lib/encoder.d.ts +7 -0
- package/lib/format-context.d.ts +43 -0
- package/lib/format-context.js +28 -5
- package/lib/frame.d.ts +23 -0
- package/lib/frame.js +46 -0
- package/lib/image.d.ts +30 -0
- package/lib/image.js +12 -0
- package/lib/input-format.d.ts +5 -0
- package/lib/input-format.js +7 -0
- package/lib/io-context.d.ts +10 -0
- package/lib/io-context.js +24 -6
- package/lib/log.js +16 -0
- package/lib/output-format.d.ts +5 -0
- package/lib/output-format.js +4 -0
- package/lib/packet.d.ts +16 -0
- package/lib/packet.js +81 -0
- package/lib/rational.d.ts +8 -0
- package/lib/rational.js +27 -1
- package/lib/resampler.d.ts +26 -0
- package/lib/resampler.js +2 -2
- package/lib/samples.d.ts +16 -0
- package/lib/scaler.d.ts +26 -0
- package/lib/scaler.js +2 -2
- package/lib/stream.d.ts +18 -0
- package/lib/stream.js +38 -5
- package/package.json +17 -3
- 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/binding.cc
CHANGED
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
#include <assert.h>
|
|
2
|
+
#include <cstdint>
|
|
2
3
|
#include <stddef.h>
|
|
3
4
|
#include <stdint.h>
|
|
4
5
|
#include <string.h>
|
|
@@ -16,6 +17,7 @@ extern "C" {
|
|
|
16
17
|
#include <libavdevice/avdevice.h>
|
|
17
18
|
#include <libavformat/avformat.h>
|
|
18
19
|
#include <libavformat/avio.h>
|
|
20
|
+
#include <libavutil/audio_fifo.h>
|
|
19
21
|
#include <libavutil/channel_layout.h>
|
|
20
22
|
#include <libavutil/dict.h>
|
|
21
23
|
#include <libavutil/error.h>
|
|
@@ -26,13 +28,17 @@ extern "C" {
|
|
|
26
28
|
#include <libavutil/pixfmt.h>
|
|
27
29
|
#include <libavutil/rational.h>
|
|
28
30
|
#include <libavutil/samplefmt.h>
|
|
29
|
-
#include <libavutil/audio_fifo.h>
|
|
30
31
|
#include <libswresample/swresample.h>
|
|
31
32
|
#include <libswscale/swscale.h>
|
|
32
33
|
}
|
|
33
34
|
|
|
35
|
+
using bare_ffmpeg_io_context_on_write_cb_t = js_function_t<void, js_arraybuffer_t>;
|
|
36
|
+
|
|
34
37
|
typedef struct {
|
|
35
38
|
AVIOContext *handle;
|
|
39
|
+
|
|
40
|
+
js_env_t *env;
|
|
41
|
+
js_persistent_t<bare_ffmpeg_io_context_on_write_cb_t> on_write;
|
|
36
42
|
} bare_ffmpeg_io_context_t;
|
|
37
43
|
|
|
38
44
|
typedef struct {
|
|
@@ -93,6 +99,12 @@ typedef struct {
|
|
|
93
99
|
|
|
94
100
|
static uv_once_t bare_ffmpeg__init_guard = UV_ONCE_INIT;
|
|
95
101
|
|
|
102
|
+
static inline bool
|
|
103
|
+
bad_timebase(const AVRational r) {
|
|
104
|
+
return r.den < 1 || // invalid denominator
|
|
105
|
+
av_q2d(r) == 0; // detect initial state: (0 / 1)
|
|
106
|
+
}
|
|
107
|
+
|
|
96
108
|
static void
|
|
97
109
|
bare_ffmpeg__on_init(void) {
|
|
98
110
|
av_log_set_level(AV_LOG_ERROR);
|
|
@@ -100,13 +112,45 @@ bare_ffmpeg__on_init(void) {
|
|
|
100
112
|
avdevice_register_all();
|
|
101
113
|
}
|
|
102
114
|
|
|
115
|
+
static int32_t
|
|
116
|
+
bare_ffmpeg_log_get_level(js_env_t *) {
|
|
117
|
+
return av_log_get_level();
|
|
118
|
+
}
|
|
119
|
+
|
|
120
|
+
static void
|
|
121
|
+
bare_ffmpeg_log_set_level(js_env_t *, int32_t level) {
|
|
122
|
+
av_log_set_level(level);
|
|
123
|
+
}
|
|
124
|
+
|
|
125
|
+
static int
|
|
126
|
+
io_context_write_packet(void *opaque, const uint8_t *chunk, int len) {
|
|
127
|
+
auto context = reinterpret_cast<bare_ffmpeg_io_context_t *>(opaque);
|
|
128
|
+
auto env = context->env;
|
|
129
|
+
|
|
130
|
+
bare_ffmpeg_io_context_on_write_cb_t callback;
|
|
131
|
+
|
|
132
|
+
int err = js_get_reference_value(env, context->on_write, callback);
|
|
133
|
+
assert(err == 0);
|
|
134
|
+
|
|
135
|
+
js_arraybuffer_t data;
|
|
136
|
+
err = js_create_arraybuffer(env, chunk, static_cast<size_t>(len), data);
|
|
137
|
+
|
|
138
|
+
assert(err == 0);
|
|
139
|
+
|
|
140
|
+
// TODO: running on js-stack during avformat_write_header()
|
|
141
|
+
// trace other invocations, pray singlethread.
|
|
142
|
+
err = js_call_function(env, callback, data);
|
|
143
|
+
return err;
|
|
144
|
+
}
|
|
145
|
+
|
|
103
146
|
static js_arraybuffer_t
|
|
104
147
|
bare_ffmpeg_io_context_init(
|
|
105
148
|
js_env_t *env,
|
|
106
149
|
js_receiver_t,
|
|
107
|
-
js_arraybuffer_span_t data,
|
|
150
|
+
std::optional<js_arraybuffer_span_t> data,
|
|
108
151
|
uint64_t offset,
|
|
109
|
-
uint64_t len
|
|
152
|
+
uint64_t len,
|
|
153
|
+
std::optional<bare_ffmpeg_io_context_on_write_cb_t> on_write
|
|
110
154
|
) {
|
|
111
155
|
int err;
|
|
112
156
|
|
|
@@ -116,18 +160,39 @@ bare_ffmpeg_io_context_init(
|
|
|
116
160
|
err = js_create_arraybuffer(env, context, handle);
|
|
117
161
|
assert(err == 0);
|
|
118
162
|
|
|
119
|
-
|
|
163
|
+
context->env = env;
|
|
164
|
+
|
|
165
|
+
int write_flag = 0;
|
|
166
|
+
if (on_write) {
|
|
167
|
+
write_flag = 1;
|
|
168
|
+
err = js_create_reference(env, *on_write, context->on_write);
|
|
169
|
+
assert(err == 0);
|
|
170
|
+
}
|
|
171
|
+
|
|
120
172
|
size_t size = static_cast<size_t>(len);
|
|
121
173
|
|
|
122
|
-
|
|
123
|
-
|
|
174
|
+
uint8_t *io = NULL;
|
|
175
|
+
|
|
176
|
+
if (size) {
|
|
124
177
|
io = reinterpret_cast<uint8_t *>(av_malloc(size));
|
|
178
|
+
}
|
|
125
179
|
|
|
126
|
-
|
|
180
|
+
if (data) {
|
|
181
|
+
memcpy(io, &data.value()[static_cast<size_t>(offset)], size);
|
|
127
182
|
}
|
|
128
183
|
|
|
129
|
-
|
|
130
|
-
|
|
184
|
+
// TODO: for stream read support provide read/seek callbacks
|
|
185
|
+
|
|
186
|
+
context->handle = avio_alloc_context(
|
|
187
|
+
io,
|
|
188
|
+
static_cast<int>(len),
|
|
189
|
+
write_flag,
|
|
190
|
+
context,
|
|
191
|
+
NULL, // io_context_read_packet
|
|
192
|
+
io_context_write_packet,
|
|
193
|
+
NULL // io_context_seek
|
|
194
|
+
);
|
|
195
|
+
assert(context->handle->opaque == context);
|
|
131
196
|
|
|
132
197
|
return handle;
|
|
133
198
|
}
|
|
@@ -141,6 +206,7 @@ bare_ffmpeg_io_context_destroy(
|
|
|
141
206
|
av_free(context->handle->buffer);
|
|
142
207
|
|
|
143
208
|
avio_context_free(&context->handle);
|
|
209
|
+
context->on_write.reset();
|
|
144
210
|
}
|
|
145
211
|
|
|
146
212
|
static js_arraybuffer_t
|
|
@@ -167,6 +233,15 @@ bare_ffmpeg_output_format_init(js_env_t *env, js_receiver_t, std::string name) {
|
|
|
167
233
|
return handle;
|
|
168
234
|
}
|
|
169
235
|
|
|
236
|
+
static int32_t
|
|
237
|
+
bare_ffmpeg_output_format_get_flags(
|
|
238
|
+
js_env_t *,
|
|
239
|
+
js_receiver_t,
|
|
240
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_output_format_t, 1> format
|
|
241
|
+
) {
|
|
242
|
+
return format->handle->flags;
|
|
243
|
+
}
|
|
244
|
+
|
|
170
245
|
static js_arraybuffer_t
|
|
171
246
|
bare_ffmpeg_input_format_init(js_env_t *env, js_receiver_t, std::string name) {
|
|
172
247
|
int err;
|
|
@@ -191,6 +266,15 @@ bare_ffmpeg_input_format_init(js_env_t *env, js_receiver_t, std::string name) {
|
|
|
191
266
|
return handle;
|
|
192
267
|
}
|
|
193
268
|
|
|
269
|
+
static int32_t
|
|
270
|
+
bare_ffmpeg_input_format_get_flags(
|
|
271
|
+
js_env_t *,
|
|
272
|
+
js_receiver_t,
|
|
273
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_input_format_t, 1> format
|
|
274
|
+
) {
|
|
275
|
+
return format->handle->flags;
|
|
276
|
+
}
|
|
277
|
+
|
|
194
278
|
static js_arraybuffer_t
|
|
195
279
|
bare_ffmpeg_format_context_open_input_with_io(
|
|
196
280
|
js_env_t *env,
|
|
@@ -369,8 +453,7 @@ static js_arraybuffer_t
|
|
|
369
453
|
bare_ffmpeg_format_context_create_stream(
|
|
370
454
|
js_env_t *env,
|
|
371
455
|
js_receiver_t,
|
|
372
|
-
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
373
|
-
js_arraybuffer_span_of_t<bare_ffmpeg_codec_t, 1> codec
|
|
456
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
374
457
|
) {
|
|
375
458
|
int err;
|
|
376
459
|
|
|
@@ -380,7 +463,7 @@ bare_ffmpeg_format_context_create_stream(
|
|
|
380
463
|
err = js_create_arraybuffer(env, stream, handle);
|
|
381
464
|
assert(err == 0);
|
|
382
465
|
|
|
383
|
-
stream->handle = avformat_new_stream(context->handle,
|
|
466
|
+
stream->handle = avformat_new_stream(context->handle, NULL);
|
|
384
467
|
|
|
385
468
|
return handle;
|
|
386
469
|
}
|
|
@@ -407,13 +490,175 @@ bare_ffmpeg_format_context_read_frame(
|
|
|
407
490
|
return err == 0;
|
|
408
491
|
}
|
|
409
492
|
|
|
493
|
+
static bool
|
|
494
|
+
bare_ffmpeg_format_context_write_header(
|
|
495
|
+
js_env_t *env,
|
|
496
|
+
js_receiver_t,
|
|
497
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
498
|
+
std::optional<js_arraybuffer_span_of_t<bare_ffmpeg_dictionary_t, 1>> muxer_options
|
|
499
|
+
) {
|
|
500
|
+
int err;
|
|
501
|
+
|
|
502
|
+
if (!muxer_options) {
|
|
503
|
+
err = avformat_write_header(context->handle, NULL);
|
|
504
|
+
} else {
|
|
505
|
+
auto dict = *muxer_options;
|
|
506
|
+
err = avformat_write_header(context->handle, &dict->handle);
|
|
507
|
+
|
|
508
|
+
const AVDictionaryEntry *option = NULL;
|
|
509
|
+
while ((option = av_dict_iterate(dict->handle, option))) {
|
|
510
|
+
av_log(context->handle, AV_LOG_WARNING, "Ignored option key='%s' value='%s'\n", option->key, option->value);
|
|
511
|
+
}
|
|
512
|
+
}
|
|
513
|
+
|
|
514
|
+
if (err < 0) {
|
|
515
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
516
|
+
assert(err == 0);
|
|
517
|
+
|
|
518
|
+
throw js_pending_exception;
|
|
519
|
+
}
|
|
520
|
+
|
|
521
|
+
return err;
|
|
522
|
+
}
|
|
523
|
+
static void
|
|
524
|
+
bare_ffmpeg_format_context_write_frame(
|
|
525
|
+
js_env_t *env,
|
|
526
|
+
js_receiver_t,
|
|
527
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
528
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
529
|
+
) {
|
|
530
|
+
int err = av_interleaved_write_frame(context->handle, packet->handle);
|
|
531
|
+
|
|
532
|
+
if (err < 0) {
|
|
533
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
534
|
+
assert(err == 0);
|
|
535
|
+
|
|
536
|
+
throw js_pending_exception;
|
|
537
|
+
}
|
|
538
|
+
}
|
|
539
|
+
|
|
540
|
+
static void
|
|
541
|
+
bare_ffmpeg_format_context_write_trailer(
|
|
542
|
+
js_env_t *env,
|
|
543
|
+
js_receiver_t,
|
|
544
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context
|
|
545
|
+
) {
|
|
546
|
+
int err = av_write_trailer(context->handle);
|
|
547
|
+
if (err < 0) {
|
|
548
|
+
err = js_throw_error(env, NULL, av_err2str(err));
|
|
549
|
+
assert(err == 0);
|
|
550
|
+
|
|
551
|
+
throw js_pending_exception;
|
|
552
|
+
}
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
static void
|
|
556
|
+
bare_ffmpeg_format_context_dump(
|
|
557
|
+
js_env_t *env,
|
|
558
|
+
js_receiver_t,
|
|
559
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_format_context_t, 1> context,
|
|
560
|
+
bool is_output,
|
|
561
|
+
int32_t index,
|
|
562
|
+
std::string url
|
|
563
|
+
) {
|
|
564
|
+
av_dump_format(context->handle, index, url.c_str(), is_output);
|
|
565
|
+
|
|
566
|
+
for (int i = 0; i < context->handle->nb_streams; i++) {
|
|
567
|
+
auto stream = context->handle->streams[i];
|
|
568
|
+
av_log(NULL, AV_LOG_INFO, " - stream=%i timebase=(%i / %i)\n", i, stream->time_base.num, stream->time_base.den);
|
|
569
|
+
}
|
|
570
|
+
}
|
|
571
|
+
|
|
572
|
+
static int32_t
|
|
573
|
+
bare_ffmpeg_stream_get_index(
|
|
574
|
+
js_env_t *env,
|
|
575
|
+
js_receiver_t,
|
|
576
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
577
|
+
) {
|
|
578
|
+
return stream->handle->index;
|
|
579
|
+
}
|
|
580
|
+
|
|
410
581
|
static int32_t
|
|
411
|
-
|
|
582
|
+
bare_ffmpeg_stream_get_id(
|
|
583
|
+
js_env_t *env,
|
|
584
|
+
js_receiver_t,
|
|
585
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
586
|
+
) {
|
|
587
|
+
return stream->handle->id;
|
|
588
|
+
}
|
|
589
|
+
|
|
590
|
+
static void
|
|
591
|
+
bare_ffmpeg_stream_set_id(
|
|
592
|
+
js_env_t *env,
|
|
593
|
+
js_receiver_t,
|
|
594
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream,
|
|
595
|
+
int32_t id
|
|
596
|
+
) {
|
|
597
|
+
stream->handle->id = id;
|
|
598
|
+
}
|
|
599
|
+
|
|
600
|
+
static js_arraybuffer_t
|
|
601
|
+
bare_ffmpeg_stream_get_time_base(
|
|
602
|
+
js_env_t *env,
|
|
603
|
+
js_receiver_t,
|
|
604
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
605
|
+
) {
|
|
606
|
+
int err;
|
|
607
|
+
|
|
608
|
+
js_arraybuffer_t result;
|
|
609
|
+
|
|
610
|
+
int32_t *data;
|
|
611
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
612
|
+
assert(err == 0);
|
|
613
|
+
|
|
614
|
+
data[0] = stream->handle->time_base.num;
|
|
615
|
+
data[1] = stream->handle->time_base.den;
|
|
616
|
+
|
|
617
|
+
return result;
|
|
618
|
+
}
|
|
619
|
+
|
|
620
|
+
static void
|
|
621
|
+
bare_ffmpeg_stream_set_time_base(
|
|
622
|
+
js_env_t *env,
|
|
623
|
+
js_receiver_t,
|
|
624
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream,
|
|
625
|
+
int num,
|
|
626
|
+
int den
|
|
627
|
+
) {
|
|
628
|
+
stream->handle->time_base.num = num;
|
|
629
|
+
stream->handle->time_base.den = den;
|
|
630
|
+
}
|
|
631
|
+
|
|
632
|
+
static js_arraybuffer_t
|
|
633
|
+
bare_ffmpeg_stream_get_avg_framerate(
|
|
412
634
|
js_env_t *env,
|
|
413
635
|
js_receiver_t,
|
|
414
636
|
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream
|
|
415
637
|
) {
|
|
416
|
-
|
|
638
|
+
int err;
|
|
639
|
+
|
|
640
|
+
js_arraybuffer_t result;
|
|
641
|
+
|
|
642
|
+
int32_t *data;
|
|
643
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
644
|
+
assert(err == 0);
|
|
645
|
+
|
|
646
|
+
data[0] = stream->handle->avg_frame_rate.num;
|
|
647
|
+
data[1] = stream->handle->avg_frame_rate.den;
|
|
648
|
+
|
|
649
|
+
return result;
|
|
650
|
+
}
|
|
651
|
+
|
|
652
|
+
static void
|
|
653
|
+
bare_ffmpeg_stream_set_avg_framerate(
|
|
654
|
+
js_env_t *env,
|
|
655
|
+
js_receiver_t,
|
|
656
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_stream_t, 1> stream,
|
|
657
|
+
int num,
|
|
658
|
+
int den
|
|
659
|
+
) {
|
|
660
|
+
stream->handle->avg_frame_rate.num = num;
|
|
661
|
+
stream->handle->avg_frame_rate.den = den;
|
|
417
662
|
}
|
|
418
663
|
|
|
419
664
|
static js_arraybuffer_t
|
|
@@ -483,6 +728,13 @@ bare_ffmpeg_find_encoder_by_id(js_env_t *env, js_receiver_t, uint32_t id) {
|
|
|
483
728
|
return handle;
|
|
484
729
|
}
|
|
485
730
|
|
|
731
|
+
static std::string
|
|
732
|
+
bare_ffmpeg_get_codec_name_by_id(js_env_t *env, js_receiver_t, uint32_t id) {
|
|
733
|
+
auto name = avcodec_get_name((enum AVCodecID) id);
|
|
734
|
+
|
|
735
|
+
return std::string(name);
|
|
736
|
+
}
|
|
737
|
+
|
|
486
738
|
static js_arraybuffer_t
|
|
487
739
|
bare_ffmpeg_codec_context_init(
|
|
488
740
|
js_env_t *env,
|
|
@@ -521,6 +773,7 @@ bare_ffmpeg_codec_context_open(
|
|
|
521
773
|
int err;
|
|
522
774
|
|
|
523
775
|
err = avcodec_open2(context->handle, context->handle->codec, NULL);
|
|
776
|
+
|
|
524
777
|
if (err < 0) {
|
|
525
778
|
err = js_throw_error(env, NULL, av_err2str(err));
|
|
526
779
|
assert(err == 0);
|
|
@@ -531,6 +784,25 @@ bare_ffmpeg_codec_context_open(
|
|
|
531
784
|
return err == 0;
|
|
532
785
|
}
|
|
533
786
|
|
|
787
|
+
static int32_t
|
|
788
|
+
bare_ffmpeg_codec_context_get_flags(
|
|
789
|
+
js_env_t *env,
|
|
790
|
+
js_receiver_t,
|
|
791
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
792
|
+
) {
|
|
793
|
+
return context->handle->flags;
|
|
794
|
+
}
|
|
795
|
+
|
|
796
|
+
static void
|
|
797
|
+
bare_ffmpeg_codec_context_set_flags(
|
|
798
|
+
js_env_t *env,
|
|
799
|
+
js_receiver_t,
|
|
800
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
801
|
+
int32_t value
|
|
802
|
+
) {
|
|
803
|
+
context->handle->flags = value;
|
|
804
|
+
}
|
|
805
|
+
|
|
534
806
|
static int64_t
|
|
535
807
|
bare_ffmpeg_frame_get_format(
|
|
536
808
|
js_env_t *env,
|
|
@@ -763,6 +1035,57 @@ bare_ffmpeg_codec_context_set_sample_rate(
|
|
|
763
1035
|
context->handle->sample_rate = sample_rate;
|
|
764
1036
|
}
|
|
765
1037
|
|
|
1038
|
+
static int
|
|
1039
|
+
bare_ffmpeg_codec_context_get_gop_size(
|
|
1040
|
+
js_env_t *env,
|
|
1041
|
+
js_receiver_t,
|
|
1042
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
1043
|
+
) {
|
|
1044
|
+
return context->handle->gop_size;
|
|
1045
|
+
}
|
|
1046
|
+
|
|
1047
|
+
static void
|
|
1048
|
+
bare_ffmpeg_codec_context_set_gop_size(
|
|
1049
|
+
js_env_t *env,
|
|
1050
|
+
js_receiver_t,
|
|
1051
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1052
|
+
int32_t gop_size
|
|
1053
|
+
) {
|
|
1054
|
+
context->handle->gop_size = gop_size;
|
|
1055
|
+
}
|
|
1056
|
+
|
|
1057
|
+
static js_arraybuffer_t
|
|
1058
|
+
bare_ffmpeg_codec_context_get_framerate(
|
|
1059
|
+
js_env_t *env,
|
|
1060
|
+
js_receiver_t,
|
|
1061
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context
|
|
1062
|
+
) {
|
|
1063
|
+
int err;
|
|
1064
|
+
|
|
1065
|
+
js_arraybuffer_t result;
|
|
1066
|
+
|
|
1067
|
+
int32_t *data;
|
|
1068
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1069
|
+
assert(err == 0);
|
|
1070
|
+
|
|
1071
|
+
data[0] = context->handle->framerate.num;
|
|
1072
|
+
data[1] = context->handle->framerate.den;
|
|
1073
|
+
|
|
1074
|
+
return result;
|
|
1075
|
+
}
|
|
1076
|
+
|
|
1077
|
+
static void
|
|
1078
|
+
bare_ffmpeg_codec_context_set_framerate(
|
|
1079
|
+
js_env_t *env,
|
|
1080
|
+
js_receiver_t,
|
|
1081
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
1082
|
+
int num,
|
|
1083
|
+
int den
|
|
1084
|
+
) {
|
|
1085
|
+
context->handle->framerate.num = num;
|
|
1086
|
+
context->handle->framerate.den = den;
|
|
1087
|
+
}
|
|
1088
|
+
|
|
766
1089
|
static bool
|
|
767
1090
|
bare_ffmpeg_codec_context_send_packet(
|
|
768
1091
|
js_env_t *env,
|
|
@@ -808,11 +1131,16 @@ bare_ffmpeg_codec_context_send_frame(
|
|
|
808
1131
|
js_env_t *env,
|
|
809
1132
|
js_receiver_t,
|
|
810
1133
|
js_arraybuffer_span_of_t<bare_ffmpeg_codec_context_t, 1> context,
|
|
811
|
-
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1
|
|
1134
|
+
std::optional<js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1>> frame
|
|
812
1135
|
) {
|
|
813
1136
|
int err;
|
|
814
1137
|
|
|
815
|
-
|
|
1138
|
+
if (frame) {
|
|
1139
|
+
err = avcodec_send_frame(context->handle, (*frame)->handle);
|
|
1140
|
+
} else {
|
|
1141
|
+
err = avcodec_send_frame(context->handle, NULL); // End of stream
|
|
1142
|
+
}
|
|
1143
|
+
|
|
816
1144
|
if (err < 0 && err != AVERROR(EAGAIN) && err != AVERROR_EOF) {
|
|
817
1145
|
err = js_throw_error(env, NULL, av_err2str(err));
|
|
818
1146
|
assert(err == 0);
|
|
@@ -853,6 +1181,7 @@ bare_ffmpeg_codec_parameters_from_context(
|
|
|
853
1181
|
int err;
|
|
854
1182
|
|
|
855
1183
|
err = avcodec_parameters_from_context(parameters->handle, context->handle);
|
|
1184
|
+
|
|
856
1185
|
if (err < 0) {
|
|
857
1186
|
err = js_throw_error(env, NULL, av_err2str(err));
|
|
858
1187
|
assert(err == 0);
|
|
@@ -942,6 +1271,15 @@ bare_ffmpeg_codec_parameters_get_codec_type(
|
|
|
942
1271
|
return parameters->handle->codec_type;
|
|
943
1272
|
}
|
|
944
1273
|
|
|
1274
|
+
static int32_t
|
|
1275
|
+
bare_ffmpeg_codec_parameters_get_codec_id(
|
|
1276
|
+
js_env_t *env,
|
|
1277
|
+
js_receiver_t,
|
|
1278
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1279
|
+
) {
|
|
1280
|
+
return parameters->handle->codec_id;
|
|
1281
|
+
}
|
|
1282
|
+
|
|
945
1283
|
static js_arraybuffer_t
|
|
946
1284
|
bare_ffmpeg_codec_parameters_get_channel_layout(
|
|
947
1285
|
js_env_t *env,
|
|
@@ -962,6 +1300,44 @@ bare_ffmpeg_codec_parameters_get_channel_layout(
|
|
|
962
1300
|
return result;
|
|
963
1301
|
}
|
|
964
1302
|
|
|
1303
|
+
static int32_t
|
|
1304
|
+
bare_ffmpeg_codec_parameters_get_width(
|
|
1305
|
+
js_env_t *env,
|
|
1306
|
+
js_receiver_t,
|
|
1307
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1308
|
+
) {
|
|
1309
|
+
return parameters->handle->width;
|
|
1310
|
+
}
|
|
1311
|
+
|
|
1312
|
+
static int32_t
|
|
1313
|
+
bare_ffmpeg_codec_parameters_get_height(
|
|
1314
|
+
js_env_t *env,
|
|
1315
|
+
js_receiver_t,
|
|
1316
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1317
|
+
) {
|
|
1318
|
+
return parameters->handle->height;
|
|
1319
|
+
}
|
|
1320
|
+
|
|
1321
|
+
static js_arraybuffer_t
|
|
1322
|
+
bare_ffmpeg_codec_parameters_get_framerate(
|
|
1323
|
+
js_env_t *env,
|
|
1324
|
+
js_receiver_t,
|
|
1325
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_codec_parameters_t, 1> parameters
|
|
1326
|
+
) {
|
|
1327
|
+
int err;
|
|
1328
|
+
|
|
1329
|
+
js_arraybuffer_t result;
|
|
1330
|
+
|
|
1331
|
+
int32_t *data;
|
|
1332
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1333
|
+
assert(err == 0);
|
|
1334
|
+
|
|
1335
|
+
data[0] = parameters->handle->framerate.num;
|
|
1336
|
+
data[1] = parameters->handle->framerate.den;
|
|
1337
|
+
|
|
1338
|
+
return result;
|
|
1339
|
+
}
|
|
1340
|
+
|
|
965
1341
|
static js_arraybuffer_t
|
|
966
1342
|
bare_ffmpeg_frame_init(js_env_t *env, js_receiver_t) {
|
|
967
1343
|
int err;
|
|
@@ -1063,6 +1439,92 @@ bare_ffmpeg_frame_set_nb_samples(
|
|
|
1063
1439
|
frame->handle->nb_samples = nb_samples;
|
|
1064
1440
|
}
|
|
1065
1441
|
|
|
1442
|
+
static int32_t
|
|
1443
|
+
bare_ffmpeg_frame_get_pict_type(
|
|
1444
|
+
js_env_t *env,
|
|
1445
|
+
js_receiver_t,
|
|
1446
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1447
|
+
) {
|
|
1448
|
+
return frame->handle->pict_type;
|
|
1449
|
+
}
|
|
1450
|
+
|
|
1451
|
+
static int64_t
|
|
1452
|
+
bare_ffmpeg_frame_get_pts(
|
|
1453
|
+
js_env_t *env,
|
|
1454
|
+
js_receiver_t,
|
|
1455
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1456
|
+
) {
|
|
1457
|
+
int64_t ts = frame->handle->pts;
|
|
1458
|
+
|
|
1459
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
1460
|
+
|
|
1461
|
+
return ts;
|
|
1462
|
+
}
|
|
1463
|
+
|
|
1464
|
+
static void
|
|
1465
|
+
bare_ffmpeg_frame_set_pts(
|
|
1466
|
+
js_env_t *,
|
|
1467
|
+
js_receiver_t,
|
|
1468
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1469
|
+
int64_t value
|
|
1470
|
+
) {
|
|
1471
|
+
frame->handle->pts = value;
|
|
1472
|
+
}
|
|
1473
|
+
|
|
1474
|
+
static int64_t
|
|
1475
|
+
bare_ffmpeg_frame_get_pkt_dts(
|
|
1476
|
+
js_env_t *env,
|
|
1477
|
+
js_receiver_t,
|
|
1478
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1479
|
+
) {
|
|
1480
|
+
int64_t ts = frame->handle->pkt_dts;
|
|
1481
|
+
|
|
1482
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
1483
|
+
|
|
1484
|
+
return ts;
|
|
1485
|
+
}
|
|
1486
|
+
|
|
1487
|
+
static void
|
|
1488
|
+
bare_ffmpeg_frame_set_pkt_dts(
|
|
1489
|
+
js_env_t *,
|
|
1490
|
+
js_receiver_t,
|
|
1491
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1492
|
+
int64_t value
|
|
1493
|
+
) {
|
|
1494
|
+
frame->handle->pkt_dts = value;
|
|
1495
|
+
}
|
|
1496
|
+
|
|
1497
|
+
static js_arraybuffer_t
|
|
1498
|
+
bare_ffmpeg_frame_get_time_base(
|
|
1499
|
+
js_env_t *env,
|
|
1500
|
+
js_receiver_t,
|
|
1501
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1502
|
+
) {
|
|
1503
|
+
int err;
|
|
1504
|
+
|
|
1505
|
+
js_arraybuffer_t result;
|
|
1506
|
+
|
|
1507
|
+
int32_t *data;
|
|
1508
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1509
|
+
assert(err == 0);
|
|
1510
|
+
|
|
1511
|
+
data[0] = frame->handle->time_base.num;
|
|
1512
|
+
data[1] = frame->handle->time_base.den;
|
|
1513
|
+
|
|
1514
|
+
return result;
|
|
1515
|
+
}
|
|
1516
|
+
static void
|
|
1517
|
+
bare_ffmpeg_frame_set_time_base(
|
|
1518
|
+
js_env_t *env,
|
|
1519
|
+
js_receiver_t,
|
|
1520
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame,
|
|
1521
|
+
int num,
|
|
1522
|
+
int den
|
|
1523
|
+
) {
|
|
1524
|
+
frame->handle->time_base.num = num;
|
|
1525
|
+
frame->handle->time_base.den = den;
|
|
1526
|
+
}
|
|
1527
|
+
|
|
1066
1528
|
static void
|
|
1067
1529
|
bare_ffmpeg_frame_alloc(
|
|
1068
1530
|
js_env_t *env,
|
|
@@ -1145,6 +1607,43 @@ bare_ffmpeg_image_fill(
|
|
|
1145
1607
|
}
|
|
1146
1608
|
}
|
|
1147
1609
|
|
|
1610
|
+
static void
|
|
1611
|
+
bare_ffmpeg_image_read(
|
|
1612
|
+
js_env_t *env,
|
|
1613
|
+
js_receiver_t,
|
|
1614
|
+
int32_t pixel_format,
|
|
1615
|
+
int32_t width,
|
|
1616
|
+
int32_t height,
|
|
1617
|
+
int32_t align,
|
|
1618
|
+
js_arraybuffer_span_t data,
|
|
1619
|
+
uint64_t offset,
|
|
1620
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> frame
|
|
1621
|
+
) {
|
|
1622
|
+
uint8_t *dst_data[4];
|
|
1623
|
+
int dst_linesize[4];
|
|
1624
|
+
|
|
1625
|
+
int err = av_image_fill_arrays(
|
|
1626
|
+
dst_data,
|
|
1627
|
+
dst_linesize,
|
|
1628
|
+
&data[offset],
|
|
1629
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
1630
|
+
width,
|
|
1631
|
+
height,
|
|
1632
|
+
align
|
|
1633
|
+
);
|
|
1634
|
+
assert(err >= 0);
|
|
1635
|
+
|
|
1636
|
+
av_image_copy(
|
|
1637
|
+
dst_data,
|
|
1638
|
+
dst_linesize,
|
|
1639
|
+
frame->handle->data,
|
|
1640
|
+
frame->handle->linesize,
|
|
1641
|
+
static_cast<AVPixelFormat>(pixel_format),
|
|
1642
|
+
width,
|
|
1643
|
+
height
|
|
1644
|
+
);
|
|
1645
|
+
}
|
|
1646
|
+
|
|
1148
1647
|
static int
|
|
1149
1648
|
bare_ffmpeg_image_get_line_size(
|
|
1150
1649
|
js_env_t *env,
|
|
@@ -1288,6 +1787,16 @@ bare_ffmpeg_packet_get_stream_index(
|
|
|
1288
1787
|
return packet->handle->stream_index;
|
|
1289
1788
|
}
|
|
1290
1789
|
|
|
1790
|
+
static void
|
|
1791
|
+
bare_ffmpeg_packet_set_stream_index(
|
|
1792
|
+
js_env_t *env,
|
|
1793
|
+
js_receiver_t,
|
|
1794
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1795
|
+
int32_t value
|
|
1796
|
+
) {
|
|
1797
|
+
packet->handle->stream_index = value;
|
|
1798
|
+
}
|
|
1799
|
+
|
|
1291
1800
|
static js_arraybuffer_t
|
|
1292
1801
|
bare_ffmpeg_packet_get_data(
|
|
1293
1802
|
js_env_t *env,
|
|
@@ -1309,6 +1818,177 @@ bare_ffmpeg_packet_get_data(
|
|
|
1309
1818
|
return handle;
|
|
1310
1819
|
}
|
|
1311
1820
|
|
|
1821
|
+
static void
|
|
1822
|
+
bare_ffmpeg_packet_set_data(
|
|
1823
|
+
js_env_t *env,
|
|
1824
|
+
js_receiver_t,
|
|
1825
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1826
|
+
js_arraybuffer_span_t data,
|
|
1827
|
+
uint32_t offset,
|
|
1828
|
+
uint32_t len
|
|
1829
|
+
) {
|
|
1830
|
+
int err;
|
|
1831
|
+
assert(offset + len <= data.size());
|
|
1832
|
+
|
|
1833
|
+
av_packet_unref(packet->handle);
|
|
1834
|
+
|
|
1835
|
+
err = av_new_packet(packet->handle, static_cast<int>(len));
|
|
1836
|
+
assert(err == 0);
|
|
1837
|
+
|
|
1838
|
+
memcpy(packet->handle->data, &data[offset], len);
|
|
1839
|
+
}
|
|
1840
|
+
|
|
1841
|
+
static bool
|
|
1842
|
+
bare_ffmpeg_packet_is_keyframe(
|
|
1843
|
+
js_env_t *,
|
|
1844
|
+
js_receiver_t,
|
|
1845
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1846
|
+
) {
|
|
1847
|
+
return packet->handle->flags & AV_PKT_FLAG_KEY;
|
|
1848
|
+
}
|
|
1849
|
+
|
|
1850
|
+
static int64_t
|
|
1851
|
+
bare_ffmpeg_packet_get_dts(
|
|
1852
|
+
js_env_t *env,
|
|
1853
|
+
js_receiver_t,
|
|
1854
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1855
|
+
) {
|
|
1856
|
+
int64_t ts = packet->handle->dts;
|
|
1857
|
+
|
|
1858
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
1859
|
+
|
|
1860
|
+
return ts;
|
|
1861
|
+
}
|
|
1862
|
+
|
|
1863
|
+
static void
|
|
1864
|
+
bare_ffmpeg_packet_set_dts(
|
|
1865
|
+
js_env_t *env,
|
|
1866
|
+
js_receiver_t,
|
|
1867
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1868
|
+
int64_t value
|
|
1869
|
+
) {
|
|
1870
|
+
packet->handle->dts = value;
|
|
1871
|
+
}
|
|
1872
|
+
|
|
1873
|
+
static int64_t
|
|
1874
|
+
bare_ffmpeg_packet_get_pts(
|
|
1875
|
+
js_env_t *env,
|
|
1876
|
+
js_receiver_t,
|
|
1877
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1878
|
+
) {
|
|
1879
|
+
int64_t ts = packet->handle->pts;
|
|
1880
|
+
|
|
1881
|
+
if (ts == AV_NOPTS_VALUE) return -1;
|
|
1882
|
+
|
|
1883
|
+
return ts;
|
|
1884
|
+
}
|
|
1885
|
+
|
|
1886
|
+
static void
|
|
1887
|
+
bare_ffmpeg_packet_set_pts(
|
|
1888
|
+
js_env_t *env,
|
|
1889
|
+
js_receiver_t,
|
|
1890
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1891
|
+
int64_t value
|
|
1892
|
+
) {
|
|
1893
|
+
packet->handle->pts = value;
|
|
1894
|
+
}
|
|
1895
|
+
|
|
1896
|
+
static js_arraybuffer_t
|
|
1897
|
+
bare_ffmpeg_packet_get_time_base(
|
|
1898
|
+
js_env_t *env,
|
|
1899
|
+
js_receiver_t,
|
|
1900
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1901
|
+
) {
|
|
1902
|
+
int err;
|
|
1903
|
+
|
|
1904
|
+
js_arraybuffer_t result;
|
|
1905
|
+
|
|
1906
|
+
int32_t *data;
|
|
1907
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
1908
|
+
assert(err == 0);
|
|
1909
|
+
|
|
1910
|
+
data[0] = packet->handle->time_base.num;
|
|
1911
|
+
data[1] = packet->handle->time_base.den;
|
|
1912
|
+
|
|
1913
|
+
return result;
|
|
1914
|
+
}
|
|
1915
|
+
|
|
1916
|
+
static void
|
|
1917
|
+
bare_ffmpeg_packet_set_time_base(
|
|
1918
|
+
js_env_t *env,
|
|
1919
|
+
js_receiver_t,
|
|
1920
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1921
|
+
int num,
|
|
1922
|
+
int den
|
|
1923
|
+
) {
|
|
1924
|
+
packet->handle->time_base.num = num;
|
|
1925
|
+
packet->handle->time_base.den = den;
|
|
1926
|
+
}
|
|
1927
|
+
|
|
1928
|
+
static int64_t
|
|
1929
|
+
bare_ffmpeg_packet_rescale_ts(
|
|
1930
|
+
js_env_t *env,
|
|
1931
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1932
|
+
int32_t num,
|
|
1933
|
+
int32_t den
|
|
1934
|
+
) {
|
|
1935
|
+
AVRational src = packet->handle->time_base;
|
|
1936
|
+
AVRational dst = {.num = num, .den = den};
|
|
1937
|
+
|
|
1938
|
+
if (
|
|
1939
|
+
bad_timebase(src) ||
|
|
1940
|
+
bad_timebase(dst) ||
|
|
1941
|
+
packet->handle->dts == AV_NOPTS_VALUE ||
|
|
1942
|
+
packet->handle->pts == AV_NOPTS_VALUE
|
|
1943
|
+
) {
|
|
1944
|
+
return false;
|
|
1945
|
+
}
|
|
1946
|
+
|
|
1947
|
+
av_packet_rescale_ts(packet->handle, src, dst);
|
|
1948
|
+
|
|
1949
|
+
packet->handle->time_base = dst;
|
|
1950
|
+
|
|
1951
|
+
return true;
|
|
1952
|
+
}
|
|
1953
|
+
|
|
1954
|
+
static int64_t
|
|
1955
|
+
bare_ffmpeg_packet_get_duration(
|
|
1956
|
+
js_env_t *env,
|
|
1957
|
+
js_receiver_t,
|
|
1958
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1959
|
+
) {
|
|
1960
|
+
return packet->handle->duration;
|
|
1961
|
+
}
|
|
1962
|
+
|
|
1963
|
+
static void
|
|
1964
|
+
bare_ffmpeg_packet_set_duration(
|
|
1965
|
+
js_env_t *env,
|
|
1966
|
+
js_receiver_t,
|
|
1967
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1968
|
+
int64_t value
|
|
1969
|
+
) {
|
|
1970
|
+
packet->handle->duration = value;
|
|
1971
|
+
}
|
|
1972
|
+
|
|
1973
|
+
static int32_t
|
|
1974
|
+
bare_ffmpeg_packet_get_flags(
|
|
1975
|
+
js_env_t *env,
|
|
1976
|
+
js_receiver_t,
|
|
1977
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet
|
|
1978
|
+
) {
|
|
1979
|
+
return packet->handle->flags;
|
|
1980
|
+
}
|
|
1981
|
+
|
|
1982
|
+
static void
|
|
1983
|
+
bare_ffmpeg_packet_set_flags(
|
|
1984
|
+
js_env_t *env,
|
|
1985
|
+
js_receiver_t,
|
|
1986
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_packet_t, 1> packet,
|
|
1987
|
+
int32_t value
|
|
1988
|
+
) {
|
|
1989
|
+
packet->handle->flags = value;
|
|
1990
|
+
}
|
|
1991
|
+
|
|
1312
1992
|
static js_arraybuffer_t
|
|
1313
1993
|
bare_ffmpeg_scaler_init(
|
|
1314
1994
|
js_env_t *env,
|
|
@@ -1363,6 +2043,9 @@ bare_ffmpeg_scaler_scale(
|
|
|
1363
2043
|
int height,
|
|
1364
2044
|
js_arraybuffer_span_of_t<bare_ffmpeg_frame_t, 1> target
|
|
1365
2045
|
) {
|
|
2046
|
+
int err = av_frame_copy_props(target->handle, source->handle);
|
|
2047
|
+
assert(err == 0);
|
|
2048
|
+
|
|
1366
2049
|
return sws_scale(
|
|
1367
2050
|
scaler->handle,
|
|
1368
2051
|
reinterpret_cast<const uint8_t *const *>(source->handle->data),
|
|
@@ -1593,6 +2276,15 @@ bare_ffmpeg_channel_layout_get_nb_channels(
|
|
|
1593
2276
|
return layout->handle.nb_channels;
|
|
1594
2277
|
}
|
|
1595
2278
|
|
|
2279
|
+
static uint64_t
|
|
2280
|
+
bare_ffmpeg_channel_layout_get_mask(
|
|
2281
|
+
js_env_t *env,
|
|
2282
|
+
js_receiver_t,
|
|
2283
|
+
js_arraybuffer_span_of_t<bare_ffmpeg_channel_layout_t, 1> layout
|
|
2284
|
+
) {
|
|
2285
|
+
return layout->handle.u.mask;
|
|
2286
|
+
}
|
|
2287
|
+
|
|
1596
2288
|
static js_arraybuffer_t
|
|
1597
2289
|
bare_ffmpeg_channel_layout_from_mask(
|
|
1598
2290
|
js_env_t *env,
|
|
@@ -1717,7 +2409,7 @@ bare_ffmpeg_audio_fifo_drain(
|
|
|
1717
2409
|
int32_t nb_samples
|
|
1718
2410
|
) {
|
|
1719
2411
|
int err;
|
|
1720
|
-
|
|
2412
|
+
|
|
1721
2413
|
int len = av_audio_fifo_drain(fifo->handle, nb_samples);
|
|
1722
2414
|
|
|
1723
2415
|
if (len < 0) {
|
|
@@ -1725,7 +2417,7 @@ bare_ffmpeg_audio_fifo_drain(
|
|
|
1725
2417
|
assert(err == 0);
|
|
1726
2418
|
throw js_pending_exception;
|
|
1727
2419
|
}
|
|
1728
|
-
|
|
2420
|
+
|
|
1729
2421
|
return len;
|
|
1730
2422
|
}
|
|
1731
2423
|
|
|
@@ -1756,6 +2448,30 @@ bare_ffmpeg_audio_fifo_space(
|
|
|
1756
2448
|
return av_audio_fifo_space(fifo->handle);
|
|
1757
2449
|
}
|
|
1758
2450
|
|
|
2451
|
+
static js_arraybuffer_t
|
|
2452
|
+
bare_ffmpeg_rational_d2q(
|
|
2453
|
+
js_env_t *env,
|
|
2454
|
+
js_receiver_t,
|
|
2455
|
+
double num
|
|
2456
|
+
) {
|
|
2457
|
+
constexpr int safe_max = 1 << 26;
|
|
2458
|
+
|
|
2459
|
+
auto rational = av_d2q(num, safe_max);
|
|
2460
|
+
|
|
2461
|
+
int err;
|
|
2462
|
+
|
|
2463
|
+
js_arraybuffer_t result;
|
|
2464
|
+
|
|
2465
|
+
int32_t *data;
|
|
2466
|
+
err = js_create_arraybuffer(env, 2, data, result);
|
|
2467
|
+
assert(err == 0);
|
|
2468
|
+
|
|
2469
|
+
data[0] = rational.num;
|
|
2470
|
+
data[1] = rational.den;
|
|
2471
|
+
|
|
2472
|
+
return result;
|
|
2473
|
+
}
|
|
2474
|
+
|
|
1759
2475
|
static js_value_t *
|
|
1760
2476
|
bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
1761
2477
|
uv_once(&bare_ffmpeg__init_guard, bare_ffmpeg__on_init);
|
|
@@ -1766,11 +2482,16 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1766
2482
|
err = js_set_property<fn>(env, exports, name); \
|
|
1767
2483
|
assert(err == 0);
|
|
1768
2484
|
|
|
2485
|
+
V("getLogLevel", bare_ffmpeg_log_get_level);
|
|
2486
|
+
V("setLogLevel", bare_ffmpeg_log_set_level);
|
|
2487
|
+
|
|
1769
2488
|
V("initIOContext", bare_ffmpeg_io_context_init)
|
|
1770
2489
|
V("destroyIOContext", bare_ffmpeg_io_context_destroy)
|
|
1771
2490
|
|
|
1772
2491
|
V("initOutputFormat", bare_ffmpeg_output_format_init)
|
|
1773
2492
|
V("initInputFormat", bare_ffmpeg_input_format_init)
|
|
2493
|
+
V("getOutputFormatFlags", bare_ffmpeg_output_format_get_flags)
|
|
2494
|
+
V("getInputFormatFlags", bare_ffmpeg_input_format_get_flags)
|
|
1774
2495
|
|
|
1775
2496
|
V("openInputFormatContextWithIO", bare_ffmpeg_format_context_open_input_with_io)
|
|
1776
2497
|
V("openInputFormatContextWithFormat", bare_ffmpeg_format_context_open_input_with_format)
|
|
@@ -1781,17 +2502,30 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1781
2502
|
V("getFormatContextBestStreamIndex", bare_ffmpeg_format_context_get_best_stream_index)
|
|
1782
2503
|
V("createFormatContextStream", bare_ffmpeg_format_context_create_stream)
|
|
1783
2504
|
V("readFormatContextFrame", bare_ffmpeg_format_context_read_frame)
|
|
1784
|
-
|
|
1785
|
-
V("
|
|
2505
|
+
V("writeFormatContextHeader", bare_ffmpeg_format_context_write_header)
|
|
2506
|
+
V("writeFormatContextFrame", bare_ffmpeg_format_context_write_frame)
|
|
2507
|
+
V("writeFormatContextTrailer", bare_ffmpeg_format_context_write_trailer)
|
|
2508
|
+
V("dumpFormatContext", bare_ffmpeg_format_context_dump)
|
|
2509
|
+
|
|
2510
|
+
V("getStreamIndex", bare_ffmpeg_stream_get_index)
|
|
2511
|
+
V("getStreamId", bare_ffmpeg_stream_get_id)
|
|
2512
|
+
V("setStreamId", bare_ffmpeg_stream_set_id)
|
|
2513
|
+
V("getStreamTimeBase", bare_ffmpeg_stream_get_time_base)
|
|
2514
|
+
V("setStreamTimeBase", bare_ffmpeg_stream_set_time_base)
|
|
2515
|
+
V("getStreamAverageFramerate", bare_ffmpeg_stream_get_avg_framerate)
|
|
2516
|
+
V("setStreamAverageFramerate", bare_ffmpeg_stream_set_avg_framerate)
|
|
1786
2517
|
V("getStreamCodecParameters", bare_ffmpeg_stream_get_codec_parameters)
|
|
1787
2518
|
|
|
1788
2519
|
V("findDecoderByID", bare_ffmpeg_find_decoder_by_id)
|
|
1789
2520
|
V("findEncoderByID", bare_ffmpeg_find_encoder_by_id)
|
|
2521
|
+
V("getCodecNameByID", bare_ffmpeg_get_codec_name_by_id)
|
|
1790
2522
|
|
|
1791
2523
|
V("initCodecContext", bare_ffmpeg_codec_context_init)
|
|
1792
2524
|
V("destroyCodecContext", bare_ffmpeg_codec_context_destroy)
|
|
1793
2525
|
V("openCodecContext", bare_ffmpeg_codec_context_open)
|
|
1794
2526
|
V("openCodecContextWithOptions", bare_ffmpeg_codec_context_open_with_options)
|
|
2527
|
+
V("getCodecContextFlags", bare_ffmpeg_codec_context_get_flags)
|
|
2528
|
+
V("setCodecContextFlags", bare_ffmpeg_codec_context_set_flags)
|
|
1795
2529
|
V("getCodecContextPixelFormat", bare_ffmpeg_codec_context_get_pixel_format)
|
|
1796
2530
|
V("setCodecContextPixelFormat", bare_ffmpeg_codec_context_set_pixel_format)
|
|
1797
2531
|
V("getCodecContextWidth", bare_ffmpeg_codec_context_get_width)
|
|
@@ -1806,6 +2540,11 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1806
2540
|
V("setCodecContextChannelLayout", bare_ffmpeg_codec_context_set_channel_layout);
|
|
1807
2541
|
V("getCodecContextSampleRate", bare_ffmpeg_codec_context_get_sample_rate);
|
|
1808
2542
|
V("setCodecContextSampleRate", bare_ffmpeg_codec_context_set_sample_rate);
|
|
2543
|
+
V("getCodecContextGOPSize", bare_ffmpeg_codec_context_get_gop_size)
|
|
2544
|
+
V("setCodecContextGOPSize", bare_ffmpeg_codec_context_set_gop_size)
|
|
2545
|
+
V("getCodecContextFramerate", bare_ffmpeg_codec_context_get_framerate)
|
|
2546
|
+
V("setCodecContextFramerate", bare_ffmpeg_codec_context_set_framerate)
|
|
2547
|
+
|
|
1809
2548
|
V("sendCodecContextPacket", bare_ffmpeg_codec_context_send_packet)
|
|
1810
2549
|
V("receiveCodecContextPacket", bare_ffmpeg_codec_context_receive_packet)
|
|
1811
2550
|
V("sendCodecContextFrame", bare_ffmpeg_codec_context_send_frame)
|
|
@@ -1820,7 +2559,11 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1820
2559
|
V("getCodecParametersSampleRate", bare_ffmpeg_codec_parameters_get_sample_rate)
|
|
1821
2560
|
V("getCodecParametersNbChannels", bare_ffmpeg_codec_parameters_get_nb_channels)
|
|
1822
2561
|
V("getCodecParametersCodecType", bare_ffmpeg_codec_parameters_get_codec_type)
|
|
2562
|
+
V("getCodecParametersCodecId", bare_ffmpeg_codec_parameters_get_codec_id)
|
|
1823
2563
|
V("getCodecParametersChannelLayout", bare_ffmpeg_codec_parameters_get_channel_layout)
|
|
2564
|
+
V("getCodecParametersWidth", bare_ffmpeg_codec_parameters_get_width)
|
|
2565
|
+
V("getCodecParametersHeight", bare_ffmpeg_codec_parameters_get_height)
|
|
2566
|
+
V("getCodecParametersFramerate", bare_ffmpeg_codec_parameters_get_framerate)
|
|
1824
2567
|
|
|
1825
2568
|
V("initFrame", bare_ffmpeg_frame_init)
|
|
1826
2569
|
V("destroyFrame", bare_ffmpeg_frame_destroy)
|
|
@@ -1836,10 +2579,18 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1836
2579
|
V("setFrameChannelLayout", bare_ffmpeg_frame_set_channel_layout)
|
|
1837
2580
|
V("getFrameNbSamples", bare_ffmpeg_frame_get_nb_samples)
|
|
1838
2581
|
V("setFrameNbSamples", bare_ffmpeg_frame_set_nb_samples)
|
|
2582
|
+
V("getFramePictType", bare_ffmpeg_frame_get_pict_type)
|
|
2583
|
+
V("getFramePTS", bare_ffmpeg_frame_get_pts)
|
|
2584
|
+
V("setFramePTS", bare_ffmpeg_frame_set_pts)
|
|
2585
|
+
V("getFramePacketDTS", bare_ffmpeg_frame_get_pkt_dts)
|
|
2586
|
+
V("setFramePacketDTS", bare_ffmpeg_frame_set_pkt_dts)
|
|
2587
|
+
V("getFrameTimeBase", bare_ffmpeg_frame_get_time_base)
|
|
2588
|
+
V("setFrameTimeBase", bare_ffmpeg_frame_set_time_base)
|
|
1839
2589
|
V("allocFrame", bare_ffmpeg_frame_alloc)
|
|
1840
2590
|
|
|
1841
2591
|
V("initImage", bare_ffmpeg_image_init)
|
|
1842
2592
|
V("fillImage", bare_ffmpeg_image_fill)
|
|
2593
|
+
V("readImage", bare_ffmpeg_image_read)
|
|
1843
2594
|
V("getImageLineSize", bare_ffmpeg_image_get_line_size)
|
|
1844
2595
|
|
|
1845
2596
|
V("initSamples", bare_ffmpeg_samples_init)
|
|
@@ -1849,7 +2600,21 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1849
2600
|
V("initPacketFromBuffer", bare_ffmpeg_packet_init_from_buffer)
|
|
1850
2601
|
V("unrefPacket", bare_ffmpeg_packet_unref)
|
|
1851
2602
|
V("getPacketStreamIndex", bare_ffmpeg_packet_get_stream_index)
|
|
2603
|
+
V("setPacketStreamIndex", bare_ffmpeg_packet_set_stream_index)
|
|
1852
2604
|
V("getPacketData", bare_ffmpeg_packet_get_data)
|
|
2605
|
+
V("setPacketData", bare_ffmpeg_packet_set_data)
|
|
2606
|
+
V("isPacketKeyframe", bare_ffmpeg_packet_is_keyframe)
|
|
2607
|
+
V("getPacketDTS", bare_ffmpeg_packet_get_dts)
|
|
2608
|
+
V("setPacketDTS", bare_ffmpeg_packet_set_dts)
|
|
2609
|
+
V("getPacketPTS", bare_ffmpeg_packet_get_pts)
|
|
2610
|
+
V("setPacketPTS", bare_ffmpeg_packet_set_pts)
|
|
2611
|
+
V("getPacketTimeBase", bare_ffmpeg_packet_get_time_base)
|
|
2612
|
+
V("setPacketTimeBase", bare_ffmpeg_packet_set_time_base)
|
|
2613
|
+
V("rescalePacketTimestamps", bare_ffmpeg_packet_rescale_ts)
|
|
2614
|
+
V("getPacketDuration", bare_ffmpeg_packet_get_duration)
|
|
2615
|
+
V("setPacketDuration", bare_ffmpeg_packet_set_duration)
|
|
2616
|
+
V("getPacketFlags", bare_ffmpeg_packet_get_flags)
|
|
2617
|
+
V("setPacketFlags", bare_ffmpeg_packet_set_flags)
|
|
1853
2618
|
|
|
1854
2619
|
V("initScaler", bare_ffmpeg_scaler_init)
|
|
1855
2620
|
V("destroyScaler", bare_ffmpeg_scaler_destroy)
|
|
@@ -1868,6 +2633,7 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1868
2633
|
|
|
1869
2634
|
V("copyChannelLayout", bare_ffmpeg_channel_layout_copy)
|
|
1870
2635
|
V("getChannelLayoutNbChannels", bare_ffmpeg_channel_layout_get_nb_channels)
|
|
2636
|
+
V("getChannelLayoutMask", bare_ffmpeg_channel_layout_get_mask)
|
|
1871
2637
|
V("channelLayoutFromMask", bare_ffmpeg_channel_layout_from_mask)
|
|
1872
2638
|
|
|
1873
2639
|
V("initAudioFifo", bare_ffmpeg_audio_fifo_init)
|
|
@@ -1879,6 +2645,8 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1879
2645
|
V("resetAudioFifo", bare_ffmpeg_audio_fifo_reset)
|
|
1880
2646
|
V("getAudioFifoSize", bare_ffmpeg_audio_fifo_size)
|
|
1881
2647
|
V("getAudioFifoSpace", bare_ffmpeg_audio_fifo_space)
|
|
2648
|
+
|
|
2649
|
+
V("rationalD2Q", bare_ffmpeg_rational_d2q)
|
|
1882
2650
|
#undef V
|
|
1883
2651
|
|
|
1884
2652
|
#define V(name) \
|
|
@@ -1890,16 +2658,44 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1890
2658
|
assert(err == 0); \
|
|
1891
2659
|
}
|
|
1892
2660
|
|
|
2661
|
+
V(AV_LOG_QUIET)
|
|
2662
|
+
V(AV_LOG_PANIC)
|
|
2663
|
+
V(AV_LOG_FATAL)
|
|
2664
|
+
V(AV_LOG_ERROR)
|
|
2665
|
+
V(AV_LOG_WARNING)
|
|
2666
|
+
V(AV_LOG_INFO)
|
|
2667
|
+
V(AV_LOG_VERBOSE)
|
|
2668
|
+
V(AV_LOG_DEBUG)
|
|
2669
|
+
V(AV_LOG_TRACE)
|
|
2670
|
+
|
|
1893
2671
|
V(AV_CODEC_ID_MJPEG)
|
|
1894
2672
|
V(AV_CODEC_ID_H264)
|
|
1895
2673
|
V(AV_CODEC_ID_AAC)
|
|
1896
2674
|
V(AV_CODEC_ID_OPUS)
|
|
1897
2675
|
V(AV_CODEC_ID_AV1)
|
|
2676
|
+
V(AV_CODEC_ID_FLAC)
|
|
2677
|
+
V(AV_CODEC_ID_MP3)
|
|
2678
|
+
|
|
2679
|
+
V(AV_CODEC_FLAG_COPY_OPAQUE)
|
|
2680
|
+
V(AV_CODEC_FLAG_FRAME_DURATION)
|
|
2681
|
+
V(AV_CODEC_FLAG_PASS1)
|
|
2682
|
+
V(AV_CODEC_FLAG_PASS2)
|
|
2683
|
+
V(AV_CODEC_FLAG_LOOP_FILTER)
|
|
2684
|
+
V(AV_CODEC_FLAG_GRAY)
|
|
2685
|
+
V(AV_CODEC_FLAG_PSNR)
|
|
2686
|
+
V(AV_CODEC_FLAG_INTERLACED_DCT)
|
|
2687
|
+
V(AV_CODEC_FLAG_LOW_DELAY)
|
|
2688
|
+
V(AV_CODEC_FLAG_GLOBAL_HEADER)
|
|
2689
|
+
V(AV_CODEC_FLAG_BITEXACT)
|
|
2690
|
+
V(AV_CODEC_FLAG_AC_PRED)
|
|
2691
|
+
V(AV_CODEC_FLAG_INTERLACED_ME)
|
|
2692
|
+
V(AV_CODEC_FLAG_CLOSED_GOP)
|
|
1898
2693
|
|
|
1899
2694
|
V(AV_PIX_FMT_RGBA)
|
|
1900
2695
|
V(AV_PIX_FMT_RGB24)
|
|
1901
2696
|
V(AV_PIX_FMT_YUVJ420P)
|
|
1902
2697
|
V(AV_PIX_FMT_YUV420P)
|
|
2698
|
+
V(AV_PIX_FMT_UYVY422)
|
|
1903
2699
|
|
|
1904
2700
|
V(AVMEDIA_TYPE_UNKNOWN)
|
|
1905
2701
|
V(AVMEDIA_TYPE_VIDEO)
|
|
@@ -1932,6 +2728,38 @@ bare_ffmpeg_exports(js_env_t *env, js_value_t *exports) {
|
|
|
1932
2728
|
V(AV_CH_LAYOUT_5POINT0)
|
|
1933
2729
|
V(AV_CH_LAYOUT_5POINT1)
|
|
1934
2730
|
V(AV_CH_LAYOUT_7POINT1)
|
|
2731
|
+
|
|
2732
|
+
V(AV_PICTURE_TYPE_NONE)
|
|
2733
|
+
V(AV_PICTURE_TYPE_I)
|
|
2734
|
+
V(AV_PICTURE_TYPE_P)
|
|
2735
|
+
V(AV_PICTURE_TYPE_B)
|
|
2736
|
+
V(AV_PICTURE_TYPE_S)
|
|
2737
|
+
V(AV_PICTURE_TYPE_SI)
|
|
2738
|
+
V(AV_PICTURE_TYPE_SP)
|
|
2739
|
+
V(AV_PICTURE_TYPE_BI)
|
|
2740
|
+
|
|
2741
|
+
// InputFormat flags
|
|
2742
|
+
V(AVFMT_SHOW_IDS)
|
|
2743
|
+
V(AVFMT_GENERIC_INDEX)
|
|
2744
|
+
V(AVFMT_TS_DISCONT)
|
|
2745
|
+
V(AVFMT_NOBINSEARCH)
|
|
2746
|
+
V(AVFMT_NOGENSEARCH)
|
|
2747
|
+
V(AVFMT_NO_BYTE_SEEK)
|
|
2748
|
+
V(AVFMT_SEEK_TO_PTS)
|
|
2749
|
+
|
|
2750
|
+
// OutputFormat flags
|
|
2751
|
+
V(AVFMT_GLOBALHEADER)
|
|
2752
|
+
V(AVFMT_VARIABLE_FPS)
|
|
2753
|
+
V(AVFMT_NODIMENSIONS)
|
|
2754
|
+
V(AVFMT_NOSTREAMS)
|
|
2755
|
+
V(AVFMT_TS_NONSTRICT)
|
|
2756
|
+
V(AVFMT_TS_NEGATIVE)
|
|
2757
|
+
|
|
2758
|
+
// Common format flags
|
|
2759
|
+
V(AVFMT_NOFILE)
|
|
2760
|
+
V(AVFMT_NEEDNUMBER)
|
|
2761
|
+
V(AVFMT_NOTIMESTAMPS)
|
|
2762
|
+
|
|
1935
2763
|
#undef V
|
|
1936
2764
|
|
|
1937
2765
|
return exports;
|