iOS 中摄像头帧数据的时间戳和系统时间戳到关系是怎么样的? - V2EX
V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
iOS 开发实用技术导航
NSHipster 中文版
http://nshipster.cn/
cocos2d 开源 2D 游戏引擎
http://www.cocos2d-iphone.org/
CocoaPods
http://cocoapods.org/
Google Analytics for Mobile 统计解决方案
http://code.google.com/mobile/analytics/
WWDC
https://developer.apple.com/wwdc/
Design Guides and Resources
https://developer.apple.com/design/
Transcripts of WWDC sessions
http://asciiwwdc.com
Cocoa with Love
http://cocoawithlove.com/
Cocoa Dev Central
http://cocoadevcentral.com/
NSHipster
http://nshipster.com/
Style Guides
Google Objective-C Style Guide
NYTimes Objective-C Style Guide
Useful Tools and Services
Charles Web Debugging Proxy
Smore
jasonlz
V2EX    iDev

iOS 中摄像头帧数据的时间戳和系统时间戳到关系是怎么样的?

  •  
  •   jasonlz 2018-05-10 21:18:25 +08:00 7510 次点击
    这是一个创建于 2785 天前的主题,其中的信息可能已经有所发展或是发生改变。
    CMTime time = CMSampleBufferGetPresentationTimeStamp( sampleBuffer );
    Float64 timestamp = CMTimeGetSeconds(time);

    这样得到的时间戳是以何时为起始点的,如何和系统时间( timeIntervalSince1970 )对齐?
    3 条回复    2018-05-12 23:45:59 +08:00
    Jameson1559
        1
    Jameson1559  
       2018-05-11 11:14:40 +08:00   1
    CMTime 并不等于时间戳,也不能和 NSDate 对等
    CMTime 的 0 点 等同于 CMTimeZero 等同于 媒体的 0 时间,是相对于媒体存在的一个计时单位
    CMTimeGetSeconds 是获取了用 秒 当作单位的 CMTime 的值
    也就是用 CMTime.value / CMTime.timescale

    关于和系统时间对齐这个,并不能理解到这个问题要问什么,如果是指:

    1) 计算当前 CMTime 与 timeIntervalSince1970 之间的差值
    不能这样计算,因为 CMTime 是相对时间,不是系统时间,两者不能进行比对 /运算

    2) 让当前 CMTime 等于 timeIntervalSince1970
    按理说不应该有这种需求,顶多说修改 CMTime 的值,但是这样做你的帧数据就乱了呀。。



    - - - -
    关于 CMTime 是什么,在 Apple 提供的文档中有更加详细的说明

    -> https://developer.apple.com/documentation/coremedia/cmtime-u58
    jasonlz
        2
    jasonlz  
    OP
       2018-05-11 16:58:38 +08:00
    @Jameson1559 现在就是要做个时间同步,让这个摄像头的时间和别的地方的数据同步,所以就不知道这个 CMTime 的 0 时刻是什么时候,我用首帧时间做了个差,然后发现有几十毫秒的误差,对于算法而言,这个误差有点致命。老哥知道这个 CMTime 的 0 时刻的系统时间怎么获取吗?
    Jameson1559
        3
    Jameson1559  
       2018-05-12 23:45:59 +08:00
    @jasonlz
    - - - -
    CTime 的 0 时间永远是相对于媒体而言的呀……但是如果硬要同步的话,我记得 AVDeviceInputDelegate 还是哪个来着,有一个方法叫 - deviceInput: didOutputSampleBuffer 的,在第一次调用采样输出的时候获得一次系统时间,然后把这个当作 0 时间来同步

    不过这里还是要注意一个问题,- deviceInput: didOutputSampleBuffer 回调的时候,根据你的采样渠道,可能会返回不止一种类型的 sample,这个不管,只需要首次回调的时间

    但是这样可能还是会有一些误差吧- -大概?

    或者你现在已经用了我说的这种方法…… ?
    关于     帮助文档     自助推广系统     博客     API     FAQ     Solana     4013 人在线   最高记录 6679       Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 28ms UTC 05:17 PVG 13:17 LAX 21:17 JFK 00:17
    Do have faith in what you're doing.
    ubao msn snddm index pchome yahoo rakuten mypaper meadowduck bidyahoo youbao zxmzxm asda bnvcg cvbfg dfscv mmhjk xxddc yybgb zznbn ccubao uaitu acv GXCV ET GDG YH FG BCVB FJFH CBRE CBC GDG ET54 WRWR RWER WREW WRWER RWER SDG EW SF DSFSF fbbs ubao fhd dfg ewr dg df ewwr ewwr et ruyut utut dfg fgd gdfgt etg dfgt dfgd ert4 gd fgg wr 235 wer3 we vsdf sdf gdf ert xcv sdf rwer hfd dfg cvb rwf afb dfh jgh bmn lgh rty gfds cxv xcv xcs vdas fdf fgd cv sdf tert sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf sdf shasha9178 shasha9178 shasha9178 shasha9178 shasha9178 liflif2 liflif2 liflif2 liflif2 liflif2 liblib3 liblib3 liblib3 liblib3 liblib3 zhazha444 zhazha444 zhazha444 zhazha444 zhazha444 dende5 dende denden denden2 denden21 fenfen9 fenf619 fen619 fenfe9 fe619 sdf sdf sdf sdf sdf zhazh90 zhazh0 zhaa50 zha90 zh590 zho zhoz zhozh zhozho zhozho2 lislis lls95 lili95 lils5 liss9 sdf0ty987 sdft876 sdft9876 sdf09876 sd0t9876 sdf0ty98 sdf0976 sdf0ty986 sdf0ty96 sdf0t76 sdf0876 df0ty98 sf0t876 sd0ty76 sdy76 sdf76 sdf0t76 sdf0ty9 sdf0ty98 sdf0ty987 sdf0ty98 sdf6676 sdf876 sd876 sd876 sdf6 sdf6 sdf9876 sdf0t sdf06 sdf0ty9776 sdf0ty9776 sdf0ty76 sdf8876 sdf0t sd6 sdf06 s688876 sd688 sdf86