3 __author__ = "Renato Filho"
4 __author_email__ = "renato.filho@indt.org.br"
16 import lib.utils as utils
17 import lib.server as server
18 import lib.transcoder as transcoder
20 __all__ = ("TranscoderGMencoder",)
22 class TranscoderGMencoder(transcoder.Transcoder):
23 gmencoder_path = utils.which("gmencoder")
28 def __init__(self, params):
29 transcoder.Transcoder.__init__(self, params)
33 def _insert_param (self, name, value):
35 self.opts.append(name)
36 self.opts.append(value)
38 def _parser_params (self):
39 self._insert_param("-i", \
40 "%s://%s" % (self.params_first("type", "file"),
41 self.params_first("uri", "")))
42 self._insert_param("--video-encode", self.params_first("ve", ""))
43 self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
44 self._insert_param("--video-fps", self.params_first("fps", ""))
45 self._insert_param("--video-width", self.params_first("width", "320"))
46 self._insert_param("--video-height", self.params_first("height", "240"))
47 self._insert_param("--audio-rate", "32000")
48 self._insert_param("--audio-encode", self.params_first("ae", ""))
51 def start(self, outfd):
52 self.opts.append (self.gmencoder_path)
53 self._parser_params ()
54 self._insert_param ("-o", "fd://%d" % outfd.fileno())
56 cmd = " ".join(self.opts)
57 self.log.info(self.tid, "GMencoder: %s" % cmd)
60 self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE,
61 stdout=subprocess.PIPE)
63 self.log.error(self.tid, "Error executing GMencoder: %s" % e)
67 while (self.proc and self.proc.poll() == None):
68 r, w, x = select.select([self.proc.stdout], [], [], 0)
69 if self.proc.stdout in r:
70 progress = self.proc.stdout.readline()
71 self.log.debug(self.tid, "stdout %s" % progress)
72 if (progress.find ("PROGRESS") >= 0):
73 self.status = progress.split (":")[1]
75 self.log.error(self.tid, "Problems handling data: %s" % e)
84 self.log.info(self.tid, "Stopped GMencoder plugin")
86 self.proc.stdin.write("QUIT\n")
87 os.kill(self.proc.pid, signal.SIGKILL)