diff --git a/README.md b/README.md index 56f1312..270c92f 100644 --- a/README.md +++ b/README.md @@ -81,10 +81,11 @@ $ git-sim [global options] [subcommand options] The `[global options]` apply to the overarching `git-sim` simulation itself, including: -`--light-mode`: Use a light mode color scheme instead of default dark mode. -`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video. -`--disable-auto-open, -d`: Disable the automatic opening of the image/video file after generation. +`--light-mode`: Use a light mode color scheme instead of default dark mode. +`--animate`: Instead of outputting a static image, animate the Git command behavior in a .mp4 video. +`--disable-auto-open, -d`: Disable the automatic opening of the image/video file after generation. `--reverse, -r`: Display commit history in the reverse direction. +`--video-format`: Output format for the video file, i.e. `mp4` or `webm`. Default output format is `mp4`. Animation-only global options (to be used in conjunction with `--animate`): diff --git a/git_sim/__main__.py b/git_sim/__main__.py index 2ae0be0..d802268 100644 --- a/git_sim/__main__.py +++ b/git_sim/__main__.py @@ -5,6 +5,7 @@ import time, datetime import cv2 import git +import subprocess from manim import config, WHITE from manim.utils.file_ops import open_file as open_media_file @@ -98,6 +99,12 @@ def main(): help="Display commit history in the reverse direction", action="store_true", ) + parser.add_argument( + "--video-format", + help="Output format for the animation files. Supports mp4 and webm", + type=str, + default="mp4", + ) subparsers = parser.add_subparsers(dest="subcommand", help="subcommand help") @@ -253,6 +260,18 @@ def main(): scene = gs.GitSim(args) scene.render() + if args.video_format == "webm": + webm_file_path = str(scene.renderer.file_writer.movie_file_path)[:-3] + "webm" + 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}" + print("Converting video output to .webm format...") + # Start ffmpeg conversion + p = subprocess.Popen(cmd, shell=True) + p.wait() + # if the conversion is successful, delete the .mp4 + if os.path.exists(webm_file_path): + os.remove(scene.renderer.file_writer.movie_file_path) + scene.renderer.file_writer.movie_file_path = webm_file_path + if not args.animate: video = cv2.VideoCapture(str(scene.renderer.file_writer.movie_file_path)) success, image = video.read()