예제 #1
0
	def fps(self):
		# get the profile object
		if self.mlt_profile == None:
			self.mlt_profile = profiles.mlt_profiles(self).get_profile(self.project_type)

		# return the frames per second
		return self.mlt_profile.fps()
예제 #2
0
	def __init__(self, path="profiles.ui", root="frmProfiles", domain="OpenShot", form=None, parent=None, project=None, **kwargs):
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		self.project = project
		self.form = form
		self.parent = parent

		#find path where openshot is running
		self.path = self.project.BASE_DIR
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
			
		self.save_prompt = False
		
		self.frmProfiles.show_all()
		
		#set the default profile
		self.set_project_type_dropdown(self.form.settings.general["default_profile"])
		if not self.cmbProjectType.get_active_text():
			self.set_project_type_dropdown("DV/DVD NTSC")
예제 #3
0
	def fps(self):
		# get the profile object
		if self.mlt_profile == None:
			self.mlt_profile = profiles.mlt_profiles(self).get_profile(self.project_type)

		# return the frames per second
		return self.mlt_profile.fps()
예제 #4
0
	def __init__(self, path="profiles.glade", root="frmProfiles", domain="OpenShot", form=None, project=None, **kwargs):
		SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		self.project = project
		self.form = form

		self.settings = preferences.Settings(self.project)
		self.settings.load_settings_from_xml()

		#find path where openshot is running
		self.path = self.project.BASE_DIR
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
			
		self.save_prompt = False
		
		image = gtk.Image()
		image.set_from_stock(gtk.STOCK_ADD, gtk.ICON_SIZE_BUTTON)
		self.btnImport.set_image(image)
			
		self.frmProfiles.show_all()
		
		#set the default profile
		self.set_project_type_dropdown(self.settings.general["default_profile"])
예제 #5
0
	def __init__(self, mode="", path="NewProject.ui", root="frmNewProject", domain="OpenShot", project=None, **kwargs):
		print "init"
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		self._ = Language_Init.Translator(project).lang.gettext
		_ = self._

		# project instance
		self.project = project
		self.form = project.form

		# check the mode of the form (i.e. new project or save as screen)
		self.mode = mode
		
		# init the project type properties
		self.init_properties()
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
			
			
		# SET THE SAVE FOLDER LOCATION
		if ".openshot" in self.project.folder:
			# This is the openshot default project (set the folder to 'DESKTOP')
			self.fileProjectFolder.set_current_folder(self.project.DESKTOP)
		
		elif len(self.project.folder) > 0:
			# set default folder (if there is a current folder)
			self.fileProjectFolder.set_current_folder(self.project.folder)
			
			
		# init the profile
		self.set_dropdown_values(self.form.settings.general["default_profile"], self.cmbProjectType)
			
		if (self.mode == "saveas"):
			# Save project as
			# Set window title
			self.frmNewProject.set_title(_("Save Project As..."))
			
			# init the project name
			self.txtProjectName.set_text(self.project.name)
			
			# init the profile
			self.set_dropdown_values(self.project.project_type, self.cmbProjectType)
			
		else:
			# New Project
			# Set window title
			self.frmNewProject.set_title(_("Create a Project"))
			
			# init the project name
			self.txtProjectName.set_text(_("Default Project"))
예제 #6
0
	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()
예제 #7
0
	def get_profiles_list(self):
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
예제 #8
0
    def get_profiles_list(self):

        # init the list of possible project types / profiles
        self.profile_list = profiles.mlt_profiles(
            self.project).get_profile_list()

        # loop through each profile, and add it to the dropdown
        for file_name, p in self.profile_list:
            # append profile to list
            self.cmbProjectType.append_text(p.description())
예제 #9
0
	def on_btnSave_clicked(self, widget, *args):
		
		file_name = self.txtProfileName.get_text()
		
		#first check if this name already exists in the 'preset' profiles
		#or USER_PROFILES_DIR
		if profiles.mlt_profiles(self.project).profile_exists(file_name):
			messagebox.show("Openshot", _("A profile with this name already exists. Please use another name."))
			return True
		else:
			self.save_profile()
예제 #10
0
    def set_profile(self, profile_name, load_xml=True):

        # set the MLT profile object... specifiec in the project properties
        self.c.stop()
        self.profile = profiles.mlt_profiles(self.project).get_profile(profile_name)

        # set the FPS
        self.fps = self.project.fps()

        # re-load the mlt objects (i.e. the producer & consumer)
        if load_xml:
            self.load_xml()
예제 #11
0
    def on_btnSave_clicked(self, widget, *args):

        file_name = self.txtProfileName.get_text()

        #first check if this name already exists in the 'preset' profiles
        #or USER_PROFILES_DIR
        if profiles.mlt_profiles(self.project).profile_exists(file_name):
            messagebox.show(
                "Openshot",
                _("A profile with this name already exists. Please use another name."
                  ))
            return True
        else:
            self.save_profile()
예제 #12
0
	def populate_profiles(self):

		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		self.liststore2.clear()
		#self.cmbProfiles.clear()
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProfiles.append_text(str(file_name))
			
		# re-select default profile
		self.set_default_profile(self.form.settings.general["default_profile"])
		if not self.cmbProfiles.get_active_text():
			self.set_default_profile("DV/DVD NTSC")
예제 #13
0
	def init_properties(self):
		# get the mlt profile
		localType = self.cmbProjectType.get_active_text()
		p = profiles.mlt_profiles(self.project).get_profile(localType)

		# populate the labels with values
		self.lblHeightValue.set_text(str(p.height()))
		self.lblWidthValue.set_text(str(p.width()))
		self.lblAspectRatioValue.set_text("%s:%s" % (p.display_aspect_num(), p.display_aspect_den()))
		self.lblFrameRateValue.set_text("%.2f" % float(p.fps()))
		self.lblPixelRatioValue.set_text("%s:%s" % (p.sample_aspect_num(), p.sample_aspect_den()))
		
		if p.progressive():
			self.lblProgressiveValue.set_text("Yes")
		else:
			self.lblProgressiveValue.set_text("No")
예제 #14
0
    def load_settings_from_xml(self):
        settings_path = os.path.join(self.project.USER_DIR, "config.xml")

        #Load the settings from the config file, if it exists
        if os.path.exists(settings_path):

            try:
                xmldoc = xml.parse(settings_path)
            except xml.xml.parsers.expat.ExpatError:
                # Invalid or empty config file
                self.save_settings_to_xml()
                return
            #loop through each settings section and load the values
            #into the relevant dictionary
            for section, section_dict in self.sections.iteritems():
                for key, value in section_dict.iteritems():
                    try:
                        element = xmldoc.getElementsByTagName(key)
                        section_dict[key] = element[0].childNodes[0].data

                        # be sure theme exists
                        if key == "default_theme":
                            if os.path.exists(
                                    os.path.join(self.project.THEMES_DIR,
                                                 section_dict[key])) == False:
                                # DOES NOT EXIST, change to default
                                section_dict[key] = "blue_glass"

                        # be sure profile exists
                        if key == "default_profile":
                            if profiles.mlt_profiles(
                                    self.project).profile_exists(
                                        section_dict[key]) == False:
                                # DOES NOT EXIST, change to default
                                print "Default profile does not exist: %s. Changing default profile to %s." % (
                                    section_dict[key], "DV/DVD NTSC")
                                section_dict[key] = "DV/DVD NTSC"

                    except IndexError:
                        #the list index will go out of range if there is
                        #an extra item in the dictionary which is
                        #not in the config file.
                        pass

        else:
            # no config file found, create one
            self.save_settings_to_xml()
예제 #15
0
    def populate_profiles(self):

        # init the list of possible project types / profiles
        self.profile_list = profiles.mlt_profiles(
            self.project).get_profile_list()

        # loop through each profile, and add it to the dropdown
        self.liststore2.clear()
        #self.cmbProfiles.clear()
        for file_name, p in self.profile_list:
            # append profile to list
            self.cmbProfiles.append_text(str(file_name))

        # re-select default profile
        self.set_default_profile(self.form.settings.general["default_profile"])
        if not self.cmbProfiles.get_active_text():
            self.set_default_profile("DV/DVD NTSC")
예제 #16
0
    def init_properties(self):
        # get the mlt profile
        localType = self.cmbProjectType.get_active_text()
        p = profiles.mlt_profiles(self.project).get_profile(localType)

        # populate the labels with values
        self.lblHeightValue.set_text(str(p.height()))
        self.lblWidthValue.set_text(str(p.width()))
        self.lblAspectRatioValue.set_text(
            "%s:%s" % (p.display_aspect_num(), p.display_aspect_den()))
        self.lblFrameRateValue.set_text("%.2f" % float(p.fps()))
        self.lblPixelRatioValue.set_text(
            "%s:%s" % (p.sample_aspect_num(), p.sample_aspect_den()))

        if p.progressive():
            self.lblProgressiveValue.set_text("Yes")
        else:
            self.lblProgressiveValue.set_text("No")
예제 #17
0
	def on_cboSimpleVideoProfile_changed(self, widget, *args):
		
		# get reference to gettext
		_ = self._
		
		#don't do anything if the combo has been cleared
		if self.cboSimpleVideoProfile.get_active_text():
			profile = str(self.cboSimpleVideoProfile.get_active_text())
			
			#does this profile exist?
			p = profiles.mlt_profiles(self.project).get_profile(profile)
			
			if str(p.description()) != profile:
				messagebox.show(_("Error!"), _("%s is not a valid LibreShot profile. Profile settings will not be applied." % profile))
				
			self.init_properties(profile)
		
			#set the value of the project type dropdown on the advanced tab
			self.set_dropdown_values(profile,self.cmbProjectType)
예제 #18
0
	def on_cboSimpleVideoProfile_changed(self, widget, *args):
		
		# get reference to gettext
		_ = self._
		
		#don't do anything if the combo has been cleared
		if self.cboSimpleVideoProfile.get_active_text():
			profile = str(self.cboSimpleVideoProfile.get_active_text())
			
			#does this profile exist?
			p = profiles.mlt_profiles(self.project).get_profile(profile)
			
			if str(p.description()) != profile:
				messagebox.show(_("Error!"), _("%s is not a valid OpenShot profile. Profile settings will not be applied." % profile))
				
			self.init_properties(profile)
		
			#set the value of the project type dropdown on the advanced tab
			self.set_dropdown_values(profile,self.cmbProjectType)
예제 #19
0
	def load_settings_from_xml(self):
		settings_path = os.path.join(self.project.USER_DIR, "config.xml")
		
		#Load the settings from the config file, if it exists
		if os.path.exists(settings_path):
			
			try:
				xmldoc = xml.parse(settings_path)
			except xml.xml.parsers.expat.ExpatError:
				# Invalid or empty config file
				self.save_settings_to_xml()
				return
			#loop through each settings section and load the values
			#into the relevant dictionary
			for section, section_dict in self.sections.iteritems():
				for key, value in section_dict.iteritems():
					try:
						element = xmldoc.getElementsByTagName(key)
						section_dict[key] = element[0].childNodes[0].data
						
						# be sure theme exists
						if key == "default_theme":
							if os.path.exists(os.path.join(self.project.THEMES_DIR, section_dict[key])) == False:
								# DOES NOT EXIST, change to default
								section_dict[key] = "blue_glass"
								
						# be sure profile exists
						if key == "default_profile":
							if profiles.mlt_profiles(self.project).profile_exists(section_dict[key]) == False:
								# DOES NOT EXIST, change to default
								print "Default profile does not exist: %s. Changing default profile to %s." % (section_dict[key], "DV/DVD NTSC")
								section_dict[key] = "DV/DVD NTSC"
						
					except IndexError:
						#the list index will go out of range if there is
						#an extra item in the dictionary which is
						#not in the config file.
						pass
		
		else:
			# no config file found, create one
			self.save_settings_to_xml()
예제 #20
0
파일: video.py 프로젝트: DjMorgul/libreshot
    def set_profile(self, profile_name, load_xml=True):
        """ set the MLT profile object... specific in the project properties """

        # stop the consumer
        self.consumer_stop()

        # set the new profile
        self.profile = profiles.mlt_profiles(
            self.project).get_profile(profile_name)

        # set the FPS
        self.fps = self.project.fps()

        # create a new consumer
        print "NEW SDL CONSUMER"
        self.new_sdl_consumer()

        # re-load the mlt objects (i.e. the producer & consumer)
        if load_xml:
            self.load_xml()
예제 #21
0
파일: video.py 프로젝트: XXLRay/libreshot
	def set_profile(self, profile_name, load_xml = True):

		""" set the MLT profile object... specific in the project properties """
		
		# stop the consumer
		self.consumer_stop()
		
		# set the new profile
		self.profile = profiles.mlt_profiles(self.project).get_profile(profile_name)

		# set the FPS
		self.fps = self.project.fps()

		# create a new consumer
		print "NEW SDL CONSUMER"
		self.new_sdl_consumer()
		
		
		# re-load the mlt objects (i.e. the producer & consumer)
		if load_xml:
			self.load_xml()
예제 #22
0
    def __init__(self,
                 path="profiles.ui",
                 root="frmProfiles",
                 domain="LibreShot",
                 form=None,
                 parent=None,
                 project=None,
                 **kwargs):
        SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path),
                                     root, domain, **kwargs)

        # Add language support
        _ = Language_Init.Translator(project).lang.gettext
        self._ = _

        self.project = project
        self.form = form
        self.parent = parent

        #find path where libreshot is running
        self.path = self.project.BASE_DIR

        # init the list of possible project types / profiles
        self.profile_list = profiles.mlt_profiles(
            self.project).get_profile_list()

        # loop through each profile, and add it to the dropdown
        for file_name, p in self.profile_list:
            # append profile to list
            self.cmbProjectType.append_text(p.description())

        self.save_prompt = False

        self.frmProfiles.show_all()

        #set the default profile
        self.set_project_type_dropdown(
            self.form.settings.general["default_profile"])
        if not self.cmbProjectType.get_active_text():
            self.set_project_type_dropdown("DV/DVD NTSC")
예제 #23
0
    def init_properties(self, profile):

        # get correct gettext method
        _ = self._

        # get the mlt profile
        localType = profile
        p = profiles.mlt_profiles(self.project).get_profile(localType)

        # populate the labels with values
        self.spnSizeHeight.set_text(str(p.height()))
        self.spnSizeWidth.set_text(str(p.width()))
        self.spnAspect1.set_text(str(p.display_aspect_num()))
        self.spnAspect2.set_text(str(p.display_aspect_den()))
        self.spnFrameRate1.set_text(str(p.frame_rate_num()))
        self.spnFrameRate2.set_text(str(p.frame_rate_den()))
        self.spnPixelRatio1.set_text(str(p.sample_aspect_num()))
        self.spnPixelRatio2.set_text(str(p.sample_aspect_den()))

        if p.progressive():
            self.chkProgressive.set_active(True)
        else:
            self.chkProgressive.set_active(False)
예제 #24
0
	def init_properties(self, profile):
		
		# get correct gettext method
		_ = self._
		
		# get the mlt profile
		localType = profile 
		p = profiles.mlt_profiles(self.project).get_profile(localType)

		# populate the labels with values
		self.spnSizeHeight.set_text(str(p.height()))
		self.spnSizeWidth.set_text(str(p.width()))
		self.spnAspect1.set_text(str(p.display_aspect_num()))
		self.spnAspect2.set_text(str(p.display_aspect_den()))
		self.spnFrameRate1.set_text(str(p.frame_rate_num()))
		self.spnFrameRate2.set_text(str(p.frame_rate_den()))
		self.spnPixelRatio1.set_text(str(p.sample_aspect_num()))
		self.spnPixelRatio2.set_text(str(p.sample_aspect_den()))
			
		if p.progressive():
			self.chkProgressive.set_active(True)
		else:
			self.chkProgressive.set_active(False)
예제 #25
0
	def __init__(self, path="ExportVideo.ui", root="frmExportVideo", domain="OpenShot", form=None, project=None, **kwargs):
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		# set important vars
		self.form = form
		self.project = project
		self.original_project_type = self.project.project_type		# remember the original project type (i.e. mlt_profile)
		
		# Show all controls on this screen
		self.frmExportVideo.show_all()
		
		# set window as MODAL (so they can't mess up the export)
		self.frmExportVideo.set_modal(True)
		
		self.invalid_codecs = []
		
		# init the project type properties
		self.init_properties(self.cmbProjectType.get_active_text())
		
		# set the export file name
		self.txtFileName.set_text(self.project.name)

		# set the export folder as the project folder (if any)
		if ".openshot" in self.project.folder:
			# This is the openshot default project (set the folder to 'DESKTOP')
			self.fileExportFolder.set_current_folder(self.project.DESKTOP)
		else:
			# Set project folder
			self.fileExportFolder.set_current_folder(self.project.folder)
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
					
		export_options = [_("Video & Audio"), _("Image Sequence")]
		# loop through export to options
		for option in export_options:
			# append profile to list
			self.cboExportTo.append_text(option)


		export_types_model = self.cboExportType.get_model()
		export_types_model.clear()
		
		export_types = [_("Export to Folder"), _("Upload to Web")]
		# loop through export to options
		for option in export_types:
			# append profile to list
			self.cboExportType.append_text(option)
		self.set_dropdown_values(_("Export to Folder"), self.cboExportType)
		
		
		upload_model = self.cboUploadServices.get_model()
		upload_model.clear()
		
		self.upload_manager = UploadManager(project, self.form.settings)
		self.upload_services = self.upload_manager.get_services()
		upload_types = self.upload_services.keys()
		upload_types.sort()
		# loop through export to options
		for option in upload_types:
			# append profile to list
			self.cboUploadServices.append_text(option)
		self.set_dropdown_values(_("YouTube"), self.cboUploadServices)
		

		#populate the format/codec drop downs 
		#formats
		format_model = self.cboVIdeoFormat.get_model()
		format_model.clear()
		
		for format in self.form.vformats:
			self.cboVIdeoFormat.append_text(format)
			
		#video codecs
		vcodecs_model = self.cboVideoCodec.get_model()
		vcodecs_model.clear()
		
		for vcodec in self.form.vcodecs:
			self.cboVideoCodec.append_text(vcodec)
			
		#audio codecs
		acodecs_model = self.cboAudioCodec.get_model()
		acodecs_model.clear()
		
		# Add 'none' audio codec
		self.cboAudioCodec.append_text( "none" )
		for acodec in self.form.acodecs:
			# Add the rest of the audio codecs
			self.cboAudioCodec.append_text(acodec)
			
			
		# set the dropdown boxes
		self.set_project_type_dropdown()
		self.set_export_to_dropdown()
		
		#load the simple project type dropdown
		presets = []
		for file in os.listdir(self.project.EXPORT_PRESETS_DIR):
			xmldoc = xml.parse(os.path.join(self.project.EXPORT_PRESETS_DIR,file))
			type = xmldoc.getElementsByTagName("type")
			presets.append(_(type[0].childNodes[0].data))
		#exclude duplicates
		presets = list(set(presets))
		for item in sorted(presets):
			self.cboSimpleProjectType.append_text(item)
			
		#indicate that exporting cancelled
		self.cancelled = False
		
		# create the infobar displaying the missing codec message
		self.use_infobar = True
		self.last_error = None
		try:
			self.infobar = gtk.InfoBar()
			self.content = self.infobar.get_content_area()
			self.label = gtk.Label()
			
			self.image = gtk.Image()
			self.image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
			
			self.content.add(self.image)
			self.content.add(self.label)
			self.vbox1.pack_start(self.infobar)
			self.vbox1.reorder_child(self.infobar, 3)
			self.infobar.set_message_type(gtk.MESSAGE_WARNING)
		except:
			# older version of pygtk can not create an InfoBar
			self.use_infobar = False
예제 #26
0
파일: video.py 프로젝트: DjMorgul/libreshot
    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
예제 #27
0
    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

        # Import required modules
        import time
        import sys
        import gobject

        try:
            import mlt
        except ImportError:
            print "*** ERROR: MLT Python bindings failed to import ***"

            # 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... specifiec 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:
            # set speed to zero (i.e. pause)
            self.p.set_speed(0)

            # Create the consumer
            if self.mode == "render":
                # get export file path
                folder = self.render_options["folder"]
                file = self.render_options["file"]
                export_path = "%s.%s" % (os.path.join(folder, file), self.render_options["f"])

                # RENDER MOVIE mode
                self.c = mlt.Consumer(self.profile, "avformat", export_path)

                # set some RENDER specific options
                self.c.set("real_time", -1)

                # set render options
                self.c.set("f", self.render_options["f"])
                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", "0.6")
                    self.c.set("qdiff", "4")
                    self.c.set("trellis", "1")

            else:
                # PREVIEW mode
                self.c = mlt.Consumer(self.profile, "sdl_preview")
                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

            # pause counter
            pause_counter = 0
            pause_frame = 0

            # Wait until the user stops the consumer
            while self.amAlive:

                # get current frame
                current_frame = self.p.position()

                # only calculate position / percentage when playing
                if self.c.is_stopped() == False:

                    # move play head
                    new_time = float(self.p.position()) / float(self.fps)

                    if self.mode == "render":
                        # update Export Dialog Progress Bar
                        self.fraction_complete = float(self.p.position()) / float(self.p.get_length() - 1)
                        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
                            percentage_complete = (float(self.p.position()) / float(self.p.get_length() - 1)) * float(
                                100
                            )
                            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
                            percentage_complete = (float(self.p.position()) / float(self.p.get_length() - 1)) * float(
                                100
                            )
                            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
                        percentage_complete = (float(self.p.position()) / float(self.p.get_length() - 1)) * float(100)
                        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.2)

                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 1 second
                    time.sleep(1)

                    # clear all the MLT objects
            self.c.stop()
            self.p = None
            self.c = None
            self.profile = None
            self.f = None

        else:
            # Diagnostics
            print "ERROR WITH %s" % self.file_name
예제 #28
0
	def __init__(self, mode="", path="NewProject.glade", root="frmNewProject", domain="OpenShot", project=None, **kwargs):
		print "init"
		SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext

		# project instance
		self.project = project
		self.form = project.form

		# check the mode of the form (i.e. new project or save as screen)
		self.mode = mode
		
		# init the project type properties
		self.init_properties()
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())

		
		# get the model and iterator of the project type dropdown box
		model = self.cmbProjectType.get_model()
		iter = model.get_iter_first()
		while True:
			# get the value of each item in the dropdown
			value = model.get_value(iter, 0)
			
			# check for the matching project type
			if self.project.project_type == value:			
				
				# set the item as active
				self.cmbProjectType.set_active_iter(iter)
		
			# get the next item in the list
			iter = model.iter_next(iter)
			
			# break loop when no more dropdown items are found
			if iter is None:
				break
			
		# SET THE SAVE FOLDER LOCATION
		if ".openshot" in self.project.folder:
			# This is the openshot default project (set the folder to 'DESKTOP')
			self.fileProjectFolder.set_current_folder(self.project.DESKTOP)
		
		elif len(self.project.folder) > 0:
			# set default folder (if there is a current folder)
			self.fileProjectFolder.set_current_folder(self.project.folder)
	
			
		if (self.mode == "saveas"):

			# init the values (based on the mode)
			self.txtProjectName.set_text(self.project.name)
			self.spinProjectLength.set_text(str(self.project.sequences[0].length / 60))
예제 #29
0
파일: Titles.py 프로젝트: XXLRay/libreshot
	def __init__(self, path="titles.ui", root="frmTitles", domain="OpenShot", form=None, project=None, file=None, **kwargs):
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		self.project = project
		self.form = form
		self.file = file

		#find path where openshot is running
		self.path = self.project.BASE_DIR

		self.cmbTemplate.set_sensitive(True)

		self.xmldoc = ""

		self.bg_color_code = ""
		self.font_color_code = "#ffffff"

		self.bg_style_string = ""
		self.title_style_string = ""
		self.subtitle_style_string = ""

		self.font_weight = 'normal'
		self.font_style = 'normal'

		self.new_title_text = ""
		self.sub_title_text = ""
		self.subTitle = False
		
		self.display_name = ""
		self.font_family = "Bitstream Vera Sans"

		# get the aspect ratio of the current project
		p = profiles.mlt_profiles(self.project).get_profile(self.project.project_type)
		
		# determine which ratio folder to get titles from
		self.ratio_folder = ""
		if p.display_aspect_num() == 4 and p.display_aspect_den() == 3:
			self.ratio_folder = "4_3"
		else:
			self.ratio_folder = "16_9"

		#load the template files
		self.template_dir = os.path.join(self.path, "openshot", "titles", self.ratio_folder)
		for file in sorted(os.listdir(self.template_dir)):
			#pretty up the filename for display purposes
			if fnmatch.fnmatch(file, '*.svg'):
				(fileName, fileExtension)=os.path.splitext(file)
			self.cmbTemplate.append_text(fileName.replace("_"," "))

		#add the changed event once the combo has been populated
		self.cmbTemplate.connect("changed", self.on_cmbTemplate_changed)

		if not self.file:
			self.cmbTemplate.grab_focus()
			# init dropdown
			self.set_template_dropdown()
		else:
			self.filename = self.file
			self.load_svg_template(self.file)
			
			try:
				self.update_font_color_button()
				self.update_background_color_button()
			except:
				print "Warning: Failed to initialize the color pickers from the SVG."
			
			#set edit button states
			self.btnEditText.set_sensitive(True)
			self.btnFont.set_sensitive(True)
			self.btnFontColor.set_sensitive(True)
			self.btnBackgroundColor.set_sensitive(True)
			self.btnAdvanced.set_sensitive(True)
			self.writeToFile(self.xmldoc)
			#preview the file
			self.set_img_pixbuf(self.filename)
			
			#show the text editor
			if self.noTitles == False:
				self.on_btnEditText_clicked(None)
			
			#turn off the create button once we have created the new file
			self.btnCreate.set_sensitive(False)
			self.cmbTemplate.set_sensitive(False)
			
			if self.noTitles == True:
				self.btnEditText.set_sensitive(False)
				self.btnFont.set_sensitive(False)
				self.btnFontColor.set_sensitive(False)
예제 #30
0
	def __init__(self, path="ExportVideo.ui", root="frmExportVideo", domain="LibreShot", form=None, project=None, **kwargs):
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		# set important vars
		self.form = form
		self.project = project
		self.original_project_type = self.project.project_type		# remember the original project type (i.e. mlt_profile)
		
		# Show all controls on this screen
		self.frmExportVideo.show_all()
		
		# set window as MODAL (so they can't mess up the export)
		self.frmExportVideo.set_modal(True)
		
		self.invalid_codecs = []
		
		# init the project type properties
		self.init_properties(self.cmbProjectType.get_active_text())
		
		# set the export file name
		self.txtFileName.set_text(self.project.name)

		# set the export folder as the project folder (if any)
		if ".libreshot" in self.project.folder:
			# This is the libreshot default project (set the folder to 'DESKTOP')
			self.fileExportFolder.set_current_folder(self.project.DESKTOP)
		else:
			# Set project folder
			self.fileExportFolder.set_current_folder(self.project.folder)
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
					
		export_options = [_("Video & Audio"), _("Image Sequence")]
		# loop through export to options
		for option in export_options:
			# append profile to list
			self.cboExportTo.append_text(option)


		export_types_model = self.cboExportType.get_model()
		export_types_model.clear()
		
		export_types = [_("Export to Folder"), _("Upload to Web")]
		# loop through export to options
		for option in export_types:
			# append profile to list
			self.cboExportType.append_text(option)
		self.set_dropdown_values(_("Export to Folder"), self.cboExportType)
		
		
		upload_model = self.cboUploadServices.get_model()
		upload_model.clear()
		
		self.upload_manager = UploadManager(project, self.form.settings)
		self.upload_services = self.upload_manager.get_services()
		upload_types = self.upload_services.keys()
		upload_types.sort()
		# loop through export to options
		for option in upload_types:
			# append profile to list
			self.cboUploadServices.append_text(option)
		self.set_dropdown_values(_("YouTube"), self.cboUploadServices)
		

		#populate the format/codec drop downs 
		#formats
		format_model = self.cboVIdeoFormat.get_model()
		format_model.clear()
		
		for format in self.form.vformats:
			self.cboVIdeoFormat.append_text(format)
			
		#video codecs
		vcodecs_model = self.cboVideoCodec.get_model()
		vcodecs_model.clear()
		
		for vcodec in self.form.vcodecs:
			self.cboVideoCodec.append_text(vcodec)
			
		#audio codecs
		acodecs_model = self.cboAudioCodec.get_model()
		acodecs_model.clear()
		
		# Add 'none' audio codec
		self.cboAudioCodec.append_text( "none" )
		for acodec in self.form.acodecs:
			# Add the rest of the audio codecs
			self.cboAudioCodec.append_text(acodec)
			
			
		# set the dropdown boxes
		self.set_project_type_dropdown()
		self.set_export_to_dropdown()
		
		#load the simple project type dropdown
		presets = []
		for file in os.listdir(self.project.EXPORT_PRESETS_DIR):
			xmldoc = xml.parse(os.path.join(self.project.EXPORT_PRESETS_DIR,file))
			type = xmldoc.getElementsByTagName("type")
			presets.append(_(type[0].childNodes[0].data))
		#exclude duplicates
		presets = list(set(presets))
		for item in sorted(presets):
			self.cboSimpleProjectType.append_text(item)
			
		#indicate that exporting cancelled
		self.cancelled = False
		
		# create the infobar displaying the missing codec message
		self.use_infobar = True
		self.last_error = None
		try:
			self.infobar = gtk.InfoBar()
			self.content = self.infobar.get_content_area()
			self.label = gtk.Label()
			
			self.image = gtk.Image()
			self.image.set_from_stock(gtk.STOCK_DIALOG_WARNING, gtk.ICON_SIZE_DIALOG)
			
			self.content.add(self.image)
			self.content.add(self.label)
			self.vbox1.pack_start(self.infobar)
			self.vbox1.reorder_child(self.infobar, 3)
			self.infobar.set_message_type(gtk.MESSAGE_WARNING)
		except:
			# older version of pygtk can not create an InfoBar
			self.use_infobar = False
예제 #31
0
    def __init__(self,
                 mode="",
                 path="NewProject.ui",
                 root="frmNewProject",
                 domain="LibreShot",
                 project=None,
                 **kwargs):
        print "init"
        SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path),
                                     root, domain, **kwargs)

        # Add language support
        self._ = Language_Init.Translator(project).lang.gettext
        _ = self._

        # project instance
        self.project = project
        self.form = project.form

        # check the mode of the form (i.e. new project or save as screen)
        self.mode = mode

        # init the project type properties
        self.init_properties()

        # init the list of possible project types / profiles
        self.profile_list = profiles.mlt_profiles(
            self.project).get_profile_list()

        # loop through each profile, and add it to the dropdown
        for file_name, p in self.profile_list:
            # append profile to list
            self.cmbProjectType.append_text(p.description())

        # SET THE SAVE FOLDER LOCATION
        if ".libreshot" in self.project.folder:
            # This is the libreshot default project (set the folder to 'DESKTOP')
            self.fileProjectFolder.set_current_folder(self.project.DESKTOP)

        elif len(self.project.folder) > 0:
            # set default folder (if there is a current folder)
            self.fileProjectFolder.set_current_folder(self.project.folder)

        # init the profile
        self.set_dropdown_values(self.form.settings.general["default_profile"],
                                 self.cmbProjectType)

        if (self.mode == "saveas"):
            # Save project as
            # Set window title
            self.frmNewProject.set_title(_("Save Project As..."))

            # init the project name
            self.txtProjectName.set_text(self.project.name)

            # init the profile
            self.set_dropdown_values(self.project.project_type,
                                     self.cmbProjectType)

        else:
            # New Project
            # Set window title
            self.frmNewProject.set_title(_("Create a Project"))

            # init the project name
            self.txtProjectName.set_text(_("Default Project"))
예제 #32
0
    def __init__(
        self, path="Preferences.glade", root="frmPreferences", domain="OpenShot", form=None, project=None, **kwargs
    ):
        SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)

        # Add language support
        _ = Language_Init.Translator(project).lang.gettext
        self._ = _

        self.project = project
        self.form = form
        self.settings = Settings(self.project)

        if getIconPath("openshot"):
            self.frmPreferences.set_icon_from_file(getIconPath("openshot"))

        view = self.icvCategories
        self.model = gtk.ListStore(str, gtk.gdk.Pixbuf)

        # Populate the form with the preference category icons
        # General section
        pixbuf = view.render_icon(gtk.STOCK_PREFERENCES, size=gtk.ICON_SIZE_BUTTON, detail=None)
        self.model.append([_("General"), pixbuf])

        # Formats section
        pixbuf = view.render_icon(gtk.STOCK_INFO, size=gtk.ICON_SIZE_BUTTON, detail=None)
        self.model.append([_("AV Formats"), pixbuf])

        # Formats section
        pixbuf = view.render_icon(gtk.STOCK_INFO, size=gtk.ICON_SIZE_BUTTON, detail=None)
        self.model.append([_("Profiles"), pixbuf])

        # Connect the iconview with the model
        view.set_model(self.model)
        # Map model text and pixbuf columns to iconview
        view.set_text_column(0)
        view.set_pixbuf_column(1)

        # populate the combo boxes
        # init the list of possible project types / profiles
        self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()

        # loop through each profile, and add it to the dropdown
        for file_name, p in self.profile_list:
            # append profile to list
            self.cmbProfiles.append_text(str(file_name))

            # populate the themes
        for dir in os.listdir(self.project.THEMES_DIR):
            self.cmbThemes.append_text(dir)

            # populate project file type combo
        for file_type in ["binary", "ascii"]:
            self.cmbFileType.append_text(file_type)

            # populate the codecs & formats

        self.VCodecList = gtk.ListStore(str)
        self.tvVCodecs.set_model(self.VCodecList)
        tree.treeviewAddGeneralTextColumn(self.tvVCodecs, _("Video Codecs"), 0)

        self.ACodecList = gtk.ListStore(str)
        self.tvACodecs.set_model(self.ACodecList)
        tree.treeviewAddGeneralTextColumn(self.tvACodecs, _("Audio Codecs"), 0)

        self.FormatsList = gtk.ListStore(str)
        self.tvFormats.set_model(self.FormatsList)
        tree.treeviewAddGeneralTextColumn(self.tvFormats, _("Formats"), 0)

        self.populate_codecs()

        # populate form objects
        self.txtImageLength.set_text(self.settings.general["imported_image_length"])
        self.txtHistoryStackSize.set_text(self.settings.general["max_history_size"])
        self.txtMeltCommandName.set_text(self.settings.general["melt_command"])
        theme_name = self.settings.general["default_theme"]
        file_type = self.settings.general["project_file_type"]
        self.set_dropdown_values(theme_name, self.cmbThemes)
        self.set_dropdown_values(self.settings.general["default_profile"], self.cmbProfiles)
        self.set_dropdown_values(file_type, self.cmbFileType)
        # set the example theme icon
        self.load_theme_image(theme_name)

        # show the form
        self.frmPreferences.show_all()
예제 #33
0
	def GetFile(self, file_name, all_frames=False):
		 """ Use this method to generate an OpenShotFile 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 OpenShot's
		 main thread) until it has finished. """

		 try:
			 
			 # determine name and location of thumbnail image
			 self.file_name = file_name
			 self.thumbnail_path = ""
			 self.file_type = "video"
			 self.label = ""
			 project_path = self.project.folder
			 myPath = self.file_name
			 (dirName, fileName) = os.path.split(myPath)
			 (fileBaseName, fileExtension)=os.path.splitext(fileName)
			 fileExtension = fileExtension.replace(".", "")
			 actual_thumbnail_path = project_path + "/thumbnail/" + fileBaseName + "_" + fileExtension + "_1.png"

			 if all_frames == False:
			 	# just get 1 thumbnail frame
			 	self.thumbnail_path = project_path + "/thumbnail/" + fileBaseName + "_" + fileExtension + "_%d.png"
			 	
			 	# set the profile
			 	self.profile = mlt.Profile("quarter_ntsc")

			 else:
			 	# export all frames of the video
			 	self.thumbnail_path = dirName + "/" + fileBaseName + "/" + fileBaseName + "_%d.png"
			 	
			 	# set the profile
			 	self.profile = profiles.mlt_profiles(self.project).get_profile(self.project.project_type)

			 # re-init the mlt factory
			 mlt.Factory.init()
			 	
			 # 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
			 
		 	 # 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
			 max_frames = float(self.p.get_length()) - 1.0
			 producer_fps = float(self.p.get_fps())
			 calculate_length = max_frames / producer_fps

			 # determine if this is an image
			 is_image = False
			 if self.p.get_length() == 15000:
			 	# 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
			 	
			 	# set the length to 300 seconds (i.e. 5 minutes)
			 	calculate_length = float(300)

			 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"))
		 

			 # 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"
				  
			 # set size of images
			 if is_image:
			 	height = 1
			 	width = 1

			 # get the 1st frame (if not exporting all frames)
			 if all_frames == False:
			 	self.p = self.p.cut(1, 1)
			 else:
			 	# mark as image seq
			 	self.label = "Image Sequence"
			 	self.file_type = "image sequence"
			 
			 # 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 openshot file object
			 newFile = files.OpenShotFile(self.project)
			 newFile.name = self.file_name
			 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

			 # return the OpenShotFile object
			 return newFile
		
		 except Exception:
			print "Failed to import file: %s" % file_name
예제 #34
0
    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()
예제 #35
0
파일: video.py 프로젝트: XXLRay/libreshot
	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
예제 #36
0
	def __init__(self, path="ExportVideo.glade", root="frmExportVideo", domain="OpenShot", form=None, project=None, **kwargs):
		SimpleGladeApp.__init__(self, os.path.join(project.GLADE_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		self.form = form
		self.project = project
		self.frmExportVideo.show_all()
		
		self.invalid_codecs = []
		
		# init the project type properties
		self.init_properties(self.cmbProjectType.get_active_text())
		
		# set the export file name
		self.txtFileName.set_text(self.project.name)

		# set the export folder as the project folder (if any)
		if ".openshot" in self.project.folder:
			# This is the openshot default project (set the folder to 'DESKTOP')
			self.fileExportFolder.set_current_folder(self.project.DESKTOP)
		else:
			# Set project folder
			self.fileExportFolder.set_current_folder(self.project.folder)
		
		# init the list of possible project types / profiles
		self.profile_list = profiles.mlt_profiles(self.project).get_profile_list()
		
		# loop through each profile, and add it to the dropdown
		for file_name, p in self.profile_list:
			# append profile to list
			self.cmbProjectType.append_text(p.description())
			
					
		export_options = [_("Video & Audio"), _("Image Sequence")]
		# loop through export to options
		for option in export_options:
			# append profile to list
			self.cboExportTo.append_text(option)
			
		#populate the format/codec drop downs 
		#formats
		format_model = self.cboVIdeoFormat.get_model()
		format_model.clear()
		
		for format in self.form.vformats:
			self.cboVIdeoFormat.append_text(format)
			
		#video codecs
		vcodecs_model = self.cboVideoCodec.get_model()
		vcodecs_model.clear()
		
		for vcodec in self.form.vcodecs:
			self.cboVideoCodec.append_text(vcodec)
			
		#audio codecs
		acodecs_model = self.cboAudioCodec.get_model()
		acodecs_model.clear()
		
		for acodec in self.form.acodecs:
			self.cboAudioCodec.append_text(acodec)
			
			
		# set the dropdown boxes
		self.set_project_type_dropdown()
		self.set_export_to_dropdown()
		
		#load the simple project type dropdown
		presets = []
		for file in os.listdir(self.project.EXPORT_PRESETS_DIR):
			xmldoc = xml.parse(os.path.join(self.project.EXPORT_PRESETS_DIR,file))
			type = xmldoc.getElementsByTagName("type")
			presets.append(_(type[0].childNodes[0].data))
		#exclude duplicates
		presets = list(set(presets))
		for item in sorted(presets):
			self.cboSimpleProjectType.append_text(item)
		#indicate that exporting cancelled
		self.cancelled = False
예제 #37
0
	def render(self, init_threads=True):
		
		# generates xml file
		self.current_project.GenerateXML(os.path.join(self.USER_DIR, "sequence.mlt"))
		print _("generating XML file for rendering")	
		self.fps = self.current_project.fps()
		#threading.Thread.__init__(self)
		self.profile = profiles.mlt_profiles(self.current_project).get_profile(self.current_project.project_type)
		self.file_name = os.path.join(self.USER_DIR, "sequence.mlt")

		# Import required modules
		import time
		import sys
		import math			
		try:
			import mlt
		except ImportError:
			print "*** ERROR: MLT Python bindings failed to import ***"	
		
		# Progress bar function
		def progress(width, percent):
			marks = math.floor(width * (percent / 100.0))
			spaces = math.floor(width - marks)
			loader = '[' + ('=' * int(marks)) + (' ' * int(spaces)) + ']'
			sys.stdout.write("%s %d%%\r" % (loader, percent))
			#if percent >= 100:
				#sys.stdout.write("\n")
			sys.stdout.flush()

		# Create producer and initialize mlt
		self.f = mlt.Factory().init()
		self.p = mlt.Producer( self.profile, 'xml:%s' % self.file_name)
		if self.p.is_valid() == False:
			print "MLT producer failure"
			sys.exit()
		self.p.set_speed(0)
		out_folder = self.render_options["folder"]
		out_file = self.render_options["file"]
		
		# Set export path
		export_path = "%s.%s" % (os.path.join(out_folder, out_file), self.render_options["f"])

		# RENDER MOVIE
		print _("Starting rendering to ") + str(export_path)
		self.c = mlt.Consumer( self.profile, "avformat", export_path)

		# set some RENDER specific options
		self.c.set("real_time", -1)
			
		# set render options
		self.c.set("f" , self.render_options["f"])
		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"])
		
		# sets correct options if rendering to h264
		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", "0.6")
			self.c.set("qdiff", "4")
			self.c.set("trellis", "1")		

		# Connect the producer to the consumer
		self.c.connect( self.p )
		self.p.set_speed(1)
		
		# Start the consumer
		self.c.start()
		
		# init the render percentage
		self.fraction_complete = 0.0
		self.render_interrupted = False

		while self.c.is_stopped() == False:
			# update Export Dialog Progress Bar
			self.fraction_complete = (float(self.p.position()) / float(self.p.get_length() - 1))
			progress(50, int(self.fraction_complete*100))
			# wait 1/5 of a second
			try:
				time.sleep( 0.2 )
			except KeyboardInterrupt:
				print "\n"
				print _("program interrupted by user")
				self.render_interrupted = True
				self.c.stop()
		
		if self.render_interrupted == False:
			progress(50, 100)
			print "\n"
			print _("project file correctly rendered")
			
		# clear all the MLT objects
		self.c.stop()
		self.p = None
		self.c = None
		self.profile = None
		self.f = None

		return
예제 #38
0
    def render(self, init_threads=True):

        # generates xml file
        self.current_project.GenerateXML(os.path.join(self.USER_DIR, "sequence.mlt"))
        print _("generating XML file for rendering")
        self.fps = self.current_project.fps()
        # threading.Thread.__init__(self)
        self.profile = profiles.mlt_profiles(self.current_project).get_profile(self.current_project.project_type)
        self.file_name = os.path.join(self.USER_DIR, "sequence.mlt")

        # Import required modules
        import time
        import sys
        import math

        try:
            import mlt
        except ImportError:
            print "*** ERROR: MLT Python bindings failed to import ***"

            # Progress bar function

        def progress(width, percent):
            marks = math.floor(width * (percent / 100.0))
            spaces = math.floor(width - marks)
            loader = "[" + ("=" * int(marks)) + (" " * int(spaces)) + "]"
            sys.stdout.write("%s %d%%\r" % (loader, percent))
            # if percent >= 100:
            # sys.stdout.write("\n")
            sys.stdout.flush()

            # Create producer and initialize mlt

        self.f = mlt.Factory().init()
        self.p = mlt.Producer(self.profile, "xml:%s" % self.file_name)
        if self.p.is_valid() == False:
            print "MLT producer failure"
            sys.exit()
        self.p.set_speed(0)
        out_folder = self.render_options["folder"]
        out_file = self.render_options["file"]

        # Set export path
        export_path = "%s.%s" % (os.path.join(out_folder, out_file), self.render_options["f"])

        # RENDER MOVIE
        print _("Starting rendering to ") + str(export_path)
        self.c = mlt.Consumer(self.profile, "avformat", export_path)

        # set some RENDER specific options
        self.c.set("real_time", -1)

        # set render options
        self.c.set("f", self.render_options["f"])
        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"])

        # sets correct options if rendering to h264
        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", "0.6")
            self.c.set("qdiff", "4")
            self.c.set("trellis", "1")

            # Connect the producer to the consumer
        self.c.connect(self.p)
        self.p.set_speed(1)

        # Start the consumer
        self.c.start()

        # init the render percentage
        self.fraction_complete = 0.0
        self.render_interrupted = False

        while self.c.is_stopped() == False:
            # update Export Dialog Progress Bar
            self.fraction_complete = float(self.p.position()) / float(self.p.get_length() - 1)
            progress(50, int(self.fraction_complete * 100))
            # wait 1/5 of a second
            try:
                time.sleep(0.2)
            except KeyboardInterrupt:
                print "\n"
                print _("program interrupted by user")
                self.render_interrupted = True
                self.c.stop()

        if self.render_interrupted == False:
            progress(50, 100)
            print "\n"
            print _("project file correctly rendered")

            # clear all the MLT objects
        self.c.stop()
        self.p = None
        self.c = None
        self.profile = None
        self.f = None

        return
예제 #39
0
	def __init__(self, path="titles.ui", root="frmTitles", domain="LibreShot", form=None, project=None, file=None, **kwargs):
		SimpleGtkBuilderApp.__init__(self, os.path.join(project.UI_DIR, path), root, domain, **kwargs)

		# Add language support
		_ = Language_Init.Translator(project).lang.gettext
		self._ = _

		self.project = project
		self.form = form
		self.file = file

		#find path where libreshot is running
		self.path = self.project.BASE_DIR

		self.cmbTemplate.set_sensitive(True)

		self.xmldoc = ""

		self.bg_color_code = ""
		self.font_color_code = "#ffffff"

		self.bg_style_string = ""
		self.title_style_string = ""
		self.subtitle_style_string = ""

		self.font_weight = 'normal'
		self.font_style = 'normal'

		self.new_title_text = ""
		self.sub_title_text = ""
		self.subTitle = False
		
		self.display_name = ""
		self.font_family = "Bitstream Vera Sans"

		# get the aspect ratio of the current project
		p = profiles.mlt_profiles(self.project).get_profile(self.project.project_type)
		
		# determine which ratio folder to get titles from
		self.ratio_folder = ""
		if p.display_aspect_num() == 4 and p.display_aspect_den() == 3:
			self.ratio_folder = "4_3"
		else:
			self.ratio_folder = "16_9"

		#load the template files
		self.template_dir = os.path.join(self.path, "libreshot", "titles", self.ratio_folder)
		for file in sorted(os.listdir(self.template_dir)):
			#pretty up the filename for display purposes
			if fnmatch.fnmatch(file, '*.svg'):
				(fileName, fileExtension)=os.path.splitext(file)
			self.cmbTemplate.append_text(fileName.replace("_"," "))

		#add the changed event once the combo has been populated
		self.cmbTemplate.connect("changed", self.on_cmbTemplate_changed)

		if not self.file:
			self.cmbTemplate.grab_focus()
			# init dropdown
			self.set_template_dropdown()
		else:
			self.filename = self.file
			self.load_svg_template(self.file)
			
			try:
				self.update_font_color_button()
				self.update_background_color_button()
			except:
				print "Warning: Failed to initialize the color pickers from the SVG."
			
			#set edit button states
			self.btnEditText.set_sensitive(True)
			self.btnFont.set_sensitive(True)
			self.btnFontColor.set_sensitive(True)
			self.btnBackgroundColor.set_sensitive(True)
			self.btnAdvanced.set_sensitive(True)
			self.writeToFile(self.xmldoc)
			#preview the file
			self.set_img_pixbuf(self.filename)
			
			#show the text editor
			if self.noTitles == False:
				self.on_btnEditText_clicked(None)
			
			#turn off the create button once we have created the new file
			self.btnCreate.set_sensitive(False)
			self.cmbTemplate.set_sensitive(False)
			
			if self.noTitles == True:
				self.btnEditText.set_sensitive(False)
				self.btnFont.set_sensitive(False)
				self.btnFontColor.set_sensitive(False)