-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathcleanup_dataset_videos.py
More file actions
69 lines (54 loc) · 2.62 KB
/
Copy pathcleanup_dataset_videos.py
File metadata and controls
69 lines (54 loc) · 2.62 KB
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
import os
import glob
import pandas as pd
def cleanup_videos(dataset_csv, start_edition, end_edition, base_video_dir):
"""
Deletes .mp4 files in edition folders that are NOT listed in the dataset CSV.
"""
if not os.path.exists(dataset_csv):
print(f"[ERROR] Dataset CSV not found at: {dataset_csv}")
return
print(f"[INFO] Loading dataset from {dataset_csv}...")
df = pd.read_csv(dataset_csv)
# The 'filename' column contains paths like 'edition19/edition19_sequence_13.mp4'
allowed_filenames = set(df['filename'].tolist())
print(f"[INFO] Starting cleanup for Editions {start_edition} to {end_edition}...")
total_deleted = 0
for i in range(start_edition, end_edition + 1):
edition_folder_name = f"edition{i}"
edition_path = os.path.join(base_video_dir, edition_folder_name)
if not os.path.exists(edition_path):
# Check if zip exists (just for logging)
if os.path.exists(f"{edition_path}.zip"):
print(f"[SKIP] {edition_folder_name}: Folder not found, but ZIP exists.")
continue
print(f"[INFO] Checking {edition_folder_name}...")
# Get all mp4 files in this edition folder
video_files = glob.glob(os.path.join(edition_path, "*.mp4"))
edition_deleted = 0
for file_path in video_files:
vid_name = os.path.basename(file_path)
# Reconstruct the relative path as it appears in the CSV
rel_path = f"{edition_folder_name}/{vid_name}"
if rel_path not in allowed_filenames:
try:
os.remove(file_path)
print(f" [DELETE] {rel_path}")
edition_deleted += 1
except Exception as e:
print(f" [ERROR] Error deleting {rel_path}: {e}")
if edition_deleted > 0:
print(f" [DONE] Deleted {edition_deleted} unlisted videos in {edition_folder_name}.")
else:
print(f" [CLEAN] {edition_folder_name}: All files match CSV or folder already clean.")
total_deleted += edition_deleted
print("==================================================")
print(f"[FINISH] Cleanup complete. Total videos deleted: {total_deleted}")
print("==================================================")
if __name__ == "__main__":
# CONFIGURATION
DATASET_PATH = r"Data\final_skeleton_dataset.csv"
START_EDITION = 19
END_EDITION = 30
BASE_VIDEO_DIR = "videos"
cleanup_videos(DATASET_PATH, START_EDITION, END_EDITION, BASE_VIDEO_DIR)