Skip to content

Commit f7b4d57

Browse files
Generate jpg from first frame of manim animation and display by default
Signed-off-by: Jacob Stopak <jacob@initialcommit.io>
1 parent e582f73 commit f7b4d57

File tree

2 files changed

+17
-2
lines changed

2 files changed

+17
-2
lines changed

git_sim/__main__.py

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
import os
44
import argparse
55
import pathlib
6+
import time, datetime
7+
import cv2
68
from manim import config, WHITE
79
from manim.utils.file_ops import open_file as open_media_file
810

@@ -57,8 +59,20 @@ def main():
5759
scene = gs.GitSim(args)
5860
scene.render()
5961

62+
if not args.animate:
63+
video = cv2.VideoCapture(str(scene.renderer.file_writer.movie_file_path))
64+
success, image = video.read()
65+
if success:
66+
t = datetime.datetime.fromtimestamp(time.time()).strftime("%m-%d-%y_%H-%M-%S")
67+
image_file_name = "git-sim-" + args.subcommand + "_" + t + ".jpg"
68+
image_file_path = os.path.join(os.path.join(config.media_dir, "images"), image_file_name)
69+
cv2.imwrite(image_file_path, image)
70+
6071
try:
61-
open_media_file(scene.renderer.file_writer.movie_file_path)
72+
if not args.animate:
73+
open_media_file(image_file_path)
74+
else:
75+
open_media_file(scene.renderer.file_writer.movie_file_path)
6276
except FileNotFoundError:
6377
print("Error automatically opening video player, please manually open the video file to view animation.")
6478

setup.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,8 @@
2121
python_requires='>=3.7',
2222
install_requires=[
2323
'gitpython',
24-
'manim'
24+
'manim',
25+
'opencv-python',
2526
],
2627
keywords='git sim simulation simulate git-simulate git-simulation git-sim manim animation gitanimation',
2728
project_urls={

0 commit comments

Comments
 (0)