bare-ffmpeg 1.0.0-8 → 1.0.0

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.
Files changed (58) hide show
  1. package/CMakeLists.txt +32 -10
  2. package/README.md +65 -769
  3. package/binding.cc +5372 -0
  4. package/cmake/ports/ffmpeg/port.cmake +513 -0
  5. package/cmake/ports/libdrm/port.cmake +32 -0
  6. package/cmake/ports/libva/port.cmake +53 -0
  7. package/cmake/ports/opus/patches/01-windows-clang.patch +52 -0
  8. package/cmake/ports/opus/port.cmake +42 -0
  9. package/cmake/ports/svt-av1/port.cmake +42 -0
  10. package/cmake/ports/x264/patches/01-windows-clang.patch +33 -0
  11. package/cmake/ports/x264/port.cmake +162 -0
  12. package/index.js +28 -9
  13. package/lib/audio-fifo.js +47 -0
  14. package/lib/channel-layout.js +35 -0
  15. package/lib/codec-context.js +185 -7
  16. package/lib/codec-parameters.js +252 -4
  17. package/lib/codec.js +17 -0
  18. package/lib/constants.js +340 -12
  19. package/lib/dictionary.js +20 -0
  20. package/lib/errors.js +26 -0
  21. package/lib/filter-context.js +7 -0
  22. package/lib/filter-graph.js +42 -0
  23. package/lib/filter-inout.js +52 -0
  24. package/lib/filter.js +7 -0
  25. package/lib/format-context.js +43 -23
  26. package/lib/frame.js +81 -12
  27. package/lib/hw-device-context.js +31 -0
  28. package/lib/hw-frames-constraints.js +54 -0
  29. package/lib/hw-frames-context.js +92 -0
  30. package/lib/image.js +14 -3
  31. package/lib/input-format.js +36 -2
  32. package/lib/io-context.js +29 -4
  33. package/lib/log.js +16 -0
  34. package/lib/output-format.js +33 -2
  35. package/lib/packet.js +143 -1
  36. package/lib/rational.js +46 -1
  37. package/lib/resampler.js +23 -17
  38. package/lib/samples.js +85 -0
  39. package/lib/scaler.js +3 -9
  40. package/lib/stream.js +51 -14
  41. package/package.json +9 -5
  42. package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
  43. package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
  44. package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
  45. package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
  46. package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
  47. package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
  48. package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
  49. package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
  50. package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
  51. package/prebuilds/linux-arm64/bare-ffmpeg/libva-drm.so.2 +0 -0
  52. package/prebuilds/linux-arm64/bare-ffmpeg/libva.so.2 +0 -0
  53. package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
  54. package/prebuilds/linux-x64/bare-ffmpeg/libva-drm.so.2 +0 -0
  55. package/prebuilds/linux-x64/bare-ffmpeg/libva.so.2 +0 -0
  56. package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
  57. package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
  58. package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
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
  }
@@ -17,9 +27,19 @@ module.exports = class FFmpegDictionary {
17
27
  }
18
28
 
19
29
  set(key, value) {
30
+ if (typeof value !== 'string') value = String(value)
31
+
20
32
  binding.setDictionaryEntry(this._handle, key, value)
21
33
  }
22
34
 
35
+ entries() {
36
+ return binding.getDictionaryEntries(this._handle)
37
+ }
38
+
39
+ *[Symbol.iterator]() {
40
+ yield* this.entries()
41
+ }
42
+
23
43
  [Symbol.dispose]() {
24
44
  this.destroy()
25
45
  }
package/lib/errors.js ADDED
@@ -0,0 +1,26 @@
1
+ module.exports = class FFmpegError extends Error {
2
+ constructor(msg, code, fn = FFmpegError) {
3
+ super(`${code}: ${msg}`)
4
+ this.code = code
5
+
6
+ if (Error.captureStackTrace) {
7
+ Error.captureStackTrace(this, fn)
8
+ }
9
+ }
10
+
11
+ get name() {
12
+ return 'FFmpegError'
13
+ }
14
+
15
+ static UNKNOWN_PIXEL_FORMAT(msg) {
16
+ return new FFmpegError(msg, 'UNKNOWN_PIXEL_FORMAT', FFmpegError.UNKNOWN_PIXEL_FORMAT)
17
+ }
18
+
19
+ static UNKNOWN_SAMPLE_FORMAT(msg) {
20
+ return new FFmpegError(msg, 'UNKNOWN_SAMPLE_FORMAT', FFmpegError.UNKNOWN_SAMPLE_FORMAT)
21
+ }
22
+
23
+ static UNKNOWN_CHANNEL_LAYOUT(msg) {
24
+ return new FFmpegError(msg, 'UNKNOWN_CHANNEL_LAYOUT', FFmpegError.UNKNOWN_CHANNEL_LAYOUT)
25
+ }
26
+ }
@@ -0,0 +1,7 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FilterContext {
4
+ constructor() {
5
+ this._handle = binding.initFilterContext()
6
+ }
7
+ }
@@ -0,0 +1,42 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FilterGraph {
4
+ constructor() {
5
+ this._handle = binding.initFilterGraph()
6
+ }
7
+
8
+ destroy() {
9
+ binding.destroyFilterGraph(this._handle)
10
+ this._handle = null
11
+ }
12
+
13
+ createFilter(context, filter, name, args) {
14
+ return binding.createFilterGraphFilter(
15
+ this._handle,
16
+ context._handle,
17
+ filter._handle,
18
+ name,
19
+ args ?? undefined
20
+ )
21
+ }
22
+
23
+ parse(filterDescription, inputs, outputs) {
24
+ binding.parseFilterGraph(this._handle, inputs._handle, outputs._handle, filterDescription)
25
+ }
26
+
27
+ configure() {
28
+ binding.configureFilterGraph(this._handle)
29
+ }
30
+
31
+ pushFrame(ctx, frame) {
32
+ return binding.pushFilterGraphFrame(ctx._handle, frame._handle)
33
+ }
34
+
35
+ pullFrame(ctx, frame) {
36
+ return binding.pullFilterGraphFrame(ctx._handle, frame._handle)
37
+ }
38
+
39
+ [Symbol.dispose]() {
40
+ this.destroy()
41
+ }
42
+ }
@@ -0,0 +1,52 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FilterInOut {
4
+ constructor(handle = binding.initFilterInout()) {
5
+ this._handle = handle
6
+ this._next = null
7
+ this._filterContext = null
8
+ }
9
+
10
+ destroy() {
11
+ binding.destroyFilterInOut(this._handle)
12
+ this._handle = null
13
+ }
14
+
15
+ get name() {
16
+ return binding.getFilterInOutName(this._handle)
17
+ }
18
+
19
+ set name(value) {
20
+ return binding.setFilterInOutName(this._handle, value)
21
+ }
22
+
23
+ get filterContext() {
24
+ return this._filterContext
25
+ }
26
+
27
+ set filterContext(value) {
28
+ this._filterContext = value
29
+ return binding.setFilterInOutFilterContext(this._handle, this._filterContext._handle)
30
+ }
31
+
32
+ get padIdx() {
33
+ return binding.getFilterInOutPadIdx(this._handle)
34
+ }
35
+
36
+ set padIdx(value) {
37
+ return binding.setFilterInOutPadIdx(this._handle, value)
38
+ }
39
+
40
+ get next() {
41
+ return this._next
42
+ }
43
+
44
+ set next(value) {
45
+ this._next = value
46
+ return binding.setFilterInOutNext(this._handle, this._next._handle)
47
+ }
48
+
49
+ [Symbol.dispose]() {
50
+ this.destroy()
51
+ }
52
+ }
package/lib/filter.js ADDED
@@ -0,0 +1,7 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class Filter {
4
+ constructor(name) {
5
+ this._handle = binding.getFilterByName(name)
6
+ }
7
+ }
@@ -4,6 +4,7 @@ const OutputFormat = require('./output-format')
4
4
  const IOContext = require('./io-context')
5
5
  const InputFormat = require('./input-format')
6
6
  const Dictionary = require('./dictionary')
7
+ /** @typedef {import('./packet')} Packet */
7
8
 
8
9
  class FFmpegFormatContext {
9
10
  constructor(io) {
@@ -16,9 +17,6 @@ class FFmpegFormatContext {
16
17
  this._io.destroy()
17
18
  this._io = null
18
19
  }
19
-
20
- for (const stream of this._streams) stream.destroy()
21
- this._streams = []
22
20
  }
23
21
 
24
22
  get io() {
@@ -45,15 +43,13 @@ class FFmpegFormatContext {
45
43
  return this._streams[index]
46
44
  }
47
45
 
46
+ /** @returns {Stream|null} */
48
47
  getBestStream(type) {
49
- if (this._streams.length == 0) {
48
+ if (this._streams.length === 0) {
50
49
  return null
51
50
  }
52
51
 
53
- const bestIndex = binding.getFormatContextBestStreamIndex(
54
- this._handle,
55
- type
56
- )
52
+ const bestIndex = binding.getFormatContextBestStreamIndex(this._handle, type)
57
53
 
58
54
  if (bestIndex < 0 || bestIndex >= this._streams.length) {
59
55
  return null
@@ -71,6 +67,7 @@ let defaultURL = null
71
67
 
72
68
  switch (Bare.platform) {
73
69
  case 'darwin':
70
+ case 'ios':
74
71
  defaultURL = '0:0'
75
72
  break
76
73
  case 'linux':
@@ -84,9 +81,7 @@ switch (Bare.platform) {
84
81
  break
85
82
  }
86
83
 
87
- exports.InputFormatContext = class FFmpegInputFormatContext extends (
88
- FFmpegFormatContext
89
- ) {
84
+ exports.InputFormatContext = class FFmpegInputFormatContext extends FFmpegFormatContext {
90
85
  constructor(io, options, url = defaultURL) {
91
86
  if (io instanceof IOContext) {
92
87
  super(io)
@@ -97,11 +92,7 @@ exports.InputFormatContext = class FFmpegInputFormatContext extends (
97
92
 
98
93
  options = options || new Dictionary()
99
94
 
100
- this._handle = binding.openInputFormatContextWithFormat(
101
- io._handle,
102
- options._handle,
103
- url
104
- )
95
+ this._handle = binding.openInputFormatContextWithFormat(io._handle, options._handle, url)
105
96
 
106
97
  options.destroy()
107
98
  }
@@ -117,17 +108,25 @@ exports.InputFormatContext = class FFmpegInputFormatContext extends (
117
108
  binding.closeInputFormatContext(this._handle)
118
109
  this._handle = null
119
110
  }
111
+
112
+ dump(printIdx = 0, printUrl = '') {
113
+ binding.dumpFormatContext(this._handle, false, printIdx, printUrl)
114
+ }
115
+
116
+ get inputFormat() {
117
+ const handle = binding.getFormatContextInputFormat(this._handle)
118
+ if (handle) return InputFormat.from(handle)
119
+ }
120
120
  }
121
121
 
122
- exports.OutputFormatContext = class FFmpegOutputFormatContext extends (
123
- FFmpegFormatContext
124
- ) {
122
+ exports.OutputFormatContext = class FFmpegOutputFormatContext extends FFmpegFormatContext {
125
123
  constructor(format, io) {
126
124
  super(io)
127
125
 
128
126
  if (typeof format === 'string') format = new OutputFormat(format)
129
127
 
130
128
  this._handle = binding.openOutputFormatContext(format._handle, io._handle)
129
+ this._isOutput = true
131
130
  }
132
131
 
133
132
  destroy() {
@@ -137,13 +136,34 @@ exports.OutputFormatContext = class FFmpegOutputFormatContext extends (
137
136
  this._handle = null
138
137
  }
139
138
 
140
- createStream(codec) {
141
- const stream = new Stream(
142
- binding.createFormatContextStream(this._handle, codec._handle)
143
- )
139
+ createStream() {
140
+ const stream = new Stream(binding.createFormatContextStream(this._handle))
144
141
 
145
142
  this._streams.push(stream)
146
143
 
147
144
  return stream
148
145
  }
146
+
147
+ /** @param {Dictionary} [options] format options */
148
+ writeHeader(options) {
149
+ binding.writeFormatContextHeader(this._handle, options?._handle)
150
+ }
151
+
152
+ /** @param {Packet} packet */
153
+ writeFrame(packet) {
154
+ binding.writeFormatContextFrame(this._handle, packet._handle)
155
+ }
156
+
157
+ writeTrailer() {
158
+ binding.writeFormatContextTrailer(this._handle)
159
+ }
160
+
161
+ dump(printIdx = 0, printUrl = '') {
162
+ binding.dumpFormatContext(this._handle, true, printIdx, printUrl)
163
+ }
164
+
165
+ get outputFormat() {
166
+ const handle = binding.getFormatContextOutputFormat(this._handle)
167
+ if (handle) return OutputFormat.from(handle)
168
+ }
149
169
  }
package/lib/frame.js CHANGED
@@ -1,4 +1,8 @@
1
1
  const binding = require('../binding')
2
+ const ChannelLayout = require('./channel-layout')
3
+ const HWFramesContext = require('./hw-frames-context')
4
+ const Rational = require('./rational')
5
+ const constants = require('./constants')
2
6
 
3
7
  module.exports = class FFmpegFrame {
4
8
  constructor() {
@@ -10,6 +14,10 @@ module.exports = class FFmpegFrame {
10
14
  this._handle = null
11
15
  }
12
16
 
17
+ unref() {
18
+ binding.unrefFrame(this._handle)
19
+ }
20
+
13
21
  get width() {
14
22
  return binding.getFrameWidth(this._handle)
15
23
  }
@@ -26,14 +34,6 @@ module.exports = class FFmpegFrame {
26
34
  binding.setFrameHeight(this._handle, value)
27
35
  }
28
36
 
29
- get pixelFormat() {
30
- return binding.getFramePixelFormat(this._handle)
31
- }
32
-
33
- set pixelFormat(value) {
34
- binding.setFramePixelFormat(this._handle, value)
35
- }
36
-
37
37
  get format() {
38
38
  return binding.getFrameFormat(this._handle)
39
39
  }
@@ -43,11 +43,11 @@ module.exports = class FFmpegFrame {
43
43
  }
44
44
 
45
45
  get channelLayout() {
46
- return binding.getFrameChannelLayout(this._handle)
46
+ return new ChannelLayout(binding.getFrameChannelLayout(this._handle))
47
47
  }
48
48
 
49
49
  set channelLayout(value) {
50
- binding.setFrameChannelLayout(this._handle, value)
50
+ binding.setFrameChannelLayout(this._handle, ChannelLayout.from(value)._handle)
51
51
  }
52
52
 
53
53
  get nbSamples() {
@@ -58,8 +58,62 @@ module.exports = class FFmpegFrame {
58
58
  binding.setFrameNbSamples(this._handle, value)
59
59
  }
60
60
 
61
- audioChannel() {
62
- return binding.getFrameAudioChannel(this._handle)
61
+ get pictType() {
62
+ return binding.getFramePictType(this._handle)
63
+ }
64
+
65
+ get pts() {
66
+ return binding.getFramePTS(this._handle)
67
+ }
68
+
69
+ set pts(value) {
70
+ return binding.setFramePTS(this._handle, value)
71
+ }
72
+
73
+ get packetDTS() {
74
+ return binding.getFramePacketDTS(this._handle)
75
+ }
76
+
77
+ set packetDTS(value) {
78
+ return binding.setFramePacketDTS(this._handle, value)
79
+ }
80
+
81
+ get timeBase() {
82
+ const view = new Int32Array(binding.getFrameTimeBase(this._handle))
83
+ return new Rational(view[0], view[1])
84
+ }
85
+
86
+ set timeBase(value) {
87
+ binding.setFrameTimeBase(this._handle, value.numerator, value.denominator)
88
+ }
89
+
90
+ get sampleRate() {
91
+ return binding.getFrameSampleRate(this._handle)
92
+ }
93
+
94
+ set sampleRate(value) {
95
+ binding.setFrameSampleRate(this._handle, value)
96
+ }
97
+
98
+ get hwFramesCtx() {
99
+ const handle = binding.getFrameHWFramesCtx(this._handle)
100
+ return handle ? HWFramesContext.from(handle) : null
101
+ }
102
+
103
+ set hwFramesCtx(hwFramesContext) {
104
+ binding.setFrameHWFramesCtx(this._handle, hwFramesContext._handle)
105
+ }
106
+
107
+ copyProperties(source) {
108
+ binding.copyFrameProperties(this._handle, source._handle)
109
+ }
110
+
111
+ transferData(destination) {
112
+ binding.transferFrameData(destination._handle, this._handle)
113
+ }
114
+
115
+ hwMap(destination, flags = constants.hwFrameMapFlags.NONE) {
116
+ binding.mapFrame(destination._handle, this._handle, flags)
63
117
  }
64
118
 
65
119
  alloc() {
@@ -69,4 +123,19 @@ module.exports = class FFmpegFrame {
69
123
  [Symbol.dispose]() {
70
124
  this.destroy()
71
125
  }
126
+
127
+ [Symbol.for('bare.inspect')]() {
128
+ return {
129
+ __proto__: { constructor: FFmpegFrame },
130
+ width: this.width,
131
+ height: this.height,
132
+ format: this.format,
133
+ channelLayout: this.channelLayout,
134
+ nbSamples: this.nbSamples,
135
+ pictType: this.pictType,
136
+ pts: this.pts,
137
+ packetDTS: this.packetDTS,
138
+ timeBase: this.timeBase
139
+ }
140
+ }
72
141
  }
@@ -0,0 +1,31 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class HWDeviceContext {
4
+ constructor(type, device = undefined, handle = undefined) {
5
+ if (handle) {
6
+ this._handle = handle
7
+ } else {
8
+ this._handle = binding.initHWDeviceContext(type, device)
9
+ }
10
+ }
11
+
12
+ static from(handle) {
13
+ if (handle == null) return null
14
+ return new HWDeviceContext(null, undefined, handle)
15
+ }
16
+
17
+ destroy() {
18
+ binding.destroyHWDeviceContext(this._handle)
19
+ this._handle = null
20
+ }
21
+
22
+ [Symbol.dispose]() {
23
+ this.destroy()
24
+ }
25
+
26
+ [Symbol.for('bare.inspect')]() {
27
+ return {
28
+ __proto__: { constructor: HWDeviceContext }
29
+ }
30
+ }
31
+ }
@@ -0,0 +1,54 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class HWFramesConstraints {
4
+ constructor(handle) {
5
+ this._handle = handle
6
+ }
7
+
8
+ get validSwFormats() {
9
+ return binding.getHWFramesConstraintsValidSwFormats(this._handle)
10
+ }
11
+
12
+ get validHwFormats() {
13
+ return binding.getHWFramesConstraintsValidHwFormats(this._handle)
14
+ }
15
+
16
+ get minWidth() {
17
+ return binding.getHWFramesConstraintsMinWidth(this._handle)
18
+ }
19
+
20
+ get maxWidth() {
21
+ return binding.getHWFramesConstraintsMaxWidth(this._handle)
22
+ }
23
+
24
+ get minHeight() {
25
+ return binding.getHWFramesConstraintsMinHeight(this._handle)
26
+ }
27
+
28
+ get maxHeight() {
29
+ return binding.getHWFramesConstraintsMaxHeight(this._handle)
30
+ }
31
+
32
+ // Note: HWFramesConstraints is independently allocated by FFmpeg and must be
33
+ // explicitly freed. It is not owned by HWFramesContext.
34
+ destroy() {
35
+ binding.destroyHWFramesConstraints(this._handle)
36
+ this._handle = null
37
+ }
38
+
39
+ [Symbol.dispose]() {
40
+ this.destroy()
41
+ }
42
+
43
+ [Symbol.for('bare.inspect')]() {
44
+ return {
45
+ __proto__: { constructor: HWFramesConstraints },
46
+ validSwFormats: this.validSwFormats,
47
+ validHwFormats: this.validHwFormats,
48
+ minWidth: this.minWidth,
49
+ maxWidth: this.maxWidth,
50
+ minHeight: this.minHeight,
51
+ maxHeight: this.maxHeight
52
+ }
53
+ }
54
+ }
@@ -0,0 +1,92 @@
1
+ const binding = require('../binding')
2
+ const HWFramesConstraints = require('./hw-frames-constraints')
3
+
4
+ module.exports = class HWFramesContext {
5
+ constructor(hwDeviceContext, format, swFormat, width, height, handle = undefined) {
6
+ if (handle) {
7
+ this._handle = handle
8
+ return
9
+ }
10
+
11
+ this._handle = binding.initHWFramesContext(
12
+ hwDeviceContext._handle,
13
+ format,
14
+ swFormat,
15
+ width,
16
+ height
17
+ )
18
+ }
19
+
20
+ static from(handle) {
21
+ if (handle == null) return null
22
+ return new HWFramesContext(null, null, null, null, null, handle)
23
+ }
24
+
25
+ get format() {
26
+ return binding.getHWFramesContextFormat(this._handle)
27
+ }
28
+
29
+ set format(value) {
30
+ binding.setHWFramesContextFormat(this._handle, value)
31
+ }
32
+
33
+ get swFormat() {
34
+ return binding.getHWFramesContextSWFormat(this._handle)
35
+ }
36
+
37
+ set swFormat(value) {
38
+ binding.setHWFramesContextSWFormat(this._handle, value)
39
+ }
40
+
41
+ get width() {
42
+ return binding.getHWFramesContextWidth(this._handle)
43
+ }
44
+
45
+ set width(value) {
46
+ binding.setHWFramesContextWidth(this._handle, value)
47
+ }
48
+
49
+ get height() {
50
+ return binding.getHWFramesContextHeight(this._handle)
51
+ }
52
+
53
+ set height(value) {
54
+ binding.setHWFramesContextHeight(this._handle, value)
55
+ }
56
+
57
+ get initialPoolSize() {
58
+ return binding.getHWFramesContextInitialPoolSize(this._handle)
59
+ }
60
+
61
+ set initialPoolSize(value) {
62
+ binding.setHWFramesContextInitialPoolSize(this._handle, value)
63
+ }
64
+
65
+ getBuffer(frame) {
66
+ binding.getHWFramesContextBuffer(this._handle, frame._handle)
67
+ }
68
+
69
+ getConstraints() {
70
+ const handle = binding.getHWFramesContextConstraints(this._handle)
71
+ return new HWFramesConstraints(handle)
72
+ }
73
+
74
+ destroy() {
75
+ binding.destroyHWFramesContext(this._handle)
76
+ this._handle = null
77
+ }
78
+
79
+ [Symbol.dispose]() {
80
+ this.destroy()
81
+ }
82
+
83
+ [Symbol.for('bare.inspect')]() {
84
+ return {
85
+ __proto__: { constructor: HWFramesContext },
86
+ format: this.format,
87
+ swFormat: this.swFormat,
88
+ width: this.width,
89
+ height: this.height
90
+ }
91
+ }
92
+ }
package/lib/image.js CHANGED
@@ -10,9 +10,7 @@ module.exports = class FFmpegImage {
10
10
  this._height = height
11
11
  this._align = align
12
12
 
13
- this._data = Buffer.from(
14
- binding.initImage(pixelFormat, width, height, align)
15
- )
13
+ this._data = Buffer.from(binding.initImage(pixelFormat, width, height, align))
16
14
  }
17
15
 
18
16
  get pixelFormat() {
@@ -40,6 +38,19 @@ module.exports = class FFmpegImage {
40
38
  this._pixelFormat,
41
39
  this._width,
42
40
  this._height,
41
+ this._align,
42
+ this._data.buffer,
43
+ this._data.byteOffset,
44
+ frame._handle
45
+ )
46
+ }
47
+
48
+ read(frame) {
49
+ binding.readImage(
50
+ this._pixelFormat,
51
+ this._width,
52
+ this._height,
53
+ this._align,
43
54
  this._data.buffer,
44
55
  this._data.byteOffset,
45
56
  frame._handle
@@ -3,6 +3,9 @@ const binding = require('../binding')
3
3
  let defaultName = null
4
4
 
5
5
  switch (Bare.platform) {
6
+ case 'android':
7
+ defaultName = 'android_camera'
8
+ break
6
9
  case 'darwin':
7
10
  case 'ios':
8
11
  defaultName = 'avfoundation'
@@ -16,7 +19,38 @@ switch (Bare.platform) {
16
19
  }
17
20
 
18
21
  module.exports = class FFmpegInputFormat {
19
- constructor(name = defaultName) {
20
- this._handle = binding.initInputFormat(name)
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)
29
+ }
30
+
31
+ get flags() {
32
+ return binding.getInputFormatFlags(this._handle)
33
+ }
34
+
35
+ get extensions() {
36
+ return binding.getInputFormatExtensions(this._handle)
37
+ }
38
+
39
+ get mimeType() {
40
+ return binding.getInputFormatMimeType(this._handle)
41
+ }
42
+
43
+ get name() {
44
+ return binding.getInputFormatName(this._handle)
45
+ }
46
+
47
+ [Symbol.for('bare.inspect')]() {
48
+ return {
49
+ __proto__: { constructor: FFmpegInputFormat },
50
+ name: this.name,
51
+ flags: this.flags,
52
+ extensions: this.extensions,
53
+ mimeType: this.mimeType
54
+ }
21
55
  }
22
56
  }