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,205 +3,209 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path"); const path_1 = require("path");
const fs_extra_1 = require("fs-extra"); const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec"); const exec_1 = require("exec");
let system = {}; /** @class FFMPEG **/
let TMPDIR; class FFMPEG {
/** constructor(sys) {
* Add padding to a number to 5 places. Return a string. this.id = 'ffmpeg';
* this.system = sys;
* @param {integer} i Integer to pad this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
* this.init();
* @returns {string} Padded string
**/
function padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
str = '0' + str;
} }
return str; async init() {
} const Log = require('log');
/** this.log = await Log({ label: this.id });
* Render a single frame from a video or image to a png. await this.checkDir();
*
* @param {object} state State object containing file data
* @param {object} light Object containing color information for frame
*
* @returns {string} Path of frame
**/
async function 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);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
let cmd;
let output;
let cmd2;
let output2;
let scale = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
} }
//console.dir(state) /**
//if (system.platform !== 'nix') { * Add padding to a number to 5 places. Return a string.
ext = 'png'; *
//} * @param {integer} i Integer to pad
tmpoutput = path_1.join(TMPDIR, `export-${padded}.${ext}`); *
rgb = rgb.map((e) => { * @returns {string} Padded string
return parseInt(e); **/
}); padded_frame(i) {
// let len = (i + '').length;
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`; let str = i + '';
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`; for (let x = 0; x < 5 - len; x++) {
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg" str = '0' + str;
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff" }
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png" return str;
try {
console.log(cmd);
output = await exec_1.exec(cmd);
} }
catch (err) { /**
console.error(err); * Render a single frame from a video or image to a png.
} *
if (output && output.stdout) * @param {object} state State object containing file data
console.log(`"${output.stdout}"`); * @param {object} light Object containing color information for frame
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) { *
* @returns {string} Path of frame
**/
async frame(state, light) {
const frameNum = state.frame;
const video = state.path;
const w = state.info.width;
const h = state.info.height;
const padded = this.padded_frame(frameNum);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
let cmd;
let output;
let cmd2;
let output2;
let scale = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
}
//console.dir(state)
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e) => {
return parseInt(e);
});
//
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`;
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg"
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try { try {
console.log(cmd2); console.log(cmd);
output2 = await exec_1.exec(cmd2); output = await exec_1.exec(cmd);
}
catch (err) {
console.error(err);
}
if (output && output.stdout)
console.log(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
output2 = await exec_1.exec(cmd2);
}
catch (err) {
console.error(err);
}
}
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
return tmpoutput;
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async frames(video, obj) {
const tmppath = this.TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(tmppath, `export-%05d.${ext}`);
try {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async clear(frame) {
const padded = this.padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
let cmd;
let fileExists;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async clearAll() {
const tmppath = this.TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file, index) => {
try {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async checkDir() {
let fileExists;
try {
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(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
} }
catch (err) { catch (err) {
console.error(err); console.error(err);
} }
} }
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
return tmpoutput;
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async function frames(video, obj) {
const tmppath = TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(tmppath, `export-%05d.${ext}`);
try {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async function clear(frame) {
const padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
let cmd;
let fileExists;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async function clearAll() {
const tmppath = TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file, index) => {
try {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir() {
let fileExists;
try {
fileExists = await fs_extra_1.exists(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}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
}
catch (err) {
console.error(err);
}
} }
module.exports = (sys) => { module.exports = (sys) => {
system = sys; return new FFMPEG(sys);
TMPDIR = path_1.join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
};
}; };
//# sourceMappingURL=index.js.map //# 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,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AC,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,205 +3,209 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path"); const path_1 = require("path");
const fs_extra_1 = require("fs-extra"); const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec"); const exec_1 = require("exec");
let system = {}; /** @class FFMPEG **/
let TMPDIR; class FFMPEG {
/** constructor(sys) {
* Add padding to a number to 5 places. Return a string. this.id = 'ffmpeg';
* this.system = sys;
* @param {integer} i Integer to pad this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
* this.init();
* @returns {string} Padded string
**/
function padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
str = '0' + str;
} }
return str; async init() {
} const Log = require('log');
/** this.log = await Log({ label: this.id });
* Render a single frame from a video or image to a png. await this.checkDir();
*
* @param {object} state State object containing file data
* @param {object} light Object containing color information for frame
*
* @returns {string} Path of frame
**/
async function 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);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
let cmd;
let output;
let cmd2;
let output2;
let scale = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
} }
//console.dir(state) /**
//if (system.platform !== 'nix') { * Add padding to a number to 5 places. Return a string.
ext = 'png'; *
//} * @param {integer} i Integer to pad
tmpoutput = path_1.join(TMPDIR, `export-${padded}.${ext}`); *
rgb = rgb.map((e) => { * @returns {string} Padded string
return parseInt(e); **/
}); padded_frame(i) {
// let len = (i + '').length;
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`; let str = i + '';
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`; for (let x = 0; x < 5 - len; x++) {
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg" str = '0' + str;
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff" }
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png" return str;
try {
console.log(cmd);
output = await exec_1.exec(cmd);
} }
catch (err) { /**
console.error(err); * Render a single frame from a video or image to a png.
} *
if (output && output.stdout) * @param {object} state State object containing file data
console.log(`"${output.stdout}"`); * @param {object} light Object containing color information for frame
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) { *
* @returns {string} Path of frame
**/
async frame(state, light) {
const frameNum = state.frame;
const video = state.path;
const w = state.info.width;
const h = state.info.height;
const padded = this.padded_frame(frameNum);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
let cmd;
let output;
let cmd2;
let output2;
let scale = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
}
//console.dir(state)
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e) => {
return parseInt(e);
});
//
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`;
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg"
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try { try {
console.log(cmd2); console.log(cmd);
output2 = await exec_1.exec(cmd2); output = await exec_1.exec(cmd);
}
catch (err) {
console.error(err);
}
if (output && output.stdout)
console.log(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
output2 = await exec_1.exec(cmd2);
}
catch (err) {
console.error(err);
}
}
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
return tmpoutput;
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async frames(video, obj) {
const tmppath = this.TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(tmppath, `export-%05d.${ext}`);
try {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async clear(frame) {
const padded = this.padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
let cmd;
let fileExists;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async clearAll() {
const tmppath = this.TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file, index) => {
try {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async checkDir() {
let fileExists;
try {
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(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
} }
catch (err) { catch (err) {
console.error(err); console.error(err);
} }
} }
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
return tmpoutput;
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async function frames(video, obj) {
const tmppath = TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(tmppath, `export-%05d.${ext}`);
try {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async function clear(frame) {
const padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
let cmd;
let fileExists;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async function clearAll() {
const tmppath = TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file, index) => {
try {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir() {
let fileExists;
try {
fileExists = await fs_extra_1.exists(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}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
}
catch (err) {
console.error(err);
}
} }
module.exports = (sys) => { module.exports = (sys) => {
system = sys; return new FFMPEG(sys);
TMPDIR = path_1.join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
};
}; };
//# sourceMappingURL=index.js.map //# 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;;;;;;;I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C;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,205 +3,209 @@ Object.defineProperty(exports, "__esModule", { value: true });
const path_1 = require("path"); const path_1 = require("path");
const fs_extra_1 = require("fs-extra"); const fs_extra_1 = require("fs-extra");
const exec_1 = require("exec"); const exec_1 = require("exec");
let system = {}; /** @class FFMPEG **/
let TMPDIR; class FFMPEG {
/** constructor(sys) {
* Add padding to a number to 5 places. Return a string. this.id = 'ffmpeg';
* this.system = sys;
* @param {integer} i Integer to pad this.TMPDIR = path_1.join(this.system.tmp, 'mcopy_digital');
* this.init();
* @returns {string} Padded string
**/
function padded_frame(i) {
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
str = '0' + str;
} }
return str; async init() {
} const Log = require('log');
/** this.log = await Log({ label: this.id });
* Render a single frame from a video or image to a png. await this.checkDir();
*
* @param {object} state State object containing file data
* @param {object} light Object containing color information for frame
*
* @returns {string} Path of frame
**/
async function 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);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
let cmd;
let output;
let cmd2;
let output2;
let scale = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
} }
//console.dir(state) /**
//if (system.platform !== 'nix') { * Add padding to a number to 5 places. Return a string.
ext = 'png'; *
//} * @param {integer} i Integer to pad
tmpoutput = path_1.join(TMPDIR, `export-${padded}.${ext}`); *
rgb = rgb.map((e) => { * @returns {string} Padded string
return parseInt(e); **/
}); padded_frame(i) {
// let len = (i + '').length;
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`; let str = i + '';
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`; for (let x = 0; x < 5 - len; x++) {
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg" str = '0' + str;
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff" }
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png" return str;
try {
console.log(cmd);
output = await exec_1.exec(cmd);
} }
catch (err) { /**
console.error(err); * Render a single frame from a video or image to a png.
} *
if (output && output.stdout) * @param {object} state State object containing file data
console.log(`"${output.stdout}"`); * @param {object} light Object containing color information for frame
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) { *
* @returns {string} Path of frame
**/
async frame(state, light) {
const frameNum = state.frame;
const video = state.path;
const w = state.info.width;
const h = state.info.height;
const padded = this.padded_frame(frameNum);
let ext = 'tif';
let rgb = light.color;
let tmpoutput;
let cmd;
let output;
let cmd2;
let output2;
let scale = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
}
//console.dir(state)
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
rgb = rgb.map((e) => {
return parseInt(e);
});
//
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`;
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg"
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try { try {
console.log(cmd2); console.log(cmd);
output2 = await exec_1.exec(cmd2); output = await exec_1.exec(cmd);
}
catch (err) {
console.error(err);
}
if (output && output.stdout)
console.log(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
output2 = await exec_1.exec(cmd2);
}
catch (err) {
console.error(err);
}
}
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
return tmpoutput;
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async frames(video, obj) {
const tmppath = this.TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(tmppath, `export-%05d.${ext}`);
try {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async clear(frame) {
const padded = this.padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
let cmd;
let fileExists;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async clearAll() {
const tmppath = this.TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file, index) => {
try {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async checkDir() {
let fileExists;
try {
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(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
} }
catch (err) { catch (err) {
console.error(err); console.error(err);
} }
} }
if (output2 && output2.stdout)
console.log(`"${output2.stdout}"`);
return tmpoutput;
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async function frames(video, obj) {
const tmppath = TMPDIR;
let ext = 'tif';
let tmpoutput;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = path_1.join(tmppath, `export-%05d.${ext}`);
try {
await fs_extra_1.mkdir(tmppath);
}
catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async function clear(frame) {
const padded = padded_frame(frame);
let ext = 'tif';
let tmppath;
let tmpoutput;
let cmd;
let fileExists;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = path_1.join(TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await fs_extra_1.exists(tmppath);
}
catch (err) {
console.error(err);
}
if (!fs_extra_1.exists)
return false;
try {
await fs_extra_1.unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
}
catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async function clearAll() {
const tmppath = TMPDIR;
let files;
try {
files = await fs_extra_1.readdir(tmppath);
}
catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file, index) => {
try {
await fs_extra_1.unlink(path_1.join(tmppath, file));
}
catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir() {
let fileExists;
try {
fileExists = await fs_extra_1.exists(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}`);
}
catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
}
catch (err) {
console.error(err);
}
} }
module.exports = (sys) => { module.exports = (sys) => {
system = sys; return new FFMPEG(sys);
TMPDIR = path_1.join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
};
}; };
//# sourceMappingURL=index.js.map //# 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,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AAa,EAAE,KAAW,EAAE,EAAE;gBAClD,IAAI;oBACH,MAAM,iBAAM,CAAC,WAAI,CAAC,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

@ -9,220 +9,226 @@ import { exec } from 'exec';
//const spawn = require('spawn'); //const spawn = require('spawn');
import { exit } from 'exit'; import { exit } from 'exit';
let system : any = {}; /** @class FFMPEG **/
let TMPDIR : string;
/** class FFMPEG {
* Add padding to a number to 5 places. Return a string. private system : any;
* private log : any;
* @param {integer} i Integer to pad private id : string = 'ffmpeg';
* private TMPDIR : string;
* @returns {string} Padded string constructor (sys : any) {
**/ this.system = sys;
this.TMPDIR = join(this.system.tmp, 'mcopy_digital');
function padded_frame (i : number) { this.init()
let len = (i + '').length;
let str = i + '';
for (let x = 0; x < 5 - len; x++) {
str = '0' + str;
} }
return str; 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.
*
* @param {integer} i Integer to pad
*
* @returns {string} Padded string
**/
/** private padded_frame (i : number) {
* Render a single frame from a video or image to a png. let len = (i + '').length;
* let str = i + '';
* @param {object} state State object containing file data for (let x = 0; x < 5 - len; x++) {
* @param {object} light Object containing color information for frame str = '0' + str;
* }
* @returns {string} Path of frame return str;
**/
async function 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);
let ext : string = 'tif';
let rgb : any[] = light.color;
let tmpoutput : string;
let cmd : string;
let output : any;
let cmd2 : string;
let output2 : any;
let scale : string = '';
if (w && h) {
scale = `,scale=${w}:${h}`;
} }
//console.dir(state) /**
* Render a single frame from a video or image to a png.
*
* @param {object} state State object containing file data
* @param {object} light Object containing color information for frame
*
* @returns {string} Path of frame
**/
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 = this.padded_frame(frameNum);
let ext : string = 'tif';
let rgb : any[] = light.color;
let tmpoutput : string;
let cmd : string;
let output : any;
let cmd2 : string;
let output2 : any;
//if (system.platform !== 'nix') { let scale : string = '';
ext = 'png'; if (w && h) {
//} scale = `,scale=${w}:${h}`;
}
tmpoutput = join(TMPDIR, `export-${padded}.${ext}`); //console.dir(state)
rgb = rgb.map((e : string) => { //if (system.platform !== 'nix') {
return parseInt(e); ext = 'png';
}); //}
//
cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`;
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg" tmpoutput = join(this.TMPDIR, `export-${padded}.${ext}`);
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
try { rgb = rgb.map((e : string) => {
console.log(cmd); return parseInt(e);
output = await exec(cmd); });
} catch (err) { //
console.error(err); cmd = `ffmpeg -y -i "${video}" -vf "select='gte(n\\,${frameNum})'${scale}" -vframes 1 -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
} cmd2 = `convert "${tmpoutput}" -resize ${w}x${h} -size ${w}x${h} xc:"rgb(${rgb[0]},${rgb[1]},${rgb[2]})" +swap -compose Darken -composite "${tmpoutput}"`;
if (output && output.stdout) console.log(`"${output.stdout}"`);
//ffmpeg -i "${video}" -ss 00:00:07.000 -vframes 1 "export-${time}.jpg"
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "export-%05d.tiff"
//-vf "select=gte(n\,${frame})" -compression_algo raw -pix_fmt rgb24 "export-${padded}.png"
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try { try {
console.log(cmd2); console.log(cmd);
output2 = await exec(cmd2); output = await exec(cmd);
} catch (err) {
console.error(err);
}
if (output && output.stdout) console.log(`"${output.stdout}"`);
if (rgb[0] !== 255 || rgb[1] !== 255 || rgb[2] !== 255) {
try {
console.log(cmd2);
output2 = await exec(cmd2);
} catch (err) {
console.error(err);
}
}
if (output2 && output2.stdout) console.log(`"${output2.stdout}"`);
return tmpoutput
}
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
public async frames (video : string, obj : any) {
const tmppath : string = this.TMPDIR;
let ext : string = 'tif';
let tmpoutput : string;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = join(tmppath, `export-%05d.${ext}`);
try {
await mkdir(tmppath);
} catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
public async clear (frame : number) {
const padded : string = this.padded_frame(frame);
let ext : string = 'tif';
let tmppath : string;
let tmpoutput : string;
let cmd : string;
let fileExists : boolean;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = join(this.TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await exists(tmppath);
} catch (err) {
console.error(err);
}
if (!exists) return false;
try {
await unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
} catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
public async clearAll () {
const tmppath : string = this.TMPDIR;
let files : any;
try {
files = await readdir(tmppath);
} catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file : string, index : any) => {
try {
await unlink(join(tmppath, file));
} catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
private async checkDir () {
let fileExists : boolean;
try {
fileExists = await exists(this.TMPDIR);
} catch (err) {
console.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await mkdir(this.TMPDIR);
console.log(`Created tmpdir ${this.TMPDIR}`);
} catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await this.clearAll();
} catch (err) { } catch (err) {
console.error(err); console.error(err);
} }
} }
if (output2 && output2.stdout) console.log(`"${output2.stdout}"`);
return tmpoutput
} }
/**
* Render all frames in a video to the temp directory.
* Not in use.
*
* @param {string} video Path to video
* @param {object} obj Not sure
*
* @returns {?}
**/
async function frames (video : string, obj : any) {
const tmppath : string = TMPDIR;
let ext : string = 'tif';
let tmpoutput : string;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmpoutput = join(tmppath, `export-%05d.${ext}`);
try {
await mkdir(tmppath);
} catch (err) {
console.error(err);
}
//ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"
}
/**
* Clears a specific frame from the tmp directory
*
* @param {integer} frame Integer of frame to clear
*
* @returns {boolean} True if successful, false if not
**/
async function clear (frame : number) {
const padded : string = padded_frame(frame);
let ext : string = 'tif';
let tmppath : string;
let tmpoutput : string;
let cmd : string;
let fileExists : boolean;
//if (system.platform !== 'nix') {
ext = 'png';
//}
tmppath = join(TMPDIR, `export-${padded}.${ext}`);
try {
fileExists = await exists(tmppath);
} catch (err) {
console.error(err);
}
if (!exists) return false;
try {
await unlink(tmppath);
console.log(`Cleared frame ${tmppath}`);
} catch (err) {
console.error(err);
}
return true;
}
/**
* Delete all frames in temp directory.
*
**/
async function clearAll () {
const tmppath : string = TMPDIR;
let files : any;
try {
files = await readdir(tmppath);
} catch (err) {
console.error(err);
}
if (files) {
files.forEach(async (file : string, index : any) => {
try {
await unlink(join(tmppath, file));
} catch (err) {
console.error(err);
}
});
}
}
/**
* Checks if mcopy temp directory exists. If it doesn't,
* create it.
**/
async function checkDir () {
let fileExists : boolean;
try {
fileExists = await exists(TMPDIR);
} catch (err) {
console.error('Error checking for tmp dir', err);
}
if (!fileExists) {
try {
await mkdir(TMPDIR);
console.log(`Created tmpdir ${TMPDIR}`);
} catch (err) {
console.error('Error creating tmp dir', err);
}
}
try {
await clearAll();
} catch (err) {
console.error(err);
}
}
module.exports = (sys : any) => { module.exports = (sys : any) => {
system = sys; return new FFMPEG(sys);
TMPDIR = join(system.tmp, 'mcopy_digital');
checkDir();
return {
frames,
frame,
clear,
clearAll
}
} }