0

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

guitarflow
  • 2,930
  • 25
  • 38

2 Answers2

1

You are going in the right direction. You need to calculate the time offset and convert it to a QTTime. QTMovie's time is zero-based.

NSTimeInterval timeInterval = timeOffset;

[_movie setCurrentTime:QTMakeTime((long long)(timeInterval * (double)movieTimeScale), movieTimeScale)];

movieTimeScale usually can be a constant, like 600. Alternatively you can get it from the movie:

long movieTimeScale = [_movie currentTime].timeScale;

Frame rate is irrelevant here.

Davyd Geyl
  • 4,578
  • 1
  • 28
  • 35
  • Hey Davyd. ok. Will check into it. In your above code, what is `timeOffset`?? Understand, that the framerate is irrelevant, the problem is just that I get values in the format `hh:mm:ss.ff` from the MIDI interface and I need to work with that. So I need a way to convert between those two. Any ideas?? Thanks in advance!! – guitarflow Dec 12 '11 at 21:54
  • Convert the value to seconds: `NSTimeInterval timeOffset = (NSTimeInterval)hh * 3600.0 + (NSTimeInterval)mm * 60.0 + (NSTimeInterval)ss + (NSTimeInterval)ff;` – Davyd Geyl Dec 13 '11 at 00:14
  • `ff` is a value in a range from `0 - 29` in the above mentioned 29.97 fps case. I don't think I can use your "formula" to achieve a correct conversion, dont't you think? I could write the `ff`as a fraction, so for 10 frames for example `ff = 10 / 29.97;` Will try that and get back to you. Thanks for your help!! – guitarflow Dec 13 '11 at 15:49
  • Sure, you need to convert number of frames to seconds, so you a right, divide it to the number of frames per second. – Davyd Geyl Dec 13 '11 at 22:11
  • Hey David, me again. I tried it and it did not work. Although the values have been pretty close, they have still been drifting. Means if I am on a certain timecode address and I then locate to that exact time with the function, the movie always goes a few frames backwards. The number of offset frames increases the further I go into the movie. I have been trying around with this for hours ... I hope you can give me a hint how to work with frames and timescale. Thanks in advance!! – guitarflow Dec 13 '11 at 22:51
  • Hi guitarflow. It is hard to tell what is wrong without seeing actual code and movie. Just keep in mind and double check the following moments. When you use `setCurrentTime` you need to pass seconds, not frames. Quicktime will find the closest frame. Im not entirely sure what is `01:00:00:10`? One day and one second? Or one hour and tenth of a second? Or one hour and 10 frames? In video editing software the number after the decimal separator usually means frames, not hundredth of seconds. Make sure what exactly you numbers mean. – Davyd Geyl Dec 13 '11 at 23:12
  • One more thing. FPS is an average number. Actual frames are not necessarily of the same duration. You can have a single frame that lasts for seconds, like a poster or static picture. Try to use 'stepForward' and 'stepBackward' to operate single frames. I hope this helps. – Davyd Geyl Dec 13 '11 at 23:14
1

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 )];
guitarflow
  • 2,930
  • 25
  • 38
  • Hey @guitarflow. Would you mind providing more information on what you did? I need to figure out the timecode of a Quicktime, and I'm starting to realize that the application needs to be in 32-bit to run. How did you resolve your issue? I've been going crazy the last few days trying to get a simple timecode track off a quicktime. – russellaugust Aug 23 '12 at 01:17
  • You will need to use the old QT API, which doesn't run in 64 bit. Maybe you should try to see what AVFoundation offers. QuickTime is 20 years old, so it's understandable it'n not working in 64 bit. It's actually fascinating enough that it is still working so well!! – guitarflow Aug 23 '12 at 11:05