9 def __init__(self, config):
13 def setup(self, filename, mux, vcodec, vbitrate,\
14 fps, acodec, abitrate, width, height, port):
16 self.filename = filename
19 self.vbitrate = int(vbitrate)
22 self.abitrate = int(abitrate)
23 self.width = int(width)
24 self.height = int(height)
28 # good one: /tmp/mpg/cpm.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000
29 self.path = self.config.get("FFmpeg", "path")
30 self.path += " -i %s -f %s -vcodec %s -b %d -r %d -acodec %s -ab %d -s %dx%d -" % (
31 self.filename, self.mux, self.vcodec, self.vbitrate,\
32 self.fps, self.acodec, self.abitrate, self.width, self.height)
34 self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
35 self.socket.bind( ('', self.port) )
41 print "Starting FFmpeg: %s" % self.path
43 # exec FFmpeg and get stdout
44 child_stdin, child_stdout = os.popen2(self.path)
47 self.child_pid = os.fork()
48 if (self.child_pid == 0):
51 conn,addr= self.socket.accept()
52 print "--> Sending Data..."
53 data = child_stdout.read(1024)
60 data = child_stdout.read(1024)
62 print "--> Finished sending data..."
68 print "--> Trying to stop FFmpeg process..."
70 os.kill(self.child_pid, 9)