/
nullvideo.js
51 lines (44 loc) · 1.27 KB
/
nullvideo.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
const cp = require('child_process');
const im = require('imagemagick');
const commandLineArgs = require('command-line-args');
const fullWidth = 1920;
const fullHeight = 1080;
const imageName = 'null.png';
const soundName = 'null.wav';
const outfileName = 'null.mp4';
const optionDefinitions = [
{ name: 'background', alias: 'b', type: String },
{ name: 'framerate', alias: 'f', type: Number },
];
const options = commandLineArgs(optionDefinitions);
var background = options.hasOwnProperty('background') ? options.background : 'black';
var framerate = options.hasOwnProperty('framerate') ? options.framerate : 30
var silence = cp.spawnSync('/usr/bin/rec', [ soundName, 'trim', 0, 0 ])
if (silence.stderr.toString().trim()) {
console.log('silence: ' + silence.stderr.toString().trim());
}
im.convert([
'-size', fullWidth + 'x' + fullHeight,
'xc:' + background,
imageName
], function (err) {
if (err) {
console.log(err);
}
cp.spawnSync('/usr/bin/ffmpeg', [
'-framerate', framerate,
'-i', imageName,
'-i', soundName,
'-safe', '0',
'-strict', '-2',
'-c:v', 'libx264',
'-b:a', '4.5M',
'-b:v', '4.5M',
'-minrate', '4.5M',
'-maxrate', '4.5M',
'-bufsize', '4.5M',
'-r', '30',
'-pix_fmt', 'yuv420p',
outfileName
]);
});