bare-ffmpeg 1.0.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.
package/binding.js ADDED
@@ -0,0 +1 @@
1
+ module.exports = require.addon()
package/index.js ADDED
@@ -0,0 +1,14 @@
1
+ exports.Codec = require('./lib/codec')
2
+ exports.CodecContext = require('./lib/codec-context')
3
+ exports.CodecParameters = require('./lib/codec-parameters')
4
+ exports.Decoder = require('./lib/decoder')
5
+ exports.Encoder = require('./lib/encoder')
6
+ exports.FormatContext = require('./lib/format-context')
7
+ exports.Frame = require('./lib/frame')
8
+ exports.Image = require('./lib/image')
9
+ exports.IOContext = require('./lib/io-context')
10
+ exports.Packet = require('./lib/packet')
11
+ exports.Scaler = require('./lib/scaler')
12
+ exports.Stream = require('./lib/stream')
13
+
14
+ exports.constants = require('./lib/constants')
@@ -0,0 +1,38 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegCodecContext {
4
+ constructor(codec, parameters) {
5
+ this._codec = codec
6
+ this._handle = binding.initCodecContext(codec._handle, parameters._handle)
7
+ }
8
+
9
+ get pixelFormat() {
10
+ return binding.getCodecContextPixelFormat(this._handle)
11
+ }
12
+
13
+ get width() {
14
+ return binding.getCodecContextWidth(this._handle)
15
+ }
16
+
17
+ get height() {
18
+ return binding.getCodecContextHeight(this._handle)
19
+ }
20
+
21
+ destroy() {
22
+ if (this._handle === null) return
23
+ binding.destroyCodecContext(this._handle)
24
+ this._handle = null
25
+ }
26
+
27
+ [Symbol.dispose]() {
28
+ this.destroy()
29
+ }
30
+
31
+ sendPacket(packet) {
32
+ binding.sendCodecContextPacket(this._handle, packet._handle)
33
+ }
34
+
35
+ receiveFrame(frame) {
36
+ binding.receiveCodecContextFrame(this._handle, frame._handle)
37
+ }
38
+ }
@@ -0,0 +1,5 @@
1
+ module.exports = class FFmpegCodecParameters {
2
+ constructor(handle) {
3
+ this._handle = handle
4
+ }
5
+ }
package/lib/codec.js ADDED
@@ -0,0 +1,35 @@
1
+ const Decoder = require('./decoder')
2
+ const Encoder = require('./encoder')
3
+
4
+ const codecs = new Map()
5
+
6
+ module.exports = class FFmpegCodec {
7
+ constructor(id) {
8
+ this._id = id
9
+ this._decoder = null
10
+ this._encoder = null
11
+ }
12
+
13
+ get id() {
14
+ return this._id
15
+ }
16
+
17
+ get decoder() {
18
+ if (this._decoder === null) this._decoder = new Decoder(this)
19
+ return this._decoder
20
+ }
21
+
22
+ get encoder() {
23
+ if (this._encoder === null) this._encoder = new Encoder(this)
24
+ return this._encoder
25
+ }
26
+
27
+ static for(id) {
28
+ let codec = codecs.get(id)
29
+ if (codec === undefined) {
30
+ codec = new FFmpegCodec(id)
31
+ codecs.set(id, codec)
32
+ }
33
+ return codec
34
+ }
35
+ }
@@ -0,0 +1,19 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = exports = {
4
+ pixelFormats: {
5
+ RGBA: binding.AV_PIX_FMT_RGBA
6
+ }
7
+ }
8
+
9
+ exports.toPixelFormat = function toPixelFormat(pixelFormat) {
10
+ if (typeof pixelFormat === 'number') return pixelFormat
11
+
12
+ if (typeof pixelFormat === 'string') {
13
+ if (pixelFormat in exports.pixelFormats === false) {
14
+ throw errors.UNKNOWN_PIXEL_FORMAT(`Unknown pixel format '${pixelFormat}'`)
15
+ }
16
+
17
+ return exports.pixelFormats[pixelFormat]
18
+ }
19
+ }
package/lib/decoder.js ADDED
@@ -0,0 +1,8 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegDecoder {
4
+ constructor(codec) {
5
+ this._codec = codec
6
+ this._handle = binding.findDecoderByID(codec._id)
7
+ }
8
+ }
package/lib/encoder.js ADDED
@@ -0,0 +1,8 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegEncoder {
4
+ constructor(codec) {
5
+ this._codec = codec
6
+ this._handle = binding.findEncoderByID(codec._id)
7
+ }
8
+ }
@@ -0,0 +1,37 @@
1
+ const binding = require('../binding')
2
+ const Stream = require('./stream.js')
3
+
4
+ module.exports = class FFmpegFormatContext {
5
+ constructor(io) {
6
+ this._io = io
7
+ this._streams = []
8
+ this._handle = binding.initFormatContext(io._handle)
9
+
10
+ for (const handle of binding.getFormatContextStreams(this._handle)) {
11
+ this._streams.push(new Stream(handle))
12
+ }
13
+ }
14
+
15
+ get io() {
16
+ return this._io
17
+ }
18
+
19
+ get streams() {
20
+ return this._streams
21
+ }
22
+
23
+ destroy() {
24
+ if (this._handle === null) return
25
+ binding.destroyFormatContext(this._handle)
26
+ this._io = null
27
+ this._handle = null
28
+ }
29
+
30
+ [Symbol.dispose]() {
31
+ this.destroy()
32
+ }
33
+
34
+ readFrame(packet) {
35
+ binding.readFormatContextFrame(this._handle, packet._handle)
36
+ }
37
+ }
package/lib/frame.js ADDED
@@ -0,0 +1,17 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegFrame {
4
+ constructor() {
5
+ this._handle = binding.initFrame()
6
+ }
7
+
8
+ destroy() {
9
+ if (this._handle === null) return
10
+ binding.destroyFrame(this._handle)
11
+ this._handle = null
12
+ }
13
+
14
+ [Symbol.dispose]() {
15
+ this.destroy()
16
+ }
17
+ }
package/lib/image.js ADDED
@@ -0,0 +1,47 @@
1
+ const binding = require('../binding')
2
+ const constants = require('./constants.js')
3
+
4
+ module.exports = class FFmpegImage {
5
+ constructor(pixelFormat, width, height, align = 1) {
6
+ pixelFormat = constants.toPixelFormat(pixelFormat)
7
+
8
+ this._pixelFormat = pixelFormat
9
+ this._width = width
10
+ this._height = height
11
+ this._align = align
12
+
13
+ this._data = Buffer.from(
14
+ binding.initImage(pixelFormat, width, height, align)
15
+ )
16
+ }
17
+
18
+ get pixelFormat() {
19
+ return this._pixelFormat
20
+ }
21
+
22
+ get width() {
23
+ return this._width
24
+ }
25
+
26
+ get height() {
27
+ return this._height
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.fillImage(
40
+ this._pixelFormat,
41
+ this._width,
42
+ this._height,
43
+ this._data.buffer,
44
+ frame._handle
45
+ )
46
+ }
47
+ }
@@ -0,0 +1,17 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegIOContext {
4
+ constructor(buffer) {
5
+ this._handle = binding.initIOContext(buffer)
6
+ }
7
+
8
+ destroy() {
9
+ if (this._handle === null) return
10
+ binding.destroyIOContext(this._handle)
11
+ this._handle = null
12
+ }
13
+
14
+ [Symbol.dispose]() {
15
+ this.destroy()
16
+ }
17
+ }
package/lib/packet.js ADDED
@@ -0,0 +1,21 @@
1
+ const binding = require('../binding')
2
+
3
+ module.exports = class FFmpegPacket {
4
+ constructor() {
5
+ this._handle = binding.initPacket()
6
+ }
7
+
8
+ unref() {
9
+ binding.unrefPacket(this._handle)
10
+ }
11
+
12
+ destroy() {
13
+ if (this._handle === null) return
14
+ binding.destroyPacket(this._handle)
15
+ this._handle = null
16
+ }
17
+
18
+ [Symbol.dispose]() {
19
+ this.destroy()
20
+ }
21
+ }
package/lib/scaler.js ADDED
@@ -0,0 +1,61 @@
1
+ const binding = require('../binding')
2
+ const constants = require('./constants')
3
+
4
+ module.exports = class FFmpegScaler {
5
+ constructor(
6
+ sourcePixelFormat,
7
+ sourceWidth,
8
+ sourceHeight,
9
+ targetPixelFormat,
10
+ targetWidth,
11
+ targetHeight
12
+ ) {
13
+ sourcePixelFormat = constants.toPixelFormat(sourcePixelFormat)
14
+ targetPixelFormat = constants.toPixelFormat(targetPixelFormat)
15
+
16
+ this._sourcePixelFormat = sourcePixelFormat
17
+ this._sourceWidth = sourceWidth
18
+ this._sourceHeight = sourceHeight
19
+ this._targetPixelFormat = targetPixelFormat
20
+ this._targetWidth = targetWidth
21
+ this._targetHeight = targetHeight
22
+
23
+ this._handle = binding.initScaler(
24
+ sourcePixelFormat,
25
+ sourceWidth,
26
+ sourceHeight,
27
+ targetPixelFormat,
28
+ targetWidth,
29
+ targetHeight
30
+ )
31
+ }
32
+
33
+ destroy() {
34
+ if (this._handle === null) return
35
+ binding.destroyScaler(this._handle)
36
+ this._handle = null
37
+ }
38
+
39
+ [Symbol.dispose]() {
40
+ this.destroy()
41
+ }
42
+
43
+ scale(source, y, height, target) {
44
+ if (typeof y !== 'number') {
45
+ target = y
46
+ y = 0
47
+ height = this._targetHeight
48
+ } else if (typeof height !== 'number') {
49
+ target = height
50
+ height = this._targetHeight
51
+ }
52
+
53
+ return binding.scaleScaler(
54
+ this._handle,
55
+ source._handle,
56
+ y,
57
+ height,
58
+ target._handle
59
+ )
60
+ }
61
+ }
package/lib/stream.js ADDED
@@ -0,0 +1,32 @@
1
+ const binding = require('../binding')
2
+ const Codec = require('./codec')
3
+ const CodecContext = require('./codec-context')
4
+ const CodecParameters = require('./codec-parameters')
5
+
6
+ module.exports = class FFmpegStream {
7
+ constructor(handle) {
8
+ this._handle = handle
9
+
10
+ this._codec = Codec.for(binding.getStreamCodec(this._handle))
11
+
12
+ this._codecParameters = new CodecParameters(
13
+ binding.getStreamCodecParameters(this._handle)
14
+ )
15
+ }
16
+
17
+ get codec() {
18
+ return this._codec
19
+ }
20
+
21
+ get codecParameters() {
22
+ return this._codecParameters
23
+ }
24
+
25
+ decoder() {
26
+ return new CodecContext(this._codec.decoder, this._codecParameters)
27
+ }
28
+
29
+ encoder() {
30
+ return new CodecContext(this._codec.encoder, this._codecParameters)
31
+ }
32
+ }
package/package.json ADDED
@@ -0,0 +1,38 @@
1
+ {
2
+ "name": "bare-ffmpeg",
3
+ "version": "1.0.0-0",
4
+ "description": "Low-level FFmpeg bindings for Bare",
5
+ "exports": {
6
+ ".": "./index.js",
7
+ "./package": "./package.json"
8
+ },
9
+ "files": [
10
+ "index.js",
11
+ "binding.c",
12
+ "binding.js",
13
+ "CMakeLists.txt",
14
+ "lib",
15
+ "prebuilds"
16
+ ],
17
+ "addon": true,
18
+ "scripts": {
19
+ "test": "prettier . --check && bare test.js"
20
+ },
21
+ "repository": {
22
+ "type": "git",
23
+ "url": "git+https://github.com/holepunchto/bare-ffmpeg.git"
24
+ },
25
+ "author": "Holepunch",
26
+ "license": "Apache-2.0",
27
+ "bugs": {
28
+ "url": "https://github.com/holepunchto/bare-ffmpeg/issues"
29
+ },
30
+ "homepage": "https://github.com/holepunchto/bare-ffmpeg#readme",
31
+ "devDependencies": {
32
+ "brittle": "^3.4.0",
33
+ "cmake-bare": "^1.1.2",
34
+ "cmake-ports": "^1.1.7",
35
+ "prettier": "^3.3.3",
36
+ "prettier-config-standard": "^7.0.0"
37
+ }
38
+ }