Package flumotion :: Package component :: Package encoders :: Package theora :: Module wizard_gtk
[hide private]

Source Code for Module flumotion.component.encoders.theora.wizard_gtk

  1  # -*- Mode: Python -*- 
  2  # vi:si:et:sw=4:sts=4:ts=4 
  3   
  4  # Flumotion - a streaming media server 
  5  # Copyright (C) 2004,2005,2006,2007,2008,2009 Fluendo, S.L. 
  6  # Copyright (C) 2010,2011 Flumotion Services, S.A. 
  7  # All rights reserved. 
  8  # 
  9  # This file may be distributed and/or modified under the terms of 
 10  # the GNU Lesser General Public License version 2.1 as published by 
 11  # the Free Software Foundation. 
 12  # This file is distributed without any warranty; without even the implied 
 13  # warranty of merchantability or fitness for a particular purpose. 
 14  # See "LICENSE.LGPL" in the source distribution for more information. 
 15  # 
 16  # Headers in this file shall remain intact. 
 17   
 18  import gettext 
 19  import os 
 20   
 21  from zope.interface import implements 
 22   
 23  from flumotion.admin.assistant.interfaces import IEncoderPlugin 
 24  from flumotion.admin.assistant.models import VideoEncoder 
 25  from flumotion.common.fraction import fractionAsFloat 
 26  from flumotion.admin.gtk.basesteps import VideoEncoderStep 
 27   
 28  __version__ = "$Rev$" 
 29  _ = gettext.gettext 
 30   
 31   
32 -class TheoraVideoEncoder(VideoEncoder):
33 """ 34 @ivar framerate: number of frames per second; to be set by view 35 @type framerate: float 36 """ 37 componentType = 'theora-encoder' 38
39 - def __init__(self):
40 super(TheoraVideoEncoder, self).__init__() 41 self.has_quality = False 42 self.has_bitrate = True 43 self.framerate = 25.0 44 45 self.properties.keyframe_delta = 2.0 46 self.properties.bitrate = 400 47 self.properties.quality = 16 48 self.properties.speed = 3
49
50 - def getProperties(self):
51 properties = super(TheoraVideoEncoder, self).getProperties() 52 if self.has_bitrate: 53 del properties.quality 54 properties.bitrate *= 1000 55 elif self.has_quality: 56 del properties.bitrate 57 else: 58 raise AssertionError 59 60 # convert the human-friendly delta to maxdistance 61 # FIXME: I think the theora-encoder component should not expose 62 # the theora element properties directly, but just have keyframe-delta 63 # directly and calculate GStreamer element properties. But that's a 64 # property change. 65 properties.keyframe_maxdistance = int(properties.keyframe_delta * 66 self.framerate) 67 del properties.keyframe_delta 68 69 self.debug('keyframe_maxdistance: %r', 70 properties.keyframe_maxdistance) 71 72 return properties
73 74
75 -class TheoraStep(VideoEncoderStep):
76 name = 'TheoraEncoder' 77 title = _('Theora Encoder') 78 sidebarName = _('Theora') 79 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 80 'wizard.glade') 81 componentType = 'theora' 82 icon = 'xiphfish.png' 83 docSection = 'help-configuration-assistant-encoder-theora' 84 docAnchor = '' 85 docVersion = 'local' 86 87 # WizardStep 88
89 - def setup(self):
90 self.bitrate.data_type = int 91 self.quality.data_type = int 92 self.keyframe_delta.data_type = float 93 self.speed_type = int 94 self.has_quality.data_type = bool 95 self.has_bitrate.data_type = bool 96 97 self.add_proxy(self.model, 98 ['has_quality', 'has_bitrate']) 99 self.add_proxy(self.model.properties, 100 ['bitrate', 'quality', 'keyframe_delta', 'speed']) 101 102 # we specify keyframe_delta in seconds, but theora expects 103 # a number of frames, so we need the framerate and calculate 104 # we need to go through the Step (which is the view) because models 105 # don't have references to other models 106 producer = self.wizard.getScenario().getVideoProducer(self.wizard) 107 self.model.framerate = fractionAsFloat(producer.getFramerate()) 108 self.debug('Framerate of video producer: %r' % self.model.framerate) 109 step = 1 / self.model.framerate 110 page = 1.0 111 self.keyframe_delta.set_increments(step, page)
112
113 - def workerChanged(self, worker):
114 self.model.worker = worker 115 116 def hasTheora(unused, worker): 117 self.wizard.runInWorker( 118 worker, 'flumotion.worker.checks.encoder', 'checkTheora')
119 120 self.wizard.debug('running Theora checks') 121 d = self.wizard.requireElements(worker, 'theoraenc') 122 d.addCallback(hasTheora, worker)
123 124 # Callbacks 125
126 - def on_radiobutton_toggled(self, button):
127 # This is bound to both radiobutton_bitrate and radiobutton_quality 128 self.bitrate.set_sensitive(self.has_bitrate.get_active()) 129 self.quality.set_sensitive(self.has_quality.get_active()) 130 131 self.model.has_bitrate = self.has_bitrate.get_active() 132 self.model.has_quality = self.has_quality.get_active()
133 134
135 -class TheoraWizardPlugin(object):
136 implements(IEncoderPlugin) 137
138 - def __init__(self, wizard):
139 self.wizard = wizard 140 self.model = TheoraVideoEncoder()
141
142 - def getConversionStep(self):
143 return TheoraStep(self.wizard, self.model)
144