Skip to content

Commit 07092af

Browse files
author
Alessandro Dalvit
committed
Set last gps timestamp in uploaded video. Fixes.
1 parent d145411 commit 07092af

4 files changed

Lines changed: 35 additions & 9 deletions

File tree

mapillary_tools/geotag/camm_builder.py

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -135,6 +135,7 @@ def _create_camm_stbl(raw_samples: T.Iterable[sample_parser.RawSample]) -> BoxDi
135135
def create_camm_trak(
136136
raw_samples: T.Sequence[sample_parser.RawSample],
137137
media_timescale: int,
138+
creation_timestamp: int,
138139
) -> BoxDict:
139140
stbl = _create_camm_stbl(raw_samples)
140141

@@ -158,8 +159,8 @@ def create_camm_trak(
158159
# TODO: find timestamps from mvhd?
159160
# do not set dynamic timestamps (e.g. time.time()) here because we'd like to
160161
# make sure the md5 of the new mp4 file unchanged
161-
"creation_time": 0,
162-
"modification_time": 0,
162+
"creation_time": creation_timestamp,
163+
"modification_time": creation_timestamp,
163164
"timescale": media_timescale,
164165
"duration": media_duration,
165166
"language": 21956,
@@ -203,8 +204,8 @@ def create_camm_trak(
203204
# TODO: find timestamps from mvhd?
204205
# do not set dynamic timestamps (e.g. time.time()) here because we'd like to
205206
# make sure the md5 of the new mp4 file unchanged
206-
"creation_time": 0,
207-
"modification_time": 0,
207+
"creation_time": creation_timestamp,
208+
"modification_time": creation_timestamp,
208209
# will update the track ID later
209210
"track_ID": 0,
210211
# If the duration of this track cannot be determined then duration is set to all 1s (32-bit maxint).
@@ -242,7 +243,15 @@ def _f(
242243
camm_samples = list(
243244
convert_points_to_raw_samples(video_metadata.points, media_timescale)
244245
)
245-
camm_trak = create_camm_trak(camm_samples, media_timescale)
246+
# We adhere to some vendor's behavior and set creation_time to the time
247+
# the recording ended, and add 2082844800 to rebase to quicktime epoch 1904-01-01
248+
last_timestamp = (
249+
video_metadata.last_unix_ts + 2082844800
250+
if video_metadata.last_unix_ts
251+
else 0
252+
)
253+
creation_timestamp = int(last_timestamp)
254+
camm_trak = create_camm_trak(camm_samples, media_timescale, creation_timestamp)
246255
elst = _create_edit_list(
247256
[video_metadata.points], movie_timescale, media_timescale
248257
)

mapillary_tools/types.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,7 @@ class VideoMetadata:
8181
points: T.Sequence[geo.Point]
8282
make: T.Optional[str] = None
8383
model: T.Optional[str] = None
84+
last_unix_ts: T.Optional[int] = None # GPS time of the last point as Unix ts
8485

8586
def update_md5sum(self) -> None:
8687
if self.md5sum is None:
@@ -156,6 +157,7 @@ class _VideoDescriptionRequired(TypedDict, total=True):
156157
class VideoDescription(_VideoDescriptionRequired, total=False):
157158
MAPDeviceMake: str
158159
MAPDeviceModel: str
160+
MAPLastUnixTimestamp: int
159161

160162

161163
class _ErrorDescription(TypedDict, total=False):
@@ -328,6 +330,10 @@ def describe_error_metadata(
328330
"type": "string",
329331
"description": "Device model, e.g. HERO10 Black, DR900S-1CH, Insta360 Titan",
330332
},
333+
"MAPLastUnixTimestamp": {
334+
"type": "integer",
335+
"description": "UNIX timestamp of the last GPS point"
336+
}
331337
},
332338
"required": [
333339
"MAPGPSTrack",
@@ -493,6 +499,8 @@ def _as_video_desc(metadata: VideoMetadata) -> VideoDescription:
493499
desc["MAPDeviceMake"] = metadata.make
494500
if metadata.model:
495501
desc["MAPDeviceModel"] = metadata.model
502+
if metadata.last_unix_ts:
503+
desc["MAPLastUnixTimestamp"] = metadata.last_unix_ts
496504
return desc
497505

498506

@@ -594,6 +602,7 @@ def _from_video_desc(desc: VideoDescription) -> VideoMetadata:
594602
points=[_decode_point(entry) for entry in desc["MAPGPSTrack"]],
595603
make=desc.get("MAPDeviceMake"),
596604
model=desc.get("MAPDeviceModel"),
605+
last_unix_ts=desc.get("MAPLastUnixTimestamp")
597606
)
598607

599608

mapillary_tools/video_data_extraction/extract_video_data.py

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ def process(self) -> T.List[MetadataOrError]:
5959

6060
def process_file(self, file: Path) -> VideoMetadataOrError:
6161
parsers = video_data_parser_factory.make_parsers(file, self.options)
62-
points: T.Sequence[geo.Point] = []
62+
points: T.Sequence[geo.GpsPoint] = []
6363
make = self.options["device_make"]
6464
model = self.options["device_model"]
6565

@@ -84,6 +84,9 @@ def process_file(self, file: Path) -> VideoMetadataOrError:
8484
{**log_vars, "e": e},
8585
)
8686

87+
last_ts = points[-1].unix_timestamp_ms if len(points) > 0 else None
88+
last_unix_ts = int(last_ts/1000) if last_ts else None
89+
8790
# After trying all parsers, return the points if we found any, otherwise
8891
# the last exception thrown or a default one.
8992
# Note that if we have points, we return them, regardless of exceptions
@@ -93,9 +96,10 @@ def process_file(self, file: Path) -> VideoMetadataOrError:
9396
filename=file,
9497
filetype=FileType.VIDEO,
9598
md5sum=None,
96-
points=points,
99+
points=self._gps_points_to_points(points),
97100
make=make,
98101
model=model,
102+
last_unix_ts=last_unix_ts
99103
)
100104
video_metadata.update_md5sum()
101105
return video_metadata
@@ -112,7 +116,7 @@ def process_file(self, file: Path) -> VideoMetadataOrError:
112116

113117
def _extract_points(
114118
self, parser: BaseParser, log_vars: T.Dict
115-
) -> T.Sequence[geo.Point]:
119+
) -> T.Sequence[geo.GpsPoint]:
116120
points = parser.extract_points()
117121
if points:
118122
LOG.debug(
@@ -125,7 +129,7 @@ def _extract_points(
125129
if parser.must_rebase_times_to_zero:
126130
points = self._rebase_times(points)
127131

128-
return self._gps_points_to_points(points)
132+
return points
129133

130134
@staticmethod
131135
def _check_paths(import_paths: T.Sequence[Path]):

schema/image_description_schema.json

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@
4646
"type": "string",
4747
"description": "Device model, e.g. HERO10 Black, DR900S-1CH, Insta360 Titan"
4848
},
49+
"MAPLastUnixTimestamp": {
50+
"type": "integer",
51+
"description": "UNIX timestamp of the last GPS point"
52+
},
4953
"filename": {
5054
"type": "string",
5155
"description": "Absolute path of the video"

0 commit comments

Comments
 (0)