gmyth-stream/plugins/media/mencoder.py
branchtrunk
changeset 474 07c12d2ceddf
parent 473 b94790c04fd5
child 475 2521ec986005
     1.1 --- a/gmyth-stream/plugins/media/mencoder.py	Fri Mar 30 23:12:52 2007 +0100
     1.2 +++ b/gmyth-stream/plugins/media/mencoder.py	Sat Mar 31 00:55:28 2007 +0100
     1.3 @@ -16,46 +16,54 @@
     1.4      def setup(self, filename, mux, vcodec, vbitrate,\
     1.5                fps, acodec, abitrate, width, height, port):
     1.6  
     1.7 -        self.filename = filename
     1.8 -        self.mux = mux
     1.9 -        self.vcodec = vcodec
    1.10 -        self.vbitrate = int(vbitrate)
    1.11 -        self.fps = int(fps)
    1.12 -        self.acodec = acodec
    1.13 -        self.abitrate = int(abitrate)
    1.14 -        self.width = int(width)
    1.15 -        self.height = int(height)
    1.16 +        if (os.path.exists(filename)):
    1.17  
    1.18 -        self.port = int(port)
    1.19 -        self.fifo = self.config.get("Mencoder", "fifo_path")
    1.20 +            self.filename = filename
    1.21 +            self.mux = mux
    1.22 +            self.vcodec = vcodec
    1.23 +            self.vbitrate = int(vbitrate)
    1.24 +            self.fps = int(fps)
    1.25 +            self.acodec = acodec
    1.26 +            self.abitrate = int(abitrate)
    1.27 +            self.width = int(width)
    1.28 +            self.height = int(height)
    1.29 +
    1.30 +            self.port = int(port)
    1.31 +            self.fifo = self.config.get("Mencoder", "fifo_path")
    1.32 +
    1.33 +            # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
    1.34 +            self.path = self.config.get("Mencoder", "path")
    1.35 +            self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
    1.36 +                         " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
    1.37 +                         " -o %s 1> /dev/null 2> /dev/null" % (
    1.38 +                self.filename, self.fps, self.mux, self.acodec, self.abitrate,
    1.39 +                self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
    1.40 +
    1.41 +
    1.42 +            if (self.socket != None):
    1.43 +                del(self.socket)
    1.44 +
    1.45 +            self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    1.46 +            self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    1.47 +            self.socket.bind( ('', self.port) )
    1.48 +            self.socket.listen(1)
    1.49 +
    1.50 +            return 0
    1.51 +
    1.52 +        else:
    1.53 +            lib.log("File requested does not exist. SETUP failed.")
    1.54 +            return -1
    1.55 +
    1.56 +    def play(self):
    1.57  
    1.58          try:
    1.59              os.mkfifo(self.fifo)
    1.60          except:
    1.61              lib.log("Fifo already exists")
    1.62  
    1.63 -        # good one: /tmp/dvb.mpg avi mpeg4 400 25 mp3lame 192 320 240 5000
    1.64 -        self.path = self.config.get("Mencoder", "path")
    1.65 -        self.path += " %s -mf fps=%d -of %s -oac %s -lameopts cbr:br=%d -ovc lavc"\
    1.66 -                     " -lavcopts vcodec=%s:vbitrate=%d -vf scale=%d:%d"\
    1.67 -                     " -o %s 1> /dev/null 2> /dev/null" % (
    1.68 -            self.filename, self.fps, self.mux, self.acodec, self.abitrate,
    1.69 -            self.vcodec, self.vbitrate, self.width, self.height, self.fifo)
    1.70 -
    1.71 -
    1.72 -        if (self.socket != None):
    1.73 -            del(self.socket)
    1.74 -
    1.75 -        self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    1.76 -        self.socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
    1.77 -        self.socket.bind( ('', self.port) )
    1.78 -        self.socket.listen(1)
    1.79 -
    1.80 -    def play(self):
    1.81 -
    1.82          lib.log("Starting Mencoder: %s" % self.path )
    1.83          # exec Mencoder
    1.84 -        pin, pout = os.popen2(self.path)
    1.85 +        pin, self.pout = os.popen2(self.path)
    1.86          pin.close()
    1.87  
    1.88          fifo = open(self.fifo)
    1.89 @@ -83,10 +91,11 @@
    1.90              else:
    1.91                  lib.log("Client timed out")
    1.92  
    1.93 -        pout.close()
    1.94  
    1.95      def stop(self):
    1.96  
    1.97 +        self.pout.close()
    1.98 +
    1.99          if (self.socket != None):
   1.100              lib.log("Closing socket")
   1.101              self.socket.close()