[Bf-python] option to choose executable instead of raising error inside function
Bastien Montagne
montagne29 at wanadoo.fr
Tue Oct 15 19:12:28 CEST 2013
Hi Flavio,
Think you are looking for AddonPreferences ?
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html
Bastien
On 15/10/2013 19:03, flavio soares wrote:
> Hi,
>
> I'm doing an exporter to ardour and it runs an external ffmpeg. I'm
> wondering if there is a way of letting user point to a local ffmpeg
> executable in case it is not recognized by "which". The idea is to
> replace the RuntimeError with something like:
>
> with open(self.filepath) as file:
> ffCommand = self.filepath
>
> but this only works inside classes.
>
>
>
> Relevant code is below:
>
> this is the main class:
>
> class ExportArdour(bpy.types.Operator, ExportHelper):
> """Export audio timeline (including audios from videos) to Ardour"""
> bl_idname = "export.ardour"
> bl_label = "Export to Ardour"
> filename_ext = ".ardour"
> filter_glob = StringProperty(default="*.ardour", options={'HIDDEN'})
>
> @classmethod
> def poll(cls, context):
> if bpy.context.sequences:
> return context.sequences is not None
>
> def execute(self, context):
> scene = bpy.context.scene
> startFrame = scene.frame_start
> endFrame = scene.frame_end
> fps, timecode = checkFPS()
>
> system = bpy.context.user_preferences.system
> audioRate = int(system.audio_sample_rate.split("_")[1])
>
> audiosFolderPath, ardourFile = os.path.split(self.filepath)
> ardourBasename = os.path.splitext(ardourFile)[0]
> audiosFolder = audiosFolderPath + os.sep + "Audios_for_" +
> ardourBasename
>
> Session = createXML(startFrame, endFrame, fps, timecode,
> audioRate,
> ardourBasename, audiosFolder)
>
> runFFMPEG(sources, audioRate, audiosFolder)
> writeXML(self.filepath, Session)
>
> return {'FINISHED'}
>
>
> ..........that calls this function (notice the RunTime error):
>
> def runFFMPEG(sources, audioRate, outputFolder):
> if which('ffmpeg') is not None:
> if (os.name <http://os.name> == "nt"):
> ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
> else:
> ffCommand = "ffmpeg"
> else:
> raise RuntimeError("You don\'t seem to have FFMPEG installed
> on your system. \
> Please install it and re-run the Ardour
> exporter.")
>
> if (os.path.exists(outputFolder) is False):
> os.mkdir(outputFolder)
>
> for source in sources:
> basename, ext = os.path.splitext(source['name'])
>
> input = source['origin']
> if (input.startswith("//")):
> input = input.replace("//", "")
>
> output = outputFolder + os.sep + basename + ".wav"
>
> # Due to spaces, the command entries (ffCommand, input and
> output) have
> # to be read as strings by the call command, thus the
> escapings below
> callFFMPEG = "\"%s\" -i \"%s\" -y -vn -ar %i -ac 1 \"%s\"" \
> % (ffCommand, input, audioRate, output)
> call(callFFMPEG, shell=True)
>
> return {'FINISHED'}
>
>
>
> thanks.
>
> flavio
>
>
> _______________________________________________
> Bf-python mailing list
> Bf-python at blender.org
> http://lists.blender.org/mailman/listinfo/bf-python
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.blender.org/pipermail/bf-python/attachments/20131015/521b3e2d/attachment.html>
More information about the Bf-python
mailing list