Skip to content

Add 70mai video extractor and GPS data parser - #964

Closed
ypcyc wants to merge 1 commit into
mapillary:mainfrom
ypcyc:main
Closed

ypcyc wants to merge 1 commit into
mapillary:mainfrom
ypcyc:main

Conversation

@ypcyc

@ypcyc ypcyc commented Nov 23, 2026

Copy link
Copy Markdown

Title

Add GPS extraction for 70mai Dashcam videos

Description

This PR adds native GPS extraction for 70mai front-camera videos that store GPS records in an MP4 hint track.

What changed

  • Locate the 70mai hint track and pair its samples with the matching video track. The hint samples have zero durations, so video-track timing is used to calculate point times.
  • Parse 493-byte records to extract coordinates, course, altitude, speed, and the record timestamp.
  • Emit at most one GPS point per second of video, using the earliest valid fix in each second.
  • Count and log distinct record timestamps and their frame counts at debug level.
  • Use the most frequent record timestamp as the epoch-time anchor, apply the default TIMEZONE_OFFSET of +8 hours, and advance subsequent point timestamps by their video-relative time.
  • Wire the 70mai extractor into native video extraction.

Validation

  • Verified against a 70mai MP4 containing 5,400 video and hint samples. Extraction returns 180 GPS points spanning 0–179 seconds.
  • Added focused tests for hint-track selection, point parsing and timing, timestamp diagnostics, and extractor behavior.
  • Focused tests pass; Ruff passes.

Notes

The altitude unit is believed to be meters based on the record template. The timestamp offset is currently a code constant set to +8 hours.

@meta-cla

meta-cla Bot commented Nov 23, 2026

Copy link
Copy Markdown

Hi @ypcyc!

Thank you for your pull request and welcome to our community.

Action Required

In order to merge any pull request (code, docs, etc.), we require contributors to sign our Contributor License Agreement, and we don't seem to have one on file for you.

Process

In order for us to review and merge your suggested changes, please sign at https://code.facebook.com/cla. If you are contributing on behalf of someone else (eg your employer), the individual CLA may not be sufficient and your employer may need to sign the corporate CLA.

Once the CLA is signed, our tooling will perform checks and validations. Afterwards, the pull request will be tagged with CLA signed. The tagging process may take up to 1 hour after signing. Please give it that time before contacting us about it.

If you have received this in error or have any questions, please contact us at cla@meta.com. Thanks!

@meta-cla

meta-cla Bot commented Nov 23, 2026

Copy link
Copy Markdown

Thank you for signing our Contributor License Agreement. We can now accept your code for this (and any) Meta Open Source project. Thanks!

@meta-cla meta-cla Bot added the cla signed label Nov 23, 2026

@caglarpir caglarpir left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for working on this, @ypcyc! Reading 70mai GPS natively would be really useful, and pairing the hint samples with the video track by sample count is a neat approach. A few things need to change before this can go in.

1. The fixed +8 hour offset (TIMEZONE_OFFSET)

The point timestamps (epoch_time) are more than labels. On upload they go into the CAMM GPS track that sets the capture time, and video_process uses them as the capture time of each sampled frame. A fixed offset is only right for cameras set to one time zone, and the record doesn't say which zone the camera was set to. The Novatek parser doesn't guess in the same situation: when the GPS clock is local time, it returns no points and leaves the video to ExifTool (_UnsupportedBlockError("Local time") in novatek_parser.py). Unless the field turns out to be UTC, epoch_time should stay None.

2. Times shift when the first fix is late

If the timestamp stays, note that extract_points gives it to the first point with a fix, not to video time 0 (first_epoch_time + point.time - first_point_time). With synthetic records whose first fix comes 10 s into the clip, every point comes out 10 s early. That happens on the first clip after the camera starts. The docstring of novatek_parser.py describes the same pitfall. If the timestamp is the clip start, anchor + point.time avoids the shift.

3. Course, speed and altitude are read as single bytes

_parse_record reads record[0x17], record[0x1B] and record[0x1F], but these look like 4-byte little-endian integers, like lat/lon: the fields start at 0x0F, 0x13, 0x17, 0x1B and 0x1F, 4 bytes apart. ExifTool's QuickTimeStream.pl has a hex dump of the same 493-byte record (70mai A810, same 03 00 ed 01 header, under GPSType 19; its offsets are 0x10 higher because the dump starts at the freeGPS header). There the int32 at 0x17 is 349, which this PR decodes as 93. As written, the course can't go above 255°, the speed above 2.55 m/s, or the altitude above 255 m or below 0. video_process writes course and altitude into each frame's EXIF, so these values would end up in uploads. ExifTool reads the speed as an int32, possibly in km/h.

4. CI checks

  • mypy reports 3 errors: max(timestamp_counts, key=timestamp_counts.get) (line 143) and hdlr["data"]["handler_type"] (line 196).
  • ruff format --check and usort diff want changes in all three files (native.py also needs two blank lines between the classes).

Smaller things

  • Keeping the earliest record of each video second can attach a position up to about 1 s old, since each fix repeats over many frames. Emitting a point at the frame where the position changes avoids that lag.
  • One record with out-of-range coordinates makes the whole video return no GPS (Invalid 70mai coordinates). Skipping just that record would be gentler.
  • The tests patch out MovieBoxParser and _extract_tracks, so finding the hint track in a real file isn't tested. tests/unit/test_novatek_parser.py builds a small MP4 in memory and could serve as a model. A test with a late first fix would cover point 2.
  • The new files are missing the license header the other modules have.
  • extract_points re-checks the sample sizes and counts that _extract_tracks already guarantees.
  • ExifTool decodes lat/lon in this record as ddmm.mmmmm × 1e5, while the PR uses degrees × 1e7. You compared against GPSData000001.txt, so it may be a firmware difference, but it's worth a second look.

Two questions

  • Could you share a short sample clip with this hint track, and the matching lines of GPSData000001.txt? We don't have a 70mai video in this format to test against.
  • Do you know what the timestamp at 0x15D is: GPS time or the camera clock? Does it change during a clip, or stay at the clip start?

@ypcyc

ypcyc commented Nov 27, 2026

Copy link
Copy Markdown
Author

HI @caglarpir Thank you for so detailed and fast feedback. I was busy these days and couldn't reply faster. I can't give full feedback now, just some additional information.
Here is the link to sample files, please request access:
https://drive.google.com/drive/folders/1kO1iYQwIkkxRq7RtETm3ARVIIgi5uBm0?usp=sharing
I previously had conversation with 70mai support on timestamps. In some cases I had "0" I guess simple no GPS fix and sometimes "-28801" values.
They commented:

Regarding the GPS timestamp, our system uses the standard Unix epoch (UTC seconds), and the GPS module also outputs UTC time through the RMC message. Due to a time conversion issue in the firmware, the GPS time was incorrectly interpreted as local time under the device’s CST (UTC+8) setting, resulting in an 8-hour difference. The firmware therefore needs to compensate for this time-zone difference.

image

@caglarpir

Copy link
Copy Markdown
Contributor

Thanks again, @ypcyc, and for asking 70mai support about the timestamps: their explanation of the 8 hours helped a lot.

Since then, mapillary_tools main reads the GPS log that 70mai cameras write next to the clips (GPSData*.txt), in #974, #990 and #991. Clips with the log in their folder are geotagged with no extra options, rear camera clips and sessions logged without GPS time included. It will be in the next release. Your clips should be geotagged by main without this PR, as long as their GPSData*.txt is in the same folder as the videos: if you try it, let us know how it goes.

I also had a 70mai clip with both a hint track and the log, so I compared the two:

  • The hint track's latitude and longitude are degrees and minutes (ddmm.mmmmm × 1e5), as ExifTool reads them, not degrees × 1e7. Read that way, they match the log and the position printed on the frames to within 10 m. Read as degrees, they are 10.8 km off.
  • The record timestamp is the camera's clock minus 8 hours, not GPS time. On that clip, adding 8 hours gives exactly the time in the file name, which is the camera's local time, while the GPS time in the log puts the start of the clip 5 hours earlier (the local offset), less the 23 seconds that the camera's clock had drifted. So the +8 hours gives local time labelled as UTC, and without the log there is no GPS time to correct it by.
  • Course, speed and altitude are 4-byte integers (offsets 0x0F to 0x1F), not single bytes.

As the log has the GPS time and the hint track doesn't, and your camera writes the log too (you compared the hint track against it), I'm closing this PR in favour of the log reader. If you have clips that were recorded without the log next to them, samples of those would help us see whether a hint-track reader is worth adding.

@caglarpir caglarpir closed this Dec 3, 2026
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.

2 participants