VidDiffBench / download_videos.py
viddiff's picture
Update download_videos.py
04e411e verified
raw
history blame
1.37 kB
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)