From 75da6856b600170f5903531584a0d3524cd76361 Mon Sep 17 00:00:00 2001 From: MaZderMind Date: Sun, 24 May 2015 12:11:56 +0200 Subject: example on how to change videomixer property in sync with the mixer thread --- voctocore/experiments/sync-videomix.py | 61 ++++++++++++++++++++++++++++++++++ 1 file changed, 61 insertions(+) create mode 100755 voctocore/experiments/sync-videomix.py (limited to 'voctocore/experiments') 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() -- cgit v1.2.3