We closed this forum 18 June 2010. It has served us well since 2005 as the ALPHA forum did before it from 2002 to 2005. New discussions are ongoing at the new URL http://forum.processing.org. You'll need to sign up and get a new user account. We're sorry about that inconvenience, but we think it's better in the long run. The content on this forum will remain online.
Page Index Toggle Pages: 1
Video Delay (Read 255 times)
Video Delay
Feb 26th, 2009, 1:48am
 
Hi all.  I am trying to delay my video capture by 10 seconds, but I'm not sure how to go about it.  I read something about saving the video images into an array and then start playing it after capturing the appropriate amount of frames, but I'm not sure how I would do that.  Help would be appreciated!

Thanks!  
Re: Video Delay
Reply #1 - Feb 26th, 2009, 12:11pm
 
hi,

i used delays before, just like you say, keep an array of images, then keep a writing and reading head offsetting each other by n frames. hope this gets you started:


// video delay, andré sier, 2008
// mouseX controls the delay amount

import processing.video.*;
PImage frames[];
Capture cam;
int time = 60*30;//1min@30pfs frames
int timehead, timeoffset, timeread;

void setup(){
 size(640,240);
 frameRate(30);
 frames = new PImage[time];
 for(int i=0;i<frames.length;i++){
   frames[i] = new PImage(width/2,height);
 }
 cam = new Capture(this,width/2,height,30);
}

void draw(){

 if(cam.available()){
   cam.read();
   timehead = (timehead + 1) % frames.length;
   frames[timehead].copy(cam,0,0,320,240,0,0,320,240);
   timeoffset = (int)map(mouseX,0,width,time,0);
   timeread = (timehead + timeoffset) % frames.length;

   image(frames[timehead],0,0,320,240);
   image(frames[timeread],320,0,320,240);
 }

}

Re: Video Delay
Reply #2 - Feb 26th, 2009, 5:39pm
 
Works perfectly! Thank you.

I was wondering, running this code seems to take up a lot of memory.  How do you suppose we could lower the mem consumption?
Re: Video Delay
Reply #3 - Feb 26th, 2009, 6:43pm
 
Ya think?

You're buffering 10 seconds worth of UNCOMPRESSED video frames.  Of course it takes a lot of memory.

I don't know whether the particulars of your application permit it, but can you avoid the buffering by using Processing's time functions to determine whether 10 seconds have passed, and not start playing the video until then?  A little "if(millis() > 10000) { play_video(); }" or whatever?
Re: Video Delay
Reply #4 - Feb 26th, 2009, 6:53pm
 
hey sofunk, nice that it works for you.

1min video@30fps is 1800frames, and i'm using 320x240 pixels, which may be a lot (138240000pix).

if you need a long video buffer with lower memory, you can lower the ram by lowering the number of frames you store (the time variable in the sketch), by lowering the dimensions of each stored frame, and by not grabbing every frame in the sequence, something like this comes to mind

if (frameCount%5==0) {
   timehead = (timehead + 1) % frames.length;
   frames[timehead].copy(cam,0,0,320,240,0,0,320,240);
}

and does anyone know of a faster, more effective PImage.copy() function?
i used a skip and round pixels in some works, works faster, but image is not so good, looses some details..
Page Index Toggle Pages: 1