[svn r678] implemented progress on gmencoder plugin trunk
authorrenatofilho
Wed May 16 18:46:10 2007 +0100 (2007-05-16)
branchtrunk
changeset 6724e623a4274a1
parent 671 a05b421242e4
child 673 5ee8c970d982
[svn r678] implemented progress on gmencoder plugin
gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py
     1.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py	Wed May 16 18:45:29 2007 +0100
     1.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py	Wed May 16 18:46:10 2007 +0100
     1.3 @@ -2,6 +2,9 @@
     1.4  import shlex
     1.5  import signal
     1.6  import subprocess
     1.7 +import time
     1.8 +
     1.9 +import select
    1.10  
    1.11  import lib.utils as utils
    1.12  import lib.server as server
    1.13 @@ -26,7 +29,7 @@
    1.14  
    1.15      def _parser_params (self):
    1.16          self._insert_param("-i", \
    1.17 -            "%s://%s" % (self.params_first("uri_prefix", "file"), self.params_first("uri_path", "")))
    1.18 +            "%s://%s" % (self.params_first("type", "file"), self.params_first("uri", "")))
    1.19          self._insert_param("--video-encode", self.params_first("ve", ""))
    1.20          self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    1.21          self._insert_param("--video-fps", self.params_first("fps", ""))
    1.22 @@ -45,13 +48,19 @@
    1.23          self.log.info ("GMencoder: %s", cmd)
    1.24  
    1.25          try:
    1.26 -            self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE)
    1.27 +            self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    1.28          except Exception, e:
    1.29              self.log.error("Error executing GMencoder: %s" % e)
    1.30              return False
    1.31  
    1.32          try:
    1.33 -             self.proc.wait()
    1.34 +			while (self.proc and self.proc.poll() == None):
    1.35 +				r, w, x = select.select([self.proc.stdout], [], [], 0)
    1.36 +				if self.proc.stdout in r:
    1.37 +					progress = self.proc.stdout.readline()
    1.38 +					if (progress.find ("PROGRESS") >= 0):
    1.39 +						self.status = progress.split (":")[1]
    1.40 +			self.log.info ("Process exit")
    1.41          except Exception, e:
    1.42              self.log.error("Problems handling data: %s" % e)
    1.43              return False
    1.44 @@ -62,7 +71,7 @@
    1.45  
    1.46      def stop(self):
    1.47          if self.proc:
    1.48 -            self.log.info ("STOPed GMencoder plugin")
    1.49 +            self.log.info ("STOPED GMencoder plugin")
    1.50              try:
    1.51                  self.proc.stdin.write ("QUIT\n")
    1.52              except Exception, e: