10 def __init__(self, config):
16 def setup(self, filename, mux, vcodec, vbitrate,\
17 fps, acodec, abitrate, width, height, port):
19 if (os.path.exists(filename)):
21 self.filename = filename
24 self.vbitrate = int(vbitrate)
27 self.abitrate = int(abitrate)
28 self.width = int(width)
29 self.height = int(height)
32 self.fifo = self.config.get("Mencoder", "fifo_path")
34 # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
35 self.path = self.config.get("Mencoder", "path")
36 self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
37 " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
38 " -o %s 1> /dev/null 2> /dev/null" % (
39 self.filename, self.fps, self.mux, self.acodec, self.abitrate,
40 self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
43 if (self.socket != None):
46 self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
47 self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
48 self.socket.bind( ('', self.port) )
54 lib.log("File requested does not exist. SETUP failed.")
62 lib.log("Fifo already exists")
64 lib.log("Starting Mencoder: %s" % self.path )
66 pin, self.pout = os.popen2(self.path)
69 fifo = open(self.fifo)
71 self.child_pid = os.fork()
72 if (self.child_pid == 0):
73 conn,addr= self.socket.accept()
74 lib.log("Sending Data to client: %s" % addr[0])
76 data = fifo.read(1024)
80 while( data != "" and retry < 5):
84 lib.log("Socket error (maybe timeout ?)")
87 data = fifo.read(1024)
90 lib.log("Finished sending Data to client: %s" % addr[0])
92 lib.log("Client timed out")
99 if (self.socket != None):
100 lib.log("Closing socket")
103 lib.log("Trying to stop Mencoder process")
104 if (self.child_pid != None):
105 os.kill(self.child_pid, 9)