Stylize code, remove unnecessary semicolons
This commit is contained in:
parent
9ea749ca3d
commit
b3e100a853
150
frameloom
150
frameloom
|
@ -1,29 +1,29 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
'use strict';
|
||||
'use strict'
|
||||
|
||||
const execRaw = require('child_process').exec;
|
||||
const os = require('os');
|
||||
const path = require('path');
|
||||
const program = require('commander');
|
||||
const fs = require('fs-extra');
|
||||
const execRaw = require('child_process').exec
|
||||
const os = require('os')
|
||||
const path = require('path')
|
||||
const program = require('commander')
|
||||
const fs = require('fs-extra')
|
||||
|
||||
let TMPDIR = os.tmpdir() || '/tmp';
|
||||
let TMPPATH;
|
||||
let TMPDIR = os.tmpdir() || '/tmp'
|
||||
let TMPPATH
|
||||
|
||||
async function exec (cmd) {
|
||||
return new Promise((resolve, reject) => {
|
||||
return execRaw(cmd, (err, stdio, stderr) => {
|
||||
if (err) return reject(err);
|
||||
return resolve(stdio);
|
||||
});
|
||||
});
|
||||
if (err) return reject(err)
|
||||
return resolve(stdio)
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
async function clear () {
|
||||
let exists;
|
||||
let exists
|
||||
try {
|
||||
exists = await fs.exists(TMPPATH);
|
||||
exists = await fs.exists(TMPPATH)
|
||||
} catch (err) {
|
||||
console.error(err)
|
||||
}
|
||||
|
@ -45,11 +45,11 @@ async function clear () {
|
|||
}
|
||||
|
||||
async function frames (video, order) {
|
||||
let ext = 'tif';
|
||||
let tmpoutput;
|
||||
let cmd;
|
||||
let ext = 'tif'
|
||||
let tmpoutput
|
||||
let cmd
|
||||
|
||||
tmpoutput = path.join(TMPPATH, `export-%05d_${order}.${ext}`);
|
||||
tmpoutput = path.join(TMPPATH, `export-%05d_${order}.${ext}`)
|
||||
|
||||
cmd = `ffmpeg -i "${video}" -compression_algo raw -pix_fmt rgb24 "${tmpoutput}"`
|
||||
|
||||
|
@ -61,16 +61,16 @@ async function frames (video, order) {
|
|||
console.error('Error exporting video', err)
|
||||
return process.exit(3)
|
||||
}
|
||||
return path.join(TMPPATH, `export_${order}`);
|
||||
return path.join(TMPPATH, `export_${order}`)
|
||||
}
|
||||
|
||||
function zeroPad (i, max = 5) {
|
||||
let len = (i + '').length;
|
||||
let str = i + '';
|
||||
let len = (i + '').length
|
||||
let str = i + ''
|
||||
for (let x = 0; x < max - len; x++) {
|
||||
str = '0' + str;
|
||||
str = '0' + str
|
||||
}
|
||||
return str;
|
||||
return str
|
||||
}
|
||||
|
||||
async function reorder (pattern, realtime) {
|
||||
|
@ -87,7 +87,7 @@ async function reorder (pattern, realtime) {
|
|||
|
||||
console.dir(frames)
|
||||
frames = frames.filter (file =>{
|
||||
if (file.indexOf('.tif') !== -1) return true;
|
||||
if (file.indexOf('.tif') !== -1) return true
|
||||
});
|
||||
//other patterns
|
||||
|
||||
|
@ -101,19 +101,19 @@ async function reorder (pattern, realtime) {
|
|||
}
|
||||
|
||||
function groupAlt (list, pattern, realtime) {
|
||||
let groups = [];
|
||||
let newList = [];
|
||||
let frameCount = 0;
|
||||
let oldPath;
|
||||
let newName;
|
||||
let newPath;
|
||||
let ext = path.extname(list[0]);
|
||||
let groups = []
|
||||
let newList = []
|
||||
let frameCount = 0
|
||||
let oldPath
|
||||
let newName
|
||||
let newPath
|
||||
let ext = path.extname(list[0])
|
||||
|
||||
for (let g of pattern) {
|
||||
groups.push([]);
|
||||
groups.push([])
|
||||
}
|
||||
for (let 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++) {
|
||||
for (let g of pattern) {
|
||||
|
@ -140,25 +140,25 @@ function groupAlt (list, pattern, realtime) {
|
|||
}
|
||||
|
||||
async function patternSort (list, pattern, realtime = false) {
|
||||
let frameCount = 0;
|
||||
let stepCount;
|
||||
let step;
|
||||
let skipCount;
|
||||
let skip;
|
||||
let alt;
|
||||
let ext = path.extname(list[0]);
|
||||
let oldPath;
|
||||
let newName;
|
||||
let newPath;
|
||||
let newList = [];
|
||||
let frameCount = 0
|
||||
let stepCount
|
||||
let step
|
||||
let skipCount
|
||||
let skip
|
||||
let alt
|
||||
let ext = path.extname(list[0])
|
||||
let oldPath
|
||||
let newName
|
||||
let newPath
|
||||
let newList = []
|
||||
|
||||
for (let el of pattern) {
|
||||
if (el !== 1) alt = true;
|
||||
if (el !== 1) alt = true
|
||||
}
|
||||
|
||||
if (realtime) {
|
||||
skip = false;
|
||||
skipCount = pattern.length + 1;
|
||||
skip = false
|
||||
skipCount = pattern.length + 1
|
||||
}
|
||||
|
||||
if (!alt) {
|
||||
|
@ -168,79 +168,79 @@ async function patternSort (list, pattern, realtime = false) {
|
|||
skipCount--;
|
||||
if (skipCount === 0) {
|
||||
skip = !skip;
|
||||
skipCount = pattern.length;
|
||||
skipCount = pattern.length
|
||||
}
|
||||
}
|
||||
|
||||
oldPath = path.join(TMPPATH, list[i]);
|
||||
oldPath = path.join(TMPPATH, list[i])
|
||||
|
||||
if (skip) {
|
||||
console.log(`Skipping ${list[i]}`);
|
||||
console.log(`Skipping ${list[i]}`)
|
||||
try {
|
||||
await fs.unlink(oldPath)
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error(err)
|
||||
}
|
||||
continue;
|
||||
continue
|
||||
}
|
||||
|
||||
newName = `./render_${zeroPad(frameCount)}${ext}`;
|
||||
newPath = path.join(TMPPATH, newName);
|
||||
console.log(`Renaming ${list[i]} -> ${newName}`);
|
||||
newName = `./render_${zeroPad(frameCount)}${ext}`
|
||||
newPath = path.join(TMPPATH, newName)
|
||||
console.log(`Renaming ${list[i]} -> ${newName}`)
|
||||
|
||||
try {
|
||||
await fs.rename(oldPath, newPath)
|
||||
newList.push(newName);
|
||||
newList.push(newName)
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error(err)
|
||||
}
|
||||
|
||||
frameCount++;
|
||||
frameCount++
|
||||
}
|
||||
} else {
|
||||
newList = groupAlt(list, pattern, realtime);
|
||||
newList = groupAlt(list, pattern, realtime)
|
||||
}
|
||||
|
||||
return newList
|
||||
}
|
||||
|
||||
async function render (output) {
|
||||
let exp = path.join(TMPPATH, `render_%05d.tif`);
|
||||
let resolution = '1920x1080';
|
||||
let h264 = `-vcodec libx264 -g 1 -crf 25 -pix_fmt yuv420p`;
|
||||
let prores = `-c:v prores -profile:v 3 -c:a pcm_s16le - g 1`;
|
||||
let format = (output.indexOf('.mov') !== -1) ? prores : h264;
|
||||
const cmd = `ffmpeg -r 24 -f image2 -s ${resolution} -i ${exp} ${format} -y ${output}`;
|
||||
let exp = path.join(TMPPATH, `render_%05d.tif`)
|
||||
let resolution = '1920x1080'
|
||||
let h264 = `-vcodec libx264 -g 1 -crf 25 -pix_fmt yuv420p`
|
||||
let prores = `-c:v prores -profile:v 3 -c:a pcm_s16le - g 1`
|
||||
let format = (output.indexOf('.mov') !== -1) ? prores : h264
|
||||
const cmd = `ffmpeg -r 24 -f image2 -s ${resolution} -i ${exp} ${format} -y ${output}`
|
||||
|
||||
console.log(`Exporting video ${output}`);
|
||||
console.log(cmd);
|
||||
console.log(`Exporting video ${output}`)
|
||||
console.log(cmd)
|
||||
|
||||
try {
|
||||
await exec(cmd);
|
||||
await exec(cmd)
|
||||
} catch (err) {
|
||||
console.error(err);
|
||||
console.error(err)
|
||||
}
|
||||
}
|
||||
|
||||
async function main (arg) {
|
||||
let input = arg.input.split(':');
|
||||
let input = arg.input.split(':')
|
||||
let output = arg.output;
|
||||
let pattern = [];
|
||||
let realtime = false;
|
||||
console.time('frameloom');
|
||||
console.time('frameloom')
|
||||
|
||||
if (input.length < 2) {
|
||||
console.error('Must provide more than 1 input');
|
||||
return process.exit(1);
|
||||
return process.exit(1)
|
||||
}
|
||||
|
||||
if (!output) {
|
||||
console.error('Must provide video output path');
|
||||
return process.exit(2);
|
||||
console.error('Must provide video output path')
|
||||
return process.exit(2)
|
||||
}
|
||||
|
||||
if (arg.pattern) {
|
||||
pattern = arg.pattern.split(':');
|
||||
pattern = arg.pattern.split(':')
|
||||
pattern = pattern.map(el =>{
|
||||
return parseInt(el);
|
||||
})
|
||||
|
|
Loading…
Reference in New Issue