Repository navigation
Accept ISO 8601 (with timezone) for --video_start_time - #822
Conversation
|
The bug persists. Although mapillary_tools sample_video --video_sample_distance -1 --video_sample_interval 1 --video_start_time '2026-04-06T14:36:07.88+02:00' 'video.mp4'
⋮
exiv2 -pv 'video.mp4/video_v_000001.jpg'
File 1/1: video.mp4/video_v_000001.jpg
0x8769 Image ExifTag Long 1 38
0x9003 Photo DateTimeOriginal Ascii 20 2026:04:06 12:36:07
0x9011 Photo OffsetTimeOriginal Ascii 7 +00:00
0x9291 Photo SubSecTimeOriginal Ascii 7 880000
0x8825 Image GPSTag Long 1 110
0x0007 GPSInfo GPSTimeStamp Rational 3 12/1 36/1 197/25
0x001d GPSInfo GPSDateStamp Ascii 11 2026:04:06In other words, There are two subsequent issues here though.
|
|
Thanks for putting this together, ISO 8601 is much friendlier than the underscore format. Sorry it sat for so long, it got stuck behind the 0.15.0 work. It still applies cleanly to main and the doctests pass. A few things I'd like to change before merging:
@JakeSmarter on DateTimeOriginal: mapillary_tools writes capture times in UTC, so Happy to make these changes myself if you're short on time, just let me know. |
|
Thank you @caglarpir for considering it.
I fully support your reasoning and approach here. Requiring a timestamp with a timezone offset is a smart move. 👍 However, the error message wording has to be chosen carefully so that users do not simply append
This is weird but nevertheless a bummer. It sounds reasonable to me to have separate code paths for affected Python versions that extend ISO 8601 timestamps to 6 fraction decimal places.
You are right, it is the same timestamp due to the |
The --video_start_time option only accepted the proprietary YYYY_MM_DD_HH_MM_SS_sss format, which is always interpreted as UTC. This left no clean way to correct timestamps for cameras whose RTC has no timezone and records local time (e.g. GoPro MAX), as reported in #819. Add a _parse_video_start_time() helper that also accepts ISO 8601: - an explicit UTC offset (or Z) is honored, and - a naive value is interpreted in the system local timezone. The legacy format is unchanged and still treated as UTC. Documented via doctests and updated the CLI help text.
…on version Review follow-up to the ISO 8601 support for --video_start_time: - A time without a UTC offset is refused. Read in the local time zone of the computer, the same command would place the video at another time on a server in UTC or a laptop abroad. The error asks for the offset of the clock the time was read from, such as +01:00 for a camera set to Central European Time, and for Z only if that clock is set to UTC. - ISO 8601 is parsed with a regular expression rather than datetime.fromisoformat(), which before Python 3.11 accepts neither Z nor fractions of other than 3 or 6 digits, such as 2026-04-06T14:36:07.88+02:00. Offsets may be Z, +hh, +hhmm or +hh:mm; seconds and fractions are optional. - The help text and the command reference list ISO 8601 first, and the video_process example uses it.
5fb87e2 to
c787d00
Compare
|
I've finished this as offered, so it can go into the next release. On top of the original commit, rebased onto main:
Thanks @ptpt for the original change, and @JakeSmarter for the review. |
…ge times The README still described --video_start_time as UTC only, and both of its examples used the underscore format. It now gives ISO 8601 with a UTC offset first, as the help text and the command reference do, and points to the command reference for cameras that record local time. The examples use 2025-03-14T08:00:30+01:00, the same instant as before. A time with an offset at the ends of the datetime range, such as 9999-12-31T23:59-01:00, falls outside that range in UTC. astimezone() raised OverflowError, which escaped as a traceback instead of an invalid-parameter error with exit code 2. It is now refused as an invalid video start time.
|
Excellent! I shall test it the next release. Thank you. |
Summary
Addresses part of #819 (GoPro MAX timestamping). The
--video_start_timeoption only accepted the proprietaryYYYY_MM_DD_HH_MM_SS_sssformat, which is always interpreted as UTC. This left no clean way to correct timestamps for cameras whose RTC has no timezone and therefore records local time (e.g. GoPro MAX).This PR makes
--video_start_timealso accept ISO 8601 with a UTC offset:2020_12_28_13_36_36_508(legacy)13:36:36Z2020-12-28T13:36:36.508Z13:36:36Z2020-12-28T13:36:36.508+01:0012:36:36Z2020-12-28T13:36:36.508(no offset)Z,+hh,+hhmmor+hh:mm) is honored. Seconds and fractions of any length are optional.+01:00for a camera set to Central European Time), and forZonly if that clock is set to UTC.--video_start_timeapplies only to videos without a GPS clock of their own.Implementation
_parse_video_start_time()insample_video.pytries the legacy format first, then parses ISO 8601 with a regular expression.datetime.fromisoformatisn't used because before Python 3.11 it accepts neitherZnor fractions of other than 3 or 6 digits (2026-04-06T14:36:07.88+02:00,2020-12-28T13:36:36.5Z). The help text anddocs/command_reference.mdlist ISO 8601 first, and thevideo_processexample uses it.The second commit applies the review points from the discussion below to the first.
This does not address the other items in #819.
Test plan
sample_videoCLI:--video_start_time 2026-06-30T18:28:44.5+02:00gives frames at 16:28:44.5 UTC; a value without an offset exits with code 2 and the error aboveruff,usort,mypy(3.9 and 3.13) clean