← Back to team overview

openshot.code team mailing list archive

[Branch ~openshot.code/openshot/main] Rev 570: Modified the av_formats.py file and added "fallback" methods to detect filters, video codecs, aud...

 

------------------------------------------------------------
revno: 570
committer: Jonathan Thomas <Jonathan.Oomph@xxxxxxxxx>
branch nick: openshot
timestamp: Wed 2011-09-14 23:12:34 -0500
message:
  Modified the av_formats.py file and added "fallback" methods to detect filters, video codecs, audio codecs, and formats using the older, more compatible 'melt' executable.  If the newer MLT API method works, it never trys the 'melt' fallback methods.  Although this is uglier than what we had before, it's much more compatible.
modified:
  openshot/classes/av_formats.py
  openshot/windows/MainGTK.py
  openshot/windows/preferences.py


--
lp:openshot
https://code.launchpad.net/~openshot.code/openshot/main

Your team OpenShot Code is subscribed to branch lp:openshot.
To unsubscribe from this branch go to https://code.launchpad.net/~openshot.code/openshot/main/+edit-subscription
=== modified file 'openshot/classes/av_formats.py'
--- openshot/classes/av_formats.py	2011-07-17 20:49:57 +0000
+++ openshot/classes/av_formats.py	2011-09-15 04:12:34 +0000
@@ -32,7 +32,10 @@
 
 class formats:
 	
-	def __init__(self):
+	def __init__(self, melt_command="melt"):
+		# init melt command
+		self.melt_command = melt_command
+		
 		# Start the mlt system
 		self.repo = mlt.Factory().init()
 		
@@ -40,18 +43,59 @@
 	def get_filters(self, format=None):
 		""" Get a list of mlt's filters, including frei0r filters """ 
 		
+		try:
+			filters_raw=[]
+			
+			services = mlt.Repository.filters(self.repo)
+			
+			for i in range(mlt.Properties.count(services)):
+				filters_raw.append(mlt.Properties.get_name(services, i))
+				
+			# sort list
+			filters_raw.sort()
+			return filters_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 filters using the MLT API.  Falling back to 'melt' executable."
+			return self.get_filters_fallback(format)
+	
+	def get_filters_fallback(self, format=None):
+		""" This method is used for backwards compatibility with older versions of MLT.
+			Get a list of mlt's filters, including frei0r filters """ 
+		
+		import subprocess
+
+		# melt -query 
+		command = [self.melt_command, "-query", "filters"]
+		output = ''
+		
 		filters_raw=[]
 		
-		services = mlt.Repository.filters(self.repo)
-		
-		for i in range(mlt.Properties.count(services)):
-			filters_raw.append(mlt.Properties.get_name(services, i))
-			
+		try:
+			process = subprocess.Popen(args=command,stdout=subprocess.PIPE,
+									stdin=subprocess.PIPE,stderr=subprocess.STDOUT)
+			output = str(process.stdout.read(20000))
+			
+			# wait for process to finish, and then close
+			process.stdin.close()
+			if process.wait() != 0:
+				print "There were some errors calling melt using os.Popen()"
+		except:
+			return filters_raw
+			
+		output_lines=output.split('\n')
+		
+		for line in output_lines:
+			if " - " in line and "..." not in line and len(line.strip()) > 0:
+				filters_raw.append(line.lstrip('  - '))
+		
 		# sort list
 		filters_raw.sort()
-		
 		return filters_raw
 	
+	
 	def has_frei0r_installed(self):
 		""" Determine if frei0r effects are installed and configured with libmlt. """
 		
@@ -64,77 +108,195 @@
 	
 		
 	def get_vcodecs(self, format=None):
+		try:
+			vcodecs_raw=[]
+			
+			# 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'))
+			
+			# Display the list of codecs
+			for i in range(0, codecs.count()):
+					vcodecs_raw.append(codecs.get(i))
+			
+			# sort list
+			vcodecs_raw.sort()
+			return vcodecs_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 video codecs using the MLT API.  Falling back to 'melt' executable."
+			return self.get_vcodecs_fallback(format)
+	
+	def get_vcodecs_fallback(self, format=None):
+		""" This method is used for backwards compatibility with older versions of MLT. """
+		
+		import subprocess
+		
+		#melt noise -consumer avformat vcodec=list
+		command = [self.melt_command, "noise", "-consumer", "avformat", "vcodec=list"]
+		output = ''
+		
 		vcodecs_raw=[]
 		
-		# 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'))
+		try:
+			process = subprocess.Popen(args=command,stdout=subprocess.PIPE,
+									stdin=subprocess.PIPE,stderr=subprocess.STDOUT)
+			output = str(process.stdout.read(20000))
+			
+			# wait for process to finish, and then close
+			process.stdin.close()
+			if process.wait() != 0:
+				print "There were some errors calling melt using os.Popen()"
+		except:
+			return vcodecs_raw
+			
+		output_lines=output.split('\n')
 		
-		# Display the list of codecs
-		for i in range(0, codecs.count()):
-				vcodecs_raw.append(codecs.get(i))
+		for line in output_lines:
+			if " - " in line and "..." not in line and len(line.strip()) > 0:
+				vcodecs_raw.append(line.lstrip('  - '))
 		
 		# sort list
 		vcodecs_raw.sort()
-		
 		return vcodecs_raw
 	
 	
 	def get_acodecs(self, format=None):
-	
+		try:
+			acodecs_raw=[]
+			
+			# Create the consumer
+			c = mlt.Consumer(mlt.Profile(), "avformat")
+	
+			# Ask for audio codecs supports
+			c.set('acodec', 'list')
+	
+			# Start the consumer to generate the list
+			c.start()
+	
+			# Get the acodec property
+			codecs = mlt.Properties(c.get_data('acodec'))
+			
+			# Display the list of codecs
+			for i in range(0, codecs.count()):
+					acodecs_raw.append(codecs.get(i))
+			
+			# sort list
+			acodecs_raw.sort()
+			return acodecs_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 audio codecs using the MLT API.  Falling back to 'melt' executable."
+			return self.get_acodecs_fallback(format)
+	
+	def get_acodecs_fallback(self, format=None):
+		""" This method is used for backwards compatibility with older versions of MLT. """
+
+		import subprocess
+
+		#this is the equivalant of running this command in the terminal:
+		#melt noise -consumer avformat acodec=list
+		command = [self.melt_command, "noise", "-consumer", "avformat", "acodec=list"]
+		output = ''
+		
 		acodecs_raw=[]
 		
-		# Create the consumer
-		c = mlt.Consumer(mlt.Profile(), "avformat")
-
-		# Ask for audio codecs supports
-		c.set('acodec', 'list')
-
-		# Start the consumer to generate the list
-		c.start()
-
-		# Get the acodec property
-		codecs = mlt.Properties(c.get_data('acodec'))
+		try:
+			process = subprocess.Popen(args=command,stdout=subprocess.PIPE,
+			stdin=subprocess.PIPE,stderr=subprocess.STDOUT)
+			output = str(process.stdout.read(20000))
+			
+			# wait for process to finish, and then close
+			process.stdin.close()
+			if process.wait() != 0:
+				print "There were some errors calling melt using os.Popen()"
+		except:
+			return acodecs_raw
+			
+		output_lines=output.split('\n')
 		
-		# Display the list of codecs
-		for i in range(0, codecs.count()):
-				acodecs_raw.append(codecs.get(i))
+		for line in output_lines:
+			if " - " in line and "..." not in line and len(line.strip()) > 0:
+				acodecs_raw.append(line.lstrip('  - '))
 		
 		# sort list
 		acodecs_raw.sort()
-		
 		return acodecs_raw
 	
 	
+	
 	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_formats_fallback(self, format=None):
+		""" This method is used for backwards compatibility with older versions of MLT. """
+
+		import subprocess
+
+		#this is the equivalant of running this command inthe terminal:
+		#melt noise -consumer avformat f=list
+		command = [self.melt_command, "noise", "-consumer", "avformat", "f=list"]
+		output = ''
+		
 		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))
-		
+		try:
+			process = subprocess.Popen(args=command,stdout=subprocess.PIPE,
+			stdin=subprocess.PIPE,stderr=subprocess.STDOUT)
+			output = str(process.stdout.read(20000))
+			
+			# wait for process to finish, and then close
+			process.stdin.close()
+			if process.wait() != 0:
+				print "There were some errors calling melt using os.Popen()"
+		except:
+			return formats_raw
+			
+		output_lines=output.split('\n')
+		
+		for line in output_lines:
+			if " - " in line and "..." not in line and len(line.strip()) > 0:
+				formats_raw.append(line.lstrip('  - '))
+
 		# sort list
 		formats_raw.sort()
-		
-		return formats_raw
+		return formats_raw
\ No newline at end of file

=== modified file 'openshot/windows/MainGTK.py'
--- openshot/windows/MainGTK.py	2011-09-08 19:30:11 +0000
+++ openshot/windows/MainGTK.py	2011-09-15 04:12:34 +0000
@@ -224,7 +224,8 @@
 		self.load_autosave_settings()
 		
 		#get the formats/codecs
-		self.get_avformats()
+		melt_command = self.settings.general["melt_command"]
+		self.get_avformats(melt_command)
 		
 		# Show Window
 		self.frmMain.show()
@@ -359,7 +360,7 @@
 		return self._(text)
 
 
-	def get_avformats(self):
+	def get_avformats(self, melt_command):
 		
 		# get translation object
 		_ = self._
@@ -368,7 +369,7 @@
 		print "\nDetecting formats, codecs, and filters..."
 		
 		#populate the codecs
-		formats = av_formats.formats()
+		formats = av_formats.formats(melt_command)
 		#video codecs
 		self.vcodecs = formats.get_vcodecs()
 		#audio codecs	

=== modified file 'openshot/windows/preferences.py'
--- openshot/windows/preferences.py	2011-09-15 03:44:59 +0000
+++ openshot/windows/preferences.py	2011-09-15 04:12:34 +0000
@@ -192,8 +192,7 @@
 		
 		melt_command = self.form.settings.general["melt_command"]
 		self.form.get_avformats(melt_command)
-		
-		self.form.get_avformats()
+
 		self.populate_codecs()