gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py
branchtrunk
changeset 594 f36075170a4e
child 595 5c5cff842d57
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py	Wed Apr 25 15:50:41 2007 +0100
     1.3 @@ -0,0 +1,82 @@
     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 +
    1.12 +__all__ = ("TranscoderGMencoder",)
    1.13 +
    1.14 +class TranscoderGMencoder(server.Transcoder):
    1.15 +    gmencoder_path = utils.which("gmencoder")
    1.16 +    name = "gmencoder"
    1.17 +    priority = -1
    1.18 +    proc = None
    1.19 +    args = {}
    1.20 +
    1.21 +    def __init__(self, params):
    1.22 +        server.Transcoder.__init__(self, params)
    1.23 +        self.opts = []
    1.24 +    # __init__()
    1.25 +
    1.26 +    def _insert_param (self, name, value):
    1.27 +        if (value != ""):
    1.28 +            self.opts.append(name)
    1.29 +            self.opts.append(value)
    1.30 +
    1.31 +    def _parser_params (self):
    1.32 +        self._insert_param("-i", \
    1.33 +            "%s://%s" % (self.params_first("uri_prefix", "file"), self.params_first("uri_path", "")))
    1.34 +        self._insert_param("--video-encode", self.params_first("ve", ""))
    1.35 +        self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
    1.36 +        self._insert_param("--video-fps", self.params_first("fps", ""))
    1.37 +        self._insert_param("--video-width", self.params_first("width", ""))
    1.38 +        self._insert_param("--video-height", self.params_first("height", ""))
    1.39 +        self._insert_param("--audio-encode", self.params_first("ae", ""))
    1.40 +        self._insert_param("--output-element", "fdsink")
    1.41 +    # _parse_params 
    1.42 +    
    1.43 +    def start(self, outfd):
    1.44 +        self.opts.append (self.gmencoder_path)
    1.45 +        self._parser_params ()
    1.46 +        self.opts.append ("--output-opts")
    1.47 +        self.opts.append ("fd=%d" % outfd.fileno())
    1.48 +
    1.49 +        cmd = " ".join(self.opts)
    1.50 +        self.log.info ("Gmemconder: %s", cmd)
    1.51 +
    1.52 +        try:
    1.53 +            self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE)
    1.54 +        except Exception, e:
    1.55 +            self.log.error("Error executing gmencoder: %s" % e)
    1.56 +            return False
    1.57 +
    1.58 +        try:
    1.59 +             self.proc.wait()
    1.60 +            
    1.61 +        except Exception, e:
    1.62 +            self.log.error("Problems handling data: %s" % e)
    1.63 +            return False
    1.64 +
    1.65 +        return True
    1.66 +    # start()
    1.67 +
    1.68 +
    1.69 +    def stop(self):
    1.70 +        if self.proc:
    1.71 +            self.log.info ("STOP")
    1.72 +            try:
    1.73 +                self.proc.stdin.write ("QUIT\n")
    1.74 +            except Exception, e:
    1.75 +                pass
    1.76 +
    1.77 +            try:
    1.78 +                self.proc.wait()
    1.79 +            except Exception, e:
    1.80 +                pass
    1.81 +
    1.82 +            self.proc = None
    1.83 +    # stop()
    1.84 +
    1.85 +# TranscoderGMencoder