gmyth-stream/server/0.2/plugins/transcoders/mencoder.py
branchtrunk
changeset 577 7dc357cbaa40
parent 572 0bc04f7e67e6
child 585 a1783dab9ba6
     1.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Thu Apr 19 16:02:10 2007 +0100
     1.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py	Thu Apr 19 22:38:46 2007 +0100
     1.3 @@ -1,8 +1,10 @@
     1.4 +import os
     1.5 +import shlex
     1.6 +import signal
     1.7 +import subprocess
     1.8 +
     1.9  import lib.utils as utils
    1.10  import lib.server as server
    1.11 -import os
    1.12 -import signal
    1.13 -import subprocess
    1.14  
    1.15  __all__ = ("TranscoderMencoder",)
    1.16  
    1.17 @@ -10,6 +12,8 @@
    1.18      mencoder_path = utils.which("mencoder")
    1.19      name = "mencoder"
    1.20      priority = -1
    1.21 +    args = {}
    1.22 +    proc = None
    1.23  
    1.24      def _setup_params(self):
    1.25          params_first = self.params_first
    1.26 @@ -22,8 +26,9 @@
    1.27          self.args["outfile"]  = params_first("outfile", "-")
    1.28  
    1.29          # input_opt
    1.30 -        self.args["type"]     = params_first("type", "file")
    1.31 -        self.args["input"]    = params_first("input", "-")
    1.32 +        uri = params_first("uri", "file://-").split("://")
    1.33 +        self.args["type"]     = uri[0]
    1.34 +        self.args["input"]    = uri[1]
    1.35  
    1.36          # audio_opts
    1.37          self.args["acodec"]   = params_first("acodec", "mp2")
    1.38 @@ -53,8 +58,8 @@
    1.39  
    1.40  
    1.41      def _setup_video(self):
    1.42 -        video = " -of %s" % self.mux
    1.43 -        video += " -ofps %s" % self.fps
    1.44 +        video = " -of %s" % self.args["mux"]
    1.45 +        video += " -ofps %s" % self.args["fps"]
    1.46  
    1.47          vcodec = self.args["vcodec"]
    1.48          if vcodec == "nuv" or vcodec == "xvid"\
    1.49 @@ -72,13 +77,13 @@
    1.50  
    1.51  
    1.52      def _arg_append(self, args, options):
    1.53 -        for arg in shlex.split(options)
    1.54 +        for arg in shlex.split(options):
    1.55              args.append(arg)
    1.56      # arg_append()
    1.57  
    1.58      def _setup_mencoder_opts(self, args):
    1.59          args.append(self.mencoder_path)
    1.60 -        args.append("-")
    1.61 +        args.append(self.args["input"])
    1.62  
    1.63          if self.args["language"]:
    1.64              self._arg_append(args, "-alang %s" % self.args["language"])
    1.65 @@ -88,8 +93,8 @@
    1.66              self._arg_append(args, "-subfps %s" % self.args["fps"])
    1.67  
    1.68          self._arg_append(args, "-idx")
    1.69 -        self._arg_append(args, self._setup_audio)
    1.70 -        self._arg_append(args, self._setup_video)
    1.71 +        self._arg_append(args, self._setup_audio())
    1.72 +        self._arg_append(args, self._setup_video())
    1.73  
    1.74          self._arg_append(args, "-really-quiet")
    1.75          self._arg_append(args, "-o %s" % self.args["outfile"])
    1.76 @@ -102,22 +107,17 @@
    1.77  
    1.78          if _type == "file":
    1.79              if not os.path.exists(self.args["input"]):
    1.80 -                raise IOError, "File requested does not exist."
    1.81 +                raise IOError,\
    1.82 +                      "File requested does not exist: %s." % self.args["input"]
    1.83  
    1.84          elif _type == "dvd":
    1.85              self.args["input"] = "dvd://".join(self.args["input"])
    1.86 -
    1.87 -        elif _type == "myth":
    1.88 -            self.args["input"] = "myth://".join(self.args["input"])
    1.89 -            self.gst_pipe = os.pipe()
    1.90      # _setup_filename()
    1.91  
    1.92  
    1.93      def __init__(self, params):
    1.94          server.Transcoder.__init__(self, params)
    1.95 -        self.proc = None
    1.96 -        self.args = None
    1.97 -        self.mencoder_opts = None
    1.98 +        self.mencoder_opts = []
    1.99  
   1.100          try:
   1.101              self._setup_params()
   1.102 @@ -125,34 +125,22 @@
   1.103              self._setup_mencoder_opts(self.mencoder_opts)
   1.104          except Exception, e:
   1.105              self.log.error(e)
   1.106 -            return False
   1.107 -
   1.108 -        return True
   1.109      # __init__()
   1.110  
   1.111  
   1.112      def start(self, outfd):
   1.113 -        cmd = " ".join(self.args)
   1.114 -        self.log.info("Mencoder: %s" % cmd)
   1.115 -
   1.116 -        if self.args["type"] == "file":
   1.117 -            _input = open(self.args["input"])
   1.118 +        cmd = " ".join(self.mencoder_opts)
   1.119 +        self.log.debug("Mencoder: %s" % cmd)
   1.120  
   1.121          try:
   1.122 -            self.proc = subprocess.Popen(self.args, close_fds=True)
   1.123 +            self.proc = subprocess.Popen(self.mencoder_opts, stdout=subprocess.PIPE, close_fds=True)
   1.124          except Exception, e:
   1.125 -            self.log.error("Error executing mencoder: %s" % cmd)
   1.126 -            return False
   1.127 -
   1.128 -        try:
   1.129 -            fifo_read = open(self.mencoder_outfile)
   1.130 -        except Exception, e:
   1.131 -            self.log.error("Error opening fifo: %s" % cmd)
   1.132 +            self.log.error("Error executing mencoder: %s" % e)
   1.133              return False
   1.134  
   1.135          try:
   1.136              while self.proc and self.proc.poll() == None:
   1.137 -                d = fifo_read.read(1024)
   1.138 +                d = self.proc.stdout.read(1024)
   1.139                  outfd.write(d)
   1.140          except Exception, e:
   1.141              self.log.error("Problems handling data: %s" % e)