-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcheckVideo.js
35 lines (34 loc) · 1.12 KB
/
checkVideo.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
const child_process = require("child_process");
const readline = require("readline");
module.exports = async (url) => {
return new Promise((resolve, reject) => {
let ffprobeProcess = child_process.spawn(ffprobe, [
"-v",
"error",
"-show_entries",
"frame=width,height,pix_fmt", // Check the frame width, height, and pix_fmt
"-select_streams",
"v",
"-of",
"csv=p=0",
url
]);
let rli = readline.createInterface({
input: ffprobeProcess.stdout
});
let lastLine = null;
rli.on("line", line => {
if (line === "") return; // Sometimes ffprobe outputs empty lines which can be safely ignored.
if (line !== lastLine && lastLine !== null) {
reject(); // Crasher!
ffprobeProcess.kill();
}
lastLine = line;
});
rli.once("close", () => {
resolve(); // Video completely checked
});
});
};
// CREDIT WHERE CREDIT IS DUE
// This is adapted from u/T1J8r's code on r/discordapp