2
# PiTiVi , Non-linear video editor
6
# Copyright (c) 2009, Edward Hervey <bilboed@bilboed.com>
8
# This program is free software; you can redistribute it and/or
9
# modify it under the terms of the GNU Lesser General Public
10
# License as published by the Free Software Foundation; either
11
# version 2.1 of the License, or (at your option) any later version.
13
# This program is distributed in the hope that it will be useful,
14
# but WITHOUT ANY WARRANTY; without even the implied warranty of
15
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16
# Lesser General Public License for more details.
18
# You should have received a copy of the GNU Lesser General Public
19
# License along with this program; if not, write to the
20
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
21
# Boston, MA 02111-1307, USA.
24
from pitivi.factories.base import OperationFactory
25
from pitivi.elements.smartscale import SmartVideoScale
26
from pitivi.stream import AudioStream, VideoStream
28
# FIXME: define a proper hierarchy
29
class OperationFactoryError(Exception):
32
class ModifierFactoryError(OperationFactoryError):
35
class TransformFactory(OperationFactory):
37
Factories that take exactly one input stream and output exactly one output
41
def addTransformStreams(self, input_stream, output_stream):
42
self.addInputStream(input_stream)
43
self.addOutputStream(output_stream)
45
def addInputStream(self, stream):
46
if len(self.input_streams) > 1:
47
raise OperationFactoryError("Can't handle more than one stream")
48
return OperationFactory.addInputStream(self, stream)
50
def addOutputStream(self, stream):
51
if len(self.output_streams) > 1:
52
raise OperationFactoryError("Can't handle more than one stream")
53
return OperationFactory.addOutputStream(self, stream)
55
def _requestNewInputStream(self, *args):
56
raise OperationFactoryError("TransformFactory doesn't allow request pads")
58
class StreamModifierFactory(TransformFactory):
60
Factories that modify the nature/type of a stream.
64
class AudioModifierFactory(StreamModifierFactory):
66
def _makeBin(self, *args):
68
idt = gst.element_factory_make("identity", "single-segment")
69
idt.props.single_segment = True
70
aconv = gst.element_factory_make("audioconvert", "aconv")
71
ares = gst.element_factory_make("audioresample", "ares")
72
arate = gst.element_factory_make("audiorate", "arate")
73
b.add(idt, aconv, ares, arate)
74
gst.element_link_many(idt, aconv, ares, arate)
76
gsink = gst.GhostPad("sink", idt.get_pad("sink"))
77
gsink.set_active(True)
80
# if we have an output stream specified, we add a capsfilter
81
if len(self.output_streams):
82
cfilter = gst.element_factory_make("capsfilter")
83
cfilter.props.caps = self.output_streams[0].caps
87
gsrc = gst.GhostPad("src", cfilter.get_pad("src"))
89
gsrc = gst.GhostPad("src", arate.get_pad("src"))
95
class VideoModifierFactory(StreamModifierFactory):
97
def _makeBin(self, *args):
99
idt = gst.element_factory_make("identity", "single-segment")
100
idt.props.single_segment = True
101
csp = gst.element_factory_make("ffmpegcolorspace", "csp")
102
vrate = gst.element_factory_make("videorate", "vrate")
104
b.add(idt, csp, vrate)
105
gst.element_link_many(idt, csp, vrate)
107
gsink = gst.GhostPad("sink", idt.get_pad("sink"))
108
gsink.set_active(True)
111
# if we have an output stream specified, we add a capsfilter
112
self.debug("output_streams:%d", len(self.output_streams))
113
if len(self.output_streams) and self.output_streams[0].caps.is_fixed():
114
vscale = SmartVideoScale()
115
vscale.set_caps(self.output_streams[0].caps)
119
idt = gst.element_factory_make("capsfilter")
120
idt.props.caps = self.output_streams[0].caps
124
gsrc = gst.GhostPad("src", idt.get_pad("src"))
126
gsrc = gst.GhostPad("src", vrate.get_pad("src"))
128
gsrc.set_active(True)
132
def get_modifier_for_stream(input_stream=None, output_stream=None):
134
Returns a L{StreamModifierFactory} for the given streams.
136
@raises ModifierFactoryError: If no modifier factory is available
137
for the given streams.
139
if input_stream == None and output_stream == None:
140
raise ModifierFactoryError("No streams provided")
141
if (isinstance(input_stream, AudioStream) or input_stream == None) and \
142
(isinstance(output_stream, AudioStream) or output_stream == None):
143
res = AudioModifierFactory()
144
elif (isinstance(input_stream, VideoStream) or input_stream == None) and \
145
(isinstance(output_stream, VideoStream) or output_stream == None):
146
res = VideoModifierFactory()
148
raise ModifierFactoryError("No modifier for given stream type")
150
res.addInputStream(input_stream)
152
res.addOutputStream(output_stream)