Skip to content

Commit f4db88b

Browse files
Added support for webm output
Signed-off-by: Abhijit Nathwani <abhijit.nathwani@gmail.com>
1 parent 0357116 commit f4db88b

File tree

2 files changed

+20
-0
lines changed

2 files changed

+20
-0
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -84,6 +84,7 @@ The `[global options]` apply to the overarching `git-sim` simulation itself, inc
8484
`--light-mode`: Use a light mode color scheme instead of default dark mode.
8585
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
8686
`--reverse`: Display commit history in the reverse direction.
87+
`--video-format`: Output format for the video file, i.e. `mp4` or `webm`. Default output format is `mp4`.
8788

8889
Animation-only global options (to be used in conjunction with `--animate`):
8990

git_sim/__main__.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
import time, datetime
66
import cv2
77
import git
8+
import subprocess
89
from manim import config, WHITE
910
from manim.utils.file_ops import open_file as open_media_file
1011

@@ -98,6 +99,12 @@ def main():
9899
help="Display commit history in the reverse direction",
99100
action="store_true",
100101
)
102+
parser.add_argument(
103+
"--video-format",
104+
help="Output format for the animation files. Supports mp4 and webm",
105+
type=str,
106+
default="mp4",
107+
)
101108

102109
subparsers = parser.add_subparsers(dest="subcommand", help="subcommand help")
103110

@@ -248,6 +255,18 @@ def main():
248255
scene = gs.GitSim(args)
249256
scene.render()
250257

258+
if args.video_format == "webm":
259+
webm_file_path = str(scene.renderer.file_writer.movie_file_path)[:-3] + "webm"
260+
cmd = f"ffmpeg -y -i {scene.renderer.file_writer.movie_file_path} -hide_banner -loglevel error -c:v libvpx-vp9 -crf 50 -b:v 0 -b:a 128k -c:a libopus {webm_file_path}"
261+
print("Converting video output to .webm format...")
262+
# Start ffmpeg conversion
263+
p = subprocess.Popen(cmd, shell=True)
264+
p.wait()
265+
# if the conversion is successful, delete the .mp4
266+
if os.path.exists(webm_file_path):
267+
os.remove(scene.renderer.file_writer.movie_file_path)
268+
scene.renderer.file_writer.movie_file_path = webm_file_path
269+
251270
if not args.animate:
252271
video = cv2.VideoCapture(str(scene.renderer.file_writer.movie_file_path))
253272
success, image = video.read()

0 commit comments

Comments
 (0)