forked from bvibber/av1-demo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
encoder.js
76 lines (64 loc) · 2.46 KB
/
encoder.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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
const child_process = require('child_process');
const config = require('./config.json');
class Encoder {
constructor(options) {
this.dest = options.dest;
this.base = options.base;
}
start() {
return new Promise((resolve, reject) => {
this.cleanup();
let ffmpeg = config.ffmpeg;
let input = 'media/' + config.input;
let args = [];
//args.push('-loglevel', 'debug');
args.push('-re');
args.push('-i');
args.push(input);
for (let i = 0; i < config.resolutions.length; i++) {
args.push('-map', '0:v:0');
}
for (let i = 0; i < config.resolutions.length; i++) {
args.push(`-filter:v:${i}`, `scale=w=${config.resolutions[i][0]}:h=${config.resolutions[i][1]}`);
args.push(`-c:v:${i}`, 'libsvt_av1');
args.push(`-b:v:${i}`, `${config.bitrates[i]}`);
}
if (config.threads) {
args.push('-threads', String(config.threads));
}
args.push('-tile-columns', '2');
//args.push('-rc', 'vbr');
args.push('-flags', 'cgop');
args.push('-forced-idr', '1');
args.push('-qp', '42');
args.push('-f', 'dash');
args.push('-live', '1');
args.push('-seg_duration', '1');
args.push('-window_size', '7200');
args.push('-hielevel', '3'); // instead of 4
args.push('-use_template', '1');
args.push('-use_timeline', '0');
args.push('-init_seg_name', this.base + '.$RepresentationID$.init.webm');
args.push('-media_seg_name', this.base + '.$RepresentationID$.$Number$.webm');
args.push('-dash_segment_type', 'webm');
args.push('-adaptation_sets', 'id=0,streams=v');
args.push('-y');
args.push(this.dest);
const options = {
maxBuffer: 1024 * 1024 * 10,
};
console.log(ffmpeg, args);
child_process.execFile(ffmpeg, args, options, (error, stdout, stderr) => {
console.log('return code', error);
console.log(stdout);
console.error(stderr);
resolve();
});
});
}
cleanup() {
let cmd = `rm -f '${this.dest}'*`;
child_process.execSync(cmd);
}
}
module.exports = Encoder;