manim/scripts/extract_frames.py
adeshpande 252aac30da
Add Ruff Lint (#3780)
Adds Ruff Linting to CI, and replaces isort in the pre-commit config with Ruff's isort rules.

Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>

---------

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
2024-06-03 23:39:08 -04:00

44 lines
1.1 KiB
Python

from __future__ import annotations
import pathlib
import sys
import numpy as np
from PIL import Image
def main():
if len(sys.argv) != 3:
print_usage()
sys.exit(1)
npz_file = sys.argv[1]
output_folder = pathlib.Path(sys.argv[2])
if not output_folder.exists():
output_folder.mkdir(parents=True)
data = np.load(npz_file)
if "frame_data" not in data:
print("The given file did not have frame_data.")
print("Are you sure this is from a Manim Graphical Unit Test?")
sys.exit(2)
frames = data["frame_data"]
for i, frame in enumerate(frames):
img = Image.fromarray(frame)
img.save(output_folder / f"frame{i}.png")
print(f"Saved {len(frames)} frames to {output_folder}")
def print_usage():
print("Manim Graphical Test Frame Extractor")
print(
"This tool outputs the frames of a Graphical Unit Test "
"stored within a .npz file, typically found under "
r"//tests/test_graphical_units/control_data"
)
print()
print("usage:")
print("python3 extract_frames.py npz_file output_directory")
if __name__ == "__main__":
main()