#!/usr/bin/env python3 """Validate WildShadow-Video paths, frame counts, and paired dimensions.""" from __future__ import annotations import argparse import csv import json import subprocess from concurrent.futures import ThreadPoolExecutor, as_completed from pathlib import Path def probe(path: Path) -> tuple[int, int, int, str]: payload = json.loads(subprocess.check_output([ "ffprobe", "-v", "error", "-select_streams", "v:0", "-count_frames", "-show_entries", "stream=width,height,nb_read_frames,pix_fmt", "-of", "json", str(path), ])) stream = payload["streams"][0] return int(stream["width"]), int(stream["height"]), int(stream["nb_read_frames"]), stream["pix_fmt"] def validate_row(root: Path, row: dict[str, str]) -> str | None: shadow = root / row["shadow_video"] target = root / row["shadow_free_video"] try: a = probe(shadow) b = probe(target) expected = int(row["frame_count"]) if a[:3] != b[:3] or a[2] != expected: return f"{row['clip_id']}: shadow={a}, shadow_free={b}, expected={expected}" except Exception as error: return f"{row['clip_id']}: {error}" return None def main() -> None: parser = argparse.ArgumentParser(description=__doc__) parser.add_argument("--root", type=Path, default=Path(__file__).resolve().parents[1]) parser.add_argument("--workers", type=int, default=16) args = parser.parse_args() manifest = args.root / "manifests" / "clips.csv" failures = [] with manifest.open(newline="", encoding="utf-8") as handle: rows = list(csv.DictReader(handle)) with ThreadPoolExecutor(max_workers=args.workers) as pool: futures = [pool.submit(validate_row, args.root, row) for row in rows] for index, future in enumerate(as_completed(futures), 1): failure = future.result() if failure: failures.append(failure) if index % 100 == 0 or index == len(rows): print(f"Validated {index}/{len(rows)}", flush=True) print(f"Validated {len(rows)} clips: {len(failures)} failures") if failures: print("\n".join(failures[:50])) raise SystemExit(1) if __name__ == "__main__": main()