def check_available_features(repo): try: print "Detecting environment..." global acodecs global vcodecs global formats global services global transitions global environment_detection_success acodecs = [] vcodecs = [] formats = [] services = {} transitions = {} # video codecs cv = mlt.Consumer(mlt.Profile(), "avformat") cv.set('vcodec', 'list') cv.start() codecs = mlt.Properties(cv.get_data('vcodec')) for i in range(0, codecs.count()): vcodecs.append(codecs.get(i)) # audio codecs ca = mlt.Consumer(mlt.Profile(), "avformat") ca.set('acodec', 'list') ca.start() codecs = mlt.Properties(ca.get_data('acodec')) for i in range(0, codecs.count()): acodecs.append(codecs.get(i)) # formats cf = mlt.Consumer(mlt.Profile(), "avformat") cf.set('f', 'list') cf.start() codecs = mlt.Properties(cf.get_data('f')) for i in range(0, codecs.count()): formats.append(codecs.get(i)) # filters envservices = mlt.Repository.filters(repo) for i in range(mlt.Properties.count(envservices)): services[mlt.Properties.get_name(envservices, i)] = True # transitions envtransitions = mlt.Repository.transitions(repo) for i in range(mlt.Properties.count(envtransitions)): transitions[mlt.Properties.get_name(envtransitions, i)] = True print "MLT detection succeeded, " + str(len(formats)) + " formats, " \ + str(len(vcodecs)) + " video codecs and " + str(len(acodecs)) + " audio codecs found." print str(len(services)) + " MLT services found." environment_detection_success = True except: print "Environment detection failed, environment unknown." GObject.timeout_add(2000, _show_failed_environment_info)
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_thumbnail_image(profile, file_path, action_object): """ Writes thumbnail image from file producer """ # Get data thumbnail_path = action_object.get_container_thumbnail_path() # Create consumer consumer = mlt.Consumer(profile, "avformat", thumbnail_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") # Create one frame producer producer = mlt.Producer(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_frames(self, clip_folder, frame_name, mark_in, mark_out): """ Writes thumbnail image from file producer """ # Get data render_path = clip_folder + frame_name + "_%04d." + "png" self.consumer = mlt.Consumer(_current_profile, "avformat", str(render_path)) self.consumer.set("real_time", -1) self.consumer.set("rescale", "bicubic") self.consumer.set("vcodec", "png") self.frame_producer = self.producer.cut(mark_in, mark_out) self.consumer.connect(self.frame_producer) self.frame_producer.set_speed(0) self.frame_producer.seek(0) self.frame_producer.set_speed(1) self.consumer.start() print("Rendering frames range") while self.running: # set false at shutdown() for abort if self.frame_producer.frame() >= mark_out: self.callback(self.frame_producer.frame() - mark_in) time.sleep( 2.0) # This seems enough, other methods produced bad waits self.running = False else: self.callback(self.frame_producer.frame()) time.sleep(0.2)
def new_sdl_consumer(self): """ Create a new SDL consumer and attach it to the producer """ # create and set new consumer self.c = mlt.Consumer( self.profile, str(self.main_form.settings.general["output_mode"])) self.c.set("real_time", 1)
def write_image(self, file_path): """ Writes thumbnail image from file producer """ # Get data md_str = md5.new(file_path).hexdigest() thumbnail_path = editorpersistance.prefs.thumbnail_folder + "/" + 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_frames(self, clip_folder, frame_name, mark_in, mark_out): """ Writes thumbnail image from file producer """ # Get data render_path = clip_folder + frame_name + "_%04d." + "png" self.consumer = mlt.Consumer(self.profile, "avformat", str(render_path)) self.consumer.set("real_time", -1) self.consumer.set("rescale", "bicubic") self.consumer.set("vcodec", "png") self.frame_producer = self.producer.cut(mark_in, mark_out) self.consumer.connect(self.frame_producer) self.frame_producer.set_speed(0) self.frame_producer.seek(0) self.frame_producer.set_speed(1) self.consumer.start() while self.running: # set false at shutdown() for abort if self.frame_producer.frame() >= mark_out: self.callback(self.frame_producer.frame() - mark_in) time.sleep( 2.0) # This seems enough, other methods produced bad waits # IF WE CAN REMOVE THIS WAIT. THAT WOULD BE GOOD. self.running = False else: self.callback( self.frame_producer.frame() ) # This is wrong for container clips but we fix it there not break G'mic tool, lazy yeah... time.sleep(0.2)
def get_img_seq_render_consumer(file_path, profile, encoding_option): #render_path = "%1/%2-%05d.%3" + file_path args_vals_list = encoding_option.get_args_vals_tuples_list(profile) vcodec = None for arg_val in args_vals_list: arg, val = arg_val if arg == "vcodec": vcodec = val render_path = os.path.dirname(file_path) + "/" + os.path.basename( file_path).split(".")[0] + "_%05d." + encoding_option.extension consumer = mlt.Consumer(profile, "avformat", str(render_path)) # Jan-2017 - SvdB - perf_value instead of -1 if editorpersistance.prefs.perf_drop_frames == True: perf_value = 1 * editorpersistance.prefs.perf_render_threads else: perf_value = -1 * editorpersistance.prefs.perf_render_threads consumer.set("real_time", perf_value) consumer.set("rescale", "bicubic") consumer.set("vcodec", str(vcodec)) print "img seq render consumer created, path:" + str( render_path) #+ ", args: " + args_msg return consumer
def run(self): tractor = self.tractor tractor.set_speed(0) tractor.seek(0) # Wait until producer is at start while tractor.frame() != 0: time.sleep(0.1) # Get render consumer xml_consumer = mlt.Consumer(PROJECT().profile, "xml", str(self.file_name)) # Connect and start rendering xml_consumer.connect(tractor) xml_consumer.start() tractor.set_speed(1) # Wait until done while xml_consumer.is_stopped() == False: print "In XML render wait loop..." time.sleep(0.1) print "XML compound clip render done" self.render_done_callback(self.file_name, self.media_name)
def get_formats(self, format=None): try: formats_raw = [] # Create the consumer c = mlt.Consumer(mlt.Profile(), "avformat") # Ask for video codecs supports c.set('f', 'list') # Start the consumer to generate the list c.start() # Get the vcodec property codecs = mlt.Properties(c.get_data('f')) # Display the list of codecs for i in range(0, codecs.count()): formats_raw.append(codecs.get(i)) # sort list formats_raw.sort() return formats_raw except: # If the above code fails, use an older technique which uses the 'melt' # command line, and parses the output print "Warning: Could not get list of formats using the MLT API. Falling back to 'melt' executable." return self.get_formats_fallback(format)
def get_img_seq_render_consumer(profile): #render_path = "%1/%2-%05d.%3" + file_path render_path = get_temp_frames_folder() + "/" + FRAME_NAME + "_%05d.png" print render_path consumer = mlt.Consumer(profile, "avformat", str(render_path)) consumer.set("real_time", -1) consumer.set("rescale", "bicubic") consumer.set("vcodec", "png") print "img seq render consumer created, path:" + str(render_path) #+ ", args: " + args_msg return consumer
def write_frame(self, clip_folder, frame): frame_path = clip_folder + "frame" + str(frame) + ".png" # Create consumer consumer = mlt.Consumer(_current_profile, "avformat", frame_path) consumer.set("real_time", 0) consumer.set("vcodec", "png") frame_producer = self.producer.cut(frame, frame) # Connect and write image consumer.connect(frame_producer) consumer.run()
def create_sdl_consumer(self): """ Creates consumer with sdl output to a gtk+ widget. """ # Create consumer and set params self.consumer = mlt.Consumer(self.profile, "sdl") self.consumer.set("real_time", 1) self.consumer.set("rescale", "bicubic") # MLT options "nearest", "bilinear", "bicubic", "hyper" self.consumer.set("resize", 1) self.consumer.set("progressive", 1) # Hold ref to switch back from rendering self.sdl_consumer = self.consumer
def write_image(self): """ Writes thumbnail image from file producer """ clip_path = self.clip.path # Create consumer matchframe_new_path = utils.get_hidden_user_dir_path( ) + 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 = utils.get_hidden_user_dir_path( ) + 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 get_mlt_render_consumer(file_path, profile, args_vals_list): consumer = mlt.Consumer(profile, "avformat", str(file_path)) consumer.set("real_time", -1) consumer.set("rescale", "bicubic") args_msg = "" for arg_val in args_vals_list: k, v = arg_val consumer.set(str(k), str(v)) args_msg = args_msg + str(k) + "=" + str(v) + ", " args_msg = args_msg.strip(", ") print "render consumer created, path:" + str( file_path) + ", args: " + args_msg return consumer
def run(self): print("Starting XML render") player = PLAYER() # Don't try anything if somehow this was started # while timeline rendering is running if player.is_rendering: print("Can't render XML when another render is already running!") return # Stop all playback before producer is disconnected self.current_playback_frame = player.producer.frame() player.ticker.stop_ticker() player.consumer.stop() player.producer.set_speed(0) player.producer.seek(0) # Wait until producer is at start while player.producer.frame() != 0: time.sleep(0.1) # Get render producer if self.rendered_sequence == None: # default is current sequence timeline_producer = PROJECT().c_seq.tractor else: timeline_producer = self.rendered_sequence.tractor # Get render consumer xml_consumer = mlt.Consumer(PROJECT().profile, "xml", str(self.file_name)) # Connect and start rendering xml_consumer.connect(timeline_producer) xml_consumer.start() timeline_producer.set_speed(1) # Wait until done while xml_consumer.is_stopped() == False: print("In XML render wait loop...") time.sleep(0.1) print("XML render done") # Get app player going again player.connect_and_start() player.seek_frame(0) self.render_done_callback(self.data)
def get_img_seq_render_consumer_codec_ext(file_path, profile, vcodec, ext): render_path = os.path.dirname(file_path) + "/" + os.path.basename(file_path).split(".")[0] + "_%05d." + ext consumer = mlt.Consumer(profile, "avformat", str(render_path)) # Jan-2017 - SvdB - perf_value instead of -1 if performance_settings_enabled == True: if editorpersistance.prefs.perf_drop_frames == True: perf_value = 1 * editorpersistance.prefs.perf_render_threads else: perf_value = -1 * editorpersistance.prefs.perf_render_threads consumer.set("real_time", perf_value) else: consumer.set("real_time", -1) consumer.set("rescale", "bicubic") consumer.set("vcodec", str(vcodec)) return consumer
def render_screen_shot(frame, render_path, vcodec): producer = current_sequence().tractor consumer = mlt.Consumer(PROJECT().profile, "avformat", str(render_path)) consumer.set("real_time", -1) consumer.set("rescale", "bicubic") consumer.set("vcodec", str(vcodec)) renderer = renderconsumer.FileRenderPlayer(None, producer, consumer, frame, frame + 1) renderer.wait_for_producer_end_stop = False renderer.consumer_pos_stop_add = 2 # Hack, see FileRenderPlayer renderer.start() while renderer.has_started_running == False: time.sleep(0.05) while renderer.stopped == False: time.sleep(0.05)
def __init__(self, loop_filename): mlt.Factory().init() self.profile = mlt.Profile() self.mlt_consumer = mlt.Consumer(self.profile, self.consumer_type_) #self.mlt_consumer.set("fullscreen", 1) self.loop = mlt.Producer(self.profile, loop_filename) #self.loop.set("force_aspect_ratio", 1.0) self.loop.set("eof", "loop") #self.playing_consumer = None self.mlt_consumer.set("rescale", "none") #self.overlay_call = None self.state = None self.pause_screen() #self.mlt_consumer.listen("producer-changed", None, self.blah ) self.mlt_consumer.start() print(("MLT profile desc", self.profile.description())) print(("Framerate", self.profile.frame_rate_num())) print(("Width/Height/Progressive", self.profile.width(), self.profile.height(), self.profile.progressive()))
def create_sdl_consumer(self): """ Creates consumer with sdl output to a gtk+ widget. """ # SDL 2 consumer is created after #if editorstate.get_sdl_version() == editorstate.SDL_2: # print "refuse SDL1 consumer" # return print "Create SDL1 consumer..." # Create consumer and set params self.consumer = mlt.Consumer(self.profile, "sdl") self.consumer.set("real_time", 1) self.consumer.set("rescale", "bicubic") # MLT options "nearest", "bilinear", "bicubic", "hyper" self.consumer.set("resize", 1) self.consumer.set("progressive", 1) # Hold ref to switch back from rendering self.sdl_consumer = self.consumer
def get_mlt_render_consumer(file_path, profile, args_vals_list): consumer = mlt.Consumer(profile, "avformat", str(file_path)) # Jan-2017 - SvdB - perf_value instead of -1 if editorpersistance.prefs.perf_drop_frames == True: perf_value = 1 * editorpersistance.prefs.perf_render_threads else: perf_value = -1 * editorpersistance.prefs.perf_render_threads consumer.set("real_time", perf_value) consumer.set("rescale", "bicubic") args_msg = "" for arg_val in args_vals_list: k, v = arg_val consumer.set(str(k), str(v)) args_msg = args_msg + str(k) + "=" + str(v) + ", " args_msg = args_msg.strip(", ") #print "render consumer created, path:" + str(file_path) + ", args: " + args_msg return consumer
def get_img_seq_render_consumer(file_path, profile, encoding_option): #render_path = "%1/%2-%05d.%3" + file_path args_vals_list = encoding_option.get_args_vals_tuples_list(profile) vcodec = None for arg_val in args_vals_list: arg, val = arg_val if arg == "vcodec": vcodec = val render_path = os.path.dirname(file_path) + "/" + os.path.basename( file_path).split(".")[0] + "_%05d." + encoding_option.extension consumer = mlt.Consumer(profile, "avformat", str(render_path)) consumer.set("real_time", -1) consumer.set("rescale", "bicubic") consumer.set("vcodec", str(vcodec)) print "img seq render consumer created, path:" + str( render_path) #+ ", args: " + args_msg return consumer
def run(self): """ Writes thumbnail image from file producer """ # Create consumer matchframe_path = utils.get_hidden_user_dir_path( ) + 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 create_sdl2_video_consumer(self): """ Creates consumer with sdl output to a gtk+ widget, SDL2 only.. """ widget = gui.editor_window.tline_display self.set_sdl_xwindow(widget) # Create consumer and set params self.consumer = mlt.Consumer(self.profile, "sdl") self.consumer.set("real_time", 1) self.consumer.set("rescale", "bicubic") # MLT options "nearest", "bilinear", "bicubic", "hyper" self.consumer.set("resize", 1) self.consumer.set("progressive", 1) self.consumer.set("window_id", str(self.xid)) alloc = gui.editor_window.tline_display.get_allocation() self.consumer.set("window_width", str(alloc.width)) self.consumer.set("window_height", str(alloc.height)) self.consumer.set("window_type", "widget") self.consumer.set("renderer_type", "software") # Hold ref to switch back from rendering self.sdl_consumer = self.consumer self.connect_and_start()
#!/usr/bin/env python # -*- coding: utf-8 -*- # Import required modules from __future__ import print_function import mlt # Start the mlt system mlt.Factory().init() # Create the consumer c = mlt.Consumer(mlt.Profile(), "avformat") # Ask for video codecs supports c.set('vcodec', 'list') # Start the consumer to generate the list c.start() # Get the vcodec property codecs = mlt.Properties(c.get_data('vcodec')) # Print the list of codecs for i in range(0, codecs.count()): print(codecs.get(i))
mlt.Factory.init() # Establish a pipeline profile = mlt.Profile("atsc_1080i_5994") #profile = mlt.Profile('square_ntsc_wide') profile.set_explicit(1) tractor = mlt.Tractor() tractor.set('eof', 'loop') playlist = mlt.Playlist() playlist.append(mlt.Producer(profile, 'color:')) # Setup the consumer consumer = 'decklink:0' if len(sys.argv) > 1: consumer = sys.argv[1] consumer = mlt.Consumer(profile, consumer) consumer.connect(playlist) #consumer.set("real_time", -2) consumer.start() def switch(resource): global playlist resource = resource playlist.lock() playlist.append(mlt.Producer(profile, str(resource))) playlist.remove(0) playlist.unlock() state = {} state['tempdir'] = None
def GetFile(self, file_location, only_thumbnail=True, new_file_base_name=None, start_time=0.00, end_time=None): """ Use this method to generate an LibreShotFile object based on the URL (or file location) of a video or audio file. Each time you call this method, it will lock this thread (and LibreShot's main thread) until it has finished. """ """ file_location: The location of the file on the hard drive, including the name and extension. only_thumbnail: True if only a thumbnail should be grabbed from the file, False if image sequence. new_file_base_name: The name of the folder and the base for the image sequence name, not including the path. start_time: The time to start grabbing frames from the file, in seconds. end_time: The time to end grabbing frames from the file, in seconds. None = To the last frame. """ try: # determine name and location of thumbnail image self.file_name = file_location self.thumbnail_path = "" self.file_type = "video" self.label = "" self.unique_id = str(uuid.uuid1()) project_path = self.project.folder (dirName, fileName) = os.path.split(file_location) (fileBaseName, fileExtension) = os.path.splitext(fileName) fileExtension = fileExtension.replace(".", "") uniqueFileBaseName = self.unique_id actual_thumbnail_path = project_path + "/thumbnail/" + uniqueFileBaseName + "_" + fileExtension + "_1.png" if only_thumbnail: # just get 1 thumbnail frame self.thumbnail_path = project_path + "/thumbnail/" + uniqueFileBaseName + "_" + fileExtension + "_%d.png" # set the profile self.profile = mlt.Profile("quarter_ntsc") else: if new_file_base_name == None or new_file_base_name == fileBaseName: # choose the same folder as the name (without extension) as default self.thumbnail_path = os.path.join( dirName, fileBaseName, fileBaseName + "_%d.png") else: # export a part of the video to a folder under the folder with the same name as the file. self.thumbnail_path = os.path.join( dirName, fileBaseName, new_file_base_name, new_file_base_name + "_%d.png") # re-init the mlt factory mlt.Factory.init() # Create the producer self.p = mlt.Producer(self.profile, '%s' % file_location) # Check if clip is valid (otherwise a seg fault) if self.p.is_valid() == False: return None # Check for invalid files - badly generated video files can have # a length of 0 or -1, e.g. # https://bugs.launchpad.net/ubuntu/+source/libreshot/+bug/927755, https://bugs.launchpad.net/kazam/+bug/925238 if self.p.get_length() < 1 or self.p.get_length() == 0x7fffffff: return None # check the 'seekable' property # If it is zero, then MLT is likely to have problems with this file. if self.p.get("seekable") == '0': messagebox.show( _("Warning!"), _("The file %s has properties that may prevent it working properly in LibreShot.\nYou may need to transcode it to another format." ) % (self.file_name)) # create the consumer self.c = mlt.Consumer(self.profile, "avformat", self.thumbnail_path) # set some consumer properties self.c.set("real_time", 0) self.c.set("vcodec", "png") # determine length of clip in seconds producer_fps = float(self.p.get_fps()) first_frame = int(round(producer_fps * start_time)) # Whole clip if end_time = None if end_time == None: last_frame = self.p.get_length() else: last_frame = int(round(producer_fps * end_time)) max_frames = last_frame - first_frame # determine dimensions height = 0 width = 0 if self.p.get("height"): height = int(self.p.get("height")) if self.p.get("width"): width = int(self.p.get("width")) audio_index = self.p.get_int("audio_index") video_index = self.p.get_int("video_index") audio_property = "meta.media.%s.codec.long_name" % audio_index if self.p.get(audio_property): self.audio_codec = self.p.get(audio_property) else: self.audio_codec = "" video_property = "meta.media.%s.codec.long_name" % video_index if self.p.get(video_property): self.video_codec = self.p.get(video_property) else: self.video_codec = "" if self.p.get_frame(): frame = self.p.get_frame() self.audio_frequency = frame.get_int("frequency") self.audio_channels = frame.get_int("channels") # determine if this is an image is_image = False if self.p.get_length( ) == 15000 and video_index == 0 and audio_index == 0: # images always have exactly 15000 frames is_image = True self.file_type = "image" # set the max length of the image to 300 seconds (i.e. 5 minutes) max_frames = producer_fps * 300 # get actual height & width of image (since MLT defaults to 1 x 1) width, height = self.get_image_size(file_location) # determine length if only_thumbnail: calculate_length = self.p.get_length() / producer_fps else: calculate_length = max_frames / producer_fps if is_image: # set the length to 300 seconds (i.e. 5 minutes) calculate_length = float(300) # set thumbnail image (if no height & width are detected) if (height == False or width == False) and (is_image == False): self.thumbnail_path = "" self.file_type = "audio" # get the 1st frame (if not exporting all frames) if only_thumbnail: max_frames = float(self.p.get_length()) - 1.0 self.p = self.p.cut(1, 1) # get the frames in an interval else: self.p = self.p.cut(first_frame, last_frame) # mark as image seq self.label = "Image Sequence" self.file_type = "image sequence" # Check if clip is valid (otherwise a seg fault) if self.p.is_valid() == False: return None # connect the producer and consumer self.c.connect(self.p) # Start the consumer, and lock the thread until it's done (to prevent crazy seg fault errors) # Only start if the media item has a thumbnail location (i.e. no audio thumbnails) if self.thumbnail_path: self.c.run() # create an libreshot file object newFile = files.LibreShotFile(self.project) # thumbnails and image sequences are stored at different locations if only_thumbnail: newFile.name = file_location else: newFile.name = self.thumbnail_path newFile.length = calculate_length newFile.thumb_location = actual_thumbnail_path newFile.videorate = (self.p.get_fps(), 0) newFile.height = height newFile.width = width newFile.max_frames = max_frames newFile.fps = producer_fps newFile.file_type = self.file_type newFile.label = self.label newFile.audio_channels = self.audio_channels newFile.audio_codec = self.audio_codec newFile.audio_frequency = self.audio_frequency newFile.video_codec = self.video_codec # return the LibreShotFile object return newFile except Exception: print "Failed to import file: %s" % file_location
def get_thumb_at_frame(self, filename, frame=1, new_name="", full_size=True): """ if new_name = None, it will default to 'name_fileext + "_%d.ext' in the thumbnail folder. if full_size is True, a full size frame will be extracted (based on the project profile). Else: quarter_ntsc""" self.file_name = filename project_path = self.project.folder myPath = self.file_name (dirName, fileName) = os.path.split(myPath) (fileBaseName, fileExtension) = os.path.splitext(fileName) fileExtension = fileExtension.replace(".", "") # Init mlt factory mlt.Factory.init() # set the profile if full_size: self.profile = profiles.mlt_profiles(self.project).get_profile( self.project.project_type) else: self.profile = mlt.Profile("quarter_ntsc") # Create the producer self.p = mlt.Producer(self.profile, '%s' % self.file_name) # Check if clip is valid (otherwise a seg fault) if self.p.is_valid() == False: return None if new_name == "": # just get 1 thumbnail frame self.thumbnail_path = project_path + "/thumbnail/" + fileBaseName + "_" + fileExtension + "_%d.png" else: #for snapshots, use the new file name #don't use the thumbnail path for the new file self.thumbnail_path = project_path + "/" + new_name # create the consumer self.c = mlt.Consumer(self.profile, "avformat", self.thumbnail_path) # set some consumer properties self.c.set("real_time", 0) self.c.set("vcodec", "png") #get the frame self.p = self.p.cut(frame, frame) # Check if clip is valid (otherwise a seg fault) if self.p.is_valid() == False: return None # connect the producer and consumer self.c.connect(self.p) # Only start if the media item has a thumbnail location (i.e. no audio thumbnails) if self.thumbnail_path: self.c.run()
def run(self): # FIXME: Is this relevant - doesn't seem to be used in this method? self.override_path = None self.alternate_progress_bar = None # track wheather the thread is playing or not self.isPlaying = False # track if this thread should die self.amAlive = True # Start the mlt system self.f = mlt.Factory().init() # set the MLT profile object... specific in the project properties self.profile = profiles.mlt_profiles(self.project).get_profile( self.project.project_type) # Create the producer self.p = mlt.Producer(self.profile, 'xml:%s' % self.file_name) if self.p.is_valid(): # set speed to zero (i.e. pause) self.pause() # PREVIEW mode self.c = mlt.Consumer( self.profile, str(self.main_form.settings.general["output_mode"])) self.c.set("real_time", 1) # Connect the producer to the consumer self.c.connect(self.p) # Start the consumer self.c.start() # Get the FPS self.fps = self.project.fps() # init the render percentage self.fraction_complete = 0.0 # Wait until the user stops the consumer while self.amAlive: # get current frame current_frame = float(self.p.position()) total_frames = float(self.p.get_length() - 1) decimal_complete = current_frame / total_frames percentage_complete = decimal_complete * 100.0 # only calculate position / percentage when playing if self.c.is_stopped() == False: # move play head new_time = current_frame / float(self.fps) if self.mode == "render": # update Export Dialog Progress Bar self.fraction_complete = decimal_complete if self.project.form.frmExportVideo: gobject.idle_add( self.project.form.frmExportVideo. update_progress, self.fraction_complete) elif self.mode == "preview": if self.alternate_progress_bar: # update alternateive progress bar (if any) of video # this is used by the clip properties window if self.alternate_progress_bar: gobject.idle_add( self.alternate_progress_bar.set_value, percentage_complete) else: # update play-head if self.project.sequences[0]: gobject.idle_add( self.project.sequences[0].move_play_head, new_time) # update progress bar of video if self.main_form.hsVideoProgress: gobject.idle_add( self.main_form.hsVideoProgress.set_value, percentage_complete) gobject.idle_add( self.main_form.scroll_to_playhead) # pause video when 100% if percentage_complete == 100: self.pause() elif self.mode == "override": # update progress bar of video if self.main_form.hsVideoProgress: gobject.idle_add( self.main_form.hsVideoProgress.set_value, percentage_complete) # wait 1/5 of a second time.sleep(0.1) else: if self.mode == "render": # update Export Dialog Progress Bar if self.fraction_complete > 0.0: # update progress bar to 100% if self.project.form.frmExportVideo: gobject.idle_add( self.project.form.frmExportVideo. update_progress, 1.0) # reset the fraction self.fraction_complete = 0.0 # wait a bit... to cool off the CPU time.sleep(0.1) # clear all the MLT objects self.consumer_stop() self.p = None self.c = None self.profile = None self.f = None else: # Diagnostics print "ERROR WITH %s" % self.file_name
def load_xml(self): # get reference to translate gettext method _ = self._ # re-init the mlt factory mlt.Factory.init() # Create the consumer if self.mode == "render": # RENDER MOVIE mode # stop the consumer self.consumer_stop() # Create the producer self.p = mlt.Producer(self.profile, 'xml:%s' % self.file_name) if self.p.is_valid() == False: print "ERROR WITH %s" % self.file_name return # get export file path folder = self.render_options["folder"] file = self.render_options["file"] format = self.render_options["f"] export_path = "%s.%s" % (os.path.join(folder, file), format) # create consumer self.c = mlt.Consumer(self.profile, "avformat", export_path) # set some RENDER specific options self.c.set("real_time", -1) # set render options if self.render_options["export_to"] == _("Image Sequence"): # image seq self.c.set("vcodec", self.render_options["vcodec"]) else: # video & audio self.c.set("f", format) self.c.set("vcodec", self.render_options["vcodec"]) self.c.set("b", self.render_options["b"]) self.c.set("acodec", self.render_options["acodec"]) self.c.set("ar", self.render_options["ar"]) self.c.set("ac", self.render_options["ac"]) self.c.set("ab", self.render_options["ab"]) if self.render_options["vcodec"] == "libx264": self.c.set("minrate", "0") self.c.set("b_strategy", "1") self.c.set("subcmp", "2") self.c.set("cmp", "2") self.c.set("coder", "1") self.c.set("flags", "+loop") self.c.set("flags2", "dct8x8") self.c.set("qmax", "51") self.c.set("subq", "7") self.c.set("qmin", "10") self.c.set("qcomp", locale.str(float("0.6"))) self.c.set("qdiff", "4") self.c.set("trellis", "1") if format == "dvd": # stolen from ffmpeg.c, void opt_target(const char *arg) self.c.set("maxrate", "9000000") self.c.set("minrate", "0") self.c.set("bufsize", "1835008") self.c.set("packetsize", "2048") self.c.set("muxrate", "10080000") else: # stop the consumer (if sdl_preview mode and an older version of MLT) if self.check_version(0, 6, 0) == False and str( self.main_form.settings.general["output_mode"] ) == "sdl_preview": # stop the consumer self.consumer_stop() # Create the producer self.p = mlt.Producer(self.profile, 'xml:%s' % self.file_name) if self.p.is_valid() == False: print "ERROR WITH %s" % self.file_name return # refresh sdl and pause video self.pause() # connect the producer and consumer self.c.connect(self.p) # start consumer if self.c.is_stopped: self.c.start()