gpt4 book ai didi

objective-c - 从计算机时钟引用的时间码

转载 作者:行者123 更新时间:2023-12-03 17:35:01 25 4
gpt4 key购买 nike

我基本上想按下一个按钮,以 30fps 启动时间码。 (每 1/30 秒调用一次)。我希望时间码引用计算机内置的时钟。我可以使用 NSDate 轻松获取 HH:mm:ss 中的当前时间,但我需要计数器从零开始并实现类似 HH:mm:ss:ff 的帧格式

想法?

最佳答案

使用CVDisplayLink生成具有显卡精度的脉冲,这将比NSTimer或调度队列准确得多。 CoreMedia/CoreVideo 本身也可以使用 SMPTE。

CVReturn MyDisplayCallback(CVDisplayLinkRef displayLink,
const CVTimeStamp *inNow,
const CVTimeStamp *inOutputTime,
CVOptionFlags flagsIn,
CVOptionFlags *flagsOut,
void *displayLinkContext) {

CVSMPTETime timecodeNow = inNow->smpteTime; // it's that easy!

DoStuffWith(timecodeNow); // you might have to modulo this run a bit if the display framerate is greater than 30fps.

return kCVReturnSuccess;
}

CVDisplayLinkRef _link;
CVDisplayLinkCreateWithCGDisplay(CGMainDisplayID(),&_link);
CVDisplayLinkSetOutputCallback(_link, MyDisplayCallback, NULL);
CVDisplayLinkStart(_link);

编辑:稍微玩了一下后,我注意到显示链接中的 SMPTE 字段没有被填写,但是主机时间是准确的。只需使用:

inNow->videoTime / inNow->videoTimeScale;

获取正常运行时间的秒数,以及

inNow->videTime % inNow->videoTimeScale

得到余数。

据我所知:

@implementation JHDLTAppDelegate

CVReturn MYCGCallback(CVDisplayLinkRef displayLink,
const CVTimeStamp *inNow,
const CVTimeStamp *inOutputTime,
CVOptionFlags flagsIn,
CVOptionFlags *flagsOut,
void *displayLinkContext) {


dispatch_async(dispatch_get_main_queue(), ^{

JHDLTAppDelegate *obj = (__bridge JHDLTAppDelegate *)displayLinkContext;

uint64_t seconds = inNow->videoTime / inNow->videoTimeScale;
[obj.outputView setStringValue:[NSString stringWithFormat:@"days: %llu/hours: %llu/seconds: %llu (%llu:%u)",
seconds / (3600 * 24),
seconds / 3600,
seconds,
inNow->videoTime, inNow->videoTimeScale]];


});

return kCVReturnSuccess;
}

- (void)applicationDidFinishLaunching:(NSNotification *)aNotification
{
CVDisplayLinkCreateWithCGDisplay(CGMainDisplayID(), &_ref);
CVDisplayLinkSetOutputCallback(_ref, MYCGCallback, (__bridge void *)self);
CVDisplayLinkStart(_ref);
}

- (void)dealloc
{
CVDisplayLinkStop(_ref);
CVDisplayLinkRelease(_ref);
}

@end

关于objective-c - 从计算机时钟引用的时间码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14696978/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com