TAO-Amodal / unzip_video.py
chengyenhsieh's picture
Update unzip_video.py
a5f02f6 verified
import os
import shutil # For zip creation and extraction
import zipfile
dataset_root = "./frames"
def zip_and_unzip_videos(dataset_root):
for split in os.listdir(dataset_root):
print('Unzipping {} videos'.format(split))
split_root = os.path.join(dataset_root, split)
for video_dataset in os.listdir(split_root):
if not video_dataset.endswith('.zip'):
continue
print('\tExtracting {}...'.format(video_dataset), end=' ')
video_dataset_root = os.path.join(split_root, video_dataset.replace('.zip', ''))
# *** Unzipping ***
# *** Zipping ***
zip_filename = video_dataset
zip_filepath = os.path.join(split_root, zip_filename) # Zip in the split folder
with zipfile.ZipFile(zip_filepath, 'r') as zipf:
zipf.extractall(video_dataset_root) # Extract to the split folder
os.remove(zip_filepath)
print('Done!')
# Call the function to perform zipping and unzipping
zip_and_unzip_videos(dataset_root)