跳转到内容

C203 第 3 课:跨设备的时钟

独立于头部运动的腕戴相机、三脚架上的房间相机和第二位佩戴者的眼镜,无法与头戴设备共用一根线。它们各自用自己的晶体计时。这一课讲在录制之前或录制期间把独立设备放到同一个时钟上的方法;第 4 课讲事后对齐录制。完整的论述见同步多台设备和 PTP 与网络时间同步。

另见术语表的同步一节。

术语 含义
时间域(Time domain) 一个时间戳所用的那个时钟;来自不同时间域的时间戳不能直接比较
PTP(IEEE 1588) 通过交换带时间戳的报文,在以太网上同步时钟的协议
最高级主时钟(Grandmaster clock) PTP 网络的根时间源
PHC PTP 硬件时钟(PTP hardware clock):网卡本身上的时钟
硬件时间戳(Hardware timestamping) 由网卡在数据包经过线路时给它们打时间戳,而不是由操作系统来打
NTP 网络时间协议(Network Time Protocol);chrony 是它的一种实现
SMPTE 时间码(SMPTE timecode) 每一帧上由时、分、秒和帧组成的标签,标准化为 SMPTE ST 12
LTC 线性时间码(Linear timecode):以音频频段信号传送的 SMPTE 时间码

已发表的采集设备中的六种模式

Section titled “已发表的采集设备中的六种模式”

实用指南把已发表的采集设备跨设备共享时间的方式归为六种模式(已发表设备中的六种模式):

模式 时间如何共享 主要限制
一台设备上的一个时钟 一个触发信号和一个时钟驱动电路板上的每个传感器 只覆盖连接到这块电路板的传感器
共用时间码或同步装置 一个时间码发生器或同步盒向每台录制设备提供相同的时间 每台设备上都要有接收器或同步输入
由一台主机录制每台相机 一部手机或头显录制它自己的相机和 USB 腕戴相机,并记录到达时间 时间戳是到达时间;各相机以不同的速率自由运行
设备之间通过网络或无线电 设备之间通过 Wi-Fi 或无线电交换时间或数据包 对齐的是时钟,不是曝光
开始和结束时的视觉事件 每台相机都拍摄同一段二维码视频或同一个 LED 时钟 需要操作员守纪律;失败时需要恢复
推理时的延迟匹配 每一路数据流在策略看到它之前,按其测得的延时平移 配置改变时必须重新测量延时
Six ways published rigs share time across devices Six small panels. One: one clock on one board, which triggers every sensor wired to it, as on RoboCap; it only covers sensors on that board. Two: a shared timecode generator or sync box feeding every recorder, as in Ego-1K and Nymeria; every device needs an input for it. Three: one host, such as a phone or headset, records its own camera and USB cameras, as EgoKit does; it logs arrival times while the cameras free-run. Four: devices exchange time packets over Wi-Fi or radio, as Aria's TICSync and SubGHz do; this aligns clocks, not exposures. Five: every camera films the same visual event, a QR code or LED clock, at the start and end, as in Ego-Exo4D and RocSync; it depends on operator discipline. Six: latency matching, where each stream is shifted by its measured delay before a policy sees it, as in UMI, DexUMI and HoMMI; the delays must be re-measured whenever the setup changes. One clock, one board e.g. RoboCap board + clock limit: only sensors wired to it Shared timecode e.g. Ego-1K, Nymeria timecode limit: an input on every device One host records all e.g. EgoKit host USBUSB limit: arrival times, free-running Network or radio e.g. Aria TICSync, SubGHz time packets over Wi-Fi or radio limit: clocks, not exposures Visual event, start and end e.g. Ego-Exo4D, RocSync limit: operator discipline Latency matching e.g. UMI, DexUMI, HoMMI shift each stream by its measured delay limit: re-measure on any change
The six patterns published rigs use to share time across devices, each with a published example (the examples are tabled on Syncing Multiple Devices). Only the first, one trigger and one clock on one board, aligns exposures by construction; network and radio sync align clocks, and visual events and latency matching align streams after the fact.

怎么选,主要取决于同步方法对比中的一个问题:这些传感器是在一台你能接线的采集设备上,在你能控制的独立设备上,还是在你无法改动的相机上?第 2 课讲了第一种。这一课讲第二种。第 4 课讲第三种,以及每一套配置无论如何都应该加上的视觉事件。

PTP:一个网络中的时钟走同一个时间

Section titled “PTP:一个网络中的时钟走同一个时间”

PTP 与一个主时钟交换带时间戳的报文,并修正网络中其他每个时钟的偏移和走速(PTP 如何校准一个网络中的各个时钟)。

The PTP delay request-response exchange Two timelines running down the page, the master clock on the left and a camera's clock on the right. The master sends a Sync message at time t1 on its clock; the camera receives it at t2 on its own clock. In two-step mode a Follow_Up message then carries the exact value of t1. The camera sends a Delay_Req at t3; the master receives it at t4 and returns t4 in a Delay_Resp message. With all four timestamps the camera computes the mean path delay as ((t2 minus t1) plus (t4 minus t3)) divided by 2, and its offset from the master as ((t2 minus t1) minus (t4 minus t3)) divided by 2, then corrects its clock. The calculation assumes the delay is the same in both directions; any asymmetry, for example a switch that queues packets for varying times, turns into offset error. Master clock Camera clock t1 t2 t3 t4 Sync Follow_Up (carries t1) Delay_Req Delay_Resp (carries t4) time mean path delay [(t2 − t1) + (t4 − t3)] / 2 camera offset from master [(t2 − t1) − (t4 − t3)] / 2 Assumes the delay is equal both ways. Any asymmetry, such as a switch queuing packets for varying times, becomes offset error.
The IEEE 1588 delay request-response exchange. Four timestamps, two taken on each clock, give both the path delay and the camera's offset from the master, which the camera then corrects. The maths assumes the delay is the same in both directions, which is why non-PTP switches that queue packets unevenly show up as offset error.

它的精度取决于数据包在哪里被打上时间戳,因为这个协议是由报文的发送时间和接收时间计算每个时钟的偏移的,并假定两个方向上的延时相同;操作系统的延时每个数据包都不一样,它破坏了这个假定,变成偏移误差。Red Hat:“Hardware PTP support provides better accuracy since the NIC can time stamp the PTP packets at the exact moment they are sent and received while software PTP support requires additional processing of the PTP packets by the operating system”(意为:硬件 PTP 支持提供更好的精度,因为网卡可以在 PTP 数据包被发送和接收的确切时刻给它们打时间戳,而软件 PTP 支持需要操作系统对 PTP 数据包做额外处理)(硬件时间戳与网络)。它还说:“When used in conjunction with hardware support, PTP is capable of sub-microsecond accuracy, which is far better than is normally obtainable with NTP”(意为:与硬件支持配合使用时,PTP 能达到亚微秒级精度,远好于 NTP 通常能达到的水平),而不支持 PTP 的交换机 “will often cause an increase in jitter or introduce an asymmetry in the delay resulting in synchronization inaccuracies”(意为:常常会使抖动增大,或在延迟中引入不对称,从而导致同步不准)(RHEL 7: Configuring PTP using ptp4l)。PTP 需要以太网,所以它更适合采集场地周围的固定相机和录制计算机,而不是穿戴在身上的设备。

在 Linux 上,PTP 用 linuxptp 运行。大部分工作由三个程序完成(使用 linuxptp 的 Linux 录制 PC):

  • ptp4l 在一个网络端口上运行 PTP。它的手册:-H 选择硬件时间戳,“This is the default time stamping”(意为:这是默认的时间戳方式);-S 选择软件时间戳;-m 把消息打印到标准输出(ptp4l(8))。
  • phc2sys 在网卡的时钟和系统时钟之间复制时间,而大多数录制软件就是用系统时钟给帧打时间戳的。Red Hat:“The phc2sys program is needed only with hardware time stamping, for synchronizing the system clock to the PTP hardware clock on the network interface card”(意为:phc2sys 程序只在使用硬件时间戳时才需要,用于把系统时钟同步到网卡上的 PTP 硬件时钟)。
  • pmc,即 “PTP management client”(意为:PTP 管理客户端),用来查询正在运行的 ptp4l。

两点提醒。Red Hat:“Do not run more than one service to set the system clock’s time at the same time”(意为:不要同时运行一个以上的服务来设置系统时钟的时间)。另外,一个 PTP 网络是与它自己保持一致,不一定与外部世界一致:Basler 指出,如果没有任何设备跟随世界时间,“the network will operate in the arbitrary timescale mode (ARB)”(意为:网络将以任意时间尺度模式(ARB)运行)(Basler)。要把带 PTP 时间戳的视频与其他时钟上的设备对齐,可以由 GPS 或 NTP 给最高级主时钟提供时间,或者加上一个每台设备都能看到的视觉同步事件(PTP 时间不是现实世界的时间)。

GigE Vision 相机可以用 PTP 得到共同的时间戳,并通过定时动作命令在设定的未来时刻曝光。厂商给出的数字和 Basler 检查锁定的步骤在在 GigE Vision 相机上启用并验证 PTP。

许多小型计算机和交换机不支持 PTP。这时 chrony(NTP 的一种实现)是实用的选择,而且在本地网络上,它能做得比 NTP 的名声更好:有了 “local hardware timestamping, good network switches, and even shorter polling intervals, a sub-microsecond accuracy and stability of a few tens of nanoseconds might be possible”(意为:本地硬件时间戳、好的网络交换机,以及更短的轮询间隔,亚微秒级的精度和几十纳秒的稳定度是有可能达到的)(chrony FAQ)。没有这些条件时,精度取决于网络抖动:在 chrony 自己的仿真对比中,抖动为 10 µs 时客户端的误差是 35 ± 8 µs,抖动为 10 ms 时是 1603 ± 447 µs。采集场地通常由自己的一台机器提供时间;实用指南给出了 chrony.conf 指令。

无论哪一种时钟同步,对齐的都是计算机的时钟。它不对齐一台 USB 相机实际曝光的时刻:如果帧是在到达时打时间戳的,第 2 课中讲的 USB 和操作系统延时仍然存在。

SMPTE 时间码给每一帧打标签:“Each frame shall be identified by a unique and complete address consisting of an hour, minute, second, and frame number”(意为:每一帧应由一个唯一而完整的地址标识,该地址由时、分、秒和帧号组成)(SMPTE ST 12-1:2014)。接在每台相机上的小型发生器让每台设备都跟随一个共用的源;Assembly101 和 HOT3D 等已发表的数据集就是这样同步它们的相机的(共用时间码或同步装置)。有三个性质很重要(SMPTE 时间码):

  • 帧级分辨率。时间码说的是哪一帧,而不是帧内的哪个位置。
  • 丢帧计数。在 29.97 fps 下,按 30 fps 来计数每小时会漂移约 3.6 s,丢帧模式通过跳过帧号来修正它。
  • 开头的一个时间戳不是时钟。只在开头存一次时间码的文件,会随录制设备自己的时钟漂移。

对于长时间的拍摄日,Tentacle Sync 建议用时间码设备而不是一次性的二维码同步:“So for long running shoots it’s always better to attach a SYNC E directly to the GoPro”(意为:所以对长时间的拍摄,把一个 SYNC E 直接接到 GoPro 上总是更好)(Tentacle Sync)。

GPS 时间码适合户外采集。GoPro Labs 固件的 GPS 时间同步在 “If there is a good GPS signal”(意为:如果 GPS 信号良好)时更新相机的时钟,并在采集结束时写入时间码轨道;GoPro 给出的精度是 “In limited testing, sync is typically within a frame or two, but your precision my vary”(意为:在有限的测试中,同步通常在一两帧以内,但你得到的精度可能有所不同)(GoPro Labs: GPS time synchronization)。

  • 网络或无线电。Project Aria 的 Gen 1 通过 Wi-Fi 的 TICSync 据报告 “better than 1ms on average after approximately 45 seconds warm-up”(意为:在大约 45 秒的预热之后,平均优于 1ms)(About TICSync);Gen 2 由一副作为主机的眼镜广播 SubGHz 无线电信号(如果你使用 Project Aria 眼镜)。Aria 眼镜是研究设备,是一个入门点,而不是采集设备当前的形态,但许多公开数据集使用它们。
  • Lab Streaming Layer 反复测量每台计算机的时钟偏移,并且 “employs the clock filter algorithm of the Network Time Protocol (NTP)”(意为:采用网络时间协议(NTP)的时钟滤波算法);它看不到设备内部的延时,这些延时必须另外测量(Kothe et al., 2025;Lab Streaming Layer)。
  • 由一台主机录制每台相机。EgoKit 把 USB 腕戴相机插到录制头部视角的手机或头显上,并写出 “a log.txt listing per-frame timestamps for post-hoc alignment”(意为:一个 log.txt,列出每帧的时间戳,供事后对齐)。它的作者把时序列为尚待解决的工作,他们的变通办法是让各相机拍摄 “a millisecond-level timer displayed on a webpage”(意为:网页上显示的毫秒级计时器)(Yu et al., 2026)。

每一种时钟方法都让曝光不对齐

Section titled “每一种时钟方法都让曝光不对齐”

所有这些方法对齐的都是时钟、时间戳或开始命令。没有一种能让自由运行的相机一起曝光,所以两台时钟完美同步的相机,曝光仍然可能相差最多半帧:30 fps 下为 16.7 ms(从共享时钟到同时曝光)。第 4 课说明如何测量剩余的误差,以及在处理流程需要亚帧级时序时如何跨过它做插值。

  1. 你的房间相机和录制 PC 运行带硬件时间戳的 ptp4l,但录制软件用系统时钟给帧打时间戳。缺了什么?
  2. 为什么一个 PTP 网络的时间可能与一台由手机设置时钟的 GoPro 不一致?
  3. 一台相机只在每个文件的开头存一次 SMPTE 时间码。在一次很长的录制中会发生什么?
  4. 你的腕戴相机是一台 USB 相机,接在录制头部视角的同一部手机上。这是哪种模式,它受什么限制?
  5. 你的设备都在 chrony 上,本地硬件也很好。你能省掉开头和结尾的同步事件吗?
  1. phc2sys,用来把网卡的时钟复制到系统时钟(使用硬件时间戳时,ptp4l 调整的是网卡的时钟,不是系统时钟)。
  2. 没有跟随世界时间的最高级主时钟时,PTP 网络运行在一个任意的时间尺度上。由 GPS 或 NTP 给最高级主时钟提供时间,或者加上一个两者都能看到的视觉事件。
  3. 在那一个时间戳之后,文件中的帧会随录制设备自己的时钟漂移。
  4. 由一台主机录制每台相机。它的时间戳是主机时钟上的到达时间,带有 USB 和操作系统的抖动,而且各相机以不同的速率自由运行。
  5. 不能。时钟同步对齐的是时钟,不是曝光;而且两端的视觉事件也是你检查结果、在某台设备出问题时恢复的手段。