# HG changeset patch
# User morphbr
# Date 1175036262 -3600
# Node ID a7aba7d166fb840c9e16884b199c776d89f85fde
# Parent 997f281ba5960f253274a687ce0fe3f97e4144b1
[svn r471] - Added plugins/media/ffmpeg.py
- Added tests/client_ffmpeg.py (To test ffmpeg plugin using mplayer)
- Bug fixes inside gmyth-stream
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/main.py
--- a/gmyth-stream/main.py Tue Mar 27 21:43:05 2007 +0100
+++ b/gmyth-stream/main.py Tue Mar 27 23:57:42 2007 +0100
@@ -1,30 +1,3 @@
- '''
- # GMyth-Stream
- #
- # @file main.py
- #
- # @brief
Plugin for GMyth-Stream
- #
- # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
- # @author Artur Duque de Souza
- #
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- '''
-
#!/usr/bin/python
import sys
@@ -62,7 +35,9 @@
elif (msg == "SETUP"):
setup = server.getMsg(1024).strip().split(" ")
media.setup(setup[0], setup[1], setup[2], \
- setup[3], setup[4], setup[5])
+ setup[3], setup[4], setup[5],
+ setup[6], setup[7], setup[8],
+ setup[9])
elif (msg == "PLAY"):
media.play()
@@ -81,5 +56,5 @@
server.disconnect_client(con)
server.stop()
-
+del(server)
print "--> Server stopped..."
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/plugins/comm/tcp.py
--- a/gmyth-stream/plugins/comm/tcp.py Tue Mar 27 21:43:05 2007 +0100
+++ b/gmyth-stream/plugins/comm/tcp.py Tue Mar 27 23:57:42 2007 +0100
@@ -1,30 +1,3 @@
- '''
- # GMyth-Stream
- #
- # @file main.py
- #
- # @brief Plugin for GMyth-Stream
- #
- # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
- # @author Artur Duque de Souza
- #
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- '''
-
import time
import socket
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/plugins/media/ffmpeg.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/plugins/media/ffmpeg.py Tue Mar 27 23:57: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)
+
+
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/plugins/media/gstreamer.py
--- a/gmyth-stream/plugins/media/gstreamer.py Tue Mar 27 21:43:05 2007 +0100
+++ b/gmyth-stream/plugins/media/gstreamer.py Tue Mar 27 23:57:42 2007 +0100
@@ -1,30 +1,3 @@
- '''
- # GMyth-Stream
- #
- # @file main.py
- #
- # @brief Plugin for GMyth-Stream
- #
- # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
- # @author Artur Duque de Souza
- #
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- '''
-
import pygst
pygst.require("0.10")
import gst
@@ -38,13 +11,20 @@
self.config = config
self.pipe = ""
- def setup(self, filename, codec, bitrate, width, height, port):
+
+ def setup(self, filename, mux, vcodec, vbitrate,\
+ fps, acodec, abitrate, width, height, port):
self.filename = filename
- self.codec = codec
- self.bitrate = int(bitrate)
+ 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)
## Pipelines
@@ -62,7 +42,7 @@
" me-method=2 ! rtph263ppay ! udpsink host=224.0.0.1 port=%d d. ! "\
"queue ! audioconvert ! faac ! rtpmp4gpay ! udpsink name=udp_audio "\
"host=224.0.0.1 port=%d" % (self.filename, self.width, self.height,\
- self.bitrate, self.port, self.port+2)
+ self.vbitrate, self.port, self.port+2)
#self.pipe = "filesrc location=/tmp/mpg/cpm.mpg ! decodebin ! ffmpegcolorspace ! ximagesink"
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/plugins/media/vlc.py
--- a/gmyth-stream/plugins/media/vlc.py Tue Mar 27 21:43:05 2007 +0100
+++ b/gmyth-stream/plugins/media/vlc.py Tue Mar 27 23:57:42 2007 +0100
@@ -1,30 +1,3 @@
-'''
- # GMyth-Stream
- #
- # @file main.py
- #
- # @brief Plugin for GMyth-Stream
- #
- # Copyright (C) 2007 INdT - Instituto Nokia de Tecnologia.
- # @author Artur Duque de Souza
- #
- #
- # This program is free software; you can redistribute it and/or modify
- # it under the terms of the GNU Lesser General Public License as published by
- # the Free Software Foundation; either version 2 of the License, or
- # (at your option) any later version.
- #
- # This program is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU Lesser General Public License
- # along with this program; if not, write to the Free Software
- # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- #
- '''
-
import os
import sys
import time
@@ -52,12 +25,12 @@
self.path += " -I telnet -d 1> /dev/null 2> /dev/null &"
os.system(self.path)
sys.exit(0)
-
- print "ESTOU EM PARENT 1"
- time.sleep(3)
- print "ESTOU EM PARENT 2"
- self.sock.connect( (self.host, self.port) )
- self.sock.send("%s\n" % self.pwd)
+ else:
+ print "ESTOU EM PARENT 1"
+ time.sleep(3)
+ print "ESTOU EM PARENT 2"
+ self.sock.connect( (self.host, self.port) )
+ self.sock.send("%s\n" % self.pwd)
def insert_file(self, filename):
@@ -65,20 +38,28 @@
self.sock.send("setup output0 input %s\n" % filename)
- def setup(self, filename, codec, bitrate, width, height, port):
+
+ def setup(self, filename, mux, vcodec, vbitrate,\
+ fps, acodec, abitrate, width, height, port):
self.filename = filename
- self.codec = codec
- self.bitrate = int(bitrate)
+ 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)
+
self.pipe = "#transcode{vcodec=%s,vb=%d,"\
"fps=25.0,scale=1,acodec=mpga,"\
"ab=64,channels=1,width=%d,height=%d}"\
":duplicate{dst=std{access=http,"\
- "mux=mpeg1,dst=:%d}}" % (self.codec, self.bitrate,\
+ "mux=mpeg1,dst=:%d}}" % (self.vcodec, self.vbitrate,\
self.widht, self.height,\
self.port)
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/stream.conf
--- a/gmyth-stream/stream.conf Tue Mar 27 21:43:05 2007 +0100
+++ b/gmyth-stream/stream.conf Tue Mar 27 23:57:42 2007 +0100
@@ -1,12 +1,18 @@
-[Media]
-engine = gstreamer
-
[Comm]
engine = tcp
-port = 12344
+port = 12345
+
+
+[Media]
+engine = ffmpeg
+
[Vlc]
path = /usr/local/bin/vlc
host = 127.0.0.1
port = 4212
pwd = admin
+
+
+[FFmpeg]
+path = /usr/bin/ffmpeg
diff -r 997f281ba596 -r a7aba7d166fb gmyth-stream/tests/client_ffmpeg.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/gmyth-stream/tests/client_ffmpeg.py Tue Mar 27 23:57:42 2007 +0100
@@ -0,0 +1,24 @@
+import os
+import time
+import socket
+
+HOST='localhost'
+PORT=5000
+
+s = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
+s.settimeout(10)
+
+arq = open('/tmp/dvb.mpg','r')
+
+mplayer = os.popen("which mplayer").read().strip()
+mplayer += " -noidx -"
+pin, pout = os.popen2(mplayer)
+
+s.connect((HOST,PORT))
+i = 0
+
+data = s.recv(1024)
+while (data != ""):
+ pin.write(data)
+ data = s.recv(1024)
+