Skip to content

Commit ca2de86

Browse files
committed
Remove dead code: unused functions, deprecated options, and unreachable code
- Remove unused extract_camera_model() from gpmf_parser.py and blackvue_parser.py (superseded by extract_gopro_info() and extract_blackvue_info()) - Remove deprecated --video_sample_interval and --video_duration_ratio CLI options (deprecated since v0.10.0), along with the _sample_single_video_by_interval() function, xor() helper, and related constants - Remove dead rich logging code path in utils.py (unconditional raise ImportError made it unreachable) - Remove deprecated MAPMetaTags field from types.py, schema, and JSON schema (deprecated since v0.10.0, never set in production) - Remove commented-out ffmpeg options from ffmpeg.py - Update tests to reflect removed features
1 parent abc0056 commit ca2de86

16 files changed

Lines changed: 20 additions & 277 deletions

mapillary_tools/blackvue_parser.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -76,17 +76,6 @@ def extract_blackvue_info(fp: T.BinaryIO) -> BlackVueInfo | None:
7676
return BlackVueInfo(model=model, gps=points)
7777

7878

79-
def extract_camera_model(fp: T.BinaryIO) -> str:
80-
try:
81-
cprt_bytes = sparser.parse_mp4_data_first(fp, [b"free", b"cprt"])
82-
except sparser.ParsingError:
83-
return ""
84-
85-
if cprt_bytes is None:
86-
return ""
87-
88-
return _extract_camera_model_from_cprt(cprt_bytes)
89-
9079

9180
def _extract_camera_model_from_cprt(cprt_bytes: bytes) -> str:
9281
"""

mapillary_tools/commands/sample_video.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -25,20 +25,6 @@ def add_basic_arguments(self, parser: argparse.ArgumentParser):
2525
type=float,
2626
required=False,
2727
)
28-
group.add_argument(
29-
"--video_sample_interval",
30-
help="[DEPRECATED since v0.10.0] Time interval, in seconds, for sampling video frames. Since v0.10.0 you must disable distance-sampling with --video_sample_distance=-1 in order to apply this option. [default: %(default)s]",
31-
default=constants.VIDEO_SAMPLE_INTERVAL,
32-
type=float,
33-
required=False,
34-
)
35-
group.add_argument(
36-
"--video_duration_ratio",
37-
help="[DEPRECATED since v0.10.0] Real time video duration ratio of the under or oversampled video duration. [default: %(default)s]",
38-
type=float,
39-
default=constants.VIDEO_DURATION_RATIO,
40-
required=False,
41-
)
4228
group.add_argument(
4329
"--video_start_time",
4430
help="Video start time specified in YYYY_MM_DD_HH_MM_SS_sss in UTC. For example 2020_12_28_12_36_36_508 represents 2020-12-28T12:36:36.508Z.",

mapillary_tools/constants.py

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -87,11 +87,8 @@ def _parse_scaled_integers(
8787
############################
8888
##### VIDEO PROCESSING #####
8989
############################
90-
# In seconds
91-
VIDEO_SAMPLE_INTERVAL = float(os.getenv(_ENV_PREFIX + "VIDEO_SAMPLE_INTERVAL", -1))
9290
# In meters
9391
VIDEO_SAMPLE_DISTANCE = float(os.getenv(_ENV_PREFIX + "VIDEO_SAMPLE_DISTANCE", 3))
94-
VIDEO_DURATION_RATIO = float(os.getenv(_ENV_PREFIX + "VIDEO_DURATION_RATIO", 1))
9592
FFPROBE_PATH: str = os.getenv(_ENV_PREFIX + "FFPROBE_PATH", "ffprobe")
9693
FFMPEG_PATH: str = os.getenv(_ENV_PREFIX + "FFMPEG_PATH", "ffmpeg")
9794
EXIFTOOL_PATH: str = os.getenv(_ENV_PREFIX + "EXIFTOOL_PATH", "exiftool")

mapillary_tools/ffmpeg.py

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -279,22 +279,11 @@ def extract_specified_frames(
279279
*["-filter_script:v", select_file.name],
280280
# Each frame is passed with its timestamp from the demuxer to the muxer
281281
*["-vsync", "0"],
282-
# vsync is deprecated by fps_mode,
283-
# but fps_mode is not avaliable on some older versions ;(
284-
# *[f"-fps_mode:{stream_specifier}", "passthrough"],
285282
# Set the number of video frames to output (this is an optimization to let ffmpeg stop early)
286283
*["-frames:v", str(len(frame_indices))],
287-
# Disabled because it doesn't always name the sample images as expected
288-
# For example "select(n\,1)" we expected the first sample to be IMG_001.JPG
289-
# but it could be IMG_005.JPG
290-
# https://www.ffmpeg.org/ffmpeg-formats.html#Options-21
291-
# If set to 1, expand the filename with pts from pkt->pts. Default value is 0.
292-
# *["-frame_pts", "1"],
293284
],
294285
# Video quality level (or the alias -q:v)
295-
# -q:v=1 is the best quality but larger image sizes
296286
# see https://stackoverflow.com/a/10234065
297-
# *["-qscale:v", "1", "-qmin", "1"],
298287
*["-qscale:v", "2"],
299288
# output
300289
output_template,

mapillary_tools/gpmf/gpmf_parser.py

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -218,21 +218,6 @@ def extract_gopro_info(
218218
return None
219219

220220

221-
def extract_camera_model(fp: T.BinaryIO) -> str:
222-
moov = MovieBoxParser.parse_stream(fp)
223-
for track in moov.extract_tracks():
224-
if _contains_gpmd_description(track):
225-
gpmd_samples = _filter_gpmd_samples(track)
226-
dvnm_by_dvid: dict[int, bytes] = {}
227-
device_found = _load_telemetry_from_samples(
228-
fp, gpmd_samples, dvnm_by_dvid=dvnm_by_dvid
229-
)
230-
if not device_found:
231-
return ""
232-
return _extract_camera_model_from_devices(dvnm_by_dvid)
233-
234-
return ""
235-
236221

237222
def _gps5_timestamp_to_epoch_time(dtstr: str):
238223
# yymmddhhmmss.sss

mapillary_tools/sample_video.py

Lines changed: 8 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -44,28 +44,21 @@ def _normalize_path(
4444
return video_dir, video_list
4545

4646

47-
def xor(a: bool, b: bool):
48-
# xor https://stackoverflow.com/a/433161
49-
return bool(a) ^ bool(b)
50-
51-
5247
def sample_video(
5348
video_import_path: Path,
5449
import_path: Path,
5550
# None if called from the sample_video command
5651
skip_subfolders=False,
5752
video_sample_distance=constants.VIDEO_SAMPLE_DISTANCE,
58-
video_sample_interval=constants.VIDEO_SAMPLE_INTERVAL,
59-
video_duration_ratio=constants.VIDEO_DURATION_RATIO,
6053
video_start_time: str | None = None,
6154
skip_sample_errors: bool = False,
6255
rerun: bool = False,
6356
) -> None:
6457
video_dir, video_list = _normalize_path(video_import_path, skip_subfolders)
6558

66-
if not xor(0 <= video_sample_distance, 0 < video_sample_interval):
59+
if video_sample_distance < 0:
6760
raise exceptions.MapillaryBadParameterError(
68-
f"Expect either non-negative video_sample_distance or positive video_sample_interval but got {video_sample_distance} and {video_sample_interval} respectively"
61+
f"Expect non-negative video_sample_distance but got {video_sample_distance}"
6962
)
7063

7164
video_start_time_dt: datetime.datetime | None = None
@@ -106,24 +99,12 @@ def sample_video(
10699
continue
107100

108101
try:
109-
if 0 <= video_sample_distance:
110-
_sample_single_video_by_distance(
111-
video_path,
112-
sample_dir,
113-
sample_distance=video_sample_distance,
114-
start_time=video_start_time_dt,
115-
)
116-
else:
117-
assert 0 < video_sample_interval, (
118-
"expect positive video_sample_interval but got {video_sample_interval}"
119-
)
120-
_sample_single_video_by_interval(
121-
video_path,
122-
sample_dir,
123-
sample_interval=video_sample_interval,
124-
duration_ratio=video_duration_ratio,
125-
start_time=video_start_time_dt,
126-
)
102+
_sample_single_video_by_distance(
103+
video_path,
104+
sample_dir,
105+
sample_distance=video_sample_distance,
106+
start_time=video_start_time_dt,
107+
)
127108
except ffmpeglib.FFmpegNotFoundError as ex:
128109
# fatal error
129110
raise exceptions.MapillaryFFmpegNotFoundError(str(ex)) from ex
@@ -179,40 +160,6 @@ def wip_sample_dir(sample_dir: Path) -> Path:
179160
)
180161

181162

182-
def _sample_single_video_by_interval(
183-
video_path: Path,
184-
sample_dir: Path,
185-
sample_interval: float,
186-
duration_ratio: float,
187-
start_time: datetime.datetime | None = None,
188-
) -> None:
189-
ffmpeg = ffmpeglib.FFMPEG(constants.FFMPEG_PATH, constants.FFPROBE_PATH)
190-
191-
if start_time is None:
192-
start_time = ffmpeglib.Probe(
193-
ffmpeg.probe_format_and_streams(video_path)
194-
).probe_video_start_time()
195-
if start_time is None:
196-
raise exceptions.MapillaryVideoError(
197-
f"Unable to extract video start time from {video_path}"
198-
)
199-
200-
with wip_dir_context(wip_sample_dir(sample_dir), sample_dir) as wip_dir:
201-
ffmpeg.extract_frames_by_interval(video_path, wip_dir, sample_interval)
202-
frame_samples = ffmpeglib.FFMPEG.sort_selected_samples(wip_dir, video_path)
203-
for frame_idx_1based, sample_paths in frame_samples:
204-
assert len(sample_paths) == 1
205-
if sample_paths[0] is None:
206-
continue
207-
# extract_frames() produces 1-based frame indices so we need to subtract 1 here
208-
seconds = (frame_idx_1based - 1) * sample_interval * duration_ratio
209-
timestamp = start_time + datetime.timedelta(seconds=seconds)
210-
exif_edit = ExifEdit(sample_paths[0])
211-
exif_edit.add_date_time_original(timestamp)
212-
exif_edit.add_gps_datetime(timestamp)
213-
exif_edit.write()
214-
215-
216163
def _within_track_time_range_buffered(points, t: float) -> bool:
217164
# apply 1ms buffer, which is MAPCaptureTime's precision
218165
start_point_time = points[0].time - 0.001

mapillary_tools/serializer/description.py

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,8 +147,6 @@ class ErrorDescription(TypedDict, total=False):
147147
"description": "Arbitrary key for grouping images",
148148
"pattern": "[a-zA-Z0-9_-]+",
149149
},
150-
# deprecated since v0.10.0; keep here for compatibility
151-
"MAPMetaTags": {"type": "object"},
152150
"MAPDeviceMake": {"type": "string"},
153151
"MAPDeviceModel": {"type": "string"},
154152
"MAPGPSAccuracyMeters": {"type": "number"},
@@ -439,7 +437,7 @@ def _as_image_desc(cls, metadata: ImageMetadata) -> ImageDescription:
439437
value = getattr(metadata, field.name)
440438
if value is not None:
441439
# ignore error: TypedDict key must be a string literal;
442-
# expected one of ("MAPMetaTags", "MAPDeviceMake", "MAPDeviceModel", "MAPGPSAccuracyMeters", "MAPCameraUUID", ...)
440+
# expected one of ("MAPDeviceMake", "MAPDeviceModel", "MAPGPSAccuracyMeters", "MAPCameraUUID", ...)
443441
desc[field.name] = value # type: ignore
444442
return desc
445443

mapillary_tools/types.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,6 @@ class ImageMetadata(geo.Point):
5050
MAPGPSAccuracyMeters: float | None = None
5151
MAPCameraUUID: str | None = None
5252
MAPOrientation: int | None = None
53-
MAPMetaTags: dict | None = None
5453
MAPFilename: str | None = None
5554

5655
def update_md5sum(self, image_data: T.BinaryIO | None = None) -> None:

mapillary_tools/utils.py

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -260,20 +260,12 @@ def configure_logger(
260260

261261
logger.setLevel(level)
262262

263-
try:
264-
# Disable globally for now. TODO Disable it in non-interactive mode only
265-
raise ImportError
266-
from rich.console import Console # type: ignore[import]
267-
from rich.logging import RichHandler # type: ignore[import]
268-
except ImportError:
269-
formatter = logging.Formatter(
270-
"%(asctime)s.%(msecs)03d - %(levelname)-7s - %(message)s",
271-
datefmt="%H:%M:%S",
272-
)
273-
handler: logging.Handler = logging.StreamHandler()
274-
handler.setFormatter(formatter)
275-
else:
276-
handler = RichHandler(console=Console(stderr=True), rich_tracebacks=True) # type: ignore
263+
formatter = logging.Formatter(
264+
"%(asctime)s.%(msecs)03d - %(levelname)-7s - %(message)s",
265+
datefmt="%H:%M:%S",
266+
)
267+
handler: logging.Handler = logging.StreamHandler()
268+
handler.setFormatter(formatter)
277269

278270
logger.addHandler(handler)
279271

schema/image_description_schema.json

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -139,9 +139,6 @@
139139
"description": "Arbitrary key for grouping images",
140140
"pattern": "[a-zA-Z0-9_-]+"
141141
},
142-
"MAPMetaTags": {
143-
"type": "object"
144-
},
145142
"MAPDeviceMake": {
146143
"type": "string"
147144
},

0 commit comments

Comments
 (0)