2019-02-08 17:46:58 +00:00
|
|
|
'use strict';
|
2019-06-09 00:51:00 +00:00
|
|
|
Object.defineProperty(exports, "__esModule", { value: true });
|
2019-06-09 01:43:14 +00:00
|
|
|
const fs_extra_1 = require("fs-extra");
|
|
|
|
const exec_1 = require("exec");
|
2019-02-08 17:46:58 +00:00
|
|
|
//const spawn = require('spawn');
|
2019-02-08 23:21:16 +00:00
|
|
|
//const exit = require('exit');
|
2019-02-08 17:46:58 +00:00
|
|
|
let system = {};
|
2019-06-09 00:51:00 +00:00
|
|
|
async function info(video) {
|
|
|
|
let cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
2019-06-09 01:43:14 +00:00
|
|
|
let fileExists;
|
2019-06-09 00:51:00 +00:00
|
|
|
let raw;
|
|
|
|
let json;
|
|
|
|
let vid;
|
|
|
|
try {
|
2019-06-09 01:43:14 +00:00
|
|
|
fileExists = await fs_extra_1.exists(video);
|
2019-06-09 00:51:00 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return exit(err, 5);
|
|
|
|
}
|
2019-06-09 01:43:14 +00:00
|
|
|
if (!fileExists) {
|
2019-06-09 00:51:00 +00:00
|
|
|
//return exit(`File ${video} does not exist`, 6);
|
|
|
|
console.error(new Error(`File ${video} does not exist`));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
console.log(cmd);
|
2019-06-09 01:43:14 +00:00
|
|
|
raw = await exec_1.exec(cmd);
|
2019-06-09 00:51:00 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//return exit(err, 7);
|
|
|
|
console.error(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
json = JSON.parse(raw.stdout);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return raw.stdout;
|
|
|
|
}
|
|
|
|
if (json && json.streams) {
|
|
|
|
vid = json.streams.find((stream) => {
|
|
|
|
if (stream.width && stream.height)
|
|
|
|
return stream;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
if (vid) {
|
|
|
|
json.width = vid.width;
|
|
|
|
json.height = vid.height;
|
|
|
|
}
|
|
|
|
return json;
|
2019-02-08 17:46:58 +00:00
|
|
|
}
|
2019-06-09 00:51:00 +00:00
|
|
|
async function frames(video) {
|
|
|
|
let cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
2019-06-09 01:43:14 +00:00
|
|
|
let fileExists;
|
2019-06-09 00:51:00 +00:00
|
|
|
let raw;
|
|
|
|
let frames;
|
|
|
|
try {
|
2019-06-09 01:43:14 +00:00
|
|
|
fileExists = await fs_extra_1.exists(video);
|
2019-06-09 00:51:00 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
//return exit(err, 5);
|
|
|
|
console.error(err);
|
|
|
|
return false;
|
|
|
|
}
|
2019-06-09 01:43:14 +00:00
|
|
|
if (!fileExists) {
|
2019-06-09 00:51:00 +00:00
|
|
|
//return exit(`File ${video} does not exist`, 6);
|
|
|
|
console.error(new Error(`File ${video} does not exist`));
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
console.log(cmd);
|
2019-06-09 01:43:14 +00:00
|
|
|
raw = await exec_1.exec(cmd);
|
2019-06-09 00:51:00 +00:00
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
console.error(err);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
try {
|
|
|
|
frames = parseInt(raw.stdout);
|
|
|
|
}
|
|
|
|
catch (err) {
|
|
|
|
return raw.stdout;
|
|
|
|
}
|
|
|
|
return frames;
|
2019-02-08 17:46:58 +00:00
|
|
|
}
|
2019-06-09 00:51:00 +00:00
|
|
|
function map(obj) {
|
|
|
|
console.dir(obj);
|
2019-02-08 17:46:58 +00:00
|
|
|
}
|
|
|
|
module.exports = (sys) => {
|
2019-06-09 00:51:00 +00:00
|
|
|
system = sys;
|
|
|
|
return {
|
|
|
|
info,
|
|
|
|
frames
|
|
|
|
};
|
|
|
|
};
|
|
|
|
//# sourceMappingURL=index.js.map
|