From d2e33bd8dedd0c870ec3ecd5549f59dc4b3371ac Mon Sep 17 00:00:00 2001 From: mmcw-dev Date: Sat, 22 Dec 2018 01:01:40 -0500 Subject: [PATCH] Script is now able to generate standard and random sequences from the example videos provided in the examples.sh script. The --realtime and --random flags are working. TODO: fix alt patterns like 2:2 or 3:1 --- examples.sh | 33 +++++++++++++++++++++++++++++++++ frameloom | 20 ++++++++++++-------- 2 files changed, 45 insertions(+), 8 deletions(-) create mode 100644 examples.sh diff --git a/examples.sh b/examples.sh new file mode 100644 index 0000000..63a6134 --- /dev/null +++ b/examples.sh @@ -0,0 +1,33 @@ +#!/bin/bash + +echo "Downloading example videos from archive.org..." + +mkdir examples + +#Please run this script sparingly!!! + +if [ ! -f ./examples/A.mp4 ]; then + wget -O A.mp4 https://ia802701.us.archive.org/9/items/electricsheep-flock-244-20000-0/00244%3D20660%3D11095%3D11000_512kb.mp4 + mv A.mp4 ./examples/ +fi +if [ ! -f ./examples/B.mp4 ]; then + wget -O B.mp4 https://ia802603.us.archive.org/0/items/electricsheep-flock-244-72500-0/00244%3D73690%3D73529%3D73425.mp4 + mv B.mp4 ./examples/ +fi +if [ ! -f ./examples/C.mp4 ]; then + wget -O C.mp4 https://ia800300.us.archive.org/6/items/electricsheep-flock-244-72500-8/00244%3D73008%3D72588%3D72531.mp4 + mv C.mp4 ./examples/ +fi +if [ ! -f ./examples/D.mp4 ]; then + wget -O D.mp4 https://ia800306.us.archive.org/34/items/electricsheep-flock-244-72500-6/00244%3D73236%3D72551%3D72705.mp4 + mv D.mp4 ./examples/ +fi +if [ ! -f ./examples/E.mp4 ]; then + wget -O E.mp4 https://ia600501.us.archive.org/16/items/electricsheep-flock-244-82500-4/00244%3D82524%3D82019%3D82016.mp4 + mv E.mp4 ./examples/ +fi + +./frameloom -i "./examples/A.mp4:./examples/B.mp4" -o "./examples/AB.mov" +./frameloom -i "./examples/A.mp4:./examples/B.mp4" -o "./examples/AB_realtime.mov" --realtime +./frameloom -i "./examples/A.mp4:./examples/B.mp4:./examples/C.mp4:./examples/D.mp4" -o "./examples/ABCD.mov" +./frameloom -i "./examples/B.mp4:./examples/C.mp4" -o "./examples/BCE_random.mov" --random \ No newline at end of file diff --git a/frameloom b/frameloom index 28cf2c9..083a38a 100755 --- a/frameloom +++ b/frameloom @@ -10,6 +10,7 @@ const fs = require('fs-extra') let TMPDIR = os.tmpdir() || '/tmp' let TMPPATH + /** * Shells out to execute a command with async/await. * Async wrapper to exec module. @@ -70,6 +71,7 @@ function shuffle (a) { * Establishes a directory if none exists. **/ async function clear () { + let cmd = `rm -r "${TMPPATH}"` let exists try { @@ -81,9 +83,10 @@ async function clear () { if (exists) { console.log(`Clearing temp directory "${TMPPATH}"`) try { - await fs.rmdir(TMPPATH) + await exec(cmd) } catch (err) { //suppress error + console.dir(err) } } @@ -94,6 +97,8 @@ async function clear () { console.error(err) } } + + return true } /** * Exports all frames from video. Appends number to the string @@ -124,7 +129,7 @@ async function frames (video, order, avconv) { return process.exit(3) } - return path.join(TMPPATH, `export_${order}`) + return path.join(TMPPATH, `export-%05d_${order}`) } /** * Re-arranges the frames into the order specified in the pattern. @@ -273,7 +278,7 @@ async function standardSort (list, pattern, realtime) { console.log(`Renaming ${list[i]} -> ${newName}`) try { - await fs.move(oldPath, newPath, { overwrite: true }) + await fs.move(oldPath, newPath) newList.push(newName) frameCount++ } catch (err) { @@ -330,7 +335,7 @@ async function randomSort (list, pattern, realtime) { console.log(`Renaming ${list[i]} -> ${newName}`) try { - await fs.move(oldPath, newPath, { overwrite : true }) + await fs.move(oldPath, newPath) newList.push(newName) } catch (err) { console.error(err) @@ -354,7 +359,8 @@ async function render (output, avconv) { let h264 = `-vcodec libx264 -g 1 -crf 25 -pix_fmt yuv420p` let prores = `-c:v prores_ks -profile:v 3` let format = (output.indexOf('.mov') !== -1) ? prores : h264 - const cmd = `${exe} -r 24 -f image2 -s ${resolution} -i ${frames} ${format} -y ${output}` + let framerate = `24` + const cmd = `${exe} -r ${framerate} -f image2 -s ${resolution} -i ${frames} ${format} -y ${output}` console.log(`Exporting video ${output}`) console.log(cmd) @@ -442,8 +448,6 @@ async function main (arg) { return process.exit(5) } - await delay(2000) - try { await render(output, avconv) } catch (err) { @@ -452,7 +456,7 @@ async function main (arg) { } try { - //await clear() + await clear() } catch (err) { console.error(err) return process.exit(7)