Created
August 3, 2015 06:10
-
-
Save anonymous/c3902745890847f8c0e1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* ASDFPixelSort for video frames v1.0 | |
Original ASDFPixelSort by Kim Asendorf <http://kimasendorf.com> | |
https://github.com/kimasendorf/ASDFPixelSort | |
Fork by dx <http://dequis.org> and chinatsu <http://360nosco.pe> | |
Randomization modifications by Dan-O | |
-- Usage: | |
1. Split a video into a series of pictures with ffmpeg: | |
$ ffmpeg -i "input.mov" -an -f image2 "frame_%06d.png" | |
2. Change `String basedir` in this script to point to where the images are located. | |
3. Tweak things, that's what's most fun, isn't it? | |
-- Notes: | |
When joining the images back into video, you'll probably want to know what the framerate of the original video is. | |
Example command with reasonable quality: | |
$ ffmpeg -f image2 -r ntsc -i "frame_%06d.png" -c:v libx264 -preset slow "frames.mkv" | |
*/ | |
// Main configuration | |
String basedir = "/volumes/Kamala/Tech Tests/Process/RAW-JPG-Pixelsort/"; // Specify the directory in which the frames are located. Use forward slashes. | |
String fileext = ".jpg"; // Change to the format your images are in. | |
int resumeprocess = 0; // If you wish to resume a previously stopped process, change this value. | |
int mode = 1; // MODE: 0 = black, 1 = bright, 2 = white | |
int blackValue = -10000000; | |
int brightnessValue = 80; | |
int whiteValue = -6000000; | |
// ------- | |
public static int randInt(-1,1) { | |
Random rand = new Random(); | |
int randomNum = rand.nextInt((max - min) + 1) + min; | |
return randomNum; | |
} | |
PImage img; | |
PImage initimg; | |
String[] filenames; | |
int row = 0; | |
int column = 0; | |
int i = 0; | |
java.io.File folder = new java.io.File(dataPath(basedir)); | |
java.io.FilenameFilter extfilter = new java.io.FilenameFilter() { | |
boolean accept(File dir, String name) { | |
return name.toLowerCase().endsWith(fileext); | |
} | |
}; | |
void setup() { | |
frameCount = 0; | |
if (resumeprocess > 0) {frameCount = resumeprocess - 1;} | |
filenames = folder.list(extfilter); | |
initimg = loadImage(basedir+"/"+filenames[0]); | |
size(initimg.width, initimg.height); // Takes the size of the first image in the folder. | |
import java.util.Random; | |
} | |
void draw() { | |
brightnessValue = brightnessValue + randInt; | |
if (i +1 > filenames.length) {println("Uh.. Done!"); System.exit(0);} | |
row = 0; | |
column = 0; | |
img = loadImage(basedir+"/"+filenames[i]); | |
image(img,0,0); | |
while(column < width-1) { | |
img.loadPixels(); | |
sortColumn(); | |
column++; | |
img.updatePixels(); | |
} | |
while(row < height-1) { | |
img.loadPixels(); | |
sortRow(); | |
row++; | |
img.updatePixels(); | |
} | |
image(img,0,0); | |
saveFrame(basedir+"/out/"+filenames[i]); | |
println("Frames processed: "+frameCount+"/"+filenames.length); | |
println("Brightness: "+brightnessValue); | |
i++; | |
} | |
/* Everything below that is the actual image processing script and irrelevant to the problem |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment