Processing.org and GSVideo: capture, frame difference and dump
This file contains 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
import codeanticode.gsvideo.*; | |
int numPixels; | |
int[] previousFrame; | |
GSCapture video; | |
GSMovieMaker mm; | |
int fps = 15; | |
void setup() { | |
size(640, 480); | |
frameRate(fps); | |
video = new GSCapture(this, width, height); | |
video.play(); | |
numPixels = video.width * video.height; | |
previousFrame = new int[numPixels]; | |
loadPixels(); | |
mm = new GSMovieMaker(this, width, height, "drawing.ogg", GSMovieMaker.THEORA, GSMovieMaker.MEDIUM, fps); | |
mm.setQueueSize(50, 10); | |
mm.start(); | |
} | |
void draw() { | |
if (video.available()) { | |
video.read(); | |
video.loadPixels(); | |
int movementSum = 0; | |
for (int i = 0; i < numPixels; i++) { | |
color currColor = video.pixels[i]; | |
color prevColor = previousFrame[i]; | |
int currR = (currColor >> 16) & 0xFF; | |
int currG = (currColor >> 8) & 0xFF; | |
int currB = currColor & 0xFF; | |
int prevR = (prevColor >> 16) & 0xFF; | |
int prevG = (prevColor >> 8) & 0xFF; | |
int prevB = prevColor & 0xFF; | |
int diffR = abs(currR - prevR); | |
int diffG = abs(currG - prevG); | |
int diffB = abs(currB - prevB); | |
movementSum += diffR + diffG + diffB; | |
pixels[i] = 0xff000000 | (diffR << 16) | (diffG << 8) | diffB; | |
previousFrame[i] = currColor; | |
if (movementSum > 0) { | |
updatePixels(); | |
mm.addFrame(pixels); | |
} | |
} | |
} | |
void keyPressed() { | |
if (key == ' ') { | |
mm.finish(); | |
exit(); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment