Merge remote-tracking branch 'origin/master'

This commit is contained in:
mmcwilliams 2019-04-17 13:58:41 -04:00
commit 3a561ad6c3
4 changed files with 117 additions and 8 deletions

View File

@ -21,7 +21,7 @@ let TMPPATH;
**/ **/
async function exec(cmd) { async function exec(cmd) {
return new Promise((resolve, reject) => { return new Promise((resolve, reject) => {
return execRaw(cmd, (err, stdio, stderr) => { return execRaw(cmd, { maxBuffer: 500 * 1024 * 1024 }, (err, stdio, stderr) => {
if (err) if (err)
return reject(err); return reject(err);
return resolve(stdio); return resolve(stdio);
@ -86,6 +86,11 @@ function shuffle(array) {
array[j] = temp; array[j] = temp;
} }
} }
function randomInt(min, max) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/** /**
* Clears the temporary directory of all files. * Clears the temporary directory of all files.
* Establishes a directory if none exists. * Establishes a directory if none exists.
@ -388,6 +393,50 @@ async function randomSort(list, pattern, realtime) {
} }
return newList; return newList;
} }
async function spinFrames() {
let frames;
let framePath;
let cmd;
let flip;
let flop;
let rotate;
console.log('Spinning frames...');
try {
frames = await fs.readdir(TMPPATH);
}
catch (err) {
console.error('Error reading tmp directory', err);
}
//console.dir(frames)
frames = frames.filter(file => {
if (file.indexOf('.tif') !== -1)
return true;
});
for (let frame of frames) {
framePath = path.join(TMPPATH, frame);
rotate = '';
flip = '';
flop = '';
if (randomInt(0, 1) === 1) {
rotate = '-rotate 180 ';
}
if (randomInt(0, 1) === 1) {
flip = '-flip ';
}
if (randomInt(0, 1) === 1) {
flop = '-flop ';
}
cmd = `convert ${framePath} ${rotate}${flip}${flop} ${framePath}`;
console.log(cmd);
try {
await exec(cmd);
}
catch (err) {
console.error(err);
process.exit(10);
}
}
}
/** /**
* Render the frames into a video using ffmpeg. * Render the frames into a video using ffmpeg.
* *

12
package-lock.json generated
View File

@ -27,9 +27,9 @@
"dev": true "dev": true
}, },
"@types/node": { "@types/node": {
"version": "11.13.0", "version": "11.13.4",
"resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.0.tgz", "resolved": "https://registry.npmjs.org/@types/node/-/node-11.13.4.tgz",
"integrity": "sha512-rx29MMkRdVmzunmiA4lzBYJNnXsW/PhG4kMBy2ATsYaDjGGR75dCFEVVROKpNwlVdcUX3xxlghKQOeDPBJobng==", "integrity": "sha512-+rabAZZ3Yn7tF/XPGHupKIL5EcAbrLxnTr/hgQICxbeuAfWtT0UZSfULE+ndusckBItcv4o6ZeOJplQikVcLvQ==",
"dev": true "dev": true
}, },
"ajv": { "ajv": {
@ -2984,9 +2984,9 @@
} }
}, },
"typescript": { "typescript": {
"version": "3.4.1", "version": "3.4.3",
"resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.1.tgz", "resolved": "https://registry.npmjs.org/typescript/-/typescript-3.4.3.tgz",
"integrity": "sha512-3NSMb2VzDQm8oBTLH6Nj55VVtUEpe/rgkIzMir0qVoLyjDZlnMBva0U6vDiV3IH+sl/Yu6oP5QwsAQtHPmDd2Q==", "integrity": "sha512-FFgHdPt4T/duxx6Ndf7hwgMZZjZpB+U0nMNGVCYPq0rEzWKjEDobm4J6yb3CS7naZ0yURFqdw9Gwc7UOh/P9oQ==",
"dev": true "dev": true
}, },
"typical": { "typical": {

View File

@ -25,5 +25,11 @@
"pkg": "^4.3.5", "pkg": "^4.3.5",
"qunit": "^2.8.0", "qunit": "^2.8.0",
"typescript": "^3.4.1" "typescript": "^3.4.1"
},
"pkg": {
"scripts": [
"./frameloom",
"./lib/**/*"
]
} }
} }

View File

@ -27,7 +27,7 @@ let TMPPATH : string
**/ **/
async function exec (cmd : string) { async function exec (cmd : string) {
return new Promise((resolve : any, reject : any) => { return new Promise((resolve : any, reject : any) => {
return execRaw(cmd, (err : any, stdio : string, stderr : string) => { return execRaw(cmd, { maxBuffer : 500 * 1024 * 1024}, (err : any, stdio : string, stderr : string) => {
if (err) return reject(err) if (err) return reject(err)
return resolve(stdio) return resolve(stdio)
}) })
@ -89,6 +89,13 @@ function shuffle (array : any[]) {
array[j] = temp array[j] = temp
} }
} }
function randomInt (min : number, max : number) {
min = Math.ceil(min);
max = Math.floor(max);
return Math.floor(Math.random() * (max - min + 1)) + min;
}
/** /**
* Clears the temporary directory of all files. * Clears the temporary directory of all files.
* Establishes a directory if none exists. * Establishes a directory if none exists.
@ -409,6 +416,53 @@ async function randomSort (list : string[], pattern : number[], realtime : boole
return newList return newList
} }
async function spinFrames () {
let frames : string[]
let framePath : string
let cmd : string
let flip : string
let flop : string
let rotate : string
console.log('Spinning frames...')
try {
frames = await fs.readdir(TMPPATH)
} catch (err) {
console.error('Error reading tmp directory', err)
}
//console.dir(frames)
frames = frames.filter (file =>{
if (file.indexOf('.tif') !== -1) return true
})
for (let frame of frames) {
framePath = path.join(TMPPATH, frame)
rotate = ''
flip = ''
flop = ''
if (randomInt(0, 1) === 1) {
rotate = '-rotate 180 '
}
if (randomInt(0, 1) === 1) {
flip = '-flip '
}
if (randomInt(0, 1) === 1) {
flop = '-flop '
}
cmd = `convert ${framePath} ${rotate}${flip}${flop} ${framePath}`
console.log(cmd)
try {
await exec(cmd)
} catch (err) {
console.error(err)
process.exit(10)
}
}
}
/** /**
* Render the frames into a video using ffmpeg. * Render the frames into a video using ffmpeg.
* *