diff -r 0bc04f7e67e6 -r 7dc357cbaa40 gmyth-stream/server/0.2/plugins/transcoders/mencoder.py --- a/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Thu Apr 19 16:02:10 2007 +0100 +++ b/gmyth-stream/server/0.2/plugins/transcoders/mencoder.py Thu Apr 19 22:38:46 2007 +0100 @@ -1,8 +1,10 @@ +import os +import shlex +import signal +import subprocess + import lib.utils as utils import lib.server as server -import os -import signal -import subprocess __all__ = ("TranscoderMencoder",) @@ -10,6 +12,8 @@ mencoder_path = utils.which("mencoder") name = "mencoder" priority = -1 + args = {} + proc = None def _setup_params(self): params_first = self.params_first @@ -22,8 +26,9 @@ self.args["outfile"] = params_first("outfile", "-") # input_opt - self.args["type"] = params_first("type", "file") - self.args["input"] = params_first("input", "-") + uri = params_first("uri", "file://-").split("://") + self.args["type"] = uri[0] + self.args["input"] = uri[1] # audio_opts self.args["acodec"] = params_first("acodec", "mp2") @@ -53,8 +58,8 @@ def _setup_video(self): - video = " -of %s" % self.mux - video += " -ofps %s" % self.fps + video = " -of %s" % self.args["mux"] + video += " -ofps %s" % self.args["fps"] vcodec = self.args["vcodec"] if vcodec == "nuv" or vcodec == "xvid"\ @@ -72,13 +77,13 @@ def _arg_append(self, args, options): - for arg in shlex.split(options) + for arg in shlex.split(options): args.append(arg) # arg_append() def _setup_mencoder_opts(self, args): args.append(self.mencoder_path) - args.append("-") + args.append(self.args["input"]) if self.args["language"]: self._arg_append(args, "-alang %s" % self.args["language"]) @@ -88,8 +93,8 @@ self._arg_append(args, "-subfps %s" % self.args["fps"]) self._arg_append(args, "-idx") - self._arg_append(args, self._setup_audio) - self._arg_append(args, self._setup_video) + self._arg_append(args, self._setup_audio()) + self._arg_append(args, self._setup_video()) self._arg_append(args, "-really-quiet") self._arg_append(args, "-o %s" % self.args["outfile"]) @@ -102,22 +107,17 @@ if _type == "file": if not os.path.exists(self.args["input"]): - raise IOError, "File requested does not exist." + raise IOError,\ + "File requested does not exist: %s." % self.args["input"] elif _type == "dvd": self.args["input"] = "dvd://".join(self.args["input"]) - - elif _type == "myth": - self.args["input"] = "myth://".join(self.args["input"]) - self.gst_pipe = os.pipe() # _setup_filename() def __init__(self, params): server.Transcoder.__init__(self, params) - self.proc = None - self.args = None - self.mencoder_opts = None + self.mencoder_opts = [] try: self._setup_params() @@ -125,34 +125,22 @@ self._setup_mencoder_opts(self.mencoder_opts) except Exception, e: self.log.error(e) - return False - - return True # __init__() def start(self, outfd): - cmd = " ".join(self.args) - self.log.info("Mencoder: %s" % cmd) - - if self.args["type"] == "file": - _input = open(self.args["input"]) + cmd = " ".join(self.mencoder_opts) + self.log.debug("Mencoder: %s" % cmd) try: - self.proc = subprocess.Popen(self.args, close_fds=True) + self.proc = subprocess.Popen(self.mencoder_opts, stdout=subprocess.PIPE, close_fds=True) except Exception, e: - self.log.error("Error executing mencoder: %s" % cmd) - return False - - try: - fifo_read = open(self.mencoder_outfile) - except Exception, e: - self.log.error("Error opening fifo: %s" % cmd) + self.log.error("Error executing mencoder: %s" % e) return False try: while self.proc and self.proc.poll() == None: - d = fifo_read.read(1024) + d = self.proc.stdout.read(1024) outfd.write(d) except Exception, e: self.log.error("Problems handling data: %s" % e)