3 __author__ = "Renato Filho"
4 __author_email__ = "renato.filho@indt.org.br"
17 import lib.utils as utils
18 import lib.server as server
19 import lib.transcoder as transcoder
21 __all__ = ("TranscoderGMencoder",)
23 class TranscoderGMencoder(transcoder.Transcoder):
24 gmencoder_path = utils.which("gmencoder")
29 def __init__(self, params):
30 transcoder.Transcoder.__init__(self, params)
34 def _insert_param (self, name, value):
36 self.opts.append(name)
37 self.opts.append(value)
39 def _parser_params (self):
40 self._insert_param("-i", \
41 "%s://%s" % (self.params_first("type", "file"),
42 self.params_first("uri", "")))
43 self._insert_param("--video-encode", self.params_first("ve", "ffenc_mpeg1video"))
44 self._insert_param("--video-opts", "bitrate=600000,pass=512,quantizer=0.05,quant-type=1")
45 self._insert_param("--video-fps", self.params_first("fps", ""))
46 self._insert_param("--video-width", self.params_first("width", "320"))
47 self._insert_param("--video-height", self.params_first("height", "240"))
48 self._insert_param("--audio-rate", "32000")
49 self._insert_param("--audio-encode", self.params_first("ae", ""))
52 def start(self, outfd):
54 self.opts.append (self.gmencoder_path)
55 self.opts.append ("-d")
56 self._parser_params ()
58 outfile = self.params_first("outfile", "")
61 path = os.path.join(sys.path[0], ".transcoded", outfile)
62 self._insert_param("-o", "file://%s" % path)
64 self._insert_param ("-o", "fd://%d" % outfd.fileno())
65 self.opts.append ("-c")
67 cmd = " ".join(self.opts)
68 self.log.info(self.tid, "GMencoder: %s" % cmd)
71 self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE,
72 stdout=subprocess.PIPE)
74 self.log.error(self.tid, "Error: executing GMencoder: %s" % e)
75 outfd.write("Error: GMencoder: %s" % e)
82 while (self.proc and self.proc.poll() == None):
83 r, w, x = select.select([self.proc.stdout], [], [], 0)
84 if self.proc.stdout in r:
85 progress = self.proc.stdout.readline()
86 if (progress.find ("PROGRESS") >= 0):
87 self.log.info (self.tid, "%s" % progress)
88 self.status = progress.split (":")[1]
90 self.log.error(self.tid, "Problems handling data: %s" % e)
94 self.log.info(self.tid, "OK: Done")
101 self.log.info(self.tid, "Stopped GMencoder plugin")
103 self.proc.stdin.write("QUIT\n")
104 os.kill(self.proc.pid, signal.SIGKILL)
112 # TranscoderGMencoder