Only require functions that are actually used rather than the entire module.
This commit is contained in:
parent
f4e799d647
commit
c0fcdd62da
76
frameloom
76
frameloom
|
@ -1,15 +1,15 @@
|
||||||
#!/usr/bin/env node
|
#!/usr/bin/env node
|
||||||
'use strict';
|
'use strict';
|
||||||
const execRaw = require('child_process').exec;
|
const execRaw = require('child_process').exec;
|
||||||
const os = require('os');
|
const { tmpdir } = require('os');
|
||||||
const path = require('path');
|
const { join, extname } = require('path');
|
||||||
const program = require('commander');
|
const program = require('commander');
|
||||||
const fs = require('fs-extra');
|
const { move, exists, unlink, readdir, mkdir } = require('fs-extra');
|
||||||
const pkg = require('./package.json');
|
const { version } = require('package.json');
|
||||||
const OUTPUT_RE = new RegExp('{{o}}', 'g');
|
const OUTPUT_RE = new RegExp('{{o}}', 'g');
|
||||||
const INPUT_RE = new RegExp('{{i}}', 'g');
|
const INPUT_RE = new RegExp('{{i}}', 'g');
|
||||||
let QUIET = false;
|
let QUIET = false;
|
||||||
let TMPDIR = os.tmpdir() || '/tmp';
|
let TMPDIR = tmpdir() || '/tmp';
|
||||||
let TMPPATH;
|
let TMPPATH;
|
||||||
/**
|
/**
|
||||||
* Shells out to execute a command with async/await.
|
* Shells out to execute a command with async/await.
|
||||||
|
@ -97,14 +97,14 @@ function randomInt(min, max) {
|
||||||
**/
|
**/
|
||||||
async function clear() {
|
async function clear() {
|
||||||
let cmd = `rm -r "${TMPPATH}"`;
|
let cmd = `rm -r "${TMPPATH}"`;
|
||||||
let exists;
|
let dirExists;
|
||||||
try {
|
try {
|
||||||
exists = await fs.exists(TMPPATH);
|
dirExists = await exists(TMPPATH);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log('Error checking if file exists', err);
|
log('Error checking if file exists', err);
|
||||||
}
|
}
|
||||||
if (exists) {
|
if (dirExists) {
|
||||||
log(`Clearing temp directory "${TMPPATH}"`);
|
log(`Clearing temp directory "${TMPPATH}"`);
|
||||||
try {
|
try {
|
||||||
await exec(cmd);
|
await exec(cmd);
|
||||||
|
@ -115,7 +115,7 @@ async function clear() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
await fs.mkdir(TMPPATH);
|
await mkdir(TMPPATH);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
if (err.code !== 'EEXIST') {
|
if (err.code !== 'EEXIST') {
|
||||||
|
@ -140,7 +140,7 @@ async function frames(video, order, avconv) {
|
||||||
let exe = avconv ? 'avconv' : 'ffmpeg';
|
let exe = avconv ? 'avconv' : 'ffmpeg';
|
||||||
let tmpoutput;
|
let tmpoutput;
|
||||||
let cmd;
|
let cmd;
|
||||||
tmpoutput = path.join(TMPPATH, `export-%05d_${order}.${ext}`);
|
tmpoutput = join(TMPPATH, `export-%05d_${order}.${ext}`);
|
||||||
cmd = `${exe} -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
|
cmd = `${exe} -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`;
|
||||||
log(`Exporting ${video} as single frames...`);
|
log(`Exporting ${video} as single frames...`);
|
||||||
try {
|
try {
|
||||||
|
@ -150,7 +150,7 @@ async function frames(video, order, avconv) {
|
||||||
log('Error exporting video', err);
|
log('Error exporting video', err);
|
||||||
return process.exit(3);
|
return process.exit(3);
|
||||||
}
|
}
|
||||||
return path.join(TMPPATH, `export-%05d_${order}`);
|
return join(TMPPATH, `export-%05d_${order}`);
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Shells out to run a sub command on every frame to perform effects
|
* Shells out to run a sub command on every frame to perform effects
|
||||||
|
@ -163,7 +163,7 @@ async function subExec(cmd) {
|
||||||
let frameCmd;
|
let frameCmd;
|
||||||
let framePath;
|
let framePath;
|
||||||
try {
|
try {
|
||||||
frames = await fs.readdir(TMPPATH);
|
frames = await readdir(TMPPATH);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log('Error reading tmp directory', err);
|
log('Error reading tmp directory', err);
|
||||||
|
@ -173,7 +173,7 @@ async function subExec(cmd) {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
for (let frame of frames) {
|
for (let frame of frames) {
|
||||||
framePath = path.join(TMPPATH, frame);
|
framePath = join(TMPPATH, frame);
|
||||||
if (cmd.indexOf('{{i}}') !== -1 || cmd.indexOf('{{o}}')) {
|
if (cmd.indexOf('{{i}}') !== -1 || cmd.indexOf('{{o}}')) {
|
||||||
frameCmd = cmd.replace(INPUT_RE, framePath)
|
frameCmd = cmd.replace(INPUT_RE, framePath)
|
||||||
.replace(OUTPUT_RE, framePath);
|
.replace(OUTPUT_RE, framePath);
|
||||||
|
@ -204,7 +204,7 @@ async function weave(pattern, realtime, random) {
|
||||||
let alt = false;
|
let alt = false;
|
||||||
log('Weaving frames...');
|
log('Weaving frames...');
|
||||||
try {
|
try {
|
||||||
frames = await fs.readdir(TMPPATH);
|
frames = await readdir(TMPPATH);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log('Error reading tmp directory', err);
|
log('Error reading tmp directory', err);
|
||||||
|
@ -268,7 +268,7 @@ async function altSort(list, pattern, realtime) {
|
||||||
let oldPath;
|
let oldPath;
|
||||||
let newName;
|
let newName;
|
||||||
let newPath;
|
let newPath;
|
||||||
let ext = path.extname(list[0]);
|
let ext = extname(list[0]);
|
||||||
let x;
|
let x;
|
||||||
let i;
|
let i;
|
||||||
for (x = 0; x < pattern.length; x++) {
|
for (x = 0; x < pattern.length; x++) {
|
||||||
|
@ -298,12 +298,12 @@ async function altSort(list, pattern, realtime) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
oldName = String(groups[patternIndexes[i]][0]);
|
oldName = String(groups[patternIndexes[i]][0]);
|
||||||
oldPath = path.join(TMPPATH, oldName);
|
oldPath = join(TMPPATH, oldName);
|
||||||
groups[patternIndexes[i]].shift();
|
groups[patternIndexes[i]].shift();
|
||||||
if (skip) {
|
if (skip) {
|
||||||
log(`Skipping ${oldName}`);
|
log(`Skipping ${oldName}`);
|
||||||
try {
|
try {
|
||||||
await fs.unlink(oldPath);
|
await unlink(oldPath);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log('Error deleting frame', err);
|
log('Error deleting frame', err);
|
||||||
|
@ -311,10 +311,10 @@ async function altSort(list, pattern, realtime) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
||||||
newPath = path.join(TMPPATH, newName);
|
newPath = join(TMPPATH, newName);
|
||||||
log(`Renaming ${oldName} -> ${newName}`);
|
log(`Renaming ${oldName} -> ${newName}`);
|
||||||
try {
|
try {
|
||||||
await fs.move(oldPath, newPath);
|
await move(oldPath, newPath);
|
||||||
newList.push(newName);
|
newList.push(newName);
|
||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
@ -339,7 +339,7 @@ async function standardSort(list, pattern, realtime) {
|
||||||
let step;
|
let step;
|
||||||
let skipCount;
|
let skipCount;
|
||||||
let skip;
|
let skip;
|
||||||
let ext = path.extname(list[0]);
|
let ext = extname(list[0]);
|
||||||
let oldPath;
|
let oldPath;
|
||||||
let newName;
|
let newName;
|
||||||
let newPath;
|
let newPath;
|
||||||
|
@ -356,11 +356,11 @@ async function standardSort(list, pattern, realtime) {
|
||||||
skipCount = pattern.length;
|
skipCount = pattern.length;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
oldPath = path.join(TMPPATH, list[i]);
|
oldPath = join(TMPPATH, list[i]);
|
||||||
if (skip) {
|
if (skip) {
|
||||||
log(`Skipping ${list[i]}`);
|
log(`Skipping ${list[i]}`);
|
||||||
try {
|
try {
|
||||||
await fs.unlink(oldPath);
|
await unlink(oldPath);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log('Error deleting frame', err);
|
log('Error deleting frame', err);
|
||||||
|
@ -368,10 +368,10 @@ async function standardSort(list, pattern, realtime) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
||||||
newPath = path.join(TMPPATH, newName);
|
newPath = join(TMPPATH, newName);
|
||||||
log(`Renaming ${list[i]} -> ${newName}`);
|
log(`Renaming ${list[i]} -> ${newName}`);
|
||||||
try {
|
try {
|
||||||
await fs.move(oldPath, newPath);
|
await move(oldPath, newPath);
|
||||||
newList.push(newName);
|
newList.push(newName);
|
||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
@ -391,7 +391,7 @@ async function standardSort(list, pattern, realtime) {
|
||||||
**/
|
**/
|
||||||
async function randomSort(list, pattern, realtime) {
|
async function randomSort(list, pattern, realtime) {
|
||||||
let frameCount = 0;
|
let frameCount = 0;
|
||||||
let ext = path.extname(list[0]);
|
let ext = extname(list[0]);
|
||||||
let oldPath;
|
let oldPath;
|
||||||
let newName;
|
let newName;
|
||||||
let newPath;
|
let newPath;
|
||||||
|
@ -405,10 +405,10 @@ async function randomSort(list, pattern, realtime) {
|
||||||
list = list.slice(0, removeLen);
|
list = list.slice(0, removeLen);
|
||||||
log(`Skipping extra frames...`);
|
log(`Skipping extra frames...`);
|
||||||
for (let i = 0; i < remove.length; i++) {
|
for (let i = 0; i < remove.length; i++) {
|
||||||
oldPath = path.join(TMPPATH, remove[i]);
|
oldPath = join(TMPPATH, remove[i]);
|
||||||
log(`Skipping ${list[i]}`);
|
log(`Skipping ${list[i]}`);
|
||||||
try {
|
try {
|
||||||
await fs.unlink(oldPath);
|
await unlink(oldPath);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log('Error deleting frame', err);
|
log('Error deleting frame', err);
|
||||||
|
@ -416,12 +416,12 @@ async function randomSort(list, pattern, realtime) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
for (let i = 0; i < list.length; i++) {
|
for (let i = 0; i < list.length; i++) {
|
||||||
oldPath = path.join(TMPPATH, list[i]);
|
oldPath = join(TMPPATH, list[i]);
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
||||||
newPath = path.join(TMPPATH, newName);
|
newPath = join(TMPPATH, newName);
|
||||||
log(`Renaming ${list[i]} -> ${newName}`);
|
log(`Renaming ${list[i]} -> ${newName}`);
|
||||||
try {
|
try {
|
||||||
await fs.move(oldPath, newPath);
|
await move(oldPath, newPath);
|
||||||
newList.push(newName);
|
newList.push(newName);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
|
@ -440,7 +440,7 @@ async function spinFrames() {
|
||||||
let rotate;
|
let rotate;
|
||||||
console.log('Spinning frames...');
|
console.log('Spinning frames...');
|
||||||
try {
|
try {
|
||||||
frames = await fs.readdir(TMPPATH);
|
frames = await readdir(TMPPATH);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
console.error('Error reading tmp directory', err);
|
console.error('Error reading tmp directory', err);
|
||||||
|
@ -451,7 +451,7 @@ async function spinFrames() {
|
||||||
return true;
|
return true;
|
||||||
});
|
});
|
||||||
for (let frame of frames) {
|
for (let frame of frames) {
|
||||||
framePath = path.join(TMPPATH, frame);
|
framePath = join(TMPPATH, frame);
|
||||||
rotate = '';
|
rotate = '';
|
||||||
flip = '';
|
flip = '';
|
||||||
flop = '';
|
flop = '';
|
||||||
|
@ -487,7 +487,7 @@ async function spinFrames() {
|
||||||
**/
|
**/
|
||||||
async function render(output, avconv) {
|
async function render(output, avconv) {
|
||||||
//process.exit()
|
//process.exit()
|
||||||
let frames = path.join(TMPPATH, `render_%05d.tif`);
|
let frames = join(TMPPATH, `render_%05d.tif`);
|
||||||
let exe = avconv ? 'avconv' : 'ffmpeg';
|
let exe = avconv ? 'avconv' : 'ffmpeg';
|
||||||
let resolution = '1920x1080'; //TODO: make variable/argument
|
let resolution = '1920x1080'; //TODO: make variable/argument
|
||||||
//TODO: make object configurable with shorthand names
|
//TODO: make object configurable with shorthand names
|
||||||
|
@ -521,7 +521,7 @@ async function main(arg) {
|
||||||
let random = false;
|
let random = false;
|
||||||
let e = false;
|
let e = false;
|
||||||
let exe = arg.avconv ? 'avconv' : 'ffmpeg';
|
let exe = arg.avconv ? 'avconv' : 'ffmpeg';
|
||||||
let exists;
|
let fileExists;
|
||||||
console.time('frameloom');
|
console.time('frameloom');
|
||||||
if (input.length < 2) {
|
if (input.length < 2) {
|
||||||
log('Must provide more than 1 input', {});
|
log('Must provide more than 1 input', {});
|
||||||
|
@ -558,13 +558,13 @@ async function main(arg) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
exists = await exec(`which ${exe}`);
|
fileExists = await exec(`which ${exe}`);
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (err) {
|
||||||
log(`Error checking for ${exe}`);
|
log(`Error checking for ${exe}`);
|
||||||
process.exit(11);
|
process.exit(11);
|
||||||
}
|
}
|
||||||
if (!exists || exists === '' || exists.indexOf(exe) === -1) {
|
if (!fileExists || fileExists === '' || fileExists.indexOf(exe) === -1) {
|
||||||
log(`${exe} is required and is not installed. Please install ${exe} to use frameloom.`);
|
log(`${exe} is required and is not installed. Please install ${exe} to use frameloom.`);
|
||||||
process.exit(12);
|
process.exit(12);
|
||||||
}
|
}
|
||||||
|
@ -574,7 +574,7 @@ async function main(arg) {
|
||||||
}
|
}
|
||||||
if (arg.realtime)
|
if (arg.realtime)
|
||||||
realtime = true;
|
realtime = true;
|
||||||
TMPPATH = path.join(TMPDIR, 'frameloom');
|
TMPPATH = join(TMPDIR, 'frameloom');
|
||||||
try {
|
try {
|
||||||
await clear();
|
await clear();
|
||||||
}
|
}
|
||||||
|
@ -634,7 +634,7 @@ async function main(arg) {
|
||||||
console.timeEnd('frameloom');
|
console.timeEnd('frameloom');
|
||||||
}
|
}
|
||||||
program
|
program
|
||||||
.version(pkg.version)
|
.version(version)
|
||||||
.option('-i, --input [files]', 'Specify input videos with paths seperated by colon')
|
.option('-i, --input [files]', 'Specify input videos with paths seperated by colon')
|
||||||
.option('-o, --output [file]', 'Specify output path of video')
|
.option('-o, --output [file]', 'Specify output path of video')
|
||||||
.option('-p, --pattern [pattern]', 'Specify a pattern for the flicker 1:1 is standard')
|
.option('-p, --pattern [pattern]', 'Specify a pattern for the flicker 1:1 is standard')
|
||||||
|
|
|
@ -3,18 +3,18 @@
|
||||||
'use strict'
|
'use strict'
|
||||||
|
|
||||||
const execRaw = require('child_process').exec
|
const execRaw = require('child_process').exec
|
||||||
const os = require('os')
|
const { tmpdir } = require('os')
|
||||||
const path = require('path')
|
const { join, extname } = require('path')
|
||||||
const program = require('commander')
|
const program = require('commander')
|
||||||
const fs = require('fs-extra')
|
const { move, exists, unlink, readdir, mkdir } = require('fs-extra')
|
||||||
|
|
||||||
const pkg : any = require('./package.json')
|
const { version } = require('package.json')
|
||||||
|
|
||||||
const OUTPUT_RE : RegExp = new RegExp('{{o}}', 'g')
|
const OUTPUT_RE : RegExp = new RegExp('{{o}}', 'g')
|
||||||
const INPUT_RE : RegExp = new RegExp('{{i}}', 'g')
|
const INPUT_RE : RegExp = new RegExp('{{i}}', 'g')
|
||||||
|
|
||||||
let QUIET : boolean = false
|
let QUIET : boolean = false
|
||||||
let TMPDIR : string = os.tmpdir() || '/tmp'
|
let TMPDIR : string = tmpdir() || '/tmp'
|
||||||
let TMPPATH : string
|
let TMPPATH : string
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -102,15 +102,15 @@ function randomInt (min : number, max : number) {
|
||||||
**/
|
**/
|
||||||
async function clear () {
|
async function clear () {
|
||||||
let cmd : string = `rm -r "${TMPPATH}"`
|
let cmd : string = `rm -r "${TMPPATH}"`
|
||||||
let exists : boolean
|
let dirExists : boolean
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exists = await fs.exists(TMPPATH)
|
dirExists = await exists(TMPPATH)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error checking if file exists', err)
|
log('Error checking if file exists', err)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (exists) {
|
if (dirExists) {
|
||||||
log(`Clearing temp directory "${TMPPATH}"`)
|
log(`Clearing temp directory "${TMPPATH}"`)
|
||||||
try {
|
try {
|
||||||
await exec(cmd)
|
await exec(cmd)
|
||||||
|
@ -121,7 +121,7 @@ async function clear () {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.mkdir(TMPPATH)
|
await mkdir(TMPPATH)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
if (err.code !== 'EEXIST') {
|
if (err.code !== 'EEXIST') {
|
||||||
log('Error making directory', err)
|
log('Error making directory', err)
|
||||||
|
@ -147,7 +147,7 @@ async function frames (video : string, order : number, avconv : boolean) {
|
||||||
let tmpoutput : string
|
let tmpoutput : string
|
||||||
let cmd : string
|
let cmd : string
|
||||||
|
|
||||||
tmpoutput = path.join(TMPPATH, `export-%05d_${order}.${ext}`)
|
tmpoutput = join(TMPPATH, `export-%05d_${order}.${ext}`)
|
||||||
|
|
||||||
cmd = `${exe} -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`
|
cmd = `${exe} -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`
|
||||||
|
|
||||||
|
@ -160,7 +160,7 @@ async function frames (video : string, order : number, avconv : boolean) {
|
||||||
return process.exit(3)
|
return process.exit(3)
|
||||||
}
|
}
|
||||||
|
|
||||||
return path.join(TMPPATH, `export-%05d_${order}`)
|
return join(TMPPATH, `export-%05d_${order}`)
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
* Shells out to run a sub command on every frame to perform effects
|
* Shells out to run a sub command on every frame to perform effects
|
||||||
|
@ -174,7 +174,7 @@ async function subExec (cmd : string) {
|
||||||
let framePath : string
|
let framePath : string
|
||||||
|
|
||||||
try {
|
try {
|
||||||
frames = await fs.readdir(TMPPATH)
|
frames = await readdir(TMPPATH)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error reading tmp directory', err)
|
log('Error reading tmp directory', err)
|
||||||
}
|
}
|
||||||
|
@ -184,7 +184,7 @@ async function subExec (cmd : string) {
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let frame of frames) {
|
for (let frame of frames) {
|
||||||
framePath = path.join(TMPPATH, frame)
|
framePath = join(TMPPATH, frame)
|
||||||
if (cmd.indexOf('{{i}}') !== -1 || cmd.indexOf('{{o}}')) {
|
if (cmd.indexOf('{{i}}') !== -1 || cmd.indexOf('{{o}}')) {
|
||||||
frameCmd = cmd.replace(INPUT_RE, framePath)
|
frameCmd = cmd.replace(INPUT_RE, framePath)
|
||||||
.replace(OUTPUT_RE, framePath)
|
.replace(OUTPUT_RE, framePath)
|
||||||
|
@ -216,7 +216,7 @@ async function weave (pattern : number[], realtime : boolean, random : boolean)
|
||||||
log('Weaving frames...')
|
log('Weaving frames...')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
frames = await fs.readdir(TMPPATH)
|
frames = await readdir(TMPPATH)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error reading tmp directory', err)
|
log('Error reading tmp directory', err)
|
||||||
}
|
}
|
||||||
|
@ -275,7 +275,7 @@ async function altSort (list : string[], pattern : number[], realtime : boolean)
|
||||||
let oldPath : string
|
let oldPath : string
|
||||||
let newName : string
|
let newName : string
|
||||||
let newPath : string
|
let newPath : string
|
||||||
let ext : string = path.extname(list[0])
|
let ext : string = extname(list[0])
|
||||||
let x : number
|
let x : number
|
||||||
let i : number
|
let i : number
|
||||||
|
|
||||||
|
@ -313,14 +313,14 @@ async function altSort (list : string[], pattern : number[], realtime : boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
oldName = String(groups[patternIndexes[i]][0])
|
oldName = String(groups[patternIndexes[i]][0])
|
||||||
oldPath = path.join(TMPPATH, oldName)
|
oldPath = join(TMPPATH, oldName)
|
||||||
|
|
||||||
groups[patternIndexes[i]].shift()
|
groups[patternIndexes[i]].shift()
|
||||||
|
|
||||||
if (skip) {
|
if (skip) {
|
||||||
log(`Skipping ${oldName}`)
|
log(`Skipping ${oldName}`)
|
||||||
try {
|
try {
|
||||||
await fs.unlink(oldPath)
|
await unlink(oldPath)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error deleting frame', err)
|
log('Error deleting frame', err)
|
||||||
}
|
}
|
||||||
|
@ -328,11 +328,11 @@ async function altSort (list : string[], pattern : number[], realtime : boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`
|
newName = `./render_${zeroPad(frameCount)}${ext}`
|
||||||
newPath = path.join(TMPPATH, newName)
|
newPath = join(TMPPATH, newName)
|
||||||
log(`Renaming ${oldName} -> ${newName}`)
|
log(`Renaming ${oldName} -> ${newName}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.move(oldPath, newPath)
|
await move(oldPath, newPath)
|
||||||
newList.push(newName)
|
newList.push(newName)
|
||||||
frameCount++
|
frameCount++
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -357,7 +357,7 @@ async function standardSort (list : string[], pattern : number[], realtime : boo
|
||||||
let step : any
|
let step : any
|
||||||
let skipCount : number
|
let skipCount : number
|
||||||
let skip : boolean
|
let skip : boolean
|
||||||
let ext : string = path.extname(list[0])
|
let ext : string = extname(list[0])
|
||||||
let oldPath : string
|
let oldPath : string
|
||||||
let newName : string
|
let newName : string
|
||||||
let newPath : string
|
let newPath : string
|
||||||
|
@ -377,12 +377,12 @@ async function standardSort (list : string[], pattern : number[], realtime : boo
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
oldPath = path.join(TMPPATH, list[i])
|
oldPath = join(TMPPATH, list[i])
|
||||||
|
|
||||||
if (skip) {
|
if (skip) {
|
||||||
log(`Skipping ${list[i]}`)
|
log(`Skipping ${list[i]}`)
|
||||||
try {
|
try {
|
||||||
await fs.unlink(oldPath)
|
await unlink(oldPath)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error deleting frame', err)
|
log('Error deleting frame', err)
|
||||||
}
|
}
|
||||||
|
@ -390,11 +390,11 @@ async function standardSort (list : string[], pattern : number[], realtime : boo
|
||||||
}
|
}
|
||||||
|
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`
|
newName = `./render_${zeroPad(frameCount)}${ext}`
|
||||||
newPath = path.join(TMPPATH, newName)
|
newPath = join(TMPPATH, newName)
|
||||||
log(`Renaming ${list[i]} -> ${newName}`)
|
log(`Renaming ${list[i]} -> ${newName}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.move(oldPath, newPath)
|
await move(oldPath, newPath)
|
||||||
newList.push(newName)
|
newList.push(newName)
|
||||||
frameCount++
|
frameCount++
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -416,7 +416,7 @@ async function standardSort (list : string[], pattern : number[], realtime : boo
|
||||||
**/
|
**/
|
||||||
async function randomSort (list : string[], pattern : number[], realtime : boolean) {
|
async function randomSort (list : string[], pattern : number[], realtime : boolean) {
|
||||||
let frameCount : number = 0
|
let frameCount : number = 0
|
||||||
let ext : string = path.extname(list[0])
|
let ext : string = extname(list[0])
|
||||||
let oldPath : string
|
let oldPath : string
|
||||||
let newName : string
|
let newName : string
|
||||||
let newPath : string
|
let newPath : string
|
||||||
|
@ -433,10 +433,10 @@ async function randomSort (list : string[], pattern : number[], realtime : boole
|
||||||
|
|
||||||
log(`Skipping extra frames...`)
|
log(`Skipping extra frames...`)
|
||||||
for (let i : number = 0; i < remove.length; i++) {
|
for (let i : number = 0; i < remove.length; i++) {
|
||||||
oldPath = path.join(TMPPATH, remove[i])
|
oldPath = join(TMPPATH, remove[i])
|
||||||
log(`Skipping ${list[i]}`)
|
log(`Skipping ${list[i]}`)
|
||||||
try {
|
try {
|
||||||
await fs.unlink(oldPath)
|
await unlink(oldPath)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error deleting frame', err)
|
log('Error deleting frame', err)
|
||||||
}
|
}
|
||||||
|
@ -444,14 +444,14 @@ async function randomSort (list : string[], pattern : number[], realtime : boole
|
||||||
}
|
}
|
||||||
|
|
||||||
for (let i : number = 0; i < list.length; i++) {
|
for (let i : number = 0; i < list.length; i++) {
|
||||||
oldPath = path.join(TMPPATH, list[i])
|
oldPath = join(TMPPATH, list[i])
|
||||||
|
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`
|
newName = `./render_${zeroPad(frameCount)}${ext}`
|
||||||
newPath = path.join(TMPPATH, newName)
|
newPath = join(TMPPATH, newName)
|
||||||
log(`Renaming ${list[i]} -> ${newName}`)
|
log(`Renaming ${list[i]} -> ${newName}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await fs.move(oldPath, newPath)
|
await move(oldPath, newPath)
|
||||||
newList.push(newName)
|
newList.push(newName)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error moving frame', err)
|
log('Error moving frame', err)
|
||||||
|
@ -474,7 +474,7 @@ async function spinFrames () {
|
||||||
console.log('Spinning frames...')
|
console.log('Spinning frames...')
|
||||||
|
|
||||||
try {
|
try {
|
||||||
frames = await fs.readdir(TMPPATH)
|
frames = await readdir(TMPPATH)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
console.error('Error reading tmp directory', err)
|
console.error('Error reading tmp directory', err)
|
||||||
}
|
}
|
||||||
|
@ -485,7 +485,7 @@ async function spinFrames () {
|
||||||
})
|
})
|
||||||
|
|
||||||
for (let frame of frames) {
|
for (let frame of frames) {
|
||||||
framePath = path.join(TMPPATH, frame)
|
framePath = join(TMPPATH, frame)
|
||||||
rotate = ''
|
rotate = ''
|
||||||
flip = ''
|
flip = ''
|
||||||
flop = ''
|
flop = ''
|
||||||
|
@ -521,7 +521,7 @@ async function spinFrames () {
|
||||||
**/
|
**/
|
||||||
async function render (output : string, avconv : boolean) {
|
async function render (output : string, avconv : boolean) {
|
||||||
//process.exit()
|
//process.exit()
|
||||||
let frames : string = path.join(TMPPATH, `render_%05d.tif`)
|
let frames : string = join(TMPPATH, `render_%05d.tif`)
|
||||||
let exe : string = avconv ? 'avconv' : 'ffmpeg'
|
let exe : string = avconv ? 'avconv' : 'ffmpeg'
|
||||||
let resolution : string = '1920x1080' //TODO: make variable/argument
|
let resolution : string = '1920x1080' //TODO: make variable/argument
|
||||||
//TODO: make object configurable with shorthand names
|
//TODO: make object configurable with shorthand names
|
||||||
|
@ -556,7 +556,7 @@ async function main (arg : any) {
|
||||||
let random : boolean = false
|
let random : boolean = false
|
||||||
let e : any = false
|
let e : any = false
|
||||||
let exe : string = arg.avconv ? 'avconv' : 'ffmpeg'
|
let exe : string = arg.avconv ? 'avconv' : 'ffmpeg'
|
||||||
let exists : any
|
let fileExists : any
|
||||||
|
|
||||||
console.time('frameloom')
|
console.time('frameloom')
|
||||||
|
|
||||||
|
@ -602,13 +602,13 @@ async function main (arg : any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
try {
|
try {
|
||||||
exists = await exec(`which ${exe}`)
|
fileExists = await exec(`which ${exe}`)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log(`Error checking for ${exe}`)
|
log(`Error checking for ${exe}`)
|
||||||
process.exit(11)
|
process.exit(11)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!exists || exists === '' || exists.indexOf(exe) === -1) {
|
if (!fileExists || fileExists === '' || fileExists.indexOf(exe) === -1) {
|
||||||
log(`${exe} is required and is not installed. Please install ${exe} to use frameloom.`)
|
log(`${exe} is required and is not installed. Please install ${exe} to use frameloom.`)
|
||||||
process.exit(12)
|
process.exit(12)
|
||||||
}
|
}
|
||||||
|
@ -620,7 +620,7 @@ async function main (arg : any) {
|
||||||
|
|
||||||
if (arg.realtime) realtime = true;
|
if (arg.realtime) realtime = true;
|
||||||
|
|
||||||
TMPPATH = path.join(TMPDIR, 'frameloom');
|
TMPPATH = join(TMPDIR, 'frameloom');
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await clear()
|
await clear()
|
||||||
|
@ -683,7 +683,7 @@ async function main (arg : any) {
|
||||||
}
|
}
|
||||||
|
|
||||||
program
|
program
|
||||||
.version(pkg.version)
|
.version(version)
|
||||||
.option('-i, --input [files]', 'Specify input videos with paths seperated by colon')
|
.option('-i, --input [files]', 'Specify input videos with paths seperated by colon')
|
||||||
.option('-o, --output [file]', 'Specify output path of video')
|
.option('-o, --output [file]', 'Specify output path of video')
|
||||||
.option('-p, --pattern [pattern]', 'Specify a pattern for the flicker 1:1 is standard')
|
.option('-p, --pattern [pattern]', 'Specify a pattern for the flicker 1:1 is standard')
|
||||||
|
|
Loading…
Reference in New Issue