-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.js
75 lines (62 loc) · 2.29 KB
/
index.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
const { exec } = require('child_process');
const path = require('path');
const fs = require('fs/promises');
const Bottleneck = require('bottleneck');
const cliProgress = require('cli-progress');
const { chunk } = require('lodash');
const { get_ebsynth_binary_path } = require('./utils');
const maxConcurrent = 2;
const tasksInOneCommand = 1;
const style = path.join(__dirname, 'SampleProject', 'key', 'frame-0.jpg');
const source_frame = path.join(__dirname, 'SampleProject', 'data', 'frame-0.jpg');
const input_frames_dir = path.join(__dirname, 'SampleProject', 'data');
const output_frames_dir = path.join(__dirname, 'SampleProject', 'output');
const run = async (command) => new Promise((resolve, reject) => {
exec(command, (error, stdout, stderr) => {
if (error) {
return reject(error);
}
if (stderr) {
console.error(stderr);
}
return resolve(stdout);
});
});
const run_ebsynth = async () => {
const ebsynth_path = await get_ebsynth_binary_path();
const images = await fs.readdir(input_frames_dir);
const limiter = new Bottleneck({
maxConcurrent,
});
const limited_run = limiter.wrap(run);
await fs.rm(output_frames_dir, { force: true, recursive: true });
await fs.mkdir(output_frames_dir, { recursive: true });
const bar = new cliProgress.SingleBar(
{
format: 'progress [{bar}] {percentage}% | ETA: {eta}s | {value}/{total} | {duration_formatted}',
},
cliProgress.Presets.shades_classic
);
bar.start(images.length, 0);
const images_chunks = chunk(images, tasksInOneCommand);
let done = 0;
await Promise.all(
images_chunks.map(async (images_chunk) => {
const command = images_chunk
.map((image) => {
const guide_target = path.join(input_frames_dir, image);
const output = path.join(output_frames_dir, image);
return `${ebsynth_path} -style ${style} -guide ${source_frame} ${guide_target} -output ${output}`;
})
.join(' & ');
await limited_run(command);
done += images_chunk.length;
bar.update(done);
})
);
bar.stop();
};
const main = async () => {
await run_ebsynth();
};
main();