def main(root_path, session_id, script, clip_path, range_in, range_out, profile_desc, gmic_frame_offset): os.nice(10) # make user configurable 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) # Check G'MIC version global _gmic_version _gmic_version = get_gmic_version() if _gmic_version == 2: respaths.set_gmic2(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() render_data = ccrutils.get_render_data() # This needs to have render data loaded to know if we are using external folders. ccrutils.maybe_init_external_session_folders() global _render_thread _render_thread = GMicHeadlessRunnerThread(script, render_data, clip_path, range_in, range_out, profile_desc, gmic_frame_offset) _render_thread.start()
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.")