| import argparse |
| import io |
| import json |
| import tarfile |
| from pathlib import Path |
|
|
| from PIL import Image |
|
|
|
|
| def parse_args() -> argparse.Namespace: |
| parser = argparse.ArgumentParser(description="Inspect one Camera Motion tar shard.") |
| parser.add_argument("--tar", type=Path, required=True, help="Path to a tar shard.") |
| parser.add_argument("--limit", type=int, default=2, help="Number of sample ids to inspect.") |
| return parser.parse_args() |
|
|
|
|
| def main() -> None: |
| args = parse_args() |
|
|
| with tarfile.open(args.tar, "r") as tar: |
| members = tar.getnames() |
| sample_ids = [] |
| for name in members: |
| if name.endswith(".json"): |
| sample_ids.append(name.rsplit(".", 1)[0]) |
| if len(sample_ids) >= args.limit: |
| break |
|
|
| print(json.dumps({"tar": str(args.tar), "num_members": len(members), "sample_ids": sample_ids}, indent=2)) |
|
|
| for sample_id in sample_ids: |
| metadata = json.loads(tar.extractfile(f"{sample_id}.json").read().decode("utf-8")) |
| frame_members = [f"{sample_id}.jpg-{i:02d}" for i in range(8)] |
| first_frame = Image.open(io.BytesIO(tar.extractfile(frame_members[0]).read())) |
| print( |
| json.dumps( |
| { |
| "sample_id": sample_id, |
| "frame_members": frame_members, |
| "metadata": metadata, |
| "first_frame_size": first_frame.size, |
| "first_frame_mode": first_frame.mode, |
| }, |
| indent=2, |
| ) |
| ) |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|