/** * Copyright (c) 2008, Benjamin Eckel * * This program is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * http://creativecommons.org/licenses/LGPL/2.1/ * * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * Or see http://processing.datasingularity.com/gpl.txt */ import processing.video.*; int numPixels; int blockSize = 10; Movie myMovie; int myMovieColors[]; int[] previousFrame; int TOLERANCE = 50; boolean go = false; boolean record = false; int fake_frame_rate = 0; MovieMaker mm; void setup() { size(626, 352, P3D); myMovie = new Movie(this, "mvii.mov"); //put movie here mm = new MovieMaker(this,width,height,"output3.mov", 24, MovieMaker.RAW, MovieMaker.BEST); numPixels = width*height; myMovieColors = new int[numPixels]; previousFrame = new int[numPixels]; //myMovie.speed(0.5); myMovie.loop(); } void draw() { loadPixels(); if (!go) { for (int i = 0; i < numPixels; i++) { // For each pixel in the video frame... pixels[i] = myMovieColors[i]; } } else { int movementSum = 0; // Amount of movement in the frame for (int i = 0; i < numPixels; i++) { color currColor = myMovieColors[i]; color prevColor = previousFrame[i]; // Extract the red, green, and blue components from current pixel int currR = (currColor >> 16) & 0xFF; int currG = (currColor >> 8) & 0xFF; int currB = currColor & 0xFF; // Extract red, green, and blue components from previous pixel int prevR = (prevColor >> 16) & 0xFF; int prevG = (prevColor >> 8) & 0xFF; int prevB = prevColor & 0xFF; // Compute the difference of the red, green, and blue values int diffR = abs(currR - prevR); int diffG = abs(currG - prevG); int diffB = abs(currB - prevB); // Add these differences to the running tally movementSum = diffR + diffG + diffB; if (movementSum > TOLERANCE) { // Render the difference image to the screen pixels[i] = 0xff000000 | (prevR << 16) | (prevG << 8) | prevB; } // Save the current color into the 'previous' buffer previousFrame[i] = currColor; } } updatePixels(); delay(fake_frame_rate); if (record) mm.addFrame(); } /** * -Space bar grabs a refernece frame and turns on and off * the effect [the first refernece frame is all black so * you may want to hit this a few times to get a good one]. * -hit 'r' to start recording. * -hit 's' to stop recording. */ void keyPressed() { if (key == ' ') go = !go; else if (key == 'r') record = true; else if (key == 's') mm.finish(); } /** * Read new values from movie */ void movieEvent(Movie m) { if (m.available()) { m.read(); m.loadPixels(); myMovieColors = m.pixels; } }