Search code examples
cocoaquicktimeqtkit

QTTime to position a movie to a certain timecode


I want to position a QuickTime movie containing a timecode track to a user-defined TC position. I am well aware of the whole timeScale, timeValue stuff but I don't know what I am missing and hope you guys can give me a hint here!!

I want to give you an example with fixed values to make it easier to explain :

The movie has NTSC frame rate, which is 29.97 fps and is non-dropframe. The movie starts at 00:59:58:00 straight. The user enters the TC position 01:00:00:10 and I want to locate to that exact position.

The only option there is for a QTMovie is the setCurrentTime(QTTime time) function and I know that the time must be an absolute value in "units" from the beginning of the movie.

So, I would need to calculate an offset first. In order to do that, I need to use the QTTimeFromString function to first convert the two timecodes to QTTime structures.

And here is where my problem starts!! The QTTimeFromString function wants a string in the format "days:hours:minutes:seconds.timeValue/timescale"

Which value do I use for timeValue?? I read sth about frames * 100 and I myself thought of "mapping" the frame value into the 2997 timescale range by multiplying the frame value.

Neither way is working ... when I set the absolute value calculated by QTTimeDecrement to the clip using setCurrentTime I am always somewhere else where I want to be ....

I don't know what I'm doing wrong and I hope you guys can help me!! Thanks in advance


Solution

  • Just wanted to fill up the missing information.

    I practically calculated an absolute number of frames since the beginning of the movie. So, an offset of the incoming timecode and the timecode of the first movie frame.

    From the TC track the movie has, I get the timecode media handler off the movie. I can then get a TimeCodeDef structure. This stuct has a field called frameDuration and this is the value the absolute frame value needs to be multiplied with.

    Locating to all timecode positions works perfect now using :

    [movie setCurrentTime:QTMakeTime(absoluteNumFrames * tcDef.frameDuration, timeScale )];