将帧转换为NTSC丢帧时间码

时间:2009-05-15 15:52:59

标签: algorithm delphi language-agnostic video

我正在寻找一个将帧中的整数值转换为NTSC丢帧时间码(hh:mm:ss.ff)的函数。

我正在使用Delphi,但可以使用任何语言。

由于

2 个答案:

答案 0 :(得分:4)

这个问题有一个众所周知的经典解决方案 ......

  • 输入帧数nr相对于实际帧速率,对于NTSC,总是 30000/1001~ = 29.97帧/秒
  • 计算结果frame-nr是30fps的标称帧速率(并且每分钟都会显示+ 2帧跳跃,除非分钟可以被10分割

(当然,如果你知道你的价值范围有限,你可以使用较小的int类型)

const uint FRAMES_PER_10min = 10*60 * 30000/1001;
const uint FRAMES_PER_1min  =  1*60 * 30000/1001;
const uint DISCREPANCY      = (1*60 * 30) - FRAMES_PER_1min;


/** reverse the drop-frame calculation
 * @param  frameNr raw frame number in 30000/1001 = 29.97fps
 * @return frame number using NTSC drop-frame encoding, nominally 30fps
 */
int64_t
calculate_drop_frame_number (int64_t frameNr)
{
  // partition into 10 minute segments
  lldiv_t tenMinFrames = lldiv (frameNr, FRAMES_PER_10min);

  // ensure the drop-frame incidents happen at full minutes;
  // at start of each 10-minute segment *no* drop incident happens,
  // thus we need to correct discrepancy between nominal/real framerate once: 
  int64_t remainingMinutes = (tenMinFrames.rem - DISCREPANCY) / FRAMES_PER_1min;

  int64_t dropIncidents = (10-1) * tenMinFrames.quot + remainingMinutes;
  return frameNr + 2*dropIncidents;
}                 // perform "drop"

从生成的“drop”frameNumber中,您可以像往常一样使用标称的30fps帧速率计算组件......

frames  =    frameNumber % 30
seconds =   (frameNumber / 30) % 60

依旧......

答案 1 :(得分:1)

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;

您需要从SysUtils单元复制DivMod例程,并在任何实现此功能的过程中包含sysUtils单元。