bare-ffmpeg 1.0.0-0 → 1.0.0-10

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.
@@ -0,0 +1,22 @@
1
+ const binding = require('../binding')
2
+
3
+ let defaultName = null
4
+
5
+ switch (Bare.platform) {
6
+ case 'darwin':
7
+ case 'ios':
8
+ defaultName = 'avfoundation'
9
+ break
10
+ case 'linux':
11
+ defaultName = 'v4l2'
12
+ break
13
+ case 'win32':
14
+ defaultName = 'dshow'
15
+ break
16
+ }
17
+
18
+ module.exports = class FFmpegInputFormat {
19
+ constructor(name = defaultName) {
20
+ this._handle = binding.initInputFormat(name)
21
+ }
22
+ }
package/lib/io-context.js CHANGED
@@ -1,12 +1,15 @@
1
1
  const binding = require('../binding')
2
2
 
3
3
  module.exports = class FFmpegIOContext {
4
- constructor(buffer) {
5
- this._handle = binding.initIOContext(buffer)
4
+ constructor(buffer = Buffer.alloc(0)) {
5
+ this._handle = binding.initIOContext(
6
+ buffer.buffer,
7
+ buffer.byteOffset,
8
+ buffer.byteLength
9
+ )
6
10
  }
7
11
 
8
12
  destroy() {
9
- if (this._handle === null) return
10
13
  binding.destroyIOContext(this._handle)
11
14
  this._handle = null
12
15
  }
@@ -0,0 +1,7 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegOutputFormat {
4
+ constructor(name) {
5
+ this._handle = binding.initOutputFormat(name)
6
+ }
7
+ }
package/lib/packet.js CHANGED
@@ -1,18 +1,33 @@
1
1
  const binding = require('../binding')
2
2
 
3
3
  module.exports = class FFmpegPacket {
4
- constructor() {
5
- this._handle = binding.initPacket()
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
+ }
14
+ }
15
+
16
+ destroy() {
17
+ binding.unrefPacket(this._handle)
18
+ this._handle = null
6
19
  }
7
20
 
8
21
  unref() {
9
22
  binding.unrefPacket(this._handle)
10
23
  }
11
24
 
12
- destroy() {
13
- if (this._handle === null) return
14
- binding.destroyPacket(this._handle)
15
- this._handle = null
25
+ get streamIndex() {
26
+ return binding.getPacketStreamIndex(this._handle)
27
+ }
28
+
29
+ get data() {
30
+ return Buffer.from(binding.getPacketData(this._handle))
16
31
  }
17
32
 
18
33
  [Symbol.dispose]() {
@@ -0,0 +1,6 @@
1
+ module.exports = class FFmpegRational {
2
+ constructor(numerator, denominator) {
3
+ this.numerator = numerator
4
+ this.denominator = denominator
5
+ }
6
+ }
@@ -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
@@ -31,15 +31,10 @@ module.exports = class FFmpegScaler {
31
31
  }
32
32
 
33
33
  destroy() {
34
- if (this._handle === null) return
35
34
  binding.destroyScaler(this._handle)
36
35
  this._handle = null
37
36
  }
38
37
 
39
- [Symbol.dispose]() {
40
- this.destroy()
41
- }
42
-
43
38
  scale(source, y, height, target) {
44
39
  if (typeof y !== 'number') {
45
40
  target = y
@@ -58,4 +53,8 @@ module.exports = class FFmpegScaler {
58
53
  target._handle
59
54
  )
60
55
  }
56
+
57
+ [Symbol.dispose]() {
58
+ this.destroy()
59
+ }
61
60
  }
package/lib/stream.js CHANGED
@@ -14,6 +14,11 @@ module.exports = class FFmpegStream {
14
14
  )
15
15
  }
16
16
 
17
+ destroy() {
18
+ this._codecParameters.destroy()
19
+ this._codecParameters = null
20
+ }
21
+
17
22
  get codec() {
18
23
  return this._codec
19
24
  }
@@ -23,10 +28,18 @@ module.exports = class FFmpegStream {
23
28
  }
24
29
 
25
30
  decoder() {
26
- return new CodecContext(this._codec.decoder, this._codecParameters)
31
+ const context = new CodecContext(this._codec.decoder)
32
+ this._codecParameters.toContext(context)
33
+ return context.open()
27
34
  }
28
35
 
29
36
  encoder() {
30
- return new CodecContext(this._codec.encoder, this._codecParameters)
37
+ const context = new CodecContext(this._codec.encoder)
38
+ this._codecParameters.toContext(context)
39
+ return context.open()
40
+ }
41
+
42
+ [Symbol.dispose]() {
43
+ this.destroy()
31
44
  }
32
45
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "bare-ffmpeg",
3
- "version": "1.0.0-0",
3
+ "version": "1.0.0-10",
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
  }