10 def __init__(self, config):
17 def set_args(self, options):
23 self.args += " %s -mf fps=%d -of %s -oac %s -lameopts vol=5 cbr:br=%d"\
24 " -ovc lavc -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
25 " -o %s 1> /dev/null 2> /dev/null" % (
26 self.filename, self.fps, self.mux, self.acodec, self.abitrate,
27 self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
31 self.args += " dvd://%s -vf scale=%d:%d -oac %s -lameopts vol=5 cbr:br=%d"\
32 " -of %s -ovc lavc -lavcopts vcodec=%s:vbitrate=%d -o %s"\
33 " -mf fps=%d 1> /dev/null 2> /dev/null" % (
34 self.filename, self.width, self.height, self.acodec, self.abitrate,
35 self.mux, self.vcodec, self.vbitrate, self.fifo, self.fps)
37 elif (opt == "local"):
38 self.mplayer = os.popen("which mplayer").read().strip()
40 def setup(self, filename, mux, vcodec, vbitrate,\
41 fps, acodec, abitrate, width, height, port, options):
43 self.filename = filename
46 self.vbitrate = int(vbitrate)
49 self.abitrate = int(abitrate)
50 self.width = int(width)
51 self.height = int(height)
54 self.fifo = self.config.get("Mencoder", "fifo_path")
58 self.set_args(options)
60 if (self.kind == "file" and not os.path.exists(self.filename)):
61 msg = "File requested does not exist. SETUP failed."
65 # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
66 #mencoder dvd://2 -vf scale=640:480 -o title2.avi -oac copy -ovc lavc -lavcopts vcodec=mpeg4
67 self.path = self.config.get("Mencoder", "path")
68 self.path += self.args
70 if (self.socket != None):
73 self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
74 self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
75 self.socket.bind( ('', self.port) )
86 lib.log("Fifo already exists")
88 lib.log("Starting Mencoder: %s" % self.path )
90 pin, self.pout = os.popen2(self.path)
93 fifo = open(self.fifo)
95 self.child_pid = os.fork()
97 if (self.child_pid == 0):
98 conn,addr= self.socket.accept()
99 lib.log("Sending Data to client: %s" % addr[0])
101 data = fifo.read(1024)
106 msg = "%s 1>/dev/null 2>/dev/null" % self.filename
107 if (self.kind == "dvd"):
110 self.mplayer += " " + msg
111 mplayer_in, self.mplayer_out = os.popen2(self.mplayer)
113 while( data != "" and retry < 5):
117 lib.log("Socket error (maybe timeout ?)")
120 data = fifo.read(1024)
123 lib.log("Finished sending Data to client: %s" % addr[0])
125 lib.log("Client timed out")
131 self.mplayer_out.close()
133 lib.log("Trying to stop before playing...")
137 if (self.socket != None):
138 lib.log("Closing socket")
141 lib.log("Trying to stop Mencoder process")
142 if (self.child_pid != None):
143 os.kill(self.child_pid, 9)