Hi all.
I've got a quicktime movie (.dv clip at 720x480i) and i want to access it frame by frame (preferrably, field by field). I have some basic processing code to step through it field by field. The below code works... somewhat. It sometimes repeats frames, since it's being accessed as time i believe.
Is there a way to access a quicktime movie in frames rather than in time? ie, grab frame number 60, rather than time of 2.0...
Quote:
/*
* fieldstepper
*/
import processing.video.*;
Movie myMovie;
float pos = 0.0;
int field = 0;
void setup()
{
size(720, 480);
background(0);
myMovie = new Movie(this, "/Users/me/testfile.dv");
frameRate( 20 );
// start at the beginning
myMovie.jump( 0 );
myMovie.read();
}
// this isn't called anymore, but just in case
void movieEvent(Movie myMovie) {
myMovie.read();
}
void draw()
{
fill( 255, 0, 0 );
rect( 0, 0, width/2, height/2 );
// first, plop down the movie
image(myMovie, 0,0);
// and draw the right field
loadPixels();
int idx1 = ((field+1)&0x01) * myMovie.width;
int idx2 = ((field+0)&0x01) * myMovie.width;
for( int y=0 ; y<myMovie.height ; y+=2 ) {
int p1 = idx1;
int p2 = idx2;
for( int x=0 ; x<myMovie.width ; x++ ) {
pixels[ p2++ ] = pixels[ p1++ ];
}
idx1 = idx1 + myMovie.width + myMovie.width;
idx2 = idx2 + myMovie.width + myMovie.width;
}
updatePixels();
}
void mousePressed()
{
if( mouseButton == LEFT ) { // advance to next field
field ++;
if( field > 1 ) {
pos = constrain( pos + (1.0/29.97), 0, myMovie.duration() );
myMovie.jump( pos );
myMovie.read();
field = 0;
}
} else {
field --;
if( field < 0 ) { // go back to the previous one
pos = constrain( pos - (1.0/29.97), 0, myMovie.duration() );
myMovie.jump( pos );
myMovie.read();
field = 1;
}
}
println( "POS: " + pos + " " + field + " / " + myMovie.duration() );
}