def run(self): self.start_time = time.monotonic() self.render_player = None self.frames_range_writer = None self.script_renderer = None if self.render_data.save_internally == True: frame_name = "frame" else: frame_name = self.render_data.frame_name clip_frames_folder = ccrutils.clip_frames_folder() rendered_frames_folder = ccrutils.rendered_frames_folder() profile = mltprofiles.get_profile(self.profile_desc) # Delete old clip frames for frame_file in os.listdir(clip_frames_folder): file_path = os.path.join(clip_frames_folder, frame_file) os.remove(file_path) # Delete old rendered frames for frame_file in os.listdir(rendered_frames_folder): file_path = os.path.join(rendered_frames_folder, frame_file) os.remove(file_path) self.frames_range_writer = gmicplayer.FramesRangeWriter( self.clip_path, self.frames_update, profile) self.frames_range_writer.write_frames(clip_frames_folder + "/", frame_name, self.range_in, self.range_out) if self.abort == True: return script_file = open(self.script_path) user_script = script_file.read() while len(os.listdir(clip_frames_folder)) != self.length: time.sleep(0.5) # Render frames with gmic script self.script_renderer = gmicplayer.FolderFramesScriptRenderer( user_script, clip_frames_folder, rendered_frames_folder + "/", frame_name, self.script_render_update_callback, self.script_render_output_callback, 10, False, # this is not useful until we get MLT to fin frames sequences not startin from 0001 0) self.script_renderer.write_frames() ccrutils.delete_clip_frames() if self.abort == True: return # Render video if self.render_data.do_video_render == True: # Render consumer args_vals_list = toolsencoding.get_args_vals_list_for_render_data( self.render_data) profile = mltprofiles.get_profile_for_index( self.render_data.profile_index) if self.render_data.save_internally == True: file_path = ccrutils.session_folder( ) + "/" + appconsts.CONTAINER_CLIP_VIDEO_CLIP_NAME + self.render_data.file_extension else: file_path = self.render_data.render_dir + "/" + self.render_data.file_name + self.render_data.file_extension consumer = renderconsumer.get_mlt_render_consumer( file_path, profile, args_vals_list) # Render producer frame_file = rendered_frames_folder + "/" + frame_name + "_0000.png" resource_name_str = utils.get_img_seq_resource_name( frame_file, True) resource_path = rendered_frames_folder + "/" + resource_name_str producer = mlt.Producer(profile, str(resource_path)) frames_length = len(os.listdir(rendered_frames_folder)) self.render_player = renderconsumer.FileRenderPlayer( "", producer, consumer, 0, frames_length - 1) self.render_player.wait_for_producer_end_stop = False self.render_player.start() while self.render_player.stopped == False: self.abort_requested() if self.abort == True: self.render_player.shutdown() return fraction = self.render_player.get_render_fraction() self.video_render_update_callback(fraction) time.sleep(0.3) ccrutils.delete_rendered_frames() # Write out completed flag file. ccrutils.write_completed_message()
def run(self): self.start_time = time.monotonic() if self.render_data.save_internally == True: frame_name = "frame" else: frame_name = self.render_data.frame_name rendered_frames_folder = ccrutils.rendered_frames_folder() # Delete old rendered frames for frame_file in os.listdir(rendered_frames_folder): file_path = os.path.join(rendered_frames_folder, frame_file) os.remove(file_path) if self.abort == True: return script_file = open(self.script_path) user_script = script_file.read() profile_file_path = mltprofiles.get_profile_file_path( self.profile_desc) editors_data_json = json.dumps( self.fluxity_plugin_edit_data["editors_list"] ) # See fluxity.FluxityContext.get_script_data() fluxity.render_frame_sequence(user_script, self.range_in, self.range_out, rendered_frames_folder, profile_file_path, self.frames_update, editors_data_json, True) render_length = self.range_out - self.range_in while len(os.listdir(rendered_frames_folder)) != render_length: if self.abort == True: return time.sleep(0.5) # Render video if self.render_data.do_video_render == True: # Render consumer args_vals_list = toolsencoding.get_args_vals_list_for_render_data( self.render_data) profile = mltprofiles.get_profile_for_index( self.render_data.profile_index) if self.render_data.save_internally == True: file_path = ccrutils.session_folder( ) + "/" + appconsts.CONTAINER_CLIP_VIDEO_CLIP_NAME + self.render_data.file_extension else: file_path = self.render_data.render_dir + "/" + self.render_data.file_name + self.render_data.file_extension consumer = renderconsumer.get_mlt_render_consumer( file_path, profile, args_vals_list) # Render producer num_part = str(1).zfill(5) frame_file = rendered_frames_folder + "/" + frame_name + "_" + num_part + ".png" resource_name_str = utils.get_img_seq_resource_name( frame_file, True) resource_path = rendered_frames_folder + "/" + resource_name_str producer = mlt.Producer(profile, str(resource_path)) frames_length = len(os.listdir(rendered_frames_folder)) self.render_player = renderconsumer.FileRenderPlayer( "", producer, consumer, 0, frames_length - 1) self.render_player.wait_for_producer_end_stop = False self.render_player.start() while self.render_player.stopped == False: self.abort_requested() if self.abort == True: self.render_player.shutdown() return fraction = self.render_player.get_render_fraction() self.video_render_update_callback(fraction) time.sleep(0.3) ccrutils.delete_rendered_frames() # Write out completed flag file. ccrutils.write_completed_message()
def get_written_frames_count(self): return len(os.listdir(ccrutils.rendered_frames_folder()))
def main(root_path, session_id, project_path, range_in, range_out, profile_desc): project_path = utils.escape_shell_path(project_path) try: editorstate.mlt_version = mlt.LIBMLT_VERSION except: editorstate.mlt_version = "0.0.99" # magic string for "not found" # Set paths. respaths.set_paths(root_path) userfolders.init() editorpersistance.load() # Init translations module with translations data translations.init_languages() translations.load_filters_translations() mlttransitions.init_module() repo = mlt.Factory().init() processutils.prepare_mlt_repo(repo) # Set numeric locale to use "." as radix, MLT initilizes this to OS locale and this causes bugs locale.setlocale(locale.LC_NUMERIC, 'C') # Check for codecs and formats on the system mltenv.check_available_features(repo) renderconsumer.load_render_profiles() # Load filter and compositor descriptions from xml files. mltfilters.load_filters_xml(mltenv.services) mlttransitions.load_compositors_xml(mltenv.transitions) # Create list of available mlt profiles mltprofiles.load_profile_list() ccrutils.init_session_folders(session_id) ccrutils.load_render_data() log_path = GLib.get_user_cache_dir() + "/blenderrenderlog" FLOG = open(log_path, 'w') render_setup_script = respaths.ROOT_PATH + "/tools/blenderrendersetup.py" blender_launch = "/usr/bin/blender -b " + project_path + " -P " + utils.escape_shell_path( render_setup_script) global _start_time _start_time = time.monotonic() render_data = ccrutils.get_render_data() # Delete old rendered frames for non-preview renders. if render_data.is_preview_render == False: rendered_frames_folder = ccrutils.rendered_frames_folder() for frame_file in os.listdir(rendered_frames_folder): file_path = os.path.join(rendered_frames_folder, frame_file) os.remove(file_path) else: # For preview render delete preview frames preview_frames_folder = ccrutils.preview_frames_folder() for frame_file in os.listdir(preview_frames_folder): file_path = os.path.join(preview_frames_folder, frame_file) os.remove(file_path) p = subprocess.Popen(blender_launch, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG, preexec_fn=os.setsid) manager_thread = ProgressPollingThread(range_in, range_out, p, render_data.is_preview_render) manager_thread.start() p.wait() if manager_thread.abort == True: return # Render video if render_data.do_video_render == True: # Change file numbering to start from 0000 to please ffmpeg rendered_folder = ccrutils.rendered_frames_folder() + "/" files = [ f for f in listdir(rendered_folder) if isfile(join(rendered_folder, f)) ] files.sort(key=lambda var: [ int(x) if x.isdigit() else x for x in re.findall(r'[^0-9]|[0-9]+', var) ]) number = 0 for rendered_file in files: source_file = rendered_folder + rendered_file file_number = '{0:04d}'.format(number) dst_file = rendered_folder + "videoframe" + file_number + ".png" Path(source_file).rename(dst_file) number += 1 # Render consumer args_vals_list = toolsencoding.get_args_vals_list_for_render_data( render_data) profile = mltprofiles.get_profile_for_index(render_data.profile_index) if ccrutils.get_render_data().save_internally == True: file_path = ccrutils.session_folder( ) + "/" + appconsts.CONTAINER_CLIP_VIDEO_CLIP_NAME + render_data.file_extension else: file_path = render_data.render_dir + "/" + render_data.file_name + render_data.file_extension consumer = renderconsumer.get_mlt_render_consumer( file_path, profile, args_vals_list) # Render producer rendered_frames_folder = ccrutils.rendered_frames_folder() frames_info = gmicplayer.FolderFramesInfo(rendered_frames_folder) frame_file = frames_info.get_lowest_numbered_file() if editorstate.mlt_version_is_equal_or_greater("0.8.5"): resource_name_str = utils.get_img_seq_resource_name( frame_file, True) else: resource_name_str = utils.get_img_seq_resource_name( frame_file, False) resource_path = rendered_frames_folder + "/" + resource_name_str producer = mlt.Producer(profile, str(resource_path)) frames_length = len(os.listdir(rendered_frames_folder)) render_player = renderconsumer.FileRenderPlayer( "", producer, consumer, 0, frames_length - 1) render_player.wait_for_producer_end_stop = False render_player.start() abort = False while render_player.stopped == False and abort == False: abort = ccrutils.abort_requested() if abort == True: render_player.shutdown() return else: fraction = render_player.get_render_fraction() elapsed = time.monotonic() - _start_time msg = "2 " + str(fraction) + " " + str(elapsed) ccrutils.write_status_message(msg) time.sleep(1.0) else: manager_thread.abort = True # to exit while loop and end thread ccrutils.write_completed_message() print("Blender render complete.")
def run(self): self.start_time = time.monotonic() args_vals_list = toolsencoding.get_args_vals_list_for_render_data( self.render_data) profile = mltprofiles.get_profile_for_index( self.render_data.profile_index) producer = mlt.Producer(profile, str(self.xml_file_path)) # Video clip consumer if self.render_data.do_video_render == True: if self.render_data.save_internally == True: file_path = ccrutils.session_folder( ) + "/" + appconsts.CONTAINER_CLIP_VIDEO_CLIP_NAME + self.render_data.file_extension else: file_path = self.render_data.render_dir + "/" + self.render_data.file_name + self.render_data.file_extension consumer = renderconsumer.get_mlt_render_consumer( file_path, profile, args_vals_list) ccrutils.delete_rendered_frames( ) # in case we switched from img seq consumer we can now delete those frames to save space # img seq consumer else: # Image sequence gets project profile project_profile = mltprofiles.get_profile(self.profile_desc) if self.render_data.save_internally == True: frame_name = "frame" else: frame_name = self.render_data.frame_name render_path = ccrutils.rendered_frames_folder( ) + frame_name + "_%04d." + "png" consumer = mlt.Consumer(project_profile, "avformat", str(render_path)) consumer.set("real_time", -1) consumer.set("rescale", "bicubic") consumer.set("vcodec", "png") self.render_player = renderconsumer.FileRenderPlayer( "", producer, consumer, self.range_in, self.range_out) self.render_player.wait_for_producer_end_stop = False self.render_player.start() while self.render_player.stopped == False: self.abort_requested() if self.abort == True: self.render_player.shutdown() return fraction = self.render_player.get_render_fraction() self.render_update_callback(fraction) time.sleep(0.3) # Write out completed flag file. ccrutils.write_completed_message()