import os n = int(input("Store every nth frames, n=")) try: from PIL import Image except ImportError: resp = input("This script requires Python Pillow. Install? [y/n]") if resp.lower() == "y": import subprocess import sys subprocess.check_call([sys.executable, '-m', 'pip', 'install', 'Pillow']) from PIL import Image else: import sys sys.exit() def split_webp(webp_path, dest_prefix): os.makedirs(os.path.dirname(dest_prefix), exist_ok=True) webp = Image.open(webp_path) for i in range(0, webp.n_frames, n): webp.seek(i) webp.save(f"{dest_prefix}.{i:03}.png") directory = os.path.dirname(__file__) for root, dirs, files in os.walk(directory): for fn in files: if not fn.lower().endswith('.webp'): continue webp_path = os.path.join(root, fn) dir_path = os.path.relpath(webp_path, directory) dest_prefix = os.path.join(directory, "frames", dir_path) print('splitting', os.path.relpath(webp_path, directory)) split_webp(webp_path, dest_prefix) input('Press enter to close')