aboutsummaryrefslogtreecommitdiff
path: root/voctocore/experiments
diff options
context:
space:
mode:
Diffstat (limited to 'voctocore/experiments')
-rwxr-xr-xvoctocore/experiments/sync-videomix.py61
1 files changed, 61 insertions, 0 deletions
diff --git a/voctocore/experiments/sync-videomix.py b/voctocore/experiments/sync-videomix.py
new file mode 100755
index 0000000..0f6e780
--- /dev/null
+++ b/voctocore/experiments/sync-videomix.py
@@ -0,0 +1,61 @@
+#!/usr/bin/python3
+import gi, time
+import socket
+
+# import GStreamer and GTK-Helper classes
+gi.require_version('Gst', '1.0')
+from gi.repository import GLib, Gst, GObject
+
+# init GObject before importing local classes
+GObject.threads_init()
+Gst.init(None)
+
+class Example:
+ def __init__(self):
+ self.mainloop = GObject.MainLoop()
+
+ pipeline = """
+ videotestsrc pattern=red !
+ {caps} !
+ identity sync=true signal-handoffs=false !
+ mix.
+
+ videotestsrc pattern=green !
+ {caps} !
+ identity sync=true signal-handoffs=false !
+ mix.
+
+ videomixer name=mix !
+ {caps} !
+ identity name=sig !
+ videoconvert !
+ pngenc !
+ multifilesink location=frame%04d.png
+ """.format(
+ caps='video/x-raw,height=450,width=800,format=I420,framerate=25/1'
+ )
+
+ self.pipeline = Gst.parse_launch(pipeline)
+ sig = self.pipeline.get_by_name('sig')
+ sig.connect('handoff', self.handoff)
+
+ self.mix = self.pipeline.get_by_name('mix')
+ self.state = 0
+
+ def handoff(self, object, buffer):
+ mixerpad = self.mix.get_static_pad('sink_1')
+
+ print('handoff, alpha=%u' % self.state)
+ mixerpad.set_property('alpha', self.state)
+ self.state = 0 if self.state else 1
+
+ def run(self):
+ self.pipeline.set_state(Gst.State.PLAYING)
+ self.mainloop.run()
+
+ def kill(self):
+ self.pipeline.set_state(Gst.State.NULL)
+ self.mainloop.quit()
+
+example = Example()
+example.run()