10 def __init__(self, config):
16 def setup(self, filename, mux, vcodec, vbitrate,\
17 fps, acodec, abitrate, width, height, port):
19 self.filename = filename
22 self.vbitrate = int(vbitrate)
25 self.abitrate = int(abitrate)
26 self.width = int(width)
27 self.height = int(height)
30 self.fifo = self.config.get("Mencoder", "fifo_path")
35 lib.log("Fifo already exists")
37 # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
38 self.path = self.config.get("Mencoder", "path")
39 self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
40 " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
41 " -o %s 1> /dev/null 2> /dev/null" % (
42 self.filename, self.fps, self.mux, self.acodec, self.abitrate,
43 self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
46 if (self.socket != None):
49 self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
50 self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
51 self.socket.bind( ('', self.port) )
52 self.socket.settimeout(10)
57 lib.log("Starting Mencoder: %s" % self.path )
59 pin, pout = os.popen2(self.path)
62 fifo = open(self.fifo)
64 self.child_pid = os.fork()
65 if (self.child_pid == 0):
66 conn,addr= self.socket.accept()
67 lib.log("Sending Data to client: %s" % addr[0])
69 data = fifo.read(4096)
73 while( data != "" and retry < 5):
77 lib.log("Socket error (maybe timeout ?)")
80 data = fifo.read(4096)
83 lib.log("Finished sending Data to client: %s" % addr[0])
85 lib.log("Client timed out")
91 if (self.socket != None):
92 lib.log("Closing socket")
95 lib.log("Trying to stop Mencoder process")
96 if (self.child_pid != None):
97 os.kill(self.child_pid, 9)