-
Notifications
You must be signed in to change notification settings - Fork 33
/
probe-check.js
36 lines (31 loc) · 1.2 KB
/
probe-check.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
const childProcess = require("child_process");
module.exports.probeSuccess = (filename) => {
return new Promise((resolve, reject) => {
let ffmpegProcess;
try {
console.log(`*** Spawing ffmpeg process ***`, filename);
ffmpegProcess = childProcess.spawn("ffprobe", ["-hide_banner", filename]);
ffmpegProcess.stdout.on('data', (data) => {
console.log('[STDOUT]', filename, data.toString());
});
ffmpegProcess.stderr.on('data', (data) => {
console.log('[STDERR]', filename, data.toString());
});
ffmpegProcess.on('exit', (code) => {
console.log('[EXIT]', filename, `code ${code}`);
if (code == 0) {
resolve(true);
} else {
resolve(false);
}
});
ffmpegProcess.on('error', (err) => {
console.log(`[ERROR]`, filename, err);
});
} catch (error) {
console.log('probe error', filename, error);
if (ffmpegProcess) ffmpegProcess.kill();
reject(error);
}
})
}