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.
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?