[svn r471] - Added plugins/media/ffmpeg.py trunk
authormorphbr
Tue Mar 27 23:57:42 2007 +0100 (2007-03-27)
branchtrunk
changeset 466a7aba7d166fb
parent 465 997f281ba596
child 467 bc13aaf7561d
[svn r471] - Added plugins/media/ffmpeg.py
- Added tests/client_ffmpeg.py (To test ffmpeg plugin using mplayer)
- Bug fixes inside gmyth-stream
gmyth-stream/main.py
gmyth-stream/plugins/comm/tcp.py
gmyth-stream/plugins/media/ffmpeg.py
gmyth-stream/plugins/media/gstreamer.py
gmyth-stream/plugins/media/vlc.py
gmyth-stream/stream.conf
gmyth-stream/tests/client_ffmpeg.py
     1.1 --- a/gmyth-stream/main.py	Tue Mar 27 21:43:05 2007 +0100
     1.2 +++ b/gmyth-stream/main.py	Tue Mar 27 23:57:42 2007 +0100
     1.3 @@ -1,30 +1,3 @@
     1.4 - '''
     1.5 - # GMyth-Stream
     1.6 - #
     1.7 - # @file main.py
     1.8 - #
     1.9 - # @brief <p> Plugin for GMyth-Stream
    1.10 - #
    1.11 - # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    1.12 - # @author Artur Duque de Souza <artur.souza@indt.org.br>
    1.13 - #
    1.14 - #
    1.15 - # This program is free software; you can redistribute it and/or modify
    1.16 - # it under the terms of the GNU Lesser General Public License as published by
    1.17 - # the Free Software Foundation; either version 2 of the License, or
    1.18 - # (at your option) any later version.
    1.19 - #
    1.20 - # This program is distributed in the hope that it will be useful,
    1.21 - # but WITHOUT ANY WARRANTY; without even the implied warranty of
    1.22 - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    1.23 - # GNU General Public License for more details.
    1.24 - #
    1.25 - # You should have received a copy of the GNU Lesser General Public License
    1.26 - # along with this program; if not, write to the Free Software
    1.27 - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    1.28 - #
    1.29 - '''
    1.30 -
    1.31  #!/usr/bin/python
    1.32  
    1.33  import sys
    1.34 @@ -62,7 +35,9 @@
    1.35          elif (msg == "SETUP"):
    1.36              setup = server.getMsg(1024).strip().split(" ")
    1.37              media.setup(setup[0], setup[1], setup[2], \
    1.38 -                        setup[3], setup[4], setup[5])
    1.39 +                        setup[3], setup[4], setup[5],
    1.40 +                        setup[6], setup[7], setup[8],
    1.41 +                        setup[9])
    1.42  
    1.43          elif (msg == "PLAY"):
    1.44              media.play()
    1.45 @@ -81,5 +56,5 @@
    1.46      server.disconnect_client(con)
    1.47  
    1.48  server.stop()
    1.49 -
    1.50 +del(server)
    1.51  print "--> Server stopped..."
     2.1 --- a/gmyth-stream/plugins/comm/tcp.py	Tue Mar 27 21:43:05 2007 +0100
     2.2 +++ b/gmyth-stream/plugins/comm/tcp.py	Tue Mar 27 23:57:42 2007 +0100
     2.3 @@ -1,30 +1,3 @@
     2.4 - '''
     2.5 - # GMyth-Stream
     2.6 - #
     2.7 - # @file main.py
     2.8 - #
     2.9 - # @brief <p> Plugin for GMyth-Stream
    2.10 - #
    2.11 - # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    2.12 - # @author Artur Duque de Souza <artur.souza@indt.org.br>
    2.13 - #
    2.14 - #
    2.15 - # This program is free software; you can redistribute it and/or modify
    2.16 - # it under the terms of the GNU Lesser General Public License as published by
    2.17 - # the Free Software Foundation; either version 2 of the License, or
    2.18 - # (at your option) any later version.
    2.19 - #
    2.20 - # This program is distributed in the hope that it will be useful,
    2.21 - # but WITHOUT ANY WARRANTY; without even the implied warranty of
    2.22 - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    2.23 - # GNU General Public License for more details.
    2.24 - #
    2.25 - # You should have received a copy of the GNU Lesser General Public License
    2.26 - # along with this program; if not, write to the Free Software
    2.27 - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    2.28 - #
    2.29 - '''
    2.30 -
    2.31  import time
    2.32  import socket
    2.33  
     3.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     3.2 +++ b/gmyth-stream/plugins/media/ffmpeg.py	Tue Mar 27 23:57:42 2007 +0100
     3.3 @@ -0,0 +1,72 @@
     3.4 +import os
     3.5 +import sys
     3.6 +import time
     3.7 +import socket
     3.8 +import ConfigParser
     3.9 +
    3.10 +class Media:
    3.11 +
    3.12 +    def __init__(self, config):
    3.13 +
    3.14 +        self.config = config
    3.15 +
    3.16 +    def setup(self, filename, mux, vcodec, vbitrate,\
    3.17 +              fps, acodec, abitrate, width, height, port):
    3.18 +
    3.19 +        self.filename = filename
    3.20 +        self.mux = mux
    3.21 +        self.vcodec = vcodec
    3.22 +        self.vbitrate = int(vbitrate)
    3.23 +        self.fps = int(fps)
    3.24 +        self.acodec = acodec
    3.25 +        self.abitrate = int(abitrate)
    3.26 +        self.width = int(width)
    3.27 +        self.height = int(height)
    3.28 +
    3.29 +        self.port = int(port)
    3.30 +
    3.31 +        # good one: /tmp/mpg/cpm.mpg mpeg mpeg1video 400 25 mp2 192 320 240 5000
    3.32 +        self.path = self.config.get("FFmpeg", "path")
    3.33 +        self.path += " -i %s -f %s -vcodec %s -b %d -r %d -acodec %s -ab %d -s %dx%d -" % (
    3.34 +            self.filename, self.mux, self.vcodec, self.vbitrate,\
    3.35 +            self.fps, self.acodec, self.abitrate, self.width, self.height)
    3.36 +
    3.37 +        self.socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    3.38 +        self.socket.bind( ('', self.port) )
    3.39 +
    3.40 +    def play(self):
    3.41 +
    3.42 +        self.socket.listen(1)
    3.43 +
    3.44 +        print "Starting FFmpeg: %s" % self.path
    3.45 +
    3.46 +        # exec FFmpeg and get stdout
    3.47 +        child_stdin, child_stdout = os.popen2(self.path)
    3.48 +        child_stdin.close()
    3.49 +
    3.50 +        self.child_pid = os.fork()
    3.51 +        if (self.child_pid == 0):
    3.52 +            #child
    3.53 +
    3.54 +            conn,addr= self.socket.accept()
    3.55 +            print "--> Sending Data..."
    3.56 +            data = child_stdout.read(1024)
    3.57 +
    3.58 +            while( data != ""):
    3.59 +                try:
    3.60 +                    conn.send(data)
    3.61 +                except socket.error:
    3.62 +                    break
    3.63 +                data = child_stdout.read(1024)
    3.64 +
    3.65 +            print "--> Finished sending data..."
    3.66 +            conn.close()
    3.67 +
    3.68 +
    3.69 +    def stop(self):
    3.70 +
    3.71 +        print "--> Trying to stop FFmpeg process..."
    3.72 +        self.socket.close()
    3.73 +        os.kill(self.child_pid, 9)
    3.74 +
    3.75 +
     4.1 --- a/gmyth-stream/plugins/media/gstreamer.py	Tue Mar 27 21:43:05 2007 +0100
     4.2 +++ b/gmyth-stream/plugins/media/gstreamer.py	Tue Mar 27 23:57:42 2007 +0100
     4.3 @@ -1,30 +1,3 @@
     4.4 - '''
     4.5 - # GMyth-Stream
     4.6 - #
     4.7 - # @file main.py
     4.8 - #
     4.9 - # @brief <p> Plugin for GMyth-Stream
    4.10 - #
    4.11 - # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    4.12 - # @author Artur Duque de Souza <artur.souza@indt.org.br>
    4.13 - #
    4.14 - #
    4.15 - # This program is free software; you can redistribute it and/or modify
    4.16 - # it under the terms of the GNU Lesser General Public License as published by
    4.17 - # the Free Software Foundation; either version 2 of the License, or
    4.18 - # (at your option) any later version.
    4.19 - #
    4.20 - # This program is distributed in the hope that it will be useful,
    4.21 - # but WITHOUT ANY WARRANTY; without even the implied warranty of
    4.22 - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    4.23 - # GNU General Public License for more details.
    4.24 - #
    4.25 - # You should have received a copy of the GNU Lesser General Public License
    4.26 - # along with this program; if not, write to the Free Software
    4.27 - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    4.28 - #
    4.29 - '''
    4.30 -
    4.31  import pygst
    4.32  pygst.require("0.10")
    4.33  import gst
    4.34 @@ -38,13 +11,20 @@
    4.35          self.config = config
    4.36          self.pipe = ""
    4.37  
    4.38 -    def setup(self, filename, codec, bitrate, width, height, port):
    4.39 +
    4.40 +    def setup(self, filename, mux, vcodec, vbitrate,\
    4.41 +              fps, acodec, abitrate, width, height, port):
    4.42  
    4.43          self.filename = filename
    4.44 -        self.codec = codec
    4.45 -        self.bitrate = int(bitrate)
    4.46 +        self.mux = mux
    4.47 +        self.vcodec = vcodec
    4.48 +        self.vbitrate = int(vbitrate)
    4.49 +        self.fps = int(fps)
    4.50 +        self.acodec = acodec
    4.51 +        self.abitrate = int(abitrate)
    4.52          self.width = int(width)
    4.53          self.height = int(height)
    4.54 +
    4.55          self.port = int(port)
    4.56  
    4.57          ## Pipelines
    4.58 @@ -62,7 +42,7 @@
    4.59                      " me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\
    4.60                      "queue  ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\
    4.61                      "host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\
    4.62 -                                                self.bitrate, self.port, self.port+2)
    4.63 +                                                self.vbitrate, self.port, self.port+2)
    4.64  
    4.65          #self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink"
    4.66  
     5.1 --- a/gmyth-stream/plugins/media/vlc.py	Tue Mar 27 21:43:05 2007 +0100
     5.2 +++ b/gmyth-stream/plugins/media/vlc.py	Tue Mar 27 23:57:42 2007 +0100
     5.3 @@ -1,30 +1,3 @@
     5.4 -'''
     5.5 - # GMyth-Stream
     5.6 - #
     5.7 - # @file main.py
     5.8 - #
     5.9 - # @brief <p> Plugin for GMyth-Stream
    5.10 - #
    5.11 - # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
    5.12 - # @author Artur Duque de Souza <artur.souza@indt.org.br>
    5.13 - #
    5.14 - #
    5.15 - # This program is free software; you can redistribute it and/or modify
    5.16 - # it under the terms of the GNU Lesser General Public License as published by
    5.17 - # the Free Software Foundation; either version 2 of the License, or
    5.18 - # (at your option) any later version.
    5.19 - #
    5.20 - # This program is distributed in the hope that it will be useful,
    5.21 - # but WITHOUT ANY WARRANTY; without even the implied warranty of
    5.22 - # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    5.23 - # GNU General Public License for more details.
    5.24 - #
    5.25 - # You should have received a copy of the GNU Lesser General Public License
    5.26 - # along with this program; if not, write to the Free Software
    5.27 - # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
    5.28 - #
    5.29 - '''
    5.30 -
    5.31  import os
    5.32  import sys
    5.33  import time
    5.34 @@ -52,12 +25,12 @@
    5.35              self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
    5.36              os.system(self.path)
    5.37              sys.exit(0)
    5.38 -
    5.39 -        print "ESTOU EM PARENT 1"
    5.40 -        time.sleep(3)
    5.41 -        print "ESTOU EM PARENT 2"
    5.42 -        self.sock.connect( (self.host, self.port) )
    5.43 -        self.sock.send("%s\n" % self.pwd)
    5.44 +        else:
    5.45 +            print "ESTOU EM PARENT 1"
    5.46 +            time.sleep(3)
    5.47 +            print "ESTOU EM PARENT 2"
    5.48 +            self.sock.connect( (self.host, self.port) )
    5.49 +            self.sock.send("%s\n" % self.pwd)
    5.50  
    5.51  
    5.52      def insert_file(self, filename):
    5.53 @@ -65,20 +38,28 @@
    5.54          self.sock.send("setup output0 input %s\n" % filename)
    5.55  
    5.56  
    5.57 -    def setup(self, filename, codec, bitrate, width, height, port):
    5.58 +
    5.59 +    def setup(self, filename, mux, vcodec, vbitrate,\
    5.60 +              fps, acodec, abitrate, width, height, port):
    5.61  
    5.62          self.filename = filename
    5.63 -        self.codec = codec
    5.64 -        self.bitrate = int(bitrate)
    5.65 +        self.mux = mux
    5.66 +        self.vcodec = vcodec
    5.67 +        self.vbitrate = int(vbitrate)
    5.68 +        self.fps = int(fps)
    5.69 +        self.acodec = acodec
    5.70 +        self.abitrate = int(abitrate)
    5.71          self.width = int(width)
    5.72          self.height = int(height)
    5.73 +
    5.74          self.port = int(port)
    5.75  
    5.76 +
    5.77          self.pipe = "#transcode{vcodec=%s,vb=%d,"\
    5.78                      "fps=25.0,scale=1,acodec=mpga,"\
    5.79                      "ab=64,channels=1,width=%d,height=%d}"\
    5.80                      ":duplicate{dst=std{access=http,"\
    5.81 -                    "mux=mpeg1,dst=:%d}}" % (self.codec, self.bitrate,\
    5.82 +                    "mux=mpeg1,dst=:%d}}" % (self.vcodec, self.vbitrate,\
    5.83                                               self.widht, self.height,\
    5.84                                               self.port)
    5.85  
     6.1 --- a/gmyth-stream/stream.conf	Tue Mar 27 21:43:05 2007 +0100
     6.2 +++ b/gmyth-stream/stream.conf	Tue Mar 27 23:57:42 2007 +0100
     6.3 @@ -1,12 +1,18 @@
     6.4 -[Media]
     6.5 -engine = gstreamer
     6.6 -
     6.7  [Comm]
     6.8  engine = tcp
     6.9 -port = 12344
    6.10 +port = 12345
    6.11 +
    6.12 +
    6.13 +[Media]
    6.14 +engine = ffmpeg
    6.15 +
    6.16  
    6.17  [Vlc]
    6.18  path = /usr/local/bin/vlc
    6.19  host = 127.0.0.1
    6.20  port = 4212
    6.21  pwd = admin
    6.22 +
    6.23 +
    6.24 +[FFmpeg]
    6.25 +path = /usr/bin/ffmpeg
     7.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     7.2 +++ b/gmyth-stream/tests/client_ffmpeg.py	Tue Mar 27 23:57:42 2007 +0100
     7.3 @@ -0,0 +1,24 @@
     7.4 +import os
     7.5 +import time
     7.6 +import socket
     7.7 +
     7.8 +HOST='localhost'
     7.9 +PORT=5000
    7.10 +
    7.11 +s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
    7.12 +s.settimeout(10)
    7.13 +
    7.14 +arq = open('/tmp/dvb.mpg','r')
    7.15 +
    7.16 +mplayer = os.popen("which mplayer").read().strip()
    7.17 +mplayer += " -noidx -"
    7.18 +pin, pout = os.popen2(mplayer)
    7.19 +
    7.20 +s.connect((HOST,PORT))
    7.21 +i = 0
    7.22 +
    7.23 +data = s.recv(1024)
    7.24 +while (data != ""):
    7.25 +    pin.write(data)
    7.26 +    data = s.recv(1024)
    7.27 +