Update extract_scene.py args to better support previewing, showing in finder, opening output files, etc.

This commit is contained in:
Grant Sanderson 2018-01-19 17:31:31 -08:00
parent 4919dbf652
commit 4e468af656
2 changed files with 38 additions and 24 deletions

View file

@ -9,6 +9,7 @@ import inspect
import traceback import traceback
import imp import imp
import os import os
import subprocess as sp
from helpers import * from helpers import *
from scene import Scene from scene import Scene
@ -58,7 +59,8 @@ def get_configuration():
("-s", "--show_last_frame"), ("-s", "--show_last_frame"),
("-l", "--low_quality"), ("-l", "--low_quality"),
("-m", "--medium_quality"), ("-m", "--medium_quality"),
("-f", "--save_pngs"), ("-g", "--save_pngs"),
("-f", "--show_file_in_finder"),
("-t", "--transparent"), ("-t", "--transparent"),
("-q", "--quiet"), ("-q", "--quiet"),
("-a", "--write_all") ("-a", "--write_all")
@ -74,11 +76,10 @@ def get_configuration():
config = { config = {
"file" : args.file, "file" : args.file,
"scene_name" : args.scene_name, "scene_name" : args.scene_name,
"camera_config" : PRODUCTION_QUALITY_CAMERA_CONFIG, #TODO "open_video_upon_completion" : args.preview,
"frame_duration" : PRODUCTION_QUALITY_FRAME_DURATION, #TODO "show_file_in_finder" : args.show_file_in_finder,
"preview" : args.preview, #By default, write to file
"write_to_movie" : args.write_to_movie, "write_to_movie" : args.write_to_movie or not args.show_last_frame,
"save_frames" : args.preview, #Scenes only save frame when previewing
"show_last_frame" : args.show_last_frame, "show_last_frame" : args.show_last_frame,
"save_pngs" : args.save_pngs, "save_pngs" : args.save_pngs,
#If -t is passed in (for transparent), this will be RGBA #If -t is passed in (for transparent), this will be RGBA
@ -88,7 +89,7 @@ def get_configuration():
"output_name" : args.output_name, "output_name" : args.output_name,
"skip_to_animation_number" : args.skip_to_animation_number, "skip_to_animation_number" : args.skip_to_animation_number,
} }
if args.low_quality or args.preview: if args.low_quality:
config["camera_config"] = LOW_QUALITY_CAMERA_CONFIG config["camera_config"] = LOW_QUALITY_CAMERA_CONFIG
config["frame_duration"] = LOW_QUALITY_FRAME_DURATION config["frame_duration"] = LOW_QUALITY_FRAME_DURATION
elif args.medium_quality: elif args.medium_quality:
@ -102,10 +103,6 @@ def get_configuration():
if stan is not None: if stan is not None:
config["skip_to_animation_number"] = int(stan) config["skip_to_animation_number"] = int(stan)
#By default, write to file
actions = ["write_to_movie", "preview", "show_last_frame"]
if not any([config[key] for key in actions]):
config["write_to_movie"] = True
config["skip_animations"] = any([ config["skip_animations"] = any([
config["show_last_frame"] and not config["write_to_movie"], config["show_last_frame"] and not config["write_to_movie"],
config["skip_to_animation_number"], config["skip_to_animation_number"],
@ -117,12 +114,23 @@ def handle_scene(scene, **config):
curr_stdout = sys.stdout curr_stdout = sys.stdout
sys.stdout = open(os.devnull, "w") sys.stdout = open(os.devnull, "w")
if config["preview"]:
scene.preview()
if config["show_last_frame"]: if config["show_last_frame"]:
if not config["write_all"]:
scene.show_frame()
scene.save_image(mode = config["saved_image_mode"]) scene.save_image(mode = config["saved_image_mode"])
open_file = any([
config["show_last_frame"],
config["open_video_upon_completion"],
config["show_file_in_finder"]
])
if open_file:
commands = ["open"]
if config["show_file_in_finder"]:
commands.append("-R")
#
if config["show_last_frame"]:
commands.append(scene.get_image_file_path())
else:
commands.append(scene.get_movie_file_path())
sp.call(commands)
if config["quiet"]: if config["quiet"]:
sys.stdout.close() sys.stdout.close()
@ -209,7 +217,6 @@ def main():
"frame_duration", "frame_duration",
"skip_animations", "skip_animations",
"write_to_movie", "write_to_movie",
"save_frames",
"output_directory", "output_directory",
"save_pngs", "save_pngs",
"skip_to_animation_number", "skip_to_animation_number",

View file

@ -33,6 +33,7 @@ class Scene(object):
"save_pngs" : False, "save_pngs" : False,
"pngs_mode" : "RGBA", "pngs_mode" : "RGBA",
"output_directory" : ANIMATIONS_DIR, "output_directory" : ANIMATIONS_DIR,
"movie_file_extension" : ".mp4",
"name" : None, "name" : None,
"always_continually_update" : False, "always_continually_update" : False,
"random_seed" : 0, "random_seed" : 0,
@ -470,24 +471,30 @@ class Scene(object):
def preview(self): def preview(self):
TkSceneRoot(self) TkSceneRoot(self)
def save_image(self, name = None, mode = "RGB", dont_update = False): def get_image_file_path(self, name = None, dont_update = False):
folder = "images" folder = "images"
if dont_update: if dont_update:
folder = str(self) folder = str(self)
path = os.path.join(self.output_directory, folder) path = os.path.join(self.output_directory, folder)
file_name = (name or str(self)) + ".png" file_name = (name or str(self)) + ".png"
full_path = os.path.join(path, file_name) return os.path.join(path, file_name)
def save_image(self, name = None, mode = "RGB", dont_update = False):
path = self.get_image_file_path(name, dont_update)
if not os.path.exists(path): if not os.path.exists(path):
os.makedirs(path) os.makedirs(path)
if not dont_update: if not dont_update:
self.update_frame() self.update_frame()
image = self.get_image() image = self.get_image()
image = image.convert(mode) image = image.convert(mode)
image.save(full_path) image.save(path)
def get_movie_file_path(self, name, extension): def get_movie_file_path(self, name = None, extension = None):
if extension is None:
extension = self.movie_file_extension
if name is None:
name = self.name
file_path = os.path.join(self.output_directory, name) file_path = os.path.join(self.output_directory, name)
if not file_path.endswith(extension): if not file_path.endswith(extension):
file_path += extension file_path += extension
@ -497,8 +504,8 @@ class Scene(object):
def open_movie_pipe(self): def open_movie_pipe(self):
name = str(self) name = str(self)
file_path = self.get_movie_file_path(name, ".mp4") file_path = self.get_movie_file_path(name)
temp_file_path = file_path.replace(".mp4", "Temp.mp4") temp_file_path = file_path.replace(name, name + "Temp")
print("Writing to %s"%temp_file_path) print("Writing to %s"%temp_file_path)
self.args_to_rename_file = (temp_file_path, file_path) self.args_to_rename_file = (temp_file_path, file_path)