Search code examples
quicktimeqtkit

Is it possible to create a QTTimeRange from two frame numbers?


All QTKit examples use seconds for making ranges. I, unfortunately, have frame numbers and need to be frame accurate. I suppose I could multiply up by the frame rate if I could figure out how to get that out of my movie.


Solution

  • You should be able to calculate the frame rate of a given video media by querying the following mediaAttributes of a QTMedia:

    • QTMediaDurationAttribute

    • QTMediaSampleCountAttribute

    (they are described in the QTKit docs here)

    and use the following formula for calculation:

    QTTime    duration     = ... // value get from mediaAttribute 
    NSNumber  sample_count = ... // value get from mediaAttribute
    double    fps = (sample_count.longValue * duration.timeScale) / duration.timeValue;
    

    Disclaimer:

    Note that I have not tried if this works, but that it is how I expect it to work based on my experience the QuickTime C APIs and the QuickTime File Format.

    Good Luck!