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