Skip to content

Sample a symlinked video into a folder named after the link - #934

Merged
caglarpir merged 2 commits into
mapillary:mainfrom
caglarpir:sample-symlinked-videos-by-their-link
Oct 27, 2026
Merged

caglarpir merged 2 commits into
mapillary:mainfrom
caglarpir:sample-symlinked-videos-by-their-link

Conversation

@caglarpir

Copy link
Copy Markdown
Contributor

Stacked on #933; review the last commit.

video_process DIR OUT, with a symbolic link in DIR to a video outside it, crashed with ValueError: '<target>' is not in the subpath of '<DIR>': the folder of the samples was named after the path of the video relative to DIR, both with their links resolved, and the video resolved to outside DIR. video_process_and_upload and sample_video crashed the same way. Given the link itself, the video was sampled into a folder named after the file it links to, while the samples were named after the link (OUT/video.mp4/link_0_000001.jpg), so that geotagging them by their videos (process OUT --geotag_source blackvue_videos --geotag_source_path DIR) found none of them and failed them all with MapillaryGeoTaggingError, as their names do not start with the name of the folder.

Make the paths absolute without resolving their links, with os.path.abspath(), where the folder of the samples is named (_normalize_path, _sample_dir) and where samples are matched to their videos (find_image_samples): the samples of DIR/link.mp4 are OUT/link.mp4/link_0_000001.jpg, whether DIR or the link is given. Two links to one video are still sampled once, as deduplicate_paths() still tells the videos found apart by their resolved paths. os.path.abspath() makes a path that does not exist absolute on Windows too, which Path.resolve() did not with Python 3.9 and 3.10, so _absolute(), the helper for that, goes.

With a link in DIR to a BlackVue video:

  • video_process DIR OUT --video_sample_distance 50: 6 frames in OUT/link.mp4/, 6 ready (main: the traceback above, exit 1). The same with DIR relative, or given with .. in it; sample_video and video_process_and_upload --dry_run too.
  • By interval every 2 s: 30 frames, with the same positions and times as the same video copied into DIR as a file; then process OUT --geotag_source blackvue_videos --geotag_source_path DIR: 30 ready.
  • video_process DIR/link.mp4 OUT: OUT/link.mp4/link_0_000001.jpg, and geotagging them by the videos in DIR: 6 ready (main: 6 MapillaryGeoTaggingError).
  • DIR itself a link to a folder: as on main, 30 frames in a folder named after the video, all geotagged.

Compared with main on process, video_process and process_and_upload --dry_run, on images and videos of many cameras with the default and other sources, the outputs and exit codes are the same.

Unit and integration tests, doctests, mypy --python-version 3.9, ruff check, ruff format --check and usort diff are clean.

A GPX file was decoded in the encoding of the locale, as v0.14.7 did
with open("r"): cp1252 on Western Windows, cp936 on Chinese Windows.
GPX files are almost always UTF-8. There, a UTF-8 GPX with "Á", "Í",
"Ð", "Ý" or most CJK characters in its names failed with
UnicodeDecodeError, as their bytes are undefined in cp1252, and the
user was told that it is not a valid GPX file; other accented letters
only came out garbled. On Linux and macOS, a GPX in another encoding,
such as ISO-8859-1 with "Café" in a name, failed the same way.

Decode it as UTF-8 with errors="replace", as NMEA logs are, so that a
byte that is not UTF-8 only turns a letter of a name into U+FFFD:
positions and times are ASCII. gpxpy still reads the file opened in
text mode itself, and a byte order mark is still ignored. A UTF-16 GPX
still fails as not a valid GPX file.
video_process DIR OUT, with a symbolic link in DIR to a video outside
it, crashed with "ValueError: '<target>' is not in the subpath of
'<DIR>'": the folder of the samples was named after the path of the
video relative to DIR, both with their links resolved, and the video
resolved to outside DIR. video_process_and_upload and sample_video
crashed the same way. Given the link itself, the video was sampled into
a folder named after the file it links to, while the samples were
named after the link (OUT/video.mp4/link_0_000001.jpg), so
that geotagging them by their videos found none of them, as their names
do not start with the name of the folder.

Make the paths absolute without resolving their links, with
os.path.abspath(), where the folder of the samples is named, and where
samples are matched to their videos: the samples of DIR/link.mp4 are
OUT/link.mp4/link_0_000001.jpg, whether DIR or the link is given. Two
links to one video are still sampled once, as the videos found are
still told apart by their resolved paths. os.path.abspath() makes a
path that does not exist absolute on Windows too, which Path.resolve()
did not with Python 3.9 and 3.10, so the helper for that goes.
@meta-cla meta-cla Bot added the cla signed label Oct 27, 2026
@caglarpir
caglarpir merged commit f4f70a9 into mapillary:main Oct 27, 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