From f4db88bd30d9422b58e19dd8291f06d62f5c2653 Mon Sep 17 00:00:00 2001 From: Abhijit Nathwani Date: Sun, 29 Jan 2023 17:05:15 +0530 Subject: [PATCH] Added support for webm output Signed-off-by: Abhijit Nathwani --- README.md | 1 + git_sim/__main__.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+) diff --git a/README.md b/README.md index 121f8f2..0847402 100644 --- a/README.md +++ b/README.md @@ -84,6 +84,7 @@ The `[global options]` apply to the overarching `git-sim` simulation itself, inc `--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. `--reverse`: 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 7839396..ee2201f 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") @@ -248,6 +255,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()