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):
31 transcoder.Transcoder.__init__(self, params)
33 self.opts.append (self.gmencoder_path)
34 self.opts.append ("-d")
35 self._parser_params ()
37 outfile = self.params_first("outfile", "")
40 path = os.path.join(sys.path[0], ".transcoded", outfile)
41 self._insert_param("-o", "file://%s" % path)
43 self._insert_param ("-o", "fd://%d" % outfd.fileno())
44 self.opts.append ("-c")
46 cmd = " ".join(self.opts)
50 def _insert_param (self, name, value):
52 self.opts.append(name)
53 self.opts.append(value)
55 def _parser_params (self):
56 self._insert_param("-i", \
57 "%s://%s" % (self.params_first("type", "file"),
58 self.params_first("uri", "")))
59 self._insert_param("--video-encode", self.params_first("ve", "ffenc_mpeg1video"))
60 self._insert_param("--video-opts", "bitrate=600000,pass=512,quantizer=0.05,quant-type=1")
61 self._insert_param("--video-fps", self.params_first("fps", ""))
62 self._insert_param("--video-width", self.params_first("width", "320"))
63 self._insert_param("--video-height", self.params_first("height", "240"))
64 self._insert_param("--audio-rate", "32000")
65 self._insert_param("--audio-encode", self.params_first("ae", ""))
68 def start(self, outfd):
69 self.log.info(self.tid, "GMencoder: %s" % cmd)
72 self.proc = subprocess.Popen(self.opts, stdin=subprocess.PIPE,
73 stdout=subprocess.PIPE)
75 self.log.error(self.tid, "Error: executing GMencoder: %s" % e)
76 outfd.write("Error: GMencoder: %s" % e)
80 while (self.proc and self.proc.poll() == None):
81 r, w, x = select.select([self.proc.stdout], [], [], 0)
82 if self.proc.stdout in r:
83 progress = self.proc.stdout.readline()
84 if (progress.find ("PROGRESS") >= 0):
85 self.status = progress.split (":")[1]
87 self.log.error(self.tid, "Problems handling data: %s" % e)
97 self.log.info(self.tid, "Stopped GMencoder plugin")
99 os.kill(self.proc.pid, signal.SIGKILL)
107 def get_progress(self):
110 def get_lenght(self):
113 # TranscoderGMencoder