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