~ubuntu-branches/ubuntu/trusty/pitivi/trusty

« back to all changes in this revision

Viewing changes to pitivi/encode.py

  • Committer: Bazaar Package Importer
  • Author(s): Sebastien Bacher
  • Date: 2011-07-07 13:43:47 UTC
  • mto: (6.1.9 sid) (1.2.12)
  • mto: This revision was merged to the branch mainline in revision 32.
  • Revision ID: james.westby@ubuntu.com-20110707134347-cari9kxjiakzej9z
Tags: upstream-0.14.1
ImportĀ upstreamĀ versionĀ 0.14.1

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
#
17
17
# You should have received a copy of the GNU Lesser General Public
18
18
# License along with this program; if not, write to the
19
 
# Free Software Foundation, Inc., 59 Temple Place - Suite 330,
20
 
# Boston, MA 02111-1307, USA.
 
19
# Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
 
20
# Boston, MA 02110-1301, USA.
21
21
 
22
22
"""
23
23
Encoding-related utilities and classes
29
29
from pitivi.factories.base import OperationFactory, SinkFactory
30
30
from pitivi.factories.operation import TransformFactory, get_modifier_for_stream
31
31
 
 
32
 
32
33
class EncoderFactory(TransformFactory):
33
34
    """
34
35
    Creates one-to-one encoding bins based on provided L{StreamEncodeSettings}.
86
87
            if isinstance(b, gst.Bin):
87
88
                b.factory.releaseBin(b)
88
89
 
 
90
 
89
91
class RenderFactory(OperationFactory):
90
92
    """
91
93
    Handles factories that consume streams and output one (and only one
162
164
    def _requestNewInputStream(self, bin, input_stream):
163
165
        raise NotImplementedError
164
166
 
 
167
 
165
168
class RenderSinkFactory(SinkFactory):
166
169
    """
167
170
    Convenience class combining a L{RenderFactory} and a L{SinkFactory}.
240
243
    """
241
244
    factory = gst.registry_get_default().lookup_feature(factoryname)
242
245
    if factory == None:
243
 
        log.warning("encode","%s is not a valid factoryname", factoryname)
 
246
        log.warning("encode", "%s is not a valid factoryname", factoryname)
244
247
        return None
245
248
 
246
249
    res = []
247
250
    sinkpads = [x for x in factory.get_static_pad_templates() if x.direction == gst.PAD_SINK]
248
251
    for p in sinkpads:
249
252
        c = p.get_caps()
250
 
        log.log("encode","sinkcaps %s", c.to_string())
 
253
        log.log("encode", "sinkcaps %s", c.to_string())
251
254
        inter = caps.intersect(c)
252
 
        log.log("encode","intersection %s", inter.to_string())
 
255
        log.log("encode", "intersection %s", inter.to_string())
253
256
        if inter:
254
257
            res.append(p.name_template)
255
258
    if len(res) > 0:
256
259
        return res[0]
257
260
    return None
258
261
 
 
262
 
259
263
def get_compatible_sink_caps(factoryname, caps):
260
264
    """
261
265
    Returns the compatible caps between 'caps' and the sink pad caps of 'factoryname'
262
266
    """
263
 
    log.log("encode","factoryname : %s , caps : %s", factoryname, caps.to_string())
 
267
    log.log("encode", "factoryname : %s , caps : %s", factoryname, caps.to_string())
264
268
    factory = gst.registry_get_default().lookup_feature(factoryname)
265
269
    if factory == None:
266
 
        log.warning("encode","%s is not a valid factoryname", factoryname)
 
270
        log.warning("encode", "%s is not a valid factoryname", factoryname)
267
271
        return None
268
272
 
269
273
    res = []
270
274
    sinkcaps = [x.get_caps() for x in factory.get_static_pad_templates() if x.direction == gst.PAD_SINK]
271
275
    for c in sinkcaps:
272
 
        log.log("encode","sinkcaps %s", c.to_string())
 
276
        log.log("encode", "sinkcaps %s", c.to_string())
273
277
        inter = caps.intersect(c)
274
 
        log.log("encode","intersection %s", inter.to_string())
 
278
        log.log("encode", "intersection %s", inter.to_string())
275
279
        if inter:
276
280
            res.append(inter)
277
281
 
279
283
        return res[0]
280
284
    return None
281
285
 
 
286
 
282
287
def list_compat(a1, b1):
283
288
    for x1 in a1:
284
289
        if not x1 in b1:
285
290
            return False
286
291
    return True
287
292
 
 
293
 
288
294
def my_can_sink_caps(muxer, ocaps, muxsinkcaps=[]):
289
295
    """ returns True if the given caps intersect with some of the muxer's
290
296
    sink pad templates' caps.
308
314
    #         return True
309
315
    # return False
310
316
 
 
317
 
311
318
class CachedEncoderList(object):
312
319
    def __init__(self):
313
320
        self._factories = None
351
358
        self._factories = None
352
359
 
353
360
_cached_encoder_list = None
 
361
 
 
362
 
354
363
def encoderlist():
355
364
    global _cached_encoder_list
356
365
    if _cached_encoder_list is None:
357
366
        _cached_encoder_list = CachedEncoderList()
358
367
    return _cached_encoder_list
359
368
 
 
369
 
360
370
def available_muxers():
361
371
    """ return all available muxers """
362
372
    enclist = encoderlist()
363
373
    return enclist.available_muxers()
364
374
 
 
375
 
365
376
def available_video_encoders():
366
377
    """ returns all available video encoders """
367
378
    enclist = encoderlist()
368
379
    return enclist.available_video_encoders()
369
380
 
 
381
 
370
382
def available_audio_encoders():
371
383
    """ returns all available audio encoders """
372
384
    enclist = encoderlist()
373
385
    return enclist.available_audio_encoders()
374
386
 
 
387
 
375
388
def encoders_muxer_compatible(encoders, muxer, muxsinkcaps=[]):
376
389
    """ returns the list of encoders compatible with the given muxer """
377
390
    res = []
385
398
                    break
386
399
    return res
387
400
 
 
401
 
388
402
raw_audio_caps = gst.Caps("audio/x-raw-float;audio/x-raw-int")
389
403
raw_video_caps = gst.Caps("video/x-raw-yuv;video/x-raw-rgb")
 
404
 
 
405
 
390
406
def muxer_can_sink_raw_audio(muxer):
391
407
    """ Returns True if given muxer can accept raw audio """
392
408
    return my_can_sink_caps(muxer, raw_audio_caps)
393
409
 
 
410
 
394
411
def muxer_can_sink_raw_video(muxer):
395
412
    """ Returns True if given muxer can accept raw video """
396
413
    return my_can_sink_caps(muxer, raw_video_caps)
397
414
 
398
415
 
399
416
def available_combinations():
400
 
 
401
417
    """Return a 3-tuple of (muxers, audio, video), where:
402
418
        - muxers is a list of muxer factories
403
419
        - audio is a dictionary from muxer names to compatible audio encoders