From 37ad2d049b497379a92ba3b032e7d9c6fe65ade6 Mon Sep 17 00:00:00 2001 From: mattmcw Date: Sun, 9 May 2021 13:05:38 -0400 Subject: [PATCH] Add basic processing example --- processing/example-sketch.sh | 10 +++++ processing/example-sketch/example-sketch.pde | 46 ++++++++++++++++++++ processing/processing.sh | 42 ++++++++++++++++++ 3 files changed, 98 insertions(+) create mode 100644 processing/example-sketch.sh create mode 100644 processing/example-sketch/example-sketch.pde create mode 100644 processing/processing.sh diff --git a/processing/example-sketch.sh b/processing/example-sketch.sh new file mode 100644 index 0000000..a811076 --- /dev/null +++ b/processing/example-sketch.sh @@ -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 \ + "${@}" \ No newline at end of file diff --git a/processing/example-sketch/example-sketch.pde b/processing/example-sketch/example-sketch.pde new file mode 100644 index 0000000..8389f3e --- /dev/null +++ b/processing/example-sketch/example-sketch.pde @@ -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(); +} \ No newline at end of file diff --git a/processing/processing.sh b/processing/processing.sh new file mode 100644 index 0000000..51586de --- /dev/null +++ b/processing/processing.sh @@ -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="${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