Skip to content

Read the GPS of a 70mai rear camera clip from the rows of its front clip - #990

Merged
caglarpir merged 8 commits into
mapillary:mainfrom
caglarpir:70mai-rear-clips
Dec 3, 2026
Merged

caglarpir merged 8 commits into
mapillary:mainfrom
caglarpir:70mai-rear-clips

Conversation

@caglarpir

@caglarpir caglarpir commented Dec 2, 2026 •

Copy link
Copy Markdown
Contributor

Problem

The GPS logs of 70mai dashcams name only the clips of the front camera (…F.MP4): all 5,223 clips named in three sample logs end with F. A rear camera clip (…B.MP4) finds no rows of its own, so it gets no GPS.

Change

  • A clip that the logs don't name takes the rows of the clip they do name with the same name except the camera letter at the end. NO20250209-170040-000944B takes the rows of NO20250209-170040-000944F, since both cameras start their clips together.
  • It matches only if the start time and the number are the same, and the logs name exactly one such clip. A clip with rows of its own keeps them.
  • The rows are placed in the clip by its own duration. Whether the log is UTC or 8 hours behind is decided from the front clip's name, as for the front clip.
  • README: keep the log, or a copy of it, beside the rear videos too.

Stacked on #974: its commits are included here, and this PR adds the last one. It conflicts with #991 in seventymai_log_parser.py, so whichever merges second needs a rebase.

Testing

  • Unit tests:

    • a rear clip takes the rows of its front clip, also when the log names it .MP44;
    • a clip with rows of its own keeps them;
    • no match when the start time or the number differs, or when two other clips match.

    Each test fails when its code path is broken.

  • A sample 70mai clip linked under its rear name beside its log gets the same 37 points as the front clip.

  • Not tested on a real rear clip: no sample has one, so the rear name is inferred from the front clip's F. The match accepts any letter in its place.

  • ruff, usort, and mypy on 3.9 and 3.13. Unit tests on 3.9 and 3.13, merged with main.

70mai dashcams write no GPS into their clips that mapillary_tools or ExifTool
can read. They write it to a text log beside the clips instead,
GPSData000001.txt, with a row per fix: the Unix time (UTC), the fix status,
the position, and the name of the clip being recorded. One log covers many
clips and hours. So process and video_process failed these clips with
MapillaryVideoGPSNotFoundError.

The native reader now falls back to the GPSData*.txt logs in the folder of a
video in which no other native reader finds GPS. It takes the valid fixes of
the rows that name the clip: status A, a positive time, a finite position
that is not null island. The rows name the clip by its file name, matched by
its stem, as some cameras leave characters of a longer name after the
extension (".MP44"). A log is indexed once per process, by the byte ranges of
the rows of each clip: a 60 MB log of 650,000 rows takes 0.3 s, then each clip
reads only its own rows. Without a log, the fallback costs a listing of the
folder, once per folder.

The rows carry the GPS time, not the time in the video. In the middle of a
recording, the camera writes the first row of a clip within about a second of
its start, so the first fix is taken as video time 0. A camera that is
switched on records before it has a fix, which took from 7 seconds to nearly
3 minutes in the logs seen. Then it either writes rows without a fix that
name the clip before the first fix, or the fixes span at least 9 seconds less
than the clip (a stall of the GPS cost at most 6 seconds otherwise), and the
last fix is taken as the end of the clip instead. A clip without a fix at
either end, or whose fixes span more than 5 seconds longer than the clip,
gets no GPS from the log, as before.

As the fallback is in the native reader, the log is used by the default
sources of process, by sources that try native before exiftool_runtime, by
sample_video for the GPS clock and positions of the frames, and to place a
GPX track on the clip by its GPS clock. A GPX converted from the whole log
was placed to start with the clip before: 19 and 39 km off for two sample
clips. It is placed by the log's clock now.

On three sample clips, process geotags them from the log, and upload
--dry_run writes their fixes as a CAMM track. For two logs of 60 and 115
clips, the fixes read for every clip are the ones that GPSBabel's 70mai
reader converts. video_process places the frames on the track of the log;
the position that the camera prints on each frame, which it updates once a
second, is the position of 0.6 to 1.5 seconds earlier on that track.
A clip without rows without a fix was placed by its last fix, as the end
of the clip, whenever its fixes spanned more than 8 seconds less than the
clip. That is meant for the first clip after the camera is switched on,
whose first fix comes late. But in the middle of a logging session, the
clips that the rule placed are all the last clip before the camera
restarted logging ("$V02"): the camera had a fix when it started the clip,
and stopped recording or logging it early. Their first fix marks their
start, and placing them by their last fix shifted them by 13 to 119
seconds in one of the logs seen.

The index of a log now records where each run of rows of a clip is: after
"$V02" (or rows that name no clip), at the top of the log, or after rows of
another clip. The span rule applies only to a clip whose first rows follow
"$V02", or are at the top of the first log in the folder, as the top of a
later log continues the previous one. Rows without a fix before the first
fix still place a clip by its last fix wherever it is.

In three logs, 58 clips are placed by their first fix instead of their last.
For all of them, the last fix of the previous clip is 0 to 5 seconds before
their first fix. For 52, the start this gives is also within 3 seconds of
the start that the previous clip gives from the time in the file names.
The top of the first log in a folder was taken as where the camera started
logging, like a "$V02" line, so a short clip there was placed by its last
fix. A log without "$V02" at its top more likely continues one that was cut
or rotated away, and for a clip continued from a log, the first fix is the
right start. Only rows right after "$V02" now count as the first the camera
logged.
The GPS logs of 70mai dashcams were read as UTC, but on some cameras their
times are 8 hours behind UTC: the firmware takes the UTC time of the GPS for
the local time of China (UTC+8). On two of three sample cameras, every clip
was stamped 8 hours early. The light in the clips shows it: a clip that the
camera's clock, printed on the frames, has at 07:37 is in morning light,
while the log read as UTC puts it at 23:36 local time. On the third camera,
the log is UTC.

The file name of a clip is the time of the camera's clock at its start, in
local time. Once the log's time is UTC, the difference between the name and
the clip's first fix is the time zone where the clip was recorded. Time zones
are within about 3 hours of the solar time of their longitude (the most, in
west China), and the two clocks are 8 hours apart, so at most one gives a
zone within 4 hours. Each clip now takes the shift, none or 8 hours, that its
name tells. A clip whose name tells neither, as when the camera's clock was
not set, takes the shift that most of the clips in the logs of its folder
tell. If they tell none, or are split evenly, the log is not used and a
warning says why: the clip gets no GPS, as before the log was read. A
difference outside UTC-12 to UTC+14 is no zone: a clock left in the time of
China in America is 16 hours ahead of a log 8 hours behind, which would
otherwise wrap around to a zone of America.

In the three sample logs, every clip with a fix tells the same shift: 8 hours
for all 60 and 115 clips of two logs recorded in UTC+2 and UTC+5, and none
for 4,394 clips of a log recorded in UTC+3. The light in the clips matches
their times now. Indexing a 60 MB log takes 0.3 s instead of 0.2 s, as it
parses the rows of each clip up to its first fix.

A GPX that GPSBabel converted from a log 8 hours behind has the same times,
so it no longer lines up with the clip's clock, now UTC: process refuses it
as outside the GPX track. These clips don't need it, as they get their GPS
from the log.
Some 70mai cameras write 1609430400, the start of 2021 in China (UTC+8), in
the rows they log before they have the time of the GPS, as others write 0 or
-28801. Only times of 0 and less were taken as no time, so a row with that
time, status A, and a position was a fix from 2021. Before the real fixes of
a clip, it made the fixes span years more than the clip, which failed it,
and a clip with only such rows got a point dated 2021.

Rows with exactly that time are now rows without a fix, so such a clip is
placed by its last fix, as with any rows without a fix before the first.
…g's clock

The name of a clip tells whether the GPS log is UTC or 8 hours behind only if
the camera's clock is set to local time. A clock set to the time of China
(UTC+8), as the placeholder times of the logs are, with a log in UTC reads
exactly as a log 8 hours behind in a zone at UTC+0. That zone fits the sun
from about 60°W to 60°E, so the clips of such a camera in Europe, Africa or
South America got times 8 hours late.

That reading no longer counts. A clip that gives only it takes the clock that
the other clips in the logs tell, or else fails with the warning that the log
can't be told. That includes a log 8 hours behind in a real zone at UTC+0
(the UK and Portugal in winter, Iceland, West Africa), unless clips of the
same camera at another offset, such as in summer, tell it.

The mirror case can't be guarded: a clock set to UTC with a log 8 hours
behind reads as a log in UTC in a zone at UTC+8, as in China, and gets times
8 hours early. The docstring, the README and the command reference now say
that the camera's clock must be set to local time, and give both limits.
… Asia

The docstring and the command reference said that a camera clock set to UTC
with a log 8 hours behind is always taken as a log in UTC in a zone at UTC+8,
8 hours early. That reading fits only where UTC+8 fits the sun, from about
60°E to 180°E. Elsewhere it reads as a log 8 hours behind in a zone at UTC+0,
which is no longer counted, so the clip fails with the warning, as in Zurich.
The GPS logs of 70mai dashcams name only the clips of the front camera
(NO20250209-170040-000944F.MP4): all 5,223 clips named in three sample logs
end with F. So a clip of the rear camera found no rows and got no GPS.

A clip that the logs don't name now takes the rows of the clip they do name
with the same name but for the letter of the camera at its end, as the two
cameras start their clips together: ...000944B takes the rows of ...000944F.
It matches only if the start time and the number are the same, and the logs
name exactly one such clip. A clip with rows of its own keeps them. The rows
are placed in the clip by its own duration, and their clock is told by the
name of the front clip, as for the front clip itself.

The README says to keep the log, or a copy of it, beside the rear videos too.

No sample has a rear clip, so its name is inferred from the front clip's
letter (F) rather than seen: the match takes any letter in its place.
@meta-cla meta-cla Bot added the cla signed label Dec 2, 2026
@caglarpir
caglarpir merged commit a17d3a2 into mapillary:main Dec 3, 2026
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant