summaryrefslogtreecommitdiff
path: root/voctocore/experiments/sync-videomix.py
diff options
context:
space:
mode:
authorMaZderMind <github@mazdermind.de>2015-05-24 12:11:56 +0200
committerMaZderMind <github@mazdermind.de>2015-05-24 12:11:56 +0200
commit75da6856b600170f5903531584a0d3524cd76361 (patch)
treede8e32f16f5d309f23d726b50ee622275e078323 /voctocore/experiments/sync-videomix.py
parentcfbdeccfc62965d227571c6fd6d66d97f67ce4a4 (diff)
example on how to change videomixer property in sync with the mixer thread
Diffstat (limited to 'voctocore/experiments/sync-videomix.py')
-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()