gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py
branchtrunk
changeset 830 0e159c5e2d32
parent 829 0a4e6b811acc
child 831 e2baa6947dbf
     1.1 --- a/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py	Tue Aug 28 15:41:35 2007 +0100
     1.2 +++ /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.3 @@ -1,91 +0,0 @@
     1.4 -import os
     1.5 -import shlex
     1.6 -import signal
     1.7 -import subprocess
     1.8 -import time
     1.9 -
    1.10 -import select
    1.11 -
    1.12 -import lib.utils as utils
    1.13 -import lib.server as server
    1.14 -
    1.15 -__all__ = ("TranscoderGMencoder",)
    1.16 -
    1.17 -class TranscoderGMencoder(server.Transcoder):
    1.18 -    gmencoder_path = utils.which("gmencoder")
    1.19 -    name = "gmencoder"
    1.20 -    priority = -1
    1.21 -    proc = None
    1.22 -
    1.23 -    def __init__(self, params):
    1.24 -        server.Transcoder.__init__(self, params)
    1.25 -        self.opts = []
    1.26 -    # __init__()
    1.27 -
    1.28 -    def _insert_param (self, name, value):
    1.29 -        if (value != ""):
    1.30 -            self.opts.append(name)
    1.31 -            self.opts.append(value)
    1.32 -
    1.33 -    def _parser_params (self):
    1.34 -        self._insert_param("-i", \
    1.35 -            "%s://%s" % (self.params_first("type", "file"), self.params_first("uri", "")))
    1.36 -        self._insert_param("--video-encode", self.params_first("ve", ""))
    1.37 -        self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    1.38 -        self._insert_param("--video-fps", self.params_first("fps", ""))
    1.39 -        self._insert_param("--video-width", self.params_first("width", ""))
    1.40 -        self._insert_param("--video-height", self.params_first("height", ""))
    1.41 -        self._insert_param("--audio-rate", "32000")
    1.42 -        self._insert_param("--audio-encode", self.params_first("ae", ""))
    1.43 -    # _parse_params
    1.44 -
    1.45 -    def start(self, outfd):
    1.46 -        self.opts.append (self.gmencoder_path)
    1.47 -        self._parser_params ()
    1.48 -        self._insert_param ("-o", "fd://%d" % outfd.fileno())
    1.49 -
    1.50 -        cmd = " ".join(self.opts)
    1.51 -        self.log.info ("GMencoder: %s", cmd)
    1.52 -
    1.53 -        try:
    1.54 -            self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
    1.55 -        except Exception, e:
    1.56 -            self.log.error("Error executing GMencoder: %s" % e)
    1.57 -            return False
    1.58 -
    1.59 -        try:
    1.60 -			while (self.proc and self.proc.poll() == None):
    1.61 -				r, w, x = select.select([self.proc.stdout], [], [], 0)
    1.62 -				if self.proc.stdout in r:
    1.63 -					progress = self.proc.stdout.readline()
    1.64 -					self.log.info ("stdout %s" % progress)
    1.65 -					if (progress.find ("PROGRESS") >= 0):
    1.66 -						self.status = progress.split (":")[1]
    1.67 -					#if (progress.find ("DONE") >= 0):
    1.68 -					#	break
    1.69 -			self.log.info ("Process exit")
    1.70 -        except Exception, e:
    1.71 -            self.log.error("Problems handling data: %s" % e)
    1.72 -            return False
    1.73 -
    1.74 -        return True
    1.75 -    # start()
    1.76 -
    1.77 -
    1.78 -    def stop(self):
    1.79 -        if self.proc:
    1.80 -            self.log.info ("STOPED GMencoder plugin")
    1.81 -            try:
    1.82 -                self.proc.stdin.write ("QUIT\n")
    1.83 -            except Exception, e:
    1.84 -                pass
    1.85 -
    1.86 -            try:
    1.87 -                self.proc.wait()
    1.88 -            except Exception, e:
    1.89 -                pass
    1.90 -
    1.91 -            self.proc = None
    1.92 -    # stop()
    1.93 -
    1.94 -# TranscoderGMencoder