Skip to content

Instantly share code, notes, and snippets.

@gregtemp
Created July 18, 2013 18:19
Show Gist options
  • Save gregtemp/6031630 to your computer and use it in GitHub Desktop.
Save gregtemp/6031630 to your computer and use it in GitHub Desktop.
Video delay - Processing 2.0 - some dood on stack overflow made this for me when I posted my version that didn't work.
import processing.video.*;
Capture cam;
PImage[] buffer;
int w = 320;
int h = 240;
int nFrames = 30;
int iWrite = 0, iRead = 1;
void setup(){
size(w, h);
cam = new Capture(this, w, h);
cam.start();
buffer = new PImage[nFrames];
}
void draw() {
if(cam.available()) {
cam.read();
buffer[iWrite] = cam.get();
if(buffer[iRead] != null){
image(buffer[iRead], 0, 0);
}
iWrite++;
iRead++;
if(iRead >= nFrames-1){
iRead = 0;
}
if(iWrite >= nFrames-1){
iWrite = 0;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment