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"), self.params_first("uri", "")))
41 self._insert_param("--video-encode", self.params_first("ve", ""))
42 self._insert_param("--video-opts", "bitrate=200,pass=2,quantizer=5")
43 self._insert_param("--video-fps", self.params_first("fps", ""))
44 self._insert_param("--video-width", self.params_first("width", ""))
45 self._insert_param("--video-height", self.params_first("height", ""))
46 self._insert_param("--audio-rate", "32000")
47 self._insert_param("--audio-encode", self.params_first("ae", ""))
50 def start(self, outfd):
51 self.opts.append (self.gmencoder_path)
52 self._parser_params ()
53 self._insert_param ("-o", "fd://%d" % outfd.fileno())
55 cmd = " ".join(self.opts)
56 self.log.info ("GMencoder: %s", cmd)
59 self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE, stdout=subprocess.PIPE)
61 self.log.error(self.tid, "Error executing GMencoder: %s" % e)
65 while (self.proc and self.proc.poll() == None):
66 r, w, x = select.select([self.proc.stdout], [], [], 0)
67 if self.proc.stdout in r:
68 progress = self.proc.stdout.readline()
69 self.log.info ("stdout %s" % progress)
70 if (progress.find ("PROGRESS") >= 0):
71 self.status = progress.split (":")[1]
72 #if (progress.find ("DONE") >= 0):
74 self.log.info ("Process exit")
76 self.log.error(self.tid, "Problems handling data: %s" % e)
85 self.log.info ("STOPED GMencoder plugin")
87 self.proc.stdin.write ("QUIT\n")