Skip to content

Added support for webm output #40

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -81,10 +81,11 @@ $ git-sim [global options] <subcommand> [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`):

Expand Down
19 changes: 19 additions & 0 deletions git_sim/__main__.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down Expand Up @@ -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")

Expand Down Expand Up @@ -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()
Expand Down