Make mediagoblin SQL models all use a consistent table naming scheme
[mediagoblin.git] / mediagoblin / media_types / video / transcoders.py
index f6a2eb214951d96dae8ac07c405274327e1495b4..6137c3bf1c6e649cba793f58b3e49164d09a9931 100644 (file)
@@ -1,5 +1,5 @@
 # GNU MediaGoblin -- federated, autonomous media hosting
-# Copyright (C) 2011 MediaGoblin contributors.  See AUTHORS.
+# Copyright (C) 2011, 2012 MediaGoblin contributors.  See AUTHORS.
 #
 # This program is free software: you can redistribute it and/or modify
 # it under the terms of the GNU Affero General Public License as published by
@@ -17,7 +17,6 @@
 from __future__ import division
 
 import os
-os.environ["GST_DEBUG_DUMP_DOT_DIR"] = "/tmp"
 os.putenv('GST_DEBUG_DUMP_DOT_DIR', '/tmp')
 
 import sys
@@ -56,7 +55,6 @@ try:
     import pygst
     pygst.require('0.10')
     import gst
-    from gst import pbutils
     from gst.extend import discoverer
 except:
     raise Exception('gst/pygst 0.10 could not be found')
@@ -76,14 +74,14 @@ class VideoThumbnailer:
 
     buffer_probes = {}
 
-    errors = []
-
     def __init__(self, source_path, dest_path):
         '''
         Set up playbin pipeline in order to get video properties.
 
         Initializes and runs the gobject.MainLoop()
         '''
+        self.errors = []
+
         self.source_path = source_path
         self.dest_path = dest_path
 
@@ -96,8 +94,8 @@ class VideoThumbnailer:
         self.videosink = gst.element_factory_make('fakesink', 'videosink')
         self.playbin.set_property('video-sink', self.videosink)
 
-        #self.audiosink = gst.element_factory_make('fakesink', 'audiosink')
-        #self.playbin.set_property('audio-sink', self.audiosink)
+        self.audiosink = gst.element_factory_make('fakesink', 'audiosink')
+        self.playbin.set_property('audio-sink', self.audiosink)
 
         self.bus = self.playbin.get_bus()
         self.bus.add_signal_watch()
@@ -197,7 +195,6 @@ class VideoThumbnailer:
 
                 _log.debug('seek amount: {0}'.format(seek_amount))
 
-                
                 seek_result = self.thumbnail_pipeline.seek(
                     1.0,
                     gst.FORMAT_TIME,
@@ -206,14 +203,6 @@ class VideoThumbnailer:
                     seek_amount,
                     gst.SEEK_TYPE_NONE,
                     0)
-                '''
-
-                seek_result = self.thumbnail_pipeline.seek_simple(
-                    gst.FORMAT_TIME,
-                    gst.SEEK_FLAG_FLUSH | gst.SEEK_FLAG_ACCURATE,
-                    seek_amount)
-
-                '''
 
                 if not seek_result:
                     self.errors.append('COULD_NOT_SEEK')
@@ -499,28 +488,30 @@ class VideoTranscoder:
         # or audio sink
         self.filesrc.link(self.decoder)
 
-        # Link all the video elements in a link to webmux
-        self.videoqueue.link(self.videorate)
-        self.videorate.link(self.ffmpegcolorspace)
-        self.ffmpegcolorspace.link(self.videoscale)
-        self.videoscale.link(self.capsfilter)
-        #self.capsfilter.link(self.xvimagesink)
-        self.capsfilter.link(self.vp8enc)
-        self.vp8enc.link(self.webmmux)
+        # Link all the video elements in a row to webmmux
+        gst.element_link_many(
+            self.videoqueue,
+            self.videorate,
+            self.ffmpegcolorspace,
+            self.videoscale,
+            self.capsfilter,
+            self.vp8enc,
+            self.webmmux)
 
         if self.data.is_audio:
-            # Link all the audio elements in a line to webmux
-            #self.audioconvert.link(self.alsasink)
-            self.audioqueue.link(self.audiorate)
-            self.audiorate.link(self.audioconvert)
-            self.audioconvert.link(self.audiocapsfilter)
-            self.audiocapsfilter.link(self.vorbisenc)
-            #self.audiocapsfilter.link(self.level)
-            #self.level.link(self.vorbisenc)
-            self.vorbisenc.link(self.webmmux)
-
-        self.webmmux.link(self.progressreport)
-        self.progressreport.link(self.filesink)
+            # Link all the audio elements in a row to webmux
+            gst.element_link_many(
+                self.audioqueue,
+                self.audiorate,
+                self.audioconvert,
+                self.audiocapsfilter,
+                self.vorbisenc,
+                self.webmmux)
+
+        gst.element_link_many(
+            self.webmmux,
+            self.progressreport,
+            self.filesink)
 
         # Setup the message bus and connect _on_message to the pipeline
         self._setup_bus()
@@ -576,17 +567,13 @@ class VideoTranscoder:
 
         elif t == gst.MESSAGE_ELEMENT:
             if message.structure.get_name() == 'progress':
-                data = {
-                    'structure': message.structure,
-                    'percent': message.structure['percent'],
-                    'total': message.structure['total'],
-                    'current': message.structure['current']}
+                data = dict(message.structure)
 
                 if self._progress_callback:
                     self._progress_callback(data)
 
                 _log.info('{percent}% done...'.format(
-                        percent=data['percent']))
+                        percent=data.get('percent')))
                 _log.debug(data)
 
         elif t == gst.MESSAGE_ERROR: