Refactored ffmpeg module into a class. Add a logger, not implemented. Not tested.

This commit is contained in:
mmcwilliams 2019-08-04 17:42:27 -04:00
parent 7c4e9d5823
commit bd79025305
7 changed files with 784 additions and 766 deletions

View File

@ -3,8 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec");
let system = {};
let TMPDIR;
/** @class FFMPEG **/
class FFMPEG {
constructor(sys) {
this.id = 'ffmpeg';
this.system = sys;
this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
this.init();
}
async init() {
const Log = require('log');
this.log = await Log({ label: this.id });
await this.checkDir();
}
/**
* Add padding to a number to 5 places. Return a string.
*
@ -12,7 +23,7 @@ let TMPDIR;
*
* @returns {string} Padded string
**/
function padded_frame(i) {
padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
@ -28,12 +39,12 @@ function padded_frame(i) {
*
* @returns {string} Path of frame
**/
async function frame(state, light) {
async frame(state, light) {
const frameNum = state.frame;
const video = state.path;
const w = state.info.width;
const h = state.info.height;
const padded = padded_frame(frameNum);
const padded = this.padded_frame(frameNum);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
@ -49,7 +60,7 @@ async function frame(state, light) {
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(TMPDIR, `export-${padded}.${ext}`);
tmpoutput = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e) => {
return parseInt(e);
});
@ -90,8 +101,8 @@ async function frame(state, light) {
*
* @returns {?}
**/
async function frames(video, obj) {
const tmppath = TMPDIR;
async frames(video, obj) {
const tmppath = this.TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
@ -113,8 +124,8 @@ async function frames(video, obj) {
*
* @returns {boolean} True if successful, false if not
**/
async function clear(frame) {
const padded = padded_frame(frame);
async clear(frame) {
const padded = this.padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
@ -123,7 +134,7 @@ async function clear(frame) {
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(TMPDIR, `export-${padded}.${ext}`);
tmppath = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
@ -145,8 +156,8 @@ async function clear(frame) {
* Delete all frames in temp directory.
*
**/
async function clearAll() {
const tmppath = TMPDIR;
async clearAll() {
const tmppath = this.TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
@ -169,39 +180,32 @@ async function clearAll() {
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir() {
async checkDir() {
let fileExists;
try {
fileExists = await fs_extra_1.exists(TMPDIR);
fileExists = await fs_extra_1.exists(this.TMPDIR);
}
catch (err) {
console.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await fs_extra_1.mkdir(TMPDIR);
console.log(`Created tmpdir ${TMPDIR}`);
await fs_extra_1.mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
await this.clearAll();
}
catch (err) {
console.error(err);
}
}
}
module.exports = (sys) => {
system = sys;
TMPDIR = path_1.join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
};
return new FFMPEG(sys);
};
//# sourceMappingURL=index.js.map

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffmpeg/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAKb,+BAA4B;AAC5B,uCAA0D;AAC1D,+BAA4B;AAI5B,IAAI,MAAM,GAAS,EAAE,CAAC;AACtB,IAAI,MAAe,CAAC;AAEpB;;;;;;IAMI;AAEJ,SAAS,YAAY,CAAE,CAAU;IAChC,IAAI,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC;IAC1B,IAAI,GAA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AC,OAAO,EAAE,IAAI,CAAC,CAAC,CAAC;iBAClC;gBAAC,OAAO,GAAG,EAAE;oBACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;iBACnB;YACF,CAAC,CAAC,CAAC;SACH;IACF,CAAC;IAED;;;QAGI;IACI,KAAK,CAAC,QAAQ;QACrB,IAAI,UAAoB,CAAC;QACzB,IAAI;YACH,UAAU,GAAG,MAAM,iBAAM,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;SACvC;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,4BAA4B,EAAE,GAAG,CAAC,CAAC;SACjD;QAED,IAAI,CAAC,UAAU,EAAE;YAChB,IAAI;gBACH,MAAM,gBAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACzB,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;aAC7C;SACD;QACD,IAAI;YACH,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;SACtB;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;IACF,CAAC;CACD;AAGD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAS,EAAE,EAAE;IAC9B,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC,CAAA"}

View File

@ -3,8 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec");
let system = {};
let TMPDIR;
/** @class FFMPEG **/
class FFMPEG {
constructor(sys) {
this.id = 'ffmpeg';
this.system = sys;
this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
this.init();
}
async init() {
const Log = require('log');
this.log = await Log({ label: this.id });
await this.checkDir();
}
/**
* Add padding to a number to 5 places. Return a string.
*
@ -12,7 +23,7 @@ let TMPDIR;
*
* @returns {string} Padded string
**/
function padded_frame(i) {
padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
@ -28,12 +39,12 @@ function padded_frame(i) {
*
* @returns {string} Path of frame
**/
async function frame(state, light) {
async frame(state, light) {
const frameNum = state.frame;
const video = state.path;
const w = state.info.width;
const h = state.info.height;
const padded = padded_frame(frameNum);
const padded = this.padded_frame(frameNum);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
@ -49,7 +60,7 @@ async function frame(state, light) {
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(TMPDIR, `export-${padded}.${ext}`);
tmpoutput = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e) => {
return parseInt(e);
});
@ -90,8 +101,8 @@ async function frame(state, light) {
*
* @returns {?}
**/
async function frames(video, obj) {
const tmppath = TMPDIR;
async frames(video, obj) {
const tmppath = this.TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
@ -113,8 +124,8 @@ async function frames(video, obj) {
*
* @returns {boolean} True if successful, false if not
**/
async function clear(frame) {
const padded = padded_frame(frame);
async clear(frame) {
const padded = this.padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
@ -123,7 +134,7 @@ async function clear(frame) {
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(TMPDIR, `export-${padded}.${ext}`);
tmppath = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
@ -145,8 +156,8 @@ async function clear(frame) {
* Delete all frames in temp directory.
*
**/
async function clearAll() {
const tmppath = TMPDIR;
async clearAll() {
const tmppath = this.TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
@ -169,39 +180,32 @@ async function clearAll() {
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir() {
async checkDir() {
let fileExists;
try {
fileExists = await fs_extra_1.exists(TMPDIR);
fileExists = await fs_extra_1.exists(this.TMPDIR);
}
catch (err) {
console.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await fs_extra_1.mkdir(TMPDIR);
console.log(`Created tmpdir ${TMPDIR}`);
await fs_extra_1.mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
await this.clearAll();
}
catch (err) {
console.error(err);
}
}
}
module.exports = (sys) => {
system = sys;
TMPDIR = path_1.join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
};
return new FFMPEG(sys);
};
//# sourceMappingURL=index.js.map

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffmpeg/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAKb,+BAA4B;AAC5B,uCAA0D;AAC1D,+BAA4B;AAI5B,IAAI,MAAM,GAAS,EAAE,CAAC;AACtB,IAAI,MAAe,CAAC;AAEpB;;;;;;IAMI;AAEJ,SAAS,YAAY,CAAE,CAAU;IAChC,IAAI,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC;IAC1B,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QACjC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAChB;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;;;IAOI;AACJ,KAAK,UAAU,KAAK,CAAE,KAAW,EAAE,KAAW;IAC7C,MAAM,QAAQ,GAAY,KAAK,CAAC,KAAK,CAAC;IACtC,MAAM,KAAK,GAAY,KAAK,CAAC,IAAI,CAAC;IAClC,MAAM,CAAC,GAAY,K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D;QAED,IAAI,CAAC,UAAU,EAAE;YAChB,IAAI;gBACH,MAAM,gBAAK,CAAC,IAAI,CAAC,MAAM,CAAC,CAAC;gBACzB,OAAO,CAAC,GAAG,CAAC,kBAAkB,IAAI,CAAC,MAAM,EAAE,CAAC,CAAC;aAC7C;YAAC,OAAO,GAAG,EAAE;gBACb,OAAO,CAAC,KAAK,CAAC,wBAAwB,EAAE,GAAG,CAAC,CAAC;aAC7C;SACD;QACD,IAAI;YACH,MAAM,IAAI,CAAC,QAAQ,EAAE,CAAC;SACtB;QAAC,OAAO,GAAG,EAAE;YACb,OAAO,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;SACnB;IACF,CAAC;CACD;AAGD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAS,EAAE,EAAE;IAC9B,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC,CAAA"}

View File

@ -3,8 +3,19 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path");
const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec");
let system = {};
let TMPDIR;
/** @class FFMPEG **/
class FFMPEG {
constructor(sys) {
this.id = 'ffmpeg';
this.system = sys;
this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
this.init();
}
async init() {
const Log = require('log');
this.log = await Log({ label: this.id });
await this.checkDir();
}
/**
* Add padding to a number to 5 places. Return a string.
*
@ -12,7 +23,7 @@ let TMPDIR;
*
* @returns {string} Padded string
**/
function padded_frame(i) {
padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
@ -28,12 +39,12 @@ function padded_frame(i) {
*
* @returns {string} Path of frame
**/
async function frame(state, light) {
async frame(state, light) {
const frameNum = state.frame;
const video = state.path;
const w = state.info.width;
const h = state.info.height;
const padded = padded_frame(frameNum);
const padded = this.padded_frame(frameNum);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
@ -49,7 +60,7 @@ async function frame(state, light) {
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(TMPDIR, `export-${padded}.${ext}`);
tmpoutput = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e) => {
return parseInt(e);
});
@ -90,8 +101,8 @@ async function frame(state, light) {
*
* @returns {?}
**/
async function frames(video, obj) {
const tmppath = TMPDIR;
async frames(video, obj) {
const tmppath = this.TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
@ -113,8 +124,8 @@ async function frames(video, obj) {
*
* @returns {boolean} True if successful, false if not
**/
async function clear(frame) {
const padded = padded_frame(frame);
async clear(frame) {
const padded = this.padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
@ -123,7 +134,7 @@ async function clear(frame) {
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(TMPDIR, `export-${padded}.${ext}`);
tmppath = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
@ -145,8 +156,8 @@ async function clear(frame) {
* Delete all frames in temp directory.
*
**/
async function clearAll() {
const tmppath = TMPDIR;
async clearAll() {
const tmppath = this.TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
@ -169,39 +180,32 @@ async function clearAll() {
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir() {
async checkDir() {
let fileExists;
try {
fileExists = await fs_extra_1.exists(TMPDIR);
fileExists = await fs_extra_1.exists(this.TMPDIR);
}
catch (err) {
console.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await fs_extra_1.mkdir(TMPDIR);
console.log(`Created tmpdir ${TMPDIR}`);
await fs_extra_1.mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
await this.clearAll();
}
catch (err) {
console.error(err);
}
}
}
module.exports = (sys) => {
system = sys;
TMPDIR = path_1.join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
};
return new FFMPEG(sys);
};
//# sourceMappingURL=index.js.map

View File

@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/ffmpeg/index.ts"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAKb,+BAA4B;AAC5B,uCAA0D;AAC1D,+BAA4B;AAI5B,IAAI,MAAM,GAAS,EAAE,CAAC;AACtB,IAAI,MAAe,CAAC;AAEpB;;;;;;IAMI;AAEJ,SAAS,YAAY,CAAE,CAAU;IAChC,IAAI,GAAG,GAAG,CAAC,CAAC,GAAG,EAAE,CAAC,CAAC,MAAM,CAAC;IAC1B,IAAI,GAAG,GAAG,CAAC,GAAG,EAAE,CAAC;IACjB,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,CAAC,GAAG,GAAG,EAAE,CAAC,EAAE,EAAE;QACjC,GAAG,GAAG,GAAG,GAAG,GAAG,CAAC;KAChB;IACD,OAAO,GAAG,CAAC;AACZ,CAAC;AAED;;;;;;;IAOI;AACJ,KAAK,UAAU,KAAK,CAAE,KAAW,EAAE,KAAW;IAC7C,MAAM,QAAQ,GAAY,KAAK,CAAC,KAAK,CAAC;IACtC,MAAM,KAAK,GAAY,KAAK,CAAC,IAAI,CAAC;IAClC,MAAM,CAAC,GAAY,KAAK,CAAC,IAAI,CAAC,KAAK,CAAC;IACpC,MAAM,CAAC,GAAY,KAAK,CAAC,IAAI,CAAC,MAAM,CAAC;IACrC,MAAM,MAAM,GAAY,YAAY,CAAC,QAAQ,CAAC,CAAC;IAC/C,IAAI,GAAG,GAAY,KAAK,CAAC;IACzB,IAAI,GAAG,GAAW,KAAK,CAAC,KAAK,CAAC;IAC9B,IAAI,SAAkB,CAAC;IACvB,IAAI,GAAY,CAAC;IACjB,IAAI,MAAY,CAAC;IACjB,IAAI,IAAa,CAAC;IAClB,IAAI,OAAa,CAAC;IAElB,IAAI,KAAK,GAAY,EAAE,CAAC;IACxB,I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C,CAAC;SACnB;IACF,CAAC;CACD;AAGD,MAAM,CAAC,OAAO,GAAG,CAAC,GAAS,EAAE,EAAE;IAC9B,OAAO,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC;AACxB,CAAC,CAAA"}

View File

@ -9,9 +9,23 @@ import { exec } from 'exec';
//const spawn = require('spawn');
import { exit } from 'exit';
let system : any = {};
let TMPDIR : string;
/** @class FFMPEG **/
class FFMPEG {
private system : any;
private log : any;
private id : string = 'ffmpeg';
private TMPDIR : string;
constructor (sys : any) {
this.system = sys;
this.TMPDIR = join(this.system.tmp, 'mcopy_digital');
this.init()
}
async init () {
const Log = require('log');
this.log = await Log({ label : this.id });
await this.checkDir();
}
/**
* Add padding to a number to 5 places. Return a string.
*
@ -20,7 +34,7 @@ let TMPDIR : string;
* @returns {string} Padded string
**/
function padded_frame (i : number) {
private padded_frame (i : number) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
@ -37,12 +51,12 @@ function padded_frame (i : number) {
*
* @returns {string} Path of frame
**/
async function frame (state : any, light : any) {
public async frame (state : any, light : any) {
const frameNum : number = state.frame;
const video : string = state.path;
const w : number = state.info.width;
const h : number = state.info.height;
const padded : string = padded_frame(frameNum);
const padded : string = this.padded_frame(frameNum);
let ext : string = 'tif';
let rgb : any[] = light.color;
let tmpoutput : string;
@ -62,7 +76,7 @@ async function frame (state : any, light : any) {
ext = 'png';
//}
tmpoutput = join(TMPDIR, `export-${padded}.${ext}`);
tmpoutput = join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e : string) => {
return parseInt(e);
@ -105,8 +119,8 @@ async function frame (state : any, light : any) {
*
* @returns {?}
**/
async function frames (video : string, obj : any) {
const tmppath : string = TMPDIR;
public async frames (video : string, obj : any) {
const tmppath : string = this.TMPDIR;
let ext : string = 'tif';
let tmpoutput : string;
@ -131,8 +145,8 @@ async function frames (video : string, obj : any) {
*
* @returns {boolean} True if successful, false if not
**/
async function clear (frame : number) {
const padded : string = padded_frame(frame);
public async clear (frame : number) {
const padded : string = this.padded_frame(frame);
let ext : string = 'tif';
let tmppath : string;
let tmpoutput : string;
@ -143,7 +157,7 @@ async function clear (frame : number) {
ext = 'png';
//}
tmppath = join(TMPDIR, `export-${padded}.${ext}`);
tmppath = join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await exists(tmppath);
@ -167,8 +181,8 @@ async function clear (frame : number) {
* Delete all frames in temp directory.
*
**/
async function clearAll () {
const tmppath : string = TMPDIR;
public async clearAll () {
const tmppath : string = this.TMPDIR;
let files : any;
try {
files = await readdir(tmppath);
@ -190,39 +204,31 @@ async function clearAll () {
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir () {
private async checkDir () {
let fileExists : boolean;
try {
fileExists = await exists(TMPDIR);
fileExists = await exists(this.TMPDIR);
} catch (err) {
console.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await mkdir(TMPDIR);
console.log(`Created tmpdir ${TMPDIR}`);
await mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
} catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
await this.clearAll();
} catch (err) {
console.error(err);
}
}
}
module.exports = (sys : any) => {
system = sys;
TMPDIR = join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
}
return new FFMPEG(sys);
}