Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Enabling transparent background of exported videos

Grant Sandersond3a39f2e65ba
diff --git a/extract_scene.py b/extract_scene.py
index 0d21e8a74..cec13bdf8 100644
--- a/extract_scene.py
+++ b/extract_scene.py
@@ -95,6 +95,7 @@ def get_configuration():
"save_pngs" : args.save_pngs,
#If -t is passed in (for transparent), this will be RGBA
"saved_image_mode": "RGBA" if args.transparent else "RGB",
+ "movie_file_extension" : ".mov" if args.transparent else ".mp4",
"quiet" : args.quiet or args.write_all,
"ignore_waits" : args.preview,
"write_all" : args.write_all,
@@ -237,6 +238,7 @@ def main():
"write_to_movie",
"output_directory",
"save_pngs",
+ "movie_file_extension",
"start_at_animation_number",
"end_at_animation_number",
]
diff --git a/scene/scene.py b/scene/scene.py
index 5a4714853..09c6ffa1e 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -570,18 +570,23 @@ class Scene(Container):
FFMPEG_BIN,
'-y', # overwrite output file if it exists
'-f', 'rawvideo',
- '-vcodec','rawvideo',
'-s', '%dx%d'%(width, height), # size of one frame
'-pix_fmt', 'rgba',
'-r', str(fps), # frames per second
'-i', '-', # The imput comes from a pipe
'-an', # Tells FFMPEG not to expect any audio
- '-vcodec', 'mpeg',
- '-c:v', 'libx264',
- '-pix_fmt', 'yuv420p',
'-loglevel', 'error',
- temp_file_path,
]
+ if self.movie_file_extension == ".mov":
+ # This is if the background of the exported video
+ # should be transparent.
+ command += ['-vcodec', 'png']
+ else:
+ command += [
+ '-c:v', 'libx264',
+ '-pix_fmt', 'yuv420p',
+ ]
+ command += [temp_file_path]
# self.writing_process = sp.Popen(command, stdin=sp.PIPE, shell=True)
self.writing_process = sp.Popen(command, stdin=sp.PIPE)