diff -r 000000000000 -r f4c6061f6f39 gmyth-stream/plugins/media/ffmpeg.py --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gmyth-stream/plugins/media/ffmpeg.py Wed Mar 28 21:26:42 2007 +0100 @@ -0,0 +1,72 @@ +import os +import sys +import time +import socket +import ConfigParser + +class Media: + + def __init__(self, config): + + self.config = config + + 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) + + self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM) + self.socket.bind( ('', self.port) ) + + def play(self): + + self.socket.listen(1) + + print "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() + print "--> Sending Data..." + data = child_stdout.read(1024) + + while( data != ""): + try: + conn.send(data) + except socket.error: + break + data = child_stdout.read(1024) + + print "--> Finished sending data..." + conn.close() + + + def stop(self): + + print "--> Trying to stop FFmpeg process..." + self.socket.close() + os.kill(self.child_pid, 9) + +