Skip to content

Commit 0a130b3

Browse files
committed
update sync videos to skip videos with existing alignment
1 parent 18ca7a9 commit 0a130b3

3 files changed

Lines changed: 11 additions & 10 deletions

File tree

packages/cheese3d/cheese3d/config.py

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -318,8 +318,7 @@ def build_regex(regex):
318318
if "view" not in regex:
319319
raise RuntimeError("Regex must contain 'view' key.")
320320
for key, rstr in regex.items():
321-
full_regex = full_regex.replace("{{" + key + "}}", # type: ignore
322-
fr"(?P<{key}>{rstr})")
321+
full_regex = full_regex.replace("{{" + key + "}}", fr"(?P<{key}>{rstr})")
323322
missing_groups = re.match("({{.*}})", full_regex)
324323
if missing_groups:
325324
raise RuntimeError(f"Regex is missing definitions for groups: {missing_groups.groups}")

packages/cheese3d/cheese3d/synchronize/core.py

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -242,12 +242,14 @@ def synchronize_videos(pipeline_cfg: SyncConfig,
242242
threshold=pipeline_cfg.led_threshold,
243243
crop=crop)
244244
pipeline = SyncPipeline.from_cfg(pipeline_cfg, ref_reader, target_reader)
245-
align_param = pipeline.align_recording()
246-
pipeline.write_json(align_param)
247-
frame_lag = int(round(maybe(align_param.lag, 0), 2) * align_param.sample_rate)
248-
align_params[view] = (video,
249-
frame_lag,
250-
align_param.sample_rate)
245+
target_path = pipeline.target.root_path()
246+
if target_path.with_suffix(".align.json").exists():
247+
print(f"alignment file exists, skipping {str(target_path)}...")
248+
else:
249+
align_param = pipeline.align_recording()
250+
pipeline.write_json(align_param)
251+
frame_lag = int(round(maybe(align_param.lag, 0), 2) * align_param.sample_rate)
252+
align_params[view] = (video, frame_lag, align_param.sample_rate)
251253
ref_lag = min(-lag for _, lag, _ in align_params.values())
252254
for video, lag, view_fps in align_params.values():
253255
shift = -lag - ref_lag

packages/cheese3d/cheese3d/synchronize/readers.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ def load_signal(self):
3636
"Instead, inherit from this class to implement "
3737
"a specific sync signal source.")
3838

39-
def root_path(self):
39+
def root_path(self) -> Path:
4040
raise NotImplementedError("Attempt to use SyncSignalReader directly. "
4141
"Instead, inherit from this class to implement "
4242
"a specific sync signal source.")
@@ -171,7 +171,7 @@ def load_signal(self):
171171
led_df = pd.read_csv(self.source, sep="\t", names=["timestamp", "signal"])
172172
analog_signal = led_df["signal"].values
173173
threshold = maybe(self.threshold, 0.1)
174-
analog_signal = np.where(analog_signal > threshold, 1, 0) # type: ignore
174+
analog_signal = np.where(analog_signal > threshold, 1, 0)
175175

176176
return analog_signal
177177

0 commit comments

Comments
 (0)