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 playback with growing delay... (Read 599 times)
Video playback with growing delay...
Feb 27th, 2008, 2:20pm
 
I'm working on a project where I'm attempting to show a live video feed which slowly becomes more and more delayed.  

I've never used video input with processing... but I believe what I need to do to achieve this is add 1/25 of a second (or 1 frame) every variable minute.

Would anyone be able to help me out with how to do this?  I don't mind if the frame is a repeated frame or a black screen.  Is there a way of buffering the video and then making these modifacations?

Cheers for any help!

Nick
Re: Video playback with growing delay...
Reply #1 - Mar 1st, 2008, 1:04am
 
Nick,

You could use the code I posted here:

http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Video;action=display;num=1159143757

And modify the addFrame method so that once per second it will only advance the inputFrame (and not the outputFrame) index variable.  I believe that would do what you need.  Also, you'd want to have inputFrame start at 1 instead of the buffer size minus 1.  That way the input and output frames start with only a single frame delay between them.

If that's not clear I can repost that code with the changes I'm describing.

One more item to note is that you'll need to have some kind of limit on the delay or the difference between the two frame indexes will eventually "wrap" around and the delay will suddenly disappear.  This means you'll have to have a maximum delay size rather than having it grow forever (which would require an infinite amount of RAM anyway).

Hope this helps!

-Ben
Re: Video playback with growing delay...
Reply #2 - Mar 1st, 2008, 3:38pm
 
Thanks!  I'm at work now, so I'm gonna give it a go later when I get home.  I'll give it a shot myself, but I'm sure I'll come crawling asking for that modified code, lol.

With setting the maximum delay... I was wanting to run the program over 4 days dropping 1 frame every 1-2 minutes, so ending up at the end of the 4 days with about a 2 minute delay on the video.  Would I need to set up something to start dumping in the ram after awhile?  It'll be running on a dedicated machine and I can pump it full of RAM.

Thanks again for your help!
Re: Video playback with growing delay...
Reply #3 - Mar 1st, 2008, 4:47pm
 
heh, yep.  I've got myself just tangled in code over here...
Re: Video playback with growing delay...
Reply #4 - Mar 5th, 2008, 7:39pm
 
Nick,

Here's a modified version of the VideoBuffer class.  The "addFrame" method now takes a boolean which will "pause" the output frame.  So, if you pass in "true" then the output will lag behind the input by a single frame.  If you pass in "false" then the delay won't change.

So, whenever you want to "drop" a frame just pass "true" to the addFrame method.


Code:

import processing.video.*;

VideoBuffer vb;
Movie myMovie;
int c = 0;

void setup()
{
size(300,300, P3D);
myMovie = new Movie(this, "station.mov");
vb = new VideoBuffer(3000, 160, 120);
myMovie.loop();
}

void movieEvent(Movie m)
{
m.read();

c++;
if(c == 30)
{
c = 0;
}

// drop one frame every 30 frames.
vb.addFrame( m, (c == 0) );
}

void draw()
{
image( vb.getFrame(), 100, 100 );
image( myMovie, 0, 0 );
}


class VideoBuffer
{
PImage[] buffer;

int inputFrame = 0;
int outputFrame = 0;
int frameWidth = 0;
int frameHeight = 0;

/*
parameters:

frames - the number of frames in the buffer (fps * duration)
width - the width of the video
height - the height of the video
*/
VideoBuffer( int frames, int width, int height )
{
buffer = new PImage[frames];
for(int i = 0; i < frames; i++)
{
this.buffer[i] = new PImage(width, height);
}
this.inputFrame = 1;
this.outputFrame = 0;
this.frameWidth = width;
this.frameHeight = height;
}

// return the current "playback" frame.
PImage getFrame()
{
return this.buffer[this.outputFrame];
}

// Add a new frame to the buffer.
void addFrame( PImage frame, boolean pauseOutput )
{
// copy the new frame into the buffer.
System.arraycopy(frame.pixels, 0, this.buffer[this.inputFrame].pixels, 0, this.frameWidth * this.frameHeight);

// advance the input and output indexes
this.inputFrame++;

if(!pauseOutput)
{
this.outputFrame++;
}

// wrap the values..
if(this.inputFrame >= this.buffer.length)
{
this.inputFrame = 0;
}
if(this.outputFrame >= this.buffer.length)
{
this.outputFrame = 0;
}
}
}
Page Index Toggle Pages: 1