Skip to content

Commit e7e392c

Browse files
Merge pull request #40 from abhijitnathwani/add-support-for-webm-output
Add support for webm video output via new --video-format option
2 parents 84811ee + f8885b2 commit e7e392c

File tree

2 files changed

+23
-3
lines changed

2 files changed

+23
-3
lines changed

README.md

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -81,10 +81,11 @@ $ git-sim [global options] <subcommand> [subcommand options]
8181

8282
The `[global options]` apply to the overarching `git-sim` simulation itself, including:
8383

84-
`--light-mode`: Use a light mode color scheme instead of default dark mode.
85-
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
86-
`--disable-auto-open, -d`: Disable the automatic opening of the image/video file after generation.
84+
`--light-mode`: Use a light mode color scheme instead of default dark mode.
85+
`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video.
86+
`--disable-auto-open, -d`: Disable the automatic opening of the image/video file after generation.
8787
`--reverse, -r`: Display commit history in the reverse direction.
88+
`--video-format`: Output format for the video file, i.e. `mp4` or `webm`. Default output format is `mp4`.
8889

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

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

@@ -253,6 +260,18 @@ def main():
253260
scene = gs.GitSim(args)
254261
scene.render()
255262

263+
if args.video_format == "webm":
264+
webm_file_path = str(scene.renderer.file_writer.movie_file_path)[:-3] + "webm"
265+
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}"
266+
print("Converting video output to .webm format...")
267+
# Start ffmpeg conversion
268+
p = subprocess.Popen(cmd, shell=True)
269+
p.wait()
270+
# if the conversion is successful, delete the .mp4
271+
if os.path.exists(webm_file_path):
272+
os.remove(scene.renderer.file_writer.movie_file_path)
273+
scene.renderer.file_writer.movie_file_path = webm_file_path
274+
256275
if not args.animate:
257276
video = cv2.VideoCapture(str(scene.renderer.file_writer.movie_file_path))
258277
success, image = video.read()

0 commit comments

Comments
 (0)