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.
IndexProgramming Questions & HelpVideo Capture,  Movie Playback,  Vision Libraries › how to jump to a specific frame # in a .mov
Page Index Toggle Pages: 1
how to jump to a specific frame # in a .mov? (Read 605 times)
how to jump to a specific frame # in a .mov?
Nov 30th, 2008, 5:45am
 
Hi all, I'm totally new to Processing.
I'm looking to do something like this:
--read in a frame from a .mov file
--do some stuff with it
--move to the next frame

It seems to me that I should be using the Movie::jump() method, but, from what I can tell, this only allows you to skip around to different *times* in a movie, calculated in seconds. The problem with this is that different movies have different framerates, so what's .5 seconds in one movie may be a different # of frames than .5 seconds in another movie. (Also, at 30fps, what's one frame? .03333333333333333333333 seconds?)

Is there any way to determine the framerate in fps of a movie? How can I skip ahead by a discrete number of frames?

Thanks!
jonathan

Re: how to jump to a specific frame # in a .mov?
Reply #1 - Nov 30th, 2008, 6:38am
 
You can control the framerate of a Movie object.

Check the Example sketch "loop" for for movie, and try replacing it with this code (mouseX controls the framerate):

import processing.video.*;

Movie myMovie;
int x;
void setup() {
 size(640, 480, P2D);
 //size(640, 480, Ja);
 background(0);
 // Load and play the video in a loop
 myMovie = new Movie(this, "station.mov");
 myMovie.loop();
 x= 0;
}

void movieEvent(Movie myMovie) {
myMovie.frameRate(x);  // <---------------here
 myMovie.read();
}

void draw() {
 tint(255, 20);
 image(myMovie, width/2-myMovie.width/2, height/2-myMovie.height/2);
 float z =  map(mouseX, 0, height, 0,30);
 x = (int)z;
}

Re: how to jump to a specific frame # in a .mov?
Reply #2 - Nov 30th, 2008, 6:56am
 
OK, thanks, but does that allow me to jump to a specific frame? E.g. if I'm viewing frame 17 and I want to jump to frame 74, is that possible without knowing the fps of the movie?

jonathan
Re: how to jump to a specific frame # in a .mov?
Reply #3 - Nov 30th, 2008, 7:49am
 
Ugh, I'm looking through the forums, and I'm beginning to think that the answer is "no."
Here's a similar, unresolved thread: http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Video;action=display;num=1196870672


Re: how to jump to a specific frame # in a .mov?
Reply #4 - Nov 30th, 2008, 10:32am
 
Yes, I've looked at the source:

http://dev.processing.org/source/index.cgi/trunk/processing/video/src/processing/video/Movie.java?rev=5052&view=markup



so, jump() calls these two lines:

int scaledTime = (int) (where * movie.getTimeScale());
movie.setTimeValue(scaledTime);



It basically refers to the Movie class in quicktime:

http://developer.apple.com/Java/Reference/1.4/Java14API_QTJ/quicktime/std/movies/Movie.html


And there is absolutely no mention of any frame whatsoever.

I think that since scaledTime is a discrete value (integer instead of float), it is the closest thing to a frame.  

OTOH, I'm not sure if scaledTime is what you want, since there is also a reference to framerate.  If they "pad" a frame with several identical ones around a scaledTime, that may or may not qualify as a frame.  I'm not sufficiently versed in this field (digital video) so I can't comment on what consists a frame with any certainty from this point.  Depending on what your goal is, this could just boil down to semantics.

So there may be no simple hack, save extending the class with frame number estimation or treating scaledTime as a frame count.  Building that will save you from keeping track of the frame calculation in the long term.


for treating scaledTime as an equivalent of a frame, try:

class CustomMovieClass extends Movie{

 public void jumpToFrame(int scaledTime) {
   try {
     movie.setTimeValue(scaledTime);

   } catch (StdQTException e) {
     errorMessage("jumpToFrame", e);
   }
 }

}


...or you can simply grab the member directly.

since:

public quicktime.std.movies.Movie movie;

is public, you can:


//////////////////////


Movie movie = ....

...

movie.movie.setTimeValue(scaledTime);



///////////////////////





Sorry to be of little help.  Perhaps someone familiar with Quicktime can give us some insight around this problem.


Re: how to jump to a specific frame # in a .mov?
Reply #5 - Dec 1st, 2008, 2:45am
 
Hmm, right now my Java skills are not up to snuff to make your suggestions work. I'll get there soon, I'm sure, but at the moment I'm not sure how to either extend the Movie class or access the Quicktime class directly.

On the http://developer.apple.com/Java/Reference/1.4/Java14API_QTJ/quicktime/std/movies/Movie.html page you sent, the interesting methods seem to be getRate() or maybe getPreferredRate(). I'm assuming that those return the frames-per-second, in which case that'd be a solution.

Thanks for your help, and I'll probably understand it better in a few days after I bang my head against Java a little more!

Page Index Toggle Pages: 1