bare-ffmpeg 1.0.0-1 → 1.0.0-11

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.
@@ -4,6 +4,7 @@ let defaultName = null
4
4
 
5
5
  switch (Bare.platform) {
6
6
  case 'darwin':
7
+ case 'ios':
7
8
  defaultName = 'avfoundation'
8
9
  break
9
10
  case 'linux':
@@ -16,9 +17,6 @@ switch (Bare.platform) {
16
17
 
17
18
  module.exports = class FFmpegInputFormat {
18
19
  constructor(name = defaultName) {
19
- if (typeof name !== 'string' || name.length < 1) {
20
- throw new TypeError('Input format name should be a non empty string')
21
- }
22
20
  this._handle = binding.initInputFormat(name)
23
21
  }
24
22
  }
package/lib/io-context.js CHANGED
@@ -1,15 +1,20 @@
1
1
  const binding = require('../binding')
2
- const ReferenceCounted = require('./reference-counted')
3
2
 
4
- module.exports = class FFmpegIOContext extends ReferenceCounted {
3
+ module.exports = class FFmpegIOContext {
5
4
  constructor(buffer = Buffer.alloc(0)) {
6
- super()
7
-
8
- this._handle = binding.initIOContext(buffer)
5
+ this._handle = binding.initIOContext(
6
+ buffer.buffer,
7
+ buffer.byteOffset,
8
+ buffer.byteLength
9
+ )
9
10
  }
10
11
 
11
- _destroy() {
12
+ destroy() {
12
13
  binding.destroyIOContext(this._handle)
13
14
  this._handle = null
14
15
  }
16
+
17
+ [Symbol.dispose]() {
18
+ this.destroy()
19
+ }
15
20
  }
package/lib/packet.js CHANGED
@@ -1,20 +1,36 @@
1
1
  const binding = require('../binding')
2
- const ReferenceCounted = require('./reference-counted')
3
2
 
4
- module.exports = class FFmpegPacket extends ReferenceCounted {
5
- constructor() {
6
- super()
7
-
8
- this._handle = binding.initPacket()
3
+ module.exports = class FFmpegPacket {
4
+ constructor(buffer) {
5
+ if (buffer) {
6
+ this._handle = binding.initPacketFromBuffer(
7
+ buffer.buffer,
8
+ buffer.byteOffset,
9
+ buffer.byteLength
10
+ )
11
+ } else {
12
+ this._handle = binding.initPacket()
13
+ }
9
14
  }
10
15
 
11
- _destroy() {
12
- binding.destroyPacket(this._handle)
16
+ destroy() {
17
+ binding.unrefPacket(this._handle)
13
18
  this._handle = null
14
19
  }
15
20
 
16
21
  unref() {
17
- this._unref()
18
22
  binding.unrefPacket(this._handle)
19
23
  }
24
+
25
+ get streamIndex() {
26
+ return binding.getPacketStreamIndex(this._handle)
27
+ }
28
+
29
+ get data() {
30
+ return Buffer.from(binding.getPacketData(this._handle))
31
+ }
32
+
33
+ [Symbol.dispose]() {
34
+ this.destroy()
35
+ }
20
36
  }
@@ -0,0 +1,63 @@
1
+ const binding = require('../binding')
2
+ const ChannelLayout = require('./channel-layout')
3
+
4
+ class Resampler {
5
+ constructor(
6
+ inputSampleRate,
7
+ inputChannelLayout,
8
+ inputFormat,
9
+ outputSampleRate,
10
+ outputChannelLayout,
11
+ outputFormat
12
+ ) {
13
+ inputChannelLayout = ChannelLayout.from(inputChannelLayout)
14
+ outputChannelLayout = ChannelLayout.from(outputChannelLayout)
15
+
16
+ this._inputSampleRate = inputSampleRate
17
+ this._outputSampleRate = outputSampleRate
18
+
19
+ this._handle = binding.initResampler(
20
+ inputSampleRate,
21
+ inputFormat,
22
+ inputChannelLayout._handle,
23
+ outputSampleRate,
24
+ outputFormat,
25
+ outputChannelLayout._handle
26
+ )
27
+ }
28
+
29
+ get inputSampleRate() {
30
+ return this._inputSampleRate
31
+ }
32
+
33
+ get outputSampleRate() {
34
+ return this._outputSampleRate
35
+ }
36
+
37
+ get delay() {
38
+ return binding.getResamplerDelay(this._handle, this._inputSampleRate)
39
+ }
40
+
41
+ convert(inputFrame, outputFrame) {
42
+ return binding.convertResampler(
43
+ this._handle,
44
+ inputFrame._handle,
45
+ outputFrame._handle
46
+ )
47
+ }
48
+
49
+ flush(outputFrame) {
50
+ return binding.flushResampler(this._handle, outputFrame._handle)
51
+ }
52
+
53
+ destroy() {
54
+ binding.destroyResampler(this._handle)
55
+ this._handle = null
56
+ }
57
+
58
+ [Symbol.dispose]() {
59
+ this.destroy()
60
+ }
61
+ }
62
+
63
+ module.exports = Resampler
package/lib/samples.js ADDED
@@ -0,0 +1,49 @@
1
+ const binding = require('../binding')
2
+ const constants = require('./constants.js')
3
+
4
+ module.exports = class FFmpegSamples {
5
+ constructor(sampleFormat, nbChannels, nbSamples, align = 0) {
6
+ sampleFormat = constants.toSampleFormat(sampleFormat)
7
+
8
+ this._sampleFormat = sampleFormat
9
+ this._nbChannels = nbChannels
10
+ this._nbSamples = nbSamples
11
+ this._align = align
12
+
13
+ this._data = Buffer.from(
14
+ binding.initSamples(sampleFormat, nbChannels, nbSamples, align)
15
+ )
16
+ }
17
+
18
+ get sampleFormat() {
19
+ return this._sampleFormat
20
+ }
21
+
22
+ get nbChannels() {
23
+ return this._nbChannels
24
+ }
25
+
26
+ get nbSamples() {
27
+ return this._nbSamples
28
+ }
29
+
30
+ get align() {
31
+ return this._align
32
+ }
33
+
34
+ get data() {
35
+ return this._data
36
+ }
37
+
38
+ fill(frame) {
39
+ binding.fillSamples(
40
+ this._sampleFormat,
41
+ this._nbChannels,
42
+ this._nbSamples,
43
+ this._align,
44
+ this._data.buffer,
45
+ this._data.byteOffset,
46
+ frame._handle
47
+ )
48
+ }
49
+ }
package/lib/scaler.js CHANGED
@@ -1,8 +1,7 @@
1
1
  const binding = require('../binding')
2
2
  const constants = require('./constants')
3
- const ReferenceCounted = require('./reference-counted')
4
3
 
5
- module.exports = class FFmpegScaler extends ReferenceCounted {
4
+ module.exports = class FFmpegScaler {
6
5
  constructor(
7
6
  sourcePixelFormat,
8
7
  sourceWidth,
@@ -11,8 +10,6 @@ module.exports = class FFmpegScaler extends ReferenceCounted {
11
10
  targetWidth,
12
11
  targetHeight
13
12
  ) {
14
- super()
15
-
16
13
  sourcePixelFormat = constants.toPixelFormat(sourcePixelFormat)
17
14
  targetPixelFormat = constants.toPixelFormat(targetPixelFormat)
18
15
 
@@ -33,7 +30,7 @@ module.exports = class FFmpegScaler extends ReferenceCounted {
33
30
  )
34
31
  }
35
32
 
36
- _destroy() {
33
+ destroy() {
37
34
  binding.destroyScaler(this._handle)
38
35
  this._handle = null
39
36
  }
@@ -56,4 +53,8 @@ module.exports = class FFmpegScaler extends ReferenceCounted {
56
53
  target._handle
57
54
  )
58
55
  }
56
+
57
+ [Symbol.dispose]() {
58
+ this.destroy()
59
+ }
59
60
  }
package/lib/stream.js CHANGED
@@ -2,12 +2,9 @@ const binding = require('../binding')
2
2
  const Codec = require('./codec')
3
3
  const CodecContext = require('./codec-context')
4
4
  const CodecParameters = require('./codec-parameters')
5
- const ReferenceCounted = require('./reference-counted')
6
5
 
7
- module.exports = class FFmpegStream extends ReferenceCounted {
6
+ module.exports = class FFmpegStream {
8
7
  constructor(handle) {
9
- super()
10
-
11
8
  this._handle = handle
12
9
 
13
10
  this._codec = Codec.for(binding.getStreamCodec(this._handle))
@@ -17,7 +14,7 @@ module.exports = class FFmpegStream extends ReferenceCounted {
17
14
  )
18
15
  }
19
16
 
20
- _destroy() {
17
+ destroy() {
21
18
  this._codecParameters.destroy()
22
19
  this._codecParameters = null
23
20
  }
@@ -41,4 +38,8 @@ module.exports = class FFmpegStream extends ReferenceCounted {
41
38
  this._codecParameters.toContext(context)
42
39
  return context.open()
43
40
  }
41
+
42
+ [Symbol.dispose]() {
43
+ this.destroy()
44
+ }
44
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ffmpeg",
3
- "version": "1.0.0-1",
3
+ "version": "1.0.0-11",
4
4
  "description": "Low-level FFmpeg bindings for Bare",
5
5
  "exports": {
6
6
  ".": "./index.js",
@@ -31,7 +31,8 @@
31
31
  "devDependencies": {
32
32
  "brittle": "^3.4.0",
33
33
  "cmake-bare": "^1.1.2",
34
- "cmake-ports": "^1.1.7",
34
+ "cmake-harden": "^1.0.2",
35
+ "cmake-ports": "^1.5.0",
35
36
  "prettier": "^3.3.3",
36
37
  "prettier-config-standard": "^7.0.0"
37
38
  }