bare-ffmpeg 1.0.0-22 → 1.0.0-24
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/CMakeLists.txt +1 -1
- package/README.md +15 -0
- package/binding.cc +23 -23
- package/cmake/ports/ffmpeg/port.cmake +1 -0
- package/lib/codec.js +0 -1
- package/lib/constants.js +0 -6
- package/lib/dictionary.js +10 -0
- package/lib/io-context.js +10 -9
- 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/CMakeLists.txt
CHANGED
package/README.md
CHANGED
|
@@ -108,6 +108,21 @@ for (const [key, value] of dict) {
|
|
|
108
108
|
}
|
|
109
109
|
```
|
|
110
110
|
|
|
111
|
+
#### Static methods
|
|
112
|
+
|
|
113
|
+
##### `Dictionary.from(object)`
|
|
114
|
+
|
|
115
|
+
A helper to create a `Dictionary` instance from an object.
|
|
116
|
+
|
|
117
|
+
```js
|
|
118
|
+
const dict = ffmpeg.Dictionary.from({
|
|
119
|
+
foo: 'bar',
|
|
120
|
+
baz: 'qux'
|
|
121
|
+
})
|
|
122
|
+
```
|
|
123
|
+
|
|
124
|
+
**Returns**: A new `Dictionary` instance
|
|
125
|
+
|
|
111
126
|
### `FormatContext`
|
|
112
127
|
|
|
113
128
|
The `FormatContext` API provides the base functionality for reading and writing media files.
|
package/binding.cc
CHANGED
|
@@ -34,8 +34,8 @@ extern "C" {
|
|
|
34
34
|
}
|
|
35
35
|
|
|
36
36
|
using bare_ffmpeg_io_context_write_cb_t = js_function_t<void, js_arraybuffer_t>;
|
|
37
|
-
using bare_ffmpeg_io_context_read_cb_t = js_function_t<int32_t,
|
|
38
|
-
using bare_ffmpeg_io_context_seek_cb_t = js_function_t<
|
|
37
|
+
using bare_ffmpeg_io_context_read_cb_t = js_function_t<int32_t, js_arraybuffer_t, int32_t>;
|
|
38
|
+
using bare_ffmpeg_io_context_seek_cb_t = js_function_t<int64_t, int64_t, std::string>;
|
|
39
39
|
|
|
40
40
|
typedef struct {
|
|
41
41
|
AVIOContext *handle;
|
|
@@ -45,8 +45,6 @@ typedef struct {
|
|
|
45
45
|
js_persistent_t<bare_ffmpeg_io_context_write_cb_t> on_write;
|
|
46
46
|
js_persistent_t<bare_ffmpeg_io_context_read_cb_t> on_read;
|
|
47
47
|
js_persistent_t<bare_ffmpeg_io_context_seek_cb_t> on_seek;
|
|
48
|
-
|
|
49
|
-
int64_t offset;
|
|
50
48
|
} bare_ffmpeg_io_context_t;
|
|
51
49
|
|
|
52
50
|
typedef struct {
|
|
@@ -168,24 +166,17 @@ bare_ffmpeg__on_io_context_read(void *opaque, uint8_t *buf, int len) {
|
|
|
168
166
|
err = js_create_external_arraybuffer(env, buf, static_cast<size_t>(len), arraybuffer);
|
|
169
167
|
assert(err == 0);
|
|
170
168
|
|
|
171
|
-
js_typedarray_t<uint8_t> uint8array;
|
|
172
|
-
err = js_create_typedarray(env, static_cast<size_t>(len), arraybuffer, uint8array);
|
|
173
|
-
assert(err == 0);
|
|
174
|
-
|
|
175
169
|
int32_t result;
|
|
176
|
-
|
|
177
|
-
assert(err == 0);
|
|
170
|
+
int call_status = js_call_function<js_type_options_t{}, int32_t, js_arraybuffer_t, int32_t>(env, callback, arraybuffer, len, result);
|
|
178
171
|
|
|
179
172
|
err = js_detach_arraybuffer(env, arraybuffer);
|
|
180
173
|
assert(err == 0);
|
|
181
174
|
|
|
182
|
-
if (
|
|
183
|
-
|
|
184
|
-
if (result > len) result = len;
|
|
175
|
+
if (call_status < 0) return AVERROR(EIO);
|
|
185
176
|
|
|
186
|
-
|
|
177
|
+
if (result == 0) return AVERROR_EOF;
|
|
187
178
|
|
|
188
|
-
return
|
|
179
|
+
return result;
|
|
189
180
|
}
|
|
190
181
|
|
|
191
182
|
static int64_t
|
|
@@ -197,27 +188,37 @@ bare_ffmpeg__on_io_context_seek(void *opaque, int64_t offset, int whence) {
|
|
|
197
188
|
auto env = context->env;
|
|
198
189
|
|
|
199
190
|
int64_t result;
|
|
200
|
-
|
|
191
|
+
std::string whence_str;
|
|
201
192
|
switch (whence) {
|
|
193
|
+
case AVSEEK_SIZE:
|
|
194
|
+
whence_str = "avseek_size";
|
|
195
|
+
break;
|
|
196
|
+
case AVSEEK_FORCE:
|
|
197
|
+
whence_str = "avseek_force";
|
|
198
|
+
break;
|
|
202
199
|
case SEEK_SET:
|
|
203
|
-
|
|
200
|
+
whence_str = "seek_set";
|
|
204
201
|
break;
|
|
205
202
|
case SEEK_CUR:
|
|
206
|
-
|
|
203
|
+
whence_str = "seek_cur";
|
|
207
204
|
break;
|
|
208
205
|
case SEEK_END:
|
|
206
|
+
whence_str = "seek_end";
|
|
207
|
+
break;
|
|
209
208
|
default:
|
|
210
|
-
|
|
209
|
+
whence_str = "unknown:" + std::to_string(whence);
|
|
211
210
|
}
|
|
212
211
|
|
|
213
212
|
bare_ffmpeg_io_context_seek_cb_t callback;
|
|
214
213
|
err = js_get_reference_value(env, context->on_seek, callback);
|
|
215
214
|
assert(err == 0);
|
|
216
215
|
|
|
217
|
-
err = js_call_function(env, callback, result);
|
|
218
|
-
|
|
216
|
+
err = js_call_function<js_type_options_t{}, int64_t, int64_t, std::string>(env, callback, offset, whence_str, result);
|
|
217
|
+
if (err < 0) return AVERROR(EIO); // read-error
|
|
219
218
|
|
|
220
|
-
|
|
219
|
+
if (result == -1) {
|
|
220
|
+
return AVERROR(ENOSYS); // seek-op not supported by IO
|
|
221
|
+
}
|
|
221
222
|
|
|
222
223
|
return result;
|
|
223
224
|
}
|
|
@@ -242,7 +243,6 @@ bare_ffmpeg_io_context_init(
|
|
|
242
243
|
assert(err == 0);
|
|
243
244
|
|
|
244
245
|
context->env = env;
|
|
245
|
-
context->offset = 0;
|
|
246
246
|
|
|
247
247
|
int writable = 0;
|
|
248
248
|
|
package/lib/codec.js
CHANGED
|
@@ -51,7 +51,6 @@ module.exports = class FFmpegCodec {
|
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
static MJPEG = this.for(constants.codecs.MJPEG)
|
|
54
|
-
static H264 = this.for(constants.codecs.H264)
|
|
55
54
|
static AAC = this.for(constants.codecs.AAC)
|
|
56
55
|
static OPUS = this.for(constants.codecs.OPUS)
|
|
57
56
|
static AV1 = this.for(constants.codecs.AV1)
|
package/lib/constants.js
CHANGED
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
2
|
const errors = require('./errors')
|
|
3
3
|
|
|
4
|
-
// Helpers
|
|
5
4
|
function makeTag(a, b, c, d) {
|
|
6
5
|
return (
|
|
7
6
|
a.charCodeAt(0) |
|
|
@@ -14,7 +13,6 @@ function makeTag(a, b, c, d) {
|
|
|
14
13
|
module.exports = exports = {
|
|
15
14
|
codecs: {
|
|
16
15
|
MJPEG: binding.AV_CODEC_ID_MJPEG,
|
|
17
|
-
H264: binding.AV_CODEC_ID_H264,
|
|
18
16
|
AAC: binding.AV_CODEC_ID_AAC,
|
|
19
17
|
OPUS: binding.AV_CODEC_ID_OPUS,
|
|
20
18
|
AV1: binding.AV_CODEC_ID_AV1,
|
|
@@ -22,11 +20,7 @@ module.exports = exports = {
|
|
|
22
20
|
MP3: binding.AV_CODEC_ID_MP3
|
|
23
21
|
},
|
|
24
22
|
tags: {
|
|
25
|
-
// Source Ref:
|
|
26
|
-
// https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/riff.c#L36
|
|
27
|
-
// https://github.com/FFmpeg/FFmpeg/blob/master/libavformat/riff.c#L530
|
|
28
23
|
MJPEG: makeTag('M', 'J', 'P', 'G'),
|
|
29
|
-
H264: makeTag('H', '2', '6', '4'),
|
|
30
24
|
AV1: makeTag('A', 'V', '0', '1'),
|
|
31
25
|
AAC: 0x00ff,
|
|
32
26
|
FLAC: 0xf1ac,
|
package/lib/dictionary.js
CHANGED
|
@@ -1,6 +1,16 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
2
|
|
|
3
3
|
module.exports = class FFmpegDictionary {
|
|
4
|
+
static from(obj) {
|
|
5
|
+
const dictionary = new FFmpegDictionary()
|
|
6
|
+
|
|
7
|
+
for (const [key, value] of Object.entries(obj)) {
|
|
8
|
+
dictionary.set(key, value)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
return dictionary
|
|
12
|
+
}
|
|
13
|
+
|
|
4
14
|
constructor() {
|
|
5
15
|
this._handle = binding.initDictionary()
|
|
6
16
|
}
|
package/lib/io-context.js
CHANGED
|
@@ -16,19 +16,12 @@ module.exports = class FFmpegIOContext {
|
|
|
16
16
|
buffer = Buffer.alloc(0)
|
|
17
17
|
}
|
|
18
18
|
|
|
19
|
-
let onwrite
|
|
20
|
-
if (opts.onwrite) {
|
|
21
|
-
onwrite = (chunk) => {
|
|
22
|
-
opts.onwrite(Buffer.from(chunk))
|
|
23
|
-
}
|
|
24
|
-
}
|
|
25
|
-
|
|
26
19
|
this._handle = binding.initIOContext(
|
|
27
20
|
buffer,
|
|
28
21
|
offset,
|
|
29
22
|
len,
|
|
30
|
-
onwrite,
|
|
31
|
-
opts.onread,
|
|
23
|
+
opts.onwrite && onwriteWrapper.bind(null, opts.onwrite),
|
|
24
|
+
opts.onread && onreadWrapper.bind(null, opts.onread),
|
|
32
25
|
opts.onseek
|
|
33
26
|
)
|
|
34
27
|
}
|
|
@@ -42,3 +35,11 @@ module.exports = class FFmpegIOContext {
|
|
|
42
35
|
this.destroy()
|
|
43
36
|
}
|
|
44
37
|
}
|
|
38
|
+
|
|
39
|
+
function onwriteWrapper(target, arraybuffer) {
|
|
40
|
+
return target(Buffer.from(arraybuffer))
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function onreadWrapper(target, arraybuffer, requestedLen) {
|
|
44
|
+
return target(Buffer.from(arraybuffer), requestedLen)
|
|
45
|
+
}
|
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
|