def render_sequence_to_movie_minimal(sequencer_asset_path): # If you do not override all of the settings in the AutomatedLevelSequenceCapture then the other settings are inherited # from Unreal's Class Default Object (CDO). Previous versions of Unreal (4.19 and below) stored the Render to Movie UI's settings in config files. Config # values are automatically loaded and applied to the CDO when the editor starts up. Unreal 4.20 and above now store the UI settings in a unique # instance in the config files, so modifications to the Render to Movie UI will no longer affect the CDO. However, legacy projects that are upgrading # from 4.19 to 4.20 may end up with the CDO being modified by their last Render to Movie UI settings. The CDO settings for AutomatedLevelSequenceCapture # is stored in /Engine/Saved/Config/<Platform>/EditorSettings.ini under the sections labeled "[/Script/MovieSceneCapture.AutomatedLevelSequenceCapture]", # and "[/Script/LevelSequence.LevelSequenceBurnInOptions]" . # If you happen to upgrade your engine and this file persists, then the old settings will be applied by default to the CDO, and thus to the instance created # in Python. If you want to ensure that your Python instances come with default settings set via C++ then you should remove that section from the config file # on each users machine, or you should override every possible setting via Python (see below). # Create an instance of UAutomatedLevelSequenceCapture capture_settings = unreal.AutomatedLevelSequenceCapture() capture_settings.level_sequence_asset = unreal.SoftObjectPath( sequencer_asset_path) # Invoke Sequencer's Render to Movie. This will throw an exception if a movie render is already # in progress, an invalid setting is passed, etc. try: print("Rendering to movie...") unreal.SequencerTools.render_movie(capture_settings, unreal.OnRenderMovieStopped()) except Exception as e: print("Python Caught Exception:") print(e)
def set_active_task(task): if task != None and SequencerCaptureUSD.task != None: raise Exception("Already has active task") SequencerCaptureUSD.task = task if task != None: if SequencerCaptureUSD.on_finished_callback == None: SequencerCaptureUSD.on_finished_callback = unreal.OnRenderMovieStopped( ) SequencerCaptureUSD.on_finished_callback.bind_callable( SequencerCaptureUSD.finished_render_movie)
def RenderSequence(path): capture_settings = unreal.AutomatedLevelSequenceCapture() capture_settings.level_sequence_asset = unreal.SoftObjectPath(path) try: unreal.SequencerTools.render_movie(capture_settings, unreal.OnRenderMovieStopped()) return True except Exception as e: print("Python Caught Exception:") print(e) return False unreal.log("Render Sequence...")
def render(self, sequence_list, i): progress = (i / len(sequence_list)) * 100 self.ProgressBar.setValue(progress) # NOTE 如果超出数组则退出执行 if i >= len(sequence_list): # NOTE 输出完成 打开输出文件夹的路径 os.startfile(self.output_directory) toast(u"渲染完成~", "info") print("渲染完成") return # NOTE 设置全局变量才起作用! global on_finished_callback sequence = sequence_list[i] self.capture = self.setup_capture() self.capture.set_editor_property( "level_sequence_asset", unreal.SoftObjectPath(sequence.get_path_name())) on_finished_callback = unreal.OnRenderMovieStopped( lambda s: self.render(sequence_list, i + 1)) unreal.SequencerTools.render_movie(self.capture, on_finished_callback)
def render(sequence_list, i, output_directory="C:/render", output_format="{sequence}"): # NOTE 如果超出数组则退出执行 if i >= len(sequence_list): # NOTE 输出完成 打开输出文件夹的路径 os.startfile(output_directory) return # NOTE 获取当前渲染序号下的 LevelSequence sequence = sequence_list[i] # NOTE 配置渲染参数 settings = unreal.MovieSceneCaptureSettings() path = unreal.DirectoryPath(output_directory) settings.set_editor_property("output_directory", path) settings.set_editor_property("output_format", output_format) settings.set_editor_property("overwrite_existing", True) settings.set_editor_property("game_mode_override", None) settings.set_editor_property("use_relative_frame_numbers", False) settings.set_editor_property("handle_frames", 0) settings.set_editor_property("zero_pad_frame_numbers", 4) settings.set_editor_property("use_custom_frame_rate", True) settings.set_editor_property("custom_frame_rate", unreal.FrameRate(24, 1)) # NOTE 渲染大小 w, h = 1280, 720 settings.set_editor_property("resolution", unreal.CaptureResolution(w, h)) settings.set_editor_property("enable_texture_streaming", False) settings.set_editor_property("cinematic_engine_scalability", True) settings.set_editor_property("cinematic_mode", True) settings.set_editor_property("allow_movement", False) settings.set_editor_property("allow_turning", False) settings.set_editor_property("show_player", False) settings.set_editor_property("show_hud", False) # NOTE 设置默认的自动渲染参数 option = unreal.AutomatedLevelSequenceCapture() option.set_editor_property("use_separate_process", False) option.set_editor_property("close_editor_when_capture_starts", False) option.set_editor_property("additional_command_line_arguments", "-NOSCREENMESSAGES") option.set_editor_property("inherited_command_line_arguments", "") option.set_editor_property("use_custom_start_frame", False) option.set_editor_property("use_custom_end_frame", False) option.set_editor_property("warm_up_frame_count", 0.0) option.set_editor_property("delay_before_warm_up", 0) option.set_editor_property("delay_before_shot_warm_up", 0.0) option.set_editor_property("write_edit_decision_list", True) # option.set_editor_property("custom_start_frame",unreal.FrameNumber(0)) # option.set_editor_property("custom_end_frame",unreal.FrameNumber(0)) option.set_editor_property("settings", settings) option.set_editor_property("level_sequence_asset", unreal.SoftObjectPath(sequence.get_path_name())) # NOTE 设置自定义渲染参数 option.set_image_capture_protocol_type( unreal.CompositionGraphCaptureProtocol) protocol = option.get_image_capture_protocol() # NOTE 这里设置 Base Color 渲染 Base Color 通道,可以根据输出的 UI 设置数组名称 passes = unreal.CompositionGraphCapturePasses(["Base Color"]) protocol.set_editor_property("include_render_passes", passes) # protocol.set_editor_property("compression_quality",100) # NOTE 设置全局变量才起作用! global on_finished_callback on_finished_callback = unreal.OnRenderMovieStopped(lambda s: render( sequence_list, i + 1, output_directory, output_format)) unreal.SequencerTools.render_movie(option, on_finished_callback)
proj_names = args.project_name artist_names = args.artist_name def on_render_movie_finished(success): print( "# Movie has finished rendering. Python can now invoke another movie render if needed. Sucess: " + str(success)) if len(seq_names) > 0: print("# Sequcnes in a queue =", seq_names) render_movies() else: print("# All sequences in a quene have been rendered!!!! Done!!!!") on_finished_callback = unreal.OnRenderMovieStopped() on_finished_callback.bind_callable(on_render_movie_finished) def render_sequence_to_movie(sequencer_asset_path, level_name, level_path, output_file_name, resolution=(1280, 720), game_mode_override='None', warm_up_frame_count=0, delay_before_warm_up=0.0, delay_before_shot_warm_up=0.0, delay_every_frame=0.0, use_burn_in=False, encorder_format='422'):
def render_sequence_to_movie(sequence_path, sequence_name): def on_render_movie_finished(success): print( "Movie has finished rendering. Python can now invoke another movie render if needed. Sucess: " + str(success)) on_finished_callback = unreal.OnRenderMovieStopped() on_finished_callback.bind_callable(on_render_movie_finished) file_path = sequence_path + "/" + sequence_name capture_settings = unreal.AutomatedLevelSequenceCapture() # out put path capture_settings.settings.output_directory = unreal.DirectoryPath( "../../../Game/Saved/VideoCaptures/") capture_settings.settings.game_mode_override = None # out put name capture_settings.settings.output_format = sequence_name capture_settings.settings.overwrite_existing = False capture_settings.settings.use_relative_frame_numbers = False capture_settings.settings.handle_frames = 0 capture_settings.settings.zero_pad_frame_numbers = 4 capture_settings.settings.use_custom_frame_rate = True capture_settings.settings.custom_frame_rate = unreal.FrameRate(24, 1) capture_settings.settings.resolution.res_x = 1280 capture_settings.settings.resolution.res_y = 720 capture_settings.settings.enable_texture_streaming = False capture_settings.settings.cinematic_engine_scalability = True capture_settings.settings.cinematic_mode = True capture_settings.settings.allow_movement = False capture_settings.settings.allow_turning = False capture_settings.settings.show_player = False capture_settings.settings.show_hud = False capture_settings.use_separate_process = False capture_settings.close_editor_when_capture_starts = False capture_settings.additional_command_line_arguments = "-NOSCREENMESSAGES" capture_settings.inherited_command_line_arguments = "" capture_settings.use_custom_start_frame = False capture_settings.use_custom_end_frame = False capture_settings.custom_start_frame = unreal.FrameNumber(0) capture_settings.custom_end_frame = unreal.FrameNumber(0) capture_settings.warm_up_frame_count = 0.0 capture_settings.delay_before_warm_up = 0 capture_settings.delay_before_shot_warm_up = 0.0 capture_settings.write_edit_decision_list = True # Change format capture_settings.set_image_capture_protocol_type( unreal.load_class( None, "/Script/MovieSceneCapture.ImageSequenceProtocol_JPG")) capture_settings.get_image_capture_protocol().compression_quality = 100 capture_settings.level_sequence_asset = unreal.SoftObjectPath( file_path) unreal.SequencerTools.render_movie(capture_settings, on_finished_callback)