viddiff commited on
Commit
7f08f38
1 Parent(s): 0de2e27

Create download_videos.py

Browse files
Files changed (1) hide show
  1. download_videos.py +39 -0
download_videos.py ADDED
@@ -0,0 +1,39 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ from huggingface_hub import hf_hub_download
2
+ import zipfile
3
+ import os
4
+
5
+ def download_and_extract_videos(dataset_name, output_dir, split):
6
+ # Create output directory if it doesn't exist
7
+ os.makedirs(output_dir, exist_ok=True)
8
+
9
+ # Download the zip file
10
+ # print(f"Downloading {zip_filename} from the dataset...")
11
+ zip_path = hf_hub_download(
12
+ repo_id=dataset_name,
13
+ filename=f"data/videos_{split}.zip",
14
+ repo_type="dataset",
15
+ local_dir=output_dir,
16
+ )
17
+
18
+ # Extract the zip file
19
+ with zipfile.ZipFile(zip_path, 'r') as zip_ref:
20
+ for file_info in zip_ref.infolist():
21
+ extracted_path = os.path.join(output_dir, file_info.filename)
22
+ if file_info.filename.endswith('/'):
23
+ os.makedirs(extracted_path, exist_ok=True)
24
+ else:
25
+ os.makedirs(os.path.dirname(extracted_path), exist_ok=True)
26
+ with zip_ref.open(file_info) as source, open(extracted_path, "wb") as target:
27
+ target.write(source.read())
28
+
29
+ print(f"Videos extracted to {output_dir}")
30
+
31
+ # Optional: Remove the downloaded zip file
32
+ # os.remove(zip_path)
33
+
34
+ # Usage
35
+ dataset_name = "viddiff/viddif_4"
36
+ output_dir = "."
37
+ splits = ("demo", "easy")
38
+ for split in splits:
39
+ download_and_extract_videos(dataset_name, output_dir, split)