-
Notifications
You must be signed in to change notification settings - Fork 0
/
encode.js
55 lines (44 loc) · 1.17 KB
/
encode.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
const { exec } = require("child_process");
const path = require("path");
const seed = require("./seed");
const rmdir = path => {
return new Promise(res => {
exec(`rm -r ${path}`, e => {
return res(e);
});
});
};
const mkdir = async path => {
await rmdir(path);
return new Promise((res, rej) => {
return exec(`mkdir ${path}`, e => {
if (e) {
return rej(e);
}
return res(e);
});
});
};
const encode = async videoPath => {
const baseDir = path.dirname(videoPath);
const framesDir = `${baseDir}/frames`;
await mkdir(framesDir);
exec(
`ffmpeg -i ${videoPath} -ss 00:00:00 -t 00:00:10 ${framesDir}/$filename%03d.jpg`,
async e => {
if (e) {
console.error("Error in FFMPEG", e);
return;
}
await seed(framesDir);
await rmdir(framesDir);
// const outDir = `${baseDir}/out`;
// rmdir(outDir);
// mkdir(outDir);
// await new Promise(res => exec(`cp -R ./prisma/* ${outDir}`, res));
// await new Promise(res => exec(`nexe play.js -o play`, res));
// await new Promise(res => exec(`cp play ${outDir}/play`, res));
}
);
};
module.exports = encode;