bare-ffmpeg 1.0.0-22 → 1.0.0-23

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 CHANGED
@@ -8,7 +8,7 @@ project(bare_ffmpeg C CXX)
8
8
 
9
9
  fetch_package("github:holepunchto/libjstl#5b85a24")
10
10
 
11
- find_port(ffmpeg FEATURES gpl dav1d svt-av1 x264 opus)
11
+ find_port(ffmpeg FEATURES dav1d svt-av1 opus)
12
12
 
13
13
  add_bare_module(bare_ffmpeg)
14
14
 
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
@@ -33,9 +33,9 @@ extern "C" {
33
33
  #include <libswscale/swscale.h>
34
34
  }
35
35
 
36
- using bare_ffmpeg_io_context_write_cb_t = js_function_t<void, js_arraybuffer_t>;
36
+ using bare_ffmpeg_io_context_write_cb_t = js_function_t<void, js_typedarray_t<uint8_t>>;
37
37
  using bare_ffmpeg_io_context_read_cb_t = js_function_t<int32_t, js_typedarray_t<uint8_t>, int32_t>;
38
- using bare_ffmpeg_io_context_seek_cb_t = js_function_t<void, int64_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 {
@@ -146,7 +144,12 @@ bare_ffmpeg__on_io_context_write(void *opaque, const uint8_t *buf, int len) {
146
144
  err = js_create_arraybuffer(env, buf, static_cast<size_t>(len), data);
147
145
  assert(err == 0);
148
146
 
149
- err = js_call_function(env, callback, data);
147
+ js_typedarray_t<uint8_t> view;
148
+ err = js_create_typedarray(env, static_cast<size_t>(len), data, view);
149
+ assert(err == 0);
150
+
151
+
152
+ err = js_call_function(env, callback, view);
150
153
  assert(err == 0);
151
154
 
152
155
  return 0;
@@ -168,24 +171,21 @@ bare_ffmpeg__on_io_context_read(void *opaque, uint8_t *buf, int len) {
168
171
  err = js_create_external_arraybuffer(env, buf, static_cast<size_t>(len), arraybuffer);
169
172
  assert(err == 0);
170
173
 
171
- js_typedarray_t<uint8_t> uint8array;
172
- err = js_create_typedarray(env, static_cast<size_t>(len), arraybuffer, uint8array);
174
+ js_typedarray_t<uint8_t> view;
175
+ err = js_create_typedarray(env, static_cast<size_t>(len), arraybuffer, view);
173
176
  assert(err == 0);
174
177
 
175
178
  int32_t result;
176
- err = js_call_function<js_type_options_t{}, int32_t, js_typedarray_t<uint8_t>, int32_t>(env, callback, uint8array, len, result);
177
- assert(err == 0);
179
+ int call_status = js_call_function<js_type_options_t{}, int32_t, js_typedarray_t<uint8_t>, int32_t>(env, callback, view, len, result);
178
180
 
179
181
  err = js_detach_arraybuffer(env, arraybuffer);
180
182
  assert(err == 0);
181
183
 
182
- if (result == 0) return AVERROR_EOF;
183
-
184
- if (result > len) result = len;
184
+ if (call_status < 0) return AVERROR(EIO);
185
185
 
186
- context->offset += static_cast<int64_t>(result);
186
+ if (result == 0) return AVERROR_EOF;
187
187
 
188
- return static_cast<int>(result);
188
+ return result;
189
189
  }
190
190
 
191
191
  static int64_t
@@ -197,27 +197,37 @@ bare_ffmpeg__on_io_context_seek(void *opaque, int64_t offset, int whence) {
197
197
  auto env = context->env;
198
198
 
199
199
  int64_t result;
200
-
200
+ std::string whence_str;
201
201
  switch (whence) {
202
+ case AVSEEK_SIZE:
203
+ whence_str = "avseek_size";
204
+ break;
205
+ case AVSEEK_FORCE:
206
+ whence_str = "avseek_force";
207
+ break;
202
208
  case SEEK_SET:
203
- result = offset;
209
+ whence_str = "seek_set";
204
210
  break;
205
211
  case SEEK_CUR:
206
- result = context->offset + offset;
212
+ whence_str = "seek_cur";
207
213
  break;
208
214
  case SEEK_END:
215
+ whence_str = "seek_end";
216
+ break;
209
217
  default:
210
- return -1;
218
+ whence_str = "unknown:" + std::to_string(whence);
211
219
  }
212
220
 
213
221
  bare_ffmpeg_io_context_seek_cb_t callback;
214
222
  err = js_get_reference_value(env, context->on_seek, callback);
215
223
  assert(err == 0);
216
224
 
217
- err = js_call_function(env, callback, result);
218
- assert(err == 0);
225
+ err = js_call_function<js_type_options_t{}, int64_t, int64_t, std::string>(env, callback, offset, whence_str, result);
226
+ if (err < 0) return AVERROR(EIO); // read-error
219
227
 
220
- context->offset = result;
228
+ if (result == -1) {
229
+ return AVERROR(ENOSYS); // seek-op not supported by IO
230
+ }
221
231
 
222
232
  return result;
223
233
  }
@@ -242,7 +252,6 @@ bare_ffmpeg_io_context_init(
242
252
  assert(err == 0);
243
253
 
244
254
  context->env = env;
245
- context->offset = 0;
246
255
 
247
256
  int writable = 0;
248
257
 
@@ -285,6 +285,7 @@ if(CMAKE_HOST_WIN32)
285
285
  find_path(
286
286
  msys2
287
287
  NAMES msys2.exe
288
+ PATHS "C:/tools/msys64"
288
289
  REQUIRED
289
290
  )
290
291
 
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,18 +16,11 @@ 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,
23
+ opts.onwrite,
31
24
  opts.onread,
32
25
  opts.onseek
33
26
  )
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ffmpeg",
3
- "version": "1.0.0-22",
3
+ "version": "1.0.0-23",
4
4
  "description": "Low-level FFmpeg bindings for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",