Refactor ffprobe into a class. Add jsdoc comments to all methods.
This commit is contained in:
parent
30c36baa9c
commit
2ff98a2148
|
@ -1,102 +1,121 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
/** @module FFPROBE **/
|
||||||
const fs_extra_1 = require("fs-extra");
|
const fs_extra_1 = require("fs-extra");
|
||||||
const path_1 = require("path");
|
const path_1 = require("path");
|
||||||
const exec_1 = require("exec");
|
const exec_1 = require("exec");
|
||||||
//const spawn = require('spawn');
|
//const spawn = require('spawn');
|
||||||
//const exit = require('exit');
|
//const exit = require('exit');
|
||||||
let system = {};
|
class FFPROBE {
|
||||||
async function info(video) {
|
constructor(sys) {
|
||||||
let cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
this.system = sys;
|
||||||
let fileExists;
|
|
||||||
let raw;
|
|
||||||
let json;
|
|
||||||
let vid;
|
|
||||||
try {
|
|
||||||
fileExists = await fs_extra_1.exists(video);
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
/**
|
||||||
return exit(err, 5);
|
* Get info on a video in json format. Use for filmout.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {object} Video info in an object
|
||||||
|
**/
|
||||||
|
async info(video) {
|
||||||
|
const cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
||||||
|
let fileExists;
|
||||||
|
let raw;
|
||||||
|
let json;
|
||||||
|
let vid; //whether video has stream with video data
|
||||||
|
try {
|
||||||
|
fileExists = await fs_extra_1.exists(video);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return exit(err, 5);
|
||||||
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec_1.exec(cmd);
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
if (!fileExists) {
|
/**
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
* Count the number of frames in the video using one of two methods.
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
* The first uses -select_streams and is very fast. The second uses
|
||||||
return false;
|
* -count_frames and is VERY slow.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {integer} Number of frames in video
|
||||||
|
**/
|
||||||
|
async frames(video) {
|
||||||
|
const ext = path_1.extname(video.toLowerCase());
|
||||||
|
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
|
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
|
let fileExists;
|
||||||
|
let raw;
|
||||||
|
let frames;
|
||||||
|
try {
|
||||||
|
fileExists = await fs_extra_1.exists(video);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
//return exit(err, 5);
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ext === '.mkv') {
|
||||||
|
cmd = backup_cmd;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec_1.exec(cmd);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
frames = parseInt(raw.stdout);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return raw.stdout;
|
||||||
|
}
|
||||||
|
return frames;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec_1.exec(cmd);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
async function frames(video) {
|
/*
|
||||||
const ext = path_1.extname(video.toLowerCase());
|
function map (obj : any) {
|
||||||
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
|
||||||
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
|
||||||
let fileExists;
|
|
||||||
let raw;
|
|
||||||
let frames;
|
|
||||||
try {
|
|
||||||
fileExists = await fs_extra_1.exists(video);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
//return exit(err, 5);
|
|
||||||
console.error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!fileExists) {
|
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ext === '.mkv') {
|
|
||||||
cmd = backup_cmd;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec_1.exec(cmd);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
frames = parseInt(raw.stdout);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return raw.stdout;
|
|
||||||
}
|
|
||||||
return frames;
|
|
||||||
}
|
|
||||||
function map(obj) {
|
|
||||||
console.dir(obj);
|
console.dir(obj);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
module.exports = (sys) => {
|
module.exports = (sys) => {
|
||||||
system = sys;
|
return new FFPROBE(sys);
|
||||||
return {
|
|
||||||
info,
|
|
||||||
frames
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=index.js.map
|
//# sourceMappingURL=index.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffprobe/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,uCAAkC;AAClC,+BAA+B;AAC/B,+BAA4B;AAC5B,iCAAiC;AACjC,+BAA+B;AAE/B,IAAI,MAAM,GAAG,EAAE,CAAC;AAEhB,KAAK,UAAU,IAAI,CAAE,KAAc;IAClC,IAAI,GAAG,GAAG,mEAAmE,KAAK,GAAG,CAAA;IACrF,IAAI,UAAU,CAAC;IACf,IAAI,GAAG,CAAC;IACR,IAAI,IAAI,CAAC;IACT,IAAI,GAAG,CAAC;IAER,IAAI;QACH,UAAU,GAAG,MAAM,i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;QAED,IAAI;YACH,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;SAC9B;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,GAAG,CAAC,MAAM,CAAC;SAClB;QAED,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAED;;;;EAIE;AAEF,MAAM,CAAC,OAAO,GAAG,CAAC,GAAS,EAAE,EAAE;IAC9B,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAA"}
|
|
@ -1,102 +1,121 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
/** @module FFPROBE **/
|
||||||
const fs_extra_1 = require("fs-extra");
|
const fs_extra_1 = require("fs-extra");
|
||||||
const path_1 = require("path");
|
const path_1 = require("path");
|
||||||
const exec_1 = require("exec");
|
const exec_1 = require("exec");
|
||||||
//const spawn = require('spawn');
|
//const spawn = require('spawn');
|
||||||
//const exit = require('exit');
|
//const exit = require('exit');
|
||||||
let system = {};
|
class FFPROBE {
|
||||||
async function info(video) {
|
constructor(sys) {
|
||||||
let cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
this.system = sys;
|
||||||
let fileExists;
|
|
||||||
let raw;
|
|
||||||
let json;
|
|
||||||
let vid;
|
|
||||||
try {
|
|
||||||
fileExists = await fs_extra_1.exists(video);
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
/**
|
||||||
return exit(err, 5);
|
* Get info on a video in json format. Use for filmout.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {object} Video info in an object
|
||||||
|
**/
|
||||||
|
async info(video) {
|
||||||
|
const cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
||||||
|
let fileExists;
|
||||||
|
let raw;
|
||||||
|
let json;
|
||||||
|
let vid; //whether video has stream with video data
|
||||||
|
try {
|
||||||
|
fileExists = await fs_extra_1.exists(video);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return exit(err, 5);
|
||||||
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec_1.exec(cmd);
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
if (!fileExists) {
|
/**
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
* Count the number of frames in the video using one of two methods.
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
* The first uses -select_streams and is very fast. The second uses
|
||||||
return false;
|
* -count_frames and is VERY slow.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {integer} Number of frames in video
|
||||||
|
**/
|
||||||
|
async frames(video) {
|
||||||
|
const ext = path_1.extname(video.toLowerCase());
|
||||||
|
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
|
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
|
let fileExists;
|
||||||
|
let raw;
|
||||||
|
let frames;
|
||||||
|
try {
|
||||||
|
fileExists = await fs_extra_1.exists(video);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
//return exit(err, 5);
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ext === '.mkv') {
|
||||||
|
cmd = backup_cmd;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec_1.exec(cmd);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
frames = parseInt(raw.stdout);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return raw.stdout;
|
||||||
|
}
|
||||||
|
return frames;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec_1.exec(cmd);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
async function frames(video) {
|
/*
|
||||||
const ext = path_1.extname(video.toLowerCase());
|
function map (obj : any) {
|
||||||
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
|
||||||
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
|
||||||
let fileExists;
|
|
||||||
let raw;
|
|
||||||
let frames;
|
|
||||||
try {
|
|
||||||
fileExists = await fs_extra_1.exists(video);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
//return exit(err, 5);
|
|
||||||
console.error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!fileExists) {
|
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ext === '.mkv') {
|
|
||||||
cmd = backup_cmd;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec_1.exec(cmd);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
frames = parseInt(raw.stdout);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return raw.stdout;
|
|
||||||
}
|
|
||||||
return frames;
|
|
||||||
}
|
|
||||||
function map(obj) {
|
|
||||||
console.dir(obj);
|
console.dir(obj);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
module.exports = (sys) => {
|
module.exports = (sys) => {
|
||||||
system = sys;
|
return new FFPROBE(sys);
|
||||||
return {
|
|
||||||
info,
|
|
||||||
frames
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=index.js.map
|
//# sourceMappingURL=index.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffprobe/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,uCAAkC;AAClC,+BAA+B;AAC/B,+BAA4B;AAC5B,iCAAiC;AACjC,+BAA+B;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YACnB,GAAG,GAAG,UAAU,CAAC;SACjB;QACD,IAAI;YACH,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,GAAG,GAAG,MAAM,WAAI,CAAC,GAAG,CAAC,CAAC;SACtB;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,KAAK,CAAC;SACb;QAED,IAAI;YACH,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;SAC9B;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,GAAG,CAAC,MAAM,CAAC;SAClB;QAED,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAED;;;;EAIE;AAEF,MAAM,CAAC,OAAO,GAAG,CAAC,GAAS,EAAE,EAAE;IAC9B,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAA"}
|
|
@ -1,102 +1,121 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
Object.defineProperty(exports, "__esModule", { value: true });
|
Object.defineProperty(exports, "__esModule", { value: true });
|
||||||
|
/** @module FFPROBE **/
|
||||||
const fs_extra_1 = require("fs-extra");
|
const fs_extra_1 = require("fs-extra");
|
||||||
const path_1 = require("path");
|
const path_1 = require("path");
|
||||||
const exec_1 = require("exec");
|
const exec_1 = require("exec");
|
||||||
//const spawn = require('spawn');
|
//const spawn = require('spawn');
|
||||||
//const exit = require('exit');
|
//const exit = require('exit');
|
||||||
let system = {};
|
class FFPROBE {
|
||||||
async function info(video) {
|
constructor(sys) {
|
||||||
let cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
this.system = sys;
|
||||||
let fileExists;
|
|
||||||
let raw;
|
|
||||||
let json;
|
|
||||||
let vid;
|
|
||||||
try {
|
|
||||||
fileExists = await fs_extra_1.exists(video);
|
|
||||||
}
|
}
|
||||||
catch (err) {
|
/**
|
||||||
return exit(err, 5);
|
* Get info on a video in json format. Use for filmout.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {object} Video info in an object
|
||||||
|
**/
|
||||||
|
async info(video) {
|
||||||
|
const cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`;
|
||||||
|
let fileExists;
|
||||||
|
let raw;
|
||||||
|
let json;
|
||||||
|
let vid; //whether video has stream with video data
|
||||||
|
try {
|
||||||
|
fileExists = await fs_extra_1.exists(video);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return exit(err, 5);
|
||||||
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec_1.exec(cmd);
|
||||||
|
}
|
||||||
|
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;
|
||||||
}
|
}
|
||||||
if (!fileExists) {
|
/**
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
* Count the number of frames in the video using one of two methods.
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
* The first uses -select_streams and is very fast. The second uses
|
||||||
return false;
|
* -count_frames and is VERY slow.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {integer} Number of frames in video
|
||||||
|
**/
|
||||||
|
async frames(video) {
|
||||||
|
const ext = path_1.extname(video.toLowerCase());
|
||||||
|
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
|
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
|
let fileExists;
|
||||||
|
let raw;
|
||||||
|
let frames;
|
||||||
|
try {
|
||||||
|
fileExists = await fs_extra_1.exists(video);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
//return exit(err, 5);
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
if (ext === '.mkv') {
|
||||||
|
cmd = backup_cmd;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec_1.exec(cmd);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
frames = parseInt(raw.stdout);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
return raw.stdout;
|
||||||
|
}
|
||||||
|
return frames;
|
||||||
}
|
}
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec_1.exec(cmd);
|
|
||||||
}
|
|
||||||
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;
|
|
||||||
}
|
}
|
||||||
async function frames(video) {
|
/*
|
||||||
const ext = path_1.extname(video.toLowerCase());
|
function map (obj : any) {
|
||||||
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
|
||||||
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
|
||||||
let fileExists;
|
|
||||||
let raw;
|
|
||||||
let frames;
|
|
||||||
try {
|
|
||||||
fileExists = await fs_extra_1.exists(video);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
//return exit(err, 5);
|
|
||||||
console.error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (!fileExists) {
|
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
if (ext === '.mkv') {
|
|
||||||
cmd = backup_cmd;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec_1.exec(cmd);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
console.error(err);
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
frames = parseInt(raw.stdout);
|
|
||||||
}
|
|
||||||
catch (err) {
|
|
||||||
return raw.stdout;
|
|
||||||
}
|
|
||||||
return frames;
|
|
||||||
}
|
|
||||||
function map(obj) {
|
|
||||||
console.dir(obj);
|
console.dir(obj);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
module.exports = (sys) => {
|
module.exports = (sys) => {
|
||||||
system = sys;
|
return new FFPROBE(sys);
|
||||||
return {
|
|
||||||
info,
|
|
||||||
frames
|
|
||||||
};
|
|
||||||
};
|
};
|
||||||
//# sourceMappingURL=index.js.map
|
//# sourceMappingURL=index.js.map
|
|
@ -1 +1 @@
|
||||||
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffprobe/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb,uCAAkC;AAClC,+BAA+B;AAC/B,+BAA4B;AAC5B,iCAAiC;AACjC,+BAA+B;AAE/B,IAAI,MAAM,GAAG,EAAE,CAAC;AAEhB,KAAK,UAAU,IAAI,CAAE,KAAc;IAClC,IAAI,GAAG,GAAG,mEAAmE,KAAK,GAAG,CAAA;IACrF,IAAI,UAAU,CAAC;IACf,IAAI,GAAG,CAAC;IACR,IAAI,IAAI,CAAC;IACT,IAAI,GAAG,CAAC;IAER,IAAI;QACH,UAAU,GAAG,MAAM,iBAAM,CAAC,KAAK,CAAC,CAAC;KACjC;IAAC,OAAO,GAAG,EAAE;QACb,OAAO,IAAI,CAAC,GAAG,EAAE,CAAC,CAAC,CAAC;KACpB;IACD,IAAI,CAAC,UAAU,EAAE;QAChB,iDAAiD;QACjD,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,KAAK,iBAAiB,CAAC,CAAC,CAAC;QACzD,OAAO,KAAK,CAAA;KACZ;IAED,IAAI;QACH,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;QACjB,GAAG,GAAG,MAAM,WAAI,CAAC,GAAG,CAAC,CAAC;KACtB;IAAC,OAAO,GAAG,EAAE;QACb,sBAAsB;QACtB,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QACnB,OAAO,KAAK,CAAA;KACZ;IAED,IAAI;QACH,IAAI,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;KAC9B;IAAC,OAAO,GAAG,EAAE;QACb,OAAO,GAAG,CAAC,MAAM,CAAC;KAClB;IAED,IAAI,IAAI,IAAI,IAAI,CAAC,OAAO,EAAE;QACzB,GAAG,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AK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,KAAK,CAAA;SACZ;QACD,IAAI,CAAC,UAAU,EAAE;YAChB,iDAAiD;YACjD,OAAO,CAAC,KAAK,CAAC,IAAI,KAAK,CAAC,QAAQ,KAAK,iBAAiB,CAAC,CAAC,CAAC;YACzD,OAAO,KAAK,CAAC;SACb;QAED,IAAI,GAAG,KAAK,MAAM,EAAE;YACnB,GAAG,GAAG,UAAU,CAAC;SACjB;QACD,IAAI;YACH,OAAO,CAAC,GAAG,CAAC,GAAG,CAAC,CAAC;YACjB,GAAG,GAAG,MAAM,WAAI,CAAC,GAAG,CAAC,CAAC;SACtB;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;YACnB,OAAO,KAAK,CAAC;SACb;QAED,IAAI;YACH,MAAM,GAAG,QAAQ,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;SAC9B;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,GAAG,CAAC,MAAM,CAAC;SAClB;QAED,OAAO,MAAM,CAAC;IACf,CAAC;CACD;AAED;;;;EAIE;AAEF,MAAM,CAAC,OAAO,GAAG,CAAC,GAAS,EAAE,EAAE;IAC9B,OAAO,IAAI,OAAO,CAAC,GAAG,CAAC,CAAC;AACzB,CAAC,CAAA"}
|
|
@ -1,109 +1,129 @@
|
||||||
'use strict';
|
'use strict';
|
||||||
|
|
||||||
|
/** @module FFPROBE **/
|
||||||
|
|
||||||
import { exists } from 'fs-extra';
|
import { exists } from 'fs-extra';
|
||||||
import { extname } from 'path';
|
import { extname } from 'path';
|
||||||
import { exec } from 'exec';
|
import { exec } from 'exec';
|
||||||
//const spawn = require('spawn');
|
//const spawn = require('spawn');
|
||||||
//const exit = require('exit');
|
//const exit = require('exit');
|
||||||
|
|
||||||
let system = {};
|
class FFPROBE {
|
||||||
|
private system : any;
|
||||||
async function info (video : string) {
|
private log : any;
|
||||||
let cmd = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`
|
constructor (sys : any) {
|
||||||
let fileExists;
|
this.system = sys;
|
||||||
let raw;
|
|
||||||
let json;
|
|
||||||
let vid;
|
|
||||||
|
|
||||||
try {
|
|
||||||
fileExists = await exists(video);
|
|
||||||
} catch (err) {
|
|
||||||
return exit(err, 5);
|
|
||||||
}
|
|
||||||
if (!fileExists) {
|
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
|
||||||
return false
|
|
||||||
}
|
|
||||||
|
|
||||||
try {
|
|
||||||
console.log(cmd);
|
|
||||||
raw = await exec(cmd);
|
|
||||||
} catch (err) {
|
|
||||||
//return exit(err, 7);
|
|
||||||
console.error(err);
|
|
||||||
return false
|
|
||||||
}
|
}
|
||||||
|
/**
|
||||||
|
* Get info on a video in json format. Use for filmout.
|
||||||
|
*
|
||||||
|
* @param {string} video Path to video
|
||||||
|
*
|
||||||
|
* @returns {object} Video info in an object
|
||||||
|
**/
|
||||||
|
public async info (video : string) {
|
||||||
|
const cmd : string = `ffprobe -v quiet -print_format json -show_format -show_streams "${video}"`
|
||||||
|
let fileExists : boolean;
|
||||||
|
let raw : any;
|
||||||
|
let json : any;
|
||||||
|
let vid : any; //whether video has stream with video data
|
||||||
|
|
||||||
try {
|
try {
|
||||||
json = JSON.parse(raw.stdout);
|
fileExists = await exists(video);
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
return raw.stdout;
|
return exit(err, 5);
|
||||||
}
|
}
|
||||||
|
if (!fileExists) {
|
||||||
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
console.log(cmd);
|
||||||
|
raw = await exec(cmd);
|
||||||
|
} catch (err) {
|
||||||
|
//return exit(err, 7);
|
||||||
|
console.error(err);
|
||||||
|
return false
|
||||||
|
}
|
||||||
|
|
||||||
if (json && json.streams) {
|
try {
|
||||||
vid = json.streams.find((stream : any) => {
|
json = JSON.parse(raw.stdout);
|
||||||
if (stream.width && stream.height) return stream;
|
} catch (err) {
|
||||||
});
|
return raw.stdout;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (vid) {
|
if (json && json.streams) {
|
||||||
json.width = vid.width;
|
vid = json.streams.find((stream : any) => {
|
||||||
json.height = vid.height;
|
if (stream.width && stream.height) return stream;
|
||||||
}
|
});
|
||||||
|
}
|
||||||
|
|
||||||
return json;
|
if (vid) {
|
||||||
}
|
json.width = vid.width;
|
||||||
|
json.height = vid.height;
|
||||||
async function frames (video : string) {
|
}
|
||||||
const ext : string = extname(video.toLowerCase());
|
|
||||||
let cmd = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
return json;
|
||||||
let backup_cmd = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
}
|
||||||
let fileExists;
|
/**
|
||||||
let raw;
|
* Count the number of frames in the video using one of two methods.
|
||||||
let frames;
|
* The first uses -select_streams and is very fast. The second uses
|
||||||
|
* -count_frames and is VERY slow.
|
||||||
try {
|
*
|
||||||
fileExists = await exists(video);
|
* @param {string} video Path to video
|
||||||
} catch (err) {
|
*
|
||||||
//return exit(err, 5);
|
* @returns {integer} Number of frames in video
|
||||||
console.error(err);
|
**/
|
||||||
return false
|
public async frames (video : string) {
|
||||||
}
|
const ext : string = extname(video.toLowerCase());
|
||||||
if (!fileExists) {
|
let cmd : string = `ffprobe -v error -select_streams v:0 -show_entries stream=nb_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
//return exit(`File ${video} does not exist`, 6);
|
let backup_cmd : string = `ffprobe -v error -count_frames -select_streams v:0 -show_entries stream=nb_read_frames -of default=nokey=1:noprint_wrappers=1 "${video}"`;
|
||||||
console.error(new Error(`File ${video} does not exist`));
|
let fileExists : boolean;
|
||||||
return false;
|
let raw : any;
|
||||||
}
|
let frames : number;
|
||||||
|
|
||||||
if (ext === '.mkv') {
|
try {
|
||||||
cmd = backup_cmd;
|
fileExists = await exists(video);
|
||||||
}
|
} catch (err) {
|
||||||
try {
|
//return exit(err, 5);
|
||||||
console.log(cmd);
|
console.error(err);
|
||||||
raw = await exec(cmd);
|
return false
|
||||||
} catch (err) {
|
}
|
||||||
console.error(err);
|
if (!fileExists) {
|
||||||
return false;
|
//return exit(`File ${video} does not exist`, 6);
|
||||||
}
|
console.error(new Error(`File ${video} does not exist`));
|
||||||
|
return false;
|
||||||
try {
|
}
|
||||||
frames = parseInt(raw.stdout)
|
|
||||||
} catch (err) {
|
if (ext === '.mkv') {
|
||||||
return raw.stdout;
|
cmd = backup_cmd;
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
return frames;
|
console.log(cmd);
|
||||||
|
raw = await exec(cmd);
|
||||||
|
} catch (err) {
|
||||||
|
console.error(err);
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
frames = parseInt(raw.stdout);
|
||||||
|
} catch (err) {
|
||||||
|
return raw.stdout;
|
||||||
|
}
|
||||||
|
|
||||||
|
return frames;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
function map (obj : any) {
|
function map (obj : any) {
|
||||||
console.dir(obj);
|
console.dir(obj);
|
||||||
}
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
module.exports = (sys : any) => {
|
module.exports = (sys : any) => {
|
||||||
system = sys;
|
return new FFPROBE(sys);
|
||||||
return {
|
}
|
||||||
info,
|
|
||||||
frames
|
|
||||||
}
|
|
||||||
}
|
|
Loading…
Reference in New Issue