def launch_phantom(): respaths.PHANTOM_JAR if _phantom_found == False: info_row = guiutils.get_centered_box([Gtk.Label(_("Phantom2D tool has not been installed on your system."))]) link_info_row = guiutils.get_centered_box([Gtk.Label(_("Install instructions:"))]) link = Gtk.LinkButton.new("https://github.com/jliljebl/phantom2D") link_row = guiutils.get_centered_box([link]) dir_info_row = guiutils.get_centered_box([Gtk.Label(_("Install directory for Phantom2D tool:"))]) dir_label = Gtk.Label(respaths.PHANTOM_JAR.rstrip("/Phantom2D.jar")) dir_label.set_selectable(True) dir_row = guiutils.get_centered_box([Gtk.Label(respaths.PHANTOM_JAR.rstrip("/Phantom2D.jar"))]) dir_row.set_margin_top(8) panel = Gtk.VBox() panel.pack_start(info_row, False, False, 0) panel.pack_start(guiutils.pad_label(12, 24), False, False, 0) panel.pack_start(link_info_row, False, False, 0) panel.pack_start(link_row, False, False, 0) panel.pack_start(guiutils.pad_label(12, 24), False, False, 0) panel.pack_start(dir_info_row, False, False, 0) panel.pack_start(dir_row, False, False, 0) dialogutils.panel_ok_dialog(_("Phantom2D not found"), panel) return FLOG = open(userfolders.get_cache_dir() + "log_phantom", 'w') subprocess.Popen([str(respaths.LAUNCH_DIR + "flowbladephantom") + " " + str(respaths.PHANTOM_JAR) \ + " profile" + " " + _get_underscored_profile() \ + " cachefolder " + userfolders.get_cache_dir() + appconsts.PHANTOM_DIR + "/" + appconsts.PHANTOM_DISK_CACHE_DIR], shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) print "Phantom2D launched"
def write_image(self): """ Writes thumbnail image from file producer """ clip_path = self.clip.path # Create consumer matchframe_new_path = userfolders.get_cache_dir( ) + appconsts.MATCH_FRAME_NEW consumer = mlt.Consumer(PROJECT().profile, "avformat", matchframe_new_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") # Create one frame producer producer = mlt.Producer(PROJECT().profile, str(clip_path)) producer = producer.cut(int(self.clip_frame), int(self.clip_frame)) # Delete new match frame try: os.remove(matchframe_new_path) except: # This fails when done first time ever pass # Connect and write image consumer.connect(producer) consumer.run() # Wait until new file exists while os.path.isfile(matchframe_new_path) != True: time.sleep(0.1) # Copy to match frame matchframe_path = userfolders.get_cache_dir() + appconsts.MATCH_FRAME shutil.copyfile(matchframe_new_path, matchframe_path) # Update timeline data # Get frame of clip.clip_in_in on timeline. clip_index = self.track.clips.index(self.clip) clip_start_in_tline = self.track.clip_start(clip_index) tline_match_frame = clip_start_in_tline + (self.clip_frame - self.clip.clip_in) tlinewidgets.set_match_frame(tline_match_frame, self.track.id, self.display_on_right) # Update view updater.repaint_tline()
def write_frames(self): clip_frames = os.listdir(self.folder) frame_count = 1 for clip_frame in clip_frames: if self.abort == True: return self.do_update_callback(frame_count) file_numbers_list = re.findall(r'\d+', clip_frame) filled_number_str = str(int(file_numbers_list[0]) + self.out_frame_offset).zfill(4) clip_frame_path = str(os.path.join(self.folder, clip_frame)) rendered_file_path = str(self.out_folder + self.frame_name + "_" + filled_number_str + ".png") # Create command list and launch process. command_list = [editorstate.gmic_path, clip_frame_path] user_script_commands = self.user_script.split(" ") command_list.extend(user_script_commands) command_list.append("-output") command_list.append(rendered_file_path) if self.re_render_existing == False: if os.path.exists(rendered_file_path) == True: frame_count = frame_count + 1 continue if frame_count == 1: # first frame displays shell output and does error checking FLOG = open(userfolders.get_cache_dir() + "log_gmic_preview", 'w') p = subprocess.Popen(command_list, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() # read log f = open(userfolders.get_cache_dir() + "log_gmic_preview", 'r') out = f.read() f.close() self.do_render_output_callback(p, out) else: FLOG = open(userfolders.get_cache_dir() + "log_gmic_preview", 'w') p = subprocess.Popen(command_list, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() frame_count = frame_count + 1
def write_image(self, file_path): """ Writes thumbnail image from file producer """ # Get data md_str = md5.new(file_path).hexdigest() thumbnail_path = userfolders.get_cache_dir() + appconsts.THUMBNAILS_DIR + "/" + md_str + ".png" # Create consumer consumer = mlt.Consumer(self.profile, "avformat", thumbnail_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") # Create one frame producer producer = mlt.Producer(self.profile, str(file_path)) if producer.is_valid() == False: raise ProducerNotValidError(file_path) info = utils.get_file_producer_info(producer) length = producer.get_length() frame = length / 2 producer = producer.cut(frame, frame) # Connect and write image consumer.connect(producer) consumer.run() return (thumbnail_path, length, info)
def create_match_frame_image_surface(self, frame_name): # Create non-scaled surface matchframe_path = userfolders.get_cache_dir( ) + appconsts.TRIM_VIEW_DIR + "/" + frame_name surface = cairo.ImageSurface.create_from_png(matchframe_path) # Create and return scaled surface profile_screen_ratio = float(PROJECT().profile.width()) / float( PROJECT().profile.height()) match_frame_width, match_frame_height = self.get_match_frame_panel_size( ) scaled_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(match_frame_width), int(match_frame_height)) cr = cairo.Context(scaled_surface) cr.scale( float(match_frame_width) / float(surface.get_width()), float(match_frame_height) / float(surface.get_height())) cr.set_source_surface(surface, 0, 0) cr.paint() return scaled_surface
def _app_destroy(): # Close threads and stop mlt consumers editorstate.player.shutdown( ) # has ticker thread and player threads running audiomonitoring.close() # Wait threads to stop while ((editorstate.player.ticker.exited == False) and (audiomonitoring._update_ticker.exited == False) and (audiowaveform.waveform_thread != None)): pass # Delete autosave file try: os.remove(userfolders.get_cache_dir() + get_instance_autosave_file()) except: print("Delete autosave file FAILED!") do_gtk_main_quit = jobs.handle_shutdown(get_instance_autosave_file()) # Exit gtk main loop if no jobs unfinished. if do_gtk_main_quit == True: Gtk.main_quit() else: # Jobs lauches its own top level window to show progress on unfinished jobs renders # and does Gtk.main_quit() later when done. pass
def _ardour_export_dialog_callback(dialog, response_id, session_folder): if response_id != Gtk.ResponseType.ACCEPT: dialog.destroy() return folder_path = session_folder.get_filenames()[0] if not (os.listdir(folder_path) == []): dialog.destroy() primary_txt = _("Selected folder contains files") secondary_txt = _( "When exporting audio to Ardour, the selected folder\nhas to be empty." ) dialogutils.info_message(primary_txt, secondary_txt, gui.editor_window.window) return # name = name_entry.get_text() dialog.destroy() xml_save_path = userfolders.get_cache_dir() + "ardour_export.xml" global _xml_render_player _xml_render_player = renderconsumer.XMLRenderPlayer( xml_save_path, _ardour_xml_render_done, None, PROJECT().c_seq, PROJECT(), PLAYER()) _xml_render_player.ardour_session_folder = folder_path _xml_render_player.start()
def _blender_clip_create_dialog_callback(dialog, response_id, data): dialog.destroy() if response_id != Gtk.ResponseType.ACCEPT: dialog.destroy() else: project_select = data[0] project_file = project_select.get_filename() dialog.destroy() if project_file == None: _show_not_all_data_info() return container_clip_data = ContainerClipData(appconsts.CONTAINER_CLIP_BLENDER, project_file, None) action_object = containeractions.get_action_object(container_clip_data) action_object.initialize_project(project_file) # blocks until info data written project_edit_info_path = userfolders.get_cache_dir() + "blender_container_projectinfo.json" info_file = open(project_edit_info_path, "r") project_edit_info = json.load(info_file) print(project_edit_info) length = int(project_edit_info["frame_end"]) - int(project_edit_info["frame_start"]) container_clip_data.data_slots["project_edit_info"] = project_edit_info container_clip_data.editable = True container_clip_data.unrendered_length = length blender_unrendered_media_image = respaths.IMAGE_PATH + "unrendered_blender.png" window_text = _("<b>Creating Container for Blender Project:</b> ") + container_clip_data.get_program_name() + ".blend" containeractions.create_unrendered_clip(length, blender_unrendered_media_image, container_clip_data, _blender_unredered_media_creation_complete, window_text)
def _get_proxy_profile(project): project_profile = project.profile new_width, new_height = _get_proxy_dimensions(project_profile, project.proxy_data.size) file_contents = "description=" + "proxy render profile" + "\n" file_contents += "frame_rate_num=" + str( project_profile.frame_rate_num()) + "\n" file_contents += "frame_rate_den=" + str( project_profile.frame_rate_den()) + "\n" file_contents += "width=" + str(new_width) + "\n" file_contents += "height=" + str(new_height) + "\n" file_contents += "progressive=1" + "\n" file_contents += "sample_aspect_num=" + str( project_profile.sample_aspect_num()) + "\n" file_contents += "sample_aspect_den=" + str( project_profile.sample_aspect_den()) + "\n" file_contents += "display_aspect_num=" + str( project_profile.display_aspect_num()) + "\n" file_contents += "display_aspect_den=" + str( project_profile.display_aspect_den()) + "\n" proxy_profile_path = userfolders.get_cache_dir() + "temp_proxy_profile" with atomicfile.AtomicFileWriter(proxy_profile_path, "w") as afw: profile_file = afw.get_file() profile_file.write(file_contents) proxy_profile = mlt.Profile(proxy_profile_path) return proxy_profile
def set_waveform_displayer_clip_from_popup(data): clip, track, item_id, item_data = data global frames_cache if clip.path in frames_cache: frame_levels = frames_cache[clip.path] clip.waveform_data = frame_levels updater.repaint_tline() return cache_file_path = userfolders.get_cache_dir() + appconsts.AUDIO_LEVELS_DIR + _get_unique_name_for_media(clip.path) if os.path.isfile(cache_file_path): f = open(cache_file_path) frame_levels = pickle.load(f) frames_cache[clip.path] = frame_levels clip.waveform_data = frame_levels updater.repaint_tline() return progress_bar = Gtk.ProgressBar() title = _("Audio Levels Data Render") text = "<b>Media File: </b>" + clip.path dialog = _waveform_render_progress_dialog(_waveform_render_abort, title, text, progress_bar, gui.editor_window.window) dialog.progress_bar = progress_bar global waveform_thread waveform_thread = WaveformCreator(clip, track.height, dialog) waveform_thread.start()
def write_files(filename): print "Starting media import..." FLOG = open(userfolders.get_cache_dir() + "log_media_import", 'w') p = subprocess.Popen([sys.executable, respaths.LAUNCH_DIR + "flowblademediaimport", filename], stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() GLib.idle_add(assets_write_complete)
def write_image(self, file_path): """ Writes thumbnail image from file producer """ # Get data md_str = hashlib.md5(file_path.encode('utf-8')).hexdigest() thumbnail_path = userfolders.get_cache_dir( ) + appconsts.THUMBNAILS_DIR + "/" + md_str + ".png" # Create consumer consumer = mlt.Consumer(self.profile, "avformat", thumbnail_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") # Create one frame producer producer = mlt.Producer(self.profile, str(file_path)) if producer.is_valid() == False: raise ProducerNotValidError(file_path) info = utils.get_file_producer_info(producer) length = producer.get_length() frame = length // 2 producer = producer.cut(frame, frame) # Connect and write image consumer.connect(producer) consumer.run() return (thumbnail_path, length, info)
def write_files(filename): print("Starting media import...") FLOG = open(userfolders.get_cache_dir() + "log_media_import", 'w') p = subprocess.Popen([sys.executable, respaths.LAUNCH_DIR + "flowblademediaimport", filename], stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() GLib.idle_add(assets_write_complete)
def write_frames(self): clip_frames = os.listdir(self.folder) frame_count = 1 for clip_frame in clip_frames: if self.abort == True: return self.do_update_callback(frame_count) # Run with nice to lower priority if requested nice_command = "nice -n " + str(self.nice) + " " file_numbers_list = re.findall(r'\d+', clip_frame) filled_number_str = str(int(file_numbers_list[0]) + self.out_frame_offset).zfill(4) clip_frame_path = str(os.path.join(self.folder, clip_frame)).replace(" ", "\ ") rendered_file_path = str(self.out_folder + self.frame_name + "_" + filled_number_str + ".png").replace(" ", "\ ") script_str = nice_command + "gmic " + clip_frame_path + " " + self.user_script + " -output " + rendered_file_path if self.re_render_existing == False: if os.path.exists(rendered_file_path) == True: frame_count = frame_count + 1 continue if frame_count == 1: # first frame displays shell output and does error checking FLOG = open(userfolders.get_cache_dir() + "log_gmic_preview", 'w') p = subprocess.Popen(script_str, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() # read log f = open(userfolders.get_cache_dir() + "log_gmic_preview", 'r') out = f.read() f.close() self.do_render_output_callback(p, out) else: FLOG = open(userfolders.get_cache_dir() + "log_gmic_preview", 'w') p = subprocess.Popen(script_str, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() frame_count = frame_count + 1
def save_project(self): persistance.show_messages = False if PROJECT().last_save_path != None: save_path = PROJECT().last_save_path else: save_path = userfolders.get_cache_dir() + self.autosave_file # if user didn't save before exit, save in autosave file to preserve render work somehow. persistance.save_project(PROJECT(), save_path)
def start_autosave(): global autosave_timeout_id time_min = 1 # hard coded, probably no need to make configurable autosave_delay_millis = time_min * 60 * 1000 print "Autosave started..." autosave_timeout_id = GObject.timeout_add(autosave_delay_millis, do_autosave) autosave_file = userfolders.get_cache_dir() + get_instance_autosave_file() persistance.save_project(editorstate.PROJECT(), autosave_file)
def display_linker(filename=NO_PROJECT_AT_LAUNCH): print("Launching Media Relinker") FLOG = open(userfolders.get_cache_dir() + "log_media_relinker", 'w') subprocess.Popen([ sys.executable, respaths.LAUNCH_DIR + "flowblademedialinker", filename ], stdin=FLOG, stdout=FLOG, stderr=FLOG)
def write_image(self): """ Writes thumbnail image from file producer """ clip_path = self.clip.path # Create consumer matchframe_new_path = userfolders.get_cache_dir() + appconsts.MATCH_FRAME_NEW consumer = mlt.Consumer(PROJECT().profile, "avformat", matchframe_new_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") # Create one frame producer producer = mlt.Producer(PROJECT().profile, str(clip_path)) producer = producer.cut(int(self.clip_frame), int(self.clip_frame)) # Delete new match frame try: os.remove(matchframe_new_path) except: # This fails when done first time ever pass # Connect and write image consumer.connect(producer) consumer.run() # Wait until new file exists while os.path.isfile(matchframe_new_path) != True: time.sleep(0.1) # Copy to match frame matchframe_path = userfolders.get_cache_dir() + appconsts.MATCH_FRAME shutil.copyfile(matchframe_new_path, matchframe_path) # Update timeline data # Get frame of clip.clip_in_in on timeline. clip_index = self.track.clips.index(self.clip) clip_start_in_tline = self.track.clip_start(clip_index) tline_match_frame = clip_start_in_tline + (self.clip_frame - self.clip.clip_in) tlinewidgets.set_match_frame(tline_match_frame, self.track.id, self.display_on_right) # Update view updater.repaint_tline()
def autosave_dialog_callback(dialog, response): dialog.destroy() autosave_file = userfolders.get_cache_dir() + AUTOSAVE_DIR + get_autosave_files()[0] if response == Gtk.ResponseType.OK: global loaded_autosave_file loaded_autosave_file = autosave_file projectaction.actually_load_project(autosave_file, True) else: os.remove(autosave_file) start_autosave()
def launch_render_server(): bus = dbus.SessionBus() if bus.name_has_owner('io.github.jliljebl.Flowblade'): # This happens for project profile changes e.g. when loading first video and changing to matching peofile. # We are only running on of these per project edit session, so do nothing. print("io.github.jliljebl.Flowblade dbus service already exists") else: print("Launching io.github.jliljebl.Flowblade dbus service") FLOG = open(userfolders.get_cache_dir() + "log_tline_render", 'w') subprocess.Popen([sys.executable, respaths.LAUNCH_DIR + "flowbladetlinerender"], stdin=FLOG, stdout=FLOG, stderr=FLOG)
def autosave_dialog_callback(dialog, response): dialog.destroy() autosave_file = userfolders.get_cache_dir() + AUTOSAVE_DIR + get_autosave_files()[0] if response == Gtk.ResponseType.OK: global loaded_autosave_file loaded_autosave_file = autosave_file projectaction.actually_load_project(autosave_file, True, False, True) else: tlinerender.init_session() # didn't do this in main and not going to do app-open_project os.remove(autosave_file) start_autosave()
def __init__(self, clip, track_height, dialog): threading.Thread.__init__(self) self.clip = clip self.temp_clip = self._get_temp_producer(clip) self.file_cache_path = userfolders.get_cache_dir() + appconsts.AUDIO_LEVELS_DIR + _get_unique_name_for_media(clip.path) self.track_height = track_height self.abort = False self.clip_media_length = self.temp_clip.get_length() self.last_rendered_frame = 0 self.stopped = False self.dialog = dialog
def run(self): # Launch render process and wait for it to end FLOG = open(userfolders.get_cache_dir() + "log_audio_levels_render", 'w') # Sep-2018 - SvdB - Added self. to be able to access the thread through 'process' self.process = subprocess.Popen([sys.executable, respaths.LAUNCH_DIR + "flowbladeaudiorender", \ self.rendered_media, self.profile_desc, respaths.ROOT_PATH], \ stdin=FLOG, stdout=FLOG, stderr=FLOG) self.process.wait() Gdk.threads_enter() updater.repaint_tline() Gdk.threads_leave()
def _convert_to_original_media_project(): editorstate.PROJECT().proxy_data.proxy_mode = appconsts.CONVERTING_TO_USE_ORIGINAL_MEDIA conv_temp_project_path = userfolders.get_cache_dir() + "proxy_conv.flb" manager_window.convert_progress_bar.set_text(_("Converting to Use Original Media")) mark_in = editorstate.PROJECT().c_seq.tractor.mark_in mark_out = editorstate.PROJECT().c_seq.tractor.mark_out persistance.save_project(editorstate.PROJECT(), conv_temp_project_path) global load_thread load_thread = ProxyProjectLoadThread(conv_temp_project_path, manager_window.convert_progress_bar, mark_in, mark_out) load_thread.start()
def initialize_project(self, project_path): info_script = str(respaths.ROOT_PATH + "/tools/blenderprojectinit.py") command_list = ["/usr/bin/blender", "-b", project_path, "-P", info_script] if editorstate.app_running_from == editorstate.RUNNING_FROM_FLATPAK: info_script = utils.get_flatpak_real_path_for_app_files(info_script) command_list = ["flatpak-spawn", "--host", "/usr/bin/blender", "-b", project_path, "-P", info_script] FLOG = open(userfolders.get_cache_dir() + "/log_blender_project_init", 'w') p = subprocess.Popen(command_list, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait()
def _blender_clip_create_dialog_callback(dialog, response_id, data): dialog.destroy() if response_id != Gtk.ResponseType.ACCEPT: dialog.destroy() else: project_select = data[0] project_file = project_select.get_filename() dialog.destroy() if project_file == None: _show_not_all_data_info() return container_clip_data = ContainerClipData( appconsts.CONTAINER_CLIP_BLENDER, project_file, None) action_object = containeractions.get_action_object(container_clip_data) is_valid, err_msg = action_object.validate_program() if is_valid == False: primary_txt = _("Blender Container Clip Validation Error") dialogutils.warning_message(primary_txt, err_msg, gui.editor_window.window) return action_object.initialize_project( project_file) # blocks until info data written project_edit_info_path = userfolders.get_cache_dir( ) + "blender_container_projectinfo.json" if editorstate.app_running_from == editorstate.RUNNING_FROM_FLATPAK: project_edit_info_path = userfolders.get_user_home_cache_for_flatpak( ) + "blender_container_projectinfo.json" info_file = open(project_edit_info_path, "r") project_edit_info = json.load(info_file) length = int(project_edit_info["frame_end"]) - int( project_edit_info["frame_start"]) container_clip_data.data_slots["project_edit_info"] = project_edit_info container_clip_data.editable = True container_clip_data.unrendered_length = length blender_unrendered_media_image = respaths.IMAGE_PATH + "unrendered_blender.png" window_text = _("Creating Container for Blender Project") containeractions.create_unrendered_clip( length, blender_unrendered_media_image, container_clip_data, _blender_unredered_media_creation_complete, window_text)
def initialize_project(self, project_path): FLOG = open(userfolders.get_cache_dir() + "/log_blender_project_init", 'w') info_script = respaths.ROOT_PATH + "/tools/blenderprojectinit.py" blender_launch = "/usr/bin/blender -b " + project_path + " -P " + info_script p = subprocess.Popen(blender_launch, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait()
def _write_offsets(video_file_path, audio_file_path, completed_callback): print "Starting clapperless analysis..." fps = str(int(utils.fps() + 0.5)) idstr = _get_offset_file_idstr(video_file_path, audio_file_path) FLOG = open(userfolders.get_cache_dir() + "log_clapperless", 'w') # clapperless.py computes offsets and writes them to file clapperless.OFFSETS_DATA_FILE p = subprocess.Popen([sys.executable, respaths.LAUNCH_DIR + "flowbladeclapperless", video_file_path, audio_file_path, "--rate", fps, "--idstr", idstr], stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() # Offsets are now available GLib.idle_add(completed_callback, (video_file_path, audio_file_path, idstr))
def run(self): # Image produceer img_producer = current_sequence().create_file_producer_clip( str(self.image_file) ) # , new_clip_name=None, novalidate=False, ttl=None): # Create tractor and track to get right length tractor = mlt.Tractor() multitrack = tractor.multitrack() track0 = mlt.Playlist() multitrack.connect(track0, 0) track0.insert(img_producer, 0, 0, self.length) # Consumer write_file = userfolders.get_cache_dir() + "/unrendered_clip.mp4" # Delete earlier created files if os.path.exists(write_file): os.remove(write_file) consumer = renderconsumer.get_default_render_consumer( write_file, PROJECT().profile) clip_renderer = renderconsumer.FileRenderPlayer( write_file, tractor, consumer, 0, self.length) clip_renderer.wait_for_producer_end_stop = True clip_renderer.start() Gdk.threads_enter() info_text = _("<b>Rendering Placeholder Media For:</b> " ) + self.data.get_program_name() + ".blend" progress_bar = Gtk.ProgressBar() dialog = rendergui.clip_render_progress_dialog( None, self.window_text, info_text, progress_bar, gui.editor_window.window, True) motion_progress_update = renderconsumer.ProgressWindowThread( dialog, progress_bar, clip_renderer, self.progress_thread_complete) motion_progress_update.start() Gdk.threads_leave() while clip_renderer.stopped == False: time.sleep(0.5) Gdk.threads_enter() self.callback(write_file, self.data) Gdk.threads_leave()
def write_frames(self): clip_frames = os.listdir(self.folder) frame_count = 1 for clip_frame in clip_frames: if self.abort == True: return self.do_update_callback(frame_count) file_numbers_list = re.findall(r'\d+', clip_frame) filled_number_str = str(file_numbers_list[0]).zfill(3) clip_frame_path = os.path.join(self.folder, clip_frame) rendered_file_path = self.out_folder + self.frame_name + "_" + filled_number_str + ".png" script_str = "gmic " + clip_frame_path + " " + self.user_script + " -output " + rendered_file_path if frame_count == 1: # first frame displays shell output and does error checking FLOG = open(userfolders.get_cache_dir() + "log_gmic_preview", 'w') p = subprocess.Popen(script_str, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() # read log f = open(userfolders.get_cache_dir() + "log_gmic_preview", 'r') out = f.read() f.close() self.do_render_output_callback(p, out) else: FLOG = open(userfolders.get_cache_dir() + "log_gmic_preview", 'w') p = subprocess.Popen(script_str, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() frame_count = frame_count + 1
def launch_phantom(): respaths.PHANTOM_JAR if _phantom_found == False: info_row = guiutils.get_centered_box([ Gtk.Label( _("Phantom2D tool has not been installed on your system.")) ]) link_info_row = guiutils.get_centered_box( [Gtk.Label(_("Install instructions:"))]) link = Gtk.LinkButton.new("https://github.com/jliljebl/phantom2D") link_row = guiutils.get_centered_box([link]) dir_info_row = guiutils.get_centered_box( [Gtk.Label(_("Install directory for Phantom2D tool:"))]) dir_label = Gtk.Label(respaths.PHANTOM_JAR.rstrip("/Phantom2D.jar")) dir_label.set_selectable(True) dir_row = guiutils.get_centered_box( [Gtk.Label(respaths.PHANTOM_JAR.rstrip("/Phantom2D.jar"))]) dir_row.set_margin_top(8) panel = Gtk.VBox() panel.pack_start(info_row, False, False, 0) panel.pack_start(guiutils.pad_label(12, 24), False, False, 0) panel.pack_start(link_info_row, False, False, 0) panel.pack_start(link_row, False, False, 0) panel.pack_start(guiutils.pad_label(12, 24), False, False, 0) panel.pack_start(dir_info_row, False, False, 0) panel.pack_start(dir_row, False, False, 0) dialogutils.panel_ok_dialog(_("Phantom2D not found"), panel) return FLOG = open(userfolders.get_cache_dir() + "log_phantom", 'w') subprocess.Popen([str(respaths.LAUNCH_DIR + "flowbladephantom") + " " + str(respaths.PHANTOM_JAR) \ + " profile" + " " + _get_underscored_profile() \ + " cachefolder " + userfolders.get_cache_dir() + appconsts.PHANTOM_DIR + "/" + appconsts.PHANTOM_DISK_CACHE_DIR], shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) print "Phantom2D launched"
def _read_offsets(idstr): offsets_file = userfolders.get_cache_dir() + clapperless.OFFSETS_DATA_FILE + "_"+ idstr with open(offsets_file) as f: file_lines = f.readlines() file_lines = [x.rstrip("\n") for x in file_lines] _files_offsets = {} for line in file_lines: tokens = line.split(clapperless.MAGIC_SEPARATOR) _files_offsets[tokens[0]] = tokens[1] os.remove(offsets_file) return _files_offsets
def autosaves_many_recovery_dialog(): autosaves_file_names = get_autosave_files() now = time.time() autosaves = [] for a_file_name in autosaves_file_names: autosave_path = userfolders.get_cache_dir() + AUTOSAVE_DIR + a_file_name autosave_object = utils.EmptyClass() autosave_object.age = now - os.stat(autosave_path).st_mtime autosave_object.path = autosave_path autosaves.append(autosave_object) autosaves = sorted(autosaves, key=lambda autosave_object: autosave_object.age) dialogs.autosaves_many_recovery_dialog(autosaves_many_dialog_callback, autosaves, gui.editor_window.window) return False
def validate_program(self): try: script_file = open(self.container_data.program) user_script = script_file.read() test_out_file = userfolders.get_cache_dir( ) + "/gmic_cont_clip_test.png" test_in_file = str(respaths.IMAGE_PATH + "unrendered_blender.png").replace( " ", "\ ") # we just need some valid input script_str = "gmic " + test_in_file + " " + user_script + " -output " + test_out_file # Render preview and write log FLOG = open( userfolders.get_cache_dir() + "gmic_container_validating_log", 'w') p = subprocess.Popen(script_str, shell=True, stdin=FLOG, stdout=FLOG, stderr=FLOG) p.wait() FLOG.close() if p.returncode == 0: return (True, None) # no errors else: # read error log, and return. f = open( userfolders.get_cache_dir() + "gmic_container_validating_log", 'r') out = f.read() f.close() return (False, out) except Exception as e: return (False, str(e))
def _app_destroy(): # Close threads and stop mlt consumers editorstate.player.shutdown() # has ticker thread and player threads running audiomonitoring.close() # Wait threads to stop while((editorstate.player.ticker.exited == False) and (audiomonitoring._update_ticker.exited == False) and (audiowaveform.waveform_thread != None)): pass # Delete autosave file try: os.remove(userfolders.get_cache_dir() + get_instance_autosave_file()) except: print "Delete autosave file FAILED" # Exit gtk main loop. Gtk.main_quit()
def create_match_frame_image_surface(self, frame_name): # Create non-scaled surface matchframe_path = userfolders.get_cache_dir() + appconsts.TRIM_VIEW_DIR + "/" + frame_name surface = cairo.ImageSurface.create_from_png(matchframe_path) # Create and return scaled surface profile_screen_ratio = float(PROJECT().profile.width()) / float(PROJECT().profile.height()) match_frame_width, match_frame_height = self.get_match_frame_panel_size() scaled_surface = cairo.ImageSurface(cairo.FORMAT_ARGB32, int(match_frame_width), int(match_frame_height)) cr = cairo.Context(scaled_surface) cr.scale(float(match_frame_width) / float(surface.get_width()), float(match_frame_height) / float(surface.get_height())) cr.set_source_surface(surface, 0, 0) cr.paint() return scaled_surface
def main(): args = cl_parser() print args.idstr offsets_output = process_files(args) # Write out offsets data out_str = "" for file_offset in offsets_output: f, offset = file_offset out_str = out_str + f + MAGIC_SEPARATOR + str(offset) + "\n" userfolders.init() output_file = userfolders.get_cache_dir() + OFFSETS_DATA_FILE + "_"+ args.idstr f = open(output_file, 'w') f.write(out_str) f.close()
def add_recent_project_path(path): """ Called when project is saved. """ if len(recent_projects.projects) == MAX_RECENT_PROJS: recent_projects.projects.pop(-1) # Reject autosaves. autosave_dir = userfolders.get_cache_dir() + appconsts.AUTOSAVE_DIR file_save_dir = os.path.dirname(path) + "/" if file_save_dir == autosave_dir: return try: index = recent_projects.projects.index(path) recent_projects.projects.pop(index) except: pass recent_projects.projects.insert(0, path) save()
def run(self): """ Writes thumbnail image from file producer """ # Create consumer matchframe_path = userfolders.get_cache_dir() + appconsts.TRIM_VIEW_DIR + "/" + self.frame_name consumer = mlt.Consumer(PROJECT().profile, "avformat", matchframe_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") # Create one frame producer producer = mlt.Producer(PROJECT().profile, str(self.clip_path)) producer.set("mlt_service", "avformat-novalidate") producer = producer.cut(int(self.clip_frame), int(self.clip_frame)) # Delete match frame try: os.remove(matchframe_path) except: # This fails when done first time ever pass # Save producer and consumer for view needing continues match frame update global _producer, _consumer if _widget.view != START_TRIM_VIEW and _widget.view != END_TRIM_VIEW: _producer = producer _consumer = consumer # Connect and write image consumer.connect(producer) consumer.run() # Wait until new file exists while os.path.isfile(matchframe_path) != True: time.sleep(0.1) # Do completion callback self.completion_callback(self.frame_name)
def _get_match_frame_path(): return userfolders.get_cache_dir() + appconsts.TRIM_VIEW_DIR + "/" + MATCH_FRAME
def _get_assets_file(): return userfolders.get_cache_dir() + MEDIA_ASSETS_IMPORT_FILE