tags:

views:

44

answers:

1

I want to export every frame in a *.mov-Movie-File, so I do this:

GoToBeginningOfMovie(movie);
TimeValue startPoint = 0;
long gnitFrames = 0;
while (startPoint >= 0) {
    GetMovieNextInterestingTime(movie, nextTimeStep, 0, &whichMediaType, startPoint, 0, &startPoint, NULL);
    gnitFrames++;
}

the problem is, the count of gnitFrames is different (many more) than when I call this:

Track track = GetMovieIndTrack(movie, 1);
Media media = GetTrackMedia(track);
OSType mediatype;
MediaHandler mediahandler = GetMediaHandler(media);
GetMediaHandlerDescription(media, &mediatype, nil, nil);
MediaGetName(mediahandler, medianame, 0, nil);
long nsamples = GetMediaSampleCount(media);

nsamples gives me the correct frame-count. So now my question: how can I do that to get to every frame in a movie just once? (When I export the frame now after I called GetNextInterestingTime, a frame is exported multiple times, sometimes even 25 times)
My operating system is Windows XP.

+1  A: 

Using nextTimeStep might be problematic as a timestep does not necessarily have to match a (video) media sample causing GetMovieNextInterestingTime() to return superfluous time stamps.

If all you want to do is to count / locate all frames in a video media, try using nextTimeMediaSample along with GetMediaNextInterestingDisplayTime() on the video Media like this:

...
TimeValue64  start           = 0;
TimeValue64  sample_time     = 0;
TimeValue64  sample_duration = -1;
int frames = 0;
while( sample_time != -1 ) {

    GetMediaNextInterestingDisplayTime( media, nextTimeMediaSample | nextTimeEdgeOK, start, fixed1, &sample_time, &sample_duration );
    if( sample_time != -1 ) {
        ++frames;
    }
    ...
    start += sample_duration;
}
...

Caveat:

According to the Q&A article below this approach is not supposed to work out for f.e. MPEG but for many other formats it works like a charm in my experience.

Technical Q&A QTMTB54: How do I count the frames in an MPEG movie?

Bjoern
this doesn't work for me, because I work with MPEG a lot and when I use this to count the frames for example, it seems that it causes a infinite loop... :(
Berschi
Have you tried passing `nextTimeStep` instead of `nextTimeMediaSample | nextTimeEdgeOK` while still using `GetMediaNextInterestingDisplayTime()`? This way you might be able to honor the fact that MPEG allows for multiple frames to be contained in a single media sample while being able to ignore times associated to Medias your not interested in...
Bjoern