@lumen5/beamcoder 0.0.1

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 (88) hide show
  1. package/.circleci/config.yml +41 -0
  2. package/.circleci/images/testbeam10-4.1/Dockerfile +12 -0
  3. package/.circleci/test_image/Dockerfile +14 -0
  4. package/.circleci/test_image/build.md +13 -0
  5. package/.eslintrc.js +27 -0
  6. package/.github/workflows/publish-npm.yml +33 -0
  7. package/LICENSE +674 -0
  8. package/README.md +1221 -0
  9. package/beamstreams.js +692 -0
  10. package/binding.gyp +103 -0
  11. package/examples/encode_h264.js +92 -0
  12. package/examples/jpeg_app.js +55 -0
  13. package/examples/jpeg_filter_app.js +101 -0
  14. package/examples/make_mp4.js +123 -0
  15. package/images/beamcoder_small.jpg +0 -0
  16. package/index.d.ts +83 -0
  17. package/index.js +44 -0
  18. package/install_ffmpeg.js +240 -0
  19. package/package.json +45 -0
  20. package/scratch/decode_aac.js +38 -0
  21. package/scratch/decode_avci.js +50 -0
  22. package/scratch/decode_hevc.js +38 -0
  23. package/scratch/decode_pcm.js +39 -0
  24. package/scratch/make_a_mux.js +68 -0
  25. package/scratch/muxer.js +74 -0
  26. package/scratch/read_wav.js +35 -0
  27. package/scratch/simple_mux.js +39 -0
  28. package/scratch/stream_avci.js +127 -0
  29. package/scratch/stream_mp4.js +78 -0
  30. package/scratch/stream_mux.js +47 -0
  31. package/scratch/stream_pcm.js +82 -0
  32. package/scratch/stream_wav.js +62 -0
  33. package/scripts/install_beamcoder_dependencies.sh +25 -0
  34. package/src/adaptor.h +202 -0
  35. package/src/beamcoder.cc +937 -0
  36. package/src/beamcoder_util.cc +1129 -0
  37. package/src/beamcoder_util.h +206 -0
  38. package/src/codec.cc +7386 -0
  39. package/src/codec.h +44 -0
  40. package/src/codec_par.cc +1818 -0
  41. package/src/codec_par.h +40 -0
  42. package/src/decode.cc +569 -0
  43. package/src/decode.h +75 -0
  44. package/src/demux.cc +584 -0
  45. package/src/demux.h +88 -0
  46. package/src/encode.cc +496 -0
  47. package/src/encode.h +72 -0
  48. package/src/filter.cc +1888 -0
  49. package/src/filter.h +30 -0
  50. package/src/format.cc +5287 -0
  51. package/src/format.h +77 -0
  52. package/src/frame.cc +2681 -0
  53. package/src/frame.h +52 -0
  54. package/src/governor.cc +286 -0
  55. package/src/governor.h +30 -0
  56. package/src/hwcontext.cc +378 -0
  57. package/src/hwcontext.h +35 -0
  58. package/src/log.cc +186 -0
  59. package/src/log.h +20 -0
  60. package/src/mux.cc +834 -0
  61. package/src/mux.h +106 -0
  62. package/src/packet.cc +762 -0
  63. package/src/packet.h +49 -0
  64. package/test/codecParamsSpec.js +148 -0
  65. package/test/decoderSpec.js +56 -0
  66. package/test/demuxerSpec.js +41 -0
  67. package/test/encoderSpec.js +69 -0
  68. package/test/filtererSpec.js +47 -0
  69. package/test/formatSpec.js +343 -0
  70. package/test/frameSpec.js +145 -0
  71. package/test/introspectionSpec.js +73 -0
  72. package/test/muxerSpec.js +34 -0
  73. package/test/packetSpec.js +122 -0
  74. package/types/Beamstreams.d.ts +98 -0
  75. package/types/Codec.d.ts +123 -0
  76. package/types/CodecContext.d.ts +555 -0
  77. package/types/CodecPar.d.ts +108 -0
  78. package/types/Decoder.d.ts +137 -0
  79. package/types/Demuxer.d.ts +113 -0
  80. package/types/Encoder.d.ts +94 -0
  81. package/types/Filter.d.ts +324 -0
  82. package/types/FormatContext.d.ts +380 -0
  83. package/types/Frame.d.ts +295 -0
  84. package/types/HWContext.d.ts +62 -0
  85. package/types/Muxer.d.ts +121 -0
  86. package/types/Packet.d.ts +82 -0
  87. package/types/PrivClass.d.ts +25 -0
  88. package/types/Stream.d.ts +165 -0
@@ -0,0 +1,240 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings to FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const os = require('os');
23
+ const fs = require('fs');
24
+ const util = require('util');
25
+ const https = require('https');
26
+ const cp = require('child_process');
27
+ const [ mkdir, access, rename, execFile, exec ] = // eslint-disable-line
28
+ [ fs.mkdir, fs.access, fs.rename, cp.execFile, cp.exec ].map(util.promisify);
29
+
30
+ async function get(ws, url, name) {
31
+ let received = 0;
32
+ let totalLength = 0;
33
+ return new Promise((comp, err) => {
34
+ https.get(url, res => {
35
+ if (res.statusCode === 301 || res.statusCode === 302) {
36
+ err({ name: 'RedirectError', message: res.headers.location });
37
+ } else {
38
+ res.pipe(ws);
39
+ if (totalLength == 0) {
40
+ totalLength = +res.headers['content-length'];
41
+ }
42
+ res.on('end', () => {
43
+ process.stdout.write(`Downloaded 100% of '${name}'. Total length ${received} bytes.\n`);
44
+ comp();
45
+ });
46
+ res.on('error', err);
47
+ res.on('data', x => {
48
+ received += x.length;
49
+ process.stdout.write(`Downloaded ${received * 100/ totalLength | 0 }% of '${name}'.\r`);
50
+ });
51
+ }
52
+ }).on('error', err);
53
+ });
54
+ }
55
+
56
+ async function getHTML(url, name) {
57
+ let received = 0;
58
+ let totalLength = 0;
59
+ return new Promise((resolve, reject) => {
60
+ https.get(url, res => {
61
+ const chunks = [];
62
+ if (totalLength == 0) {
63
+ totalLength = +res.headers['content-length'];
64
+ }
65
+ res.on('end', () => {
66
+ process.stdout.write(`Downloaded 100% of '${name}'. Total length ${received} bytes.\n`);
67
+ resolve(Buffer.concat(chunks));
68
+ });
69
+ res.on('error', reject);
70
+ res.on('data', (chunk) => {
71
+ chunks.push(chunk);
72
+ received += chunk.length;
73
+ process.stdout.write(`Downloaded ${received * 100/ totalLength | 0 }% of '${name}'.\r`);
74
+ });
75
+ }).on('error', reject);
76
+ });
77
+ }
78
+
79
+ async function inflate(rs, folder, name) {
80
+ const unzip = require('unzipper');
81
+ const directory = await unzip.Open.file(`${folder}/${name}.zip`);
82
+ const directoryName = directory.files[0].path;
83
+ return new Promise((comp, err) => {
84
+ console.log(`Unzipping '${folder}/${name}.zip'.`);
85
+ rs.pipe(unzip.Extract({ path: folder }).on('close', () => {
86
+ fs.rename(`./${folder}/${directoryName}`, `./${folder}/${name}`, () => {
87
+ console.log(`Unzipping of '${folder}/${name}.zip' completed.`);
88
+ comp();
89
+ });
90
+ }));
91
+ rs.on('error', err);
92
+ });
93
+ }
94
+
95
+ async function win32() {
96
+ console.log('Checking/Installing FFmpeg dependencies for Beam Coder on Windows.');
97
+
98
+ await mkdir('ffmpeg').catch(e => {
99
+ if (e.code === 'EEXIST') return;
100
+ else throw e;
101
+ });
102
+
103
+ const ffmpegFilename = 'ffmpeg-5.x-win64-shared';
104
+ await access(`ffmpeg/${ffmpegFilename}`, fs.constants.R_OK).catch(async () => {
105
+ const html = await getHTML('https://github.com/BtbN/FFmpeg-Builds/wiki/Latest', 'latest autobuilds');
106
+ const htmlStr = html.toString('utf-8');
107
+ const autoPos = htmlStr.indexOf('<p><a href=');
108
+ const endPos = htmlStr.indexOf('</div>', autoPos);
109
+ const autoStr = htmlStr.substring(autoPos, endPos);
110
+ const sharedEndPos = autoStr.lastIndexOf('">win64-gpl-shared-5.');
111
+ if (sharedEndPos === -1)
112
+ throw new Error('Failed to find latest v4.x autobuild from "https://github.com/BtbN/FFmpeg-Builds/wiki/Latest"');
113
+ const startStr = '<p><a href="';
114
+ const sharedStartPos = autoStr.lastIndexOf(startStr, sharedEndPos) + startStr.length;
115
+ const downloadSource = autoStr.substring(sharedStartPos, sharedEndPos);
116
+
117
+ let ws_shared = fs.createWriteStream(`ffmpeg/${ffmpegFilename}.zip`);
118
+ await get(ws_shared, downloadSource, `${ffmpegFilename}.zip`)
119
+ .catch(async (err) => {
120
+ if (err.name === 'RedirectError') {
121
+ const redirectURL = err.message;
122
+ await get(ws_shared, redirectURL, `${ffmpegFilename}.zip`);
123
+ } else console.error(err);
124
+ });
125
+
126
+ await exec('npm install unzipper --no-save');
127
+ let rs_shared = fs.createReadStream(`ffmpeg/${ffmpegFilename}.zip`);
128
+ await inflate(rs_shared, 'ffmpeg', `${ffmpegFilename}`);
129
+ });
130
+ }
131
+
132
+ async function linux() {
133
+ console.log('Checking FFmpeg dependencies for Beam Coder on Linux.');
134
+ const { stdout } = await execFile('ldconfig', ['-p']).catch(console.error);
135
+ let result = 0;
136
+
137
+ if (stdout.indexOf('libavcodec.so.59') < 0) {
138
+ console.error('libavcodec.so.59 is not installed.');
139
+ result = 1;
140
+ }
141
+ if (stdout.indexOf('libavformat.so.59') < 0) {
142
+ console.error('libavformat.so.59 is not installed.');
143
+ result = 1;
144
+ }
145
+ if (stdout.indexOf('libavdevice.so.59') < 0) {
146
+ console.error('libavdevice.so.59 is not installed.');
147
+ result = 1;
148
+ }
149
+ if (stdout.indexOf('libavfilter.so.8') < 0) {
150
+ console.error('libavfilter.so.8 is not installed.');
151
+ result = 1;
152
+ }
153
+ if (stdout.indexOf('libavutil.so.57') < 0) {
154
+ console.error('libavutil.so.57 is not installed.');
155
+ result = 1;
156
+ }
157
+ if (stdout.indexOf('libpostproc.so.56') < 0) {
158
+ console.error('libpostproc.so.56 is not installed.');
159
+ result = 1;
160
+ }
161
+ if (stdout.indexOf('libswresample.so.4') < 0) {
162
+ console.error('libswresample.so.4 is not installed.');
163
+ result = 1;
164
+ }
165
+ if (stdout.indexOf('libswscale.so.6') < 0) {
166
+ console.error('libswscale.so.6 is not installed.');
167
+ result = 1;
168
+ }
169
+
170
+ if (result === 1) {
171
+ console.log(`Try running the following (Ubuntu/Debian):
172
+ sudo add-apt-repository ppa:jonathonf/ffmpeg-4
173
+ sudo apt-get install libavcodec-dev libavformat-dev libavdevice-dev libavfilter-dev libavutil-dev libpostproc-dev libswresample-dev libswscale-dev`);
174
+ process.exit(1);
175
+ }
176
+ return result;
177
+ }
178
+
179
+ async function darwin() {
180
+ console.log('Checking for FFmpeg dependencies via HomeBrew.');
181
+ let output;
182
+ let returnMessage;
183
+
184
+ try {
185
+ output = await exec('brew list ffmpeg@5');
186
+ returnMessage = 'FFmpeg already present via Homebrew.';
187
+ } catch (err) {
188
+ if (err.stderr.indexOf('Error: No such keg') === -1 &&
189
+ err.stderr.indexOf('ffmpeg@5') === -1) {
190
+ console.error(err);
191
+ console.log('Either Homebrew is not installed or something else is wrong.\nExiting');
192
+ process.exit(1);
193
+ }
194
+
195
+ console.log('FFmpeg not installed. Attempting to install via Homebrew.');
196
+ try {
197
+ output = await exec('brew install nasm pkg-config texi2html ffmpeg@5');
198
+ returnMessage = 'FFmpeg installed via Homebrew.';
199
+ } catch (err) {
200
+ console.log('Failed to install ffmpeg:\n');
201
+ console.error(err);
202
+ process.exit(1);
203
+ }
204
+ }
205
+
206
+ console.log(output.stdout);
207
+ console.log(returnMessage);
208
+
209
+ return 0;
210
+ }
211
+
212
+ switch (os.platform()) {
213
+ case 'win32':
214
+ if (os.arch() != 'x64') {
215
+ console.error('Only 64-bit platforms are supported.');
216
+ process.exit(1);
217
+ } else {
218
+ win32().catch(console.error);
219
+ }
220
+ break;
221
+ case 'linux':
222
+ if (os.arch() != 'x64' && os.arch() != 'arm64') {
223
+ console.error('Only 64-bit platforms are supported.');
224
+ process.exit(1);
225
+ } else {
226
+ linux();
227
+ }
228
+ break;
229
+ case 'darwin':
230
+ if (os.arch() != 'x64' && os.arch() != 'arm64') {
231
+ console.error('Only 64-bit platforms are supported.');
232
+ process.exit(1);
233
+ } else {
234
+ darwin();
235
+ }
236
+ break;
237
+ default:
238
+ console.error(`Platfrom ${os.platform()} is not supported.`);
239
+ break;
240
+ }
package/package.json ADDED
@@ -0,0 +1,45 @@
1
+ {
2
+ "name": "@lumen5/beamcoder",
3
+ "version": "0.0.1",
4
+ "description": "Node.js native bindings to FFmpeg.",
5
+ "main": "index.js",
6
+ "types": "index.d.ts",
7
+ "scripts": {
8
+ "preinstall": "node install_ffmpeg.js",
9
+ "install": "node-gyp rebuild",
10
+ "test": "tape test/*.js",
11
+ "lint": "eslint **/*.js",
12
+ "lint-html": "eslint **/*.js -f html -o ./reports/lint-results.html",
13
+ "lint-fix": "eslint --fix **/*.js"
14
+ },
15
+ "repository": {
16
+ "type": "git",
17
+ "url": "git+https://github.com/Streampunk/beamcoder.git"
18
+ },
19
+ "keywords": [
20
+ "FFmpeg",
21
+ "libav",
22
+ "video",
23
+ "audio",
24
+ "sound",
25
+ "encode",
26
+ "decode",
27
+ "transcode",
28
+ "N-API"
29
+ ],
30
+ "author": "Streampunk Media Ltd",
31
+ "license": "GPL-3.0-or-later",
32
+ "bugs": {
33
+ "url": "https://github.com/Streampunk/beamcoder/issues"
34
+ },
35
+ "homepage": "https://github.com/Streampunk/beamcoder#readme",
36
+ "dependencies": {
37
+ "bindings": "^1.5.0",
38
+ "segfault-handler": "^1.3.0"
39
+ },
40
+ "devDependencies": {
41
+ "eslint": "^8.9.0",
42
+ "tape": "^5.5.2"
43
+ },
44
+ "gypfile": true
45
+ }
@@ -0,0 +1,38 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const beamcoder = require('../index.js');
23
+
24
+ async function run() {
25
+ let demuxer = await beamcoder.demuxer({ url: '../media/bbb_1080p_c.ts'});
26
+ let decoder = beamcoder.decoder({ name: 'aac' });
27
+ let packet = {};
28
+ for ( let x = 0 ; packet !== null && x < 100 ; x++ ) {
29
+ packet = await demuxer.read();
30
+ if (packet.stream_index == 1) {
31
+ console.log(JSON.stringify(packet, null, 2));
32
+ let frames = await decoder.decode(packet);
33
+ console.log(JSON.stringify(frames.frames[0], null, 2));
34
+ }
35
+ }
36
+ }
37
+
38
+ run();
@@ -0,0 +1,50 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const beamcoder = require('../index.js');
23
+
24
+ async function run() {
25
+ // let demuxer = await beamcoder.demuxer('../media/dpp/AS11_DPP_HD_EXAMPLE_1.mxf');
26
+ // console.log(JSON.stringify(demuxer, null, 2));
27
+ let demuxer = await beamcoder.demuxer('M:/dpp/AS11_4K_8.mxf');
28
+ // let demuxer = await beamcoder.demuxer('M:/dpp/AS11.mxf');
29
+ demuxer.streams.forEach(s => s.discard = (0 == s.index) ? 'default' : 'all');
30
+ // let decoder = beamcoder.decoder({ name: 'h264', thread_count: 4, thread_type: { FRAME: false, SLICE: true } });
31
+ let decoder = beamcoder.decoder({ name: 'h264', thread_count: 1, hwaccel: true });
32
+ // console.dir(decoder, { getters: true, depth: 3 });
33
+ let packet = {};
34
+ for ( let x = 0 ; x < 2000 && packet != null; x++ ) {
35
+ packet = await demuxer.read();
36
+ if (packet && packet.stream_index === 0) {
37
+ //console.log(JSON.stringify(packet, null, 2));
38
+ let frames = await decoder.decode(packet);
39
+ // console.log(JSON.stringify(frames.frames[0], null, 2));
40
+ if (frames.frames[0]) {
41
+ console.log(frames.frames[0].data);
42
+ }
43
+ console.log(x, frames.total_time);
44
+ }
45
+ }
46
+ let frames = await decoder.flush();
47
+ console.log('flush', frames.total_time, frames.length);
48
+ }
49
+
50
+ run();
@@ -0,0 +1,38 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const beamcoder = require('../index.js');
23
+
24
+ async function run() {
25
+ let demuxer = await beamcoder.demuxer('../media/bbb_1080p_c.ts');
26
+ console.log(demuxer);
27
+ let decoder = await beamcoder.decoder({ name: 'hevc' });
28
+ for ( let x = 0 ; x < 100 ; x++ ) {
29
+ let packet = await demuxer.read();
30
+ if (packet.stream_index == 0) {
31
+ // console.log(packet);
32
+ let frames = await decoder.decode(packet); // eslint-disable-line
33
+ // console.log(frames);
34
+ }
35
+ }
36
+ }
37
+
38
+ run();
@@ -0,0 +1,39 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const beamcoder = require('../index.js');
23
+
24
+ async function run() {
25
+ let demuxer = await beamcoder.demuxer('../media/dpp/AS11_DPP_HD_EXAMPLE_1.mxf');
26
+ console.log(demuxer.streams[1]);
27
+ let decoder = await beamcoder.decoder({ demuxer: demuxer, stream_index : 1 });
28
+ console.log(decoder);
29
+ for ( let x = 0 ; x < 100 ; x++ ) {
30
+ let packet = await demuxer.read();
31
+ if (packet.stream == 1) {
32
+ //console.log(packet);
33
+ let frames = await decoder.decode(packet);
34
+ console.log(frames.frames);
35
+ }
36
+ }
37
+ }
38
+
39
+ run();
@@ -0,0 +1,68 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const beamcoder = require('../index.js');
23
+
24
+ async function run() {
25
+ let demuxer = await beamcoder.demuxer('../media/sound/BBCNewsCountdown.wav');
26
+ console.log(demuxer.streams[0].codecpar);
27
+ let muxer = beamcoder.muxer({ filename: 'file:test.wav' });
28
+ let stream = muxer.newStream({
29
+ name: 'pcm_s16le',
30
+ time_base: [1, 48000 ],
31
+ interleaved: false, });
32
+ Object.assign(stream.codecpar, {
33
+ channels: 2,
34
+ sample_rate: 48000,
35
+ format: 's16',
36
+ channel_layout: 'stereo',
37
+ block_align: 4,
38
+ bits_per_coded_sample: 16,
39
+ bit_rate: 48000 * 4 * 8
40
+ });
41
+ /* let stream = muxer.newStream({
42
+ name: 'pcm_s16le',
43
+ time_base: [1, 48000 ],
44
+ codecpar: {
45
+ name: 'pcm_s16le',
46
+ channels: 2,
47
+ sample_rate: 48000,
48
+ format: 's16',
49
+ channel_layout: 'stereo',
50
+ block_align: 4,
51
+ bits_per_coded_sample: 16,
52
+ bit_rate: 48000*4
53
+ }
54
+ }); */
55
+ console.log(stream.codecpar);
56
+ // stream.time_base = demuxer.streams[0].time_base;
57
+ // stream.codecpar = demuxer.streams[0].codecpar;
58
+ await muxer.openIO({ options: { blocksize: 8192 }}).then(console.log);
59
+ await muxer.writeHeader({ options: { write_bext: true, write_peak: 'on', peak_format: 2 }}).then(console.log);
60
+ let packet = {};
61
+ for ( let x = 0 ; x < 100 && packet !== null ; x++ ) {
62
+ packet = await demuxer.read();
63
+ await muxer.writeFrame(packet);
64
+ }
65
+ await muxer.writeTrailer();
66
+ }
67
+
68
+ run();
@@ -0,0 +1,74 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ // Work in progress
23
+
24
+ const beamcoder = require('../index.js');
25
+
26
+ const STREAM_FRAME_RATE = 25;
27
+
28
+ function allocAudioFrame(sampleFormat, channelLayout, sampleRate, nbSamples) {
29
+
30
+ return beamcoder.frame({
31
+ format: sampleFormat,
32
+ channel_layout: channelLayout,
33
+ sample_rate: sampleRate,
34
+ nb_samples: nbSamples
35
+ }).alloc();
36
+ }
37
+
38
+ function allocPicture(pixelFmt, width, height) { // eslint-disable-line
39
+
40
+ return beamcoder.frame({
41
+ format: pixelFmt,
42
+ width: width,
43
+ height: height
44
+ }).alloc();
45
+ }
46
+
47
+ async function addStream(stream, muxer, codecID) { // eslint-disable-line
48
+ let codec = await beamcoder.encoder({ codec_id: codecID });
49
+
50
+ stream.st = muxer.newStream();
51
+ stream.enc = codec;
52
+ switch (codec.media_type) {
53
+ case 'video':
54
+ codec.setParameters({
55
+ codec_id: codecID,
56
+ bit_rate: 400000,
57
+ width: 352,
58
+ height: 288,
59
+ time_base: [1, STREAM_FRAME_RATE],
60
+ gop_size: 12
61
+ });
62
+ break;
63
+ case 'audio':
64
+ break;
65
+ default:
66
+ break;
67
+ }
68
+ }
69
+
70
+ async function run() {
71
+ allocAudioFrame('s32p', 'stereo', 48000, 1920);
72
+ }
73
+
74
+ run();
@@ -0,0 +1,35 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+
22
+ const beamcoder = require('../index.js');
23
+
24
+ async function run() {
25
+ let demuxer = await beamcoder.demuxer('../media/sound/BBCNewsCountdown.wav');
26
+ let packet = {};
27
+ for ( let x = 0 ; x < 100 && packet !== null ; x++ ) {
28
+ packet = await demuxer.read();
29
+ console.log(x, packet);
30
+ }
31
+ console.log(await demuxer.seek({ frame : 120 }));
32
+ console.log(await demuxer.read());
33
+ }
34
+
35
+ run();
@@ -0,0 +1,39 @@
1
+ /*
2
+ Aerostat Beam Coder - Node.js native bindings for FFmpeg.
3
+ Copyright (C) 2019 Streampunk Media Ltd.
4
+
5
+ This program is free software: you can redistribute it and/or modify
6
+ it under the terms of the GNU General Public License as published by
7
+ the Free Software Foundation, either version 3 of the License, or
8
+ (at your option) any later version.
9
+
10
+ This program is distributed in the hope that it will be useful,
11
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
12
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13
+ GNU General Public License for more details.
14
+
15
+ You should have received a copy of the GNU General Public License
16
+ along with this program. If not, see <https://www.gnu.org/licenses/>.
17
+
18
+ https://www.streampunk.media/ mailto:furnace@streampunk.media
19
+ 14 Ormiscaig, Aultbea, Achnasheen, IV22 2JJ U.K.
20
+ */
21
+ const beamcoder = require('../index.js');
22
+
23
+ async function run() {
24
+ let demuxer = await beamcoder.demuxer('../media/sound/BBCNewsCountdown.wav');
25
+ let muxer = beamcoder.muxer({ filename: 'file:test.wav' });
26
+ let stream = muxer.newStream(demuxer.streams[0]); // eslint-disable-line
27
+ // stream.time_base = demuxer.streams[0].time_base;
28
+ // stream.codecpar = demuxer.streams[0].codecpar;
29
+ await muxer.openIO();
30
+ await muxer.writeHeader();
31
+ let packet = {};
32
+ for ( let x = 0 ; x < 100 && packet !== null ; x++ ) {
33
+ packet = await demuxer.read();
34
+ await muxer.writeFrame(packet);
35
+ }
36
+ await muxer.writeTrailer();
37
+ }
38
+
39
+ run();