1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 from twisted.internet import reactor
23 import gobject
24 import gst
25
26 from flumotion.common import errors, messages, gstreamer
27 from flumotion.common.i18n import N_, gettexter
28 from flumotion.component import feedcomponent
29
30 __version__ = "$Rev$"
31 T_ = gettexter()
32
33
35 """
36 I am a GStreamer bin that can change the framerate of a video stream.
37 """
38 logCategory = "videosrate"
39 CAPS_TEMPLATE = "video/x-raw-yuv%(fr)s;"\
40 "video/x-raw-rgb%(fr)s"
41
42 __gproperties__ = {
43 'framerate': (gobject.TYPE_OBJECT, 'framerate',
44 'Video framerate', gobject.PARAM_READWRITE)}
45
46 - def __init__(self, framerate=gst.Fraction(25, 1)):
47 gst.Bin.__init__(self)
48 self._framerate = framerate
49
50 self._videorate = gst.element_factory_make("videorate")
51 self._capsfilter = gst.element_factory_make("capsfilter")
52 self.add(self._videorate, self._capsfilter)
53
54 self._videorate.link(self._capsfilter)
55
56
57 self._sinkPad = gst.GhostPad('sink', self._videorate.get_pad('sink'))
58 self._srcPad = gst.GhostPad('src', self._capsfilter.get_pad('src'))
59 self.add_pad(self._sinkPad)
60 self.add_pad(self._srcPad)
61
62 self._setFramerate(framerate)
63
68
70 if property.name == 'framerate':
71 self._setFramerate(value)
72 else:
73 raise AttributeError('unknown property %s' % property.name)
74
76 if property.name == 'framerate':
77 return self._framerate
78 else:
79 raise AttributeError('unknown property %s' % property.name)
80
82 if self._framerate is None:
83 return ""
84 return ",framerate=(fraction)%d/%d" % (self._framerate.num,
85 self._framerate.denom)
86
87
88 -class Videorate(feedcomponent.PostProcEffect):
89 """
90 I am an effect that can be added to any component that has a videorate
91 component and a way of changing the output framerate.
92 """
93 logCategory = "videorate-effect"
94
95 - def __init__(self, name, sourcePad, pipeline, framerate):
96 """
97 @param element: the video source element on which the post
98 processing effect will be added
99 @param sourcePad: source pad used for linking the effect
100 @param pipeline: the pipeline of the element
101 @param framerate: output framerate
102 """
103 feedcomponent.PostProcEffect.__init__(self, name, sourcePad,
104 VideorateBin(framerate), pipeline)
105
107 self.effectBin.set_property("framerate", framerate)
108 return framerate
109
111 return self.effectBin.get_property('framerate')
112