| |
| """ |
| Download LVBench videos from Hugging Face (lmms-lab/LVBench). |
| |
| Downloads chunked zip files and extracts them. |
| |
| Usage: |
| python download_lvbench.py |
| python download_lvbench.py --output-dir /path/to/lvbench |
| """ |
|
|
| from __future__ import annotations |
|
|
| import argparse |
| import zipfile |
| from pathlib import Path |
|
|
| from huggingface_hub import hf_hub_download |
|
|
| REPO_ID = "lmms-lab/LVBench" |
| DEFAULT_OUTPUT = Path("/opt/dlami/nvme/lvbench") |
|
|
| VIDEO_ZIPS = [f"video_chunks/videos_chunk_{i:03d}.zip" for i in range(1, 15)] |
|
|
|
|
| def parse_args() -> argparse.Namespace: |
| p = argparse.ArgumentParser(description="Download LVBench from Hugging Face.") |
| p.add_argument("--output-dir", type=Path, default=DEFAULT_OUTPUT) |
| return p.parse_args() |
|
|
|
|
| def download_and_extract(repo_file: str, extract_to: Path, label: str) -> None: |
| extract_to.mkdir(parents=True, exist_ok=True) |
| print(f" Downloading {label}: {repo_file} ...") |
| local_zip = hf_hub_download( |
| repo_id=REPO_ID, filename=repo_file, repo_type="dataset", |
| ) |
| print(f" Extracting to {extract_to} ...") |
| with zipfile.ZipFile(local_zip, "r") as zf: |
| zf.extractall(extract_to) |
| print(f" Done: {repo_file}") |
|
|
|
|
| def main() -> None: |
| args = parse_args() |
| out_dir = args.output_dir |
|
|
| existing = sum(1 for f in out_dir.iterdir() if f.suffix == ".mp4") if out_dir.exists() else 0 |
| if existing >= 100: |
| print(f"[skip] Already have {existing} videos in {out_dir}") |
| else: |
| print(f"Downloading {len(VIDEO_ZIPS)} video chunks...") |
| for i, zf in enumerate(VIDEO_ZIPS, 1): |
| download_and_extract(zf, out_dir, f"chunk {i}/{len(VIDEO_ZIPS)}") |
|
|
| video_count = sum(1 for f in out_dir.iterdir() if f.suffix == ".mp4") if out_dir.exists() else 0 |
| print(f"\nDone. Total videos on disk: {video_count}") |
| print(f" Videos: {out_dir}") |
|
|
|
|
| if __name__ == "__main__": |
| main() |
|
|