# HG changeset patch # User renatofilho # Date 1177358887 -3600 # Node ID 549c4664701e8f6f8500f6931aa70269a08e898d # Parent 3219eb5401c0d0c095f812b2dd72301d59caa617 [svn r595] created new plugin diff -r 3219eb5401c0 -r 549c4664701e gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/server/0.2/plugins/transcoders/gmencoder.py Mon Apr 23 21:08:07 2007 +0100 @@ -0,0 +1,82 @@ +import os +import shlex +import signal +import subprocess + +import lib.utils as utils +import lib.server as server + +__all__ = ("TranscoderGMencoder",) + +class TranscoderGMencoder(server.Transcoder): + gmencoder_path = utils.which("gmencoder") + name = "gmencoder" + priority = -1 + proc = None + args = {} + + def __init__(self, params): + server.Transcoder.__init__(self, params) + self.opts = [] + # __init__() + + def _insert_param (self, name, value): + if (value != ""): + self.opts.append(name) + self.opts.append(value) + + def _parser_params (self): + self._insert_param("-i", \ + "%s://%s" % (self.params_first("uri_prefix", "file"), self.params_first("uri_path", ""))) + self._insert_param("--video-encode", self.params_first("ve", "")) + self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5") + self._insert_param("--video-fps", self.params_first("fps", "")) + self._insert_param("--video-width", self.params_first("width", "")) + self._insert_param("--video-height", self.params_first("height", "")) + self._insert_param("--audio-encode", self.params_first("ae", "")) + self._insert_param("--output-element", "fdsink") + # _parse_params + + def start(self, outfd): + self.opts.append (self.gmencoder_path) + self._parser_params () + self.opts.append ("--output-opts") + self.opts.append ("fd=%d" % outfd.fileno()) + + cmd = " ".join(self.opts) + self.log.info ("Gmemconder: %s", cmd) + + try: + self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE) + except Exception, e: + self.log.error("Error executing gmencoder: %s" % e) + return False + + try: + self.proc.wait() + + except Exception, e: + self.log.error("Problems handling data: %s" % e) + return False + + return True + # start() + + + def stop(self): + if self.proc: + self.log.info ("STOP") + try: + self.proc.stdin.write ("QUIT\n") + except Exception, e: + pass + + try: + self.proc.wait() + except Exception, e: + pass + + self.proc = None + # stop() + +# TranscoderGMencoder