views:

401

answers:

1

I'm looking for a function that converts an integer value in frames to NTSC Drop Frame Timecode (hh:mm:ss.ff).

I'm using Delphi, but could be in any language.

Thanks

+3  A: 
function FramesToNTSCDropFrameCode(Frames:Integer;FramesPerSecond:Double):string;
var
  iTH, iTM, iTS, iTF : word;
  MinCount, MFrameCount : word;
begin
  DivMod( Frames, Trunc(SecsPerMin * FramesPerSecond), MinCount, MFrameCount );
  DivMod( MinCount, MinsPerHour, iTH, iTM );
  DivMod( MFrameCount, Trunc(FramesPerSecond), ITS, ITF );
  Result := Format('%.2d:%.2d:%.2d.%.2d',[iTH,iTM,iTS,iTF]);
end;

You will need to copy the DivMod routine from the SysUtils unit, and also include the sysUtils unit in whatever implements this function.

skamradt
+1, but IMO the format string should be '%.2d:%.2d:%.2d.%.2d' - removing the first three digits because they are not necessary, and adding the last one because otherwise single digit frames in a second are not formatted correctly.
mghie
Corrected, Originally I had left the last digit open for formatting to handle larger framespersecond... which in retrospect is unlikely.
skamradt
NTSC Drop Frame Timecode is 29.97 fps, but you code only accepts fps as integer, so I don't think it's right.
Erick Sasse
Updated and corrected. I thought NTSC drop frame timecode was 30 fps.
skamradt
It's still not right, because drop frame requires you to drop 2 frames per minute except the tenth minute.
Erick Sasse