From d3a39f2e65ba1a448846776f26926f4de06de708 Mon Sep 17 00:00:00 2001 From: Grant Sanderson Date: Tue, 20 Feb 2018 14:03:59 -0800 Subject: [PATCH] Enabling transparent background of exported videos --- extract_scene.py | 2 ++ scene/scene.py | 15 ++++++++++----- 2 files changed, 12 insertions(+), 5 deletions(-) diff --git a/extract_scene.py b/extract_scene.py index 0d21e8a7..cec13bdf 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 5a471485..09c6ffa1 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)