~ubuntu-branches/ubuntu/lucid/oggconvert/lucid

« back to all changes in this revision

Viewing changes to OggConvert/ocv_transcoder.py

  • Committer: Bazaar Package Importer
  • Author(s): Luca Falavigna
  • Date: 2008-01-19 17:52:14 UTC
  • mfrom: (1.1.3 upstream)
  • Revision ID: james.westby@ubuntu.com-20080119175214-w91ytv04bs0w9cuu
Tags: 0.3.1-1ubuntu1
* Merge from debian unstable. Fix LP: #175770
  Remaining changes:
  - Suggest gstreamer multiverse plugins

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
        self._vformat = vformat
42
42
        if self._vformat == "THEORA":
43
43
            self._vquality = ocv_constants.THEORA_QUALITY_MAPPING[vquality]
 
44
        elif self._vformat == "SCHRO":
 
45
            self._vquality = ocv_constants.SCHRO_QUALITY_MAPPING[vquality]
44
46
        else:
 
47
            # We should never get here
45
48
            self._vquality = 0
46
49
        self._aquality = ocv_constants.VORBIS_QUALITY_MAPPING[aquality]
47
50
        self._fformat = fformat
128
131
        caps = pad.get_caps()
129
132
        pad_type = caps.to_string()[0:5]
130
133
        if pad_type == "video":
131
 
            encoder = VideoEncoder(self._vformat)
132
 
            self._pipeline.add(encoder.bin,)
133
 
            # Schroenc doesn't have a quality setting right now
134
 
            if not self._vformat == "SCHRO":
135
 
                encoder.encoder.set_property("quality", self._vquality)
136
 
            encoder.bin.set_state(gst.STATE_PAUSED)
137
 
            pad.link(encoder.bin.get_pad("sink"))
138
 
            encoder.bin.link(self._mux)
 
134
            encoder = VideoEncoder(self._vformat, self._vquality)
 
135
            self._pipeline.add(encoder)
 
136
            encoder.set_state(gst.STATE_PAUSED)
 
137
            pad.link(encoder.get_pad("sink"))
 
138
            encoder.link(self._mux)
139
139
        elif pad_type == "audio":
140
 
            encoder = AudioEncoder()
141
 
            self._pipeline.add(encoder.bin)
142
 
            encoder.encoder.set_property("quality", self._aquality)
143
 
            encoder.bin.set_state(gst.STATE_PAUSED)
144
 
            pad.link(encoder.bin.get_pad("sink"))
145
 
            encoder.bin.link(self._mux)
 
140
            encoder = AudioEncoder(self._aquality)
 
141
            self._pipeline.add(encoder)
 
142
            encoder.set_state(gst.STATE_PAUSED)
 
143
            pad.link(encoder.get_pad("sink"))
 
144
            encoder.link(self._mux)
146
145
        else:
147
146
            print "Unknown pad type detected, %s" %pad_type
148
147
      
161
160
            
162
161
        
163
162
        
164
 
class VideoEncoder:
165
 
    def __init__(self, format):
166
 
        
167
 
        self.bin = gst.Bin()
 
163
class VideoEncoder(gst.Bin):
 
164
    def __init__(self, format, quality):
 
165
        gst.Bin.__init__(self)
168
166
        self._queue1 = gst.element_factory_make("queue")
169
167
        self._queue1.set_property("max-size-buffers",500)
170
168
        self._queue2 = gst.element_factory_make("queue")
176
174
            self.encoder = gst.element_factory_make("schroenc")
177
175
            for prop in ocv_constants.SCHRO_OPTS:
178
176
                self.encoder.set_property(prop, ocv_constants.SCHRO_OPTS[prop])
 
177
            try:
 
178
                self.encoder.set_property("noise-threshold", quality)
 
179
            except TypeError:
 
180
                print "This version of schroenc doesn't have the quality property"
179
181
        else:
180
182
            self.encoder = gst.element_factory_make("theoraenc")
181
183
            for prop in ocv_constants.THEORA_OPTS:
182
184
                self.encoder.set_property(prop, ocv_constants.THEORA_OPTS[prop])            
183
 
        
184
 
        
185
 
        self.bin.add(self._queue1, 
 
185
            self.encoder.set_property("quality", quality)
 
186
        
 
187
        self.add(self._queue1, 
186
188
                     self._ffmpegcsp,
187
189
                     self._videorate,
188
190
                     self.encoder,
195
197
                              self._queue2)
196
198
        
197
199
        # Create GhostPads
198
 
        self.bin.add_pad(gst.GhostPad('sink', self._queue1.get_pad('sink')))
199
 
        self.bin.add_pad(gst.GhostPad('src', self._queue2.get_pad('src')))
200
 
        
201
 
        
202
 
        
203
 
        
204
 
class AudioEncoder:
205
 
    def __init__(self):
206
 
        
207
 
        self.bin = gst.Bin()
 
200
        self.add_pad(gst.GhostPad('sink', self._queue1.get_pad('sink')))
 
201
        self.add_pad(gst.GhostPad('src', self._queue2.get_pad('src')))
 
202
        
 
203
        
 
204
        
 
205
        
 
206
class AudioEncoder(gst.Bin):
 
207
    def __init__(self, quality):
 
208
        gst.Bin.__init__(self)
208
209
        self._queue1 = gst.element_factory_make("queue")
209
210
        self._queue1.set_property("max-size-buffers",500)
210
211
        self._queue2 = gst.element_factory_make("queue")
236
237
        for prop in ocv_constants.VORBIS_OPTS:
237
238
            self.encoder.set_property(prop, ocv_constants.VORBIS_OPTS[prop])
238
239
        
 
240
        self.encoder.set_property("quality", quality)
239
241
        
240
 
        self.bin.add(self._queue1, 
 
242
        self.add(self._queue1, 
241
243
                     self._audioconvert,
242
244
                     self._audiorate,
243
245
                     self.encoder,
250
252
                              self._queue2)
251
253
        
252
254
        # Create GhostPads
253
 
        self.bin.add_pad(gst.GhostPad('sink', self._queue1.get_pad('sink')))
254
 
        self.bin.add_pad(gst.GhostPad('src', self._queue2.get_pad('src')))
 
255
        self.add_pad(gst.GhostPad('sink', self._queue1.get_pad('sink')))
 
256
        self.add_pad(gst.GhostPad('src', self._queue2.get_pad('src')))
255
257
        
256
258
 
257
259