• Open Menu Close Menu
  • Apple
  • Shopping Bag
  • Apple
  • Mac
  • iPad
  • iPhone
  • Watch
  • TV
  • Music
  • Support
  • Search apple.com
  • Shopping Bag

Lists

Open Menu Close Menu
  • Terms and Conditions
  • Lists hosted on this site
  • Email the Postmaster
  • Tips for posting to public mailing lists
Re: NSMovieView: Get frame counter
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: NSMovieView: Get frame counter


  • Subject: Re: NSMovieView: Get frame counter
  • From: Jens Bauer <email@hidden>
  • Date: Sun, 15 Jun 2003 23:20:09 +0200

Hi Douglas,

Indeed, this is good info! :)
-I already begun looking inside the QuickTime API, before you replied, however, I only found out about the movie timing, partly by experimenting as well.

For the interested people, here's a snippet for converting the frame number into SMPTE format:

// Get the current frame (method of NSMovie subclass, eg. MyMovie):

- (float)currentFrame
{
Movie qtmovie;
TimeRecord tr;

qtmovie = (Movie) [self QTMovie];
if(qtmovie)
{
tr.value.hi = 0;
tr.value.lo = 0;
tr.scale = 0;
tr.base = NULL;
GetMovieTime(qtmovie, &tr);
}
return((((tr.value.hi * (65536.0 * 65536.0)) + tr.value.lo) * [self framesPerSec]) / tr.scale);
}
// There are 2 ways to get the time from GetMovieTime: the result of the function is an integer, but you can also get an unsigned wide, which I am doing, since I don't like limiting my applications too much. The above method can be shortened to this, if you really want to:
// -Ofcourse, you may find it neater to rewrite the currentFrame method, so that it returns the movie position in seconds; it is a float anyway, then you don't have to set up framesPerSec prior to calling this method.
// return(((tr.value.hi * (65536.0 * 65536.0)) + tr.value.lo) / tr.scale);


- (long)currentFrame
{
return((GetMovieTime([self QTMovie], NULL) * [self framesPerSec]) / 600);
}
// I do not recommend this optimization, though, the scale value is hardcoded, there's no testing for if the movie is NULL, and the movie is limited to "only" 497 hours. ;)
-Imagine that the movie is actually 500 hours, and you watched 497 hours - wouldn't it be a shame if you cannot watch the last 3 hours ? :D


And here's the snippet for the SMPTE-time formatting:
- (NSString *)stringFromFrame:(long)frameCount
{
long h;
long m;
long s;
long f;
long frames_per_sec;
long inv;

inv = frameCount < 0;
if(inv)
{
frameCount = -frameCount;
}
frames_per_sec = [self framesPerSec];

f = frameCount % frames_per_sec;
frameCount /= frames_per_sec;
s = frameCount % 60;
m = (frameCount / 60) % 60;
h = frameCount / (60 * 60);

return([NSString stringWithFormat:@"%sd:d:d.d", inv ? "-" : "", h, m, s, f]);
}

If you want PAL, set framesPerSec to 25, if you want NTSC, set it to 30. :)

Note: I spent some time on making it possible to return a string like @"-00:00:00.02", due to that you might want to use time relative to a mark in the movie (eg. starting point). I remember making NSTextFields showing the time-codes 'right aligned'. ;)


On Sunday, Jun 15, 2003, at 15:18 Europe/Copenhagen, Douglas A. Welton wrote:

How do I get the current frame, the selection start and selection end
from a NSMovie/NSMovieView ?

Cocoa, per se, isn't going to do this for you. You're going to have to get
native with the appropriate QuickTime calls.

OK, I'll create a wrapper-class for the most interesting functions, and when I'm done, I'll put it up on objc-source.org. I'll let you guys know if/when I put it up. ;)

Use the -QTMovie selector from NSMovie to get the opaque data structure that
points to actual QuickTime Movie (defined as type "Movie").

You can then use functions like GetMovieDuration() and GetMovieTimeScale()
to do the computations you need. Check out the QuickTime sample code for
QTTimeCode. This example will show you almost everything you need.

I'd also like to get the selection range. It doesn't appear to me how
this is possible.

Finally, I'd like to grab a frame, modify it, and write it back.
I know that QuickTime player can do this, you can even paste TIFF
images into the movie-player, so this must be possible from my own
player as well. ;)

As for editing functions, getting the selection start/stop points or
inserting next frames or movies, check out the "Editing Movies" section in
the QuickTime 6 API Reference. All the functions you will need will be
there.

You may want to take a look at the SimpleCocoaMovie sample code, and the
QuickTime Sample code for CocoaCreateMovie, CocoaVideoFrameToNSImage, and
CocoaVideoFrameToGWorld.

This indeed sounds interesting, that might be exactly what I need! :)

If you need more sample code, contact me off-list.

Thanks, Douglas, this is very helpful. For the record, I also found something here:
/Developer/Examples/InterfaceBuilder/bMoviePalette/
-This also has a TimeFormatter, but this time formatter does not display the frameCount.

Thanks again! :)


Love,
Jens
_______________________________________________
cocoa-dev mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/cocoa-dev
Do not post admin requests to the list. They will be ignored.

References: 
 >Re: NSMovieView: Get frame counter (From: "Douglas A. Welton" <email@hidden>)

  • Prev by Date: Registering File Types or Icons
  • Next by Date: Re: Finding text that the user entered
  • Previous by thread: Re: NSMovieView: Get frame counter
  • Next by thread: Scripts for PackageMaker
  • Index(es):
    • Date
    • Thread