diff -r 07c12d2ceddf -r 88bf59e8da5f gmyth-stream/plugins/media/mencoder.py --- a/gmyth-stream/plugins/media/mencoder.py Sat Mar 31 00:55:28 2007 +0100 +++ b/gmyth-stream/plugins/media/mencoder.py Mon Apr 02 16:57:57 2007 +0100 @@ -12,47 +12,71 @@ self.config = config self.socket = None self.child_pid = None + self.mplayer = None + + def set_args(self, options): + + for opt in options: + + if (opt == "file"): + self.kind = "file" + self.args += " %s -mf fps=%d -of %s -oac %s -lameopts vol=5 cbr:br=%d"\ + " -ovc lavc -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\ + " -o %s 1> /dev/null 2> /dev/null" % ( + self.filename, self.fps, self.mux, self.acodec, self.abitrate, + self.vcodec, self.vbitrate, self.width, self.height, self.fifo) + + elif (opt == "dvd"): + self.kind = "dvd" + self.args += " dvd://%s -vf scale=%d:%d -oac %s -lameopts vol=5 cbr:br=%d"\ + " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%d -o %s"\ + " -mf fps=%d 1> /dev/null 2> /dev/null" % ( + self.filename, self.width, self.height, self.acodec, self.abitrate, + self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps) + + elif (opt == "local"): + self.mplayer = os.popen("which mplayer").read().strip() def setup(self, filename, mux, vcodec, vbitrate,\ - fps, acodec, abitrate, width, height, port): + fps, acodec, abitrate, width, height, port, options): - if (os.path.exists(filename)): + self.filename = filename + self.mux = mux + self.vcodec = vcodec + self.vbitrate = int(vbitrate) + self.fps = int(fps) + self.acodec = acodec + self.abitrate = int(abitrate) + self.width = int(width) + self.height = int(height) - self.filename = filename - self.mux = mux - self.vcodec = vcodec - self.vbitrate = int(vbitrate) - self.fps = int(fps) - self.acodec = acodec - self.abitrate = int(abitrate) - self.width = int(width) - self.height = int(height) + self.port = int(port) + self.fifo = self.config.get("Mencoder", "fifo_path") - self.port = int(port) - self.fifo = self.config.get("Mencoder", "fifo_path") + self.args = "" + self.kind = "" + self.set_args(options) - # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 - self.path = self.config.get("Mencoder", "path") - self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\ - " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\ - " -o %s 1> /dev/null 2> /dev/null" % ( - self.filename, self.fps, self.mux, self.acodec, self.abitrate, - self.vcodec, self.vbitrate, self.width, self.height, self.fifo) + 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 + #mencoder dvd://2 -vf scale=640:480 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4 + self.path = self.config.get("Mencoder", "path") + self.path += self.args - if (self.socket != None): - del(self.socket) + if (self.socket != None): + del(self.socket) - self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) - self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.socket.bind( ('', self.port) ) - self.socket.listen(1) + self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) + self.socket.bind( ('', self.port) ) + self.socket.listen(1) - return 0 + return 0 - else: - lib.log("File requested does not exist. SETUP failed.") - return -1 def play(self): @@ -69,6 +93,7 @@ fifo = open(self.fifo) self.child_pid = os.fork() + if (self.child_pid == 0): conn,addr= self.socket.accept() lib.log("Sending Data to client: %s" % addr[0]) @@ -77,6 +102,14 @@ conn.settimeout(5) retry = 0 + if (self.mplayer): + msg = "%s 1>/dev/null 2>/dev/null" % self.filename + if (self.kind == "dvd"): + msg = "dvd://" + msg + + self.mplayer += " " + msg + mplayer_in, self.mplayer_out = os.popen2(self.mplayer) + while( data != "" and retry < 5): try: conn.send(data) @@ -93,8 +126,13 @@ def stop(self): + try: + self.pout.close() + self.mplayer_out.close() + except: + lib.log("Trying to stop before playing...") - self.pout.close() + self.mplayer = None if (self.socket != None): lib.log("Closing socket")