Converting a number of frames into smpte timecode format
807589Aug 2 2008 — edited Aug 2 2008Hi all,
I've been thinking about this for a while but don't think I've come up with a good solution just yet. So I wanted to see if anybody could show me a swift and efficient way.
The problem:
A given number of frames is to be translated into the corresponding smpte timecode. A single frame lasts 1/25th of a second.
So, for example: the timecode 01:30:12:24 (hh:mm:ss:ff) translates to 24+(12*25)+(30*60*25)+(1*60*60*25) = 135324 frames. As you see it's very simple to break it down into frames. But how would you reverse the procedure?
I have two ideas, the first was to subtract from the sum of frames until i have broken it down completely. That seems to involve quite a complicated if structure but I guess it's a reasonably fast way. Next I had the idea that I could iterate through the whole lot and on every 25th iteration step up the seconds variable, and when it reached 60 step up the minute variable and so forth. I do have doubts about the efficiency of that particular code though as this will be a very frequent task in my application.
My guess is the best and only real option is to go with the former idea, but I want to make sure I am not missing a super simple and elegant way of doing this.
Thanks,
Johan