我正在寻找一个函数,它将帧中的整数值转换为ntsc drop frame timecode(hh:m m:ss.ff)。
我在用Delphi,但可以用任何语言。
谢谢
最佳答案
这个问题有一个著名的经典解…
输入帧计数nr与实际帧速率相关,对于ntsc,实际帧速率始终为30000/1001~=29.97帧/秒。
计算结果帧nr为30fps的标称帧速率(并且将在每一整分钟显示a+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
等等。。。
关于algorithm - 将帧转换为NTSC丢帧时间码,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/869490/