1.1 --- a/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 18:05:44 2007 +0100
1.2 +++ b/gmyth-stream/server/plugins/media/mencoder.py Wed Apr 04 21:36:07 2007 +0100
1.3 @@ -46,17 +46,17 @@
1.4 self.kind = "file"
1.5 self.args += " %s -mf fps=%s -of %s %s"\
1.6 " -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -vf scale=%s:%s"\
1.7 - " -o %s 1> /dev/null 2> /dev/null" % (
1.8 + " -really-quiet -o %s" % (
1.9 self.filename, self.fps, self.mux, audio, self.vcodec,
1.10 self.vbitrate, self.width, self.height, self.fifo)
1.11
1.12 elif opt == "dvd":
1.13 self.kind = "dvd"
1.14 self.args += " dvd://%s -alang %s -vf scale=%s:%s %s"\
1.15 - " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s -o %s"\
1.16 - " -ofps %s 1> /dev/null 2> /dev/null" % (
1.17 + " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%s"\
1.18 + " -ofps %s -really-quiet -o %s" % (
1.19 self.filename, self.language, self.width, self.height, audio,
1.20 - self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps)
1.21 + self.mux, self.vcodec, self.vbitrate, self.fps, self.fifo)
1.22
1.23 elif opt == "local":
1.24 self.mplayer = os.popen("which mplayer").read().strip()
1.25 @@ -97,7 +97,21 @@
1.26 self.height = height
1.27
1.28 self.port = int(port)
1.29 - self.fifo = self.config.get("Mencoder", "fifo_path")
1.30 +
1.31 + self.path = self.config.get("Mencoder", "path")
1.32 + a, b = os.popen2(self.path)
1.33 + version = b.read().split("MEncoder ")[1].split(" (C)")[0].split("-")[-1]
1.34 +
1.35 + if version > "4.1.1": self.mencoder_old = False
1.36 + else: self.mencoder_old = True
1.37 +
1.38 + a.close()
1.39 + b.close()
1.40 +
1.41 + if self.mencoder_old:
1.42 + self.fifo = self.config.get("Mencoder", "fifo_path")
1.43 + else:
1.44 + self.fifo = "-"
1.45
1.46 self.args = ""
1.47 self.kind = ""
1.48 @@ -110,8 +124,6 @@
1.49
1.50 # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000 file
1.51 #4 mpeg mpeg1video 400 25 mp3lame 192 400 240 5000 language=en local dvd
1.52 - self.path = self.config.get("Mencoder", "path")
1.53 -
1.54 if self.socket != None:
1.55 del(self.socket)
1.56
1.57 @@ -125,16 +137,21 @@
1.58
1.59 def play(self):
1.60
1.61 - try:
1.62 - os.mkfifo(self.fifo)
1.63 - except:
1.64 - lib.log("Fifo already exists")
1.65 + if self.mencoder_old:
1.66 + try:
1.67 + os.mkfifo(self.fifo)
1.68 + except:
1.69 + lib.log("Fifo already exists")
1.70 +
1.71
1.72 lib.log("Starting Mencoder: %s %s" % (self.path, self.args) )
1.73 # exec Mencoder
1.74 - self.mencoder_pid = Popen(self.path + self.args, shell=True)
1.75 -
1.76 - fifo = open(self.fifo)
1.77 + if self.mencoder_old:
1.78 + self.mencoder_pid = Popen(self.path + self.args, shell=True)
1.79 + fifo = open(self.fifo)
1.80 + else:
1.81 + self.path += self.args
1.82 + pin, self.pout = os.popen2(self.path)
1.83
1.84 self.child_pid = os.fork()
1.85
1.86 @@ -142,7 +159,8 @@
1.87 conn,addr= self.socket.accept()
1.88 lib.log("Sending Data to client: %s" % addr[0])
1.89
1.90 - data = fifo.read(1024)
1.91 + data = self.pout.read(1024)
1.92 +
1.93 conn.settimeout(5)
1.94 retry = 0
1.95
1.96 @@ -159,7 +177,7 @@
1.97 lib.log("Socket error (maybe timeout ?)")
1.98 retry += 1
1.99
1.100 - data = fifo.read(1024)
1.101 + data = self.pout.read(1024)
1.102
1.103 if retry < 5:
1.104 lib.log("Finished sending Data to client: %s" % addr[0])
1.105 @@ -171,7 +189,10 @@
1.106
1.107 def stop(self):
1.108 try:
1.109 - os.kill(self.mencoder_pid.pid + 1, signal.SIGKILL)
1.110 + if self.mplayer_old:
1.111 + os.kill(self.mencoder_pid.pid + 1, signal.SIGKILL)
1.112 + else:
1.113 + self.pout.close()
1.114 self.mplayer = None
1.115 except:
1.116 lib.log("Trying to stop before playing...")