File size: 3,969 Bytes
5767e72
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
import json
import os
import argparse
import sys

def check_num_videos(json_path, video_dir):
    """
    Checks if the total number of video files matches the expected count
    based on the input JSON filename.

    json file for i2v task is assumed to contain the string 'i2v'
    """
    # Logic preserved from original script:
    # distinct expected counts for i2v vs t2v based on filename
    if 'i2v' in os.path.basename(json_path).lower():
        expected_count = 5590
    else:
        expected_count = 4720

    print(f"--- Checking counts for: {os.path.basename(json_path)} ---")
    
    # Check if directory exists
    if not os.path.isdir(video_dir):
        print(f"! Error: Directory '{video_dir}' not found.")
        return False

    # Count files ending in .mp4
    files = [f for f in os.listdir(video_dir) if f.lower().endswith('.mp4')]
    actual_count = len(files)

    # Compare and Report
    print(f"Expected videos: {expected_count}")
    print(f"Found videos:    {actual_count}")

    if actual_count == expected_count:
        print("OK! check_num_videos: SUCCESS. Count matches.")
        return True
    else:
        diff = expected_count - actual_count
        if diff > 0:
            print(f"! check_num_videos: FAIL. Missing {diff} videos.")
        else:
            print(f"! check_num_videos: FAIL. Found {abs(diff)} extra videos.")
        return False

def filter_missing_videos(json_path, video_dir, output_path):
    """
    Identifies specifically which entries from the JSON are missing
    corresponding video files in the directory.
    """
    if not os.path.exists(json_path):
        print(f"! Error: Input JSON '{json_path}' not found.")
        return

    try:
        with open(json_path, 'r') as f:
            data = json.load(f)
    except json.JSONDecodeError:
        print(f"! Error: Failed to decode JSON from '{json_path}'.")
        return

    missing_entries = []
    print(f"\n--- Scanning {len(data)} entries against '{video_dir}' ---")

    for entry in data:
        # Adjust key if your json uses something other than 'image_name'
        # Fallback to 'prompt' or other keys if necessary, but using original logic:
        image_name = entry.get('image_name', '') 
        
        if not image_name:
            continue

        # Logic: Convert 'xxx.jpg' -> 'xxx' -> 'xxx-0.mp4'
        base_name = os.path.splitext(image_name)[0]
        expected_video_name = f"{base_name}-0.mp4"
        expected_video_path = os.path.join(video_dir, expected_video_name)
        
        # If video file is NOT found, add the whole entry to our list
        if not os.path.exists(expected_video_path):
            missing_entries.append(entry)

    # Save the missing entries to a new file
    if missing_entries:
        with open(output_path, 'w') as f:
            json.dump(missing_entries, f, indent=4)
        
        print(f"! Found {len(missing_entries)} missing videos.")
        print(f"Data for missing entries saved to: {output_path}")
    else:
        print("OK! All videos exist! No missing entries found.")

if __name__ == "__main__":
    parser = argparse.ArgumentParser(
        description="Check for missing sampled videos against a VBench JSON reference."
    )

    # Positional arguments
    parser.add_argument(
        "json_path",
        type=str,
        help="Path to the original JSON file (e.g., vbench2_i2v_full_info.json)"
    )
    parser.add_argument(
        "video_dir",
        type=str,
        help="Path to the folder containing sampled .mp4 files"
    )

    # Optional argument
    parser.add_argument(
        "--output",
        type=str,
        default="missing_entries.json",
        help="Path to save the resulting JSON of missing entries (default: missing_entries.json)"
    )

    args = parser.parse_args()

    # Run the checks
    check_num_videos(args.json_path, args.video_dir)
    filter_missing_videos(args.json_path, args.video_dir, args.output)