Discussion:
[Bf-python] option to choose executable instead of raising error inside function
flavio soares
2013-10-15 17:03:19 UTC
Permalink
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 == "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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.blender.org/pipermail/bf-python/attachments/20131015/5cb0deb9/attachment.htm
Bastien Montagne
2013-10-15 17:12:28 UTC
Permalink
Hi Flavio,

Think you are looking for AddonPreferences ?
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html

Bastien
Post by flavio soares
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
ffCommand = self.filepath
but this only works inside classes.
"""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
return context.sequences is not None
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'}
ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
ffCommand = "ffmpeg"
raise RuntimeError("You don\'t seem to have FFMPEG installed
on your system. \
Please install it and re-run the Ardour
exporter.")
os.mkdir(outputFolder)
basename, ext = os.path.splitext(source['name'])
input = source['origin']
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.htm
flavio soares
2013-10-15 17:38:00 UTC
Permalink
Hi, Bastien,

Thanks for the link. I'll try to mess with it, but I think the addon part
is ok. The problem is really calling a window to choose the executable and
storing it in a variable.


2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>
Post by Bastien Montagne
Hi Flavio,
Think you are looking for AddonPreferences ?
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html
Bastien
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
ffCommand = self.filepath
but this only works inside classes.
"""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
return context.sequences is not None
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'}
ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
ffCommand = "ffmpeg"
raise RuntimeError("You don\'t seem to have FFMPEG installed on
your system. \
Please install it and re-run the Ardour
exporter.")
os.mkdir(outputFolder)
basename, ext = os.path.splitext(source['name'])
input = source['origin']
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 listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
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/0290762a/attachment-0001.htm
Bastien Montagne
2013-10-15 17:47:08 UTC
Permalink
Eh, it?s like any file, right? Just have a look around in other addons,
many of them handle files?

I would point you to official ui_translate addon, for example, but it
has some extra complexity you do not need? Just note that simply adding
"subtype='FILE_PATH'" parameter to a string prop definition will turn it
into a file-selector one in the UI? ;)
Post by flavio soares
Hi, Bastien,
Thanks for the link. I'll try to mess with it, but I think the addon
part is ok. The problem is really calling a window to choose the
executable and storing it in a variable.
2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr
<mailto:montagne29 at wanadoo.fr>>
Hi Flavio,
Think you are looking for AddonPreferences ?
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html
Bastien
Post by flavio soares
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
ffCommand = self.filepath
but this only works inside classes.
"""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
return context.sequences is not None
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'}
ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
ffCommand = "ffmpeg"
raise RuntimeError("You don\'t seem to have FFMPEG
installed on your system. \
Please install it and re-run the
Ardour exporter.")
os.mkdir(outputFolder)
basename, ext = os.path.splitext(source['name'])
input = source['origin']
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 <mailto:Bf-python at blender.org>
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
Bf-python at blender.org <mailto:Bf-python at blender.org>
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
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/e2fa13bd/attachment.htm
flavio soares
2013-10-15 18:05:11 UTC
Permalink
Alright! Thanks, that's probably it! =)


2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>
Post by Bastien Montagne
Eh, it?s like any file, right? Just have a look around in other addons,
many of them handle files?
I would point you to official ui_translate addon, for example, but it has
some extra complexity you do not need? Just note that simply adding
"subtype='FILE_PATH'" parameter to a string prop definition will turn it
into a file-selector one in the UI? ;)
Hi, Bastien,
Thanks for the link. I'll try to mess with it, but I think the addon part
is ok. The problem is really calling a window to choose the executable and
storing it in a variable.
2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>
Post by Bastien Montagne
Hi Flavio,
Think you are looking for AddonPreferences ?
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html
Bastien
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
ffCommand = self.filepath
but this only works inside classes.
"""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
return context.sequences is not None
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'}
ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
ffCommand = "ffmpeg"
raise RuntimeError("You don\'t seem to have FFMPEG installed on
your system. \
Please install it and re-run the Ardour
exporter.")
os.mkdir(outputFolder)
basename, ext = os.path.splitext(source['name'])
input = source['origin']
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 listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
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/fcc11a07/attachment-0001.htm
flavio soares
2013-10-16 22:48:31 UTC
Permalink
Hi, Bastien,

I've been studying your addon and the way you set the prefs. Thanks, that's
exactly what I was looking for. =)

*Well, actually, not exactly - setting preferences was more clever than
what I had in mind, so thumbs up!


2013/10/15 flavio soares <qazav3.0 at gmail.com>
Post by flavio soares
Alright! Thanks, that's probably it! =)
2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>
Post by Bastien Montagne
Eh, it?s like any file, right? Just have a look around in other addons,
many of them handle files?
I would point you to official ui_translate addon, for example, but it has
some extra complexity you do not need? Just note that simply adding
"subtype='FILE_PATH'" parameter to a string prop definition will turn it
into a file-selector one in the UI? ;)
Hi, Bastien,
Thanks for the link. I'll try to mess with it, but I think the addon
part is ok. The problem is really calling a window to choose the executable
and storing it in a variable.
2013/10/15 Bastien Montagne <montagne29 at wanadoo.fr>
Post by Bastien Montagne
Hi Flavio,
Think you are looking for AddonPreferences ?
http://www.blender.org/documentation/blender_python_api_2_69_1/bpy.types.AddonPreferences.html
Bastien
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
ffCommand = self.filepath
but this only works inside classes.
"""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
return context.sequences is not None
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'}
ffCommand = ffmpegPath + os.sep + "ffmpeg.exe"
ffCommand = "ffmpeg"
raise RuntimeError("You don\'t seem to have FFMPEG installed on
your system. \
Please install it and re-run the Ardour
exporter.")
os.mkdir(outputFolder)
basename, ext = os.path.splitext(source['name'])
input = source['origin']
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 listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing list
Bf-python at blender.org
http://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
Bf-python mailing listBf-python at blender.orghttp://lists.blender.org/mailman/listinfo/bf-python
_______________________________________________
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/20131016/d904854c/attachment.htm
Loading...