Add basic processing example

This commit is contained in:
Matt McWilliams 2021-05-09 13:05:38 -04:00
parent 52a5de45e6
commit 37ad2d049b
3 changed files with 98 additions and 0 deletions

View File

@ -0,0 +1,10 @@
#!/bin/bash
#https://github.com/processing/processing/wiki/Command-Line
# processing-java requires the full path of the sketch
SKETCH=`realpath ./processing/example-sketch`
echo "$SKETCH"
# pass all arguments on bash script example-sketch.pde sketch
processing-java --sketch="${SKETCH}" --run \
"${@}"

View File

@ -0,0 +1,46 @@
//Input should be .jpg or .png
String input = "";
String output = "";
PImage inputImage;
PGraphics canvas;
void setup() {
if (args != null) {
if (args.length > 0 && args[0] != null) {
input = args[0];
} else {
println("No input argument provided");
exit();
}
if (args.length > 1 && args[1] != null) {
output = args[1];
} else {
exit();
}
} else {
println("No arguments provided");
exit();
}
//don't show the processing window
surface.setVisible(false);
//only draw script once
noLoop();
//use psuedo-random generator
randomSeed(50);
}
void draw () {
inputImage = loadImage(input);
canvas = createGraphics(inputImage.width, inputImage.height);
canvas.image(inputImage, 0, 0);
/************************
* Do cool things here!!!
************************/
canvas.save(output);
exit();
}

42
processing/processing.sh Normal file
View File

@ -0,0 +1,42 @@
#!/bin/bash -e
#####################################################
#
# This script will export all frames of a video and
# then loop over them by running a processing sketch
# on each one. The example provided "example-sketch"
# will
#
# Usage: bash processing/processing.sh <input video> <output video>
#
#####################################################
INPUT="${1}"
OUTPUT="${2}"
# Check if output file extension is .mov
if [[ "${OUTPUT}" != *".mov" ]]; then
echo "Please use an .mov extension on your output file argument"
exit 1
fi
mkdir -p frames
mkdir -p processing-frames
ffmpeg -i "${INPUT}" frames/frame-%06d.png
FRAMES=frames/*.png
for frame in ${FRAMES}; do
echo "Processing $frame with example-sketch..."
# Run the processing sketch on every frame
bash processing/example-sketch.sh "${frame}" "processing-${frame}"
done
ffmpeg -f image2 -i processing-frames/frame-%06d.png -c:v prores_ks -profile:v 3 "${OUTPUT}"
# clean up frames folder
rm -rf frames
rm -rf processing-frames