18
17
# You should have received a copy of the GNU Lesser General Public
19
18
# License along with this program; if not, write to the
20
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
# Boston, MA 02111-1307, USA.
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
20
# Boston, MA 02110-1301, USA.
77
78
return type_(os.getenv(var))
80
82
def get_env_default(var, default):
81
83
value = os.getenv(var)
86
89
def get_dir(path, autocreate=True):
87
90
if autocreate and not os.path.exists(path):
91
95
def get_dirs(glob):
92
96
return [d for d in glob.split(os.path.pathsep) if os.path.exists(d)]
94
99
def get_env_dir(var, default, autocreate=True):
95
100
return get_dir(get_env_default(var, default))
97
103
def get_env_dirs(var, default):
98
104
return get_dirs(get_env_default(var, default))
100
107
def xdg_config_home(autocreate=True):
101
108
return get_dir(xdg_dirs.xdg_config_home, autocreate)
103
111
def xdg_data_home(autocreate=True):
104
112
return get_dir(xdg_dirs.xdg_data_home, autocreate)
106
115
def xdg_cache_home(autocreate=True):
107
116
return get_dir(xdg_dirs.xdg_cache_home, autocreate)
109
119
def xdg_data_dirs():
110
120
return get_env_dirs(xdg_dirs.xdg_data_dirs)
112
123
def xdg_config_dirs():
113
124
return get_env_dirs(xdg_dirs.xdg_config_dirs)
115
127
class ConfigError(Exception):
118
131
class Notification(object):
120
133
"""A descriptor to help with the implementation of signals"""
237
251
return get_dir(os.path.join(xdg_config_home(autocreate), "pitivi"),
240
def get_local_plugin_path(self, autocreate=True):
242
Compute the absolute path to local plugin repository
244
@param autocreate: create the path if missing
245
@return: the plugin repository path
252
xdg_data_home(autocreate),
258
def get_plugin_settings_path(self, autocreate=True):
260
Compute the absolute path to local plugin settings' repository
262
@param autocreate: create the path if missing
263
@return: the plugin settings path
266
return get_dir(os.path.join(self.get_local_settings_path(autocreate),
267
"plugin-settings"), autocreate)
269
254
def iterAllOptions(self):
271
256
Iterate over all registered options
438
425
def __str__(self):
439
426
return "<RenderSettings %s [%d streams]>" % (self.muxer, len(self.settings))
441
429
class ExportSettings(Signallable, Loggable):
443
431
Multimedia export settings
447
434
'settings-changed' : the settings have changed
448
435
'encoders-changed' : The encoders or muxer have changed
437
@ivar render_scale: The scale to be applied to the video width and height
439
@type render_scale: int
451
"settings-changed" : None,
452
"encoders-changed" : None,
442
"settings-changed": None,
443
"encoders-changed": None,
455
446
# Audio/Video settings for processing/export
457
448
# TODO : Add PAR/DAR for video
458
449
# TODO : switch to using GstFraction internally where appliable
461
# The following dependant attributes caches are common to all instances!
462
# A (muxer -> containersettings) map.
463
_containersettings_cache = {}
464
# A (vencoder -> vcodecsettings) map.
465
_vcodecsettings_cache = {}
466
# A (aencoder -> acodecsettings) map.
467
_acodecsettings_cache = {}
469
451
muxers, aencoders, vencoders = available_combinations()
471
453
def __init__(self, **unused_kw):
481
463
self.vencoder = "theoraenc"
482
464
self.aencoder = "vorbisenc"
483
465
self.muxer = "oggmux"
466
# A (muxer -> containersettings) map.
467
self._containersettings_cache = {}
468
# A (vencoder -> vcodecsettings) map.
469
self._vcodecsettings_cache = {}
470
# A (aencoder -> acodecsettings) map.
471
self._acodecsettings_cache = {}
486
474
ret = ExportSettings()
487
475
ret.videowidth = self.videowidth
488
476
ret.videoheight = self.videoheight
477
ret.render_scale = self.render_scale
489
478
ret.videorate = gst.Fraction(self.videorate.num, self.videorate.denom)
490
479
ret.videopar = gst.Fraction(self.videopar.num, self.videopar.denom)
491
480
ret.audiochannels = self.audiochannels
505
494
def __str__(self):
506
495
msg = _("Export Settings\n")
507
496
msg += _("Video: ") + str(self.videowidth) + " " + str(self.videoheight) +\
508
" " + str(self.videorate) + " " + str (self.videopar)
509
msg += "\n\t" + str(self.vencoder) + " " +str(self.vcodecsettings)
497
" " + str(self.videorate) + " " + str(self.videopar)
498
msg += "\n\t" + str(self.vencoder) + " " + str(self.vcodecsettings)
510
499
msg += _("\nAudio: ") + str(self.audiochannels) + " " + str(self.audiorate) +\
511
500
" " + str(self.audiodepth)
512
501
msg += "\n\t" + str(self.aencoder) + " " + str(self.acodecsettings)
529
518
def getVideoCaps(self, render=False):
530
519
""" Returns the GstCaps corresponding to the video settings """
531
520
videowidth, videoheight = self.getVideoWidthAndHeight(render=render)
532
astr = "width=%d,height=%d,pixel-aspect-ratio=%d/%d,framerate=%d/%d" % (
521
vstr = "width=%d,height=%d,pixel-aspect-ratio=%d/%d,framerate=%d/%d" % (
533
522
videowidth, videoheight,
534
523
self.videopar.num, self.videopar.denom,
535
524
self.videorate.num, self.videorate.denom)
536
vcaps = gst.caps_from_string("video/x-raw-yuv,%s;video/x-raw-rgb,%s" % (astr, astr))
525
caps_str = "video/x-raw-yuv,%s;video/x-raw-rgb,%s" % (vstr, vstr)
526
video_caps = gst.caps_from_string(caps_str)
537
527
if self.vencoder:
538
return get_compatible_sink_caps(self.vencoder, vcaps)
528
return get_compatible_sink_caps(self.vencoder, video_caps)
541
531
def getAudioCaps(self):
542
532
""" Returns the GstCaps corresponding to the audio settings """
543
astr = "rate=%d,channels=%d" % (self.audiorate, self.audiochannels)
544
astrcaps = gst.caps_from_string("audio/x-raw-int,%s;audio/x-raw-float,%s" % (astr, astr))
533
astr = "rate=%d,channels=%d,depth=%d" % (
534
self.audiorate, self.audiochannels, self.audiodepth)
535
caps_str = "audio/x-raw-int,%s;audio/x-raw-float,%s" % (astr, astr)
536
audio_caps = gst.caps_from_string(caps_str)
545
537
if self.aencoder:
546
return get_compatible_sink_caps(self.aencoder, astrcaps)
549
# interset with current audioencoder sink pad caps
538
return get_compatible_sink_caps(self.aencoder, audio_caps)
551
541
def setVideoProperties(self, width=-1, height=-1, framerate=-1, par=-1,
552
542
render_scale=-1):
637
627
return self.vencoders[self.muxer]
639
630
def export_settings_to_render_settings(export,
640
631
have_video=True, have_audio=True):
641
632
"""Convert the specified ExportSettings object to a RenderSettings object.