Video Delay/Buffer in Processing 2.0 -
i'm having ton of trouble making simple video delay in processing. looked around on internet , keep finding same bit of code , can't work @ all. when first tried it, did nothing (at all). here's modified version (which @ least seems load frames buffer), have no idea why doesn't work , i'm getting tired of pulling out hair. please... please, love of god, please point out stupid mistake i'm making here. , now, without further delay (hah, it?), code:
import processing.video.*; videobuffer vb; movie mymovie; capture cam; float seconds = 1; void setup() { size(320,240, p3d); framerate(30); string[] cameras = capture.list(); if (cameras.length == 0) { println("there no cameras available capture."); exit(); } else { println("available cameras:"); (int = 0; < cameras.length; i++) { println(cameras[i]); } cam = new capture(this, cameras[3]); cam.start(); } vb = new videobuffer(90, width, height); } void draw() { if (cam.available() == true) { cam.read(); vb.addframe(cam); } image(cam, 0, 0); image( vb.getframe(), 150, 0 ); } class videobuffer { pimage[] buffer; int inputframe = 0; int outputframe = 0; int framewidth = 0; int frameheight = 0; videobuffer( int frames, int vwidth, int vheight ) { buffer = new pimage[frames]; for(int = 0; < frames; i++) { this.buffer[i] = new pimage(vwidth, vheight); } this.inputframe = 0; this.outputframe = 1; this.framewidth = vwidth; this.frameheight = vheight; } // return current "playback" frame. pimage getframe() { return this.buffer[this.outputframe]; } // add new frame buffer. void addframe( pimage frame ) { // copy new frame buffer. this.buffer[this.inputframe] = frame; // advance input , output indexes this.inputframe++; this.outputframe++; println(this.inputframe + " " + this.outputframe); // wrap values.. if(this.inputframe >= this.buffer.length) { this.inputframe = 0; } if(this.outputframe >= this.buffer.length) { this.outputframe = 0; } } }
this works in processing 2.0.1.
import processing.video.*; capture cam; pimage[] buffer; int w = 640; int h = 360; int nframes = 60; 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; } } }
there problem inside addframe
-method. store reference pimage object, pixels overwritten time. have use buffer[inputframe] = frame.get()
instead of buffer[inputframe] = frame
. get()
method returns copy of image.
Comments
Post a Comment