File size: 2,606 Bytes
0a4deb9
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
#!/usr/bin/env python3
"""
Download Video-MME videos from Hugging Face (lmms-lab/Video-MME).

Downloads chunked zip files and extracts them.

Usage:
    python download_videomme.py
    python download_videomme.py --output-dir /path/to/videomme
"""

from __future__ import annotations

import argparse
import zipfile
from pathlib import Path

from huggingface_hub import hf_hub_download

REPO_ID = "lmms-lab/Video-MME"
DEFAULT_OUTPUT = Path("/opt/dlami/nvme/videomme")

VIDEO_ZIPS = [f"videos_chunked_{i:02d}.zip" for i in range(1, 21)]
SUBTITLE_ZIP = "subtitle.zip"


def parse_args() -> argparse.Namespace:
    p = argparse.ArgumentParser(description="Download Video-MME from Hugging Face.")
    p.add_argument("--output-dir", type=Path, default=DEFAULT_OUTPUT)
    p.add_argument("--skip-subtitles", action="store_true")
    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()
    data_dir = args.output_dir / "data"
    sub_dir = args.output_dir / "subtitle"

    existing = sum(1 for f in data_dir.iterdir() if f.suffix in (".mp4", ".MP4", ".mkv")) if data_dir.exists() else 0
    if existing >= 900:
        print(f"[skip] Already have {existing} videos in {data_dir}")
    else:
        print(f"[1/2] Downloading {len(VIDEO_ZIPS)} video chunks...")
        for i, zf in enumerate(VIDEO_ZIPS, 1):
            download_and_extract(zf, data_dir, f"chunk {i}/{len(VIDEO_ZIPS)}")

    if args.skip_subtitles:
        print("[skip] Subtitle download skipped (--skip-subtitles)")
    else:
        existing_subs = sum(1 for f in sub_dir.iterdir() if f.suffix == ".srt") if sub_dir.exists() else 0
        if existing_subs >= 800:
            print(f"[skip] Already have {existing_subs} subtitles in {sub_dir}")
        else:
            print("[2/2] Downloading subtitles...")
            download_and_extract(SUBTITLE_ZIP, sub_dir, "subtitles")

    video_count = sum(1 for f in data_dir.iterdir() if f.suffix in (".mp4", ".MP4", ".mkv")) if data_dir.exists() else 0
    print(f"\nDone. Total videos on disk: {video_count}")
    print(f"  Videos: {data_dir}")
    print(f"  Subtitles: {sub_dir}")


if __name__ == "__main__":
    main()