File size: 3,217 Bytes
82cd523
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
#!/usr/bin/env python3
"""解压 Real-Time Visual Understanding 全部 10 个 zip 到统一目录,
解压成功且 sample 数符合预期后删除原 zip。"""
import os
import sys
import zipfile
from pathlib import Path

ZIP_DIR = Path("/mnt/tokyo-ai/gst/StreamingBench-/Real-Time_Visual_Understanding_zips")
OUT_DIR = Path("/mnt/tokyo-ai/gst/StreamingBench-/Real-Time_Visual_Understanding_videos")
OUT_DIR.mkdir(parents=True, exist_ok=True)

RANGES = [
    "1-50", "51-100", "101-150", "151-200", "201-250",
    "251-300", "301-350", "351-400", "401-450", "451-500",
]


def should_skip(name: str) -> bool:
    # 过滤 macOS 元数据
    if name.startswith("__MACOSX/"):
        return True
    base = os.path.basename(name)
    if base in (".DS_Store",) or base.startswith("._"):
        return True
    return False


def extract_one(zip_path: Path, expected_start: int, expected_end: int) -> tuple[int, int]:
    """返回 (mp4_count, json_count)"""
    mp4_count = 0
    json_count = 0
    with zipfile.ZipFile(zip_path) as z:
        members = [m for m in z.infolist() if not should_skip(m.filename)]
        for m in members:
            target = OUT_DIR / m.filename
            if m.is_dir():
                target.mkdir(parents=True, exist_ok=True)
                continue
            target.parent.mkdir(parents=True, exist_ok=True)
            with z.open(m) as src, open(target, "wb") as dst:
                while True:
                    chunk = src.read(8 * 1024 * 1024)
                    if not chunk:
                        break
                    dst.write(chunk)
            if target.suffix == ".mp4":
                mp4_count += 1
            elif target.suffix == ".json":
                json_count += 1

    # 校验 sample 范围
    expected = expected_end - expected_start + 1
    actual_samples = [d.name for d in OUT_DIR.iterdir()
                      if d.is_dir() and d.name.startswith("sample_")]
    have_in_range = sum(1 for s in actual_samples
                        if expected_start <= int(s.split("_")[1]) <= expected_end)
    if have_in_range != expected:
        raise RuntimeError(
            f"{zip_path.name}: expected {expected} samples in [{expected_start},{expected_end}], "
            f"found {have_in_range}"
        )
    return mp4_count, json_count


def main():
    total_mp4 = 0
    total_json = 0
    for r in RANGES:
        start, end = map(int, r.split("-"))
        zp = ZIP_DIR / f"Real-Time Visual Understanding_{r}.zip"
        if not zp.exists():
            print(f"!! MISSING {zp.name}", flush=True)
            sys.exit(1)
        print(f"=== EXTRACT {r} ===", flush=True)
        mp4, js = extract_one(zp, start, end)
        total_mp4 += mp4
        total_json += js
        print(f"=== EXTRACTED {r} mp4={mp4} json={js} ===", flush=True)
        # 解压并校验通过后删除 zip
        zp.unlink()
        print(f"=== REMOVED {zp.name} ===", flush=True)

    # 最终汇总
    samples = sorted(d for d in os.listdir(OUT_DIR)
                     if d.startswith("sample_"))
    print(f"=== ALL DONE samples={len(samples)} mp4={total_mp4} json={total_json} ===",
          flush=True)


if __name__ == "__main__":
    main()