Implemented altsort for patterns other than 1:1. Added a check for the ffmpeg or avconv binaries before running.
This commit is contained in:
parent
2b2b98eb01
commit
aa42c8dc67
|
@ -45,7 +45,5 @@ Options:
|
||||||
|
|
||||||
## TODO
|
## TODO
|
||||||
|
|
||||||
* Fix alternate sort pattern features
|
|
||||||
* Check for ffmpeg or avconv before executing
|
|
||||||
* Generate example videos automatically
|
* Generate example videos automatically
|
||||||
* Publish example videos
|
* Publish example videos
|
86
frameloom
86
frameloom
|
@ -219,6 +219,7 @@ async function weave(pattern, realtime, random) {
|
||||||
alt = true;
|
alt = true;
|
||||||
}
|
}
|
||||||
if (random) {
|
if (random) {
|
||||||
|
log('Sorting frames randomly...');
|
||||||
try {
|
try {
|
||||||
seq = await randomSort(frames, pattern, realtime);
|
seq = await randomSort(frames, pattern, realtime);
|
||||||
}
|
}
|
||||||
|
@ -227,6 +228,7 @@ async function weave(pattern, realtime, random) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (!alt) {
|
else if (!alt) {
|
||||||
|
log('Sorting frames normally...');
|
||||||
try {
|
try {
|
||||||
seq = await standardSort(frames, pattern, realtime);
|
seq = await standardSort(frames, pattern, realtime);
|
||||||
}
|
}
|
||||||
|
@ -235,8 +237,9 @@ async function weave(pattern, realtime, random) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (alt) {
|
else if (alt) {
|
||||||
log('This feature is not ready, please check https://github.com/sixteenmillimeter/frameloom.git', {});
|
//log('This feature is not ready, please check https://github.com/sixteenmillimeter/frameloom.git', {})
|
||||||
process.exit(10);
|
//process.exit(10)
|
||||||
|
log('Sorting frames with alternate pattern...');
|
||||||
try {
|
try {
|
||||||
seq = await altSort(frames, pattern, realtime);
|
seq = await altSort(frames, pattern, realtime);
|
||||||
}
|
}
|
||||||
|
@ -256,34 +259,69 @@ async function weave(pattern, realtime, random) {
|
||||||
async function altSort(list, pattern, realtime) {
|
async function altSort(list, pattern, realtime) {
|
||||||
let groups = [];
|
let groups = [];
|
||||||
let newList = [];
|
let newList = [];
|
||||||
|
let loops = 0;
|
||||||
|
let patternIndexes = [];
|
||||||
let frameCount = 0;
|
let frameCount = 0;
|
||||||
|
let skipCount;
|
||||||
|
let skip;
|
||||||
|
let oldName;
|
||||||
let oldPath;
|
let oldPath;
|
||||||
let newName;
|
let newName;
|
||||||
let newPath;
|
let newPath;
|
||||||
let ext = path.extname(list[0]);
|
let ext = path.extname(list[0]);
|
||||||
for (let g of pattern) {
|
let x;
|
||||||
|
let i;
|
||||||
|
for (x = 0; x < pattern.length; x++) {
|
||||||
groups.push([]);
|
groups.push([]);
|
||||||
|
for (let i = 0; i < pattern[x]; i++) {
|
||||||
|
patternIndexes.push(x);
|
||||||
}
|
}
|
||||||
for (let i = 0; i < list.length; i++) {
|
}
|
||||||
|
for (i = 0; i < list.length; i++) {
|
||||||
groups[i % pattern.length].push(list[i]);
|
groups[i % pattern.length].push(list[i]);
|
||||||
}
|
}
|
||||||
for (let x = 0; x < list.length; x++) {
|
loops = Math.ceil(list.length / patternIndexes.length);
|
||||||
for (let g of pattern) {
|
if (realtime) {
|
||||||
for (let i = 0; i < g; i++) {
|
skip = false;
|
||||||
/*oldPath = path.join(TMPPATH, list[i]);
|
skipCount = patternIndexes.length + 1;
|
||||||
|
}
|
||||||
|
for (x = 0; x < loops; x++) {
|
||||||
|
for (i = 0; i < patternIndexes.length; i++) {
|
||||||
|
if (realtime) {
|
||||||
|
skipCount--;
|
||||||
|
if (skipCount === 0) {
|
||||||
|
skip = !skip;
|
||||||
|
skipCount = pattern.length;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (typeof groups[patternIndexes[i]][0] === 'undefined') {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
oldName = String(groups[patternIndexes[i]][0]);
|
||||||
|
oldPath = path.join(TMPPATH, oldName);
|
||||||
|
groups[patternIndexes[i]].shift();
|
||||||
|
if (skip) {
|
||||||
|
log(`Skipping ${oldName}`);
|
||||||
|
try {
|
||||||
|
await fs.unlink(oldPath);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
log('Error deleting frame', err);
|
||||||
|
}
|
||||||
|
continue;
|
||||||
|
}
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
||||||
newPath = path.join(TMPPATH, newName);
|
newPath = path.join(TMPPATH, newName);
|
||||||
|
log(`Renaming ${oldName} -> ${newName}`);
|
||||||
log(`Renaming ${list[i]} -> ${newName}`);
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//await fs.move(oldPath, newPath, { overwrite: true })
|
await fs.move(oldPath, newPath);
|
||||||
newList.push(newName);
|
newList.push(newName);
|
||||||
} catch (err) {
|
|
||||||
log(err);
|
|
||||||
}*/
|
|
||||||
frameCount++;
|
frameCount++;
|
||||||
}
|
}
|
||||||
|
catch (err) {
|
||||||
|
log('Error renaming frame', err);
|
||||||
|
return process.exit(10);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return newList;
|
return newList;
|
||||||
|
@ -483,6 +521,8 @@ async function main(arg) {
|
||||||
let avconv = false;
|
let avconv = false;
|
||||||
let random = false;
|
let random = false;
|
||||||
let e = false;
|
let e = false;
|
||||||
|
let exe = arg.avconv ? 'avconv' : 'ffmpeg';
|
||||||
|
let exists;
|
||||||
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', {});
|
||||||
|
@ -518,6 +558,21 @@ async function main(arg) {
|
||||||
pattern.push(1);
|
pattern.push(1);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
try {
|
||||||
|
exists = await exec(`which ${exe}`);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
log(`Error checking for ${exe}`);
|
||||||
|
process.exit(11);
|
||||||
|
}
|
||||||
|
if (!exists || exists === '' || exists.indexOf(exe) === -1) {
|
||||||
|
log(`${exe} is required and is not installed. Please install ${exe} to use frameloom.`);
|
||||||
|
process.exit(12);
|
||||||
|
}
|
||||||
|
if (pattern.length !== input.length) {
|
||||||
|
log(`Number of inputs (${input.length}) doesn't match the pattern length (${pattern.length})`);
|
||||||
|
process.exit(10);
|
||||||
|
}
|
||||||
if (arg.realtime)
|
if (arg.realtime)
|
||||||
realtime = true;
|
realtime = true;
|
||||||
TMPPATH = path.join(TMPDIR, 'frameloom');
|
TMPPATH = path.join(TMPDIR, 'frameloom');
|
||||||
|
@ -538,7 +593,6 @@ async function main(arg) {
|
||||||
return process.exit(4);
|
return process.exit(4);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
log('Weaving frames');
|
|
||||||
try {
|
try {
|
||||||
await weave(pattern, realtime, random);
|
await weave(pattern, realtime, random);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "frameloom",
|
"name": "frameloom",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"lockfileVersion": 1,
|
"lockfileVersion": 1,
|
||||||
"requires": true,
|
"requires": true,
|
||||||
"dependencies": {
|
"dependencies": {
|
||||||
|
|
|
@ -1,6 +1,6 @@
|
||||||
{
|
{
|
||||||
"name": "frameloom",
|
"name": "frameloom",
|
||||||
"version": "1.0.2",
|
"version": "1.0.3",
|
||||||
"description": "Node script to generate flicker videos by interweaving frames from multiple videos",
|
"description": "Node script to generate flicker videos by interweaving frames from multiple videos",
|
||||||
"main": "frameloom",
|
"main": "frameloom",
|
||||||
"scripts": {
|
"scripts": {
|
||||||
|
|
106
src/frameloom.ts
106
src/frameloom.ts
|
@ -231,20 +231,23 @@ async function weave (pattern : number[], realtime : boolean, random : boolean)
|
||||||
}
|
}
|
||||||
|
|
||||||
if (random){
|
if (random){
|
||||||
|
log('Sorting frames randomly...')
|
||||||
try {
|
try {
|
||||||
seq = await randomSort(frames, pattern, realtime)
|
seq = await randomSort(frames, pattern, realtime)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error sorting frames', err)
|
log('Error sorting frames', err)
|
||||||
}
|
}
|
||||||
} else if (!alt) {
|
} else if (!alt) {
|
||||||
|
log('Sorting frames normally...')
|
||||||
try {
|
try {
|
||||||
seq = await standardSort(frames, pattern, realtime)
|
seq = await standardSort(frames, pattern, realtime)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
log('Error sorting frames', err)
|
log('Error sorting frames', err)
|
||||||
}
|
}
|
||||||
} else if (alt) {
|
} else if (alt) {
|
||||||
log('This feature is not ready, please check https://github.com/sixteenmillimeter/frameloom.git', {})
|
//log('This feature is not ready, please check https://github.com/sixteenmillimeter/frameloom.git', {})
|
||||||
process.exit(10)
|
//process.exit(10)
|
||||||
|
log('Sorting frames with alternate pattern...')
|
||||||
try {
|
try {
|
||||||
seq = await altSort(frames, pattern, realtime)
|
seq = await altSort(frames, pattern, realtime)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -263,39 +266,82 @@ async function weave (pattern : number[], realtime : boolean, random : boolean)
|
||||||
async function altSort (list : string[], pattern : number[], realtime : boolean) {
|
async function altSort (list : string[], pattern : number[], realtime : boolean) {
|
||||||
let groups : any[] = []
|
let groups : any[] = []
|
||||||
let newList : string[] = []
|
let newList : string[] = []
|
||||||
|
let loops : number = 0
|
||||||
|
let patternIndexes : number[] = []
|
||||||
let frameCount : number = 0
|
let frameCount : number = 0
|
||||||
|
let skipCount : number
|
||||||
|
let skip : boolean
|
||||||
|
let oldName : string
|
||||||
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 = path.extname(list[0])
|
||||||
|
let x : number
|
||||||
|
let i : number
|
||||||
|
|
||||||
for (let g of pattern) {
|
for (x = 0; x < pattern.length; x++) {
|
||||||
groups.push([])
|
groups.push([])
|
||||||
|
for (let i : number = 0; i < pattern[x]; i++) {
|
||||||
|
patternIndexes.push(x)
|
||||||
}
|
}
|
||||||
for (let i : number = 0; i < list.length; i++) {
|
}
|
||||||
|
|
||||||
|
for (i = 0; i < list.length; i++) {
|
||||||
groups[i % pattern.length].push(list[i])
|
groups[i % pattern.length].push(list[i])
|
||||||
}
|
}
|
||||||
for (let x : number = 0; x < list.length; x++) {
|
|
||||||
for (let g of pattern) {
|
|
||||||
for (let i : number = 0; i < g; i++) {
|
|
||||||
|
|
||||||
/*oldPath = path.join(TMPPATH, list[i]);
|
loops = Math.ceil(list.length / patternIndexes.length)
|
||||||
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
|
||||||
newPath = path.join(TMPPATH, newName);
|
|
||||||
|
|
||||||
log(`Renaming ${list[i]} -> ${newName}`);
|
if (realtime) {
|
||||||
|
skip = false
|
||||||
|
skipCount = patternIndexes.length + 1
|
||||||
|
}
|
||||||
|
|
||||||
|
for (x = 0; x < loops; x++) {
|
||||||
|
for (i = 0; i < patternIndexes.length; i++) {
|
||||||
|
|
||||||
|
if (realtime) {
|
||||||
|
skipCount--;
|
||||||
|
if (skipCount === 0) {
|
||||||
|
skip = !skip;
|
||||||
|
skipCount = pattern.length
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (typeof groups[patternIndexes[i]][0] === 'undefined') {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
oldName = String(groups[patternIndexes[i]][0])
|
||||||
|
oldPath = path.join(TMPPATH, oldName)
|
||||||
|
|
||||||
|
groups[patternIndexes[i]].shift()
|
||||||
|
|
||||||
|
if (skip) {
|
||||||
|
log(`Skipping ${oldName}`)
|
||||||
|
try {
|
||||||
|
await fs.unlink(oldPath)
|
||||||
|
} catch (err) {
|
||||||
|
log('Error deleting frame', err)
|
||||||
|
}
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
|
newName = `./render_${zeroPad(frameCount)}${ext}`
|
||||||
|
newPath = path.join(TMPPATH, newName)
|
||||||
|
log(`Renaming ${oldName} -> ${newName}`)
|
||||||
|
|
||||||
try {
|
try {
|
||||||
//await fs.move(oldPath, newPath, { overwrite: true })
|
await fs.move(oldPath, newPath)
|
||||||
newList.push(newName);
|
newList.push(newName)
|
||||||
} catch (err) {
|
|
||||||
log(err);
|
|
||||||
}*/
|
|
||||||
|
|
||||||
frameCount++
|
frameCount++
|
||||||
|
} catch (err) {
|
||||||
|
log('Error renaming frame', err)
|
||||||
|
return process.exit(10)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return newList
|
return newList
|
||||||
}
|
}
|
||||||
/**
|
/**
|
||||||
|
@ -485,12 +531,6 @@ async function render (output : string, avconv : boolean) {
|
||||||
log(`Exporting video ${output}`)
|
log(`Exporting video ${output}`)
|
||||||
log(cmd)
|
log(cmd)
|
||||||
|
|
||||||
/*try {
|
|
||||||
await exec(`ls "${TMPPATH}"`)
|
|
||||||
} catch (err) {
|
|
||||||
log(err)
|
|
||||||
}*/
|
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await exec(cmd)
|
await exec(cmd)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
@ -511,6 +551,8 @@ async function main (arg : any) {
|
||||||
let avconv : boolean = false
|
let avconv : boolean = false
|
||||||
let random : boolean = false
|
let random : boolean = false
|
||||||
let e : any = false
|
let e : any = false
|
||||||
|
let exe : string = arg.avconv ? 'avconv' : 'ffmpeg'
|
||||||
|
let exists : any
|
||||||
|
|
||||||
console.time('frameloom')
|
console.time('frameloom')
|
||||||
|
|
||||||
|
@ -555,6 +597,23 @@ async function main (arg : any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
exists = await exec(`which ${exe}`)
|
||||||
|
} catch (err) {
|
||||||
|
log(`Error checking for ${exe}`)
|
||||||
|
process.exit(11)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!exists || exists === '' || exists.indexOf(exe) === -1) {
|
||||||
|
log(`${exe} is required and is not installed. Please install ${exe} to use frameloom.`)
|
||||||
|
process.exit(12)
|
||||||
|
}
|
||||||
|
|
||||||
|
if (pattern.length !== input.length) {
|
||||||
|
log(`Number of inputs (${input.length}) doesn't match the pattern length (${pattern.length})`)
|
||||||
|
process.exit(10)
|
||||||
|
}
|
||||||
|
|
||||||
if (arg.realtime) realtime = true;
|
if (arg.realtime) realtime = true;
|
||||||
|
|
||||||
TMPPATH = path.join(TMPDIR, 'frameloom');
|
TMPPATH = path.join(TMPDIR, 'frameloom');
|
||||||
|
@ -577,7 +636,6 @@ async function main (arg : any) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
log('Weaving frames')
|
|
||||||
try {
|
try {
|
||||||
await weave(pattern, realtime, random)
|
await weave(pattern, realtime, random)
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|
Loading…
Reference in New Issue