File size: 1,374 Bytes
7f08f38
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
04e411e
7f08f38
04e411e
7f08f38
 
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
from huggingface_hub import hf_hub_download
import zipfile
import os

def download_and_extract_videos(dataset_name, output_dir, split):
    # Create output directory if it doesn't exist
    os.makedirs(output_dir, exist_ok=True)

    # Download the zip file
    # print(f"Downloading {zip_filename} from the dataset...")
    zip_path = hf_hub_download(
        repo_id=dataset_name,
        filename=f"data/videos_{split}.zip",
        repo_type="dataset",
        local_dir=output_dir,
    )

    # Extract the zip file
    with zipfile.ZipFile(zip_path, 'r') as zip_ref:
        for file_info in zip_ref.infolist():
            extracted_path = os.path.join(output_dir, file_info.filename)
            if file_info.filename.endswith('/'):
                os.makedirs(extracted_path, exist_ok=True)
            else:
                os.makedirs(os.path.dirname(extracted_path), exist_ok=True)
                with zip_ref.open(file_info) as source, open(extracted_path, "wb") as target:
                    target.write(source.read())

    print(f"Videos extracted to {output_dir}")

    # Optional: Remove the downloaded zip file
    # os.remove(zip_path)

# Usage
dataset_name = "viddiff/VidDiffBench"
output_dir = "."
splits = ['ballsports', 'music', 'diving', 'fitness', 'surgery']
for split in splits: 
    download_and_extract_videos(dataset_name, output_dir, split)