diff -r 0a4e6b811acc -r 0e159c5e2d32 gmyth-stream/server/0.1/plugins/media/ffmpeg.py --- a/gmyth-stream/server/0.1/plugins/media/ffmpeg.py Tue Aug 28 15:41:35 2007 +0100 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,91 +0,0 @@ -import os -import sys -import lib -import time -import socket -import ConfigParser - -class Media: - - def __init__(self, config): - - self.config = config - self.socket = None - self.child_pid = None - - def setup(self, filename, mux, vcodec, vbitrate,\ - fps, acodec, abitrate, width, height, port): - - self.filename = filename - self.mux = mux - self.vcodec = vcodec - self.vbitrate = int(vbitrate) - self.fps = int(fps) - self.acodec = acodec - self.abitrate = int(abitrate) - self.width = int(width) - self.height = int(height) - - self.port = int(port) - - # good one: /tmp/mpg/cpm.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000 - self.path = self.config.get("FFmpeg", "path") - self.path += " -i %s -f %s -vcodec %s -b %d -r %d -acodec %s -ab %d -s %dx%d -" % ( - self.filename, self.mux, self.vcodec, self.vbitrate,\ - self.fps, self.acodec, self.abitrate, self.width, self.height) - - if (self.socket != None): - del(self.socket) - - self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) - self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1) - self.socket.bind( ('', self.port) ) - self.socket.settimeout(10) - self.socket.listen(1) - - def play(self): - - lib.log("Starting FFmpeg: %s" % self.path) - - # exec FFmpeg and get stdout - child_stdin, child_stdout = os.popen2(self.path) - child_stdin.close() - - self.child_pid = os.fork() - if (self.child_pid == 0): - #child - - conn,addr= self.socket.accept() - lib.log("Sending Data to client: %s" % addr[0]) - data = child_stdout.read(1024) - conn.settimeout(5) - retry = 0 - - while( data != "" and retry < 5): - try: - conn.send(data) - except socket.error: - lib.log("Socket error (maybe timeout ?)") - retry = retry + 1 - - data = child_stdout.read(1024) - - if (retry < 5): - lib.log("Finished sending Data to client: %s" % addr[0]) - else: - lib.log("Client timed out") - - child_stdout.close() - #conn.close() - #sys.exit() - - - def stop(self): - - if (self.socket != None): - lib.log("Closing socket") - self.socket.close() - - lib.log("Trying to stop FFmpeg process") - if (self.child_pid != None): - os.kill(self.child_pid, 9)