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

Source Code for Module flumotion.component.encoders.vp8.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 VP8VideoEncoder(VideoEncoder):
33 """ 34 @ivar framerate: number of frames per second; to be set by view 35 @type framerate: float 36 """ 37 componentType = 'vp8-encoder' 38
39 - def __init__(self):
40 super(VP8VideoEncoder, 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
49 - def getProperties(self):
50 properties = super(VP8VideoEncoder, self).getProperties() 51 if self.has_bitrate: 52 del properties.quality 53 properties.bitrate *= 1000 54 elif self.has_quality: 55 del properties.bitrate 56 else: 57 raise AssertionError 58 59 # convert the human-friendly delta to maxdistance 60 properties.keyframe_maxdistance = int(properties.keyframe_delta * 61 self.framerate) 62 del properties.keyframe_delta 63 64 self.debug('keyframe_maxdistance: %r', 65 properties.keyframe_maxdistance) 66 67 return properties
68 69
70 -class VP8Step(VideoEncoderStep):
71 name = 'VP8Encoder' 72 title = _('VP8 Encoder') 73 sidebarName = _('VP8') 74 gladeFile = os.path.join(os.path.dirname(os.path.abspath(__file__)), 75 'wizard.glade') 76 componentType = 'vp8' 77 docSection = 'help-configuration-assistant-encoder-vp8' 78 docAnchor = '' 79 docVersion = 'local' 80 81 # WizardStep 82
83 - def setup(self):
84 self.bitrate.data_type = int 85 self.quality.data_type = int 86 self.keyframe_delta.data_type = float 87 self.has_quality.data_type = bool 88 self.has_bitrate.data_type = bool 89 90 self.add_proxy(self.model, 91 ['has_quality', 'has_bitrate']) 92 self.add_proxy(self.model.properties, 93 ['bitrate', 'quality', 'keyframe_delta']) 94 95 # we specify keyframe_delta in seconds, but vp8 expects 96 # a number of frames, so we need the framerate and calculate 97 # we need to go through the Step (which is the view) because models 98 # don't have references to other models 99 producer = self.wizard.getScenario().getVideoProducer(self.wizard) 100 self.model.framerate = fractionAsFloat(producer.getFramerate()) 101 self.debug('Framerate of video producer: %r' % self.model.framerate) 102 step = 1 / self.model.framerate 103 page = 1.0 104 self.keyframe_delta.set_increments(step, page)
105
106 - def workerChanged(self, worker):
107 self.model.worker = worker 108 self.wizard.requireElements(worker, 'vp8enc')
109 110 # Callbacks 111
112 - def on_radiobutton_toggled(self, button):
113 # This is bound to both radiobutton_bitrate and radiobutton_quality 114 self.bitrate.set_sensitive(self.has_bitrate.get_active()) 115 self.quality.set_sensitive(self.has_quality.get_active()) 116 117 self.model.has_bitrate = self.has_bitrate.get_active() 118 self.model.has_quality = self.has_quality.get_active()
119 120
121 -class VP8WizardPlugin(object):
122 implements(IEncoderPlugin) 123
124 - def __init__(self, wizard):
125 self.wizard = wizard 126 self.model = VP8VideoEncoder()
127
128 - def getConversionStep(self):
129 return VP8Step(self.wizard, self.model)
130