summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xvoctocore/experiments/intervideo.py128
1 files changed, 59 insertions, 69 deletions
diff --git a/voctocore/experiments/intervideo.py b/voctocore/experiments/intervideo.py
index 404ea20..11b39ce 100755
--- a/voctocore/experiments/intervideo.py
+++ b/voctocore/experiments/intervideo.py
@@ -13,28 +13,32 @@ Gst.init(None)
class Example:
def __init__(self):
self.mainloop = GObject.MainLoop()
- #self.vsink = Gst.parse_launch('intervideosrc channel=video ! video/x-raw,height=600,width=800,format=I420,framerate=25/1 ! timeoverlay ! videoconvert ! ximagesink')
- self.vsource = None
+ self.source_pipeline = None
- #self.asink = Gst.parse_launch('interaudiosrc channel=audio ! audio/x-raw,format=S16LE,layout=interleaved,rate=48000,channels=2 ! autoaudiosink')
- self.asource = None
-
- self.sink = Gst.parse_launch("""
+ self.sink_pipeline = Gst.parse_launch("""
intervideosrc channel=video !
queue !
- video/x-raw,height=600,width=800,format=I420,framerate=25/1 !
- timeoverlay !
- tee name=vtee !
+ video/x-raw,width=800,height=450,format=I420,framerate=25/1 !
+ textoverlay halignment=left valignment=top ypad=50 text=intervideosrc !
+ timeoverlay halignment=left valignment=top ypad=50 xpad=400 !
+ tee name=vtee
+
+ interaudiosrc blocksize=4096 channel=audio !
+ queue !
+ audio/x-raw,format=S16LE,layout=interleaved,rate=48000,channels=2 !
+ tee name=atee
+
+
+ vtee. !
queue !
videoconvert !
+ textoverlay halignment=left valignment=top ypad=75 text=avenc_mpeg2video !
+ timeoverlay halignment=left valignment=top ypad=75 xpad=400 !
avenc_mpeg2video bitrate=50000 max-key-interval=0 !
queue !
mux.
- interaudiosrc blocksize=4096 channel=audio !
- queue !
- audio/x-raw,format=S16LE,layout=interleaved,rate=48000,channels=2 !
- tee name=atee !
+ atee. !
queue !
avenc_mp2 bitrate=192000 !
queue !
@@ -43,88 +47,74 @@ class Example:
mpegtsmux name=mux !
filesink location=foo.ts
- vtee. ! queue ! videoconvert ! xvimagesink
- atee. ! queue ! audioconvert ! alsasink
- """)
-
- # Create the server, binding to localhost on port 5000
- vsock = socket.socket(socket.AF_INET6)
- vsock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- vsock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
- vsock.bind(('::', 5000))
- vsock.listen(1)
+ vtee. !
+ queue !
+ textoverlay halignment=left valignment=top ypad=75 text=xvimagesink !
+ timeoverlay halignment=left valignment=top ypad=75 xpad=400 !
+ videoconvert !
+ xvimagesink
+ atee. !
+ queue !
+ audioconvert !
+ alsasink
+ """)
# Create the server, binding to localhost on port 5000
- asock = socket.socket(socket.AF_INET6)
- asock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
- asock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
- asock.bind(('::', 6000))
- asock.listen(1)
+ sock = socket.socket(socket.AF_INET6)
+ sock.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
+ sock.setsockopt(socket.IPPROTO_IPV6, socket.IPV6_V6ONLY, False)
+ sock.bind(('::', 10000))
+ sock.listen(1)
# register socket for callback inside the GTK-Mainloop
- GObject.io_add_watch(vsock, GObject.IO_IN, self.video_connect)
- GObject.io_add_watch(asock, GObject.IO_IN, self.audio_connect)
+ GObject.io_add_watch(sock, GObject.IO_IN, self.on_connect)
- def video_connect(self, sock, *args):
+ def on_connect(self, sock, *args):
'''Asynchronous connection listener. Starts a handler for each connection.'''
- if self.vsource:
+ if self.source_pipeline:
return False
conn, addr = sock.accept()
print("Connection from", addr)
- self.vsource = Gst.parse_launch('fdsrc name=a fd=%u ! gdpdepay ! video/x-raw,height=600,width=800,format=I420,framerate=25/1 ! timeoverlay halignment=right ! intervideosink channel=video' % conn.fileno())
-
- self.vsource.bus.add_signal_watch()
- self.vsource.bus.connect("message::eos", self.video_disconnect)
-
- self.vsource.set_state(Gst.State.PLAYING)
-
- self.vconn = conn
- return True
-
- def video_disconnect(self, bus, message):
- self.vsource.set_state(Gst.State.NULL)
- self.vsource = None
- self.vconn = None
- return True
-
+ self.source_pipeline = Gst.parse_launch("""
+ fdsrc name=a fd=%u !
+ matroskademux name=demux
- def audio_connect(self, sock, *args):
- '''Asynchronous connection listener. Starts a handler for each connection.'''
- if self.asource:
- return False
+ demux. !
+ video/x-raw,width=800,height=450,format=I420,framerate=25/1 !
+ queue !
+ textoverlay halignment=left valignment=top ypad=25 text=intervideosink !
+ timeoverlay halignment=left valignment=top ypad=25 xpad=400 !
+ intervideosink channel=video
- conn, addr = sock.accept()
- print("Connection from", addr)
+ demux. !
+ audio/x-raw,format=S16LE,channels=2,layout=interleaved,rate=48000,channel-mask=(bitmask)0x3 !
+ queue !
+ interaudiosink channel=audio
- self.asource = Gst.parse_launch('fdsrc name=a fd=%u ! gdpdepay ! audio/x-raw,format=S16LE,layout=interleaved,rate=48000,channels=2 ! interaudiosink channel=audio' % conn.fileno())
+ """ % conn.fileno())
- self.asource.bus.add_signal_watch()
- self.asource.bus.connect("message::eos", self.audio_disconnect)
+ self.source_pipeline.bus.add_signal_watch()
+ self.source_pipeline.bus.connect("message::eos", self.on_disconnect)
- self.asource.set_state(Gst.State.PLAYING)
+ self.source_pipeline.set_state(Gst.State.PLAYING)
- self.aconn = conn
+ self.conn = conn
return True
- def audio_disconnect(self, bus, message):
- self.asource.set_state(Gst.State.NULL)
- self.asource = None
- self.aconn = None
+ def on_disconnect(self, bus, message):
+ self.source_pipeline.set_state(Gst.State.NULL)
+ self.source_pipeline = None
+ self.conn = None
return True
-
def run(self):
- self.sink.set_state(Gst.State.PLAYING)
+ self.sink_pipeline.set_state(Gst.State.PLAYING)
self.mainloop.run()
- def kill(self):
- self.sink.set_state(Gst.State.NULL)
- self.mainloop.quit()
-
example = Example()
example.run()