bare-ffmpeg 1.0.0-2 → 1.0.0-20
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 +10 -3
- package/README.md +990 -0
- package/binding.cc +3150 -0
- package/cmake/ports/ffmpeg/port.cmake +513 -0
- package/cmake/ports/opus/patches/01-windows-clang.patch +52 -0
- package/cmake/ports/opus/port.cmake +42 -0
- package/cmake/ports/svt-av1/port.cmake +42 -0
- package/cmake/ports/x264/patches/01-windows-clang.patch +33 -0
- package/cmake/ports/x264/port.cmake +157 -0
- package/index.js +14 -4
- package/lib/audio-fifo.js +47 -0
- package/lib/channel-layout.js +35 -0
- package/lib/codec-context.js +92 -15
- package/lib/codec-parameters.js +154 -8
- package/lib/codec.js +19 -0
- package/lib/constants.js +163 -8
- package/lib/dictionary.js +10 -15
- package/lib/errors.js +38 -0
- package/lib/format-context.js +62 -31
- package/lib/frame.js +87 -16
- package/lib/image.js +22 -0
- package/lib/input-format.js +8 -3
- package/lib/io-context.js +29 -6
- package/lib/log.js +16 -0
- package/lib/output-format.js +4 -0
- package/lib/packet.js +88 -13
- package/lib/rational.js +35 -1
- package/lib/resampler.js +63 -0
- package/lib/samples.js +49 -0
- package/lib/scaler.js +8 -7
- package/lib/stream.js +37 -12
- package/package.json +7 -4
- package/prebuilds/android-arm/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-ia32/bare-ffmpeg.bare +0 -0
- package/prebuilds/android-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/darwin-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-arm64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/ios-x64-simulator/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/linux-x64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-arm64/bare-ffmpeg.bare +0 -0
- package/prebuilds/win32-x64/bare-ffmpeg.bare +0 -0
- package/binding.c +0 -2128
- package/lib/reference-counted.js +0 -39
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
include_guard(GLOBAL)
|
|
2
|
+
|
|
3
|
+
if(WIN32)
|
|
4
|
+
set(lib x264.lib)
|
|
5
|
+
else()
|
|
6
|
+
set(lib libx264.a)
|
|
7
|
+
endif()
|
|
8
|
+
|
|
9
|
+
set(env)
|
|
10
|
+
|
|
11
|
+
set(args
|
|
12
|
+
--disable-cli
|
|
13
|
+
|
|
14
|
+
--enable-static
|
|
15
|
+
--enable-strip
|
|
16
|
+
--enable-pic
|
|
17
|
+
)
|
|
18
|
+
|
|
19
|
+
if(CMAKE_BUILD_TYPE MATCHES "Debug|RelWithDebInfo")
|
|
20
|
+
list(APPEND args --enable-debug)
|
|
21
|
+
endif()
|
|
22
|
+
|
|
23
|
+
if(CMAKE_SYSTEM_NAME)
|
|
24
|
+
set(platform ${CMAKE_SYSTEM_NAME})
|
|
25
|
+
else()
|
|
26
|
+
set(platform ${CMAKE_HOST_SYSTEM_NAME})
|
|
27
|
+
endif()
|
|
28
|
+
|
|
29
|
+
string(TOLOWER "${platform}" platform)
|
|
30
|
+
|
|
31
|
+
if(platform MATCHES "darwin|ios")
|
|
32
|
+
set(platform "darwin")
|
|
33
|
+
elseif(platform MATCHES "linux|android")
|
|
34
|
+
set(platform "linux")
|
|
35
|
+
elseif(platform MATCHES "windows")
|
|
36
|
+
set(platform "msys")
|
|
37
|
+
else()
|
|
38
|
+
message(FATAL_ERROR "Unsupported platform '${platform}'")
|
|
39
|
+
endif()
|
|
40
|
+
|
|
41
|
+
if(APPLE AND CMAKE_OSX_ARCHITECTURES)
|
|
42
|
+
set(arch ${CMAKE_OSX_ARCHITECTURES})
|
|
43
|
+
elseif(MSVC AND CMAKE_GENERATOR_PLATFORM)
|
|
44
|
+
set(arch ${CMAKE_GENERATOR_PLATFORM})
|
|
45
|
+
elseif(ANDROID AND CMAKE_ANDROID_ARCH_ABI)
|
|
46
|
+
set(arch ${CMAKE_ANDROID_ARCH_ABI})
|
|
47
|
+
elseif(CMAKE_SYSTEM_PROCESSOR)
|
|
48
|
+
set(arch ${CMAKE_SYSTEM_PROCESSOR})
|
|
49
|
+
else()
|
|
50
|
+
set(arch ${CMAKE_HOST_SYSTEM_PROCESSOR})
|
|
51
|
+
endif()
|
|
52
|
+
|
|
53
|
+
string(TOLOWER "${arch}" arch)
|
|
54
|
+
|
|
55
|
+
if(arch MATCHES "arm64|aarch64")
|
|
56
|
+
set(arch "aarch64")
|
|
57
|
+
elseif(arch MATCHES "armv7-a|armeabi-v7a")
|
|
58
|
+
set(arch "arm")
|
|
59
|
+
elseif(arch MATCHES "x64|x86_64|amd64")
|
|
60
|
+
set(arch "x86_64")
|
|
61
|
+
elseif(arch MATCHES "x86|i386|i486|i586|i686")
|
|
62
|
+
set(arch "i686")
|
|
63
|
+
else()
|
|
64
|
+
message(FATAL_ERROR "Unsupported architecture '${arch}'")
|
|
65
|
+
endif()
|
|
66
|
+
|
|
67
|
+
list(APPEND args --host=${arch}-${platform})
|
|
68
|
+
|
|
69
|
+
if(APPLE)
|
|
70
|
+
list(APPEND args --sysroot=${CMAKE_OSX_SYSROOT})
|
|
71
|
+
elseif(ANDROID)
|
|
72
|
+
list(APPEND args --sysroot=${CMAKE_SYSROOT} --disable-asm)
|
|
73
|
+
elseif(WIN32)
|
|
74
|
+
list(APPEND args --disable-asm)
|
|
75
|
+
endif()
|
|
76
|
+
|
|
77
|
+
if(CMAKE_C_COMPILER)
|
|
78
|
+
cmake_path(GET CMAKE_C_COMPILER PARENT_PATH CC_path)
|
|
79
|
+
cmake_path(GET CMAKE_C_COMPILER FILENAME CC_filename)
|
|
80
|
+
|
|
81
|
+
list(APPEND env "CC=${CC_filename}")
|
|
82
|
+
|
|
83
|
+
list(APPEND args
|
|
84
|
+
--extra-cflags=--target=${CMAKE_C_COMPILER_TARGET}
|
|
85
|
+
--extra-ldflags=--target=${CMAKE_C_COMPILER_TARGET}
|
|
86
|
+
)
|
|
87
|
+
|
|
88
|
+
if(CMAKE_LINKER_TYPE MATCHES "LLD")
|
|
89
|
+
list(APPEND args --extra-ldflags=-fuse-ld=lld)
|
|
90
|
+
endif()
|
|
91
|
+
|
|
92
|
+
list(APPEND env --modify "PATH=path_list_prepend:${CC_path}")
|
|
93
|
+
endif()
|
|
94
|
+
|
|
95
|
+
if(CMAKE_ASM_NASM_COMPILER)
|
|
96
|
+
cmake_path(GET CMAKE_ASM_NASM_COMPILER PARENT_PATH AS_path)
|
|
97
|
+
cmake_path(GET CMAKE_ASM_NASM_COMPILER FILENAME AS_filename)
|
|
98
|
+
|
|
99
|
+
list(APPEND env "AS=${AS_filename}")
|
|
100
|
+
|
|
101
|
+
list(APPEND env --modify "PATH=path_list_prepend:${AS_path}")
|
|
102
|
+
elseif(CMAKE_ASM_COMPILER)
|
|
103
|
+
cmake_path(GET CMAKE_ASM_COMPILER PARENT_PATH AS_path)
|
|
104
|
+
cmake_path(GET CMAKE_ASM_COMPILER FILENAME AS_filename)
|
|
105
|
+
|
|
106
|
+
list(APPEND env "AS=${AS_filename}")
|
|
107
|
+
|
|
108
|
+
list(APPEND args --extra-asflags=--target=${CMAKE_ASM_COMPILER_TARGET})
|
|
109
|
+
|
|
110
|
+
list(APPEND env --modify "PATH=path_list_prepend:${AS_path}")
|
|
111
|
+
endif()
|
|
112
|
+
|
|
113
|
+
if(CMAKE_RC_COMPILER)
|
|
114
|
+
cmake_path(GET CMAKE_RC_COMPILER PARENT_PATH RC_path)
|
|
115
|
+
cmake_path(GET CMAKE_RC_COMPILER FILENAME RC_filename)
|
|
116
|
+
|
|
117
|
+
list(APPEND env "RC=${RC_filename}")
|
|
118
|
+
|
|
119
|
+
list(APPEND env --modify "PATH=path_list_prepend:${RC_path}")
|
|
120
|
+
endif()
|
|
121
|
+
|
|
122
|
+
if(CMAKE_AR)
|
|
123
|
+
cmake_path(GET CMAKE_AR PARENT_PATH AR_path)
|
|
124
|
+
cmake_path(GET CMAKE_AR FILENAME AR_filename)
|
|
125
|
+
|
|
126
|
+
list(APPEND env "AR=${AR_filename}")
|
|
127
|
+
|
|
128
|
+
list(APPEND env --modify "PATH=path_list_prepend:${AR_path}")
|
|
129
|
+
endif()
|
|
130
|
+
|
|
131
|
+
declare_port(
|
|
132
|
+
"git:code.videolan.org/videolan/x264#stable"
|
|
133
|
+
x264
|
|
134
|
+
AUTOTOOLS
|
|
135
|
+
BYPRODUCTS lib/${lib}
|
|
136
|
+
ARGS ${args}
|
|
137
|
+
ENV ${env}
|
|
138
|
+
PATCHES
|
|
139
|
+
patches/01-windows-clang.patch
|
|
140
|
+
)
|
|
141
|
+
|
|
142
|
+
add_library(x264 STATIC IMPORTED GLOBAL)
|
|
143
|
+
|
|
144
|
+
add_dependencies(x264 ${x264})
|
|
145
|
+
|
|
146
|
+
set_target_properties(
|
|
147
|
+
x264
|
|
148
|
+
PROPERTIES
|
|
149
|
+
IMPORTED_LOCATION "${x264_PREFIX}/lib/${lib}"
|
|
150
|
+
)
|
|
151
|
+
|
|
152
|
+
file(MAKE_DIRECTORY "${x264_PREFIX}/include")
|
|
153
|
+
|
|
154
|
+
target_include_directories(
|
|
155
|
+
x264
|
|
156
|
+
INTERFACE "${x264_PREFIX}/include"
|
|
157
|
+
)
|
package/index.js
CHANGED
|
@@ -1,27 +1,35 @@
|
|
|
1
|
+
const AudioFIFO = require('./lib/audio-fifo')
|
|
2
|
+
const ChannelLayout = require('./lib/channel-layout')
|
|
1
3
|
const Codec = require('./lib/codec')
|
|
2
4
|
const CodecContext = require('./lib/codec-context')
|
|
3
5
|
const CodecParameters = require('./lib/codec-parameters')
|
|
4
6
|
const Decoder = require('./lib/decoder')
|
|
7
|
+
const Dictionary = require('./lib/dictionary')
|
|
5
8
|
const Encoder = require('./lib/encoder')
|
|
6
9
|
const {
|
|
7
10
|
InputFormatContext,
|
|
8
11
|
OutputFormatContext
|
|
9
12
|
} = require('./lib/format-context')
|
|
10
13
|
const Frame = require('./lib/frame')
|
|
11
|
-
const Image = require('./lib/image')
|
|
12
14
|
const IOContext = require('./lib/io-context')
|
|
15
|
+
const Image = require('./lib/image')
|
|
13
16
|
const InputFormat = require('./lib/input-format')
|
|
14
17
|
const OutputFormat = require('./lib/output-format')
|
|
15
18
|
const Packet = require('./lib/packet')
|
|
19
|
+
const Rational = require('./lib/rational')
|
|
20
|
+
const Resampler = require('./lib/resampler')
|
|
21
|
+
const Samples = require('./lib/samples')
|
|
16
22
|
const Scaler = require('./lib/scaler')
|
|
17
23
|
const Stream = require('./lib/stream')
|
|
18
|
-
const
|
|
19
|
-
const Dictionary = require('./lib/dictionary')
|
|
24
|
+
const log = require('./lib/log')
|
|
20
25
|
|
|
26
|
+
exports.AudioFIFO = AudioFIFO
|
|
27
|
+
exports.ChannelLayout = ChannelLayout
|
|
21
28
|
exports.Codec = Codec
|
|
22
29
|
exports.CodecContext = CodecContext
|
|
23
30
|
exports.CodecParameters = CodecParameters
|
|
24
31
|
exports.Decoder = Decoder
|
|
32
|
+
exports.Dictionary = Dictionary
|
|
25
33
|
exports.Encoder = Encoder
|
|
26
34
|
exports.Frame = Frame
|
|
27
35
|
exports.IOContext = IOContext
|
|
@@ -31,9 +39,11 @@ exports.InputFormatContext = InputFormatContext
|
|
|
31
39
|
exports.OutputFormat = OutputFormat
|
|
32
40
|
exports.OutputFormatContext = OutputFormatContext
|
|
33
41
|
exports.Packet = Packet
|
|
42
|
+
exports.Samples = Samples
|
|
34
43
|
exports.Scaler = Scaler
|
|
35
44
|
exports.Stream = Stream
|
|
36
45
|
exports.Rational = Rational
|
|
37
|
-
exports.
|
|
46
|
+
exports.Resampler = Resampler
|
|
47
|
+
exports.log = log
|
|
38
48
|
|
|
39
49
|
exports.constants = require('./lib/constants')
|
|
@@ -0,0 +1,47 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const constants = require('./constants')
|
|
3
|
+
|
|
4
|
+
module.exports = class FFmpegAudioFIFO {
|
|
5
|
+
constructor(sampleFormat, channels, nbSamples) {
|
|
6
|
+
sampleFormat = constants.toSampleFormat(sampleFormat)
|
|
7
|
+
|
|
8
|
+
this._handle = binding.initAudioFifo(sampleFormat, channels, nbSamples)
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
destroy() {
|
|
12
|
+
binding.destroyAudioFifo(this._handle)
|
|
13
|
+
this._handle = null
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
write(frame) {
|
|
17
|
+
return binding.writeAudioFifo(this._handle, frame._handle)
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
read(frame, nbSamples) {
|
|
21
|
+
return binding.readAudioFifo(this._handle, frame._handle, nbSamples)
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
peek(frame, nbSamples) {
|
|
25
|
+
return binding.peekAudioFifo(this._handle, frame._handle, nbSamples)
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
drain(nbSamples) {
|
|
29
|
+
return binding.drainAudioFifo(this._handle, nbSamples)
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
reset() {
|
|
33
|
+
binding.resetAudioFifo(this._handle)
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
get size() {
|
|
37
|
+
return binding.getAudioFifoSize(this._handle)
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
get space() {
|
|
41
|
+
return binding.getAudioFifoSpace(this._handle)
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
[Symbol.dispose]() {
|
|
45
|
+
this.destroy()
|
|
46
|
+
}
|
|
47
|
+
}
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
const binding = require('../binding')
|
|
2
|
+
const constants = require('./constants')
|
|
3
|
+
|
|
4
|
+
module.exports = class FFmpegChannelLayout {
|
|
5
|
+
constructor(handle) {
|
|
6
|
+
this._handle = handle
|
|
7
|
+
}
|
|
8
|
+
|
|
9
|
+
get nbChannels() {
|
|
10
|
+
return binding.getChannelLayoutNbChannels(this._handle)
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
get mask() {
|
|
14
|
+
return binding.getChannelLayoutMask(this._handle)
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
static from(value) {
|
|
18
|
+
if (typeof value === 'string') value = constants.toChannelLayout(value)
|
|
19
|
+
|
|
20
|
+
if (typeof value === 'number') {
|
|
21
|
+
value = binding.channelLayoutFromMask(value)
|
|
22
|
+
} else if (typeof value === 'object' && value !== null) {
|
|
23
|
+
value = binding.copyChannelLayout(value._handle)
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
return new this(value)
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
[Symbol.for('bare.inspect')]() {
|
|
30
|
+
return {
|
|
31
|
+
__proto__: { constructor: FFmpegChannelLayout },
|
|
32
|
+
nbChannels: this.nbChannels
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
}
|
package/lib/codec-context.js
CHANGED
|
@@ -1,17 +1,15 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
|
-
const ReferenceCounted = require('./reference-counted')
|
|
3
2
|
const Rational = require('./rational')
|
|
3
|
+
const ChannelLayout = require('./channel-layout')
|
|
4
4
|
|
|
5
|
-
module.exports = class FFmpegCodecContext
|
|
5
|
+
module.exports = class FFmpegCodecContext {
|
|
6
6
|
constructor(codec) {
|
|
7
|
-
super()
|
|
8
|
-
|
|
9
7
|
this._codec = codec
|
|
10
8
|
this._opened = false
|
|
11
9
|
this._handle = binding.initCodecContext(codec._handle)
|
|
12
10
|
}
|
|
13
11
|
|
|
14
|
-
|
|
12
|
+
destroy() {
|
|
15
13
|
binding.destroyCodecContext(this._handle)
|
|
16
14
|
this._handle = null
|
|
17
15
|
}
|
|
@@ -40,16 +38,73 @@ module.exports = class FFmpegCodecContext extends ReferenceCounted {
|
|
|
40
38
|
binding.setCodecContextHeight(this._handle, value)
|
|
41
39
|
}
|
|
42
40
|
|
|
41
|
+
get sampleFormat() {
|
|
42
|
+
return binding.getCodecContextSampleFormat(this._handle)
|
|
43
|
+
}
|
|
44
|
+
|
|
45
|
+
set sampleFormat(value) {
|
|
46
|
+
return binding.setCodecContextSampleFormat(this._handle, value)
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
get sampleRate() {
|
|
50
|
+
return binding.getCodecContextSampleRate(this._handle)
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
set sampleRate(value) {
|
|
54
|
+
binding.setCodecContextSampleRate(this._handle, value)
|
|
55
|
+
}
|
|
56
|
+
|
|
43
57
|
get timeBase() {
|
|
44
58
|
const view = new Int32Array(binding.getCodecContextTimeBase(this._handle))
|
|
45
59
|
return new Rational(view[0], view[1])
|
|
46
60
|
}
|
|
47
61
|
|
|
48
62
|
set timeBase(value) {
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
63
|
+
binding.setCodecContextTimeBase(
|
|
64
|
+
this._handle,
|
|
65
|
+
value.numerator,
|
|
66
|
+
value.denominator
|
|
67
|
+
)
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
get frameRate() {
|
|
71
|
+
const view = new Int32Array(binding.getCodecContextFramerate(this._handle))
|
|
72
|
+
return new Rational(view[0], view[1])
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
set frameRate(value) {
|
|
76
|
+
binding.setCodecContextFramerate(
|
|
77
|
+
this._handle,
|
|
78
|
+
value.numerator,
|
|
79
|
+
value.denominator
|
|
80
|
+
)
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
get channelLayout() {
|
|
84
|
+
return new ChannelLayout(binding.getCodecContextChannelLayout(this._handle))
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
set channelLayout(value) {
|
|
88
|
+
binding.setCodecContextChannelLayout(
|
|
89
|
+
this._handle,
|
|
90
|
+
ChannelLayout.from(value)._handle
|
|
91
|
+
)
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
get gopSize() {
|
|
95
|
+
return binding.getCodecContextGOPSize(this._handle)
|
|
96
|
+
}
|
|
97
|
+
|
|
98
|
+
set gopSize(value) {
|
|
99
|
+
binding.setCodecContextGOPSize(this._handle, value)
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
get flags() {
|
|
103
|
+
return binding.getCodecContextFlags(this._handle)
|
|
104
|
+
}
|
|
105
|
+
|
|
106
|
+
set flags(value) {
|
|
107
|
+
binding.setCodecContextFlags(this._handle, value)
|
|
53
108
|
}
|
|
54
109
|
|
|
55
110
|
open(options) {
|
|
@@ -64,21 +119,43 @@ module.exports = class FFmpegCodecContext extends ReferenceCounted {
|
|
|
64
119
|
}
|
|
65
120
|
|
|
66
121
|
sendPacket(packet) {
|
|
67
|
-
binding.sendCodecContextPacket(this._handle, packet._handle)
|
|
68
|
-
return this
|
|
122
|
+
return binding.sendCodecContextPacket(this._handle, packet._handle)
|
|
69
123
|
}
|
|
70
124
|
|
|
71
125
|
receivePacket(packet) {
|
|
72
|
-
|
|
73
|
-
if (res) packet._ref()
|
|
74
|
-
return res
|
|
126
|
+
return binding.receiveCodecContextPacket(this._handle, packet._handle)
|
|
75
127
|
}
|
|
76
128
|
|
|
77
129
|
sendFrame(frame) {
|
|
78
|
-
|
|
130
|
+
let frameHandle = undefined
|
|
131
|
+
|
|
132
|
+
if (frame) frameHandle = frame._handle
|
|
133
|
+
|
|
134
|
+
return binding.sendCodecContextFrame(this._handle, frameHandle)
|
|
79
135
|
}
|
|
80
136
|
|
|
81
137
|
receiveFrame(frame) {
|
|
82
138
|
return binding.receiveCodecContextFrame(this._handle, frame._handle)
|
|
83
139
|
}
|
|
140
|
+
|
|
141
|
+
[Symbol.dispose]() {
|
|
142
|
+
this.destroy()
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
[Symbol.for('bare.inspect')]() {
|
|
146
|
+
return {
|
|
147
|
+
__proto__: { constructor: FFmpegCodecContext },
|
|
148
|
+
_codec: this._codec,
|
|
149
|
+
_opened: this._opened,
|
|
150
|
+
flags: this.flags,
|
|
151
|
+
pixelFormat: this.pixelFormat,
|
|
152
|
+
width: this.width,
|
|
153
|
+
height: this.height,
|
|
154
|
+
sampleFormat: this.sampleFormat,
|
|
155
|
+
sampleRate: this.sampleRate,
|
|
156
|
+
timeBase: this.timeBase,
|
|
157
|
+
channelLayout: this.channelLayout,
|
|
158
|
+
gopSize: this.gopSize
|
|
159
|
+
}
|
|
160
|
+
}
|
|
84
161
|
}
|
package/lib/codec-parameters.js
CHANGED
|
@@ -1,33 +1,157 @@
|
|
|
1
1
|
const binding = require('../binding')
|
|
2
|
-
const
|
|
2
|
+
const ChannelLayout = require('./channel-layout')
|
|
3
|
+
const Rational = require('./rational')
|
|
3
4
|
|
|
4
|
-
module.exports = class FFmpegCodecParameters
|
|
5
|
+
module.exports = class FFmpegCodecParameters {
|
|
5
6
|
constructor(handle) {
|
|
6
|
-
super()
|
|
7
|
-
|
|
8
7
|
this._handle = handle
|
|
9
8
|
}
|
|
10
9
|
|
|
11
|
-
_destroy() {
|
|
12
|
-
this._handle = null
|
|
13
|
-
}
|
|
14
|
-
|
|
15
10
|
get bitRate() {
|
|
16
11
|
return binding.getCodecParametersBitRate(this._handle)
|
|
17
12
|
}
|
|
18
13
|
|
|
14
|
+
set bitRate(rate) {
|
|
15
|
+
binding.setCodecParametersBitRate(this._handle, rate)
|
|
16
|
+
}
|
|
17
|
+
|
|
19
18
|
get bitsPerCodedSample() {
|
|
20
19
|
return binding.getCodecParametersBitsPerCodedSample(this._handle)
|
|
21
20
|
}
|
|
22
21
|
|
|
22
|
+
set bitsPerCodedSample(bits) {
|
|
23
|
+
binding.setCodecParametersBitsPerCodedSample(this._handle, bits)
|
|
24
|
+
}
|
|
25
|
+
|
|
23
26
|
get bitsPerRawSample() {
|
|
24
27
|
return binding.getCodecParametersBitsPerRawSample(this._handle)
|
|
25
28
|
}
|
|
26
29
|
|
|
30
|
+
set bitsPerRawSample(bits) {
|
|
31
|
+
binding.setCodecParametersBitsPerRawSample(this._handle, bits)
|
|
32
|
+
}
|
|
33
|
+
|
|
27
34
|
get sampleRate() {
|
|
28
35
|
return binding.getCodecParametersSampleRate(this._handle)
|
|
29
36
|
}
|
|
30
37
|
|
|
38
|
+
set sampleRate(rate) {
|
|
39
|
+
binding.setCodecParametersSampleRate(this._handle, rate)
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
get frameRate() {
|
|
43
|
+
const view = new Int32Array(
|
|
44
|
+
binding.getCodecParametersFramerate(this._handle)
|
|
45
|
+
)
|
|
46
|
+
return new Rational(view[0], view[1])
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
set frameRate(rate) {
|
|
50
|
+
binding.setCodecParametersFramerate(
|
|
51
|
+
this._handle,
|
|
52
|
+
rate.numerator,
|
|
53
|
+
rate.denominator
|
|
54
|
+
)
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
get nbChannels() {
|
|
58
|
+
return binding.getCodecParametersNbChannels(this._handle)
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
set nbChannels(numberOfChannels) {
|
|
62
|
+
binding.setCodecParametersNbChannels(this._handle, numberOfChannels)
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
get type() {
|
|
66
|
+
return binding.getCodecParametersType(this._handle)
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
set type(type) {
|
|
70
|
+
binding.setCodecParametersType(this._handle, type)
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
get tag() {
|
|
74
|
+
return binding.getCodecParametersTag(this._handle)
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
set tag(tag) {
|
|
78
|
+
binding.setCodecParametersTag(this._handle, tag)
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
get id() {
|
|
82
|
+
return binding.getCodecParametersId(this._handle)
|
|
83
|
+
}
|
|
84
|
+
|
|
85
|
+
set id(id) {
|
|
86
|
+
binding.setCodecParametersId(this._handle, id)
|
|
87
|
+
}
|
|
88
|
+
|
|
89
|
+
get level() {
|
|
90
|
+
return binding.getCodecParametersLevel(this._handle)
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
set level(level) {
|
|
94
|
+
binding.setCodecParametersLevel(this._handle, level)
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
get profile() {
|
|
98
|
+
return binding.getCodecParametersProfile(this._handle)
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
set profile(profile) {
|
|
102
|
+
binding.setCodecParametersProfile(this._handle, profile)
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
get format() {
|
|
106
|
+
return binding.getCodecParametersFormat(this._handle)
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
set format(format) {
|
|
110
|
+
binding.setCodecParametersFormat(this._handle, format)
|
|
111
|
+
}
|
|
112
|
+
|
|
113
|
+
get channelLayout() {
|
|
114
|
+
return new ChannelLayout(
|
|
115
|
+
binding.getCodecParametersChannelLayout(this._handle)
|
|
116
|
+
)
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
set channelLayout(value) {
|
|
120
|
+
binding.setCodecParametersChannelLayout(
|
|
121
|
+
this._handle,
|
|
122
|
+
ChannelLayout.from(value)._handle
|
|
123
|
+
)
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
get width() {
|
|
127
|
+
return binding.getCodecParametersWidth(this._handle)
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
set width(value) {
|
|
131
|
+
binding.setCodecParametersWidth(this._handle, value)
|
|
132
|
+
}
|
|
133
|
+
|
|
134
|
+
get height() {
|
|
135
|
+
return binding.getCodecParametersHeight(this._handle)
|
|
136
|
+
}
|
|
137
|
+
|
|
138
|
+
set height(value) {
|
|
139
|
+
binding.setCodecParametersHeight(this._handle, value)
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
get extraData() {
|
|
143
|
+
return Buffer.from(binding.getCodecParametersExtraData(this._handle))
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
set extraData(value) {
|
|
147
|
+
binding.setCodecParametersExtraData(
|
|
148
|
+
this._handle,
|
|
149
|
+
value.buffer,
|
|
150
|
+
value.byteOffset,
|
|
151
|
+
value.byteLength
|
|
152
|
+
)
|
|
153
|
+
}
|
|
154
|
+
|
|
31
155
|
fromContext(context) {
|
|
32
156
|
binding.codecParametersFromContext(this._handle, context._handle)
|
|
33
157
|
}
|
|
@@ -35,4 +159,26 @@ module.exports = class FFmpegCodecParameters extends ReferenceCounted {
|
|
|
35
159
|
toContext(context) {
|
|
36
160
|
binding.codecParametersToContext(context._handle, this._handle)
|
|
37
161
|
}
|
|
162
|
+
|
|
163
|
+
// TODO: add other props
|
|
164
|
+
[Symbol.for('bare.inspect')]() {
|
|
165
|
+
return {
|
|
166
|
+
__proto__: { constructor: FFmpegCodecParameters },
|
|
167
|
+
type: this.type,
|
|
168
|
+
id: this.id,
|
|
169
|
+
format: this.format,
|
|
170
|
+
profile: this.profile,
|
|
171
|
+
level: this.level,
|
|
172
|
+
width: this.width,
|
|
173
|
+
height: this.height,
|
|
174
|
+
bitRate: this.bitRate,
|
|
175
|
+
bitsPerCodedSample: this.bitsPerCodedSample,
|
|
176
|
+
bitsPerRawSample: this.bitsPerRawSample,
|
|
177
|
+
sampleRate: this.sampleRate,
|
|
178
|
+
nbChannels: this.nbChannels,
|
|
179
|
+
channelLayout: this.channelLayout,
|
|
180
|
+
frameRate: this.frameRate,
|
|
181
|
+
extraData: this.extraData
|
|
182
|
+
}
|
|
183
|
+
}
|
|
38
184
|
}
|
package/lib/codec.js
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
const Decoder = require('./decoder')
|
|
2
2
|
const Encoder = require('./encoder')
|
|
3
3
|
const constants = require('./constants')
|
|
4
|
+
const binding = require('../binding')
|
|
4
5
|
|
|
5
6
|
const codecs = new Map()
|
|
6
7
|
|
|
@@ -25,6 +26,21 @@ module.exports = class FFmpegCodec {
|
|
|
25
26
|
return this._encoder
|
|
26
27
|
}
|
|
27
28
|
|
|
29
|
+
get name() {
|
|
30
|
+
if (Number.isInteger(this._id)) {
|
|
31
|
+
return binding.getCodecNameByID(this._id)
|
|
32
|
+
}
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
[Symbol.for('bare.inspect')]() {
|
|
36
|
+
return {
|
|
37
|
+
__proto__: { constructor: FFmpegCodec },
|
|
38
|
+
id: this.id,
|
|
39
|
+
name: this.name
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
/** @return {FFmpegCodec} */
|
|
28
44
|
static for(id) {
|
|
29
45
|
let codec = codecs.get(id)
|
|
30
46
|
if (codec === undefined) {
|
|
@@ -36,4 +52,7 @@ module.exports = class FFmpegCodec {
|
|
|
36
52
|
|
|
37
53
|
static MJPEG = this.for(constants.codecs.MJPEG)
|
|
38
54
|
static H264 = this.for(constants.codecs.H264)
|
|
55
|
+
static AAC = this.for(constants.codecs.AAC)
|
|
56
|
+
static OPUS = this.for(constants.codecs.OPUS)
|
|
57
|
+
static AV1 = this.for(constants.codecs.AV1)
|
|
39
58
|
}
|