-
Notifications
You must be signed in to change notification settings - Fork 143
Expand file tree
/
Copy pathblackvue_parser.py
More file actions
46 lines (33 loc) · 1.2 KB
/
blackvue_parser.py
File metadata and controls
46 lines (33 loc) · 1.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
from __future__ import annotations
import argparse
import pathlib
import gpxpy
import gpxpy.gpx
from mapillary_tools import geo, utils
from mapillary_tools.geotag import blackvue_parser, utils as geotag_utils
def _parse_gpx(path: pathlib.Path) -> list[geo.Point] | None:
with path.open("rb") as fp:
points = blackvue_parser.extract_points(fp)
return points
def _convert_to_track(path: pathlib.Path):
track = gpxpy.gpx.GPXTrack()
points = _parse_gpx(path)
if points is None:
raise RuntimeError(f"Invalid BlackVue video {path}")
segment = geotag_utils.convert_points_to_gpx_segment(points)
track.segments.append(segment)
with path.open("rb") as fp:
model = blackvue_parser.extract_camera_model(fp)
track.description = f"Extracted from {model}"
track.name = path.name
return track
def main():
parser = argparse.ArgumentParser()
parser.add_argument("blackvue_video_path", nargs="+")
parsed = parser.parse_args()
gpx = gpxpy.gpx.GPX()
for p in utils.find_videos([pathlib.Path(p) for p in parsed.blackvue_video_path]):
gpx.tracks.append(_convert_to_track(p))
print(gpx.to_xml())
if __name__ == "__main__":
main()