diff -r 9900800a8dd6 -r 4fcd764b21a6 gmyth-stream/server/plugins/media/mencoder.py --- a/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 21:18:43 2007 +0100 +++ b/gmyth-stream/server/plugins/media/mencoder.py Thu Apr 05 15:26:33 2007 +0100 @@ -14,6 +14,7 @@ def __init__(self, config): self.config = config + self.args = "" self.language = "en" self.socket = None self.child_pid = None @@ -33,32 +34,7 @@ for opt in options: - if opt == "file" or opt == "dvd": - - if self.acodec == "mp3lame": - audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate - else: - audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\ - self.acodec, self.abitrate) - - - if opt == "file": - self.kind = "file" - self.args += " %s -mf fps=%s -of %s %s"\ - " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\ - " -really-quiet -o %s" % ( - self.filename, self.fps, self.mux, audio, self.vcodec, - self.vbitrate, self.width, self.height, self.fifo) - - elif opt == "dvd": - self.kind = "dvd" - self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\ - " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\ - " -ofps %s -really-quiet -o %s" % ( - self.filename, self.language, self.width, self.height, audio, - self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo) - - elif opt == "local": + if opt == "local": self.mplayer = os.popen("which mplayer").read().strip() elif opt.find("language=") >= 0: @@ -83,21 +59,7 @@ self.mplayer += " " + msg self.mplayer_pid = Popen(self.mplayer, shell=True) - def setup(self, filename, mux, vcodec, vbitrate,\ - fps, acodec, abitrate, width, height, port, options): - - self.filename = filename - self.mux = mux - self.vcodec = vcodec - self.vbitrate = vbitrate - self.fps = fps - self.acodec = acodec - self.abitrate = abitrate - self.width = width - self.height = height - - self.port = int(port) - + def setup_mencoder(self): self.path = self.config.get("Mencoder", "path") a, b = os.popen2(self.path) version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1] @@ -105,6 +67,8 @@ if version > "4.1.1": self.mencoder_old = False else: self.mencoder_old = True + lib.log("Mencoder version: %s" % version) + a.close() b.close() @@ -113,16 +77,74 @@ else: self.fifo = "-" - self.args = "" - self.kind = "" + def setup_filename(self, filename): + try: + self.kind, self.filename = filename.split("://") + except: + return (False, "Wrong filename protocol") + + if self.acodec == "mp3lame": + audio = "-oac mp3lame -lameopts cbr:br=%s vol=5" % self.abitrate + else: + audio = "-oac lavc -lavcopts acodec=%s:abitrate=%s" % (\ + self.acodec, self.abitrate) + + if self.kind == "file": + if not os.path.exists(self.filename): + msg = "File requested does not exist. SETUP failed." + lib.log(msg) + return (False, msg) + + self.args += " %s -mf fps=%s -of %s %s"\ + " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\ + " -really-quiet -o %s 2>/dev/null" % ( + self.filename, self.fps, self.mux, audio, self.vcodec, + self.vbitrate, self.width, self.height, self.fifo) + + elif self.kind == "dvd": + self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\ + " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\ + " -ofps %s -really-quiet -o %s 2>/dev/null" % ( + self.filename, self.language, self.width, self.height, audio, + self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo) + + return (True, "") + + ''' + MENCODER SETUP DESCRIPTION + =========================== + + -> mux, vcodecs and acodecs + |-> mencoder (-of | -ovc | -oac) help + + -> if used mpeg as mux: + |-> to setup format: format=%s as an option at the end + + ''' + + def setup(self, filename, mux, vcodec, vbitrate,\ + fps, acodec, abitrate, width, height, port, options): + + self.mux = mux + self.vcodec = vcodec + self.vbitrate = vbitrate + self.fps = fps + self.acodec = acodec + self.abitrate = abitrate + self.width = width + self.height = height + self.port = int(port) + + self.setup_mencoder() + ret_val = self.setup_filename(filename) + + if not ret_val[0]: + return ret_val[1] + self.set_args(options) - if self.kind == "file" and not os.path.exists(self.filename): - msg = "File requested does not exist. SETUP failed." - lib.log(msg) - return msg - # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file + # /tmp/dvb.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000 format=mpeg1 file #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd if self.socket != None: del(self.socket) @@ -148,7 +170,7 @@ # exec Mencoder if self.mencoder_old: self.mencoder_pid = Popen(self.path + self.args, shell=True) - fifo = open(self.fifo) + self.pout = open(self.fifo) else: self.path += self.args pin, self.pout = os.popen2(self.path)