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