[svn r573] New function to get the information about the program info path directiory.
1 import lib.utils as utils
2 import lib.server as server
7 __all__ = ("TranscoderMencoder",)
9 class TranscoderMencoder(server.Transcoder):
10 mencoder_path = utils.which("mencoder")
11 def_mencoder_outfile = os.path.join(os.path.sep, "tmp",
12 "mencoder-fifo-%(uid)s-%(pid)s")
16 def __init__(self, params):
17 server.Transcoder.__init__(self, params)
21 vars = {"uid": os.getuid(), "pid": os.getpid()}
22 mencoder_outfile_base = self.def_mencoder_outfile % vars
23 mencoder_outfile = mencoder_outfile_base
25 while os.path.exists(mencoder_outfile):
27 mencoder_outfile = mencoder_outfile_base + ".%s" % i
29 self.mencoder_outfile = mencoder_outfile
30 os.mkfifo(self.mencoder_outfile)
32 args = [self.mencoder_path, "-really-quiet",
33 "-o", self.mencoder_outfile]
35 params_first = self.params_first
37 type = params_first("type")
38 location = params_first("location")
39 args.append("%s://%s" % (type, location))
41 mux = params_first("mux", "avi")
42 args.extend(["-of", mux])
44 acodec = params_first("acodec", "mp3")
45 abitrate = params_first("abitrate", "128")
46 if acodec == "mp3lame":
47 args.extend(["-oac", "mp3lame", "-lameopts",
48 "cbr:br=%s" % abitrate])
50 args.extend(["-oac", "lavc", "-lavcopts",
51 "acodec=%s:abitrate=%s" % (acodec, abitrate)])
53 vcodec = params_first("vcodec", "mpeg4")
54 vbitrate = params_first("vbitrate", "400")
55 args.extend(["-ovc", "lavc", "-lavcopts",
56 "vcodec=%s:vbitrate=%s" % (vcodec, vbitrate)])
58 fps = params_first("fps", "24")
59 args.extend(["-ofps", fps])
61 width = params_first("width", "320")
62 height = params_first("height", "240")
63 args.extend(["-vf", "scale=%s:%s" % (width, height)])
69 def _unlink_fifo(self):
71 os.unlink(self.mencoder_outfile)
77 def start(self, outfd):
78 cmd = " ".join(self.args)
79 self.log.info("Mencoder: %s" % cmd)
82 self.proc = subprocess.Popen(self.args, close_fds=True)
84 self.log.error("Error executing mencoder: %s" % cmd)
88 fifo_read = open(self.mencoder_outfile)
90 self.log.error("Error opening fifo: %s" % cmd)
94 while self.proc and self.proc.poll() == None:
95 d = fifo_read.read(1024)
98 self.log.error("Problems handling data: %s" % e)
110 os.kill(self.proc.pid, signal.SIGTERM)